summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <devin.lu@quantatw.com>2019-11-20 16:42:12 +0800
committerCommit Bot <commit-bot@chromium.org>2020-01-28 19:36:08 +0000
commit53a2f5aed395b71b221e198d2b376ecc7236a669 (patch)
treee318616d5e70cfa31f623a62e15b46cf5034326f
parentdaecaa9cdbc8e373efd9a1ecc4f5cf2b565167c8 (diff)
downloadchrome-ec-53a2f5aed395b71b221e198d2b376ecc7236a669.tar.gz
driver/temp_sensor: add support OTI502 temperature sensor
This patch adds OTI502 IR temperature sensor driver. OT502 has two temperture information which is ambient and object temperature. ambient is chip temperature and object is IR temperature. BUG=b:140817732 BRANCH=none TEST=none Change-Id: Ia49e0c7962eaa446f788a9104204c6dbe18ee97c Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1925795 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> (cherry picked from commit 1e3e4d8b438b109b91d2a85ff1ba37c47e9f8ac9) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2025081 Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org> Tested-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
-rw-r--r--driver/build.mk1
-rw-r--r--driver/temp_sensor/oti502.c67
-rw-r--r--driver/temp_sensor/oti502.h27
-rw-r--r--include/config.h1
4 files changed, 96 insertions, 0 deletions
diff --git a/driver/build.mk b/driver/build.mk
index edd97a09a9..7de8fa4ca8 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -107,6 +107,7 @@ driver-$(CONFIG_TEMP_SENSOR_F75303)+=temp_sensor/f75303.o
driver-$(CONFIG_TEMP_SENSOR_G753)+=temp_sensor/g753.o
driver-$(CONFIG_TEMP_SENSOR_G781)+=temp_sensor/g78x.o
driver-$(CONFIG_TEMP_SENSOR_G782)+=temp_sensor/g78x.o
+driver-$(CONFIG_TEMP_SENSOR_OTI502)+=temp_sensor/oti502.o
driver-$(CONFIG_TEMP_SENSOR_SB_TSI)+=temp_sensor/sb_tsi.o
driver-$(CONFIG_TEMP_SENSOR_TMP006)+=temp_sensor/tmp006.o
driver-$(CONFIG_TEMP_SENSOR_TMP112)+=temp_sensor/tmp112.o
diff --git a/driver/temp_sensor/oti502.c b/driver/temp_sensor/oti502.c
new file mode 100644
index 0000000000..8a420363e8
--- /dev/null
+++ b/driver/temp_sensor/oti502.c
@@ -0,0 +1,67 @@
+/* Copyright 2019 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.
+ */
+
+/* OTI502 temperature sensor module for Chrome EC */
+
+#include "common.h"
+#include "console.h"
+#include "oti502.h"
+#include "i2c.h"
+#include "hooks.h"
+#include "util.h"
+
+static int temp_val_ambient; /* Ambient is chip temperature*/
+static int temp_val_object; /* Object is IR temperature */
+
+static int oti502_read_block(const int offset, uint8_t *data, int len)
+{
+ return i2c_read_block(I2C_PORT_THERMAL, OTI502_I2C_ADDR_FLAGS,
+ offset, data, len);
+}
+
+int oti502_get_val(int idx, int *temp_ptr)
+{
+ switch (idx) {
+ case OTI502_IDX_AMBIENT:
+ *temp_ptr = temp_val_ambient;
+ break;
+ case OTI502_IDX_OBJECT:
+ *temp_ptr = temp_val_object;
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+
+ return EC_SUCCESS;
+}
+
+static void temp_sensor_poll(void)
+{
+ uint8_t temp_val[6];
+
+ memset(temp_val, 0, sizeof(temp_val));
+
+ oti502_read_block(0x80, temp_val, sizeof(temp_val));
+
+ if (temp_val[2] >= 0x80) {
+ /* Treat temperature as 0 degree C if temperature is negative*/
+ temp_val_ambient = 0;
+ ccprintf("Temperature ambient is negative !\n");
+ } else {
+ temp_val_ambient = ((temp_val[1] << 8) + temp_val[0]) / 200;
+ temp_val_ambient = C_TO_K(temp_val_ambient);
+ }
+
+ if (temp_val[5] >= 0x80) {
+ /* Treat temperature as 0 degree C if temperature is negative*/
+ temp_val_object = 0;
+ ccprintf("Temperature object is negative !\n");
+ } else {
+ temp_val_object = ((temp_val[4] << 8) + temp_val[5]) / 200;
+ temp_val_object = C_TO_K(temp_val_object);
+ }
+}
+DECLARE_HOOK(HOOK_SECOND, temp_sensor_poll, HOOK_PRIO_TEMP_SENSOR);
+
diff --git a/driver/temp_sensor/oti502.h b/driver/temp_sensor/oti502.h
new file mode 100644
index 0000000000..4e846282c1
--- /dev/null
+++ b/driver/temp_sensor/oti502.h
@@ -0,0 +1,27 @@
+/* Copyright 2019 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.
+ */
+
+/* OTI502 temperature sensor module for Chrome EC */
+
+#ifndef __CROS_EC_OTI502_H
+#define __CROS_EC_OTI502_H
+
+#define OTI502_I2C_ADDR_FLAGS 0x10
+
+#define OTI502_IDX_AMBIENT 0
+#define OTI502_IDX_OBJECT 1
+
+/**
+ * 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 oti502_get_val(int idx, int *temp_ptr);
+
+#endif /* __CROS_EC_OTI502_H */
diff --git a/include/config.h b/include/config.h
index 9c131a8e87..d2dd07348e 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3438,6 +3438,7 @@
#undef CONFIG_TEMP_SENSOR_G753 /* G753 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_G781 /* G781 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_G782 /* G782 sensor, on I2C bus */
+#undef CONFIG_TEMP_SENSOR_OTI502 /* OTI502 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_SB_TSI /* SB_TSI sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_TMP006 /* TI TMP006 sensor, on I2C bus */
#undef CONFIG_TEMP_SENSOR_TMP411 /* TI TMP411 sensor, on I2C bus */