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)