mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Konrad Dybcio <konradybcio@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
	Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>,
	Wesley Cheng <wesley.cheng@oss.qualcomm.com>,
	Jack Pham <jack.pham@oss.qualcomm.com>,
	Raghavendra Thoorpu <rthoorpu@qti.qualcomm.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Subject: Re: [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set()
Date: Mon, 20 Oct 2025 12:49:27 +0300	[thread overview]
Message-ID: <aPYFpzD6sklAvywa@kuha.fi.intel.com> (raw)
In-Reply-To: <20251014-topic-ps883x_usb4-v1-2-e6adb1a4296e@oss.qualcomm.com>

On Tue, Oct 14, 2025 at 06:06:46PM +0200, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> In preparation to extend it with new alt/USB modes, rework the code a
> bit by changing the flow into a pair of switch statements.
> 
> Reviewed-by: Jack Pham <jack.pham@oss.qualcomm.com>
> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

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

> ---
>  drivers/usb/typec/mux/ps883x.c | 71 ++++++++++++++++++++++--------------------
>  1 file changed, 37 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/ps883x.c b/drivers/usb/typec/mux/ps883x.c
> index 68f172df7be3..72f1e737ca4b 100644
> --- a/drivers/usb/typec/mux/ps883x.c
> +++ b/drivers/usb/typec/mux/ps883x.c
> @@ -99,44 +99,47 @@ static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state
>  	int cfg1 = 0x00;
>  	int cfg2 = 0x00;
>  
> -	if (retimer->orientation == TYPEC_ORIENTATION_NONE ||
> -	    state->mode == TYPEC_STATE_SAFE) {
> -		return ps883x_configure(retimer, cfg0, cfg1, cfg2);
> -	}
> -
> -	if (state->alt && state->alt->svid != USB_TYPEC_DP_SID)
> -		return -EINVAL;
> -
>  	if (retimer->orientation == TYPEC_ORIENTATION_REVERSE)
>  		cfg0 |= CONN_STATUS_0_ORIENTATION_REVERSED;
>  
> -	switch (state->mode) {
> -	case TYPEC_STATE_USB:
> -		cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED;
> -		break;
> +	if (state->alt) {
> +		switch (state->alt->svid) {
> +		case USB_TYPEC_DP_SID:
> +			cfg1 |= CONN_STATUS_1_DP_CONNECTED |
> +				CONN_STATUS_1_DP_HPD_LEVEL;
>  
> -	case TYPEC_DP_STATE_C:
> -		cfg1 = CONN_STATUS_1_DP_CONNECTED |
> -		       CONN_STATUS_1_DP_SINK_REQUESTED |
> -		       CONN_STATUS_1_DP_PIN_ASSIGNMENT_C_D |
> -		       CONN_STATUS_1_DP_HPD_LEVEL;
> -		break;
> -
> -	case TYPEC_DP_STATE_D:
> -		cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED;
> -		cfg1 = CONN_STATUS_1_DP_CONNECTED |
> -		       CONN_STATUS_1_DP_SINK_REQUESTED |
> -		       CONN_STATUS_1_DP_PIN_ASSIGNMENT_C_D |
> -		       CONN_STATUS_1_DP_HPD_LEVEL;
> -		break;
> -
> -	case TYPEC_DP_STATE_E:
> -		cfg1 = CONN_STATUS_1_DP_CONNECTED |
> -		       CONN_STATUS_1_DP_HPD_LEVEL;
> -		break;
> -
> -	default:
> -		return -EOPNOTSUPP;
> +			switch (state->mode)  {
> +			case TYPEC_DP_STATE_C:
> +				cfg1 |= CONN_STATUS_1_DP_SINK_REQUESTED |
> +					CONN_STATUS_1_DP_PIN_ASSIGNMENT_C_D;
> +				fallthrough;
> +			case TYPEC_DP_STATE_D:
> +				cfg1 |= CONN_STATUS_0_USB_3_1_CONNECTED;
> +				break;
> +			default: /* MODE_E */
> +				break;
> +			}
> +			break;
> +		default:
> +			dev_err(&retimer->client->dev, "Got unsupported SID: 0x%x\n",
> +				state->alt->svid);
> +			return -EOPNOTSUPP;
> +		}
> +	} else {
> +		switch (state->mode) {
> +		case TYPEC_STATE_SAFE:
> +		/* USB2 pins don't even go through this chip */
> +		case TYPEC_MODE_USB2:
> +			break;
> +		case TYPEC_STATE_USB:
> +		case TYPEC_MODE_USB3:
> +			cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED;
> +			break;
> +		default:
> +			dev_err(&retimer->client->dev, "Got unsupported mode: %lu\n",
> +				state->mode);
> +			return -EOPNOTSUPP;
> +		}
>  	}
>  
>  	return ps883x_configure(retimer, cfg0, cfg1, cfg2);
> 
> -- 
> 2.51.0

-- 
heikki

  reply	other threads:[~2025-10-20  9:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 16:06 [PATCH 0/3] TBT3/USB4 support for PS8830 Konrad Dybcio
2025-10-14 16:06 ` [PATCH 1/3] usb: typec: ps883x: Cache register settings, not Type-C mode Konrad Dybcio
2025-10-20  9:43   ` Heikki Krogerus
2025-10-14 16:06 ` [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set() Konrad Dybcio
2025-10-20  9:49   ` Heikki Krogerus [this message]
2025-10-14 16:06 ` [PATCH 3/3] usb: typec: ps883x: Add USB4 mode and TBT3 altmode support Konrad Dybcio
2025-10-20  9:49   ` 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=aPYFpzD6sklAvywa@kuha.fi.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=bjorn.andersson@oss.qualcomm.com \
    --cc=dmitry.baryshkov@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jack.pham@oss.qualcomm.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=konradybcio@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=rthoorpu@qti.qualcomm.com \
    --cc=wesley.cheng@oss.qualcomm.com \
    /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

all inboxes | Powered by JetHome®