Re: [RFC][PATCH 3/3] usb: dwc3: Registering a role switch in the DRD code.

From: Roger Quadros
Date: Wed Oct 16 2019 - 05:25:28 EST


On 15/10/2019 22:10, John Stultz wrote:
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?).

Yes, we need to deal with it in the driver. e.g. in current case
when debugfs overrides a role from "otg" to "host" or "device",
we ignore the notifier.

Something similar could be done with role switch I think.

Felipe, what do you think?

--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki