summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Parker <dparker@chromium.org>2013-06-25 14:57:38 -0700
committerChromeBot <chrome-bot@google.com>2013-07-11 22:32:52 -0700
commitb2bc8aaa20479a87261aed8611367f11cf33c909 (patch)
tree6455c210351740621c86af9f43e40eae618f278c
parenteb8920c93921122e19c1ccf682b76d45a0bda7fd (diff)
downloadchrome-ec-b2bc8aaa20479a87261aed8611367f11cf33c909.tar.gz
Basic G781 temp sensor support for Falco and Peppy.
This lets us read the internal and external temp values. More functionality to come once we figure out what is needed. BUG=chrome-os-partner:20432 BRANCH=falco,peppy TEST=run ec 'temps' command on Falco and Peppy. Signed-off-by: Dave Parker <dparker@chromium.org> Change-Id: I4f452f438e0a158dc8b34901e3faad3ce36d28b2 Reviewed-on: https://gerrit.chromium.org/gerrit/60145 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org> Commit-Queue: Dave Parker <dparker@chromium.org> Tested-by: Dave Parker <dparker@chromium.org>
-rw-r--r--board/falco/board.c15
-rw-r--r--board/falco/board.h24
-rw-r--r--board/peppy/board.c15
-rw-r--r--board/peppy/board.h22
-rw-r--r--common/build.mk1
-rw-r--r--common/temp_sensor_g781.c46
-rw-r--r--include/temp_sensor_g781.h28
7 files changed, 132 insertions, 19 deletions
diff --git a/board/falco/board.c b/board/falco/board.c
index a812e8ea1a..4748cc415b 100644
--- a/board/falco/board.c
+++ b/board/falco/board.c
@@ -23,8 +23,8 @@
#include "registers.h"
#include "switch.h"
#include "temp_sensor.h"
+#include "temp_sensor_g781.h"
#include "timer.h"
-#include "tmp006.h"
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
@@ -168,11 +168,12 @@ const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
-/* HEY: Need correct I2C addresses and read function for external sensor */
- {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
#ifdef CONFIG_PECI
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
#endif
+ {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
+ {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4},
+ {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4},
};
struct keyboard_scan_config keyscan_config = {
@@ -213,3 +214,11 @@ 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/falco/board.h b/board/falco/board.h
index 2dc76d7190..ba9ffcfa59 100644
--- a/board/falco/board.h
+++ b/board/falco/board.h
@@ -37,6 +37,7 @@
#define CONFIG_POWER_BUTTON
#define CONFIG_PWM_FAN
#define CONFIG_TEMP_SENSOR
+#define CONFIG_TEMP_SENSOR_G781
#define CONFIG_USB_PORT_POWER_DUMB
#define CONFIG_WIRELESS
@@ -181,24 +182,31 @@ enum adc_channel {
/* AC Adapter ID voltage in mV */
ADC_AC_ADAPTER_ID_VOLTAGE,
- /* HEY: Falco MB has only one discrete thermal sensor, but it has two
- * values (one internal and one external). Both should be here.
- */
-
ADC_CH_COUNT
};
enum temp_sensor_id {
- /* HEY - need two I2C sensor values */
-
+#ifdef CONFIG_PECI
+ /* CPU die temperature via PECI */
+ TEMP_SENSOR_CPU_PECI = 0,
/* EC internal temperature sensor */
TEMP_SENSOR_EC_INTERNAL,
- /* CPU die temperature via PECI */
- TEMP_SENSOR_CPU_PECI,
+#else
+ /* EC internal temperature sensor */
+ TEMP_SENSOR_EC_INTERNAL = 0,
+#endif
+ /* G781 internal and external sensors */
+ TEMP_SENSOR_I2C_G781_INTERNAL,
+ TEMP_SENSOR_I2C_G781_EXTERNAL,
TEMP_SENSOR_COUNT
};
+/**
+ * Board-specific g781 power state.
+ */
+int board_g781_has_power(void);
+
/* HEY: The below stuff is for Link. Pick a different pin for Falco */
/* Target value for BOOTCFG. This is set to PE2/USB1_CTL1, which has an external
* pullup. If this signal is pulled to ground when the EC boots, the EC will get
diff --git a/board/peppy/board.c b/board/peppy/board.c
index fb97805ef7..8e7ed2e88c 100644
--- a/board/peppy/board.c
+++ b/board/peppy/board.c
@@ -23,8 +23,8 @@
#include "registers.h"
#include "switch.h"
#include "temp_sensor.h"
+#include "temp_sensor_g781.h"
#include "timer.h"
-#include "tmp006.h"
#include "util.h"
/* GPIO signal list. Must match order from enum gpio_signal. */
@@ -162,11 +162,12 @@ const struct i2c_port_t i2c_ports[I2C_PORTS_USED] = {
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
-/* HEY: Need correct I2C addresses and read function for external sensor */
- {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
#ifdef CONFIG_PECI
{"PECI", TEMP_SENSOR_TYPE_CPU, peci_temp_sensor_get_val, 0, 2},
#endif
+ {"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
+ {"G781Internal", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 0, 4},
+ {"G781External", TEMP_SENSOR_TYPE_BOARD, g781_get_val, 1, 4},
};
struct keyboard_scan_config keyscan_config = {
@@ -207,3 +208,11 @@ 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/peppy/board.h b/board/peppy/board.h
index a999d6f9e4..883e27a44f 100644
--- a/board/peppy/board.h
+++ b/board/peppy/board.h
@@ -36,6 +36,7 @@
#define CONFIG_POWER_BUTTON
#define CONFIG_PWM_FAN
#define CONFIG_TEMP_SENSOR
+#define CONFIG_TEMP_SENSOR_G781
#define CONFIG_USB_PORT_POWER_DUMB
#define CONFIG_WIRELESS
@@ -48,7 +49,7 @@
/* I2C ports */
#define I2C_PORT_BATTERY 0
#define I2C_PORT_CHARGER 0
-#define I2C_PORT_THERMAL 2
+#define I2C_PORT_THERMAL 5
/* There are only two I2C ports used because battery and charger share a port */
#define I2C_PORTS_USED 2
@@ -187,16 +188,27 @@ enum adc_channel {
};
enum temp_sensor_id {
- /* HEY - need two I2C sensor values */
-
+#ifdef CONFIG_PECI
+ /* CPU die temperature via PECI */
+ TEMP_SENSOR_CPU_PECI = 0,
/* EC internal temperature sensor */
TEMP_SENSOR_EC_INTERNAL,
- /* CPU die temperature via PECI */
- TEMP_SENSOR_CPU_PECI,
+#else
+ /* EC internal temperature sensor */
+ TEMP_SENSOR_EC_INTERNAL = 0,
+#endif
+ /* G781 internal and external sensors */
+ TEMP_SENSOR_I2C_G781_INTERNAL,
+ TEMP_SENSOR_I2C_G781_EXTERNAL,
TEMP_SENSOR_COUNT
};
+/**
+ * Board-specific g781 power state.
+ */
+int board_g781_has_power(void);
+
/* HEY: The below stuff is for Link. Pick a different pin for Peppy */
/* Target value for BOOTCFG. This is set to PE2/USB1_CTL1, which has an external
* pullup. If this signal is pulled to ground when the EC boots, the EC will get
diff --git a/common/build.mk b/common/build.mk
index a4f0422f67..858e05b7b9 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -57,6 +57,7 @@ common-$(HAS_TASK_LIGHTBAR)+=lightbar.o
common-$(HAS_TASK_THERMAL)+=thermal.o
common-$(HAS_TASK_VBOOTHASH)+=sha256.o vboot_hash.o
common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
+common-$(CONFIG_TEMP_SENSOR_G781)+=temp_sensor_g781.o
common-$(CONFIG_TEMP_SENSOR_TMP006)+=temp_sensor_tmp006.o
common-$(CONFIG_USB_PORT_POWER_SMART)+=usb_port_power_smart.o
common-$(CONFIG_USB_PORT_POWER_DUMB)+=usb_port_power_dumb.o
diff --git a/common/temp_sensor_g781.c b/common/temp_sensor_g781.c
new file mode 100644
index 0000000000..32f29e72f5
--- /dev/null
+++ b/common/temp_sensor_g781.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.
+ */
+
+/* G781 temperature sensor module for Chrome EC */
+
+#include "board.h"
+#include "common.h"
+#include "console.h"
+#include "i2c.h"
+#include "temp_sensor_g781.h"
+
+int g781_get_val(int idx, int *temp_ptr)
+{
+ int command;
+ int rv;
+ int temp_raw = 0;
+
+ if (!board_g781_has_power())
+ return EC_ERROR_NOT_POWERED;
+
+ switch (idx) {
+ case 0:
+ command = G781_TEMP_LOCAL;
+ break;
+ case 1:
+ command = G781_TEMP_REMOTE;
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+
+ rv = i2c_read8(I2C_PORT_THERMAL, G781_I2C_ADDR, command, &temp_raw);
+
+ if (rv < 0)
+ return rv;
+
+ /* Negative numbers are 2's compliment with sign bit 7 */
+ if (temp_raw & (1 << 7))
+ temp_raw = ~(~temp_raw & 0xff) + 1;
+
+ /* Temperature from sensor is in degrees Celsius */
+ *temp_ptr = temp_raw + 273;
+ return EC_SUCCESS;
+}
diff --git a/include/temp_sensor_g781.h b/include/temp_sensor_g781.h
new file mode 100644
index 0000000000..2e5c428bc6
--- /dev/null
+++ b/include/temp_sensor_g781.h
@@ -0,0 +1,28 @@
+/* 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.
+ */
+
+/* G781 temperature sensor module for Chrome EC */
+
+#ifndef __CROS_EC_TEMP_SENSOR_G781_H
+#define __CROS_EC_TEMP_SENSOR_G781_H
+
+#define G781_I2C_ADDR 0x98 /* 7-bit address is 0x4C */
+
+/* Chip-specific commands */
+#define G781_TEMP_LOCAL 0x00
+#define G781_TEMP_REMOTE 0x01
+
+/**
+ * Get the last polled value of a sensor.
+ *
+ * @param idx Index to read. Idx indicates whether to read die
+ * temperature or external temperature.
+ * @param temp_ptr Destination for temperature in K.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int g781_get_val(int idx, int *temp_ptr);
+
+#endif /* __CROS_EC_TEMP_SENSOR_G781_H */