From c8df8cd58bb4d0bdbf3f953e4a4394dec797609f Mon Sep 17 00:00:00 2001 From: Scott Collyer Date: Wed, 1 Aug 2018 16:56:41 -0700 Subject: DragonEgg: Add support to Type C port 1 Port 1 uses the ITE builtin TCPC, Silergy SYV682A PPC, and the parade PS8818 redriver. Port 1 is intended to use the EC ADC to detect VBUS, but port 0 and 2 require different methods. The Silergy can detect VBUS (not safe0V or safe5v), so currently the PPC is being used to detect VBUS. BUG=b:111281797 BRANCH=none TEST=Verified that port 1 can attach as both a sink or source. Change-Id: Iad0c3d509961c836cd55f77cd5f276c1a3e5aacf Signed-off-by: Scott Collyer Reviewed-on: https://chromium-review.googlesource.com/1159829 Commit-Ready: Scott Collyer Tested-by: Scott Collyer Reviewed-by: Jett Rink --- baseboard/dragonegg/baseboard.c | 22 +++++++++++++++++++++- baseboard/dragonegg/baseboard.h | 8 +++++++- board/dragonegg/board.c | 21 ++++++++++++++++++++- board/dragonegg/board.h | 2 ++ board/dragonegg/ec.tasklist | 3 ++- board/dragonegg/gpio.inc | 1 + 6 files changed, 53 insertions(+), 4 deletions(-) diff --git a/baseboard/dragonegg/baseboard.c b/baseboard/dragonegg/baseboard.c index 678d84d040..14e9dc3923 100644 --- a/baseboard/dragonegg/baseboard.c +++ b/baseboard/dragonegg/baseboard.c @@ -9,6 +9,7 @@ #include "chipset.h" #include "console.h" #include "driver/ppc/sn5s330.h" +#include "driver/ppc/syv682x.h" #include "driver/tcpm/it83xx_pd.h" #include "driver/tcpm/tcpci.h" #include "driver/tcpm/tcpm.h" @@ -25,6 +26,7 @@ #include "util.h" #define USB_PD_PORT_ITE_0 0 +#define USB_PD_PORT_ITE_1 1 #define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) #define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) @@ -162,6 +164,12 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { .drv = &it83xx_tcpm_drv, .pol = TCPC_ALERT_ACTIVE_LOW, }, + + [USB_PD_PORT_ITE_1] = { + /* TCPC is embedded within EC so no i2c config needed */ + .drv = &it83xx_tcpm_drv, + .pol = TCPC_ALERT_ACTIVE_LOW, + }, }; /******************************************************************************/ @@ -172,11 +180,23 @@ struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = { .i2c_addr = SN5S330_ADDR0, .drv = &sn5s330_drv }, + + [USB_PD_PORT_ITE_1] = { + .i2c_port = I2C_PORT_USBC1C2, + .i2c_addr = SYV682X_ADDR0, + .drv = &syv682x_drv + }, }; unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { - { + [USB_PD_PORT_ITE_0] = { + .port_addr = 0, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + }, + + [USB_PD_PORT_ITE_1] = { .port_addr = 0, .driver = &virtual_usb_mux_driver, .hpd_update = &virtual_hpd_update, diff --git a/baseboard/dragonegg/baseboard.h b/baseboard/dragonegg/baseboard.h index 535d1731c7..03f1d8bb91 100644 --- a/baseboard/dragonegg/baseboard.h +++ b/baseboard/dragonegg/baseboard.h @@ -21,6 +21,7 @@ /* #define CONFIG_POWER_TRACK_HOST_SLEEP_STATE */ /* EC Defines */ +#define CONFIG_ADC #define CONFIG_PWM #define CONFIG_VBOOT_HASH #define CONFIG_VSTORE @@ -66,7 +67,7 @@ * on the MLB for now. In addition, this config option will likely move to * board.h as it likely board dependent and not same across all follower boards. */ -#define CONFIG_USB_PD_PORT_COUNT 1 +#define CONFIG_USB_PD_PORT_COUNT 2 #define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_LOGGING @@ -75,10 +76,15 @@ #define CONFIG_USB_PD_DISCHARGE_PPC #define CONFIG_USB_PD_TRY_SRC #define CONFIG_USB_PD_VBUS_DETECT_PPC +/* + * TODO(b/113541930): ADC measurements are available for port 0 and 1, but not + * port 2. + */ #define CONFIG_USB_PD_VBUS_MEASURE_NOT_PRESENT #define CONFIG_USB_PD_TCPM_TCPCI #define CONFIG_USB_MUX_VIRTUAL #define CONFIG_USBC_PPC_SN5S330 /* C0 PPC */ +#define CONFIG_USBC_PPC_SYV682X /* C1 PPC */ #define CONFIG_USBC_PPC_VCONN #define CONFIG_USBC_SS_MUX #define CONFIG_USBC_VCONN diff --git a/board/dragonegg/board.c b/board/dragonegg/board.c index e1ba7f4336..6b784a9baa 100644 --- a/board/dragonegg/board.c +++ b/board/dragonegg/board.c @@ -4,7 +4,8 @@ */ /* DragonEgg board-specific configuration */ - +#include "adc.h" +#include "adc_chip.h" #include "common.h" #include "charger.h" #include "console.h" @@ -31,6 +32,24 @@ static void ppc_interrupt(enum gpio_signal signal) #include "gpio_list.h" /* Must come after other header files. */ +/******************************************************************************/ +/* ADC channels */ +const struct adc_t adc_channels[] = { + /* Vbus C0 sensing (7.3x voltage divider). PPVAR_USB_C0_VBUS */ + [ADC_VBUS_C0] = {.name = "VBUS_C0", + .factor_mul = (ADC_MAX_MVOLT * 73) / 10, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + .channel = CHIP_ADC_CH1}, + /* Vbus C1 sensing (7.3x voltage divider). PPVAR_USB_C1_VBUS */ + [ADC_VBUS_C1] = {.name = "VBUS_C1", + .factor_mul = (ADC_MAX_MVOLT * 73) / 10, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + .channel = CHIP_ADC_CH0}, +}; +BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); + /******************************************************************************/ /* SPI devices */ /* TODO(b/110880394): Fill out correctly (SPI FLASH) */ diff --git a/board/dragonegg/board.h b/board/dragonegg/board.h index 0f6c83a3ee..6f0baf50a3 100644 --- a/board/dragonegg/board.h +++ b/board/dragonegg/board.h @@ -48,6 +48,8 @@ #include "registers.h" enum adc_channel { + ADC_VBUS_C0, + ADC_VBUS_C1, ADC_CH_COUNT }; diff --git a/board/dragonegg/ec.tasklist b/board/dragonegg/ec.tasklist index afe7ed4aa0..04618aa7e2 100644 --- a/board/dragonegg/ec.tasklist +++ b/board/dragonegg/ec.tasklist @@ -30,5 +30,6 @@ TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \ TASK_ALWAYS(POWERBTN, power_button_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) + TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(PD_C1, pd_task, NULL, LARGER_TASK_STACK_SIZE) diff --git a/board/dragonegg/gpio.inc b/board/dragonegg/gpio.inc index fad3232c4b..417402d251 100644 --- a/board/dragonegg/gpio.inc +++ b/board/dragonegg/gpio.inc @@ -112,3 +112,4 @@ ALTERNATE(PIN_MASK(I, 0x0C), 0, MODULE_ADC, 0) ALTERNATE(PIN_MASK(L, 0x01), 0, MODULE_ADC, 0) /* Keyboard Backlight Control */ ALTERNATE(PIN_MASK(A, 0x01), 0, MODULE_PWM, 0) +ALTERNATE(PIN_MASK(I, 0x03), 0, MODULE_ADC, 0) /* ADC1 & ADC0: ADC_USB_C0_VBUS & ADC_USB_C1_VBUS */ -- cgit v1.2.1