summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-09-11 10:31:31 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-12 19:10:30 +0000
commit221ac6d3793512f45770d78b4d67bf00693128d5 (patch)
tree1a98e1485a941343c56f53a1e0664366895396cc
parent918b2dde3a85b952356580040dbfc611204fae2a (diff)
downloadchrome-ec-221ac6d3793512f45770d78b4d67bf00693128d5.tar.gz
Implement LED control host command
This enables 'ectool led' command. BUG=chrome-os-partner:22056 TEST='ectool led battery query' and check brightness ranges are correct. TEST='ectool led battery green' and LED turns green. TEST='ectool led battery yellow' and LED turns yellow. TEST='ectool led battery auto' and LED goes back to auto control. TEST='ectool led power query' returns error. BRANCH=None Change-Id: Ide4d80851270fc17d474aee58ec46436a709745c Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/168870 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/led_kirby.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/common/led_kirby.c b/common/led_kirby.c
index 44a1b7b891..53f11d10db 100644
--- a/common/led_kirby.c
+++ b/common/led_kirby.c
@@ -11,6 +11,7 @@
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
+#include "host_command.h"
#include "pwm.h"
#include "util.h"
@@ -19,6 +20,8 @@
#define BRIGHTNESS_GREEN 25
#define BRIGHTNESS_YELLOW 50
+static int led_auto_control = 1;
+
void led_set_color(uint8_t red, uint8_t green, uint8_t yellow)
{
if (!yellow)
@@ -50,6 +53,9 @@ static void led_update_color(void)
{
enum power_state state = charge_get_state();
+ if (!led_auto_control)
+ return;
+
/* check ac. no ac -> off */
if (!extpower_is_present()) {
led_set_color(0, 0, 0);
@@ -80,6 +86,45 @@ DECLARE_HOOK(HOOK_AC_CHANGE, led_update_color, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_CHARGE_STATE_CHANGE, led_update_color, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
+/* Host commands */
+
+static int led_command_control(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_led_control *p = args->params;
+ struct ec_response_led_control *r = args->response;
+ int i;
+ uint8_t clipped[EC_LED_COLOR_COUNT];
+
+ /* Only support battery LED control */
+ if (p->led_id != EC_LED_ID_BATTERY_LED)
+ return EC_RES_INVALID_PARAM;
+
+ if (p->flags & EC_LED_FLAGS_AUTO) {
+ led_auto_control = 1;
+ led_update_color();
+ } else if (!(p->flags & EC_LED_FLAGS_QUERY)) {
+ for (i = 0; i < EC_LED_COLOR_COUNT; ++i)
+ clipped[i] = MIN(p->brightness[i], 100);
+ led_auto_control = 0;
+ led_set_color(clipped[EC_LED_COLOR_RED],
+ clipped[EC_LED_COLOR_GREEN],
+ clipped[EC_LED_COLOR_YELLOW]);
+ }
+
+ r->brightness_range[EC_LED_COLOR_RED] = 100;
+ r->brightness_range[EC_LED_COLOR_GREEN] = 100;
+ r->brightness_range[EC_LED_COLOR_BLUE] = 0;
+ r->brightness_range[EC_LED_COLOR_YELLOW] = 100;
+ r->brightness_range[EC_LED_COLOR_WHITE] = 0;
+ args->response_size = sizeof(struct ec_response_led_control);
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_LED_CONTROL,
+ led_command_control,
+ EC_VER_MASK(1));
+
+/*****************************************************************************/
/* Console commands */
static int command_led(int argc, char **argv)