summaryrefslogtreecommitdiff
path: root/board/peppy
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-10-01 14:29:45 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-07 18:30:45 +0000
commit90a6676ad531fd8c53e6398050f8093a921245fc (patch)
treeaee8387c1b1416ce46c0bdc34b7a47ffc0f0acaa /board/peppy
parent57aaa0267ec042d8b36aacf5b3efba12df4e6ec2 (diff)
downloadchrome-ec-90a6676ad531fd8c53e6398050f8093a921245fc.tar.gz
cleanup: Move board-specific LED state machines to board dirs
The LED state machine ends up being very board-specific, as does the specific configuration of LEDs and whether they're PWM'd or just GPIOs. dparker has some clever ideas for how to move more of the functionality to common/led_common.c (used at present only by peppy); that will be done as a follow-on to this CL. There's a unit test for the spring LED implementation. To keep that compiling, just use a symlink to the spring-specific implementation. No code changes; just moving around files. BUG=chrome-os-partner:18343 BRANCH=none TEST=build all boards; pass unit tests Change-Id: I5973e701a29a72575db9a161dc146855ab21cca6 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/171771 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'board/peppy')
-rw-r--r--board/peppy/board.h1
-rw-r--r--board/peppy/build.mk2
-rw-r--r--board/peppy/led.c186
3 files changed, 188 insertions, 1 deletions
diff --git a/board/peppy/board.h b/board/peppy/board.h
index ff4681aadc..160e6f1d2b 100644
--- a/board/peppy/board.h
+++ b/board/peppy/board.h
@@ -30,6 +30,7 @@
#define CONFIG_FAN_POWER_GOOD GPIO_PP5000_PGOOD
#define CONFIG_KEYBOARD_BOARD_CONFIG
#define CONFIG_KEYBOARD_PROTOCOL_8042
+#define CONFIG_LED_COMMON
#define CONFIG_POWER_BUTTON
#define CONFIG_POWER_BUTTON_X86
#define CONFIG_PWM
diff --git a/board/peppy/build.mk b/board/peppy/build.mk
index b82aa39df6..2eb0db0bc6 100644
--- a/board/peppy/build.mk
+++ b/board/peppy/build.mk
@@ -9,4 +9,4 @@
# the IC is TI Stellaris LM4
CHIP:=lm4
-board-y=board.o battery.o
+board-y=board.o battery.o led.o
diff --git a/board/peppy/led.c b/board/peppy/led.c
new file mode 100644
index 0000000000..ffdcdb8359
--- /dev/null
+++ b/board/peppy/led.c
@@ -0,0 +1,186 @@
+/* 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 Peppy.
+ */
+
+#include "battery.h"
+#include "charge_state.h"
+#include "chipset.h"
+#include "ec_commands.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "led_common.h"
+#include "util.h"
+
+#define LED_TOTAL_TICKS 16
+#define LED_ON_TICKS 4
+
+enum led_color {
+ LED_OFF = 0,
+ LED_BLUE,
+ LED_AMBER,
+ LED_PINK,
+
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
+};
+
+const enum ec_led_id supported_led_ids[] = {
+ EC_LED_ID_POWER_LED, EC_LED_ID_BATTERY_LED};
+
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+static int peppy_led_set_gpio(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;
+ case LED_PINK:
+ gpio_set_level(gpio_led_blue_l, 0);
+ gpio_set_level(gpio_led_amber_l, 0);
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+ return EC_SUCCESS;
+}
+
+static int peppy_led_set_color_battery(enum led_color color)
+{
+ return peppy_led_set_gpio(color, GPIO_BAT_LED0_L, GPIO_BAT_LED1_L);
+}
+
+static int peppy_led_set_color_power(enum led_color color)
+{
+ return peppy_led_set_gpio(color, GPIO_PWR_LED0_L, GPIO_PWR_LED1_L);
+}
+
+static int peppy_led_set_color(enum ec_led_id led_id, enum led_color color)
+{
+ int rv;
+
+ led_auto_control(led_id, 0);
+ switch (led_id) {
+ case EC_LED_ID_BATTERY_LED:
+ rv = peppy_led_set_color_battery(color);
+ break;
+ case EC_LED_ID_POWER_LED:
+ rv = peppy_led_set_color_power(color);
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+ return rv;
+}
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ if (brightness[EC_LED_COLOR_BLUE] != 0 &&
+ brightness[EC_LED_COLOR_YELLOW] != 0)
+ peppy_led_set_color(led_id, LED_PINK);
+ else if (brightness[EC_LED_COLOR_BLUE] != 0)
+ peppy_led_set_color(led_id, LED_BLUE);
+ else if (brightness[EC_LED_COLOR_YELLOW] != 0)
+ peppy_led_set_color(led_id, LED_AMBER);
+ else
+ peppy_led_set_color(led_id, LED_OFF);
+
+ 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 */
+ brightness_range[EC_LED_COLOR_BLUE] = 1;
+ brightness_range[EC_LED_COLOR_YELLOW] = 1;
+}
+
+static void peppy_led_set_power(void)
+{
+ static int power_ticks;
+ static int previous_state_suspend;
+
+ power_ticks++;
+
+ if (chipset_in_state(CHIPSET_STATE_SUSPEND)) {
+ /* Reset ticks if entering suspend so LED turns amber
+ * as soon as possible. */
+ if (!previous_state_suspend)
+ power_ticks = 0;
+
+ /* Blink once every four seconds. */
+ peppy_led_set_color_power(
+ (power_ticks % LED_TOTAL_TICKS < LED_ON_TICKS) ?
+ LED_AMBER : LED_OFF);
+
+ previous_state_suspend = 1;
+ return;
+ }
+
+ previous_state_suspend = 0;
+
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ peppy_led_set_color_power(LED_OFF);
+ else if (chipset_in_state(CHIPSET_STATE_ON))
+ peppy_led_set_color_power(LED_BLUE);
+}
+
+static void peppy_led_set_battery(void)
+{
+ static int battery_ticks;
+ uint32_t chflags = charge_get_flags();
+
+ battery_ticks++;
+
+ switch (charge_get_state()) {
+ case PWR_STATE_CHARGE:
+ peppy_led_set_color_battery(LED_AMBER);
+ break;
+ case PWR_STATE_CHARGE_NEAR_FULL:
+ peppy_led_set_color_battery(LED_BLUE);
+ break;
+ case PWR_STATE_DISCHARGE:
+ peppy_led_set_color_battery(LED_OFF);
+ break;
+ case PWR_STATE_ERROR:
+ peppy_led_set_color_battery(
+ (battery_ticks % LED_TOTAL_TICKS < LED_ON_TICKS) ?
+ LED_AMBER : LED_OFF);
+ break;
+ case PWR_STATE_IDLE: /* External power connected in IDLE. */
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ peppy_led_set_color_battery(
+ (battery_ticks & 0x4) ? LED_BLUE : LED_OFF);
+ else
+ peppy_led_set_color_battery(LED_BLUE);
+ break;
+ default:
+ /* Other states don't alter LED behavior */
+ break;
+ }
+}
+
+/* Called by hook task every 250mSec */
+static void led_tick(void)
+{
+ if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED))
+ peppy_led_set_power();
+
+ if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
+ peppy_led_set_battery();
+}
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);