diff options
-rw-r--r-- | board/phaser/board.c | 67 | ||||
-rw-r--r-- | board/phaser/board.h | 6 | ||||
-rw-r--r-- | board/phaser/gpio.inc | 2 |
3 files changed, 72 insertions, 3 deletions
diff --git a/board/phaser/board.c b/board/phaser/board.c index 057a94daad..7c9b261815 100644 --- a/board/phaser/board.c +++ b/board/phaser/board.c @@ -15,6 +15,7 @@ #include "driver/accel_lis2dh.h" #include "driver/accelgyro_lsm6dsm.h" #include "driver/ppc/nx20p348x.h" +#include "driver/ppc/syv682x.h" #include "driver/tcpm/anx7447.h" #include "extpower.h" #include "gpio.h" @@ -23,12 +24,14 @@ #include "lid_switch.h" #include "power.h" #include "power_button.h" +#include "stdbool.h" #include "switch.h" #include "task.h" #include "tablet_mode.h" #include "tcpci.h" #include "temp_sensor.h" #include "thermistor.h" +#include "usbc_ppc.h" #include "util.h" #include "battery_smart.h" @@ -39,16 +42,37 @@ #define USB_PD_PORT_PS8751 1 static uint8_t sku_id; +static bool support_syv_ppc; + +/* Check PPC ID and board version to decide which one ppc is used. */ +static bool board_is_support_syv_ppc(void) +{ + uint32_t board_version = 0; + + if (cbi_get_board_version(&board_version) != EC_SUCCESS) + CPRINTSUSB("Get board version failed."); + + if ((board_version >= 5) && (gpio_get_level(GPIO_PPC_ID))) + return true; + + return false; +} static void ppc_interrupt(enum gpio_signal signal) { switch (signal) { case GPIO_USB_PD_C0_INT_ODL: - nx20p348x_interrupt(0); + if (support_syv_ppc) + syv682x_interrupt(0); + else + nx20p348x_interrupt(0); break; case GPIO_USB_PD_C1_INT_ODL: - nx20p348x_interrupt(1); + if (support_syv_ppc) + syv682x_interrupt(1); + else + nx20p348x_interrupt(1); break; default: @@ -219,6 +243,8 @@ static void cbi_init(void) ccprints("SKU: 0x%04x", sku_id); board_update_sensor_config_from_sku(); + + support_syv_ppc = board_is_support_syv_ppc(); } DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1); @@ -296,3 +322,40 @@ void board_overcurrent_event(int port, int is_overcurrented) /* Note that the level is inverted because the pin is active low. */ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented); } + +static const struct ppc_config_t ppc_syv682x_port0 = { + .i2c_port = I2C_PORT_TCPC0, + .i2c_addr = SYV682X_ADDR0, + .drv = &syv682x_drv, +}; + +static const struct ppc_config_t ppc_syv682x_port1 = { + .i2c_port = I2C_PORT_TCPC1, + .i2c_addr = SYV682X_ADDR0, + .drv = &syv682x_drv, +}; + +static void board_setup_ppc(void) +{ + if (!support_syv_ppc) + return; + + memcpy(&ppc_chips[USB_PD_PORT_TCPC_0], + &ppc_syv682x_port0, + sizeof(struct ppc_config_t)); + memcpy(&ppc_chips[USB_PD_PORT_TCPC_1], + &ppc_syv682x_port1, + sizeof(struct ppc_config_t)); + + gpio_set_flags(GPIO_USB_PD_C0_INT_ODL, GPIO_INT_BOTH); + gpio_set_flags(GPIO_USB_PD_C1_INT_ODL, GPIO_INT_BOTH); +} +DECLARE_HOOK(HOOK_INIT, board_setup_ppc, HOOK_PRIO_INIT_I2C + 2); + +int ppc_get_alert_status(int port) +{ + if (port == 0) + return gpio_get_level(GPIO_USB_PD_C0_INT_ODL) == 0; + + return gpio_get_level(GPIO_USB_PD_C1_INT_ODL) == 0; +} diff --git a/board/phaser/board.h b/board/phaser/board.h index 6a10f7e8bf..c350ae2a63 100644 --- a/board/phaser/board.h +++ b/board/phaser/board.h @@ -43,6 +43,12 @@ #define CONFIG_ACCEL_LSM6DSM_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +/* Additional PPC second source */ +#define CONFIG_USBC_PPC_SYV682X +#define CONFIG_USBC_PPC_DEDICATED_INT +#undef CONFIG_SYV682X_HV_ILIM +#define CONFIG_SYV682X_HV_ILIM SYV682X_HV_ILIM_5_50 + #ifndef __ASSEMBLER__ #include "gpio_signal.h" diff --git a/board/phaser/gpio.inc b/board/phaser/gpio.inc index eb1242eadb..dc2e6d4249 100644 --- a/board/phaser/gpio.inc +++ b/board/phaser/gpio.inc @@ -159,12 +159,12 @@ GPIO(EC_INT_L, PIN(9, 4), GPIO_ODR_HIGH) /* EC_AP_INT_ODL */ /* Misc. */ GPIO(CCD_MODE_EC_L, PIN(E, 3), GPIO_INPUT) GPIO(TRACKPAD_INT_1V8_ODL, PIN(9, 3), GPIO_INPUT | GPIO_SEL_1P8V) +GPIO(PPC_ID, PIN(9, 7), GPIO_INPUT | GPIO_PULL_DOWN) /* PPC ID Pin */ /* Unused pins */ GPIO(CHARGER_PMON, PIN(4, 2), GPIO_INPUT) GPIO(CHARGER_IADP, PIN(4, 3), GPIO_INPUT) GPIO(EC_GPIO57, PIN(5, 7), GPIO_INPUT | GPIO_PULL_UP) /* TP Only */ -GPIO(EC_GPIO97, PIN(9, 7), GPIO_INPUT | GPIO_PULL_UP) /* TP Only */ GPIO(EC_I2S_SFRM, PIN(A, 5), GPIO_INPUT | GPIO_SEL_1P8V) GPIO(EC_I2S_SCLK, PIN(A, 7), GPIO_INPUT | GPIO_SEL_1P8V) GPIO(EC_I2S_TX_PCH_RX, PIN(B, 0), GPIO_INPUT | GPIO_SEL_1P8V) |