Skip to contentSkip to conversation

usb: ehci-mx6: Create MISC USB device wrapper

RFC In review Adam Ford 2 participants 3 messages Apr 3, 2019 – Aug 13, 2019

Subsystems (2)
lore
Share & tools
lore

Adam Ford

author
#0 lore raw

RFC 1/1 usb: ehci-mx6: Create MISC USB device wrapper

In preparation to support DM_USB_GADGET, this creates a misc device which binds the host. This is necessary because U_BOOT_DRIVER(usb_mx6) is currently hard coded to UCLASS_USB and if we want to support UCLASS_USB_GADGET_GENERIC we'll need to bind a separate device in the future.

drivers/usb/host/Kconfig +1 -0
index ba1e6bfa43..25c7e2d6a1 100644
@@ -134,6 +134,7 @@ config USB_EHCI_MARVELL
 
 config USB_EHCI_MX6
 	bool "Support for i.MX6 on-chip EHCI USB controller"
+	select MISC
 	depends on ARCH_MX6
 	default y
 	---help---
drivers/usb/host/ehci-mx6.c +27 -1
index 16abeef3b2..4003b8616f 100644
@@ -19,6 +19,7 @@
 #include <asm/mach-types.h>
 #include <power/regulator.h>
 #include <linux/usb/otg.h>
+#include <dm/lists.h>
 
 #include "ehci.h"
 
@@ -567,7 +568,6 @@ static const struct udevice_id mx6_usb_ids[] = {
 U_BOOT_DRIVER(usb_mx6) = {
 	.name	= "ehci_mx6",
 	.id	= UCLASS_USB,
-	.of_match = mx6_usb_ids,
 	.ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
 	.probe	= ehci_usb_probe,
 	.remove = ehci_deregister,
@@ -576,4 +576,30 @@ U_BOOT_DRIVER(usb_mx6) = {
 	.priv_auto_alloc_size = sizeof(struct ehci_mx6_priv_data),
 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static int mx6_usb_wrapper_bind(struct udevice *dev)
+{
+	const void *fdt = gd->fdt_blob;
+	int node = dev_of_offset(dev);
+	const char *name = fdt_get_name(fdt, node, NULL);
+	int ret;
+
+	ret = device_bind_driver_to_node(dev,
+					"ehci_mx6",
+					name,
+					offset_to_ofnode(node),
+					&dev);
+	if (ret)
+		pr_err("mx6_usb - Unable to bind USB host node\n");
+
+	return ret;
+}
+
+U_BOOT_DRIVER(usb_mx6_wrapper) = {
+	.name	= "mx6-usb-wrapper",
+	.id	= UCLASS_MISC,
+	.of_match = mx6_usb_ids,
+	.bind = mx6_usb_wrapper_bind,
+};
+
 #endif
Signature · 1 line
2.17.1
author
#1 lore raw
Quoted 43 lines · Adam Ford

In preparation to support DM_USB_GADGET, this creates a misc device which binds the host. This is necessary because U_BOOT_DRIVER(usb_mx6) is currently hard coded to UCLASS_USB and if we want to support UCLASS_USB_GADGET_GENERIC we'll need to bind a separate device in the future.

drivers/usb/host/Kconfig +1 -0
index ba1e6bfa43..25c7e2d6a1 100644
@@ -134,6 +134,7 @@ config USB_EHCI_MARVELL
 
 config USB_EHCI_MX6
        bool "Support for i.MX6 on-chip EHCI USB controller"
+       select MISC
        depends on ARCH_MX6
        default y
        ---help---
drivers/usb/host/ehci-mx6.c +1 -1
index 16abeef3b2..4003b8616f 100644
@@ -19,6 +19,7 @@
 #include <asm/mach-types.h>
 #include <power/regulator.h>
 #include <linux/usb/otg.h>
+#include <dm/lists.h>
 
 #include "ehci.h"
 
@@ -567,7 +568,6 @@ static const struct udevice_id mx6_usb_ids[] = {
 U_BOOT_DRIVER(usb_mx6) = {
        .name   = "ehci_mx6",
        .id     = UCLASS_USB,
-       .of_match = mx6_usb_ids,
        .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
        .probe  = ehci_usb_probe,
        .remove = ehci_deregister,
@@ -576,4 +576,30 @@ U_BOOT_DRIVER(usb_mx6) = {
        .priv_auto_alloc_size = sizeof(struct ehci_mx6_priv_data),

drivers/usb/host/ehci-mx6.c U_BOOT_DRIVER(usb_mx6) = { · line 586

Quoted 10 lines
drivers/usb/host/ehci-mx6.c +8 -0
        .flags  = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static int mx6_usb_wrapper_bind(struct udevice *dev)
+{
+       const void *fdt = gd->fdt_blob;
+       int node = dev_of_offset(dev);
+       const char *name = fdt_get_name(fdt, node, NULL);
+       int ret;
+

For clarification, this patch, this patch should behave just like it has been in the past. The idea we'd check the dr_mode and/or ID pin inside mx6_usb_wrapper_bind. Instead of binding the ehci_mx6 with UCLASS_USB all the time, we'd bind something with the UCLASS_USB_GADGET_GENERIC based on dr_mode and/or ID pin status. Before I go down a rabit hole, I thought I'd send out the RFC to see what people's thoughts are. If someone else has this driver already updated to support DM_USB_GADGET or is working on it, I'll back off.

Quoted 22 lines
drivers/usb/host/ehci-mx6.c +18 -1
+       ret = device_bind_driver_to_node(dev,
+                                       "ehci_mx6",
+                                       name,
+                                       offset_to_ofnode(node),
+                                       &dev);
+       if (ret)
+               pr_err("mx6_usb - Unable to bind USB host node\n");
+
+       return ret;
+}
+
+U_BOOT_DRIVER(usb_mx6_wrapper) = {
+       .name   = "mx6-usb-wrapper",
+       .id     = UCLASS_MISC,
+       .of_match = mx6_usb_ids,
+       .bind = mx6_usb_wrapper_bind,
+};
+
 #endif
--

2.17.1

#2 lore raw

Hi Adam,

Quoted 55 lines · Adam Ford
Quoted 43 lines · Adam Ford

In preparation to support DM_USB_GADGET, this creates a misc device which binds the host. This is necessary because U_BOOT_DRIVER(usb_mx6) is currently hard coded to UCLASS_USB and if we want to support UCLASS_USB_GADGET_GENERIC we'll need to bind a separate device in the future.

drivers/usb/host/Kconfig +1 -0
index ba1e6bfa43..25c7e2d6a1 100644
@@ -134,6 +134,7 @@ config USB_EHCI_MARVELL
 
 config USB_EHCI_MX6
        bool "Support for i.MX6 on-chip EHCI USB controller"
+       select MISC
        depends on ARCH_MX6
        default y
        ---help---
drivers/usb/host/ehci-mx6.c +1 -1
index 16abeef3b2..4003b8616f 100644
@@ -19,6 +19,7 @@
 #include <asm/mach-types.h>
 #include <power/regulator.h>
 #include <linux/usb/otg.h>
+#include <dm/lists.h>
 
 #include "ehci.h"
 
@@ -567,7 +568,6 @@ static const struct udevice_id mx6_usb_ids[] = {
 U_BOOT_DRIVER(usb_mx6) = {
        .name   = "ehci_mx6",
        .id     = UCLASS_USB,
-       .of_match = mx6_usb_ids,
        .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
        .probe  = ehci_usb_probe,
        .remove = ehci_deregister,
@@ -576,4 +576,30 @@ U_BOOT_DRIVER(usb_mx6) = {
        .priv_auto_alloc_size = sizeof(struct ehci_mx6_priv_data),

drivers/usb/host/ehci-mx6.c U_BOOT_DRIVER(usb_mx6) = { · line 586

Quoted 10 lines
drivers/usb/host/ehci-mx6.c +8 -0
        .flags  = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static int mx6_usb_wrapper_bind(struct udevice *dev)
+{
+       const void *fdt = gd->fdt_blob;
+       int node = dev_of_offset(dev);
+       const char *name = fdt_get_name(fdt, node, NULL);
+       int ret;
+
Quoted 8 lines

For clarification, this patch, this patch should behave just like it has been in the past. The idea we'd check the dr_mode and/or ID pin inside mx6_usb_wrapper_bind. Instead of binding the ehci_mx6 with UCLASS_USB all the time, we'd bind something with the UCLASS_USB_GADGET_GENERIC based on dr_mode and/or ID pin status. Before I go down a rabit hole, I thought I'd send out the RFC to see what people's thoughts are. If someone else has this driver already updated to support DM_USB_GADGET or is working on it, I'll back off.

It looks reasonable to me, but Marek is the USB expert.

Quoted 15 lines
Quoted 15 lines
drivers/usb/host/ehci-mx6.c +14 -0
+       ret = device_bind_driver_to_node(dev,
+                                       "ehci_mx6",
+                                       name,
+                                       offset_to_ofnode(node),
+                                       &dev);
+       if (ret)
+               pr_err("mx6_usb - Unable to bind USB host node\n");
+
+       return ret;
+}
+
+U_BOOT_DRIVER(usb_mx6_wrapper) = {
+       .name   = "mx6-usb-wrapper",
+       .id     = UCLASS_MISC,
Quoted 8 lines
Quoted 8 lines
drivers/usb/host/ehci-mx6.c +4 -1
+       .of_match = mx6_usb_ids,
+       .bind = mx6_usb_wrapper_bind,
+};
+
 #endif
--

2.17.1

Regards,
SImon