summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Yilun Lin <yllin@chromium.org>2022-11-02 10:14:57 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-03 05:28:30 +0000
commit75f77820cffd3d11143d308ceaf5f61132ae22a5 (patch)
tree4a075e4a3e6b90f9b7a840c8ae4ecaa8fc985fc4
parent8f5ab72e645b6f09f507f1d325ccb5eafb208cd9 (diff)
downloadchrome-ec-75f77820cffd3d11143d308ceaf5f61132ae22a5.tar.gz
corsola: fix typec port count
When HDMI DB connected, the port count will be the CONFIG_USB_PD_PORT_MAX_COUNT - 1. However, we didn't correct the count in board_get_usb_pd_port_count() due to we used the extra port to emulate USB virtual mux for DP functionality. The incorrect port count will generate i2c errors when we try to disable PPC function at C1 port when we start to sink from C0. This CL fixes the incorrect accessing. BUG=None TEST=No C1 port error messages in the console when charging BRANCH=corsola Change-Id: I86df09fe48594ed77881e56d40e9795442f9bd93 Signed-off-by: Eric Yilun Lin <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3996815 Tested-by: Eric Yilun Lin <yllin@google.com> Auto-Submit: Eric Yilun Lin <yllin@google.com> Commit-Queue: Eric Yilun Lin <yllin@google.com> Code-Coverage: Sung-Chi Li <lschyi@chromium.org> Code-Coverage: Eric Yilun Lin <yllin@google.com> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
-rw-r--r--zephyr/projects/corsola/include/variant_db_detection.h4
-rw-r--r--zephyr/projects/corsola/src/kingler/usbc_config.c7
-rw-r--r--zephyr/projects/corsola/src/krabby/usbc_config.c10
-rw-r--r--zephyr/projects/corsola/src/usbc_config.c14
4 files changed, 29 insertions, 6 deletions
diff --git a/zephyr/projects/corsola/include/variant_db_detection.h b/zephyr/projects/corsola/include/variant_db_detection.h
index 285ff327f2..e98ba3067d 100644
--- a/zephyr/projects/corsola/include/variant_db_detection.h
+++ b/zephyr/projects/corsola/include/variant_db_detection.h
@@ -30,4 +30,8 @@ inline enum corsola_db_type corsola_get_db_type(void)
};
#endif /* CONFIG_VARIANT_CORSOLA_DB_DETECTION */
+/* return the adjusted port count for board overridden usbc/charger functions.
+ */
+uint8_t board_get_adjusted_usb_pd_port_count(void);
+
#endif /* __CROS_EC_CORSOLA_DB_DETECTION_H */
diff --git a/zephyr/projects/corsola/src/kingler/usbc_config.c b/zephyr/projects/corsola/src/kingler/usbc_config.c
index 8c0ca86454..7531904c4a 100644
--- a/zephyr/projects/corsola/src/kingler/usbc_config.c
+++ b/zephyr/projects/corsola/src/kingler/usbc_config.c
@@ -174,7 +174,8 @@ int board_set_active_charge_port(int port)
{
int i;
bool is_valid_port =
- (port >= 0 && port < board_get_usb_pd_port_count());
+ (port >= 0 && port < board_get_adjusted_usb_pd_port_count());
+ /* adjust the actual port count when not the type-c db connected. */
if (!is_valid_port && port != CHARGE_PORT_NONE) {
return EC_ERROR_INVAL;
@@ -184,7 +185,7 @@ int board_set_active_charge_port(int port)
CPRINTS("Disabling all charger ports");
/* Disable all ports. */
- for (i = 0; i < board_get_usb_pd_port_count(); i++) {
+ for (i = 0; i < board_get_adjusted_usb_pd_port_count(); i++) {
/*
* Do not return early if one fails otherwise we can
* get into a boot loop assertion failure.
@@ -209,7 +210,7 @@ int board_set_active_charge_port(int port)
* Turn off the other ports' sink path FETs, before enabling the
* requested charge port.
*/
- for (i = 0; i < board_get_usb_pd_port_count(); i++) {
+ for (i = 0; i < board_get_adjusted_usb_pd_port_count(); i++) {
if (i == port) {
continue;
}
diff --git a/zephyr/projects/corsola/src/krabby/usbc_config.c b/zephyr/projects/corsola/src/krabby/usbc_config.c
index 7a7f710804..8e03e8dbad 100644
--- a/zephyr/projects/corsola/src/krabby/usbc_config.c
+++ b/zephyr/projects/corsola/src/krabby/usbc_config.c
@@ -15,6 +15,8 @@
#include "usb_pd.h"
#include "usbc_ppc.h"
+#include "variant_db_detection.h"
+
#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ##args)
#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
@@ -71,7 +73,9 @@ void board_reset_pd_mcu(void)
int board_set_active_charge_port(int port)
{
int i;
- int is_valid_port = (port >= 0 && port < board_get_usb_pd_port_count());
+ int is_valid_port =
+ (port >= 0 && port < board_get_adjusted_usb_pd_port_count());
+ /* adjust the actual port count when not the type-c db connected. */
if (!is_valid_port && port != CHARGE_PORT_NONE) {
return EC_ERROR_INVAL;
@@ -81,7 +85,7 @@ int board_set_active_charge_port(int port)
CPRINTS("Disabling all charger ports");
/* Disable all ports. */
- for (i = 0; i < ppc_cnt; i++) {
+ for (i = 0; i < board_get_adjusted_usb_pd_port_count(); i++) {
/*
* Do not return early if one fails otherwise we can
* get into a boot loop assertion failure.
@@ -106,7 +110,7 @@ int board_set_active_charge_port(int port)
* Turn off the other ports' sink path FETs, before enabling the
* requested charge port.
*/
- for (i = 0; i < ppc_cnt; i++) {
+ for (i = 0; i < board_get_adjusted_usb_pd_port_count(); i++) {
if (i == port) {
continue;
}
diff --git a/zephyr/projects/corsola/src/usbc_config.c b/zephyr/projects/corsola/src/usbc_config.c
index b9a1524fb6..8bc03991ee 100644
--- a/zephyr/projects/corsola/src/usbc_config.c
+++ b/zephyr/projects/corsola/src/usbc_config.c
@@ -59,6 +59,11 @@ DECLARE_HOOK(HOOK_INIT, baseboard_init, HOOK_PRIO_PRE_DEFAULT);
__override uint8_t board_get_usb_pd_port_count(void)
{
+ /* This function returns the PORT_COUNT+1 when HDMI db is connected.
+ * This is a trick to ensure the usb_mux_set being set properley.
+ * HDMI display functions using the USB virtual mux to * communicate
+ * with the DP bridge.
+ */
if (corsola_get_db_type() == CORSOLA_DB_HDMI) {
if (tasks_inited) {
return CONFIG_USB_PD_PORT_MAX_COUNT;
@@ -72,6 +77,15 @@ __override uint8_t board_get_usb_pd_port_count(void)
return CONFIG_USB_PD_PORT_MAX_COUNT;
}
+uint8_t board_get_adjusted_usb_pd_port_count(void)
+{
+ if (corsola_get_db_type() == CORSOLA_DB_TYPEC) {
+ return CONFIG_USB_PD_PORT_MAX_COUNT;
+ } else {
+ return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
+ }
+}
+
/* USB-A */
void usb_a0_interrupt(enum gpio_signal signal)
{