summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/fruitpie/board.c89
-rw-r--r--board/fruitpie/board.h9
-rw-r--r--board/samus_pd/board.c159
-rw-r--r--board/samus_pd/board.h9
-rw-r--r--board/samus_pd/gpio.inc12
-rw-r--r--common/usb_pd_protocol.c2
-rw-r--r--include/usb_pd.h17
7 files changed, 147 insertions, 150 deletions
diff --git a/board/fruitpie/board.c b/board/fruitpie/board.c
index 7d88bbcc36..e734c5c2af 100644
--- a/board/fruitpie/board.c
+++ b/board/fruitpie/board.c
@@ -163,7 +163,7 @@ int board_set_debug(int enable)
return rv;
}
-void board_set_usb_mux(enum typec_mux mux)
+void board_set_usb_mux(int port, enum typec_mux mux, int polarity)
{
/* reset everything */
gpio_set_level(GPIO_SS1_EN_L, 1);
@@ -171,67 +171,68 @@ void board_set_usb_mux(enum typec_mux mux)
gpio_set_level(GPIO_DP_MODE, 0);
gpio_set_level(GPIO_SS1_USB_MODE_L, 1);
gpio_set_level(GPIO_SS2_USB_MODE_L, 1);
- switch (mux) {
- case TYPEC_MUX_NONE:
+
+ if (mux == TYPEC_MUX_NONE)
/* everything is already disabled, we can return */
return;
- case TYPEC_MUX_USB1:
- gpio_set_level(GPIO_SS1_USB_MODE_L, 0);
- break;
- case TYPEC_MUX_USB2:
- gpio_set_level(GPIO_SS2_USB_MODE_L, 0);
- break;
- case TYPEC_MUX_DP1:
- gpio_set_level(GPIO_DP_POLARITY_L, 1);
- gpio_set_level(GPIO_DP_MODE, 1);
- break;
- case TYPEC_MUX_DP2:
- gpio_set_level(GPIO_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_SS2_USB_MODE_L :
+ GPIO_SS1_USB_MODE_L, 0);
+ }
+
+ if (mux == TYPEC_MUX_DP || mux == TYPEC_MUX_DOCK) {
+ /* DP uses available superspeed lanes (x2 or x4) */
+ gpio_set_level(GPIO_DP_POLARITY_L, !polarity);
gpio_set_level(GPIO_DP_MODE, 1);
- break;
}
+ /* switch on superspeed lanes */
gpio_set_level(GPIO_SS1_EN_L, 0);
gpio_set_level(GPIO_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"};
+ enum typec_mux mux = TYPEC_MUX_NONE;
+ int i;
if (argc < 2) {
+ int has_ss = !gpio_get_level(GPIO_SS1_EN_L);
+ int has_usb = !gpio_get_level(GPIO_SS1_USB_MODE_L)
+ || !gpio_get_level(GPIO_SS2_USB_MODE_L);
+ int has_dp = !!gpio_get_level(GPIO_DP_MODE);
+ const char *dp_str = gpio_get_level(GPIO_DP_POLARITY_L) ?
+ "DP1" : "DP2";
+ const char *usb_str = gpio_get_level(GPIO_SS1_USB_MODE_L) ?
+ "USB2" : "USB1";
/* dump current state */
- ccprintf("CC1 %d mV CC2 %d mV\n",
+ ccprintf("CC1 %d mV CC2 %d mV (polarity:CC%d)\n",
adc_read_channel(ADC_CH_CC1_PD),
- adc_read_channel(ADC_CH_CC2_PD));
- ccprintf("DP %d Polarity %d\n", gpio_get_level(GPIO_DP_MODE),
- !!gpio_get_level(GPIO_DP_POLARITY_L) + 1);
- ccprintf("Superspeed %s\n",
- gpio_get_level(GPIO_SS1_EN_L) ? "None" :
- (gpio_get_level(GPIO_DP_MODE) ? "DP" :
- (!gpio_get_level(GPIO_SS1_USB_MODE_L) ? "USB1" : "USB2")
- ));
- return EC_SUCCESS;
- }
-
- if (!strcasecmp(argv[1], "mux")) {
- enum typec_mux mux = TYPEC_MUX_NONE;
- int i;
+ adc_read_channel(ADC_CH_CC2_PD),
+ 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_PARAM2;
-
- for (i = 0; i < ARRAY_SIZE(mux_name); i++)
- if (!strcasecmp(argv[2], mux_name[i]))
- mux = i;
- board_set_usb_mux(mux);
return EC_SUCCESS;
- } else {
- return EC_ERROR_PARAM1;
}
- 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(0, mux, pd_polarity);
+ return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(typec, command_typec,
- "[mux none|usb1|usb2|dp1|d2]",
- "Control type-C connector",
+ "[none|usb|dp|dock]",
+ "Control type-C connector muxing",
NULL);
diff --git a/board/fruitpie/board.h b/board/fruitpie/board.h
index 9181e15dba..67bd82375d 100644
--- a/board/fruitpie/board.h
+++ b/board/fruitpie/board.h
@@ -80,15 +80,6 @@ enum adc_channel {
ADC_CH_COUNT
};
-/* Muxing for the USB type C */
-enum typec_mux {
- TYPEC_MUX_NONE,
- TYPEC_MUX_USB1,
- TYPEC_MUX_USB2,
- TYPEC_MUX_DP1,
- TYPEC_MUX_DP2,
-};
-
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */
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);
diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h
index 76a4da3eed..b84771a352 100644
--- a/board/samus_pd/board.h
+++ b/board/samus_pd/board.h
@@ -59,15 +59,6 @@ enum adc_channel {
ADC_CH_COUNT
};
-/* Muxing for the USB type C */
-enum typec_mux {
- TYPEC_MUX_NONE,
- TYPEC_MUX_USB1,
- TYPEC_MUX_USB2,
- TYPEC_MUX_DP1,
- TYPEC_MUX_DP2,
-};
-
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */
diff --git a/board/samus_pd/gpio.inc b/board/samus_pd/gpio.inc
index 77851bef7d..7da19454af 100644
--- a/board/samus_pd/gpio.inc
+++ b/board/samus_pd/gpio.inc
@@ -64,14 +64,14 @@ GPIO(USB_C0_SS1_EN_L, E, 2, GPIO_OUT_HIGH, NULL)
GPIO(USB_C0_SS2_EN_L, E, 3, GPIO_OUT_HIGH, NULL)
GPIO(USB_C1_SS1_EN_L, E, 9, GPIO_OUT_HIGH, NULL)
GPIO(USB_C1_SS2_EN_L, E, 10, GPIO_OUT_HIGH, NULL)
-GPIO(USB_C0_SS1_DP_MODE_L, E, 4, GPIO_OUT_HIGH, NULL)
-GPIO(USB_C0_SS2_DP_MODE_L, E, 5, GPIO_OUT_HIGH, NULL)
-GPIO(USB_C1_SS1_DP_MODE_L, E, 11, GPIO_OUT_HIGH, NULL)
-GPIO(USB_C1_SS2_DP_MODE_L, E, 13, GPIO_OUT_HIGH, NULL)
+GPIO(USB_C0_SS1_DP_MODE, E, 4, GPIO_OUT_HIGH, NULL)
+GPIO(USB_C0_SS2_DP_MODE, E, 5, GPIO_OUT_HIGH, NULL)
+GPIO(USB_C1_SS1_DP_MODE, E, 11, GPIO_OUT_HIGH, NULL)
+GPIO(USB_C1_SS2_DP_MODE, E, 13, GPIO_OUT_HIGH, NULL)
GPIO(USB_C0_DP_MODE_L, E, 8, GPIO_OUT_HIGH, NULL)
GPIO(USB_C1_DP_MODE_L, F, 6, GPIO_OUT_LOW, NULL)
-GPIO(USB_C0_DP_POLARITY_L, E, 7, GPIO_OUT_HIGH, NULL)
-GPIO(USB_C1_DP_POLARITY_L, F, 3, GPIO_OUT_HIGH, NULL)
+GPIO(USB_C0_DP_POLARITY, E, 7, GPIO_OUT_HIGH, NULL)
+GPIO(USB_C1_DP_POLARITY, F, 3, GPIO_OUT_HIGH, NULL)
#if 0
/* Alternate functions */
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 228bc883ca..1c6c9f611a 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -192,7 +192,7 @@ static uint8_t pd_role = PD_ROLE_DEFAULT;
/* 3-bit rolling message ID counter */
static uint8_t pd_message_id;
/* Port polarity : 0 => CC1 is CC line, 1 => CC2 is CC line */
-static uint8_t pd_polarity;
+uint8_t pd_polarity;
static enum {
PD_STATE_DISABLED,
diff --git a/include/usb_pd.h b/include/usb_pd.h
index e02c86f0ca..db8d214dc7 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -209,6 +209,23 @@ extern const int pd_src_pdo_cnt;
extern const uint32_t pd_snk_pdo[];
extern const int pd_snk_pdo_cnt;
+/* Muxing for the USB type C */
+enum typec_mux {
+ TYPEC_MUX_NONE,
+ TYPEC_MUX_USB,
+ TYPEC_MUX_DP,
+ TYPEC_MUX_DOCK,
+};
+
+/*
+ * Configure superspeed muxes on type-C port.
+ *
+ * @param port port number.
+ * @param mux selected function.
+ * @param polarity plug polarity (0=CC1, 1=CC2).
+ */
+void board_set_usb_mux(int port, enum typec_mux mux, int polarity);
+
/* --- Physical layer functions : chip specific --- */
/* Packet preparation/retrieval */