Mike Frysinger | 71b2ef7 | 2022-09-12 18:54:36 | [diff] [blame] | 1 | /* Copyright 2021 The ChromiumOS Authors |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 6 | #include "accelgyro.h" |
| 7 | #include "adc_chip.h" |
Devin Lu | eedacab | 2022-02-14 09:23:27 | [diff] [blame] | 8 | #include "cbi_ssfc.h" |
Jeremy Bettis | c50046a | 2022-11-28 17:00:45 | [diff] [blame] | 9 | #include "common.h" |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 10 | #include "driver/accel_bma2x2.h" |
Devin Lu | eedacab | 2022-02-14 09:23:27 | [diff] [blame] | 11 | #include "driver/accel_bma422.h" |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 12 | #include "driver/accelgyro_lsm6dsm.h" |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 13 | #include "driver/als_tcs3400_public.h" |
Keith Short | 9877be7 | 2022-02-11 22:46:24 | [diff] [blame] | 14 | #include "gpio.h" |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 15 | #include "hooks.h" |
| 16 | #include "motion_sense.h" |
| 17 | #include "temp_sensor.h" |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 18 | #include "temp_sensor/thermistor.h" |
Jeremy Bettis | c50046a | 2022-11-28 17:00:45 | [diff] [blame] | 19 | #include "thermal.h" |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 20 | |
| 21 | /* ADC configuration */ |
| 22 | const struct adc_t adc_channels[] = { |
Devin Lu | 6e9c1b3 | 2021-08-06 01:30:47 | [diff] [blame] | 23 | [ADC_TEMP_SENSOR_1_DDR] = { |
| 24 | .name = "TEMP_DDR", |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 25 | .input_ch = NPCX_ADC_CH0, |
| 26 | .factor_mul = ADC_MAX_VOLT, |
| 27 | .factor_div = ADC_READ_MAX + 1, |
| 28 | .shift = 0, |
| 29 | }, |
Devin Lu | 6e9c1b3 | 2021-08-06 01:30:47 | [diff] [blame] | 30 | [ADC_TEMP_SENSOR_2_SOC] = { |
| 31 | .name = "TEMP_SOC", |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 32 | .input_ch = NPCX_ADC_CH1, |
| 33 | .factor_mul = ADC_MAX_VOLT, |
| 34 | .factor_div = ADC_READ_MAX + 1, |
| 35 | .shift = 0, |
| 36 | }, |
| 37 | [ADC_TEMP_SENSOR_3_CHARGER] = { |
| 38 | .name = "TEMP_CHARGER", |
| 39 | .input_ch = NPCX_ADC_CH6, |
| 40 | .factor_mul = ADC_MAX_VOLT, |
| 41 | .factor_div = ADC_READ_MAX + 1, |
| 42 | .shift = 0, |
| 43 | }, |
Devin Lu | 6e9c1b3 | 2021-08-06 01:30:47 | [diff] [blame] | 44 | [ADC_TEMP_SENSOR_4_REGULATOR] = { |
| 45 | .name = "TEMP_REGULATOR", |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 46 | .input_ch = NPCX_ADC_CH7, |
| 47 | .factor_mul = ADC_MAX_VOLT, |
| 48 | .factor_div = ADC_READ_MAX + 1, |
| 49 | .shift = 0, |
| 50 | }, |
| 51 | }; |
| 52 | BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); |
| 53 | |
| 54 | K_MUTEX_DEFINE(g_lid_accel_mutex); |
| 55 | K_MUTEX_DEFINE(g_base_accel_mutex); |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 56 | static struct accelgyro_saved_data_t g_bma253_data; |
Devin Lu | eedacab | 2022-02-14 09:23:27 | [diff] [blame] | 57 | static struct accelgyro_saved_data_t g_bma422_data; |
Devin Lu | 856b4e1 | 2021-08-05 08:23:11 | [diff] [blame] | 58 | static struct lsm6dsm_data lsm6dsm_data = LSM6DSM_DATA; |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 59 | |
Jack Rosenthal | 5d575a5 | 2022-06-27 20:02:12 | [diff] [blame] | 60 | static const mat33_fp_t lid_standard_ref = { { FLOAT_TO_FP(-1), 0, 0 }, |
| 61 | { 0, FLOAT_TO_FP(1), 0 }, |
| 62 | { 0, 0, FLOAT_TO_FP(-1) } }; |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 63 | |
Jack Rosenthal | 5d575a5 | 2022-06-27 20:02:12 | [diff] [blame] | 64 | static const mat33_fp_t base_standard_ref = { { FLOAT_TO_FP(-1), 0, 0 }, |
| 65 | { 0, FLOAT_TO_FP(1), 0 }, |
| 66 | { 0, 0, FLOAT_TO_FP(-1) } }; |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 67 | |
| 68 | /* TCS3400 private data */ |
| 69 | static struct als_drv_data_t g_tcs3400_data = { |
| 70 | .als_cal.scale = 1, |
| 71 | .als_cal.uscale = 0, |
| 72 | .als_cal.offset = 0, |
| 73 | .als_cal.channel_scale = { |
| 74 | .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kc from VPD */ |
Isaac Lee | ed19189 | 2021-11-09 06:34:11 | [diff] [blame] | 75 | .cover_scale = ALS_CHANNEL_SCALE(0.98), /* CT */ |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 76 | }, |
| 77 | }; |
| 78 | |
| 79 | /* |
| 80 | * TODO: b/184702900 need to calibrate ALS/RGB sensor. At default settings, |
| 81 | * shining phone flashlight on sensor pegs all readings at 0xFFFF. |
| 82 | */ |
| 83 | static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = { |
| 84 | .calibration.rgb_cal[X] = { |
Isaac Lee | ed19189 | 2021-11-09 06:34:11 | [diff] [blame] | 85 | .offset = 66, /* 66.47729532 */ |
| 86 | .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(0.00222243), |
| 87 | .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0.51877192), |
| 88 | .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(-0.28664117), |
| 89 | .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0.0586877), |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 90 | .scale = { |
| 91 | .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kr */ |
Isaac Lee | ed19189 | 2021-11-09 06:34:11 | [diff] [blame] | 92 | .cover_scale = ALS_CHANNEL_SCALE(0.61) |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 93 | } |
| 94 | }, |
| 95 | .calibration.rgb_cal[Y] = { |
Isaac Lee | ed19189 | 2021-11-09 06:34:11 | [diff] [blame] | 96 | .offset = 41, /* 40.95355984 */ |
| 97 | .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(-0.15384715), |
| 98 | .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(0.40454969), |
| 99 | .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(-0.237452), |
| 100 | .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0.13102168), |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 101 | .scale = { |
| 102 | .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kg */ |
| 103 | .cover_scale = ALS_CHANNEL_SCALE(1.0) |
| 104 | }, |
| 105 | }, |
| 106 | .calibration.rgb_cal[Z] = { |
Isaac Lee | ed19189 | 2021-11-09 06:34:11 | [diff] [blame] | 107 | .offset = 5, /* 5.08596128 */ |
| 108 | .coeff[TCS_RED_COEFF_IDX] = FLOAT_TO_FP(-0.79005309), |
| 109 | .coeff[TCS_GREEN_COEFF_IDX] = FLOAT_TO_FP(-0.35553576), |
| 110 | .coeff[TCS_BLUE_COEFF_IDX] = FLOAT_TO_FP(0.13997097), |
| 111 | .coeff[TCS_CLEAR_COEFF_IDX] = FLOAT_TO_FP(0.40223911), |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 112 | .scale = { |
| 113 | .k_channel_scale = ALS_CHANNEL_SCALE(1.0), /* kb */ |
Isaac Lee | ed19189 | 2021-11-09 06:34:11 | [diff] [blame] | 114 | .cover_scale = ALS_CHANNEL_SCALE(1.6) |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 115 | } |
| 116 | }, |
Boris Mittelberg | c8bc274 | 2022-08-11 22:03:42 | [diff] [blame] | 117 | .calibration.irt = FLOAT_TO_FP(0.41), |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 118 | .saturation.again = TCS_DEFAULT_AGAIN, |
| 119 | .saturation.atime = TCS_DEFAULT_ATIME, |
| 120 | }; |
| 121 | |
| 122 | struct motion_sensor_t motion_sensors[] = { |
| 123 | [LID_ACCEL] = { |
| 124 | .name = "Lid Accel", |
| 125 | .active_mask = SENSOR_ACTIVE_S0_S3, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 126 | .chip = MOTIONSENSE_CHIP_BMA255, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 127 | .type = MOTIONSENSE_TYPE_ACCEL, |
| 128 | .location = MOTIONSENSE_LOC_LID, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 129 | .drv = &bma2x2_accel_drv, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 130 | .mutex = &g_lid_accel_mutex, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 131 | .drv_data = &g_bma253_data, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 132 | .port = I2C_PORT_SENSOR, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 133 | .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 134 | .rot_standard_ref = &lid_standard_ref, /* identity matrix */ |
| 135 | .default_range = 2, /* g */ |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 136 | .min_frequency = BMA255_ACCEL_MIN_FREQ, |
| 137 | .max_frequency = BMA255_ACCEL_MAX_FREQ, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 138 | .config = { |
| 139 | /* EC use accel for angle detection */ |
| 140 | [SENSOR_CONFIG_EC_S0] = { |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 141 | .odr = 10000 | ROUND_UP_FLAG, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 142 | }, |
| 143 | /* Sensor on for lid angle detection */ |
| 144 | [SENSOR_CONFIG_EC_S3] = { |
| 145 | .odr = 10000 | ROUND_UP_FLAG, |
| 146 | }, |
| 147 | }, |
| 148 | }, |
| 149 | |
| 150 | [BASE_ACCEL] = { |
| 151 | .name = "Base Accel", |
| 152 | .active_mask = SENSOR_ACTIVE_S0_S3, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 153 | .chip = MOTIONSENSE_CHIP_LSM6DSM, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 154 | .type = MOTIONSENSE_TYPE_ACCEL, |
| 155 | .location = MOTIONSENSE_LOC_BASE, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 156 | .drv = &lsm6dsm_drv, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 157 | .mutex = &g_base_accel_mutex, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 158 | .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data, |
elmo_lan | 1d0e31a | 2021-07-13 11:52:48 | [diff] [blame] | 159 | MOTIONSENSE_TYPE_ACCEL), |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 160 | .port = I2C_PORT_SENSOR, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 161 | .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 162 | .rot_standard_ref = &base_standard_ref, |
| 163 | .default_range = 4, /* g */ |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 164 | .min_frequency = LSM6DSM_ODR_MIN_VAL, |
| 165 | .max_frequency = LSM6DSM_ODR_MAX_VAL, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 166 | .config = { |
| 167 | [SENSOR_CONFIG_EC_S0] = { |
| 168 | .odr = 13000 | ROUND_UP_FLAG, |
| 169 | .ec_rate = 100 * MSEC, |
| 170 | }, |
| 171 | [SENSOR_CONFIG_EC_S3] = { |
| 172 | .odr = 10000 | ROUND_UP_FLAG, |
| 173 | .ec_rate = 100 * MSEC, |
| 174 | }, |
| 175 | }, |
| 176 | }, |
| 177 | |
| 178 | [BASE_GYRO] = { |
| 179 | .name = "Base Gyro", |
| 180 | .active_mask = SENSOR_ACTIVE_S0_S3, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 181 | .chip = MOTIONSENSE_CHIP_LSM6DSM, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 182 | .type = MOTIONSENSE_TYPE_GYRO, |
| 183 | .location = MOTIONSENSE_LOC_BASE, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 184 | .drv = &lsm6dsm_drv, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 185 | .mutex = &g_base_accel_mutex, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 186 | .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data, |
elmo_lan | 1d0e31a | 2021-07-13 11:52:48 | [diff] [blame] | 187 | MOTIONSENSE_TYPE_GYRO), |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 188 | .port = I2C_PORT_SENSOR, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 189 | .i2c_spi_addr_flags = LSM6DSM_ADDR0_FLAGS, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 190 | .default_range = 1000 | ROUND_UP_FLAG, /* dps */ |
| 191 | .rot_standard_ref = &base_standard_ref, |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 192 | .min_frequency = LSM6DSM_ODR_MIN_VAL, |
| 193 | .max_frequency = LSM6DSM_ODR_MAX_VAL, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 194 | }, |
| 195 | |
| 196 | [CLEAR_ALS] = { |
| 197 | .name = "Clear Light", |
| 198 | .active_mask = SENSOR_ACTIVE_S0_S3, |
| 199 | .chip = MOTIONSENSE_CHIP_TCS3400, |
| 200 | .type = MOTIONSENSE_TYPE_LIGHT, |
| 201 | .location = MOTIONSENSE_LOC_CAMERA, |
| 202 | .drv = &tcs3400_drv, |
| 203 | .drv_data = &g_tcs3400_data, |
| 204 | .port = I2C_PORT_SENSOR, |
| 205 | .i2c_spi_addr_flags = TCS3400_I2C_ADDR_FLAGS, |
| 206 | .rot_standard_ref = NULL, |
| 207 | .default_range = 0x10000, /* scale = 1x, uscale = 0 */ |
| 208 | .min_frequency = TCS3400_LIGHT_MIN_FREQ, |
| 209 | .max_frequency = TCS3400_LIGHT_MAX_FREQ, |
| 210 | .config = { |
| 211 | /* Run ALS sensor in S0 */ |
| 212 | [SENSOR_CONFIG_EC_S0] = { |
| 213 | .odr = 1000, |
| 214 | }, |
| 215 | }, |
| 216 | }, |
| 217 | |
| 218 | [RGB_ALS] = { |
| 219 | /* |
| 220 | * RGB channels read by CLEAR_ALS and so the i2c port and |
| 221 | * address do not need to be defined for RGB_ALS. |
| 222 | */ |
| 223 | .name = "RGB Light", |
| 224 | .active_mask = SENSOR_ACTIVE_S0_S3, |
| 225 | .chip = MOTIONSENSE_CHIP_TCS3400, |
| 226 | .type = MOTIONSENSE_TYPE_LIGHT_RGB, |
| 227 | .location = MOTIONSENSE_LOC_CAMERA, |
| 228 | .drv = &tcs3400_rgb_drv, |
| 229 | .drv_data = &g_tcs3400_rgb_data, |
| 230 | .rot_standard_ref = NULL, |
| 231 | .default_range = 0x10000, /* scale = 1x, uscale = 0 */ |
| 232 | }, |
| 233 | }; |
| 234 | const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); |
| 235 | |
Devin Lu | eedacab | 2022-02-14 09:23:27 | [diff] [blame] | 236 | struct motion_sensor_t bma422_lid_accel = { |
| 237 | .name = "Lid Accel", |
| 238 | .active_mask = SENSOR_ACTIVE_S0_S3, |
| 239 | .chip = MOTIONSENSE_CHIP_BMA422, |
| 240 | .type = MOTIONSENSE_TYPE_ACCEL, |
| 241 | .location = MOTIONSENSE_LOC_LID, |
| 242 | .drv = &bma4_accel_drv, |
| 243 | .mutex = &g_lid_accel_mutex, |
| 244 | .drv_data = &g_bma422_data, |
| 245 | .port = I2C_PORT_SENSOR, |
| 246 | .i2c_spi_addr_flags = BMA4_I2C_ADDR_PRIMARY, |
| 247 | .rot_standard_ref = &lid_standard_ref, |
| 248 | .default_range = 2, /* g, enough for laptop. */ |
| 249 | .min_frequency = BMA4_ACCEL_MIN_FREQ, |
| 250 | .max_frequency = BMA4_ACCEL_MAX_FREQ, |
| 251 | .config = { |
| 252 | /* EC use accel for angle detection */ |
| 253 | [SENSOR_CONFIG_EC_S0] = { |
| 254 | .odr = 12500 | ROUND_UP_FLAG, |
| 255 | .ec_rate = 100 * MSEC, |
| 256 | }, |
| 257 | /* Sensor on in S3 */ |
| 258 | [SENSOR_CONFIG_EC_S3] = { |
| 259 | .odr = 12500 | ROUND_UP_FLAG, |
| 260 | .ec_rate = 0, |
| 261 | }, |
| 262 | }, |
| 263 | }; |
| 264 | |
| 265 | static void board_update_motion_sensor_config(void) |
| 266 | { |
| 267 | if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_BMA422) |
| 268 | motion_sensors[LID_ACCEL] = bma422_lid_accel; |
| 269 | } |
| 270 | |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 271 | /* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */ |
| 272 | const struct motion_sensor_t *motion_als_sensors[] = { |
| 273 | &motion_sensors[CLEAR_ALS], |
| 274 | }; |
| 275 | BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT); |
| 276 | |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 277 | static void board_sensors_init(void) |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 278 | { |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 279 | /* Enable interrupt for the TCS3400 color light sensor */ |
| 280 | gpio_enable_interrupt(GPIO_EC_ALS_RGB_INT_R_L); |
| 281 | /* Enable gpio interrupt for base accelgyro sensor */ |
| 282 | gpio_enable_interrupt(GPIO_EC_IMU_INT_R_L); |
Devin Lu | eedacab | 2022-02-14 09:23:27 | [diff] [blame] | 283 | |
| 284 | board_update_motion_sensor_config(); |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 285 | } |
Devin Lu | edc228b | 2021-07-19 03:03:05 | [diff] [blame] | 286 | DECLARE_HOOK(HOOK_INIT, board_sensors_init, HOOK_PRIO_INIT_I2C + 1); |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 287 | |
| 288 | /* Temperature sensor configuration */ |
| 289 | const struct temp_sensor_t temp_sensors[] = { |
Jack Rosenthal | 5d575a5 | 2022-06-27 20:02:12 | [diff] [blame] | 290 | [TEMP_SENSOR_1_DDR] = { .name = "DDR", |
| 291 | .type = TEMP_SENSOR_TYPE_BOARD, |
| 292 | .read = get_temp_3v3_30k9_47k_4050b, |
| 293 | .idx = ADC_TEMP_SENSOR_1_DDR }, |
| 294 | [TEMP_SENSOR_2_SOC] = { .name = "SOC", |
| 295 | .type = TEMP_SENSOR_TYPE_BOARD, |
| 296 | .read = get_temp_3v3_30k9_47k_4050b, |
| 297 | .idx = ADC_TEMP_SENSOR_2_SOC }, |
| 298 | [TEMP_SENSOR_3_CHARGER] = { .name = "Charger", |
| 299 | .type = TEMP_SENSOR_TYPE_BOARD, |
| 300 | .read = get_temp_3v3_30k9_47k_4050b, |
| 301 | .idx = ADC_TEMP_SENSOR_3_CHARGER }, |
| 302 | [TEMP_SENSOR_4_REGULATOR] = { .name = "Regulator", |
| 303 | .type = TEMP_SENSOR_TYPE_BOARD, |
| 304 | .read = get_temp_3v3_30k9_47k_4050b, |
| 305 | .idx = ADC_TEMP_SENSOR_4_REGULATOR }, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 306 | }; |
| 307 | BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); |
| 308 | |
Tom Hughes | 04d24d1 | 2023-12-01 18:08:13 | [diff] [blame^] | 309 | static const struct ec_thermal_config thermal_ddr = { |
| 310 | .temp_host = { |
| 311 | [EC_TEMP_THRESH_HIGH] = C_TO_K(75), |
| 312 | [EC_TEMP_THRESH_HALT] = C_TO_K(80), |
| 313 | }, |
| 314 | .temp_host_release = { |
| 315 | [EC_TEMP_THRESH_HIGH] = C_TO_K(70), |
| 316 | }, |
| 317 | }; |
Devin Lu | 6e9c1b3 | 2021-08-06 01:30:47 | [diff] [blame] | 318 | |
| 319 | /* |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 320 | * Tiger Lake specifies 100 C as maximum TDP temperature. THRMTRIP# occurs at |
Devin Lu | 6e9c1b3 | 2021-08-06 01:30:47 | [diff] [blame] | 321 | * 130 C. However, sensor is located next to SOC, so we need to use the lower |
| 322 | * SOC temperature limit (85 C) |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 323 | */ |
Tom Hughes | 04d24d1 | 2023-12-01 18:08:13 | [diff] [blame^] | 324 | static const struct ec_thermal_config thermal_cpu = { |
| 325 | .temp_host = { |
| 326 | [EC_TEMP_THRESH_HIGH] = C_TO_K(75), |
| 327 | [EC_TEMP_THRESH_HALT] = C_TO_K(80), |
| 328 | }, |
| 329 | .temp_host_release = { |
| 330 | [EC_TEMP_THRESH_HIGH] = C_TO_K(70), |
| 331 | }, |
| 332 | }; |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 333 | |
Tom Hughes | 04d24d1 | 2023-12-01 18:08:13 | [diff] [blame^] | 334 | static const struct ec_thermal_config thermal_charger = { |
| 335 | .temp_host = { |
| 336 | [EC_TEMP_THRESH_HIGH] = C_TO_K(80), |
| 337 | [EC_TEMP_THRESH_HALT] = C_TO_K(85), |
| 338 | }, |
| 339 | .temp_host_release = { |
| 340 | [EC_TEMP_THRESH_HIGH] = C_TO_K(75), |
| 341 | }, |
| 342 | }; |
Devin Lu | 6e9c1b3 | 2021-08-06 01:30:47 | [diff] [blame] | 343 | |
Tom Hughes | 04d24d1 | 2023-12-01 18:08:13 | [diff] [blame^] | 344 | static const struct ec_thermal_config thermal_regulator = { |
| 345 | .temp_host = { |
| 346 | [EC_TEMP_THRESH_HIGH] = C_TO_K(80), |
| 347 | [EC_TEMP_THRESH_HALT] = C_TO_K(85), |
| 348 | }, |
| 349 | .temp_host_release = { |
| 350 | [EC_TEMP_THRESH_HIGH] = C_TO_K(75), |
| 351 | }, |
| 352 | }; |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 353 | |
| 354 | /* this should really be "const" */ |
| 355 | struct ec_thermal_config thermal_params[] = { |
Tom Hughes | 04d24d1 | 2023-12-01 18:08:13 | [diff] [blame^] | 356 | [TEMP_SENSOR_1_DDR] = thermal_ddr, |
| 357 | [TEMP_SENSOR_2_SOC] = thermal_cpu, |
| 358 | [TEMP_SENSOR_3_CHARGER] = thermal_charger, |
| 359 | [TEMP_SENSOR_4_REGULATOR] = thermal_regulator, |
Wisley Chen | 2ef205a | 2021-06-25 08:37:56 | [diff] [blame] | 360 | }; |
| 361 | BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT); |