Skip to content

Commit 27bf5be

Browse files
Junlisuzhougregkh
authored andcommitted
usb: chipidea: handle single role for usb role class
If usb port is configed to be single role, but usb role class is trying to set unavailable role, don't try to do role change. Signed-off-by: Jun Li <[email protected]> Signed-off-by: Peter Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1e31d3c commit 27bf5be

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

drivers/usb/chipidea/ci.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ static inline enum usb_role ci_role_to_usb_role(struct ci_hdrc *ci)
302302
return USB_ROLE_NONE;
303303
}
304304

305+
static inline enum ci_role usb_role_to_ci_role(enum usb_role role)
306+
{
307+
if (role == USB_ROLE_HOST)
308+
return CI_ROLE_HOST;
309+
else if (role == USB_ROLE_DEVICE)
310+
return CI_ROLE_GADGET;
311+
else
312+
return CI_ROLE_END;
313+
}
314+
305315
/**
306316
* hw_read_id_reg: reads from a identification register
307317
* @ci: the controller

drivers/usb/chipidea/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,11 @@ static int ci_usb_role_switch_set(struct device *dev, enum usb_role role)
618618
struct ci_hdrc *ci = dev_get_drvdata(dev);
619619
struct ci_hdrc_cable *cable = NULL;
620620
enum usb_role current_role = ci_role_to_usb_role(ci);
621+
enum ci_role ci_role = usb_role_to_ci_role(role);
621622
unsigned long flags;
622623

623-
if (current_role == role)
624+
if ((ci_role != CI_ROLE_END && !ci->roles[ci_role]) ||
625+
(current_role == role))
624626
return 0;
625627

626628
pm_runtime_get_sync(ci->dev);

0 commit comments

Comments
 (0)