diff options
author | Divya Sasidharan <divya.s.sasidharan@intel.com> | 2018-04-18 15:28:42 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-04-24 13:31:32 -0700 |
commit | dc875f284fd9c152d337949cf486d8c072c8a9e6 (patch) | |
tree | d1001eca30ba6f6935dc51fa0d22a37aed2a8348 /board | |
parent | 6782985535a50ee829e4993aa3fd0a1fb98d9b25 (diff) | |
download | chrome-ec-dc875f284fd9c152d337949cf486d8c072c8a9e6.tar.gz |
yorp: Enable temperature sensors
BUG=b:77944804
BRANCH=None
TEST=On yorp; test adc values, verify they are valid.
Change-Id: I64191f33c594d8869391bab813902f59a63d2ea1
Signed-off-by: Divya Sasidharan <divya.s.sasidharan@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/1018118
Commit-Ready: Divya Sasidharan <divya.s.sasidharan@intel.corp-partner.google.com>
Tested-by: Divya Sasidharan <divya.s.sasidharan@intel.corp-partner.google.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'board')
-rw-r--r-- | board/yorp/board.c | 92 | ||||
-rw-r--r-- | board/yorp/board.h | 15 | ||||
-rw-r--r-- | board/yorp/gpio.inc | 1 |
3 files changed, 105 insertions, 3 deletions
diff --git a/board/yorp/board.c b/board/yorp/board.c index 2b9fe53136..df34cad66b 100644 --- a/board/yorp/board.c +++ b/board/yorp/board.c @@ -31,6 +31,8 @@ #include "power_button.h" #include "switch.h" #include "system.h" +#include "temp_sensor.h" +#include "thermistor.h" #include "tcpci.h" #include "usb_mux.h" #include "usbc_ppc.h" @@ -83,6 +85,10 @@ const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); /* ADC channels */ const struct adc_t adc_channels[] = { + [ADC_TEMP_SENSOR_AMB] = { + "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0}, + [ADC_TEMP_SENSOR_CHARGER] = { + "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0}, /* Vbus C0 sensing (10x voltage divider). PPVAR_USB_C0_VBUS */ [ADC_VBUS_C0] = { "VBUS_C0", NPCX_ADC_CH4, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0}, @@ -129,6 +135,92 @@ const int usb_port_enable[USB_PORT_COUNT] = { /* TODO(b/74388692): Add second port control after hardware fix. */ }; +/* + * 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[] = { + {"Ambient", TEMP_SENSOR_TYPE_BOARD, board_get_ambient_temp, 0, 5}, + {"Charger", TEMP_SENSOR_TYPE_BOARD, board_get_charger_temp, 1, 1}, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + /* Called by APL power state machine when transitioning from G3 to S5 */ void chipset_pre_init_callback(void) { diff --git a/board/yorp/board.h b/board/yorp/board.h index 2fc76e3525..b2265f8c71 100644 --- a/board/yorp/board.h +++ b/board/yorp/board.h @@ -147,6 +147,8 @@ #define CONFIG_POWER_BUTTON #define CONFIG_POWER_BUTTON_X86 #define CONFIG_POWER_PP5000_CONTROL +#define CONFIG_TEMP_SENSOR +#define CONFIG_THERMISTOR_NCP15WB #define CONFIG_EXTPOWER_GPIO #undef CONFIG_EXTPOWER_DEBOUNCE_MS /* @@ -162,8 +164,10 @@ #include "registers.h" enum adc_channel { - ADC_VBUS_C0, - ADC_VBUS_C1, + ADC_TEMP_SENSOR_AMB, /* ADC0 */ + ADC_TEMP_SENSOR_CHARGER, /* ADC1 */ + ADC_VBUS_C0, /* ADC4 */ + ADC_VBUS_C1, /* ADC9 */ ADC_CH_COUNT }; @@ -184,8 +188,13 @@ enum power_signal { POWER_SIGNAL_COUNT }; -/* Motion sensors */ +enum temp_sensor_id { + TEMP_SENSOR_AMBIENT = 0, + TEMP_SENSOR_CHARGER, + TEMP_SENSOR_COUNT +}; +/* Motion sensors */ enum sensor_id { LID_ACCEL, BASE_ACCEL, diff --git a/board/yorp/gpio.inc b/board/yorp/gpio.inc index 7834a60638..e77dc29cc3 100644 --- a/board/yorp/gpio.inc +++ b/board/yorp/gpio.inc @@ -123,6 +123,7 @@ ALTERNATE(PIN_MASK(8, 0x80), 0, MODULE_I2C, 0) /* I2C1 SDA */ ALTERNATE(PIN_MASK(D, 0x03), 0, MODULE_I2C, 0) /* I2C3 */ ALTERNATE(PIN_MASK(F, 0x0C), 0, MODULE_I2C, 0) /* I2C4 */ ALTERNATE(PIN_MASK(B, 0x0C), 0, MODULE_I2C, 0) /* I2C7 */ +ALTERNATE(PIN_MASK(4, 0x30), 0, MODULE_ADC, 0) /* ADC0-1 */ ALTERNATE(PIN_MASK(4, 0x02), 0, MODULE_ADC, 0) /* ADC4: ADC_USB_C0_VBUS */ ALTERNATE(PIN_MASK(F, 0x01), 0, MODULE_ADC, 0) /* ADC9: ADC_USB_C1_VBUS */ ALTERNATE(PIN_MASK(C, 0x18), 0, MODULE_PWM, 0) /* LED 1 & 2 */ |