summaryrefslogtreecommitdiff
path: root/driver/temp_sensor/thermistor.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/temp_sensor/thermistor.c')
-rw-r--r--driver/temp_sensor/thermistor.c84
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 */