oak: shutdown tmp432 if AC isn't present in non-S0 state

To reduce the power consumption in non-S0 AP power state,
Shut tmp432 down if external power isn't present.

BRANCH=none
BUG=chrome-os-partner:43118
TEST=manual
1. make BOARD=oak -j
2. shutdown AP by EC console command:
   > apshutdown
3. plug external power
4. check whether tmp432 is still running:
   > tmp432
5. unplug external power
6. check whether tmp432 is shutdown:
   > tmp432

Change-Id: I4726a18c8754dbe60070d878dff143c76d586dcc
Signed-off-by: Ben Lok <ben.lok@mediatek.com>
Reviewed-on: https://chromium-review.googlesource.com/295059
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Ben Lok
2015-08-21 19:28:32 +08:00
committed by chrome-bot
parent e8bdf07a58
commit efa83d23c7
4 changed files with 80 additions and 53 deletions

View File

@@ -196,9 +196,22 @@ void __board_i2c_set_timeout(int port, uint32_t timeout)
void i2c_set_timeout(int port, uint32_t timeout)
__attribute__((weak, alias("__board_i2c_set_timeout")));
/**
* There is a level shift for AC_OK & LID_OPEN signal between AP & EC,
* disable it (drive high) when AP is off, otherwise enable it (drive low).
*/
static void board_extpower_buffer_to_soc(void)
{
/* Drive high when AP is off (G3), else drive low */
gpio_set_level(GPIO_LEVEL_SHIFT_EN_L,
chipset_in_state(CHIPSET_STATE_HARD_OFF) ? 1 : 0);
}
/* Initialize board. */
static void board_init(void)
{
/* Enable Level shift of AC_OK & LID_OPEN signals */
board_extpower_buffer_to_soc();
/* Enable rev1 testing GPIOs */
gpio_set_level(GPIO_SYSTEM_POWER_H, 1);
/* Enable PD MCU interrupt */
@@ -465,3 +478,67 @@ void vbus_task(void)
}
}
#endif /* BOARD_REV < OAK_REV4 */
#ifdef CONFIG_TEMP_SENSOR_TMP432
static void tmp432_set_power_deferred(void)
{
/* Shut tmp432 down if not in S0 && no external power */
if (!extpower_is_present() && !chipset_in_state(CHIPSET_STATE_ON)) {
if (EC_SUCCESS != tmp432_set_power(TMP432_POWER_OFF))
CPRINTS("ERROR: Can't shutdown TMP432.");
return;
}
/* else, turn it on. */
if (EC_SUCCESS != tmp432_set_power(TMP432_POWER_ON))
CPRINTS("ERROR: Can't turn on TMP432.");
}
DECLARE_DEFERRED(tmp432_set_power_deferred);
#endif
/**
* Hook of AC change. turn on/off tmp432 depends on AP & AC status.
*/
static void board_extpower(void)
{
board_extpower_buffer_to_soc();
#ifdef CONFIG_TEMP_SENSOR_TMP432
hook_call_deferred(tmp432_set_power_deferred, 0);
#endif
}
DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT);
/* Called on AP S5 -> S3 transition, and before HOOK_CHIPSET_STARTUP */
static void board_chipset_pre_init(void)
{
/* Enable level shift of AC_OK when power on */
board_extpower_buffer_to_soc();
}
DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, board_chipset_pre_init, HOOK_PRIO_DEFAULT);
/* Called on AP S3 -> S5 transition */
static void board_chipset_shutdown(void)
{
/* Disable level shift to SoC when shutting down */
gpio_set_level(GPIO_LEVEL_SHIFT_EN_L, 1);
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT);
/* Called on AP S3 -> S0 transition */
static void board_chipset_resume(void)
{
#ifdef CONFIG_TEMP_SENSOR_TMP432
hook_call_deferred(tmp432_set_power_deferred, 0);
#endif
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
/* Called on AP S0 -> S3 transition */
static void board_chipset_suspend(void)
{
#ifdef CONFIG_TEMP_SENSOR_TMP432
hook_call_deferred(tmp432_set_power_deferred, 0);
#endif
}
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);

View File

@@ -39,6 +39,7 @@
#define CONFIG_CHARGER_V2
#define CONFIG_CHIPSET_MEDIATEK
#define CONFIG_CMD_TYPEC
#define CONFIG_EXTPOWER_GPIO
#define CONFIG_FORCE_CONSOLE_RESUME
/*
* EC_WAKE: PA0 - WKUP1
@@ -87,7 +88,7 @@
#undef CONFIG_UART_RX_DMA
#undef DEFERRABLE_MAX_COUNT
#define DEFERRABLE_MAX_COUNT 11
#define DEFERRABLE_MAX_COUNT 12
/*
* Allow dangerous commands.

View File

@@ -10,5 +10,5 @@ CHIP := stm32
CHIP_FAMILY := stm32f0
CHIP_VARIANT:= stm32f09x
board-y = board.o battery.o extpower.o led.o
board-y = board.o battery.o led.o
board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o

View File

@@ -1,51 +0,0 @@
/* Copyright 2015 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.
*/
/*
* Pure GPIO-based external power detection, buffered to PCH.
* Drive high in S5-S0 when AC_PRESENT is high, otherwise drive low.
*/
#include "chipset.h"
#include "common.h"
#include "gpio.h"
#include "hooks.h"
#include "system.h"
#include "util.h"
int extpower_is_present(void)
{
return gpio_get_level(GPIO_AC_PRESENT);
}
static void extpower_buffer_to_soc(void)
{
/* Drive high when AP is off */
gpio_set_level(GPIO_LEVEL_SHIFT_EN_L,
chipset_in_state(CHIPSET_STATE_HARD_OFF) ? 1 : 0);
}
DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, extpower_buffer_to_soc, HOOK_PRIO_DEFAULT);
static void extpower_shutdown(void)
{
/* Disable level shift to SoC when shutting down */
gpio_set_level(GPIO_LEVEL_SHIFT_EN_L, 1);
}
DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, extpower_shutdown, HOOK_PRIO_DEFAULT);
void extpower_interrupt(enum gpio_signal signal)
{
/* Trigger notification of external power change */
extpower_buffer_to_soc();
}
static void extpower_init(void)
{
extpower_buffer_to_soc();
/* Enable interrupts, now that we've initialized */
gpio_enable_interrupt(GPIO_AC_PRESENT);
}
DECLARE_HOOK(HOOK_INIT, extpower_init, HOOK_PRIO_DEFAULT);