summaryrefslogtreecommitdiff
path: root/board/nipperkin/led.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/nipperkin/led.c')
-rw-r--r--board/nipperkin/led.c80
1 files changed, 45 insertions, 35 deletions
diff --git a/board/nipperkin/led.c b/board/nipperkin/led.c
index 93131400d2..c7d6e0e0bc 100644
--- a/board/nipperkin/led.c
+++ b/board/nipperkin/led.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -35,22 +35,19 @@ enum led_color {
LED_OFF = 0,
LED_AMBER,
LED_WHITE,
- LED_COLOR_COUNT /* Number of colors, not a color itself */
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
};
-enum led_port {
- LED_LEFT_PORT = 0,
- LED_RIGHT_PORT
-};
+enum led_port { LED_LEFT_PORT = 0, LED_RIGHT_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 == LED_LEFT_PORT ? GPIO_C0_CHARGE_LED_AMBER_L :
- GPIO_C1_CHARGE_LED_AMBER_L);
+ GPIO_C1_CHARGE_LED_AMBER_L);
white_led = (port == LED_LEFT_PORT ? GPIO_C0_CHARGE_LED_WHITE_L :
- GPIO_C1_CHARGE_LED_WHITE_L);
+ GPIO_C1_CHARGE_LED_WHITE_L);
switch (color) {
case LED_WHITE:
@@ -121,18 +118,19 @@ static void set_active_port_color(enum led_color color)
int port = charge_manager_get_active_charge_port();
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED))
- led_set_color_battery(LED_RIGHT_PORT,
- (port == LED_RIGHT_PORT) ? color : LED_OFF);
+ led_set_color_battery(LED_RIGHT_PORT, (port == LED_RIGHT_PORT) ?
+ color :
+ LED_OFF);
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED))
- led_set_color_battery(LED_LEFT_PORT,
- (port == LED_LEFT_PORT) ? color : LED_OFF);
+ led_set_color_battery(LED_LEFT_PORT, (port == LED_LEFT_PORT) ?
+ color :
+ LED_OFF);
}
static void led_set_battery(void)
{
static int battery_ticks;
static int power_ticks;
- uint32_t chflags = charge_get_flags();
battery_ticks++;
@@ -142,16 +140,19 @@ static void led_set_battery(void)
* system suspend with non-charging state.
*/
if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
- charge_get_state() != PWR_STATE_CHARGE) {
-
+ charge_get_state() != PWR_STATE_CHARGE) {
power_ticks++;
- led_set_color_battery(LED_RIGHT_PORT, power_ticks
- % LED_TICKS_PER_CYCLE_S3 < POWER_LED_ON_S3_TICKS
- ? LED_WHITE : LED_OFF);
- led_set_color_battery(LED_LEFT_PORT, power_ticks
- % LED_TICKS_PER_CYCLE_S3 < POWER_LED_ON_S3_TICKS
- ? LED_WHITE : LED_OFF);
+ led_set_color_battery(LED_RIGHT_PORT,
+ power_ticks % LED_TICKS_PER_CYCLE_S3 <
+ POWER_LED_ON_S3_TICKS ?
+ LED_WHITE :
+ LED_OFF);
+ led_set_color_battery(LED_LEFT_PORT,
+ power_ticks % LED_TICKS_PER_CYCLE_S3 <
+ POWER_LED_ON_S3_TICKS ?
+ LED_WHITE :
+ LED_OFF);
return;
}
@@ -165,30 +166,38 @@ static void led_set_battery(void)
case PWR_STATE_DISCHARGE:
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) {
if (charge_get_percent() < 10)
- led_set_color_battery(LED_RIGHT_PORT,
- (battery_ticks % LED_TICKS_PER_CYCLE
- < LED_ON_TICKS) ? LED_AMBER : LED_OFF);
+ led_set_color_battery(
+ LED_RIGHT_PORT,
+ (battery_ticks % LED_TICKS_PER_CYCLE <
+ LED_ON_TICKS) ?
+ LED_AMBER :
+ LED_OFF);
else
led_set_color_battery(LED_RIGHT_PORT, LED_OFF);
}
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) {
if (charge_get_percent() < 10)
- led_set_color_battery(LED_LEFT_PORT,
- (battery_ticks % LED_TICKS_PER_CYCLE
- < LED_ON_TICKS) ? LED_AMBER : LED_OFF);
+ led_set_color_battery(
+ LED_LEFT_PORT,
+ (battery_ticks % LED_TICKS_PER_CYCLE <
+ LED_ON_TICKS) ?
+ LED_AMBER :
+ LED_OFF);
else
led_set_color_battery(LED_LEFT_PORT, LED_OFF);
}
break;
case PWR_STATE_ERROR:
if (led_auto_control_is_enabled(EC_LED_ID_RIGHT_LED)) {
- led_set_color_battery(LED_RIGHT_PORT,
+ led_set_color_battery(
+ LED_RIGHT_PORT,
(battery_ticks & 0x1) ? LED_AMBER : LED_OFF);
}
if (led_auto_control_is_enabled(EC_LED_ID_LEFT_LED)) {
- led_set_color_battery(LED_LEFT_PORT,
+ led_set_color_battery(
+ LED_LEFT_PORT,
(battery_ticks & 0x1) ? LED_AMBER : LED_OFF);
}
break;
@@ -197,12 +206,13 @@ static void led_set_battery(void)
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);
+ set_active_port_color(LED_WHITE);
+ break;
+ case PWR_STATE_FORCED_IDLE:
+ set_active_port_color(
+ (battery_ticks % LED_TICKS_PER_CYCLE < LED_ON_TICKS) ?
+ LED_AMBER :
+ LED_OFF);
break;
default:
/* Other states don't alter LED behavior */