Re: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
From: Roger Quadros
Date: Mon Aug 12 2019 - 07:06:02 EST
On 12/08/2019 13:31, Heikki Krogerus wrote:
> Hi,
>
>>>>>> + real_role = cdsn3_real_role_switch_get(cdns->dev);
>>>>>> +
>>>>>> + current_role = role;
>>>>>> + dev_dbg(cdns->dev, "Switching role");
>>>>>> +
>>>>>> + ret = cdns3_role_start(cdns, real_role);
>>>>>> + if (ret) {
>>>>>> + /* Back to current role */
>>>>>> + dev_err(cdns->dev, "set %d has failed, back to %d\n",
>>>>>> + role, current_role);
>>>>>> + ret = cdns3_role_start(cdns, current_role);
>>>>>> + if (ret)
>>>>>> + dev_err(cdns->dev, "back to %d failed too\n",
>>>>>> + current_role);
>>>>>> + }
>>>>>> +exit:
>>>>>> + pm_runtime_put_sync(cdns->dev);
>>>>>> + return ret;
>>>>>> +}
>>>>>> +
>>>>>> +static const struct usb_role_switch_desc cdns3_switch_desc = {
>>>>>> + .set = cdns3_role_switch_set,
>>>>>> + .get = cdsn3_real_role_switch_get,
>>>>>> + .allow_userspace_control = true,
>>>>>
>>>>> how does user initiated cdns3_role_switch_set() via sysfs co-exist with role
>>>>> changes done by hardware events. e.g. ID/VBUS?
>>>>>
>>>>
>>>> Do you expect any issues whit this, have you seen any problem with this
>>>> on your platform ?
>>>>
>>>> I assume that it should work in this way:
>>>> 1. user change role by sysfs
>>>> 2. Driver change the role according with user request.
>>>> 3. If we receive correct ID/VBUS then role should not be changed
>>>> because new role is the same as current set in point 2.
>>>>
>>>
>>> I have not tested this series yet.
>>> My understanding is that if user sets role to "host" or "device" then it should
>>> remain in that role irrespective of ID/VBUS. Once user sets it to "none" then
>>> port should set role based on ID/VBUS.
>>
>> According with your understanding it works the same way as by debugfs.
>> Now I have no doubts to remove debugfs.c file :)
>
> Hold on! The role "none" means that the connector should not be
> connected to either the host nor device.
OK.
>
> The sysfs file we expose from the class for the role switches is
> primarily meant for supporting proprietary protocols that require us
> to basically override the connector USB data role. The default role
> should always be selected in the drivers.
OK. Let's take this example
- Port is dual-role port micro AB.
- microAB to type-A adapter is connected which pulls ID low. port transitions
to "host" role by the controller driver.
- proprietary protocol want to switch role to device role so writes "device" to
mode switch sysfs. port transitions to "device" role.
Now, how does controller driver know to fall back to HW based role switching?
>
> With USB Type-C connectors and alternate modes, the "none" role is
> used for example when the connector is put into "USB Safe State". In
> case you guys are not familiar with USB Safe State, then it is a state
> (defined in USB PD specifications) for the connector where the data
> lines on the connector should not be physically connected to anything.
> The connector needs to be put into safe state always when entering
> or exiting an alternate mode, before the final mode (USB or alternate)
> is actually being set for the connector.
>
>
> thanks,
>
--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki