summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authormatt_wang <matt_wang@compal.corp-partner.google.com>2023-01-06 16:25:13 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-01-30 19:20:08 +0000
commitb9c7a21328b3ec7001b4072c46b33af27453525e (patch)
treec0a48b5b55df0cc1aebc38f038cd2e5a4aaa1a2a /driver
parent8b6f7de2a730fd8d2be3b2a576b22301a11ba3bd (diff)
downloadchrome-ec-b9c7a21328b3ec7001b4072c46b33af27453525e.tar.gz
Zephyr: Add configs for F75303
The F75303 driver needs a Kconfig, and needs to build in zephyr. Add support to the device tree parsing and definition for the F75303 i2c temperature sensors. LOW_COVERAGE_REASON=no emulator for the F75303. b:266089368 BUG=b:262409595 BRANCH=none TEST=build the project that using the F75303 success.(mushu nami markarth) Change-Id: Id769718fbcda3e4213c50c90c9c7918bc0a31a43 Signed-off-by: matt_wang <matt_wang@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4142061 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Chao Gui <chaogui@google.com> Reviewed-by: Chao Gui <chaogui@google.com>
Diffstat (limited to 'driver')
-rw-r--r--driver/temp_sensor/f75303.c60
-rw-r--r--driver/temp_sensor/f75303.h45
2 files changed, 99 insertions, 6 deletions
diff --git a/driver/temp_sensor/f75303.c b/driver/temp_sensor/f75303.c
index d83f7bc4a6..dbeaf4470c 100644
--- a/driver/temp_sensor/f75303.c
+++ b/driver/temp_sensor/f75303.c
@@ -10,10 +10,19 @@
#include "f75303.h"
#include "hooks.h"
#include "i2c.h"
+#include "math_util.h"
#include "util.h"
+#ifdef CONFIG_ZEPHYR
+#include "temp_sensor/temp_sensor.h"
+#endif
+
+#define F75303_RESOLUTION 11
+#define F75303_SHIFT1 (16 - F75303_RESOLUTION)
+#define F75303_SHIFT2 (F75303_RESOLUTION - 8)
+
static int temps[F75303_IDX_COUNT];
-static int8_t fake_temp[F75303_IDX_COUNT] = { -1, -1, -1 };
+static int8_t fake_temp[F75303_IDX_COUNT];
/**
* Read 8 bits register from temp sensor.
@@ -50,6 +59,34 @@ int f75303_get_val(int idx, int *temp)
return EC_SUCCESS;
}
+static inline int f75303_reg_to_mk(int16_t reg)
+{
+ int temp_mc;
+
+ temp_mc = (((reg >> F75303_SHIFT1) * 1000) >> F75303_SHIFT2);
+
+ return MILLI_CELSIUS_TO_MILLI_KELVIN(temp_mc);
+}
+
+int f75303_get_val_k(int idx, int *temp_k_ptr)
+{
+ if (idx >= F75303_IDX_COUNT)
+ return EC_ERROR_INVAL;
+
+ *temp_k_ptr = MILLI_KELVIN_TO_KELVIN(temps[idx]);
+ return EC_SUCCESS;
+}
+
+int f75303_get_val_mk(int idx, int *temp_mk_ptr)
+{
+ if (idx >= F75303_IDX_COUNT)
+ return EC_ERROR_INVAL;
+
+ *temp_mk_ptr = temps[idx];
+ return EC_SUCCESS;
+}
+
+#ifndef CONFIG_ZEPHYR
static void f75303_sensor_poll(void)
{
get_temp(F75303_TEMP_LOCAL, &temps[F75303_IDX_LOCAL]);
@@ -57,6 +94,18 @@ static void f75303_sensor_poll(void)
get_temp(F75303_TEMP_REMOTE2, &temps[F75303_IDX_REMOTE2]);
}
DECLARE_HOOK(HOOK_SECOND, f75303_sensor_poll, HOOK_PRIO_TEMP_SENSOR);
+#else
+void f75303_update_temperature(int idx)
+{
+ int temp_reg = 0;
+
+ if (idx >= F75303_IDX_COUNT)
+ return;
+
+ if (get_temp(idx, &temp_reg) == EC_SUCCESS)
+ temps[idx] = f75303_reg_to_mk(temp_reg);
+}
+#endif /* CONFIG_ZEPHYR */
static int f75303_set_fake_temp(int argc, const char **argv)
{
@@ -89,3 +138,12 @@ static int f75303_set_fake_temp(int argc, const char **argv)
}
DECLARE_CONSOLE_COMMAND(f75303, f75303_set_fake_temp, "<index> <value>|off",
"Set fake temperature of sensor f75303.");
+
+static void f75303_init(void)
+{
+ int index;
+
+ for (index = 0; index < F75303_IDX_COUNT; index++)
+ fake_temp[index] = -1;
+}
+DECLARE_HOOK(HOOK_INIT, f75303_init, HOOK_PRIO_TEMP_SENSOR);
diff --git a/driver/temp_sensor/f75303.h b/driver/temp_sensor/f75303.h
index f8c85231da..4632978145 100644
--- a/driver/temp_sensor/f75303.h
+++ b/driver/temp_sensor/f75303.h
@@ -14,13 +14,20 @@
#define F75303_I2C_ADDR_FLAGS 0x4C
#endif
-enum f75303_index {
- F75303_IDX_LOCAL = 0,
- F75303_IDX_REMOTE1,
- F75303_IDX_REMOTE2,
- F75303_IDX_COUNT,
+/*
+ * I2C port and address information for all the board F75303 sensors should be
+ * defined in an array of the following structures, with an enum f75303_sensor
+ * indexing the array. The enum f75303_sensor shall end with a F75303_IDX_COUNT
+ * defining the maximum number of sensors for the board.
+ */
+
+struct f75303_sensor_t {
+ int i2c_port;
+ int i2c_addr_flags;
};
+extern const struct f75303_sensor_t f75303_sensors[];
+
/* F75303 register */
#define F75303_TEMP_LOCAL 0x00
#define F75303_TEMP_REMOTE1 0x01
@@ -37,4 +44,32 @@ enum f75303_index {
*/
int f75303_get_val(int idx, int *temp);
+/**
+ * Get the last polled value of a sensor.
+ *
+ * @param idx Index to read, from board's enum f75303_sensor
+ * definition
+ *
+ * @param temp_k_ptr Destination for temperature in K.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int f75303_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 f75303_sensor
+ * definition
+ *
+ * @param temp_mk_ptr Destination for temperature in mK.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int f75303_get_val_mk(int idx, int *temp_mk_ptr);
+
+#ifdef CONFIG_ZEPHYR
+void f75303_update_temperature(int idx);
+#endif /* CONFIG_ZEPHYR */
+
#endif /* __CROS_EC_F75303_H */