*Re: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
2019-08-12 9:43 ` Pawel Laszczak@ 2019-08-12 10:31 ` Heikki Krogerus
2019-08-12 11:05 ` Roger Quadros0 siblings, 1 reply; 59+ messages in thread
From: Heikki Krogerus @ 2019-08-12 10:31 UTC (permalink / raw)
To: Pawel Laszczak
Cc: Roger Quadros, felipe.balbi, gregkh, linux-usb, linux-kernel,
jbergsagel, nsekhar, nm, Suresh Punnoose, Jayshri Dajiram Pawar,
Rahul Kumar, Anil Joy Varughese
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.
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.
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,
--
heikki
^permalinkrawreply [flat|nested] 59+ messages in thread

*Re: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
2019-08-12 10:31 ` Heikki Krogerus@ 2019-08-12 11:05 ` Roger Quadros
2019-08-12 12:46 ` Felipe Balbi0 siblings, 1 reply; 59+ messages in thread
From: Roger Quadros @ 2019-08-12 11:05 UTC (permalink / raw)
To: Heikki Krogerus, Pawel Laszczak
Cc: felipe.balbi, gregkh, linux-usb, linux-kernel, jbergsagel,
nsekhar, nm, Suresh Punnoose, Jayshri Dajiram Pawar, Rahul Kumar,
Anil Joy Varughese
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
^permalinkrawreply [flat|nested] 59+ messages in thread

*Re: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
2019-08-13 7:30 ` Chunfeng Yun@ 2019-08-13 7:48 ` Roger Quadros
2019-08-13 8:50 ` Chunfeng Yun0 siblings, 1 reply; 59+ messages in thread
From: Roger Quadros @ 2019-08-13 7:48 UTC (permalink / raw)
To: Chunfeng Yun
Cc: Felipe Balbi, Heikki Krogerus, Pawel Laszczak, gregkh, linux-usb,
linux-kernel, jbergsagel, nsekhar, nm, Suresh Punnoose,
Jayshri Dajiram Pawar, Rahul Kumar, Anil Joy Varughese
On 13/08/2019 10:30, Chunfeng Yun wrote:
> On Mon, 2019-08-12 at 16:04 +0300, Roger Quadros wrote:
>>
>> On 12/08/2019 15:46, Felipe Balbi wrote:
>>>
>>> Hi,
>>>
>>> Roger Quadros <rogerq@ti.com> writes:
>>>>> 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?
>>>
>>> Use a 'disconnect' or 'suspend' event to go reset it? But that should,
>>> probably, be done at kernel space, no?
>>>
>>
>> Yes that could be one option.
>> So after a disconnect, sysfs role should reflect actual hardware role. correct?
>
> Maybe it's difficult to support both HW based role switch and SW based
> role switch by sysfs at the same if the HW's FSM rely on, such as, the
> state of Vbus pin or ID pin. Likes the upper example, when user writes
> "device" to mode switch sysfs, the driver should skip the HW state of ID
> pin, due to it's state is Low, or force it as High.
>
We do need a clear way of indicating that SW wants to override so HW
state is ignored.
> Another option way is that introduces a property in DTS to indicate the
> way the driver want to use (HW based or SW based, usb_role_switch
> doesn't provide this information for the controller driver), but is not
> flexible enough.
That is not good enough for us. We need both HW and SW based role switching.
Can we introduce a new state (e.g. "auto") in usb_role_switch. This would
explicitly indicate the driver to do HW based switching.
This way we don't need to depend on connect/disconnect events and can
do role switch tests even without cable/device connected.
--
cheers,
-roger
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
^permalinkrawreply [flat|nested] 59+ messages in thread

*Re: [PATCH v10 5/6] usb:cdns3 Add Cadence USB3 DRD Driver
2019-08-13 7:48 ` Roger Quadros@ 2019-08-13 8:50 ` Chunfeng Yun0 siblings, 0 replies; 59+ messages in thread
From: Chunfeng Yun @ 2019-08-13 8:50 UTC (permalink / raw)
To: Roger Quadros
Cc: Felipe Balbi, Heikki Krogerus, Pawel Laszczak, gregkh, linux-usb,
linux-kernel, jbergsagel, nsekhar, nm, Suresh Punnoose,
Jayshri Dajiram Pawar, Rahul Kumar, Anil Joy Varughese
On Tue, 2019-08-13 at 10:48 +0300, Roger Quadros wrote:
>
> On 13/08/2019 10:30, Chunfeng Yun wrote:
> > On Mon, 2019-08-12 at 16:04 +0300, Roger Quadros wrote:
> >>
> >> On 12/08/2019 15:46, Felipe Balbi wrote:
> >>>
> >>> Hi,
> >>>
> >>> Roger Quadros <rogerq@ti.com> writes:
> >>>>> 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?
> >>>
> >>> Use a 'disconnect' or 'suspend' event to go reset it? But that should,
> >>> probably, be done at kernel space, no?
> >>>
> >>
> >> Yes that could be one option.
> >> So after a disconnect, sysfs role should reflect actual hardware role. correct?
> >
> > Maybe it's difficult to support both HW based role switch and SW based
> > role switch by sysfs at the same if the HW's FSM rely on, such as, the
> > state of Vbus pin or ID pin. Likes the upper example, when user writes
> > "device" to mode switch sysfs, the driver should skip the HW state of ID
> > pin, due to it's state is Low, or force it as High.
> >
>
> We do need a clear way of indicating that SW wants to override so HW
> state is ignored.
>
> > Another option way is that introduces a property in DTS to indicate the
> > way the driver want to use (HW based or SW based, usb_role_switch
> > doesn't provide this information for the controller driver), but is not
> > flexible enough.
>
> That is not good enough for us. We need both HW and SW based role switching.
>
> Can we introduce a new state (e.g. "auto") in usb_role_switch. This would
> explicitly indicate the driver to do HW based switching.
But "auto" is not a role?
How about introducing a new attribute in usb_role_switch?
>
> This way we don't need to depend on connect/disconnect events and can
> do role switch tests even without cable/device connected.
>
^permalinkrawreply [flat|nested] 59+ messages in thread