Re: [PATCH v4 9/9] usb: dwc3: Add host-mode as default support

From: John Stultz
Date: Thu Nov 07 2019 - 17:23:34 EST


On Tue, Oct 29, 2019 at 2:25 AM Felipe Balbi <balbi@xxxxxxxxxx> wrote:
> John Stultz <john.stultz@xxxxxxxxxx> writes:
> > diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> > index 61d4fd8aead4..0e3466fe5ac4 100644
> > --- a/drivers/usb/dwc3/drd.c
> > +++ b/drivers/usb/dwc3/drd.c
> > @@ -489,7 +489,10 @@ static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role)
> > mode = DWC3_GCTL_PRTCAP_DEVICE;
> > break;
> > default:
> > - mode = DWC3_GCTL_PRTCAP_DEVICE;
> > + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST)
> > + mode = DWC3_GCTL_PRTCAP_HOST;
> > + else
> > + mode = DWC3_GCTL_PRTCAP_DEVICE;
> > break;
> > }
> >
> > @@ -515,7 +518,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev)
> > role = dwc->current_otg_role;
> > break;
> > default:
> > - role = USB_ROLE_DEVICE;
> > + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST)
> > + role = USB_ROLE_HOST;
>
> look at this, we now have 3 different encodings for role which DWC3
> needs to understand. One is its own PRTCAP_DIR, then there USB_DR_MODE_*
> and now USB_ROLE_*, can we make it so that we only have one private
> encoding and one generic encoding?

And you left out the DWC3_OTG_ROLE_* set too!

So I agree it can be easy to muddle up. The enums are *almost* equivalent:

include/linux/usb/role.h:
enum usb_role {
USB_ROLE_NONE,
USB_ROLE_HOST,
USB_ROLE_DEVICE,
};

include/linux/usb/otg.h:
enum usb_dr_mode {
USB_DR_MODE_UNKNOWN,
USB_DR_MODE_HOST,
USB_DR_MODE_PERIPHERAL,
USB_DR_MODE_OTG,
};

But both are widely used:
$ git grep USB_ROLE_ | wc -l
123
$ git grep USB_DR_MODE_ | wc -l
190

So I'm not sure how easy it will be to condense down, since the usage
is coming from different usb subsystems (otg and role switching) and
I worry assuming them equivalent in just one driver may run into
trouble eventually if the values diverge (ie someone adds
USB_ROLE_BRICK or something).

Heikki/Greg: Any thoughts on this? Does it make sense to try to drop
the usb_role enum and users and replace it with usb_dr_mode?

thanks
-john