[PATCH 14/18] usb: dwc2: Add functions to set and clear force mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Added functions to set force mode for host and device. These functions
will check the current mode and only force if needed.

Signed-off-by: John Youn <johnyoun@xxxxxxxxxxxx>
---
 drivers/usb/dwc2/core.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 7090050..caaff42 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -3105,6 +3105,60 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
 	dwc2_set_param_hibernation(hsotg, params->hibernation);
 }
 
+/*
+ * Force host mode if not in host mode. Returns true if the mode was
+ * forced.
+ */
+static bool dwc2_force_host_if_needed(struct dwc2_hsotg *hsotg)
+{
+	u32 gusbcfg;
+
+	if (dwc2_is_host_mode(hsotg))
+		return false;
+
+	gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
+	gusbcfg &= ~GUSBCFG_FORCEDEVMODE;
+	gusbcfg |= GUSBCFG_FORCEHOSTMODE;
+	dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG);
+	usleep_range(25000, 50000);
+
+	return true;
+}
+
+/*
+ * Force device mode if not in device mode. Returns true if the mode
+ * was forced.
+ */
+static bool dwc2_force_device_if_needed(struct dwc2_hsotg *hsotg)
+{
+	u32 gusbcfg;
+
+	if (dwc2_is_device_mode(hsotg))
+		return false;
+
+	gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
+	gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
+	gusbcfg |= GUSBCFG_FORCEDEVMODE;
+	dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG);
+	usleep_range(25000, 50000);
+
+	return true;
+}
+
+/*
+ * Clears the force mode bits.
+ */
+static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
+{
+	u32 gusbcfg;
+
+	gusbcfg = dwc2_readl(hsotg->regs + GUSBCFG);
+	gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
+	gusbcfg &= ~GUSBCFG_FORCEDEVMODE;
+	dwc2_writel(gusbcfg, hsotg->regs + GUSBCFG);
+	usleep_range(25000, 50000);
+}
+
 /**
  * During device initialization, read various hardware configuration
  * registers and interpret the contents.
-- 
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux