diff mbox

[U-Boot,05/11] drivers: usb: dwc3: add ti dwc3 misc driver for wrapper

Message ID 20170523115546.399-6-vigneshr@ti.com
State Superseded
Delegated to: Marek Vasut
Headers show

Commit Message

Raghavendra, Vignesh May 23, 2017, 11:55 a.m. UTC
From: Mugunthan V N <mugunthanvnm@ti.com>

Add a misc driver for DWC3 wrapper, so that based on dr_mode the
USB devices can bind to USB host or USB device drivers.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
Signed-off-by: Vignesh R <vigneshr@ti.com>
---
 board/ti/am57xx/board.c      | 11 ----------
 drivers/usb/dwc3/core.h      |  4 ++++
 drivers/usb/dwc3/dwc3-omap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/dwc3/gadget.c    |  2 +-
 4 files changed, 57 insertions(+), 12 deletions(-)

Comments

Simon Glass May 31, 2017, 3:50 a.m. UTC | #1
On 23 May 2017 at 05:55, Vignesh R <vigneshr@ti.com> wrote:
> From: Mugunthan V N <mugunthanvnm@ti.com>
>
> Add a misc driver for DWC3 wrapper, so that based on dr_mode the
> USB devices can bind to USB host or USB device drivers.
>
> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
> Signed-off-by: Vignesh R <vigneshr@ti.com>
> ---
>  board/ti/am57xx/board.c      | 11 ----------
>  drivers/usb/dwc3/core.h      |  4 ++++
>  drivers/usb/dwc3/dwc3-omap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/dwc3/gadget.c    |  2 +-
>  4 files changed, 57 insertions(+), 12 deletions(-)

Can you explain why this is a misc driver, and how it will be instantiated?
Raghavendra, Vignesh May 31, 2017, 5:06 a.m. UTC | #2
Hi,

On Wednesday 31 May 2017 09:20 AM, Simon Glass wrote:
> On 23 May 2017 at 05:55, Vignesh R <vigneshr@ti.com> wrote:
>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>
>> Add a misc driver for DWC3 wrapper, so that based on dr_mode the
>> USB devices can bind to USB host or USB device drivers.
>>
>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>> Signed-off-by: Vignesh R <vigneshr@ti.com>
>> ---
>>  board/ti/am57xx/board.c      | 11 ----------
>>  drivers/usb/dwc3/core.h      |  4 ++++
>>  drivers/usb/dwc3/dwc3-omap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
>>  drivers/usb/dwc3/gadget.c    |  2 +-
>>  4 files changed, 57 insertions(+), 12 deletions(-)
> 
> Can you explain why this is a misc driver, and how it will be instantiated?

Based on dr_mode property, the device node needs to bind to either
"host" driver or "peripheral" driver. Therefore, this wrapper is written
for DWC3, which on bind will read dr_mode property and appropriately
associate USB DT node with DWC3 peripheral driver or host driver.

This is similar to what exists today for MUSB[1] and is instantiated by
arch_misc_init() function for am33xx and am43xx

I got these patch from U-Boot list which the author had submitted
previosuly and got Reviewed-by and did not look deep into it. But looks
like this patch really needs be read along with patch 7/10. I will
re-split and reorder this patch in the next version.


[1]https://www.mail-archive.com/u-boot@lists.denx.de/msg231076.html
Raghavendra, Vignesh May 31, 2017, 5:06 a.m. UTC | #3
Hi,

On Wednesday 31 May 2017 09:20 AM, Simon Glass wrote:
> On 23 May 2017 at 05:55, Vignesh R <vigneshr@ti.com> wrote:
>> From: Mugunthan V N <mugunthanvnm@ti.com>
>>
>> Add a misc driver for DWC3 wrapper, so that based on dr_mode the
>> USB devices can bind to USB host or USB device drivers.
>>
>> Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
>> Signed-off-by: Vignesh R <vigneshr@ti.com>
>> ---
>>  board/ti/am57xx/board.c      | 11 ----------
>>  drivers/usb/dwc3/core.h      |  4 ++++
>>  drivers/usb/dwc3/dwc3-omap.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
>>  drivers/usb/dwc3/gadget.c    |  2 +-
>>  4 files changed, 57 insertions(+), 12 deletions(-)
> 
> Can you explain why this is a misc driver, and how it will be instantiated?

Based on dr_mode property, the device node needs to bind to either
"host" driver or "peripheral" driver. Therefore, this wrapper is written
for DWC3, which on bind will read dr_mode property and appropriately
associate USB DT node with DWC3 peripheral driver or host driver.

This is similar to what exists today for MUSB[1] and is instantiated by
arch_misc_init() function for am33xx and am43xx

I got these patch from U-Boot list which the author had submitted
previously and got Reviewed-by and did not look deep into it. But looks
like this patch really needs be read along with patch 7/10. I will
re-split and reorder this patch in the next version.


[1]https://www.mail-archive.com/u-boot@lists.denx.de/msg231076.html
diff mbox

Patch

diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c
index 3566f8d94972..6137601588a2 100644
--- a/board/ti/am57xx/board.c
+++ b/board/ti/am57xx/board.c
@@ -706,17 +706,6 @@  static struct ti_usb_phy_device usb_phy2_device = {
 	.usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
 	.index = 1,
 };
-
-int usb_gadget_handle_interrupts(int index)
-{
-	u32 status;
-
-	status = dwc3_omap_uboot_interrupt_status(index);
-	if (status)
-		dwc3_uboot_handle_interrupt(index);
-
-	return 0;
-}
 #endif /* CONFIG_USB_DWC3 */
 
 #if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP)
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 72d2fcdd3f42..24f03e484fd5 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -713,7 +713,11 @@  struct dwc3 {
 	/* device lock */
 	spinlock_t		lock;
 
+#ifndef CONFIG_DM_USB
 	struct device		*dev;
+#else
+	struct udevice		*dev;
+#endif
 
 	struct platform_device	*xhci;
 	struct resource		xhci_resources[DWC3_XHCI_RESOURCES_NUM];
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index f18884f13392..10b93eed5793 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -28,6 +28,11 @@ 
 
 #include "linux-compat.h"
 
+#include <libfdt.h>
+#include <dm/device.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
 /*
  * All these registers belong to OMAP's Wrapper around the
  * DesignWare USB3 Core.
@@ -135,6 +140,8 @@  struct dwc3_omap {
 	u32			index;
 };
 
+#ifndef CONFIG_DM_USB
+
 static LIST_HEAD(dwc3_omap_list);
 
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
@@ -462,3 +469,48 @@  MODULE_ALIAS("platform:omap-dwc3");
 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("DesignWare USB3 OMAP Glue Layer");
+
+#else
+
+static int ti_dwc3_wrapper_bind(struct udevice *parent)
+{
+	const void *fdt = gd->fdt_blob;
+	int node;
+
+	for (node = fdt_first_subnode(fdt, parent->of_offset); node > 0;
+	     node = fdt_next_subnode(fdt, node)) {
+		const char *name = fdt_get_name(fdt, node, NULL);
+		enum usb_dr_mode dr_mode;
+
+		if (strncmp(name, "usb@", 4))
+			continue;
+
+		dr_mode = usb_get_dr_mode(node);
+		switch (dr_mode) {
+		case USB_DR_MODE_PERIPHERAL:
+		case USB_DR_MODE_OTG:
+			/* Bind MUSB device */
+			break;
+		case USB_DR_MODE_HOST:
+			/* Bind MUSB host */
+			break;
+		default:
+			break;
+		};
+	}
+	return 0;
+}
+
+static const struct udevice_id ti_dwc3_ids[] = {
+	{ .compatible = "ti,am437x-dwc3" },
+	{ }
+};
+
+U_BOOT_DRIVER(ti_dwc3_wrapper) = {
+	.name	= "ti-dwc3-wrapper",
+	.id	= UCLASS_MISC,
+	.of_match = ti_dwc3_ids,
+	.bind = ti_dwc3_wrapper_bind,
+};
+
+#endif /* CONFIG_DM_USB */
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index e065c5aeb38d..18bbd5318e48 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2610,7 +2610,7 @@  int dwc3_gadget_init(struct dwc3 *dwc)
 	if (ret)
 		goto err4;
 
-	ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
+	ret = usb_add_gadget_udc((struct device *)dwc->dev, &dwc->gadget);
 	if (ret) {
 		dev_err(dwc->dev, "failed to register udc\n");
 		goto err4;