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 1/3] usb: typec: ps883x: Cache register settings, not Type-C mode
Date: Mon, 20 Oct 2025 12:43:34 +0300	[thread overview]
Message-ID: <aPYERtFRKx6jdh_R@kuha.fi.intel.com> (raw)
In-Reply-To: <20251014-topic-ps883x_usb4-v1-1-e6adb1a4296e@oss.qualcomm.com>

On Tue, Oct 14, 2025 at 06:06:45PM +0200, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> Certain Type-C mode configurations may result in identical settings of
> the PS8830. Check if the latter have changed instead of assuming
> there's always a difference.
> 
> ps883x_set() is changed to accept a typec_retimer_state in preparation
> for more work and the ps883x_sw_set() (which only handles orientation
> switching) is changed to use regmap_assign_bits(), which itself does
> not perform any writes if the desired value is already set.
> 
> 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 | 41 ++++++++++++++++++++++-------------------
>  1 file changed, 22 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/ps883x.c b/drivers/usb/typec/mux/ps883x.c
> index ad59babf7cce..68f172df7be3 100644
> --- a/drivers/usb/typec/mux/ps883x.c
> +++ b/drivers/usb/typec/mux/ps883x.c
> @@ -54,8 +54,9 @@ struct ps883x_retimer {
>  	struct mutex lock; /* protect non-concurrent retimer & switch */
>  
>  	enum typec_orientation orientation;
> -	unsigned long mode;
> -	unsigned int svid;
> +	u8 cfg0;
> +	u8 cfg1;
> +	u8 cfg2;
>  };
>  
>  static int ps883x_configure(struct ps883x_retimer *retimer, int cfg0,
> @@ -64,6 +65,9 @@ static int ps883x_configure(struct ps883x_retimer *retimer, int cfg0,
>  	struct device *dev = &retimer->client->dev;
>  	int ret;
>  
> +	if (retimer->cfg0 == cfg0 && retimer->cfg1 == cfg1 && retimer->cfg2 == cfg2)
> +		return 0;
> +
>  	ret = regmap_write(retimer->regmap, REG_USB_PORT_CONN_STATUS_0, cfg0);
>  	if (ret) {
>  		dev_err(dev, "failed to write conn_status_0: %d\n", ret);
> @@ -82,27 +86,31 @@ static int ps883x_configure(struct ps883x_retimer *retimer, int cfg0,
>  		return ret;
>  	}
>  
> +	retimer->cfg0 = cfg0;
> +	retimer->cfg1 = cfg1;
> +	retimer->cfg2 = cfg2;
> +
>  	return 0;
>  }
>  
> -static int ps883x_set(struct ps883x_retimer *retimer)
> +static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state *state)
>  {
>  	int cfg0 = CONN_STATUS_0_CONNECTION_PRESENT;
>  	int cfg1 = 0x00;
>  	int cfg2 = 0x00;
>  
>  	if (retimer->orientation == TYPEC_ORIENTATION_NONE ||
> -	    retimer->mode == TYPEC_STATE_SAFE) {
> +	    state->mode == TYPEC_STATE_SAFE) {
>  		return ps883x_configure(retimer, cfg0, cfg1, cfg2);
>  	}
>  
> -	if (retimer->mode != TYPEC_STATE_USB && retimer->svid != USB_TYPEC_DP_SID)
> +	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 (retimer->mode) {
> +	switch (state->mode) {
>  	case TYPEC_STATE_USB:
>  		cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED;
>  		break;
> @@ -149,7 +157,13 @@ static int ps883x_sw_set(struct typec_switch_dev *sw,
>  	if (retimer->orientation != orientation) {
>  		retimer->orientation = orientation;
>  
> -		ret = ps883x_set(retimer);
> +		ret = regmap_assign_bits(retimer->regmap, REG_USB_PORT_CONN_STATUS_0,
> +					 CONN_STATUS_0_ORIENTATION_REVERSED,
> +					 orientation == TYPEC_ORIENTATION_REVERSE);
> +		if (ret) {
> +			dev_err(&retimer->client->dev, "failed to set orientation: %d\n", ret);
> +			return ret;
> +		}
>  	}
>  
>  	mutex_unlock(&retimer->lock);
> @@ -165,18 +179,7 @@ static int ps883x_retimer_set(struct typec_retimer *rtmr,
>  	int ret = 0;
>  
>  	mutex_lock(&retimer->lock);
> -
> -	if (state->mode != retimer->mode) {
> -		retimer->mode = state->mode;
> -
> -		if (state->alt)
> -			retimer->svid = state->alt->svid;
> -		else
> -			retimer->svid = 0;
> -
> -		ret = ps883x_set(retimer);
> -	}
> -
> +	ret = ps883x_set(retimer, state);
>  	mutex_unlock(&retimer->lock);
>  
>  	if (ret)
> 
> -- 
> 2.51.0

-- 
heikki

  reply	other threads:[~2025-10-20  9:43 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 [this message]
2025-10-14 16:06 ` [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set() Konrad Dybcio
2025-10-20  9:49   ` Heikki Krogerus
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=aPYERtFRKx6jdh_R@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®