diff options
author | Alexandru Stan <amstan@chromium.org> | 2014-07-09 16:45:41 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-07-11 01:56:17 +0000 |
commit | 423c40c5a0c2b97df287e751a8ebfd326f2e6723 (patch) | |
tree | 878e5444f97a682aa37570238d988883a02c3131 | |
parent | 6ab38d8715bb49753b98b21f5430c6986dc12cf2 (diff) | |
download | chrome-ec-423c40c5a0c2b97df287e751a8ebfd326f2e6723.tar.gz |
Created Veyron board folder based on Big
The 2 boards are similar enough to test stuff on big for now, at least
until the new hardware comes.
Also added veyron to flash_ec.
Also cleaned up the style: pre-upload.py was giving errors on files
that were unmodified from big(spaces instead of tabs).
I had to ignore this though:
> ERROR: Macros with complex values should be enclosed in parenthesis
> #471: FILE: board/veyron/board.h:35:
> +#define KB_OUT_PORT_LIST GPIO_A, GPIO_B, GPIO_C
BRANCH=none
BUG=chrome-os-partner:30167
TEST=~/trunk/src/platform/ec $ make BOARD=veyron clean &&
make -j BOARD=veyron && util/flash_ec --board=veyron --ro
verify ec is alive and version is reported as veyron
Change-Id: I1f4bd562c0ab55360a2160a753ad8ad9b58f8c47
Signed-off-by: Alexandru Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/207270
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Doug Anderson <dianders@chromium.org>
-rw-r--r-- | board/veyron/battery.c | 313 | ||||
-rw-r--r-- | board/veyron/board.c | 66 | ||||
-rw-r--r-- | board/veyron/board.h | 78 | ||||
-rw-r--r-- | board/veyron/build.mk | 13 | ||||
-rw-r--r-- | board/veyron/ec.tasklist | 23 | ||||
-rw-r--r-- | board/veyron/gpio.inc | 58 | ||||
-rw-r--r-- | board/veyron/led.c | 179 | ||||
-rwxr-xr-x | util/flash_ec | 2 |
8 files changed, 731 insertions, 1 deletions
diff --git a/board/veyron/battery.c b/board/veyron/battery.c new file mode 100644 index 0000000000..be6ba3ebdf --- /dev/null +++ b/board/veyron/battery.c @@ -0,0 +1,313 @@ +/* Copyright (c) 2013 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 "gpio.h" +#include "host_command.h" +#include "util.h" +#include "console.h" + +/* Console output macros */ +#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) + +/* These 2 defines are for cut_off command for 3S battery */ +#define SB_SHIP_MODE_ADDR 0x3a +#define SB_SHIP_MODE_DATA 0xc574 + +static struct battery_info *battery_info; +static int support_cut_off; + +struct battery_device { + char manuf[9]; + char device[9]; + int design_mv; + struct battery_info *battery_info; + int support_cut_off; +}; + +/* + * Used for the case that battery cannot be detected, such as the pre-charge + * case. In this case, we need to provide the battery with the enough voltage + * (usually the highest voltage among batteries, but the smallest precharge + * current). This should be as conservative as possible. + */ +static struct battery_info info_precharge = { + + .voltage_max = 12900, /* the max voltage among batteries */ + .voltage_normal = 11400, + .voltage_min = 9000, + + /* Pre-charge values. */ + .precharge_current = 256, /* mA, the min current among batteries */ + + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 75, +}; + +static struct battery_info info_2s = { + /* + * Design voltage + * max = 8.4V + * normal = 7.4V + * min = 6.0V + */ + .voltage_max = 8400, + .voltage_normal = 7400, + .voltage_min = 6000, + + /* Pre-charge current: I <= 0.01C */ + .precharge_current = 64, /* mA */ + + /* + * Operational temperature range + * 0 <= T_charge <= 50 deg C + * -20 <= T_discharge <= 60 deg C + */ + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 50, + .discharging_min_c = -20, + .discharging_max_c = 60, +}; + +static struct battery_info info_3s = { + + .voltage_max = 12600, + .voltage_normal = 11100, /* Average of max & min */ + .voltage_min = 9000, + + /* Pre-charge values. */ + .precharge_current = 392, /* mA */ + + .start_charging_min_c = 0, + .start_charging_max_c = 60, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 50, +}; + +static struct battery_info info_3s_LGC = { + + .voltage_max = 12900, + .voltage_normal = 11400, /* Average of max & min */ + .voltage_min = 9000, + + /* Pre-charge values. */ + .precharge_current = 256, /* mA */ + + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 75, +}; + +static struct battery_info info_4s_LGC = { + + .voltage_max = 17200, + .voltage_normal = 15200, /* Average of max & min */ + .voltage_min = 12000, + + /* Pre-charge values. */ + .precharge_current = 256, /* mA */ + + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 75, +}; + +static struct battery_device support_batteries[] = { + { + .manuf = "NVT", + .device = "ARROW", + .design_mv = 7400, + .battery_info = &info_2s, + .support_cut_off = 0, + }, + { + .manuf = "SANYO", + .device = "AP13J3K", + .design_mv = 11250, + .battery_info = &info_3s, + .support_cut_off = 1, + }, + { + .manuf = "SONYCorp", + .device = "AP13J4K", + .design_mv = 11400, + .battery_info = &info_3s, + .support_cut_off = 1, + }, + { + .manuf = "LGC", + .device = "AC14B8K", + .design_mv = 15200, + .battery_info = &info_4s_LGC, + .support_cut_off = 1, + }, + { + .manuf = "LGC", + .device = "AC14B18J", + .design_mv = 11400, + .battery_info = &info_3s_LGC, + .support_cut_off = 1, + }, +}; + +#ifdef CONFIG_BATTERY_OVERRIDE_PARAMS +/* + * The following parameters are for 2S battery. + * There is no corresponding params for 3S battery. + */ +enum { + TEMP_RANGE_10, + TEMP_RANGE_23, + TEMP_RANGE_35, + TEMP_RANGE_45, + TEMP_RANGE_50, + TEMP_RANGE_MAX +}; + +enum { + VOLT_RANGE_7200, + VOLT_RANGE_8000, + VOLT_RANGE_8400, + VOLT_RANGE_MAX +}; + +/* + * Vendor provided charging method + * temp : < 7.2V, 7.2V ~ 8.0V, 8.0V ~ 8.4V + * - 0 ~ 10 : 0.8A 1.6A 0.8A + * - 10 ~ 23 : 1.6A 4.0A 1.6A + * - 23 ~ 35 : 4.0A 4.0A 4.0A + * - 35 ~ 45 : 1.6A 4.0A 1.6A + * - 45 ~ 50 : 0.8A 1.6A 0.8A + */ +static const int const current_limit[TEMP_RANGE_MAX][VOLT_RANGE_MAX] = { + { 800, 1600, 800}, + {1600, 4000, 1600}, + {4000, 4000, 4000}, + {1600, 4000, 1600}, + { 800, 1600, 800}, +}; + +static inline void limit_value(int *val, int limit) +{ + if (*val > limit) + *val = limit; +} + +void battery_override_params(struct batt_params *batt) +{ + int *desired_current = &batt->desired_current; + int temp_range, volt_range; + int bat_temp_c = DECI_KELVIN_TO_CELSIUS(batt->temperature); + + if (battery_info == NULL) + return; + + /* Return if the battery is not a 2S battery */ + if (battery_info->voltage_max != info_2s.voltage_max) + return; + + /* Limit charging voltage */ + if (batt->desired_voltage > battery_info->voltage_max) + batt->desired_voltage = battery_info->voltage_max; + + /* Don't charge if outside of allowable temperature range */ + if (bat_temp_c >= battery_info->charging_max_c || + bat_temp_c < battery_info->charging_min_c) { + batt->desired_voltage = 0; + batt->desired_current = 0; + batt->flags &= ~BATT_FLAG_WANT_CHARGE; + return; + } + + if (bat_temp_c <= 10) + temp_range = TEMP_RANGE_10; + else if (bat_temp_c <= 23) + temp_range = TEMP_RANGE_23; + else if (bat_temp_c <= 35) + temp_range = TEMP_RANGE_35; + else if (bat_temp_c <= 45) + temp_range = TEMP_RANGE_45; + else + temp_range = TEMP_RANGE_50; + + if (batt->voltage < 7200) + volt_range = VOLT_RANGE_7200; + else if (batt->voltage < 8000) + volt_range = VOLT_RANGE_8000; + else + volt_range = VOLT_RANGE_8400; + + limit_value(desired_current, current_limit[temp_range][volt_range]); + + /* If battery wants current, give it at least the precharge current */ + if (*desired_current > 0 && + *desired_current < battery_info->precharge_current) + *desired_current = battery_info->precharge_current; +} +#endif /* CONFIG_BATTERY_OVERRIDE_PARAMS */ + +const struct battery_info *battery_get_info(void) +{ + int i; + char manuf[9]; + char device[9]; + int design_mv; + + if (battery_manufacturer_name(manuf, sizeof(manuf))) { + CPRINTS("Failed to get MANUF name"); + return &info_precharge; + } + + if (battery_device_name(device, sizeof(device))) { + CPRINTS("Failed to get DEVICE name"); + return &info_precharge; + } + if (battery_design_voltage((int *)&design_mv)) { + CPRINTS("Failed to get DESIGN_VOLTAGE"); + return &info_precharge; + } + + for (i = 0; i < ARRAY_SIZE(support_batteries); ++i) { + if ((strcasecmp(support_batteries[i].manuf, manuf) == 0) && + (strcasecmp(support_batteries[i].device, device) == 0) && + (support_batteries[i].design_mv == design_mv)) { + CPRINTS("battery Manuf:%s, Device=%s, design=%u", + manuf, device, design_mv); + support_cut_off = support_batteries[i].support_cut_off; + battery_info = support_batteries[i].battery_info; + return battery_info; + } + } + + CPRINTS("un-recognized battery Manuf:%s, Device:%s", + manuf, device); + return &info_precharge; +} + +int board_cut_off_battery(void) +{ + if (support_cut_off) + return sb_write(SB_SHIP_MODE_ADDR, SB_SHIP_MODE_DATA); + else + return EC_RES_INVALID_COMMAND; +} diff --git a/board/veyron/board.c b/board/veyron/board.c new file mode 100644 index 0000000000..b20f921274 --- /dev/null +++ b/board/veyron/board.c @@ -0,0 +1,66 @@ +/* Copyright (c) 2014 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. + */ +/* Veyron board-specific configuration */ + +#include "battery.h" +#include "chipset.h" +#include "common.h" +#include "extpower.h" +#include "gpio.h" +#include "i2c.h" +#include "keyboard_raw.h" +#include "lid_switch.h" +#include "power.h" +#include "power_button.h" +#include "power.h" +#include "pwm.h" +#include "pwm_chip.h" +#include "registers.h" +#include "spi.h" +#include "task.h" +#include "util.h" +#include "timer.h" +#include "charger.h" + +#define GPIO_KB_INPUT (GPIO_INPUT | GPIO_PULL_UP | GPIO_INT_BOTH) +#define GPIO_KB_OUTPUT GPIO_ODR_HIGH + +#include "gpio_list.h" + +/* Pins with alternate functions */ +const struct gpio_alt_func gpio_alt_funcs[] = { + {GPIO_A, 0x00f0, GPIO_ALT_SPI, MODULE_SPI, GPIO_DEFAULT}, + {GPIO_A, 0x0600, GPIO_ALT_USART, MODULE_UART, GPIO_DEFAULT}, + {GPIO_B, 0x00c0, GPIO_ALT_I2C, MODULE_I2C, GPIO_DEFAULT}, +}; +const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); + +/* power signal list. Must match order of enum power_signal. */ +const struct power_signal_info power_signal_list[] = { + {GPIO_SOC1V8_XPSHOLD, 1, "XPSHOLD"}, + {GPIO_SUSPEND_L, 0, "SUSPEND#_ASSERTED"}, +}; +BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT); + +/* I2C ports */ +const struct i2c_port_t i2c_ports[] = { + {"master", I2C_PORT_MASTER, 100}, +}; +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); + +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ +const struct pwm_t pwm_channels[] = { + {STM32_TIM(2), STM32_TIM_CH(3), + PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, +}; +BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); + +/** + * Discharge battery when on AC power for factory test. + */ +int board_discharge_on_ac(int enable) +{ + return charger_discharge_on_ac(enable); +} diff --git a/board/veyron/board.h b/board/veyron/board.h new file mode 100644 index 0000000000..8972bc7eae --- /dev/null +++ b/board/veyron/board.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2014 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. + */ + +/* Veyron board configuration */ + +#ifndef __BOARD_H +#define __BOARD_H + +/* Optional features */ +#define CONFIG_AP_HANG_DETECT +#define CONFIG_BATTERY_SMART +#define CONFIG_BATTERY_CUT_OFF +#define CONFIG_CHARGER +#define CONFIG_CHARGER_V2 +#define CONFIG_CHARGER_BQ24735 +#define CONFIG_CHIPSET_TEGRA +#define CONFIG_POWER_COMMON +#define CONFIG_EXTPOWER_GPIO +#define CONFIG_HOST_COMMAND_STATUS +#define CONFIG_I2C +#define CONFIG_KEYBOARD_PROTOCOL_MKBP +#define CONFIG_SPI +#define CONFIG_PWM +#define CONFIG_POWER_BUTTON +#define CONFIG_VBOOT_HASH +#define CONFIG_LED_COMMON +#define CONFIG_CHARGER_DISCHARGE_ON_AC +#undef CONFIG_CONSOLE_CMDHELP + +#ifndef __ASSEMBLER__ + +/* Keyboard output port list */ +#define KB_OUT_PORT_LIST GPIO_A, GPIO_B, GPIO_C + +/* Single I2C port, where the EC is the master. */ +#define I2C_PORT_MASTER 0 +#define I2C_PORT_BATTERY I2C_PORT_MASTER +#define I2C_PORT_CHARGER I2C_PORT_MASTER + +/* Timer selection */ +#define TIM_CLOCK_MSB 3 +#define TIM_CLOCK_LSB 9 +#define TIM_POWER_LED 2 +#define TIM_WATCHDOG 4 + +#include "gpio_signal.h" + +enum power_signal { + TEGRA_XPSHOLD = 0, + TEGRA_SUSPEND_ASSERTED, + + /* Number of power signals */ + POWER_SIGNAL_COUNT +}; + +enum pwm_channel { + PWM_CH_POWER_LED = 0, + /* Number of PWM channels */ + PWM_CH_COUNT +}; + +/* Charger module */ +#define CONFIG_CHARGER_SENSE_RESISTOR 10 /* Charge sense resistor, mOhm */ +#define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 /* Input sensor resistor, mOhm */ +/* Input current limit for 45W AC adapter: + * 45W/19V*85%=2013mA, choose the closest charger setting = 2048mA + */ +#define CONFIG_CHARGER_INPUT_CURRENT 2048 /* mA, based on Link HW design */ +#define CONFIG_CHARGER_CURRENT_LIMIT 3000 /* PL102 inductor 3.0A(3.8A) */ + +/* Discharge battery when on AC power for factory test. */ +int board_discharge_on_ac(int enable); + +#endif /* !__ASSEMBLER__ */ + +#endif /* __BOARD_H */ diff --git a/board/veyron/build.mk b/board/veyron/build.mk new file mode 100644 index 0000000000..605af9c169 --- /dev/null +++ b/board/veyron/build.mk @@ -0,0 +1,13 @@ +# -*- makefile -*- +# Copyright (c) 2014 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 STmicro STM32L100RBT6 +CHIP:=stm32 +CHIP_FAMILY:=stm32l +CHIP_VARIANT:=stm32l100 + +board-y=board.o battery.o led.o diff --git a/board/veyron/ec.tasklist b/board/veyron/ec.tasklist new file mode 100644 index 0000000000..318cfe2553 --- /dev/null +++ b/board/veyron/ec.tasklist @@ -0,0 +1,23 @@ +/* Copyright (c) 2014 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(n, r, d, s) 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(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(CONSOLE, console_task, NULL, TASK_STACK_SIZE) \ + TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) diff --git a/board/veyron/gpio.inc b/board/veyron/gpio.inc new file mode 100644 index 0000000000..f8cd6720a3 --- /dev/null +++ b/board/veyron/gpio.inc @@ -0,0 +1,58 @@ +/* -*- mode:c -*- + * + * Copyright (c) 2014 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. + */ + +/* Inputs with interrupt handlers are first for efficiency */ +GPIO(POWER_BUTTON_L, B, 5, GPIO_INT_BOTH, power_button_interrupt) +GPIO(SOC1V8_XPSHOLD, A, 3, GPIO_INT_BOTH, power_signal_interrupt) +GPIO(LID_OPEN, C, 13, GPIO_INT_BOTH, lid_interrupt) +GPIO(SUSPEND_L, C, 7, GPIO_KB_INPUT, power_signal_interrupt) +GPIO(SPI1_NSS, A, 4, GPIO_INT_BOTH | GPIO_PULL_UP, spi_event) +GPIO(AC_PRESENT, A, 0, GPIO_INT_BOTH, extpower_interrupt) + +/* Keyboard inputs */ +GPIO(KB_IN00, C, 8, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN01, C, 9, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN02, C, 10, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN03, C, 11, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN04, C, 12, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN05, C, 14, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN06, C, 15, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) +GPIO(KB_IN07, D, 2, GPIO_KB_INPUT, keyboard_raw_gpio_interrupt) + +/* Other inputs */ +GPIO(WP_L, B, 4, GPIO_INPUT, NULL) + +/* Outputs */ +GPIO(AP_RESET_L, B, 3, GPIO_ODR_HIGH, NULL) +GPIO(CHARGER_EN, B, 2, GPIO_OUT_LOW, NULL) +GPIO(EC_INT, B, 9, GPIO_ODR_HIGH, NULL) +GPIO(ENTERING_RW, H, 0, GPIO_OUT_LOW, NULL) +GPIO(I2C1_SCL, B, 6, GPIO_ODR_HIGH, NULL) +GPIO(I2C1_SDA, B, 7, GPIO_ODR_HIGH, NULL) +GPIO(LED_POWER_L, A, 2, GPIO_OUT_HIGH, NULL) /* PWR_LED1 */ +GPIO(PMIC_PWRON_L, A, 12, GPIO_OUT_HIGH, NULL) +GPIO(PMIC_RESET, A, 15, GPIO_OUT_LOW, NULL) +GPIO(KB_OUT00, B, 0, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT01, B, 8, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT02, B, 12, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT03, B, 13, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT04, B, 14, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT05, B, 15, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT06, C, 0, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT07, C, 1, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT08, C, 2, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT09, B, 1, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT10, C, 5, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT11, C, 4, GPIO_KB_OUTPUT, NULL) +GPIO(KB_OUT12, A, 13, GPIO_KB_OUTPUT, NULL) +GPIO(PWR_LED0, B, 10, GPIO_OUT_LOW, NULL) +GPIO(BAT_LED0, B, 11, GPIO_OUT_LOW, NULL) +GPIO(BAT_LED1, A, 8, GPIO_OUT_LOW, NULL) +GPIO(CHARGING, A, 11, GPIO_OUT_LOW, NULL) +GPIO(EC_BL_OVERRIDE, H, 1, GPIO_ODR_HIGH, NULL) +GPIO(PMIC_THERM_L, A, 1, GPIO_ODR_HIGH, NULL) +GPIO(PMIC_WARM_RESET_L, C, 3, GPIO_ODR_HIGH, NULL) diff --git a/board/veyron/led.c b/board/veyron/led.c new file mode 100644 index 0000000000..aebc2d3251 --- /dev/null +++ b/board/veyron/led.c @@ -0,0 +1,179 @@ +/* Copyright (c) 2014 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 LED and Power LED control for Veyron + */ + +#include "gpio.h" +#include "hooks.h" +#include "battery.h" +#include "charge_state.h" +#include "chipset.h" +#include "led_common.h" +#include "util.h" + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_BATTERY_LED, EC_LED_ID_POWER_LED}; + +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +enum led_color { + LED_OFF = 0, + LED_BLUE, + LED_ORANGE, + LED_COLOR_COUNT /* Number of colors, not a color itself */ +}; + +static int bat_led_set_color(enum led_color color) +{ + switch (color) { + case LED_OFF: + gpio_set_level(GPIO_CHARGING, 0); + gpio_set_level(GPIO_BAT_LED1, 0); + break; + case LED_BLUE: + gpio_set_level(GPIO_CHARGING, 0); + gpio_set_level(GPIO_BAT_LED1, 1); + break; + case LED_ORANGE: + gpio_set_level(GPIO_CHARGING, 1); + gpio_set_level(GPIO_BAT_LED1, 0); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +static int pwr_led_set_color(enum led_color color) +{ + switch (color) { + case LED_OFF: + gpio_set_level(GPIO_LED_POWER_L, 0); + gpio_set_level(GPIO_PWR_LED0, 0); + break; + case LED_BLUE: + gpio_set_level(GPIO_LED_POWER_L, 1); + gpio_set_level(GPIO_PWR_LED0, 0); + break; + case LED_ORANGE: + gpio_set_level(GPIO_LED_POWER_L, 0); + gpio_set_level(GPIO_PWR_LED0, 1); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ + /* Ignoring led_id as both leds support the same colors */ + brightness_range[EC_LED_COLOR_BLUE] = 1; + brightness_range[EC_LED_COLOR_YELLOW] = 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_BLUE] != 0) + bat_led_set_color(LED_BLUE); + else if (brightness[EC_LED_COLOR_YELLOW] != 0) + bat_led_set_color(LED_ORANGE); + else + bat_led_set_color(LED_OFF); + break; + case EC_LED_ID_POWER_LED: + if (brightness[EC_LED_COLOR_BLUE] != 0) + pwr_led_set_color(LED_BLUE); + else if (brightness[EC_LED_COLOR_YELLOW] != 0) + pwr_led_set_color(LED_ORANGE); + else + pwr_led_set_color(LED_OFF); + break; + default: + return EC_ERROR_UNKNOWN; + } + return EC_SUCCESS; +} + +static void veyron_led_set_power(void) +{ + static int power_second; + + power_second++; + + /* PWR LED behavior: + * Power on: Blue + * Suspend: Orange in breeze mode ( 1 sec on/ 3 sec off) + * Power off: OFF + */ + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + pwr_led_set_color(LED_OFF); + else if (chipset_in_state(CHIPSET_STATE_ON)) + pwr_led_set_color(LED_BLUE); + else if (chipset_in_state(CHIPSET_STATE_SUSPEND)) + pwr_led_set_color((power_second & 3) ? LED_OFF : LED_ORANGE); +} + +static void veyron_led_set_battery(void) +{ + static int battery_second; + uint32_t chflags = charge_get_flags(); + + battery_second++; + + /* BAT LED behavior: + * Fully charged / idle: Blue + * Force idle (for factory): 2 secs of blue, 2 secs of yellow + * Under charging: Orange + * Battery low (10%): Orange in breeze mode (1 sec on, 3 sec off) + * Battery critical low (less than 3%) or abnormal battery + * situation: Orange in blinking mode (1 sec on, 1 sec off) + * Using battery or not connected to AC power: OFF + */ + switch (charge_get_state()) { + case PWR_STATE_CHARGE: + bat_led_set_color(LED_ORANGE); + break; + case PWR_STATE_DISCHARGE: + if (charge_get_percent() < 3) + bat_led_set_color((battery_second & 1) + ? LED_OFF : LED_ORANGE); + else if (charge_get_percent() < 10) + bat_led_set_color((battery_second & 3) + ? LED_OFF : LED_ORANGE); + else + bat_led_set_color(LED_OFF); + break; + case PWR_STATE_ERROR: + bat_led_set_color((battery_second & 1) ? LED_OFF : LED_ORANGE); + break; + case PWR_STATE_CHARGE_NEAR_FULL: + bat_led_set_color(LED_BLUE); + break; + case PWR_STATE_IDLE: /* External power connected in IDLE. */ + if (chflags & CHARGE_FLAG_FORCE_IDLE) + bat_led_set_color( + (battery_second & 0x2) ? LED_BLUE : LED_ORANGE); + else + bat_led_set_color(LED_BLUE); + break; + default: + /* Other states don't alter LED behavior */ + break; + } +} + +/** * Called by hook task every 1 sec */ +static void led_second(void) +{ + if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) + veyron_led_set_power(); + if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) + veyron_led_set_battery(); +} +DECLARE_HOOK(HOOK_SECOND, led_second, HOOK_PRIO_DEFAULT); + diff --git a/util/flash_ec b/util/flash_ec index 1401d341a5..fe9105d3d6 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -284,7 +284,7 @@ info "${MCU} UART pty : ${EC_UART}" save="$(servo_save)" case "${BOARD}" in - big | discovery | nyan | pit | snow | spring ) flash_stm32 ;; + big | discovery | nyan | pit | snow | spring | veyron ) flash_stm32 ;; fruitpie | zinger | firefly | samus_pd | ryu ) flash_stm32 ;; twinkie) flash_stm32_dfu ;; falco | peppy | rambi | samus | squawks ) flash_lm4 ;; |