summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJules Maselbas <jmaselbas@kalray.eu>2021-03-12 17:24:31 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-03-15 09:51:33 +0100
commit5d417e1b8bd22df8e9e318b28d17c56bf8fadb7e (patch)
tree81e6e17c749cfc3066b5ff918295b50841d68429
parentfdd30cc251c87b2932ece10023b4c7287e1e560d (diff)
downloadbarebox-5d417e1b8bd22df8e9e318b28d17c56bf8fadb7e.tar.gz
barebox-5d417e1b8bd22df8e9e318b28d17c56bf8fadb7e.tar.xz
usb: dwc2: Move wait_for_mode and iddig_filter_enabled to core
Move functions dwc2_wait_for_mode() and dwc2_iddig_filter_enabled() into core.c so they can be used during dwc2_core_init(). Cc: Michael Grzeschik <m.grzeschik@pengutronix.de> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/usb/dwc2/core.c53
-rw-r--r--drivers/usb/dwc2/dwc2.h3
-rw-r--r--drivers/usb/dwc2/gadget.c53
3 files changed, 56 insertions, 53 deletions
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 8ec77d68a5..24efe5a412 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -681,6 +681,59 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2)
return 0;
}
+/**
+ * dwc2_wait_for_mode() - Waits for the controller mode.
+ * @dwc2: Programming view of the DWC_otg controller.
+ * @host_mode: If true, waits for host mode, otherwise device mode.
+ */
+void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode)
+{
+ unsigned int timeout = 110 * USECOND;
+ int ret;
+
+ dev_vdbg(dwc2->dev, "Waiting for %s mode\n",
+ host_mode ? "host" : "device");
+
+ ret = wait_on_timeout(timeout, dwc2_is_host_mode(dwc2) == host_mode);
+ if (ret)
+ dev_err(dwc2->dev, "%s: Couldn't set %s mode\n",
+ __func__, host_mode ? "host" : "device");
+
+ dev_vdbg(dwc2->dev, "%s mode set\n",
+ host_mode ? "Host" : "Device");
+}
+
+/**
+ * dwc2_iddig_filter_enabled() - Returns true if the IDDIG debounce
+ * filter is enabled.
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+bool dwc2_iddig_filter_enabled(struct dwc2 *dwc2)
+{
+ u32 gsnpsid;
+ u32 ghwcfg4;
+
+ /* Check if core configuration includes the IDDIG filter. */
+ ghwcfg4 = dwc2_readl(dwc2, GHWCFG4);
+ if (!(ghwcfg4 & GHWCFG4_IDDIG_FILT_EN))
+ return false;
+
+ /*
+ * Check if the IDDIG debounce filter is bypassed. Available
+ * in core version >= 3.10a.
+ */
+ gsnpsid = dwc2_readl(dwc2, GSNPSID);
+ if (gsnpsid >= DWC2_CORE_REV_3_10a) {
+ u32 gotgctl = dwc2_readl(dwc2, GOTGCTL);
+
+ if (gotgctl & GOTGCTL_DBNCE_FLTR_BYPASS)
+ return false;
+ }
+
+ return true;
+}
+
/*
* Do core a soft reset of the core. Be careful with this because it
* resets all the internal state machines of the core.
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index b9fdda850d..31827d4c7a 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -25,6 +25,9 @@ int dwc2_get_dr_mode(struct dwc2 *dwc2);
int dwc2_core_reset(struct dwc2 *dwc2);
void dwc2_core_init(struct dwc2 *dwc2);
+void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode);
+bool dwc2_iddig_filter_enabled(struct dwc2 *dwc2);
+
/* Host functions */
#ifdef CONFIG_USB_DWC2_HOST
int dwc2_submit_roothub(struct dwc2 *dwc2, struct usb_device *dev,
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 3fc7099d78..3df5d73522 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2661,59 +2661,6 @@ static int dwc2_eps_alloc(struct dwc2 *dwc2)
}
/**
- * dwc2_wait_for_mode() - Waits for the controller mode.
- * @dwc2: Programming view of the DWC_otg controller.
- * @host_mode: If true, waits for host mode, otherwise device mode.
- */
-static void dwc2_wait_for_mode(struct dwc2 *dwc2, bool host_mode)
-{
- unsigned int timeout = 110 * USECOND;
- int ret;
-
- dev_vdbg(dwc2->dev, "Waiting for %s mode\n",
- host_mode ? "host" : "device");
-
- ret = wait_on_timeout(timeout, dwc2_is_host_mode(dwc2) == host_mode);
- if (ret)
- dev_err(dwc2->dev, "%s: Couldn't set %s mode\n",
- __func__, host_mode ? "host" : "device");
-
- dev_vdbg(dwc2->dev, "%s mode set\n",
- host_mode ? "Host" : "Device");
-}
-
-/**
- * dwc2_iddig_filter_enabled() - Returns true if the IDDIG debounce
- * filter is enabled.
- *
- * @hsotg: Programming view of DWC_otg controller
- */
-static bool dwc2_iddig_filter_enabled(struct dwc2 *dwc2)
-{
- u32 gsnpsid;
- u32 ghwcfg4;
-
- /* Check if core configuration includes the IDDIG filter. */
- ghwcfg4 = dwc2_readl(dwc2, GHWCFG4);
- if (!(ghwcfg4 & GHWCFG4_IDDIG_FILT_EN))
- return false;
-
- /*
- * Check if the IDDIG debounce filter is bypassed. Available
- * in core version >= 3.10a.
- */
- gsnpsid = dwc2_readl(dwc2, GSNPSID);
- if (gsnpsid >= DWC2_CORE_REV_3_10a) {
- u32 gotgctl = dwc2_readl(dwc2, GOTGCTL);
-
- if (gotgctl & GOTGCTL_DBNCE_FLTR_BYPASS)
- return false;
- }
-
- return true;
-}
-
-/**
* dwc2_force_mode() - Force the mode of the controller.
*
* Forcing the mode is needed for two cases: