summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
Diffstat (limited to 'board')
-rw-r--r--board/spring/board.c43
-rw-r--r--board/spring/board.h10
-rw-r--r--board/spring/usb_charging.c10
3 files changed, 59 insertions, 4 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());
}