summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxiong.huang <xiong.huang@bitland.corp-partner.google.com>2019-08-05 19:49:23 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-15 12:21:15 +0000
commit5a9cec3e736deb3152b30a5a8ba87e495251e338 (patch)
treee1068c50a9d549e9a771fc836da53f12a3315a66
parente86d9393ba8cdd7e54e9b03805397f37351c4c6e (diff)
downloadchrome-ec-5a9cec3e736deb3152b30a5a8ba87e495251e338.tar.gz
kodama: Redefine battery and power led behavior
Redefine battery and power led behavior instead of RGB tricolour led. BUG=b:136977971 BRANCH=master TEST=1)Reach battery and power led SPEC requirement. 2)Command "ectool led power/battery **" can control led in VT2. Cq-Depend:chromium:1730377 Change-Id: I10a4f3a62f46f961b1742e9b7890e943c090995c Signed-off-by: Xiong Huang <xiong.huang@bitland.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1734952 Reviewed-by: Yilun Lin <yllin@chromium.org> Tested-by: Paul Ma <magf@bitland.corp-partner.google.com>
-rw-r--r--board/kodama/board.h3
-rw-r--r--board/kodama/led.c198
2 files changed, 105 insertions, 96 deletions
diff --git a/board/kodama/board.h b/board/kodama/board.h
index 88f5c66e2c..9903e3ec14 100644
--- a/board/kodama/board.h
+++ b/board/kodama/board.h
@@ -23,6 +23,9 @@
#define CONFIG_USB_MUX_IT5205
+#define CONFIG_LED_ONOFF_STATES
+#define CONFIG_LED_POWER_LED
+
/* Battery */
#ifdef BOARD_KRANE
#define BATTERY_DESIRED_CHARGING_CURRENT 3500 /* mA */
diff --git a/board/kodama/led.c b/board/kodama/led.c
index 930415108c..4f793ef215 100644
--- a/board/kodama/led.c
+++ b/board/kodama/led.c
@@ -4,132 +4,138 @@
*
* Battery LED control for Kukui board.
*/
-
-#include "battery.h"
#include "charge_state.h"
#include "driver/charger/rt946x.h"
-#include "hooks.h"
#include "led_common.h"
+#include "led_onoff_states.h"
+#include "ec_commands.h"
-const enum ec_led_id supported_led_ids[] = { EC_LED_ID_BATTERY_LED };
-
-const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-
-static enum charge_state prv_chstate = PWR_STATE_INIT;
-
-#define LED_OFF MT6370_LED_ID_OFF
#define LED_RED MT6370_LED_ID1
#define LED_GREEN MT6370_LED_ID2
-#define LED_BLUE MT6370_LED_ID3
+#define LED_WHITE MT6370_LED_ID3
#define LED_MASK_OFF 0
#define LED_MASK_RED MT6370_MASK_RGB_ISNK1DIM_EN
#define LED_MASK_GREEN MT6370_MASK_RGB_ISNK2DIM_EN
-#define LED_MASK_BLUE MT6370_MASK_RGB_ISNK3DIM_EN
+#define LED_MASK_WHITE MT6370_MASK_RGB_ISNK3DIM_EN
+
+#define LED_ON_LVL 0
+#define LED_OFF_LVL 1
+
+const int led_charge_lvl_1 = 5;
+const int led_charge_lvl_2 = 97;
+
+struct led_descriptor led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = {
+ [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_RED, LED_INDEFINITE} },
+ [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} },
+ [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_GREEN, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} },
+ [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_RED, 1 * LED_ONE_SEC},
+ {LED_OFF, 1 * LED_ONE_SEC} },
+ [STATE_FACTORY_TEST] = {{EC_LED_COLOR_RED, 2 * LED_ONE_SEC},
+ {EC_LED_COLOR_GREEN, 2 * LED_ONE_SEC} },
+};
+
+const struct led_descriptor
+ led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES] = {
+ [PWR_LED_STATE_ON] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} },
+ [PWR_LED_STATE_SUSPEND_AC] = {{EC_LED_COLOR_WHITE, 3 * LED_ONE_SEC},
+ {LED_OFF, LED_ONE_SEC / 2} },
+ [PWR_LED_STATE_SUSPEND_NO_AC] = {{LED_OFF, LED_INDEFINITE} },
+ [PWR_LED_STATE_OFF] = {{LED_OFF, LED_INDEFINITE} },
+};
+
+const enum ec_led_id supported_led_ids[] = {
+ EC_LED_ID_POWER_LED,
+ EC_LED_ID_BATTERY_LED
+};
-static void kukui_led_set_battery(void)
-{
- enum charge_state chstate;
- uint8_t br[EC_LED_COLOR_COUNT] = { 0 };
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+static int led_mask = LED_MASK_OFF;
- chstate = charge_get_state();
+static void led_set_color(int mask)
+{
+ static int new_mask = LED_MASK_OFF;
- if (prv_chstate == chstate)
+ if (new_mask == mask)
return;
+ else
+ new_mask = mask;
+
+ mt6370_led_set_brightness(LED_MASK_RED, (mask & LED_MASK_RED) ?
+ LED_ON_LVL : LED_OFF_LVL);
+ mt6370_led_set_brightness(LED_MASK_GREEN, (mask & LED_MASK_GREEN) ?
+ LED_ON_LVL : LED_OFF_LVL);
+ mt6370_led_set_brightness(LED_MASK_WHITE, (mask & LED_MASK_WHITE) ?
+ LED_ON_LVL : LED_OFF_LVL);
+ mt6370_led_set_color(led_mask);
+}
- prv_chstate = chstate;
+void led_set_color_power(enum ec_led_colors color)
+{
+ if (color == EC_LED_COLOR_WHITE)
+ led_mask |= LED_MASK_WHITE;
+ else
+ led_mask &= ~LED_MASK_WHITE;
+ led_set_color(led_mask);
+}
- switch (chstate) {
- case PWR_STATE_CHARGE:
- /* Always indicate when charging, even in suspend. */
- br[EC_LED_COLOR_BLUE] = 1;
+void led_set_color_battery(enum ec_led_colors color)
+{
+ switch (color) {
+ case EC_LED_COLOR_RED:
+ led_mask |= LED_MASK_RED;
+ led_mask &= ~LED_MASK_GREEN;
break;
- case PWR_STATE_DISCHARGE:
- if (charge_get_percent() <= 10)
- br[EC_LED_COLOR_RED] = 1;
+ case EC_LED_COLOR_AMBER:
+ led_mask |= LED_MASK_RED;
+ led_mask |= LED_MASK_GREEN;
break;
- case PWR_STATE_ERROR:
- br[EC_LED_COLOR_RED] = 1;
+ case EC_LED_COLOR_GREEN:
+ led_mask &= ~LED_MASK_RED;
+ led_mask |= LED_MASK_GREEN;
break;
- case PWR_STATE_CHARGE_NEAR_FULL:
- br[EC_LED_COLOR_GREEN] = 1;
+ default: /* LED_OFF and other unsupported colors */
+ led_mask &= ~LED_MASK_RED;
+ led_mask &= ~LED_MASK_GREEN;
break;
- default:
- /* Other states don't alter LED behavior */
- return;
}
-
- led_set_brightness(EC_LED_ID_BATTERY_LED, br);
+ led_set_color(led_mask);
}
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
- if (led_id != EC_LED_ID_BATTERY_LED)
- return;
-
- brightness_range[EC_LED_COLOR_RED] = MT6370_LED_BRIGHTNESS_MAX;
- brightness_range[EC_LED_COLOR_GREEN] = MT6370_LED_BRIGHTNESS_MAX;
- brightness_range[EC_LED_COLOR_BLUE] = MT6370_LED_BRIGHTNESS_MAX;
+ if (led_id == EC_LED_ID_BATTERY_LED) {
+ brightness_range[EC_LED_COLOR_RED] = 1;
+ brightness_range[EC_LED_COLOR_AMBER] = 1;
+ brightness_range[EC_LED_COLOR_GREEN] = 1;
+ } else if (led_id == EC_LED_ID_POWER_LED) {
+ brightness_range[EC_LED_COLOR_WHITE] = 1;
+ }
}
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
{
- uint8_t red, green, blue;
-
- if (led_id != EC_LED_ID_BATTERY_LED)
+ if (led_id == EC_LED_ID_BATTERY_LED) {
+ if (brightness[EC_LED_COLOR_RED] != 0)
+ led_set_color_battery(EC_LED_COLOR_RED);
+ else if (brightness[EC_LED_COLOR_AMBER] != 0)
+ led_set_color_battery(EC_LED_COLOR_AMBER);
+ else if (brightness[EC_LED_COLOR_GREEN] != 0)
+ led_set_color_battery(EC_LED_COLOR_GREEN);
+ else
+ led_set_color_battery(LED_OFF);
+ } else if (led_id == EC_LED_ID_POWER_LED) {
+ if (brightness[EC_LED_COLOR_WHITE] != 0)
+ led_set_color_power(EC_LED_COLOR_WHITE);
+ else
+ led_set_color_power(LED_OFF);
+ } else {
return EC_ERROR_INVAL;
-
- red = brightness[EC_LED_COLOR_RED];
- green = brightness[EC_LED_COLOR_GREEN];
- blue = brightness[EC_LED_COLOR_BLUE];
-
- mt6370_led_set_brightness(LED_RED, red);
- mt6370_led_set_brightness(LED_GREEN, green);
- mt6370_led_set_brightness(LED_BLUE, blue);
-
- /* Enables LED sink power if necessary. */
- mt6370_led_set_color((red ? LED_MASK_RED : 0) |
- (blue ? LED_MASK_BLUE : 0) |
- (green ? LED_MASK_GREEN : 0));
- return EC_SUCCESS;
-}
-
-/*
- * Reset prv_chstate so that led can be updated immediately once
- * auto-controlled.
- */
-static void led_reset_auto_control(void)
-{
- prv_chstate = PWR_STATE_INIT;
-}
-
-/* Called by hook task every 1 sec */
-static void led_second(void)
-{
- if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
- kukui_led_set_battery();
- else
- led_reset_auto_control();
-}
-DECLARE_HOOK(HOOK_SECOND, led_second, HOOK_PRIO_DEFAULT);
-
-__override void led_control(enum ec_led_id led_id, enum ec_led_state state)
-{
- uint8_t br[EC_LED_COLOR_COUNT] = { 0 };
-
- if ((led_id != EC_LED_ID_RECOVERY_HW_REINIT_LED) &&
- (led_id != EC_LED_ID_SYSRQ_DEBUG_LED))
- return;
-
- if (state == LED_STATE_RESET) {
- led_reset_auto_control();
- led_auto_control(EC_LED_ID_BATTERY_LED, 1);
- return;
}
- if (state)
- br[EC_LED_COLOR_GREEN] = 1;
-
- led_auto_control(EC_LED_ID_BATTERY_LED, 0);
- led_set_brightness(EC_LED_ID_BATTERY_LED, br);
+ return EC_SUCCESS;
}