Skip to content

Commit 3cb2b8e

Browse files
vphiremaCommit Bot
authored and
Commit Bot
committed
usb_mux: cleanup the usb_mux_get() function
Simplified the usb_mux_get() function and made the MUX info prints same as in ectool. BUG=none BRANCH=none TEST=make buildall -j Change-Id: Iefb16e1dbd323afbe248b06fe9c53abc63be9a67 Signed-off-by: Vijay Hiremath <[email protected]> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1931284 Reviewed-by: Jett Rink <[email protected]>
1 parent 3e2f184 commit 3cb2b8e

File tree

6 files changed

+22
-41
lines changed

6 files changed

+22
-41
lines changed

Diff for: board/cheza/usb_pd_policy.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,10 @@ static void svdm_dp_post_config(int port)
373373
static int is_dp_muxable(int port)
374374
{
375375
int i;
376-
const char *dp_str, *usb_str;
377376

378377
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
379378
if (i != port) {
380-
usb_mux_get(i, &dp_str, &usb_str);
381-
if (dp_str)
379+
if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED)
382380
return 0;
383381
}
384382

Diff for: board/elm/usb_pd_policy.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ static uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
215215

216216
static void svdm_safe_dp_mode(int port)
217217
{
218-
const char *dp_str, *usb_str;
219-
enum typec_mux typec_mux_setting;
220-
221218
/* make DP interface safe until configure */
222219
dp_flags[port] = 0;
223220
dp_status[port] = 0;
@@ -228,9 +225,8 @@ static void svdm_safe_dp_mode(int port)
228225
* To avoid broken the SS connection,
229226
* keep the current setting if SS connection is enabled already.
230227
*/
231-
typec_mux_setting = (usb_mux_get(port, &dp_str, &usb_str) && usb_str) ?
232-
TYPEC_MUX_USB : TYPEC_MUX_NONE;
233-
usb_mux_set(port, typec_mux_setting,
228+
usb_mux_set(port, usb_mux_get(port) & USB_PD_MUX_USB_ENABLED ?
229+
TYPEC_MUX_USB : TYPEC_MUX_NONE,
234230
USB_SWITCH_CONNECT, pd_get_polarity(port));
235231
}
236232

Diff for: board/oak/usb_pd_policy.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ static uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
213213

214214
static void svdm_safe_dp_mode(int port)
215215
{
216-
const char *dp_str, *usb_str;
217-
enum typec_mux typec_mux_setting;
218-
219216
/* make DP interface safe until configure */
220217
dp_flags[port] = 0;
221218
dp_status[port] = 0;
@@ -226,9 +223,8 @@ static void svdm_safe_dp_mode(int port)
226223
* To avoid broken the SS connection,
227224
* keep the current setting if SS connection is enabled already.
228225
*/
229-
typec_mux_setting = (usb_mux_get(port, &dp_str, &usb_str) && usb_str) ?
230-
TYPEC_MUX_USB : TYPEC_MUX_NONE;
231-
usb_mux_set(port, typec_mux_setting,
226+
usb_mux_set(port, usb_mux_get(port) & USB_PD_MUX_USB_ENABLED ?
227+
TYPEC_MUX_USB : TYPEC_MUX_NONE,
232228
USB_SWITCH_CONNECT, pd_get_polarity(port));
233229
}
234230

Diff for: board/trogdor/usb_pd_policy.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,10 @@ static void svdm_dp_post_config(int port)
329329
static int is_dp_muxable(int port)
330330
{
331331
int i;
332-
const char *dp_str, *usb_str;
333332

334333
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
335334
if (i != port) {
336-
usb_mux_get(i, &dp_str, &usb_str);
337-
if (dp_str)
335+
if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED)
338336
return 0;
339337
}
340338

Diff for: driver/usb_mux/usb_mux.c

+14-19
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,11 @@ void usb_mux_set(int port, enum typec_mux mux_mode,
171171
enter_low_power_mode(port);
172172
}
173173

174-
int usb_mux_get(int port, const char **dp_str, const char **usb_str)
174+
mux_state_t usb_mux_get(int port)
175175
{
176176
const struct usb_mux *mux = &usb_muxes[port];
177177
int res;
178178
mux_state_t mux_state;
179-
const char *dp, *usb;
180179

181180
exit_low_power_mode(port);
182181

@@ -186,13 +185,7 @@ int usb_mux_get(int port, const char **dp_str, const char **usb_str)
186185
return 0;
187186
}
188187

189-
dp = mux_state & MUX_POLARITY_INVERTED ? "DP2" : "DP1";
190-
usb = mux_state & MUX_POLARITY_INVERTED ? "USB2" : "USB1";
191-
192-
*dp_str = mux_state & MUX_DP_ENABLED ? dp : NULL;
193-
*usb_str = mux_state & MUX_USB_ENABLED ? usb : NULL;
194-
195-
return *dp_str || *usb_str;
188+
return mux_state;
196189
}
197190

198191
void usb_mux_flip(int port)
@@ -241,16 +234,18 @@ static int command_typec(int argc, char **argv)
241234
return EC_ERROR_PARAM1;
242235

243236
if (argc < 3) {
244-
const char *dp_str, *usb_str;
245-
ccprintf("Port C%d: polarity:CC%d\n",
246-
port, pd_get_polarity(port) + 1);
247-
if (usb_mux_get(port, &dp_str, &usb_str))
248-
ccprintf("Superspeed %s%s%s\n",
249-
dp_str ? dp_str : "",
250-
dp_str && usb_str ? "+" : "",
251-
usb_str ? usb_str : "");
252-
else
253-
ccprintf("No Superspeed connection\n");
237+
mux_state_t mux_state;
238+
239+
mux_state = usb_mux_get(port);
240+
ccprintf("Port %d: USB=%d DP=%d POLARITY=%s HPD_IRQ=%d "
241+
"HPD_LVL=%d SAFE=%d\n", port,
242+
!!(mux_state & USB_PD_MUX_USB_ENABLED),
243+
!!(mux_state & USB_PD_MUX_DP_ENABLED),
244+
mux_state & USB_PD_MUX_POLARITY_INVERTED ?
245+
"INVERTED" : "NORMAL",
246+
!!(mux_state & USB_PD_MUX_HPD_IRQ),
247+
!!(mux_state & USB_PD_MUX_HPD_LVL),
248+
!!(mux_state & USB_PD_MUX_SAFE_MODE));
254249

255250
return EC_SUCCESS;
256251
}

Diff for: include/usb_mux.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,9 @@ void usb_mux_set(int port, enum typec_mux mux_mode,
264264
* Query superspeed mux status on type-C port.
265265
*
266266
* @param port port number.
267-
* @param dp_str pointer to the DP string to return.
268-
* @param usb_str pointer to the USB string to return.
269-
* @return Non-zero if superspeed connection is enabled; otherwise, zero.
267+
* @return current MUX state (USB_PD_MUX_*).
270268
*/
271-
int usb_mux_get(int port, const char **dp_str, const char **usb_str);
269+
mux_state_t usb_mux_get(int port);
272270

273271
/**
274272
* Flip the superspeed muxes on type-C port.

0 commit comments

Comments
 (0)