From 1178484e0e728ab123b8bf3433624c92936b7229 Mon Sep 17 00:00:00 2001 From: Simon Que Date: Thu, 9 Aug 2012 10:51:39 -0700 Subject: Handle IRQ from TPS65090, pass AC status to AP Changes made by this patch: 1. Create IRQ handler for the TPS65090 IRQ. IRQ wakes up charger task. 2. Charger task sets the AC_STATUS GPIO based on the AC status. 3. Initialize PMU at power-on. BRANCH=snow BUG=chrome-os-partner:11739 TEST=Power on the system, with servo v2 connected to EC console. Plug and unplug AC. The IRQ handler should be triggered. Change-Id: Ice23411c275111fdb56d2c47ba28c3c44dee4d71 Signed-off-by: Simon Que Reviewed-on: https://gerrit.chromium.org/gerrit/29914 Commit-Ready: Rong Chang Reviewed-by: Rong Chang Tested-by: Rong Chang --- common/pmu_tps65090_charger.c | 46 +++++++------------------------------------ 1 file changed, 7 insertions(+), 39 deletions(-) (limited to 'common/pmu_tps65090_charger.c') diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index 62c84bb342..29f6dda19c 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -57,38 +57,6 @@ static void enable_charging(int enable) gpio_set_level(GPIO_CHARGER_EN, enable); } - -/** - * Get AC state through GPIO - * - * @return 0 AC off - * @return 1 AC on - * - * TODO: This is a board specific function, should be moved to - * system_common.c or board.c - */ -static int 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. - * Hence the ac state can be logical OR of these two signal line. - * - * One drawback of this detection is, when press-and-hold power - * button. AC state will be unknown. The implementation below treats - * that condition as AC off. - * - * TODO(rongchang): move board related function to board/ and common - * interface to system_get_ac() - */ - - return gpio_get_level(GPIO_AC_PWRBTN_L) && - gpio_get_level(GPIO_KB_PWR_ON_L); -} - /* * TODO(rongchang): move battery vendor specific functions to battery pack * module @@ -182,7 +150,7 @@ static int calc_next_state(int state) case ST_IDLE: /* Check AC and chiset state */ - if (!get_ac()) { + if (!pmu_get_ac()) { if (chipset_in_state(CHIPSET_STATE_ON)) return ST_DISCHARGING; @@ -224,7 +192,7 @@ static int calc_next_state(int state) return wait_t1_idle(); case ST_PRE_CHARGING: - if (!get_ac()) + if (!pmu_get_ac()) return wait_t1_idle(); /* If the battery goes online after enable the charger, @@ -238,7 +206,7 @@ static int calc_next_state(int state) case ST_CHARGING: /* Go back to idle state when AC is unplugged */ - if (!get_ac()) + if (!pmu_get_ac()) break; /* @@ -284,7 +252,7 @@ static int calc_next_state(int state) case ST_DISCHARGING: /* Go back to idle state when AC is plugged */ - if (get_ac()) + if (pmu_get_ac()) return wait_t1_idle(); /* Check battery discharging temperature range */ @@ -319,9 +287,9 @@ void pmu_charger_task(void) int state = ST_IDLE; int next_state; - pmu_init(); - while (1) { + pmu_clear_irq(); + next_state = calc_next_state(state); if (next_state != state) { CPRINTF("[batt] state %s -> %s\n", @@ -331,6 +299,6 @@ void pmu_charger_task(void) } /* TODO(sjg@chromium.org): root cause crosbug.com/p/11285 */ - usleep(5000 * 1000); + task_wait_event(5000 * 1000); } } -- cgit v1.2.1