summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-09-19 09:41:11 -0700
committerGerrit <chrome-bot@google.com>2012-09-20 07:14:18 -0700
commitc350c20f443eb69429727f2f967522e7b2817515 (patch)
tree2726920511b4b2299f330889db46f77a952f79fe
parent07cae3f8e1f7e8b53c8b60752d4e7d519ff01a74 (diff)
downloadchrome-ec-c350c20f443eb69429727f2f967522e7b2817515.tar.gz
tpschrome: AC detection is board specific.
the PMU VACG signal used to detect AC state is connected to a GPIO, so it's a board specific configuration. On top of that, Daisy variants have custom logic on that line which is not present on the next boards, so we need to update it before doing BSP for next-gen boards. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BUG=chrome-os-partner:14313 TEST=make BOARD=snow && make BOARD=daisy on snow EC console, type "pmu" command with AC plugge and unplugged, see that the "ac gpio" line reflects the right value. BRANCH=none Change-Id: If1e19b89b2f2de45d8dddc8340931e56c5f7f0a5 Reviewed-on: https://gerrit.chromium.org/gerrit/33630 Reviewed-by: David Hendricks <dhendrix@chromium.org> Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/daisy/board.c34
-rw-r--r--board/snow/board.c33
-rw-r--r--common/pmu_tps65090.c39
-rw-r--r--common/pmu_tps65090_charger.c12
-rw-r--r--include/pmu_tpschrome.h22
5 files changed, 86 insertions, 54 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;
+}
diff --git a/board/snow/board.c b/board/snow/board.c
index 36dac730cd..c1423c316e 100644
--- a/board/snow/board.c
+++ b/board/snow/board.c
@@ -16,6 +16,7 @@
#include "power_led.h"
#include "registers.h"
#include "spi.h"
+#include "task.h"
#include "timer.h"
#include "util.h"
@@ -421,3 +422,35 @@ int board_pmu_init(void)
return failure ? EC_ERROR_UNKNOWN : EC_SUCCESS;
}
#endif /* CONFIG_BOARD_PMU_INIT */
+
+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;
+}
diff --git a/common/pmu_tps65090.c b/common/pmu_tps65090.c
index 8d6d27a170..97e3292c54 100644
--- a/common/pmu_tps65090.c
+++ b/common/pmu_tps65090.c
@@ -366,47 +366,12 @@ int pmu_low_current_charging(int enable)
void pmu_irq_handler(enum gpio_signal signal)
{
#ifdef CONFIG_AC_POWER_STATUS
- gpio_set_level(GPIO_AC_STATUS, pmu_get_ac());
+ gpio_set_level(GPIO_AC_STATUS, board_get_ac());
#endif
task_wake(TASK_ID_PMU_TPS65090_CHARGER);
CPRINTF("Charger IRQ received.\n");
}
-int pmu_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.
- *
- * TODO(rongchang): move board related function to board/ and common
- * interface to system_get_ac()
- */
-
- 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;
-}
-
int pmu_shutdown(void)
{
int offset, failure = 0;
@@ -591,7 +556,7 @@ static int command_pmu(int argc, char **argv)
if (rv)
return rv;
CPRINTF("pmu events b%08b\n", value);
- CPRINTF("ac gpio %d\n", pmu_get_ac());
+ CPRINTF("ac gpio %d\n", board_get_ac());
if (rv)
ccprintf("Failed - error %d\n", rv);
diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c
index be3abd0bb2..d710262954 100644
--- a/common/pmu_tps65090_charger.c
+++ b/common/pmu_tps65090_charger.c
@@ -194,7 +194,7 @@ static int calc_next_state(int state)
switch (state) {
case ST_IDLE:
/* Check AC and chiset state */
- if (!pmu_get_ac()) {
+ if (!board_get_ac()) {
if (chipset_in_state(CHIPSET_STATE_ON))
return ST_DISCHARGING;
return ST_IDLE;
@@ -231,7 +231,7 @@ static int calc_next_state(int state)
return ST_IDLE;
case ST_PRE_CHARGING:
- if (!pmu_get_ac())
+ if (!board_get_ac())
return ST_IDLE;
/* If the battery goes online after enable the charger,
@@ -252,7 +252,7 @@ static int calc_next_state(int state)
case ST_CHARGING:
/* Go back to idle state when AC is unplugged */
- if (!pmu_get_ac())
+ if (!board_get_ac())
return ST_IDLE;
/*
@@ -305,7 +305,7 @@ static int calc_next_state(int state)
* - battery temperature is in start charging range
* - no battery alarm
*/
- if (pmu_get_ac()) {
+ if (board_get_ac()) {
if (battery_status(&alarm))
return ST_CHARGING_ERROR;
@@ -326,7 +326,7 @@ static int calc_next_state(int state)
case ST_DISCHARGING:
/* Go back to idle state when AC is plugged */
- if (pmu_get_ac())
+ if (board_get_ac())
return ST_IDLE;
/* Prepare EC sleep after system stopped discharging */
@@ -453,7 +453,7 @@ void pmu_charger_task(void)
pre_charging_count++;
break;
default:
- if (pmu_get_ac()) {
+ if (board_get_ac()) {
wait_time = T1_USEC;
break;
} else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
diff --git a/include/pmu_tpschrome.h b/include/pmu_tpschrome.h
index 1d60c6b1cd..5f9d1e89a9 100644
--- a/include/pmu_tpschrome.h
+++ b/include/pmu_tpschrome.h
@@ -165,17 +165,6 @@ int pmu_low_current_charging(int enable);
void pmu_irq_handler(enum gpio_signal signal);
/**
- * 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
- */
-int pmu_get_ac(void);
-
-/**
* Set temperature threshold
*
* @param temp_n TSET_T1 to TSET_T4
@@ -217,6 +206,17 @@ int pmu_enable_ext_control(int enable);
int pmu_set_fastcharge(enum FASTCHARGE_TIMEOUT timeout);
/**
+ * Get AC state
+ *
+ * @return 0 AC off
+ * @return 1 AC on
+ *
+ * This is a board specific function as we get the PMU VACG signal
+ * through a GPIO.
+ */
+int board_get_ac(void);
+
+/**
* Reset the entire board if it is capable
*/
void board_hard_reset(void);