diff mbox series

usb: cdns3: Fix hardware based role switch

Message ID 20201125124936.5929-1-rogerq@ti.com
State New
Headers show
Series usb: cdns3: Fix hardware based role switch | expand

Commit Message

Roger Quadros Nov. 25, 2020, 12:49 p.m. UTC
Hardware based role switch is broken as the driver always skips it.
Fix this by registering for  SW role switch only if 'usb-role-switch'
property is present in the device tree.

Fixes: 50642709f659 ("usb: cdns3: core: quit if it uses role switch class")
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 drivers/usb/cdns3/core.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

Comments

Roger Quadros Nov. 27, 2020, 9:30 a.m. UTC | #1
Hi Peter,

On 25/11/2020 14:49, Roger Quadros wrote:
> Hardware based role switch is broken as the driver always skips it.

> Fix this by registering for  SW role switch only if 'usb-role-switch'

> property is present in the device tree.

> 

> Fixes: 50642709f659 ("usb: cdns3: core: quit if it uses role switch class")

> Signed-off-by: Roger Quadros <rogerq@ti.com>


Can you please pick this up for -rc cycle, else otg will be broken for us in v5.10 release.
Thanks.

cheers,
-roger

> ---

>   drivers/usb/cdns3/core.c | 27 +++++++++++++++------------

>   1 file changed, 15 insertions(+), 12 deletions(-)

> 

> diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c

> index a0f73d4711ae..170deb3eacf0 100644

> --- a/drivers/usb/cdns3/core.c

> +++ b/drivers/usb/cdns3/core.c

> @@ -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) {

> @@ -582,7 +584,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
Peter Chen Nov. 27, 2020, 9:47 a.m. UTC | #2
> Hi Peter,

> 

> On 25/11/2020 14:49, Roger Quadros wrote:

> > Hardware based role switch is broken as the driver always skips it.

> > Fix this by registering for  SW role switch only if 'usb-role-switch'

> > property is present in the device tree.

> >

> > Fixes: 50642709f659 ("usb: cdns3: core: quit if it uses role switch

> > class")

> > Signed-off-by: Roger Quadros <rogerq@ti.com>

> 

> Can you please pick this up for -rc cycle, else otg will be broken for us in v5.10

> release.

> Thanks.

> 


It is at my -fixes tree along with my two fixes[1][2]. If there is no report issue,
I will send it to Greg next Monday.

[1] https://patchwork.kernel.org/project/linux-usb/patch/20201126065409.7533-1-peter.chen@kernel.org/
[2] https://patchwork.kernel.org/project/linux-usb/patch/20201126065409.7533-2-peter.chen@kernel.org/

Peter
diff mbox series

Patch

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index a0f73d4711ae..170deb3eacf0 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -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) {
@@ -582,7 +584,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: