[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <949C620F-CA75-4A14-96DD-E42A349FC6EF@aosc.io>
Date: Wed, 18 Aug 2021 17:20:41 +0800
From: Icenowy Zheng <icenowy@...c.io>
To: Kyle Tso <kyletso@...gle.com>, Guenter Roeck <linux@...ck-us.net>
CC: Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
Badhri Jagan Sridharan <badhri@...gle.com>
Subject: Re: [PATCH] usb: typec: tcpm: always rediscover when swapping DR
于 2021年8月18日 GMT+08:00 下午4:02:24, Kyle Tso <kyletso@...gle.com> 写到:
>On Tue, Aug 17, 2021 at 11:13 PM Guenter Roeck <linux@...ck-us.net> wrote:
>>
>> On 8/17/21 2:36 AM, Heikki Krogerus wrote:
>> > On Fri, Aug 13, 2021 at 12:31:31PM +0800, Icenowy Zheng wrote:
>> >> Currently, TCPM code omits discover when swapping to gadget, and assume
>> >> that no altmodes are available when swapping from gadget. However, we do
>> >> send discover when we get attached as gadget -- this leads to modes to be
>> >> discovered twice when attached as gadget and then swap to host.
>> >>
>> >> Always re-send discover when swapping DR, regardless of what change is
>> >> being made; and because of this, the assumption that no altmodes are
>> >> registered with gadget role is broken, and altmodes de-registeration is
>> >> always needed now.
>> >>
>> >> Signed-off-by: Icenowy Zheng <icenowy@...c.io>
>> >> ---
>> >> drivers/usb/typec/tcpm/tcpm.c | 9 ++++-----
>> >> 1 file changed, 4 insertions(+), 5 deletions(-)
>> >>
>> >> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
>> >> index b9bb63d749ec..ab6d0d51ee1c 100644
>> >> --- a/drivers/usb/typec/tcpm/tcpm.c
>> >> +++ b/drivers/usb/typec/tcpm/tcpm.c
>> >> @@ -4495,15 +4495,14 @@ static void run_state_machine(struct tcpm_port *port)
>> >> tcpm_set_state(port, ready_state(port), 0);
>> >> break;
>> >> case DR_SWAP_CHANGE_DR:
>> >> - if (port->data_role == TYPEC_HOST) {
>> >> - tcpm_unregister_altmodes(port);
>> >> + tcpm_unregister_altmodes(port);
>> >> + if (port->data_role == TYPEC_HOST)
>> >> tcpm_set_roles(port, true, port->pwr_role,
>> >> TYPEC_DEVICE);
>> >> - } else {
>> >> + else
>> >> tcpm_set_roles(port, true, port->pwr_role,
>> >> TYPEC_HOST);
>> >> - port->send_discover = true;
>> >> - }
>> >> + port->send_discover = true;
>> >> tcpm_ams_finish(port);
>> >> tcpm_set_state(port, ready_state(port), 0);
>> >> break;
>> >
>> > Why is it necessary to do discovery with data role swap in general?
>> >
>> > thanks,
>> >
>>
>> Additional question: There are two patches pending related to DR_SWAP
>> and discovery. Are they both needed, or do they both solve the same
>> problem ?
>>
>> Thanks,
>> Guenter
>
>Hi, I just noticed this patch.
>
>Part of this patch and part of my patch
>https://lore.kernel.org/r/20210816075449.2236547-1-kyletso@google.com
>are to solve the same problem that Discover_Identity is not sent in a
>case where the port becomes UFP after DR_SWAP while in PD3.
>
>The difference (for the DR_SWAP part) is that my patch does not set
>the flag "send_discover" if the port becomes UFP after PD2 DR_SWAP.
>That is because in PD2 Spec, UFP is not allowed to be the SVDM
>Initiator.
>
>This patch indeed solves another problem where
>tcpm_unregister_altmodes should be called during PD3 DR_SWAP because
>the port partner may return mode data in the latest Discover_Mode. For
>the PD2 case, I don't think it needs to be called because PD2 DFP will
>always return NAK for Discover_Mode. However it is fine because it is
>safe to call tcpm_unregister_altmodes even if there is no mode data.
>
>In fact, when I was tracing the code I found another bug. PD2 UFP is
>not allowed to send Discover_Identity and Discover_Mode. I can send
>another patch to address this problem.
Well, to be honest, it's why I send this patch.
I didn't read PD spec before, so I assumed UFP is okay to send
discover, and this is what I got wrong. I should remove the
discover sending flag when we attach as sink.
Will it be okay for me to send this patch? It should help my device here.
>
>thanks,
>Kyle
Powered by blists - more mailing lists