]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: typec: ps883x: Cache register settings, not Type-C mode
authorKonrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Tue, 14 Oct 2025 16:06:45 +0000 (18:06 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Oct 2025 08:58:31 +0000 (10:58 +0200)
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>
Link: https://patch.msgid.link/20251014-topic-ps883x_usb4-v1-1-e6adb1a4296e@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/mux/ps883x.c

index ad59babf7ccec8bbb152703052301734c941fbc7..68f172df7be3b57d468e9e345b1bbea1dc3acc22 100644 (file)
@@ -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)