diff options
author | Scott Collyer <scollyer@google.com> | 2019-01-31 15:14:52 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-12 14:00:13 -0800 |
commit | af64914692f5469782882157b633368b25b2e3a8 (patch) | |
tree | 1cd77dc01f68c66ffea10bfd6b8ee8859677684b /driver/temp_sensor/thermistor.c | |
parent | 8de6b302a3d97018a10795488ba83adf69011940 (diff) | |
download | chrome-ec-af64914692f5469782882157b633368b25b2e3a8.tar.gz |
temp_sensor: Guard thermistor readings by their power rail enable gpio
If a temperature reading is taken using a thermistor circuit when the
power rail for that circuit is not powered, then the resultiing
reading will convert to a very high temperature which will then lead
to a false thermal shutdown event.
This CL utilizes an existing config option
CONFIG_TEMP_SENSOR_POWER_GPIO to allow for the thermistor driver
functions to know which gpio to check to see if a power rail is
enabled or not. If the rail is not enabled, the function returns
EC_ERROR_UNKNOWN so the reading will be ignored by the calling
function. Since this change to the thermistor driver is dependent on
the config option, it does not affect in existing boards, but can be
used for boards that have this requirement.
BRANCH=none
BUG=b:123900860
TEST=Verified that the the EC console message 'thermal SHUTDOWN' no
longer appears following an EC reboot as the ADC readings are now
ignored if the GPIO controlling the power rail is not enabled.
Change-Id: I92b010ab7e801f4897edb3a6d0325d9d7fc74f21
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1448816
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver/temp_sensor/thermistor.c')
-rw-r--r-- | driver/temp_sensor/thermistor.c | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/driver/temp_sensor/thermistor.c b/driver/temp_sensor/thermistor.c index 82a18ff500..89bbc2a3d1 100644 --- a/driver/temp_sensor/thermistor.c +++ b/driver/temp_sensor/thermistor.c @@ -7,6 +7,7 @@ #include "adc.h" #include "common.h" +#include "gpio.h" #include "thermistor.h" #include "util.h" @@ -93,8 +94,17 @@ static const struct thermistor_info thermistor_info_51_47 = { int get_temp_3v3_51k1_47k_4050b(int idx_adc, int *temp_ptr) { - int mv = adc_read_channel(idx_adc); + int mv; +#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO + /* + * If the power rail for the thermistor circuit is not enabled, then + * need to ignore any ADC measurments. + */ + if (!gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO)) + return EC_ERROR_NOT_POWERED; +#endif + mv = adc_read_channel(idx_adc); if (mv < 0) return EC_ERROR_UNKNOWN; @@ -135,8 +145,17 @@ static const struct thermistor_info thermistor_info_13_47 = { int get_temp_3v3_13k7_47k_4050b(int idx_adc, int *temp_ptr) { - int mv = adc_read_channel(idx_adc); + int mv; +#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO + /* + * If the power rail for the thermistor circuit is not enabled, then + * need to ignore any ADC measurments. + */ + if (!gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO)) + return EC_ERROR_NOT_POWERED; +#endif + mv = adc_read_channel(idx_adc); if (mv < 0) return EC_ERROR_UNKNOWN; @@ -177,15 +196,23 @@ static const struct thermistor_info thermistor_info_6v0_51_47 = { int get_temp_6v0_51k1_47k_4050b(int idx_adc, int *temp_ptr) { - int mv = adc_read_channel(idx_adc); + int mv; +#ifdef CONFIG_TEMP_SENSOR_POWER_GPIO + /* + * If the power rail for the thermistor circuit is not enabled, then + * need to ignore any ADC measurments. + */ + if (!gpio_get_level(CONFIG_TEMP_SENSOR_POWER_GPIO)) + return EC_ERROR_NOT_POWERED; +#endif + mv = adc_read_channel(idx_adc); if (mv < 0) return EC_ERROR_UNKNOWN; - *temp_ptr = thermistor_linear_interpolate(mv, &thermistor_info_6v0_51_47); + *temp_ptr = thermistor_linear_interpolate(mv, + &thermistor_info_6v0_51_47); *temp_ptr = C_TO_K(*temp_ptr); return EC_SUCCESS; } #endif /* CONFIG_STEINHART_HART_6V0_51K1_47K_4050B */ - - |