* [PATCH 0/3] TBT3/USB4 support for PS8830
@ 2025-10-14 16:06 Konrad Dybcio
2025-10-14 16:06 ` [PATCH 1/3] usb: typec: ps883x: Cache register settings, not Type-C mode Konrad Dybcio
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Konrad Dybcio @ 2025-10-14 16:06 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: Dmitry Baryshkov, Bjorn Andersson, Wesley Cheng, Jack Pham,
Raghavendra Thoorpu, linux-usb, linux-kernel, Konrad Dybcio
As the product page [1] states, the chip is actually capable of
retiming USB4 and Thunderbolt 3 (4, even!) signals, while remaining
spec-compliant.
This series reworks the driver a little and introduces support for the
new aforementioned modes.
I carried Jack's Reviewed-by tags from an internal preview submission,
which I hope is fine with everyone.
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
Konrad Dybcio (3):
usb: typec: ps883x: Cache register settings, not Type-C mode
usb: typec: ps883x: Rework ps883x_set()
usb: typec: ps883x: Add USB4 mode and TBT3 altmode support
drivers/usb/typec/mux/ps883x.c | 129 ++++++++++++++++++++++++++---------------
include/linux/usb/typec_tbt.h | 1 +
2 files changed, 83 insertions(+), 47 deletions(-)
---
base-commit: 52ba76324a9d7c39830c850999210a36ef023cde
change-id: 20251006-topic-ps883x_usb4-32d4c3abaac1
Best regards,
--
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] usb: typec: ps883x: Cache register settings, not Type-C mode
2025-10-14 16:06 [PATCH 0/3] TBT3/USB4 support for PS8830 Konrad Dybcio
@ 2025-10-14 16:06 ` 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-14 16:06 ` [PATCH 3/3] usb: typec: ps883x: Add USB4 mode and TBT3 altmode support Konrad Dybcio
2 siblings, 1 reply; 7+ messages in thread
From: Konrad Dybcio @ 2025-10-14 16:06 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: Dmitry Baryshkov, Bjorn Andersson, Wesley Cheng, Jack Pham,
Raghavendra Thoorpu, linux-usb, linux-kernel, Konrad Dybcio
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>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set()
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-14 16:06 ` 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
2 siblings, 1 reply; 7+ messages in thread
From: Konrad Dybcio @ 2025-10-14 16:06 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: Dmitry Baryshkov, Bjorn Andersson, Wesley Cheng, Jack Pham,
Raghavendra Thoorpu, linux-usb, linux-kernel, Konrad Dybcio
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>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] usb: typec: ps883x: Add USB4 mode and TBT3 altmode support
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-14 16:06 ` [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set() Konrad Dybcio
@ 2025-10-14 16:06 ` Konrad Dybcio
2025-10-20 9:49 ` Heikki Krogerus
2 siblings, 1 reply; 7+ messages in thread
From: Konrad Dybcio @ 2025-10-14 16:06 UTC (permalink / raw)
To: Heikki Krogerus, Greg Kroah-Hartman
Cc: Dmitry Baryshkov, Bjorn Andersson, Wesley Cheng, Jack Pham,
Raghavendra Thoorpu, linux-usb, linux-kernel, Konrad Dybcio
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
This chip can do some more than the driver currently describes. Add
support for configuring it for various flavors of TBT3/USB4 operation.
Reviewed-by: Jack Pham <jack.pham@oss.qualcomm.com>
Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
---
drivers/usb/typec/mux/ps883x.c | 29 +++++++++++++++++++++++++++++
include/linux/usb/typec_tbt.h | 1 +
2 files changed, 30 insertions(+)
diff --git a/drivers/usb/typec/mux/ps883x.c b/drivers/usb/typec/mux/ps883x.c
index 72f1e737ca4b..7c61629b36d6 100644
--- a/drivers/usb/typec/mux/ps883x.c
+++ b/drivers/usb/typec/mux/ps883x.c
@@ -14,15 +14,18 @@
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
+#include <linux/usb/pd.h>
#include <linux/usb/typec_altmode.h>
#include <linux/usb/typec_dp.h>
#include <linux/usb/typec_mux.h>
#include <linux/usb/typec_retimer.h>
+#include <linux/usb/typec_tbt.h>
#define REG_USB_PORT_CONN_STATUS_0 0x00
#define CONN_STATUS_0_CONNECTION_PRESENT BIT(0)
#define CONN_STATUS_0_ORIENTATION_REVERSED BIT(1)
+#define CONN_STATUS_0_ACTIVE_CABLE BIT(2)
#define CONN_STATUS_0_USB_3_1_CONNECTED BIT(5)
#define REG_USB_PORT_CONN_STATUS_1 0x01
@@ -34,6 +37,10 @@
#define REG_USB_PORT_CONN_STATUS_2 0x02
+#define CONN_STATUS_2_TBT_CONNECTED BIT(0)
+#define CONN_STATUS_2_TBT_UNIDIR_LSRX_ACT_LT BIT(4)
+#define CONN_STATUS_2_USB4_CONNECTED BIT(7)
+
struct ps883x_retimer {
struct i2c_client *client;
struct gpio_desc *reset_gpio;
@@ -95,6 +102,8 @@ static int ps883x_configure(struct ps883x_retimer *retimer, int cfg0,
static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state *state)
{
+ struct typec_thunderbolt_data *tb_data;
+ const struct enter_usb_data *eudo_data;
int cfg0 = CONN_STATUS_0_CONNECTION_PRESENT;
int cfg1 = 0x00;
int cfg2 = 0x00;
@@ -120,6 +129,18 @@ static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state
break;
}
break;
+ case USB_TYPEC_TBT_SID:
+ tb_data = state->data;
+
+ /* Unconditional */
+ cfg2 |= CONN_STATUS_2_TBT_CONNECTED;
+
+ if (tb_data->cable_mode & TBT_CABLE_ACTIVE_PASSIVE)
+ cfg0 |= CONN_STATUS_0_ACTIVE_CABLE;
+
+ if (tb_data->enter_vdo & TBT_ENTER_MODE_UNI_DIR_LSRX)
+ cfg2 |= CONN_STATUS_2_TBT_UNIDIR_LSRX_ACT_LT;
+ break;
default:
dev_err(&retimer->client->dev, "Got unsupported SID: 0x%x\n",
state->alt->svid);
@@ -135,6 +156,14 @@ static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state
case TYPEC_MODE_USB3:
cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED;
break;
+ case TYPEC_MODE_USB4:
+ eudo_data = state->data;
+
+ cfg2 |= CONN_STATUS_2_USB4_CONNECTED;
+
+ if (FIELD_GET(EUDO_CABLE_TYPE_MASK, eudo_data->eudo) != EUDO_CABLE_TYPE_PASSIVE)
+ cfg0 |= CONN_STATUS_0_ACTIVE_CABLE;
+ break;
default:
dev_err(&retimer->client->dev, "Got unsupported mode: %lu\n",
state->mode);
diff --git a/include/linux/usb/typec_tbt.h b/include/linux/usb/typec_tbt.h
index 55dcea12082c..0b570f1b8bc8 100644
--- a/include/linux/usb/typec_tbt.h
+++ b/include/linux/usb/typec_tbt.h
@@ -55,6 +55,7 @@ struct typec_thunderbolt_data {
/* TBT3 Device Enter Mode VDO bits */
#define TBT_ENTER_MODE_CABLE_SPEED(s) TBT_SET_CABLE_SPEED(s)
+#define TBT_ENTER_MODE_UNI_DIR_LSRX BIT(23)
#define TBT_ENTER_MODE_ACTIVE_CABLE BIT(24)
#endif /* __USB_TYPEC_TBT_H */
--
2.51.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] usb: typec: ps883x: Cache register settings, not Type-C mode
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
0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2025-10-20 9:43 UTC (permalink / raw)
To: Konrad Dybcio
Cc: Greg Kroah-Hartman, Dmitry Baryshkov, Bjorn Andersson,
Wesley Cheng, Jack Pham, Raghavendra Thoorpu, linux-usb,
linux-kernel, Konrad Dybcio
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set()
2025-10-14 16:06 ` [PATCH 2/3] usb: typec: ps883x: Rework ps883x_set() Konrad Dybcio
@ 2025-10-20 9:49 ` Heikki Krogerus
0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2025-10-20 9:49 UTC (permalink / raw)
To: Konrad Dybcio
Cc: Greg Kroah-Hartman, Dmitry Baryshkov, Bjorn Andersson,
Wesley Cheng, Jack Pham, Raghavendra Thoorpu, linux-usb,
linux-kernel, Konrad Dybcio
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] usb: typec: ps883x: Add USB4 mode and TBT3 altmode support
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
0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2025-10-20 9:49 UTC (permalink / raw)
To: Konrad Dybcio
Cc: Greg Kroah-Hartman, Dmitry Baryshkov, Bjorn Andersson,
Wesley Cheng, Jack Pham, Raghavendra Thoorpu, linux-usb,
linux-kernel, Konrad Dybcio
On Tue, Oct 14, 2025 at 06:06:47PM +0200, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
>
> This chip can do some more than the driver currently describes. Add
> support for configuring it for various flavors of TBT3/USB4 operation.
>
> 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 | 29 +++++++++++++++++++++++++++++
> include/linux/usb/typec_tbt.h | 1 +
> 2 files changed, 30 insertions(+)
>
> diff --git a/drivers/usb/typec/mux/ps883x.c b/drivers/usb/typec/mux/ps883x.c
> index 72f1e737ca4b..7c61629b36d6 100644
> --- a/drivers/usb/typec/mux/ps883x.c
> +++ b/drivers/usb/typec/mux/ps883x.c
> @@ -14,15 +14,18 @@
> #include <linux/mutex.h>
> #include <linux/regmap.h>
> #include <linux/regulator/consumer.h>
> +#include <linux/usb/pd.h>
> #include <linux/usb/typec_altmode.h>
> #include <linux/usb/typec_dp.h>
> #include <linux/usb/typec_mux.h>
> #include <linux/usb/typec_retimer.h>
> +#include <linux/usb/typec_tbt.h>
>
> #define REG_USB_PORT_CONN_STATUS_0 0x00
>
> #define CONN_STATUS_0_CONNECTION_PRESENT BIT(0)
> #define CONN_STATUS_0_ORIENTATION_REVERSED BIT(1)
> +#define CONN_STATUS_0_ACTIVE_CABLE BIT(2)
> #define CONN_STATUS_0_USB_3_1_CONNECTED BIT(5)
>
> #define REG_USB_PORT_CONN_STATUS_1 0x01
> @@ -34,6 +37,10 @@
>
> #define REG_USB_PORT_CONN_STATUS_2 0x02
>
> +#define CONN_STATUS_2_TBT_CONNECTED BIT(0)
> +#define CONN_STATUS_2_TBT_UNIDIR_LSRX_ACT_LT BIT(4)
> +#define CONN_STATUS_2_USB4_CONNECTED BIT(7)
> +
> struct ps883x_retimer {
> struct i2c_client *client;
> struct gpio_desc *reset_gpio;
> @@ -95,6 +102,8 @@ static int ps883x_configure(struct ps883x_retimer *retimer, int cfg0,
>
> static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state *state)
> {
> + struct typec_thunderbolt_data *tb_data;
> + const struct enter_usb_data *eudo_data;
> int cfg0 = CONN_STATUS_0_CONNECTION_PRESENT;
> int cfg1 = 0x00;
> int cfg2 = 0x00;
> @@ -120,6 +129,18 @@ static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state
> break;
> }
> break;
> + case USB_TYPEC_TBT_SID:
> + tb_data = state->data;
> +
> + /* Unconditional */
> + cfg2 |= CONN_STATUS_2_TBT_CONNECTED;
> +
> + if (tb_data->cable_mode & TBT_CABLE_ACTIVE_PASSIVE)
> + cfg0 |= CONN_STATUS_0_ACTIVE_CABLE;
> +
> + if (tb_data->enter_vdo & TBT_ENTER_MODE_UNI_DIR_LSRX)
> + cfg2 |= CONN_STATUS_2_TBT_UNIDIR_LSRX_ACT_LT;
> + break;
> default:
> dev_err(&retimer->client->dev, "Got unsupported SID: 0x%x\n",
> state->alt->svid);
> @@ -135,6 +156,14 @@ static int ps883x_set(struct ps883x_retimer *retimer, struct typec_retimer_state
> case TYPEC_MODE_USB3:
> cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED;
> break;
> + case TYPEC_MODE_USB4:
> + eudo_data = state->data;
> +
> + cfg2 |= CONN_STATUS_2_USB4_CONNECTED;
> +
> + if (FIELD_GET(EUDO_CABLE_TYPE_MASK, eudo_data->eudo) != EUDO_CABLE_TYPE_PASSIVE)
> + cfg0 |= CONN_STATUS_0_ACTIVE_CABLE;
> + break;
> default:
> dev_err(&retimer->client->dev, "Got unsupported mode: %lu\n",
> state->mode);
> diff --git a/include/linux/usb/typec_tbt.h b/include/linux/usb/typec_tbt.h
> index 55dcea12082c..0b570f1b8bc8 100644
> --- a/include/linux/usb/typec_tbt.h
> +++ b/include/linux/usb/typec_tbt.h
> @@ -55,6 +55,7 @@ struct typec_thunderbolt_data {
>
> /* TBT3 Device Enter Mode VDO bits */
> #define TBT_ENTER_MODE_CABLE_SPEED(s) TBT_SET_CABLE_SPEED(s)
> +#define TBT_ENTER_MODE_UNI_DIR_LSRX BIT(23)
> #define TBT_ENTER_MODE_ACTIVE_CABLE BIT(24)
>
> #endif /* __USB_TYPEC_TBT_H */
>
> --
> 2.51.0
--
heikki
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-10-20 9:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).