summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 64b4b98339..7beb937268 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -110,6 +110,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 1bc0f30006..823210d2d7 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3500,6 +3500,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 */