summaryrefslogtreecommitdiff
path: root/driver/temp_sensor
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2018-07-23 09:10:34 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-07-23 17:25:56 -0700
commit2559377b62c67f65acb818feeb56a6022e1defd6 (patch)
tree7e23a0a51e62f3c0ff827be65cc516baf1215006 /driver/temp_sensor
parent03e1252e560a3029b497e32caee3275e5556ac32 (diff)
downloadchrome-ec-2559377b62c67f65acb818feeb56a6022e1defd6.tar.gz
f75303: Simplify f75303_get_val API
This patch simplifies the f75303_get_val API for better readability and preparation for the upcoming temperature control command. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=none BRANCH=none TEST=Verify temps command print expected values on Sona. Change-Id: I8c71a64c5a5f766f12cf2b3ab59ef6b7481d1b59 Reviewed-on: https://chromium-review.googlesource.com/1146903 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'driver/temp_sensor')
-rw-r--r--driver/temp_sensor/f75303.c38
-rw-r--r--driver/temp_sensor/f75303.h9
2 files changed, 17 insertions, 30 deletions
diff --git a/driver/temp_sensor/f75303.c b/driver/temp_sensor/f75303.c
index 81cf5eefdd..5c89ba8a4c 100644
--- a/driver/temp_sensor/f75303.c
+++ b/driver/temp_sensor/f75303.c
@@ -11,19 +11,17 @@
#include "hooks.h"
#include "util.h"
-static int temp_val_local;
-static int temp_val_remote1;
-static int temp_val_remote2;
+static int temps[F75303_IDX_COUNT];
/**
* Read 8 bits register from temp sensor.
*/
-static int raw_read8(const int offset, int *data_ptr)
+static int raw_read8(const int offset, int *data)
{
- return i2c_read8(I2C_PORT_THERMAL, F75303_I2C_ADDR, offset, data_ptr);
+ return i2c_read8(I2C_PORT_THERMAL, F75303_I2C_ADDR, offset, data);
}
-static int get_temp(const int offset, int *temp_ptr)
+static int get_temp(const int offset, int *temp)
{
int rv;
int temp_raw = 0;
@@ -32,34 +30,22 @@ static int get_temp(const int offset, int *temp_ptr)
if (rv != 0)
return rv;
- *temp_ptr = C_TO_K(temp_raw);
+ *temp = C_TO_K(temp_raw);
return EC_SUCCESS;
}
-int f75303_get_val(int idx, int *temp_ptr)
+int f75303_get_val(int idx, int *temp)
{
- switch (idx) {
- case F75303_IDX_LOCAL:
- *temp_ptr = temp_val_local;
- break;
- case F75303_IDX_REMOTE1:
- *temp_ptr = temp_val_remote1;
- break;
- case F75303_IDX_REMOTE2:
- *temp_ptr = temp_val_remote2;
- break;
- default:
- return EC_ERROR_UNKNOWN;
- }
-
+ if (idx < 0 || F75303_IDX_COUNT <= idx)
+ return EC_ERROR_INVAL;
+ *temp = temps[idx];
return EC_SUCCESS;
}
static void f75303_sensor_poll(void)
{
- get_temp(F75303_TEMP_LOCAL, &temp_val_local);
- get_temp(F75303_TEMP_REMOTE1, &temp_val_remote1);
- get_temp(F75303_TEMP_REMOTE2, &temp_val_remote2);
+ 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]);
}
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
index 6c8d41250c..ada32e75e7 100644
--- a/driver/temp_sensor/f75303.h
+++ b/driver/temp_sensor/f75303.h
@@ -14,6 +14,7 @@ enum f75303_index {
F75303_IDX_LOCAL = 0,
F75303_IDX_REMOTE1,
F75303_IDX_REMOTE2,
+ F75303_IDX_COUNT,
};
/* F75303 register */
@@ -24,12 +25,12 @@ enum f75303_index {
/**
* 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.
+ * @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_ptr);
+int f75303_get_val(int idx, int *temp);
#endif /* __CROS_EC_F75303_H */