From 6d49e2660ef679b4811b4b93ef11de9be2c21389 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 2 Apr 2013 13:16:15 -0700 Subject: [PATCH] Add common implementation for daisy/snow extpower_is_present The implementations are identical for daisy and snow, so move to a common file instead of having duplicate code in board.c BUG=chrome-os-partner:18343 BRANCH=none TEST=build daisy, snow Change-Id: I63597885607fd03b3bf87bcebf2146190b301f22 Signed-off-by: Randall Spangler Reviewed-on: https://gerrit.chromium.org/gerrit/47183 Reviewed-by: Vic Yang --- board/daisy/board.c | 33 ------------------------------ board/daisy/board.h | 1 + board/snow/board.c | 33 ------------------------------ board/snow/board.h | 1 + common/build.mk | 1 + common/extpower_snow.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 66 deletions(-) create mode 100644 common/extpower_snow.c diff --git a/board/daisy/board.c b/board/daisy/board.c index 2f432d0842..30930066ab 100644 --- a/board/daisy/board.c +++ b/board/daisy/board.c @@ -5,7 +5,6 @@ /* Daisy board-specific configuration */ #include "common.h" -#include "extpower.h" #include "gaia_power.h" #include "gpio.h" #include "i2c.h" @@ -184,35 +183,3 @@ void keyboard_suppress_noise(void) gpio_set_level(GPIO_CODEC_INT, 0); gpio_set_level(GPIO_CODEC_INT, 1); } - -int extpower_is_present(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/daisy/board.h b/board/daisy/board.h index 1d0a19e5bb..c013b602a0 100644 --- a/board/daisy/board.h +++ b/board/daisy/board.h @@ -20,6 +20,7 @@ /* Optional features */ #define CONFIG_CHIPSET_GAIA +#define CONFIG_EXTPOWER_SNOW #define CONFIG_I2C #define CONFIG_KEYBOARD_PROTOCOL_MKBP #define CONFIG_KEYBOARD_SUPPRESS_NOISE diff --git a/board/snow/board.c b/board/snow/board.c index 7af5011e8a..e7fdd50e37 100644 --- a/board/snow/board.c +++ b/board/snow/board.c @@ -7,7 +7,6 @@ #include "chipset.h" #include "common.h" #include "console.h" -#include "extpower.h" #include "gaia_power.h" #include "gpio.h" #include "hooks.h" @@ -302,35 +301,3 @@ int pmu_board_init(void) return failure ? EC_ERROR_UNKNOWN : EC_SUCCESS; } #endif /* CONFIG_BOARD_PMU_INIT */ - -int extpower_is_present(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.h b/board/snow/board.h index 9c14b76443..7bedbe28e0 100644 --- a/board/snow/board.h +++ b/board/snow/board.h @@ -25,6 +25,7 @@ #define CONFIG_CHIPSET_GAIA #define CONFIG_CMD_PMU #define CONFIG_CONFIGURE_BOARD_LATE +#define CONFIG_EXTPOWER_SNOW #define CONFIG_HOST_COMMAND_STATUS #define CONFIG_I2C #define CONFIG_I2C_ARBITRATION diff --git a/common/build.mk b/common/build.mk index d9bb745f9e..a7e10a8375 100644 --- a/common/build.mk +++ b/common/build.mk @@ -17,6 +17,7 @@ common-$(CONFIG_CHIPSET_X86)+=x86_power.o common-$(CONFIG_PMU_TPS65090)+=pmu_tps65090.o pmu_tps65090_charger.o common-$(CONFIG_EOPTION)+=eoption.o common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o +common-$(CONFIG_EXTPOWER_SNOW)+=extpower_snow.o common-$(CONFIG_FLASH)+=flash_common.o fmap.o common-$(CONFIG_I2C)+=i2c_commands.o common-$(CONFIG_I2C_ARBITRATION)+=i2c_arbitration.o diff --git a/common/extpower_snow.c b/common/extpower_snow.c new file mode 100644 index 0000000000..12e44696d8 --- /dev/null +++ b/common/extpower_snow.c @@ -0,0 +1,46 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* External power detection for daisy/snow/pit */ + +#include "common.h" +#include "extpower.h" +#include "gpio.h" +#include "pmu_tpschrome.h" +#include "task.h" + +int extpower_is_present(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; +} + +/* TODO: host events and hook notifications */