summaryrefslogtreecommitdiff
path: root/board/daisy/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/daisy/board.c')
-rw-r--r--board/daisy/board.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/board/daisy/board.c b/board/daisy/board.c
index 2d09a79a04..f8612a1231 100644
--- a/board/daisy/board.c
+++ b/board/daisy/board.c
@@ -9,8 +9,10 @@
#include "dma.h"
#include "i2c.h"
#include "gpio.h"
+#include "pmu_tpschrome.h"
#include "registers.h"
#include "spi.h"
+#include "task.h"
#include "util.h"
/*
@@ -195,3 +197,35 @@ void board_keyboard_suppress_noise(void)
gpio_set_level(GPIO_CODEC_INT, 0);
gpio_set_level(GPIO_CODEC_INT, 1);
}
+
+int board_get_ac(void)
+{
+ /*
+ * Detect AC state using combined gpio pins
+ *
+ * On daisy and snow, there's no single gpio signal to detect AC.
+ * GPIO_AC_PWRBTN_L provides AC on and PWRBTN release.
+ * GPIO_KB_PWR_ON_L provides PWRBTN release.
+ *
+ * When AC plugged, both GPIOs will be high.
+ *
+ * One drawback of this detection is, when press-and-hold power
+ * button. AC state will be unknown. This function will fallback
+ * to PMU VACG.
+ */
+
+ int ac_good = 1, battery_good;
+
+ if (gpio_get_level(GPIO_KB_PWR_ON_L))
+ return gpio_get_level(GPIO_AC_PWRBTN_L);
+
+ /* Check PMU VACG */
+ if (!in_interrupt_context())
+ pmu_get_power_source(&ac_good, &battery_good);
+
+ /*
+ * Charging task only interacts with AP in discharging state. So
+ * return 1 when AC status can not be detected by GPIO or VACG.
+ */
+ return ac_good;
+}