diff options
Diffstat (limited to 'board/coral')
-rw-r--r-- | board/coral/battery.c | 702 | ||||
-rw-r--r-- | board/coral/board.c | 1027 | ||||
-rw-r--r-- | board/coral/board.h | 309 | ||||
-rw-r--r-- | board/coral/build.mk | 14 | ||||
-rw-r--r-- | board/coral/ec.tasklist | 26 | ||||
-rw-r--r-- | board/coral/gpio.inc | 167 | ||||
-rw-r--r-- | board/coral/led.c | 325 | ||||
-rw-r--r-- | board/coral/sku.h | 91 | ||||
-rw-r--r-- | board/coral/usb_pd_policy.c | 107 | ||||
-rw-r--r-- | board/coral/vif_override.xml | 3 |
10 files changed, 0 insertions, 2771 deletions
diff --git a/board/coral/battery.c b/board/coral/battery.c deleted file mode 100644 index ebc8071c0d..0000000000 --- a/board/coral/battery.c +++ /dev/null @@ -1,702 +0,0 @@ -/* Copyright 2017 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" -#include "bd9995x.h" -#include "charge_ramp.h" -#include "charge_state.h" -#include "common.h" -#include "console.h" -#include "ec_commands.h" -#include "extpower.h" -#include "gpio.h" -#include "hooks.h" -#include "i2c.h" -#include "util.h" - -#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) - -/* Number of writes needed to invoke battery cutoff command */ -#define SHIP_MODE_WRITES 2 - -enum battery_type { - BATTERY_LGC15, - BATTERY_LGC203, - BATTERY_SANYO, - BATTERY_SONY, - BATTERY_PANASONIC, - BATTERY_CELXPERT, - BATTERY_LGC011, - BATTERY_SMP011, - BATTERY_LGC, - BATTERY_BYD, - BATTERY_SIMPLO, - BATTERY_TYPE_COUNT, -}; - -struct ship_mode_info { - const uint8_t reg_addr; - const uint16_t reg_data[SHIP_MODE_WRITES]; -}; - -struct fet_info { - const int mfgacc_support; - const uint8_t reg_addr; - const uint16_t reg_mask; - const uint16_t disconnect_val; -}; - -struct fuel_gauge_info { - const char *manuf_name; - const char *device_name; - const struct ship_mode_info ship_mode; - const struct fet_info fet; -}; - -struct board_batt_params { - const struct fuel_gauge_info fuel_gauge; - const struct battery_info batt_info; -}; - -#define DEFAULT_BATTERY_TYPE BATTERY_SANYO -static enum battery_present batt_pres_prev = BP_NOT_SURE; -static enum battery_type board_battery_type = BATTERY_TYPE_COUNT; - -/* Battery may delay reporting battery present */ -static int battery_report_present = 1; - -static int disch_on_ac; - -/* - * Battery info for all Coral battery types. Note that the fields - * start_charging_min/max and charging_min/max are not used for the charger. - * The effective temperature limits are given by discharging_min/max_c. - * - * Fuel Gauge (FG) parameters which are used for determing if the battery - * is connected, the appropriate ship mode (battery cutoff) command, and the - * charge/discharge FETs status. - * - * Ship mode (battery cutoff) requires 2 writes to the appropirate smart battery - * register. For some batteries, the charge/discharge FET bits are set when - * charging/discharging is active, in other types, these bits set mean that - * charging/discharging is disabled. Therefore, in addition to the mask for - * these bits, a disconnect value must be specified. Note that for TI fuel - * gauge, the charge/discharge FET status is found in Operation Status (0x54), - * but a read of Manufacturer Access (0x00) will return the lower 16 bits of - * Operation status which contains the FET status bits. - * - * The assumption for battery types supported is that the charge/discharge FET - * status can be read with a sb_read() command and therefore, only the regsister - * address, mask, and disconnect value need to be provided. - */ -static const struct board_batt_params info[] = { - /* LGC AC15A8J Battery Information */ - [BATTERY_LGC15] = { - .fuel_gauge = { - .manuf_name = "LGC", - .device_name = "AC15A8J", - .ship_mode = { - .reg_addr = 0x3A, - .reg_data = { 0xC574, 0xC574 }, - }, - .fet = { - .mfgacc_support = 1, - .reg_addr = 0x0, - .reg_mask = 0x0002, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 11520, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - - /* LGC C203-36J Battery Information */ - [BATTERY_LGC203] = { - .fuel_gauge = { - .manuf_name = "AS1GXXc3KB", - .ship_mode = { - .reg_addr = 0x00, - .reg_data = { 0x0010, 0x0010 }, - }, - .fet = { - .mfgacc_support = 1, - .reg_addr = 0x0, - .reg_mask = 0x0002, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 11520, /* mV */ - .voltage_min = 9000, /* mV */ - .precharge_current = 256, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 45, - .charging_min_c = 0, - .charging_max_c = 60, - .discharging_min_c = 0, - .discharging_max_c = 60, - }, - }, - - /* SANYO AC15A3J Battery Information */ - [BATTERY_SANYO] = { - .fuel_gauge = { - .manuf_name = "SANYO", - .ship_mode = { - .reg_addr = 0x3A, - .reg_data = { 0xC574, 0xC574 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x4000, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 11550, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - - /* Sony Ap13J4K Battery Information */ - [BATTERY_SONY] = { - .fuel_gauge = { - .manuf_name = "SONYCorp", - .ship_mode = { - .reg_addr = 0x3A, - .reg_data = { 0xC574, 0xC574 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x8000, - .disconnect_val = 0x8000, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 11400, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - - /* Panasonic AP1505L Battery Information */ - [BATTERY_PANASONIC] = { - .fuel_gauge = { - .manuf_name = "PANASONIC", - .ship_mode = { - .reg_addr = 0x3A, - .reg_data = { 0xC574, 0xC574 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x4000, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 11550, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - - /* Celxpert Li7C3PG0 Battery Information */ - [BATTERY_CELXPERT] = { - .fuel_gauge = { - .manuf_name = "Celxpert", - .ship_mode = { - .reg_addr = 0x34, - .reg_data = { 0x0, 0x1000 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x0018, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13050, 5), - .voltage_normal = 11400, /* mV */ - .voltage_min = 9000, /* mV */ - .precharge_current = 200, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 50, - .charging_min_c = 0, - .charging_max_c = 60, - .discharging_min_c = 0, - .discharging_max_c = 60, - }, - }, - - /* LGC\011 L17L3PB0 Battery Information */ - [BATTERY_LGC011] = { - .fuel_gauge = { - .manuf_name = "LGC", - .ship_mode = { - .reg_addr = 0x34, - .reg_data = { 0x0, 0x1000 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x0018, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13050, 5), - .voltage_normal = 11400, /* mV */ - .voltage_min = 9000, /* mV */ - .precharge_current = 500, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 50, - .charging_min_c = 0, - .charging_max_c = 60, - .discharging_min_c = 0, - .discharging_max_c = 60, - }, - }, - - /* SMP\011 L17M3PB0 Battery Information */ - [BATTERY_SMP011] = { - .fuel_gauge = { - .manuf_name = "SMP", - .ship_mode = { - .reg_addr = 0x34, - .reg_data = { 0x0, 0x1000 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x0018, - .disconnect_val = 0x0, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13050, 5), - .voltage_normal = 11400, /* mV */ - .voltage_min = 9000, /* mV */ - .precharge_current = 186, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 50, - .charging_min_c = 0, - .charging_max_c = 60, - .discharging_min_c = 0, - .discharging_max_c = 60, - }, - }, - - /* LGC DELL Y07HK Battery Information */ - [BATTERY_LGC] = { - .fuel_gauge = { - .manuf_name = "LGC-LGC3.553", - .ship_mode = { - .reg_addr = 0x0, - .reg_data = { 0x10, 0x10 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x6000, - .disconnect_val = 0x6000, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 114000, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - - /* BYD DELL FY8XM6C Battery Information */ - [BATTERY_BYD] = { - .fuel_gauge = { - .manuf_name = "BYD", - .ship_mode = { - .reg_addr = 0x0, - .reg_data = { 0x10, 0x10 }, - }, - .fet = { - .reg_addr = 0x0, - .reg_mask = 0x6000, - .disconnect_val = 0x6000, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 114000, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - - /* Simplo () Battery Information */ - [BATTERY_SIMPLO] = { - .fuel_gauge = { - .manuf_name = "SMP-SDI3.72", - .ship_mode = { - .reg_addr = 0x0, - .reg_data = { 0x10, 0x10 }, - }, - .fet = { - .reg_addr = 0x43, - .reg_mask = 0x0003, - .disconnect_val = 0x0000, - } - }, - .batt_info = { - .voltage_max = TARGET_WITH_MARGIN(13200, 5), - .voltage_normal = 114900, /* mV */ - .voltage_min = 9000, /* mV */ - .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 = 0, - .discharging_max_c = 60, - }, - }, - -}; -BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_TYPE_COUNT); - -static inline const struct board_batt_params *board_get_batt_params(void) -{ - return &info[board_battery_type == BATTERY_TYPE_COUNT ? - DEFAULT_BATTERY_TYPE : board_battery_type]; -} - -/* Get type of the battery connected on the board */ -static int board_get_battery_type(void) -{ - char manu_name[32], device_name[32]; - int i; - - if (!battery_manufacturer_name(manu_name, sizeof(manu_name))) { - for (i = 0; i < BATTERY_TYPE_COUNT; i++) { - if (!strcasecmp(manu_name, - info[i].fuel_gauge.manuf_name)) { - if (info[i].fuel_gauge.device_name == NULL) { - board_battery_type = i; - break; - } else if (!battery_device_name(device_name, - sizeof(device_name))) { - if (!strcasecmp(device_name, - info[i].fuel_gauge.device_name)) { - board_battery_type = i; - break; - } - } - } - } - } - - return board_battery_type; -} - -/* - * Initialize the battery type for the board. - * - * Very first battery info is called by the charger driver to initialize - * the charger parameters hence initialize the battery type for the board - * as soon as the I2C is initialized. - */ -static void board_init_battery_type(void) -{ - if (board_get_battery_type() != BATTERY_TYPE_COUNT) - CPRINTS("found batt:%s", - info[board_battery_type].fuel_gauge.manuf_name); - else - CPRINTS("battery not found"); -} -DECLARE_HOOK(HOOK_INIT, board_init_battery_type, HOOK_PRIO_INIT_I2C + 1); - -const struct battery_info *battery_get_info(void) -{ - return &board_get_batt_params()->batt_info; -} - -int board_cut_off_battery(void) -{ - int rv; - int cmd; - int data; - - /* If battery type is unknown can't send ship mode command */ - if (board_get_battery_type() == BATTERY_TYPE_COUNT) - return EC_RES_ERROR; - - /* Ship mode command must be sent twice to take effect */ - cmd = info[board_battery_type].fuel_gauge.ship_mode.reg_addr; - data = info[board_battery_type].fuel_gauge.ship_mode.reg_data[0]; - rv = sb_write(cmd, data); - if (rv != EC_SUCCESS) - return EC_RES_ERROR; - - data = info[board_battery_type].fuel_gauge.ship_mode.reg_data[1]; - rv = sb_write(cmd, data); - - return rv ? EC_RES_ERROR : EC_RES_SUCCESS; -} - -static int charger_should_discharge_on_ac(struct charge_state_data *curr) -{ - /* can not discharge on AC without battery */ - if (curr->batt.is_present != BP_YES) - return 0; - - /* Do not discharge on AC if the battery is still waking up */ - if (!(curr->batt.flags & BATT_FLAG_WANT_CHARGE) && - !(curr->batt.status & STATUS_FULLY_CHARGED)) - return 0; - - /* - * In light load (<450mA being withdrawn from VSYS) the DCDC of the - * charger operates intermittently i.e. DCDC switches continuously - * and then stops to regulate the output voltage and current, and - * sometimes to prevent reverse current from flowing to the input. - * This causes a slight voltage ripple on VSYS that falls in the - * audible noise frequency (single digit kHz range). This small - * ripple generates audible noise in the output ceramic capacitors - * (caps on VSYS and any input of DCDC under VSYS). - * - * To overcome this issue enable the battery learning operation - * and suspend USB charging and DC/DC converter. - */ - if (!battery_is_cut_off() && - !(curr->batt.flags & BATT_FLAG_WANT_CHARGE) && - (curr->batt.status & STATUS_FULLY_CHARGED)) - return 1; - - /* - * To avoid inrush current from the external charger, enable - * discharge on AC till the new charger is detected and charge - * detect delay has passed. - */ - if (!chg_ramp_is_detected() && curr->batt.state_of_charge > 2) - return 1; - - return 0; -} - -int charger_profile_override(struct charge_state_data *curr) -{ - disch_on_ac = charger_should_discharge_on_ac(curr); - - charger_discharge_on_ac(disch_on_ac); - - if (disch_on_ac) { - curr->state = ST_DISCHARGE; - return 0; - } - - return 0; -} - -enum battery_present battery_hw_present(void) -{ - /* The GPIO is low when the battery is physically present */ - return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES; -} - - -static int battery_init(void) -{ - int batt_status; - - return battery_status(&batt_status) ? 0 : - !!(batt_status & STATUS_INITIALIZED); -} - -/* Allow booting now that the battery has woke up */ -static void battery_now_present(void) -{ - CPRINTS("battery will now report present"); - battery_report_present = 1; -} -DECLARE_DEFERRED(battery_now_present); - -/* - * This function checks the charge/dishcarge FET status bits. Each battery type - * supported provides the register address, mask, and disconnect value for these - * 2 FET status bits. If the FET status matches the disconnected value, then - * BATTERY_DISCONNECTED is returned. This function is required to handle the - * cases when the fuel gauge is awake and will return a non-zero state of - * charge, but is not able yet to provide power (i.e. discharge FET is not - * active). By returning BATTERY_DISCONNECTED the AP will not be powered up - * until either the external charger is able to provided enough power, or - * the battery is able to provide power and thus prevent a brownout when the - * AP is powered on by the EC. - */ -static int battery_check_disconnect(void) -{ - int rv; - int reg; - uint8_t data[6]; - - /* If battery type is not known, can't check CHG/DCHG FETs */ - if (board_battery_type == BATTERY_TYPE_COUNT) { - /* Keep trying to determine the battery type */ - board_init_battery_type(); - if (board_battery_type == BATTERY_TYPE_COUNT) - /* Still don't know, so return here */ - return BATTERY_DISCONNECT_ERROR; - } - - /* Read the status of charge/discharge FETs */ - if (info[board_battery_type].fuel_gauge.fet.mfgacc_support == 1) { - rv = sb_read_mfgacc(PARAM_OPERATION_STATUS, - SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); - /* Get the lowest 16bits of the OperationStatus() data */ - reg = data[2] | data[3] << 8; - } else - rv = sb_read(info[board_battery_type].fuel_gauge.fet.reg_addr, - ®); - - if (rv) - return BATTERY_DISCONNECT_ERROR; - - CPRINTS("Battery FET: reg 0x%04x mask 0x%04x disc 0x%04x", reg, - info[board_battery_type].fuel_gauge.fet.reg_mask, - info[board_battery_type].fuel_gauge.fet.disconnect_val); - reg &= info[board_battery_type].fuel_gauge.fet.reg_mask; - if (reg == info[board_battery_type].fuel_gauge.fet.disconnect_val) - return BATTERY_DISCONNECTED; - - return BATTERY_NOT_DISCONNECTED; -} - -/* - * Physical detection of battery. - */ - -enum battery_present battery_is_present(void) -{ - enum battery_present batt_pres; - static int battery_report_present_timer_started; - - /* Get the physical hardware status */ - batt_pres = battery_hw_present(); - - /* - * Make sure battery status is implemented, I2C transactions are - * success & the battery status is Initialized to find out if it - * is a working battery and it is not in the cut-off mode. - * - * FETs are turned off after Power Shutdown time. - * The device will wake up when a voltage is applied to PACK. - * Battery status will be inactive until it is initialized. - */ - if (batt_pres == BP_YES && batt_pres_prev != batt_pres && - (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL || - battery_check_disconnect() != BATTERY_NOT_DISCONNECTED || - battery_init() == 0)) { - battery_report_present = 0; - /* - * When this path is taken, the _timer_started flag must be - * reset so the 'else if' path will be entered and the - * battery_report_present flag can be set by the deferred - * call. This handles the case of the battery being disconected - * and reconnected while running or if battery_init() returns an - * error due to a failed sb_read. - */ - battery_report_present_timer_started = 0; - } else if (batt_pres == BP_YES && batt_pres_prev == BP_NO && - !battery_report_present_timer_started) { - /* - * Wait 1/2 second before reporting present if it was - * previously reported as not present - */ - battery_report_present_timer_started = 1; - battery_report_present = 0; - hook_call_deferred(&battery_now_present_data, 500 * MSEC); - } - - if (!battery_report_present) - batt_pres = BP_NO; - - batt_pres_prev = batt_pres; - - return batt_pres; -} - -int board_battery_initialized(void) -{ - return battery_hw_present() == batt_pres_prev; -} - - -/* Customs options controllable by host command. */ -#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0) -#define PARAM_LEARN_MODE 0x10001 -#define PARAM_DISCONNECT_STATE 0x10002 - -enum ec_status charger_profile_override_get_param(uint32_t param, - uint32_t *value) -{ - switch (param) { - case PARAM_LEARN_MODE: - *value = disch_on_ac; - return EC_SUCCESS; - case PARAM_DISCONNECT_STATE: - *value = battery_check_disconnect(); - return EC_SUCCESS; - default: - return EC_RES_INVALID_PARAM; - } -} - -enum ec_status charger_profile_override_set_param(uint32_t param, - uint32_t value) -{ - return EC_RES_INVALID_PARAM; -} diff --git a/board/coral/board.c b/board/coral/board.c deleted file mode 100644 index a563071294..0000000000 --- a/board/coral/board.c +++ /dev/null @@ -1,1027 +0,0 @@ -/* Copyright 2016 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. - */ - -/* Coral board-specific configuration */ - -#include "adc.h" -#include "button.h" -#include "charge_manager.h" -#include "charge_ramp.h" -#include "charge_state.h" -#include "charger.h" -#include "chipset.h" -#include "console.h" -#include "driver/als_opt3001.h" -#include "driver/accel_kionix.h" -#include "driver/accel_kx022.h" -#include "driver/accelgyro_bmi_common.h" -#include "driver/charger/bd9995x.h" -#include "driver/tcpm/anx74xx.h" -#include "driver/tcpm/ps8xxx.h" -#include "driver/tcpm/tcpci.h" -#include "driver/tcpm/tcpm.h" -#include "extpower.h" -#include "gpio.h" -#include "hooks.h" -#include "host_command.h" -#include "i2c.h" -#include "keyboard_scan.h" -#include "lid_angle.h" -#include "lid_switch.h" -#include "math_util.h" -#include "motion_sense.h" -#include "motion_lid.h" -#include "power.h" -#include "power_button.h" -#include "pwm.h" -#include "pwm_chip.h" -#include "sku.h" -#include "spi.h" -#include "switch.h" -#include "system.h" -#include "tablet_mode.h" -#include "task.h" -#include "temp_sensor.h" -#include "temp_sensor/thermistor.h" -#include "timer.h" -#include "uart.h" -#include "usb_charge.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usb_pd_tcpm.h" -#include "util.h" - -#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) -#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) - -#define IN_ALL_SYS_PG POWER_SIGNAL_MASK(X86_ALL_SYS_PG) -#define IN_PGOOD_PP3300 POWER_SIGNAL_MASK(X86_PGOOD_PP3300) -#define IN_PGOOD_PP5000 POWER_SIGNAL_MASK(X86_PGOOD_PP5000) - -#define USB_PD_PORT_ANX74XX 0 -#define USB_PD_PORT_PS8751 1 - -static int sku_id; - -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); -} - -#ifdef CONFIG_USB_PD_TCPC_LOW_POWER -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_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); -} -DECLARE_DEFERRED(anx74xx_cable_det_handler); - -void anx74xx_cable_det_interrupt(enum gpio_signal signal) -{ - /* debounce for 2 msec */ - hook_call_deferred(&anx74xx_cable_det_handler_data, (2 * MSEC)); -} -#endif - -/* - * enable_input_devices() is called by the tablet_mode ISR, but changes the - * state of GPIOs, so its definition must reside after including gpio_list. - * Use DECLARE_DEFERRED to generate enable_input_devices_data. - */ -static void enable_input_devices(void); -DECLARE_DEFERRED(enable_input_devices); - -#define LID_DEBOUNCE_US (30 * MSEC) /* Debounce time for lid switch */ -void tablet_mode_interrupt(enum gpio_signal signal) -{ - hook_call_deferred(&enable_input_devices_data, LID_DEBOUNCE_US); -} - -#include "gpio_list.h" - -/* ADC channels */ -const struct adc_t adc_channels[] = { - /* Vfs = Vref = 2.816V, 10-bit unsigned reading */ - [ADC_TEMP_SENSOR_CHARGER] = { - "CHARGER", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX + 1, 0 - }, - [ADC_TEMP_SENSOR_AMB] = { - "AMBIENT", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX + 1, 0 - }, - [ADC_BOARD_ID] = { - "BRD_ID", NPCX_ADC_CH2, ADC_MAX_VOLT, ADC_READ_MAX + 1, 0 - }, - [ADC_BOARD_SKU_1] = { - "BRD_SKU_1", NPCX_ADC_CH3, ADC_MAX_VOLT, ADC_READ_MAX + 1, 0 - }, - [ADC_BOARD_SKU_0] = { - "BRD_SKU_0", NPCX_ADC_CH4, ADC_MAX_VOLT, ADC_READ_MAX + 1, 0 - }, -}; -BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); - -/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ -const struct pwm_t pwm_channels[] = { - [PWM_CH_KBLIGHT] = { 4, PWM_CONFIG_DSLEEP, 100 }, -}; -BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); - -const struct i2c_port_t i2c_ports[] = { - {"tcpc0", NPCX_I2C_PORT0_0, 400, - GPIO_EC_I2C_USB_C0_PD_SCL, GPIO_EC_I2C_USB_C0_PD_SDA}, - {"tcpc1", NPCX_I2C_PORT0_1, 400, - GPIO_EC_I2C_USB_C1_PD_SCL, GPIO_EC_I2C_USB_C1_PD_SDA}, - {"accelgyro", I2C_PORT_GYRO, 400, - GPIO_EC_I2C_GYRO_SCL, GPIO_EC_I2C_GYRO_SDA}, - {"sensors", NPCX_I2C_PORT2, 400, - GPIO_EC_I2C_SENSOR_SCL, GPIO_EC_I2C_SENSOR_SDA}, - {"batt", NPCX_I2C_PORT3, 100, - GPIO_EC_I2C_POWER_SCL, GPIO_EC_I2C_POWER_SDA}, -}; -const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); - -#ifdef CONFIG_CMD_I2C_STRESS_TEST -struct i2c_stress_test i2c_stress_tests[] = { -/* NPCX_I2C_PORT0_0 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC - { - .port = NPCX_I2C_PORT0_0, - .addr_flags = ANX74XX_I2C_ADDR1_FLAGS, - .i2c_test = &anx74xx_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT0_1 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC - { - .port = NPCX_I2C_PORT0_1, - .addr_flags = PS8751_I2C_ADDR1_FLAGS, - .i2c_test = &ps8xxx_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT1 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL - { - .port = I2C_PORT_GYRO, - .addr_flags = BMI160_ADDR0_FLAGS, - .i2c_test = &bmi160_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT2 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL - { - .port = I2C_PORT_LID_ACCEL, - .addr_flags = KX022_ADDR1_FLAGS, - .i2c_test = &kionix_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT3 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_BATTERY - { - .i2c_test = &battery_i2c_stress_test_dev, - }, -#endif -#ifdef CONFIG_CMD_I2C_STRESS_TEST_CHARGER - { - .i2c_test = &bd9995x_i2c_stress_test_dev, - }, -#endif -}; -const int i2c_test_dev_used = ARRAY_SIZE(i2c_stress_tests); -#endif /* CONFIG_CMD_I2C_STRESS_TEST */ - -const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { - [USB_PD_PORT_ANX74XX] = { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = NPCX_I2C_PORT0_0, - .addr_flags = ANX74XX_I2C_ADDR1_FLAGS, - }, - .drv = &anx74xx_tcpm_drv, - }, - [USB_PD_PORT_PS8751] = { - .bus_type = EC_BUS_TYPE_I2C, - .i2c_info = { - .port = NPCX_I2C_PORT0_1, - .addr_flags = PS8751_I2C_ADDR1_FLAGS, - }, - .drv = &ps8xxx_tcpm_drv, - }, -}; - -const struct charger_config_t chg_chips[] = { - { - .i2c_port = I2C_PORT_CHARGER, - .i2c_addr_flags = BD9995X_ADDR_FLAGS, - .drv = &bd9995x_drv, - }, -}; - -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_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; -} - -const enum gpio_signal hibernate_wake_pins[] = { - GPIO_AC_PRESENT, - GPIO_LID_OPEN, - GPIO_POWER_BUTTON_L, -}; - -const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); - -static int ps8751_tune_mux(const struct usb_mux *me) -{ - /* 0x98 sets lower EQ of DP port (4.5db) */ - mux_write(me, PS8XXX_REG_MUX_DP_EQ_CONFIGURATION, 0x98); - return EC_SUCCESS; -} - -const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { - [USB_PD_PORT_ANX74XX] = { - .usb_port = USB_PD_PORT_ANX74XX, - .driver = &anx74xx_tcpm_usb_mux_driver, - .hpd_update = &anx74xx_tcpc_update_hpd_status, - }, - [USB_PD_PORT_PS8751] = { - .usb_port = USB_PD_PORT_PS8751, - .driver = &tcpci_tcpm_usb_mux_driver, - .hpd_update = &ps8xxx_tcpc_update_hpd_status, - .board_init = &ps8751_tune_mux, - } -}; - -const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = { - GPIO_USB1_ENABLE, -}; - -/** - * 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_ANX74XX) - return; - - switch (mode) { - case ANX74XX_NORMAL_MODE: - gpio_set_level(GPIO_EN_USB_TCPC_PWR, 1); - msleep(ANX74XX_PWR_H_RST_H_DELAY_MS); - gpio_set_level(GPIO_USB_C0_PD_RST_L, 1); - break; - case ANX74XX_STANDBY_MODE: - gpio_set_level(GPIO_USB_C0_PD_RST_L, 0); - msleep(ANX74XX_RST_L_PWR_L_DELAY_MS); - gpio_set_level(GPIO_EN_USB_TCPC_PWR, 0); - msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS); - break; - default: - break; - } -} - -/** - * 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) -{ - /* Assert reset to TCPC1 (ps8751) */ - gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0); - - /* Assert reset to TCPC0 (anx3429) */ - gpio_set_level(GPIO_USB_C0_PD_RST_L, 0); - - /* TCPC1 (ps8751) requires 1ms reset down assertion */ - msleep(MAX(1, ANX74XX_RST_L_PWR_L_DELAY_MS)); - - /* Deassert reset to TCPC1 */ - gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1); - /* Disable TCPC0 power */ - gpio_set_level(GPIO_EN_USB_TCPC_PWR, 0); - - /* - * anx3429 requires 10ms reset/power down assertion - */ - msleep(ANX74XX_PWR_L_PWR_H_DELAY_MS); - board_set_tcpc_power_mode(USB_PD_PORT_ANX74XX, 1); -} - -static void board_tcpc_init(void) -{ - int reg; - int count = 0; - - /* Wait for disconnected battery to wake up */ - while (battery_hw_present() == BP_YES && - battery_is_present() == BP_NO) { - usleep(100 * MSEC); - /* Give up waiting after 2 seconds */ - if (++count > 20) - break; - } - - /* Only reset TCPC if not sysjump */ - if (!system_jumped_late()) - board_reset_pd_mcu(); - - /* - * TODO: Remove when Coral is updated with PS8751 A3. - * - * Force PS8751 A2 to wake from low power mode. - * If PS8751 remains in low power mode after sysjump, - * TCPM_INIT will fail due to not able to access PS8751. - * - * NOTE: PS8751 A3 will wake on any I2C access. - */ - i2c_read8(NPCX_I2C_PORT0_1, 0x08, 0xA0, ®); - - /* Enable TCPC0 interrupt */ - gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL); - - /* Enable TCPC1 interrupt */ - gpio_enable_interrupt(GPIO_USB_C1_PD_INT_ODL); - -#ifdef CONFIG_USB_PD_TCPC_LOW_POWER - /* Enable CABLE_DET interrupt for ANX3429 wake from standby */ - gpio_enable_interrupt(GPIO_USB_C0_CABLE_DET); -#endif - /* - * Initialize HPD to low; after sysjump SOC needs to see - * HPD pulse to enable video path - */ - for (int port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; ++port) - usb_mux_hpd_update(port, USB_PD_MUX_HPD_LVL_DEASSERTED | - USB_PD_MUX_HPD_IRQ_DEASSERTED); -} -DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_DEFAULT); - -const struct temp_sensor_t temp_sensors[] = { - [TEMP_SENSOR_BATTERY] = {.name = "Battery", - .type = TEMP_SENSOR_TYPE_BATTERY, - .read = charge_get_battery_temp, - .idx = 0}, - [TEMP_SENSOR_AMBIENT] = {.name = "Ambient", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = get_temp_3v3_51k1_47k_4050b, - .idx = ADC_TEMP_SENSOR_AMB}, - [TEMP_SENSOR_CHARGER] = {.name = "Charger", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = get_temp_3v3_13k7_47k_4050b, - .idx = ADC_TEMP_SENSOR_CHARGER}, -}; -BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); - -/* Called by APL power state machine when transitioning from G3 to S5 */ -void chipset_pre_init_callback(void) -{ - /* - * No need to re-init PMIC since settings are sticky across sysjump. - * However, be sure to check that PMIC is already enabled. If it is - * then there's no need to re-sequence the PMIC. - */ - if (system_jumped_to_this_image() && gpio_get_level(GPIO_PMIC_EN)) - return; - - /* Enable PP5000 before PP3300 due to NFC: chrome-os-partner:50807 */ - gpio_set_level(GPIO_EN_PP5000, 1); - while (!gpio_get_level(GPIO_PP5000_PG)) - ; - - /* - * To prevent SLP glitches, PMIC_EN (V5A_EN) should be enabled - * at the same time as PP3300 (chrome-os-partner:51323). - */ - /* Enable 3.3V rail */ - gpio_set_level(GPIO_EN_PP3300, 1); - while (!gpio_get_level(GPIO_PP3300_PG)) - ; - - /* Enable PMIC */ - gpio_set_level(GPIO_PMIC_EN, 1); -} - -static void board_set_tablet_mode(void) -{ - int tablet_mode = 0; - - if (SKU_IS_CONVERTIBLE(sku_id)) - tablet_mode = !gpio_get_level(GPIO_TABLET_MODE_L); - - tablet_set_mode(tablet_mode, TABLET_TRIGGER_LID); -} - -/* Initialize board. */ -static void board_init(void) -{ - /* Ensure tablet mode is initialized according to the hardware state - * so that the cached state reflects reality. */ - board_set_tablet_mode(); - - gpio_enable_interrupt(GPIO_TABLET_MODE_L); - - /* Enable charger interrupts */ - gpio_enable_interrupt(GPIO_CHARGER_INT_L); - - /* Enable Gyro interrupts */ - gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); - - /* Need to read SKU ID at least once each boot */ - sku_id = BOARD_VERSION_UNKNOWN; -} -/* PP3300 needs to be enabled before TCPC init hooks */ -DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_FIRST); - -int pd_snk_is_vbus_provided(int port) -{ - if (port != 0 && port != 1) - panic("Invalid charge port\n"); - - return bd9995x_is_vbus_provided(port); -} - -/** - * Set active charge port -- only one port can be active at a time. - * - * @param charge_port Charge port to enable. - * - * Returns EC_SUCCESS if charge port is accepted and made active, - * EC_ERROR_* otherwise. - */ -int board_set_active_charge_port(int charge_port) -{ - enum bd9995x_charge_port bd9995x_port; - int bd9995x_port_select = 1; - - switch (charge_port) { - case USB_PD_PORT_ANX74XX: - case USB_PD_PORT_PS8751: - /* Don't charge from a source port */ - if (board_vbus_source_enabled(charge_port)) - return -1; - - bd9995x_port = charge_port; - break; - case CHARGE_PORT_NONE: - bd9995x_port_select = 0; - bd9995x_port = BD9995X_CHARGE_PORT_BOTH; - - /* - * To avoid inrush current from the external charger, enable - * discharge on AC till the new charger is detected and - * charge detect delay has passed. - */ - if (charge_get_percent() > 2) - charger_discharge_on_ac(1); - break; - default: - panic("Invalid charge port\n"); - break; - } - - CPRINTS("New chg p%d", charge_port); - - return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select); -} - -/** - * Set the charge limit based upon desired maximum. - * - * @param port Port number. - * @param supplier Charge supplier type. - * @param charge_ma Desired charge limit (mA). - * @param charge_mv Negotiated charge voltage (mV). - */ -void board_set_charge_limit(int port, int supplier, int charge_ma, - int max_ma, int charge_mv) -{ - /* Enable charging trigger by BC1.2 detection */ - int bc12_enable = (supplier == CHARGE_SUPPLIER_BC12_CDP || - supplier == CHARGE_SUPPLIER_BC12_DCP || - supplier == CHARGE_SUPPLIER_BC12_SDP || - supplier == CHARGE_SUPPLIER_OTHER); - - if (bd9995x_bc12_enable_charging(port, bc12_enable)) - return; - - charge_ma = (charge_ma * 95) / 100; - charge_set_input_current_limit(MAX(charge_ma, - CONFIG_CHARGER_INPUT_CURRENT), charge_mv); -} - -/** - * Return if VBUS is sagging too low - */ -int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) -{ - int voltage; - - if (charger_get_vbus_voltage(port, &voltage)) - voltage = 0; - - return voltage < BD9995X_BC12_MIN_VOLTAGE; -} - -static void enable_input_devices(void) -{ - /* We need to turn on tablet mode for motion sense */ - board_set_tablet_mode(); - - /* Then, we disable peripherals only when the lid reaches 360 position. - * (It's probably already disabled by motion_sense_task.) - * We deliberately do not enable peripherals when the lid is leaving - * 360 position. Instead, we let motion_sense_task enable it once it - * reaches laptop zone (180 or less). */ - if (tablet_get_mode()) - lid_angle_peripheral_enable(0); -} - -/* Enable or disable input devices, based on chipset state and tablet mode */ -__override void lid_angle_peripheral_enable(int enable) -{ - /* If the lid is in 360 position, ignore the lid angle, - * which might be faulty. Disable keyboard. - */ - if (tablet_get_mode() || chipset_in_state(CHIPSET_STATE_ANY_OFF)) - enable = 0; - keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE); -} - -/* Called on AP S5 -> S3 transition */ -static void board_chipset_startup(void) -{ - /* Enable USB-A port. */ - gpio_set_level(GPIO_USB1_ENABLE, 1); - - /* Enable Trackpad */ - gpio_set_level(GPIO_EN_P3300_TRACKPAD_ODL, 0); - - hook_call_deferred(&enable_input_devices_data, 0); -} -DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT); - -/* Called on AP S3 -> S5 transition */ -static void board_chipset_shutdown(void) -{ - /* Disable USB-A port. */ - gpio_set_level(GPIO_USB1_ENABLE, 0); - - /* Disable Trackpad */ - gpio_set_level(GPIO_EN_P3300_TRACKPAD_ODL, 1); - - hook_call_deferred(&enable_input_devices_data, 0); - /* FIXME(dhendrix): Drive USB_PD_RST_ODL low to prevent - leakage? (see comment in schematic) */ -} -DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT); - -/* FIXME(dhendrix): Add CHIPSET_RESUME and CHIPSET_SUSPEND - hooks to enable/disable sensors? */ -/* Called on AP S3 -> S0 transition */ -static void board_chipset_resume(void) -{ - gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1); -} -DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); - -/* Called on AP S0 -> S3 transition */ -static void board_chipset_suspend(void) -{ - gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0); -} -DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); - -/* - * FIXME(dhendrix): Weak symbol hack until we can get a better solution for - * both Amenia and Coral. - */ -void chipset_do_shutdown(void) -{ - /* Disable PMIC */ - gpio_set_level(GPIO_PMIC_EN, 0); - - /*Disable 3.3V rail */ - gpio_set_level(GPIO_EN_PP3300, 0); - while (gpio_get_level(GPIO_PP3300_PG)) - ; - - /*Disable 5V rail */ - gpio_set_level(GPIO_EN_PP5000, 0); - while (gpio_get_level(GPIO_PP5000_PG)) - ; -} - -void board_hibernate_late(void) -{ - int i; - const uint32_t hibernate_pins[][2] = { - /* Turn off LEDs in hibernate */ - {GPIO_BAT_LED_BLUE, GPIO_INPUT | GPIO_PULL_UP}, - {GPIO_BAT_LED_AMBER, GPIO_INPUT | GPIO_PULL_UP}, - {GPIO_LID_OPEN, GPIO_INT_RISING | GPIO_PULL_DOWN}, - - /* - * BD99956 handles charge input automatically. We'll disable - * charge output in hibernate. Charger will assert ACOK_OD - * when VBUS or VCC are plugged in. - */ - {GPIO_USB_C0_5V_EN, GPIO_INPUT | GPIO_PULL_DOWN}, - {GPIO_USB_C1_5V_EN, GPIO_INPUT | GPIO_PULL_DOWN}, - }; - - /* Change GPIOs' state in hibernate for better power consumption */ - for (i = 0; i < ARRAY_SIZE(hibernate_pins); ++i) - gpio_set_flags(hibernate_pins[i][0], hibernate_pins[i][1]); - - gpio_config_module(MODULE_KEYBOARD_SCAN, 0); - - /* - * Calling gpio_config_module sets disabled alternate function pins to - * GPIO_INPUT. But to prevent keypresses causing leakage currents - * while hibernating we want to enable GPIO_PULL_UP as well. - */ - gpio_set_flags_by_mask(0x2, 0x03, GPIO_INPUT | GPIO_PULL_UP); - gpio_set_flags_by_mask(0x1, 0x7F, GPIO_INPUT | GPIO_PULL_UP); - gpio_set_flags_by_mask(0x0, 0xE0, GPIO_INPUT | GPIO_PULL_UP); - /* KBD_KSO2 needs to have a pull-down enabled instead of pull-up */ - gpio_set_flags_by_mask(0x1, 0x80, GPIO_INPUT | GPIO_PULL_DOWN); -} - -/* Motion sensors */ -/* Mutexes */ -static struct mutex g_lid_mutex; -static struct mutex g_base_mutex; - -/* Matrix to rotate accelrator into standard reference frame */ -const mat33_fp_t base_standard_ref = { - { 0, FLOAT_TO_FP(-1), 0}, - { FLOAT_TO_FP(1), 0, 0}, - { 0, 0, FLOAT_TO_FP(1)} -}; - -const mat33_fp_t mag_standard_ref = { - { FLOAT_TO_FP(-1), 0, 0}, - { 0, FLOAT_TO_FP(1), 0}, - { 0, 0, FLOAT_TO_FP(-1)} -}; - -/* sensor private data */ -static struct kionix_accel_data g_kx022_data; -static struct bmi_drv_data_t g_bmi160_data; - -/* FIXME(dhendrix): Copied from Amenia, probably need to tweak for Coral */ -struct motion_sensor_t motion_sensors[] = { - [LID_ACCEL] = { - .name = "Lid Accel", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_KX022, - .type = MOTIONSENSE_TYPE_ACCEL, - .location = MOTIONSENSE_LOC_LID, - .drv = &kionix_accel_drv, - .mutex = &g_lid_mutex, - .drv_data = &g_kx022_data, - .port = I2C_PORT_LID_ACCEL, - .i2c_spi_addr_flags = KX022_ADDR1_FLAGS, - .rot_standard_ref = NULL, /* Identity matrix. */ - .default_range = 2, /* g, enough for laptop. */ - .min_frequency = KX022_ACCEL_MIN_FREQ, - .max_frequency = KX022_ACCEL_MAX_FREQ, - .config = { - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - }, - /* Sensor on for lid angle detection */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - }, - }, - }, - - [BASE_ACCEL] = { - .name = "Base Accel", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMI160, - .type = MOTIONSENSE_TYPE_ACCEL, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, - .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, - .port = I2C_PORT_GYRO, - .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, - .rot_standard_ref = &base_standard_ref, - .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */ - .min_frequency = BMI_ACCEL_MIN_FREQ, - .max_frequency = BMI_ACCEL_MAX_FREQ, - .config = { - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* Sensor on for lid angle detection */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - }, - }, - - [BASE_GYRO] = { - .name = "Base Gyro", - .active_mask = SENSOR_ACTIVE_S0, - .chip = MOTIONSENSE_CHIP_BMI160, - .type = MOTIONSENSE_TYPE_GYRO, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, - .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, - .port = I2C_PORT_GYRO, - .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, - .default_range = 1000, /* dps */ - .rot_standard_ref = &base_standard_ref, - .min_frequency = BMI_GYRO_MIN_FREQ, - .max_frequency = BMI_GYRO_MAX_FREQ, - }, -}; -unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); - -void board_hibernate(void) -{ - /* - * To support hibernate called from console commands, ectool commands - * and key sequence, shutdown the AP before hibernating. - */ - chipset_do_shutdown(); - - /* Added delay to allow AP to settle down */ - msleep(100); - - /* Enable both the VBUS & VCC ports before entering PG3 */ - bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH, 1); - - /* Turn BGATE OFF for saving the power */ - bd9995x_set_power_save_mode(BD9995X_PWR_SAVE_MAX); -} - -static void board_set_motion_sensor_count(uint8_t sku_id) -{ - /* - * There are two possible sensor configurations. Clamshell device will - * not have any of the motion sensors populated, while convertible - * devices have the BMI160 Accel/Gryo and Kionx KX022 lid acceleration - * sensor. If a new SKU id is used that is not in the table, then the - * number of motion sensors will remain as ARRAY_SIZE(motion_sensors). - */ - motion_sensor_count = SKU_IS_CONVERTIBLE(sku_id) ? - ARRAY_SIZE(motion_sensors) : 0; - - CPRINTS("Motion Sensor Count = %d", motion_sensor_count); -} - -struct { - enum coral_board_version version; - int thresh_mv; -} const coral_board_versions[] = { - /* Vin = 3.3V, Ideal voltage, R2 values listed below */ - /* R1 = 51.1 kOhm */ - { BOARD_VERSION_1, 200 }, /* 124 mV, 2.0 Kohm */ - { BOARD_VERSION_2, 366 }, /* 278 mV, 4.7 Kohm */ - { BOARD_VERSION_3, 550 }, /* 456 mV, 8.2 Kohm */ - { BOARD_VERSION_4, 752 }, /* 644 mV, 12.4 Kohm */ - { BOARD_VERSION_5, 927}, /* 860 mV, 18.0 Kohm */ - { BOARD_VERSION_6, 1073 }, /* 993 mV, 22.0 Kohm */ - { BOARD_VERSION_7, 1235 }, /* 1152 mV, 27.4 Kohm */ - { BOARD_VERSION_8, 1386 }, /* 1318 mV, 34.0 Kohm */ - { BOARD_VERSION_9, 1552 }, /* 1453 mV, 40.2 Kohm */ - /* R1 = 10.0 kOhm */ - { BOARD_VERSION_10, 1739 }, /* 1650 mV, 10.0 Kohm */ - { BOARD_VERSION_11, 1976 }, /* 1827 mV, 12.4 Kohm */ - { BOARD_VERSION_12, 2197 }, /* 2121 mV, 18.0 Kohm */ - { BOARD_VERSION_13, 2344 }, /* 2269 mV, 22.0 Kohm */ - { BOARD_VERSION_14, 2484 }, /* 2418 mV, 27.4 Kohm */ - { BOARD_VERSION_15, 2636 }, /* 2550 mV, 34.0 Kohm */ - { BOARD_VERSION_16, 2823 }, /* 2721 mV, 47.0 Kohm */ -}; -BUILD_ASSERT(ARRAY_SIZE(coral_board_versions) == BOARD_VERSION_COUNT); - -static int board_read_version(enum adc_channel chan) -{ - int mv; - int i; - - /* ID/SKU enable is active high */ - gpio_set_flags(GPIO_EC_BRD_ID_EN, GPIO_OUT_HIGH); - /* Wait to allow cap charge */ - msleep(1); - mv = adc_read_channel(chan); - CPRINTS("ID/SKU ADC %d = %d mV", chan, mv); - /* Disable ID/SKU circuit */ - gpio_set_flags(GPIO_EC_BRD_ID_EN, GPIO_INPUT); - - if (mv == ADC_READ_ERROR) - return BOARD_VERSION_UNKNOWN; - - for (i = 0; i < BOARD_VERSION_COUNT; i++) - if (mv < coral_board_versions[i].thresh_mv) - return coral_board_versions[i].version; - - return BOARD_VERSION_UNKNOWN; -} - -int board_get_version(void) -{ - static int version = BOARD_VERSION_UNKNOWN; - - if (version != BOARD_VERSION_UNKNOWN) - return version; - - version = board_read_version(ADC_BOARD_ID); - - CPRINTS("Board version: %d", version); - return version; -} - -static void sku_id_init(void) -{ - int sku_id_lower; - int sku_id_higher; - - if (sku_id == BOARD_VERSION_UNKNOWN) { - sku_id_lower = board_read_version(ADC_BOARD_SKU_0); - sku_id_higher = board_read_version(ADC_BOARD_SKU_1); - if ((sku_id_lower != BOARD_VERSION_UNKNOWN) && - (sku_id_higher != BOARD_VERSION_UNKNOWN)) - sku_id = (sku_id_higher << 4) | sku_id_lower; - CPRINTS("SKU ID: %d", sku_id); - /* Use sku_id to set motion sensor count */ - board_set_motion_sensor_count(sku_id); - - if (0 == SKU_IS_CONVERTIBLE(sku_id)) { - CPRINTS("Disable tablet mode interrupt"); - gpio_disable_interrupt(GPIO_TABLET_MODE_L); - /* Enfore device in laptop mode */ - tablet_set_mode(0, TABLET_TRIGGER_LID); - } - } -} -/* This can't run until after the ADC module has been initialized */ -DECLARE_HOOK(HOOK_INIT, sku_id_init, HOOK_PRIO_INIT_ADC + 1); - -static void print_form_factor_list(int low, int high) -{ - int id; - int count = 0; - - if (high > 255) - high = 255; - for (id = low; id <= high; id++) { - ccprintf("SKU ID %03d: %s\n", id, SKU_IS_CONVERTIBLE(id) ? - "Convertible" : "Clamshell"); - /* Don't print too many lines at once */ - if (!(++count % 5)) - msleep(20); - } -} - -static int command_sku(int argc, char **argv) -{ - enum adc_channel chan; - - if (argc < 2) { - system_get_sku_id(); - ccprintf("SKU ID: %d\n", sku_id); - return EC_SUCCESS; - } - - if (!strcasecmp(argv[1], "form")) { - if (argc >= 4) { - char *e; - int low, high; - - low = strtoi(argv[2], &e, 10); - if (*e) - return EC_ERROR_PARAM1; - - high = strtoi(argv[3], &e, 10); - if (*e) - return EC_ERROR_PARAM2; - print_form_factor_list(low, high); - return EC_SUCCESS; - } else { - return EC_ERROR_PARAM_COUNT; - } - } - - if (!strcasecmp(argv[1], "board")) - chan = ADC_BOARD_ID; - else if (!strcasecmp(argv[1], "line0")) - chan = ADC_BOARD_SKU_0; - else if (!strcasecmp(argv[1], "line1")) - chan = ADC_BOARD_SKU_1; - else - return EC_ERROR_PARAM1; - - ccprintf("sku: %s = %d, adc %d\n", argv[1], board_read_version(chan), - chan); - - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(sku, command_sku, - "<board|line0|line1|form [low high]>", - "Get board id, sku, form factor"); - -__override uint32_t board_get_sku_id(void) -{ - if (sku_id == BOARD_VERSION_UNKNOWN) - sku_id_init(); - - return (uint32_t)sku_id; -} - -/* Keyboard scan setting */ -__override struct keyboard_scan_config keyscan_config = { - /* - * F3 key scan cycle completed but scan input is not - * charging to logic high when EC start scan next - * column for "T" key, so we set .output_settle_us - * to 80us from 50us. - */ - .output_settle_us = 80, - .debounce_down_us = 9 * MSEC, - .debounce_up_us = 30 * MSEC, - .scan_period_us = 3 * MSEC, - .min_post_scan_delay_us = 1000, - .poll_timeout_us = 100 * MSEC, - .actual_key_mask = { - 0x14, 0xff, 0xff, 0xff, 0xff, 0xf5, 0xff, - 0xa4, 0xff, 0xfe, 0x55, 0xfa, 0xca /* full set */ - }, -}; - -__override uint32_t board_override_feature_flags0(uint32_t flags0) -{ - uint32_t sku = system_get_sku_id(); - - /* - * We always compile in backlight support for coral, but only some - * models come with the hardware. Therefore, check if the current - * device is one of them and return the default value - with backlight - * here. - */ - if (sku == 8 || sku == 11) - return flags0; - - // Report that there is no keyboard backlight - flags0 &= ~EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB); - - return flags0; -} diff --git a/board/coral/board.h b/board/coral/board.h deleted file mode 100644 index 24b0ecf86e..0000000000 --- a/board/coral/board.h +++ /dev/null @@ -1,309 +0,0 @@ -/* Copyright 2016 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. - */ - -/* Coral board configuration */ - -#ifndef __CROS_EC_BOARD_H -#define __CROS_EC_BOARD_H - -/* - * By default, enable all console messages except Events: - * The sensor stack is generating a lot of activity. - */ -#define CC_DEFAULT (CC_ALL & ~CC_MASK(CC_EVENTS)) -#undef CONFIG_HOSTCMD_DEBUG_MODE -#define CONFIG_HOSTCMD_DEBUG_MODE HCDEBUG_OFF - - -/* EC console commands */ -#define CONFIG_CMD_ACCELS -#define CONFIG_CMD_ACCEL_INFO -#define CONFIG_CMD_BATT_MFG_ACCESS -#define CONFIG_CMD_CHARGER_ADC_AMON_BMON -#define CONFIG_CHARGER_SENSE_RESISTOR 10 -#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10 -#define BD9995X_IOUT_GAIN_SELECT \ - BD9995X_CMD_PMON_IOUT_CTRL_SET_IOUT_GAIN_SET_20V - -#define CONFIG_CHARGER_PSYS_READ -#define BD9995X_PSYS_GAIN_SELECT \ - BD9995X_CMD_PMON_IOUT_CTRL_SET_PMON_GAIN_SET_02UAW - -#define CONFIG_CMD_I2C_STRESS_TEST -#define CONFIG_CMD_I2C_STRESS_TEST_ACCEL -#define CONFIG_CMD_I2C_STRESS_TEST_ALS -#define CONFIG_CMD_I2C_STRESS_TEST_BATTERY -#define CONFIG_CMD_I2C_STRESS_TEST_CHARGER -#define CONFIG_CMD_I2C_STRESS_TEST_TCPC - -/* Port80 */ -#undef CONFIG_PORT80_HISTORY_LEN -#define CONFIG_PORT80_HISTORY_LEN 256 - -/* Battery */ -#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION" -#define CONFIG_BATTERY_CUT_OFF -#define CONFIG_BATTERY_HW_PRESENT_CUSTOM -#define CONFIG_BATTERY_LEVEL_NEAR_FULL 94 -#define CONFIG_BATTERY_PRESENT_CUSTOM -#define CONFIG_BATTERY_SMART - -/* Charger */ -#define CONFIG_CHARGE_MANAGER -#define CONFIG_CHARGE_RAMP_SW -#define CONFIG_CHARGE_STATE_DEBUG -#define CONFIG_CHARGER -#define CONFIG_CHARGER_BD9995X -#define CONFIG_CHARGER_BD9995X_CHGEN -#define CONFIG_CHARGER_DISCHARGE_ON_AC -#define CONFIG_CHARGER_INPUT_CURRENT 512 -#define CONFIG_CHARGER_MAINTAIN_VBAT -#undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON -#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1 -#define CONFIG_USB_CHARGER -#define CONFIG_CHARGER_PROFILE_OVERRIDE -#define CONFIG_CHARGE_MANAGER_EXTERNAL_POWER_LIMIT - -/* USB-A config */ -#define CONFIG_USB_PORT_POWER_SMART -#define CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE USB_CHARGE_MODE_CDP -#define CONFIG_USB_PORT_POWER_SMART_SIMPLE -#undef CONFIG_USB_PORT_POWER_SMART_PORT_COUNT -#define CONFIG_USB_PORT_POWER_SMART_PORT_COUNT 1 -#define GPIO_USB1_ILIM_SEL GPIO_USB_A_CHARGE_EN_L -#define GPIO_USB_CTL1 GPIO_EN_PP5000 - -#define CONFIG_TABLET_MODE - -/* USB PD config */ -#define CONFIG_HOSTCMD_PD_CONTROL -#define CONFIG_USB_PD_ALT_MODE -#define CONFIG_USB_PD_ALT_MODE_DFP -#define CONFIG_USB_PD_DUAL_ROLE -#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#define CONFIG_USB_PD_DISCHARGE_TCPC -#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_VBUS_DETECT_CHARGER -#define CONFIG_USB_PD_TCPC_LOW_POWER -#define CONFIG_USB_PD_TCPM_MUX /* for both PS8751 and ANX3429 */ -#define CONFIG_USB_PD_TCPM_ANX3429 -#define CONFIG_USB_PD_TCPM_PS8751 -#define CONFIG_USB_PD_TCPM_TCPCI -#define CONFIG_USB_PD_TRY_SRC -#define CONFIG_USB_POWER_DELIVERY -#define CONFIG_USB_PD_TCPMV1 -#define CONFIG_USB_PD_COMM_LOCKED - -#define CONFIG_USBC_SS_MUX -#define CONFIG_USBC_SS_MUX_DFP_ONLY -#define CONFIG_USBC_VCONN -#define CONFIG_USBC_VCONN_SWAP - -/* SoC / PCH */ -#define CONFIG_HOSTCMD_LPC -#define CONFIG_CHIPSET_APOLLOLAKE -#define CONFIG_CHIPSET_RESET_HOOK -#define CONFIG_POWER_BUTTON -#define CONFIG_POWER_BUTTON_X86 -#define CONFIG_POWER_COMMON -#define CONFIG_POWER_S0IX -#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE - -/* EC */ -#define CONFIG_ADC -#define CONFIG_EXTPOWER_GPIO -#undef CONFIG_EXTPOWER_DEBOUNCE_MS -#define CONFIG_EXTPOWER_DEBOUNCE_MS 1000 -#define CONFIG_FPU -/* Region sizes are not a power of 2 so we can't use MPU */ -#undef CONFIG_MPU -#define CONFIG_HOSTCMD_FLASH_SPI_INFO -#define CONFIG_I2C -#define CONFIG_I2C_CONTROLLER - -#define CONFIG_KEYBOARD_PROTOCOL_8042 -#define CONFIG_KEYBOARD_COL2_INVERTED -#define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2 -#define CONFIG_LED_COMMON -#define CONFIG_LID_SWITCH -#define CONFIG_LOW_POWER_IDLE -#define CONFIG_LTO -#define CONFIG_POWER_SIGNAL_INTERRUPT_STORM_DETECT_THRESHOLD 30 -#define CONFIG_PWM -#define CONFIG_PWM_KBLIGHT -#define CONFIG_TEMP_SENSOR -#define CONFIG_THERMISTOR_NCP15WB -#define CONFIG_STEINHART_HART_3V3_13K7_47K_4050B -#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B -#define CONFIG_DPTF -#define CONFIG_SCI_GPIO GPIO_PCH_SCI_L -#define CONFIG_VBOOT_HASH -#define CONFIG_VOLUME_BUTTONS -#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL -#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL -#define CONFIG_BACKLIGHT_LID -#define CONFIG_WIRELESS -#define CONFIG_WIRELESS_SUSPEND EC_WIRELESS_SWITCH_WLAN_POWER -#define CONFIG_WLAN_POWER_ACTIVE_LOW -#define WIRELESS_GPIO_WLAN_POWER GPIO_WIRELESS_GPIO_WLAN_POWER -#define CONFIG_PWR_STATE_DISCHARGE_FULL - -/* - * During shutdown sequence TPS65094x PMIC turns off the sensor rails - * asynchronously to the EC. If we access the sensors when the sensor power - * rails are off we get I2C errors. To avoid this issue, defer switching - * the sensors rate if in S3. By the time deferred function is serviced if - * the chipset is in S5 we can back out from switching the sensor rate. - * - * Time taken by V1P8U rail to go down from S3 is 30ms to 60ms hence defer - * the sensor switching after 60ms. - */ -#undef CONFIG_MOTION_SENSE_SUSPEND_DELAY_US -#define CONFIG_MOTION_SENSE_SUSPEND_DELAY_US (MSEC * 60) - -#define CONFIG_FLASH_SIZE_BYTES 524288 -#define CONFIG_SPI_FLASH_REGS -#define CONFIG_SPI_FLASH_W25Q40 /* FIXME: Should be GD25LQ40? */ - -/* - * Enable 1 slot of secure temporary storage to support - * suspend/resume with read/write memory training. - */ -#define CONFIG_VSTORE -#define CONFIG_VSTORE_SLOT_COUNT 1 - -/* Optional feature - used by nuvoton */ -#define NPCX_UART_MODULE2 1 /* 0:GPIO10/11 1:GPIO64/65 as UART */ -#define NPCX_JTAG_MODULE2 0 /* 0:GPIO21/17/16/20 1:GPIOD5/E2/D4/E5 as JTAG*/ -/* FIXME(dhendrix): these pins are just normal GPIOs on Coral. Do we need - * to change some other setting to put them in GPIO mode? */ -#define NPCX_TACH_SEL2 0 /* 0:GPIO40/73 1:GPIO93/A6 as TACH */ - -/* I2C ports */ -#define I2C_PORT_GYRO NPCX_I2C_PORT1 -#define I2C_PORT_LID_ACCEL NPCX_I2C_PORT2 -#define I2C_PORT_BATTERY NPCX_I2C_PORT3 -#define I2C_PORT_CHARGER NPCX_I2C_PORT3 -/* Accelerometer and Gyroscope are the same device. */ -#define I2C_PORT_ACCEL I2C_PORT_GYRO - -/* Sensors */ -#define CONFIG_MKBP_EVENT -#define CONFIG_MKBP_USE_HOST_EVENT -#define CONFIG_ACCELGYRO_BMI160 -#define CONFIG_ACCEL_INTERRUPTS -#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ - TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) -#define CONFIG_MAG_CALIBRATE -#define CONFIG_ACCEL_KX022 -#define CONFIG_LID_ANGLE -#define CONFIG_LID_ANGLE_UPDATE -#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL -#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL -#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT - -/* Enable sensor fifo, must also define the _SIZE and _THRES */ -#define CONFIG_ACCEL_FIFO -/* FIFO size is in power of 2. */ -#define CONFIG_ACCEL_FIFO_SIZE 512 -/* Depends on how fast the AP boots and typical ODRs */ -#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3) - - -#ifndef __ASSEMBLER__ - -#include "gpio_signal.h" -#include "registers.h" - -/* ADC signal */ -enum adc_channel { - ADC_TEMP_SENSOR_CHARGER, /* ADC0 */ - ADC_TEMP_SENSOR_AMB, /* ADC1 */ - ADC_BOARD_ID, /* ADC2 */ - ADC_BOARD_SKU_1, /* ADC3 */ - ADC_BOARD_SKU_0, /* ADC4 */ - ADC_CH_COUNT -}; - -enum pwm_channel { - PWM_CH_KBLIGHT = 0, - /* Number of PWM channels */ - PWM_CH_COUNT -}; - -enum temp_sensor_id { - TEMP_SENSOR_BATTERY = 0, - TEMP_SENSOR_AMBIENT, - TEMP_SENSOR_CHARGER, - TEMP_SENSOR_COUNT -}; - -/* - * Motion sensors: - * When reading through IO memory is set up for sensors (LPC is used), - * the first 2 entries must be accelerometers, then gyroscope. - * For BMI160, accel, gyro and compass sensors must be next to each other. - */ -enum sensor_id { - LID_ACCEL, - BASE_ACCEL, - BASE_GYRO, - SENSOR_COUNT, -}; - -#define CONFIG_HOSTCMD_SKUID -enum coral_board_version { - BOARD_VERSION_UNKNOWN = -1, - BOARD_VERSION_1, - BOARD_VERSION_2, - BOARD_VERSION_3, - BOARD_VERSION_4, - BOARD_VERSION_5, - BOARD_VERSION_6, - BOARD_VERSION_7, - BOARD_VERSION_8, - BOARD_VERSION_9, - BOARD_VERSION_10, - BOARD_VERSION_11, - BOARD_VERSION_12, - BOARD_VERSION_13, - BOARD_VERSION_14, - BOARD_VERSION_15, - BOARD_VERSION_16, - BOARD_VERSION_COUNT, -}; - -/* TODO: determine the following board specific type-C power constants */ -/* FIXME(dhendrix): verify all of the below PD_* numbers */ -/* - * delay to turn on the power supply max is ~16ms. - * delay to turn off the power supply max is about ~180ms. - */ -#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */ -#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */ - -/* delay to turn on/off vconn */ - -/* Define typical operating power and max power */ -#define PD_OPERATING_POWER_MW 15000 -#define PD_MAX_POWER_MW 45000 -#define PD_MAX_CURRENT_MA 3000 -#define PD_MAX_VOLTAGE_MV 20000 - -/* Reset PD MCU */ -void board_reset_pd_mcu(void); - -int board_get_version(void); - -void board_set_tcpc_power_mode(int port, int mode); - -/* Sensors without hardware FIFO are in forced mode */ -#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL) - -#endif /* !__ASSEMBLER__ */ - -#endif /* __CROS_EC_BOARD_H */ diff --git a/board/coral/build.mk b/board/coral/build.mk deleted file mode 100644 index 728d027803..0000000000 --- a/board/coral/build.mk +++ /dev/null @@ -1,14 +0,0 @@ -# -*- makefile -*- -# Copyright 2015 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_VARIANT:=npcx5m6g - -board-y=board.o led.o -board-$(CONFIG_BATTERY_SMART)+=battery.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o diff --git a/board/coral/ec.tasklist b/board/coral/ec.tasklist deleted file mode 100644 index eeebc0cc59..0000000000 --- a/board/coral/ec.tasklist +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2016 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(CHG_RAMP, chg_ramp_task, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(USB_CHG, usb_charger_task, NULL, 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(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_NOTEST(KEYPROTO, keyboard_protocol_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(POWERBTN, power_button_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(PD_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/coral/gpio.inc b/board/coral/gpio.inc deleted file mode 100644 index 8e52eeeed2..0000000000 --- a/board/coral/gpio.inc +++ /dev/null @@ -1,167 +0,0 @@ -/* -*- mode:c -*- - * - * Copyright 2016 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. */ - -GPIO_INT(CHARGER_INT_L, PIN(3, 3), GPIO_INT_FALLING, bd9995x_vbus_interrupt) /* CHARGER_EC_INT_ODL from BD99956 */ -/* - * TODO: The pull ups for Parade TCPC interrupt line can be removed in versions - * of board following EVT in which daughter card (which has an external pull up) - * will always be inserted. - */ -GPIO_INT(USB_C0_PD_INT_ODL, PIN(3, 7), GPIO_INT_FALLING, tcpc_alert_event) /* from Analogix TCPC */ -GPIO_INT(USB_C1_PD_INT_ODL, PIN(B, 1), GPIO_INT_FALLING | GPIO_PULL_UP, tcpc_alert_event) /* from Parade TCPC */ - -GPIO_INT(USB_C0_CABLE_DET, PIN(C, 5), GPIO_INT_RISING, anx74xx_cable_det_interrupt) /* CABLE_DET from ANX3429 */ -#ifdef CONFIG_POWER_S0IX -GPIO_INT(PCH_SLP_S0_L, PIN(7, 5), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S0_L */ -#endif -GPIO_INT(PCH_SLP_S4_L, PIN(8, 6), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S4_L */ -GPIO_INT(PCH_SLP_S3_L, PIN(7, 3), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S3_L */ -GPIO_INT(SUSPWRDNACK, PIN(7, 2), GPIO_INT_BOTH, power_signal_interrupt) -GPIO_INT(RSMRST_L_PGOOD, PIN(6, 0), GPIO_INT_BOTH, power_signal_interrupt) /* PMIC_EC_RSMRST_ODL */ -GPIO_INT(ALL_SYS_PGOOD, PIN(5, 0), GPIO_INT_BOTH, power_signal_interrupt) /* PMIC_EC_PWROK_OD */ - -GPIO_INT(AC_PRESENT, PIN(C, 1), GPIO_INT_BOTH, extpower_interrupt) /* ACOK_OD from BD99956 */ -/* TODO: We might remove external pull-up for POWER_BUTTON_L in EVT */ -GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH, power_button_interrupt) /* MECH_PWR_BTN_ODL */ -GPIO_INT(LID_OPEN, PIN(6, 7), GPIO_INT_BOTH, lid_interrupt) -GPIO_INT(EC_VOLDN_BTN_ODL, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) -GPIO_INT(EC_VOLUP_BTN_ODL, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) - -/* Tablet switch is active-low. L: lid is attached (360 position) H: detached */ -GPIO_INT(TABLET_MODE_L, PIN(3, 6), GPIO_INT_BOTH, tablet_mode_interrupt) - -GPIO_INT(WP_L, PIN(4, 0), GPIO_INT_BOTH | GPIO_SEL_1P8V, switch_interrupt) /* EC_WP_ODL */ - -GPIO_INT(BASE_SIXAXIS_INT_L, PIN(9, 3), GPIO_INT_FALLING | GPIO_SEL_1P8V, - bmi160_interrupt) -GPIO(LID_ACCEL_INT_L, PIN(C, 7), GPIO_INPUT | GPIO_SEL_1P8V) - -/* I2C GPIOs will be set to alt. function later. */ -GPIO(EC_I2C_GYRO_SDA, PIN(8, 7), GPIO_INPUT | GPIO_SEL_1P8V) -GPIO(EC_I2C_GYRO_SCL, PIN(9, 0), GPIO_INPUT | GPIO_SEL_1P8V) -GPIO(EC_I2C_SENSOR_SDA, PIN(9, 1), GPIO_INPUT | GPIO_SEL_1P8V) -GPIO(EC_I2C_SENSOR_SCL, PIN(9, 2), GPIO_INPUT | GPIO_SEL_1P8V) -GPIO(EC_I2C_USB_C0_PD_SDA, PIN(B, 4), GPIO_INPUT) -GPIO(EC_I2C_USB_C0_PD_SCL, PIN(B, 5), GPIO_INPUT) -GPIO(EC_I2C_USB_C1_PD_SDA, PIN(B, 2), GPIO_INPUT) -GPIO(EC_I2C_USB_C1_PD_SCL, PIN(B, 3), GPIO_INPUT) -GPIO(EC_I2C_POWER_SDA, PIN(D, 0), GPIO_INPUT) -GPIO(EC_I2C_POWER_SCL, PIN(D, 1), GPIO_INPUT) - -/* - * LPC: - * Pins 46, 47, 51, 52, 53, 54, 55, default to LPC mode. - * Pin 56 (CLKRUN#) defaults to GPIO mode. - * Pin 57 (SER_IRQ) defaults to LPC mode, but we also have EC_PCH_KB_INT_ODL - * (Pin B0) in case it doesn't work (Set CONFIG_KEYBOARD_IRQ_GPIO in this case). - * - * See also the NO_LPC_ESPI bit in DEVALT1 and the CONFIG_HOSTCMD_SHI option. - */ - -GPIO(PCH_SMI_L, PIN(A, 6), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* EC_SMI_ODL */ -GPIO(PCH_SCI_L, PIN(A, 7), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* EC_SCI_ODL */ -#ifndef CONFIG_POWER_S0IX -GPIO(PCH_SLP_S0_L, PIN(7, 5), GPIO_INPUT) /* SLP_S0_L */ -#endif - -/* Enable for board and SKU ID ADCs */ -GPIO(EC_BRD_ID_EN, PIN(3, 5), GPIO_INPUT) - -GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) -GPIO(ENTERING_RW, PIN(7, 6), GPIO_OUTPUT) /* EC_ENTERING_RW */ - -GPIO(PCH_RSMRST_L, PIN(7, 0), GPIO_OUT_LOW) -GPIO(EC_BATT_PRES_L, PIN(3, 4), GPIO_INPUT) -GPIO(PMIC_EN, PIN(8, 5), GPIO_OUT_LOW) -GPIO(EN_PP3300, PIN(C, 2), GPIO_OUT_LOW) -GPIO(PP3300_PG, PIN(6, 2), GPIO_INPUT) -GPIO(EN_PP5000, PIN(C, 6), GPIO_OUT_LOW) -GPIO(PP5000_PG, PIN(7, 1), GPIO_INPUT) -GPIO(EN_P3300_TRACKPAD_ODL, PIN(3, 2), GPIO_ODR_LOW) -/* Control the gate for trackpad IRQ. High closes the gate. - * This is always set low so that the OS can manage the trackpad. */ -GPIO(TRACKPAD_INT_GATE, PIN(A, 1), GPIO_OUT_LOW) -GPIO(PCH_SYS_PWROK, PIN(E, 7), GPIO_OUT_LOW) /* EC_PCH_PWROK */ -GPIO(ENABLE_BACKLIGHT, PIN(9, 7), GPIO_ODR_HIGH | GPIO_SEL_1P8V) /* EC_BL_EN_OD */ - -GPIO(WIRELESS_GPIO_WLAN_POWER, PIN(6, 6), GPIO_ODR_HIGH) /* EN_PP3300_WLAN_ODL */ - -/* - * PCH_PROCHOT_ODL is primarily for monitoring the PROCHOT# signal which is - * normally driven by the PMIC. The EC can also drive this signal in the event - * that the ambient or charger temperature sensors exceeds their thresholds. - */ -GPIO(CPU_PROCHOT, PIN(A, 3), GPIO_INPUT | GPIO_SEL_1P8V) /* PCH_PROCHOT_ODL */ - -GPIO(PCH_PWRBTN_L, PIN(0, 1), GPIO_ODR_HIGH) /* EC_PCH_PWR_BTN_ODL */ -GPIO(PCH_WAKE_L, PIN(8, 1), GPIO_ODR_HIGH) /* EC_PCH_WAKE_ODL */ -GPIO(USB_C0_HPD_1P8_ODL, PIN(9, 4), GPIO_INPUT | GPIO_SEL_1P8V) -GPIO(USB_C1_HPD_1P8_ODL, PIN(A, 5), GPIO_INPUT | GPIO_SEL_1P8V) - -GPIO(USB2_OTG_VBUSSENSE, PIN(9, 5), GPIO_OUTPUT) - -/* EC_PCH_RTCRST is a sledgehammer for resetting SoC state and should rarely - * be used. Set as input for now, we'll set it as an output when we want to use - * it. Has external pull-down resistor. */ -GPIO(EC_PCH_RTCRST, PIN(B, 7), GPIO_INPUT) -GPIO(SYS_RESET_L, PIN(6, 1), GPIO_ODR_HIGH) /* SYS_RST_ODL */ - -/* FIXME: What, if anything, to do about EC_RST_ODL on VCC1_RST#? */ - -GPIO(CHARGER_RST_ODL, PIN(C, 0), GPIO_ODR_HIGH) -GPIO(USB_A_CHARGE_EN_L, PIN(8, 4), GPIO_OUT_LOW) -GPIO(USB1_ENABLE, PIN(0, 0), GPIO_OUT_HIGH) -GPIO(EN_USB_TCPC_PWR, PIN(C, 3), GPIO_OUT_LOW) - -GPIO(USB_C0_PD_RST_L, PIN(0, 3), GPIO_OUT_LOW) /* USB_C0_PD_RST_L */ -GPIO(USB_C1_PD_RST_ODL, PIN(7, 4), GPIO_ODR_HIGH) - -/* - * Configure as input to enable @ 1.5A, output-low to turn off, or output-high - * to enable @ 3A. - */ -GPIO(USB_C0_5V_EN, PIN(D, 3), GPIO_OUT_LOW | GPIO_PULL_UP) /* EN_USB_C0_5V_OUT, Enable C0 */ -GPIO(USB_C1_5V_EN, PIN(D, 2), GPIO_OUT_LOW | GPIO_PULL_UP) /* EN_USB_C1_5V_OUT, Enable C1 */ - -GPIO(BAT_LED_BLUE, PIN(8, 0), GPIO_OUT_HIGH) -GPIO(BAT_LED_AMBER, PIN(C, 4), GPIO_OUT_HIGH) -GPIO(POWER_LED, PIN(0, 2), GPIO_OUT_HIGH) - - -/* - * Alternate function pins - */ -/* Keyboard pins */ -#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP) -#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH) -#define GPIO_KB_OUTPUT_COL2 (GPIO_OUT_LOW) -ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) -ALTERNATE(PIN_MASK(2, 0xfc), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) -ALTERNATE(PIN_MASK(2, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) -ALTERNATE(PIN_MASK(0, 0xe0), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) -ALTERNATE(PIN_MASK(1, 0x7f), 0, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) -GPIO(KBD_KSO2, PIN(1, 7), GPIO_KB_OUTPUT_COL2) - -/* Board and SKU ID ADC inputs (GPIO 41, 42, 43) */ -ALTERNATE(PIN_MASK(4, 0x02), 1, MODULE_ADC, 0) -ALTERNATE(PIN_MASK(4, 0x04), 1, MODULE_ADC, 0) -ALTERNATE(PIN_MASK(4, 0x08), 1, MODULE_ADC, 0) - -ALTERNATE(PIN_MASK(8, 0x80), 1, MODULE_I2C, 0) /* GPIO87 for EC_I2C_GYRO_SDA */ -ALTERNATE(PIN_MASK(9, 0x01), 1, MODULE_I2C, 0) /* GPIO90 for EC_I2C_GYRO_SCL */ -ALTERNATE(PIN_MASK(9, 0x06), 1, MODULE_I2C, 0) /* GPIO92-91 for EC_I2C_SENSOR_SDA/SCL */ -ALTERNATE(PIN_MASK(B, 0x30), 1, MODULE_I2C, 0) /* GPIOB5-B4 for EC_I2C_USB_C0_PD_SDA/SCL */ -ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, 0) /* GPOPB3-B2 for EC_I2C_USB_C1_PD_SDA/SCL */ -ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* GPIOD1-D0 for EC_I2C_POWER_SDA/SCL */ - -ALTERNATE(PIN(B, 6), 3, MODULE_PWM, 0) /* PWM KB Backlight */ - -/* FIXME: Make UART RX an interrupt? */ -ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */ diff --git a/board/coral/led.c b/board/coral/led.c deleted file mode 100644 index 2a1e39946c..0000000000 --- a/board/coral/led.c +++ /dev/null @@ -1,325 +0,0 @@ -/* Copyright 2016 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 for Coral - */ - -#include "battery.h" -#include "charge_state.h" -#include "chipset.h" -#include "ec_commands.h" -#include "extpower.h" -#include "gpio.h" -#include "hooks.h" -#include "host_command.h" -#include "led_common.h" -#include "system.h" -#include "util.h" - -#define LED_ON_LVL 0 -#define LED_OFF_LVL 1 -#define LED_INDEFINITE -1 -#define LED_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS) -#define LED_CHARGE_LEVEL_1_DEFAULT 100 -#define LED_CHARGE_LEVEL_1_ROBO 5 -#define LED_POWER_BLINK_ON_MSEC 3000 -#define LED_POWER_BLINK_OFF_MSEC 600 -#define LED_POWER_ON_TICKS (LED_POWER_BLINK_ON_MSEC / HOOK_TICK_INTERVAL_MS) -#define LED_POWER_OFF_TICKS (LED_POWER_BLINK_OFF_MSEC / HOOK_TICK_INTERVAL_MS) - -const enum ec_led_id supported_led_ids[] = { - EC_LED_ID_BATTERY_LED}; - -const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); - -#define GPIO_LED_COLOR_1 GPIO_BAT_LED_AMBER -#define GPIO_LED_COLOR_2 GPIO_BAT_LED_BLUE -#define GPIO_LED_COLOR_3 GPIO_POW_LED - -enum led_phase { - LED_PHASE_0, - LED_PHASE_1, - LED_NUM_PHASES -}; - -enum led_color { - LED_OFF, - LED_COLOR_1, - LED_COLOR_2, - LED_COLOR_BOTH, - LED_COLOR_COUNT /* Number of colors, not a color itself */ -}; - -enum led_states { - STATE_CHARGING_LVL_1, - STATE_CHARGING_LVL_2, - STATE_CHARGING_LVL_3, - STATE_DISCHARGE_S0, - STATE_DISCHARGE_S3, - STATE_DISCHARGE_S5, - STATE_BATTERY_ERROR, - STATE_FACTORY_TEST, - LED_NUM_STATES -}; - -struct led_descriptor { - int8_t color; - int8_t time; -}; - -struct led_info { - enum led_states state; - uint8_t charge_lvl_1; - const struct led_descriptor (*state_table)[LED_NUM_PHASES]; - void (*update_power)(void); -}; - -/* - * LED state tables describe the desired LED behavior for a each possible - * state. The LED state is based on both chip power state and the battery charge - * level. The first parameter is the color and the 2nd parameter is the time in - * ticks, where each tick is 200 msec. If the time parameter is set to -1, that - * means it is a non-blinking pattern. - */ - -/* COLOR_1 = Amber, COLOR_2 = Blue */ -static const struct led_descriptor led_default_state_table[][LED_NUM_PHASES] = { - { {LED_COLOR_1, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_2, LED_INDEFINITE}, {LED_COLOR_1, LED_INDEFINITE} }, - { {LED_COLOR_2, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_2, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_1, 1 * LED_ONE_SEC }, {LED_OFF, 3 * LED_ONE_SEC} }, - { {LED_OFF, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_1, 1 * LED_ONE_SEC}, {LED_OFF, 1 * LED_ONE_SEC} }, - { {LED_COLOR_1, 2 * LED_ONE_SEC}, {LED_COLOR_2, 2 * LED_ONE_SEC} }, -}; - -/* COLOR_1 = Green, COLOR_2 = Red */ -static const struct led_descriptor led_robo_state_table[][LED_NUM_PHASES] = { - { {LED_COLOR_2, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_BOTH, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_1, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_OFF, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_OFF, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_OFF, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_2, 1 * LED_ONE_SEC}, {LED_OFF, 1 * LED_ONE_SEC} }, - { {LED_COLOR_2, 2 * LED_ONE_SEC}, {LED_COLOR_1, 2 * LED_ONE_SEC} }, -}; - -static const struct led_descriptor led_nasher_state_table[][LED_NUM_PHASES] = { - { {LED_COLOR_1, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_2, LED_INDEFINITE}, {LED_COLOR_1, LED_INDEFINITE} }, - { {LED_COLOR_2, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_2, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_2, 1 * LED_ONE_SEC}, {LED_OFF, 1 * LED_ONE_SEC} }, - { {LED_OFF, LED_INDEFINITE}, {LED_OFF, LED_INDEFINITE} }, - { {LED_COLOR_1, 1 * LED_ONE_SEC}, {LED_OFF, 1 * LED_ONE_SEC} }, - { {LED_COLOR_1, 2 * LED_ONE_SEC}, {LED_COLOR_2, 2 * LED_ONE_SEC} }, -}; - -static struct led_info led; - -static int led_set_color_battery(enum led_color color) -{ - switch (color) { - case LED_OFF: - gpio_set_level(GPIO_LED_COLOR_1, LED_OFF_LVL); - gpio_set_level(GPIO_LED_COLOR_2, LED_OFF_LVL); - break; - case LED_COLOR_1: - gpio_set_level(GPIO_LED_COLOR_1, LED_ON_LVL); - gpio_set_level(GPIO_LED_COLOR_2, LED_OFF_LVL); - break; - case LED_COLOR_2: - gpio_set_level(GPIO_LED_COLOR_1, LED_OFF_LVL); - gpio_set_level(GPIO_LED_COLOR_2, LED_ON_LVL); - break; - case LED_COLOR_BOTH: - gpio_set_level(GPIO_LED_COLOR_1, LED_ON_LVL); - gpio_set_level(GPIO_LED_COLOR_2, LED_ON_LVL); - break; - default: - return EC_ERROR_UNKNOWN; - } - return EC_SUCCESS; -} - -static void led_set_color_power(int level) -{ - gpio_set_level(GPIO_POWER_LED, level); -} - -void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) -{ - brightness_range[EC_LED_COLOR_BLUE] = 1; - brightness_range[EC_LED_COLOR_AMBER] = 1; - brightness_range[EC_LED_COLOR_RED] = 1; - brightness_range[EC_LED_COLOR_GREEN] = 1; -} - -int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) -{ - if (brightness[EC_LED_COLOR_BLUE] != 0) - led_set_color_battery(LED_COLOR_2); - else if (brightness[EC_LED_COLOR_AMBER] != 0) - led_set_color_battery(LED_COLOR_1); - else if (brightness[EC_LED_COLOR_RED] != 0) - led_set_color_battery(LED_COLOR_2); - else if (brightness[EC_LED_COLOR_GREEN] != 0) - led_set_color_battery(LED_COLOR_1); - else - led_set_color_battery(LED_OFF); - - return EC_SUCCESS; -} - -static enum led_states led_get_state(void) -{ - int charge_lvl; - enum led_states new_state = LED_NUM_STATES; - - switch (charge_get_state()) { - case PWR_STATE_CHARGE: - /* Get percent charge */ - charge_lvl = charge_get_percent(); - /* Determine which charge state to use */ - new_state = charge_lvl <= led.charge_lvl_1 ? - STATE_CHARGING_LVL_1 : STATE_CHARGING_LVL_2; - break; - case PWR_STATE_DISCHARGE_FULL: - if (extpower_is_present()) { - new_state = STATE_CHARGING_LVL_3; - break; - } - /* Intentional fall-through */ - case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: - if (chipset_in_state(CHIPSET_STATE_ON)) - new_state = STATE_DISCHARGE_S0; - else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) - new_state = STATE_DISCHARGE_S3; - else - new_state = STATE_DISCHARGE_S5; - break; - case PWR_STATE_ERROR: - new_state = STATE_BATTERY_ERROR; - break; - case PWR_STATE_CHARGE_NEAR_FULL: - new_state = STATE_CHARGING_LVL_3; - break; - case PWR_STATE_IDLE: /* External power connected in IDLE */ - if (charge_get_flags() & CHARGE_FLAG_FORCE_IDLE) - new_state = STATE_FACTORY_TEST; - else - new_state = STATE_DISCHARGE_S0; - break; - default: - /* Other states don't alter LED behavior */ - break; - } - - return new_state; -} - -static void led_update_battery(void) -{ - static int ticks; - int phase; - enum led_states desired_state = led_get_state(); - - /* Get updated state based on power state and charge level */ - if (desired_state < LED_NUM_STATES && desired_state != led.state) { - /* State is changing */ - led.state = desired_state; - /* Reset ticks counter when state changes */ - ticks = 0; - } - - /* - * Determine the which phase of the state table to use. Assume it's - * phase 0. If the time values for both phases of the current state are - * not -1, then this state uses some blinking pattern. The phase is then - * determined by taking the modulo of ticks by the blinking pattern - * period. - */ - phase = 0; - if ((led.state_table[led.state][LED_PHASE_0].time != LED_INDEFINITE) && - (led.state_table[led.state][LED_PHASE_1].time != LED_INDEFINITE)) { - int period; - - period = led.state_table[led.state][LED_PHASE_0].time + - led.state_table[led.state][LED_PHASE_1].time; - if (period) - phase = ticks % period < - led.state_table[led.state][LED_PHASE_0].time ? - 0 : 1; - } - - /* Set the color for the given state and phase */ - led_set_color_battery(led.state_table[led.state][phase].color); - ticks++; -} - -static void led_robo_update_power(void) -{ - int level; - static int ticks; - - if (chipset_in_state(CHIPSET_STATE_ON)) { - /* In S0 power LED is always on */ - level = LED_ON_LVL; - ticks = 0; - } else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) && - led.state <= STATE_CHARGING_LVL_3) { - int period; - - /* - * If in suspend/standby and the device is charging, then the - * power LED is off for 600 msec, on for 3 seconds. - */ - period = LED_POWER_ON_TICKS + LED_POWER_OFF_TICKS; - level = ticks % period < LED_POWER_OFF_TICKS ? - LED_OFF_LVL : LED_ON_LVL; - ticks++; - } else { - level = LED_OFF_LVL; - ticks = 0; - } - - led_set_color_power(level); -} - -/* Called by hook task every hook tick (200 msec) */ -static void led_update(void) -{ - /* Update battery LED */ - if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) { - led_update_battery(); - if (led.update_power != NULL) - (*led.update_power)(); - } -} -DECLARE_HOOK(HOOK_TICK, led_update, HOOK_PRIO_DEFAULT); - -static void led_init(void) -{ - int sku = system_get_sku_id(); - - if ((sku >= 70 && sku <= 79) || (sku >= 124 && sku <= 125) || - (sku >= 144 && sku <= 145)) { - led.charge_lvl_1 = LED_CHARGE_LEVEL_1_ROBO; - led.state_table = led_robo_state_table; - led.update_power = led_robo_update_power; - } else if (sku >= 160 && sku <= 166) { - led.charge_lvl_1 = LED_CHARGE_LEVEL_1_DEFAULT; - led.state_table = led_nasher_state_table; - led.update_power = NULL; - } else { - led.charge_lvl_1 = LED_CHARGE_LEVEL_1_DEFAULT; - led.state_table = led_default_state_table; - led.update_power = NULL; - } - led_set_color_battery(LED_OFF); -} -/* Make sure this comes after SKU ID hook */ -DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT + 2); diff --git a/board/coral/sku.h b/board/coral/sku.h deleted file mode 100644 index 4588932377..0000000000 --- a/board/coral/sku.h +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright 2017 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. - */ - -/* Coral SKU ID Table */ - -#ifndef __CROS_EC_SKU_H -#define __CROS_EC_SKU_H - -#define SKU_CONVERTIBLE(id) (1 << ((id) & 0x7)) - -/* - * There are 256 possible SKUs for Coral. This table is used to map a given SKU - * ID to its form factor, which is then used to determine number of motion - * sensors. A bit value of 0 is for clamshell and a bit value of 1 indicates a - * convertible device. The assumption is all devices are defined as clamshells - * unless SKU_CONVERTIBLE(id) is spelled out in the initialization. - */ -static const uint8_t form_factor[32] = { - /* SKU 0 - 7 */ - SKU_CONVERTIBLE(4) | SKU_CONVERTIBLE(5), - /* SKU 8 - 15 */ - SKU_CONVERTIBLE(8) | SKU_CONVERTIBLE(9) | SKU_CONVERTIBLE(10) | - SKU_CONVERTIBLE(11), - /* SKU 16 - 23 */ - 0x00, - /* SKU 24 - 31 */ - 0x00, - /* SKU 32 - 39 */ - 0x00, - /* SKU 40 - 47 */ - 0x00, - /* SKU 48 - 55 */ - 0x00, - /* SKU 56 - 63 */ - 0x00, - /* SKU 64 - 71 */ - SKU_CONVERTIBLE(71), - /* SKU 72 - 79 */ - 0x00, - /* SKU 80 - 87 */ - 0x00, - /* SKU 88 - 95 */ - 0x00, - /* SKU 96 - 103 */ - 0x00, - /* SKU 104 - 111 */ - 0x00, - /* SKU 112 - 119 */ - 0x00, - /* SKU 120 - 127 */ - 0x00, - /* SKU 128 - 135 */ - 0x00, - /* SKU 136 - 143 */ - 0x00, - /* SKU 144 - 151 */ - 0x00, - /* SKU 152 - 159 */ - 0x00, - /* SKU 160 - 167 */ - SKU_CONVERTIBLE(163) | SKU_CONVERTIBLE(164) | SKU_CONVERTIBLE(165) | - SKU_CONVERTIBLE(166), - /* SKU 168 - 175 */ - 0x00, - /* SKU 176 - 183 */ - 0x00, - /* SKU 184 - 191 */ - 0x00, - /* SKU 192 - 199 */ - 0x00, - /* SKU 200 - 207 */ - 0x00, - /* SKU 208 - 215 */ - 0x00, - /* SKU 216 - 223 */ - 0x00, - /* SKU 224 - 231 */ - 0x00, - /* SKU 232 - 239 */ - 0x00, - /* SKU 240 - 247 */ - 0x00, - /* SKU 248 - 255 */ - 0x00, -}; - -#define SKU_IS_CONVERTIBLE(id) ((form_factor[(id) >> 3] >> ((id) & 0x7)) & 1) - -#endif /* __CROS_EC_SKU_H */ diff --git a/board/coral/usb_pd_policy.c b/board/coral/usb_pd_policy.c deleted file mode 100644 index e071f6ae2a..0000000000 --- a/board/coral/usb_pd_policy.c +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright 2016 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 "atomic.h" -#include "extpower.h" -#include "charge_manager.h" -#include "common.h" -#include "console.h" -#include "driver/charger/bd9995x.h" -#include "driver/tcpm/anx74xx.h" -#include "driver/tcpm/ps8xxx.h" -#include "gpio.h" -#include "hooks.h" -#include "host_command.h" -#include "registers.h" -#include "system.h" -#include "task.h" -#include "timer.h" -#include "util.h" -#include "usb_mux.h" -#include "usb_pd.h" -#include "usb_pd_tcpm.h" - -#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) -#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) - -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}; - -int board_vbus_source_enabled(int port) -{ - return vbus_en[port]; -} - -static void board_vbus_update_source_current(int port) -{ - enum gpio_signal gpio = port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN; - int flags = (vbus_rp[port] == TYPEC_RP_1A5 && vbus_en[port]) ? - (GPIO_INPUT | GPIO_PULL_UP) : (GPIO_OUTPUT | GPIO_PULL_UP); - - /* - * Driving USB_Cx_5V_EN high, actually put a 16.5k resistance - * (2x 33k in parallel) on the NX5P3290 load switch ILIM pin, - * setting a minimum OCP current of 3186 mA. - * Putting an internal pull-up on USB_Cx_5V_EN, effectively put a 33k - * resistor on ILIM, setting a minimum OCP current of 1505 mA. - */ - gpio_set_level(gpio, vbus_en[port]); - gpio_set_flags(gpio, flags); -} - -void typec_set_source_current_limit(int port, enum tcpc_rp_value rp) -{ - vbus_rp[port] = rp; - - /* change the GPIO driving the load switch if needed */ - board_vbus_update_source_current(port); -} - -int pd_set_power_supply_ready(int port) -{ - /* Ensure we're not charging from this port */ - bd9995x_select_input_port(port, 0); - - /* Ensure we advertise the proper available current quota */ - charge_manager_source_port(port, 1); - - pd_set_vbus_discharge(port, 0); - /* Provide VBUS */ - vbus_en[port] = 1; - board_vbus_update_source_current(port); - - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); - - return EC_SUCCESS; /* we are ready */ -} - -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); - - /* Give back the current quota we are no longer using */ - charge_manager_source_port(port, 0); - - /* notify host of power info change */ - pd_send_host_event(PD_EVENT_POWER_CHANGE); -} - -int pd_check_vconn_swap(int port) -{ - /* in G3, do not allow vconn swap since pp5000_A rail is off */ - return gpio_get_level(GPIO_EN_PP5000); -} diff --git a/board/coral/vif_override.xml b/board/coral/vif_override.xml deleted file mode 100644 index 32736caf64..0000000000 --- a/board/coral/vif_override.xml +++ /dev/null @@ -1,3 +0,0 @@ -<!-- Add VIF field overrides here. See genvif.c and the Vendor Info File - Definition from the USB-IF. ---> |