diff options
author | Devin Lu <devin.lu@quantatw.com> | 2019-11-20 16:42:12 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-22 16:05:23 +0000 |
commit | 1e3e4d8b438b109b91d2a85ff1ba37c47e9f8ac9 (patch) | |
tree | 55947b447c500d121d94f5ce181a5ae19163e637 /driver/temp_sensor | |
parent | cb5112309fd345411361029fe8b281501cd1ba1f (diff) | |
download | chrome-ec-1e3e4d8b438b109b91d2a85ff1ba37c47e9f8ac9.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>
Diffstat (limited to 'driver/temp_sensor')
-rw-r--r-- | driver/temp_sensor/oti502.c | 67 | ||||
-rw-r--r-- | driver/temp_sensor/oti502.h | 27 |
2 files changed, 94 insertions, 0 deletions
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 */ |