summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2019-11-22 11:42:29 -0800
committerCommit Bot <commit-bot@chromium.org>2019-11-26 20:01:22 +0000
commit3cb2b8e2be4c3526510f46ad69225b57e2b34cd0 (patch)
treecedfefa7e1feb2fbfde897258aaa550c453bf6e7
parent3e2f184b5bb43461adc3c4ec791ef1ae34441946 (diff)
downloadchrome-ec-3cb2b8e2be4c3526510f46ad69225b57e2b34cd0.tar.gz
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 <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1931284 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--board/cheza/usb_pd_policy.c4
-rw-r--r--board/elm/usb_pd_policy.c8
-rw-r--r--board/oak/usb_pd_policy.c8
-rw-r--r--board/trogdor/usb_pd_policy.c4
-rw-r--r--driver/usb_mux/usb_mux.c33
-rw-r--r--include/usb_mux.h6
6 files changed, 22 insertions, 41 deletions
diff --git a/board/cheza/usb_pd_policy.c b/board/cheza/usb_pd_policy.c
index 502a773150..061c6bb5df 100644
--- a/board/cheza/usb_pd_policy.c
+++ b/board/cheza/usb_pd_policy.c
@@ -373,12 +373,10 @@ static void svdm_dp_post_config(int port)
static int is_dp_muxable(int port)
{
int i;
- const char *dp_str, *usb_str;
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
if (i != port) {
- usb_mux_get(i, &dp_str, &usb_str);
- if (dp_str)
+ if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED)
return 0;
}
diff --git a/board/elm/usb_pd_policy.c b/board/elm/usb_pd_policy.c
index 11e1ca2c6a..06ba8d13c2 100644
--- a/board/elm/usb_pd_policy.c
+++ b/board/elm/usb_pd_policy.c
@@ -215,9 +215,6 @@ static uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
static void svdm_safe_dp_mode(int port)
{
- const char *dp_str, *usb_str;
- enum typec_mux typec_mux_setting;
-
/* make DP interface safe until configure */
dp_flags[port] = 0;
dp_status[port] = 0;
@@ -228,9 +225,8 @@ static void svdm_safe_dp_mode(int port)
* To avoid broken the SS connection,
* keep the current setting if SS connection is enabled already.
*/
- typec_mux_setting = (usb_mux_get(port, &dp_str, &usb_str) && usb_str) ?
- TYPEC_MUX_USB : TYPEC_MUX_NONE;
- usb_mux_set(port, typec_mux_setting,
+ usb_mux_set(port, usb_mux_get(port) & USB_PD_MUX_USB_ENABLED ?
+ TYPEC_MUX_USB : TYPEC_MUX_NONE,
USB_SWITCH_CONNECT, pd_get_polarity(port));
}
diff --git a/board/oak/usb_pd_policy.c b/board/oak/usb_pd_policy.c
index be6868f268..77d10730a4 100644
--- a/board/oak/usb_pd_policy.c
+++ b/board/oak/usb_pd_policy.c
@@ -213,9 +213,6 @@ static uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
static void svdm_safe_dp_mode(int port)
{
- const char *dp_str, *usb_str;
- enum typec_mux typec_mux_setting;
-
/* make DP interface safe until configure */
dp_flags[port] = 0;
dp_status[port] = 0;
@@ -226,9 +223,8 @@ static void svdm_safe_dp_mode(int port)
* To avoid broken the SS connection,
* keep the current setting if SS connection is enabled already.
*/
- typec_mux_setting = (usb_mux_get(port, &dp_str, &usb_str) && usb_str) ?
- TYPEC_MUX_USB : TYPEC_MUX_NONE;
- usb_mux_set(port, typec_mux_setting,
+ usb_mux_set(port, usb_mux_get(port) & USB_PD_MUX_USB_ENABLED ?
+ TYPEC_MUX_USB : TYPEC_MUX_NONE,
USB_SWITCH_CONNECT, pd_get_polarity(port));
}
diff --git a/board/trogdor/usb_pd_policy.c b/board/trogdor/usb_pd_policy.c
index dec48ded41..56756e5abc 100644
--- a/board/trogdor/usb_pd_policy.c
+++ b/board/trogdor/usb_pd_policy.c
@@ -329,12 +329,10 @@ static void svdm_dp_post_config(int port)
static int is_dp_muxable(int port)
{
int i;
- const char *dp_str, *usb_str;
for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
if (i != port) {
- usb_mux_get(i, &dp_str, &usb_str);
- if (dp_str)
+ if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED)
return 0;
}
diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c
index 0a33aef948..93c741c1e9 100644
--- a/driver/usb_mux/usb_mux.c
+++ b/driver/usb_mux/usb_mux.c
@@ -171,12 +171,11 @@ void usb_mux_set(int port, enum typec_mux mux_mode,
enter_low_power_mode(port);
}
-int usb_mux_get(int port, const char **dp_str, const char **usb_str)
+mux_state_t usb_mux_get(int port)
{
const struct usb_mux *mux = &usb_muxes[port];
int res;
mux_state_t mux_state;
- const char *dp, *usb;
exit_low_power_mode(port);
@@ -186,13 +185,7 @@ int usb_mux_get(int port, const char **dp_str, const char **usb_str)
return 0;
}
- dp = mux_state & MUX_POLARITY_INVERTED ? "DP2" : "DP1";
- usb = mux_state & MUX_POLARITY_INVERTED ? "USB2" : "USB1";
-
- *dp_str = mux_state & MUX_DP_ENABLED ? dp : NULL;
- *usb_str = mux_state & MUX_USB_ENABLED ? usb : NULL;
-
- return *dp_str || *usb_str;
+ return mux_state;
}
void usb_mux_flip(int port)
@@ -241,16 +234,18 @@ static int command_typec(int argc, char **argv)
return EC_ERROR_PARAM1;
if (argc < 3) {
- const char *dp_str, *usb_str;
- ccprintf("Port C%d: polarity:CC%d\n",
- port, pd_get_polarity(port) + 1);
- if (usb_mux_get(port, &dp_str, &usb_str))
- ccprintf("Superspeed %s%s%s\n",
- dp_str ? dp_str : "",
- dp_str && usb_str ? "+" : "",
- usb_str ? usb_str : "");
- else
- ccprintf("No Superspeed connection\n");
+ mux_state_t mux_state;
+
+ mux_state = usb_mux_get(port);
+ ccprintf("Port %d: USB=%d DP=%d POLARITY=%s HPD_IRQ=%d "
+ "HPD_LVL=%d SAFE=%d\n", port,
+ !!(mux_state & USB_PD_MUX_USB_ENABLED),
+ !!(mux_state & USB_PD_MUX_DP_ENABLED),
+ mux_state & USB_PD_MUX_POLARITY_INVERTED ?
+ "INVERTED" : "NORMAL",
+ !!(mux_state & USB_PD_MUX_HPD_IRQ),
+ !!(mux_state & USB_PD_MUX_HPD_LVL),
+ !!(mux_state & USB_PD_MUX_SAFE_MODE));
return EC_SUCCESS;
}
diff --git a/include/usb_mux.h b/include/usb_mux.h
index c0e781f65d..c628cfc869 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -264,11 +264,9 @@ void usb_mux_set(int port, enum typec_mux mux_mode,
* Query superspeed mux status on type-C port.
*
* @param port port number.
- * @param dp_str pointer to the DP string to return.
- * @param usb_str pointer to the USB string to return.
- * @return Non-zero if superspeed connection is enabled; otherwise, zero.
+ * @return current MUX state (USB_PD_MUX_*).
*/
-int usb_mux_get(int port, const char **dp_str, const char **usb_str);
+mux_state_t usb_mux_get(int port);
/**
* Flip the superspeed muxes on type-C port.