diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2019-03-07 20:43:52 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-09 01:18:58 -0800 |
commit | cec7957e56226c09a676b9d5373625715031b034 (patch) | |
tree | c8e7714c86bce0839242396e0b643b0aafe2828a /driver | |
parent | 4524f0cd70fb5a96d2618a2f4a2bb43ecc6f36e7 (diff) | |
download | chrome-ec-cec7957e56226c09a676b9d5373625715031b034.tar.gz |
thermistor: Consolidate thermistor_get_temperature() functions
BUG=none
BRANCH=none
TEST=make buildall -j
Change-Id: I30064163b1af1090e75fbd4927ef25f77ddc043a
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1510516
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/temp_sensor/thermistor.c | 84 |
1 files changed, 32 insertions, 52 deletions
diff --git a/driver/temp_sensor/thermistor.c b/driver/temp_sensor/thermistor.c index 89bbc2a3d1..15295a00ea 100644 --- a/driver/temp_sensor/thermistor.c +++ b/driver/temp_sensor/thermistor.c @@ -63,6 +63,32 @@ int thermistor_linear_interpolate(uint16_t mv, return t_low + num_steps; } +#if defined(CONFIG_STEINHART_HART_3V3_51K1_47K_4050B) || \ + defined(CONFIG_STEINHART_HART_3V3_13K7_47K_4050B) || \ + defined(CONFIG_STEINHART_HART_6V0_51K1_47K_4050B) +static int thermistor_get_temperature(int idx_adc, int *temp_ptr, + const struct thermistor_info *info) +{ + 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 /* CONFIG_TEMP_SENSOR_POWER_GPIO */ + mv = adc_read_channel(idx_adc); + if (mv < 0) + return EC_ERROR_UNKNOWN; + + *temp_ptr = thermistor_linear_interpolate(mv, info); + *temp_ptr = C_TO_K(*temp_ptr); + return EC_SUCCESS; +} +#endif + #ifdef CONFIG_STEINHART_HART_3V3_51K1_47K_4050B /* * Data derived from Steinhart-Hart equation in a resistor divider circuit with @@ -94,23 +120,8 @@ static const struct thermistor_info thermistor_info_51_47 = { int get_temp_3v3_51k1_47k_4050b(int idx_adc, int *temp_ptr) { - 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_51_47); - *temp_ptr = C_TO_K(*temp_ptr); - return EC_SUCCESS; + return thermistor_get_temperature(idx_adc, temp_ptr, + &thermistor_info_51_47); } #endif /* CONFIG_STEINHART_HART_3V3_51K1_47K_4050B */ @@ -145,23 +156,8 @@ static const struct thermistor_info thermistor_info_13_47 = { int get_temp_3v3_13k7_47k_4050b(int idx_adc, int *temp_ptr) { - 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_13_47); - *temp_ptr = C_TO_K(*temp_ptr); - return EC_SUCCESS; + return thermistor_get_temperature(idx_adc, temp_ptr, + &thermistor_info_13_47); } #endif /* CONFIG_STEINHART_HART_3V3_13K7_47K_4050B */ @@ -196,23 +192,7 @@ 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; - -#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 = C_TO_K(*temp_ptr); - return EC_SUCCESS; + return thermistor_get_temperature(idx_adc, temp_ptr, + &thermistor_info_6v0_51_47); } #endif /* CONFIG_STEINHART_HART_6V0_51K1_47K_4050B */ |