summaryrefslogtreecommitdiff
path: root/driver/temp_sensor
diff options
context:
space:
mode:
authorElmo_Lan <elmo_lan@compal.corp-partner.google.com>2018-01-12 03:45:06 -0500
committerchrome-bot <chrome-bot@chromium.org>2018-01-28 21:17:06 -0800
commite46d0fcbc8be50381cf9bf6cafc1f60cd7247ded (patch)
treeda116453076718149d43370db3f3745f6b6378e2 /driver/temp_sensor
parent4e39404604cbe0336eff7e1d087aebdec58a2021 (diff)
downloadchrome-ec-e46d0fcbc8be50381cf9bf6cafc1f60cd7247ded.tar.gz
Nami: Update for ALS and temperture sensor
Implement ALS code and add a new thermal sensor (Fintek, F75303) BUG=b:71839392 BRANCH=none TEST=Verify Nami can read ALS and thermal data via I2C by ec console. Change-Id: I0f8fd486f62508bbca30a57f435b9f26621cf34b Signed-off-by: Elmo_Lan <elmo_lan@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/863350 Commit-Ready: Elmo Lan <elmo_lan@compal.corp-partner.google.com> Tested-by: Elmo Lan <elmo_lan@compal.corp-partner.google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Elmo Lan <elmo_lan@compal.corp-partner.google.com>
Diffstat (limited to 'driver/temp_sensor')
-rw-r--r--driver/temp_sensor/f75303.c63
-rw-r--r--driver/temp_sensor/f75303.h33
2 files changed, 96 insertions, 0 deletions
diff --git a/driver/temp_sensor/f75303.c b/driver/temp_sensor/f75303.c
new file mode 100644
index 0000000000..61d672a7bd
--- /dev/null
+++ b/driver/temp_sensor/f75303.c
@@ -0,0 +1,63 @@
+/* Copyright 2018 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.
+ */
+
+/* F75303 temperature sensor module for Chrome EC */
+
+#include "common.h"
+#include "f75303.h"
+#include "i2c.h"
+#include "hooks.h"
+#include "util.h"
+
+static int temp_val_local;
+static int temp_val_remote1;
+
+/**
+ * Read 8 bits register from temp sensor.
+ */
+static int raw_read8(const int offset, int *data_ptr)
+{
+ return i2c_read8(I2C_PORT_THERMAL, F75303_I2C_ADDR, offset, data_ptr);
+}
+
+static int get_temp(const int offset, int *temp_ptr)
+{
+ int rv;
+ int temp_raw = 0;
+
+ rv = raw_read8(offset, &temp_raw);
+ if (rv != 0)
+ return rv;
+
+ *temp_ptr = temp_raw;
+ return EC_SUCCESS;
+}
+
+int f75303_get_val(int idx, int *temp_ptr)
+{
+ switch (idx) {
+ case F75303_IDX_LOCAL:
+ *temp_ptr = temp_val_local;
+ break;
+ case F75303_IDX_REMOTE:
+ *temp_ptr = temp_val_remote1;
+ break;
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+
+ return EC_SUCCESS;
+}
+
+static void f75303_sensor_poll(void)
+{
+ get_temp(F75303_TEMP_LOCAL, &temp_val_local);
+ temp_val_local = C_TO_K(temp_val_local);
+
+ get_temp(F75303_TEMP_REMOTE, &temp_val_remote1);
+ temp_val_remote1 = C_TO_K(temp_val_remote1);
+}
+DECLARE_HOOK(HOOK_SECOND, f75303_sensor_poll, HOOK_PRIO_TEMP_SENSOR);
+
diff --git a/driver/temp_sensor/f75303.h b/driver/temp_sensor/f75303.h
new file mode 100644
index 0000000000..da08898301
--- /dev/null
+++ b/driver/temp_sensor/f75303.h
@@ -0,0 +1,33 @@
+/* Copyright 2018 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.
+ */
+
+/* F75303 temperature sensor module for Chrome EC */
+
+#ifndef __CROS_EC_F75303_H
+#define __CROS_EC_F75303_H
+
+#define F75303_I2C_ADDR 0x9A /* 7-bit address is 0x4C */
+
+enum f75303_index {
+ F75303_IDX_LOCAL = 0,
+ F75303_IDX_REMOTE,
+};
+
+/* F75303 register */
+#define F75303_TEMP_LOCAL 0x00
+#define F75303_TEMP_REMOTE 0x01
+
+/**
+ * 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 f75303_get_val(int idx, int *temp_ptr);
+
+#endif /* __CROS_EC_F75303_H */