Skip to contentSkip to conversation

usb: host: ehci-vf: Migrate Vybrid USB to driver model

PATCH Superseded Sanchayan Maity 4 participants 14 messages Aug 3, 2016 – Aug 9, 2016

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Add driver model support for Vybrid USB driver.

---
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(-)
drivers/usb/host/ehci-vf.c +117 -6
index 61789dd..8c5c593 100644
@@ -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
Signature · 1 line
2.9.2
#1 lore raw

PATCH 2/4 ARM: dts: vf: Add device tree node for USB on Vybrid

Add device tree node for USB peripheral on Vybrid.

---
 arch/arm/dts/vf.dtsi | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/arm/dts/vf.dtsi +13 -0
index 1530d2f..951d321 100644
@@ -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 at 40034000 {
+				compatible = "fsl,vf610-usb";
+				reg = <0x40034000 0x800>;
+				status = "disabled";
+			};
 		};
 
 		aips1: aips-bus at 40080000 {
@@ -133,6 +141,11 @@
 				status = "disabled";
 			};
 
+			ehci1: ehci1 at 400b4000 {
+				compatible = "fsl,vf610-usb";
+				reg = <0x400b4000 0x800>;
+				status = "disabled";
+			};
 		};
 	};
 };
Signature · 1 line
2.9.2
#2 lore raw

PATCH 3/4 ARM: dts: vf-colibri: Enable USB device tree node for Colibri Vybrid

In reply to Sanchayan Maity

Enable USB device tree node for Toradex Colibri Vybrid module.

---
 arch/arm/dts/vf-colibri.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm/dts/vf-colibri.dtsi +10 -0
index dc52748..e7d4c01 100644
@@ -21,6 +21,16 @@
 	};
 };
 
+&ehci0 {
+	dr_mode = "peripheral";
+	status = "okay";
+};
+
+&ehci1 {
+	dr_mode = "host";
+	status = "okay";
+};
+
 &uart0 {
 	status = "okay";
 };
Signature · 1 line
2.9.2
#3 lore raw

PATCH 4/4 configs: colibri_vf_defconfig: Enable USB driver model for Colibri Vybrid

In reply to Sanchayan Maity

Enable USB driver model for Toradex Colibri Vybrid modules.

---
 configs/colibri_vf_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/colibri_vf_defconfig +1 -0
index 986cec4..5017c7d 100644
@@ -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
Signature · 1 line
2.9.2
#4 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

In reply to Sanchayan Maity
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 203 lines

---
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(-)
drivers/usb/host/ehci-vf.c +117 -6
index 61789dd..8c5c593 100644
@@ -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
Signature · 2 lines
Best regards,
Marek Vasut
#5 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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.

Quoted 177 lines
Quoted 172 lines

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(-)
drivers/usb/host/ehci-vf.c +117 -6
index 61789dd..8c5c593 100644
@@ -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
Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Quoted 44 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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

Quoted 7 lines

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?)

Quoted 9 lines

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

Quoted 251 lines

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.

Quoted 169 lines
Quoted 169 lines

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(-)
drivers/usb/host/ehci-vf.c +115 -6
index 61789dd..8c5c593 100644
@@ -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,
Quoted 8 lines

drivers/usb/host/ehci-vf.c int ehci_hcd_stop(int index) · line 288

Quoted 3 lines
drivers/usb/host/ehci-vf.c +2 -0
+};
+#endif

--
Best regards,
Marek Vasut

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#7 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Hello Stefan,

Quoted 47 lines · Stefan Agner
Quoted 46 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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:

Quoted 8 lines
Quoted 5 lines

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.

Quoted 4 lines

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,

Quoted 269 lines
Quoted 11 lines

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

Quoted 251 lines

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.

Quoted 169 lines
Quoted 169 lines

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(-)
drivers/usb/host/ehci-vf.c +115 -6
index 61789dd..8c5c593 100644
@@ -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,
Quoted 8 lines

drivers/usb/host/ehci-vf.c int ehci_hcd_stop(int index) · line 288

Quoted 3 lines
drivers/usb/host/ehci-vf.c +2 -0
+};
+#endif

--
Best regards,
Marek Vasut

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#8 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

In reply to maitysanchayan at gmail.com

Hello,

Adding Lukasz's second mail ID to cc

Quoted 127 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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

Quoted 15 lines

Regards,
Sanchayan.

Quoted 12 lines
Quoted 12 lines

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.

Quoted 165 lines
Quoted 165 lines
Quoted 160 lines

Regards,
Sanchayan.

---
 drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 117 insertions(+), 6 deletions(-)
drivers/usb/host/ehci-vf.c +117 -6
index 61789dd..8c5c593 100644
@@ -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
Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Hello,

Quoted 142 lines · maitysanchayan at gmail.com

Hello,

Adding Lukasz's second mail ID to cc

Quoted 137 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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.

Quoted 7 lines
Quoted 7 lines

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.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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?

drivers/usb/host/usb-uclass.c +1 -1
index be114fc..1bcd73f 100644
@@ -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.

Quoted 169 lines

Regards,
Sanchayan.

Quoted 165 lines
Quoted 165 lines
Quoted 160 lines

Regards,
Sanchayan.

---
 drivers/usb/host/ehci-vf.c | 123 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 117 insertions(+), 6 deletions(-)
drivers/usb/host/ehci-vf.c +117 -6
index 61789dd..8c5c593 100644
@@ -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
Signature · 2 lines
Best regards,
Marek Vasut
#10 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Hi maitysanchayan at gmail.com,

Quoted 193 lines

Hello,

Quoted 151 lines · maitysanchayan at gmail.com

Hello,

Adding Lukasz's second mail ID to cc

Quoted 127 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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

Quoted 16 lines

Regards,
Sanchayan.

Quoted 13 lines
Quoted 13 lines

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?

(quoted diff) +0 -0

b/drivers/usb/host/usb-uclass.c index be114fc..1bcd73f 100644

drivers/usb/host/usb-uclass.c +1 -1
@@ -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'

Quoted 5 lines

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?

Quoted 183 lines

Ideally it should have worked with just a command of "dfu 0 nand 4".

Regards,
Sanchayan.

Quoted 176 lines

Regards,
Sanchayan.

Quoted 172 lines
Quoted 172 lines
Quoted 167 lines

Regards,
Sanchayan.

---
 drivers/usb/host/ehci-vf.c | 123

++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)

(quoted diff) +0 -0

b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644

drivers/usb/host/ehci-vf.c +19 -0
@@ -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];

drivers/usb/host/ehci-vf.c +3 -6
 	/* 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) {

drivers/usb/host/ehci-vf.c +24 -0
 	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);

drivers/usb/host/ehci-vf.c +15 -0
+	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);

drivers/usb/host/ehci-vf.c +16 -0
+	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);

drivers/usb/host/ehci-vf.c +6 -0
+		setbits_le32(&ehci->portsc, USB_EN);
+	}
+
+	mdelay(10);
+
+	hccr = (struct ehci_hccr

*)((uint32_t)&ehci->caplength);

drivers/usb/host/ehci-vf.c +2 -0
+	hcor = (struct ehci_hcor *)((uint32_t)hccr +
+

HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +

drivers/usb/host/ehci-vf.c +1 -0
+	return ehci_register(dev, hccr, hcor, &vf_ehci_ops,

0, plat->init_type); +}

drivers/usb/host/ehci-vf.c +25 -0
+
+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),

drivers/usb/host/ehci-vf.c +1 -0
+	.priv_auto_alloc_size = sizeof(struct

ehci_vf_priv_data),

drivers/usb/host/ehci-vf.c +3 -0
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif
Signature · 2 lines
Best regards,
Marek Vasut
Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#11 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Hello Lukasz,

Quoted 195 lines · Lukasz Majewski

Hi maitysanchayan at gmail.com,

Quoted 193 lines

Hello,

Quoted 151 lines · maitysanchayan at gmail.com

Hello,

Adding Lukasz's second mail ID to cc

Quoted 127 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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

Quoted 16 lines

Regards,
Sanchayan.

Quoted 13 lines
Quoted 13 lines

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?

(quoted diff) +0 -0

b/drivers/usb/host/usb-uclass.c index be114fc..1bcd73f 100644

drivers/usb/host/usb-uclass.c +1 -1
@@ -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'

Quoted 8 lines
Quoted 5 lines

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.

Quoted 193 lines
Quoted 184 lines

Ideally it should have worked with just a command of "dfu 0 nand 4".

Regards,
Sanchayan.

Quoted 176 lines

Regards,
Sanchayan.

Quoted 172 lines
Quoted 172 lines
Quoted 167 lines

Regards,
Sanchayan.

---
 drivers/usb/host/ehci-vf.c | 123

++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)

(quoted diff) +0 -0

b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644

drivers/usb/host/ehci-vf.c +19 -0
@@ -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];

drivers/usb/host/ehci-vf.c +3 -6
 	/* 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) {

drivers/usb/host/ehci-vf.c +24 -0
 	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);

drivers/usb/host/ehci-vf.c +15 -0
+	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);

drivers/usb/host/ehci-vf.c +16 -0
+	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);

drivers/usb/host/ehci-vf.c +6 -0
+		setbits_le32(&ehci->portsc, USB_EN);
+	}
+
+	mdelay(10);
+
+	hccr = (struct ehci_hccr

*)((uint32_t)&ehci->caplength);

drivers/usb/host/ehci-vf.c +2 -0
+	hcor = (struct ehci_hcor *)((uint32_t)hccr +
+

HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +

drivers/usb/host/ehci-vf.c +1 -0
+	return ehci_register(dev, hccr, hcor, &vf_ehci_ops,

0, plat->init_type); +}

drivers/usb/host/ehci-vf.c +25 -0
+
+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),

drivers/usb/host/ehci-vf.c +1 -0
+	.priv_auto_alloc_size = sizeof(struct

ehci_vf_priv_data),

drivers/usb/host/ehci-vf.c +3 -0
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif
Signature · 2 lines
Best regards,
Marek Vasut
Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#12 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

In reply to maitysanchayan at gmail.com

Hi maitysanchayan at gmail.com,

Quoted 46 lines

Hello,

Adding Lukasz's second mail ID to cc

Quoted 41 lines · maitysanchayan at gmail.com

Hello,

Quoted 38 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 31 lines

---
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 :-)

Quoted 90 lines
Quoted 90 lines

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.

Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

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.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Does this imply I

Quoted 1 line

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?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

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.

Quoted 179 lines

@Lukasz
Can you comment?

Regards,
Sanchayan.

Quoted 171 lines
Quoted 171 lines
Quoted 166 lines

Regards,
Sanchayan.

---
 drivers/usb/host/ehci-vf.c | 123

++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)

(quoted diff) +0 -0

b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644

drivers/usb/host/ehci-vf.c +19 -0
@@ -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];

drivers/usb/host/ehci-vf.c +3 -6
 	/* 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) {

drivers/usb/host/ehci-vf.c +39 -0
 	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);

drivers/usb/host/ehci-vf.c +16 -0
+	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);

drivers/usb/host/ehci-vf.c +6 -0
+		setbits_le32(&ehci->portsc, USB_EN);
+	}
+
+	mdelay(10);
+
+	hccr = (struct ehci_hccr

*)((uint32_t)&ehci->caplength);

drivers/usb/host/ehci-vf.c +2 -0
+	hcor = (struct ehci_hcor *)((uint32_t)hccr +
+

HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +

drivers/usb/host/ehci-vf.c +1 -0
+	return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0,

plat->init_type); +}

drivers/usb/host/ehci-vf.c +25 -0
+
+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),

drivers/usb/host/ehci-vf.c +1 -0
+	.priv_auto_alloc_size = sizeof(struct

ehci_vf_priv_data),

drivers/usb/host/ehci-vf.c +3 -0
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif
Signature · 2 lines
Best regards,
Marek Vasut
Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group
#13 lore raw

PATCH 1/4 usb: host: ehci-vf: Migrate Vybrid USB to driver model

Hello Lukasz,

Quoted 47 lines · Lukasz Majewski

Hi maitysanchayan at gmail.com,

Quoted 45 lines

Hello,

Adding Lukasz's second mail ID to cc

Quoted 40 lines · maitysanchayan at gmail.com

Hello,

Quoted 37 lines · Marek Vasut
Quoted 3 lines · Sanchayan Maity

Add driver model support for Vybrid USB driver.

CCing Lukasz.

Quoted 30 lines

---
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 ...

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

resetting ...

Patch for fixing this has been already posted by you. Thanks :-)

Happy to contribute :)

Quoted 91 lines
Quoted 91 lines
Quoted 91 lines

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.

Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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.

Quoted 3 lines

What I can see, is that usb_gadget_register_driver() calls usb_setup_ehci_gadget(). when DM is supported.

Yes.

Quoted 3 lines

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

drivers/usb/host/usb-uclass.c +1 -1
index be114fc..1bcd73f 100644
@@ -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.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

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.

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Does this imply I

Quoted 1 line

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.

Quoted 8 lines

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.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

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.

Quoted 189 lines
Quoted 180 lines

@Lukasz
Can you comment?

Regards,
Sanchayan.

Quoted 171 lines
Quoted 171 lines
Quoted 166 lines

Regards,
Sanchayan.

---
 drivers/usb/host/ehci-vf.c | 123

++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-)

(quoted diff) +0 -0

b/drivers/usb/host/ehci-vf.c index 61789dd..8c5c593 100644

drivers/usb/host/ehci-vf.c +19 -0
@@ -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];

drivers/usb/host/ehci-vf.c +3 -6
 	/* 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) {

drivers/usb/host/ehci-vf.c +39 -0
 	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);

drivers/usb/host/ehci-vf.c +16 -0
+	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);

drivers/usb/host/ehci-vf.c +6 -0
+		setbits_le32(&ehci->portsc, USB_EN);
+	}
+
+	mdelay(10);
+
+	hccr = (struct ehci_hccr

*)((uint32_t)&ehci->caplength);

drivers/usb/host/ehci-vf.c +2 -0
+	hcor = (struct ehci_hcor *)((uint32_t)hccr +
+

HC_LENGTH(ehci_readl(&hccr->cr_capbase))); +

drivers/usb/host/ehci-vf.c +1 -0
+	return ehci_register(dev, hccr, hcor, &vf_ehci_ops, 0,

plat->init_type); +}

drivers/usb/host/ehci-vf.c +25 -0
+
+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),

drivers/usb/host/ehci-vf.c +1 -0
+	.priv_auto_alloc_size = sizeof(struct

ehci_vf_priv_data),

drivers/usb/host/ehci-vf.c +3 -0
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
+#endif
Signature · 2 lines
Best regards,
Marek Vasut
Signature · 5 lines
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group