linux-usb.vger.kernel.org archive mirror
 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 3/3] usb: typec: tcpm: allow switching to mode accessory to mux properly
Date: Mon, 7 Apr 2025 16:50:13 +0300	[thread overview]
Message-ID: <Z_PYFT7IGMhX7gLO@kuha.fi.intel.com> (raw)
In-Reply-To: <20250404-ml-topic-tcpm-v1-3-b99f44badce8@pengutronix.de>

+Badhri

On Fri, Apr 04, 2025 at 12:43:06AM +0200, Michael Grzeschik wrote:
> The funciton tcpm_acc_attach is not setting the proper state when
> calling tcpm_set_role. The function tcpm_set_role is currently only
> handling TYPEC_STATE_USB. For the tcpm_acc_attach to switch into other
> modal states tcpm_set_role needs to be extended by an extra state
> parameter. This patch is handling the proper state change when calling
> tcpm_acc_attach.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>

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

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 01714a42f848a..784fa23102f90 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1153,7 +1153,7 @@ static int tcpm_set_attached_state(struct tcpm_port *port, bool attached)
>  				     port->data_role);
>  }
>  
> -static int tcpm_set_roles(struct tcpm_port *port, bool attached,
> +static int tcpm_set_roles(struct tcpm_port *port, bool attached, int state,
>  			  enum typec_role role, enum typec_data_role data)
>  {
>  	enum typec_orientation orientation;
> @@ -1190,7 +1190,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,
>  		}
>  	}
>  
> -	ret = tcpm_mux_set(port, TYPEC_STATE_USB, usb_role, orientation);
> +	ret = tcpm_mux_set(port, state, usb_role, orientation);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -4355,7 +4355,8 @@ static int tcpm_src_attach(struct tcpm_port *port)
>  
>  	tcpm_enable_auto_vbus_discharge(port, true);
>  
> -	ret = tcpm_set_roles(port, true, TYPEC_SOURCE, tcpm_data_role_for_source(port));
> +	ret = tcpm_set_roles(port, true, TYPEC_STATE_USB,
> +			     TYPEC_SOURCE, tcpm_data_role_for_source(port));
>  	if (ret < 0)
>  		return ret;
>  
> @@ -4530,7 +4531,8 @@ static int tcpm_snk_attach(struct tcpm_port *port)
>  
>  	tcpm_enable_auto_vbus_discharge(port, true);
>  
> -	ret = tcpm_set_roles(port, true, TYPEC_SINK, tcpm_data_role_for_sink(port));
> +	ret = tcpm_set_roles(port, true, TYPEC_STATE_USB,
> +			     TYPEC_SINK, tcpm_data_role_for_sink(port));
>  	if (ret < 0)
>  		return ret;
>  
> @@ -4555,6 +4557,7 @@ static int tcpm_acc_attach(struct tcpm_port *port)
>  	int ret;
>  	enum typec_role role;
>  	enum typec_data_role data;
> +	int state = TYPEC_STATE_USB;
>  
>  	if (port->attached)
>  		return 0;
> @@ -4563,7 +4566,13 @@ static int tcpm_acc_attach(struct tcpm_port *port)
>  	data = tcpm_port_is_sink(port) ? tcpm_data_role_for_sink(port)
>  				       : tcpm_data_role_for_source(port);
>  
> -	ret = tcpm_set_roles(port, true, role, data);
> +	if (tcpm_port_is_audio(port))
> +		state = TYPEC_MODE_AUDIO;
> +
> +	if (tcpm_port_is_debug(port))
> +		state = TYPEC_MODE_DEBUG;
> +
> +	ret = tcpm_set_roles(port, true, state, role, data);
>  	if (ret < 0)
>  		return ret;
>  
> @@ -5349,7 +5358,7 @@ static void run_state_machine(struct tcpm_port *port)
>  		 */
>  		tcpm_set_vconn(port, false);
>  		tcpm_set_vbus(port, false);
> -		tcpm_set_roles(port, port->self_powered, TYPEC_SOURCE,
> +		tcpm_set_roles(port, port->self_powered, TYPEC_STATE_USB, TYPEC_SOURCE,
>  			       tcpm_data_role_for_source(port));
>  		/*
>  		 * If tcpc fails to notify vbus off, TCPM will wait for PD_T_SAFE_0V +
> @@ -5381,7 +5390,7 @@ static void run_state_machine(struct tcpm_port *port)
>  		tcpm_set_vconn(port, false);
>  		if (port->pd_capable)
>  			tcpm_set_charge(port, false);
> -		tcpm_set_roles(port, port->self_powered, TYPEC_SINK,
> +		tcpm_set_roles(port, port->self_powered, TYPEC_STATE_USB, TYPEC_SINK,
>  			       tcpm_data_role_for_sink(port));
>  		/*
>  		 * VBUS may or may not toggle, depending on the adapter.
> @@ -5505,10 +5514,10 @@ static void run_state_machine(struct tcpm_port *port)
>  	case DR_SWAP_CHANGE_DR:
>  		tcpm_unregister_altmodes(port);
>  		if (port->data_role == TYPEC_HOST)
> -			tcpm_set_roles(port, true, port->pwr_role,
> +			tcpm_set_roles(port, true, TYPEC_STATE_USB, port->pwr_role,
>  				       TYPEC_DEVICE);
>  		else
> -			tcpm_set_roles(port, true, port->pwr_role,
> +			tcpm_set_roles(port, true, TYPEC_STATE_USB, port->pwr_role,
>  				       TYPEC_HOST);
>  		tcpm_ams_finish(port);
>  		tcpm_set_state(port, ready_state(port), 0);
> 
> -- 
> 2.39.5

-- 
heikki

      reply	other threads:[~2025-04-07 13:50 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
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 [this message]

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_PYFT7IGMhX7gLO@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;
as well as URLs for NNTP newsgroup(s).