diff options
author | hao.zhou <hao.zhou3@bitland.corp-partner.google.com> | 2020-07-14 19:30:58 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-07-15 05:23:30 +0000 |
commit | 29f5f79610663bafb208b7251488e00461470f1b (patch) | |
tree | ab3e4eff23c0153df2b8c297da473bac25b3b5f2 /board/lingcod/board.c | |
parent | 3e34235c49b59b9dd55d76158dd706350a76f776 (diff) | |
download | chrome-ec-29f5f79610663bafb208b7251488e00461470f1b.tar.gz |
lingcod: Initial EC image
Create the initial EC image for the lingcod variant by copying the
malefor reference board EC files into a new directory named for
the variant.
(Auto-Generated by create_initial_ec_image.sh version 1.0.3).
BUG=b:161103776
BRANCH=none
TEST=make BOARD=lingcod
Signed-off-by: hao.zhou <hao.zhou3@bitland.corp-partner.google.com>
Change-Id: I8b1d7f2deff74dfac5bcb8f32684c53448fff576
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2297073
Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'board/lingcod/board.c')
-rw-r--r-- | board/lingcod/board.c | 353 |
1 files changed, 353 insertions, 0 deletions
diff --git a/board/lingcod/board.c b/board/lingcod/board.c new file mode 100644 index 0000000000..5841ea0385 --- /dev/null +++ b/board/lingcod/board.c @@ -0,0 +1,353 @@ +/* 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. + */ + +/* Malefor board-specific configuration */ + +#include "button.h" +#include "cbi_ec_fw_config.h" +#include "common.h" +#include "driver/accel_lis2dh.h" +#include "driver/accelgyro_lsm6dsm.h" +#include "driver/ppc/sn5s330.h" +#include "driver/ppc/syv682x.h" +#include "driver/sync.h" +#include "extpower.h" +#include "fan.h" +#include "fan_chip.h" +#include "gpio.h" +#include "hooks.h" +#include "keyboard_scan.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 "uart.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) +#define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args) + +/* + * FW_CONFIG defaults for Malefor if the CBI data is not initialized. + */ +union volteer_cbi_fw_config fw_config_defaults = { + .usb_db = DB_USB3_NO_A, +}; + +static void board_init(void) +{ + if (ec_cfg_has_tabletmode()) { + /* Enable gpio interrupt for base accelgyro sensor */ + gpio_enable_interrupt(GPIO_EC_IMU_INT_L); + } else { + motion_sensor_count = 0; + /* Device is clamshell only */ + tablet_set_mode(0); + /* Gyro is not present, don't allow line to float */ + gpio_set_flags(GPIO_EC_IMU_INT_L, GPIO_INPUT | GPIO_PULL_DOWN); + } + + /* + * TODO: b/154447182 - Malefor will control power LED and battery LED + * independently, and keep the max brightness of power LED and battery + * LED as 50%. + */ + pwm_enable(PWM_CH_LED4_SIDESEL, 1); + pwm_set_duty(PWM_CH_LED4_SIDESEL, 50); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); + +int board_is_lid_angle_tablet_mode(void) +{ + return ec_cfg_has_tabletmode(); +} + +/* Enable or disable input devices, based on tablet mode or chipset state */ +#ifndef TEST_BUILD +void lid_angle_peripheral_enable(int enable) +{ + if (ec_cfg_has_tabletmode()) { + if (chipset_in_state(CHIPSET_STATE_ANY_OFF) || + tablet_get_mode()) + enable = 0; + keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE); + } +} +#endif + +/******************************************************************************/ +/* Sensors */ +/* Lid and base Sensor mutex */ +static struct mutex g_lid_accel_mutex; +static struct mutex g_base_mutex; + +/* Lid and base accel private data */ +static struct stprivate_data g_lis2dh_data; +static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA; + +/* Matrix to rotate lid and base sensor into standard reference frame */ +static const mat33_fp_t lid_standard_ref = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(1), 0, 0}, + { 0, 0, FLOAT_TO_FP(-1)} +}; + +static const mat33_fp_t base_standard_ref = { + { FLOAT_TO_FP(1), 0, 0}, + { 0, FLOAT_TO_FP(-1), 0}, + { 0, 0, FLOAT_TO_FP(-1)} +}; + +struct motion_sensor_t motion_sensors[] = { + [LID_ACCEL] = { + .name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_LIS2DE, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &lis2dh_drv, + .mutex = &g_lid_accel_mutex, + .drv_data = &g_lis2dh_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = LIS2DH_ADDR1_FLAGS, + .rot_standard_ref = &lid_standard_ref, + .min_frequency = LIS2DH_ODR_MIN_VAL, + .max_frequency = LIS2DH_ODR_MAX_VAL, + .default_range = 2, /* g, to support tablet mode */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, + }, + + [BASE_ACCEL] = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_LSM6DSM, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &lsm6dsm_drv, + .mutex = &g_base_mutex, + .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data, + MOTIONSENSE_TYPE_ACCEL), + .int_signal = GPIO_EC_IMU_INT_L, + .flags = MOTIONSENSE_FLAG_INT_SIGNAL, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, + .rot_standard_ref = &base_standard_ref, + .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */ + .min_frequency = LSM6DSM_ODR_MIN_VAL, + .max_frequency = LSM6DSM_ODR_MAX_VAL, + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 13000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* Sensor on for angle detection */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + }, + }, + + [BASE_GYRO] = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_LSM6DSM, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &lsm6dsm_drv, + .mutex = &g_base_mutex, + .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data, + MOTIONSENSE_TYPE_GYRO), + .int_signal = GPIO_EC_IMU_INT_L, + .flags = MOTIONSENSE_FLAG_INT_SIGNAL, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, + .default_range = 1000 | ROUND_UP_FLAG, /* dps */ + .rot_standard_ref = &base_standard_ref, + .min_frequency = LSM6DSM_ODR_MIN_VAL, + .max_frequency = LSM6DSM_ODR_MAX_VAL, + }, +}; +unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); + +/******************************************************************************/ +/* 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_POWER_SCL, + .sda = GPIO_EC_I2C5_POWER_SDA, + }, + { + .name = "eeprom", + .port = I2C_PORT_EEPROM, + .kbps = 400, + .scl = GPIO_EC_I2C7_EEPROM_SCL, + .sda = GPIO_EC_I2C7_EEPROM_SDA, + }, +}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +/******************************************************************************/ +/* PWM configuration */ +const struct pwm_t pwm_channels[] = { + [PWM_CH_LED4_SIDESEL] = { + .channel = 7, + .flags = PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP, + /* Run at a higher frequency than the color PWM signals to avoid + * timing-based color shifts. + */ + .freq = 4800, + }, + [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); + +void board_reset_pd_mcu(void) +{ + /* TODO(b/159024035): Malefor: check USB PD reset operation */ +} + +__override void board_cbi_init(void) +{ + /* TODO(b/159024035): Malefor: check FW_CONFIG fields for USB DB type */ +} + +/******************************************************************************/ +/* 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; + } +} + |