summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatryk Duda <pdk@semihalf.com>2020-11-23 16:30:37 +0100
committerCommit Bot <commit-bot@chromium.org>2020-11-23 18:40:49 +0000
commit264c5edd3df88195cdbe9e1f81aba6f0d36d8cdb (patch)
tree8aaa2a2ec20552126833a58a2de23c293cf510e5
parent5421f90715c09ef638ce3d9b0661d51e8108017f (diff)
downloadchrome-ec-264c5edd3df88195cdbe9e1f81aba6f0d36d8cdb.tar.gz
PD: Fix passing information about polarity when DTS is connected
Commit 7dec638eb577aaa3a00d0551d73c276b94ebacb2 introduced two polarity modes POLARITY_CC1_DTS, POLARITY_CC2_DTS in enum tcpc_cc_polarity, but in many places there was an assumption that value other than 0 means that cable is inverted, the most notable example is usb_mux_set(). As a result kernel sometimes was not reporting SuperSpeed depending on if cable was inverted or not. This patch adds mapping from polarity with DTS to polarity without DTS where necessary. BUG=b:162254118 BRANCH=none TEST=Connect ServoV4 to eve and run servod. Make sure that USB-C muxer is connects USB3.0 lines (servod should set it). Flash EC ToT on eve. Boot ChromeOS and go to Developer Console. Run 'dmesg -w', check if device (eg. ethernet adapter) is attached as SuperSpeed device. Unplug cable, invert and plug again. Kernel should report that device is attached as SuperSpeed. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I354ef7047240cc8b5db01936b3780fae7387edb5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2555157 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Jett Rink <jettrink@chromium.org>
-rw-r--r--baseboard/grunt/usb_pd_policy.c4
-rw-r--r--baseboard/kukui/usb_pd_policy.c4
-rw-r--r--baseboard/trogdor/usb_pd_policy.c6
-rw-r--r--baseboard/zork/usb_pd_policy.c6
-rw-r--r--board/cheza/usb_pd_policy.c6
-rw-r--r--board/flapjack/usb_pd_policy.c11
-rw-r--r--board/nocturne/usb_pd_policy.c3
-rw-r--r--board/pdeval-stm32f072/usb_pd_policy.c9
-rw-r--r--common/usb_common.c5
-rw-r--r--common/usb_pd_alt_mode_dfp.c6
-rw-r--r--common/usb_pd_host_cmd.c2
-rw-r--r--common/usb_pd_protocol.c2
-rw-r--r--common/usbc/usb_mode.c4
-rw-r--r--driver/usb_mux/usb_mux.c2
14 files changed, 42 insertions, 28 deletions
diff --git a/baseboard/grunt/usb_pd_policy.c b/baseboard/grunt/usb_pd_policy.c
index 4b28081785..f9cfc8c834 100644
--- a/baseboard/grunt/usb_pd_policy.c
+++ b/baseboard/grunt/usb_pd_policy.c
@@ -116,7 +116,7 @@ __override int svdm_dp_config(int port, uint32_t *payload)
*/
if (mux_mode == USB_PD_MUX_DP_ENABLED)
usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
CMD_DP_CONFIG | VDO_OPOS(opos));
@@ -132,7 +132,7 @@ __override void svdm_dp_post_config(int port)
/* Connect the SBU and USB lines to the connector. */
ppc_set_sbu(port, 1);
usb_mux_set(port, svdm_dp_mux_mode(port), USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
dp_flags[port] |= DP_FLAGS_DP_ON;
if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING))
diff --git a/baseboard/kukui/usb_pd_policy.c b/baseboard/kukui/usb_pd_policy.c
index 02e16ae624..b17552a08c 100644
--- a/baseboard/kukui/usb_pd_policy.c
+++ b/baseboard/kukui/usb_pd_policy.c
@@ -22,9 +22,9 @@ static int board_get_polarity(int port)
{
/* Krane's aux mux polarity is reversed. Workaround to flip it back. */
if (IS_ENABLED(BOARD_KRANE) && board_get_version() == 3)
- return !pd_get_polarity(port);
+ return !polarity_rm_dts(pd_get_polarity(port));
- return pd_get_polarity(port);
+ return polarity_rm_dts(pd_get_polarity(port));
}
static uint8_t vbus_en;
diff --git a/baseboard/trogdor/usb_pd_policy.c b/baseboard/trogdor/usb_pd_policy.c
index 023922038a..ef5c470611 100644
--- a/baseboard/trogdor/usb_pd_policy.c
+++ b/baseboard/trogdor/usb_pd_policy.c
@@ -195,7 +195,8 @@ __override int svdm_dp_attention(int port, uint32_t *payload)
* lanes DP).
*/
usb_mux_set(port, USB_PD_MUX_DOCK,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
} else {
/* Disconnect the DP port selection mux. */
gpio_set_level(GPIO_DP_MUX_OE_L, 1);
@@ -207,7 +208,8 @@ __override int svdm_dp_attention(int port, uint32_t *payload)
/* Disconnect the DP but keep the USB SS lines in TCPC chip. */
usb_mux_set(port, USB_PD_MUX_USB_ENABLED,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
}
if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
diff --git a/baseboard/zork/usb_pd_policy.c b/baseboard/zork/usb_pd_policy.c
index ad106c8b6b..f988fd18d0 100644
--- a/baseboard/zork/usb_pd_policy.c
+++ b/baseboard/zork/usb_pd_policy.c
@@ -119,7 +119,7 @@ __override int svdm_dp_config(int port, uint32_t *payload)
*/
if (mux_mode == USB_PD_MUX_DP_ENABLED)
usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
CMD_DP_CONFIG | VDO_OPOS(opos));
@@ -134,7 +134,7 @@ __override void svdm_dp_post_config(int port)
/* Connect the SBU and USB lines to the connector. */
ppc_set_sbu(port, 1);
usb_mux_set(port, svdm_dp_mux_mode(port), USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
dp_flags[port] |= DP_FLAGS_DP_ON;
if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING))
@@ -155,7 +155,7 @@ __override void svdm_safe_dp_mode(int port)
dp_status[port] = 0;
usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
}
__override void svdm_exit_dp_mode(int port)
diff --git a/board/cheza/usb_pd_policy.c b/board/cheza/usb_pd_policy.c
index 694899ab79..88fcded727 100644
--- a/board/cheza/usb_pd_policy.c
+++ b/board/cheza/usb_pd_policy.c
@@ -191,11 +191,13 @@ __override int svdm_dp_attention(int port, uint32_t *payload)
usb_mux_set(port, mf_pref ?
USB_PD_MUX_DOCK : USB_PD_MUX_DP_ENABLED,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
} else {
usb_mux_set(port, mf_pref ?
USB_PD_MUX_USB_ENABLED : USB_PD_MUX_NONE,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
}
/* ack */
diff --git a/board/flapjack/usb_pd_policy.c b/board/flapjack/usb_pd_policy.c
index 3603b6c931..ef2156f1fe 100644
--- a/board/flapjack/usb_pd_policy.c
+++ b/board/flapjack/usb_pd_policy.c
@@ -83,7 +83,8 @@ __override void svdm_dp_post_config(int port)
gpio_set_level(GPIO_USB_C0_HPD_OD, 1);
gpio_set_level(GPIO_USB_C0_DP_OE_L, 0);
- gpio_set_level(GPIO_USB_C0_DP_POLARITY, pd_get_polarity(port));
+ gpio_set_level(GPIO_USB_C0_DP_POLARITY,
+ polarity_rm_dts(pd_get_polarity(port)));
/* set the minimum time delay (2ms) for the next HPD IRQ */
svdm_hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL;
@@ -106,7 +107,7 @@ __override int svdm_dp_attention(int port, uint32_t *payload)
}
usb_mux_set(port, lvl ? USB_PD_MUX_DP_ENABLED : USB_PD_MUX_NONE,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT, polarity_rm_dts(pd_get_polarity(port)));
usb_mux_hpd_update(port, lvl, irq);
@@ -122,7 +123,8 @@ __override int svdm_dp_attention(int port, uint32_t *payload)
gpio_set_level(GPIO_USB_C0_HPD_OD, 1);
gpio_set_level(GPIO_USB_C0_DP_OE_L, 0);
- gpio_set_level(GPIO_USB_C0_DP_POLARITY, pd_get_polarity(port));
+ gpio_set_level(GPIO_USB_C0_DP_POLARITY,
+ polarity_rm_dts(pd_get_polarity(port)));
/* set the minimum time delay (2ms) for the next HPD IRQ */
svdm_hpd_deadline[port] = get_time().val +
@@ -133,7 +135,8 @@ __override int svdm_dp_attention(int port, uint32_t *payload)
} else {
gpio_set_level(GPIO_USB_C0_HPD_OD, lvl);
gpio_set_level(GPIO_USB_C0_DP_OE_L, !lvl);
- gpio_set_level(GPIO_USB_C0_DP_POLARITY, pd_get_polarity(port));
+ gpio_set_level(GPIO_USB_C0_DP_POLARITY,
+ polarity_rm_dts(pd_get_polarity(port)));
/* set the minimum time delay (2ms) for the next HPD IRQ */
svdm_hpd_deadline[port] = get_time().val +
HPD_USTREAM_DEBOUNCE_LVL;
diff --git a/board/nocturne/usb_pd_policy.c b/board/nocturne/usb_pd_policy.c
index e2951f291e..14329b61b3 100644
--- a/board/nocturne/usb_pd_policy.c
+++ b/board/nocturne/usb_pd_policy.c
@@ -97,7 +97,8 @@ __override void svdm_safe_dp_mode(int port)
{
/* make DP interface safe until configure */
usb_mux_set(port, USB_PD_MUX_NONE,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
/*
* Isolate the SBU lines.
diff --git a/board/pdeval-stm32f072/usb_pd_policy.c b/board/pdeval-stm32f072/usb_pd_policy.c
index f5bbf8d619..d5a40fa6e8 100644
--- a/board/pdeval-stm32f072/usb_pd_policy.c
+++ b/board/pdeval-stm32f072/usb_pd_policy.c
@@ -194,7 +194,10 @@ __override void svdm_safe_dp_mode(int port)
{
/* make DP interface safe until configure */
dp_flags[port] = 0;
- /* board_set_usb_mux(port, USB_PD_MUX_NONE, pd_get_polarity(port)); */
+ /*
+ * board_set_usb_mux(port, USB_PD_MUX_NONE,
+ * polarity_rm_dts(pd_get_polarity(port)));
+ */
}
__override int svdm_dp_config(int port, uint32_t *payload)
@@ -207,7 +210,7 @@ __override int svdm_dp_config(int port, uint32_t *payload)
#ifdef CONFIG_USB_PD_TCPM_ANX7447
mux_state_t mux_state = USB_PD_MUX_NONE;
- if (pd_get_polarity(port))
+ if (polarity_rm_dts(pd_get_polarity(port)))
mux_state |= USB_PD_MUX_POLARITY_INVERTED;
#endif
@@ -234,7 +237,7 @@ __override int svdm_dp_config(int port, uint32_t *payload)
/*
* board_set_usb_mux(port, USB_PD_MUX_DP_ENABLED,
- * pd_get_polarity(port));
+ * polarity_rm_dts(pd_get_polarity(port)));
*/
payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
CMD_DP_CONFIG | VDO_OPOS(opos));
diff --git a/common/usb_common.c b/common/usb_common.c
index 7d4a0df99e..1b068ba8af 100644
--- a/common/usb_common.c
+++ b/common/usb_common.c
@@ -441,7 +441,7 @@ void set_usb_mux_with_current_data_role(int port)
USB_SWITCH_DISCONNECT : USB_SWITCH_CONNECT;
usb_mux_set(port, mux_mode, usb_switch_mode,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
}
}
@@ -450,7 +450,8 @@ void usb_mux_set_safe_mode(int port)
if (IS_ENABLED(CONFIG_USBC_SS_MUX)) {
usb_mux_set(port, IS_ENABLED(CONFIG_USB_MUX_VIRTUAL) ?
USB_PD_MUX_SAFE_MODE : USB_PD_MUX_NONE,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
}
/* Isolate the SBU lines. */
diff --git a/common/usb_pd_alt_mode_dfp.c b/common/usb_pd_alt_mode_dfp.c
index 65d77054ff..151e6c2594 100644
--- a/common/usb_pd_alt_mode_dfp.c
+++ b/common/usb_pd_alt_mode_dfp.c
@@ -749,7 +749,8 @@ void set_tbt_compat_mode_ready(int port)
/* Set usb mux to Thunderbolt-compatible mode */
usb_mux_set(port, USB_PD_MUX_TBT_COMPAT_ENABLED,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
+ USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
}
}
@@ -1078,7 +1079,8 @@ __overridable int svdm_dp_config(int port, uint32_t *payload)
/* Connect the SBU and USB lines to the connector. */
if (IS_ENABLED(CONFIG_USBC_PPC_SBU))
ppc_set_sbu(port, 1);
- usb_mux_set(port, mux_mode, USB_SWITCH_CONNECT, pd_get_polarity(port));
+ usb_mux_set(port, mux_mode, USB_SWITCH_CONNECT,
+ polarity_rm_dts(pd_get_polarity(port)));
payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
CMD_DP_CONFIG | VDO_OPOS(opos));
diff --git a/common/usb_pd_host_cmd.c b/common/usb_pd_host_cmd.c
index c63ec6b79c..f8cb9f38e3 100644
--- a/common/usb_pd_host_cmd.c
+++ b/common/usb_pd_host_cmd.c
@@ -325,7 +325,7 @@ static enum ec_status hc_usb_pd_control(struct host_cmd_handler_args *args)
typec_mux_map[p->mux] == USB_PD_MUX_NONE ?
USB_SWITCH_DISCONNECT :
USB_SWITCH_CONNECT,
- pd_get_polarity(p->port));
+ polarity_rm_dts(pd_get_polarity(p->port)));
if (p->swap == USB_PD_CTRL_SWAP_DATA) {
pd_request_data_swap(p->port);
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 5bc3e0a1e2..9bb03e4c33 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -2200,7 +2200,7 @@ static void exit_tbt_mode_sop_prime(int port)
AMS_START);
usb_mux_set(port, USB_PD_MUX_USB_ENABLED, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
}
static void pd_vdm_send_state_machine(int port)
diff --git a/common/usbc/usb_mode.c b/common/usbc/usb_mode.c
index 900552b451..5a1965d431 100644
--- a/common/usbc/usb_mode.c
+++ b/common/usbc/usb_mode.c
@@ -129,7 +129,7 @@ void enter_usb_failed(int port)
* to USB mode on receiving a NAK.
*/
usb_mux_set(port, USB_PD_MUX_USB_ENABLED, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
usb4_debug_prints(port, USB4_MODE_FAILURE);
usb4_state[port] = USB4_INACTIVE;
@@ -235,7 +235,7 @@ void enter_usb_accepted(int port, enum tcpm_transmit_type type)
/* Set usb mux to USB4 mode */
usb_mux_set(port, USB_PD_MUX_USB4_ENABLED, USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
usb4_debug_prints(port, USB4_MODE_SUCCESS);
break;
diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c
index c4af3b2ed9..e311faf26a 100644
--- a/driver/usb_mux/usb_mux.c
+++ b/driver/usb_mux/usb_mux.c
@@ -351,7 +351,7 @@ static int command_typec(int argc, char **argv)
usb_mux_set(port, mux, mux == USB_PD_MUX_NONE ?
USB_SWITCH_DISCONNECT :
USB_SWITCH_CONNECT,
- pd_get_polarity(port));
+ polarity_rm_dts(pd_get_polarity(port)));
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(typec, command_typec,