aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Anderson <dianders@chromium.org>2016-01-28 21:20:10 -0500
committerFelipe Balbi <balbi@kernel.org>2016-03-04 08:14:44 -0500
commitfae4e82609b0887d6d675170d0c20b6af45d83ba (patch)
treed765ea7f3d85865c47ad4308eff9ee4f49a6634c
parentfb616e3f837eee20cc0c6d5866983f7d2730d5a3 (diff)
usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call
As we start getting more exact about our scheduling it's becoming more and more important to know exactly how far through the current frame we are. This lets us make decisions about whether there's still time left to start a new transaction in the current frame. We'll add dwc2_hcd_get_future_frame_number() which will tell you what the frame number will be a certain number of microseconds (us) from now. We can use this information to help decide if there's enough time left in the frame for a transaction that will take a certain duration. This is expected to be used by a future change ("usb: dwc2: host: Properly set even/odd frame"). Acked-by: John Youn <johnyoun@synopsys.com> Signed-off-by: Douglas Anderson <dianders@chromium.org> Tested-by: Heiko Stuebner <heiko@sntech.de> Tested-by: Stefan Wahren <stefan.wahren@i2se.com> Signed-off-by: Felipe Balbi <balbi@kernel.org>
-rw-r--r--drivers/usb/dwc2/core.h4
-rw-r--r--drivers/usb/dwc2/hcd.c29
2 files changed, 33 insertions, 0 deletions
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 64d45a2053bb..52cbea28d0e9 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1235,12 +1235,16 @@ static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
1235 1235
1236#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) 1236#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
1237extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); 1237extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg);
1238extern int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us);
1238extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg); 1239extern void dwc2_hcd_connect(struct dwc2_hsotg *hsotg);
1239extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force); 1240extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force);
1240extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg); 1241extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
1241#else 1242#else
1242static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg) 1243static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1243{ return 0; } 1244{ return 0; }
1245static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg,
1246 int us)
1247{ return 0; }
1244static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {} 1248static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {}
1245static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {} 1249static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force) {}
1246static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} 1250static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index f48da015fa5e..8edd0b45f41c 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -1947,6 +1947,35 @@ int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
1947 return (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT; 1947 return (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT;
1948} 1948}
1949 1949
1950int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us)
1951{
1952 u32 hprt = dwc2_readl(hsotg->regs + HPRT0);
1953 u32 hfir = dwc2_readl(hsotg->regs + HFIR);
1954 u32 hfnum = dwc2_readl(hsotg->regs + HFNUM);
1955 unsigned int us_per_frame;
1956 unsigned int frame_number;
1957 unsigned int remaining;
1958 unsigned int interval;
1959 unsigned int phy_clks;
1960
1961 /* High speed has 125 us per (micro) frame; others are 1 ms per */
1962 us_per_frame = (hprt & HPRT0_SPD_MASK) ? 1000 : 125;
1963
1964 /* Extract fields */
1965 frame_number = (hfnum & HFNUM_FRNUM_MASK) >> HFNUM_FRNUM_SHIFT;
1966 remaining = (hfnum & HFNUM_FRREM_MASK) >> HFNUM_FRREM_SHIFT;
1967 interval = (hfir & HFIR_FRINT_MASK) >> HFIR_FRINT_SHIFT;
1968
1969 /*
1970 * Number of phy clocks since the last tick of the frame number after
1971 * "us" has passed.
1972 */
1973 phy_clks = (interval - remaining) +
1974 DIV_ROUND_UP(interval * us, us_per_frame);
1975
1976 return dwc2_frame_num_inc(frame_number, phy_clks / interval);
1977}
1978
1950int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg) 1979int dwc2_hcd_is_b_host(struct dwc2_hsotg *hsotg)
1951{ 1980{
1952 return hsotg->op_state == OTG_STATE_B_HOST; 1981 return hsotg->op_state == OTG_STATE_B_HOST;