[U-Boot] [PATCH v1 1/4] usb: host: ehci-vf: Migrate Vybrid USB to driver model

Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
Regards, Sanchayan. --- drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{ + int ret; + + /* Do board specific initialisation */ + ret = board_ehci_hcd_init(index); + if (ret) + return ret; + + usb_power_config(index); + usb_oc_config(index); + usb_internal_phy_clock_gate(index); + usb_phy_enable(index, ehci); + + return 0; +} + +#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */ - board_ehci_hcd_init(index); - - usb_power_config(index); - usb_oc_config(index); - usb_internal_phy_clock_gate(index); - usb_phy_enable(index, ehci); + ret = ehci_vf_common_init(index); + if (ret) + return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr + @@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data { + struct ehci_ctrl ctrl; + struct usb_ehci *ehci; + enum usb_init_type init_type; + int portnr; +}; + +static int vf_init_after_reset(struct ehci_ctrl *dev) +{ + struct ehci_vf_priv_data *priv = dev->priv; + enum usb_init_type type = priv->init_type; + struct usb_ehci *ehci = priv->ehci; + int ret; + + ret = ehci_vf_common_init(priv->ehci, priv->portnr); + if (ret) + return ret; + + if (type == USB_INIT_DEVICE) + return 0; + + setbits_le32(&ehci->usbmode, CM_HOST); + writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc); + setbits_le32(&ehci->portsc, USB_EN); + + mdelay(10); + + return 0; +} + +static const struct ehci_ops vf_ehci_ops = { + .init_after_reset = vf_init_after_reset +}; + +static int ehci_usb_probe(struct udevice *dev) +{ + struct usb_platdata *plat = dev_get_platdata(dev); + struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev); + struct ehci_vf_priv_data *priv = dev_get_priv(dev); + struct ehci_hccr *hccr; + struct ehci_hcor *hcor; + int ret; + + priv->ehci = ehci; + priv->portnr = dev->seq; + priv->init_type = plat->init_type; + + ret = ehci_vf_common_init(ehci, priv->portnr); + if (ret) + return ret; + + if (priv->init_type == USB_INIT_HOST) { + setbits_le32(&ehci->usbmode, CM_HOST); + writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc); + setbits_le32(&ehci->portsc, USB_EN); + } + + mdelay(10); + + hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); + hcor = (struct ehci_hcor *)((uint32_t)hccr + + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); + + return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type); +} + +static int ehci_usb_remove(struct udevice *dev) +{ + int ret; + + ret = ehci_deregister(dev); + if (ret) + return ret; + + return 0; +} + +static const struct udevice_id vf_usb_ids[] = { + { .compatible = "fsl,vf610-usb" }, + { } +}; + +U_BOOT_DRIVER(usb_ehci) = { + .name = "ehci_vf", + .id = UCLASS_USB, + .of_match = vf_usb_ids, + .probe = ehci_usb_probe, + .remove = ehci_usb_remove, + .ops = &ehci_usb_ops, + .platdata_auto_alloc_size = sizeof(struct usb_platdata), + .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +}; +#endif

Add device tree node for USB peripheral on Vybrid.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- arch/arm/dts/vf.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/arch/arm/dts/vf.dtsi b/arch/arm/dts/vf.dtsi index 1530d2f..951d321 100644 --- a/arch/arm/dts/vf.dtsi +++ b/arch/arm/dts/vf.dtsi @@ -20,6 +20,8 @@ serial5 = &uart5; spi0 = &dspi0; spi1 = &dspi1; + ehci0 = &ehci0; + ehci1 = &ehci1; };
soc { @@ -113,6 +115,12 @@ reg = <0x400ff100 0x40>; #gpio-cells = <2>; }; + + ehci0: ehci0@40034000 { + compatible = "fsl,vf610-usb"; + reg = <0x40034000 0x800>; + status = "disabled"; + }; };
aips1: aips-bus@40080000 { @@ -133,6 +141,11 @@ status = "disabled"; };
+ ehci1: ehci1@400b4000 { + compatible = "fsl,vf610-usb"; + reg = <0x400b4000 0x800>; + status = "disabled"; + }; }; }; };

Enable USB device tree node for Toradex Colibri Vybrid module.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- arch/arm/dts/vf-colibri.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/arch/arm/dts/vf-colibri.dtsi b/arch/arm/dts/vf-colibri.dtsi index dc52748..e7d4c01 100644 --- a/arch/arm/dts/vf-colibri.dtsi +++ b/arch/arm/dts/vf-colibri.dtsi @@ -21,6 +21,16 @@ }; };
+&ehci0 { + dr_mode = "peripheral"; + status = "okay"; +}; + +&ehci1 { + dr_mode = "host"; + status = "okay"; +}; + &uart0 { status = "okay"; };

Enable USB driver model for Toradex Colibri Vybrid modules.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com --- configs/colibri_vf_defconfig | 1 + 1 file changed, 1 insertion(+)
diff --git a/configs/colibri_vf_defconfig b/configs/colibri_vf_defconfig index 986cec4..5017c7d 100644 --- a/configs/colibri_vf_defconfig +++ b/configs/colibri_vf_defconfig @@ -33,6 +33,7 @@ CONFIG_SYS_NAND_VF610_NFC_60_ECC_BYTES=y CONFIG_FSL_LPUART=y CONFIG_FSL_DSPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_GADGET=y CONFIG_CI_UDC=y CONFIG_USB_GADGET_DOWNLOAD=y

On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type);
+}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct usb_platdata),
- .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif

Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0 - -1 -1 - -1 -1 - not found g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 -1 - -1 -1 - not found USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 0 - found uclass_find_device_by_seq: 0 1 - -1 0 - -1 1 - found uclass_find_device_by_seq: 0 2 - -1 0 - -1 1 - -1 -1 - not found uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 0 - found uclass_find_device_by_seq: 0 1 - -1 0 - -1 -1 - not found USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 -1 - not found uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 -1 - not found 2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 0 - found uclass_find_device_by_seq: 0 1 - -1 0 - -1 -1 - not found uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0 - -1 0 - found uclass_find_device_by_seq: 0 1 - -1 0 - -1 1 - found uclass_find_device_by_seq: 0 2 - -1 0 - -1 1 - -1 -1 - not found 2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type);
+}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct usb_platdata),
- .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut

On 2016-08-07 23:15, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19
Hm, I guess this comes from usb_setup_ehci_gadget called through usb_gadget_register_driver. The call in there seems rather hardcoded:
ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); (seq = 0, and find_req_seq=true, maybe find_req_seq=false helps? Maybe it is because we use the second USB DR controller for OTG?)
data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
I guess that comes from cmd/dfu.c not handling the error code of g_dnl_register...
-- Stefan
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type);
+}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct usb_platdata),
- .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hello Stefan,
On 16-08-08 00:25:16, Stefan Agner wrote:
On 2016-08-07 23:15, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19
Hm, I guess this comes from usb_setup_ehci_gadget called through usb_gadget_register_driver. The call in there seems rather hardcoded:
Yes it comes from that function.
ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); (seq = 0, and find_req_seq=true, maybe find_req_seq=false helps? Maybe it is because we use the second USB DR controller for OTG?)
I have already tried using that value along with what I see during use as USB host.
While eventually the second USB controller is to be used as OTG for us, the point of failure is even before the device_probe call in usb_setup_ehci_gadget. Also before the device probe call the plat-> init_type is set to USB_DEVICE and I have not yet added the type check in usb_probe function akin to the non DM case in ehci_hcd_init which takes care of OTG handling.
Something related to sequence numbers and uclass device. I tried DM_UC_FLAG_SEQ_ALIAS but that seems to be specified for UCLASS USB anyways.
Regards, Sanchayan,
data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
I guess that comes from cmd/dfu.c not handling the error code of g_dnl_register...
-- Stefan
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type);
+}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct usb_platdata),
- .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hello,
Adding Lukasz's second mail ID to cc
On 16-08-08 11:45:35, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
@Lukasz Can you comment?
Regards, Sanchayan.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type);
+}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct usb_platdata),
- .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut

Hello,
On 16-08-08 18:56:21, maitysanchayan@gmail.com wrote:
Hello,
Adding Lukasz's second mail ID to cc
On 16-08-08 11:45:35, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
@Lukasz Can you comment?
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index be114fc..1bcd73f 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -355,7 +355,7 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) int ret;
/* Find the old device and remove it */ - ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); + ret = uclass_find_device_by_seq(UCLASS_USB, 0, false, &dev); if (ret) return ret; ret = device_remove(dev);
Having the above change, the following sequence of commands seems to work?
U-Boot 2016.09-rc1-00329-g4e72f10-dirty (Aug 08 2016 - 19:19:38 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 ERROR: g_dnl_register failed at cmd/dfu.c:59/do_dfu() Colibri VFxx # usb start starting USB... USB0: USB EHCI 1.00 USB1: USB EHCI 1.00 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 1 for devices... 2 USB Device(s) found Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3'
Using the third parameter as false makes it look for probed devices. Since it got probed because of the "usb start" it now works. With the original parameter as "true" it will look for a device that will request the concerned sequence number if probed. However it seems to not work?
Ideally it should have worked with just a command of "dfu 0 nand 4".
Regards, Sanchayan.
Regards, Sanchayan.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index];
/* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
@@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci *)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0, plat->init_type);
+}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct usb_platdata),
- .priv_auto_alloc_size = sizeof(struct ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut

Hi maitysanchayan@gmail.com,
Hello,
On 16-08-08 18:56:21, maitysanchayan@gmail.com wrote:
Hello,
Adding Lukasz's second mail ID to cc
On 16-08-08 11:45:35, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
@Lukasz Can you comment?
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index be114fc..1bcd73f 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -355,7 +355,7 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) int ret;
/* Find the old device and remove it */
ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
ret = uclass_find_device_by_seq(UCLASS_USB, 0, false, &dev); if (ret) return ret; ret = device_remove(dev);
Having the above change, the following sequence of commands seems to work?
U-Boot 2016.09-rc1-00329-g4e72f10-dirty (Aug 08 2016 - 19:19:38 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 ERROR: g_dnl_register failed at cmd/dfu.c:59/do_dfu() Colibri VFxx # usb start starting USB... USB0: USB EHCI 1.00 USB1: USB EHCI 1.00 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 1 for devices... 2 USB Device(s) found Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3'
Using the third parameter as false makes it look for probed devices. Since it got probed because of the "usb start" it now works. With the original parameter as "true" it will look for a device that will request the concerned sequence number if probed. However it seems to not work?
Could you confirm that for your platform DFU is working without CONFIG_DM_USB enabled?
Ideally it should have worked with just a command of "dfu 0 nand 4".
Regards, Sanchayan.
Regards, Sanchayan.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index]; /* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr + @@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW),
&ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci
*)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW),
&ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops,
0, plat->init_type); +}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct
usb_platdata),
- .priv_auto_alloc_size = sizeof(struct
ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut

Hello Lukasz,
On 16-08-09 15:25:50, Lukasz Majewski wrote:
Hi maitysanchayan@gmail.com,
Hello,
On 16-08-08 18:56:21, maitysanchayan@gmail.com wrote:
Hello,
Adding Lukasz's second mail ID to cc
On 16-08-08 11:45:35, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model. Does this imply I cannot use any usb gadget functionality if I am using USB DM? However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
@Lukasz Can you comment?
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index be114fc..1bcd73f 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -355,7 +355,7 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) int ret;
/* Find the old device and remove it */
ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
ret = uclass_find_device_by_seq(UCLASS_USB, 0, false, &dev); if (ret) return ret; ret = device_remove(dev);
Having the above change, the following sequence of commands seems to work?
U-Boot 2016.09-rc1-00329-g4e72f10-dirty (Aug 08 2016 - 19:19:38 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 ERROR: g_dnl_register failed at cmd/dfu.c:59/do_dfu() Colibri VFxx # usb start starting USB... USB0: USB EHCI 1.00 USB1: USB EHCI 1.00 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 1 for devices... 2 USB Device(s) found Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3'
Using the third parameter as false makes it look for probed devices. Since it got probed because of the "usb start" it now works. With the original parameter as "true" it will look for a device that will request the concerned sequence number if probed. However it seems to not work?
Could you confirm that for your platform DFU is working without CONFIG_DM_USB enabled?
Yes DFU works without CONFIG_DM_USB enabled.
Regards, Sanchayan.
Ideally it should have worked with just a command of "dfu 0 nand 4".
Regards, Sanchayan.
Regards, Sanchayan.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index]; /* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr + @@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW),
&ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci
*)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW),
&ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops,
0, plat->init_type); +}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct
usb_platdata),
- .priv_auto_alloc_size = sizeof(struct
ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut
-- Best regards,
Lukasz Majewski
Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

Hi maitysanchayan@gmail.com,
Hello,
Adding Lukasz's second mail ID to cc
On 16-08-08 11:45:35, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
Patch for fixing this has been already posted by you. Thanks :-)
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Please do not mix host and device controllers. Those are two disjoint drivers.
What I can see, is that usb_gadget_register_driver() calls usb_setup_ehci_gadget(). when DM is supported.
It then calls uclass_find_device_by_seq(), which tries to find a device (probably ci_udc? ) which is not supported in DM.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model.
Unfortunately, it hasn't been converted to DM yet.
Does this imply I
cannot use any usb gadget functionality if I am using USB DM?
I didn't encounter such problem yet.
However, I think that it would be possible to make some "glue" code to try to connect both host and device controllers (which would be some kind of a hack).
I assume (from log) that you work on calibri-vf board. Is gadget (and CI-UDC) working properly when DM is not enabled?
However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
The only idea which come to my mind is to hack the usb_gadget_register_driver() function to work with (for usb host) and without (for usb gadget) DM. It might require some code copying, though.
@Lukasz Can you comment?
Regards, Sanchayan.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index]; /* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr + @@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci
*)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW),
&ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0,
plat->init_type); +}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct
usb_platdata),
- .priv_auto_alloc_size = sizeof(struct
ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut

Hello Lukasz,
On 16-08-09 15:20:58, Lukasz Majewski wrote:
Hi maitysanchayan@gmail.com,
Hello,
Adding Lukasz's second mail ID to cc
On 16-08-08 11:45:35, maitysanchayan@gmail.com wrote:
Hello,
On 16-08-03 17:13:11, Marek Vasut wrote:
On 08/03/2016 01:58 PM, Sanchayan Maity wrote:
Add driver model support for Vybrid USB driver.
Signed-off-by: Sanchayan Maity maitysanchayan@gmail.com
CCing Lukasz.
Hello,
I am trying to migrate the Vybrid USB driver to driver model. Patches are based on top of uboot master branch. With this implementation, host works perfectly fine on both USB ports but I have problems using it in client mode.
I tried DFU to test client mode and I get the following
Colibri VFxx # version
U-Boot 2016.09-rc1-00235-g4e8c122 (Aug 03 2016 - 17:07:48 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 data abort pc : [<8ff80f18>] lr : [<8ff612a9>] reloc pc : [<3f431f18>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb50cc r9 : 8fd16ee8 r8 : 8ffbc574 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
Patch for fixing this has been already posted by you. Thanks :-)
Happy to contribute :)
FWIW here is output with DEBUG enabled in uclass.c
when testing with DFU:
uclass_find_device_by_seq: 1 0
- -1 -1
- -1 -1
- not found
g_dnl_register: failed!, error: -19 data abort pc : [<8ff80fb0>] lr : [<8ff612a9>] reloc pc : [<3f431fb0>] lr : [<3f4122a9>] sp : 8fd15000 ip : 00000000 fp : 00002710 r10: 8ffb5274 r9 : 8fd16ee8 r8 : 8ffbc714 r7 : 00000000 r6 : 00000000 r5 : 00000000 r4 : 00000000 r3 : 0000f4b9 r2 : 80000000 r1 : 00000001 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
resetting ...
When testing host mode with usb start
Colibri VFxx # usb start starting USB... USB0: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- -1 -1
- not found
USB EHCI 1.00 USB1: uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
USB EHCI 1.00 scanning bus 0 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 -1
- not found
2 USB Device(s) found scanning bus 1 for devices... uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 -1
- not found
uclass_find_device_by_seq: 0 -1 uclass_find_device_by_seq: 0 0
- -1 0
- found
uclass_find_device_by_seq: 0 1
- -1 0
- -1 1
- found
uclass_find_device_by_seq: 0 2
- -1 0
- -1 1
- -1 -1
- not found
2 USB Device(s) found
Regards, Sanchayan.
It seems to return ENODEV from usb_setup_ehci_gadget after calling uclass_find_device_by_seq. I am not sure what I am missing in the current implementation. Can someone point me in the correct direction? Since host works on both ports I would assume the device tree nodes are correct.
Please do not mix host and device controllers. Those are two disjoint drivers.
True. The idea is to have OTG functionality or at least client functionality like DFU or UMS working when dr_mode is specified as otg or peripheral from device tree.
What I can see, is that usb_gadget_register_driver() calls usb_setup_ehci_gadget(). when DM is supported.
Yes.
It then calls uclass_find_device_by_seq(), which tries to find a device (probably ci_udc? ) which is not supported in DM.
Yes ci_udc would be the driver in question. Hmmm if it is not supported I wonder why have the CONFIG_DM_USB option in there.
As I mentioned in one of my other replies
diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index be114fc..1bcd73f 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -355,7 +355,7 @@ int usb_setup_ehci_gadget(struct ehci_ctrl **ctlrp) int ret;
/* Find the old device and remove it */ - ret = uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev); + ret = uclass_find_device_by_seq(UCLASS_USB, 0, false, &dev); if (ret) return ret; ret = device_remove(dev);
Having the above change, the following sequence of commands seems to work?
U-Boot 2016.09-rc1-00329-g4e72f10-dirty (Aug 08 2016 - 19:19:38 +0530) arm-linux-gnueabihf-gcc (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005 GNU ld (GNU Binutils) 2.25.0 Linaro 2015_10 Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3' g_dnl_register: failed!, error: -19 ERROR: g_dnl_register failed at cmd/dfu.c:59/do_dfu() Colibri VFxx # usb start starting USB... USB0: USB EHCI 1.00 USB1: USB EHCI 1.00 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 1 for devices... 2 USB Device(s) found Colibri VFxx # dfu 0 nand 4 using id 'nand0,0' using id 'nand0,1' using id 'nand0,3'
Using the third parameter as false makes it look for probed devices. Since it got probed because of the "usb start" it now works. With the original parameter as "true" it will look for a device that will request the concerned sequence number if probed. However it seems to not work?
Ideally it should have worked with just a command of "dfu 0 nand 4".
So the question becomes why
uclass_find_device_by_seq(UCLASS_USB, 0, true, &dev);
does not find the device in question. If I understand correctly the above should have looked for a UCLASS_USB device which would have the sequence number 0 if probed. And this is implemented in usb-uclass.c.
Tried to look in documentation and usb-info.txt mentions that gadget framework does not use driver model.
Unfortunately, it hasn't been converted to DM yet.
Ok.
Does this imply I
cannot use any usb gadget functionality if I am using USB DM?
I didn't encounter such problem yet.
Hmm if gadget framework has not been converted to driver model does it not imply that I cannot use DFU or UMS with DM enabled? Sorry I did not understand this clearly.
However, I think that it would be possible to make some "glue" code to try to connect both host and device controllers (which would be some kind of a hack).
I assume (from log) that you work on calibri-vf board. Is gadget (and CI-UDC) working properly when DM is not enabled?
Yes I work primarily on Vybrid and in this case our own Toradex Colibri Vybrid module. DFU and UMS work properly without DM.
However the function usb_gadget_register_driver in ci_udc.c does have a CONFIG_DM_USB and calls into usb_setup_ehci_gadget which is in usb-uclass.c.
The only idea which come to my mind is to hack the usb_gadget_register_driver() function to work with (for usb host) and without (for usb gadget) DM. It might require some code copying, though.
See my above hack which kinda works for me at the moment.
Regards, Sanchayan.
@Lukasz Can you comment?
Regards, Sanchayan.
Regards, Sanchayan.
drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/ehci-vf.c b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644 --- a/drivers/usb/host/ehci-vf.c +++ b/drivers/usb/host/ehci-vf.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <dm.h> #include <usb.h> #include <errno.h> #include <linux/compiler.h> @@ -131,6 +132,24 @@ int __weak board_ehci_hcd_init(int port) return 0; }
+int ehci_vf_common_init(struct usb_ehci *ehci, int index) +{
- int ret;
- /* Do board specific initialisation */
- ret = board_ehci_hcd_init(index);
- if (ret)
return ret;
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
- return 0;
+}
+#ifndef CONFIG_DM_USB int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr, struct ehci_hcor **hcor) { @@ -143,12 +162,9 @@ int ehci_hcd_init(int index, enum usb_init_type init, ehci = (struct usb_ehci *)nc_reg_bases[index]; /* Do board specific initialisation */
- board_ehci_hcd_init(index);
- usb_power_config(index);
- usb_oc_config(index);
- usb_internal_phy_clock_gate(index);
- usb_phy_enable(index, ehci);
ret = ehci_vf_common_init(index);
if (ret)
return ret;
*hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength); *hcor = (struct ehci_hcor *)((uint32_t)*hccr + @@ -175,3 +191,98 @@ int ehci_hcd_stop(int index) { return 0; } +#else +struct ehci_vf_priv_data {
- struct ehci_ctrl ctrl;
- struct usb_ehci *ehci;
- enum usb_init_type init_type;
- int portnr;
+};
+static int vf_init_after_reset(struct ehci_ctrl *dev) +{
- struct ehci_vf_priv_data *priv = dev->priv;
- enum usb_init_type type = priv->init_type;
- struct usb_ehci *ehci = priv->ehci;
- int ret;
- ret = ehci_vf_common_init(priv->ehci, priv->portnr);
- if (ret)
return ret;
- if (type == USB_INIT_DEVICE)
return 0;
- setbits_le32(&ehci->usbmode, CM_HOST);
- writel((PORT_PTS_UTMI | PORT_PTS_PTW), &ehci->portsc);
- setbits_le32(&ehci->portsc, USB_EN);
- mdelay(10);
- return 0;
+}
+static const struct ehci_ops vf_ehci_ops = {
- .init_after_reset = vf_init_after_reset
+};
+static int ehci_usb_probe(struct udevice *dev) +{
- struct usb_platdata *plat = dev_get_platdata(dev);
- struct usb_ehci *ehci = (struct usb_ehci
*)dev_get_addr(dev);
- struct ehci_vf_priv_data *priv = dev_get_priv(dev);
- struct ehci_hccr *hccr;
- struct ehci_hcor *hcor;
- int ret;
- priv->ehci = ehci;
- priv->portnr = dev->seq;
- priv->init_type = plat->init_type;
- ret = ehci_vf_common_init(ehci, priv->portnr);
- if (ret)
return ret;
- if (priv->init_type == USB_INIT_HOST) {
setbits_le32(&ehci->usbmode, CM_HOST);
writel((PORT_PTS_UTMI | PORT_PTS_PTW),
&ehci->portsc);
setbits_le32(&ehci->portsc, USB_EN);
- }
- mdelay(10);
- hccr = (struct ehci_hccr
*)((uint32_t)&ehci->caplength);
- hcor = (struct ehci_hcor *)((uint32_t)hccr +
HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +
- return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0,
plat->init_type); +}
+static int ehci_usb_remove(struct udevice *dev) +{
- int ret;
- ret = ehci_deregister(dev);
- if (ret)
return ret;
- return 0;
+}
+static const struct udevice_id vf_usb_ids[] = {
- { .compatible = "fsl,vf610-usb" },
- { }
+};
+U_BOOT_DRIVER(usb_ehci) = {
- .name = "ehci_vf",
- .id = UCLASS_USB,
- .of_match = vf_usb_ids,
- .probe = ehci_usb_probe,
- .remove = ehci_usb_remove,
- .ops = &ehci_usb_ops,
- .platdata_auto_alloc_size = sizeof(struct
usb_platdata),
- .priv_auto_alloc_size = sizeof(struct
ehci_vf_priv_data),
- .flags = DM_FLAG_ALLOC_PRIV_DMA,
+}; +#endif
-- Best regards, Marek Vasut
-- Best regards,
Lukasz Majewski
Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
participants (5)
-
Lukasz Majewski
-
maitysanchayan@gmail.com
-
Marek Vasut
-
Sanchayan Maity
-
Stefan Agner