summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-02-05 15:03:03 +0800
committerChromeBot <chrome-bot@google.com>2013-02-05 20:16:17 -0800
commitf4a9ffdee34f2d59b120eded5688efa3491d5ab1 (patch)
tree8bc4c87cc7691b0daf446fc1c4d4af7470d87f18
parentc817977583ddfaa718b421f7e2896ff8d165adae (diff)
downloadchrome-ec-f4a9ffdee34f2d59b120eded5688efa3491d5ab1.tar.gz
spring: Control battery LED
This implements a basic battery LED policy: - Charged: green - Charging: yellow - Error: red - No charger: off BUG=chrome-os-partner:17561 TEST=Manual BRANCH=none Change-Id: I7fa8242efa4d0382d8ef0cafe80f01d44c390397 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/42607 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/board.c43
-rw-r--r--board/spring/board.h10
-rw-r--r--board/spring/usb_charging.c10
-rw-r--r--common/pmu_tps65090_charger.c26
-rw-r--r--include/pmu_tpschrome.h18
5 files changed, 90 insertions, 17 deletions
diff --git a/board/spring/board.c b/board/spring/board.c
index 1ac1107625..3b26ab4cf9 100644
--- a/board/spring/board.c
+++ b/board/spring/board.c
@@ -12,8 +12,10 @@
#include "gpio.h"
#include "hooks.h"
#include "i2c.h"
+#include "lp5562.h"
#include "pmu_tpschrome.h"
#include "registers.h"
+#include "smart_battery.h"
#include "stm32_adc.h"
#include "timer.h"
#include "util.h"
@@ -26,6 +28,11 @@
#define HARD_RESET_TIMEOUT_MS 5
+/* We use yellow LED instead of blue LED. Re-map colors here. */
+#define LED_COLOR_GREEN LP5562_COLOR_GREEN
+#define LED_COLOR_YELLOW LP5562_COLOR_BLUE
+#define LED_COLOR_RED LP5562_COLOR_RED
+
/* GPIO interrupt handlers prototypes */
#ifndef CONFIG_TASK_GAIAPOWER
#define gaia_power_event NULL
@@ -290,3 +297,39 @@ int board_get_ac(void)
/* use TPSChrome VACG signal to detect AC state */
return gpio_get_level(GPIO_BCHGR_VACG);
}
+
+int board_battery_led(enum charging_state state)
+{
+ int current;
+ uint32_t color = LED_COLOR_RED;
+
+ /*
+ * LED power is controlled by accessory detection. We only
+ * set color here.
+ */
+ switch (state) {
+ case ST_IDLE:
+ color = LED_COLOR_GREEN;
+ break;
+ case ST_DISCHARGING: /* Battery assist */
+ case ST_PRE_CHARGING:
+ color = LED_COLOR_YELLOW;
+ break;
+ case ST_CHARGING:
+ if (battery_desired_current(&current)) {
+ /* Cannot talk to the battery. Set LED to red. */
+ color = LED_COLOR_RED;
+ break;
+ }
+ if (current)
+ color = LED_COLOR_YELLOW;
+ else
+ color = LED_COLOR_GREEN;
+ break;
+ case ST_CHARGING_ERROR:
+ color = LED_COLOR_RED;
+ break;
+ }
+
+ return lp5562_set_color(color);
+}
diff --git a/board/spring/board.h b/board/spring/board.h
index dee62008ce..757e26bcea 100644
--- a/board/spring/board.h
+++ b/board/spring/board.h
@@ -58,7 +58,7 @@
/* Charger/accessories detection */
#define CONFIG_TSU6721
-/* LED driver */
+/* Battery LED driver */
#define CONFIG_LP5562
/* Timer selection */
@@ -137,6 +137,9 @@ enum ilim_config {
ILIM_CONFIG_PWM,
};
+/* Forward declaration */
+enum charging_state;
+
void configure_board(void);
void matrix_interrupt(enum gpio_signal signal);
@@ -157,7 +160,10 @@ void board_ilim_config(enum ilim_config config);
void board_pwm_duty_cycle(int percent);
/* Update USB port status */
-void board_usb_charge_update(void);
+void board_usb_charge_update(int force_update);
+
+/* Update battery LED color */
+int board_battery_led(enum charging_state state);
#endif /* !__ASSEMBLER__ */
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c
index fea46b333a..66b6ad667c 100644
--- a/board/spring/usb_charging.c
+++ b/board/spring/usb_charging.c
@@ -8,6 +8,7 @@
#include "board.h"
#include "console.h"
#include "gpio.h"
+#include "lp5562.h"
#include "registers.h"
#include "task.h"
#include "timer.h"
@@ -129,6 +130,11 @@ static void usb_device_change(int dev_type)
else
gpio_set_level(GPIO_BOOST_EN, 1);
+ if (dev_type & TSU6721_TYPE_VBUS_DEBOUNCED)
+ lp5562_poweron();
+ else
+ lp5562_poweroff();
+
/* Log to console */
CPRINTF("[%T USB Attached: ");
if (dev_type == TSU6721_TYPE_NONE)
@@ -157,13 +163,13 @@ static void usb_device_change(int dev_type)
CPRINTF("Unknown]\n");
}
-void board_usb_charge_update(void)
+void board_usb_charge_update(int force_update)
{
int int_val = tsu6721_get_interrupts();
if (int_val & TSU6721_INT_DETACH)
usb_device_change(TSU6721_TYPE_NONE);
- else if (int_val)
+ else if (int_val || force_update)
usb_device_change(tsu6721_get_device_type());
}
diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c
index 14475a1c71..3df1ef3350 100644
--- a/common/pmu_tps65090_charger.c
+++ b/common/pmu_tps65090_charger.c
@@ -5,6 +5,7 @@
* TI TPS65090 PMU charging task.
*/
+#include "board.h"
#include "clock.h"
#include "chipset.h"
#include "common.h"
@@ -41,15 +42,6 @@
#define T2_USEC (10 * SECOND)
#define T3_USEC (10 * SECOND)
-/* Non-SBS charging states */
-enum charging_state {
- ST_IDLE,
- ST_PRE_CHARGING,
- ST_CHARGING,
- ST_CHARGING_ERROR,
- ST_DISCHARGING,
-};
-
static const char * const state_list[] = {
"idle",
"pre-charging",
@@ -373,6 +365,14 @@ static int calc_next_state(int state)
return ST_IDLE;
}
+int __board_battery_led(enum charging_state state)
+{
+ return EC_SUCCESS;
+}
+
+int board_battery_led(enum charging_state state)
+ __attribute__((weak, alias("__board_battery_led")));
+
void pmu_charger_task(void)
{
int state = ST_IDLE;
@@ -399,6 +399,7 @@ void pmu_charger_task(void)
tsu6721_init(); /* Init here until we can do with HOOK_INIT */
gpio_enable_interrupt(GPIO_USB_CHG_INT);
+ board_usb_charge_update(1);
#endif
while (1) {
@@ -406,7 +407,7 @@ void pmu_charger_task(void)
pmu_clear_irq();
#ifdef CONFIG_TSU6721
- board_usb_charge_update();
+ board_usb_charge_update(0);
#endif
/*
@@ -417,8 +418,7 @@ void pmu_charger_task(void)
* failed.
*/
next_state = pre_charging_count > PRE_CHARGING_RETRY ?
- calc_next_state(ST_IDLE) :
- calc_next_state(state);
+ ST_CHARGING_ERROR : calc_next_state(state);
if (next_state != state) {
/* Reset state of charge moving average window */
@@ -458,6 +458,8 @@ void pmu_charger_task(void)
}
}
+ board_battery_led(state);
+
switch (state) {
case ST_CHARGING:
case ST_CHARGING_ERROR:
diff --git a/include/pmu_tpschrome.h b/include/pmu_tpschrome.h
index 4e42ec7e77..3de4c37315 100644
--- a/include/pmu_tpschrome.h
+++ b/include/pmu_tpschrome.h
@@ -10,6 +10,15 @@
#include "gpio.h"
+/* Non-SBS charging states */
+enum charging_state {
+ ST_IDLE,
+ ST_PRE_CHARGING,
+ ST_CHARGING,
+ ST_CHARGING_ERROR,
+ ST_DISCHARGING,
+};
+
/* JEITA temperature threshold */
enum TPS_TEMPERATURE {
TSET_T1,
@@ -224,7 +233,14 @@ int board_get_ac(void);
*/
void board_hard_reset(void);
-/* Wake TPS65090 charger task, but throttled to at most one call per tick. */
+/**
+ * Update battery LED according to charger state.
+ */
+int board_battery_led(enum charging_state state);
+
+/**
+ * Wake TPS65090 charger task, but throttled to at most one call per tick
+ */
void pmu_task_throttled_wake(void);
#endif /* __CROS_EC_TPSCHROME_H */