[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251014-topic-ps883x_usb4-v1-1-e6adb1a4296e@oss.qualcomm.com>
Date: Tue, 14 Oct 2025 18:06:45 +0200
From: Konrad Dybcio <konradybcio@...nel.org>
To: Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Dmitry Baryshkov <dmitry.baryshkov@....qualcomm.com>,
Bjorn Andersson <bjorn.andersson@....qualcomm.com>,
Wesley Cheng <wesley.cheng@....qualcomm.com>,
Jack Pham <jack.pham@....qualcomm.com>,
Raghavendra Thoorpu <rthoorpu@....qualcomm.com>, linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org,
Konrad Dybcio <konrad.dybcio@....qualcomm.com>
Subject: [PATCH 1/3] usb: typec: ps883x: Cache register settings, not
Type-C mode
From: Konrad Dybcio <konrad.dybcio@....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@....qualcomm.com>
Signed-off-by: Konrad Dybcio <konrad.dybcio@....qualcomm.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
Powered by blists - more mailing lists