summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2019-03-07 20:43:52 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-09 01:18:58 -0800
commitcec7957e56226c09a676b9d5373625715031b034 (patch)
treec8e7714c86bce0839242396e0b643b0aafe2828a
parent4524f0cd70fb5a96d2618a2f4a2bb43ecc6f36e7 (diff)
downloadchrome-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>
-rw-r--r--driver/temp_sensor/thermistor.c84
-rw-r--r--include/config.h1
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