mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Battery LED control for Slippy
BUG=chrome-os-partner:21180 BRANCH=slippy TEST=Manual. Verify LED is amber while charging, blue when charged, and off when external power disconnected. Signed-off-by: Dave Parker <dparker@chromium.org> Change-Id: If80bb9b0c70951d257621a2fe3ef20cd8749a033 Reviewed-on: https://gerrit.chromium.org/gerrit/62848 Tested-by: Dave Parker <dparker@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Dave Parker <dparker@chromium.org>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#ifdef HAS_TASK_KEYPROTO
|
||||
#define CONFIG_KEYBOARD_PROTOCOL_8042
|
||||
#endif
|
||||
#define CONFIG_LED_SLIPPY
|
||||
#define CONFIG_LID_SWITCH
|
||||
#define CONFIG_LPC
|
||||
#define CONFIG_PECI
|
||||
@@ -136,8 +137,8 @@ enum gpio_signal {
|
||||
GPIO_PCH_RTCRST_L, /* Not supposed to be here */
|
||||
GPIO_PCH_SRTCRST_L, /* Not supposed to be here */
|
||||
|
||||
BAT_LED0_L, /* Battery charging LED - Blue */
|
||||
BAT_LED1_L, /* Battery charging LED - Amber */
|
||||
GPIO_BAT_LED0_L, /* Battery charging LED - Blue */
|
||||
GPIO_BAT_LED1_L, /* Battery charging LED - Amber */
|
||||
|
||||
/* Number of GPIOs; not an actual GPIO */
|
||||
GPIO_COUNT
|
||||
|
||||
@@ -41,6 +41,7 @@ common-$(CONFIG_KEYBOARD_TEST)+=keyboard_test.o
|
||||
common-$(CONFIG_LED_DRIVER_LP5562)+=led_driver_lp5562.o led_lp5562.o
|
||||
common-$(CONFIG_LED_FALCO)+=led_falco.o
|
||||
common-$(CONFIG_LED_PEPPY)+=led_peppy.o
|
||||
common-$(CONFIG_LED_SLIPPY)+=led_slippy.o
|
||||
common-$(CONFIG_LID_SWITCH)+=lid_switch.o
|
||||
common-$(CONFIG_LPC)+=port80.o
|
||||
common-$(CONFIG_ONEWIRE_LED)+=onewire_led.o
|
||||
|
||||
91
common/led_slippy.c
Normal file
91
common/led_slippy.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/* 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.
|
||||
*
|
||||
* Power and battery LED control for Slippy.
|
||||
*/
|
||||
|
||||
#include "battery.h"
|
||||
#include "charge_state.h"
|
||||
#include "chipset.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "lid_switch.h"
|
||||
|
||||
#define LED_TOTAL_TICKS 16
|
||||
#define LED_ON_TICKS 4
|
||||
|
||||
enum led_color {
|
||||
LED_OFF = 0,
|
||||
LED_BLUE,
|
||||
LED_AMBER,
|
||||
LED_COLOR_COUNT /* Number of colors, not a color itself */
|
||||
};
|
||||
|
||||
static int led_set_color(enum led_color color, enum gpio_signal gpio_led_blue_l,
|
||||
enum gpio_signal gpio_led_amber_l)
|
||||
{
|
||||
switch (color) {
|
||||
case LED_OFF:
|
||||
gpio_set_level(gpio_led_blue_l, 1);
|
||||
gpio_set_level(gpio_led_amber_l, 1);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
gpio_set_level(gpio_led_blue_l, 0);
|
||||
gpio_set_level(gpio_led_amber_l, 1);
|
||||
break;
|
||||
case LED_AMBER:
|
||||
gpio_set_level(gpio_led_blue_l, 1);
|
||||
gpio_set_level(gpio_led_amber_l, 0);
|
||||
break;
|
||||
default:
|
||||
return EC_ERROR_UNKNOWN;
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int bat_led_set_color(enum led_color color)
|
||||
{
|
||||
return led_set_color(color, GPIO_BAT_LED0_L, GPIO_BAT_LED1_L);
|
||||
}
|
||||
|
||||
/* Called by hook task every 250mSec */
|
||||
static void led_tick(void)
|
||||
{
|
||||
static int ticks;
|
||||
uint32_t chflags = charge_get_flags();
|
||||
|
||||
/* Battery LED is on the c-panel */
|
||||
if (!lid_is_open()) {
|
||||
bat_led_set_color(LED_OFF);
|
||||
return;
|
||||
}
|
||||
|
||||
ticks++;
|
||||
|
||||
switch (charge_get_state()) {
|
||||
case PWR_STATE_CHARGE:
|
||||
bat_led_set_color(LED_AMBER);
|
||||
break;
|
||||
case PWR_STATE_CHARGE_NEAR_FULL:
|
||||
bat_led_set_color(LED_BLUE);
|
||||
break;
|
||||
case PWR_STATE_DISCHARGE:
|
||||
bat_led_set_color(LED_OFF);
|
||||
break;
|
||||
case PWR_STATE_ERROR:
|
||||
bat_led_set_color((ticks & 0x2) ? LED_AMBER : LED_OFF);
|
||||
break;
|
||||
case PWR_STATE_IDLE: /* External power connected in IDLE state. */
|
||||
if (chflags & CHARGE_FLAG_FORCE_IDLE)
|
||||
bat_led_set_color((ticks & 0x4) ? LED_BLUE : LED_OFF);
|
||||
else
|
||||
bat_led_set_color(LED_BLUE);
|
||||
break;
|
||||
default:
|
||||
/* Other states don't alter LED behavior */
|
||||
break;
|
||||
}
|
||||
}
|
||||
DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
|
||||
|
||||
@@ -105,6 +105,7 @@ CONFIG_KEYBOARD_SUPPRESS_NOISE
|
||||
CONFIG_LED_DRIVER_LP5562
|
||||
CONFIG_LED_FALCO
|
||||
CONFIG_LED_PEPPY
|
||||
CONFIG_LED_SLIPPY
|
||||
CONFIG_LID_SWITCH
|
||||
CONFIG_LOW_POWER_IDLE
|
||||
CONFIG_LPC
|
||||
|
||||
Reference in New Issue
Block a user