summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorLogan_Liao <Logan_Liao@compal.corp-partner.google.com>2023-02-24 11:19:23 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-15 02:55:30 +0000
commit141fa4916511ee3162c8067041f4ee21b00f194e (patch)
treeb4de84b2689ac24f82e5075ad99b1ab5fd4fdb84 /driver
parentb68720a8a6492445555253308fbcae7ab53ecea1 (diff)
downloadchrome-ec-141fa4916511ee3162c8067041f4ee21b00f194e.tar.gz
Zephyr: Correct Temp sensor F75303 read methond.
This patch correct F75303 read fail on zephyr. BUG=b:269786658 BRANCH=none TEST=test markarth console that temps show right value. Change-Id: I315d80e2166d0b5f4d69f4e671846abe52fccbba Signed-off-by: Logan_Liao <Logan_Liao@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4290094 Reviewed-by: Logan Liao <logan_liao@compal.corp-partner.google.com> Tested-by: Logan Liao <logan_liao@compal.corp-partner.google.com> Reviewed-by: Chao Gui <chaogui@google.com> Commit-Queue: Logan Liao <logan_liao@compal.corp-partner.google.com>
Diffstat (limited to 'driver')
-rw-r--r--driver/temp_sensor/f75303.c51
-rw-r--r--driver/temp_sensor/f75303.h75
2 files changed, 44 insertions, 82 deletions
diff --git a/driver/temp_sensor/f75303.c b/driver/temp_sensor/f75303.c
index dbeaf4470c..cfbfbc3b5a 100644
--- a/driver/temp_sensor/f75303.c
+++ b/driver/temp_sensor/f75303.c
@@ -7,10 +7,10 @@
#include "common.h"
#include "console.h"
-#include "f75303.h"
#include "hooks.h"
#include "i2c.h"
#include "math_util.h"
+#include "temp_sensor/f75303.h"
#include "util.h"
#ifdef CONFIG_ZEPHYR
@@ -24,6 +24,7 @@
static int temps[F75303_IDX_COUNT];
static int8_t fake_temp[F75303_IDX_COUNT];
+#ifndef CONFIG_ZEPHYR
/**
* Read 8 bits register from temp sensor.
*/
@@ -31,7 +32,18 @@ static int raw_read8(const int offset, int *data)
{
return i2c_read8(I2C_PORT_THERMAL, F75303_I2C_ADDR_FLAGS, offset, data);
}
+#else
+/**
+ * Read 8 bits register from temp sensor.
+ */
+static int raw_read8(int sensor, const int offset, int *data)
+{
+ return i2c_read8(f75303_sensors[sensor].i2c_port,
+ f75303_sensors[sensor].i2c_addr_flags, offset, data);
+}
+#endif /* !CONFIG_ZEPHYR */
+#ifndef CONFIG_ZEPHYR
static int get_temp(const int offset, int *temp)
{
int rv;
@@ -44,6 +56,20 @@ static int get_temp(const int offset, int *temp)
*temp = C_TO_K(temp_raw);
return EC_SUCCESS;
}
+#else
+static int get_temp(int sensor, const int offset, int *temp)
+{
+ int rv;
+ int temp_raw = 0;
+
+ rv = raw_read8(sensor, offset, &temp_raw);
+ if (rv != 0)
+ return rv;
+
+ *temp = CELSIUS_TO_MILLI_KELVIN(temp_raw);
+ return EC_SUCCESS;
+}
+#endif /* !CONFIG_ZEPHYR */
int f75303_get_val(int idx, int *temp)
{
@@ -89,21 +115,32 @@ int f75303_get_val_mk(int idx, int *temp_mk_ptr)
#ifndef CONFIG_ZEPHYR
static void f75303_sensor_poll(void)
{
- get_temp(F75303_TEMP_LOCAL, &temps[F75303_IDX_LOCAL]);
- get_temp(F75303_TEMP_REMOTE1, &temps[F75303_IDX_REMOTE1]);
- get_temp(F75303_TEMP_REMOTE2, &temps[F75303_IDX_REMOTE2]);
+ get_temp(F75303_TEMP_LOCAL_REGISTER, &temps[F75303_IDX_LOCAL]);
+ get_temp(F75303_TEMP_REMOTE1_REGISTER, &temps[F75303_IDX_REMOTE1]);
+ get_temp(F75303_TEMP_REMOTE2_REGISTER, &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;
+ int rv;
if (idx >= F75303_IDX_COUNT)
return;
-
- if (get_temp(idx, &temp_reg) == EC_SUCCESS)
- temps[idx] = f75303_reg_to_mk(temp_reg);
+ switch (idx) {
+ case F75303_IDX_LOCAL:
+ rv = get_temp(idx, F75303_TEMP_LOCAL_REGISTER, &temp_reg);
+ break;
+ case F75303_IDX_REMOTE1:
+ rv = get_temp(idx, F75303_TEMP_REMOTE1_REGISTER, &temp_reg);
+ break;
+ case F75303_IDX_REMOTE2:
+ rv = get_temp(idx, F75303_TEMP_REMOTE2_REGISTER, &temp_reg);
+ break;
+ }
+ if (rv == EC_SUCCESS)
+ temps[idx] = temp_reg;
}
#endif /* CONFIG_ZEPHYR */
diff --git a/driver/temp_sensor/f75303.h b/driver/temp_sensor/f75303.h
deleted file mode 100644
index 4632978145..0000000000
--- a/driver/temp_sensor/f75303.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* Copyright 2018 The ChromiumOS Authors
- * 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
-
-#ifdef BOARD_MUSHU
-#define F75303_I2C_ADDR_FLAGS 0x4D
-#else
-#define F75303_I2C_ADDR_FLAGS 0x4C
-#endif
-
-/*
- * 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
-#define F75303_TEMP_REMOTE2 0x23
-
-/**
- * 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 Destination for temperature in K.
- *
- * @return EC_SUCCESS if successful, non-zero if error.
- */
-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 */