diff options
author | Devin Lu <devin.lu@quantatw.com> | 2020-06-08 13:11:45 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-15 00:11:21 +0000 |
commit | 3df08544d75c8854c8d0088e2afb4fe88f94b64b (patch) | |
tree | 33919550c9104bf61ee85c664dc0b14dd04f6587 | |
parent | e2a86fa31cda43b76ddfec4df6a1a9cf91f90e6c (diff) | |
download | chrome-ec-3df08544d75c8854c8d0088e2afb4fe88f94b64b.tar.gz |
berknip: add 5V regulator temperature sensor
Add a thermistor which near to 5V regulator.
BUG=b:157711232
BRANCH=none
TEST=Verified console "temps" can read temperature.
Signed-off-by: Devin Lu <Devin.Lu@quantatw.com>
Change-Id: I0020fc74b9b4b3f16dae7a1263e793ec2783b665
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2234047
Commit-Queue: Edward Hill <ecgh@chromium.org>
Tested-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
-rw-r--r-- | baseboard/zork/baseboard.c | 4 | ||||
-rw-r--r-- | baseboard/zork/baseboard.h | 2 | ||||
-rw-r--r-- | board/berknip/board.c | 48 | ||||
-rw-r--r-- | board/berknip/board.h | 2 | ||||
-rw-r--r-- | board/berknip/gpio.inc | 2 |
5 files changed, 55 insertions, 3 deletions
diff --git a/baseboard/zork/baseboard.c b/baseboard/zork/baseboard.c index a848341bb2..b2afc18793 100644 --- a/baseboard/zork/baseboard.c +++ b/baseboard/zork/baseboard.c @@ -170,13 +170,13 @@ const struct thermistor_info thermistor_info = { .data = thermistor_data, }; -int board_get_temp(int idx, int *temp_k) +__overridable int board_get_temp(int idx, int *temp_k) { int mv; int temp_c; enum adc_channel channel; - /* idx is the sensor index set below in temp_sensors[] */ + /* idx is the sensor index set in board temp_sensors[] */ switch (idx) { case TEMP_SENSOR_CHARGER: channel = ADC_TEMP_SENSOR_CHARGER; diff --git a/baseboard/zork/baseboard.h b/baseboard/zork/baseboard.h index 04fd6d34c6..edeb359d52 100644 --- a/baseboard/zork/baseboard.h +++ b/baseboard/zork/baseboard.h @@ -323,6 +323,8 @@ enum sensor_id { */ extern mat33_fp_t zork_base_standard_ref; +extern const struct thermistor_info thermistor_info; + /* Sensors without hardware FIFO are in forced mode */ #define CONFIG_ACCEL_FORCE_MODE_MASK (1 << LID_ACCEL) diff --git a/board/berknip/board.c b/board/berknip/board.c index 634168dc89..74b1654f9c 100644 --- a/board/berknip/board.c +++ b/board/berknip/board.c @@ -30,6 +30,7 @@ #include "system.h" #include "task.h" #include "temp_sensor.h" +#include "thermistor.h" #include "usb_charge.h" #include "usb_mux.h" @@ -317,7 +318,48 @@ const struct fan_t fans[] = { }; BUILD_ASSERT(ARRAY_SIZE(fans) == FAN_CH_COUNT); +__override int board_get_temp(int idx, int *temp_k) +{ + int mv; + int temp_c; + enum adc_channel channel; + + /* idx is the sensor index set in board temp_sensors[] */ + switch (idx) { + case TEMP_SENSOR_CHARGER: + channel = ADC_TEMP_SENSOR_CHARGER; + break; + case TEMP_SENSOR_SOC: + /* thermistor is not powered in G3 */ + if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) + return EC_ERROR_NOT_POWERED; + + channel = ADC_TEMP_SENSOR_SOC; + break; + case TEMP_SENSOR_5V_REGULATOR: + channel = ADC_TEMP_SENSOR_5V_REGULATOR; + break; + default: + return EC_ERROR_INVAL; + } + + mv = adc_read_channel(channel); + if (mv < 0) + return EC_ERROR_INVAL; + + temp_c = thermistor_linear_interpolate(mv, &thermistor_info); + *temp_k = C_TO_K(temp_c); + return EC_SUCCESS; +} + const struct adc_t adc_channels[] = { + [ADC_TEMP_SENSOR_5V_REGULATOR] = { + .name = "5V_REGULATOR", + .input_ch = NPCX_ADC_CH0, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, [ADC_TEMP_SENSOR_CHARGER] = { .name = "CHARGER", .input_ch = NPCX_ADC_CH2, @@ -354,6 +396,12 @@ const struct temp_sensor_t temp_sensors[] = { .read = sb_tsi_get_val, .idx = 0, }, + [TEMP_SENSOR_5V_REGULATOR] = { + .name = "5V_REGULATOR", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_temp, + .idx = TEMP_SENSOR_5V_REGULATOR, + }, }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); diff --git a/board/berknip/board.h b/board/berknip/board.h index 83e5614ab6..9fa3da69f4 100644 --- a/board/berknip/board.h +++ b/board/berknip/board.h @@ -70,6 +70,7 @@ #ifndef __ASSEMBLER__ enum adc_channel { + ADC_TEMP_SENSOR_5V_REGULATOR, ADC_TEMP_SENSOR_CHARGER, ADC_TEMP_SENSOR_SOC, ADC_CH_COUNT @@ -97,6 +98,7 @@ enum temp_sensor_id { TEMP_SENSOR_CHARGER = 0, TEMP_SENSOR_SOC, TEMP_SENSOR_CPU, + TEMP_SENSOR_5V_REGULATOR, TEMP_SENSOR_COUNT }; diff --git a/board/berknip/gpio.inc b/board/berknip/gpio.inc index f9d7a502ae..3195c2336e 100644 --- a/board/berknip/gpio.inc +++ b/board/berknip/gpio.inc @@ -122,7 +122,7 @@ ALTERNATE(PIN_MASK(3, BIT(3) | BIT(6)), 0, MODULE_I2C, 0) /* I2C5 */ ALTERNATE(PIN_MASK(E, BIT(3) | BIT(4)), 0, MODULE_I2C, 0) /* I2C6 */ ALTERNATE(PIN_MASK(B, BIT(2) | BIT(3)), 0, MODULE_I2C, 0) /* I2C7 */ -ALTERNATE(PIN_MASK(4, BIT(2) | BIT(3)), 0, MODULE_ADC, 0) /* ADC2, ADC3 Temp Sensors */ +ALTERNATE(PIN_MASK(4, BIT(0) | BIT(2) | BIT(3)), 0, MODULE_ADC, 0) /* ADC0, ADC2, ADC3 Temp Sensors */ ALTERNATE(PIN_MASK(C, BIT(3)), 0, MODULE_PWM, 0) /* PWM0 LED */ ALTERNATE(PIN_MASK(C, BIT(4)), 0, MODULE_PWM, 0) /* PWM2 - EC_FAN_PWM */ |