From b90e9587c85ee8f7c504e3e23cd8f2273059b2a5 Mon Sep 17 00:00:00 2001 From: Zick Wei Date: Tue, 31 Aug 2021 16:37:33 +0800 Subject: guybrush: move thermal sensor/setting to variant This patch move thermal sensor and setting to variant, let variant have their own setting. BUG=none BRANCH=none TEST=make BOARD=dewatt, make BOARD=guybrush, make BOARD=nipperkin Signed-off-by: Zick Wei Change-Id: Ibf37a0a45d1a728abc5ed88dde230f0561698bbc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3132547 Reviewed-by: Devin Lu Reviewed-by: Rob Barnes Commit-Queue: Rob Barnes --- baseboard/guybrush/baseboard.c | 151 ---------------------------------------- baseboard/guybrush/baseboard.h | 20 ------ board/dewatt/board.c | 152 +++++++++++++++++++++++++++++++++++++++++ board/dewatt/board.h | 20 ++++++ board/guybrush/board.c | 152 +++++++++++++++++++++++++++++++++++++++++ board/guybrush/board.h | 20 ++++++ board/nipperkin/board.c | 152 +++++++++++++++++++++++++++++++++++++++++ board/nipperkin/board.h | 20 ++++++ 8 files changed, 516 insertions(+), 171 deletions(-) diff --git a/baseboard/guybrush/baseboard.c b/baseboard/guybrush/baseboard.c index df6cab8538..344ea459de 100644 --- a/baseboard/guybrush/baseboard.c +++ b/baseboard/guybrush/baseboard.c @@ -5,7 +5,6 @@ /* Guybrush family-specific configuration */ -#include "adc.h" #include "cros_board_info.h" #include "base_fw_config.h" #include "battery_fuel_gauge.h" @@ -23,8 +22,6 @@ #include "driver/retimer/ps8811.h" #include "driver/retimer/ps8818.h" #include "driver/tcpm/nct38xx.h" -#include "driver/temp_sensor/sb_tsi.h" -#include "driver/temp_sensor/tmp112.h" #include "driver/usb_mux/anx7451.h" #include "driver/usb_mux/amd_fp6.h" #include "fan.h" @@ -39,9 +36,6 @@ #include "pi3usb9201.h" #include "power.h" #include "pwm.h" -#include "temp_sensor.h" -#include "thermal.h" -#include "temp_sensor/thermistor.h" #include "usb_mux.h" #include "usb_pd_tcpm.h" #include "usbc_ppc.h" @@ -149,145 +143,7 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -/* ADC Channels */ -const struct adc_t adc_channels[] = { - [ADC_TEMP_SENSOR_SOC] = { - .name = "SOC", - .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_CH1, - .factor_mul = ADC_MAX_VOLT, - .factor_div = ADC_READ_MAX + 1, - .shift = 0, - }, - [ADC_TEMP_SENSOR_MEMORY] = { - .name = "MEMORY", - .input_ch = NPCX_ADC_CH2, - .factor_mul = ADC_MAX_VOLT, - .factor_div = ADC_READ_MAX + 1, - .shift = 0, - }, - [ADC_CORE_IMON1] = { - .name = "CORE_I", - .input_ch = NPCX_ADC_CH3, - .factor_mul = ADC_MAX_VOLT, - .factor_div = ADC_READ_MAX + 1, - .shift = 0, - }, - [ADC_SOC_IMON2] = { - .name = "SOC_I", - .input_ch = NPCX_ADC_CH4, - .factor_mul = ADC_MAX_VOLT, - .factor_div = ADC_READ_MAX + 1, - .shift = 0, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* Temp Sensors */ -static int board_get_memory_temp(int, int *); - -const struct tmp112_sensor_t tmp112_sensors[] = { - { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS0 }, - { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS1 }, -}; -BUILD_ASSERT(ARRAY_SIZE(tmp112_sensors) == TMP112_COUNT); - -const struct temp_sensor_t temp_sensors[] = { - [TEMP_SENSOR_SOC] = { - .name = "SOC", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = board_get_soc_temp_k, - .idx = TMP112_SOC, - }, - [TEMP_SENSOR_CHARGER] = { - .name = "Charger", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = get_temp_3v3_30k9_47k_4050b, - .idx = ADC_TEMP_SENSOR_CHARGER, - }, - [TEMP_SENSOR_MEMORY] = { - .name = "Memory", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = board_get_memory_temp, - .idx = ADC_TEMP_SENSOR_MEMORY, - }, - [TEMP_SENSOR_CPU] = { - .name = "CPU", - .type = TEMP_SENSOR_TYPE_CPU, - .read = sb_tsi_get_val, - .idx = 0, - }, - [TEMP_SENSOR_AMBIENT] = { - .name = "Ambient", - .type = TEMP_SENSOR_TYPE_BOARD, - .read = tmp112_get_val_k, - .idx = TMP112_AMB, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); - -struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT] = { - [TEMP_SENSOR_SOC] = { - .temp_host = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(100), - [EC_TEMP_THRESH_HALT] = C_TO_K(105), - }, - .temp_host_release = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(80), - }, - /* TODO: Setting fan off to 0 so it's allways on */ - .temp_fan_off = C_TO_K(0), - .temp_fan_max = C_TO_K(70), - }, - [TEMP_SENSOR_CHARGER] = { - .temp_host = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(100), - [EC_TEMP_THRESH_HALT] = C_TO_K(105), - }, - .temp_host_release = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(80), - }, - .temp_fan_off = 0, - .temp_fan_max = 0, - }, - [TEMP_SENSOR_MEMORY] = { - .temp_host = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(100), - [EC_TEMP_THRESH_HALT] = C_TO_K(105), - }, - .temp_host_release = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(80), - }, - .temp_fan_off = 0, - .temp_fan_max = 0, - }, - [TEMP_SENSOR_CPU] = { - .temp_host = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(100), - [EC_TEMP_THRESH_HALT] = C_TO_K(105), - }, - .temp_host_release = { - [EC_TEMP_THRESH_HIGH] = C_TO_K(80), - }, - /* - * CPU temp sensor fan thresholds are high because they are a - * backup for the SOC temp sensor fan thresholds. - */ - .temp_fan_off = C_TO_K(60), - .temp_fan_max = C_TO_K(90), - }, - /* - * Note: Leave ambient entries at 0, both as it does not represent a - * hotspot and as not all boards have this sensor - */ -}; -BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); const struct charger_config_t chg_chips[] = { { @@ -813,13 +669,6 @@ void bc12_interrupt(enum gpio_signal signal) } } -static int board_get_memory_temp(int idx, int *temp_k) -{ - if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) - return EC_ERROR_NOT_POWERED; - return get_temp_3v3_30k9_47k_4050b(idx, temp_k); -} - /** * Return if VBUS is sagging too low */ diff --git a/baseboard/guybrush/baseboard.h b/baseboard/guybrush/baseboard.h index dd8ad3cc43..25268d5ade 100644 --- a/baseboard/guybrush/baseboard.h +++ b/baseboard/guybrush/baseboard.h @@ -314,16 +314,6 @@ enum usba_port { USBA_PORT_COUNT }; -/* ADC Channels */ -enum adc_channel { - ADC_TEMP_SENSOR_SOC = 0, - ADC_TEMP_SENSOR_CHARGER, - ADC_TEMP_SENSOR_MEMORY, - ADC_CORE_IMON1, - ADC_SOC_IMON2, - ADC_CH_COUNT -}; - /* TMP112 sensors */ enum tmp112_sensor { TMP112_SOC, @@ -331,16 +321,6 @@ enum tmp112_sensor { TMP112_COUNT, }; -/* Temp Sensors */ -enum temp_sensor_id { - TEMP_SENSOR_SOC = 0, - TEMP_SENSOR_CHARGER, - TEMP_SENSOR_MEMORY, - TEMP_SENSOR_CPU, - TEMP_SENSOR_AMBIENT, - TEMP_SENSOR_COUNT -}; - enum sensor_id { LID_ACCEL, BASE_ACCEL, diff --git a/board/dewatt/board.c b/board/dewatt/board.c index d0762fa595..72e803d100 100644 --- a/board/dewatt/board.c +++ b/board/dewatt/board.c @@ -5,6 +5,7 @@ /* Guybrush board-specific configuration */ +#include "adc.h" #include "base_fw_config.h" #include "board_fw_config.h" #include "button.h" @@ -16,6 +17,8 @@ #include "driver/accel_bma422.h" #include "driver/retimer/ps8811.h" #include "driver/retimer/ps8818.h" +#include "driver/temp_sensor/sb_tsi.h" +#include "driver/temp_sensor/tmp112.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -25,8 +28,10 @@ #include "power_button.h" #include "switch.h" #include "tablet_mode.h" +#include "temp_sensor.h" #include "temp_sensor/thermistor.h" #include "temp_sensor/tmp112.h" +#include "thermal.h" #include "usb_mux.h" #include "gpio_list.h" /* Must come after other header files. */ @@ -383,3 +388,150 @@ int board_get_ambient_temp_mk(int *temp_mk) return tmp112_get_val_mk(TMP112_AMB, temp_mk); } + +/* ADC Channels */ +const struct adc_t adc_channels[] = { + [ADC_TEMP_SENSOR_SOC] = { + .name = "SOC", + .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_CH1, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_TEMP_SENSOR_MEMORY] = { + .name = "MEMORY", + .input_ch = NPCX_ADC_CH2, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_CORE_IMON1] = { + .name = "CORE_I", + .input_ch = NPCX_ADC_CH3, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_SOC_IMON2] = { + .name = "SOC_I", + .input_ch = NPCX_ADC_CH4, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); + +/* Temp Sensors */ +static int board_get_memory_temp(int, int *); + +const struct tmp112_sensor_t tmp112_sensors[] = { + { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS0 }, + { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS1 }, +}; +BUILD_ASSERT(ARRAY_SIZE(tmp112_sensors) == TMP112_COUNT); + +const struct temp_sensor_t temp_sensors[] = { + [TEMP_SENSOR_SOC] = { + .name = "SOC", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_soc_temp_k, + .idx = TMP112_SOC, + }, + [TEMP_SENSOR_CHARGER] = { + .name = "Charger", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_30k9_47k_4050b, + .idx = ADC_TEMP_SENSOR_CHARGER, + }, + [TEMP_SENSOR_MEMORY] = { + .name = "Memory", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_memory_temp, + .idx = ADC_TEMP_SENSOR_MEMORY, + }, + [TEMP_SENSOR_CPU] = { + .name = "CPU", + .type = TEMP_SENSOR_TYPE_CPU, + .read = sb_tsi_get_val, + .idx = 0, + }, + [TEMP_SENSOR_AMBIENT] = { + .name = "Ambient", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = tmp112_get_val_k, + .idx = TMP112_AMB, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + +struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT] = { + [TEMP_SENSOR_SOC] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + /* TODO: Setting fan off to 0 so it's allways on */ + .temp_fan_off = C_TO_K(0), + .temp_fan_max = C_TO_K(70), + }, + [TEMP_SENSOR_CHARGER] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + .temp_fan_off = 0, + .temp_fan_max = 0, + }, + [TEMP_SENSOR_MEMORY] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + .temp_fan_off = 0, + .temp_fan_max = 0, + }, + [TEMP_SENSOR_CPU] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + /* + * CPU temp sensor fan thresholds are high because they are a + * backup for the SOC temp sensor fan thresholds. + */ + .temp_fan_off = C_TO_K(60), + .temp_fan_max = C_TO_K(90), + }, + /* + * Note: Leave ambient entries at 0, both as it does not represent a + * hotspot and as not all boards have this sensor + */ +}; +BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); + +static int board_get_memory_temp(int idx, int *temp_k) +{ + if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) + return EC_ERROR_NOT_POWERED; + return get_temp_3v3_30k9_47k_4050b(idx, temp_k); +} diff --git a/board/dewatt/board.h b/board/dewatt/board.h index dc09530e8e..f5c47718d5 100644 --- a/board/dewatt/board.h +++ b/board/dewatt/board.h @@ -71,6 +71,26 @@ enum base_accelgyro_type { BASE_GYRO_BMI323 = 2, }; +/* ADC Channels */ +enum adc_channel { + ADC_TEMP_SENSOR_SOC = 0, + ADC_TEMP_SENSOR_CHARGER, + ADC_TEMP_SENSOR_MEMORY, + ADC_CORE_IMON1, + ADC_SOC_IMON2, + ADC_CH_COUNT +}; + +/* Temp Sensors */ +enum temp_sensor_id { + TEMP_SENSOR_SOC = 0, + TEMP_SENSOR_CHARGER, + TEMP_SENSOR_MEMORY, + TEMP_SENSOR_CPU, + TEMP_SENSOR_AMBIENT, + TEMP_SENSOR_COUNT +}; + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/guybrush/board.c b/board/guybrush/board.c index dedbc6dce9..04aa9e8777 100644 --- a/board/guybrush/board.c +++ b/board/guybrush/board.c @@ -5,6 +5,7 @@ /* Guybrush board-specific configuration */ +#include "adc.h" #include "base_fw_config.h" #include "board_fw_config.h" #include "button.h" @@ -16,6 +17,8 @@ #include "driver/accel_bma422.h" #include "driver/retimer/ps8811.h" #include "driver/retimer/ps8818.h" +#include "driver/temp_sensor/sb_tsi.h" +#include "driver/temp_sensor/tmp112.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -25,8 +28,10 @@ #include "power_button.h" #include "switch.h" #include "tablet_mode.h" +#include "temp_sensor.h" #include "temp_sensor/thermistor.h" #include "temp_sensor/tmp112.h" +#include "thermal.h" #include "usb_mux.h" #include "gpio_list.h" /* Must come after other header files. */ @@ -398,3 +403,150 @@ int board_get_ambient_temp_mk(int *temp_mk) return tmp112_get_val_mk(TMP112_AMB, temp_mk); } + +/* ADC Channels */ +const struct adc_t adc_channels[] = { + [ADC_TEMP_SENSOR_SOC] = { + .name = "SOC", + .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_CH1, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_TEMP_SENSOR_MEMORY] = { + .name = "MEMORY", + .input_ch = NPCX_ADC_CH2, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_CORE_IMON1] = { + .name = "CORE_I", + .input_ch = NPCX_ADC_CH3, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_SOC_IMON2] = { + .name = "SOC_I", + .input_ch = NPCX_ADC_CH4, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); + +/* Temp Sensors */ +static int board_get_memory_temp(int, int *); + +const struct tmp112_sensor_t tmp112_sensors[] = { + { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS0 }, + { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS1 }, +}; +BUILD_ASSERT(ARRAY_SIZE(tmp112_sensors) == TMP112_COUNT); + +const struct temp_sensor_t temp_sensors[] = { + [TEMP_SENSOR_SOC] = { + .name = "SOC", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_soc_temp_k, + .idx = TMP112_SOC, + }, + [TEMP_SENSOR_CHARGER] = { + .name = "Charger", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_30k9_47k_4050b, + .idx = ADC_TEMP_SENSOR_CHARGER, + }, + [TEMP_SENSOR_MEMORY] = { + .name = "Memory", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_memory_temp, + .idx = ADC_TEMP_SENSOR_MEMORY, + }, + [TEMP_SENSOR_CPU] = { + .name = "CPU", + .type = TEMP_SENSOR_TYPE_CPU, + .read = sb_tsi_get_val, + .idx = 0, + }, + [TEMP_SENSOR_AMBIENT] = { + .name = "Ambient", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = tmp112_get_val_k, + .idx = TMP112_AMB, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + +struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT] = { + [TEMP_SENSOR_SOC] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + /* TODO: Setting fan off to 0 so it's allways on */ + .temp_fan_off = C_TO_K(0), + .temp_fan_max = C_TO_K(70), + }, + [TEMP_SENSOR_CHARGER] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + .temp_fan_off = 0, + .temp_fan_max = 0, + }, + [TEMP_SENSOR_MEMORY] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + .temp_fan_off = 0, + .temp_fan_max = 0, + }, + [TEMP_SENSOR_CPU] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + /* + * CPU temp sensor fan thresholds are high because they are a + * backup for the SOC temp sensor fan thresholds. + */ + .temp_fan_off = C_TO_K(60), + .temp_fan_max = C_TO_K(90), + }, + /* + * Note: Leave ambient entries at 0, both as it does not represent a + * hotspot and as not all boards have this sensor + */ +}; +BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); + +static int board_get_memory_temp(int idx, int *temp_k) +{ + if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) + return EC_ERROR_NOT_POWERED; + return get_temp_3v3_30k9_47k_4050b(idx, temp_k); +} diff --git a/board/guybrush/board.h b/board/guybrush/board.h index 7dd66e020e..39adbc2ec7 100644 --- a/board/guybrush/board.h +++ b/board/guybrush/board.h @@ -71,6 +71,26 @@ enum base_accelgyro_type { BASE_GYRO_BMI323 = 2, }; +/* ADC Channels */ +enum adc_channel { + ADC_TEMP_SENSOR_SOC = 0, + ADC_TEMP_SENSOR_CHARGER, + ADC_TEMP_SENSOR_MEMORY, + ADC_CORE_IMON1, + ADC_SOC_IMON2, + ADC_CH_COUNT +}; + +/* Temp Sensors */ +enum temp_sensor_id { + TEMP_SENSOR_SOC = 0, + TEMP_SENSOR_CHARGER, + TEMP_SENSOR_MEMORY, + TEMP_SENSOR_CPU, + TEMP_SENSOR_AMBIENT, + TEMP_SENSOR_COUNT +}; + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/nipperkin/board.c b/board/nipperkin/board.c index ee82594d2a..ae8ff661c0 100644 --- a/board/nipperkin/board.c +++ b/board/nipperkin/board.c @@ -5,6 +5,7 @@ /* Guybrush board-specific configuration */ +#include "adc.h" #include "base_fw_config.h" #include "board_fw_config.h" #include "button.h" @@ -13,6 +14,8 @@ #include "cros_board_info.h" #include "driver/retimer/ps8811.h" #include "driver/retimer/ps8818.h" +#include "driver/temp_sensor/sb_tsi.h" +#include "driver/temp_sensor/tmp112.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -22,8 +25,10 @@ #include "power_button.h" #include "switch.h" #include "tablet_mode.h" +#include "temp_sensor.h" #include "temp_sensor/thermistor.h" #include "temp_sensor/tmp112.h" +#include "thermal.h" #include "usb_mux.h" #include "gpio_list.h" /* Must come after other header files. */ @@ -163,3 +168,150 @@ int board_get_ambient_temp_mk(int *temp_mk) return tmp112_get_val_mk(TMP112_AMB, temp_mk); } + +/* ADC Channels */ +const struct adc_t adc_channels[] = { + [ADC_TEMP_SENSOR_SOC] = { + .name = "SOC", + .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_CH1, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_TEMP_SENSOR_MEMORY] = { + .name = "MEMORY", + .input_ch = NPCX_ADC_CH2, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_CORE_IMON1] = { + .name = "CORE_I", + .input_ch = NPCX_ADC_CH3, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_SOC_IMON2] = { + .name = "SOC_I", + .input_ch = NPCX_ADC_CH4, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); + +/* Temp Sensors */ +static int board_get_memory_temp(int, int *); + +const struct tmp112_sensor_t tmp112_sensors[] = { + { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS0 }, + { I2C_PORT_SENSOR, TMP112_I2C_ADDR_FLAGS1 }, +}; +BUILD_ASSERT(ARRAY_SIZE(tmp112_sensors) == TMP112_COUNT); + +const struct temp_sensor_t temp_sensors[] = { + [TEMP_SENSOR_SOC] = { + .name = "SOC", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_soc_temp_k, + .idx = TMP112_SOC, + }, + [TEMP_SENSOR_CHARGER] = { + .name = "Charger", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_30k9_47k_4050b, + .idx = ADC_TEMP_SENSOR_CHARGER, + }, + [TEMP_SENSOR_MEMORY] = { + .name = "Memory", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = board_get_memory_temp, + .idx = ADC_TEMP_SENSOR_MEMORY, + }, + [TEMP_SENSOR_CPU] = { + .name = "CPU", + .type = TEMP_SENSOR_TYPE_CPU, + .read = sb_tsi_get_val, + .idx = 0, + }, + [TEMP_SENSOR_AMBIENT] = { + .name = "Ambient", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = tmp112_get_val_k, + .idx = TMP112_AMB, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + +struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT] = { + [TEMP_SENSOR_SOC] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + /* TODO: Setting fan off to 0 so it's allways on */ + .temp_fan_off = C_TO_K(0), + .temp_fan_max = C_TO_K(70), + }, + [TEMP_SENSOR_CHARGER] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + .temp_fan_off = 0, + .temp_fan_max = 0, + }, + [TEMP_SENSOR_MEMORY] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + .temp_fan_off = 0, + .temp_fan_max = 0, + }, + [TEMP_SENSOR_CPU] = { + .temp_host = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(100), + [EC_TEMP_THRESH_HALT] = C_TO_K(105), + }, + .temp_host_release = { + [EC_TEMP_THRESH_HIGH] = C_TO_K(80), + }, + /* + * CPU temp sensor fan thresholds are high because they are a + * backup for the SOC temp sensor fan thresholds. + */ + .temp_fan_off = C_TO_K(60), + .temp_fan_max = C_TO_K(90), + }, + /* + * Note: Leave ambient entries at 0, both as it does not represent a + * hotspot and as not all boards have this sensor + */ +}; +BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); + +static int board_get_memory_temp(int idx, int *temp_k) +{ + if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) + return EC_ERROR_NOT_POWERED; + return get_temp_3v3_30k9_47k_4050b(idx, temp_k); +} diff --git a/board/nipperkin/board.h b/board/nipperkin/board.h index 4a1d3b0638..dd3238483d 100644 --- a/board/nipperkin/board.h +++ b/board/nipperkin/board.h @@ -45,6 +45,26 @@ enum battery_type { BATTERY_TYPE_COUNT, }; +/* ADC Channels */ +enum adc_channel { + ADC_TEMP_SENSOR_SOC = 0, + ADC_TEMP_SENSOR_CHARGER, + ADC_TEMP_SENSOR_MEMORY, + ADC_CORE_IMON1, + ADC_SOC_IMON2, + ADC_CH_COUNT +}; + +/* Temp Sensors */ +enum temp_sensor_id { + TEMP_SENSOR_SOC = 0, + TEMP_SENSOR_CHARGER, + TEMP_SENSOR_MEMORY, + TEMP_SENSOR_CPU, + TEMP_SENSOR_AMBIENT, + TEMP_SENSOR_COUNT +}; + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ -- cgit v1.2.1