Skip to contentSkip to conversation

add soc setup code for USB DR OTG mode

PATCH In review Li Yang 3 participants 5 messages Feb 5, 2007 – Feb 6, 2007 PowerPC

lore
Share & tools
lore

Li Yang

author
#0 lore raw

PATCH 2/3 add soc setup code for USB DR OTG mode

---
arch/powerpc/sysdev/fsl_soc.c | 76 ++++++++++++++++++++++++++++++----------

1 files changed, 57 insertions(+), 19 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +0 -0
index ad31e56..d9541aa 100644
@@ -440,7 +440,8 @@ static int __init fsl_usb_of_init(void)
{
	struct device_node *np;
	unsigned int i;
-	struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
+	struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
+		*usb_dev_dr_client = NULL;
	int ret;

	for (np = NULL, i = 0;

@@ -506,33 +507,70 @@ static int __init fsl_usb_of_init(void)

		of_irq_to_resource(np, 0, &r[1]);

- usb_dev_dr =
- platform_device_register_simple("fsl-ehci", i, r, 2);
- if (IS_ERR(usb_dev_dr)) {
- ret = PTR_ERR(usb_dev_dr);
- goto err;
- }
-
- usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
- usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
+ prop = get_property(np, "dr_mode", NULL);

- usb_data.operating_mode = FSL_USB2_DR_HOST;
+ if (prop && !strcmp(prop, "host")) {
+ usb_data.operating_mode = FSL_USB2_DR_HOST;
+ usb_dev_dr_host = platform_device_register_simple(
+ "fsl-ehci", i, r, 2);
+ if (IS_ERR(usb_dev_dr_host)) {
+ ret = PTR_ERR(usb_dev_dr_host);
+ goto err;
+ }
+
+ } else if (prop && !strcmp(prop, "peripheral")) {
+ usb_data.operating_mode = FSL_USB2_DR_DEVICE;
+ usb_dev_dr_client = platform_device_register_simple(
+ "fsl-usb2-udc", i, r, 2);
+ if (IS_ERR(usb_dev_dr_client)) {
+ ret = PTR_ERR(usb_dev_dr_client);
+ goto err;
+ }
+ } else if (!prop || (prop && !strcmp(prop, "otg"))) {
+ usb_data.operating_mode = FSL_USB2_DR_OTG;
+ usb_dev_dr_host = platform_device_register_simple(
+ "fsl-ehci", i, r, 2);
+ if (IS_ERR(usb_dev_dr_host)) {
+ ret = PTR_ERR(usb_dev_dr_host);
+ goto err;
+ }
+ usb_dev_dr_client = platform_device_register_simple(
+ "fsl-usb2-udc", i, r, 2);
+ if (IS_ERR(usb_dev_dr_client)) {
+ ret = PTR_ERR(usb_dev_dr_client);
+ goto err;
+ }
+ }

		prop = get_property(np, "phy_type", NULL);
		usb_data.phy_mode = determine_usb_phy(prop);

- ret =
- platform_device_add_data(usb_dev_dr, &usb_data,
- sizeof(struct
- fsl_usb2_platform_data));
- if (ret)
- goto unreg_dr;
+ if (usb_dev_dr_host) {
+ usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
+ usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
+ dev.coherent_dma_mask;
+ if ((ret = platform_device_add_data(usb_dev_dr_host,
+ &usb_data, sizeof(struct
+ fsl_usb2_platform_data))))
+ goto unreg_dr;
+ }
+ if (usb_dev_dr_client) {
+ usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
+ usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
+ dev.coherent_dma_mask;
+ if ((ret = platform_device_add_data(usb_dev_dr_client,
+ &usb_data, sizeof(struct
+ fsl_usb2_platform_data))))
+ goto unreg_dr;
+ }

	}
	return 0;

unreg_dr:
- if (usb_dev_dr)
- platform_device_unregister(usb_dev_dr);
+ if (usb_dev_dr_host)
+ platform_device_unregister(usb_dev_dr_host);
+ if (usb_dev_dr_client)
+ platform_device_unregister(usb_dev_dr_client);
unreg_mph:

	if (usb_dev_mph)
		platform_device_unregister(usb_dev_mph);
#1 lore raw

On Feb 5, 2007, at 3:10 AM, Li Yang wrote:

You have no description about what this patch does and why its needed.

Nack. See comments inline.

Quoted 40 lines

---
arch/powerpc/sysdev/fsl_soc.c | 76 +++++++++++++++++++++++++++++
+----------

1 files changed, 57 insertions(+), 19 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +11 -11
index ad31e56..d9541aa 100644
@@ -440,7 +440,8 @@ static int __init fsl_usb_of_init(void)
 {
 	struct device_node *np;
 	unsigned int i;
-	struct platform_device *usb_dev_mph = NULL, *usb_dev_dr = NULL;
+	struct platform_device *usb_dev_mph = NULL, *usb_dev_dr_host = NULL,
+		*usb_dev_dr_client = NULL;
 	int ret;
 	for (np = NULL, i = 0;
@@ -506,33 +507,70 @@ static int __init fsl_usb_of_init(void)
 		of_irq_to_resource(np, 0, &r[1]);
-		usb_dev_dr =
-		    platform_device_register_simple("fsl-ehci", i, r, 2);
-		if (IS_ERR(usb_dev_dr)) {
-			ret = PTR_ERR(usb_dev_dr);
-			goto err;
-		}
-
-		usb_dev_dr->dev.coherent_dma_mask = 0xffffffffUL;
-		usb_dev_dr->dev.dma_mask = &usb_dev_dr->dev.coherent_dma_mask;
+		prop = get_property(np, "dr_mode", NULL);
-		usb_data.operating_mode = FSL_USB2_DR_HOST;
+		if (prop && !strcmp(prop, "host")) {
+			usb_data.operating_mode = FSL_USB2_DR_HOST;
+			usb_dev_dr_host = platform_device_register_simple(
+					"fsl-ehci", i, r, 2);
+			if (IS_ERR(usb_dev_dr_host)) {
+				ret = PTR_ERR(usb_dev_dr_host);
+				goto err;
+			}

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 526

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +10 -0
+			
+		} else if (prop && !strcmp(prop, "peripheral")) {
+			usb_data.operating_mode = FSL_USB2_DR_DEVICE;
+			usb_dev_dr_client = platform_device_register_simple(
+					"fsl-usb2-udc", i, r, 2);
+			if (IS_ERR(usb_dev_dr_client)) {
+				ret = PTR_ERR(usb_dev_dr_client);
+				goto err;
+			}
+		} else if (!prop || (prop && !strcmp(prop, "otg"))) {

Why do we assume if the prop is not defined we are OTG? This will break existing users and is not acceptable. If the prop doesn't exist we have to assume 'host' support to maintain compatibility.

Quoted 4 lines
arch/powerpc/sysdev/fsl_soc.c +4 -0
+			usb_data.operating_mode = FSL_USB2_DR_OTG;
+			usb_dev_dr_host = platform_device_register_simple(
+					"fsl-ehci", i, r, 2);
+			if (IS_ERR(usb_dev_dr_host)) {

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 540

Quoted 10 lines
arch/powerpc/sysdev/fsl_soc.c +10 -0
+				ret = PTR_ERR(usb_dev_dr_host);
+				goto err;
+			}
+			usb_dev_dr_client = platform_device_register_simple(
+					"fsl-usb2-udc", i, r, 2);
+			if (IS_ERR(usb_dev_dr_client)) {
+				ret = PTR_ERR(usb_dev_dr_client);
+				goto err;
+			}
+		}

shouldn't there be an error case if the string doesn't match any of the above?

Quoted 36 lines
arch/powerpc/sysdev/fsl_soc.c +18 -6
 		prop = get_property(np, "phy_type", NULL);
 		usb_data.phy_mode = determine_usb_phy(prop);
-		ret =
-		    platform_device_add_data(usb_dev_dr, &usb_data,
-					     sizeof(struct
-						    fsl_usb2_platform_data));
-		if (ret)
-			goto unreg_dr;
+		if (usb_dev_dr_host) {
+			usb_dev_dr_host->dev.coherent_dma_mask = 0xffffffffUL;
+			usb_dev_dr_host->dev.dma_mask = &usb_dev_dr_host->
+				dev.coherent_dma_mask;
+			if ((ret = platform_device_add_data(usb_dev_dr_host,
+						&usb_data, sizeof(struct
+						fsl_usb2_platform_data))))
+				goto unreg_dr;
+		}
+		if (usb_dev_dr_client) {
+			usb_dev_dr_client->dev.coherent_dma_mask = 0xffffffffUL;
+			usb_dev_dr_client->dev.dma_mask = &usb_dev_dr_client->
+				dev.coherent_dma_mask;
+			if ((ret = platform_device_add_data(usb_dev_dr_client,
+						&usb_data, sizeof(struct
+						fsl_usb2_platform_data))))
+				goto unreg_dr;
+		}
 	}
 	return 0;

unreg_dr:

arch/powerpc/sysdev/fsl_soc.c +4 -2
-	if (usb_dev_dr)
-		platform_device_unregister(usb_dev_dr);
+	if (usb_dev_dr_host)
+		platform_device_unregister(usb_dev_dr_host);
+	if (usb_dev_dr_client)
+		platform_device_unregister(usb_dev_dr_client);

unreg_mph:

Quoted 2 lines
	if (usb_dev_mph)
		platform_device_unregister(usb_dev_mph);

- k

#2 lore raw
Quoted 4 lines

-----Original Message-----
From: Kumar Gala [mailto:[email protected]]
Sent: Monday, February 05, 2007 11:16 PM
To: Li Yang-r58472

Quoted 8 lines

Cc: Paul; [email protected]
Subject: Re: [PATCH 2/3] add soc setup code for USB DR OTG mode =20
=20
On Feb 5, 2007, at 3:10 AM, Li Yang wrote:
=20
You have no description about what this patch does and why its needed. =20

Add platform_device setup code for OTG/client mode of 834x DR. It is needed for USB client driver to work.

Quoted 8 lines

Nack. See comments inline.
=20

Quoted 6 lines

---
arch/powerpc/sysdev/fsl_soc.c | 76 +++++++++++++++++++++++++++++
+----------

1 files changed, 57 insertions(+), 19 deletions(-)
Quoted 10 lines

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 443

Quoted 10 lines
arch/powerpc/sysdev/ renamed from arch/powerpc/sysdev/fsl_soc.c +0 -0

fsl_soc.c
index ad31e56..d9541aa 100644

arch/powerpc/sysdev/fsl_soc.c +0 -1
@@ -440,7 +440,8 @@ static int __init fsl_usb_of_init(void)
 {
 	struct device_node *np;
 	unsigned int i;
-	struct platform_device *usb_dev_mph =3D NULL, *usb_dev_dr =3D =

NULL;

Quoted 1 line

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 443

Quoted 1 line
arch/powerpc/sysdev/fsl_soc.c +1 -0
+	struct platform_device *usb_dev_mph =3D NULL, *usb_dev_dr_host =3D

NULL,

Quoted 7 lines

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 508

Quoted 7 lines
arch/powerpc/sysdev/fsl_soc.c +1 -2
+		*usb_dev_dr_client =3D NULL;
 	int ret;
 	for (np =3D NULL, i =3D 0;
@@ -506,33 +507,70 @@ static int __init fsl_usb_of_init(void)
 		of_irq_to_resource(np, 0, &r[1]);
-		usb_dev_dr =3D
-		    platform_device_register_simple("fsl-ehci", i, r,

2);

Quoted 7 lines

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 515

Quoted 7 lines
arch/powerpc/sysdev/fsl_soc.c +0 -7
-		if (IS_ERR(usb_dev_dr)) {
-			ret =3D PTR_ERR(usb_dev_dr);
-			goto err;
-		}
-
-		usb_dev_dr->dev.coherent_dma_mask =3D 0xffffffffUL;
-		usb_dev_dr->dev.dma_mask =3D

&usb_dev_dr->dev.coherent_dma_mask;

Quoted 5 lines

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 511

Quoted 5 lines
arch/powerpc/sysdev/fsl_soc.c +4 -1
+		prop =3D get_property(np, "dr_mode", NULL);
-		usb_data.operating_mode =3D FSL_USB2_DR_HOST;
+		if (prop && !strcmp(prop, "host")) {
+			usb_data.operating_mode =3D FSL_USB2_DR_HOST;
+			usb_dev_dr_host =3D

platform_device_register_simple(

Quoted 9 lines

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 520

Quoted 9 lines
arch/powerpc/sysdev/fsl_soc.c +9 -0
+					"fsl-ehci", i, r, 2);
+			if (IS_ERR(usb_dev_dr_host)) {
+				ret =3D PTR_ERR(usb_dev_dr_host);
+				goto err;
+			}
+
+		} else if (prop && !strcmp(prop, "peripheral")) {
+			usb_data.operating_mode =3D FSL_USB2_DR_DEVICE;
+			usb_dev_dr_client =3D

platform_device_register_simple(

Quoted 10 lines

arch/powerpc/sysdev/fsl_soc.c static int __init fsl_usb_of_init(void) · line 526

Quoted 6 lines
arch/powerpc/sysdev/fsl_soc.c +6 -0
+					"fsl-usb2-udc", i, r, 2);
+			if (IS_ERR(usb_dev_dr_client)) {
+				ret =3D PTR_ERR(usb_dev_dr_client);
+				goto err;
+			}
+		} else if (!prop || (prop && !strcmp(prop, "otg"))) {

=20
Why do we assume if the prop is not defined we are OTG? This will break existing users and is not acceptable. If the prop doesn't exist we have to assume 'host' support to maintain compatibility.

No, it doesn't break existing users. In otg mode, it supports both host and client feature. The specific mode to use can be easily selected by loading the needed driver.

- Leo

#3 lore raw
In reply to Kumar Gala

T24gTW9uZGF5IDA1IEZlYnJ1YXJ5IDIwMDcgMTY6MTUsIEt1bWFyIEdhbGEgd3JvdGU6Cj4gPiAr oKCgoKCgoKCgoKCgoKCgoKCgoKCgdXNiX2RhdGEub3BlcmF0aW5nX21vZGUgPSBGU0xfVVNCMl9E Ul9IT1NUOwo+ID4gK6CgoKCgoKCgoKCgoKCgoKCgoKCgoHVzYl9kZXZfZHJfaG9zdCA9IHBsYXRm b3JtX2RldmljZV9yZWdpc3Rlcl9zaW1wbGUoCj4gPiAroKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCg oKCgoKCgoKCgoKCgoCJmc2wtZWhjaSIsIGksIHIsIDIpOwo+ID4gK6CgoKCgoKCgoKCgoKCgoKCg oKCgoGlmIChJU19FUlIodXNiX2Rldl9kcl9ob3N0KSkgewo+ID4gK6CgoKCgoKCgoKCgoKCgoKCg oKCgoKCgoKCgoKCgcmV0ID0gUFRSX0VSUih1c2JfZGV2X2RyX2hvc3QpOwo+ID4gK6CgoKCgoKCg oKCgoKCgoKCgoKCgoKCgoKCgoKCgZ290byBlcnI7CgpJIGp1c3Qgc2F3IHRoYXQgdGhpcyBmaWxl IGhhcyBhIG51bWJlciBvZiBjYWxscyB0byAKcGxhdGZvcm1fZGV2aWNlX3JlZ2lzdGVyX3NpbXBs ZSgpIGZvciBkZXZpY2VzIHRoYXQgY29tZSBmcm9tIHRoZSBPRgpkZXZpY2UgdHJlZS4KCkNhbiB0 aGlzIGJlIGNvbnZlcnRlZCB0byB1c2Ugb2ZfcmVnaXN0ZXJfcGxhdGZvcm1fZHJpdmVyKCkgYW5k Cm9mX3BsYXRmb3JtX2RldmljZV9wcm9iZSgpIGluc3RlYWQ/CgoJQXJuZCA8PjwK

#4 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · Kumar Gala

Review

Quoted 7 lines
(quoted diff) +2 -0
+                     usb_data.operating_mode = FSL_USB2_DR_HOST;
+                     usb_dev_dr_host =  

platform_device_register_simple(

(quoted diff) +4 -0
+                                     "fsl-ehci", i, r, 2);
+                     if (IS_ERR(usb_dev_dr_host)) {
+                             ret = PTR_ERR(usb_dev_dr_host);
+                             goto err;
Quoted 6 lines

I just saw that this file has a number of calls to platform_device_register_simple() for devices that come from the OF device tree.

Can this be converted to use of_register_platform_driver() and of_platform_device_probe() instead?

This is an ongoing issue and will help once arch/ppc consumers of these drivers go away. Until then we will continue to use platform_devices.

- k