diff --git a/board/glados/board.h b/board/glados/board.h index ad1de2b883..5317c19e63 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -28,6 +28,7 @@ #define CONFIG_CHIPSET_SKYLAKE #define CONFIG_CLOCK_CRYSTAL #define CONFIG_EXTPOWER_GPIO +#define CONFIG_HOSTCMD_PD #define CONFIG_I2C #define CONFIG_KEYBOARD_PROTOCOL_8042 #define CONFIG_LED_COMMON diff --git a/board/oak/board.h b/board/oak/board.h index 5cac3c7501..78c7999d1f 100644 --- a/board/oak/board.h +++ b/board/oak/board.h @@ -46,6 +46,7 @@ #define CONFIG_HIBERNATE #define CONFIG_HIBERNATE_WAKEUP_PINS (STM32_PWR_CSR_EWUP1|STM32_PWR_CSR_EWUP6) #define CONFIG_HOST_COMMAND_STATUS +#define CONFIG_HOSTCMD_PD #define CONFIG_I2C #define CONFIG_KEYBOARD_COL2_INVERTED #define CONFIG_KEYBOARD_PROTOCOL_MKBP diff --git a/board/samus/board.h b/board/samus/board.h index 2f8576a1d2..f1eb461c27 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -61,6 +61,8 @@ #define CONFIG_HIBERNATE_DELAY_SEC (3600 * 24 * 7) #define CONFIG_HIBERNATE_BATT_PCT 10 #define CONFIG_HIBERNATE_BATT_SEC (3600 * 24) +#define CONFIG_HOSTCMD_PD +#define CONFIG_HOSTCMD_PD_CHG_CTRL #define CONFIG_HOSTCMD_PD_PANIC #define CONFIG_PECI_TJMAX 105 #define CONFIG_PWM @@ -69,7 +71,6 @@ #define CONFIG_TEMP_SENSOR_TMP006 #define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PP3300_DSW_GATED_EN #define CONFIG_UART_HOST 2 -#define CONFIG_USB_PD_MCU_CHG_CTRL #define CONFIG_USB_PORT_POWER_SMART #define CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE USB_CHARGE_MODE_CDP #define CONFIG_USB_PORT_POWER_SMART_INVERTED diff --git a/common/build.mk b/common/build.mk index b551c3f8fc..1c006a843b 100644 --- a/common/build.mk +++ b/common/build.mk @@ -46,6 +46,7 @@ common-$(CONFIG_FLASH)+=flash.o common-$(CONFIG_FMAP)+=fmap.o common-$(CONFIG_GESTURE_DETECTION)+=gesture.o common-$(CONFIG_HOSTCMD_EVENTS)+=host_event_commands.o +common-$(CONFIG_HOSTCMD_PD)+=host_command_master.o common-$(CONFIG_I2C)+=i2c.o common-$(CONFIG_I2C_ARBITRATION)+=i2c_arbitration.o common-$(CONFIG_INDUCTIVE_CHARGING)+=inductive_charging.o @@ -90,7 +91,7 @@ common-$(HAS_TASK_CHIPSET)+=chipset.o common-$(HAS_TASK_CONSOLE)+=console.o console_output.o uart_buffering.o common-$(HAS_TASK_CONSOLE)+=memory_commands.o common-$(HAS_TASK_HOSTCMD)+=host_command.o -common-$(HAS_TASK_PDCMD)+=host_command_master.o host_command_pd.o +common-$(HAS_TASK_PDCMD)+=host_command_pd.o common-$(HAS_TASK_KEYSCAN)+=keyboard_scan.o common-$(HAS_TASK_LIGHTBAR)+=lb_common.o lightbar.o common-$(HAS_TASK_MOTIONSENSE)+=motion_sense.o math_util.o diff --git a/common/host_command_pd.c b/common/host_command_pd.c index a10a591637..0ece50a468 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -22,7 +22,7 @@ #define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM(1) -#ifdef CONFIG_USB_PD_MCU_CHG_CTRL +#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL /* By default allow 5V charging only for the dead battery case */ static enum pd_charge_state charge_state = PD_CHARGE_5V; @@ -37,7 +37,7 @@ int pd_get_active_charge_port(void) void host_command_pd_send_status(enum pd_charge_state new_chg_state) { -#ifdef CONFIG_USB_PD_MCU_CHG_CTRL +#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL /* Update PD MCU charge state if necessary */ if (new_chg_state != PD_CHARGE_NO_CHANGE) charge_state = new_chg_state; @@ -46,6 +46,7 @@ void host_command_pd_send_status(enum pd_charge_state new_chg_state) task_set_event(TASK_ID_PDCMD, TASK_EVENT_EXCHANGE_PD_STATUS, 0); } +#ifdef CONFIG_HOSTCMD_PD static int pd_send_host_command(struct ec_params_pd_status *ec_status, struct ec_response_pd_status *pd_status) { @@ -62,21 +63,20 @@ static int pd_send_host_command(struct ec_params_pd_status *ec_status, sizeof(struct ec_response_pd_status)); return rv; } +#endif static void pd_exchange_status(void) { +#ifdef CONFIG_HOSTCMD_PD struct ec_params_pd_status ec_status; struct ec_response_pd_status pd_status; int rv = 0; -#ifdef CONFIG_USB_PD_TCPM_TCPCI - int loop_count; -#endif #ifdef CONFIG_HOSTCMD_PD_PANIC static int pd_in_rw; #endif /* Send PD charge state and battery state of charge */ -#ifdef CONFIG_USB_PD_MCU_CHG_CTRL +#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL ec_status.charge_state = charge_state; #endif if (charge_get_flags() & CHARGE_FLAG_BATT_RESPONSIVE) @@ -106,7 +106,7 @@ static void pd_exchange_status(void) } #endif -#ifdef CONFIG_USB_PD_MCU_CHG_CTRL +#ifdef CONFIG_HOSTCMD_PD_CHG_CTRL #ifdef HAS_TASK_LIGHTBAR /* * If charge port has changed, and it was initialized, then show @@ -130,13 +130,18 @@ static void pd_exchange_status(void) CONFIG_CHARGER_INPUT_CURRENT)); if (rv < 0) CPRINTS("Failed to set input current limit from PD MCU"); -#endif /* CONFIG_USB_PD_MCU_CHG_CTRL */ +#endif /* CONFIG_HOSTCMD_PD_CHG_CTRL */ /* If PD is signalling host event, then pass it up to AP */ if (pd_status.status & PD_STATUS_HOST_EVENT) host_set_single_event(EC_HOST_EVENT_PD_MCU); +#endif /* CONFIG_HOSTCMD_PD */ -#ifdef CONFIG_USB_PD_TCPM_TCPCI + /* + * If we are TCPM, connected to an off chip TCPC, then check + * TCPC alert status. + */ +#if defined(CONFIG_USB_POWER_DELIVERY) && !defined(CONFIG_USB_PD_TCPM_STUB) /* * Loop here until all Alerts from either port have been handled. * This is necessary to prevent the case where Alert bits are set @@ -145,22 +150,30 @@ static void pd_exchange_status(void) * in turn prevents the GPIO line from being released. */ while (!gpio_get_level(GPIO_PD_MCU_INT)) { + int loop_count = 0; /* * If TCPC is not present on this MCU, then check * to see if either PD port is signallng an * Alert# to the TCPM. */ +#ifdef CONFIG_HOSTCMD_PD if (pd_status.status & PD_STATUS_TCPC_ALERT_0) tcpc_alert(0); if (pd_status.status & PD_STATUS_TCPC_ALERT_1) tcpc_alert(1); +#else + tcpc_alert(0); + tcpc_alert(1); +#endif if (loop_count++) { usleep(50*MSEC); +#ifdef CONFIG_HOSTCMD_PD rv = pd_send_host_command(&ec_status, &pd_status); if (rv < 0) { CPRINTS("Host command to PD MCU failed"); return; } +#endif } } #endif diff --git a/include/config.h b/include/config.h index 2ff2ef45f5..7050b94ee7 100644 --- a/include/config.h +++ b/include/config.h @@ -755,6 +755,15 @@ #define CONFIG_HOSTCMD_RATE_LIMITING_MIN_REST (3 * MSEC) #define CONFIG_HOSTCMD_RATE_LIMITING_RECESS (20 * MSEC) +/* PD MCU supports host commands */ +#undef CONFIG_HOSTCMD_PD + +/* + * Use if PD MCU controls charging (selecting charging port and input + * current limit). + */ +#undef CONFIG_HOSTCMD_PD_CHG_CTRL + /* Panic when status of PD MCU reflects that it has crashed */ #undef CONFIG_HOSTCMD_PD_PANIC @@ -1308,12 +1317,6 @@ /* The size in bytes of the FIFO used for PD events logging */ #undef CONFIG_USB_PD_LOG_SIZE -/* - * Use if PD MCU controls charging (selecting charging port and input - * current limit). - */ -#undef CONFIG_USB_PD_MCU_CHG_CTRL - /* Define if USB-PD device has no way of detecting USB VBUS */ #undef CONFIG_USB_PD_NO_VBUS_DETECT