diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2017-04-24 17:04:36 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-05-12 20:58:01 -0700 |
commit | c2f640c159b65bf6595714f24c316f2553c986e4 (patch) | |
tree | f134b11fc509fe966c607abe7cc40037cf3c3714 | |
parent | 05a8637ca0f5118da1af8d14d460d210cc2665b3 (diff) | |
download | chrome-ec-c2f640c159b65bf6595714f24c316f2553c986e4.tar.gz |
Fizz: Add LED control
This patch adds code to control the power LED.
BUG=b:37646390
BRANCH=none
TEST=Verify LED turns green, red, amber, off. Verify LED turns green
or off when chipset is on or off, respectively.
Change-Id: I1d7940d9bb4414d97c541ead802efeb8f279533e
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/486947
-rw-r--r-- | board/fizz/build.mk | 1 | ||||
-rw-r--r-- | board/fizz/led.c | 111 |
2 files changed, 112 insertions, 0 deletions
diff --git a/board/fizz/build.mk b/board/fizz/build.mk index a45e41ff09..2ff420939e 100644 --- a/board/fizz/build.mk +++ b/board/fizz/build.mk @@ -12,3 +12,4 @@ CHIP_VARIANT:=npcx5m6g board-y=board.o board-$(CONFIG_BATTERY_SMART)+=battery.o board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-y+=led.o diff --git a/board/fizz/led.c b/board/fizz/led.c new file mode 100644 index 0000000000..f22198fe7c --- /dev/null +++ b/board/fizz/led.c @@ -0,0 +1,111 @@ +/* Copyright 2017 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 Fizz + */ + +#include "chipset.h" +#include "console.h" +#include "ec_commands.h" +#include "gpio.h" +#include "hooks.h" +#include "led_common.h" +#include "util.h" + +static int led_debug; + +enum led_color { + LED_OFF = 0, + LED_RED, + LED_GREEN, + LED_AMBER, + + /* Number of colors, not a color itself */ + LED_COLOR_COUNT +}; + +static int led_set_color_power(enum led_color color) +{ + int green = 0; + int red = 0; + + switch (color) { + case LED_OFF: + break; + case LED_GREEN: + green = 1; + break; + case LED_RED: + red = 1; + break; + case LED_AMBER: + green = 1; + red = 1; + break; + default: + return EC_ERROR_UNKNOWN; + } + + gpio_set_level(GPIO_PWR_GRN_LED, green); + gpio_set_level(GPIO_PWR_RED_LED, red); + + return EC_SUCCESS; +} + +static int led_set_color(enum ec_led_id id, enum led_color color) +{ + switch (id) { + case EC_LED_ID_POWER_LED: + return led_set_color_power(color); + default: + return EC_ERROR_UNKNOWN; + } +} + +static void led_set_power(void) +{ + if (chipset_in_state(CHIPSET_STATE_ON)) { + led_set_color(EC_LED_ID_POWER_LED, LED_GREEN); + return; + } +} + +/** + * Called by hook task every 250 ms + */ +static void led_tick(void) +{ + if (led_debug) + return; + led_set_power(); +} +DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT); + +static int command_led(int argc, char **argv) +{ + enum ec_led_id id = EC_LED_ID_POWER_LED; + + if (argc < 2) + return EC_ERROR_PARAM_COUNT; + + if (!strcasecmp(argv[1], "debug")) { + led_debug ^= 1; + ccprintf("led_debug %s\n", led_debug ? "on" : "off"); + } else if (!strcasecmp(argv[1], "off")) { + led_set_color(id, LED_OFF); + } else if (!strcasecmp(argv[1], "red")) { + led_set_color(id, LED_RED); + } else if (!strcasecmp(argv[1], "green")) { + led_set_color(id, LED_GREEN); + } else if (!strcasecmp(argv[1], "amber")) { + led_set_color(id, LED_AMBER); + } else { + /* maybe handle charger_discharge_on_ac() too? */ + return EC_ERROR_PARAM1; + } + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(led, command_led, + "[debug|red|green|amber|off]", + "Turn on/off LED"); |