summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2014-08-19 19:45:55 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-22 05:47:54 +0000
commite307172bd581c5ec3ce2944333d09412626e6e10 (patch)
tree8c2cbff04d7ee899ec906a2638c564bd627b549e
parentc7c312d057b84ebc13bf462ac884cdaf40fcb3a2 (diff)
downloadchrome-ec-e307172bd581c5ec3ce2944333d09412626e6e10.tar.gz
lightbar: Enable tap-for-battery even in G3
This adds an optional lb_power() function that the lightbar TAP sequence can use to briefly power up the lightbar rails while the AP is shut down. BUG=chrome-os-partner:29041 BRANCH=ToT TEST=manual Shut the AP down, then from the EC console run "lightbar seq tap". The lightbar should light up and briefly indicate the current power levels. You can manully force the battery status with "lightbar demo on", then use the arrow keys to change the state. Note that the Samus that I tested on had trouble recognizing when it was charging or not. That's a separate bug. Change-Id: Iad3f08506d9e049e89d0711af00da2f1aa2337e0 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/213664 Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/samus/board.h1
-rw-r--r--board/samus/power_sequence.c30
-rw-r--r--common/lightbar.c20
-rw-r--r--include/config.h7
-rw-r--r--include/lb_common.h5
5 files changed, 57 insertions, 6 deletions
diff --git a/board/samus/board.h b/board/samus/board.h
index eb13854008..0bcaddb0bb 100644
--- a/board/samus/board.h
+++ b/board/samus/board.h
@@ -23,6 +23,7 @@
#define CONFIG_KEYBOARD_BOARD_CONFIG
#define CONFIG_KEYBOARD_PROTOCOL_8042
#define CONFIG_KEYBOARD_COL2_INVERTED
+#define CONFIG_LIGHTBAR_POWER_RAILS
#define CONFIG_LOW_POWER_IDLE
#define CONFIG_POWER_BUTTON
#define CONFIG_POWER_BUTTON_X86
diff --git a/board/samus/power_sequence.c b/board/samus/power_sequence.c
index aabb83d78d..9c166093e8 100644
--- a/board/samus/power_sequence.c
+++ b/board/samus/power_sequence.c
@@ -436,6 +436,36 @@ enum power_state power_handle_state(enum power_state state)
return state;
}
+#ifdef CONFIG_LIGHTBAR_POWER_RAILS
+/* Returns true if a change was made, NOT the new state */
+int lb_power(int enabled)
+{
+ /* No change needed. */
+ if (enabled == gpio_get_level(GPIO_PP5000_EN))
+ return 0;
+
+ /* If the AP is on, we don't change the rails. */
+ if (!chipset_in_state(CHIPSET_STATE_ANY_OFF))
+ return 0;
+
+ /*
+ * If the AP is off, we can still turn the lightbar on briefly.
+ * When turning on, we have to wait for the rails to come up fully
+ * before we the lightbar ICs will respond. There's not a reliable
+ * PGOOD signal for that (I tried), so we just have to wait. These
+ * delays seem to work.
+ */
+ gpio_set_level(GPIO_PP5000_EN, enabled);
+ if (enabled)
+ msleep(10);
+ gpio_set_level(GPIO_LIGHTBAR_RESET_L, enabled);
+ if (enabled)
+ msleep(1);
+
+ return 1;
+}
+#endif
+
static int host_command_gsv(struct host_cmd_handler_args *args)
{
const struct ec_params_get_set_value *p = args->params;
diff --git a/common/lightbar.c b/common/lightbar.c
index e817b38da5..8b0352a878 100644
--- a/common/lightbar.c
+++ b/common/lightbar.c
@@ -74,7 +74,7 @@ static const struct lightbar_params_v1 default_params = {
.s3_ramp_up = 2500,
.s3_ramp_down = 10000,
.tap_tick_delay = 5000, /* oscillation step time */
- .tap_display_time = 5000000, /* total sequence time */
+ .tap_display_time = 3000000, /* total sequence time */
.tap_pct_red = 10, /* below this is red */
.tap_pct_green = 97, /* above this is green */
@@ -819,6 +819,8 @@ static uint32_t sequence_TAP_inner(void)
start = get_time();
while (1) {
+ get_battery_level();
+
if (st.battery_percent < st.p.tap_pct_red)
base_color = RED;
else if (st.battery_percent > st.p.tap_pct_green)
@@ -877,11 +879,13 @@ static uint32_t sequence_TAP(void)
uint32_t r;
uint8_t br, save[NUM_LEDS][3];
- /* TODO(crosbug.com/p/29041): Do we need more than lb_init()?
- * Yes. And then we may need to turn it off again, if the AP is still
- * off when we're done.
- */
- lb_init();
+#ifdef CONFIG_LIGHTBAR_POWER_RAILS
+ /* Request that the lightbar power rails be turned on. */
+ if (lb_power(1)) {
+ lb_init();
+ lb_set_rgb(NUM_LEDS, 0, 0, 0);
+ }
+#endif
lb_on();
for (i = 0; i < NUM_LEDS; i++)
@@ -895,6 +899,10 @@ static uint32_t sequence_TAP(void)
for (i = 0; i < NUM_LEDS; i++)
lb_set_rgb(i, save[i][0], save[i][1], save[i][2]);
+#ifdef CONFIG_LIGHTBAR_POWER_RAILS
+ /* Suggest that the lightbar power rails can be shut down again. */
+ lb_power(0);
+#endif
return r;
}
diff --git a/include/config.h b/include/config.h
index 535008525c..2a5b6d6999 100644
--- a/include/config.h
+++ b/include/config.h
@@ -652,6 +652,13 @@
#define CONFIG_LID_SWITCH
/*
+ * Support for turning the lightbar power rails on briefly when the AP is off.
+ * Enabling this requires implementing the board-specific lb_power() function
+ * to do it (see lb_common.h).
+ */
+#undef CONFIG_LIGHTBAR_POWER_RAILS
+
+/*
* Low power idle options. These are disabled by default and all boards that
* want to use low power idle must define it. When using the LFIOSC, the low
* frequency clock will be used to conserve even more power when possible.
diff --git a/include/lb_common.h b/include/lb_common.h
index f2f53aae35..49ab193254 100644
--- a/include/lb_common.h
+++ b/include/lb_common.h
@@ -34,5 +34,10 @@ void lb_start_builtin_cycle(void);
void lb_hc_cmd_dump(struct ec_response_lightbar *out);
/* Write the IC controller register given by the LIGHTBAR_CMD_REG command. */
void lb_hc_cmd_reg(const struct ec_params_lightbar *in);
+/*
+ * Optional (see config.h). Request that the lightbar power rails be on or off.
+ * Returns true if a change to the rails was made, false if it wasn't.
+ */
+int lb_power(int enabled);
#endif /* __CROS_EC_LB_COMMON_H */