diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2017-03-10 09:45:35 +0100 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-03-27 10:57:15 -0700 |
commit | 891c48239b618ee2c33adff328bedb658b01d1b4 (patch) | |
tree | 75550b91fcfc4d897abc8bc4438ddc37f9da7fe4 | |
parent | 29e438184ff7ed178787ea69cbf5873b4956efc2 (diff) | |
download | chrome-ec-891c48239b618ee2c33adff328bedb658b01d1b4.tar.gz |
remove reef derivatives
The derivatives development should be done in the firmware branch.
(here it is firmware-reef-9042.B)
They are way too many 'follow reef settings' CLs, either all derivatives
should be updated at the same time or we have to cut the rotten fruits.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=b:36192920
TEST=make buildall
Change-Id: I20cbc4897c7e6e3355ca0a4ed0e856d6b1d17eff
Reviewed-on: https://chromium-review.googlesource.com/452459
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | board/pyro/battery.c | 312 | ||||
-rw-r--r-- | board/pyro/board.c | 1111 | ||||
-rw-r--r-- | board/pyro/board.h | 343 | ||||
-rw-r--r-- | board/pyro/build.mk | 14 | ||||
-rw-r--r-- | board/pyro/ec.tasklist | 39 | ||||
-rw-r--r-- | board/pyro/gpio.inc | 170 | ||||
-rw-r--r-- | board/pyro/led.c | 279 | ||||
-rw-r--r-- | board/pyro/usb_pd_policy.c | 420 | ||||
-rw-r--r-- | board/snappy/battery.c | 255 | ||||
-rw-r--r-- | board/snappy/board.c | 1140 | ||||
-rw-r--r-- | board/snappy/board.h | 336 | ||||
-rw-r--r-- | board/snappy/build.mk | 14 | ||||
-rw-r--r-- | board/snappy/ec.tasklist | 39 | ||||
-rw-r--r-- | board/snappy/gpio.inc | 167 | ||||
-rw-r--r-- | board/snappy/led.c | 187 | ||||
-rw-r--r-- | board/snappy/usb_pd_policy.c | 420 | ||||
-rwxr-xr-x | util/flash_ec | 6 |
17 files changed, 0 insertions, 5252 deletions
diff --git a/board/pyro/battery.c b/board/pyro/battery.c deleted file mode 100644 index 6d804d840d..0000000000 --- a/board/pyro/battery.c +++ /dev/null @@ -1,312 +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. - * - * 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 "console.h" -#include "ec_commands.h" -#include "extpower.h" -#include "gpio.h" -#include "hooks.h" -#include "host_command.h" -#include "system.h" -#include "i2c.h" -#include "util.h" - -/* FET ON/OFF cammand write to fet off register */ -#define SB_FET_OFF 0x34 -#define SB_FETOFF_DATA1 0x0000 -#define SB_FETOFF_DATA2 0x1000 -#define SB_FETON_DATA1 0x2000 -#define SB_FETON_DATA2 0x4000 -#define BATTERY_FETOFF 0x0100 - -/* First use day base */ -#define BATT_FUD_BASE 0x38 - -#define GREEN_BOOK_SUPPORT (1 << 2) - -/* Shutdown mode parameter to write to manufacturer access register */ -#define PARAM_CUT_OFF_LOW 0x10 -#define PARAM_CUT_OFF_HIGH 0x00 - -static enum battery_present batt_pres_prev = BP_NOT_SURE; - -/* Battery info for BQ40Z55 */ -static const struct battery_info info = { - /* FIXME(dhendrix): where do these values come from? */ - .voltage_max = 13050, /* mV */ - .voltage_normal = 11250, - .voltage_min = 9000, - .precharge_current = 200, /* 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 = 70, -}; - -static inline 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; -} - -const struct battery_info *battery_get_info(void) -{ - return &info; -} - -static void wakeup(void) -{ - int d; - int mode; - - /* Add Green Book support */ - if (sb_read(SB_BATTERY_MODE, &mode) == EC_RES_SUCCESS) { - mode |= GREEN_BOOK_SUPPORT; - sb_write(SB_BATTERY_MODE, mode); - } - - if (sb_read(SB_FET_OFF, &d) == EC_RES_SUCCESS) { - if (extpower_is_present() && (d == BATTERY_FETOFF)) { - sb_write(SB_FET_OFF, SB_FETON_DATA1); - sb_write(SB_FET_OFF, SB_FETON_DATA2); - } - } -} -DECLARE_HOOK(HOOK_INIT, wakeup, HOOK_PRIO_DEFAULT); - -static int cutoff(void) -{ - int rv; - - /* Ship mode command must be sent twice to take effect */ - rv = sb_write(SB_FET_OFF, SB_FETOFF_DATA1); - - if (rv != EC_SUCCESS) - return rv; - - return sb_write(SB_FET_OFF, SB_FETOFF_DATA2); -} - -int board_cut_off_battery(void) -{ - return cutoff(); -} - -int battery_get_vendor_param(uint32_t param, uint32_t *value) -{ - return EC_ERROR_UNIMPLEMENTED; -} - -/* parameter 0 for first use day */ -int battery_set_vendor_param(uint32_t param, uint32_t value) -{ - if (param == 0) { - int rv, ymd; - - rv = sb_read(BATT_FUD_BASE, &ymd); - if (rv != EC_SUCCESS) - return EC_ERROR_UNKNOWN; - if (ymd == 0) - return sb_write(BATT_FUD_BASE, value) ? - EC_ERROR_UNKNOWN : EC_SUCCESS; - - rv = sb_read(BATT_FUD_BASE | 0x03, &ymd); - if (rv != EC_SUCCESS) - return EC_ERROR_UNKNOWN; - if (ymd == 0) - return sb_write(BATT_FUD_BASE | 0x03, value) ? - EC_ERROR_UNKNOWN : EC_SUCCESS; - - rv = sb_read(BATT_FUD_BASE | 0x07, &ymd); - if (rv != EC_SUCCESS) - return EC_ERROR_UNKNOWN; - if (ymd == 0) - return sb_write(BATT_FUD_BASE | 0x07, value) ? - EC_ERROR_UNKNOWN : EC_SUCCESS; - - return EC_ERROR_UNKNOWN; - } else { - return EC_ERROR_UNIMPLEMENTED; - } -} - -enum battery_disconnect_state battery_get_disconnect_state(void) -{ - uint8_t data[6]; - int rv; - - /* - * Take note if we find that the battery isn't in disconnect state, - * and always return NOT_DISCONNECTED without probing the battery. - * This assumes the battery will not go to disconnect state during - * runtime. - */ - static int not_disconnected; - - if (not_disconnected) - return BATTERY_NOT_DISCONNECTED; - - if (extpower_is_present()) { - /* Check if battery charging + discharging is disabled. */ - rv = sb_read_mfgacc(PARAM_OPERATION_STATUS, - SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); - if (rv) - return BATTERY_DISCONNECT_ERROR; - if (~data[3] & (BATTERY_DISCHARGING_DISABLED | - BATTERY_CHARGING_DISABLED)) { - not_disconnected = 1; - return BATTERY_NOT_DISCONNECTED; - } - - /* - * Battery is neither charging nor discharging. Verify that - * we didn't enter this state due to a safety fault. - */ - rv = sb_read_mfgacc(PARAM_SAFETY_STATUS, - SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); - if (rv || data[2] || data[3] || data[4] || data[5]) - return BATTERY_DISCONNECT_ERROR; - - /* - * Battery is present and also the status is initialized and - * no safety fault, battery is disconnected. - */ - if (battery_is_present() == BP_YES) - return BATTERY_DISCONNECTED; - } - not_disconnected = 1; - return BATTERY_NOT_DISCONNECTED; -} - -#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE - -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; -} - -/* - * This can override the smart battery's charging profile. To make a change, - * modify one or more of requested_voltage, requested_current, or state. - * Leave everything else unchanged. - * - * Return the next poll period in usec, or zero to use the default (which is - * state dependent). - */ - -int charger_profile_override(struct charge_state_data *curr) -{ - int 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; -} - -/* Customs options controllable by host command. */ -#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0) - -enum ec_status charger_profile_override_get_param(uint32_t param, - uint32_t *value) -{ - return EC_RES_INVALID_PARAM; -} - -enum ec_status charger_profile_override_set_param(uint32_t param, - uint32_t value) -{ - return EC_RES_INVALID_PARAM; -} -#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */ - -/* - * Physical detection of battery. - */ -enum battery_present battery_is_present(void) -{ - enum battery_present batt_pres; - int batt_status, rv; - - /* 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. - * - * If battery I2C fails but VBATT is high, battery is booting from - * 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()) { - rv = battery_status(&batt_status); - if ((rv && bd9995x_get_battery_voltage() >= info.voltage_min) || - (!rv && !(batt_status & STATUS_INITIALIZED))) - batt_pres = BP_NO; - } - - batt_pres_prev = batt_pres; - - return batt_pres; -} - -int board_battery_initialized(void) -{ - return battery_hw_present() == batt_pres_prev; -} diff --git a/board/pyro/board.c b/board/pyro/board.c deleted file mode 100644 index f47159cb65..0000000000 --- a/board/pyro/board.c +++ /dev/null @@ -1,1111 +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. - */ - -/* Pyro board-specific configuration */ - -#include "adc.h" -#include "adc_chip.h" -#include "als.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_bmi160.h" -#include "driver/baro_bmp280.h" -#include "driver/charger/bd9995x.h" -#include "driver/tcpm/anx74xx.h" -#include "driver/tcpm/ps8751.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 "spi.h" -#include "switch.h" -#include "system.h" -#include "tablet_mode.h" -#include "task.h" -#include "temp_sensor.h" -#include "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 void tcpc_alert_event(enum gpio_signal signal) -{ - if ((signal == GPIO_USB_C0_PD_INT_ODL) && - !gpio_get_level(GPIO_USB_C0_PD_RST_L)) - return; - - if ((signal == GPIO_USB_C1_PD_INT_ODL) && - !gpio_get_level(GPIO_USB_C1_PD_RST_ODL)) - return; - -#ifdef HAS_TASK_PDCMD - /* Exchange status with TCPCs */ - host_command_pd_send_status(PD_CHARGE_NO_CHANGE); -#endif -} - -#ifdef CONFIG_USB_PD_TCPC_LOW_POWER -static void anx74xx_cable_det_handler(void) -{ - int level = gpio_get_level(GPIO_USB_C0_CABLE_DET); - - /* - * Setting the low power is handled by DRP status hence - * handle only the attach event. - */ - if (level) - anx74xx_handle_power_mode(USB_PD_PORT_ANX74XX, - ANX74XX_NORMAL_MODE); - - /* confirm if cable_det is asserted */ - if (!level || gpio_get_level(GPIO_USB_C0_PD_RST_L)) - return; - - task_set_event(TASK_ID_PD_C0, PD_EVENT_TCPC_RESET, 0); -} -DECLARE_DEFERRED(anx74xx_cable_det_handler); -DECLARE_HOOK(HOOK_CHIPSET_RESUME, anx74xx_cable_det_handler, HOOK_PRIO_LAST); - -void anx74xx_cable_det_interrupt(enum gpio_signal signal) -{ - /* debounce for 2ms */ - 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" - -/* power signal list. Must match order of enum power_signal. */ -const struct power_signal_info power_signal_list[] = { - {GPIO_RSMRST_L_PGOOD, 1, "RSMRST_L"}, - {GPIO_PCH_SLP_S3_L, 1, "SLP_S3_DEASSERTED"}, - {GPIO_PCH_SLP_S4_L, 1, "SLP_S4_DEASSERTED"}, - {GPIO_SUSPWRNACK, 1, "SUSPWRNACK_DEASSERTED"}, - - {GPIO_ALL_SYS_PGOOD, 1, "ALL_SYS_PGOOD"}, - {GPIO_PP3300_PG, 1, "PP3300_PG"}, - {GPIO_PP5000_PG, 1, "PP5000_PG"}, -}; -BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT); - -/* 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 - }, -}; -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_LED_RED] = {3, PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW, 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 = 0x50, - .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 = 0x16, - .i2c_test = &ps8751_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT1 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL - { - .port = I2C_PORT_GYRO, - .addr = BMI160_ADDR0, - .i2c_test = &bmi160_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT2 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL - { - .port = I2C_PORT_BARO, - .addr = BMP280_I2C_ADDRESS1, - .i2c_test = &bmp280_i2c_stress_test_dev, - }, - { - .port = I2C_PORT_LID_ACCEL, - .addr = KX022_ADDR1, - .i2c_test = &kionix_i2c_stress_test_dev, - }, -#endif -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ALS - { - .i2c_test = &opt3001_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_COUNT] = { - [USB_PD_PORT_ANX74XX] = { - .i2c_host_port = NPCX_I2C_PORT0_0, - .i2c_slave_addr = 0x50, - .drv = &anx74xx_tcpm_drv, - .pol = TCPC_ALERT_ACTIVE_LOW, - }, - [USB_PD_PORT_PS8751] = { - .i2c_host_port = NPCX_I2C_PORT0_1, - .i2c_slave_addr = 0x16, - .drv = &tcpci_tcpm_drv, - .pol = TCPC_ALERT_ACTIVE_LOW, - }, -}; - -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); - -struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { - { - .port_addr = USB_PD_PORT_ANX74XX, /* don't care / unused */ - .driver = &anx74xx_tcpm_usb_mux_driver, - .hpd_update = &anx74xx_tcpc_update_hpd_status, - }, - { - .port_addr = USB_PD_PORT_PS8751, - .driver = &tcpci_tcpm_usb_mux_driver, - .hpd_update = &ps8751_tcpc_update_hpd_status, - } -}; - -/* called from anx74xx_set_power_mode() */ -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(10); - 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(1); - gpio_set_level(GPIO_EN_USB_TCPC_PWR, 0); - break; - default: - break; - } -} - -/** - * Reset PD MCU -- 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 */ - gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0); - - /* Assert reset to TCPC0 */ - board_set_tcpc_power_mode(0, 0); - - /* Deassert reset to TCPC1 */ - gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1); - - /* TCPC0 requires 10ms reset/power down assertion */ - msleep(10); - - /* Deassert reset to TCPC0 */ - board_set_tcpc_power_mode(0, 1); -} - -void board_tcpc_init(void) -{ - int port, reg; - - /* Only reset TCPC if not sysjump */ - if (!system_jumped_to_this_image()) - board_reset_pd_mcu(); - - /* - * 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, 0x10, 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 (port = 0; port < CONFIG_USB_PD_PORT_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); - -/* - * Data derived from Seinhart-Hart equation in a resistor divider circuit with - * Vdd=3300mV, R = 13.7Kohm, and Murata NCP15WB-series thermistor (B = 4050, - * T0 = 298.15, nominal resistance (R0) = 47Kohm). - */ -#define CHARGER_THERMISTOR_SCALING_FACTOR 13 -static const struct thermistor_data_pair charger_thermistor_data[] = { - { 3044 / CHARGER_THERMISTOR_SCALING_FACTOR, 0 }, - { 2890 / CHARGER_THERMISTOR_SCALING_FACTOR, 10 }, - { 2680 / CHARGER_THERMISTOR_SCALING_FACTOR, 20 }, - { 2418 / CHARGER_THERMISTOR_SCALING_FACTOR, 30 }, - { 2117 / CHARGER_THERMISTOR_SCALING_FACTOR, 40 }, - { 1800 / CHARGER_THERMISTOR_SCALING_FACTOR, 50 }, - { 1490 / CHARGER_THERMISTOR_SCALING_FACTOR, 60 }, - { 1208 / CHARGER_THERMISTOR_SCALING_FACTOR, 70 }, - { 966 / CHARGER_THERMISTOR_SCALING_FACTOR, 80 }, - { 860 / CHARGER_THERMISTOR_SCALING_FACTOR, 85 }, - { 766 / CHARGER_THERMISTOR_SCALING_FACTOR, 90 }, - { 679 / CHARGER_THERMISTOR_SCALING_FACTOR, 95 }, - { 603 / CHARGER_THERMISTOR_SCALING_FACTOR, 100 }, -}; - -static const struct thermistor_info charger_thermistor_info = { - .scaling_factor = CHARGER_THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(charger_thermistor_data), - .data = charger_thermistor_data, -}; - -int board_get_charger_temp(int idx, int *temp_ptr) -{ - int mv = adc_read_channel(NPCX_ADC_CH0); - - if (mv < 0) - return -1; - - *temp_ptr = thermistor_linear_interpolate(mv, &charger_thermistor_info); - *temp_ptr = C_TO_K(*temp_ptr); - return 0; -} - -/* - * Data derived from Seinhart-Hart equation in a resistor divider circuit with - * Vdd=3300mV, R = 51.1Kohm, and Murata NCP15WB-series thermistor (B = 4050, - * T0 = 298.15, nominal resistance (R0) = 47Kohm). - */ -#define AMB_THERMISTOR_SCALING_FACTOR 11 -static const struct thermistor_data_pair amb_thermistor_data[] = { - { 2512 / AMB_THERMISTOR_SCALING_FACTOR, 0 }, - { 2158 / AMB_THERMISTOR_SCALING_FACTOR, 10 }, - { 1772 / AMB_THERMISTOR_SCALING_FACTOR, 20 }, - { 1398 / AMB_THERMISTOR_SCALING_FACTOR, 30 }, - { 1070 / AMB_THERMISTOR_SCALING_FACTOR, 40 }, - { 803 / AMB_THERMISTOR_SCALING_FACTOR, 50 }, - { 597 / AMB_THERMISTOR_SCALING_FACTOR, 60 }, - { 443 / AMB_THERMISTOR_SCALING_FACTOR, 70 }, - { 329 / AMB_THERMISTOR_SCALING_FACTOR, 80 }, - { 285 / AMB_THERMISTOR_SCALING_FACTOR, 85 }, - { 247 / AMB_THERMISTOR_SCALING_FACTOR, 90 }, - { 214 / AMB_THERMISTOR_SCALING_FACTOR, 95 }, - { 187 / AMB_THERMISTOR_SCALING_FACTOR, 100 }, -}; - -static const struct thermistor_info amb_thermistor_info = { - .scaling_factor = AMB_THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(amb_thermistor_data), - .data = amb_thermistor_data, -}; - -int board_get_ambient_temp(int idx, int *temp_ptr) -{ - int mv = adc_read_channel(NPCX_ADC_CH1); - - if (mv < 0) - return -1; - - *temp_ptr = thermistor_linear_interpolate(mv, &amb_thermistor_info); - *temp_ptr = C_TO_K(*temp_ptr); - return 0; -} - - -const struct temp_sensor_t temp_sensors[] = { - /* FIXME(dhendrix): tweak action_delay_sec */ - {"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_get_battery_temp, 0, 1}, - {"Ambient", TEMP_SENSOR_TYPE_BOARD, board_get_ambient_temp, 0, 5}, - {"Charger", TEMP_SENSOR_TYPE_BOARD, board_get_charger_temp, 1, 1}, -}; -BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); - -/* ALS instances. Must be in same order as enum als_id. */ -struct als_t als[] = { - /* FIXME(dhendrix): verify attenuation_factor */ - {"TI", opt3001_init, opt3001_read_lux, 5}, -}; -BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); - -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_EC_VOLDN_BTN_ODL, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_EC_VOLUP_BTN_ODL, - 30 * MSEC, 0}, -}; - -/* Called by APL power state machine when transitioning from G3 to S5 */ -static void chipset_pre_init(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); -} -DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, chipset_pre_init, HOOK_PRIO_DEFAULT); - -static void board_set_tablet_mode(void) -{ - tablet_set_mode(!gpio_get_level(GPIO_TABLET_MODE_L)); -} - -/* 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); -} -/* 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) -{ - enum bd9995x_charge_port bd9995x_port; - - switch (port) { - case USB_PD_PORT_ANX74XX: - case USB_PD_PORT_PS8751: - bd9995x_port = bd9995x_pd_port_to_chg_port(port); - break; - default: - panic("Invalid charge port\n"); - break; - } - - return bd9995x_is_vbus_provided(bd9995x_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; - static int initialized; - - /* - * Reject charge port disable if our battery is critical and we - * have yet to initialize a charge port - continue to charge using - * charger ROM / POR settings. - */ - if (!initialized && - charge_port == CHARGE_PORT_NONE && - charge_get_percent() < 2) - return -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 = bd9995x_pd_port_to_chg_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); - initialized = 1; - - 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 whether ramping is allowed for given supplier - */ -int board_is_ramp_allowed(int supplier) -{ - /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) - return 0; - else - return (supplier == CHARGE_SUPPLIER_BC12_DCP || - supplier == CHARGE_SUPPLIER_BC12_SDP || - supplier == CHARGE_SUPPLIER_BC12_CDP || - supplier == CHARGE_SUPPLIER_OTHER); -} - -/** - * Return the maximum allowed input current - */ -int board_get_ramp_current_limit(int supplier, int sup_curr) -{ - return bd9995x_get_bc12_ilim(supplier); -} - -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - -/** - * Return if VBUS is sagging too low - */ -int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) -{ - return charger_get_vbus_voltage(port) < 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 */ -#ifndef TEST_BUILD -void lid_angle_peripheral_enable(int enable) -{ - /* - * If the lid is in 360 position, ignore the lid angle, - * which might be faulty. Disable keyboard and touchpad. - */ - if (tablet_get_mode() || chipset_in_state(CHIPSET_STATE_ANY_OFF)) - enable = 0; - keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE); -} -#endif - -/* 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? - */ - -/* - * FIXME(dhendrix): Weak symbol hack until we can get a better solution for - * both Amenia and Pyro. - */ -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_GREEN, GPIO_INPUT | GPIO_PULL_DOWN}, - {GPIO_BAT_LED_AMBER, GPIO_INPUT | GPIO_PULL_DOWN}, - {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); - gpio_config_module(MODULE_PWM, 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 matrix_3x3_t base_standard_ref = { - { 0, FLOAT_TO_FP(-1), 0}, - { FLOAT_TO_FP(1), 0, 0}, - { 0, 0, FLOAT_TO_FP(1)} -}; - -const matrix_3x3_t lid_standard_ref = { - { FLOAT_TO_FP(-1), 0, 0}, - { 0, FLOAT_TO_FP(-1), 0}, - { 0, 0, FLOAT_TO_FP(1)} -}; - -struct kionix_accel_data g_kx022_data; -struct bmi160_drv_data_t g_bmi160_data; -struct bmp280_drv_data_t bmp280_drv_data; - -/* FIXME(dhendrix): Copied from Amenia, probably need to tweak for Pyro */ -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, - .addr = KX022_ADDR1, - .rot_standard_ref = &lid_standard_ref, /* Identity matrix. */ - .default_range = 2, /* g, enough for laptop. */ - .config = { - /* AP: by default use EC settings */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* unused */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, - - [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, - .addr = BMI160_ADDR0, - .rot_standard_ref = &base_standard_ref, - .default_range = 2, /* g, enough for laptop. */ - .config = { - /* AP: by default use EC settings */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0 - }, - }, - }, - - [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, - .addr = BMI160_ADDR0, - .default_range = 1000, /* dps */ - .rot_standard_ref = &base_standard_ref, - .config = { - /* AP: by default shutdown all sensors */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC does not need in S0 */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, - - [BASE_MAG] = { - .name = "Base Mag", - .active_mask = SENSOR_ACTIVE_S0, - .chip = MOTIONSENSE_CHIP_BMI160, - .type = MOTIONSENSE_TYPE_MAG, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, - .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, - .port = I2C_PORT_GYRO, - .addr = BMI160_ADDR0, - .default_range = 1 << 11, /* 16LSB / uT, fixed */ - .rot_standard_ref = NULL, - .config = { - /* AP: by default shutdown all sensors */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC does not need in S0 */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, - - [BASE_BARO] = { - .name = "Base Baro", - .active_mask = SENSOR_ACTIVE_S0, - .chip = MOTIONSENSE_CHIP_BMP280, - .type = MOTIONSENSE_TYPE_BARO, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmp280_drv, - .drv_data = &bmp280_drv_data, - .port = I2C_PORT_BARO, - .addr = BMP280_I2C_ADDRESS1, - .default_range = 1 << 18, /* 1bit = 4 Pa, 16bit ~= 2600 hPa */ - .config = { - /* AP: by default shutdown all sensors */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC does not need in S0 */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, -}; -const 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); -} - -struct { - enum pyro_board_version version; - int thresh_mv; -} const pyro_board_versions[] = { - /* Vin = 3.3V, R1 = 46.4K, R2 values listed below */ - { BOARD_VERSION_1, 328 * 1.03 }, /* 5.11 Kohm */ - { BOARD_VERSION_2, 670 * 1.03 }, /* 11.8 Kohm */ - { BOARD_VERSION_3, 1012 * 1.03 }, /* 20.5 Kohm */ - { BOARD_VERSION_4, 1357 * 1.03 }, /* 32.4 Kohm */ - { BOARD_VERSION_5, 1690 * 1.03 }, /* 48.7 Kohm */ - { BOARD_VERSION_6, 2020 * 1.03 }, /* 73.2 Kohm */ - { BOARD_VERSION_7, 2352 * 1.03 }, /* 115 Kohm */ - { BOARD_VERSION_8, 2802 * 1.03 }, /* 261 Kohm */ -}; -BUILD_ASSERT(ARRAY_SIZE(pyro_board_versions) == BOARD_VERSION_COUNT); - -int board_get_version(void) -{ - static int version = BOARD_VERSION_UNKNOWN; - int mv, i; - - if (version != BOARD_VERSION_UNKNOWN) - return version; - - /* FIXME(dhendrix): enable ADC */ - gpio_set_flags(GPIO_EC_BRD_ID_EN_ODL, GPIO_ODR_HIGH); - gpio_set_level(GPIO_EC_BRD_ID_EN_ODL, 0); - /* Wait to allow cap charge */ - msleep(1); - mv = adc_read_channel(ADC_BOARD_ID); - /* FIXME(dhendrix): disable ADC */ - gpio_set_level(GPIO_EC_BRD_ID_EN_ODL, 1); - gpio_set_flags(GPIO_EC_BRD_ID_EN_ODL, GPIO_INPUT); - - if (mv == ADC_READ_ERROR) { - version = BOARD_VERSION_UNKNOWN; - return version; - } - - for (i = 0; i < BOARD_VERSION_COUNT; i++) { - if (mv < pyro_board_versions[i].thresh_mv) { - version = pyro_board_versions[i].version; - break; - } - } - - CPRINTS("Board version: %d", version); - return version; -} - -/* Keyboard scan setting */ -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 */ - }, -}; - -#ifdef CONFIG_KEYBOARD_FACTORY_TEST -/* - * We have total 32 pins for keyboard connecter, {-1, -1} mean - * the N/A pin that don't consider it and reserve index 0 area - * that we don't have pin 0. - */ -const int keyboard_factory_scan_pins[][2] = { - {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, - {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {0, 5}, - {1, 1}, {1, 0}, {0, 6}, {0, 7}, {-1, -1}, - {-1, -1}, {1, 4}, {1, 3}, {-1, -1}, {1, 6}, - {-1, -1}, {3, 1}, {2, 0}, {1, 5}, {2, 6}, - {-1, -1}, {2, 1}, {2, 4}, {2, 5}, {1, 2}, - {2, 3}, {2, 2}, {3, 0}, -}; - -const int keyboard_factory_scan_pins_used = - ARRAY_SIZE(keyboard_factory_scan_pins); -#endif diff --git a/board/pyro/board.h b/board/pyro/board.h deleted file mode 100644 index 3aa7d6002a..0000000000 --- a/board/pyro/board.h +++ /dev/null @@ -1,343 +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. - */ - -/* Pyro board configuration */ - -#ifndef __CROS_EC_BOARD_H -#define __CROS_EC_BOARD_H - -/* - * By default, enable all console messages excepted HC, ACPI and event: - * The sensor stack is generating a lot of activity. - */ -#define CC_DEFAULT (CC_ALL & ~(CC_MASK(CC_EVENTS) | CC_MASK(CC_LPC))) -#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_CMD_CHARGER_PSYS -#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 - -/* Battery */ -#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION" -#define CONFIG_BATTERY_CUT_OFF -#define CONFIG_BATTERY_PRESENT_CUSTOM -#define CONFIG_BATTERY_REVIVE_DISCONNECT -#define CONFIG_BATTERY_SMART -#define CONFIG_BATTERY_VENDOR_PARAM - -/* battery firmware update */ -#define CONFIG_CRC8 -#define CONFIG_SB_FIRMWARE_UPDATE -#define CONFIG_SMBUS - -/* Charger */ -#define CONFIG_CHARGE_MANAGER -#define CONFIG_CHARGE_RAMP -#define CONFIG_CHARGER -#define CONFIG_CHARGER_V2 -#define CONFIG_CHARGER_BD99956 -#define CONFIG_CHARGER_BD9995X_CHGEN -#define CONFIG_CHARGER_DISCHARGE_ON_AC -#define CONFIG_CHARGER_INPUT_CURRENT 512 -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1 -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 18000 -#define CONFIG_CHARGER_MAINTAIN_VBAT -#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1 -#define CONFIG_CHARGER_PROFILE_OVERRIDE -#define CONFIG_USB_CHARGER -#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_USB_ILIM_SEL GPIO_USB_A_CHARGE_EN_L -#define GPIO_USB_CTL1 GPIO_EN_PP5000 - -#define CONFIG_TABLET_MODE - -/* USB PD config */ -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL -#define CONFIG_CMD_PD_CONTROL -#define CONFIG_USB_PD_ALT_MODE -#define CONFIG_USB_PD_ALT_MODE_DFP -#define CONFIG_USB_PD_CUSTOM_VDM -#define CONFIG_USB_PD_DUAL_ROLE -#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#define CONFIG_USB_PD_DISCHARGE -#define CONFIG_USB_PD_DISCHARGE_TCPC -#define CONFIG_USB_PD_LOGGING -#define CONFIG_USB_PD_LOG_SIZE 512 -#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 -#define CONFIG_USB_PD_PORT_COUNT 2 -#define CONFIG_USB_PD_QUIRK_SLOW_CC_STATUS -#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_ANX74XX -#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_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_LPC -#define CONFIG_CHIPSET_APOLLOLAKE -#define CONFIG_CHIPSET_RESET_HOOK -#undef CONFIG_PECI -#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_BOARD_VERSION -#define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 -#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_MASTER -#define CONFIG_KEYBOARD_BOARD_CONFIG -#define CONFIG_KEYBOARD_PROTOCOL_8042 -#define CONFIG_KEYBOARD_COL2_INVERTED -#define CONFIG_KEYBOARD_FACTORY_TEST -#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_TEMP_SENSOR -#define CONFIG_THERMISTOR_NCP15WB -#define CONFIG_DPTF -#define CONFIG_SCI_GPIO GPIO_PCH_SCI_L -#define CONFIG_UART_HOST 0 -#define CONFIG_VBOOT_HASH -#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 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 Pyro. Do we need - * to change some other setting to put them in GPIO mode? - */ -#define NPCX_TACH_SEL2 0 /* 0:GPIO40/A4 1:GPIO93/D3 as TACH */ - -/* I2C ports */ -#define I2C_PORT_GYRO NPCX_I2C_PORT1 -#define I2C_PORT_LID_ACCEL NPCX_I2C_PORT2 -#define I2C_PORT_ALS NPCX_I2C_PORT2 -#define I2C_PORT_BARO 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_CUSTOM(4) -#define CONFIG_MAG_BMI160_BMM150 -#define BMM150_I2C_ADDRESS BMM150_ADDR0 /* 8-bit address */ -#define CONFIG_MAG_CALIBRATE -#define CONFIG_ACCEL_KX022 -#define CONFIG_ALS_OPT3001 -#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 -#define CONFIG_BARO_BMP280 -#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 - -/* FIFO size is in power of 2. */ -#define CONFIG_ACCEL_FIFO 1024 - -/* Depends on how fast the AP boots and typical ODRs */ -#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 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_CH_COUNT -}; - -enum pwm_channel { - PWM_CH_LED_RED, - /* Number of PWM channels */ - PWM_CH_COUNT -}; - -enum power_signal { - X86_RSMRST_N = 0, - X86_SLP_S3_N, - X86_SLP_S4_N, - X86_SUSPWRDNACK, - - X86_ALL_SYS_PG, /* PMIC_EC_PWROK_OD */ - X86_PGOOD_PP3300, /* GPIO_PP3300_PG */ - X86_PGOOD_PP5000, /* GPIO_PP5000_PG */ - - /* Number of X86 signals */ - POWER_SIGNAL_COUNT -}; - -enum temp_sensor_id { - TEMP_SENSOR_BATTERY = 0, - TEMP_SENSOR_AMBIENT, - TEMP_SENSOR_CHARGER, - TEMP_SENSOR_COUNT -}; - -/* Light sensors */ -enum als_id { - ALS_OPT3001 = 0, - - ALS_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 = 0, - BASE_ACCEL, - BASE_GYRO, - BASE_MAG, - BASE_BARO, -}; - -enum pyro_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_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 PD_VCONN_SWAP_DELAY 5000 /* us */ - -/* 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 - -/* The higher the input voltage, the higher the power efficiency. */ -#define PD_PREFER_HIGH_VOLTAGE - -#ifdef CONFIG_KEYBOARD_FACTORY_TEST -extern const int keyboard_factory_scan_pins[][2]; -extern const int keyboard_factory_scan_pins_used; -#endif - -/* Reset PD MCU */ -void board_reset_pd_mcu(void); - -int board_get_version(void); - -void board_set_tcpc_power_mode(int port, int mode); -void board_print_tcpc_fw_version(int port); - -/* Sensors without hardware FIFO are in forced mode */ -#define CONFIG_ACCEL_FORCE_MODE_MASK \ - ((1 << LID_ACCEL) | (1 << BASE_BARO)) - -#endif /* !__ASSEMBLER__ */ - -#endif /* __CROS_EC_BOARD_H */ diff --git a/board/pyro/build.mk b/board/pyro/build.mk deleted file mode 100644 index 728d027803..0000000000 --- a/board/pyro/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/pyro/ec.tasklist b/board/pyro/ec.tasklist deleted file mode 100644 index 47e0048872..0000000000 --- a/board/pyro/ec.tasklist +++ /dev/null @@ -1,39 +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. - */ - -/* - * List of enabled tasks in the priority order - * - * The first one has the lowest priority. - * - * For each task, use the macro TASK_ALWAYS(n, r, d, s) for base tasks and - * TASK_NOTEST(n, r, d, s) for tasks that can be excluded in test binaries, - * where : - * 'n' in the name of the task - * 'r' in the main routine of the task - * 'd' in an opaque parameter passed to the routine at startup - * 's' is the stack size in bytes; must be a multiple of 8 - * - * For USB PD tasks, IDs must be in consecutive order and correspond to - * the port which they are for. See TASK_ID_TO_PD_PORT() macro. - */ - -#define CONFIG_TASK_LIST \ - TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(ALS, als_task, NULL, 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_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \ - TASK_ALWAYS(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) - diff --git a/board/pyro/gpio.inc b/board/pyro/gpio.inc deleted file mode 100644 index 5e8ce38343..0000000000 --- a/board/pyro/gpio.inc +++ /dev/null @@ -1,170 +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 */ - -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(SUSPWRNACK, 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, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) -GPIO_INT(EC_VOLUP_BTN_ODL, PIN(8, 2), 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_SPS 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 */ -GPIO(PCH_SLP_S0_L, PIN(7, 5), GPIO_INPUT) /* SLP_S0_L */ - -/* - * BRD_ID1 is a an ADC pin which will be used to measure multiple values. - * Assert EC_BRD_ID_EN_ODL and then read BRD_ID1. - */ -ALTERNATE(PIN_MASK(4, 0x08), 1, MODULE_ADC, 0) -GPIO(EC_BRD_ID_EN_ODL, PIN(3, 5), GPIO_INPUT) - -GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) -GPIO(EC_HAVEN_RESET_ODL, PIN(0, 2), GPIO_ODR_HIGH) -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(PCH_RCIN_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(4, 2), GPIO_OUT_LOW) -GPIO(EN_USB_TCPC_PWR, PIN(C, 3), GPIO_OUT_LOW) -GPIO(USB1_ENABLE, PIN(4, 1), 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_LOW) -/* - * 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 */ - -/* Clear for non-HDI breakout, must be pulled high */ -GPIO(NC1, PIN(0, 0), GPIO_INPUT | GPIO_PULL_UP | GPIO_SEL_1P8V) - -GPIO(ENG_STRAP, PIN(B, 6), GPIO_INPUT) - -GPIO(BAT_LED_GREEN, PIN(8, 4), GPIO_OUT_HIGH) -GPIO(BAT_LED_AMBER, PIN(C, 4), 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) - -ALTERNATE(PIN(4, 4), 6, MODULE_ADC, 0) /* TEMP_SENSOR_AMB (FIXME: alt function 6?) */ -ALTERNATE(PIN(4, 5), 6, MODULE_ADC, 0) /* TEMP_SENSOR_CHARGER (FIXME: alt function?) */ - -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 */ - -/* FIXME: Make UART RX an interrupt? */ -ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */ - -/* LED PWM */ -ALTERNATE(PIN_MASK(8, 0x01), 1, MODULE_PWM, GPIO_OUTPUT) /* GPIO80: PWM3 */ diff --git a/board/pyro/led.c b/board/pyro/led.c deleted file mode 100644 index 18cb8c7201..0000000000 --- a/board/pyro/led.c +++ /dev/null @@ -1,279 +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 Pyro - */ - -#include "battery.h" -#include "charge_state.h" -#include "chipset.h" -#include "console.h" -#include "ec_commands.h" -#include "extpower.h" -#include "gpio.h" -#include "hooks.h" -#include "host_command.h" -#include "led_common.h" -#include "pwm.h" -#include "util.h" - -#define CPRINTF(format, args...) cprintf(CC_PWM, format, ## args) -#define CPRINTS(format, args...) cprints(CC_PWM, format, ## args) - -#define BAT_LED_ON 1 -#define BAT_LED_OFF 0 - -#define CRITICAL_LOW_BATTERY_PERCENTAGE 3 -#define LOW_BATTERY_PERCENTAGE 10 - -#define LED_TOTAL_TICKS 2 -#define LED_ON_TICKS 1 - -#define TICKS_STEP1_BRIGHTER 0 -#define TICKS_STEP2_DIMMER 20 -#define TICKS_STEP3_OFF 40 - -#define FULL_BATTERY_PERMILLAGE 875 - -static int led_debug; -static int ticks; - -const enum ec_led_id supported_led_ids[] = { - EC_LED_ID_POWER_LED, EC_LED_ID_BATTERY_LED}; - -const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); - -enum led_color { - LED_OFF = 0, - LED_RED, - LED_GREEN, - LED_AMBER, - LED_COLOR_COUNT /* Number of colors, not a color itself */ -}; - -static int led_set_color_battery(enum led_color color) -{ - switch (color) { - case LED_OFF: - gpio_set_level(GPIO_BAT_LED_GREEN, BAT_LED_OFF); - gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_OFF); - break; - case LED_GREEN: - gpio_set_level(GPIO_BAT_LED_GREEN, BAT_LED_ON); - gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_OFF); - break; - case LED_AMBER: - gpio_set_level(GPIO_BAT_LED_GREEN, BAT_LED_OFF); - gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_ON); - break; - default: - return EC_ERROR_UNKNOWN; - } - return EC_SUCCESS; -} - -/* Brightness vs. color, in the order of off, red */ -static const uint8_t color_brightness[2] = { - [LED_OFF] = 0, - [LED_RED] = 100, -}; - -static void led_set_color_power(enum led_color color) -{ - pwm_set_duty(PWM_CH_LED_RED, color_brightness[color]); -} - -void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) -{ - brightness_range[EC_LED_COLOR_RED] = 100; - brightness_range[EC_LED_COLOR_GREEN] = 1; - brightness_range[EC_LED_COLOR_AMBER] = 1; -} - -int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) -{ - switch (led_id) { - case EC_LED_ID_BATTERY_LED: - if (brightness[EC_LED_COLOR_GREEN] != 0) - led_set_color_battery(LED_GREEN); - else if (brightness[EC_LED_COLOR_AMBER] != 0) - led_set_color_battery(LED_AMBER); - else - led_set_color_battery(LED_OFF); - break; - case EC_LED_ID_POWER_LED: - if (brightness[EC_LED_COLOR_RED] != 0) - pwm_set_duty(PWM_CH_LED_RED, color_brightness[LED_RED]); - else - pwm_set_duty(PWM_CH_LED_RED, color_brightness[LED_OFF]); - break; - default: - break; - } - return EC_SUCCESS; -} - -static void led_set_battery(void) -{ - static int battery_ticks; - int remaining_capacity; - int full_charge_capacity; - int permillage; - - battery_ticks++; - - remaining_capacity = *(int *)host_get_memmap(EC_MEMMAP_BATT_CAP); - full_charge_capacity = *(int *)host_get_memmap(EC_MEMMAP_BATT_LFCC); - permillage = !full_charge_capacity ? 0 : - (1000 * remaining_capacity) / full_charge_capacity; - - switch (charge_get_state()) { - case PWR_STATE_CHARGE: - led_set_color_battery(permillage < - FULL_BATTERY_PERMILLAGE ? LED_AMBER : LED_GREEN); - break; - case PWR_STATE_DISCHARGE_FULL: - if (extpower_is_present()) { - led_set_color_battery(LED_GREEN); - break; - } - /* Intentional fall-through */ - case PWR_STATE_DISCHARGE: - led_set_color_battery(LED_OFF); - break; - case PWR_STATE_CHARGE_NEAR_FULL: - led_set_color_battery(LED_GREEN); - break; - default: - /* Other states don't alter LED behavior */ - led_set_color_battery(LED_OFF); - break; - } -} - -static void suspend_led_update_deferred(void); -DECLARE_DEFERRED(suspend_led_update_deferred); - -static void suspend_led_update_deferred(void) -{ - int delay = 50 * MSEC; - - ticks++; - - /* 1s gradual on, 1s gradual off, 3s off */ - if (ticks <= TICKS_STEP2_DIMMER) { - pwm_set_duty(PWM_CH_LED_RED, ticks*5); - } else if (ticks <= TICKS_STEP3_OFF) { - pwm_set_duty(PWM_CH_LED_RED, (TICKS_STEP3_OFF - ticks)*5); - } else { - ticks = TICKS_STEP1_BRIGHTER; - delay = 3000 * MSEC; - } - - hook_call_deferred(&suspend_led_update_deferred_data, delay); -} - -static void suspend_led_init(void) -{ - ticks = TICKS_STEP2_DIMMER; - - hook_call_deferred(&suspend_led_update_deferred_data, 0); -} -DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, suspend_led_init, HOOK_PRIO_DEFAULT); - -static void suspend_led_deinit(void) -{ - hook_call_deferred(&suspend_led_update_deferred_data, -1); -} -DECLARE_HOOK(HOOK_CHIPSET_RESUME, suspend_led_deinit, HOOK_PRIO_DEFAULT); -DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, suspend_led_deinit, HOOK_PRIO_DEFAULT); - -static void led_set_power(void) -{ - static int power_ticks; - static int previous_state_suspend; - static int blink_ticks; - - power_ticks++; - - /* Blink 3 times (0.25s on/0.25s off, repeat 3 times) */ - if (extpower_is_present()) { - blink_ticks++; - if (!previous_state_suspend) - power_ticks = 0; - - while (blink_ticks < 7) { - led_set_color_power( - (power_ticks % LED_TOTAL_TICKS) < LED_ON_TICKS ? - LED_RED : LED_OFF); - - previous_state_suspend = 1; - return; - } - } - if (!extpower_is_present()) - blink_ticks = 0; - - previous_state_suspend = 0; - - if (chipset_in_state(CHIPSET_STATE_SOFT_OFF)) - led_set_color_power(LED_OFF); - if (chipset_in_state(CHIPSET_STATE_ON)) - led_set_color_power(LED_RED); -} - -static void led_init(void) -{ - /* Configure GPIOs */ - gpio_config_module(MODULE_PWM, 1); - - /* - * Enable PWMs and set to 0% duty cycle. If they're disabled, - * seems to ground the pins instead of letting them float. - */ - pwm_enable(PWM_CH_LED_RED, 1); - - led_set_color_power(LED_OFF); -} -DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); - -/* Called by hook task every 25 ms */ -static void led_tick(void) -{ - if (led_debug) - return; - - if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) - led_set_battery(); - if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - led_set_power(); -} -DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); - -/******************************************************************/ -/* Console commands */ -static int command_led_color(int argc, char **argv) -{ - if (argc > 1) { - if (!strcasecmp(argv[1], "debug")) { - led_debug ^= 1; - CPRINTF("led_debug = %d\n", led_debug); - } else if (!strcasecmp(argv[1], "off")) { - led_set_color_power(LED_OFF); - led_set_color_battery(LED_OFF); - } else if (!strcasecmp(argv[1], "red")) { - led_set_color_power(LED_RED); - } else if (!strcasecmp(argv[1], "green")) { - led_set_color_battery(LED_GREEN); - } else if (!strcasecmp(argv[1], "amber")) { - led_set_color_battery(LED_AMBER); - } else { - return EC_ERROR_PARAM1; - } - } - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(ledcolor, command_led_color, - "[debug|red|green|amber|off]", - "Change LED color"); diff --git a/board/pyro/usb_pd_policy.c b/board/pyro/usb_pd_policy.c deleted file mode 100644 index 3a77eb6cad..0000000000 --- a/board/pyro/usb_pd_policy.c +++ /dev/null @@ -1,420 +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/ps8751.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) - -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - -/* TODO: 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_is_valid_input_voltage(int mv) -{ - return 1; -} - -void pd_transition_voltage(int idx) -{ - /* No-operation: we are always 5V */ -} - -static uint8_t vbus_en[CONFIG_USB_PD_PORT_COUNT]; -static uint8_t vbus_rp[CONFIG_USB_PD_PORT_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, int 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(bd9995x_pd_port_to_chg_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); -} - -void pd_set_input_current_limit(int port, uint32_t max_ma, - uint32_t supply_voltage) -{ -#ifdef CONFIG_CHARGE_MANAGER - struct charge_port_info charge; - - charge.current = max_ma; - charge.voltage = supply_voltage; - charge_manager_update_charge(CHARGE_SUPPLIER_PD, port, &charge); -#endif -} - -void typec_set_input_current_limit(int port, uint32_t max_ma, - uint32_t supply_voltage) -{ -#ifdef CONFIG_CHARGE_MANAGER - struct charge_port_info charge; - - charge.current = max_ma; - charge.voltage = supply_voltage; - charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, port, &charge); -#endif -} - -int pd_board_checks(void) -{ - return EC_SUCCESS; -} - -int pd_check_power_swap(int port) -{ - /* - * Allow power swap as long as we are acting as a dual role device, - * otherwise assume our role is fixed (not in S0 or console command - * to fix our role). - */ - return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; -} - -int pd_check_data_swap(int port, int data_role) -{ - /* Allow data swap if we are a UFP, otherwise don't allow */ - return (data_role == PD_ROLE_UFP) ? 1 : 0; -} - -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); -} - -void pd_execute_data_swap(int port, int data_role) -{ - /* Do nothing */ -} - -void pd_check_pr_role(int port, int pr_role, int flags) -{ - /* - * If partner is dual-role power and dualrole toggling is on, consider - * if a power swap is necessary. - */ - if ((flags & PD_FLAGS_PARTNER_DR_POWER) && - pd_get_dual_role() == PD_DRP_TOGGLE_ON) { - /* - * If we are a sink and partner is not externally powered, then - * swap to become a source. If we are source and partner is - * externally powered, swap to become a sink. - */ - int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; - - if ((!partner_extpower && pr_role == PD_ROLE_SINK) || - (partner_extpower && pr_role == PD_ROLE_SOURCE)) - pd_request_power_swap(port); - } -} - -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) - pd_request_data_swap(port); -} -/* ----------------- 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; - - /* 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]); - - CPRINTF("DevId:%d.%d SW:%d RW:%d\n", - HW_DEV_ID_MAJ(dev_id), - HW_DEV_ID_MIN(dev_id), - VDO_INFO_SW_DBG_VER(payload[6]), - is_rw); - } else if (cnt == 6) { - /* really old devices don't have last byte */ - pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); - } - break; - case VDO_CMD_CURRENT: - CPRINTF("Current: %dmA\n", payload[1]); - break; - case VDO_CMD_FLIP: - usb_mux_flip(port); - break; -#ifdef CONFIG_USB_PD_LOGGING - case VDO_CMD_GET_LOG: - pd_log_recv_vdm(port, cnt, payload); - break; -#endif /* CONFIG_USB_PD_LOGGING */ - } - - return 0; -} - -#ifdef CONFIG_USB_PD_ALT_MODE_DFP -static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; -static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; - -static void svdm_safe_dp_mode(int port) -{ - /* make DP interface safe until configure */ - dp_flags[port] = 0; - dp_status[port] = 0; - usb_mux_set(port, TYPEC_MUX_NONE, - USB_SWITCH_CONNECT, pd_get_polarity(port)); -} - -static int svdm_enter_dp_mode(int port, uint32_t mode_caps) -{ - /* Only enter mode if device is DFP_D capable */ - if (mode_caps & MODE_DP_SNK) { - svdm_safe_dp_mode(port); - return 0; - } - - return -1; -} - -static int svdm_dp_status(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_STATUS | VDO_OPOS(opos)); - payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ - 0, /* HPD level ... not applicable */ - 0, /* exit DP? ... no */ - 0, /* usb mode? ... no */ - 0, /* multi-function ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON)), - 0, /* power low? ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON))); - return 2; -}; - -static int svdm_dp_config(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); - int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); - - if (!pin_mode) - return 0; - - usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP, - USB_SWITCH_CONNECT, pd_get_polarity(port)); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_CONFIG | VDO_OPOS(opos)); - payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ - 1, /* DPv1.3 signaling */ - 2); /* UFP connected */ - return 2; -}; - -static void svdm_dp_post_config(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - - dp_flags[port] |= DP_FLAGS_DP_ON; - if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING)) - return; - mux->hpd_update(port, 1, 0); -} - -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]); - const struct usb_mux *mux = &usb_muxes[port]; - - dp_status[port] = payload[1]; - if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { - if (lvl) - dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; - return 1; - } - mux->hpd_update(port, lvl, irq); - - /* 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 */ diff --git a/board/snappy/battery.c b/board/snappy/battery.c deleted file mode 100644 index 7dcff42cdd..0000000000 --- a/board/snappy/battery.c +++ /dev/null @@ -1,255 +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. - * - * 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 "console.h" -#include "ec_commands.h" -#include "extpower.h" -#include "gpio.h" -#include "i2c.h" -#include "util.h" - -/* Shutdown mode parameter to write to manufacturer access register */ -#define PARAM_CUT_OFF_LOW 0x10 -#define PARAM_CUT_OFF_HIGH 0x00 - -static enum battery_present batt_pres_prev = BP_NOT_SURE; - -/* Battery info for BQ40Z55 */ -static const struct battery_info info = { - /* FIXME(dhendrix): where do these values come from? */ - .voltage_max = 8700, /* mV */ - .voltage_normal = 7600, - .voltage_min = 6100, - .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 = 0, - .discharging_max_c = 60, -}; - -static inline 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; -} - -const struct battery_info *battery_get_info(void) -{ - return &info; -} - -int board_cut_off_battery(void) -{ - int rv; - uint8_t buf[3]; - - /* Ship mode command must be sent twice to take effect */ - buf[0] = SB_MANUFACTURER_ACCESS & 0xff; - buf[1] = PARAM_CUT_OFF_LOW; - buf[2] = PARAM_CUT_OFF_HIGH; - - i2c_lock(I2C_PORT_BATTERY, 1); - rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0, - I2C_XFER_SINGLE); - rv |= i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0, - I2C_XFER_SINGLE); - i2c_lock(I2C_PORT_BATTERY, 0); - - return rv; -} - -enum battery_disconnect_state battery_get_disconnect_state(void) -{ - uint8_t data[6]; - int rv; - - /* - * Take note if we find that the battery isn't in disconnect state, - * and always return NOT_DISCONNECTED without probing the battery. - * This assumes the battery will not go to disconnect state during - * runtime. - */ - static int not_disconnected; - - if (not_disconnected) - return BATTERY_NOT_DISCONNECTED; - - if (extpower_is_present()) { - /* Check if battery charging + discharging is disabled. */ - rv = sb_read_mfgacc(PARAM_OPERATION_STATUS, - SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); - if (rv) - return BATTERY_DISCONNECT_ERROR; - if (~data[3] & (BATTERY_DISCHARGING_DISABLED | - BATTERY_CHARGING_DISABLED)) { - not_disconnected = 1; - return BATTERY_NOT_DISCONNECTED; - } - - /* - * Battery is neither charging nor discharging. Verify that - * we didn't enter this state due to a safety fault. - */ - rv = sb_read_mfgacc(PARAM_SAFETY_STATUS, - SB_ALT_MANUFACTURER_ACCESS, data, sizeof(data)); - if (rv || data[2] || data[3] || data[4] || data[5]) - return BATTERY_DISCONNECT_ERROR; - - /* - * Battery is present and also the status is initialized and - * no safety fault, battery is disconnected. - */ - if (battery_is_present() == BP_YES) - return BATTERY_DISCONNECTED; - } - not_disconnected = 1; - return BATTERY_NOT_DISCONNECTED; -} - -#ifdef CONFIG_CHARGER_PROFILE_OVERRIDE - -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; -} - -/* - * This can override the smart battery's charging profile. To make a change, - * modify one or more of requested_voltage, requested_current, or state. - * Leave everything else unchanged. - * - * Return the next poll period in usec, or zero to use the default (which is - * state dependent). - */ - -int charger_profile_override(struct charge_state_data *curr) -{ - const struct battery_info *batt_info; - - /* temp in 0.1 deg C */ - int temp_c = curr->batt.temperature - 2731; - - /* Current and previous battery voltage */ - int 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; - } - - batt_info = battery_get_info(); - /* Don't charge if outside of allowable temperature range */ - if (temp_c >= batt_info->charging_max_c * 10 || - temp_c < batt_info->charging_min_c * 10) { - curr->requested_current = 0; - curr->requested_voltage = 0; - curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE; - curr->state = ST_IDLE; - } - return 0; -} - -/* Customs options controllable by host command. */ -#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0) - -enum ec_status charger_profile_override_get_param(uint32_t param, - uint32_t *value) -{ - return EC_RES_INVALID_PARAM; -} - -enum ec_status charger_profile_override_set_param(uint32_t param, - uint32_t value) -{ - return EC_RES_INVALID_PARAM; -} -#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */ - -/* - * Physical detection of battery. - */ -enum battery_present battery_is_present(void) -{ - enum battery_present batt_pres; - int batt_status, rv; - - /* 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. - * - * If battery I2C fails but VBATT is high, battery is booting from - * 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()) { - rv = battery_status(&batt_status); - if ((rv && bd9995x_get_battery_voltage() >= info.voltage_min) || - (!rv && !(batt_status & STATUS_INITIALIZED))) - batt_pres = BP_NO; - } - - batt_pres_prev = batt_pres; - - return batt_pres; -} - -int board_battery_initialized(void) -{ - return battery_hw_present() == batt_pres_prev; -} diff --git a/board/snappy/board.c b/board/snappy/board.c deleted file mode 100644 index 9d58593e76..0000000000 --- a/board/snappy/board.c +++ /dev/null @@ -1,1140 +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. - */ - -/* Snappy board-specific configuration */ - -#include "adc.h" -#include "adc_chip.h" -#include "als.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_bmi160.h" -#include "driver/baro_bmp280.h" -#include "driver/charger/bd9995x.h" -#include "driver/tcpm/anx74xx.h" -#include "driver/tcpm/ps8751.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 "spi.h" -#include "switch.h" -#include "system.h" -#include "tablet_mode.h" -#include "task.h" -#include "temp_sensor.h" -#include "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 void tcpc_alert_event(enum gpio_signal signal) -{ - if ((signal == GPIO_USB_C0_PD_INT_ODL) && - !gpio_get_level(GPIO_USB_C0_PD_RST_L)) - return; - - if ((signal == GPIO_USB_C1_PD_INT_ODL) && - !gpio_get_level(GPIO_USB_C1_PD_RST_ODL)) - return; - -#ifdef HAS_TASK_PDCMD - /* Exchange status with TCPCs */ - host_command_pd_send_status(PD_CHARGE_NO_CHANGE); -#endif -} - -#ifdef CONFIG_USB_PD_TCPC_LOW_POWER -static void anx74xx_cable_det_handler(void) -{ - int level = gpio_get_level(GPIO_USB_C0_CABLE_DET); - - /* - * Setting the low power is handled by DRP status hence - * handle only the attach event. - */ - if (level) - anx74xx_handle_power_mode(USB_PD_PORT_ANX74XX, - ANX74XX_NORMAL_MODE); - - /* confirm if cable_det is asserted */ - if (!level || gpio_get_level(GPIO_USB_C0_PD_RST_L)) - return; - - task_set_event(TASK_ID_PD_C0, PD_EVENT_TCPC_RESET, 0); -} -DECLARE_DEFERRED(anx74xx_cable_det_handler); -DECLARE_HOOK(HOOK_CHIPSET_RESUME, anx74xx_cable_det_handler, HOOK_PRIO_LAST); - -void anx74xx_cable_det_interrupt(enum gpio_signal signal) -{ - /* debounce for 2ms */ - 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" - -/* power signal list. Must match order of enum power_signal. */ -const struct power_signal_info power_signal_list[] = { - {GPIO_RSMRST_L_PGOOD, 1, "RSMRST_L"}, - {GPIO_PCH_SLP_S3_L, 1, "SLP_S3_DEASSERTED"}, - {GPIO_PCH_SLP_S4_L, 1, "SLP_S4_DEASSERTED"}, - {GPIO_SUSPWRNACK, 1, "SUSPWRNACK_DEASSERTED"}, - - {GPIO_ALL_SYS_PGOOD, 1, "ALL_SYS_PGOOD"}, - {GPIO_PP3300_PG, 1, "PP3300_PG"}, - {GPIO_PP5000_PG, 1, "PP5000_PG"}, -}; -BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT); - -/* 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 - }, -}; -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[] = { -}; -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 = 0x50, - .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 = 0x16, - .i2c_test = &ps8751_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT1 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL - { - .port = I2C_PORT_GYRO, - .addr = BMI160_ADDR0, - .i2c_test = &bmi160_i2c_stress_test_dev, - }, -#endif - -/* NPCX_I2C_PORT2 */ -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL - { - .port = I2C_PORT_BARO, - .addr = BMP280_I2C_ADDRESS1, - .i2c_test = &bmp280_i2c_stress_test_dev, - }, - { - .port = I2C_PORT_LID_ACCEL, - .addr = KX022_ADDR1, - .i2c_test = &kionix_i2c_stress_test_dev, - }, -#endif -#ifdef CONFIG_CMD_I2C_STRESS_TEST_ALS - { - .i2c_test = &opt3001_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_COUNT] = { - [USB_PD_PORT_ANX74XX] = { - .i2c_host_port = NPCX_I2C_PORT0_0, - .i2c_slave_addr = 0x50, - .drv = &anx74xx_tcpm_drv, - .pol = TCPC_ALERT_ACTIVE_LOW, - }, - [USB_PD_PORT_PS8751] = { - .i2c_host_port = NPCX_I2C_PORT0_1, - .i2c_slave_addr = 0x16, - .drv = &tcpci_tcpm_drv, - .pol = TCPC_ALERT_ACTIVE_LOW, - }, -}; - -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 *mux) -{ - /* Snappy specific signal reconditioning */ - i2c_write8(mux->port_addr, TCPC_PORT1_I2C_ADDR, - PS8751_REG_MUX_USB_C2SS_EQ, 0x50); - i2c_write8(mux->port_addr, TCPC_PORT1_I2C_ADDR, - PS8751_REG_MUX_USB_C2SS_HS_THRESHOLD, 0x80); - return EC_SUCCESS; -} - -struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { - { - .port_addr = USB_PD_PORT_ANX74XX, /* don't care / unused */ - .driver = &anx74xx_tcpm_usb_mux_driver, - .hpd_update = &anx74xx_tcpc_update_hpd_status, - }, - { - .port_addr = USB_PD_PORT_PS8751, /* port # not i2c address */ - .driver = &tcpci_tcpm_usb_mux_driver, - .hpd_update = &ps8751_tcpc_update_hpd_status, - .board_init = &ps8751_tune_mux, - } -}; - -/* called from anx74xx_set_power_mode() */ -void board_set_tcpc_power_mode(int port, int mode) -{ - if (port == 0) { - gpio_set_level(GPIO_USB_C0_PD_RST_L, mode); - msleep(mode ? 10 : 1); - gpio_set_level(GPIO_EN_USB_TCPC_PWR, mode); - } -} - -/** - * Reset PD MCU -- 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 */ - gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0); - - /* Assert reset to TCPC0 */ - board_set_tcpc_power_mode(0, 0); - - /* Deassert reset to TCPC1 */ - gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1); - - /* TCPC0 requires 10ms reset/power down assertion */ - msleep(10); - - /* Deassert reset to TCPC0 */ - board_set_tcpc_power_mode(0, 1); -} - -void board_tcpc_init(void) -{ - int port, reg; - - /* Only reset TCPC if not sysjump */ - if (!system_jumped_to_this_image()) - board_reset_pd_mcu(); - - /* - * 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, 0x10, 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 (port = 0; port < CONFIG_USB_PD_PORT_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); - -/* - * Data derived from Seinhart-Hart equation in a resistor divider circuit with - * Vdd=3300mV, R = 13.7Kohm, and Murata NCP15WB-series thermistor (B = 4050, - * T0 = 298.15, nominal resistance (R0) = 47Kohm). - */ -#define CHARGER_THERMISTOR_SCALING_FACTOR 13 -static const struct thermistor_data_pair charger_thermistor_data[] = { - { 3044 / CHARGER_THERMISTOR_SCALING_FACTOR, 0 }, - { 2890 / CHARGER_THERMISTOR_SCALING_FACTOR, 10 }, - { 2680 / CHARGER_THERMISTOR_SCALING_FACTOR, 20 }, - { 2418 / CHARGER_THERMISTOR_SCALING_FACTOR, 30 }, - { 2117 / CHARGER_THERMISTOR_SCALING_FACTOR, 40 }, - { 1800 / CHARGER_THERMISTOR_SCALING_FACTOR, 50 }, - { 1490 / CHARGER_THERMISTOR_SCALING_FACTOR, 60 }, - { 1208 / CHARGER_THERMISTOR_SCALING_FACTOR, 70 }, - { 966 / CHARGER_THERMISTOR_SCALING_FACTOR, 80 }, - { 860 / CHARGER_THERMISTOR_SCALING_FACTOR, 85 }, - { 766 / CHARGER_THERMISTOR_SCALING_FACTOR, 90 }, - { 679 / CHARGER_THERMISTOR_SCALING_FACTOR, 95 }, - { 603 / CHARGER_THERMISTOR_SCALING_FACTOR, 100 }, -}; - -static const struct thermistor_info charger_thermistor_info = { - .scaling_factor = CHARGER_THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(charger_thermistor_data), - .data = charger_thermistor_data, -}; - -int board_get_charger_temp(int idx, int *temp_ptr) -{ - int mv = adc_read_channel(NPCX_ADC_CH0); - - if (mv < 0) - return -1; - - *temp_ptr = thermistor_linear_interpolate(mv, &charger_thermistor_info); - *temp_ptr = C_TO_K(*temp_ptr); - return 0; -} - -/* - * Data derived from Seinhart-Hart equation in a resistor divider circuit with - * Vdd=3300mV, R = 51.1Kohm, and Murata NCP15WB-series thermistor (B = 4050, - * T0 = 298.15, nominal resistance (R0) = 47Kohm). - */ -#define AMB_THERMISTOR_SCALING_FACTOR 11 -static const struct thermistor_data_pair amb_thermistor_data[] = { - { 2512 / AMB_THERMISTOR_SCALING_FACTOR, 0 }, - { 2158 / AMB_THERMISTOR_SCALING_FACTOR, 10 }, - { 1772 / AMB_THERMISTOR_SCALING_FACTOR, 20 }, - { 1398 / AMB_THERMISTOR_SCALING_FACTOR, 30 }, - { 1070 / AMB_THERMISTOR_SCALING_FACTOR, 40 }, - { 803 / AMB_THERMISTOR_SCALING_FACTOR, 50 }, - { 597 / AMB_THERMISTOR_SCALING_FACTOR, 60 }, - { 443 / AMB_THERMISTOR_SCALING_FACTOR, 70 }, - { 329 / AMB_THERMISTOR_SCALING_FACTOR, 80 }, - { 285 / AMB_THERMISTOR_SCALING_FACTOR, 85 }, - { 247 / AMB_THERMISTOR_SCALING_FACTOR, 90 }, - { 214 / AMB_THERMISTOR_SCALING_FACTOR, 95 }, - { 187 / AMB_THERMISTOR_SCALING_FACTOR, 100 }, -}; - -static const struct thermistor_info amb_thermistor_info = { - .scaling_factor = AMB_THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(amb_thermistor_data), - .data = amb_thermistor_data, -}; - -int board_get_ambient_temp(int idx, int *temp_ptr) -{ - int mv = adc_read_channel(NPCX_ADC_CH1); - - if (mv < 0) - return -1; - - *temp_ptr = thermistor_linear_interpolate(mv, &amb_thermistor_info); - *temp_ptr = C_TO_K(*temp_ptr); - return 0; -} - - -const struct temp_sensor_t temp_sensors[] = { - /* FIXME(dhendrix): tweak action_delay_sec */ - {"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_get_battery_temp, 0, 1}, - {"Ambient", TEMP_SENSOR_TYPE_BOARD, board_get_ambient_temp, 0, 5}, - {"Charger", TEMP_SENSOR_TYPE_BOARD, board_get_charger_temp, 1, 1}, -}; -BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); - -/* ALS instances. Must be in same order as enum als_id. */ -struct als_t als[] = { - /* FIXME(dhendrix): verify attenuation_factor */ - {"TI", opt3001_init, opt3001_read_lux, 5}, -}; -BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); - -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_EC_VOLDN_BTN_ODL, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_EC_VOLUP_BTN_ODL, - 30 * MSEC, 0}, -}; - -/* Called by APL power state machine when transitioning from G3 to S5 */ -static void chipset_pre_init(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); -} -DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, chipset_pre_init, HOOK_PRIO_DEFAULT); - -static void board_set_tablet_mode(void) -{ - tablet_set_mode(!gpio_get_level(GPIO_TABLET_MODE_L)); -} - -/* 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); -} -/* 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) -{ - enum bd9995x_charge_port bd9995x_port; - - switch (port) { - case USB_PD_PORT_ANX74XX: - case USB_PD_PORT_PS8751: - bd9995x_port = bd9995x_pd_port_to_chg_port(port); - break; - default: - panic("Invalid charge port\n"); - break; - } - - return bd9995x_is_vbus_provided(bd9995x_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; - static int initialized; - - /* - * Reject charge port disable if our battery is critical and we - * have yet to initialize a charge port - continue to charge using - * charger ROM / POR settings. - */ - if (!initialized && - charge_port == CHARGE_PORT_NONE && - charge_get_percent() < 2) - return -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 = bd9995x_pd_port_to_chg_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); - initialized = 1; - - 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 whether ramping is allowed for given supplier - */ -int board_is_ramp_allowed(int supplier) -{ - /* Don't allow ramping in RO when write protected */ - if (system_get_image_copy() != SYSTEM_IMAGE_RW - && system_is_locked()) - return 0; - else - return (supplier == CHARGE_SUPPLIER_BC12_DCP || - supplier == CHARGE_SUPPLIER_BC12_SDP || - supplier == CHARGE_SUPPLIER_BC12_CDP || - supplier == CHARGE_SUPPLIER_OTHER); -} - -/** - * Return the maximum allowed input current - */ -int board_get_ramp_current_limit(int supplier, int sup_curr) -{ - return bd9995x_get_bc12_ilim(supplier); -} - -/** - * Return if board is consuming full amount of input current - */ -int board_is_consuming_full_charge(void) -{ - int chg_perc = charge_get_percent(); - - return chg_perc > 2 && chg_perc < 95; -} - -/** - * Return if VBUS is sagging too low - */ -int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state) -{ - return charger_get_vbus_voltage(port) < 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 */ -#ifndef TEST_BUILD -void lid_angle_peripheral_enable(int enable) -{ - /* - * If the lid is in 360 position, ignore the lid angle, - * which might be faulty. Disable keyboard and touchpad. - */ - if (tablet_get_mode() || chipset_in_state(CHIPSET_STATE_ANY_OFF)) - enable = 0; - keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE); -} -#endif - -/* 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? - */ - -/* - * FIXME(dhendrix): Weak symbol hack until we can get a better solution for - * both Amenia and Snappy. - */ -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_POWER_LED_WHITE, GPIO_INPUT | GPIO_PULL_UP}, - {GPIO_BAT_LED_WHITE, 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 matrix_3x3_t base_standard_ref = { - { 0, FLOAT_TO_FP(-1), 0}, - { FLOAT_TO_FP(-1), 0, 0}, - { 0, 0, FLOAT_TO_FP(-1)} -}; - -const matrix_3x3_t lid_a_cover_facing_ref = { - { FLOAT_TO_FP(1), 0, 0}, - { 0, FLOAT_TO_FP(1), 0}, - { 0, 0, FLOAT_TO_FP(1)} -}; - -const matrix_3x3_t lid_b_cover_facing_ref = { - { FLOAT_TO_FP(1), 0, 0}, - { 0, FLOAT_TO_FP(-1), 0}, - { 0, 0, FLOAT_TO_FP(-1)} -}; - -struct kionix_accel_data g_kx022_data; -struct bmi160_drv_data_t g_bmi160_data; -struct bmp280_drv_data_t bmp280_drv_data; - -/* FIXME(dhendrix): Copied from Amenia, probably need to tweak for Snappy */ -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, - .addr = KX022_ADDR1, - .rot_standard_ref = &lid_a_cover_facing_ref, /* Identity matrix. */ - .default_range = 2, /* g, enough for laptop. */ - .config = { - /* AP: by default use EC settings */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* unused */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, - - [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, - .addr = BMI160_ADDR0, - .rot_standard_ref = &base_standard_ref, - .default_range = 2, /* g, enough for laptop. */ - .config = { - /* AP: by default use EC settings */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC use accel for angle detection */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0 - }, - }, - }, - - [BASE_GYRO] = { - .name = "Base Gyro", - .active_mask = SENSOR_ACTIVE_S0_S3, - .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, - .addr = BMI160_ADDR0, - .default_range = 1000, /* dps */ - .rot_standard_ref = &base_standard_ref, - .config = { - /* AP: by default shutdown all sensors */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC does not need in S0 */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, - - [BASE_MAG] = { - .name = "Base Mag", - .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMI160, - .type = MOTIONSENSE_TYPE_MAG, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmi160_drv, - .mutex = &g_base_mutex, - .drv_data = &g_bmi160_data, - .port = I2C_PORT_GYRO, - .addr = BMI160_ADDR0, - .default_range = 1 << 11, /* 16LSB / uT, fixed */ - .rot_standard_ref = NULL, - .config = { - /* AP: by default shutdown all sensors */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC does not need in S0 */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, - - [BASE_BARO] = { - .name = "Base Baro", - .active_mask = SENSOR_ACTIVE_S0, - .chip = MOTIONSENSE_CHIP_BMP280, - .type = MOTIONSENSE_TYPE_BARO, - .location = MOTIONSENSE_LOC_BASE, - .drv = &bmp280_drv, - .drv_data = &bmp280_drv_data, - .port = I2C_PORT_BARO, - .addr = BMP280_I2C_ADDRESS1, - .default_range = 1 << 18, /* 1bit = 4 Pa, 16bit ~= 2600 hPa */ - .config = { - /* AP: by default shutdown all sensors */ - [SENSOR_CONFIG_AP] = { - .odr = 0, - .ec_rate = 0, - }, - /* EC does not need in S0 */ - [SENSOR_CONFIG_EC_S0] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S3] = { - .odr = 0, - .ec_rate = 0, - }, - /* Sensor off in S3/S5 */ - [SENSOR_CONFIG_EC_S5] = { - .odr = 0, - .ec_rate = 0, - }, - }, - }, -}; -const 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); -} - -struct { - enum snappy_board_version version; - int thresh_mv; -} const snappy_board_versions[] = { - /* Vin = 3.3V, R1 = 46.4K, R2 values listed below */ - { BOARD_VERSION_1, 328 * 1.03 }, /* 5.11 Kohm */ - { BOARD_VERSION_2, 670 * 1.03 }, /* 11.8 Kohm */ - { BOARD_VERSION_3, 1012 * 1.03 }, /* 20.5 Kohm */ - { BOARD_VERSION_4, 1357 * 1.03 }, /* 32.4 Kohm */ - { BOARD_VERSION_5, 1690 * 1.03 }, /* 48.7 Kohm */ - { BOARD_VERSION_6, 2020 * 1.03 }, /* 73.2 Kohm */ - { BOARD_VERSION_7, 2352 * 1.03 }, /* 115 Kohm */ - { BOARD_VERSION_8, 2802 * 1.03 }, /* 261 Kohm */ -}; -BUILD_ASSERT(ARRAY_SIZE(snappy_board_versions) == BOARD_VERSION_COUNT); - -int board_get_version(void) -{ - static int version = BOARD_VERSION_UNKNOWN; - int mv, i; - - if (version != BOARD_VERSION_UNKNOWN) - return version; - - /* FIXME(dhendrix): enable ADC */ - gpio_set_flags(GPIO_EC_BRD_ID_EN_ODL, GPIO_ODR_HIGH); - gpio_set_level(GPIO_EC_BRD_ID_EN_ODL, 0); - /* Wait to allow cap charge */ - msleep(1); - mv = adc_read_channel(ADC_BOARD_ID); - /* FIXME(dhendrix): disable ADC */ - gpio_set_level(GPIO_EC_BRD_ID_EN_ODL, 1); - gpio_set_flags(GPIO_EC_BRD_ID_EN_ODL, GPIO_INPUT); - - if (mv == ADC_READ_ERROR) { - version = BOARD_VERSION_UNKNOWN; - return version; - } - - for (i = 0; i < BOARD_VERSION_COUNT; i++) { - if (mv < snappy_board_versions[i].thresh_mv) { - version = snappy_board_versions[i].version; - break; - } - } - - CPRINTS("Board version: %d", version); - return version; -} - -/* Keyboard scan setting */ -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 */ - }, -}; - -#ifdef CONFIG_KEYBOARD_FACTORY_TEST -/* - * We have total 21 pins for keyboard connecter, {-1, -1} mean - * the N/A pin that don't consider it and reserve index 0 area - * that we don't have pin 0. - */ -const int keyboard_factory_scan_pins[][2] = { - {-1, -1}, {0, 5}, {1, 1}, {1, 0}, {0, 6}, - {0, 7}, {1, 4}, {1, 3}, {1, 6}, {-1, -1}, - {3, 1}, {2, 0}, {1, 5}, {2, 6}, {-1, -1}, - {2, 1}, {2, 4}, {2, 5}, {1, 2}, {2, 3}, - {2, 2}, {3, 0}, -}; - -const int keyboard_factory_scan_pins_used = - ARRAY_SIZE(keyboard_factory_scan_pins); -#endif - -static void board_init_late(void) -{ - int version = system_get_board_version(); - - /* Set the sensors in the right powermode */ - if (version <= BOARD_VERSION_4) { - int i; - - for (i = BASE_ACCEL; i <= BASE_MAG; ++i) - motion_sensors[i].active_mask = SENSOR_ACTIVE_S0; - } - - /* - * New form-factor aligns w/ electro, lid accelerometer - * faces to B-cover. - */ - if (version < BOARD_VERSION_6) - motion_sensors[LID_ACCEL].rot_standard_ref = - &lid_b_cover_facing_ref; -} -/* - * We need robust ADC read, that is the source of board version; - * in order to apply board specific tweaks, so eusure this hook - * comes after adc_init(). - */ -DECLARE_HOOK(HOOK_INIT, board_init_late, HOOK_PRIO_INIT_ADC + 1); diff --git a/board/snappy/board.h b/board/snappy/board.h deleted file mode 100644 index 49a166132c..0000000000 --- a/board/snappy/board.h +++ /dev/null @@ -1,336 +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. - */ - -/* Snappy board configuration */ - -#ifndef __CROS_EC_BOARD_H -#define __CROS_EC_BOARD_H - -/* - * By default, enable all console messages excepted HC, ACPI and event: - * The sensor stack is generating a lot of activity. - */ -#define CC_DEFAULT (CC_ALL & ~(CC_MASK(CC_EVENTS) | CC_MASK(CC_LPC))) -#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_CMD_CHARGER_PSYS -#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 - -/* Battery */ -#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION" -#define CONFIG_BATTERY_CUT_OFF -#define CONFIG_BATTERY_PRESENT_CUSTOM -#define CONFIG_BATTERY_REVIVE_DISCONNECT -#define CONFIG_BATTERY_SMART - -/* Charger */ -#define CONFIG_CHARGE_MANAGER -#define CONFIG_CHARGE_RAMP -#define CONFIG_CHARGER -#define CONFIG_CHARGER_V2 -#define CONFIG_CHARGER_BD99956 -#define CONFIG_CHARGER_BD9995X_CHGEN -#define CONFIG_CHARGER_DISCHARGE_ON_AC -#define CONFIG_CHARGER_INPUT_CURRENT 512 -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 1 -#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 18000 -#define CONFIG_CHARGER_MAINTAIN_VBAT -#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1 -#define CONFIG_CHARGER_PROFILE_OVERRIDE -#define CONFIG_USB_CHARGER -#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_USB_ILIM_SEL GPIO_USB_A_CHARGE_EN_L -#define GPIO_USB_CTL1 GPIO_EN_PP5000 - -#define CONFIG_TABLET_MODE - -/* USB PD config */ -#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL -#define CONFIG_CMD_PD_CONTROL -#define CONFIG_USB_PD_ALT_MODE -#define CONFIG_USB_PD_ALT_MODE_DFP -#define CONFIG_USB_PD_CUSTOM_VDM -#define CONFIG_USB_PD_DUAL_ROLE -#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE -#define CONFIG_USB_PD_DISCHARGE -#define CONFIG_USB_PD_DISCHARGE_TCPC -#define CONFIG_USB_PD_LOGGING -#define CONFIG_USB_PD_LOG_SIZE 512 -#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0 -#define CONFIG_USB_PD_PORT_COUNT 2 -#define CONFIG_USB_PD_QUIRK_SLOW_CC_STATUS -#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_ANX74XX -#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_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_LPC -#define CONFIG_CHIPSET_APOLLOLAKE -#define CONFIG_CHIPSET_RESET_HOOK -#undef CONFIG_PECI -#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_BOARD_VERSION -#define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 -#define CONFIG_EXTPOWER_GPIO -#undef CONFIG_EXTPOWER_DEBOUNCE_MS -#define CONFIG_EXTPOWER_DEBOUNCE_MS 1000 -#define CONFIG_FPU -/* Region sizes are not power of 2 so we can't use MPU */ -#undef CONFIG_MPU -#define CONFIG_HOSTCMD_FLASH_SPI_INFO -#define CONFIG_I2C -#define CONFIG_I2C_MASTER -#define CONFIG_KEYBOARD_BOARD_CONFIG -#define CONFIG_KEYBOARD_PROTOCOL_8042 -#define CONFIG_KEYBOARD_COL2_INVERTED -#define CONFIG_KEYBOARD_FACTORY_TEST -#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_TEMP_SENSOR -#define CONFIG_THERMISTOR_NCP15WB -#define CONFIG_DPTF -#define CONFIG_SCI_GPIO GPIO_PCH_SCI_L -#define CONFIG_UART_HOST 0 -#define CONFIG_VBOOT_HASH -#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 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 Snappy. Do we need - * to change some other setting to put them in GPIO mode? - */ -#define NPCX_TACH_SEL2 0 /* 0:GPIO40/A4 1:GPIO93/D3 as TACH */ - -/* I2C ports */ -#define I2C_PORT_GYRO NPCX_I2C_PORT1 -#define I2C_PORT_LID_ACCEL NPCX_I2C_PORT2 -#define I2C_PORT_ALS NPCX_I2C_PORT2 -#define I2C_PORT_BARO 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_CUSTOM(4) -#define CONFIG_MAG_BMI160_BMM150 -#define BMM150_I2C_ADDRESS BMM150_ADDR0 /* 8-bit address */ -#define CONFIG_MAG_CALIBRATE -#define CONFIG_ACCEL_KX022 -#define CONFIG_ALS_OPT3001 -#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 -#define CONFIG_BARO_BMP280 -#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 - -/* FIFO size is in power of 2. */ -#define CONFIG_ACCEL_FIFO 1024 - -/* Depends on how fast the AP boots and typical ODRs */ -#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 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_CH_COUNT -}; - -enum pwm_channel { - /* Number of PWM channels */ - PWM_CH_COUNT -}; - -enum power_signal { - X86_RSMRST_N = 0, - X86_SLP_S3_N, - X86_SLP_S4_N, - X86_SUSPWRDNACK, - - X86_ALL_SYS_PG, /* PMIC_EC_PWROK_OD */ - X86_PGOOD_PP3300, /* GPIO_PP3300_PG */ - X86_PGOOD_PP5000, /* GPIO_PP5000_PG */ - - /* Number of X86 signals */ - POWER_SIGNAL_COUNT -}; - -enum temp_sensor_id { - TEMP_SENSOR_BATTERY = 0, - TEMP_SENSOR_AMBIENT, - TEMP_SENSOR_CHARGER, - TEMP_SENSOR_COUNT -}; - -/* Light sensors */ -enum als_id { - ALS_OPT3001 = 0, - - ALS_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 = 0, - BASE_ACCEL, - BASE_GYRO, - BASE_MAG, - BASE_BARO, -}; - -enum snappy_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_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 PD_VCONN_SWAP_DELAY 5000 /* us */ - -/* 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 - -#ifdef CONFIG_KEYBOARD_FACTORY_TEST -extern const int keyboard_factory_scan_pins[][2]; -extern const int keyboard_factory_scan_pins_used; -#endif - -/* Reset PD MCU */ -void board_reset_pd_mcu(void); - -int board_get_version(void); - -#define TCPC_PORT0_I2C_ADDR 0x50 -#define TCPC_PORT1_I2C_ADDR 0x16 - -void board_set_tcpc_power_mode(int port, int mode); -void board_print_tcpc_fw_version(int port); - -/* Sensors without hardware FIFO are in forced mode */ -#define CONFIG_ACCEL_FORCE_MODE_MASK \ - ((1 << LID_ACCEL) | (1 << BASE_BARO)) - -#endif /* !__ASSEMBLER__ */ - -#endif /* __CROS_EC_BOARD_H */ diff --git a/board/snappy/build.mk b/board/snappy/build.mk deleted file mode 100644 index 728d027803..0000000000 --- a/board/snappy/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/snappy/ec.tasklist b/board/snappy/ec.tasklist deleted file mode 100644 index 47e0048872..0000000000 --- a/board/snappy/ec.tasklist +++ /dev/null @@ -1,39 +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. - */ - -/* - * List of enabled tasks in the priority order - * - * The first one has the lowest priority. - * - * For each task, use the macro TASK_ALWAYS(n, r, d, s) for base tasks and - * TASK_NOTEST(n, r, d, s) for tasks that can be excluded in test binaries, - * where : - * 'n' in the name of the task - * 'r' in the main routine of the task - * 'd' in an opaque parameter passed to the routine at startup - * 's' is the stack size in bytes; must be a multiple of 8 - * - * For USB PD tasks, IDs must be in consecutive order and correspond to - * the port which they are for. See TASK_ID_TO_PD_PORT() macro. - */ - -#define CONFIG_TASK_LIST \ - TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(ALS, als_task, NULL, 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_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \ - TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \ - TASK_ALWAYS(CONSOLE, console_task, NULL, VENTI_TASK_STACK_SIZE) \ - TASK_ALWAYS(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) - diff --git a/board/snappy/gpio.inc b/board/snappy/gpio.inc deleted file mode 100644 index a605d1b675..0000000000 --- a/board/snappy/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 */ - -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(SUSPWRNACK, 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, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) -GPIO_INT(EC_VOLUP_BTN_ODL, PIN(8, 2), 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_SPS 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 */ -GPIO(PCH_SLP_S0_L, PIN(7, 5), GPIO_INPUT) /* SLP_S0_L */ - -/* - * BRD_ID1 is a an ADC pin which will be used to measure multiple values. - * Assert EC_BRD_ID_EN_ODL and then read BRD_ID1. - */ -ALTERNATE(PIN_MASK(4, 0x08), 1, MODULE_ADC, 0) -GPIO(EC_BRD_ID_EN_ODL, PIN(3, 5), GPIO_INPUT) - -GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) -GPIO(EC_HAVEN_RESET_ODL, PIN(0, 2), GPIO_ODR_HIGH) -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(PCH_RCIN_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(4, 2), GPIO_OUT_LOW) -GPIO(EN_USB_TCPC_PWR, PIN(C, 3), GPIO_OUT_LOW) -GPIO(USB1_ENABLE, PIN(4, 1), 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_LOW) - -/* - * 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 */ - -/* Clear for non-HDI breakout, must be pulled high */ -GPIO(NC2, PIN(8, 4), GPIO_INPUT | GPIO_PULL_UP | GPIO_SEL_1P8V) - -GPIO(POWER_LED_WHITE, PIN(8, 0), GPIO_OUT_HIGH) -GPIO(BAT_LED_WHITE, PIN(0, 0), GPIO_OUT_HIGH) -GPIO(BAT_LED_AMBER, PIN(C, 4), 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) - -ALTERNATE(PIN(4, 4), 6, MODULE_ADC, 0) /* TEMP_SENSOR_AMB (FIXME: alt function 6?) */ -ALTERNATE(PIN(4, 5), 6, MODULE_ADC, 0) /* TEMP_SENSOR_CHARGER (FIXME: alt function?) */ - -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 */ - -/* FIXME: Make UART RX an interrupt? */ -ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART from EC to Servo */ diff --git a/board/snappy/led.c b/board/snappy/led.c deleted file mode 100644 index ad7ae2f5e1..0000000000 --- a/board/snappy/led.c +++ /dev/null @@ -1,187 +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 Snappy - */ - -#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 "util.h" - -#define BAT_LED_ON 0 -#define BAT_LED_OFF 1 - -const enum ec_led_id supported_led_ids[] = { - EC_LED_ID_POWER_LED, EC_LED_ID_BATTERY_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 int led_set_color_battery(enum led_color color) -{ - switch (color) { - case LED_OFF: - gpio_set_level(GPIO_BAT_LED_WHITE, BAT_LED_OFF); - gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_OFF); - break; - case LED_WHITE: - gpio_set_level(GPIO_BAT_LED_WHITE, BAT_LED_ON); - gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_OFF); - break; - case LED_AMBER: - gpio_set_level(GPIO_BAT_LED_WHITE, BAT_LED_OFF); - gpio_set_level(GPIO_BAT_LED_AMBER, BAT_LED_ON); - break; - default: - return EC_ERROR_UNKNOWN; - } - return EC_SUCCESS; -} - -static int led_set_color_power(enum led_color color) -{ - switch (color) { - case LED_OFF: - gpio_set_level(GPIO_POWER_LED_WHITE, BAT_LED_OFF); - break; - case LED_WHITE: - gpio_set_level(GPIO_POWER_LED_WHITE, BAT_LED_ON); - break; - default: - return EC_ERROR_UNKNOWN; - } - return EC_SUCCESS; -} - -void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) -{ - brightness_range[EC_LED_COLOR_WHITE] = 1; - brightness_range[EC_LED_COLOR_AMBER] = 1; -} - -static int led_set_color(enum ec_led_id led_id, enum led_color color) -{ - int rv; - - switch (led_id) { - case EC_LED_ID_BATTERY_LED: - rv = led_set_color_battery(color); - break; - case EC_LED_ID_POWER_LED: - rv = led_set_color_power(color); - break; - default: - return EC_ERROR_UNKNOWN; - } - return rv; -} - -int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) -{ - if (brightness[EC_LED_COLOR_WHITE] != 0) - led_set_color(led_id, LED_WHITE); - else if (brightness[EC_LED_COLOR_AMBER] != 0) - led_set_color(led_id, LED_AMBER); - else - led_set_color(led_id, LED_OFF); - - return EC_SUCCESS; -} - -static void led_set_battery(void) -{ - static int battery_ticks; - static int power_ticks; - uint32_t chflags = charge_get_flags(); - int remaining_capacity; - int full_charge_capacity; - int permillage; - - battery_ticks++; - power_ticks++; - - remaining_capacity = *(int *)host_get_memmap(EC_MEMMAP_BATT_CAP); - full_charge_capacity = *(int *)host_get_memmap(EC_MEMMAP_BATT_LFCC); - permillage = !full_charge_capacity ? 0 : - (1000 * remaining_capacity) / full_charge_capacity; - - switch (charge_get_state()) { - case PWR_STATE_CHARGE: - led_set_color_battery(LED_AMBER); - break; - case PWR_STATE_DISCHARGE_FULL: - if (extpower_is_present()) { - led_set_color_battery(LED_WHITE); - break; - } - /* Intentional fall-through */ - case PWR_STATE_DISCHARGE: - /* - * Blink white light (1 sec on, 1 sec off) - * when battery capacity is less than 10% - */ - if (permillage < 100) - led_set_color_battery( - (battery_ticks & 0x4) ? LED_WHITE : LED_OFF); - else - led_set_color_battery(LED_OFF); - break; - case PWR_STATE_ERROR: - led_set_color_battery( - (battery_ticks & 0x2) ? LED_WHITE : LED_OFF); - break; - case PWR_STATE_CHARGE_NEAR_FULL: - led_set_color_battery(LED_WHITE); - break; - case PWR_STATE_IDLE: /* External power connected in IDLE */ - if (chflags & CHARGE_FLAG_FORCE_IDLE) - led_set_color_battery( - (battery_ticks & 0x4) ? LED_AMBER : LED_OFF); - else - led_set_color_battery(LED_WHITE); - break; - default: - /* Other states don't alter LED behavior */ - break; - } -} - -static void led_set_power(void) -{ - static int power_tick; - - power_tick++; - - if (chipset_in_state(CHIPSET_STATE_ON)) - led_set_color_power(LED_WHITE); - else if (chipset_in_state(CHIPSET_STATE_SUSPEND | - CHIPSET_STATE_STANDBY)) - led_set_color_power( - (power_tick & 0x4) ? LED_WHITE : LED_OFF); - else - led_set_color_power(LED_OFF); -} - -/* Called by hook task every TICK */ -static void led_tick(void) -{ - if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) - led_set_battery(); - if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) - led_set_power(); -} -DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); diff --git a/board/snappy/usb_pd_policy.c b/board/snappy/usb_pd_policy.c deleted file mode 100644 index 3a77eb6cad..0000000000 --- a/board/snappy/usb_pd_policy.c +++ /dev/null @@ -1,420 +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/ps8751.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) - -#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\ - PDO_FIXED_COMM_CAP) - -/* TODO: 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_is_valid_input_voltage(int mv) -{ - return 1; -} - -void pd_transition_voltage(int idx) -{ - /* No-operation: we are always 5V */ -} - -static uint8_t vbus_en[CONFIG_USB_PD_PORT_COUNT]; -static uint8_t vbus_rp[CONFIG_USB_PD_PORT_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, int 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(bd9995x_pd_port_to_chg_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); -} - -void pd_set_input_current_limit(int port, uint32_t max_ma, - uint32_t supply_voltage) -{ -#ifdef CONFIG_CHARGE_MANAGER - struct charge_port_info charge; - - charge.current = max_ma; - charge.voltage = supply_voltage; - charge_manager_update_charge(CHARGE_SUPPLIER_PD, port, &charge); -#endif -} - -void typec_set_input_current_limit(int port, uint32_t max_ma, - uint32_t supply_voltage) -{ -#ifdef CONFIG_CHARGE_MANAGER - struct charge_port_info charge; - - charge.current = max_ma; - charge.voltage = supply_voltage; - charge_manager_update_charge(CHARGE_SUPPLIER_TYPEC, port, &charge); -#endif -} - -int pd_board_checks(void) -{ - return EC_SUCCESS; -} - -int pd_check_power_swap(int port) -{ - /* - * Allow power swap as long as we are acting as a dual role device, - * otherwise assume our role is fixed (not in S0 or console command - * to fix our role). - */ - return pd_get_dual_role() == PD_DRP_TOGGLE_ON ? 1 : 0; -} - -int pd_check_data_swap(int port, int data_role) -{ - /* Allow data swap if we are a UFP, otherwise don't allow */ - return (data_role == PD_ROLE_UFP) ? 1 : 0; -} - -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); -} - -void pd_execute_data_swap(int port, int data_role) -{ - /* Do nothing */ -} - -void pd_check_pr_role(int port, int pr_role, int flags) -{ - /* - * If partner is dual-role power and dualrole toggling is on, consider - * if a power swap is necessary. - */ - if ((flags & PD_FLAGS_PARTNER_DR_POWER) && - pd_get_dual_role() == PD_DRP_TOGGLE_ON) { - /* - * If we are a sink and partner is not externally powered, then - * swap to become a source. If we are source and partner is - * externally powered, swap to become a sink. - */ - int partner_extpower = flags & PD_FLAGS_PARTNER_EXTPOWER; - - if ((!partner_extpower && pr_role == PD_ROLE_SINK) || - (partner_extpower && pr_role == PD_ROLE_SOURCE)) - pd_request_power_swap(port); - } -} - -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) - pd_request_data_swap(port); -} -/* ----------------- 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; - - /* 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]); - - CPRINTF("DevId:%d.%d SW:%d RW:%d\n", - HW_DEV_ID_MAJ(dev_id), - HW_DEV_ID_MIN(dev_id), - VDO_INFO_SW_DBG_VER(payload[6]), - is_rw); - } else if (cnt == 6) { - /* really old devices don't have last byte */ - pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); - } - break; - case VDO_CMD_CURRENT: - CPRINTF("Current: %dmA\n", payload[1]); - break; - case VDO_CMD_FLIP: - usb_mux_flip(port); - break; -#ifdef CONFIG_USB_PD_LOGGING - case VDO_CMD_GET_LOG: - pd_log_recv_vdm(port, cnt, payload); - break; -#endif /* CONFIG_USB_PD_LOGGING */ - } - - return 0; -} - -#ifdef CONFIG_USB_PD_ALT_MODE_DFP -static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; -static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; - -static void svdm_safe_dp_mode(int port) -{ - /* make DP interface safe until configure */ - dp_flags[port] = 0; - dp_status[port] = 0; - usb_mux_set(port, TYPEC_MUX_NONE, - USB_SWITCH_CONNECT, pd_get_polarity(port)); -} - -static int svdm_enter_dp_mode(int port, uint32_t mode_caps) -{ - /* Only enter mode if device is DFP_D capable */ - if (mode_caps & MODE_DP_SNK) { - svdm_safe_dp_mode(port); - return 0; - } - - return -1; -} - -static int svdm_dp_status(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_STATUS | VDO_OPOS(opos)); - payload[1] = VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */ - 0, /* HPD level ... not applicable */ - 0, /* exit DP? ... no */ - 0, /* usb mode? ... no */ - 0, /* multi-function ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON)), - 0, /* power low? ... no */ - (!!(dp_flags[port] & DP_FLAGS_DP_ON))); - return 2; -}; - -static int svdm_dp_config(int port, uint32_t *payload) -{ - int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); - int mf_pref = PD_VDO_DPSTS_MF_PREF(dp_status[port]); - int pin_mode = pd_dfp_dp_get_pin_mode(port, dp_status[port]); - - if (!pin_mode) - return 0; - - usb_mux_set(port, mf_pref ? TYPEC_MUX_DOCK : TYPEC_MUX_DP, - USB_SWITCH_CONNECT, pd_get_polarity(port)); - - payload[0] = VDO(USB_SID_DISPLAYPORT, 1, - CMD_DP_CONFIG | VDO_OPOS(opos)); - payload[1] = VDO_DP_CFG(pin_mode, /* pin mode */ - 1, /* DPv1.3 signaling */ - 2); /* UFP connected */ - return 2; -}; - -static void svdm_dp_post_config(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - - dp_flags[port] |= DP_FLAGS_DP_ON; - if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING)) - return; - mux->hpd_update(port, 1, 0); -} - -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]); - const struct usb_mux *mux = &usb_muxes[port]; - - dp_status[port] = payload[1]; - if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { - if (lvl) - dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; - return 1; - } - mux->hpd_update(port, lvl, irq); - - /* 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 */ diff --git a/util/flash_ec b/util/flash_ec index 6c36d2f1e2..18a66bf955 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -107,9 +107,7 @@ BOARDS_NPCX_SPI=( gru kevin poppy - pyro reef - snappy wheatley ) @@ -126,9 +124,7 @@ BOARDS_MEC1322=( BOARDS_SPI_1800MV=( gru kevin - pyro reef - snappy ) BOARDS_RAIDEN=( @@ -136,9 +132,7 @@ BOARDS_RAIDEN=( gru kevin poppy - pyro reef - snappy ) # Flags |