Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751333AbdH0RZB (ORCPT ); Sun, 27 Aug 2017 13:25:01 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:59708 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751182AbdH0RZA (ORCPT ); Sun, 27 Aug 2017 13:25:00 -0400 Date: Sun, 27 Aug 2017 10:24:58 -0700 From: Guenter Roeck To: Badhri Jagan Sridharan Cc: Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 06/11 v2] staging: typec: tcpm: Comply with TryWait.SNK State Message-ID: <20170827172458.GQ22819@roeck-us.net> References: <20170827064921.2931-1-Badhri@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170827064921.2931-1-Badhri@google.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4268 Lines: 125 On Sat, Aug 26, 2017 at 11:49:21PM -0700, Badhri Jagan Sridharan wrote: > According to the spec: > "4.5.2.2.10.2 Exiting from TryWait.SNK State > The port shall transition to Attached.SNK after tCCDebounce if or when VBUS > is detected. Note the Source may initiate USB PD communications which will > cause brief periods of the SNK.Open state on both the CC1 and CC2 pins, > but this event will not exceed tPDDebounce. The port shall transition to > Unattached.SNK when the state of both of the CC1 and CC2 pins is SNK.Open > for at least tPDDebounce." > > Signed-off-by: Badhri Jagan Sridharan > --- > Changelog since v1: > - Corrected tag > For v2 up to here: Reviewed-by: Guenter Roeck > drivers/staging/typec/tcpm.c | 58 +++++++++++++++++++++++--------------------- > 1 file changed, 30 insertions(+), 28 deletions(-) > > diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c > index fc179bdea7e4..0ae33330a5c7 100644 > --- a/drivers/staging/typec/tcpm.c > +++ b/drivers/staging/typec/tcpm.c > @@ -2403,26 +2403,24 @@ static void run_state_machine(struct tcpm_port *port) > break; > case SNK_TRYWAIT: > tcpm_set_cc(port, TYPEC_CC_RD); > - tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, PD_T_CC_DEBOUNCE); > + tcpm_set_state(port, SNK_TRYWAIT_VBUS, PD_T_CC_DEBOUNCE); > break; > - case SNK_TRYWAIT_DEBOUNCE: > - if (port->vbus_present) { > + case SNK_TRYWAIT_VBUS: > + /* > + * TCPM stays in this state indefinitely until VBUS > + * is detected as long as Rp is not detected for > + * more than a time period of tPDDebounce. > + */ > + if (port->vbus_present && tcpm_port_is_sink(port)) { > tcpm_set_state(port, SNK_ATTACHED, 0); > break; > } > - if (tcpm_port_is_disconnected(port)) { > - tcpm_set_state(port, SNK_UNATTACHED, > - PD_T_PD_DEBOUNCE); > - break; > - } > - if (tcpm_port_is_source(port)) > - tcpm_set_state(port, SRC_ATTACHED, 0); > - /* XXX Are we supposed to stay in this state ? */ > + if (!tcpm_port_is_sink(port)) > + tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0); > break; > - case SNK_TRYWAIT_VBUS: > - tcpm_set_state(port, SNK_ATTACHED, PD_T_CC_DEBOUNCE); > + case SNK_TRYWAIT_DEBOUNCE: > + tcpm_set_state(port, SNK_UNATTACHED, PD_T_PD_DEBOUNCE); > break; > - > case SNK_ATTACHED: > ret = tcpm_snk_attach(port); > if (ret < 0) > @@ -2960,19 +2958,16 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, > tcpm_set_state(port, SRC_TRY_WAIT, 0); > break; > case SNK_TRYWAIT_DEBOUNCE: > - if (port->vbus_present) { > - tcpm_set_state(port, SNK_ATTACHED, 0); > - break; > - } > - if (tcpm_port_is_source(port)) { > - tcpm_set_state(port, SRC_ATTACHED, 0); > - break; > - } > - if (tcpm_port_is_disconnected(port) && > - port->delayed_state != SNK_UNATTACHED) > + if (tcpm_port_is_sink(port)) > + tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0); > + break; > + case SNK_TRYWAIT_VBUS: > + if (!tcpm_port_is_sink(port)) > tcpm_set_state(port, SNK_TRYWAIT_DEBOUNCE, 0); > break; > - > + case SNK_TRYWAIT: > + /* Do nothing, waiting for tCCDebounce */ > + break; > case PR_SWAP_SNK_SRC_SINK_OFF: > case PR_SWAP_SRC_SNK_TRANSITION_OFF: > case PR_SWAP_SRC_SNK_SOURCE_OFF: > @@ -3030,7 +3025,14 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port) > /* Do nothing, waiting for PD_DEBOUNCE to do be done */ > break; > case SNK_TRYWAIT: > - tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0); > + /* Do nothing, waiting for tCCDebounce */ > + break; > + case SNK_TRYWAIT_VBUS: > + if (tcpm_port_is_sink(port)) > + tcpm_set_state(port, SNK_ATTACHED, 0); > + break; > + case SNK_TRYWAIT_DEBOUNCE: > + /* Do nothing, waiting for Rp */ > break; > case SRC_TRY_WAIT: > case SRC_TRY_DEBOUNCE: > @@ -3067,10 +3069,10 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port) > case SNK_TRY_WAIT_DEBOUNCE: > /* Do nothing, waiting for PD_DEBOUNCE to do be done */ > break; > + case SNK_TRYWAIT: > case SNK_TRYWAIT_VBUS: > - tcpm_set_state(port, SNK_TRYWAIT, 0); > + case SNK_TRYWAIT_DEBOUNCE: > break; > - > case SNK_ATTACH_WAIT: > tcpm_set_state(port, SNK_UNATTACHED, 0); > break; > -- > 2.14.1.342.g6490525c54-goog >