public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Michael Grzeschik <m.grzeschik@pengutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@pengutronix.de, Badhri Jagan Sridharan <badhri@google.com>
Subject: Re: [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug
Date: Mon, 7 Apr 2025 16:48:11 +0300	[thread overview]
Message-ID: <Z_PXm5XbFk52jq_-@kuha.fi.intel.com> (raw)
In-Reply-To: <20250404-ml-topic-tcpm-v1-2-b99f44badce8@pengutronix.de>

+Badhri

On Fri, Apr 04, 2025 at 12:43:05AM +0200, Michael Grzeschik wrote:
> This patch extends the is_debug macro to cover the sink case (ufp). It
> also handles the transition to access the DEBUG_ACC_ATTACHED state in
> the sink case. It also handles the debounce case in which the cc
> pins are not immediately valid after the plug event.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 34 +++++++++++++++++++++++++++++-----
>  1 file changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 839697c14265e..01714a42f848a 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -67,6 +67,7 @@
>  						\
>  	S(ACC_UNATTACHED),			\
>  	S(DEBUG_ACC_ATTACHED),			\
> +	S(DEBUG_ACC_DEBOUNCE),			\
>  	S(AUDIO_ACC_ATTACHED),			\
>  	S(AUDIO_ACC_DEBOUNCE),			\
>  						\
> @@ -621,7 +622,8 @@ static const char * const pd_rev[] = {
>  	  !tcpm_cc_is_source((port)->cc1)))
>  
>  #define tcpm_port_is_debug(port) \
> -	(tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2))
> +	((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \
> +	 (tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2)))
>  
>  #define tcpm_port_is_audio(port) \
>  	(tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2))
> @@ -4969,7 +4971,13 @@ static void run_state_machine(struct tcpm_port *port)
>  			tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
>  		break;
>  	case SNK_ATTACH_WAIT:
> -		if ((port->cc1 == TYPEC_CC_OPEN &&
> +		if (tcpm_port_is_debug(port))
> +			tcpm_set_state(port, DEBUG_ACC_ATTACHED,
> +				       PD_T_CC_DEBOUNCE);
> +		else if (tcpm_port_is_audio(port))
> +			tcpm_set_state(port, AUDIO_ACC_ATTACHED,
> +				       PD_T_CC_DEBOUNCE);
> +		else if ((port->cc1 == TYPEC_CC_OPEN &&
>  		     port->cc2 != TYPEC_CC_OPEN) ||
>  		    (port->cc1 != TYPEC_CC_OPEN &&
>  		     port->cc2 == TYPEC_CC_OPEN))
> @@ -4983,6 +4991,12 @@ static void run_state_machine(struct tcpm_port *port)
>  		if (tcpm_port_is_disconnected(port))
>  			tcpm_set_state(port, SNK_UNATTACHED,
>  				       PD_T_PD_DEBOUNCE);
> +		else if (tcpm_port_is_debug(port))
> +			tcpm_set_state(port, DEBUG_ACC_ATTACHED,
> +				       PD_T_CC_DEBOUNCE);
> +		else if (tcpm_port_is_audio(port))
> +			tcpm_set_state(port, AUDIO_ACC_ATTACHED,
> +				       PD_T_CC_DEBOUNCE);
>  		else if (port->vbus_present)
>  			tcpm_set_state(port,
>  				       tcpm_try_src(port) ? SRC_TRY
> @@ -5281,7 +5295,10 @@ static void run_state_machine(struct tcpm_port *port)
>  	/* Accessory states */
>  	case ACC_UNATTACHED:
>  		tcpm_acc_detach(port);
> -		tcpm_set_state(port, SRC_UNATTACHED, 0);
> +		if (port->port_type == TYPEC_PORT_SRC)
> +			tcpm_set_state(port, SRC_UNATTACHED, 0);
> +		else
> +			tcpm_set_state(port, SNK_UNATTACHED, 0);
>  		break;
>  	case DEBUG_ACC_ATTACHED:
>  	case AUDIO_ACC_ATTACHED:
> @@ -5289,6 +5306,7 @@ static void run_state_machine(struct tcpm_port *port)
>  		if (ret < 0)
>  			tcpm_set_state(port, ACC_UNATTACHED, 0);
>  		break;
> +	case DEBUG_ACC_DEBOUNCE:
>  	case AUDIO_ACC_DEBOUNCE:
>  		tcpm_set_state(port, ACC_UNATTACHED, port->timings.cc_debounce_time);
>  		break;
> @@ -5880,7 +5898,8 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
>  		}
>  		break;
>  	case SNK_UNATTACHED:
> -		if (tcpm_port_is_sink(port))
> +		if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
> +		    tcpm_port_is_sink(port))
>  			tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
>  		break;
>  	case SNK_ATTACH_WAIT:
> @@ -5943,7 +5962,12 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
>  
>  	case DEBUG_ACC_ATTACHED:
>  		if (cc1 == TYPEC_CC_OPEN || cc2 == TYPEC_CC_OPEN)
> -			tcpm_set_state(port, ACC_UNATTACHED, 0);
> +			tcpm_set_state(port, DEBUG_ACC_DEBOUNCE, 0);
> +		break;
> +
> +	case DEBUG_ACC_DEBOUNCE:
> +		if (tcpm_port_is_debug(port))
> +			tcpm_set_state(port, DEBUG_ACC_ATTACHED, 0);
>  		break;
>  
>  	case SNK_TRY:
> 
> -- 
> 2.39.5

-- 
heikki

  reply	other threads:[~2025-04-07 13:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 22:43 [PATCH 0/3] usb: typec: tcpm: sink (ufp) accessory mode support Michael Grzeschik
2025-04-03 22:43 ` [PATCH 1/3] usb: typec: tcpm: allow to use sink in accessory mode Michael Grzeschik
2025-04-07 13:46   ` Heikki Krogerus
2025-04-03 22:43 ` [PATCH 2/3] usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug Michael Grzeschik
2025-04-07 13:48   ` Heikki Krogerus [this message]
2025-04-03 22:43 ` [PATCH 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly Michael Grzeschik
2025-04-07 13:50   ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z_PXm5XbFk52jq_-@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.grzeschik@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox