diff options
author | matt_wang <matt_wang@compal.corp-partner.google.com> | 2023-01-06 16:25:13 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-30 19:20:08 +0000 |
commit | b9c7a21328b3ec7001b4072c46b33af27453525e (patch) | |
tree | c0a48b5b55df0cc1aebc38f038cd2e5a4aaa1a2a /driver/temp_sensor/f75303.c | |
parent | 8b6f7de2a730fd8d2be3b2a576b22301a11ba3bd (diff) | |
download | chrome-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/temp_sensor/f75303.c')
-rw-r--r-- | driver/temp_sensor/f75303.c | 60 |
1 files changed, 59 insertions, 1 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); |