mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-09 17:11:42 +00:00
veyron: Sharing the single bicolor LED to also display power status
Veyron only has one bicolor led (green and orange) near the AC connector. I dedicated the green channel for displaying power status: * Power on: Green * Suspend: Green in breeze mode ( 1 sec on/ 3 sec off) * Power off: OFF Charging is now displayed only on the orange channel: * Fully charged / idle: Off * 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 The unfortunate side effect is that they have to share. So while the laptop is charging in standby the led will blink orange(1s)-yellow(3s). While it's a little ugly (it would have been nice to have 2 separate leds), it still provides more information than how it was done before (where there was no indication of power state). BUG=None TEST=Go through the various states (charging on/off/low and power on/off/ /suspend (warning: kernel doesn't report suspend to the EC properly yet, one can still test this by reverting c/209668 "veyron: fixed SUSPEND_L line")) BRANCH=None Change-Id: I8ca0fb0909da1a186e4e5c451d8868e977b3ca1b Signed-off-by: Alexandru M Stan <amstan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/209911 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Chris Zhong <zyw@rock-chips.com> Commit-Queue: Doug Anderson <dianders@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
3e993df474
commit
3ac281f270
@@ -19,26 +19,19 @@ const enum ec_led_id supported_led_ids[] = {
|
||||
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
|
||||
|
||||
enum led_color {
|
||||
LED_OFF = 0,
|
||||
LED_GREEN,
|
||||
LED_GREEN = 0,
|
||||
LED_ORANGE,
|
||||
LED_COLOR_COUNT /* Number of colors, not a color itself */
|
||||
};
|
||||
|
||||
static int bat_led_set_color(enum led_color color)
|
||||
static int bat_led_set(enum led_color color, int on)
|
||||
{
|
||||
switch (color) {
|
||||
case LED_OFF:
|
||||
gpio_set_level(GPIO_BAT_LED0, 1);
|
||||
gpio_set_level(GPIO_BAT_LED1, 1);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
gpio_set_level(GPIO_BAT_LED0, 1);
|
||||
gpio_set_level(GPIO_BAT_LED1, 0);
|
||||
gpio_set_level(GPIO_BAT_LED1, on ? 0 : 1);
|
||||
break;
|
||||
case LED_ORANGE:
|
||||
gpio_set_level(GPIO_BAT_LED0, 0);
|
||||
gpio_set_level(GPIO_BAT_LED1, 1);
|
||||
gpio_set_level(GPIO_BAT_LED0, on ? 0 : 1);
|
||||
break;
|
||||
default:
|
||||
return EC_ERROR_UNKNOWN;
|
||||
@@ -46,7 +39,6 @@ static int bat_led_set_color(enum led_color color)
|
||||
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 */
|
||||
@@ -57,12 +49,16 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
|
||||
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
|
||||
{
|
||||
if (EC_LED_ID_BATTERY_LED == led_id) {
|
||||
if (brightness[EC_LED_COLOR_GREEN] != 0)
|
||||
bat_led_set_color(LED_GREEN);
|
||||
else if (brightness[EC_LED_COLOR_YELLOW] != 0)
|
||||
bat_led_set_color(LED_ORANGE);
|
||||
else
|
||||
bat_led_set_color(LED_OFF);
|
||||
if (brightness[EC_LED_COLOR_GREEN] != 0) {
|
||||
bat_led_set(LED_GREEN, 1);
|
||||
bat_led_set(LED_ORANGE, 0);
|
||||
} else if (brightness[EC_LED_COLOR_YELLOW] != 0) {
|
||||
bat_led_set(LED_GREEN, 1);
|
||||
bat_led_set(LED_ORANGE, 1);
|
||||
} else {
|
||||
bat_led_set(LED_GREEN, 0);
|
||||
bat_led_set(LED_ORANGE, 0);
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
} else {
|
||||
return EC_ERROR_UNKNOWN;
|
||||
@@ -70,16 +66,34 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
|
||||
|
||||
}
|
||||
|
||||
static void veyron_led_set_power(void)
|
||||
{
|
||||
static int power_second;
|
||||
|
||||
power_second++;
|
||||
|
||||
/* PWR LED behavior:
|
||||
* Power on: Green
|
||||
* Suspend: Green in breeze mode ( 1 sec on/ 3 sec off)
|
||||
* Power off: OFF
|
||||
*/
|
||||
if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
|
||||
bat_led_set(LED_GREEN, 0);
|
||||
else if (chipset_in_state(CHIPSET_STATE_ON))
|
||||
bat_led_set(LED_GREEN, 1);
|
||||
else if (chipset_in_state(CHIPSET_STATE_SUSPEND))
|
||||
bat_led_set(LED_GREEN, (power_second & 3) ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
* Fully charged / idle: Off
|
||||
* 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
|
||||
@@ -88,30 +102,24 @@ static void veyron_led_set_battery(void)
|
||||
*/
|
||||
switch (charge_get_state()) {
|
||||
case PWR_STATE_CHARGE:
|
||||
bat_led_set_color(LED_ORANGE);
|
||||
bat_led_set(LED_ORANGE, 1);
|
||||
break;
|
||||
case PWR_STATE_CHARGE_NEAR_FULL:
|
||||
bat_led_set(LED_ORANGE, 1);
|
||||
break;
|
||||
case PWR_STATE_DISCHARGE:
|
||||
if (charge_get_percent() < 3)
|
||||
bat_led_set_color((battery_second & 1)
|
||||
? LED_OFF : LED_ORANGE);
|
||||
bat_led_set(LED_ORANGE, (battery_second & 1) ? 0 : 1);
|
||||
else if (charge_get_percent() < 10)
|
||||
bat_led_set_color((battery_second & 3)
|
||||
? LED_OFF : LED_ORANGE);
|
||||
bat_led_set(LED_ORANGE, (battery_second & 3) ? 0 : 1);
|
||||
else
|
||||
bat_led_set_color(LED_OFF);
|
||||
bat_led_set(LED_ORANGE, 0);
|
||||
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_GREEN);
|
||||
bat_led_set(LED_ORANGE, (battery_second & 1) ? 0 : 1);
|
||||
break;
|
||||
case PWR_STATE_IDLE: /* External power connected in IDLE. */
|
||||
if (chflags & CHARGE_FLAG_FORCE_IDLE)
|
||||
bat_led_set_color((battery_second & 0x2)
|
||||
? LED_GREEN : LED_ORANGE);
|
||||
else
|
||||
bat_led_set_color(LED_GREEN);
|
||||
bat_led_set(LED_ORANGE, 0);
|
||||
break;
|
||||
default:
|
||||
/* Other states don't alter LED behavior */
|
||||
@@ -122,6 +130,8 @@ static void veyron_led_set_battery(void)
|
||||
/** * 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user