summaryrefslogtreecommitdiff
path: root/board/samus_pd/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/samus_pd/board.c')
-rw-r--r--board/samus_pd/board.c159
1 files changed, 78 insertions, 81 deletions
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c
index 321bf56229..7c40859fbb 100644
--- a/board/samus_pd/board.c
+++ b/board/samus_pd/board.c
@@ -13,6 +13,7 @@
#include "i2c.h"
#include "registers.h"
#include "task.h"
+#include "usb_pd.h"
#include "usb_pd_config.h"
#include "util.h"
@@ -105,34 +106,33 @@ const struct i2c_port_t i2c_ports[] = {
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
-void board_set_usb_mux(int port, enum typec_mux mux)
+void board_set_usb_mux(int port, enum typec_mux mux, int polarity)
{
if (port == 0) {
/* reset everything */
gpio_set_level(GPIO_USB_C0_SS1_EN_L, 1);
gpio_set_level(GPIO_USB_C0_SS2_EN_L, 1);
gpio_set_level(GPIO_USB_C0_DP_MODE_L, 1);
- gpio_set_level(GPIO_USB_C0_SS1_DP_MODE_L, 1);
- gpio_set_level(GPIO_USB_C0_SS2_DP_MODE_L, 1);
- switch (mux) {
- case TYPEC_MUX_NONE:
+ gpio_set_level(GPIO_USB_C0_DP_POLARITY, 1);
+ gpio_set_level(GPIO_USB_C0_SS1_DP_MODE, 1);
+ gpio_set_level(GPIO_USB_C0_SS2_DP_MODE, 1);
+
+ if (mux == TYPEC_MUX_NONE)
/* everything is already disabled, we can return */
return;
- case TYPEC_MUX_USB1:
- gpio_set_level(GPIO_USB_C0_SS1_DP_MODE_L, 0);
- break;
- case TYPEC_MUX_USB2:
- gpio_set_level(GPIO_USB_C0_SS2_DP_MODE_L, 0);
- break;
- case TYPEC_MUX_DP1:
- gpio_set_level(GPIO_USB_C0_DP_POLARITY_L, 1);
- gpio_set_level(GPIO_USB_C0_DP_MODE_L, 0);
- break;
- case TYPEC_MUX_DP2:
- gpio_set_level(GPIO_USB_C0_DP_POLARITY_L, 0);
+
+ if (mux == TYPEC_MUX_USB || mux == TYPEC_MUX_DOCK) {
+ /* USB 3.0 uses 2 superspeed lanes */
+ gpio_set_level(polarity ? GPIO_USB_C0_SS2_DP_MODE :
+ GPIO_USB_C0_SS1_DP_MODE, 0);
+ }
+
+ if (mux == TYPEC_MUX_DP || mux == TYPEC_MUX_DOCK) {
+ /* DP uses available superspeed lanes (x2 or x4) */
+ gpio_set_level(GPIO_USB_C0_DP_POLARITY, polarity);
gpio_set_level(GPIO_USB_C0_DP_MODE_L, 0);
- break;
}
+ /* switch on superspeed lanes */
gpio_set_level(GPIO_USB_C0_SS1_EN_L, 0);
gpio_set_level(GPIO_USB_C0_SS2_EN_L, 0);
} else {
@@ -140,37 +140,41 @@ void board_set_usb_mux(int port, enum typec_mux mux)
gpio_set_level(GPIO_USB_C1_SS1_EN_L, 1);
gpio_set_level(GPIO_USB_C1_SS2_EN_L, 1);
gpio_set_level(GPIO_USB_C1_DP_MODE_L, 1);
- gpio_set_level(GPIO_USB_C1_SS1_DP_MODE_L, 1);
- gpio_set_level(GPIO_USB_C1_SS2_DP_MODE_L, 1);
- switch (mux) {
- case TYPEC_MUX_NONE:
+ gpio_set_level(GPIO_USB_C1_DP_POLARITY, 1);
+ gpio_set_level(GPIO_USB_C1_SS1_DP_MODE, 1);
+ gpio_set_level(GPIO_USB_C1_SS2_DP_MODE, 1);
+
+ if (mux == TYPEC_MUX_NONE)
/* everything is already disabled, we can return */
return;
- case TYPEC_MUX_USB1:
- gpio_set_level(GPIO_USB_C1_SS1_DP_MODE_L, 0);
- break;
- case TYPEC_MUX_USB2:
- gpio_set_level(GPIO_USB_C1_SS2_DP_MODE_L, 0);
- break;
- case TYPEC_MUX_DP1:
- gpio_set_level(GPIO_USB_C1_DP_POLARITY_L, 1);
- gpio_set_level(GPIO_USB_C1_DP_MODE_L, 0);
- break;
- case TYPEC_MUX_DP2:
- gpio_set_level(GPIO_USB_C1_DP_POLARITY_L, 0);
+
+ if (mux == TYPEC_MUX_USB || mux == TYPEC_MUX_DOCK) {
+ /* USB 3.0 uses 2 superspeed lanes */
+ gpio_set_level(polarity ? GPIO_USB_C1_SS2_DP_MODE :
+ GPIO_USB_C1_SS1_DP_MODE, 0);
+ }
+
+ if (mux == TYPEC_MUX_DP || mux == TYPEC_MUX_DOCK) {
+ /* DP uses available superspeed lanes (x2 or x4) */
+ gpio_set_level(GPIO_USB_C1_DP_POLARITY, polarity);
gpio_set_level(GPIO_USB_C1_DP_MODE_L, 0);
- break;
}
+ /* switch on superspeed lanes */
gpio_set_level(GPIO_USB_C1_SS1_EN_L, 0);
gpio_set_level(GPIO_USB_C1_SS2_EN_L, 0);
}
}
+/* PD Port polarity as detected by the common PD code */
+extern uint8_t pd_polarity;
+
static int command_typec(int argc, char **argv)
{
- const char * const mux_name[] = {"none", "usb1", "usb2", "dp1", "dp2"};
+ const char * const mux_name[] = {"none", "usb", "dp", "dock"};
char *e;
int port;
+ enum typec_mux mux = TYPEC_MUX_NONE;
+ int i;
if (argc < 2)
return EC_ERROR_PARAM_COUNT;
@@ -181,58 +185,51 @@ static int command_typec(int argc, char **argv)
if (argc < 3) {
/* dump current state */
+ int has_usb, has_dp, has_ss;
+ const char *dp_str, *usb_str;
if (port == 0) {
- ccprintf("Port C%d: CC1 %d mV CC2 %d mV\n",
- port,
- pd_adc_read(0),
- pd_adc_read(1));
- ccprintf("DP %d Polarity %d\n",
- !gpio_get_level(GPIO_USB_C0_DP_MODE_L),
- !!gpio_get_level(GPIO_USB_C0_DP_POLARITY_L)
- + 1);
- ccprintf("Superspeed %s\n",
- gpio_get_level(GPIO_USB_C0_SS1_EN_L) ? "None" :
- (!gpio_get_level(GPIO_USB_C0_DP_MODE_L) ? "DP" :
- (!gpio_get_level(GPIO_USB_C0_SS1_DP_MODE_L) ?
- "USB1" : "USB2")));
+ has_ss = !gpio_get_level(GPIO_USB_C0_SS1_EN_L);
+ has_usb = !gpio_get_level(GPIO_USB_C0_SS1_DP_MODE)
+ || !gpio_get_level(GPIO_USB_C0_SS2_DP_MODE);
+ has_dp = !gpio_get_level(GPIO_USB_C0_DP_MODE_L);
+ dp_str = gpio_get_level(GPIO_USB_C0_DP_POLARITY) ?
+ "DP2" : "DP1";
+ usb_str = gpio_get_level(GPIO_USB_C0_SS1_DP_MODE) ?
+ "USB2" : "USB1";
} else {
- /* TODO: add param to pd_adc_read() to read C1 ADCs */
- ccprintf("Port C%d: CC1 %d mV CC2 %d mV\n",
- port,
- adc_read_channel(ADC_C1_CC1_PD),
- adc_read_channel(ADC_C1_CC2_PD));
- ccprintf("DP %d Polarity %d\n",
- !gpio_get_level(GPIO_USB_C1_DP_MODE_L),
- !!gpio_get_level(GPIO_USB_C1_DP_POLARITY_L)
- + 1);
- ccprintf("Superspeed %s\n",
- gpio_get_level(GPIO_USB_C1_SS1_EN_L) ? "None" :
- (!gpio_get_level(GPIO_USB_C1_DP_MODE_L) ? "DP" :
- (!gpio_get_level(GPIO_USB_C1_SS1_DP_MODE_L) ?
- "USB1" : "USB2")));
+ has_ss = !gpio_get_level(GPIO_USB_C1_SS1_EN_L);
+ has_usb = !gpio_get_level(GPIO_USB_C1_SS1_DP_MODE)
+ || !gpio_get_level(GPIO_USB_C1_SS2_DP_MODE);
+ has_dp = !gpio_get_level(GPIO_USB_C1_DP_MODE_L);
+ dp_str = gpio_get_level(GPIO_USB_C1_DP_POLARITY) ?
+ "DP2" : "DP1";
+ usb_str = gpio_get_level(GPIO_USB_C1_SS1_DP_MODE) ?
+ "USB2" : "USB1";
}
- return EC_SUCCESS;
- }
-
- if (!strcasecmp(argv[2], "mux")) {
- enum typec_mux mux = TYPEC_MUX_NONE;
- int i;
+ /* TODO: add param to pd_adc_read() to read C1 ADCs */
+ ccprintf("Port C%d: CC1 %d mV CC2 %d mV (polarity:CC%d)\n",
+ port,
+ port ? adc_read_channel(ADC_C1_CC1_PD) : pd_adc_read(0),
+ port ? adc_read_channel(ADC_C1_CC2_PD) : pd_adc_read(1),
+ port ? 1 /*TODO: polarity on Port1*/ : pd_polarity + 1);
+ if (has_ss)
+ ccprintf("Superspeed %s%s%s\n",
+ has_dp ? dp_str : "",
+ has_dp && has_usb ? "+" : "",
+ has_usb ? usb_str : "");
+ else
+ ccprintf("No Superspeed connection\n");
- if (argc < 3)
- return EC_ERROR_PARAM3;
-
- for (i = 0; i < ARRAY_SIZE(mux_name); i++)
- if (!strcasecmp(argv[3], mux_name[i]))
- mux = i;
- board_set_usb_mux(port, mux);
return EC_SUCCESS;
- } else {
- return EC_ERROR_PARAM2;
}
- return EC_ERROR_UNKNOWN;
+ for (i = 0; i < ARRAY_SIZE(mux_name); i++)
+ if (!strcasecmp(argv[2], mux_name[i]))
+ mux = i;
+ board_set_usb_mux(port, mux, pd_polarity);
+ return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(typec, command_typec,
- "port [mux none|usb1|usb2|dp1|d2]",
- "Control type-C connector",
+ "<port> [none|usb|dp|dock]",
+ "Control type-C connector muxing",
NULL);