From: Pritam Manohar Sutar Date: Fri, 24 Oct 2025 08:54:55 +0000 (+0530) Subject: usb: dwc3: Allow usb role swich control from userspace X-Git-Tag: v6.19-rc1~63^2~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=389597581e3ef46940476f2d59c9ac7f9a26b113;p=thirdparty%2Fkernel%2Flinux.git usb: dwc3: Allow usb role swich control from userspace There is a possibility of user needs for USB mode switching on boards that lack external hardware support for dynamic host/device role detection. This is particularly relevant in automotive applications where userspace applications need to switch USB roles (host to device) at runtime for CarPlay/Android Auto integration. Add an `allow_userspace_control` flag to handle such cases. When enabled, it exposes a sysfs attribute that allows userspace to switch the USB role manually between host and device. This provides flexibility for platforms that cannot rely on hardware-based mode detection. The role switch can be done as below echo host > /sys/class/usb_role/.usb-role-switch/role echo device > /sys/class/usb_role/.usb-role-switch/role Acked-by: Thinh Nguyen Signed-off-by: Pritam Manohar Sutar Link: https://patch.msgid.link/20251024085455.789555-1-pritam.sutar@samsung.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index 4c91240eb4299..589bbeb274541 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -515,6 +515,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc) dwc3_role_switch.set = dwc3_usb_role_switch_set; dwc3_role_switch.get = dwc3_usb_role_switch_get; dwc3_role_switch.driver_data = dwc; + dwc3_role_switch.allow_userspace_control = true; dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch); if (IS_ERR(dwc->role_sw)) return PTR_ERR(dwc->role_sw);