Skip to contentSkip to conversation

Revert "usb: cdns3: core: quit if it uses role switch class"

PATCH In review Roger Quadros 4 participants 11 messages Nov 23, 2020 – Nov 25, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "usb: cdns3: core: quit if it uses role switch class"

This reverts commit 50642709f6590fe40afa6d22c32f23f5b842aed5.

This commit breaks hardware based role switching on TI platforms. cdns->role_sw is always going to be non-zero as it is a pointer to the usb_role_switch instance. Some other means needs to be used if hardware based role switching is not required by the platform.

---
 drivers/usb/cdns3/core.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/usb/cdns3/core.c +0 -4
index a0f73d4711ae..4c1445cf2ad0 100644
@@ -280,10 +280,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
 	enum usb_role real_role, current_role;
 	int ret = 0;
 
-	/* Depends on role switch class */
-	if (cdns->role_sw)
-		return 0;
-
 	pm_runtime_get_sync(cdns->dev);
 
 	current_role = cdns->role;
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#1 lore raw
Quoted 18 lines · Roger Quadros

This reverts commit 50642709f6590fe40afa6d22c32f23f5b842aed5.

This commit breaks hardware based role switching on TI platforms. cdns->role_sw is always going to be non-zero as it is a pointer to the usb_role_switch instance. Some other means needs to be used if hardware based role switching is not required by the platform.

---
 drivers/usb/cdns3/core.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/usb/cdns3/core.c +0 -0
index a0f73d4711ae..4c1445cf2ad0 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 285

Quoted 10 lines
drivers/usb/cdns3/core.c +0 -4
@@ -280,10 +280,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
 	enum usb_role real_role, current_role;
 	int ret = 0;
 
-	/* Depends on role switch class */
-	if (cdns->role_sw)
-		return 0;
-
 	pm_runtime_get_sync(cdns->dev);
 
 	current_role = cdns->role;

Hi Roger,

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

Signature · 2 lines
Thanks,
Peter Chen
#2 lore raw

Peter,

Quoted 32 lines · Peter Chen
Quoted 18 lines · Roger Quadros

This reverts commit 50642709f6590fe40afa6d22c32f23f5b842aed5.

This commit breaks hardware based role switching on TI platforms. cdns->role_sw is always going to be non-zero as it is a pointer to the usb_role_switch instance. Some other means needs to be used if hardware based role switching is not required by the platform.

---
  drivers/usb/cdns3/core.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/usb/cdns3/core.c +0 -0
index a0f73d4711ae..4c1445cf2ad0 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 285

Quoted 10 lines
drivers/usb/cdns3/core.c +0 -4
@@ -280,10 +280,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
  	enum usb_role real_role, current_role;
  	int ret = 0;
 
-	/* Depends on role switch class */
-	if (cdns->role_sw)
-		return 0;
-
  	pm_runtime_get_sync(cdns->dev);
 
  	current_role = cdns->role;

Hi Roger,

Quoted 5 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

cheers,
-roger

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#3 lore raw

Best regards,
Peter Chen

Quoted 52 lines

-----Original Message-----
From: Roger Quadros <[email protected]>
Sent: 2020年11月24日 17:39
To: Peter Chen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class"

Peter,

Quoted 32 lines · Peter Chen
Quoted 18 lines · Roger Quadros

This reverts commit 50642709f6590fe40afa6d22c32f23f5b842aed5.

This commit breaks hardware based role switching on TI platforms. cdns->role_sw is always going to be non-zero as it is a pointer to the usb_role_switch instance. Some other means needs to be used if hardware based role switching is not required by the platform.

---
  drivers/usb/cdns3/core.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/usb/cdns3/core.c +0 -0
index a0f73d4711ae..4c1445cf2ad0 100644
@@ -280,10 +280,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
  	enum usb_role real_role, current_role;

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns)

Quoted 10 lines
drivers/usb/cdns3/core.c +0 -5
  	int ret = 0;
 
-	/* Depends on role switch class */
-	if (cdns->role_sw)
-		return 0;
-
  	pm_runtime_get_sync(cdns->dev);
 
  	current_role = cdns->role;
--

Hi Roger,

Quoted 5 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +2 -2
index 2e469139769f..fdd52e87a7b2 100644
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
        enum usb_role real_role, current_role;
        int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                return 0;
 
        pm_runtime_get_sync(cdns->dev);

Peter

#4 lore raw

+Heikki

Peter,

Quoted 73 lines · Peter Chen

Best regards,
Peter Chen

Quoted 52 lines

-----Original Message-----
From: Roger Quadros <[email protected]>
Sent: 2020年11月24日 17:39
To: Peter Chen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class"

Peter,

Quoted 32 lines · Peter Chen
Quoted 18 lines · Roger Quadros

This reverts commit 50642709f6590fe40afa6d22c32f23f5b842aed5.

This commit breaks hardware based role switching on TI platforms. cdns->role_sw is always going to be non-zero as it is a pointer to the usb_role_switch instance. Some other means needs to be used if hardware based role switching is not required by the platform.

---
   drivers/usb/cdns3/core.c | 4 ----
   1 file changed, 4 deletions(-)
drivers/usb/cdns3/core.c +0 -0
index a0f73d4711ae..4c1445cf2ad0 100644
@@ -280,10 +280,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
   	enum usb_role real_role, current_role;

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns)

Quoted 10 lines
drivers/usb/cdns3/core.c +0 -5
   	int ret = 0;
 
-	/* Depends on role switch class */
-	if (cdns->role_sw)
-		return 0;
-
   	pm_runtime_get_sync(cdns->dev);
 
   	current_role = cdns->role;
--

Hi Roger,

Quoted 5 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
         enum usb_role real_role, current_role;
         int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                 return 0;
 
         pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

How about the following? It still doesn't handle role-switch-default-mode property though.

drivers/usb/cdns3/core.c +7 -5
index 4c1445cf2ad0..986b56a9940c 100644
@@ -532,11 +532,13 @@ static int cdns3_probe(struct platform_device *pdev)
 	if (device_property_read_bool(dev, "usb-role-switch"))
 		sw_desc.fwnode = dev->fwnode;
 
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");
-		goto err3;
+	if (device_property_read_bool(cdns->dev, "usb-role-switch")) {
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
 	}
 
 	if (cdns->wakeup_irq) {

cheers,
-roger

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#5 lore raw
Quoted 112 lines · Roger Quadros

+Heikki

Peter,

Quoted 73 lines · Peter Chen

Best regards,
Peter Chen

Quoted 52 lines

-----Original Message-----
From: Roger Quadros <[email protected]>
Sent: 2020年11月24日 17:39
To: Peter Chen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] Revert "usb: cdns3: core: quit if it uses role switch class"

Peter,

Quoted 32 lines · Peter Chen
Quoted 18 lines · Roger Quadros

This reverts commit 50642709f6590fe40afa6d22c32f23f5b842aed5.

This commit breaks hardware based role switching on TI platforms. cdns->role_sw is always going to be non-zero as it is a pointer to the usb_role_switch instance. Some other means needs to be used if hardware based role switching is not required by the platform.

---
   drivers/usb/cdns3/core.c | 4 ----
   1 file changed, 4 deletions(-)
drivers/usb/cdns3/core.c +0 -0
index a0f73d4711ae..4c1445cf2ad0 100644
@@ -280,10 +280,6 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
   	enum usb_role real_role, current_role;

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns)

Quoted 10 lines
drivers/usb/cdns3/core.c +0 -5
   	int ret = 0;
 
-	/* Depends on role switch class */
-	if (cdns->role_sw)
-		return 0;
-
   	pm_runtime_get_sync(cdns->dev);
 
   	current_role = cdns->role;
--

Hi Roger,

Quoted 5 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
         enum usb_role real_role, current_role;
         int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                 return 0;
 
         pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

How about the following? It still doesn't handle role-switch-default-mode property though.

drivers/usb/cdns3/core.c +0 -4
index 4c1445cf2ad0..986b56a9940c 100644
@@ -532,11 +532,13 @@ static int cdns3_probe(struct platform_device *pdev)
 	if (device_property_read_bool(dev, "usb-role-switch"))
 		sw_desc.fwnode = dev->fwnode;
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");

drivers/usb/cdns3/core.c static int cdns3_probe(struct platform_device *pdev) · line 542

Quoted 10 lines
drivers/usb/cdns3/core.c +7 -1
-		goto err3;
+	if (device_property_read_bool(cdns->dev, "usb-role-switch")) {
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
 	}
 	if (cdns->wakeup_irq) {

Makes sense to me. FWIW:

thanks,

Signature · 1 line
heikki
#6 lore raw
In reply to Roger Quadros
Quoted 39 lines · Roger Quadros
Quoted 25 lines
Quoted 10 lines
Quoted 6 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
         enum usb_role real_role, current_role;
         int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                 return 0;
 
         pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Quoted 8 lines

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

How about the following? It still doesn't handle role-switch-default-mode property though.

Roger, you said you also use /sys entries (I suppose it means through role switch class) to do role switch, with your change, there will be no /sys entry for role switch.

Peter

Quoted 35 lines
Quoted 2 lines
Quoted 2 lines

We use both hardware role switch and /sys entries for manually forcing a certain role.

drivers/usb/cdns3/core.c +7 -5
index 4c1445cf2ad0..986b56a9940c 100644
@@ -532,11 +532,13 @@ static int cdns3_probe(struct platform_device *pdev)
 	if (device_property_read_bool(dev, "usb-role-switch"))
 		sw_desc.fwnode = dev->fwnode;
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");
-		goto err3;
+	if (device_property_read_bool(cdns->dev, "usb-role-switch")) {
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
 	}
 	if (cdns->wakeup_irq) {
 
 

cheers,
-roger

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Signature · 2 lines
Thanks,
Peter Chen
#7 lore raw

Peter,

Quoted 46 lines · Peter Chen
Quoted 45 lines · Roger Quadros
Quoted 25 lines
Quoted 10 lines
Quoted 6 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
          enum usb_role real_role, current_role;
          int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                  return 0;
 
          pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

Quoted 6 lines
Quoted 2 lines

How about the following? It still doesn't handle role-switch-default-mode property though.

Roger, you said you also use /sys entries (I suppose it means through role switch class) to do role switch, with your change, there will be no /sys entry for role switch.

Sorry for the confusion. Although we do need both features (SW role switch + HW role switch) I don't think it is required to operate simultaneously. If users need SW control they can set the DT flag.

cheers,
-roger

Quoted 39 lines

Peter

Quoted 35 lines
Quoted 2 lines
Quoted 2 lines

We use both hardware role switch and /sys entries for manually forcing a certain role.

drivers/usb/cdns3/core.c +7 -5
index 4c1445cf2ad0..986b56a9940c 100644
@@ -532,11 +532,13 @@ static int cdns3_probe(struct platform_device *pdev)
  	if (device_property_read_bool(dev, "usb-role-switch"))
  		sw_desc.fwnode = dev->fwnode;
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");
-		goto err3;
+	if (device_property_read_bool(cdns->dev, "usb-role-switch")) {
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
  	}
  	if (cdns->wakeup_irq) {
 
 

cheers,
-roger

Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
#8 lore raw
Quoted 52 lines · Roger Quadros

Peter,

Quoted 49 lines · Peter Chen
Quoted 47 lines · Roger Quadros
Quoted 25 lines
Quoted 10 lines
Quoted 6 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
          enum usb_role real_role, current_role;
          int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                  return 0;
 
          pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

How about the following? It still doesn't handle role-switch-default-mode property though.

Quoted 7 lines
Quoted 3 lines

Roger, you said you also use /sys entries (I suppose it means through role switch class) to do role switch, with your change, there will be no /sys entry for role switch.

Sorry for the confusion. Although we do need both features (SW role switch + HW role switch) I don't think it is required to operate simultaneously. If users need SW control they can set the DT flag.

I see. I prefer embracing all things related to role switch under the firmware entry condition. Besides, I find another issue that devm_request_irq for wakeup_irq does not call usb_role_switch_unregister if it has failed. So, probably, two patches are needed. I am OK you send the patches to fix both.

drivers/usb/cdns3/core.c +15 -12
index 2e469139769f..fc6a8152406c 100644
@@ -427,7 +427,6 @@ static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
  */
 static int cdns3_probe(struct platform_device *pdev)
 {
-	struct usb_role_switch_desc sw_desc = { };
 	struct device *dev = &pdev->dev;
 	struct resource	*res;
 	struct cdns3 *cdns;
@@ -529,18 +528,21 @@ static int cdns3_probe(struct platform_device *pdev)
 	if (ret)
 		goto err2;
 
-	sw_desc.set = cdns3_role_set;
-	sw_desc.get = cdns3_role_get;
-	sw_desc.allow_userspace_control = true;
-	sw_desc.driver_data = cdns;
-	if (device_property_read_bool(dev, "usb-role-switch"))
+	if (device_property_read_bool(dev, "usb-role-switch")) {
+		struct usb_role_switch_desc sw_desc = { };
+
+		sw_desc.set = cdns3_role_set;
+		sw_desc.get = cdns3_role_get;
+		sw_desc.allow_userspace_control = true;
+		sw_desc.driver_data = cdns;
 		sw_desc.fwnode = dev->fwnode;
 
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");
-		goto err3;
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
 	}
 
 	if (cdns->wakeup_irq) {
@@ -583,7 +585,8 @@ static int cdns3_probe(struct platform_device *pdev)
 	return 0;
 err4:
 	cdns3_drd_exit(cdns);
-	usb_role_switch_unregister(cdns->role_sw);
+	if (cdns->role_sw)
+		usb_role_switch_unregister(cdns->role_sw);
 err3:
 	set_phy_power_off(cdns);
 err2:
Signature · 2 lines
Thanks,
Peter Chen
#9 lore raw
Quoted 61 lines · Peter Chen
Quoted 52 lines · Roger Quadros

Peter,

Quoted 49 lines · Peter Chen
Quoted 47 lines · Roger Quadros
Quoted 25 lines
Quoted 10 lines
Quoted 6 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
           enum usb_role real_role, current_role;
           int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                   return 0;
 
           pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

How about the following? It still doesn't handle role-switch-default-mode property though.

Quoted 7 lines
Quoted 3 lines

Roger, you said you also use /sys entries (I suppose it means through role switch class) to do role switch, with your change, there will be no /sys entry for role switch.

Sorry for the confusion. Although we do need both features (SW role switch + HW role switch) I don't think it is required to operate simultaneously. If users need SW control they can set the DT flag.

Quoted 5 lines

I see. I prefer embracing all things related to role switch under the firmware entry condition. Besides, I find another issue that devm_request_irq for wakeup_irq does not call usb_role_switch_unregister if it has failed. So, probably, two patches are needed. I am OK you send the patches to fix both.

Pawel, can you please confirm that if you are ok with either h/w role switching or s/w role switching but not both working at the same time?

It would have been nice by user to to know the current role even for h/w based swithcing but it looks like now that won't be possible.

cheers,
-roger

Quoted 56 lines
drivers/usb/cdns3/core.c +15 -12
index 2e469139769f..fc6a8152406c 100644
@@ -427,7 +427,6 @@ static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
   */
  static int cdns3_probe(struct platform_device *pdev)
  {
-	struct usb_role_switch_desc sw_desc = { };
  	struct device *dev = &pdev->dev;
  	struct resource	*res;
  	struct cdns3 *cdns;
@@ -529,18 +528,21 @@ static int cdns3_probe(struct platform_device *pdev)
  	if (ret)
  		goto err2;
 
-	sw_desc.set = cdns3_role_set;
-	sw_desc.get = cdns3_role_get;
-	sw_desc.allow_userspace_control = true;
-	sw_desc.driver_data = cdns;
-	if (device_property_read_bool(dev, "usb-role-switch"))
+	if (device_property_read_bool(dev, "usb-role-switch")) {
+		struct usb_role_switch_desc sw_desc = { };
+
+		sw_desc.set = cdns3_role_set;
+		sw_desc.get = cdns3_role_get;
+		sw_desc.allow_userspace_control = true;
+		sw_desc.driver_data = cdns;
  		sw_desc.fwnode = dev->fwnode;
 
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");
-		goto err3;
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
  	}
 
  	if (cdns->wakeup_irq) {
@@ -583,7 +585,8 @@ static int cdns3_probe(struct platform_device *pdev)
  	return 0;
  err4:
  	cdns3_drd_exit(cdns);
-	usb_role_switch_unregister(cdns->role_sw);
+	if (cdns->role_sw)
+		usb_role_switch_unregister(cdns->role_sw);
  err3:
  	set_phy_power_off(cdns);
  err2:
Signature · 2 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
maintainer
#10 lore raw
Quoted 69 lines · Peter Chen
Quoted 61 lines · Roger Quadros
Quoted 52 lines

Peter,

Quoted 49 lines · Peter Chen
Quoted 47 lines · Roger Quadros
Quoted 25 lines
Quoted 10 lines
Quoted 6 lines

I am sorry about that. Do you use role switch /sys entry, if you have used, I prefer using "usb-role-switch" property at dts to judge if SoC OTG signals or external signals for role switch. If you have not used it, I prefer only setting cdns->role_sw for role switch use cases.

We use both hardware role switch and /sys entries for manually forcing a certain role.

Quoted 7 lines

We do not set any "usb-role-switch" property at DTS.

Currently cdns->role_sw is being always set by driver irrespective of any DT property, so this patch is clearly wrong and needs to be reverted.

What do you think?

Could you accept below fix?

drivers/usb/cdns3/core.c +0 -0
index 2e469139769f..fdd52e87a7b2 100644

drivers/usb/cdns3/core.c int cdns3_hw_role_switch(struct cdns3 *cdns) · line 287

Quoted 10 lines
drivers/usb/cdns3/core.c +2 -2
@@ -280,8 +280,8 @@ int cdns3_hw_role_switch(struct cdns3 *cdns)
           enum usb_role real_role, current_role;
           int ret = 0;
 
-       /* Depends on role switch class */
-       if (cdns->role_sw)
+       /* quit if switch role through external signals */
+       if (device_property_read_bool(cdns->dev, "usb-role-switch"))
                   return 0;
 
           pm_runtime_get_sync(cdns->dev);

Although this will fix the issue I don't think this is making the driver to behave as expected with usb-role-switch property.

Now, even if usb-role-switch property is not present the driver will still register the role switch driver.

I think we need to register the role switch driver only if usb-role-switch property is present. We would also need to set the default role if role-switch-default-mode is present.

How about the following? It still doesn't handle role-switch-default-mode property though.

Quoted 7 lines
Quoted 3 lines

Roger, you said you also use /sys entries (I suppose it means through role switch class) to do role switch, with your change, there will be no /sys entry for role switch.

Sorry for the confusion. Although we do need both features (SW role switch + HW role switch) I don't think it is required to operate simultaneously. If users need SW control they can set the DT flag.

Quoted 5 lines

I see. I prefer embracing all things related to role switch under the firmware entry condition. Besides, I find another issue that devm_request_irq for wakeup_irq does not call usb_role_switch_unregister if it has failed. So, probably, two patches are needed. I am OK you send the patches to fix both.

Quoted 5 lines

Pawel, can you please confirm that if you are ok with either h/w role switching or s/w role switching but not both working at the same time?

It would have been nice by user to to know the current role even for h/w based swithcing but it looks like now that won't be possible.

For the moment it's ok for me, but form testing point of view it could be nice to have possibility to easy choose between these two modes in dynamically way.

For PCI based on platform probably I will have to add some parameter to cdns3-pci.ko module to allow selecting modes. I don't use DTS.

Don't worry about it now. You can post this fix.

Cheers,
Pawel

Quoted 63 lines

cheers,
-roger

Quoted 47 lines
drivers/usb/cdns3/core.c +13 -11
index 2e469139769f..fc6a8152406c 100644
@@ -427,7 +427,6 @@ static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
   */
  static int cdns3_probe(struct platform_device *pdev)
  {
-	struct usb_role_switch_desc sw_desc = { };
  	struct device *dev = &pdev->dev;
  	struct resource	*res;
  	struct cdns3 *cdns;
@@ -529,18 +528,21 @@ static int cdns3_probe(struct platform_device *pdev)
  	if (ret)
  		goto err2;
 
-	sw_desc.set = cdns3_role_set;
-	sw_desc.get = cdns3_role_get;
-	sw_desc.allow_userspace_control = true;
-	sw_desc.driver_data = cdns;
-	if (device_property_read_bool(dev, "usb-role-switch"))
+	if (device_property_read_bool(dev, "usb-role-switch")) {
+		struct usb_role_switch_desc sw_desc = { };
+
+		sw_desc.set = cdns3_role_set;
+		sw_desc.get = cdns3_role_get;
+		sw_desc.allow_userspace_control = true;
+		sw_desc.driver_data = cdns;
  		sw_desc.fwnode = dev->fwnode;
 
-	cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
-	if (IS_ERR(cdns->role_sw)) {
-		ret = PTR_ERR(cdns->role_sw);
-		dev_warn(dev, "Unable to register Role Switch\n");
-		goto err3;
+		cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
+		if (IS_ERR(cdns->role_sw)) {
+			ret = PTR_ERR(cdns->role_sw);
+			dev_warn(dev, "Unable to register Role Switch\n");
+			goto err3;
+		}
  	}
 
  	if (cdns->wakeup_irq) {

drivers/usb/cdns3/core.c static int cdns3_probe(struct platform_device *pdev) · line 592

Quoted 9 lines
drivers/usb/cdns3/core.c +2 -1
@@ -583,7 +585,8 @@ static int cdns3_probe(struct platform_device *pdev)
  	return 0;
  err4:
  	cdns3_drd_exit(cdns);
-	usb_role_switch_unregister(cdns->role_sw);
+	if (cdns->role_sw)
+		usb_role_switch_unregister(cdns->role_sw);
  err3:
  	set_phy_power_off(cdns);
  err2:

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki