summaryrefslogtreecommitdiff
path: root/board/chronicler
diff options
context:
space:
mode:
authorYu-An Chen <yu-an.chen@quanta.corp-partner.google.com>2021-06-03 19:12:50 +0800
committerCommit Bot <commit-bot@chromium.org>2021-06-10 21:48:20 +0000
commitcd40e99251db94f2ddf69bd63f98ecfe35c25fe7 (patch)
tree3a654f4a269218639915bbdc41001499603244cf /board/chronicler
parentaf535e7e927affe68a8a3ea9d6f064cb19b7beab (diff)
downloadchrome-ec-cd40e99251db94f2ddf69bd63f98ecfe35c25fe7.tar.gz
Chronicler: Implement LED behavior
Chronicler 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:190019962 BRANCH=volteer 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: Yu-An Chen <yu-an.chen@quanta.corp-partner.google.com> Change-Id: I90626a233fe0ec53a3ad9ecbb57f7b47de57ce18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2936838 Tested-by: Yu-An Chen <yu-an.chen@quanta.corp-partner.google.com> Auto-Submit: Yu-An Chen <yu-an.chen@quanta.corp-partner.google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'board/chronicler')
-rw-r--r--board/chronicler/battery.c2
-rw-r--r--board/chronicler/board.c27
-rw-r--r--board/chronicler/board.h10
-rw-r--r--board/chronicler/gpio.inc14
-rw-r--r--board/chronicler/led.c239
5 files changed, 175 insertions, 117 deletions
diff --git a/board/chronicler/battery.c b/board/chronicler/battery.c
index 48508e87bf..f1dff394e4 100644
--- a/board/chronicler/battery.c
+++ b/board/chronicler/battery.c
@@ -10,7 +10,7 @@
#include "util.h"
/*
- * Battery info for all Volteer battery types. Note that the fields
+ * Battery info for all Chronicler battery types. Note that the fields
* start_charging_min/max and charging_min/max are not used for the charger.
* The effective temperature limits are given by discharging_min/max_c.
*
diff --git a/board/chronicler/board.c b/board/chronicler/board.c
index a80177e8d9..2369202c49 100644
--- a/board/chronicler/board.c
+++ b/board/chronicler/board.c
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Volteer board-specific configuration */
+/* Chronicler board-specific configuration */
#include "bb_retimer.h"
#include "button.h"
#include "common.h"
@@ -184,31 +184,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/chronicler/board.h b/board/chronicler/board.h
index 1414031c1e..ca691c437c 100644
--- a/board/chronicler/board.h
+++ b/board/chronicler/board.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* Volteer board configuration */
+/* Chronicler board configuration */
#ifndef __CROS_EC_BOARD_H
#define __CROS_EC_BOARD_H
@@ -33,10 +33,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 */
@@ -173,10 +169,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/chronicler/gpio.inc b/board/chronicler/gpio.inc
index 941a1a313e..39181828c6 100644
--- a/board/chronicler/gpio.inc
+++ b/board/chronicler/gpio.inc
@@ -29,7 +29,7 @@ GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi2
GPIO_INT(EC_ALS_RGB_INT_L, PIN(D, 4), GPIO_INT_FALLING, tcs3400_interrupt)
GPIO_INT(TABLET_MODE_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr)
/*
- * Lid g-sensor interrupt unused on Volteer, configure as regular input for
+ * Lid g-sensor interrupt unused on Chronicler, configure as regular input for
* power saving.
*/
GPIO(EC_ACCEL_INT, PIN(8, 1), GPIO_INPUT | GPIO_PULL_UP)
@@ -106,6 +106,12 @@ 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)
+/* LED */
+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(CHARGER_INT_L, PIN(7, 3), GPIO_INPUT) /* Interrupt not used from ISL9241, on board pull-up */
GPIO(EC_GP_SEL0_ODL, PIN(B, 6), GPIO_OUT_LOW) /* Cannot be configured as input, drive output low, don't rely on the default setting of PxDOUT register */
@@ -151,12 +157,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/chronicler/led.c b/board/chronicler/led.c
index b2d67e7570..dfa7fefa1b 100644
--- a/board/chronicler/led.c
+++ b/board/chronicler/led.c
@@ -2,112 +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 Chronicler
*/
+#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(enum led_port 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 Chronicler, Chronicler 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);
}
-DECLARE_HOOK(HOOK_TICK, led_set_charge_port_tick, HOOK_PRIO_DEFAULT);
-static void board_led_init(void)
+/* Called by hook task every TICK */
+static void led_tick(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);
+ led_set_battery();
}
-DECLARE_HOOK(HOOK_INIT, board_led_init, HOOK_PRIO_DEFAULT);
-
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);