summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/npcx9_evb/board.c9
-rw-r--r--board/npcx9_evb/board.h5
-rw-r--r--driver/temp_sensor/tmp112.c36
-rw-r--r--driver/temp_sensor/tmp112.h17
4 files changed, 52 insertions, 15 deletions
diff --git a/board/npcx9_evb/board.c b/board/npcx9_evb/board.c
index 5b72579be3..2a7b1e2945 100644
--- a/board/npcx9_evb/board.c
+++ b/board/npcx9_evb/board.c
@@ -81,9 +81,16 @@ const struct fan_t fans[] = {
BUILD_ASSERT(ARRAY_SIZE(fans) == FAN_CH_COUNT);
/******************************************************************************/
+/* TMP112 sensors. Must be in the exactly same order as in enum tmp112_sensor */
+const struct tmp112_sensor_t tmp112_sensors[] = {
+ { I2C_PORT_THERMAL, TMP112_I2C_ADDR_FLAGS0 },
+};
+BUILD_ASSERT(ARRAY_SIZE(tmp112_sensors) == TMP112_COUNT);
+
+/******************************************************************************/
/* Temperature sensor. */
const struct temp_sensor_t temp_sensors[] = {
- { "System", TEMP_SENSOR_TYPE_BOARD, tmp112_get_val, 0 },
+ { "System", TEMP_SENSOR_TYPE_BOARD, tmp112_get_val, TMP112_0 },
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
diff --git a/board/npcx9_evb/board.h b/board/npcx9_evb/board.h
index bec4e7f2c4..345f601e91 100644
--- a/board/npcx9_evb/board.h
+++ b/board/npcx9_evb/board.h
@@ -88,6 +88,11 @@ enum adc_channel {
ADC_CH_COUNT
};
+enum tmp112_sensor {
+ TMP112_0,
+ TMP112_COUNT,
+};
+
enum temp_sensor_id {
TEMP_SENSOR_SYSTHERM0, /* TMP100 */
TEMP_SENSOR_COUNT
diff --git a/driver/temp_sensor/tmp112.c b/driver/temp_sensor/tmp112.c
index 04f22db89c..9a72bf273f 100644
--- a/driver/temp_sensor/tmp112.c
+++ b/driver/temp_sensor/tmp112.c
@@ -16,26 +16,28 @@
#define TMP112_SHIFT1 (16 - TMP112_RESOLUTION)
#define TMP112_SHIFT2 (TMP112_RESOLUTION - 8)
-static int temp_val_local;
+static int temp_val_local[TMP112_COUNT];
-static int raw_read16(const int offset, int *data_ptr)
+static int raw_read16(int sensor, const int offset, int *data_ptr)
{
- return i2c_read16(I2C_PORT_THERMAL, TMP112_I2C_ADDR_FLAGS0,
+ return i2c_read16(tmp112_sensors[sensor].i2c_port,
+ tmp112_sensors[sensor].i2c_addr_flags,
offset, data_ptr);
}
-static int raw_write16(const int offset, int data)
+static int raw_write16(int sensor, const int offset, int data)
{
- return i2c_write16(I2C_PORT_THERMAL, TMP112_I2C_ADDR_FLAGS0,
+ return i2c_write16(tmp112_sensors[sensor].i2c_port,
+ tmp112_sensors[sensor].i2c_addr_flags,
offset, data);
}
-static int get_temp(int *temp_ptr)
+static int get_temp(int sensor, int *temp_ptr)
{
int rv;
int temp_raw = 0;
- rv = raw_read16(TMP112_REG_TEMP, &temp_raw);
+ rv = raw_read16(sensor, TMP112_REG_TEMP, &temp_raw);
if (rv < 0)
return rv;
@@ -54,22 +56,28 @@ static inline int tmp112_reg_to_c(int16_t reg)
int tmp112_get_val(int idx, int *temp_ptr)
{
- *temp_ptr = temp_val_local;
+ if (idx >= TMP112_COUNT)
+ return EC_ERROR_INVAL;
+
+ *temp_ptr = temp_val_local[idx];
return EC_SUCCESS;
}
static void tmp112_poll(void)
{
+ int s;
int temp_c = 0;
- if (get_temp(&temp_c) == EC_SUCCESS)
- temp_val_local = C_TO_K(tmp112_reg_to_c(temp_c));
+ for (s = 0; s < TMP112_COUNT; s++) {
+ if (get_temp(s, &temp_c) == EC_SUCCESS)
+ temp_val_local[s] = C_TO_K(tmp112_reg_to_c(temp_c));
+ }
}
DECLARE_HOOK(HOOK_SECOND, tmp112_poll, HOOK_PRIO_TEMP_SENSOR);
static void tmp112_init(void)
{
- int tmp;
+ int tmp, s;
int set_mask, clr_mask;
/* 12 bit mode */
@@ -78,7 +86,9 @@ static void tmp112_init(void)
/* not oneshot mode */
clr_mask = BIT(7);
- raw_read16(TMP112_REG_CONF, &tmp);
- raw_write16(TMP112_REG_CONF, (tmp & ~clr_mask) | set_mask);
+ for (s = 0; s < TMP112_COUNT; s++) {
+ raw_read16(s, TMP112_REG_CONF, &tmp);
+ raw_write16(s, TMP112_REG_CONF, (tmp & ~clr_mask) | set_mask);
+ }
}
DECLARE_HOOK(HOOK_INIT, tmp112_init, HOOK_PRIO_DEFAULT);
diff --git a/driver/temp_sensor/tmp112.h b/driver/temp_sensor/tmp112.h
index 3386bc77ed..af9506ec5b 100644
--- a/driver/temp_sensor/tmp112.h
+++ b/driver/temp_sensor/tmp112.h
@@ -18,10 +18,25 @@
#define TMP112_REG_HYST 0x02
#define TMP112_REG_MAX 0x03
+/*
+ * I2C port and address information for all the board TMP112 sensors should be
+ * defined in an array of the following structures, with an enum tmp112_sensor
+ * indexing the array. The enum tmp112_sensor shall end with a TMP112_COUNT
+ * defining the maximum number of sensors for the board.
+ */
+
+struct tmp112_sensor_t {
+ int i2c_port;
+ int i2c_addr_flags;
+};
+
+extern const struct tmp112_sensor_t tmp112_sensors[];
+
/**
* Get the last polled value of a sensor.
*
- * @param idx Index to read. (Ignored)
+ * @param idx Index to read, from board's enum tmp112_sensor
+ * definition
*
* @param temp_ptr Destination for temperature in K.
*