Re: [PATCH 10/18] usb: dwc2: Add functions to check the HW OTG config

2015-12-09 Thread Doug Anderson
John,

On Wed, Dec 2, 2015 at 11:13 AM, John Youn  wrote:
> Added functions to query the GHWCFG2.OTG_MODE. This tells us whether the
> controller hardware is configured for OTG, device-only, or host-only.
>
> Signed-off-by: John Youn 
> ---
>  drivers/usb/dwc2/core.c | 37 +
>  drivers/usb/dwc2/core.h | 13 +
>  2 files changed, 50 insertions(+)

On a backport to 3.14 on rk3288, confirmed that one port is properly
identified as host only and the other as OTG.  Specifically:

dwc2_hw_is_device() = false on both ports
dwc2_hw_is_host() = true on host only port, false on otg port
dwc2_hw_is_otg() = true on otg port (didn't test on host only port,
but by code inspection should be right).

These functions also look sane according to the databook, so feel free to add:

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


[PATCH 10/18] usb: dwc2: Add functions to check the HW OTG config

2015-12-02 Thread John Youn
Added functions to query the GHWCFG2.OTG_MODE. This tells us whether the
controller hardware is configured for OTG, device-only, or host-only.

Signed-off-by: John Youn 
---
 drivers/usb/dwc2/core.c | 37 +
 drivers/usb/dwc2/core.h | 13 +
 2 files changed, 50 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index b7a733a..382f563 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -3323,6 +3323,43 @@ void dwc2_disable_global_interrupts(struct dwc2_hsotg 
*hsotg)
dwc2_writel(ahbcfg, hsotg->regs + GAHBCFG);
 }
 
+/* Returns the controller's GHWCFG2.OTG_MODE. */
+unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg)
+{
+   u32 ghwcfg2 = dwc2_readl(hsotg->regs + GHWCFG2);
+
+   return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >>
+   GHWCFG2_OP_MODE_SHIFT;
+}
+
+/* Returns true if the controller is capable of DRD. */
+bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg)
+{
+   unsigned op_mode = dwc2_op_mode(hsotg);
+
+   return (op_mode == GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) ||
+   (op_mode == GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE) ||
+   (op_mode == GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE);
+}
+
+/* Returns true if the controller is host-only. */
+bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg)
+{
+   unsigned op_mode = dwc2_op_mode(hsotg);
+
+   return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_HOST) ||
+   (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST);
+}
+
+/* Returns true if the controller is device-only. */
+bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg)
+{
+   unsigned op_mode = dwc2_op_mode(hsotg);
+
+   return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
+   (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE);
+}
+
 MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
 MODULE_AUTHOR("Synopsys, Inc.");
 MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 53c992a..2768f0c 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1147,6 +1147,19 @@ extern int dwc2_lowlevel_hw_enable(struct dwc2_hsotg 
*hsotg);
 extern int dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg);
 
 /*
+ * The following functions check the controller's OTG operation mode
+ * capability (GHWCFG2.OTG_MODE).
+ *
+ * These functions can be used before the internal hsotg->hw_params
+ * are read in and cached so they always read directly from the
+ * GHWCFG2 register.
+ */
+unsigned dwc2_op_mode(struct dwc2_hsotg *hsotg);
+bool dwc2_hw_is_otg(struct dwc2_hsotg *hsotg);
+bool dwc2_hw_is_host(struct dwc2_hsotg *hsotg);
+bool dwc2_hw_is_device(struct dwc2_hsotg *hsotg);
+
+/*
  * Dump core registers and SPRAM
  */
 extern void dwc2_dump_dev_registers(struct dwc2_hsotg *hsotg);
-- 
2.6.3

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