diff options
author | Andrew McRae <amcrae@google.com> | 2019-11-13 09:41:34 +1100 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-12-11 09:05:06 +0000 |
commit | 536eb90d4e354e2efb4c21ca8502eda12ddaa389 (patch) | |
tree | 3ebd816b8fc25d2dd5bfc938d41a6e3657d48e2b | |
parent | 8d00345012f717500a85890a07326ff27cf54593 (diff) | |
download | chrome-ec-536eb90d4e354e2efb4c21ca8502eda12ddaa389.tar.gz |
puff: Add USB Type C power delivery config
Add the configuration and support for the USB Type C power
delivery, at least enough for proto.
BRANCH=none
BUG=b:143256147
TEST=EC buildall, tests
Change-Id: I8b1c2f27b31ba163716d8a50b76ad967260ae2f2
Signed-off-by: Andrew McRae <amcrae@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1958250
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Andrew McRae <amcrae@chromium.org>
Commit-Queue: Andrew McRae <amcrae@chromium.org>
-rw-r--r-- | board/puff/board.c | 83 | ||||
-rw-r--r-- | board/puff/board.h | 23 | ||||
-rw-r--r-- | board/puff/usb_pd_policy.c | 21 |
3 files changed, 98 insertions, 29 deletions
diff --git a/board/puff/board.c b/board/puff/board.c index 4e78186b6c..f5057a9c0a 100644 --- a/board/puff/board.c +++ b/board/puff/board.c @@ -8,6 +8,8 @@ #include "adc.h" #include "adc_chip.h" #include "button.h" +#include "charge_manager.h" +#include "charge_state_v2.h" #include "common.h" #include "cros_board_info.h" #include "driver/ina3221.h" @@ -55,6 +57,38 @@ static void tcpc_alert_event(enum gpio_signal signal) schedule_deferred_pd_interrupt(0); } +uint16_t tcpc_get_alert_status(void) +{ + uint16_t status = 0; + int level; + + /* + * Check which port has the ALERT line set and ignore if that TCPC has + * its reset line active. + */ + if (!gpio_get_level(GPIO_USB_C0_TCPC_INT_ODL)) { + level = !!(tcpc_config[USB_PD_PORT_TCPC_0].flags & + TCPC_FLAGS_RESET_ACTIVE_HIGH); + if (gpio_get_level(GPIO_USB_C0_TCPC_RST) != level) + status |= PD_STATUS_TCPC_ALERT_0; + } + + return status; +} + +void board_set_charge_limit(int port, int supplier, int charge_ma, + int max_ma, int charge_mv) +{ + charge_set_input_current_limit(MAX(charge_ma, + CONFIG_CHARGER_INPUT_CURRENT), + charge_mv); +} + +int charge_set_input_current_limit(int ma, int mv) +{ + return EC_SUCCESS; +} + #include "port-sm.c" static bool usbc_overcurrent; @@ -137,8 +171,21 @@ const struct pwm_t pwm_channels[] = { /******************************************************************************/ /* USB-C TCPC Configuration */ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .bus_type = EC_BUS_TYPE_I2C, + .i2c_info = { + .port = I2C_PORT_TCPC0, + .addr_flags = AN7447_TCPC0_I2C_ADDR_FLAGS, + }, + .drv = &anx7447_tcpm_drv, + .flags = TCPC_FLAGS_RESET_ACTIVE_HIGH, + }, }; struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .driver = &anx7447_usb_mux_driver, + .hpd_update = &anx7447_tcpc_update_hpd_status, + }, }; /******************************************************************************/ @@ -289,6 +336,11 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); /******************************************************************************/ /* USB-C PPC Configuration */ struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = { + [USB_PD_PORT_TCPC_0] = { + .i2c_port = I2C_PORT_PPC0, + .i2c_addr_flags = SN5S330_ADDR0_FLAGS, + .drv = &sn5s330_drv + }, }; unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); @@ -298,14 +350,14 @@ const int usb_port_enable[USB_PORT_COUNT] = { }; /* Power Delivery and charging functions */ -void baseboard_tcpc_init(void) +static void board_tcpc_init(void) { /* Only reset TCPC if not sysjump */ if (!system_jumped_to_this_image()) board_reset_pd_mcu(); } -DECLARE_HOOK(HOOK_INIT, baseboard_tcpc_init, HOOK_PRIO_INIT_I2C + 1); +DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 1); int64_t get_time_dsw_pwrok(void) { @@ -313,32 +365,25 @@ int64_t get_time_dsw_pwrok(void) return -20 * MSEC; } -uint16_t tcpc_get_alert_status(void) -{ - uint16_t status = 0; - - return status; -} - void board_reset_pd_mcu(void) { + /* Maybe should only reset if we are powered off barreljack */ + int level = !!(tcpc_config[USB_PD_PORT_TCPC_0].flags & + TCPC_FLAGS_RESET_ACTIVE_HIGH); + + gpio_set_level(GPIO_USB_C0_TCPC_RST, level); + msleep(BOARD_TCPC_C0_RESET_HOLD_DELAY); + gpio_set_level(GPIO_USB_C0_TCPC_RST, !level); + if (BOARD_TCPC_C0_RESET_POST_DELAY) + msleep(BOARD_TCPC_C0_RESET_POST_DELAY); } +/* TODO: set the active charge port */ int board_set_active_charge_port(int port) { return EC_SUCCESS; } -int ppc_get_alert_status(int port) -{ - return 0; -} - -void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) -{ -} - void board_overcurrent_event(int port, int is_overcurrented) { /* Sanity check the port. */ diff --git a/board/puff/board.h b/board/puff/board.h index 0c4dcd2b2b..2c4283e47b 100644 --- a/board/puff/board.h +++ b/board/puff/board.h @@ -74,12 +74,6 @@ #define CONFIG_DEDICATED_CHARGE_PORT_COUNT 1 #define DEDICATED_CHARGE_PORT 1 -/* Charger */ -#define CONFIG_CHARGE_MANAGER - -#undef CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON -#define CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON 30000 - #define CONFIG_POWER_BUTTON #define CONFIG_POWER_BUTTON_IGNORE_LID #define CONFIG_POWER_BUTTON_X86 @@ -117,10 +111,16 @@ #define CONFIG_STEINHART_HART_3V3_30K9_47K_4050B #define CONFIG_THROTTLE_AP -/* USB */ -/* TODO: (b/143256147) Finish USB config */ -#undef CONFIG_USB_CHARGER +/* Charger */ +#define CONFIG_CHARGE_MANAGER +#define CONFIG_CHARGER_INPUT_CURRENT 512 /* Allow low-current USB charging */ + +/* USB type C */ +/* Use TCPMv2 */ +#define CONFIG_USB_SM_FRAMEWORK +#undef CONFIG_USB_CHARGER #define CONFIG_USB_POWER_DELIVERY +#define CONFIG_USB_PID 0x5040 #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP #define CONFIG_USB_PD_DISCHARGE_PPC @@ -136,11 +136,16 @@ #define CONFIG_USB_PD_TCPM_ANX7447 #define CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND #define CONFIG_USB_PD_TRY_SRC +#define CONFIG_USB_TYPEC_DRP_ACC_TRYSRC #define CONFIG_USBC_SS_MUX #define CONFIG_USBC_SS_MUX_DFP_ONLY #define CONFIG_USBC_VCONN #define CONFIG_USBC_VCONN_SWAP +#define USB_PD_PORT_TCPC_0 0 +#define BOARD_TCPC_C0_RESET_HOLD_DELAY ANX74XX_RESET_HOLD_MS +#define BOARD_TCPC_C0_RESET_POST_DELAY ANX74XX_RESET_HOLD_MS + /* USB Type A Features */ #define CONFIG_USB_PORT_POWER_DUMB /* There are five ports, but power enable is ganged across all of them. */ diff --git a/board/puff/usb_pd_policy.c b/board/puff/usb_pd_policy.c index 0012512f84..74b5c698e7 100644 --- a/board/puff/usb_pd_policy.c +++ b/board/puff/usb_pd_policy.c @@ -22,6 +22,7 @@ #define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) #define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) + int pd_check_vconn_swap(int port) { /* Only allow vconn swap if pp5000_A rail is enabled */ @@ -30,6 +31,24 @@ int pd_check_vconn_swap(int port) void pd_power_supply_reset(int port) { + int prev_en; + + prev_en = ppc_is_sourcing_vbus(port); + + /* Disable VBUS. */ + ppc_vbus_source_enable(port, 0); + + /* Enable discharge if we were previously sourcing 5V */ + if (prev_en) + pd_set_vbus_discharge(port, 1); + +#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT + /* Give back the current quota we are no longer using */ + charge_manager_source_port(port, 0); +#endif /* defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT) */ + + /* Notify host of power info change. */ + pd_send_host_event(PD_EVENT_POWER_CHANGE); } int pd_set_power_supply_ready(int port) @@ -46,5 +65,5 @@ int pd_snk_is_vbus_provided(int port) int board_vbus_source_enabled(int port) { - return 0; + return ppc_is_sourcing_vbus(port); } |