summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2018-03-27 14:44:54 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-04-09 15:18:52 -0700
commit32bbdbf88cf5422ac1ca8fe8121d3cec07c379c3 (patch)
tree370a5240525ba5805118cdcb0eb2284d2baa4cbe
parenteab54036ea8fbd01fd5a7ebdea9b42b0ea08547c (diff)
downloadchrome-ec-32bbdbf88cf5422ac1ca8fe8121d3cec07c379c3.tar.gz
bip: add initial power sequence usb-pd
BRANCH=none BUG=b:75972988,b:76218141 TEST=buildall Change-Id: I8d03f10828821c6d8e096d882db9f82cc901003a Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/982562 Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--board/bip/battery.c32
-rw-r--r--board/bip/board.c222
-rw-r--r--board/bip/board.h120
-rw-r--r--board/bip/build.mk2
-rw-r--r--board/bip/ec.tasklist10
-rw-r--r--board/bip/gpio.inc46
-rw-r--r--board/bip/usb_pd_policy.c352
7 files changed, 767 insertions, 17 deletions
diff --git a/board/bip/battery.c b/board/bip/battery.c
new file mode 100644
index 0000000000..5806901cf2
--- /dev/null
+++ b/board/bip/battery.c
@@ -0,0 +1,32 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Battery pack vendor provided charging profile
+ */
+#include "battery.h"
+#include "battery_smart.h"
+/* TODO(b/74353771): Once CL:978619 lands. Pull common code in baseboard. */
+
+/* TODO(b/74353771): Ensure settings here are correct */
+static const struct battery_info info = {
+ .voltage_max = 13200, /* mV */
+ .voltage_normal = 11550,
+ .voltage_min = 9000,
+ .precharge_current = 256, /* mA */
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 50,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = -20,
+ .discharging_max_c = 75,
+};
+const struct battery_info *battery_get_info(void)
+{
+ return &info;
+}
+int board_cut_off_battery(void)
+{
+ /* TODO(b/74353771): Ensure settings here are correct */
+ return EC_RES_ERROR;
+}
diff --git a/board/bip/board.c b/board/bip/board.c
index 38f8d60192..392ced37eb 100644
--- a/board/bip/board.c
+++ b/board/bip/board.c
@@ -5,34 +5,177 @@
/* Bip board-specific configuration */
+#include "adc.h"
+#include "adc_chip.h"
#include "common.h"
+#include "driver/bc12/bq24392.h"
+#include "driver/ppc/sn5s330.h"
+#include "driver/tcpm/it83xx_pd.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/usb_mux_it5205.h"
#include "ec2i_chip.h"
+#include "extpower.h"
#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
#include "lid_switch.h"
+#include "power.h"
#include "power_button.h"
#include "spi.h"
-#include "uart.h"
#include "switch.h"
#include "system.h"
+#include "tcpci.h"
+#include "uart.h"
+#include "usb_mux.h"
+#include "usbc_ppc.h"
#include "util.h"
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ if (signal == GPIO_USB_C0_PD_INT_ODL)
+ sn5s330_interrupt(0);
+ else if (signal == GPIO_USB_C1_PD_INT_ODL)
+ sn5s330_interrupt(1);
+}
+
#include "gpio_list.h" /* Must come after other header files. */
/******************************************************************************/
/* Wake up pins */
-/* TODO(b/73811887): Fill out correctly */
const enum gpio_signal hibernate_wake_pins[] = {
- GPIO_LID_OPEN
+ GPIO_LID_OPEN,
+ GPIO_AC_PRESENT,
+ GPIO_POWER_BUTTON_L,
};
const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins);
/******************************************************************************/
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ /* Vbus C0 sensing (10x voltage divider). PPVAR_USB_C0_VBUS */
+ [ADC_VBUS_C0] = {
+ "VBUS_C0", 10*ADC_MAX_MVOLT, ADC_READ_MAX+1, 0, CHIP_ADC_CH13},
+ /* Vbus C1 sensing (10x voltage divider). PPVAR_USB_C1_VBUS */
+ [ADC_VBUS_C1] = {
+ "VBUS_C1", 10*ADC_MAX_MVOLT, ADC_READ_MAX+1, 0, CHIP_ADC_CH14},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+/******************************************************************************/
+/* Power signal list. Must match order of enum power_signal. */
+const struct power_signal_info power_signal_list[] = {
+#ifdef CONFIG_POWER_S0IX
+ {GPIO_PCH_SLP_S0_L,
+ POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
+ "SLP_S0_DEASSERTED"},
+#endif
+ {GPIO_PCH_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
+ {GPIO_PCH_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
+ {GPIO_SUSPWRDNACK, POWER_SIGNAL_ACTIVE_HIGH,
+ "SUSPWRDNACK_DEASSERTED"},
+
+ {GPIO_ALL_SYS_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "ALL_SYS_PGOOD"},
+ {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L"},
+ {GPIO_PP3300_PG, POWER_SIGNAL_ACTIVE_HIGH, "PP3300_PG"},
+ {GPIO_PP5000_PG, POWER_SIGNAL_ACTIVE_HIGH, "PP5000_PG"},
+};
+BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
+
+/******************************************************************************/
/* SPI devices */
-/* TODO(b/73811887): Fill out correctly (SPI FLASH) */
+/* TODO(b/75972988): Fill out correctly (SPI FLASH) */
const struct spi_device_t spi_devices[] = {
};
const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices);
/******************************************************************************/
+/* I2C port map. */
+const struct i2c_port_t i2c_ports[] = {
+/* TODO(b/77139726): increase I2C bus speeds after bringup. */
+ {"power", IT83XX_I2C_CH_A, 100, GPIO_I2C0_SCL, GPIO_I2C0_SDA},
+ {"sensor", IT83XX_I2C_CH_B, 100, GPIO_I2C1_SCL, GPIO_I2C1_SDA},
+ {"usbc0", IT83XX_I2C_CH_C, 100, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
+ {"usbc1", IT83XX_I2C_CH_E, 100, GPIO_I2C4_SCL, GPIO_I2C4_SDA},
+ {"eeprom", IT83XX_I2C_CH_F, 100, GPIO_I2C5_SCL, GPIO_I2C5_SDA},
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+#define USB_PD_PORT_0_ITE 0
+#define USB_PD_PORT_1_PS8751 1
+
+/******************************************************************************/
+/* USB-C TCPC config. */
+const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
+ [USB_PD_PORT_0_ITE] = {
+ /* TCPC is embedded within EC so no i2c config needed */
+ .drv = &it83xx_tcpm_drv,
+ .pol = TCPC_ALERT_ACTIVE_LOW,
+ },
+ [USB_PD_PORT_1_PS8751] = {
+ .i2c_host_port = I2C_PORT_USBC1,
+ .i2c_slave_addr = PS8751_I2C_ADDR1,
+ .drv = &ps8xxx_tcpm_drv,
+ .pol = TCPC_ALERT_ACTIVE_LOW,
+ },
+};
+
+/******************************************************************************/
+/* USB-C MUX config */
+static void board_it83xx_hpd_status(int port, int hpd_lvl, int hpd_irq);
+
+struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
+ [USB_PD_PORT_0_ITE] = {
+ /* Driver uses I2C_PORT_USB_MUX as I2C port */
+ .port_addr = IT5205_I2C_ADDR1,
+ .driver = &it5205_usb_mux_driver,
+ .hpd_update = &board_it83xx_hpd_status,
+ },
+ [USB_PD_PORT_1_PS8751] = {
+ .port_addr = USB_PD_PORT_1_PS8751,
+ .driver = &tcpci_tcpm_usb_mux_driver,
+ .hpd_update = &board_it83xx_hpd_status,
+ }
+};
+
+/******************************************************************************/
+/* USB-C PPC config */
+const struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = {
+ [USB_PD_PORT_0_ITE] = {
+ .i2c_port = I2C_PORT_USBC0,
+ .i2c_addr = SN5S330_ADDR0,
+ .drv = &sn5s330_drv
+ },
+ [USB_PD_PORT_1_PS8751] = {
+ .i2c_port = I2C_PORT_USBC1,
+ .i2c_addr = SN5S330_ADDR0,
+ .drv = &sn5s330_drv
+ },
+};
+const unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
+
+/******************************************************************************/
+/* USB-C BC 1.2 chip Configuration */
+const struct bq24392_config_t bq24392_config[CONFIG_USB_PD_PORT_COUNT] = {
+ [USB_PD_PORT_0_ITE] = {
+ .chip_enable_pin = GPIO_USB_C0_BC12_VBUS_ON,
+ .chg_det_pin = GPIO_USB_C0_BC12_CHG_DET_L,
+ .flags = BQ24392_FLAGS_CHG_DET_ACTIVE_LOW,
+ },
+ [USB_PD_PORT_1_PS8751] = {
+ .chip_enable_pin = GPIO_USB_C1_BC12_VBUS_ON,
+ .chg_det_pin = GPIO_USB_C1_BC12_CHG_DET_L,
+ .flags = BQ24392_FLAGS_CHG_DET_ACTIVE_LOW,
+ },
+};
+
+/******************************************************************************/
+/* USB-A config */
+const int usb_port_enable[USB_PORT_COUNT] = {
+ GPIO_EN_USB_A0_5V,
+ GPIO_EN_USB_A1_5V,
+};
+
+/******************************************************************************/
/* PNPCFG settings */
/* TODO(b/76022972): Ensure correct and put in common chip code instead */
const struct ec2i_t pnpcfg_settings[] = {
@@ -122,3 +265,74 @@ const struct ec2i_t pnpcfg_settings[] = {
#endif
};
BUILD_ASSERT(ARRAY_SIZE(pnpcfg_settings) == EC2I_SETTING_COUNT);
+
+
+/* TODO(crbug.com/826441): Consolidate this logic with other impls */
+static void board_it83xx_hpd_status(int port, int hpd_lvl, int hpd_irq)
+{
+ enum gpio_signal gpio = port ?
+ GPIO_USB_C1_HPD_1V8_ODL : GPIO_USB_C0_HPD_1V8_ODL;
+
+ /* Invert HPD level since GPIOs are active low. */
+ hpd_lvl = !hpd_lvl;
+
+ gpio_set_level(gpio, hpd_lvl);
+ if (hpd_irq) {
+ gpio_set_level(gpio, 1);
+ msleep(1);
+ gpio_set_level(gpio, hpd_lvl);
+ }
+}
+
+void board_pd_vconn_ctrl(int port, int cc_pin, int enabled)
+{
+ /*
+ * We ignore the cc_pin because the polarity should already be set
+ * correctly in the PPC driver via the pd state machine.
+ */
+ if (ppc_set_vconn(port, enabled) != EC_SUCCESS)
+ cprints(CC_USBPD, "C%d: Failed %sabling vconn",
+ port, enabled ? "en" : "dis");
+}
+
+enum adc_channel board_get_vbus_adc(int port)
+{
+ return port ? ADC_VBUS_C1 : ADC_VBUS_C0;
+}
+
+/**
+ * Reset all system PD/TCPC MCUs -- currently only called from
+ * handle_pending_reboot() in common/power.c just before hard
+ * resetting the system. This logic is likely not needed as the
+ * PP3300_A rail should be dropped on EC reset.
+ */
+void board_reset_pd_mcu(void)
+{
+ /* TODO(b/76218141): Flesh out USB code */
+}
+
+int board_set_active_charge_port(int port)
+{
+ /* TODO(b/76218141): Flesh out USB code */
+ return EC_SUCCESS;
+}
+
+void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
+{
+ /* TODO(b/76218141): Flesh out USB code */
+}
+
+void board_overcurrent_event(int port)
+{
+ /* TODO(b/76218141): Do we need to pass this signal upstream? */
+
+ cprints(CC_USBPD, "p%d: overcurrent!", port);
+}
+
+
+uint16_t tcpc_get_alert_status(void)
+{
+ /* TODO(b/76218141): Flesh out USB code */
+ return 0;
+}
diff --git a/board/bip/board.h b/board/bip/board.h
index 280e05f91e..ad1a230595 100644
--- a/board/bip/board.h
+++ b/board/bip/board.h
@@ -14,18 +14,109 @@
/* ITE Config */
#define CONFIG_IT83XX_FLASH_CLOCK_48MHZ /* Flash clock must be > (50Mhz / 2) */
-#define CONFIG_POWER_BUTTON
-#define CONFIG_KEYBOARD_BOARD_CONFIG
-#define CONFIG_KEYBOARD_PROTOCOL_8042
+/* EC Features */
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
#define CONFIG_LOW_POWER_IDLE
+#define CONFIG_VBOOT_HASH
+#define CONFIG_VSTORE
+#define CONFIG_VSTORE_SLOT_COUNT 1
+
+/* Charger Configuration */
+#define CONFIG_CHARGE_MANAGER
+#define CONFIG_CHARGE_RAMP_HW
+#define CONFIG_CHARGER
+#define CONFIG_CHARGER_V2
+ /* TODO(b/76429930): Use correct driver below after writing BQ25703 driver */
+#define CONFIG_CHARGER_ISL9238
+#define CONFIG_CHARGER_INPUT_CURRENT 512 /* Allow low-current USB charging */
+#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
+#define CONFIG_CHARGER_SENSE_RESISTOR 10
+#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_DISCHARGE_ON_AC
+#define CONFIG_USB_CHARGER
+
+/* Battery Configuration */
+#define CONFIG_BATTERY_CUT_OFF
+/* TODO(b/74427009): Ensure this works in dead battery conditions */
+#define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_L
+#define CONFIG_BATTERY_SMART
+
+/* USB-C Configuration */
+#define CONFIG_USB_POWER_DELIVERY
+#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_DUAL_ROLE_AUTO_TOGGLE
+#define CONFIG_USB_PD_TRY_SRC
+#define CONFIG_USB_PD_LOGGING
+#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_ALT_MODE_DFP
+#define CONFIG_USB_PD_COMM_LOCKED
+#define CONFIG_USB_PD_TCPC_LOW_POWER
+#define CONFIG_USB_PD_TCPM_ITE83XX /* C0 TPCP: ITE EC */
+#define CONFIG_USB_MUX_IT5205 /* C0 MUX: IT5205 */
+#define CONFIG_USB_PD_TCPM_PS8751 /* C1 TCPC & Mux: single PS8751 */
+#define CONFIG_USB_PD_TCPM_TCPCI
+#define CONFIG_USB_PD_TCPM_MUX
+#define CONFIG_USBC_SS_MUX
+#define CONFIG_USBC_SS_MUX_DFP_ONLY
+#define CONFIG_USBC_PPC_SN5S330 /* C0 & C1 PPC: each SN5S330 */
+#define CONFIG_USBC_PPC_VCONN
+#define CONFIG_USB_PD_DISCHARGE_PPC
+#define CONFIG_USBC_VCONN
+#define CONFIG_USBC_VCONN_SWAP
+#define CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT
+#define CONFIG_BC12_DETECT_BQ24392
+
+/* USB-A Configuration */
+#define CONFIG_USB_PORT_POWER_DUMB
+#define USB_PORT_COUNT 2
+
+/* TODO(b/76218141): Use correct PD delay values */
+#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
+#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
+#define PD_VCONN_SWAP_DELAY 5000 /* us */
+
+/* TODO(b/76218141): Use correct PD power values */
+#define PD_OPERATING_POWER_MW 15000
+#define PD_MAX_POWER_MW 45000
+#define PD_MAX_CURRENT_MA 3000
+#define PD_MAX_VOLTAGE_MV 20000
+
+/* I2C Bus Configuration */
+#define I2C_PORT_BATTERY IT83XX_I2C_CH_A /* Shared bus */
+#define I2C_PORT_CHARGER IT83XX_I2C_CH_A /* Shared bus */
+#define I2C_PORT_SENSOR IT83XX_I2C_CH_B
+#define I2C_PORT_USBC0 IT83XX_I2C_CH_C
+#define I2C_PORT_USBC1 IT83XX_I2C_CH_E
+#define I2C_PORT_USB_MUX I2C_PORT_USBC0 /* For MUX driver */
+#define I2C_PORT_EEPROM IT83XX_I2C_CH_F
+
+/* SoC / PCH Configuration */
+#define CONFIG_CHIPSET_GEMINILAKE
+#define CONFIG_CHIPSET_RESET_HOOK
+#define CONFIG_ESPI
+/* TODO(b/76023457): Enable Virtual Wires after bringup */
+#define CONFIG_LPC
+#define CONFIG_KEYBOARD_PROTOCOL_8042
+#define CONFIG_POWER_COMMON
+#define CONFIG_POWER_S0IX
+#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE
+#define CONFIG_POWER_BUTTON
+#define CONFIG_POWER_BUTTON_X86
+#define CONFIG_EXTPOWER_GPIO
+/* TODO(b/75974377), increase CONFIG_EXTPOWER_DEBOUNCE_MS from 30 to 1000? */
+
#ifndef __ASSEMBLER__
#include "gpio_signal.h"
#include "registers.h"
-/* TODO(b/75972988): Fill out correctly */
enum adc_channel {
+ ADC_VBUS_C0,
+ ADC_VBUS_C1,
ADC_CH_COUNT
};
@@ -34,6 +125,27 @@ enum pwm_channel {
PWM_CH_COUNT
};
+enum power_signal {
+#ifdef CONFIG_POWER_S0IX
+ X86_SLP_S0_N, /* PCH -> SLP_S0_L */
+#endif
+ X86_SLP_S3_N, /* PCH -> SLP_S3_L */
+ X86_SLP_S4_N, /* PCH -> SLP_S4_L */
+ X86_SUSPWRDNACK, /* PCH -> SUSPWRDNACK */
+
+ X86_ALL_SYS_PG, /* PMIC -> PMIC_EC_PWROK_OD */
+ X86_RSMRST_N, /* PMIC -> PMIC_EC_RSMRST_ODL */
+ X86_PGOOD_PP3300, /* PMIC -> PP3300_PG_OD */
+ X86_PGOOD_PP5000, /* PMIC -> PP5000_PG_OD */
+
+ /* Number of X86 signals */
+ POWER_SIGNAL_COUNT
+};
+
+/* Forward declare board-specific functions */
+void board_reset_pd_mcu(void);
+void board_pd_vconn_ctrl(int port, int cc_pin, int enabled);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/bip/build.mk b/board/bip/build.mk
index ab440ab72a..7ef4b615d9 100644
--- a/board/bip/build.mk
+++ b/board/bip/build.mk
@@ -10,3 +10,5 @@ CHIP:=it83xx
BASEBOARD:=octopus
board-y=board.o
+board-$(CONFIG_BATTERY_SMART)+=battery.o
+board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o \ No newline at end of file
diff --git a/board/bip/ec.tasklist b/board/bip/ec.tasklist
index 9d0778b7c3..65a4100a37 100644
--- a/board/bip/ec.tasklist
+++ b/board/bip/ec.tasklist
@@ -22,6 +22,14 @@
#define CONFIG_TASK_LIST \
TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, 0, TASK_STACK_SIZE) \
+ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, 1, TASK_STACK_SIZE) \
+ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
+ TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \
+ TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \
- TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE)
+ TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_ALWAYS(POWERBTN, power_button_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/bip/gpio.inc b/board/bip/gpio.inc
index e4e27fa2ee..3b7a6d6a2c 100644
--- a/board/bip/gpio.inc
+++ b/board/bip/gpio.inc
@@ -13,15 +13,31 @@ GPIO_INT(LID_OPEN, PIN(E, 2), GPIO_INT_BOTH, lid_interrupt)
GPIO_INT(WP_L, PIN(I, 4), GPIO_INT_BOTH, switch_interrupt) /* EC_WP_ODL */
GPIO_INT(POWER_BUTTON_L, PIN(E, 4), GPIO_INT_BOTH, power_button_interrupt) /* MECH_PWR_BTN_ODL */
#ifdef CONFIG_LOW_POWER_IDLE
-/* Used to wake up the EC from Doze mode when writing to console */
+/* Used to wake up the EC from Deep Doze mode when writing to console */
GPIO_INT(UART1_RX, PIN(B, 0), GPIO_INT_FALLING, uart_deepsleep_interrupt) /* UART_SERVO_TX_EC_RX */
#endif
-/*
- * TODO(b/76023457): Move below 4 signals to virtual wires over eSPI
- */
+/* USB-C interrupts */
+GPIO_INT(USB_C0_PD_INT_ODL, PIN(H, 6), GPIO_INT_FALLING, ppc_interrupt)
+GPIO_INT(USB_C1_PD_INT_ODL, PIN(H, 5), GPIO_INT_FALLING, ppc_interrupt)
+
+/* Power State interrupts */
+#ifdef CONFIG_POWER_S0IX
+GPIO_INT(PCH_SLP_S0_L, PIN(G, 6), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S0_L */
+#endif
+GPIO_INT(PCH_SLP_S4_L, PIN(F, 3), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S4_L */
+GPIO_INT(PCH_SLP_S3_L, PIN(F, 2), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S3_L */
+GPIO_INT(SUSPWRDNACK, PIN(E, 1), GPIO_INT_BOTH, power_signal_interrupt) /* SUSPWRDNACK */
+GPIO_INT(RSMRST_L_PGOOD, PIN(F, 1), GPIO_INT_BOTH, power_signal_interrupt) /* PMIC_EC_RSMRST_ODL */
+GPIO_INT(ALL_SYS_PGOOD, PIN(F, 0), GPIO_INT_BOTH, power_signal_interrupt) /* PMIC_EC_PWROK_OD */
+GPIO_INT(AC_PRESENT, PIN(A, 7), GPIO_INT_BOTH, extpower_interrupt) /* ACOK_OD */
+
+
GPIO(PCH_PLTRST_L, PIN(E, 3), GPIO_INPUT) /* PLT_RST_L: Platform Reset from SoC */
GPIO(SYS_RESET_L, PIN(B, 6), GPIO_ODR_HIGH) /* SYS_RST_ODL */
+/*
+ * TODO(b/76023457): Move below 2 signals to virtual wires over eSPI
+ */
GPIO(PCH_SMI_L, PIN(D, 4), GPIO_OUT_LOW) /* EC_SMI_R_ODL */
GPIO(PCH_SCI_L, PIN(D, 3), GPIO_OUT_LOW) /* EC_SCI_R_ODL */
@@ -53,13 +69,27 @@ GPIO(I2C1_SCL, PIN(C, 1), GPIO_INPUT |
GPIO_SEL_1P8V) /* EC_I2C_SENSOR_U_SCL */
GPIO(I2C1_SDA, PIN(C, 2), GPIO_INPUT |
GPIO_SEL_1P8V) /* EC_I2C_SENSOR_U_SDA */
-GPIO(I2C2_SCL, PIN(F, 6), GPIO_INPUT) /* EC_I2C_USBC_MUX_SCL */
-GPIO(I2C2_SDA, PIN(F, 7), GPIO_INPUT) /* EC_I2C_USBC_MUX_SDA */
-GPIO(I2C4_SCL, PIN(E, 0), GPIO_INPUT) /* EC_I2C_USB_PD_SCL */
-GPIO(I2C4_SDA, PIN(E, 7), GPIO_INPUT) /* EC_I2C_USB_PD_SDA */
+GPIO(I2C2_SCL, PIN(F, 6), GPIO_INPUT) /* EC_I2C_USB_C0_MUX_SCL */
+GPIO(I2C2_SDA, PIN(F, 7), GPIO_INPUT) /* EC_I2C_USB_C0_MUX_SDA */
+GPIO(I2C4_SCL, PIN(E, 0), GPIO_INPUT) /* EC_I2C_USB_C1_MUX_SCL */
+GPIO(I2C4_SDA, PIN(E, 7), GPIO_INPUT) /* EC_I2C_USB_C1_MUX_SDA */
GPIO(I2C5_SCL, PIN(A, 4), GPIO_INPUT) /* EC_I2C_PROG_SCL */
GPIO(I2C5_SDA, PIN(A, 5), GPIO_INPUT) /* EC_I2C_PROG_SDA */
+/* USB pins */
+GPIO(EN_USB_A0_5V, PIN(B, 7), GPIO_OUT_LOW) /* Enable A0 5V Charging */
+GPIO(EN_USB_A1_5V, PIN(H, 3), GPIO_OUT_LOW) /* Enable A1 5V Charging */
+GPIO(USB_A0_CHARGE_EN_L, PIN(K, 0), GPIO_OUT_HIGH) /* Enable A0 1.5A Charging */
+GPIO(USB_A1_CHARGE_EN_L, PIN(K, 6), GPIO_OUT_HIGH) /* Enable A1 1.5A Charging */
+GPIO(USB_C0_HPD_1V8_ODL, PIN(J, 0), GPIO_ODR_HIGH |
+ GPIO_SEL_1P8V) /* C0 DP Hotplug Detect */
+GPIO(USB_C1_HPD_1V8_ODL, PIN(J, 1), GPIO_ODR_HIGH |
+ GPIO_SEL_1P8V) /* C1 DP Hotplug Detect */
+GPIO(USB_C0_BC12_CHG_DET_L, PIN(A, 0), GPIO_INPUT) /* C0 BC1.2 Detect */
+GPIO(USB_C1_BC12_CHG_DET_L, PIN(A, 1), GPIO_INPUT) /* C1 BC1.2 Detect */
+GPIO(USB_C0_BC12_VBUS_ON, PIN(J, 4), GPIO_OUT_LOW) /* C0 BC1.2 Power */
+GPIO(USB_C1_BC12_VBUS_ON, PIN(J, 5), GPIO_OUT_LOW) /* C1 BC1.2 Power */
+
/* Alternate functions GPIO definitions */
/* Cr50 requires no pull-ups on UART pins. */
ALTERNATE(PIN_MASK(B, 0x03), 0, MODULE_UART, 0) /* UART from EC to Servo */
diff --git a/board/bip/usb_pd_policy.c b/board/bip/usb_pd_policy.c
new file mode 100644
index 0000000000..93ad7dfa40
--- /dev/null
+++ b/board/bip/usb_pd_policy.c
@@ -0,0 +1,352 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "charge_manager.h"
+#include "common.h"
+#include "compile_time_macros.h"
+#include "console.h"
+#include "ec_commands.h"
+#include "gpio.h"
+#include "system.h"
+#include "usb_mux.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+
+#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\
+ PDO_FIXED_COMM_CAP)
+
+
+const uint32_t pd_src_pdo[] = {
+ PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS),
+};
+const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
+const uint32_t pd_src_pdo_max[] = {
+ PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS),
+};
+const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max);
+
+const uint32_t pd_snk_pdo[] = {
+ PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
+ PDO_BATT(4750, 21000, 15000),
+ PDO_VAR(4750, 21000, 3000),
+};
+const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
+
+int pd_board_checks(void)
+{
+ return EC_SUCCESS;
+}
+
+int pd_check_data_swap(int port, int data_role)
+{
+ /*
+ * Allow data swap if we are a UFP, otherwise don't allow.
+ *
+ * When we are still in the Read-Only firmware, avoid swapping roles
+ * so we don't jump in RW as a SNK/DFP and potentially confuse the
+ * power supply by sending a soft-reset with wrong data role.
+ */
+ return (data_role == PD_ROLE_UFP) &&
+ (system_get_image_copy() != SYSTEM_IMAGE_RO) ? 1 : 0;
+}
+
+void pd_check_dr_role(int port, int dr_role, int flags)
+{
+ /* If UFP, try to switch to DFP */
+ if ((flags & PD_FLAGS_PARTNER_DR_DATA) &&
+ dr_role == PD_ROLE_UFP &&
+ system_get_image_copy() != SYSTEM_IMAGE_RO)
+ pd_request_data_swap(port);
+}
+
+int pd_check_power_swap(int port)
+{
+ /*
+ * Allow power swap as long as we are acting as a dual role device,
+ * otherwise assume our role is fixed (not in S0 or console command
+ * to fix our role).
+ */
+ return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0;
+}
+
+void pd_check_pr_role(int port, int pr_role, int flags)
+{
+ /*
+ * If partner is dual-role power and dualrole toggling is on, consider
+ * if a power swap is necessary.
+ */
+ if ((flags & PD_FLAGS_PARTNER_DR_POWER) &&
+ pd_get_dual_role() == PD_DRP_TOGGLE_ON) {
+ /*
+ * If we are a sink and partner is not externally powered, then
+ * swap to become a source. If we are source and partner is
+ * externally powered, swap to become a sink.
+ */
+ int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER;
+
+ if ((!partner_extpower && pr_role == PD_ROLE_SINK) ||
+ (partner_extpower && pr_role == PD_ROLE_SOURCE))
+ pd_request_power_swap(port);
+ }
+}
+
+int pd_check_vconn_swap(int port)
+{
+ /* Only allow vconn swap if pp5000_A rail is enabled */
+ return gpio_get_level(GPIO_EN_PP5000);
+}
+
+/* TODO: Delete this method once CL:885462 lands */
+void pd_execute_data_swap(int port, int data_role)
+{
+ /* Do nothing */
+}
+
+int pd_is_valid_input_voltage(int mv)
+{
+ return 1;
+}
+
+void pd_power_supply_reset(int port)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+}
+
+int pd_set_power_supply_ready(int port)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+
+ /* Notify host of power info change. */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
+
+ return EC_SUCCESS;
+}
+
+void pd_transition_voltage(int idx)
+{
+ /* No-operation: we are always 5V */
+}
+
+void typec_set_source_current_limit(int port, int rp)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+}
+
+int pd_snk_is_vbus_provided(int port)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+ return 0;
+}
+
+int board_vbus_source_enabled(int port)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+ return 0;
+}
+
+/* ----------------- Vendor Defined Messages ------------------ */
+const struct svdm_response svdm_rsp = {
+ .identity = NULL,
+ .svids = NULL,
+ .modes = NULL,
+};
+
+int pd_custom_vdm(int port, int cnt, uint32_t *payload,
+ uint32_t **rpayload)
+{
+ int cmd = PD_VDO_CMD(payload[0]);
+ uint16_t dev_id = 0;
+ int is_rw, is_latest;
+
+ /* make sure we have some payload */
+ if (cnt == 0)
+ return 0;
+
+ switch (cmd) {
+ case VDO_CMD_VERSION:
+ /* guarantee last byte of payload is null character */
+ *(payload + cnt - 1) = 0;
+ CPRINTF("version: %s\n", (char *)(payload+1));
+ break;
+ case VDO_CMD_READ_INFO:
+ case VDO_CMD_SEND_INFO:
+ /* copy hash */
+ if (cnt == 7) {
+ dev_id = VDO_INFO_HW_DEV_ID(payload[6]);
+ is_rw = VDO_INFO_IS_RW(payload[6]);
+
+ is_latest = pd_dev_store_rw_hash(port,
+ dev_id,
+ payload + 1,
+ is_rw ?
+ SYSTEM_IMAGE_RW :
+ SYSTEM_IMAGE_RO);
+ /*
+ * Send update host event unless our RW hash is
+ * already known to be the latest update RW.
+ */
+ if (!is_rw || !is_latest)
+ pd_send_host_event(PD_EVENT_UPDATE_DEVICE);
+
+ CPRINTF("DevId:%d.%d SW:%d RW:%d\n",
+ HW_DEV_ID_MAJ(dev_id),
+ HW_DEV_ID_MIN(dev_id),
+ VDO_INFO_SW_DBG_VER(payload[6]),
+ is_rw);
+ } else if (cnt == 6) {
+ /* really old devices don't have last byte */
+ pd_dev_store_rw_hash(port, dev_id, payload + 1,
+ SYSTEM_IMAGE_UNKNOWN);
+ }
+ break;
+ case VDO_CMD_CURRENT:
+ CPRINTF("Current: %dmA\n", payload[1]);
+ break;
+ case VDO_CMD_FLIP:
+ usb_mux_flip(port);
+ break;
+#ifdef CONFIG_USB_PD_LOGGING
+ case VDO_CMD_GET_LOG:
+ pd_log_recv_vdm(port, cnt, payload);
+ break;
+#endif /* CONFIG_USB_PD_LOGGING */
+ }
+
+ return 0;
+}
+
+#ifdef CONFIG_USB_PD_ALT_MODE_DFP
+static int dp_flags[CONFIG_USB_PD_PORT_COUNT];
+static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT];
+
+static void svdm_safe_dp_mode(int port)
+{
+ /* make DP interface safe until configure */
+ dp_flags[port] = 0;
+ dp_status[port] = 0;
+ usb_mux_set(port, TYPEC_MUX_NONE,
+ USB_SWITCH_CONNECT, pd_get_polarity(port));
+}
+
+static int svdm_enter_dp_mode(int port, uint32_t mode_caps)
+{
+ /* Only enter mode if device is DFP_D capable */
+ if (mode_caps & MODE_DP_SNK) {
+ svdm_safe_dp_mode(port);
+ return 0;
+ }
+
+ return -1;
+}
+
+static int svdm_dp_status(int port, uint32_t *payload)
+{
+ int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
+
+ payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
+ CMD_DP_STATUS | VDO_OPOS(opos));
+ payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
+ 0, /* HPD level ... not applicable */
+ 0, /* exit DP? ... no */
+ 0, /* usb mode? ... no */
+ 0, /* multi-function ... no */
+ (!!(dp_flags[port] & DP_FLAGS_DP_ON)),
+ 0, /* power low? ... no */
+ (!!(dp_flags[port] & DP_FLAGS_DP_ON)));
+ return 2;
+};
+
+static int svdm_dp_config(int port, uint32_t *payload)
+{
+ int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT);
+ int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]);
+ int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]);
+
+ if (!pin_mode)
+ return 0;
+
+ usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP,
+ USB_SWITCH_CONNECT, pd_get_polarity(port));
+
+ payload[0] = VDO(USB_SID_DISPLAYPORT, 1,
+ CMD_DP_CONFIG | VDO_OPOS(opos));
+ payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */
+ 1, /* DPv1.3 signaling */
+ 2); /* UFP connected */
+ return 2;
+};
+
+
+static void svdm_dp_post_config(int port)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+}
+
+static int svdm_dp_attention(int port, uint32_t *payload)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+ return 1; /* ack */
+}
+
+static void svdm_exit_dp_mode(int port)
+{
+ /* TODO(b/74127309): Flesh out USB code */
+}
+
+static int svdm_enter_gfu_mode(int port, uint32_t mode_caps)
+{
+ /* Always enter GFU mode */
+ return 0;
+}
+
+static void svdm_exit_gfu_mode(int port)
+{
+}
+
+static int svdm_gfu_status(int port, uint32_t *payload)
+{
+ /*
+ * This is called after enter mode is successful, send unstructured
+ * VDM to read info.
+ */
+ pd_send_vdm(port, USB_VID_GOOGLE, VDO_CMD_READ_INFO, NULL, 0);
+ return 0;
+}
+
+static int svdm_gfu_config(int port, uint32_t *payload)
+{
+ return 0;
+}
+
+static int svdm_gfu_attention(int port, uint32_t *payload)
+{
+ return 0;
+}
+
+const struct svdm_amode_fx supported_modes[] = {
+ {
+ .svid = USB_SID_DISPLAYPORT,
+ .enter = &svdm_enter_dp_mode,
+ .status = &svdm_dp_status,
+ .config = &svdm_dp_config,
+ .post_config = &svdm_dp_post_config,
+ .attention = &svdm_dp_attention,
+ .exit = &svdm_exit_dp_mode,
+ },
+ {
+ .svid = USB_VID_GOOGLE,
+ .enter = &svdm_enter_gfu_mode,
+ .status = &svdm_gfu_status,
+ .config = &svdm_gfu_config,
+ .attention = &svdm_gfu_attention,
+ .exit = &svdm_exit_gfu_mode,
+ }
+};
+const int supported_modes_cnt = ARRAY_SIZE(supported_modes);
+#endif /* CONFIG_USB_PD_ALT_MODE_DFP */