summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2017-05-08 15:46:57 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-05-18 06:03:52 -0700
commit0b077ad67173f11f8816b01213bc09f622326799 (patch)
treec788524e881233bb1c2e4691a56cea8f9b0db1bc
parent6959f42da69f0a7e1c496e14cca48893c3d2fd89 (diff)
downloadchrome-ec-0b077ad67173f11f8816b01213bc09f622326799.tar.gz
poppy/soraka: Basic LED support
This applies the simple rule: Charging port led is on, other is off. When charging, LED is amber, otherwise it's white. Open questions: - Do we want blinking on low battery? On which side(s)? In which AP states? - No blinking in S3? That's ok? - Need to add led blinking support for special debug mode - Recovery mode blinking does not work as LED is powered from a rail that is not on when AP is in S5. BRANCH=none BUG=b:37970194 TEST=Charge from one side, led is first amber, then white when battery is full. Switch side, led behaves the same way. Change-Id: I0531d72cd621148c0d0cce57a32b7310792d9936 Reviewed-on: https://chromium-review.googlesource.com/497372 Commit-Ready: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/poppy/board.h1
-rw-r--r--board/poppy/build.mk1
-rw-r--r--board/poppy/gpio.inc3
-rw-r--r--board/poppy/led.c158
l---------board/soraka/led.c1
5 files changed, 161 insertions, 3 deletions
diff --git a/board/poppy/board.h b/board/poppy/board.h
index 5b0e2d930d..bbaa65a233 100644
--- a/board/poppy/board.h
+++ b/board/poppy/board.h
@@ -34,6 +34,7 @@
#define CONFIG_FPU
#define CONFIG_I2C
#define CONFIG_I2C_MASTER
+#define CONFIG_LED_COMMON
#define CONFIG_LID_SWITCH
#define CONFIG_LOW_POWER_IDLE
#define CONFIG_LTO
diff --git a/board/poppy/build.mk b/board/poppy/build.mk
index 705891e38c..d8ae2af836 100644
--- a/board/poppy/build.mk
+++ b/board/poppy/build.mk
@@ -11,4 +11,5 @@ CHIP_VARIANT:=npcx5m6g
board-y=board.o
board-$(CONFIG_BATTERY_SMART)+=battery.o
+board-$(CONFIG_LED_COMMON)+=led.o
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o
diff --git a/board/poppy/gpio.inc b/board/poppy/gpio.inc
index 7c33a5fe05..fb8aed6b77 100644
--- a/board/poppy/gpio.inc
+++ b/board/poppy/gpio.inc
@@ -105,14 +105,11 @@ GPIO(USB_C0_TCPC_PWR, PIN(8, 4), GPIO_OUT_LOW) /* Enable C0 TCPC Power */
GPIO(USB2_OTG_ID, PIN(A, 1), GPIO_ODR_LOW) /* OTG ID */
GPIO(USB2_OTG_VBUSSENSE, PIN(9, 5), GPIO_OUT_LOW) /* OTG VBUS Sense */
-#ifdef BOARD_SORAKA
/* LEDs (2 colors on each port) */
-/* TODO(b/35585396): Implement. */
GPIO(LED_YELLOW_C0, PIN(3, 2), GPIO_OUT_LOW)
GPIO(LED_WHITE_C0, PIN(C, 6), GPIO_OUT_LOW)
GPIO(LED_YELLOW_C1, PIN(3, 1), GPIO_OUT_LOW)
GPIO(LED_WHITE_C1, PIN(3, 0), GPIO_OUT_LOW)
-#endif
/* Board ID */
GPIO(BOARD_VERSION1, PIN(C, 4), GPIO_INPUT) /* Board ID bit0 */
diff --git a/board/poppy/led.c b/board/poppy/led.c
new file mode 100644
index 0000000000..0219cce908
--- /dev/null
+++ b/board/poppy/led.c
@@ -0,0 +1,158 @@
+/* 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.
+ */
+
+#include "battery.h"
+#include "charge_manager.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 BAT_LED_ON 1
+#define BAT_LED_OFF 0
+
+const enum ec_led_id supported_led_ids[] = {
+ EC_LED_ID_LEFT_LED,
+ EC_LED_ID_RIGHT_LED,
+};
+
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+enum led_color {
+ LED_OFF = 0,
+ LED_AMBER,
+ LED_WHITE,
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
+};
+
+static void side_led_set_color(int port, enum led_color color)
+{
+ gpio_set_level(port ? GPIO_LED_YELLOW_C1 : GPIO_LED_YELLOW_C0,
+ (color == LED_AMBER) ? BAT_LED_ON : BAT_LED_OFF);
+ gpio_set_level(port ? GPIO_LED_WHITE_C1 : GPIO_LED_WHITE_C0,
+ (color == LED_WHITE) ? BAT_LED_ON : BAT_LED_OFF);
+}
+
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ brightness_range[EC_LED_COLOR_YELLOW] = 1;
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+}
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ int port;
+
+ switch (led_id) {
+ case EC_LED_ID_LEFT_LED:
+ port = 0;
+ break;
+ case EC_LED_ID_RIGHT_LED:
+ port = 1;
+ break;
+ default:
+ return EC_ERROR_PARAM1;
+ }
+
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ side_led_set_color(port, LED_WHITE);
+ else if (brightness[EC_LED_COLOR_YELLOW] != 0)
+ side_led_set_color(port, LED_AMBER);
+ else
+ side_led_set_color(port, LED_OFF);
+
+ return EC_SUCCESS;
+}
+
+/*
+ * Set active charge port color to the parameter, turn off all others.
+ * If no port is active (-1), turn off all LEDs.
+ */
+static void set_active_port_color(enum led_color color)
+{
+ int port = charge_manager_get_active_charge_port();
+
+ side_led_set_color(0, (port == 0) ? color : LED_OFF);
+ side_led_set_color(1, (port == 1) ? color : LED_OFF);
+}
+
+static void board_led_set_battery(void)
+{
+ static int battery_ticks;
+ uint32_t chflags = charge_get_flags();
+
+ battery_ticks++;
+
+ switch (charge_get_state()) {
+ case PWR_STATE_CHARGE:
+ /* Always indicate when charging, even in suspend. */
+ set_active_port_color(LED_AMBER);
+ break;
+ case PWR_STATE_DISCHARGE:
+ /*
+ * TODO(b/37970194): Do we really want to blink on low battery?
+ * If yes, what's the threshold? In S0 only?
+ */
+ if (charge_get_percent() < 12)
+ side_led_set_color(0,
+ (battery_ticks & 0x4) ? LED_WHITE : LED_OFF);
+ else
+ side_led_set_color(0, LED_OFF);
+
+ side_led_set_color(1, LED_OFF);
+ break;
+ case PWR_STATE_ERROR:
+ set_active_port_color((battery_ticks & 0x2) ?
+ LED_WHITE : LED_OFF);
+ break;
+ case PWR_STATE_CHARGE_NEAR_FULL:
+ set_active_port_color(LED_WHITE);
+ break;
+ case PWR_STATE_IDLE: /* External power connected in IDLE */
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ set_active_port_color((battery_ticks & 0x4) ?
+ LED_AMBER : LED_OFF);
+ else
+ set_active_port_color(LED_WHITE);
+ break;
+ default:
+ /* Other states don't alter LED behavior */
+ break;
+ }
+}
+
+/* Called by hook task every TICK */
+static void led_tick(void)
+{
+ if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
+ board_led_set_battery();
+}
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
+
+void led_control(enum ec_led_id led_id, enum ec_led_state state)
+{
+ if (led_id == EC_LED_ID_RECOVERY_HW_REINIT_LED) {
+ enum led_color color;
+
+ if (state == LED_STATE_RESET) {
+ led_auto_control(EC_LED_ID_BATTERY_LED, 1);
+ board_led_set_battery();
+ return;
+ }
+
+ color = state ? LED_WHITE : LED_OFF;
+
+ led_auto_control(EC_LED_ID_BATTERY_LED, 0);
+
+ side_led_set_color(0, color);
+ side_led_set_color(1, color);
+ }
+}
diff --git a/board/soraka/led.c b/board/soraka/led.c
new file mode 120000
index 0000000000..5e7dfa71bf
--- /dev/null
+++ b/board/soraka/led.c
@@ -0,0 +1 @@
+../poppy/led.c \ No newline at end of file