summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/casta/board.c2
-rw-r--r--board/garg/board.c2
-rw-r--r--board/glados_pd/board.c13
-rw-r--r--common/mock/usb_pd_mock.c5
-rw-r--r--common/system.c20
-rw-r--r--common/usb_common.c2
-rw-r--r--common/usbc/usb_tc_ctvpd_sm.c10
-rw-r--r--common/usbc/usb_tc_vpd_sm.c10
-rw-r--r--include/config.h4
-rw-r--r--include/usb_pd.h20
-rw-r--r--test/charge_manager.c5
-rw-r--r--test/charge_ramp.c5
-rw-r--r--test/usb_pd_int.c4
-rw-r--r--test/usb_prl_old.c4
14 files changed, 87 insertions, 19 deletions
diff --git a/board/casta/board.c b/board/casta/board.c
index cbf66d00a0..d277ab3b1c 100644
--- a/board/casta/board.c
+++ b/board/casta/board.c
@@ -164,7 +164,7 @@ void board_overcurrent_event(int port, int is_overcurrented)
gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
}
-uint8_t board_get_usb_pd_port_count(void)
+__override uint8_t board_get_usb_pd_port_count(void)
{
if (sku_id == 2)
return CONFIG_USB_PD_PORT_MAX_COUNT - 1;
diff --git a/board/garg/board.c b/board/garg/board.c
index bc4dc9e226..58efecdfce 100644
--- a/board/garg/board.c
+++ b/board/garg/board.c
@@ -296,7 +296,7 @@ void board_overcurrent_event(int port, int is_overcurrented)
gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
}
-uint8_t board_get_usb_pd_port_count(void)
+__override uint8_t board_get_usb_pd_port_count(void)
{
/* HDMI SKU has one USB PD port */
if (sku_id == 9 || sku_id == 19 || sku_id == 50)
diff --git a/board/glados_pd/board.c b/board/glados_pd/board.c
index 13fa2a16ef..ad23131a3c 100644
--- a/board/glados_pd/board.c
+++ b/board/glados_pd/board.c
@@ -49,6 +49,19 @@ void board_config_pre_init(void)
#include "gpio_list.h"
+__override uint8_t board_get_usb_pd_port_count(void)
+{
+ return CONFIG_USB_PD_PORT_MAX_COUNT;
+}
+
+void pd_set_suspend(int port, int suspend)
+{
+ /*
+ * Do nothing. This is only here to make the linker happy for this
+ * old board on ToT.
+ */
+}
+
/* Initialize board. */
static void board_init(void)
{
diff --git a/common/mock/usb_pd_mock.c b/common/mock/usb_pd_mock.c
index 2223e9153d..afcf19b483 100644
--- a/common/mock/usb_pd_mock.c
+++ b/common/mock/usb_pd_mock.c
@@ -78,3 +78,8 @@ inline uint8_t board_get_usb_pd_port_count(void)
{
return CONFIG_USB_PD_PORT_MAX_COUNT;
}
+
+void pd_set_suspend(int port, int suspend)
+{
+}
+
diff --git a/common/system.c b/common/system.c
index 6a26161f67..333ca2d26e 100644
--- a/common/system.c
+++ b/common/system.c
@@ -872,23 +872,31 @@ static int handle_pending_reboot(enum ec_reboot_cmd cmd)
case EC_REBOOT_JUMP_RW:
return system_run_image_copy(system_get_active_copy());
case EC_REBOOT_COLD:
-#ifdef HAS_TASK_PDCMD
/*
* Reboot the PD chip(s) as well, but first suspend the ports
* if this board has PD tasks running so they don't query the
* TCPCs while they reset.
*/
-#ifdef HAS_TASK_PD_C0
- {
+ if (IS_ENABLED(HAS_TASK_PD_C0)) {
int port;
for (port = 0; port < board_get_usb_pd_port_count();
port++)
pd_set_suspend(port, 1);
+
+ /*
+ * Give enough time to apply CC Open and brown out if
+ * we are running with out a battery.
+ */
+ msleep(20 * MSEC);
}
-#endif
- board_reset_pd_mcu();
-#endif
+
+ /* Reset external PD chips. */
+ if (IS_ENABLED(HAS_TASK_PDCMD) ||
+ IS_ENABLED(HAS_TASK_PD_INT_C0) ||
+ IS_ENABLED(HAS_TASK_PD_INT_C1) ||
+ IS_ENABLED(HAS_TASK_PD_INT_C2))
+ board_reset_pd_mcu();
cflush();
system_reset(SYSTEM_RESET_HARD);
diff --git a/common/usb_common.c b/common/usb_common.c
index b1920e3351..c592deaafa 100644
--- a/common/usb_common.c
+++ b/common/usb_common.c
@@ -297,7 +297,7 @@ int pd_check_requested_voltage(uint32_t rdo, const int port)
return EC_SUCCESS;
}
-__attribute__((weak)) uint8_t board_get_usb_pd_port_count(void)
+__overridable uint8_t board_get_usb_pd_port_count(void)
{
return CONFIG_USB_PD_PORT_MAX_COUNT;
}
diff --git a/common/usbc/usb_tc_ctvpd_sm.c b/common/usbc/usb_tc_ctvpd_sm.c
index 4cb2599431..f6aab7dec3 100644
--- a/common/usbc/usb_tc_ctvpd_sm.c
+++ b/common/usbc/usb_tc_ctvpd_sm.c
@@ -286,6 +286,16 @@ static void tc_disabled_exit(const int port)
CPRINTS("C%d: resumed!", port);
}
+void pd_set_suspend(int port, int suspend)
+{
+ /*
+ * This shouldn't happen. If it does, we need to send an event to the
+ * PD task to put the SM into the disabled state. It is not safe to
+ * directly set_state here since this may be in another task.
+ */
+ assert(false);
+}
+
/**
* ErrorRecovery
*
diff --git a/common/usbc/usb_tc_vpd_sm.c b/common/usbc/usb_tc_vpd_sm.c
index 1b5f308098..7d25001813 100644
--- a/common/usbc/usb_tc_vpd_sm.c
+++ b/common/usbc/usb_tc_vpd_sm.c
@@ -187,6 +187,16 @@ static void tc_disabled_run(const int port)
task_wait_event(-1);
}
+void pd_set_suspend(int port, int suspend)
+{
+ /*
+ * This shouldn't happen. If it does, we need to send an event to the
+ * PD task to put the SM into the disabled state. It is not safe to
+ * directly set_state here since this may be in another task.
+ */
+ assert(false);
+}
+
static void tc_disabled_exit(const int port)
{
if (!IS_ENABLED(CONFIG_USB_PD_TCPC)) {
diff --git a/include/config.h b/include/config.h
index 2d13bb550c..851f5d9e64 100644
--- a/include/config.h
+++ b/include/config.h
@@ -5117,6 +5117,10 @@
#undef CONFIG_HOSTCMD_PD
#endif
+#if defined(HAS_TASK_PDCMD) && defined(HAS_TASK_PD_C0_INT)
+#error Should not use PDCMD task with PD INT tasks
+#endif
+
/* Certain console cmds are irrelevant without parent modules. */
#ifndef CONFIG_BATTERY
#undef CONFIG_CMD_PWR_AVG
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 4c968699c0..b2707f5f2b 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -2667,22 +2667,22 @@ int pd_set_frs_enable(int port, int enable);
*/
__override_proto uint8_t get_dp_pin_mode(int port);
-#ifdef CONFIG_USB_PD_PORT_MAX_COUNT
-#ifdef CONFIG_USB_POWER_DELIVERY
/**
* Get board specific usb pd port count
*
* @return <= CONFIG_USB_PD_PORT_MAX_COUNT if configured in board file,
* else return CONFIG_USB_PD_PORT_MAX_COUNT
*/
-uint8_t board_get_usb_pd_port_count(void);
-#else
-static inline uint8_t board_get_usb_pd_port_count(void)
-{
- return CONFIG_USB_PD_PORT_MAX_COUNT;
-}
-#endif /* CONFIG_USB_POWER_DELIVERY */
-#endif /* CONFIG_USB_PD_PORT_MAX_COUNT */
+__override_proto uint8_t board_get_usb_pd_port_count(void);
+
+
+/**
+ * Resets external PD chips including TCPCs and MCUs.
+ *
+ * Boards must provide this when PDCMD (PD MCUs case) or PD INT (TCPC case)
+ * tasks are present.
+ */
+void board_reset_pd_mcu(void);
/**
* Return true if specified PD port is debug accessory.
diff --git a/test/charge_manager.c b/test/charge_manager.c
index 51a587b68a..2a64ca3e98 100644
--- a/test/charge_manager.c
+++ b/test/charge_manager.c
@@ -45,6 +45,11 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
active_charge_limit = charge_ma;
}
+__override uint8_t board_get_usb_pd_port_count(void)
+{
+ return CONFIG_USB_PD_PORT_MAX_COUNT;
+}
+
/* Sets a charge port that will be rejected as the active port. */
static void set_charge_port_to_reject(int port)
{
diff --git a/test/charge_ramp.c b/test/charge_ramp.c
index 01571c8f3a..d239081c1c 100644
--- a/test/charge_ramp.c
+++ b/test/charge_ramp.c
@@ -37,6 +37,11 @@ static int charge_limit_ma;
/* Mock functions */
+__override uint8_t board_get_usb_pd_port_count(void)
+{
+ return CONFIG_USB_PD_PORT_MAX_COUNT;
+}
+
/* Override test_mockable implementations in charge_ramp module */
int chg_ramp_allowed(int port, int supplier)
{
diff --git a/test/usb_pd_int.c b/test/usb_pd_int.c
index b93001a27f..8a15cfdcd6 100644
--- a/test/usb_pd_int.c
+++ b/test/usb_pd_int.c
@@ -25,6 +25,10 @@ const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
}
};
+void board_reset_pd_mcu(void)
+{
+}
+
static int deferred_resume_called;
void pd_deferred_resume(int port)
{
diff --git a/test/usb_prl_old.c b/test/usb_prl_old.c
index f11db7fb5c..4f0cc05caa 100644
--- a/test/usb_prl_old.c
+++ b/test/usb_prl_old.c
@@ -92,6 +92,10 @@ static uint32_t test_data[] = {
0x11223344
};
+void pd_set_suspend(int port, int suspend)
+{
+}
+
static struct pd_prl {
int rev;
int pd_enable;