diff options
author | MiceLin <mice_lin@wistron.corp-partner.google.com> | 2020-08-12 09:28:43 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-12 07:56:48 +0000 |
commit | 4242f8f1dfff6074b29d4a3d07e53cd851befc10 (patch) | |
tree | 1865ec4c922a5ad2498260294939b7d6912d921c /board/eldrid/board.c | |
parent | 82e1f1ddb60ba2c39d89a4dd430a806eb7b288a7 (diff) | |
download | chrome-ec-4242f8f1dfff6074b29d4a3d07e53cd851befc10.tar.gz |
eldrid: Initial EC image
Create the initial EC image for the eldrid variant by copying the
volteer reference board EC files into a new directory named for
the variant.
(Auto-Generated by create_initial_ec_image.sh version 1.0.4).
BUG=162115131
BRANCH=none
TEST=make BOARD=eldrid
Signed-off-by: MiceLin <mice_lin@wistron.corp-partner.google.com>
Change-Id: Id458253b4c44d4124f025b014970c7d044760452
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321809
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'board/eldrid/board.c')
-rw-r--r-- | board/eldrid/board.c | 423 |
1 files changed, 423 insertions, 0 deletions
diff --git a/board/eldrid/board.c b/board/eldrid/board.c new file mode 100644 index 0000000000..bb7b47f484 --- /dev/null +++ b/board/eldrid/board.c @@ -0,0 +1,423 @@ +/* Copyright 2020 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. + */ + +/* Volteer board-specific configuration */ + +#include "button.h" +#include "common.h" +#include "accelgyro.h" +#include "cbi_ec_fw_config.h" +#include "driver/accel_bma2x2.h" +#include "driver/accelgyro_bmi260.h" +#include "driver/als_tcs3400.h" +#include "driver/ppc/sn5s330.h" +#include "driver/ppc/syv682x.h" +#include "driver/retimer/bb_retimer.h" +#include "driver/sync.h" +#include "driver/tcpm/ps8xxx.h" +#include "driver/tcpm/tcpci.h" +#include "extpower.h" +#include "fan.h" +#include "fan_chip.h" +#include "gpio.h" +#include "hooks.h" +#include "lid_switch.h" +#include "power.h" +#include "power_button.h" +#include "pwm.h" +#include "pwm_chip.h" +#include "switch.h" +#include "system.h" +#include "task.h" +#include "tablet_mode.h" +#include "throttle_ap.h" +#include "uart.h" +#include "usb_pd_tbt.h" +#include "usbc_ppc.h" +#include "util.h" + +#include "gpio_list.h" /* Must come after other header files. */ + +#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args) + +/* + * FW_CONFIG defaults for Volteer if the CBI data is not initialized. + */ +union volteer_cbi_fw_config fw_config_defaults = { + .usb_db = DB_USB4_GEN2, +}; + +static void board_init(void) +{ + /* Illuminate motherboard and daughter board LEDs equally to start. */ + pwm_enable(PWM_CH_LED4_SIDESEL, 1); + pwm_set_duty(PWM_CH_LED4_SIDESEL, 50); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + +__override enum tbt_compat_cable_speed board_get_max_tbt_speed(int port) +{ + enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type(); + + if (port == USBC_PORT_C1) { + if (usb_db == DB_USB4_GEN2) { + /* + * Older boards violate 205mm trace length prior + * to connection to the re-timer and only support up + * to GEN2 speeds. + */ + return TBT_SS_U32_GEN1_GEN2; + } else if (usb_db == DB_USB4_GEN3) { + return TBT_SS_TBT_GEN3; + } + } + + /* + * Thunderbolt-compatible mode not supported + * + * TODO (b/147726366): All the USB-C ports need to support same speed. + * Need to fix once USB-C feature set is known for Volteer. + */ + return TBT_SS_RES_0; +} + +__override bool board_is_tbt_usb4_port(int port) +{ + enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type(); + + /* + * Volteer reference design only supports TBT & USB4 on port 1 + * if the USB4 DB is present. + * + * TODO (b/147732807): All the USB-C ports need to support same + * features. Need to fix once USB-C feature set is known for Volteer. + */ + return ((port == USBC_PORT_C1) + && ((usb_db == DB_USB4_GEN2) || (usb_db == DB_USB4_GEN3))); +} + +/******************************************************************************/ +/* Physical fans. These are logically separate from pwm_channels. */ + +const struct fan_conf fan_conf_0 = { + .flags = FAN_USE_RPM_MODE, + .ch = MFT_CH_0, /* Use MFT id to control fan */ + .pgood_gpio = -1, + .enable_gpio = GPIO_EN_PP5000_FAN, +}; + +/* + * Fan specs from datasheet: + * Max speed 5900 rpm (+/- 7%), minimum duty cycle 30%. + * Minimum speed not specified by RPM. Set minimum RPM to max speed (with + * margin) x 30%. + * 5900 x 1.07 x 0.30 = 1894, round up to 1900 + */ +const struct fan_rpm fan_rpm_0 = { + .rpm_min = 1900, + .rpm_start = 1900, + .rpm_max = 5900, +}; + +const struct fan_t fans[FAN_CH_COUNT] = { + [FAN_CH_0] = { + .conf = &fan_conf_0, + .rpm = &fan_rpm_0, + }, +}; + +/******************************************************************************/ +/* MFT channels. These are logically separate from pwm_channels. */ +const struct mft_t mft_channels[] = { + [MFT_CH_0] = { + .module = NPCX_MFT_MODULE_1, + .clk_src = TCKC_LFCLK, + .pwm_id = PWM_CH_FAN, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(mft_channels) == MFT_CH_COUNT); + +/******************************************************************************/ +/* I2C port map configuration */ +const struct i2c_port_t i2c_ports[] = { + { + .name = "sensor", + .port = I2C_PORT_SENSOR, + .kbps = 400, + .scl = GPIO_EC_I2C0_SENSOR_SCL, + .sda = GPIO_EC_I2C0_SENSOR_SDA, + }, + { + .name = "usb_c0", + .port = I2C_PORT_USB_C0, + .kbps = 1000, + .scl = GPIO_EC_I2C1_USB_C0_SCL, + .sda = GPIO_EC_I2C1_USB_C0_SDA, + }, + { + .name = "usb_c1", + .port = I2C_PORT_USB_C1, + .kbps = 1000, + .scl = GPIO_EC_I2C2_USB_C1_SCL, + .sda = GPIO_EC_I2C2_USB_C1_SDA, + }, + { + .name = "usb_1_mix", + .port = I2C_PORT_USB_1_MIX, + .kbps = 100, + .scl = GPIO_EC_I2C3_USB_1_MIX_SCL, + .sda = GPIO_EC_I2C3_USB_1_MIX_SDA, + }, + { + .name = "power", + .port = I2C_PORT_POWER, + .kbps = 100, + .scl = GPIO_EC_I2C5_BATTERY_SCL, + .sda = GPIO_EC_I2C5_BATTERY_SDA, + }, + { + .name = "eeprom", + .port = I2C_PORT_EEPROM, + .kbps = 400, + .scl = GPIO_EC_I2C7_EEPROM_PWR_SCL_R, + .sda = GPIO_EC_I2C7_EEPROM_PWR_SDA_R, + }, +}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +/******************************************************************************/ +/* PWM configuration */ +const struct pwm_t pwm_channels[] = { + [PWM_CH_LED1_BLUE] = { + .channel = 2, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + .freq = 4800, + }, + [PWM_CH_LED2_GREEN] = { + .channel = 0, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + .freq = 4800, + }, + [PWM_CH_LED3_RED] = { + .channel = 1, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + .freq = 4800, + }, + [PWM_CH_LED4_SIDESEL] = { + .channel = 7, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + /* + * If using the side select to run both LEDs at the same time, + * the frequency should be 1/2 of the color channel PWM + * frequency to drive each LED equally. + */ + .freq = 2400, + }, + [PWM_CH_FAN] = { + .channel = 5, + .flags = PWM_CONFIG_OPEN_DRAIN, + .freq = 25000 + }, + [PWM_CH_KBLIGHT] = { + .channel = 3, + .flags = 0, + /* + * Set PWM frequency to multiple of 50 Hz and 60 Hz to prevent + * flicker. Higher frequencies consume similar average power to + * lower PWM frequencies, but higher frequencies record a much + * lower maximum power. + */ + .freq = 2400, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); + +/******************************************************************************/ +/* Volteer specific USB daughter-board configuration */ + +/* USBC TCPC configuration for USB3 daughter board */ +static const struct tcpc_config_t tcpc_config_p1_usb3 = { + .bus_type = EC_BUS_TYPE_I2C, + .i2c_info = { + .port = I2C_PORT_USB_C1, + .addr_flags = PS8751_I2C_ADDR1_FLAGS, + }, + .flags = TCPC_FLAGS_TCPCI_REV2_0 | TCPC_FLAGS_TCPCI_REV2_0_NO_VSAFE0V, + .drv = &ps8xxx_tcpm_drv, + .usb23 = USBC_PORT_1_USB2_NUM | (USBC_PORT_1_USB3_NUM << 4), +}; + +/* + * USB3 DB mux configuration - the top level mux still needs to be set to the + * virtual_usb_mux_driver so the AP gets notified of mux changes and updates + * the TCSS configuration on state changes. + */ +static const struct usb_mux usbc1_usb3_db_retimer = { + .usb_port = USBC_PORT_C1, + .driver = &tcpci_tcpm_usb_mux_driver, + .hpd_update = &ps8xxx_tcpc_update_hpd_status, + .next_mux = NULL, +}; + +static const struct usb_mux mux_config_p1_usb3_active = { + .usb_port = USBC_PORT_C1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, + .next_mux = &usbc1_usb3_db_retimer, +}; + +static const struct usb_mux mux_config_p1_usb3_passive = { + .usb_port = USBC_PORT_C1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, +}; + +/******************************************************************************/ +/* USB-A charging control */ + +const int usb_port_enable[USB_PORT_COUNT] = { + GPIO_EN_PP5000_USBA, +}; + +static enum gpio_signal ps8xxx_rst_odl = GPIO_USB_C1_RT_RST_ODL; + +static void ps8815_reset(void) +{ + int val; + + gpio_set_level(ps8xxx_rst_odl, 0); + msleep(GENERIC_MAX(PS8XXX_RESET_DELAY_MS, + PS8815_PWR_H_RST_H_DELAY_MS)); + gpio_set_level(ps8xxx_rst_odl, 1); + msleep(PS8815_FW_INIT_DELAY_MS); + + /* + * b/144397088 + * ps8815 firmware 0x01 needs special configuration + */ + + CPRINTS("%s: patching ps8815 registers", __func__); + + if (i2c_read8(I2C_PORT_USB_C1, + PS8751_I2C_ADDR1_P2_FLAGS, 0x0f, &val) == EC_SUCCESS) + CPRINTS("ps8815: reg 0x0f was %02x", val); + + if (i2c_write8(I2C_PORT_USB_C1, + PS8751_I2C_ADDR1_P2_FLAGS, 0x0f, 0x31) == EC_SUCCESS) + CPRINTS("ps8815: reg 0x0f set to 0x31"); + + if (i2c_read8(I2C_PORT_USB_C1, + PS8751_I2C_ADDR1_P2_FLAGS, 0x0f, &val) == EC_SUCCESS) + CPRINTS("ps8815: reg 0x0f now %02x", val); +} + +void board_reset_pd_mcu(void) +{ + enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type(); + + /* No reset available for TCPC on port 0 */ + /* Daughterboard specific reset for port 1 */ + if (usb_db == DB_USB3_ACTIVE) { + ps8815_reset(); + usb_mux_hpd_update(USBC_PORT_C1, 0, 0); + } +} + +/* + * Set up support for the USB3 daughterboard: + * Parade PS8815 TCPC (integrated retimer) + * Diodes PI3USB9201 BC 1.2 chip (same as USB4 board) + * Silergy SYV682A PPC (same as USB4 board) + * Virtual mux with stacked retimer + */ +static void config_db_usb3_active(void) +{ + tcpc_config[USBC_PORT_C1] = tcpc_config_p1_usb3; + usb_muxes[USBC_PORT_C1] = mux_config_p1_usb3_active; +} + +/* + * Set up support for the passive USB3 daughterboard: + * TUSB422 TCPC (already the default) + * PI3USB9201 BC 1.2 chip (already the default) + * Silergy SYV682A PPC (already the default) + * Virtual mux without stacked retimer + */ + +static void config_db_usb3_passive(void) +{ + usb_muxes[USBC_PORT_C1] = mux_config_p1_usb3_passive; +} + +static const char *db_type_prefix = "USB DB type: "; +__override void board_cbi_init(void) +{ + enum ec_cfg_usb_db_type usb_db = ec_cfg_usb_db_type(); + + /* Reconfigure Volteer GPIOs based on the board ID */ + if (get_board_id() == 0) { + CPRINTS("Configuring GPIOs for board ID 0"); + CPRINTS("VOLUME_UP button disabled"); + + /* Reassign USB_C1_RT_RST_ODL */ + bb_controls[USBC_PORT_C1].retimer_rst_gpio = + GPIO_USB_C1_RT_RST_ODL_BOARDID_0; + ps8xxx_rst_odl = GPIO_USB_C1_RT_RST_ODL_BOARDID_0; + } + + switch (usb_db) { + case DB_USB_ABSENT: + CPRINTS("%sNone", db_type_prefix); + break; + case DB_USB4_GEN2: + CPRINTS("%sUSB4 Gen1/2", db_type_prefix); + break; + case DB_USB4_GEN3: + CPRINTS("%sUSB4 Gen3", db_type_prefix); + break; + case DB_USB3_ACTIVE: + config_db_usb3_active(); + CPRINTS("%sUSB3 Active", db_type_prefix); + break; + case DB_USB3_PASSIVE: + config_db_usb3_passive(); + CPRINTS("%sUSB3 Passive", db_type_prefix); + break; + default: + CPRINTS("%sID %d not supported", db_type_prefix, usb_db); + } +} + +/******************************************************************************/ +/* USBC PPC configuration */ +struct ppc_config_t ppc_chips[] = { + [USBC_PORT_C0] = { + .i2c_port = I2C_PORT_USB_C0, + .i2c_addr_flags = SN5S330_ADDR0_FLAGS, + .drv = &sn5s330_drv, + }, + [USBC_PORT_C1] = { + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = SYV682X_ADDR0_FLAGS, + .drv = &syv682x_drv, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(ppc_chips) == USBC_PORT_COUNT); +unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); + +/******************************************************************************/ +/* PPC support routines */ +void ppc_interrupt(enum gpio_signal signal) +{ + switch (signal) { + case GPIO_USB_C0_PPC_INT_ODL: + sn5s330_interrupt(USBC_PORT_C0); + break; + case GPIO_USB_C1_PPC_INT_ODL: + syv682x_interrupt(USBC_PORT_C1); + default: + break; + } +} |