[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7d5ba117-735e-3fb0-97f7-33be328a4ae6@huawei.com>
Date: Fri, 12 Apr 2019 09:23:42 +0800
From: Chen Yu <chenyu56@...wei.com>
To: John Stultz <john.stultz@...aro.org>
CC: <liuyu712@...ilicon.com>,
Linux USB List <linux-usb@...r.kernel.org>,
"open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS"
<devicetree@...r.kernel.org>, lkml <linux-kernel@...r.kernel.org>,
"Zhuangluan Su" <suzhuangluan@...ilicon.com>,
Kongfei <kongfei@...ilicon.com>, <wanghu17@...ilicon.com>,
butao <butao@...ilicon.com>, <chenyao11@...wei.com>,
<fangshengzhou@...ilicon.com>,
Li Pengcheng <lipengcheng8@...wei.com>,
<songxiaowei@...ilicon.com>, YiPing Xu <xuyiping@...ilicon.com>,
<xuyoujun4@...wei.com>, Yudongbin <yudongbin@...ilicon.com>,
Zang Leigang <zangleigang@...ilicon.com>,
Jun Li <lijun.kernel@...il.com>,
Valentin Schneider <valentin.schneider@....com>,
Felipe Balbi <balbi@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Subject: Re: [PATCH v5 10/13] usb: dwc3: Registering a role switch in the DRD
code.
Hi John,
On 2019/4/12 8:48, John Stultz wrote:
> On Thu, Mar 28, 2019 at 9:14 PM Yu Chen <chenyu56@...wei.com> wrote:
>>
>> The Type-C drivers use USB role switch API to inform the
>> system about the negotiated data role, so registering a role
>> switch in the DRD code in order to support platforms with
>> USB Type-C connectors.
>>
>
> Hey Yu Chen!
> Thanks so much for sending these patches out! I have run into some
> troubles on bootup where things aren't working properly at first, that
> seem to be due to state initialization races. In chasing those down,
> I've found some other quirks I wanted to bring up.
>
>> --- a/drivers/usb/dwc3/drd.c
>> +++ b/drivers/usb/dwc3/drd.c
>> @@ -479,6 +479,43 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
>> return edev;
>> }
>>
>> +static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role)
>> +{
>> + struct dwc3 *dwc = dev_get_drvdata(dev);
>> + u32 mode;
>> +
>> + switch (role) {
>> + case USB_ROLE_HOST:
>> + mode = DWC3_GCTL_PRTCAP_HOST;
>> + break;
>> + case USB_ROLE_DEVICE:
>> + mode = DWC3_GCTL_PRTCAP_DEVICE;
>> + break;
>> + default:
>> + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST)
>> + mode = DWC3_GCTL_PRTCAP_HOST;
>> + else
>> + mode = DWC3_GCTL_PRTCAP_DEVICE;
>> + break;
>> + }
>> +
>> + dwc3_set_mode(dwc, mode);
>> + return 0;
>> +}
>> +
>> +static enum usb_role dwc3_usb_role_switch_get(struct device *dev)
>> +{
>> + struct dwc3 *dwc = dev_get_drvdata(dev);
>> + unsigned long flags;
>> + enum usb_role role;
>> +
>> + spin_lock_irqsave(&dwc->lock, flags);
>> + role = dwc->current_otg_role;
>> + spin_unlock_irqrestore(&dwc->lock, flags);
>> +
>> + return role;
>> +}
>> +
>
> So the two functions above are a bit asymmetric. The
> dwc3_usb_role_switch_set() can put the device into host or device
> mode, which eventually sets the current_dr_role value. However on the
> dwc3_usb_role_switch_get() we return the current_otg_role value.
> current_otg_role isn't set unless current_dr_role is
> DWC3_GCTL_PRTCAP_OTG, which doesn't seem to happen here.
>
> I suspect in dwc3_usb_role_switch_get() we should return
> current_dr_role, unless current_dr_role==DWC3_GCTL_PRTCAP_OTG, in
> which case we'd want to return current_otg_role.
>
> Does that make sense?
>
Yes, you are right! The dwc3_usb_role_switch_get() should return current_dr_role
. Actually if we register the dwc3_role_switch, the current_dr_role would not be DWC3_GCTL_PRTCAP_OTG.
> Nothing really actually use this dwc3_usb_role_switch_get() yet, so
> this was easy to overlook, and I only caught it as I was trying to
> debug some of the initialization races.
>
> thanks
> -john
>
> .
>
Powered by blists - more mailing lists