diff options
author | Tino Liu <tino.liu@quanta.corp-partner.google.com> | 2018-07-18 17:25:19 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-07-26 04:07:32 -0700 |
commit | 48113728b689870e6aeda6534d36eeffd3b738b3 (patch) | |
tree | 143a7a236eeffdf2206f46bed7b14ff4bc620304 | |
parent | 3793a83cbd7349b07453cc5a44674f9e7bc856f3 (diff) | |
download | chrome-ec-48113728b689870e6aeda6534d36eeffd3b738b3.tar.gz |
F75303: Set fake temperature
Add new console command `f75303` to set fake temperature for F75303.
Usage:
f75303 <index> <value>|off
<index>
0: F75303_Local
1: F75303_Remote1
2: F75303_Remote2
<value>
integer from 0 to 100 (Celsius degree)
"off"
turn off fake temperature mode, back to normal
BUG=none
BRANCH=master
TEST=fan target speed can follow fake temperature, make buildall pass
Change-Id: I341434207af71cf6aa63350887eac3499508d2ff
Signed-off-by: Tino Liu <tino.liu@quanta.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/1141746
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | driver/temp_sensor/f75303.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/driver/temp_sensor/f75303.c b/driver/temp_sensor/f75303.c index 5c89ba8a4c..e2a324f0fb 100644 --- a/driver/temp_sensor/f75303.c +++ b/driver/temp_sensor/f75303.c @@ -10,8 +10,10 @@ #include "i2c.h" #include "hooks.h" #include "util.h" +#include "console.h" static int temps[F75303_IDX_COUNT]; +static int8_t fake_temp[F75303_IDX_COUNT] = {-1, -1, -1}; /** * Read 8 bits register from temp sensor. @@ -38,6 +40,12 @@ int f75303_get_val(int idx, int *temp) { if (idx < 0 || F75303_IDX_COUNT <= idx) return EC_ERROR_INVAL; + + if (fake_temp[idx] != -1) { + *temp = C_TO_K(fake_temp[idx]); + return EC_SUCCESS; + } + *temp = temps[idx]; return EC_SUCCESS; } @@ -49,3 +57,36 @@ 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); + +static int f75303_set_fake_temp(int argc, char **argv) +{ + int index; + int value; + char *e; + + if (argc != 3) + return EC_ERROR_PARAM_COUNT; + + index = strtoi(argv[1], &e, 0); + if ((*e) || (index < 0) || (index >= F75303_IDX_COUNT)) + return EC_ERROR_PARAM1; + + if (!strcasecmp(argv[2], "off")) { + fake_temp[index] = -1; + ccprintf("Turn off fake temp mode for sensor %u.\n", index); + return EC_SUCCESS; + } + + value = strtoi(argv[2], &e, 0); + + if ((*e) || (value < 0) || (value > 100)) + return EC_ERROR_PARAM2; + + fake_temp[index] = value; + ccprintf("Force sensor %u = %uC.\n", index, value); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(f75303, f75303_set_fake_temp, + "<index> <value>|off", + "Set fake temperature of sensor f75303."); |