From 6a6468f479a7e816fb656b3e1d8af30c7de837a4 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Tue, 19 Apr 2022 21:06:33 +0200 Subject: usb: xhci-dwc3: Support role switch default role When the device tree indicates support for role switching through the "usb-role-switch" property, take the "role-switch-default-mode" property into account when deciding which role to put the controller into. This makes USB devices work on Apple M1 systems where the device tree may include a "dr_mode" property that is set to "otg", but where we need to put the controller into "host" mode to see devices connected to the type-C ports. Signed-off-by: Mark Kettenis --- drivers/usb/common/common.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'drivers/usb/common/common.c') diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index ee0c064f1ff..cff86a51ae0 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -40,6 +40,22 @@ enum usb_dr_mode usb_get_dr_mode(ofnode node) return USB_DR_MODE_UNKNOWN; } +enum usb_dr_mode usb_get_role_switch_default_mode(ofnode node) +{ + const char *dr_mode; + int i; + + dr_mode = ofnode_read_string(node, "role-switch-default-mode"); + if (!dr_mode) + return USB_DR_MODE_UNKNOWN; + + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) + if (!strcmp(dr_mode, usb_dr_modes[i])) + return i; + + return USB_DR_MODE_UNKNOWN; +} + static const char *const speed_names[] = { [USB_SPEED_UNKNOWN] = "UNKNOWN", [USB_SPEED_LOW] = "low-speed", -- cgit v1.2.3