Clean up G781 temperature sensor power detection

This was previously done in a board-specific function across 4 boards.
Except that the board-specific function was identical in all cases
(that is, not really board-specific).  Put it back in the common
implementation to get rid of duplicated code, and use
CONFIG_TEMP_SENSOR_POWER_GPIO to indicate which GPIO rail controls the
sensor power.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I29de40001d5d4dc873e5ba8f3abb328c6271f235
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171140
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
Randall Spangler
2013-09-30 15:06:11 -07:00
committed by chrome-internal-fetch
parent bd74ad1e20
commit 05c367d9ce
12 changed files with 35 additions and 58 deletions

View File

@@ -253,14 +253,6 @@ void board_process_wake_events(uint32_t active_wake_events)
gpio_set_level(GPIO_PCH_WAKE_L, 1);
}
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void)
{
return gpio_get_level(GPIO_PP3300_DX_EN);
}
/**
* Discharge battery when on AC power for factory test.
*/
@@ -269,7 +261,6 @@ int board_discharge_on_ac(int enable)
return charger_discharge_on_ac(enable);
}
/*
* Take a nice smooth ramp and make it all chunky.
* And never turn it off. Bah. That'll do wonders for battery life.

View File

@@ -33,6 +33,7 @@
#define CONFIG_SWITCH_DEDICATED_RECOVERY
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_G781
#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PP3300_DX_EN
#define CONFIG_UART_HOST 2
#define CONFIG_USB_PORT_POWER_DUMB
#define CONFIG_WIRELESS
@@ -202,11 +203,6 @@ enum temp_sensor_id {
*/
void lcdvcc_interrupt(enum gpio_signal signal);
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void);
/* Wireless signals */
#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L
#define WIRELESS_GPIO_WWAN GPIO_PP3300_LTE_EN

View File

@@ -37,6 +37,7 @@
#define CONFIG_PWM_KBLIGHT
#define CONFIG_SWITCH_DEDICATED_RECOVERY
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PGOOD_1_8VS
#define CONFIG_TEMP_SENSOR_TMP006
#define CONFIG_UART_HOST 1
#define CONFIG_USB_PORT_POWER_SMART

View File

@@ -244,14 +244,6 @@ void board_process_wake_events(uint32_t active_wake_events)
gpio_set_level(GPIO_PCH_WAKE_L, 1);
}
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void)
{
return gpio_get_level(GPIO_PP3300_DX_EN);
}
/**
* Discharge battery when on AC power for factory test.
*/

View File

@@ -36,6 +36,7 @@
#define CONFIG_SWITCH_DEDICATED_RECOVERY
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_G781
#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PP3300_DX_EN
#define CONFIG_UART_HOST 2
#define CONFIG_USB_PORT_POWER_DUMB
#define CONFIG_WIRELESS
@@ -196,11 +197,6 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void);
/* Wireless signals */
#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L
#define WIRELESS_GPIO_WWAN GPIO_PP3300_LTE_EN

View File

@@ -203,11 +203,3 @@ void board_process_wake_events(uint32_t active_wake_events)
else
gpio_set_level(GPIO_PCH_WAKE_L, 1);
}
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void)
{
return gpio_get_level(GPIO_PP3300_DX_EN);
}

View File

@@ -20,6 +20,7 @@
#define CONFIG_PWM
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_G781
#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PP3300_DX_EN
#define CONFIG_WIRELESS
/* TODO(rspangler): port these to Rambi, or remove if not needed */
@@ -180,11 +181,6 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void);
#endif /* !__ASSEMBLER__ */
#endif /* __BOARD_H */

View File

@@ -242,14 +242,6 @@ void board_process_wake_events(uint32_t active_wake_events)
gpio_set_level(GPIO_PCH_WAKE_L, 1);
}
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void)
{
return gpio_get_level(GPIO_PP3300_DX_EN);
}
/**
* Discharge battery when on AC power for factory test.
*/

View File

@@ -36,6 +36,7 @@
#define CONFIG_SWITCH_DEDICATED_RECOVERY
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_G781
#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PP3300_DX_EN
#define CONFIG_UART_HOST 2
#define CONFIG_USB_PORT_POWER_DUMB
#define CONFIG_WIRELESS
@@ -196,11 +197,6 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
/**
* Board-specific g781 power state.
*/
int board_g781_has_power(void);
/* Wireless signals */
#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L
#define WIRELESS_GPIO_WWAN GPIO_PP3300_LTE_EN

View File

@@ -7,6 +7,7 @@
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "i2c.h"
#include "hooks.h"
#include "temp_sensor_g781.h"
@@ -15,6 +16,20 @@
static int g781_temp_val_local;
static int g781_temp_val_remote;
/**
* Determine whether the sensor is powered.
*
* @return non-zero the g781 sensor is powered.
*/
static int g781_has_power(void)
{
#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
#else
return 1;
#endif
}
static int g781_read8(const int offset, int *data_ptr)
{
return i2c_read8(I2C_PORT_THERMAL, G781_I2C_ADDR, offset, data_ptr);
@@ -48,7 +63,7 @@ static int g781_set_temp(const int offset, int temp)
int g781_get_val(int idx, int *temp_ptr)
{
if (!board_g781_has_power())
if (!g781_has_power())
return EC_ERROR_NOT_POWERED;
switch (idx) {
@@ -67,7 +82,7 @@ int g781_get_val(int idx, int *temp_ptr)
static void g781_temp_sensor_poll(void)
{
if (!board_g781_has_power())
if (!g781_has_power())
return;
g781_get_temp(G781_TEMP_LOCAL, &g781_temp_val_local);
@@ -145,7 +160,7 @@ static int command_g781(int argc, char **argv)
int offset;
int rv;
if (!board_g781_has_power()) {
if (!g781_has_power()) {
ccprintf("ERROR: Temp sensor not powered.\n");
return EC_ERROR_NOT_POWERED;
}

View File

@@ -58,8 +58,11 @@ static struct tmp006_data_t tmp006_data[TMP006_COUNT];
*/
static int tmp006_has_power(int idx)
{
/* All TMP006 sensors are powered by VS. */
return gpio_get_level(GPIO_PGOOD_1_8VS);
#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO
return gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO);
#else
return 1;
#endif
}
static int tmp006_read_die_temp(const struct tmp006_data_t *tdata,

View File

@@ -618,6 +618,13 @@
#undef CONFIG_TEMP_SENSOR_G781 /* G781 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_TMP006 /* TI TMP006 sensor, on I2C bus */
/*
* If defined, active-high GPIO which indicates temperature sensor chips are
* powered. If not defined, temperature sensors are assumed to be always
* powered.
*/
#undef CONFIG_TEMP_SENSOR_POWER_GPIO
/*****************************************************************************/
/* UART config */