summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2021-08-06 14:15:56 -0600
committerCommit Bot <commit-bot@chromium.org>2021-08-25 16:48:00 +0000
commit65e82a3f49ab5077021e8dd16e1816d71f3d96cc (patch)
treee94a62595672e81f0087bdd26470f7ec269f13bf
parenta21cecdf596ea520de514ca632303c0d0188b179 (diff)
downloadchrome-ec-65e82a3f49ab5077021e8dd16e1816d71f3d96cc.tar.gz
tmp112: Support reading TMP112 in millikelvin
TMP112 supports .0625 degrees of resolution. Retain this resolution and support reading the temp in degrees millikelvin. BUG=b:176994331 TEST=Build and run on guybrush BRANCH=None Change-Id: I2802016b1edb08678953238e7f01acdd320c37cf Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3001391 Commit-Queue: Diana Z <dzigterman@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--baseboard/guybrush/baseboard.c2
-rw-r--r--board/dewatt/board.c2
-rw-r--r--board/guybrush/board.c2
-rw-r--r--board/nipperkin/board.c2
-rw-r--r--board/npcx9_evb/board.c2
-rw-r--r--common/build.mk1
-rw-r--r--driver/temp_sensor/tmp112.c32
-rw-r--r--driver/temp_sensor/tmp112.h16
8 files changed, 41 insertions, 18 deletions
diff --git a/baseboard/guybrush/baseboard.c b/baseboard/guybrush/baseboard.c
index 675350a022..5768326c44 100644
--- a/baseboard/guybrush/baseboard.c
+++ b/baseboard/guybrush/baseboard.c
@@ -227,7 +227,7 @@ const struct temp_sensor_t temp_sensors[] = {
[TEMP_SENSOR_AMBIENT] = {
.name = "Ambient",
.type = TEMP_SENSOR_TYPE_BOARD,
- .read = tmp112_get_val,
+ .read = tmp112_get_val_k,
.idx = TMP112_AMB,
},
};
diff --git a/board/dewatt/board.c b/board/dewatt/board.c
index 54cc3a61a5..b773499326 100644
--- a/board/dewatt/board.c
+++ b/board/dewatt/board.c
@@ -370,5 +370,5 @@ int board_get_soc_temp(int idx, int *temp_k)
if (board_version == 1)
return get_temp_3v3_30k9_47k_4050b(ADC_TEMP_SENSOR_SOC, temp_k);
- return tmp112_get_val(idx, temp_k);
+ return tmp112_get_val_k(idx, temp_k);
}
diff --git a/board/guybrush/board.c b/board/guybrush/board.c
index e6e7256eec..fd260a0690 100644
--- a/board/guybrush/board.c
+++ b/board/guybrush/board.c
@@ -370,5 +370,5 @@ int board_get_soc_temp(int idx, int *temp_k)
if (board_version == 1)
return get_temp_3v3_30k9_47k_4050b(ADC_TEMP_SENSOR_SOC, temp_k);
- return tmp112_get_val(idx, temp_k);
+ return tmp112_get_val_k(idx, temp_k);
}
diff --git a/board/nipperkin/board.c b/board/nipperkin/board.c
index 3a76bb3175..ca2218ea84 100644
--- a/board/nipperkin/board.c
+++ b/board/nipperkin/board.c
@@ -150,5 +150,5 @@ int board_get_soc_temp(int idx, int *temp_k)
if (board_version == 1)
return get_temp_3v3_30k9_47k_4050b(ADC_TEMP_SENSOR_SOC, temp_k);
- return tmp112_get_val(idx, temp_k);
+ return tmp112_get_val_k(idx, temp_k);
}
diff --git a/board/npcx9_evb/board.c b/board/npcx9_evb/board.c
index 876ca7bd10..a104a409b0 100644
--- a/board/npcx9_evb/board.c
+++ b/board/npcx9_evb/board.c
@@ -90,7 +90,7 @@ 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, TMP112_0 },
+ { "System", TEMP_SENSOR_TYPE_BOARD, tmp112_get_val_k, TMP112_0 },
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
diff --git a/common/build.mk b/common/build.mk
index 7c505c066f..2ba81f6006 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -28,6 +28,7 @@ common-$(CONFIG_ACCEL_LIS2DH)+=math_util.o
common-$(CONFIG_ACCEL_LIS2DS)+=math_util.o
common-$(CONFIG_ACCEL_KXCJ9)+=math_util.o
common-$(CONFIG_ACCEL_KX022)+=math_util.o
+common-$(CONFIG_TEMP_SENSOR_TMP112)+=math_util.o
ifneq ($(CORE),cortex-m)
common-$(CONFIG_AES)+=aes.o
endif
diff --git a/driver/temp_sensor/tmp112.c b/driver/temp_sensor/tmp112.c
index 064bc70301..4da5c4e0e8 100644
--- a/driver/temp_sensor/tmp112.c
+++ b/driver/temp_sensor/tmp112.c
@@ -10,6 +10,7 @@
#include "tmp112.h"
#include "i2c.h"
#include "hooks.h"
+#include "math_util.h"
#include "util.h"
#define TMP112_RESOLUTION 12
@@ -18,7 +19,7 @@
#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
-static int temp_val_local[TMP112_COUNT];
+static int temp_mk_local[TMP112_COUNT];
static int raw_read16(int sensor, const int offset, int *data_ptr)
{
@@ -48,7 +49,7 @@ static int raw_write16(int sensor, const int offset, int data)
offset, data);
}
-static int get_temp(int sensor, int *temp_ptr)
+static int get_reg_temp(int sensor, int *temp_ptr)
{
int rv;
int temp_raw = 0;
@@ -61,32 +62,41 @@ static int get_temp(int sensor, int *temp_ptr)
return EC_SUCCESS;
}
-static inline int tmp112_reg_to_c(int16_t reg)
+static inline int tmp112_reg_to_mk(int16_t reg)
{
- int tmp;
+ int temp_mc;
- tmp = (((reg >> TMP112_SHIFT1) * 1000 ) >> TMP112_SHIFT2);
+ temp_mc = (((reg >> TMP112_SHIFT1) * 1000) >> TMP112_SHIFT2);
- return tmp / 1000;
+ return MILLI_CELSIUS_TO_MILLI_KELVIN(temp_mc);
}
-int tmp112_get_val(int idx, int *temp_ptr)
+int tmp112_get_val_k(int idx, int *temp_k_ptr)
{
if (idx >= TMP112_COUNT)
return EC_ERROR_INVAL;
- *temp_ptr = temp_val_local[idx];
+ *temp_k_ptr = MILLI_KELVIN_TO_KELVIN(temp_mk_local[idx]);
+ return EC_SUCCESS;
+}
+
+int tmp112_get_val_mk(int idx, int *temp_mk_ptr)
+{
+ if (idx >= TMP112_COUNT)
+ return EC_ERROR_INVAL;
+
+ *temp_mk_ptr = temp_mk_local[idx];
return EC_SUCCESS;
}
static void tmp112_poll(void)
{
int s;
- int temp_c = 0;
+ int temp_reg = 0;
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));
+ if (get_reg_temp(s, &temp_reg) == EC_SUCCESS)
+ temp_mk_local[s] = tmp112_reg_to_mk(temp_reg);
}
}
DECLARE_HOOK(HOOK_SECOND, tmp112_poll, HOOK_PRIO_TEMP_SENSOR);
diff --git a/driver/temp_sensor/tmp112.h b/driver/temp_sensor/tmp112.h
index fce7edc15b..d1b97b138c 100644
--- a/driver/temp_sensor/tmp112.h
+++ b/driver/temp_sensor/tmp112.h
@@ -38,11 +38,23 @@ extern const struct tmp112_sensor_t tmp112_sensors[];
* @param idx Index to read, from board's enum tmp112_sensor
* definition
*
- * @param temp_ptr Destination for temperature in K.
+ * @param temp_k_ptr Destination for temperature in K.
*
* @return EC_SUCCESS if successful, non-zero if error.
*/
-int tmp112_get_val(int idx, int *temp_ptr);
+int tmp112_get_val_k(int idx, int *temp_k_ptr);
+
+/**
+ * Get the last polled value of a sensor.
+ *
+ * @param idx Index to read, from board's enum tmp112_sensor
+ * definition
+ *
+ * @param temp_mk_ptr Destination for temperature in mK.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int tmp112_get_val_mk(int idx, int *temp_mk_ptr);
/**
* Init the sensors. Note, this will run automatically on HOOK_INIT, but is