summaryrefslogtreecommitdiff
path: root/board/cheza
diff options
context:
space:
mode:
Diffstat (limited to 'board/cheza')
-rw-r--r--board/cheza/base_detect.c216
-rw-r--r--board/cheza/battery.c45
-rw-r--r--board/cheza/board.c700
-rw-r--r--board/cheza/board.h225
-rw-r--r--board/cheza/build.mk13
-rw-r--r--board/cheza/ec.tasklist23
-rw-r--r--board/cheza/gpio.inc169
-rw-r--r--board/cheza/led.c163
-rw-r--r--board/cheza/usb_pd_policy.c473
9 files changed, 0 insertions, 2027 deletions
diff --git a/board/cheza/base_detect.c b/board/cheza/base_detect.c
deleted file mode 100644
index 3999ad022f..0000000000
--- a/board/cheza/base_detect.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/* 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.
- */
-
-/* Lux base without battery detection code */
-
-#include "adc.h"
-#include "adc_chip.h"
-#include "board.h"
-#include "chipset.h"
-#include "common.h"
-#include "console.h"
-#include "extpower.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "host_command.h"
-#include "system.h"
-#include "tablet_mode.h"
-#include "task.h"
-#include "timer.h"
-#include "util.h"
-
-#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
-
-/* Base detection and debouncing */
-#define BASE_DETECT_DEBOUNCE_US (20 * MSEC)
-
-/*
- * If the base status is unclear (i.e. not within expected ranges, read
- * the ADC value again every 500ms.
- */
-#define BASE_DETECT_RETRY_US (500 * MSEC)
-
-/*
- * When base is disconnected, and gets connected:
- * Lid has 1M pull-up, base has 200K pull-down, so the ADC
- * value should be around 200/(200+1000)*3300 = 550.
- *
- * Idle value should be ~3300: lid has 1M pull-up, and nothing else (i.e. ADC
- * maxing out at 2813).
- */
-#define BASE_DISCONNECTED_CONNECT_MIN_MV 450
-#define BASE_DISCONNECTED_CONNECT_MAX_MV 650
-
-#define BASE_DISCONNECTED_MIN_MV 2800
-#define BASE_DISCONNECTED_MAX_MV (ADC_MAX_VOLT+1)
-
-/*
- * When base is connected, then gets disconnected:
- * Lid has 1M pull-up, lid has 10.0K pull-down, so the ADC
- * value should be around 10.0/(10.0+1000)*3300 = 33.
- *
- * Idle level when connected should be:
- * Lid has 10K pull-down, base has 5.1K pull-up, so the ADC value should be
- * around 10.0/(10.0+5.1)*3300 = 2185 (actual value is 2153 as there is still
- * a 1M pull-up on lid, and 200K pull-down on base).
- */
-#define BASE_CONNECTED_DISCONNECT_MIN_MV 20
-#define BASE_CONNECTED_DISCONNECT_MAX_MV 45
-
-#define BASE_CONNECTED_MIN_MV 2050
-#define BASE_CONNECTED_MAX_MV 2300
-
-static uint64_t base_detect_debounce_time;
-
-static void base_detect_deferred(void);
-DECLARE_DEFERRED(base_detect_deferred);
-
-enum base_status {
- BASE_UNKNOWN = 0,
- BASE_DISCONNECTED = 1,
- BASE_CONNECTED = 2,
-};
-
-static enum base_status current_base_status;
-
-/*
- * This function is called whenever there is a change in the base detect
- * status. Actions taken include:
- * 1. Enable/disable pull-down on half-duplex UART line
- * 2. Enable/disable power to base.
- * 3. Indicate mode change to host.
- * 4. Indicate tablet mode to host. Current assumption is that if base is
- * disconnected then the system is in tablet mode, else if the base is
- * connected, then the system is not in tablet mode.
- */
-static void base_detect_change(enum base_status status)
-{
- int connected = (status == BASE_CONNECTED);
-
- if (current_base_status == status)
- return;
-
- current_base_status = status;
-
- /* Enable pull-down if connected. */
- gpio_set_level(GPIO_EN_CC_LID_BASE_PULLDN, !connected);
-
- /* We don't enable dual-battery support. Set the base power directly. */
- gpio_set_level(GPIO_EN_PPVAR_VAR_BASE, connected);
-
- tablet_set_mode(!connected);
-}
-
-static void print_base_detect_value(const char *str, int v)
-{
- CPRINTS("Base %s. ADC: %d", str, v);
-}
-
-static void base_detect_deferred(void)
-{
- uint64_t time_now = get_time().val;
- int v;
-
- if (base_detect_debounce_time > time_now) {
- hook_call_deferred(&base_detect_deferred_data,
- base_detect_debounce_time - time_now);
- return;
- }
-
- v = adc_read_channel(ADC_BASE_DET);
- if (v == ADC_READ_ERROR)
- goto retry;
-
- if (current_base_status == BASE_CONNECTED) {
- if (v >= BASE_CONNECTED_DISCONNECT_MIN_MV &&
- v <= BASE_CONNECTED_DISCONNECT_MAX_MV) {
- print_base_detect_value("disconnected", v);
- base_detect_change(BASE_DISCONNECTED);
- return;
- } else if (v >= BASE_CONNECTED_MIN_MV &&
- v <= BASE_CONNECTED_MAX_MV) {
- /* Still connected. */
- return;
- }
- } else { /* Disconnected or unknown. */
- if (v >= BASE_DISCONNECTED_CONNECT_MIN_MV &&
- v <= BASE_DISCONNECTED_CONNECT_MAX_MV) {
- print_base_detect_value("connected", v);
- base_detect_change(BASE_CONNECTED);
- return;
- } else if (v >= BASE_DISCONNECTED_MIN_MV &&
- v <= BASE_DISCONNECTED_MAX_MV) {
- if (current_base_status == BASE_UNKNOWN) {
- print_base_detect_value("disconnected", v);
- base_detect_change(BASE_DISCONNECTED);
- }
- /* Still disconnected. */
- return;
- }
- }
-
-retry:
- print_base_detect_value("status unclear", v);
- /* Unclear base status, schedule again in a while. */
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_RETRY_US);
-}
-
-void base_detect_interrupt(enum gpio_signal signal)
-{
- uint64_t time_now = get_time().val;
-
- if (base_detect_debounce_time <= time_now)
- hook_call_deferred(&base_detect_deferred_data,
- BASE_DETECT_DEBOUNCE_US);
-
- base_detect_debounce_time = time_now + BASE_DETECT_DEBOUNCE_US;
-}
-
-static void base_detect_enable(void)
-{
- /* Enable base detection interrupt. */
- base_detect_debounce_time = get_time().val;
- hook_call_deferred(&base_detect_deferred_data, 0);
- gpio_enable_interrupt(GPIO_CC_LID_BASE_ADC);
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, base_detect_enable, HOOK_PRIO_DEFAULT);
-
-static void base_detect_disable(void)
-{
- /* Disable base detection interrupt and disable power to base. */
- gpio_disable_interrupt(GPIO_CC_LID_BASE_ADC);
- base_detect_change(BASE_DISCONNECTED);
-}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, base_detect_disable, HOOK_PRIO_DEFAULT);
-
-static void base_init(void)
-{
- /*
- * Make sure base power and pull-down are off. This will reset the base
- * if it is already connected.
- */
- gpio_set_level(GPIO_EN_PPVAR_VAR_BASE, 0);
- gpio_set_level(GPIO_EN_CC_LID_BASE_PULLDN, 1);
-}
-DECLARE_HOOK(HOOK_INIT, base_init, HOOK_PRIO_DEFAULT+1);
-
-void base_force_state(int state)
-{
- if (state == 1) {
- gpio_disable_interrupt(GPIO_CC_LID_BASE_ADC);
- base_detect_change(BASE_CONNECTED);
- CPRINTS("BD forced connected");
- } else if (state == 0) {
- gpio_disable_interrupt(GPIO_CC_LID_BASE_ADC);
- base_detect_change(BASE_DISCONNECTED);
- CPRINTS("BD forced disconnected");
- } else {
- hook_call_deferred(&base_detect_deferred_data, 0);
- gpio_enable_interrupt(GPIO_CC_LID_BASE_ADC);
- CPRINTS("BD forced reset");
- }
-}
diff --git a/board/cheza/battery.c b/board/cheza/battery.c
deleted file mode 100644
index ab98864a9a..0000000000
--- a/board/cheza/battery.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/* 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"
-
-/* Shutdown mode parameter to write to manufacturer access register */
-#define SB_SHIP_MODE_REG SB_MANUFACTURER_ACCESS
-#define SB_SHUTDOWN_DATA 0x0010
-
-/* Battery info */
-static const struct battery_info info = {
- .voltage_max = 8800,
- .voltage_normal = 7700,
- .voltage_min = 6000,
- .precharge_current = 256, /* mA */
- .start_charging_min_c = 0,
- .start_charging_max_c = 45,
- .charging_min_c = 0,
- .charging_max_c = 45,
- .discharging_min_c = -10,
- .discharging_max_c = 60,
-};
-
-const struct battery_info *battery_get_info(void)
-{
- return &info;
-}
-
-int board_cut_off_battery(void)
-{
- int rv;
-
- /* Ship mode command must be sent twice to take effect */
- rv = sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
-
- if (rv != EC_SUCCESS)
- return rv;
-
- return sb_write(SB_SHIP_MODE_REG, SB_SHUTDOWN_DATA);
-}
diff --git a/board/cheza/board.c b/board/cheza/board.c
deleted file mode 100644
index 8fb927d436..0000000000
--- a/board/cheza/board.c
+++ /dev/null
@@ -1,700 +0,0 @@
-/* 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.
- */
-
-/* Cheza board-specific configuration */
-
-#include "adc_chip.h"
-#include "als.h"
-#include "button.h"
-#include "charge_manager.h"
-#include "charge_state.h"
-#include "chipset.h"
-#include "extpower.h"
-#include "driver/accelgyro_bmi160.h"
-#include "driver/als_opt3001.h"
-#include "driver/ppc/sn5s330.h"
-#include "driver/tcpm/anx74xx.h"
-#include "driver/tcpm/ps8xxx.h"
-#include "driver/tcpm/tcpci.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "lid_switch.h"
-#include "pi3usb9281.h"
-#include "power.h"
-#include "power_button.h"
-#include "pwm.h"
-#include "pwm_chip.h"
-#include "system.h"
-#include "shi_chip.h"
-#include "switch.h"
-#include "task.h"
-#include "usb_charge.h"
-#include "usb_mux.h"
-#include "usb_pd.h"
-#include "usbc_ppc.h"
-#include "util.h"
-
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-
-#define USB_PD_PORT_ANX3429 0
-#define USB_PD_PORT_PS8751 1
-
-/* Forward declaration */
-static void tcpc_alert_event(enum gpio_signal signal);
-static void vbus0_evt(enum gpio_signal signal);
-static void vbus1_evt(enum gpio_signal signal);
-static void usb0_evt(enum gpio_signal signal);
-static void usb1_evt(enum gpio_signal signal);
-static void ppc_interrupt(enum gpio_signal signal);
-static void anx74xx_cable_det_interrupt(enum gpio_signal signal);
-static void usb1_oc_evt(enum gpio_signal signal);
-
-#include "gpio_list.h"
-
-/* GPIO Interrupt Handlers */
-static void tcpc_alert_event(enum gpio_signal signal)
-{
- int port = -1;
-
- switch (signal) {
- case GPIO_USB_C0_PD_INT_ODL:
- port = 0;
- break;
- case GPIO_USB_C1_PD_INT_ODL:
- port = 1;
- break;
- default:
- return;
- }
-
- schedule_deferred_pd_interrupt(port);
-}
-
-static void vbus0_evt(enum gpio_signal signal)
-{
- /* VBUS present GPIO is inverted */
- usb_charger_vbus_change(0, !gpio_get_level(GPIO_USB_C0_VBUS_DET_L));
- task_wake(TASK_ID_PD_C0);
-}
-
-static void vbus1_evt(enum gpio_signal signal)
-{
- /* VBUS present GPIO is inverted */
- usb_charger_vbus_change(1, !gpio_get_level(GPIO_USB_C1_VBUS_DET_L));
- task_wake(TASK_ID_PD_C1);
-}
-
-static void usb0_evt(enum gpio_signal signal)
-{
- task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12, 0);
-}
-
-static void usb1_evt(enum gpio_signal signal)
-{
- task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12, 0);
-}
-
-static void anx74xx_cable_det_handler(void)
-{
- int cable_det = gpio_get_level(GPIO_USB_C0_CABLE_DET);
- int reset_n = gpio_get_level(GPIO_USB_C0_PD_RST_R_L);
-
- /*
- * A cable_det low->high transition was detected. If following the
- * debounce time, cable_det is high, and reset_n is low, then ANX3429 is
- * currently in standby mode and needs to be woken up. Set the
- * TCPC_RESET event which will bring the ANX3429 out of standby
- * mode. Setting this event is gated on reset_n being low because the
- * ANX3429 will always set cable_det when transitioning to normal mode
- * and if in normal mode, then there is no need to trigger a tcpc reset.
- */
- if (cable_det && !reset_n)
- task_set_event(TASK_ID_PD_C0, PD_EVENT_TCPC_RESET, 0);
-}
-DECLARE_DEFERRED(anx74xx_cable_det_handler);
-
-static void anx74xx_cable_det_interrupt(enum gpio_signal signal)
-{
- /* debounce for 2 msec */
- hook_call_deferred(&anx74xx_cable_det_handler_data, (2 * MSEC));
-}
-
-static void ppc_interrupt(enum gpio_signal signal)
-{
- /* Only port-0 uses PPC chip */
- sn5s330_interrupt(0);
-}
-
-static void usb1_oc_evt_deferred(void)
-{
- /* Only port-1 has overcurrent GPIO interrupt */
- board_overcurrent_event(1, 1);
-}
-DECLARE_DEFERRED(usb1_oc_evt_deferred);
-
-static void usb1_oc_evt(enum gpio_signal signal)
-{
- /* Switch the context to handle the event */
- hook_call_deferred(&usb1_oc_evt_deferred_data, 0);
-}
-
-/* Wake-up pins for hibernate */
-const enum gpio_signal hibernate_wake_pins[] = {
- GPIO_LID_OPEN,
- GPIO_AC_PRESENT,
- GPIO_POWER_BUTTON_L,
- GPIO_EC_RST_ODL,
-};
-const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins);
-
-/* ADC channels */
-const struct adc_t adc_channels[] = {
- /* Base detection */
- [ADC_BASE_DET] = {
- "BASE_DET",
- NPCX_ADC_CH0,
- ADC_MAX_VOLT,
- ADC_READ_MAX + 1,
- 0
- },
- /* Measure VBUS through a 1/10 voltage divider */
- [ADC_VBUS] = {
- "VBUS",
- NPCX_ADC_CH1,
- ADC_MAX_VOLT * 10,
- ADC_READ_MAX + 1,
- 0
- },
- /*
- * Adapter current output or battery charging/discharging current (uV)
- * 18x amplification on charger side.
- */
- [ADC_AMON_BMON] = {
- "AMON_BMON",
- NPCX_ADC_CH2,
- ADC_MAX_VOLT * 1000 / 18,
- ADC_READ_MAX + 1,
- 0
- },
- /*
- * ISL9238 PSYS output is 1.44 uA/W over 5.6K resistor, to read
- * 0.8V @ 99 W, i.e. 124000 uW/mV. Using ADC_MAX_VOLT*124000 and
- * ADC_READ_MAX+1 as multiplier/divider leads to overflows, so we
- * only divide by 2 (enough to avoid precision issues).
- */
- [ADC_PSYS] = {
- "PSYS",
- NPCX_ADC_CH3,
- ADC_MAX_VOLT * 124000 * 2 / (ADC_READ_MAX + 1),
- 2,
- 0
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
-
-const struct pwm_t pwm_channels[] = {
- /* TODO(waihong): Assign a proper frequency. */
- [PWM_CH_DISPLIGHT] = { 5, 0, 4800 },
-};
-BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
-
-
-/* Power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
- [SDM845_AP_RST_ASSERTED] = {
- GPIO_AP_RST_L,
- POWER_SIGNAL_ACTIVE_LOW | POWER_SIGNAL_DISABLE_AT_BOOT,
- "AP_RST_ASSERTED"},
- [SDM845_PS_HOLD] = {
- GPIO_PS_HOLD,
- POWER_SIGNAL_ACTIVE_HIGH,
- "PS_HOLD"},
- [SDM845_PMIC_FAULT_L] = {
- GPIO_PMIC_FAULT_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "PMIC_FAULT_L"},
- [SDM845_POWER_GOOD] = {
- GPIO_POWER_GOOD,
- POWER_SIGNAL_ACTIVE_HIGH,
- "POWER_GOOD"},
- [SDM845_WARM_RESET] = {
- GPIO_WARM_RESET_L,
- POWER_SIGNAL_ACTIVE_HIGH,
- "WARM_RESET_L"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
-/* I2C port map */
-const struct i2c_port_t i2c_ports[] = {
- {"power", I2C_PORT_POWER, 100, GPIO_I2C0_SCL, GPIO_I2C0_SDA},
- /* TODO(b/78189419): ANX7428 operates at 400kHz initially. */
- {"tcpc0", I2C_PORT_TCPC0, 400, GPIO_I2C1_SCL, GPIO_I2C1_SDA},
- {"tcpc1", I2C_PORT_TCPC1, 1000, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
- {"eeprom", I2C_PORT_EEPROM, 400, GPIO_I2C5_SCL, GPIO_I2C5_SDA},
- {"sensor", I2C_PORT_SENSOR, 400, GPIO_I2C7_SCL, GPIO_I2C7_SDA},
-};
-const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
-
-/* Power Path Controller */
-struct ppc_config_t ppc_chips[] = {
- {
- .i2c_port = I2C_PORT_TCPC0,
- .i2c_addr_flags = SN5S330_ADDR0_FLAGS,
- .drv = &sn5s330_drv
- },
- /*
- * Port 1 uses two power switches instead:
- * NX5P3290: to source VBUS
- * NX20P5090: to sink VBUS (charge battery)
- * which are controlled directly by EC GPIOs.
- */
-};
-unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
-
-/* TCPC mux configuration */
-const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- /* Alert is active-low, open-drain */
- [USB_PD_PORT_ANX3429] = {
- .bus_type = EC_BUS_TYPE_I2C,
- .i2c_info = {
- .port = I2C_PORT_TCPC0,
- .addr_flags = 0x28,
- },
- .drv = &anx74xx_tcpm_drv,
- .flags = TCPC_FLAGS_ALERT_OD,
- },
- [USB_PD_PORT_PS8751] = {
- .bus_type = EC_BUS_TYPE_I2C,
- .i2c_info = {
- .port = I2C_PORT_TCPC1,
- .addr_flags = 0x0B,
- },
- .drv = &ps8xxx_tcpm_drv,
- },
-};
-
-/*
- * Port-0 USB mux driver.
- *
- * The USB mux is handled by TCPC chip and the HPD is handled by AP.
- * Redirect to anx74xx_tcpm_usb_mux_driver but override the get() function
- * to check the HPD_IRQ mask from virtual_usb_mux_driver.
- */
-static int port0_usb_mux_init(int port)
-{
- return anx74xx_tcpm_usb_mux_driver.init(port);
-}
-
-static int port0_usb_mux_set(int i2c_addr, mux_state_t mux_state)
-{
- return anx74xx_tcpm_usb_mux_driver.set(i2c_addr, mux_state);
-}
-
-static int port0_usb_mux_get(int port, mux_state_t *mux_state)
-{
- int rv;
- mux_state_t virtual_mux_state;
-
- rv = anx74xx_tcpm_usb_mux_driver.get(port, mux_state);
- rv |= virtual_usb_mux_driver.get(port, &virtual_mux_state);
-
- if (virtual_mux_state & USB_PD_MUX_HPD_IRQ)
- *mux_state |= USB_PD_MUX_HPD_IRQ;
- return rv;
-}
-
-const struct usb_mux_driver port0_usb_mux_driver = {
- .init = port0_usb_mux_init,
- .set = port0_usb_mux_set,
- .get = port0_usb_mux_get,
-};
-
-/*
- * Port-1 USB mux driver.
- *
- * The USB mux is handled by TCPC chip and the HPD is handled by AP.
- * Redirect to tcpci_tcpm_usb_mux_driver but override the get() function
- * to check the HPD_IRQ mask from virtual_usb_mux_driver.
- */
-static int port1_usb_mux_init(int port)
-{
- return tcpci_tcpm_usb_mux_driver.init(port);
-}
-
-static int port1_usb_mux_set(int i2c_addr, mux_state_t mux_state)
-{
- return tcpci_tcpm_usb_mux_driver.set(i2c_addr, mux_state);
-}
-
-static int port1_usb_mux_get(int port, mux_state_t *mux_state)
-{
- int rv;
- mux_state_t virtual_mux_state;
-
- rv = tcpci_tcpm_usb_mux_driver.get(port, mux_state);
- rv |= virtual_usb_mux_driver.get(port, &virtual_mux_state);
-
- if (virtual_mux_state & USB_PD_MUX_HPD_IRQ)
- *mux_state |= USB_PD_MUX_HPD_IRQ;
- return rv;
-}
-
-static int port1_usb_mux_enter_low_power(int port)
-{
- return tcpci_tcpm_usb_mux_driver.enter_low_power_mode(port);
-}
-
-const struct usb_mux_driver port1_usb_mux_driver = {
- .init = &port1_usb_mux_init,
- .set = &port1_usb_mux_set,
- .get = &port1_usb_mux_get,
- .enter_low_power_mode = &port1_usb_mux_enter_low_power,
-};
-
-struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
- {
- .driver = &port0_usb_mux_driver,
- .hpd_update = &virtual_hpd_update,
- },
- {
- .driver = &port1_usb_mux_driver,
- .hpd_update = &virtual_hpd_update,
- }
-};
-
-/* BC1.2 */
-struct pi3usb9281_config pi3usb9281_chips[] = {
- {
- .i2c_port = I2C_PORT_POWER,
- },
- {
- .i2c_port = I2C_PORT_EEPROM,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
- CONFIG_BC12_DETECT_PI3USB9281_CHIP_COUNT);
-
-/* Initialize board. */
-static void board_init(void)
-{
- /* Enable BC1.2 VBUS detection */
- gpio_enable_interrupt(GPIO_USB_C0_VBUS_DET_L);
- gpio_enable_interrupt(GPIO_USB_C1_VBUS_DET_L);
-
- /* Enable BC1.2 interrupts */
- gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_L);
- gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_L);
-
- /* Enable interrupt for BMI160 sensor */
- gpio_enable_interrupt(GPIO_ACCEL_GYRO_INT_L);
-}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-
-void board_tcpc_init(void)
-{
- int port;
-
- /* Only reset TCPC if not sysjump */
- if (!system_jumped_to_this_image()) {
- /* TODO(crosbug.com/p/61098): How long do we need to wait? */
- board_reset_pd_mcu();
- }
-
- /* Enable PPC interrupts */
- gpio_enable_interrupt(GPIO_USB_C0_SWCTL_INT_ODL);
-
- /* Enable TCPC interrupts */
- gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
- gpio_enable_interrupt(GPIO_USB_C1_PD_INT_ODL);
-
- /* Enable CABLE_DET interrupt for ANX3429 wake from standby */
- gpio_enable_interrupt(GPIO_USB_C0_CABLE_DET);
-
- /*
- * Initialize HPD to low; after sysjump SOC needs to see
- * HPD pulse to enable video path
- */
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++) {
- const struct usb_mux *mux = &usb_muxes[port];
-
- mux->hpd_update(port, 0, 0);
- }
-}
-DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C+1);
-
-/* Called on AP S0 -> S3 transition */
-static void board_chipset_suspend(void)
-{
- /*
- * Turn off display backlight in S3. AP has its own control. The EC's
- * and the AP's will be AND'ed together in hardware.
- */
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
-}
-DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
-
-/* Called on AP S3 -> S0 transition */
-static void board_chipset_resume(void)
-{
- /* Turn on display backlight in S0. */
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);
-}
-DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
-
-/* Called on AP S5 -> S3 transition */
-static void board_chipset_startup(void)
-{
- gpio_set_flags(GPIO_USB_C1_OC_ODL, GPIO_INT_FALLING | GPIO_PULL_UP);
- gpio_enable_interrupt(GPIO_USB_C1_OC_ODL);
-}
-DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT);
-
-/* Called on AP S3 -> S5 transition */
-static void board_chipset_shutdown(void)
-{
- /* 5V is off in S5. Disable pull-up to prevent current leak. */
- gpio_disable_interrupt(GPIO_USB_C1_OC_ODL);
- gpio_set_flags(GPIO_USB_C1_OC_ODL, GPIO_INT_FALLING);
-}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT);
-
-/**
- * Power on (or off) a single TCPC.
- * minimum on/off delays are included.
- *
- * @param port Port number of TCPC.
- * @param mode 0: power off, 1: power on.
- */
-void board_set_tcpc_power_mode(int port, int mode)
-{
- if (port != USB_PD_PORT_ANX3429)
- return;
-
- if (mode) {
- gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 1);
- msleep(ANX74XX_PWR_H_RST_H_DELAY_MS);
- gpio_set_level(GPIO_USB_C0_PD_RST_R_L, 1);
- } else {
- gpio_set_level(GPIO_USB_C0_PD_RST_R_L, 0);
- msleep(ANX74XX_RST_L_PWR_L_DELAY_MS);
- gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 0);
- msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS);
- }
-}
-
-void board_reset_pd_mcu(void)
-{
- /* Assert reset */
- gpio_set_level(GPIO_USB_C0_PD_RST_R_L, 0);
- gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0);
-
- msleep(MAX(1, ANX74XX_RST_L_PWR_L_DELAY_MS));
- gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1);
- /* Disable TCPC0 (anx3429) power */
- gpio_set_level(GPIO_EN_USB_C0_TCPC_PWR, 0);
-
- msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS);
- board_set_tcpc_power_mode(USB_PD_PORT_ANX3429, 1);
-}
-
-int board_vbus_sink_enable(int port, int enable)
-{
- if (port == USB_PD_PORT_ANX3429) {
- /* Port 0 is controlled by a PPC SN5S330 */
- return ppc_vbus_sink_enable(port, enable);
- } else if (port == USB_PD_PORT_PS8751) {
- /* Port 1 is controlled by a power switch NX20P5090 */
- gpio_set_level(GPIO_EN_USB_C1_CHARGE_EC_L, !enable);
- return EC_SUCCESS;
- }
- return EC_ERROR_INVAL;
-}
-
-int board_is_sourcing_vbus(int port)
-{
- if (port == USB_PD_PORT_ANX3429) {
- /* Port 0 is controlled by a PPC SN5S330 */
- return ppc_is_sourcing_vbus(port);
- } else if (port == USB_PD_PORT_PS8751) {
- /* Port 1 is controlled by a power switch NX5P3290 */
- return gpio_get_level(GPIO_EN_USB_C1_5V_OUT);
- }
- return EC_ERROR_INVAL;
-}
-
-void board_overcurrent_event(int port, int is_overcurrented)
-{
- /* TODO(b/120231371): Notify AP */
- CPRINTS("p%d: overcurrent!", port);
-}
-
-int board_set_active_charge_port(int port)
-{
- int is_real_port = (port >= 0 &&
- port < CONFIG_USB_PD_PORT_MAX_COUNT);
- int i;
- int rv;
-
- if (!is_real_port && port != CHARGE_PORT_NONE)
- return EC_ERROR_INVAL;
-
- CPRINTS("New chg p%d", port);
-
- if (port == CHARGE_PORT_NONE) {
- /* Disable all ports. */
- for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
- rv = board_vbus_sink_enable(i, 0);
- if (rv) {
- CPRINTS("Disabling p%d sink path failed.", i);
- return rv;
- }
- }
-
- return EC_SUCCESS;
- }
-
- /* Check if the port is sourcing VBUS. */
- if (board_is_sourcing_vbus(port)) {
- CPRINTF("Skip enable p%d", port);
- return EC_ERROR_INVAL;
- }
-
- /*
- * Turn off the other ports' sink path FETs, before enabling the
- * requested charge port.
- */
- for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++) {
- if (i == port)
- continue;
-
- if (board_vbus_sink_enable(i, 0))
- CPRINTS("p%d: sink path disable failed.", i);
- }
-
- /* Enable requested charge port. */
- if (board_vbus_sink_enable(port, 1)) {
- CPRINTS("p%d: sink path enable failed.", port);
- return EC_ERROR_UNKNOWN;
- }
-
- return EC_SUCCESS;
-}
-
-void board_set_charge_limit(int port, int supplier, int charge_ma,
- int max_ma, int charge_mv)
-{
- /*
- * Ignore lower charge ceiling on PD transition if our battery is
- * critical, as we may brownout.
- */
- if (supplier == CHARGE_SUPPLIER_PD &&
- charge_ma < 1500 &&
- charge_get_percent() < CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) {
- CPRINTS("Using max ilim %d", max_ma);
- charge_ma = max_ma;
- }
-
- charge_set_input_current_limit(MAX(charge_ma,
- CONFIG_CHARGER_INPUT_CURRENT),
- charge_mv);
-}
-
-uint16_t tcpc_get_alert_status(void)
-{
- uint16_t status = 0;
-
- if (!gpio_get_level(GPIO_USB_C0_PD_INT_ODL))
- if (gpio_get_level(GPIO_USB_C0_PD_RST_R_L))
- status |= PD_STATUS_TCPC_ALERT_0;
- if (!gpio_get_level(GPIO_USB_C1_PD_INT_ODL))
- if (gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
- status |= PD_STATUS_TCPC_ALERT_1;
-
- return status;
-}
-
-/* Mutexes */
-static struct mutex g_lid_mutex;
-
-static struct bmi160_drv_data_t g_bmi160_data;
-static struct opt3001_drv_data_t g_opt3001_data = {
- .scale = 1,
- .uscale = 0,
- .offset = 0,
-};
-
-/* Matrix to rotate accelerometer into standard reference frame */
-const mat33_fp_t base_standard_ref = {
- { FLOAT_TO_FP(-1), 0, 0},
- { 0, FLOAT_TO_FP(-1), 0},
- { 0, 0, FLOAT_TO_FP(1)}
-};
-
-struct motion_sensor_t motion_sensors[] = {
- /*
- * Note: bmi160: supports accelerometer and gyro sensor
- * Requirement: accelerometer sensor must init before gyro sensor
- * DO NOT change the order of the following table.
- */
- [LID_ACCEL] = {
- .name = "Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3_S5,
- .chip = MOTIONSENSE_CHIP_BMI160,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &bmi160_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_bmi160_data,
- .port = I2C_PORT_SENSOR,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .rot_standard_ref = &base_standard_ref,
- .default_range = 4, /* g */
- .min_frequency = BMI160_ACCEL_MIN_FREQ,
- .max_frequency = BMI160_ACCEL_MAX_FREQ,
- .config = {
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- },
- },
- [LID_GYRO] = {
- .name = "Gyro",
- .active_mask = SENSOR_ACTIVE_S0_S3_S5,
- .chip = MOTIONSENSE_CHIP_BMI160,
- .type = MOTIONSENSE_TYPE_GYRO,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &bmi160_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_bmi160_data,
- .port = I2C_PORT_SENSOR,
- .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
- .default_range = 1000, /* dps */
- .rot_standard_ref = &base_standard_ref,
- .min_frequency = BMI160_GYRO_MIN_FREQ,
- .max_frequency = BMI160_GYRO_MAX_FREQ,
- },
- [LID_ALS] = {
- .name = "Light",
- .active_mask = SENSOR_ACTIVE_S0,
- .chip = MOTIONSENSE_CHIP_OPT3001,
- .type = MOTIONSENSE_TYPE_LIGHT,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &opt3001_drv,
- .drv_data = &g_opt3001_data,
- .port = I2C_PORT_SENSOR,
- .i2c_spi_addr_flags = OPT3001_I2C_ADDR_FLAGS,
- .rot_standard_ref = NULL,
- .default_range = 0x10000, /* scale = 1; uscale = 0 */
- .min_frequency = OPT3001_LIGHT_MIN_FREQ,
- .max_frequency = OPT3001_LIGHT_MAX_FREQ,
- .config = {
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 1000,
- },
- },
- },
-};
-const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
diff --git a/board/cheza/board.h b/board/cheza/board.h
deleted file mode 100644
index 76e64277b5..0000000000
--- a/board/cheza/board.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/* 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.
- */
-
-/* Cheza board configuration */
-
-#ifndef __CROS_EC_BOARD_H
-#define __CROS_EC_BOARD_H
-
-/* TODO(waihong): Remove the following bringup features */
-#define CONFIG_BRINGUP
-#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands. */
-#define CONFIG_USB_PD_DEBUG_LEVEL 3
-#define CONFIG_CMD_AP_RESET_LOG
-#define CONFIG_HOSTCMD_AP_RESET
-
-/*
- * By default, enable all console messages excepted event and HC:
- * The sensor stack is generating a lot of activity.
- * They can be enabled through the console command 'chan'.
- */
-#define CC_DEFAULT (CC_ALL & ~(CC_MASK(CC_EVENTS) | CC_MASK(CC_HOSTCMD)))
-
-/* NPCX7 config */
-#define NPCX_UART_MODULE2 1 /* GPIO64/65 are used as UART pins. */
-#define NPCX_TACH_SEL2 0 /* No tach. */
-#define NPCX7_PWM1_SEL 0 /* GPIO C2 is not used as PWM1. */
-
-/* Internal SPI flash on NPCX7 */
-#define CONFIG_FLASH_SIZE (1024 * 1024) /* 1MB internal spi flash */
-#define CONFIG_SPI_FLASH_REGS
-#define CONFIG_SPI_FLASH_W25Q80 /* Internal SPI flash type. */
-#define CONFIG_HOSTCMD_FLASH_SPI_INFO
-
-/* EC Modules */
-#define CONFIG_I2C
-#define CONFIG_I2C_MASTER
-#define CONFIG_LED_COMMON
-#define CONFIG_LOW_POWER_IDLE
-#define CONFIG_ADC
-#define CONFIG_BACKLIGHT_LID
-#define CONFIG_FPU
-#define CONFIG_PWM
-#define CONFIG_PWM_DISPLIGHT
-
-#define CONFIG_VBOOT_HASH
-
-#define CONFIG_DETACHABLE_BASE
-
-#undef CONFIG_PECI
-
-#define CONFIG_HOSTCMD_SPS
-#define CONFIG_HOST_COMMAND_STATUS
-#define CONFIG_HOSTCMD_SECTION_SORTED /* Host commands are sorted. */
-#define CONFIG_MKBP_EVENT
-#define CONFIG_KEYBOARD_PROTOCOL_MKBP
-#define CONFIG_MKBP_USE_GPIO
-
-#define CONFIG_BOARD_VERSION_GPIO
-#define CONFIG_POWER_BUTTON
-#define CONFIG_VOLUME_BUTTONS
-#define CONFIG_BUTTON_TRIGGERED_RECOVERY
-#define CONFIG_EMULATED_SYSRQ
-#define CONFIG_CMD_BUTTON
-#define CONFIG_SWITCH
-#define CONFIG_LID_SWITCH
-#define CONFIG_EXTPOWER_GPIO
-
-#define CONFIG_TABLET_MODE
-#define CONFIG_TABLET_MODE_SWITCH
-
-/* Battery */
-#define CONFIG_BATTERY_CUT_OFF
-#define CONFIG_BATTERY_PRESENT_GPIO GPIO_BATT_PRES_ODL
-#define CONFIG_BATTERY_SMART
-
-/* Charger */
-#define CONFIG_CHARGER
-#define CONFIG_CHARGE_MANAGER
-#define CONFIG_CHARGER_ISL9238
-#define CONFIG_CHARGE_RAMP_HW
-#define CONFIG_USB_CHARGER
-#define CONFIG_CMD_CHARGER_ADC_AMON_BMON
-#define CONFIG_CHARGER_PSYS
-#define CONFIG_CHARGER_PSYS_READ
-#define CONFIG_CHARGER_DISCHARGE_ON_AC
-
-#define CONFIG_CHARGER_INPUT_CURRENT 512
-#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2
-#define CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON 7500
-#define CONFIG_CHARGER_SENSE_RESISTOR 10
-#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20
-
-/* BC 1.2 Charger */
-#define CONFIG_BC12_DETECT_PI3USB9281
-#define CONFIG_BC12_DETECT_PI3USB9281_CHIP_COUNT 2
-
-/* USB */
-#define CONFIG_USB_POWER_DELIVERY
-#define CONFIG_CMD_PD_CONTROL
-#define CONFIG_USB_PD_ALT_MODE
-#define CONFIG_USB_PD_ALT_MODE_DFP
-#define CONFIG_USB_PD_DISCHARGE_PPC
-#define CONFIG_USB_PD_DUAL_ROLE
-#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
-#define CONFIG_USB_PD_LOGGING
-#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0
-#define CONFIG_USB_PD_PORT_MAX_COUNT 2
-#define CONFIG_USB_PD_TCPC_LOW_POWER
-#define CONFIG_USB_PD_TCPM_ANX3429
-#define CONFIG_USB_PD_TCPM_PS8751
-#define CONFIG_USB_PD_TCPM_MUX
-#define CONFIG_USB_PD_TCPM_TCPCI
-#define CONFIG_USB_PD_TRY_SRC
-#define CONFIG_USB_PD_VBUS_DETECT_CHARGER
-#define CONFIG_USB_PD_5V_EN_CUSTOM
-#define CONFIG_USB_MUX_VIRTUAL
-#define CONFIG_USBC_PPC_SN5S330
-#define CONFIG_USBC_SS_MUX
-#define CONFIG_USBC_VCONN
-#define CONFIG_USBC_VCONN_SWAP
-
-/* RTC */
-#define CONFIG_CMD_RTC
-#define CONFIG_HOSTCMD_RTC
-
-/* Sensors */
-#define CONFIG_ACCELGYRO_BMI160
-#define CONFIG_ACCEL_INTERRUPTS
-#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
- TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
-/* Enable sensor fifo, must also define the _SIZE and _THRES */
-#define CONFIG_ACCEL_FIFO
-/* FIFO size is a power of 2. */
-#define CONFIG_ACCEL_FIFO_SIZE 256
-/* Depends on how fast the AP boots and typical ODRs. */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3)
-#define CONFIG_CMD_ACCELS
-#define CONFIG_CMD_ACCEL_INFO
-#define CONFIG_ALS
-#define CONFIG_ALS_OPT3001
-#define ALS_COUNT 1
-#define OPT3001_I2C_ADDR_FLAGS OPT3001_I2C_ADDR1_FLAGS
-
-/* PD */
-#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 */
-
-#define PD_OPERATING_POWER_MW 15000
-#define PD_MAX_POWER_MW ((PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA) / 1000)
-#define PD_MAX_CURRENT_MA 3000
-#define PD_MAX_VOLTAGE_MV 20000
-
-/* Chipset */
-#define CONFIG_CHIPSET_SDM845
-#define CONFIG_CHIPSET_RESET_HOOK
-#define CONFIG_POWER_COMMON
-#define CONFIG_POWER_PP5000_CONTROL
-
-/* NPCX Features */
-#define CONFIG_HIBERNATE_PSL
-
-/* I2C Ports */
-#define I2C_PORT_BATTERY I2C_PORT_POWER
-#define I2C_PORT_CHARGER I2C_PORT_POWER
-#define I2C_PORT_ACCEL I2C_PORT_SENSOR
-#define I2C_PORT_POWER NPCX_I2C_PORT0_0
-#define I2C_PORT_TCPC0 NPCX_I2C_PORT1_0
-#define I2C_PORT_TCPC1 NPCX_I2C_PORT2_0
-#define I2C_PORT_EEPROM NPCX_I2C_PORT5_0
-#define I2C_PORT_SENSOR NPCX_I2C_PORT7_0
-
-#ifndef __ASSEMBLER__
-
-#include "gpio_signal.h"
-#include "registers.h"
-
-enum power_signal {
- SDM845_AP_RST_ASSERTED = 0,
- SDM845_PS_HOLD,
- SDM845_PMIC_FAULT_L,
- SDM845_POWER_GOOD,
- SDM845_WARM_RESET,
- /* Number of power signals */
- POWER_SIGNAL_COUNT
-};
-
-enum adc_channel {
- ADC_BASE_DET,
- ADC_VBUS,
- ADC_AMON_BMON,
- ADC_PSYS,
- ADC_CH_COUNT
-};
-
-/* Motion sensors */
-enum sensor_id {
- LID_ACCEL = 0,
- LID_GYRO,
- LID_ALS,
- SENSOR_COUNT,
-};
-
-enum pwm_channel {
- PWM_CH_DISPLIGHT,
- PWM_CH_COUNT
-};
-
-/* Custom function to indicate if sourcing VBUS */
-int board_is_sourcing_vbus(int port);
-/* Enable VBUS sink for a given port */
-int board_vbus_sink_enable(int port, int enable);
-/* Reset all TCPCs. */
-void board_reset_pd_mcu(void);
-/* Base detection interrupt handler */
-void base_detect_interrupt(enum gpio_signal signal);
-
-/* Sensors without hardware FIFO are in forced mode */
-#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ALS)
-
-#endif /* !defined(__ASSEMBLER__) */
-
-#endif /* __CROS_EC_BOARD_H */
diff --git a/board/cheza/build.mk b/board/cheza/build.mk
deleted file mode 100644
index 2e8e53ec88..0000000000
--- a/board/cheza/build.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-# -*- makefile -*-
-# 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.
-#
-# Board specific files build
-#
-
-CHIP:=npcx
-CHIP_FAMILY:=npcx7
-CHIP_VARIANT:=npcx7m7wb
-
-board-y=battery.o board.o led.o usb_pd_policy.o base_detect.o
diff --git a/board/cheza/ec.tasklist b/board/cheza/ec.tasklist
deleted file mode 100644
index c38fe0495a..0000000000
--- a/board/cheza/ec.tasklist
+++ /dev/null
@@ -1,23 +0,0 @@
-/* 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.
- */
-
-/*
- * See CONFIG_TASK_LIST in config.h for details.
- */
-
-#define CONFIG_TASK_LIST \
- TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
- TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, TASK_STACK_SIZE) \
- TASK_ALWAYS(USB_CHG_P1, usb_charger_task, NULL, TASK_STACK_SIZE) \
- TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
- TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
- TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_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, 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) \
- TASK_ALWAYS(PD_INT_C0, pd_interrupt_handler_task, 0, TASK_STACK_SIZE) \
- TASK_ALWAYS(PD_INT_C1, pd_interrupt_handler_task, 1, TASK_STACK_SIZE)
diff --git a/board/cheza/gpio.inc b/board/cheza/gpio.inc
deleted file mode 100644
index bc9d12ad79..0000000000
--- a/board/cheza/gpio.inc
+++ /dev/null
@@ -1,169 +0,0 @@
-/* -*- mode:c -*-
- *
- * 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.
- */
-
-/* Declare symbolic names for all the GPIOs that we care about.
- * Note: Those with interrupt handlers must be declared first. */
-
-/* USB-C interrupts */
-GPIO_INT(USB_C0_PD_INT_ODL, PIN(A, 0), GPIO_INT_FALLING, tcpc_alert_event) /* Interrupt from port-0 TCPC */
-GPIO_INT(USB_C1_PD_INT_ODL, PIN(F, 5), GPIO_INT_FALLING, tcpc_alert_event) /* Interrupt from port-1 TCPC */
-GPIO_INT(USB_C0_SWCTL_INT_ODL, PIN(0, 3), GPIO_INT_FALLING, ppc_interrupt) /* Interrupt from port-0 PPC */
-GPIO_INT(USB_C0_BC12_INT_L, PIN(6, 1), GPIO_INT_FALLING, usb0_evt) /* Interrupt from port-0 BC1.2 */
-GPIO_INT(USB_C1_BC12_INT_L, PIN(8, 2), GPIO_INT_FALLING, usb1_evt) /* Interrupt from port-1 BC1.2 */
-GPIO_INT(USB_C0_VBUS_DET_L, PIN(6, 2), GPIO_INT_BOTH | GPIO_PULL_UP, vbus0_evt) /* BC1.2 VBUS detection on port-0 */
-GPIO_INT(USB_C1_VBUS_DET_L, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, vbus1_evt) /* BC1.2 VBUS detection on port-1 */
-GPIO_INT(USB_C0_CABLE_DET, PIN(3, 7), GPIO_INT_RISING, anx74xx_cable_det_interrupt) /* Cable detection from port-0 TCPC */
-GPIO_INT(USB_C1_OC_ODL, PIN(7, 2), GPIO_INT_FALLING, usb1_oc_evt) /* Port-1 power switch over-current */
-GPIO_INT(ACCEL_GYRO_INT_L, PIN(D, 3), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt) /* Accelerometer/gyro interrupt */
-
-/* System interrupts */
-GPIO_INT(AC_PRESENT, PIN(0, 0), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, extpower_interrupt) /* ACOK_OD */
-GPIO_INT(POWER_BUTTON_L, PIN(0, 1), GPIO_INT_BOTH, power_button_interrupt) /* EC_PWR_BTN_ODL */
-GPIO_INT(VOLUME_DOWN_L, PIN(7, 0), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) /* EC_VOLDN_BTN_ODL */
-GPIO_INT(VOLUME_UP_L, PIN(F, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) /* EC_VOLUP_BTN_ODL */
-GPIO_INT(WP_L, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt) /* EC_WP_ODL */
-GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, lid_interrupt) /* LID_OPEN_EC */
-GPIO_INT(AP_RST_REQ, PIN(C, 2), GPIO_INT_RISING | GPIO_PULL_DOWN | GPIO_SEL_1P8V, chipset_reset_request_interrupt) /* Reset request from AP */
-GPIO_INT(AP_RST_L, PIN(C, 1), GPIO_INT_BOTH | GPIO_SEL_1P8V, power_signal_interrupt)
-GPIO_INT(PS_HOLD, PIN(D, 4), GPIO_INT_BOTH | GPIO_PULL_DOWN | GPIO_SEL_1P8V, power_signal_interrupt) /* Indicate when AP triggers reset/shutdown */
-GPIO_INT(PMIC_FAULT_L, PIN(7, 6), GPIO_INT_BOTH | GPIO_SEL_1P8V, power_signal_interrupt) /* Any PMIC fault? */
-/*
- * When switch-cap is off, the POWER_GOOD signal is floating. Need a pull-down
- * to make it low. Overload the interrupt function chipset_warm_reset_interrupt
- * for not only signalling power_signal_interrupt but also handling the logic
- * of WARM_RESET_L which is pulled-up by the same rail of POWER_GOOD.
- */
-GPIO_INT(POWER_GOOD, PIN(5, 4), GPIO_INT_BOTH | GPIO_PULL_DOWN, chipset_warm_reset_interrupt) /* SRC_PP1800_S4A from PMIC */
-GPIO_INT(WARM_RESET_L, PIN(F, 4), GPIO_INT_BOTH | GPIO_SEL_1P8V, chipset_warm_reset_interrupt) /* AP warm reset */
-GPIO_INT(SHI_CS_L, PIN(5, 3), GPIO_INT_FALLING | GPIO_PULL_DOWN, shi_cs_event) /* AP_EC_SPI_CS_L */
-GPIO_INT(CC_LID_BASE_ADC, PIN(4, 5), GPIO_INT_BOTH, base_detect_interrupt) /* Base detection */
-
-/*
- * EC_RST_ODL acts as a wake source from PSL hibernate mode. However, it does
- * not need to be an interrupt for normal EC operations. Thus, configure it as
- * GPIO_INT_BOTH with wake on low-to-high edge using GPIO_HIB_WAKE_HIGH so that
- * PSL common code can configure PSL_IN correctly.
- *
- * Use the rising edge to wake EC up. If we chose the falling edge, it would
- * still wake EC up, but EC is in an intermediate state until the signal goes
- * back to high.
- */
-GPIO(EC_RST_ODL, PIN(0, 2), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH) /* Wake source: EC reset */
-GPIO(ENTERING_RW, PIN(E, 1), GPIO_OUT_LOW) /* EC_ENTERING_RW: Indicate when EC is entering RW code */
-GPIO(CCD_MODE_ODL, PIN(E, 3), GPIO_INPUT) /* Case Closed Debug Mode */
-GPIO(BATT_PRES_ODL, PIN(E, 5), GPIO_INPUT) /* EC_BATT_PRES_ODL: Battery Present */
-GPIO(PROCHOT_L, PIN(3, 4), GPIO_INPUT)
-
-/* PMIC/AP 1.8V */
-GPIO(PM845_RESIN_L, PIN(3, 2), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* PMIC reset trigger */
-GPIO(PMIC_KPD_PWR_ODL, PIN(D, 6), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* PMIC power button */
-GPIO(EC_INT_L, PIN(A, 2), GPIO_ODR_HIGH) /* Interrupt line between AP and EC */
-GPIO(AP_SUSPEND_L, PIN(5, 7), GPIO_INPUT) /* Suspend signal from AP */
-
-/* Power enables */
-GPIO(SWITCHCAP_ON_L, PIN(D, 5), GPIO_OUT_LOW) /* Enable switch cap. XXX: It's active-high */
-GPIO(VBOB_EN, PIN(9, 5), GPIO_OUT_LOW) /* Enable VBOB */
-GPIO(EN_PP3300_A, PIN(A, 6), GPIO_OUT_LOW) /* Enable PP3300 */
-GPIO(EN_PP5000, PIN(6, 7), GPIO_OUT_LOW) /* EN_PP5000_A: Enable PP5000 */
-GPIO(ENABLE_BACKLIGHT, PIN(B, 6), GPIO_OUT_LOW) /* EC_BL_DISABLE_L: Backlight disable signal from EC */
-
-/* Sensors */
-GPIO(ALS_INT_L, PIN(5, 0), GPIO_INPUT) /* ALS sensor interrupt */
-GPIO(P_SENSOR_INT_L, PIN(F, 3), GPIO_INPUT | GPIO_SEL_1P8V) /* P-sensor interrupt */
-GPIO(RCAM_VSYNC, PIN(4, 0), GPIO_INPUT | GPIO_SEL_1P8V) /* VSYNC from rear camera */
-
-/* Base */
-GPIO(EN_PPVAR_VAR_BASE, PIN(0, 4), GPIO_OUT_LOW) /* Power to the base */
-GPIO(EN_CC_LID_BASE_PH, PIN(D, 1), GPIO_ODR_HIGH)
-GPIO(EN_CC_LID_BASE_PULLDN, PIN(D, 0), GPIO_ODR_HIGH)
-GPIO(REVERSE_DOCK_EC, PIN(C, 6), GPIO_INPUT) /* Indicate if the dock is reversed */
-GPIO(CC_LID_RX_BASE_TX, PIN(7, 5), GPIO_INPUT)
-GPIO(CC_LID_RX_BASE_RX, PIN(8, 6), GPIO_INPUT)
-
-/* LEDs */
-GPIO(CHG_LED_Y_C0, PIN(C, 3), GPIO_OUT_LOW) /* EC_CHG_LED_Y_C0 */
-GPIO(CHG_LED_W_C0, PIN(C, 4), GPIO_OUT_LOW) /* EC_CHG_LED_W_C0 */
-GPIO(CHG_LED_Y_C1, PIN(6, 0), GPIO_OUT_LOW) /* EC_CHG_LED_Y_C1 */
-GPIO(CHG_LED_W_C1, PIN(C, 0), GPIO_OUT_LOW) /* EC_CHG_LED_W_C1 */
-
-/*
- * USB HS muxes
- *
- * C0_MUX:D ----- C0_BC12 ---- C0_PORT
- * AP --+------- C0_MUX:D1
- * | +--- C0_MUX:D2
- * | |
- * | |
- * | | C1_MUX:D ----- C1_BC12 ---- C1_PORT
- * | | +- C1_MUX:D1
- * +------- C1_MUX:D2
- * | |
- * AP --- USB_HUB
- */
-/* Switch both port-0 and port-1 to the hub, which matches the SS path. */
-GPIO(USB_C0_HS_MUX_OE_L, PIN(A, 4), GPIO_OUT_LOW)
-GPIO(USB_C0_HS_MUX_SEL, PIN(A, 3), GPIO_OUT_HIGH) /* L:D1(AP), H:D2(hub) */
-GPIO(USB_C1_HS_MUX_OE_L, PIN(7, 3), GPIO_OUT_LOW)
-GPIO(USB_C1_HS_MUX_SEL, PIN(7, 4), GPIO_OUT_LOW) /* L:D1(hub), H:D2(AP) */
-
-/* USB-C port-0 controls */
-GPIO(USB_C0_PD_RST_R_L, PIN(F, 1), GPIO_OUT_HIGH) /* Port-0 TCPC chip reset */
-GPIO(EN_USB_C0_TCPC_PWR, PIN(C, 5), GPIO_OUT_LOW) /* Port-0 TCPC power enable */
-
-/* USB-C port-1 controls */
-GPIO(USB_C1_PD_RST_ODL, PIN(E, 4), GPIO_ODR_HIGH) /* Port-1 TCPC chip reset */
-GPIO(EN_USB_C1_5V_OUT, PIN(6, 3), GPIO_OUT_LOW) /* Port-1 power switch 5V output */
-GPIO(EN_USB_C1_3A, PIN(5, 6), GPIO_OUT_LOW) /* Port-1 power switch 3A current */
-GPIO(EN_USB_C1_CHARGE_EC_L, PIN(B, 1), GPIO_OUT_LOW) /* Port-1 enable charging */
-GPIO(USBC_MUX_CONF1, PIN(5, 1), GPIO_OUT_HIGH) /* Port-1 enable DP switch */
-
-/* USB-C port-1 interrupts */
-GPIO(USB_C1_DP_HPD, PIN(9, 6), GPIO_INPUT) /* DP HPD from port-1 TCPC */
-
-/* I2C */
-GPIO(I2C0_SCL, PIN(B, 5), GPIO_INPUT) /* EC_I2C_POWER_SCL */
-GPIO(I2C0_SDA, PIN(B, 4), GPIO_INPUT) /* EC_I2C_POWER_SDA */
-GPIO(I2C1_SCL, PIN(9, 0), GPIO_INPUT) /* EC_I2C_USB_C0_PD_SCL */
-GPIO(I2C1_SDA, PIN(8, 7), GPIO_INPUT) /* EC_I2C_USB_C0_PD_SDA */
-GPIO(I2C2_SCL, PIN(9, 2), GPIO_INPUT) /* EC_I2C_USB_C1_PD_SCL */
-GPIO(I2C2_SDA, PIN(9, 1), GPIO_INPUT) /* EC_I2C_USB_C1_PD_SDA */
-GPIO(I2C5_SCL, PIN(3, 3), GPIO_INPUT) /* EC_I2C_EEPROM_SCL */
-GPIO(I2C5_SDA, PIN(3, 6), GPIO_INPUT) /* EC_I2C_EEPROM_SDA */
-GPIO(I2C7_SCL, PIN(B, 3), GPIO_INPUT |
- GPIO_SEL_1P8V) /* EC_I2C_SENSOR_SCL */
-GPIO(I2C7_SDA, PIN(B, 2), GPIO_INPUT |
- GPIO_SEL_1P8V) /* EC_I2C_SENSOR_SDA */
-
-/* Board/SKU IDs */
-GPIO(BOARD_VERSION1, PIN(C, 7), GPIO_INPUT) /* BRD_ID1 */
-GPIO(BOARD_VERSION2, PIN(9, 3), GPIO_INPUT) /* BRD_ID2 */
-GPIO(BOARD_VERSION3, PIN(8, 0), GPIO_INPUT) /* BRD_ID3 */
-GPIO(SKU_ID1, PIN(F, 0), GPIO_INPUT)
-GPIO(SKU_ID2, PIN(4, 1), GPIO_INPUT)
-
-/* Switchcap */
-/*
- * GPIO0 is configured as PVC_PG. When the chip in power down mode, it outputs
- * high-Z. Set pull-down to avoid floating.
- */
-GPIO(DA9313_GPIO0, PIN(E, 2), GPIO_INPUT | GPIO_PULL_DOWN) /* Switchcap GPIO0 */
-
-/* Alternate functions GPIO definitions */
-ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART (GPIO64/65) */
-ALTERNATE(PIN_MASK(B, 0x30), 1, MODULE_I2C, 0) /* I2C0 (GPIOB4/B5) */
-ALTERNATE(PIN_MASK(9, 0x07), 1, MODULE_I2C, 0) /* I2C1 SDA (GPIO90), I2C2 (GPIO91/92) */
-ALTERNATE(PIN_MASK(8, 0x80), 1, MODULE_I2C, 0) /* I2C1 SCL (GPIO87) */
-ALTERNATE(PIN_MASK(3, 0x48), 1, MODULE_I2C, 0) /* I2C5 (GPIO33/36) */
-ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, GPIO_SEL_1P8V) /* I2C7 (GPIOB2/B3) - 1.8V */
-ALTERNATE(PIN_MASK(4, 0x1C), 0, MODULE_ADC, 0) /* ADC1 (GPIO44), ADC2 (GPIO43), ADC3 (GPIO42) */
-ALTERNATE(PIN_MASK(4, 0xC0), 1, MODULE_SPI, GPIO_SEL_1P8V) /* SHI_SDO (GPIO47), SHI_SDI (GPIO46) */
-ALTERNATE(PIN_MASK(5, 0x28), 1, MODULE_SPI, GPIO_SEL_1P8V) /* SHI_SCLK (GPIO55), SHI_CS# (GPIO53) */
-ALTERNATE(PIN_MASK(B, 0x80), 1, MODULE_PWM, 0) /* PWM5 (GPIOB7) */
-ALTERNATE(PIN_MASK(D, 0x04), 1, MODULE_PMU, 0) /* PSL_IN1 (GPIOD2) - LID_OPEN_EC */
-ALTERNATE(PIN_MASK(0, 0x01), 1, MODULE_PMU, 0) /* PSL_IN2 (GPIO00) - ACOK_OD */
-ALTERNATE(PIN_MASK(0, 0x02), 1, MODULE_PMU, 0) /* PSL_IN3 (GPIO01) - EC_PWR_BTN_ODL */
-ALTERNATE(PIN_MASK(0, 0x04), 1, MODULE_PMU, 0) /* PSL_IN4 (GPIO02) - EC_RST_ODL */
diff --git a/board/cheza/led.c b/board/cheza/led.c
deleted file mode 100644
index 21ca78cb5c..0000000000
--- a/board/cheza/led.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* 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.
- *
- * Power and battery LED control.
- */
-
-#include "battery.h"
-#include "charge_manager.h"
-#include "charge_state.h"
-#include "chipset.h"
-#include "ec_commands.h"
-#include "gpio.h"
-#include "hooks.h"
-#include "host_command.h"
-#include "led_common.h"
-#include "system.h"
-#include "util.h"
-
-#define BAT_LED_ON 1
-#define BAT_LED_OFF 0
-
-const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_RIGHT_LED,
- EC_LED_ID_LEFT_LED,
-};
-
-const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-
-enum led_color {
- LED_OFF = 0,
- LED_AMBER,
- LED_WHITE,
- LED_COLOR_COUNT /* Number of colors, not a color itself */
-};
-
-static void side_led_set_color(int port, enum led_color color)
-{
- gpio_set_level(port ? GPIO_CHG_LED_Y_C1 : GPIO_CHG_LED_Y_C0,
- (color == LED_AMBER) ? BAT_LED_ON : BAT_LED_OFF);
- gpio_set_level(port ? GPIO_CHG_LED_W_C1 : GPIO_CHG_LED_W_C0,
- (color == LED_WHITE) ? BAT_LED_ON : BAT_LED_OFF);
-}
-
-void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
-{
- brightness_range[EC_LED_COLOR_AMBER] = 1;
- brightness_range[EC_LED_COLOR_WHITE] = 1;
-}
-
-int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
-{
- int port;
-
- switch (led_id) {
- case EC_LED_ID_RIGHT_LED:
- port = 0;
- break;
- case EC_LED_ID_LEFT_LED:
- port = 1;
- break;
- default:
- return EC_ERROR_PARAM1;
- }
-
- if (brightness[EC_LED_COLOR_WHITE] != 0)
- side_led_set_color(port, LED_WHITE);
- else if (brightness[EC_LED_COLOR_AMBER] != 0)
- side_led_set_color(port, LED_AMBER);
- else
- side_led_set_color(port, LED_OFF);
-
- return EC_SUCCESS;
-}
-
-/*
- * Set active charge port color to the parameter, turn off all others.
- * If no port is active (-1), turn off all LEDs.
- */
-static void set_active_port_color(enum led_color color)
-{
- int port = charge_manager_get_active_charge_port();
-
- if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED))
- side_led_set_color(0, (port == 0) ? color : LED_OFF);
- if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
- side_led_set_color(1, (port == 1) ? color : LED_OFF);
-}
-
-static void board_led_set_battery(void)
-{
- static int battery_ticks;
- uint32_t chflags = charge_get_flags();
-
- battery_ticks++;
-
- switch (charge_get_state()) {
- case PWR_STATE_CHARGE:
- /* Always indicate when charging, even in suspend. */
- set_active_port_color(LED_AMBER);
- break;
- case PWR_STATE_DISCHARGE:
- if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) {
- if (charge_get_percent() <= 10)
- side_led_set_color(0,
- (battery_ticks & 0x4) ? LED_WHITE : LED_OFF);
- else
- side_led_set_color(0, LED_OFF);
- }
-
- if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
- side_led_set_color(1, LED_OFF);
- break;
- case PWR_STATE_ERROR:
- set_active_port_color((battery_ticks & 0x2) ?
- LED_WHITE : LED_OFF);
- break;
- case PWR_STATE_CHARGE_NEAR_FULL:
- set_active_port_color(LED_WHITE);
- break;
- case PWR_STATE_IDLE: /* External power connected in IDLE */
- if (chflags & CHARGE_FLAG_FORCE_IDLE)
- set_active_port_color((battery_ticks & 0x4) ?
- LED_AMBER : LED_OFF);
- else
- set_active_port_color(LED_WHITE);
- break;
- default:
- /* Other states don't alter LED behavior */
- break;
- }
-}
-
-/* Called by hook task every TICK */
-static void led_tick(void)
-{
- board_led_set_battery();
-}
-DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
-
-void led_control(enum ec_led_id led_id, enum ec_led_state state)
-{
- enum led_color color;
-
- if ((led_id != EC_LED_ID_RECOVERY_HW_REINIT_LED) &&
- (led_id != EC_LED_ID_SYSRQ_DEBUG_LED))
- return;
-
- if (state == LED_STATE_RESET) {
- led_auto_control(EC_LED_ID_LEFT_LED, 1);
- led_auto_control(EC_LED_ID_RIGHT_LED, 1);
- board_led_set_battery();
- return;
- }
-
- color = state ? LED_WHITE : LED_OFF;
-
- led_auto_control(EC_LED_ID_LEFT_LED, 0);
- led_auto_control(EC_LED_ID_RIGHT_LED, 0);
-
- side_led_set_color(0, color);
- side_led_set_color(1, color);
-}
diff --git a/board/cheza/usb_pd_policy.c b/board/cheza/usb_pd_policy.c
deleted file mode 100644
index 061c6bb5df..0000000000
--- a/board/cheza/usb_pd_policy.c
+++ /dev/null
@@ -1,473 +0,0 @@
-/* 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 "console.h"
-#include "gpio.h"
-#include "pi3usb9281.h"
-#include "system.h"
-#include "usb_mux.h"
-#include "usbc_ppc.h"
-#include "util.h"
-
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-
-#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\
- PDO_FIXED_COMM_CAP)
-
-/* TODO(waihong): Fill in correct source and sink capabilities */
-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)
-{
- /* Always allow data swap */
- return 1;
-}
-
-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(port) == 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(port) == 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)
-{
- /* TODO(waihong): Check any case we do not allow. */
- return 1;
-}
-
-void pd_execute_data_swap(int port, int data_role)
-{
- int enable = (data_role == PD_ROLE_UFP);
- int type;
-
- /*
- * Exclude the PD charger, in which the "USB Communications Capable"
- * bit is unset in the Fixed Supply PDO.
- */
- if (pd_capable(port))
- enable = enable && pd_get_partner_usb_comm_capable(port);
-
- /*
- * The hub behind the BC1.2 chip may advertise a BC1.2 type. So
- * disconnect the switch when getting the charger type to ensure
- * the detected type is from external.
- */
- usb_charger_set_switches(port, USB_SWITCH_DISCONNECT);
- type = pi3usb9281_get_device_type(port);
- usb_charger_set_switches(port, USB_SWITCH_RESTORE);
-
- /* Exclude the BC1.2 charger, which is not detected as CDP or SDP. */
- enable = enable && (type & (PI3USB9281_TYPE_CDP | PI3USB9281_TYPE_SDP));
-
- /* Only mux one port to AP. If already muxed, return. */
- if (enable && (!gpio_get_level(GPIO_USB_C0_HS_MUX_SEL) ||
- gpio_get_level(GPIO_USB_C1_HS_MUX_SEL)))
- return;
-
- /* Port-0 and port-1 have different polarities. */
- if (port == 0)
- gpio_set_level(GPIO_USB_C0_HS_MUX_SEL, enable ? 0 : 1);
- else if (port == 1)
- gpio_set_level(GPIO_USB_C1_HS_MUX_SEL, enable ? 1 : 0);
-}
-
-int pd_is_valid_input_voltage(int mv)
-{
- return 1;
-}
-
-static uint8_t vbus_en[CONFIG_USB_PD_PORT_MAX_COUNT];
-static uint8_t vbus_rp[CONFIG_USB_PD_PORT_MAX_COUNT] = {TYPEC_RP_1A5,
- TYPEC_RP_1A5};
-
-static void board_vbus_update_source_current(int port)
-{
- if (port == 0) {
- /*
- * Port 0 is controlled by a USB-C PPC SN5S330.
- */
- ppc_set_vbus_source_current_limit(port, vbus_rp[port]);
- ppc_vbus_source_enable(port, vbus_en[port]);
- } else if (port == 1) {
- /*
- * Port 1 is controlled by a USB-C current-limited power
- * switch, NX5P3290. Change the GPIO driving the load switch.
- *
- * 1.5 vs 3.0 A limit is controlled by a dedicated gpio.
- * If the GPIO is asserted, it shorts a n-MOSFET to put a
- * 16.5k resistance (2x 33k in parallel) on the NX5P3290 load
- * switch ILIM pin, setting a minimum OCP current of 3100 mA.
- * If the GPIO is deasserted, the n-MOSFET is open that makes
- * a single 33k resistor on ILIM, setting a minimum OCP
- * current of 1505 mA.
- */
- gpio_set_level(GPIO_EN_USB_C1_3A,
- vbus_rp[port] == TYPEC_RP_3A0 ? 1 : 0);
- gpio_set_level(GPIO_EN_USB_C1_5V_OUT, vbus_en[port]);
- }
-}
-
-void pd_power_supply_reset(int port)
-{
- int prev_en;
-
- prev_en = vbus_en[port];
-
- /* Disable VBUS */
- vbus_en[port] = 0;
- board_vbus_update_source_current(port);
-
- /* 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)
-{
- /* Disable charging */
- board_vbus_sink_enable(port, 0);
-
- pd_set_vbus_discharge(port, 0);
-
- /* Provide VBUS */
- vbus_en[port] = 1;
- board_vbus_update_source_current(port);
-
- /* Ensure we advertise the proper available current quota */
- charge_manager_source_port(port, 1);
-
- /* notify host of power info change */
- pd_send_host_event(PD_EVENT_POWER_CHANGE);
-
- return EC_SUCCESS; /* we are ready */
-}
-
-void pd_transition_voltage(int idx)
-{
- /* No-operation: we are always 5V */
-}
-
-int board_vbus_source_enabled(int port)
-{
- return vbus_en[port];
-}
-
-void typec_set_source_current_limit(int port, enum tcpc_rp_value rp)
-{
- vbus_rp[port] = rp;
- board_vbus_update_source_current(port);
-}
-
-int pd_snk_is_vbus_provided(int port)
-{
- return !gpio_get_level(port ? GPIO_USB_C1_VBUS_DET_L :
- GPIO_USB_C0_VBUS_DET_L);
-}
-
-/* ----------------- 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_MAX_COUNT];
-static uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_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 pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]);
-
- if (!pin_mode)
- return 0;
-
- 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)
-{
- dp_flags[port] |= DP_FLAGS_DP_ON;
-}
-
-/**
- * Is the port fine to be muxed its DisplayPort lines?
- *
- * Only one port can be muxed to DisplayPort at a time.
- *
- * @param port Port number of TCPC.
- * @return 1 is fine; 0 is bad as other port is already muxed;
- */
-static int is_dp_muxable(int port)
-{
- int i;
-
- for (i = 0; i < CONFIG_USB_PD_PORT_MAX_COUNT; i++)
- if (i != port) {
- if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED)
- return 0;
- }
-
- return 1;
-}
-
-static int svdm_dp_attention(int port, uint32_t *payload)
-{
- int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]);
- int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]);
- int mf_pref = PD_VDO_DPSTS_MF_PREF(payload[1]);
- const struct usb_mux *mux = &usb_muxes[port];
-
- dp_status[port] = payload[1];
-
- mux->hpd_update(port, lvl, irq);
-
- if (lvl && is_dp_muxable(port)) {
- /*
- * The GPIO USBC_MUX_CONF1 enables the mux of the DP redriver
- * for the port 1.
- */
- gpio_set_level(GPIO_USBC_MUX_CONF1, port == 1);
-
- usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
- } else {
- usb_mux_set(port, mf_pref ? TYPEC_MUX_USB : TYPEC_MUX_NONE,
- USB_SWITCH_CONNECT, pd_get_polarity(port));
- }
-
- /* ack */
- return 1;
-}
-
-static void svdm_exit_dp_mode(int port)
-{
- const struct usb_mux *mux = &usb_muxes[port];
-
- svdm_safe_dp_mode(port);
- mux->hpd_update(port, 0, 0);
-}
-
-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 */