Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: typec: ps883x: Rework ps883x_set()

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>
Link: https://patch.msgid.link/20251014-topic-ps883x_usb4-v1-2-e6adb1a4296e@oss.qualcomm.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Konrad Dybcio and committed by
Greg Kroah-Hartman
6bebd9b7 f83cb615

+37 -34
+37 -34
drivers/usb/typec/mux/ps883x.c
··· 99 99 int cfg1 = 0x00; 100 100 int cfg2 = 0x00; 101 101 102 - if (retimer->orientation == TYPEC_ORIENTATION_NONE || 103 - state->mode == TYPEC_STATE_SAFE) { 104 - return ps883x_configure(retimer, cfg0, cfg1, cfg2); 105 - } 106 - 107 - if (state->alt && state->alt->svid != USB_TYPEC_DP_SID) 108 - return -EINVAL; 109 - 110 102 if (retimer->orientation == TYPEC_ORIENTATION_REVERSE) 111 103 cfg0 |= CONN_STATUS_0_ORIENTATION_REVERSED; 112 104 113 - switch (state->mode) { 114 - case TYPEC_STATE_USB: 115 - cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED; 116 - break; 105 + if (state->alt) { 106 + switch (state->alt->svid) { 107 + case USB_TYPEC_DP_SID: 108 + cfg1 |= CONN_STATUS_1_DP_CONNECTED | 109 + CONN_STATUS_1_DP_HPD_LEVEL; 117 110 118 - case TYPEC_DP_STATE_C: 119 - cfg1 = CONN_STATUS_1_DP_CONNECTED | 120 - CONN_STATUS_1_DP_SINK_REQUESTED | 121 - CONN_STATUS_1_DP_PIN_ASSIGNMENT_C_D | 122 - CONN_STATUS_1_DP_HPD_LEVEL; 123 - break; 124 - 125 - case TYPEC_DP_STATE_D: 126 - cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED; 127 - cfg1 = CONN_STATUS_1_DP_CONNECTED | 128 - CONN_STATUS_1_DP_SINK_REQUESTED | 129 - CONN_STATUS_1_DP_PIN_ASSIGNMENT_C_D | 130 - CONN_STATUS_1_DP_HPD_LEVEL; 131 - break; 132 - 133 - case TYPEC_DP_STATE_E: 134 - cfg1 = CONN_STATUS_1_DP_CONNECTED | 135 - CONN_STATUS_1_DP_HPD_LEVEL; 136 - break; 137 - 138 - default: 139 - return -EOPNOTSUPP; 111 + switch (state->mode) { 112 + case TYPEC_DP_STATE_C: 113 + cfg1 |= CONN_STATUS_1_DP_SINK_REQUESTED | 114 + CONN_STATUS_1_DP_PIN_ASSIGNMENT_C_D; 115 + fallthrough; 116 + case TYPEC_DP_STATE_D: 117 + cfg1 |= CONN_STATUS_0_USB_3_1_CONNECTED; 118 + break; 119 + default: /* MODE_E */ 120 + break; 121 + } 122 + break; 123 + default: 124 + dev_err(&retimer->client->dev, "Got unsupported SID: 0x%x\n", 125 + state->alt->svid); 126 + return -EOPNOTSUPP; 127 + } 128 + } else { 129 + switch (state->mode) { 130 + case TYPEC_STATE_SAFE: 131 + /* USB2 pins don't even go through this chip */ 132 + case TYPEC_MODE_USB2: 133 + break; 134 + case TYPEC_STATE_USB: 135 + case TYPEC_MODE_USB3: 136 + cfg0 |= CONN_STATUS_0_USB_3_1_CONNECTED; 137 + break; 138 + default: 139 + dev_err(&retimer->client->dev, "Got unsupported mode: %lu\n", 140 + state->mode); 141 + return -EOPNOTSUPP; 142 + } 140 143 } 141 144 142 145 return ps883x_configure(retimer, cfg0, cfg1, cfg2);