From cec7957e56226c09a676b9d5373625715031b034 Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Thu, 7 Mar 2019 20:43:52 -0800 Subject: thermistor: Consolidate thermistor_get_temperature() functions BUG=none BRANCH=none TEST=make buildall -j Change-Id: I30064163b1af1090e75fbd4927ef25f77ddc043a Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/1510516 Commit-Ready: Vijay P Hiremath Tested-by: Vijay P Hiremath Reviewed-by: Daisuke Nojiri Reviewed-by: Jett Rink --- driver/temp_sensor/thermistor.c | 84 ++++++++++++++++------------------------- include/config.h | 1 + 2 files changed, 33 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 */ diff --git a/include/config.h b/include/config.h index 0f87f97784..b1b779f276 100644 --- a/include/config.h +++ b/include/config.h @@ -3060,6 +3060,7 @@ */ #undef CONFIG_STEINHART_HART_3V3_13K7_47K_4050B #undef CONFIG_STEINHART_HART_3V3_51K1_47K_4050B +#undef CONFIG_STEINHART_HART_6V0_51K1_47K_4050B /* * If defined, active-high GPIO which indicates temperature sensor chips are -- cgit v1.2.1