summaryrefslogtreecommitdiff
path: root/board/elemi
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2020-10-19 15:48:06 +0800
committerCommit Bot <commit-bot@chromium.org>2020-10-29 01:53:08 +0000
commit4def417c483e0aab7be73cbab429cf093ae4644c (patch)
tree6934a8cc751502d8bf6bebe7636f2458aae1d8f4 /board/elemi
parent2dfac202ed424dbef9c9a50b4bec36b450e7e0d2 (diff)
downloadchrome-ec-4def417c483e0aab7be73cbab429cf093ae4644c.tar.gz
elemi: Implement LED behavior
Elemi have two charging leds on left side and right side. Each side have two colors amber and white. The led behavior define as following: 1. Charging led: led on with charging port active, other port is off. 2. Charging: Amber. 3. Discharging: Off. 4. Battery Error: Blinking white (0.4 sec on, 0.4 sec off) 5. Fuel < 10%: Blinking white on right side port (1 sec on, 1 sec off) 6. Force idle for factory: Blinking amber (1 sec on, 1 sec off) 7. S0ix without charging state: Blinking both side LED white (1 sec on, 1 sec off) BUG=b:169409487 BRANCH=firmware-volteer-13521.B-master TEST=make sure led behavior intended. make sure ectool led left white/amber/off/auto work correctly. make sure ectool led right white/amber/off/auto work correctly. Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Change-Id: I9e4837ddbf300ec7a6c0e0dc8660dc157f9228aa Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2484115 Reviewed-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'board/elemi')
-rw-r--r--board/elemi/board.c35
-rw-r--r--board/elemi/board.h11
-rw-r--r--board/elemi/gpio.inc10
-rw-r--r--board/elemi/led.c234
4 files changed, 173 insertions, 117 deletions
diff --git a/board/elemi/board.c b/board/elemi/board.c
index 1993b241fb..96e0ec51a2 100644
--- a/board/elemi/board.c
+++ b/board/elemi/board.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Volteer board-specific configuration */
+/* Elemi board-specific configuration */
#include "bb_retimer.h"
#include "button.h"
#include "common.h"
@@ -74,14 +74,6 @@ 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();
@@ -267,31 +259,6 @@ 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,
diff --git a/board/elemi/board.h b/board/elemi/board.h
index 15e6938562..236b64a174 100644
--- a/board/elemi/board.h
+++ b/board/elemi/board.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Volteer board configuration */
+/* Elemi board configuration */
#ifndef __CROS_EC_BOARD_H
#define __CROS_EC_BOARD_H
@@ -24,11 +24,6 @@
/* Chipset features */
#define CONFIG_POWER_PP5000_CONTROL
-/* LED defines */
-#define CONFIG_LED_PWM
-/* Although there are 2 LEDs, they are both controlled by the same lines. */
-#define CONFIG_LED_PWM_COUNT 1
-
/* Keyboard features */
/* Sensors */
@@ -167,10 +162,6 @@ enum battery_type {
};
enum pwm_channel {
- PWM_CH_LED1_BLUE = 0,
- PWM_CH_LED2_GREEN,
- PWM_CH_LED3_RED,
- PWM_CH_LED4_SIDESEL,
PWM_CH_FAN,
PWM_CH_KBLIGHT,
PWM_CH_COUNT
diff --git a/board/elemi/gpio.inc b/board/elemi/gpio.inc
index 4a3cd1728c..4c7a137e76 100644
--- a/board/elemi/gpio.inc
+++ b/board/elemi/gpio.inc
@@ -112,6 +112,10 @@ GPIO(M2_SSD_PLN, PIN(A, 0), GPIO_ODR_HIGH) /* SSD power-loss notification */
GPIO(M2_SSD_PLA, PIN(7, 0), GPIO_INPUT) /* SSD power-loss acknowledgment */
GPIO(CCD_MODE_ODL, PIN(E, 5), GPIO_INPUT) /* Case Closed Debug Mode */
GPIO(EC_SLP_S0IX, PIN(7, 2), GPIO_INPUT | GPIO_PULL_UP)
+GPIO(C0_CHARGE_LED_AMBER_L, PIN(C, 3), GPIO_OUT_HIGH) /* Amber C0 port */
+GPIO(C0_CHARGE_LED_WHITE_L, PIN(C, 4), GPIO_OUT_HIGH) /* White C0 port */
+GPIO(C1_CHARGE_LED_AMBER_L, PIN(6, 0), GPIO_OUT_HIGH) /* Amber C1 port */
+GPIO(C1_CHARGE_LED_WHITE_L, PIN(C, 2), GPIO_OUT_HIGH) /* White C1 port */
/* Unused signals */
GPIO(UNUSED_GPIO41, PIN(4, 1), GPIO_INPUT | GPIO_PULL_UP)
@@ -151,12 +155,6 @@ ALTERNATE(PIN_MASK(D, BIT(1) | BIT(0)), 0, MODULE_I2C, 0)
ALTERNATE(PIN_MASK(3, BIT(3) | BIT(6)), 0, MODULE_I2C, 0) /* I2C5 */
ALTERNATE(PIN_MASK(B, BIT(3) | BIT(2)), 0, MODULE_I2C, 0) /* I2C7 */
-/* This selects between an LED module on the motherboard and one on the daughter
- * board, to be controlled by LED_{1,2,3}_L. PWM allows driving both modules at
- * the same time. */
-ALTERNATE(PIN_MASK(6, BIT(0)), 0, MODULE_PWM, 0) /* LED_SIDESEL_4_L */
-ALTERNATE(PIN_MASK(C, BIT(2) | BIT(3) | BIT(4)), 0, MODULE_PWM, 0) /* LED_{3,2,1}_L */
-
/* Fan signals */
GPIO(EN_PP5000_FAN, PIN(6, 1), GPIO_OUT_LOW)
ALTERNATE(PIN_MASK(B, BIT(7)), 0, MODULE_PWM, 0) /* FAN_PWM */
diff --git a/board/elemi/led.c b/board/elemi/led.c
index 4486bcb912..d8df9c92a0 100644
--- a/board/elemi/led.c
+++ b/board/elemi/led.c
@@ -2,103 +2,203 @@
* 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 Volteer
+ * Power and battery LED control for Elemi
*/
+#include "battery.h"
#include "charge_manager.h"
-#include "common.h"
+#include "charge_state.h"
+#include "chipset.h"
#include "ec_commands.h"
-#include "hooks.h"
+#include "gpio.h"
+#include "host_command.h"
#include "led_common.h"
-#include "led_pwm.h"
-#include "pwm.h"
+#include "hooks.h"
+
+#define BAT_LED_ON 0
+#define BAT_LED_OFF 1
+
+#define POWER_LED_ON 0
+#define POWER_LED_OFF 1
+
+#define LED_CYCLE_TIME_MS (2 * 1000)
+#define LED_TICKS_PER_CYCLE (LED_CYCLE_TIME_MS / HOOK_TICK_INTERVAL_MS)
+#define LED_ON_TIME_MS (1 * 1000)
+#define LED_ON_TICKS (LED_ON_TIME_MS / HOOK_TICK_INTERVAL_MS)
const enum ec_led_id supported_led_ids[] = {
- EC_LED_ID_POWER_LED,
+ EC_LED_ID_LEFT_LED,
+ EC_LED_ID_RIGHT_LED,
};
+
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-struct pwm_led led_color_map[] = {
- /* Red, Green, Blue */
- [EC_LED_COLOR_RED] = { 100, 0, 0 },
- [EC_LED_COLOR_GREEN] = { 0, 100, 0 },
- [EC_LED_COLOR_BLUE] = { 0, 0, 100 },
- /* The green LED seems to be brighter than the others, so turn down
- * green from its natural level for these secondary colors.
- */
- [EC_LED_COLOR_YELLOW] = { 100, 70, 0 },
- [EC_LED_COLOR_WHITE] = { 100, 70, 100 },
- [EC_LED_COLOR_AMBER] = { 100, 20, 0 },
+enum led_color {
+ LED_OFF = 0,
+ LED_AMBER,
+ LED_WHITE,
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
};
-struct pwm_led pwm_leds[] = {
- /* 2 RGB diffusers controlled by 1 set of 3 channels. */
- [PWM_LED0] = {
- .ch0 = PWM_CH_LED3_RED,
- .ch1 = PWM_CH_LED2_GREEN,
- .ch2 = PWM_CH_LED1_BLUE,
- .enable = &pwm_enable,
- .set_duty = &pwm_set_duty,
- },
+enum led_port {
+ RIGHT_PORT = 0,
+ LEFT_PORT
};
+static void led_set_color_battery(int port, enum led_color color)
+{
+ enum gpio_signal amber_led, white_led;
+
+ amber_led = (port == RIGHT_PORT ? GPIO_C0_CHARGE_LED_AMBER_L :
+ GPIO_C1_CHARGE_LED_AMBER_L);
+ white_led = (port == RIGHT_PORT ? GPIO_C0_CHARGE_LED_WHITE_L :
+ GPIO_C1_CHARGE_LED_WHITE_L);
+
+ switch (color) {
+ case LED_WHITE:
+ gpio_set_level(white_led, BAT_LED_ON);
+ gpio_set_level(amber_led, BAT_LED_OFF);
+ break;
+ case LED_AMBER:
+ gpio_set_level(white_led, BAT_LED_OFF);
+ gpio_set_level(amber_led, BAT_LED_ON);
+ break;
+ case LED_OFF:
+ gpio_set_level(white_led, BAT_LED_OFF);
+ gpio_set_level(amber_led, BAT_LED_OFF);
+ break;
+ default:
+ break;
+ }
+}
+
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
- brightness_range[EC_LED_COLOR_RED] = 255;
- brightness_range[EC_LED_COLOR_GREEN] = 255;
- brightness_range[EC_LED_COLOR_BLUE] = 255;
+ switch (led_id) {
+ case EC_LED_ID_LEFT_LED:
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+ brightness_range[EC_LED_COLOR_AMBER] = 1;
+ break;
+ case EC_LED_ID_RIGHT_LED:
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+ brightness_range[EC_LED_COLOR_AMBER] = 1;
+ break;
+ default:
+ break;
+ }
}
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
{
- enum pwm_led_id pwm_id;
-
- /* Convert ec_led_id to pwm_led_id. */
- if (led_id == EC_LED_ID_POWER_LED)
- pwm_id = PWM_LED0;
- else
- return EC_ERROR_UNKNOWN;
-
- if (brightness[EC_LED_COLOR_RED])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_RED);
- else if (brightness[EC_LED_COLOR_GREEN])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_GREEN);
- else if (brightness[EC_LED_COLOR_BLUE])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_BLUE);
- else if (brightness[EC_LED_COLOR_YELLOW])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_YELLOW);
- else if (brightness[EC_LED_COLOR_WHITE])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_WHITE);
- else if (brightness[EC_LED_COLOR_AMBER])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_AMBER);
- else
- /* Otherwise, the "color" is "off". */
- set_pwm_led_color(pwm_id, -1);
+ switch (led_id) {
+ case EC_LED_ID_LEFT_LED:
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color_battery(LEFT_PORT, LED_WHITE);
+ else if (brightness[EC_LED_COLOR_AMBER] != 0)
+ led_set_color_battery(LEFT_PORT, LED_AMBER);
+ else
+ led_set_color_battery(LEFT_PORT, LED_OFF);
+ break;
+ case EC_LED_ID_RIGHT_LED:
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color_battery(RIGHT_PORT, LED_WHITE);
+ else if (brightness[EC_LED_COLOR_AMBER] != 0)
+ led_set_color_battery(RIGHT_PORT, LED_AMBER);
+ else
+ led_set_color_battery(RIGHT_PORT, LED_OFF);
+ break;
+ default:
+ return EC_ERROR_PARAM1;
+ }
return EC_SUCCESS;
}
-/* Illuminates the LED on the side of the active charging port. If not charging,
- * illuminates both LEDs.
+/*
+ * Set active charge port color to the parameter, turn off all others.
+ * If no port is active (-1), turn off all LEDs.
*/
-static void led_set_charge_port_tick(void)
+static void set_active_port_color(enum led_color color)
{
- int port;
- int side_select_duty;
+ int port = charge_manager_get_active_charge_port();
+
+ if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED))
+ led_set_color_battery(RIGHT_PORT,
+ (port == RIGHT_PORT) ? color : LED_OFF);
+ if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
+ led_set_color_battery(LEFT_PORT,
+ (port == LEFT_PORT) ? color : LED_OFF);
+}
+
+static void led_set_battery(void)
+{
+ static int battery_ticks;
+ static int suspend_ticks;
+ uint32_t chflags = charge_get_flags();
+
+ battery_ticks++;
+
+ /*
+ * Override battery LEDs for Elemi, Elemi doesn't have power LED,
+ * blinking both two side battery white LEDs to indicate
+ * system suspend without charging state.
+ */
+ if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
+ charge_get_state() != PWR_STATE_CHARGE) {
- port = charge_manager_get_active_charge_port();
- switch (port) {
- case 0:
- side_select_duty = 100;
+ suspend_ticks++;
+
+ led_set_color_battery(RIGHT_PORT, suspend_ticks & 0x4 ?
+ LED_WHITE : LED_OFF);
+ led_set_color_battery(LEFT_PORT, suspend_ticks & 0x4 ?
+ LED_WHITE : LED_OFF);
+ return;
+ }
+
+ suspend_ticks = 0;
+
+ switch (charge_get_state()) {
+ case PWR_STATE_CHARGE:
+ /* Always indicate when charging, even in suspend. */
+ set_active_port_color(LED_AMBER);
+ break;
+ case PWR_STATE_DISCHARGE:
+ if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) {
+ if (charge_get_percent() < 10)
+ led_set_color_battery(RIGHT_PORT,
+ (battery_ticks % LED_TICKS_PER_CYCLE
+ < LED_ON_TICKS) ? LED_WHITE : LED_OFF);
+ else
+ led_set_color_battery(RIGHT_PORT, LED_OFF);
+ }
+
+ if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
+ led_set_color_battery(LEFT_PORT, LED_OFF);
break;
- case 1:
- side_select_duty = 0;
+ case PWR_STATE_ERROR:
+ set_active_port_color((battery_ticks & 0x2) ?
+ LED_WHITE : LED_OFF);
+ break;
+ case PWR_STATE_CHARGE_NEAR_FULL:
+ set_active_port_color(LED_WHITE);
+ break;
+ case PWR_STATE_IDLE: /* External power connected in IDLE */
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ set_active_port_color((battery_ticks %
+ LED_TICKS_PER_CYCLE < LED_ON_TICKS) ?
+ LED_AMBER : LED_OFF);
+ else
+ set_active_port_color(LED_WHITE);
break;
default:
- side_select_duty = 50;
+ /* Other states don't alter LED behavior */
+ break;
}
+}
- if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
- pwm_set_duty(PWM_CH_LED4_SIDESEL, side_select_duty);
+/* Called by hook task every TICK */
+static void led_tick(void)
+{
+ led_set_battery();
}
-DECLARE_HOOK(HOOK_TICK, led_set_charge_port_tick, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);