On Tue, Oct 15, 2019 at 1:25 AM Roger Quadros <rogerq@xxxxxx> wrote:
On 03/10/2019 02:16, John Stultz wrote:
@@ -487,7 +539,28 @@ int dwc3_drd_init(struct dwc3 *dwc)
if (IS_ERR(dwc->edev))
return PTR_ERR(dwc->edev);
- if (dwc->edev) {
+ if (device_property_read_bool(dwc->dev, "usb-role-switch")) {
I think we should use role switch unconditionally and get rid of the
debugfs role status/change mechanism.
+ struct usb_role_switch_desc dwc3_role_switch = {0};
+ u32 mode;
+
+ if (device_property_read_bool(dwc->dev,
+ "role-switch-default-host")) {
+ dwc->role_switch_default_mode = USB_DR_MODE_HOST;
+ mode = DWC3_GCTL_PRTCAP_HOST;
+ } else {
+ dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL;
+ mode = DWC3_GCTL_PRTCAP_DEVICE;
+ }
+ dwc3_role_switch.fwnode = dev_fwnode(dwc->dev);
+ dwc3_role_switch.set = dwc3_usb_role_switch_set;
+ dwc3_role_switch.get = dwc3_usb_role_switch_get;
+ dwc->role_sw = usb_role_switch_register(dwc->dev,
+ &dwc3_role_switch);
+ if (IS_ERR(dwc->role_sw))
+ return PTR_ERR(dwc->role_sw);
+
+ dwc3_set_mode(dwc, mode);
+ } else if (dwc->edev) {
Role switch should exist regardless if dwc->edev is present or not.
Does that risk duplicative mode sets when things change (via the
dwc3_drd_notifier and dwc3_usb_role_switch_set calls?).