Skip to content

Commit 6703052

Browse files
Roger QuadrosPeter Chen
authored andcommitted
usb: cdns3: Fix hardware based role switch
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: 5064270 ("usb: cdns3: core: quit if it uses role switch class") Signed-off-by: Roger Quadros <rogerq@ti.com> Signed-off-by: Peter Chen <peter.chen@nxp.com>
1 parent f3bc432 commit 6703052

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

drivers/usb/cdns3/core.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ static irqreturn_t cdns3_wakeup_irq(int irq, void *data)
427427
*/
428428
static int cdns3_probe(struct platform_device *pdev)
429429
{
430-
struct usb_role_switch_desc sw_desc = { };
431430
struct device *dev = &pdev->dev;
432431
struct resource *res;
433432
struct cdns3 *cdns;
@@ -529,18 +528,21 @@ static int cdns3_probe(struct platform_device *pdev)
529528
if (ret)
530529
goto err2;
531530

532-
sw_desc.set = cdns3_role_set;
533-
sw_desc.get = cdns3_role_get;
534-
sw_desc.allow_userspace_control = true;
535-
sw_desc.driver_data = cdns;
536-
if (device_property_read_bool(dev, "usb-role-switch"))
531+
if (device_property_read_bool(dev, "usb-role-switch")) {
532+
struct usb_role_switch_desc sw_desc = { };
533+
534+
sw_desc.set = cdns3_role_set;
535+
sw_desc.get = cdns3_role_get;
536+
sw_desc.allow_userspace_control = true;
537+
sw_desc.driver_data = cdns;
537538
sw_desc.fwnode = dev->fwnode;
538539

539-
cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
540-
if (IS_ERR(cdns->role_sw)) {
541-
ret = PTR_ERR(cdns->role_sw);
542-
dev_warn(dev, "Unable to register Role Switch\n");
543-
goto err3;
540+
cdns->role_sw = usb_role_switch_register(dev, &sw_desc);
541+
if (IS_ERR(cdns->role_sw)) {
542+
ret = PTR_ERR(cdns->role_sw);
543+
dev_warn(dev, "Unable to register Role Switch\n");
544+
goto err3;
545+
}
544546
}
545547

546548
if (cdns->wakeup_irq) {
@@ -582,7 +584,8 @@ static int cdns3_probe(struct platform_device *pdev)
582584
return 0;
583585
err4:
584586
cdns3_drd_exit(cdns);
585-
usb_role_switch_unregister(cdns->role_sw);
587+
if (cdns->role_sw)
588+
usb_role_switch_unregister(cdns->role_sw);
586589
err3:
587590
set_phy_power_off(cdns);
588591
err2:

0 commit comments

Comments
 (0)