diff options
author | Jett Rink <jettrink@chromium.org> | 2018-06-12 15:18:35 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-15 10:56:44 -0700 |
commit | 35ae76ab7060364a2e343b59d58ec86d8e06990b (patch) | |
tree | 58bbfc4f782a39b07cd7eb21eba2e3d4871399e5 /board/yorp/board.c | |
parent | 33581f7a5f4c657b94b254537671ffe0a6fe6bd2 (diff) | |
download | chrome-ec-35ae76ab7060364a2e343b59d58ec86d8e06990b.tar.gz |
thermistor: move thermistor tables into common code
The exact same 2 lookup tables are in multiple board files. We seem to
reuse the 2 thermistor circuit enough that we should single source them
in a common location.
BRANCH=none
BUG=none
TEST=yorp sensors still function properly
Change-Id: Ic393c609c78c8a51c55a67b639c1fb9e6c387d8a
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1100943
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Justin TerAvest <teravest@chromium.org>
Diffstat (limited to 'board/yorp/board.c')
-rw-r--r-- | board/yorp/board.c | 118 |
1 files changed, 16 insertions, 102 deletions
diff --git a/board/yorp/board.c b/board/yorp/board.c index db72cbe744..f51ebab20b 100644 --- a/board/yorp/board.c +++ b/board/yorp/board.c @@ -33,9 +33,9 @@ #include "switch.h" #include "system.h" #include "tablet_mode.h" +#include "tcpci.h" #include "temp_sensor.h" #include "thermistor.h" -#include "tcpci.h" #include "usb_mux.h" #include "usbc_ppc.h" #include "util.h" @@ -83,108 +83,22 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* - * Data derived from Seinhart-Hart equation in a resistor divider circuit with - * Vdd=3300mV, R = 13.7Kohm, and Murata NCP15WB-series thermistor (B = 4050, - * T0 = 298.15, nominal resistance (R0) = 47Kohm). - */ -#define CHARGER_THERMISTOR_SCALING_FACTOR 13 -static const struct thermistor_data_pair charger_thermistor_data[] = { - { 3044 / CHARGER_THERMISTOR_SCALING_FACTOR, 0 }, - { 2890 / CHARGER_THERMISTOR_SCALING_FACTOR, 10 }, - { 2680 / CHARGER_THERMISTOR_SCALING_FACTOR, 20 }, - { 2418 / CHARGER_THERMISTOR_SCALING_FACTOR, 30 }, - { 2117 / CHARGER_THERMISTOR_SCALING_FACTOR, 40 }, - { 1800 / CHARGER_THERMISTOR_SCALING_FACTOR, 50 }, - { 1490 / CHARGER_THERMISTOR_SCALING_FACTOR, 60 }, - { 1208 / CHARGER_THERMISTOR_SCALING_FACTOR, 70 }, - { 966 / CHARGER_THERMISTOR_SCALING_FACTOR, 80 }, - { 860 / CHARGER_THERMISTOR_SCALING_FACTOR, 85 }, - { 766 / CHARGER_THERMISTOR_SCALING_FACTOR, 90 }, - { 679 / CHARGER_THERMISTOR_SCALING_FACTOR, 95 }, - { 603 / CHARGER_THERMISTOR_SCALING_FACTOR, 100 }, -}; - -static const struct thermistor_info charger_thermistor_info = { - .scaling_factor = CHARGER_THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(charger_thermistor_data), - .data = charger_thermistor_data, -}; - -int board_get_charger_temp(int idx, int *temp_ptr) -{ - int mv = adc_read_channel(NPCX_ADC_CH1); - - if (mv < 0) - return EC_ERROR_UNKNOWN; - - *temp_ptr = thermistor_linear_interpolate(mv, &charger_thermistor_info); - *temp_ptr = C_TO_K(*temp_ptr); - return EC_SUCCESS; -} - -/* - * Data derived from Seinhart-Hart equation in a resistor divider circuit with - * Vdd=3300mV, R = 51.1Kohm, and Murata NCP15WB-series thermistor (B = 4050, - * T0 = 298.15, nominal resistance (R0) = 47Kohm). - */ -#define AMB_THERMISTOR_SCALING_FACTOR 11 -static const struct thermistor_data_pair amb_thermistor_data[] = { - { 2512 / AMB_THERMISTOR_SCALING_FACTOR, 0 }, - { 2158 / AMB_THERMISTOR_SCALING_FACTOR, 10 }, - { 1772 / AMB_THERMISTOR_SCALING_FACTOR, 20 }, - { 1398 / AMB_THERMISTOR_SCALING_FACTOR, 30 }, - { 1070 / AMB_THERMISTOR_SCALING_FACTOR, 40 }, - { 803 / AMB_THERMISTOR_SCALING_FACTOR, 50 }, - { 597 / AMB_THERMISTOR_SCALING_FACTOR, 60 }, - { 443 / AMB_THERMISTOR_SCALING_FACTOR, 70 }, - { 329 / AMB_THERMISTOR_SCALING_FACTOR, 80 }, - { 285 / AMB_THERMISTOR_SCALING_FACTOR, 85 }, - { 247 / AMB_THERMISTOR_SCALING_FACTOR, 90 }, - { 214 / AMB_THERMISTOR_SCALING_FACTOR, 95 }, - { 187 / AMB_THERMISTOR_SCALING_FACTOR, 100 }, -}; - -static const struct thermistor_info amb_thermistor_info = { - .scaling_factor = AMB_THERMISTOR_SCALING_FACTOR, - .num_pairs = ARRAY_SIZE(amb_thermistor_data), - .data = amb_thermistor_data, -}; - -int board_get_ambient_temp(int idx, int *temp_ptr) -{ - int mv = adc_read_channel(NPCX_ADC_CH0); - - if (mv < 0) - return EC_ERROR_UNKNOWN; - - *temp_ptr = thermistor_linear_interpolate(mv, &amb_thermistor_info); - *temp_ptr = C_TO_K(*temp_ptr); - return EC_SUCCESS; -} - const struct temp_sensor_t temp_sensors[] = { - { - .name = "Battery", - .type = TEMP_SENSOR_TYPE_BATTERY, - .read = charge_get_battery_temp, - .idx = 0, - .action_delay_sec = 1 - }, - { - .name = "Ambient", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = board_get_ambient_temp, - .idx = 0, - .action_delay_sec = 5 - }, - { - .name = "Charger", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = board_get_charger_temp, - .idx = 1, - .action_delay_sec = 1 - }, + [TEMP_SENSOR_BATTERY] = {.name = "Battery", + .type = TEMP_SENSOR_TYPE_BATTERY, + .read = charge_get_battery_temp, + .idx = 0, + .action_delay_sec = 1}, + [TEMP_SENSOR_AMBIENT] = {.name = "Ambient", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_51k1_47k_4050b, + .idx = ADC_TEMP_SENSOR_AMB, + .action_delay_sec = 5}, + [TEMP_SENSOR_CHARGER] = {.name = "Charger", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_13k7_47k_4050b, + .idx = ADC_TEMP_SENSOR_CHARGER, + .action_delay_sec = 1}, }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); |