summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-09-30 15:06:11 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-01 19:12:07 +0000
commit05c367d9ce44fdc14eaa5c060b9b16dbf7dd6a98 (patch)
tree377f6ef24cd5d9e70f1aad389bcf4d882ed2899d
parentbd74ad1e2008e31754718ecc1882a6ac98dbb11e (diff)
downloadchrome-ec-05c367d9ce44fdc14eaa5c060b9b16dbf7dd6a98.tar.gz
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>
-rw-r--r--board/falco/board.c9
-rw-r--r--board/falco/board.h6
-rw-r--r--board/link/board.h1
-rw-r--r--board/peppy/board.c8
-rw-r--r--board/peppy/board.h6
-rw-r--r--board/rambi/board.c8
-rw-r--r--board/rambi/board.h6
-rw-r--r--board/slippy/board.c8
-rw-r--r--board/slippy/board.h6
-rw-r--r--common/temp_sensor_g781.c21
-rw-r--r--common/temp_sensor_tmp006.c7
-rw-r--r--include/config.h7
12 files changed, 35 insertions, 58 deletions
diff --git a/board/falco/board.c b/board/falco/board.c
index 1a390eaae4..f682a8c11c 100644
--- a/board/falco/board.c
+++ b/board/falco/board.c
@@ -254,14 +254,6 @@ void board_process_wake_events(uint32_t active_wake_events)
}
/**
- * 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.
*/
int board_discharge_on_ac(int enable)
@@ -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.
diff --git a/board/falco/board.h b/board/falco/board.h
index 1bd0320992..f87f0eaed3 100644
--- a/board/falco/board.h
+++ b/board/falco/board.h
@@ -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
diff --git a/board/link/board.h b/board/link/board.h
index 3ff1749c41..0986ed20fa 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -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
diff --git a/board/peppy/board.c b/board/peppy/board.c
index dde622bedd..8018b158e5 100644
--- a/board/peppy/board.c
+++ b/board/peppy/board.c
@@ -245,14 +245,6 @@ void board_process_wake_events(uint32_t active_wake_events)
}
/**
- * 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.
*/
int board_discharge_on_ac(int enable)
diff --git a/board/peppy/board.h b/board/peppy/board.h
index 46d110d642..b99c759396 100644
--- a/board/peppy/board.h
+++ b/board/peppy/board.h
@@ -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
diff --git a/board/rambi/board.c b/board/rambi/board.c
index a5813dba0a..93d04940a7 100644
--- a/board/rambi/board.c
+++ b/board/rambi/board.c
@@ -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);
-}
diff --git a/board/rambi/board.h b/board/rambi/board.h
index 9792d31e51..bb48e48307 100644
--- a/board/rambi/board.h
+++ b/board/rambi/board.h
@@ -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 */
diff --git a/board/slippy/board.c b/board/slippy/board.c
index 087c03d1e3..60851ceca9 100644
--- a/board/slippy/board.c
+++ b/board/slippy/board.c
@@ -243,14 +243,6 @@ void board_process_wake_events(uint32_t active_wake_events)
}
/**
- * 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.
*/
int board_discharge_on_ac(int enable)
diff --git a/board/slippy/board.h b/board/slippy/board.h
index e56702adfe..eb84c19b6a 100644
--- a/board/slippy/board.h
+++ b/board/slippy/board.h
@@ -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
diff --git a/common/temp_sensor_g781.c b/common/temp_sensor_g781.c
index 96dd18ea60..389b12629e 100644
--- a/common/temp_sensor_g781.c
+++ b/common/temp_sensor_g781.c
@@ -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;
}
diff --git a/common/temp_sensor_tmp006.c b/common/temp_sensor_tmp006.c
index 45e81814f4..19d66d87aa 100644
--- a/common/temp_sensor_tmp006.c
+++ b/common/temp_sensor_tmp006.c
@@ -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,
diff --git a/include/config.h b/include/config.h
index 1e1568ca6b..978b512d38 100644
--- a/include/config.h
+++ b/include/config.h
@@ -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 */