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>
This commit is contained in:
Vijay Hiremath 2019-11-22 11:42:29 -08:00 committed by Commit Bot
parent 3e2f184b5b
commit 3cb2b8e2be
6 changed files with 22 additions and 41 deletions

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.