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 <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/47183
Reviewed-by: Vic Yang <victoryang@chromium.org>
This commit is contained in:
Randall Spangler
2013-04-02 13:16:15 -07:00
committed by ChromeBot
parent 4d1aadaf60
commit 6d49e2660e
6 changed files with 49 additions and 66 deletions

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

46
common/extpower_snow.c Normal file
View File

@@ -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 */