diff options
author | SolonFan <solonfan@ami.com.cn> | 2016-02-15 15:41:58 +0800 |
---|---|---|
committer | ChromeOS bot <3su6n15k.default@developer.gserviceaccount.com> | 2016-02-22 02:00:40 +0000 |
commit | fc9220224ccfbd2400b7a48cdbc3b14409fcde5a (patch) | |
tree | 0280b7eeb725d8a96255c63f5f92ccda1d2bec7e | |
parent | 84c5169b10576536ee8df93bf086da632b18b457 (diff) | |
download | chrome-ec-fc9220224ccfbd2400b7a48cdbc3b14409fcde5a.tar.gz |
Umaro: Init EC code for umaro
Clone from Strago with only string changes
BUG=None
TEST='make buildall -j'
BRANCH=firmware-strago-7287.B
Change-Id: I8cd3f27cffccfa20c9529d8e9462aa0ba49afe46
Signed-off-by: SolonFan <solonfan@ami.com.cn>
Reviewed-on: https://chromium-review.googlesource.com/327442
Reviewed-by: Shawn N <shawnn@chromium.org>
l--------- | board/umaro/Makefile | 1 | ||||
-rw-r--r-- | board/umaro/battery.c | 43 | ||||
-rw-r--r-- | board/umaro/board.c | 250 | ||||
-rw-r--r-- | board/umaro/board.h | 151 | ||||
-rw-r--r-- | board/umaro/build.mk | 14 | ||||
-rw-r--r-- | board/umaro/ec.tasklist | 29 | ||||
-rw-r--r-- | board/umaro/gpio.inc | 150 | ||||
-rw-r--r-- | board/umaro/led.c | 210 | ||||
-rw-r--r-- | board/umaro/lfw/gpio.inc | 16 |
9 files changed, 864 insertions, 0 deletions
diff --git a/board/umaro/Makefile b/board/umaro/Makefile new file mode 120000 index 0000000000..94aaae2c4d --- /dev/null +++ b/board/umaro/Makefile @@ -0,0 +1 @@ +../../Makefile
\ No newline at end of file diff --git a/board/umaro/battery.c b/board/umaro/battery.c new file mode 100644 index 0000000000..24d3753107 --- /dev/null +++ b/board/umaro/battery.c @@ -0,0 +1,43 @@ +/* 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" + +/* Shutdown mode parameter to write to manufacturer access register */ +#define SB_SHUTDOWN_DATA 0x0010 + +static const struct battery_info info = { + .voltage_max = 8700,/* mV */ + .voltage_normal = 7600, + .voltage_min = 6000, + .precharge_current = 150,/* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 45, + .discharging_min_c = -20, + .discharging_max_c = 60, +}; + +const struct battery_info *battery_get_info(void) +{ + return &info; +} + +int board_cut_off_battery(void) +{ + int rv; + + /* Ship mode command must be sent twice to take effect */ + rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); + + if (rv != EC_SUCCESS) + return rv; + + return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); +} diff --git a/board/umaro/board.c b/board/umaro/board.c new file mode 100644 index 0000000000..51bb2aabff --- /dev/null +++ b/board/umaro/board.c @@ -0,0 +1,250 @@ +/* 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. + */ +/* Umaro board-specific configuration */ + +#include "adc.h" +#include "als.h" +#include "button.h" +#include "charger.h" +#include "charge_state.h" +#include "driver/accel_kxcj9.h" +#include "driver/als_isl29035.h" +#include "driver/gyro_l3gd20h.h" +#include "driver/temp_sensor/tmp432.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "host_command.h" +#include "i2c.h" +#include "lid_switch.h" +#include "math_util.h" +#include "motion_lid.h" +#include "motion_sense.h" +#include "power.h" +#include "power_button.h" +#include "pwm.h" +#include "pwm_chip.h" +#include "registers.h" +#include "temp_sensor.h" +#include "temp_sensor_chip.h" +#include "thermal.h" +#include "uart.h" +#include "util.h" + +#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP) +#define GPIO_KB_OUTPUT (GPIO_ODR_HIGH) +#define GPIO_KB_OUTPUT_COL2 (GPIO_OUT_LOW) + +#include "gpio_list.h" + +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ +const struct pwm_t pwm_channels[] = { + {0, PWM_CONFIG_ACTIVE_LOW}, + {1, PWM_CONFIG_ACTIVE_LOW}, + {3, PWM_CONFIG_ACTIVE_LOW}, +}; + +BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); + +/* power signal list. Must match order of enum power_signal. */ +const struct power_signal_info power_signal_list[] = { + {GPIO_ALL_SYS_PGOOD, 1, "ALL_SYS_PWRGD"}, + {GPIO_RSMRST_L_PGOOD, 1, "RSMRST_N_PWRGD"}, + {GPIO_PCH_SLP_S3_L, 1, "SLP_S3#_DEASSERTED"}, + {GPIO_PCH_SLP_S4_L, 1, "SLP_S4#_DEASSERTED"}, +}; +BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT); + +const struct i2c_port_t i2c_ports[] = { + {"batt_chg", MEC1322_I2C0_0, 100, + GPIO_I2C_PORT0_0_SCL, GPIO_I2C_PORT0_0_SDA}, + {"muxes", MEC1322_I2C0_1, 100, + GPIO_I2C_PORT0_1_SCL, GPIO_I2C_PORT0_1_SDA}, + {"pd_mcu", MEC1322_I2C1, 1000, + GPIO_I2C_PORT1_SCL, GPIO_I2C_PORT1_SDA}, + {"sensors", MEC1322_I2C2, 100, + GPIO_I2C_PORT2_SCL, GPIO_I2C_PORT2_SDA}, + {"thermal", MEC1322_I2C3, 100, + GPIO_I2C_PORT3_SCL, GPIO_I2C_PORT3_SDA} +}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +const enum gpio_signal hibernate_wake_pins[] = { + GPIO_POWER_BUTTON_L, +}; + +const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); + +/* + * Temperature sensors data; must be in same order as enum temp_sensor_id. + * Sensor index and name must match those present in coreboot: + * src/mainboard/google/${board}/acpi/dptf.asl + */ +const struct temp_sensor_t temp_sensors[] = { + {"TMP432_Internal", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val, + TMP432_IDX_LOCAL, 4}, + {"TMP432_Sensor_1", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val, + TMP432_IDX_REMOTE1, 4}, + {"TMP432_Sensor_2", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val, + TMP432_IDX_REMOTE2, 4}, + {"Battery", TEMP_SENSOR_TYPE_BATTERY, charge_temp_sensor_get_val, + 0, 4}, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + +/* ALS instances. Must be in same order as enum als_id. */ +struct als_t als[] = { + {"ISL", isl29035_read_lux, 5}, +}; +BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); + +/* Thermal limits for each temp sensor. All temps are in degrees K. Must be in + * same order as enum temp_sensor_id. To always ignore any temp, use 0. + */ +struct ec_thermal_config thermal_params[] = { + {{0, 0, 0}, 0, 0}, /* TMP432_Internal */ + {{0, 0, 0}, 0, 0}, /* TMP432_Sensor_1 */ + {{0, 0, 0}, 0, 0}, /* TMP432_Sensor_2 */ + {{0, 0, 0}, 0, 0}, /* Battery Sensor */ +}; +BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); + +const struct button_config buttons[] = { + {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN, + 30 * MSEC, 0}, + {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP, + 30 * MSEC, 0}, +}; +BUILD_ASSERT(ARRAY_SIZE(buttons) == CONFIG_BUTTON_COUNT); + +/* Four Motion sensors */ +/* kxcj9 mutex and local/private data*/ +static struct mutex g_kxcj9_mutex[2]; +struct kxcj9_data g_kxcj9_data[2]; + +#ifdef CONFIG_GYRO_L3GD20H +/* Gyro sensor */ +/* l3gd20h mutex and local/private data*/ +static struct mutex g_l3gd20h_mutex; +struct l3gd20_data g_l3gd20h_data; +#endif + +/* 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 motion_sensor_t motion_sensors[] = { + {.name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &kxcj9_drv, + .mutex = &g_kxcj9_mutex[0], + .drv_data = &g_kxcj9_data[0], + .i2c_addr = KXCJ9_ADDR1, + .rot_standard_ref = &base_standard_ref, + .default_config = { + .odr = 100000, + .range = 2, + .ec_rate = SUSPEND_SAMPLING_INTERVAL, + } + }, + {.name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KXCJ9, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &kxcj9_drv, + .mutex = &g_kxcj9_mutex[1], + .drv_data = &g_kxcj9_data[1], + .i2c_addr = KXCJ9_ADDR0, + .rot_standard_ref = &lid_standard_ref, + .default_config = { + .odr = 100000, + .range = 2, + .ec_rate = SUSPEND_SAMPLING_INTERVAL, + } + }, +#ifdef CONFIG_GYRO_L3GD20H + {.name = "Lid Gyro", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_L3GD20H, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_LID, + .drv = &l3gd20h_drv, + .mutex = &g_l3gd20h_mutex, + .drv_data = &g_l3gd20h_data, + .i2c_addr = L3GD20_ADDR1, + .rot_standard_ref = NULL, + .default_config = { + .odr = 190000, + .range = 2000, + .ec_rate = SUSPEND_SAMPLING_INTERVAL, + } + }, +#endif +}; +const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); + +/* Define the accelerometer orientation matrices. */ +const struct accel_orientation acc_orient = { + /* Hinge aligns with x axis. */ + .rot_hinge_90 = { + { FLOAT_TO_FP(1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)}, + { 0, FLOAT_TO_FP(-1), 0} + }, + .rot_hinge_180 = { + { FLOAT_TO_FP(1), 0, 0}, + { 0, FLOAT_TO_FP(-1), 0}, + { 0, 0, FLOAT_TO_FP(-1)} + }, + .hinge_axis = {1, 0, 0}, +}; + +/* + * In S3, power rail for sensors (+V3p3S) goes down asynchronous to EC. We need + * to execute this routine first and set the sensor state to "Not Initialized". + * This prevents the motion_sense_suspend hook routine from communicating with + * the sensor. + */ +static void motion_sensors_pre_init(void) +{ + struct motion_sensor_t *sensor; + int i; + + for (i = 0; i < motion_sensor_count; ++i) { + sensor = &motion_sensors[i]; + sensor->state = SENSOR_NOT_INITIALIZED; + + sensor->runtime_config.odr = sensor->default_config.odr; + sensor->runtime_config.range = sensor->default_config.range; + } +} +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, motion_sensors_pre_init, + MOTION_SENSE_HOOK_PRIO - 1); + +/* init ADC ports to avoid floating state due to thermistors */ +static void adc_pre_init(void) +{ + /* Configure GPIOs */ + gpio_config_module(MODULE_ADC, 1); +} +DECLARE_HOOK(HOOK_INIT, adc_pre_init, HOOK_PRIO_INIT_ADC - 1); + +int i2c_port_is_smbus(int port) +{ + return (port == MEC1322_I2C0_0 || port == MEC1322_I2C0_1) ? 1 : 0; +} diff --git a/board/umaro/board.h b/board/umaro/board.h new file mode 100644 index 0000000000..cee05d0224 --- /dev/null +++ b/board/umaro/board.h @@ -0,0 +1,151 @@ +/* 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. + */ + +/* Umaro board configuration */ + +#ifndef __CROS_EC_BOARD_H +#define __CROS_EC_BOARD_H + +/* Optional features */ +#define CONFIG_WATCHDOG_HELP +#define CONFIG_CLOCK_CRYSTAL +#define CONFIG_CHIPSET_BRASWELL +#define CONFIG_SCI_GPIO GPIO_PCH_SCI_L + +#define CONFIG_BOARD_VERSION + +#define CONFIG_KEYBOARD_COL2_INVERTED +#define CONFIG_KEYBOARD_IRQ_GPIO GPIO_KBD_IRQ_L +#undef CONFIG_KEYBOARD_KSO_BASE +#define CONFIG_KEYBOARD_KSO_BASE 4 /* KSO starts from KSO04 */ +#define CONFIG_KEYBOARD_PROTOCOL_8042 +#define CONFIG_POWER_BUTTON +#define CONFIG_POWER_BUTTON_X86 +#define CONFIG_LID_SWITCH +#define CONFIG_LOW_POWER_IDLE +#define CONFIG_LOW_POWER_PSEUDO_G3 +#define CONFIG_POWER_COMMON +#define CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5 +#define CONFIG_EXTPOWER_GPIO +#define CONFIG_VBOOT_HASH +#define CONFIG_PORT80_TASK_EN +#define CONFIG_WIRELESS + +#define CONFIG_SPI_PORT 1 +#define CONFIG_SPI_CS_GPIO GPIO_PVT_CS0 +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_SIZE 524288 +#define CONFIG_SPI_FLASH_W25Q64 + +#define CONFIG_USB_PORT_POWER_SMART +#define CONFIG_USB_PORT_POWER_SMART_SIMPLE + +#define CONFIG_TEMP_SENSOR +#define CONFIG_TEMP_SENSOR_TMP432 + +#define CONFIG_PMIC + +#define CONFIG_ALS +#define CONFIG_ALS_ISL29035 +#define CONFIG_BATTERY_CUT_OFF +#define CONFIG_BATTERY_PRESENT_GPIO GPIO_BAT_PRESENT_L +#define CONFIG_BATTERY_SMART +#define CONFIG_CHARGER +#define CONFIG_CHARGER_V2 +#define CONFIG_CHARGER_BQ24770 +#define CONFIG_CHARGER_ILIM_PIN_DISABLED +#define CONFIG_CHARGER_SENSE_RESISTOR 10 +#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10 +#define CONFIG_CHARGER_INPUT_CURRENT 2240 +#define CONFIG_CHARGER_DISCHARGE_ON_AC + +#define CONFIG_PWM +#define CONFIG_LED_COMMON + +#define CONFIG_I2C + +/* Accelerometer */ +#define CONFIG_ACCEL_KXCJ9 +#define CONFIG_CMD_ACCELS +#define CONFIG_CMD_ACCEL_INFO +#define CONFIG_LID_ANGLE +#define CONFIG_LID_ANGLE_SENSOR_BASE 0 +#define CONFIG_LID_ANGLE_SENSOR_LID 1 + +/* Wireless signals */ +#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L + +/* Number of buttons */ +#define CONFIG_BUTTON_COUNT 2 + +/* Modules we want to exclude */ +#undef CONFIG_EEPROM +#undef CONFIG_EOPTION +#undef CONFIG_PSTORE +#undef CONFIG_PECI +#undef CONFIG_FANS +#undef CONFIG_ADC +#ifndef __ASSEMBLER__ + +#include "gpio_signal.h" +#include "registers.h" + +/* I2C ports */ +#define I2C_PORT_BATTERY MEC1322_I2C0_0 +#define I2C_PORT_CHARGER MEC1322_I2C0_0 +#define I2C_PORT_PD_MCU MEC1322_I2C1 +#define I2C_PORT_TCPC MEC1322_I2C1 +#define I2C_PORT_ACCEL MEC1322_I2C2 +#define I2C_PORT_GYRO MEC1322_I2C2 +#define I2C_PORT_ALS MEC1322_I2C2 +#define I2C_PORT_THERMAL MEC1322_I2C3 + +/* ADC signal */ +enum adc_channel { + /* Number of ADC channels */ + ADC_CH_COUNT +}; + +/* power signal definitions */ +enum power_signal { + X86_ALL_SYS_PWRGD = 0, + X86_RSMRST_L_PWRGD, + X86_SLP_S3_DEASSERTED, + X86_SLP_S4_DEASSERTED, + + /* Number of X86 signals */ + POWER_SIGNAL_COUNT +}; + +enum pwm_channel { + PWM_CH_LED_RED, + PWM_CH_LED_BLUE, + PWM_CH_LED_GREEN, + /* Number of PWM channels */ + PWM_CH_COUNT +}; + +enum temp_sensor_id { + /* TMP432 local and remote sensors */ + TEMP_SENSOR_I2C_TMP432_LOCAL, + TEMP_SENSOR_I2C_TMP432_REMOTE1, + TEMP_SENSOR_I2C_TMP432_REMOTE2, + + /* Battery temperature sensor */ + TEMP_SENSOR_BATTERY, + + TEMP_SENSOR_COUNT +}; + +/* Light sensors */ +enum als_id { + ALS_ISL29035 = 0, + + ALS_COUNT, +}; + +#endif /* !__ASSEMBLER__ */ + +#endif /* __CROS_EC_BOARD_H */ diff --git a/board/umaro/build.mk b/board/umaro/build.mk new file mode 100644 index 0000000000..45d6d79856 --- /dev/null +++ b/board/umaro/build.mk @@ -0,0 +1,14 @@ +# -*- makefile -*- +# 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. +# +# Board specific files build +# + +# the IC is SMSC MEC1322 / external SPI is 4MB / external clock is crystal +CHIP:=mec1322 +CHIP_SPI_SIZE_KB:=512 + +board-y=board.o led.o +board-$(CONFIG_BATTERY_SMART)+=battery.o diff --git a/board/umaro/ec.tasklist b/board/umaro/ec.tasklist new file mode 100644 index 0000000000..faa2d681c9 --- /dev/null +++ b/board/umaro/ec.tasklist @@ -0,0 +1,29 @@ +/* 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 + */ +#define CONFIG_TASK_LIST \ + TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_NOTEST(PORT80, port80_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(POWERBTN, power_button_task, NULL, TASK_STACK_SIZE) \ + TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) diff --git a/board/umaro/gpio.inc b/board/umaro/gpio.inc new file mode 100644 index 0000000000..54fad05df3 --- /dev/null +++ b/board/umaro/gpio.inc @@ -0,0 +1,150 @@ +/* -*- 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. + */ + +GPIO_INT(LID_OPEN, PIN(27), GPIO_INT_BOTH | GPIO_PULL_UP, lid_interrupt) /* Lid switch */ +GPIO_INT(AC_PRESENT, PIN(30), GPIO_INT_BOTH | GPIO_PULL_UP | GPIO_PULL_DOWN, extpower_interrupt) /* BC_ACOK / EC_ACIN - to know if battery or AC connected */ +#ifdef CONFIG_BUTTON_COUNT +GPIO_INT(VOLUME_UP, PIN(31), GPIO_INT_BOTH, button_interrupt) /* Volume up button */ +GPIO_INT(VOLUME_DOWN, PIN(34), GPIO_INT_BOTH, button_interrupt) /* Volume down button */ +#endif +GPIO_INT(POWER_BUTTON_L, PIN(35), GPIO_INT_BOTH, power_button_interrupt) /* Power button */ +GPIO_INT(RSMRST_L_PGOOD, PIN(63), GPIO_INT_BOTH, power_signal_interrupt) /* RSMRST_N_PWRGD from power logic */ +GPIO_INT(ALL_SYS_PGOOD, PIN(130), GPIO_INT_BOTH, power_signal_interrupt) /* ALL_SYS_PWRGD from power logic */ +#ifdef CONFIG_LOW_POWER_IDLE +GPIO_INT(UART0_RX, PIN(162), GPIO_INT_BOTH_DSLEEP | GPIO_PULL_UP, uart_deepsleep_interrupt) /* UART0 RX input */ +#else +GPIO_INT(UART0_RX, PIN(162), GPIO_INPUT | GPIO_PULL_UP, NULL) /* UART0 RX input */ +#endif +GPIO_INT(PCH_SLP_S4_L, PIN(200), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S4# signal from PCH */ +GPIO_INT(PCH_SLP_S3_L, PIN(206), GPIO_INT_BOTH, power_signal_interrupt) /* SLP_S3# signal from PCH */ + +GPIO(BOARD_VERSION2, PIN(0), GPIO_INPUT) /* BOARD_ID1 */ +GPIO(KBD_KSO2, PIN(1), GPIO_KB_OUTPUT_COL2) /* Negative edge triggered irq. */ + +GPIO(NC_USBPD_BOOT0, PIN(12), GPIO_INPUT | GPIO_PULL_DOWN) /* NC */ +GPIO(USB_ILIM_SEL, PIN(13), GPIO_OUT_HIGH) /* USB current control */ +GPIO(I2C_PORT0_0_SCL, PIN(15), GPIO_INPUT) +GPIO(I2C_PORT0_0_SDA, PIN(16), GPIO_INPUT) +GPIO(I2C_PORT0_1_SCL, PIN(134), GPIO_INPUT) +GPIO(I2C_PORT0_1_SDA, PIN(17), GPIO_INPUT) +GPIO(I2C_PORT1_SCL, PIN(22), GPIO_INPUT) +GPIO(I2C_PORT1_SDA, PIN(23), GPIO_INPUT) +GPIO(I2C_PORT2_SCL, PIN(20), GPIO_INPUT) +GPIO(I2C_PORT2_SDA, PIN(21), GPIO_INPUT) +GPIO(I2C_PORT3_SCL, PIN(24), GPIO_INPUT) +GPIO(I2C_PORT3_SDA, PIN(25), GPIO_INPUT) +GPIO(PCH_SCI_L, PIN(26), GPIO_ODR_HIGH) /* SCI output */ + +#ifndef CONFIG_BUTTON_COUNT +GPIO(VOLUME_UP, PIN(31), GPIO_INPUT) /* Volume up button */ +#endif +GPIO(WP_L, PIN(33), GPIO_INPUT) /* EC_SPI_WP_ME_L */ +#ifndef CONFIG_BUTTON_COUNT +GPIO(VOLUME_DOWN, PIN(34), GPIO_INPUT) /* Volume down button */ +#endif +GPIO(USB2_ENABLE, PIN(36), GPIO_OUT_LOW) /* Enable power for USB2 Port */ + +GPIO(ENTERING_RW, PIN(41), GPIO_OUT_LOW) /* Indicate when EC is entering RW code */ +GPIO(PCH_SMI_L, PIN(44), GPIO_ODR_HIGH) /* SMI output */ +GPIO(USB_OC1_L, PIN(45), GPIO_INT_FALLING) /* DB2 BC1.2 over current signal to EC */ +GPIO(DP_USB_C_HPD_Q, PIN(46), GPIO_OUT_HIGH) /* DP hot plug detect from EC to SOC */ + +GPIO(OTG_SW_EN, PIN(50), GPIO_OUT_LOW) /* */ +GPIO(PCH_SUS_STAT_L, PIN(51), GPIO_INT_FALLING) /* Signal to inform EC that SOC is entering low power state */ +GPIO(EC_ACDET_CTRL, PIN(52), GPIO_INPUT | GPIO_PULL_UP) +GPIO(TRACKPAD_PWREN, PIN(53), GPIO_OUT_HIGH) /* Enable power for Track Pad */ +GPIO(USB_OC0_L, PIN(55), GPIO_INT_FALLING) /* Over current signal of the BC1.2 charger to EC */ +GPIO(EC_ADC1, PIN(57), GPIO_INPUT) /* EC_ADC1, TEMP_SENSOR_2 no_stuff */ + +GPIO(EC_ADC0, PIN(61), GPIO_INPUT) /* EC_ADC0 */ +GPIO(EC_HIB_L, PIN(64), GPIO_OUT_LOW) /* Set to high before Pseduo G3 */ +GPIO(PCH_SYS_PWROK, PIN(65), GPIO_OUT_LOW) /* EC thinks everything is up and ready (DELAY_ALL_SYS_PWRGD) */ +GPIO(PCH_WAKE_L, PIN(66), GPIO_ODR_HIGH) /* PCH wake pin */ +GPIO(USB1_ENABLE, PIN(67), GPIO_OUT_LOW) /* Enable power for USB3 Port */ + +GPIO(NC_GPIO100, PIN(100), GPIO_INPUT | GPIO_PULL_UP) /* NC */ +GPIO(NC_GPIO101, PIN(101), GPIO_INPUT | GPIO_PULL_UP) /* NC */ +GPIO(BOARD_VERSION3, PIN(102), GPIO_INPUT) /* BOARD_ID2 */ +GPIO(USB_CTL1, PIN(105), GPIO_OUT_HIGH) /* USB charging mode control */ + +GPIO(PCH_RCIN_L, PIN(110), GPIO_ODR_HIGH) /* Reset line to PCH (for 8042 emulation) */ +GPIO(NC_115, PIN(115), GPIO_INPUT | GPIO_PULL_UP) /* NC */ +GPIO(EC_VNN_VCLK, PIN(122), GPIO_INPUT | GPIO_PULL_UP) /* Interrupt from USB PD Controller to EC */ +GPIO(STRAP_L, PIN(123), GPIO_OUT_LOW) +GPIO(EC_VNN_ALERT_L, PIN(124), GPIO_INPUT | GPIO_PULL_UP) +GPIO(GYRO_INT2, PIN(127), GPIO_INPUT | GPIO_PULL_DOWN) /* Gyro sensor interrupt 2 to EC */ + +GPIO(EC_PLUG_DETECT, PIN(132), GPIO_INT_BOTH | GPIO_PULL_UP | GPIO_PULL_DOWN) +GPIO(PD_RST_L, PIN(135), GPIO_ODR_HIGH) /* USB PD MCU reset */ + +GPIO(THERMAL_PROBE_EN_L,PIN(140), GPIO_OUT_HIGH) +GPIO(PCH_RSMRST_L, PIN(143), GPIO_OUT_LOW) /* RSMRST_N to PCH */ +GPIO(EC_KBD_ALERT, PIN(145), GPIO_OUT_LOW) /* EC_KBD_ALERT */ +GPIO(PVT_CS0, PIN(146), GPIO_ODR_HIGH) /* SPI PVT Chip select */ +GPIO(ALS_INT, PIN(147), GPIO_INPUT | GPIO_PULL_UP) /* ALS sensor interrupt to EC */ + +GPIO(WLAN_OFF_L, PIN(150), GPIO_ODR_HIGH) /* Wireless LAN */ +GPIO(CPU_PROCHOT, PIN(151), GPIO_OUT_LOW) +GPIO(KBD_IRQ_L, PIN(152), GPIO_ODR_HIGH) /* Negative edge triggered irq. */ +GPIO(BOARD_VERSION1, PIN(154), GPIO_INPUT) /* BOARD_ID0 */ +GPIO(EC_PERICOM_INT, PIN(155), GPIO_INT_BOTH) /* Pericom USB device interrupt */ +GPIO(PWR_BTN_SELECT, PIN(156), GPIO_ODR_HIGH) /* HIGH in clamshell mode and LOW in tablet mode */ +GPIO(PCH_SUSPWRDNACK, PIN(157), GPIO_INT_FALLING) /* PMC SUSPWRDNACK signal from SOC to EC */ + +GPIO(PCH_PWRBTN_L, PIN(160), GPIO_OUT_HIGH) /* Power button output to PCH */ +GPIO(GYRO_INT1, PIN(161), GPIO_INPUT | GPIO_PULL_DOWN) /* Gyro sensor interrupt 1 to EC */ +GPIO(VP9_CODEC_RESET_L, PIN(163), GPIO_OUT_LOW) /* VP9_CODEC_RESET_L, OUTPUT, ACTIVE LOW */ + +GPIO(STARTUP_LATCH_SET, PIN(201), GPIO_INPUT) /* Not used in BCRD2. Programmed as Input to fix EC power leakage in S3*/ +GPIO(EC_BL_DISABLE_L, PIN(202), GPIO_OUT_HIGH) /* EDP backligh disable signal from EC */ +GPIO(SMC_SHUTDOWN, PIN(203), GPIO_OUT_LOW) /* Shutdown signal from EC to power sequencing PLD */ +GPIO(USBPD_BST_OFF, PIN(204), GPIO_OUT_LOW) + +GPIO(BAT_PRESENT_L, PIN(210), GPIO_INPUT) /* HW detection signal from battery to EC */ +GPIO(GPIO_3_EC, PIN(211), GPIO_OUT_LOW) /* Sleep SOIX signal from SOC to EC */ + +/* Alternate functions GPIO definition */ +ALTERNATE(PIN_MASK(16, 0x24), 1, MODULE_UART, 0) /* UART0 */ + +ALTERNATE(PIN_MASK(1, 0x60), 2, MODULE_I2C, GPIO_OPEN_DRAIN) /* I2C0: Battery Charger */ +ALTERNATE(PIN_MASK(2, 0x3f), 2, MODULE_I2C, GPIO_OPEN_DRAIN) /* I2C1: Temp Sensor / I2C2: SOC / I2C3: VNN */ + +ALTERNATE(PIN_MASK(0, 0xfc), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) +ALTERNATE(PIN_MASK(1, 0x03), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) +ALTERNATE(PIN_MASK(10, 0xd8), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_OUTPUT) +ALTERNATE(PIN_MASK(3, 0x04), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) +ALTERNATE(PIN_MASK(4, 0x0d), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) +ALTERNATE(PIN_MASK(12, 0x60), 2, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) +ALTERNATE(PIN_MASK(14, 0x14), 3, MODULE_KEYBOARD_SCAN, GPIO_KB_INPUT) + +ALTERNATE(PIN_MASK(1, 0x10), 0, MODULE_LPC, GPIO_ODR_HIGH) /* 14: LPC CLKRUN - Program as GPIO for power saving */ +ALTERNATE(PIN_MASK(11, 0x9e), 1, MODULE_LPC, 0) /* 111~114:LAD[0:3], 117:PCI_CLK */ +ALTERNATE(PIN_MASK(11, 0x40), 1, MODULE_LPC, GPIO_INT_BOTH) /* 116: LRESET# */ +ALTERNATE(PIN_MASK(12, 0x01), 1, MODULE_LPC, 0) /* 120: LFRAME# */ + +ALTERNATE(PIN_MASK(5, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(16, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(15, 0x08), 1, MODULE_SPI, 0) /* 153: CLK */ + +ALTERNATE(PIN_MASK(13, 0x48), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 133: PWM0, 136: PWM1 */ +ALTERNATE(PIN_MASK(14, 0x02), 1, MODULE_PWM_LED, GPIO_OUTPUT) /* 141: PWM3 */ +ALTERNATE(PIN_MASK(5, 0x40), 1, MODULE_ADC, 0) /* 56: temperature sensor 1 */ +ALTERNATE(PIN_MASK(6, 0x05), 1, MODULE_ADC, 0) /* 60: PC_MON, 62: temperature sensor 3 */ + +/* Re-Config LPC Pins to GPIO Open Drain for SOC G3 (EC - POWER_G3) state */ +ALTERNATE(PIN_MASK(1, 0x10), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 14: LPC CLKRUN */ +ALTERNATE(PIN_MASK(11, 0x9e), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 111~114:LAD[0:3], 117:PCI_CLK */ +ALTERNATE(PIN_MASK(11, 0x40), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 116: LRESET# */ +ALTERNATE(PIN_MASK(12, 0x01), 0, MODULE_GPIO, GPIO_ODR_HIGH) /* 120: LFRAME# */ + +/* I2C pins */ +/* I2C0_0 CLK - GPIO015, I2C0_0 DAT - GPIO016, I2C0_1 DAT - GPIO017 */ +ALTERNATE(PIN_MASK(1, 0xe0), 2, MODULE_I2C, GPIO_ODR_HIGH) +/* I2C0_1 CLK - GPIO134 */ +ALTERNATE(PIN_MASK(13, 0x10), 2, MODULE_I2C, GPIO_ODR_HIGH) +/* I2C{1,2,3} CLK / DAT - GPIO022-GPIO025*/ +ALTERNATE(PIN_MASK(2, 0x3f), 2, MODULE_I2C, GPIO_ODR_HIGH) diff --git a/board/umaro/led.c b/board/umaro/led.c new file mode 100644 index 0000000000..cecd44580e --- /dev/null +++ b/board/umaro/led.c @@ -0,0 +1,210 @@ +/* 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/Battery LED control for Umaro + */ + +#include "charge_state.h" +#include "chipset.h" +#include "console.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "led_common.h" +#include "pwm.h" +#include "registers.h" +#include "util.h" + +#define CPRINTF(format, args...) cprintf(CC_PWM, format, ## args) +#define CPRINTS(format, args...) cprints(CC_PWM, format, ## args) + +#define LED_TOTAL_TICKS 16 +#define LED_ON_TICKS 4 + +static int led_debug; + +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_AMBER, + LED_GREEN, + + /* Number of colors, not a color itself */ + LED_COLOR_COUNT +}; + +/* Brightness vs. color, in the order of off, red, amber, and green */ +static const uint8_t color_brightness[LED_COLOR_COUNT][3] = { + /* {Red, Blue, Green}, */ + [LED_OFF] = { 0, 0, 0}, + [LED_RED] = {100, 0, 0}, + [LED_AMBER] = { 75, 0, 10}, + [LED_GREEN] = { 0, 0, 100}, +}; + +/** + * Set LED color + * + * @param color Enumerated color value + */ +static void set_color(enum led_color color) +{ + pwm_set_duty(PWM_CH_LED_RED, color_brightness[color][0]); + pwm_set_duty(PWM_CH_LED_BLUE, color_brightness[color][1]); + pwm_set_duty(PWM_CH_LED_GREEN, color_brightness[color][2]); +} + +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_BLUE] = 100; + brightness_range[EC_LED_COLOR_GREEN] = 100; +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + pwm_set_duty(PWM_CH_LED_RED, brightness[EC_LED_COLOR_RED]); + pwm_set_duty(PWM_CH_LED_BLUE, brightness[EC_LED_COLOR_BLUE]); + pwm_set_duty(PWM_CH_LED_GREEN, brightness[EC_LED_COLOR_GREEN]); + return EC_SUCCESS; +} + +static void umaro_led_set_power(void) +{ + static int power_ticks; + static int previous_state_suspend; + + power_ticks++; + + if (chipset_in_state(CHIPSET_STATE_SUSPEND)) { + /* Reset ticks if entering suspend so LED turns amber + * as soon as possible. */ + if (!previous_state_suspend) + power_ticks = 0; + + /* Blink once every four seconds. */ + set_color( + (power_ticks % LED_TOTAL_TICKS) < LED_ON_TICKS ? + LED_AMBER : LED_OFF); + + previous_state_suspend = 1; + return; + } + + previous_state_suspend = 0; + + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + set_color(LED_OFF); + else if (chipset_in_state(CHIPSET_STATE_ON)) + set_color(LED_GREEN); +} + +static void umaro_led_set_battery(void) +{ + static int battery_ticks; + + battery_ticks++; + + switch (charge_get_state()) { + case PWR_STATE_CHARGE: + set_color(LED_AMBER); + break; + case PWR_STATE_ERROR: + set_color(LED_RED); + break; + case PWR_STATE_CHARGE_NEAR_FULL: + case PWR_STATE_IDLE: /* External power connected in IDLE. */ + set_color(LED_GREEN); + break; + default: + /* Other states don't alter LED behavior */ + break; + } +} + +static void led_init(void) +{ + /* Configure GPIOs */ + gpio_config_module(MODULE_PWM_LED, 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); + pwm_enable(PWM_CH_LED_GREEN, 1); + pwm_enable(PWM_CH_LED_BLUE, 1); + + set_color(LED_OFF); +} +DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); + +/** + * Called by hook task every 250 ms + */ +static void led_tick(void) +{ + if (led_debug) + return; + + if (extpower_is_present()) { + if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) { + umaro_led_set_battery(); + return; + } + } else if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) { + umaro_led_set_power(); + return; + } + + set_color(LED_OFF); +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); + +static void dump_pwm_channels(void) +{ + int ch; + for (ch = 0; ch < 4; ch++) { + CPRINTF("channel = %d\n", ch); + CPRINTF("0x%04X 0x%04X 0x%04X\n", + MEC1322_PWM_CFG(ch), + MEC1322_PWM_ON(ch), + MEC1322_PWM_OFF(ch)); + } +} +/******************************************************************/ +/* 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")) { + set_color(LED_OFF); + } else if (!strcasecmp(argv[1], "red")) { + set_color(LED_RED); + } else if (!strcasecmp(argv[1], "green")) { + set_color(LED_GREEN); + } else if (!strcasecmp(argv[1], "amber")) { + set_color(LED_AMBER); + } else { + /* maybe handle charger_discharge_on_ac() too? */ + return EC_ERROR_PARAM1; + } + } + + if (led_debug == 1) + dump_pwm_channels(); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(ledcolor, command_led_color, + "[debug|red|green|amber|off]", + "Change LED color", + NULL); + diff --git a/board/umaro/lfw/gpio.inc b/board/umaro/lfw/gpio.inc new file mode 100644 index 0000000000..5e07ea8e87 --- /dev/null +++ b/board/umaro/lfw/gpio.inc @@ -0,0 +1,16 @@ +/* -*- 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. + * + * Minimal set of GPIOs needed for LFW loader + */ + +GPIO(PVT_CS0, PIN(146), GPIO_ODR_HIGH) /* SPI PVT Chip select */ + +/* Alternate functions GPIO definition */ +ALTERNATE(PIN_MASK(16, 0x24), 1, MODULE_UART, 0) /* UART0 */ +ALTERNATE(PIN_MASK(5, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(16, 0x10), 1, MODULE_SPI, 0) +ALTERNATE(PIN_MASK(15, 0x08), 1, MODULE_SPI, 0) /* 153: CLK */ |