developer | 2cdaeb1 | 2022-10-04 20:25:05 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 |
| 2 | * |
| 3 | * Copyright (c) 2022 MediaTek Inc. |
| 4 | * Author: Henry Yen <henry.yen@mediatek.com> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/bits.h> |
| 8 | #include <linux/clk.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/interrupt.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/iopoll.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/nvmem-consumer.h> |
| 16 | #include <linux/of_irq.h> |
| 17 | #include <linux/of.h> |
| 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_device.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/reset.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/thermal.h> |
| 25 | #include "soc_temp_lvts.h" |
| 26 | |
| 27 | /* |
| 28 | * Definition or macro function |
| 29 | */ |
| 30 | #define STOP_COUNTING_V5 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x00) |
| 31 | #define SET_RG_TSFM_LPDLY_V5 (DEVICE_WRITE | RG_TSFM_CTRL_4 << 8 | 0xA6) |
| 32 | #define SET_COUNTING_WINDOW_20US1_V5 (DEVICE_WRITE | RG_TSFM_CTRL_2 << 8 | 0x00) |
| 33 | #define SET_COUNTING_WINDOW_20US2_V5 (DEVICE_WRITE | RG_TSFM_CTRL_1 << 8 | 0x20) |
| 34 | #define TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V5 \ |
| 35 | (DEVICE_WRITE | RG_TSV2F_CTRL_2 << 8 | 0x8C) |
| 36 | #define TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V5 \ |
| 37 | (DEVICE_WRITE | RG_TSV2F_CTRL_4 << 8 | 0xFC) |
| 38 | #define SET_TS_RSV_V5 (DEVICE_WRITE | RG_TSV2F_CTRL_1 << 8 | 0x8D) |
| 39 | #define SET_TS_EN_V5 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 0xF1) |
developer | a97210b | 2023-04-25 14:55:53 +0800 | [diff] [blame^] | 40 | #define SET_TS_V2VF_RSV_V5 (DEVICE_WRITE | RG_TSV2F_CTRL_3 << 8 | 0x04) |
developer | 2cdaeb1 | 2022-10-04 20:25:05 +0800 | [diff] [blame] | 41 | |
| 42 | #define SET_MANUAL_RCK_V5 (DEVICE_WRITE | RG_TSV2F_CTRL_6 << 8 | 0x00) |
| 43 | #define SELECT_SENSOR_RCK_V5(id) (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | (id)) |
| 44 | #define SET_DEVICE_SINGLE_MODE_V5 (DEVICE_WRITE | RG_TSFM_CTRL_3 << 8 | 0xB8) |
| 45 | #define KICK_OFF_RCK_COUNTING_V5 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x02) |
| 46 | #define SET_SENSOR_NO_RCK_V5(id) \ |
| 47 | (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | 0x10 | (id)) |
| 48 | #define SET_DEVICE_LOW_POWER_SINGLE_MODE_V5 \ |
| 49 | (DEVICE_WRITE | RG_TSFM_CTRL_3 << 8 | 0xB8) |
| 50 | |
| 51 | #define STOP_COUNTING_V4 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x00) |
| 52 | #define SET_RG_TSFM_LPDLY_V4 (DEVICE_WRITE | RG_TSFM_CTRL_4 << 8 | 0xA6) |
| 53 | #define SET_COUNTING_WINDOW_20US1_V4 (DEVICE_WRITE | RG_TSFM_CTRL_2 << 8 | 0x00) |
| 54 | #define SET_COUNTING_WINDOW_20US2_V4 (DEVICE_WRITE | RG_TSFM_CTRL_1 << 8 | 0x20) |
| 55 | #define TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V4 \ |
| 56 | (DEVICE_WRITE | RG_TSV2F_CTRL_2 << 8 | 0x84) |
| 57 | #define TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V4 \ |
| 58 | (DEVICE_WRITE | RG_TSV2F_CTRL_4 << 8 | 0x7C) |
| 59 | #define SET_TS_RSV_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_1 << 8 | 0x8D) |
| 60 | #define SET_TS_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 0xF4) |
| 61 | #define TOGGLE_RG_TSV2F_VCO_RST1_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 0xFC) |
| 62 | #define TOGGLE_RG_TSV2F_VCO_RST2_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 0xF4) |
| 63 | |
| 64 | #define SET_LVTS_AUTO_RCK_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_6 << 8 | 0x01) |
| 65 | #define SELECT_SENSOR_RCK_V4(id) (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | (id)) |
| 66 | #define SET_DEVICE_SINGLE_MODE_V4 (DEVICE_WRITE | RG_TSFM_CTRL_3 << 8 | 0x78) |
| 67 | #define KICK_OFF_RCK_COUNTING_V4 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x02) |
| 68 | #define SET_SENSOR_NO_RCK_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | 0x10) |
| 69 | #define SET_DEVICE_LOW_POWER_SINGLE_MODE_V4 \ |
| 70 | (DEVICE_WRITE | RG_TSFM_CTRL_3 << 8 | 0xB8) |
| 71 | |
| 72 | #define ENABLE_FEATURE(feature) (lvts_data->feature_bitmap |= (feature)) |
| 73 | #define DISABLE_FEATURE(feature) (lvts_data->feature_bitmap &= (~(feature))) |
| 74 | #define IS_ENABLE(feature) (lvts_data->feature_bitmap & (feature)) |
| 75 | |
| 76 | #define DISABLE_THERMAL_HW_REBOOT (-274000) |
| 77 | |
| 78 | #define CLOCK_26MHZ_CYCLE_NS (38) |
| 79 | #define BUS_ACCESS_US (2) |
| 80 | #define GOLDEN_TEMP_MAX (62) |
| 81 | #define FEATURE_DEVICE_AUTO_RCK (BIT(0)) |
| 82 | #define FEATURE_CK26M_ACTIVE (BIT(1)) |
| 83 | #define FEATURE_IRQ (BIT(2)) |
| 84 | #define FEATURE_RESET (BIT(3)) |
| 85 | #define CK26M_ACTIVE \ |
| 86 | (((lvts_data->feature_bitmap & FEATURE_CK26M_ACTIVE) ? 1 : 0) << 30) |
| 87 | #define GET_BASE_ADDR(tc_id) \ |
| 88 | (lvts_data->domain[lvts_data->tc[tc_id].domain_index].base + \ |
| 89 | lvts_data->tc[tc_id].addr_offset) |
| 90 | |
| 91 | #define SET_TC_SPEED_IN_US(pu, gd, fd, sd) \ |
| 92 | { \ |
| 93 | .period_unit = (((pu)*1000) / (256 * CLOCK_26MHZ_CYCLE_NS)), \ |
| 94 | .group_interval_delay = ((gd) / (pu)), \ |
| 95 | .filter_interval_delay = ((fd) / (pu)), \ |
| 96 | .sensor_interval_delay = ((sd) / (pu)), \ |
| 97 | } |
| 98 | |
| 99 | #define GET_CAL_DATA_BITMASK(index, h, l) \ |
| 100 | (((index) < lvts_data->num_efuse_addr) ? \ |
| 101 | ((lvts_data->efuse[(index)] & GENMASK(h, l)) >> l) : \ |
| 102 | 0) |
| 103 | |
| 104 | #define GET_CAL_DATA_BIT(index, bit) \ |
| 105 | (((index) < lvts_data->num_efuse_addr) ? \ |
| 106 | ((lvts_data->efuse[index] & BIT(bit)) >> (bit)) : \ |
| 107 | 0) |
| 108 | |
| 109 | #define GET_TC_SENSOR_NUM(tc_id) (lvts_data->tc[tc_id].num_sensor) |
| 110 | |
| 111 | #define ONE_SAMPLE (lvts_data->counting_window_us + 2 * BUS_ACCESS_US) |
| 112 | |
| 113 | #define NUM_OF_SAMPLE(tc_id) \ |
| 114 | ((lvts_data->tc[tc_id].hw_filter < LVTS_FILTER_2) ? \ |
| 115 | 1 : \ |
| 116 | ((lvts_data->tc[tc_id].hw_filter > LVTS_FILTER_16_OF_18) ? \ |
| 117 | 1 : \ |
| 118 | ((lvts_data->tc[tc_id].hw_filter == \ |
| 119 | LVTS_FILTER_16_OF_18) ? \ |
| 120 | 18 : \ |
| 121 | ((lvts_data->tc[tc_id].hw_filter == \ |
| 122 | LVTS_FILTER_8_OF_10) ? \ |
| 123 | 10 : \ |
| 124 | (lvts_data->tc[tc_id].hw_filter * \ |
| 125 | 2))))) |
| 126 | |
| 127 | #define PERIOD_UNIT_US(tc_id) \ |
| 128 | ((lvts_data->tc[tc_id].tc_speed.period_unit * 256 * \ |
| 129 | CLOCK_26MHZ_CYCLE_NS) / \ |
| 130 | 1000) |
| 131 | #define FILTER_INT_US(tc_id) \ |
| 132 | (lvts_data->tc[tc_id].tc_speed.filter_interval_delay * \ |
| 133 | PERIOD_UNIT_US(tc_id)) |
| 134 | #define SENSOR_INT_US(tc_id) \ |
| 135 | (lvts_data->tc[tc_id].tc_speed.sensor_interval_delay * \ |
| 136 | PERIOD_UNIT_US(tc_id)) |
| 137 | #define GROUP_INT_US(tc_id) \ |
| 138 | (lvts_data->tc[tc_id].tc_speed.group_interval_delay * \ |
| 139 | PERIOD_UNIT_US(tc_id)) |
| 140 | |
| 141 | #define SENSOR_LATENCY_US(tc_id) \ |
| 142 | ((NUM_OF_SAMPLE(tc_id) - 1) * FILTER_INT_US(tc_id) + \ |
| 143 | NUM_OF_SAMPLE(tc_id) * ONE_SAMPLE) |
| 144 | |
| 145 | #define GROUP_LATENCY_US(tc_id) \ |
| 146 | (GET_TC_SENSOR_NUM(tc_id) * SENSOR_LATENCY_US(tc_id) + \ |
| 147 | (GET_TC_SENSOR_NUM(tc_id) - 1) * SENSOR_INT_US(tc_id) + \ |
| 148 | GROUP_INT_US(tc_id)) |
| 149 | |
| 150 | /* |
| 151 | * LVTS local common code |
| 152 | */ |
| 153 | static int lvts_raw_to_temp(struct formula_coeff *co, unsigned int msr_raw) |
| 154 | { |
| 155 | /* This function returns degree mC */ |
| 156 | |
| 157 | int temp; |
| 158 | |
| 159 | msr_raw &= 0xffff; |
| 160 | temp = (co->a * ((unsigned long long)msr_raw)) >> 14; |
| 161 | temp = temp + co->golden_temp * 500 + co->b; |
| 162 | |
| 163 | return temp; |
| 164 | } |
| 165 | |
| 166 | static unsigned int lvts_temp_to_raw(struct formula_coeff *co, int temp) |
| 167 | { |
| 168 | unsigned int msr_raw; |
| 169 | |
| 170 | msr_raw = ((long long)((co->golden_temp * 500 + co->b - temp)) << 14) / |
| 171 | (-1 * co->a); |
| 172 | |
| 173 | return msr_raw; |
| 174 | } |
| 175 | |
| 176 | static int lvts_read_all_tc_temperature(struct lvts_data *lvts_data) |
| 177 | { |
| 178 | struct tc_settings *tc = lvts_data->tc; |
| 179 | unsigned int i, j, s_index, msr_raw; |
| 180 | int max_temp = -100000, current_temp; |
| 181 | void __iomem *base; |
| 182 | |
| 183 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 184 | base = GET_BASE_ADDR(i); |
| 185 | for (j = 0; j < tc[i].num_sensor; j++) { |
| 186 | s_index = tc[i].sensor_map[j]; |
| 187 | |
| 188 | msr_raw = readl(LVTSMSR0_0 + base + 0x4 * j) & |
| 189 | MRS_RAW_MASK; |
| 190 | current_temp = |
| 191 | lvts_raw_to_temp(&lvts_data->coeff, msr_raw); |
| 192 | |
| 193 | if (msr_raw == 0) |
| 194 | current_temp = THERMAL_TEMP_INVALID; |
| 195 | |
| 196 | max_temp = max(max_temp, current_temp); |
| 197 | |
| 198 | lvts_data->sen_data[s_index].msr_raw = msr_raw; |
| 199 | lvts_data->sen_data[s_index].temp = current_temp; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return max_temp; |
| 204 | } |
| 205 | |
| 206 | static int soc_temp_lvts_read_temp(void *data, int *temperature) |
| 207 | { |
| 208 | struct soc_temp_tz *lvts_tz = (struct soc_temp_tz *)data; |
| 209 | struct lvts_data *lvts_data = lvts_tz->lvts_data; |
| 210 | |
| 211 | if (lvts_tz->id == 0) |
| 212 | *temperature = lvts_read_all_tc_temperature(lvts_data); |
| 213 | else if (lvts_tz->id - 1 < lvts_data->num_sensor) |
| 214 | *temperature = lvts_data->sen_data[lvts_tz->id - 1].temp; |
| 215 | else |
| 216 | return -EINVAL; |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static const struct thermal_zone_of_device_ops soc_temp_lvts_ops = { |
| 222 | .get_temp = soc_temp_lvts_read_temp, |
| 223 | }; |
| 224 | |
| 225 | static void lvts_write_device(struct lvts_data *lvts_data, unsigned int data, |
| 226 | int tc_id) |
| 227 | { |
| 228 | void __iomem *base; |
| 229 | |
| 230 | base = GET_BASE_ADDR(tc_id); |
| 231 | |
| 232 | writel(data, LVTS_CONFIG_0 + base); |
| 233 | |
| 234 | usleep_range(5, 15); |
| 235 | } |
| 236 | |
| 237 | static unsigned int lvts_read_device(struct lvts_data *lvts_data, |
| 238 | unsigned int reg_idx, int tc_id) |
| 239 | { |
| 240 | struct device *dev = lvts_data->dev; |
| 241 | void __iomem *base; |
| 242 | unsigned int data; |
| 243 | int ret; |
| 244 | |
| 245 | base = GET_BASE_ADDR(tc_id); |
| 246 | writel(READ_DEVICE_REG(reg_idx), LVTS_CONFIG_0 + base); |
| 247 | |
| 248 | ret = readl_poll_timeout(LVTS_CONFIG_0 + base, data, |
| 249 | !(data & DEVICE_ACCESS_STARTUS), 2, 200); |
| 250 | if (ret) |
| 251 | dev_err(dev, |
| 252 | "Error: LVTS %d DEVICE_ACCESS_START didn't ready\n", |
| 253 | tc_id); |
| 254 | |
| 255 | data = readl(LVTSRDATA0_0 + base); |
| 256 | |
| 257 | return data; |
| 258 | } |
| 259 | |
| 260 | static void wait_all_tc_sensing_point_idle(struct lvts_data *lvts_data) |
| 261 | { |
| 262 | struct device *dev = lvts_data->dev; |
| 263 | unsigned int mask, error_code, is_error; |
| 264 | void __iomem *base; |
| 265 | int i, cnt, ret; |
| 266 | |
| 267 | mask = BIT(10) | BIT(7) | BIT(0); |
| 268 | |
| 269 | for (cnt = 0; cnt < 2; cnt++) { |
| 270 | is_error = 0; |
| 271 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 272 | base = GET_BASE_ADDR(i); |
| 273 | ret = readl_poll_timeout(LVTSMSRCTL1_0 + base, |
| 274 | error_code, |
| 275 | !(error_code & mask), 2, 200); |
| 276 | /* |
| 277 | * Error code |
| 278 | * 000: IDLE |
| 279 | * 001: Write transaction |
| 280 | * 010: Waiting for read after Write |
| 281 | * 011: Disable Continue fetching on Device |
| 282 | * 100: Read transaction |
| 283 | * 101: Set Device special Register for Voltage |
| 284 | * threshold |
| 285 | * 111: Set TSMCU number for Fetch |
| 286 | */ |
| 287 | error_code = ((error_code & BIT(10)) >> 8) + |
| 288 | ((error_code & BIT(7)) >> 6) + |
| 289 | (error_code & BIT(0)); |
| 290 | |
| 291 | if (ret) |
| 292 | dev_err(dev, |
| 293 | "Error LVTS %d sensing points aren't idle, error_code %d\n", |
| 294 | i, error_code); |
| 295 | |
| 296 | if (error_code != 0) |
| 297 | is_error = 1; |
| 298 | } |
| 299 | |
| 300 | if (is_error == 0) |
| 301 | break; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | static void lvts_reset(struct lvts_data *lvts_data) |
| 306 | { |
| 307 | int i; |
| 308 | |
| 309 | for (i = 0; i < lvts_data->num_domain; i++) { |
| 310 | if (lvts_data->domain[i].reset) |
| 311 | reset_control_assert(lvts_data->domain[i].reset); |
| 312 | |
| 313 | if (lvts_data->domain[i].reset) |
| 314 | reset_control_deassert(lvts_data->domain[i].reset); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | static void device_identification(struct lvts_data *lvts_data) |
| 319 | { |
| 320 | struct device *dev = lvts_data->dev; |
| 321 | unsigned int i, data; |
| 322 | void __iomem *base; |
| 323 | |
| 324 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 325 | base = GET_BASE_ADDR(i); |
| 326 | |
| 327 | writel(ENABLE_LVTS_CTRL_CLK, LVTSCLKEN_0 + base); |
| 328 | |
| 329 | lvts_write_device(lvts_data, RESET_ALL_DEVICES, i); |
| 330 | |
| 331 | lvts_write_device(lvts_data, READ_BACK_DEVICE_ID, i); |
| 332 | |
| 333 | /* Check LVTS device ID */ |
| 334 | data = (readl(LVTS_ID_0 + base) & GENMASK(7, 0)); |
| 335 | if (data != (0x83 + i)) |
| 336 | dev_err(dev, |
| 337 | "LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", |
| 338 | i, (0x83 + i), data); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | static void disable_all_sensing_points(struct lvts_data *lvts_data) |
| 343 | { |
| 344 | unsigned int i; |
| 345 | void __iomem *base; |
| 346 | |
| 347 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 348 | base = GET_BASE_ADDR(i); |
| 349 | writel(DISABLE_SENSING_POINT, LVTSMONCTL0_0 + base); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | static void enable_all_sensing_points(struct lvts_data *lvts_data) |
| 354 | { |
| 355 | struct device *dev = lvts_data->dev; |
| 356 | struct tc_settings *tc = lvts_data->tc; |
| 357 | unsigned int i, num; |
| 358 | void __iomem *base; |
| 359 | |
| 360 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 361 | base = GET_BASE_ADDR(i); |
| 362 | num = tc[i].num_sensor; |
| 363 | |
| 364 | if (num > ALL_SENSING_POINTS) { |
| 365 | dev_err(dev, |
| 366 | "%s, LVTS%d, illegal number of sensors: %d\n", |
| 367 | __func__, i, tc[i].num_sensor); |
| 368 | continue; |
| 369 | } |
| 370 | |
| 371 | writel(ENABLE_SENSING_POINT(num), LVTSMONCTL0_0 + base); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | static void set_polling_speed(struct lvts_data *lvts_data, int tc_id) |
| 376 | { |
| 377 | struct device *dev = lvts_data->dev; |
| 378 | struct tc_settings *tc = lvts_data->tc; |
| 379 | unsigned int lvts_mon_ctl_1, lvts_mon_ctl_2; |
| 380 | void __iomem *base; |
| 381 | |
| 382 | base = GET_BASE_ADDR(tc_id); |
| 383 | |
| 384 | lvts_mon_ctl_1 = ((tc[tc_id].tc_speed.group_interval_delay << 20) & |
| 385 | GENMASK(29, 20)) | |
| 386 | (tc[tc_id].tc_speed.period_unit & GENMASK(9, 0)); |
| 387 | lvts_mon_ctl_2 = |
| 388 | ((tc[tc_id].tc_speed.filter_interval_delay << 16) & |
| 389 | GENMASK(25, 16)) | |
| 390 | (tc[tc_id].tc_speed.sensor_interval_delay & GENMASK(9, 0)); |
| 391 | /* |
| 392 | * Clock source of LVTS thermal controller is 26MHz. |
| 393 | * Period unit is a base for all interval delays |
| 394 | * All interval delays must multiply it to convert a setting to time. |
| 395 | * |
| 396 | * Filter interval delay: |
| 397 | * A delay between two samples of the same sensor |
| 398 | * |
| 399 | * Sensor interval delay: |
| 400 | * A delay between two samples of differnet sensors |
| 401 | * |
| 402 | * Group interval delay: |
| 403 | * A delay between different rounds. |
| 404 | * |
| 405 | * For example: |
| 406 | * If Period unit = C, filter delay = 1, sensor delay = 2, |
| 407 | * group delay = 1, and two sensors, TS1 and TS2, are in a LVTS |
| 408 | * thermal controller and then |
| 409 | * Period unit = C * 1/26M * 256 = 12 * 38.46ns * 256 = 118.149us |
| 410 | * Filter interval delay = 1 * Period unit = 118.149us |
| 411 | * Sensor interval delay = 2 * Period unit = 236.298us |
| 412 | * Group interval delay = 1 * Period unit = 118.149us |
| 413 | * |
| 414 | * TS1 TS1 ... TS1 TS2 TS2 ... TS2 TS1... |
| 415 | * <--> Filter interval delay |
| 416 | * <--> Sensor interval delay |
| 417 | * <--> Group interval delay |
| 418 | */ |
| 419 | writel(lvts_mon_ctl_1, LVTSMONCTL1_0 + base); |
| 420 | writel(lvts_mon_ctl_2, LVTSMONCTL2_0 + base); |
| 421 | |
| 422 | dev_info(dev, "%s %d, LVTSMONCTL1_0= 0x%x,LVTSMONCTL2_0= 0x%x\n", |
| 423 | __func__, tc_id, readl(LVTSMONCTL1_0 + base), |
| 424 | readl(LVTSMONCTL2_0 + base)); |
| 425 | } |
| 426 | |
| 427 | static void set_hw_filter(struct lvts_data *lvts_data, int tc_id) |
| 428 | { |
| 429 | struct device *dev = lvts_data->dev; |
| 430 | struct tc_settings *tc = lvts_data->tc; |
| 431 | unsigned int option; |
| 432 | void __iomem *base; |
| 433 | |
| 434 | base = GET_BASE_ADDR(tc_id); |
| 435 | option = tc[tc_id].hw_filter & 0x7; |
| 436 | /* hw filter |
| 437 | * 000: Get one sample |
| 438 | * 001: Get 2 samples and average them |
| 439 | * 010: Get 4 samples, drop max and min, then average the rest of 2 |
| 440 | * samples |
| 441 | * 011: Get 6 samples, drop max and min, then average the rest of 4 |
| 442 | * samples |
| 443 | * 100: Get 10 samples, drop max and min, then average the rest of 8 |
| 444 | * samples |
| 445 | * 101: Get 18 samples, drop max and min, then average the rest of 16 |
| 446 | * samples |
| 447 | */ |
| 448 | option = (option << 9) | (option << 6) | (option << 3) | option; |
| 449 | |
| 450 | writel(option, LVTSMSRCTL0_0 + base); |
| 451 | dev_info(dev, "%s %d, LVTSMSRCTL0_0= 0x%x\n", __func__, tc_id, |
| 452 | readl(LVTSMSRCTL0_0 + base)); |
| 453 | } |
| 454 | |
| 455 | static int get_dominator_index(struct lvts_data *lvts_data, int tc_id) |
| 456 | { |
| 457 | struct device *dev = lvts_data->dev; |
| 458 | struct tc_settings *tc = lvts_data->tc; |
| 459 | int d_index; |
| 460 | |
| 461 | if (tc[tc_id].dominator_sensing_point == ALL_SENSING_POINTS) { |
| 462 | d_index = ALL_SENSING_POINTS; |
| 463 | } else if (tc[tc_id].dominator_sensing_point < tc[tc_id].num_sensor) { |
| 464 | d_index = tc[tc_id].dominator_sensing_point; |
| 465 | } else { |
| 466 | dev_err(dev, |
| 467 | "Error: LVTS%d, dominator_sensing_point= %d should smaller than num_sensor= %d\n", |
| 468 | tc_id, tc[tc_id].dominator_sensing_point, |
| 469 | tc[tc_id].num_sensor); |
| 470 | |
| 471 | dev_err(dev, |
| 472 | "Use the sensing point 0 as the dominated sensor\n"); |
| 473 | d_index = SENSING_POINT0; |
| 474 | } |
| 475 | |
| 476 | return d_index; |
| 477 | } |
| 478 | |
| 479 | static void disable_hw_reboot_interrupt(struct lvts_data *lvts_data, int tc_id) |
| 480 | { |
| 481 | unsigned int temp; |
| 482 | void __iomem *base; |
| 483 | |
| 484 | base = GET_BASE_ADDR(tc_id); |
| 485 | |
| 486 | /* LVTS thermal controller has two interrupts for thermal HW reboot |
| 487 | * One is for AP SW and the other is for RGU |
| 488 | * The interrupt of AP SW can turn off by a bit of a register, but |
| 489 | * the other for RGU cannot. |
| 490 | * To prevent rebooting device accidentally, we are going to add |
| 491 | * a huge offset to LVTS and make LVTS always report extremely low |
| 492 | * temperature. |
| 493 | */ |
| 494 | |
| 495 | /* After adding the huge offset 0x3FFF, LVTS alawys adds the |
| 496 | * offset to MSR_RAW. |
| 497 | * When MSR_RAW is larger, SW will convert lower temperature/ |
| 498 | */ |
| 499 | temp = readl(LVTSPROTCTL_0 + base); |
| 500 | writel(temp | 0x3FFF, LVTSPROTCTL_0 + base); |
| 501 | |
| 502 | /* Disable the interrupt of AP SW */ |
| 503 | temp = readl(LVTSMONINT_0 + base); |
| 504 | writel(temp & ~(STAGE3_INT_EN), LVTSMONINT_0 + base); |
| 505 | } |
| 506 | |
| 507 | static void enable_hw_reboot_interrupt(struct lvts_data *lvts_data, int tc_id) |
| 508 | { |
| 509 | unsigned int temp; |
| 510 | void __iomem *base; |
| 511 | |
| 512 | base = GET_BASE_ADDR(tc_id); |
| 513 | |
| 514 | /* Enable the interrupt of AP SW */ |
| 515 | temp = readl(LVTSMONINT_0 + base); |
| 516 | writel(temp | STAGE3_INT_EN, LVTSMONINT_0 + base); |
| 517 | /* Clear the offset */ |
| 518 | temp = readl(LVTSPROTCTL_0 + base); |
| 519 | writel(temp & ~PROTOFFSET, LVTSPROTCTL_0 + base); |
| 520 | } |
| 521 | |
| 522 | static void set_tc_hw_reboot_threshold(struct lvts_data *lvts_data, |
| 523 | int trip_point, int tc_id) |
| 524 | { |
| 525 | struct device *dev = lvts_data->dev; |
| 526 | unsigned int msr_raw, temp, config, d_index; |
| 527 | void __iomem *base; |
| 528 | |
| 529 | base = GET_BASE_ADDR(tc_id); |
| 530 | d_index = get_dominator_index(lvts_data, tc_id); |
| 531 | |
| 532 | dev_info(dev, "%s: LVTS%d, the dominator sensing point= %d\n", __func__, |
| 533 | tc_id, d_index); |
| 534 | |
| 535 | disable_hw_reboot_interrupt(lvts_data, tc_id); |
| 536 | |
| 537 | temp = readl(LVTSPROTCTL_0 + base); |
| 538 | if (d_index == ALL_SENSING_POINTS) { |
| 539 | /* Maximum of 4 sensing points */ |
| 540 | config = (0x1 << 16); |
| 541 | writel(config | temp, LVTSPROTCTL_0 + base); |
| 542 | } else { |
| 543 | /* Select protection sensor */ |
| 544 | config = ((d_index << 2) + 0x2) << 16; |
| 545 | writel(config | temp, LVTSPROTCTL_0 + base); |
| 546 | } |
| 547 | |
| 548 | msr_raw = lvts_temp_to_raw(&lvts_data->coeff, trip_point); |
| 549 | writel(msr_raw, LVTSPROTTC_0 + base); |
| 550 | |
| 551 | enable_hw_reboot_interrupt(lvts_data, tc_id); |
| 552 | } |
| 553 | |
| 554 | static void set_all_tc_hw_reboot(struct lvts_data *lvts_data) |
| 555 | { |
| 556 | struct tc_settings *tc = lvts_data->tc; |
| 557 | int i, trip_point; |
| 558 | |
| 559 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 560 | trip_point = tc[i].hw_reboot_trip_point; |
| 561 | |
| 562 | if (tc[i].num_sensor == 0) |
| 563 | continue; |
| 564 | |
| 565 | if (trip_point == DISABLE_THERMAL_HW_REBOOT) |
| 566 | continue; |
| 567 | |
| 568 | set_tc_hw_reboot_threshold(lvts_data, trip_point, i); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | static int lvts_init(struct lvts_data *lvts_data) |
| 573 | { |
| 574 | struct platform_ops *ops = &lvts_data->ops; |
| 575 | struct device *dev = lvts_data->dev; |
| 576 | int ret; |
| 577 | |
| 578 | ret = clk_prepare_enable(lvts_data->clk); |
| 579 | if (ret) { |
| 580 | dev_err(dev, |
| 581 | "Error: Failed to enable lvts controller clock: %d\n", |
| 582 | ret); |
| 583 | return ret; |
| 584 | } |
| 585 | |
| 586 | if (lvts_data->feature_bitmap & FEATURE_RESET) |
| 587 | lvts_reset(lvts_data); |
| 588 | |
| 589 | device_identification(lvts_data); |
| 590 | if (ops->device_enable_and_init) |
| 591 | ops->device_enable_and_init(lvts_data); |
| 592 | |
| 593 | if (IS_ENABLE(FEATURE_DEVICE_AUTO_RCK)) { |
| 594 | if (ops->device_enable_auto_rck) |
| 595 | ops->device_enable_auto_rck(lvts_data); |
| 596 | } else { |
| 597 | if (ops->device_read_count_rc_n) |
| 598 | ops->device_read_count_rc_n(lvts_data); |
| 599 | } |
| 600 | |
| 601 | if (ops->set_cal_data) |
| 602 | ops->set_cal_data(lvts_data); |
| 603 | |
| 604 | disable_all_sensing_points(lvts_data); |
| 605 | wait_all_tc_sensing_point_idle(lvts_data); |
| 606 | if (ops->init_controller) |
| 607 | ops->init_controller(lvts_data); |
| 608 | enable_all_sensing_points(lvts_data); |
| 609 | |
| 610 | set_all_tc_hw_reboot(lvts_data); |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
| 615 | static int prepare_calibration_data(struct lvts_data *lvts_data) |
| 616 | { |
| 617 | struct device *dev = lvts_data->dev; |
| 618 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 619 | struct platform_ops *ops = &lvts_data->ops; |
| 620 | int i, offset, size; |
| 621 | char buffer[512]; |
| 622 | |
| 623 | cal_data->count_r = |
| 624 | devm_kcalloc(dev, lvts_data->num_sensor, |
| 625 | sizeof(*cal_data->count_r), GFP_KERNEL); |
| 626 | if (!cal_data->count_r) |
| 627 | return -ENOMEM; |
| 628 | |
| 629 | cal_data->count_rc = |
| 630 | devm_kcalloc(dev, lvts_data->num_sensor, |
| 631 | sizeof(*cal_data->count_rc), GFP_KERNEL); |
| 632 | if (!cal_data->count_rc) |
| 633 | return -ENOMEM; |
| 634 | |
| 635 | if (ops->efuse_to_cal_data && !cal_data->use_fake_efuse) |
| 636 | ops->efuse_to_cal_data(lvts_data); |
| 637 | |
| 638 | if (cal_data->golden_temp == 0 || |
| 639 | cal_data->golden_temp > GOLDEN_TEMP_MAX) |
| 640 | cal_data->use_fake_efuse = 1; |
| 641 | |
| 642 | if (cal_data->use_fake_efuse) { |
| 643 | /* It means all efuse data are equal to 0 */ |
| 644 | dev_err(dev, |
| 645 | "[lvts_cal] This sample is not calibrated, fake !!\n"); |
| 646 | |
| 647 | cal_data->golden_temp = cal_data->default_golden_temp; |
| 648 | for (i = 0; i < lvts_data->num_sensor; i++) { |
| 649 | cal_data->count_r[i] = cal_data->default_count_r; |
| 650 | cal_data->count_rc[i] = cal_data->default_count_rc; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | lvts_data->coeff.golden_temp = cal_data->golden_temp; |
| 655 | |
| 656 | dev_info(dev, "[lvts_cal] golden_temp = %d\n", cal_data->golden_temp); |
| 657 | |
| 658 | size = sizeof(buffer); |
| 659 | offset = snprintf(buffer, size, "[lvts_cal] num:g_count:g_count_rc "); |
| 660 | for (i = 0; i < lvts_data->num_sensor; i++) |
| 661 | offset += |
| 662 | snprintf(buffer + offset, size - offset, "%d:%d:%d ", i, |
| 663 | cal_data->count_r[i], cal_data->count_rc[i]); |
| 664 | |
| 665 | buffer[offset] = '\0'; |
| 666 | dev_info(dev, "%s\n", buffer); |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | static int get_calibration_data(struct lvts_data *lvts_data) |
| 672 | { |
| 673 | struct device *dev = lvts_data->dev; |
| 674 | char cell_name[8]; |
| 675 | struct nvmem_cell *cell; |
| 676 | u32 *buf; |
| 677 | size_t len; |
| 678 | int i, j, index = 0; |
| 679 | |
| 680 | lvts_data->efuse = devm_kcalloc(dev, lvts_data->num_efuse_addr, |
| 681 | sizeof(*lvts_data->efuse), GFP_KERNEL); |
| 682 | if (!lvts_data->efuse) |
| 683 | return -ENOMEM; |
| 684 | |
| 685 | for (i = 0; i < lvts_data->num_efuse_block; i++) { |
| 686 | snprintf(cell_name, sizeof(cell_name), "e_data%d", i + 1); |
| 687 | cell = nvmem_cell_get(dev, cell_name); |
| 688 | if (IS_ERR(cell)) { |
| 689 | dev_err(dev, "Error: Failed to get nvmem cell %s\n", |
| 690 | cell_name); |
| 691 | return PTR_ERR(cell); |
| 692 | } |
| 693 | |
| 694 | buf = (u32 *)nvmem_cell_read(cell, &len); |
| 695 | nvmem_cell_put(cell); |
| 696 | |
| 697 | if (IS_ERR(buf)) |
| 698 | return PTR_ERR(buf); |
| 699 | |
| 700 | for (j = 0; j < (len / sizeof(u32)); j++) { |
| 701 | if (index >= lvts_data->num_efuse_addr) { |
| 702 | dev_err(dev, |
| 703 | "Array efuse is going to overflow"); |
| 704 | kfree(buf); |
| 705 | return -EINVAL; |
| 706 | } |
| 707 | |
| 708 | lvts_data->efuse[index] = buf[j]; |
| 709 | index++; |
| 710 | } |
| 711 | |
| 712 | kfree(buf); |
| 713 | } |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | static int of_update_lvts_data(struct lvts_data *lvts_data, |
| 719 | struct platform_device *pdev) |
| 720 | { |
| 721 | struct device *dev = lvts_data->dev; |
| 722 | struct power_domain *domain; |
| 723 | struct resource *res; |
| 724 | unsigned int i; |
| 725 | int ret; |
| 726 | |
| 727 | lvts_data->clk = devm_clk_get(dev, "lvts_clk"); |
| 728 | if (IS_ERR(lvts_data->clk)) |
| 729 | return PTR_ERR(lvts_data->clk); |
| 730 | |
| 731 | domain = devm_kcalloc(dev, lvts_data->num_domain, sizeof(*domain), |
| 732 | GFP_KERNEL); |
| 733 | if (!domain) |
| 734 | return -ENOMEM; |
| 735 | |
| 736 | for (i = 0; i < lvts_data->num_domain; i++) { |
| 737 | /* Get base address */ |
| 738 | res = platform_get_resource(pdev, IORESOURCE_MEM, i); |
| 739 | if (!res) { |
| 740 | dev_err(dev, "No IO resource, index %d\n", i); |
| 741 | return -ENXIO; |
| 742 | } |
| 743 | |
| 744 | domain[i].base = devm_ioremap_resource(dev, res); |
| 745 | if (IS_ERR(domain[i].base)) { |
| 746 | dev_err(dev, "Failed to remap io, index %d\n", i); |
| 747 | return PTR_ERR(domain[i].base); |
| 748 | } |
| 749 | |
| 750 | /* Get interrupt number */ |
| 751 | if (lvts_data->feature_bitmap & FEATURE_IRQ) { |
| 752 | res = platform_get_resource(pdev, IORESOURCE_IRQ, i); |
| 753 | if (!res) { |
| 754 | dev_err(dev, "No irq resource, index %d\n", i); |
| 755 | return -EINVAL; |
| 756 | } |
| 757 | domain[i].irq_num = res->start; |
| 758 | } |
| 759 | |
| 760 | /* Get reset control */ |
| 761 | if (lvts_data->feature_bitmap & FEATURE_RESET) { |
| 762 | domain[i].reset = |
| 763 | devm_reset_control_get_by_index(dev, i); |
| 764 | if (IS_ERR(domain[i].reset)) { |
| 765 | dev_err(dev, "Failed to get, index %d\n", i); |
| 766 | return PTR_ERR(domain[i].reset); |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | lvts_data->domain = domain; |
| 772 | |
| 773 | lvts_data->sen_data = |
| 774 | devm_kcalloc(dev, lvts_data->num_sensor, |
| 775 | sizeof(*lvts_data->sen_data), GFP_KERNEL); |
| 776 | if (!lvts_data->sen_data) |
| 777 | return -ENOMEM; |
| 778 | |
| 779 | ret = get_calibration_data(lvts_data); |
| 780 | if (ret) |
| 781 | lvts_data->cal_data.use_fake_efuse = 1; |
| 782 | ret = prepare_calibration_data(lvts_data); |
| 783 | if (ret) |
| 784 | return ret; |
| 785 | |
| 786 | return 0; |
| 787 | } |
| 788 | |
| 789 | static void lvts_device_close(struct lvts_data *lvts_data) |
| 790 | { |
| 791 | unsigned int i; |
| 792 | void __iomem *base; |
| 793 | |
| 794 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 795 | base = GET_BASE_ADDR(i); |
| 796 | lvts_write_device(lvts_data, RESET_ALL_DEVICES, i); |
| 797 | writel(DISABLE_LVTS_CTRL_CLK, LVTSCLKEN_0 + base); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | static void lvts_close(struct lvts_data *lvts_data) |
| 802 | { |
| 803 | disable_all_sensing_points(lvts_data); |
| 804 | wait_all_tc_sensing_point_idle(lvts_data); |
| 805 | lvts_device_close(lvts_data); |
| 806 | clk_disable_unprepare(lvts_data->clk); |
| 807 | } |
| 808 | |
| 809 | static void tc_irq_handler(struct lvts_data *lvts_data, int tc_id) |
| 810 | { |
| 811 | struct device *dev = lvts_data->dev; |
| 812 | unsigned int ret = 0; |
| 813 | void __iomem *base; |
| 814 | |
| 815 | base = GET_BASE_ADDR(tc_id); |
| 816 | |
| 817 | ret = readl(LVTSMONINTSTS_0 + base); |
| 818 | /* Write back to clear interrupt status */ |
| 819 | writel(ret, LVTSMONINTSTS_0 + base); |
| 820 | |
| 821 | dev_info( |
| 822 | dev, |
| 823 | "[Thermal IRQ] LVTS thermal controller %d, LVTSMONINTSTS=0x%08x\n", |
| 824 | tc_id, ret); |
| 825 | |
| 826 | if (ret & THERMAL_PROTECTION_STAGE_3) |
| 827 | dev_info( |
| 828 | dev, |
| 829 | "[Thermal IRQ]: Thermal protection stage 3 interrupt triggered\n"); |
| 830 | } |
| 831 | |
| 832 | static irqreturn_t irq_handler(int irq, void *dev_id) |
| 833 | { |
| 834 | struct lvts_data *lvts_data = (struct lvts_data *)dev_id; |
| 835 | struct device *dev = lvts_data->dev; |
| 836 | struct tc_settings *tc = lvts_data->tc; |
| 837 | unsigned int i, *irq_bitmap; |
| 838 | void __iomem *base; |
| 839 | |
| 840 | irq_bitmap = |
| 841 | kcalloc(lvts_data->num_domain, sizeof(*irq_bitmap), GFP_ATOMIC); |
| 842 | |
| 843 | if (!irq_bitmap) |
| 844 | return IRQ_NONE; |
| 845 | |
| 846 | for (i = 0; i < lvts_data->num_domain; i++) { |
| 847 | base = lvts_data->domain[i].base; |
| 848 | irq_bitmap[i] = readl(THERMINTST + base); |
| 849 | dev_info(dev, "%s : THERMINTST = 0x%x\n", __func__, |
| 850 | irq_bitmap[i]); |
| 851 | } |
| 852 | |
| 853 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 854 | if ((irq_bitmap[tc[i].domain_index] & tc[i].irq_bit) == 0) |
| 855 | tc_irq_handler(lvts_data, i); |
| 856 | } |
| 857 | |
| 858 | kfree(irq_bitmap); |
| 859 | |
| 860 | return IRQ_HANDLED; |
| 861 | } |
| 862 | |
| 863 | static int lvts_register_irq_handler(struct lvts_data *lvts_data) |
| 864 | { |
| 865 | struct device *dev = lvts_data->dev; |
| 866 | unsigned int i; |
| 867 | int ret; |
| 868 | |
| 869 | for (i = 0; i < lvts_data->num_domain; i++) { |
| 870 | ret = devm_request_irq(dev, lvts_data->domain[i].irq_num, |
| 871 | irq_handler, IRQF_TRIGGER_HIGH, |
| 872 | "mtk_lvts", lvts_data); |
| 873 | |
| 874 | if (ret) { |
| 875 | dev_err(dev, |
| 876 | "Failed to register LVTS IRQ, ret %d, domain %d irq_num %d\n", |
| 877 | ret, i, lvts_data->domain[i].irq_num); |
| 878 | lvts_close(lvts_data); |
| 879 | return ret; |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int lvts_register_thermal_zones(struct lvts_data *lvts_data) |
| 887 | { |
| 888 | struct device *dev = lvts_data->dev; |
| 889 | struct thermal_zone_device *tzdev; |
| 890 | struct soc_temp_tz *lvts_tz; |
| 891 | int i, ret; |
| 892 | |
| 893 | for (i = 0; i < lvts_data->num_sensor + 1; i++) { |
| 894 | lvts_tz = devm_kzalloc(dev, sizeof(*lvts_tz), GFP_KERNEL); |
| 895 | if (!lvts_tz) { |
| 896 | lvts_close(lvts_data); |
| 897 | return -ENOMEM; |
| 898 | } |
| 899 | |
| 900 | lvts_tz->id = i; |
| 901 | lvts_tz->lvts_data = lvts_data; |
| 902 | |
| 903 | tzdev = devm_thermal_zone_of_sensor_register( |
| 904 | dev, lvts_tz->id, lvts_tz, &soc_temp_lvts_ops); |
| 905 | |
| 906 | if (IS_ERR(tzdev)) { |
| 907 | if (lvts_tz->id != 0) |
| 908 | return 0; |
| 909 | |
| 910 | ret = PTR_ERR(tzdev); |
| 911 | lvts_close(lvts_data); |
| 912 | return ret; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | static int lvts_probe(struct platform_device *pdev) |
| 920 | { |
| 921 | struct device *dev = &pdev->dev; |
| 922 | struct lvts_data *lvts_data; |
| 923 | int ret; |
| 924 | |
| 925 | lvts_data = (struct lvts_data *)of_device_get_match_data(dev); |
| 926 | |
| 927 | if (!lvts_data) { |
| 928 | dev_err(dev, "Error: Failed to get lvts platform data\n"); |
| 929 | return -ENODATA; |
| 930 | } |
| 931 | |
| 932 | lvts_data->dev = &pdev->dev; |
| 933 | |
| 934 | ret = of_update_lvts_data(lvts_data, pdev); |
| 935 | if (ret) |
| 936 | return ret; |
| 937 | |
| 938 | platform_set_drvdata(pdev, lvts_data); |
| 939 | |
| 940 | ret = lvts_init(lvts_data); |
| 941 | if (ret) |
| 942 | return ret; |
| 943 | |
| 944 | if (lvts_data->feature_bitmap & FEATURE_IRQ) { |
| 945 | ret = lvts_register_irq_handler(lvts_data); |
| 946 | if (ret) |
| 947 | return ret; |
| 948 | } |
| 949 | |
| 950 | ret = lvts_register_thermal_zones(lvts_data); |
| 951 | if (ret) |
| 952 | return ret; |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | static int lvts_remove(struct platform_device *pdev) |
| 958 | { |
| 959 | struct lvts_data *lvts_data; |
| 960 | |
| 961 | lvts_data = (struct lvts_data *)platform_get_drvdata(pdev); |
| 962 | |
| 963 | lvts_close(lvts_data); |
| 964 | |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | static int lvts_suspend(struct platform_device *pdev, pm_message_t state) |
| 969 | { |
| 970 | struct lvts_data *lvts_data; |
| 971 | |
| 972 | lvts_data = (struct lvts_data *)platform_get_drvdata(pdev); |
| 973 | |
| 974 | lvts_close(lvts_data); |
| 975 | |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | static int lvts_resume(struct platform_device *pdev) |
| 980 | { |
| 981 | int ret; |
| 982 | struct lvts_data *lvts_data; |
| 983 | |
| 984 | lvts_data = (struct lvts_data *)platform_get_drvdata(pdev); |
| 985 | |
| 986 | ret = lvts_init(lvts_data); |
| 987 | if (ret) |
| 988 | return ret; |
| 989 | |
| 990 | return 0; |
| 991 | } |
| 992 | |
| 993 | /* |
| 994 | * LVTS v4 common code |
| 995 | */ |
| 996 | |
| 997 | static void device_enable_and_init_v4(struct lvts_data *lvts_data) |
| 998 | { |
| 999 | unsigned int i; |
| 1000 | |
| 1001 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 1002 | lvts_write_device(lvts_data, STOP_COUNTING_V4, i); |
| 1003 | lvts_write_device(lvts_data, SET_RG_TSFM_LPDLY_V4, i); |
| 1004 | lvts_write_device(lvts_data, SET_COUNTING_WINDOW_20US1_V4, i); |
| 1005 | lvts_write_device(lvts_data, SET_COUNTING_WINDOW_20US2_V4, i); |
| 1006 | lvts_write_device(lvts_data, TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V4, |
| 1007 | i); |
| 1008 | lvts_write_device(lvts_data, TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V4, |
| 1009 | i); |
| 1010 | lvts_write_device(lvts_data, SET_TS_RSV_V4, i); |
| 1011 | lvts_write_device(lvts_data, SET_TS_EN_V4, i); |
| 1012 | lvts_write_device(lvts_data, TOGGLE_RG_TSV2F_VCO_RST1_V4, i); |
| 1013 | lvts_write_device(lvts_data, TOGGLE_RG_TSV2F_VCO_RST2_V4, i); |
| 1014 | } |
| 1015 | |
| 1016 | lvts_data->counting_window_us = 20; |
| 1017 | } |
| 1018 | |
| 1019 | static void device_enable_auto_rck_v4(struct lvts_data *lvts_data) |
| 1020 | { |
| 1021 | unsigned int i; |
| 1022 | |
| 1023 | for (i = 0; i < lvts_data->num_tc; i++) |
| 1024 | lvts_write_device(lvts_data, SET_LVTS_AUTO_RCK_V4, i); |
| 1025 | } |
| 1026 | |
| 1027 | static int device_read_count_rc_n_v4(struct lvts_data *lvts_data) |
| 1028 | { |
| 1029 | /* Resistor-Capacitor Calibration */ |
| 1030 | /* count_RC_N: count RC now */ |
| 1031 | struct device *dev = lvts_data->dev; |
| 1032 | struct tc_settings *tc = lvts_data->tc; |
| 1033 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1034 | unsigned int offset, size, s_index, data; |
| 1035 | void __iomem *base; |
| 1036 | int ret, i, j; |
| 1037 | char buffer[512]; |
| 1038 | |
| 1039 | cal_data->count_rc_now = |
| 1040 | devm_kcalloc(dev, lvts_data->num_sensor, |
| 1041 | sizeof(*cal_data->count_rc_now), GFP_KERNEL); |
| 1042 | if (!cal_data->count_rc_now) |
| 1043 | return -ENOMEM; |
| 1044 | |
| 1045 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 1046 | base = GET_BASE_ADDR(i); |
| 1047 | for (j = 0; j < tc[i].num_sensor; j++) { |
| 1048 | s_index = tc[i].sensor_map[j]; |
| 1049 | |
| 1050 | lvts_write_device(lvts_data, SELECT_SENSOR_RCK_V4(j), |
| 1051 | i); |
| 1052 | lvts_write_device(lvts_data, SET_DEVICE_SINGLE_MODE_V4, |
| 1053 | i); |
| 1054 | usleep_range(10, 20); |
| 1055 | |
| 1056 | lvts_write_device(lvts_data, KICK_OFF_RCK_COUNTING_V4, |
| 1057 | i); |
| 1058 | usleep_range(30, 40); |
| 1059 | |
| 1060 | ret = readl_poll_timeout( |
| 1061 | LVTS_CONFIG_0 + base, data, |
| 1062 | !(data & DEVICE_SENSING_STATUS), 2, 200); |
| 1063 | |
| 1064 | data = lvts_read_device(lvts_data, 0x00, i); |
| 1065 | |
| 1066 | cal_data->count_rc_now[s_index] = |
| 1067 | (data & GENMASK(23, 0)); |
| 1068 | } |
| 1069 | |
| 1070 | /* Recover Setting for Normal Access on |
| 1071 | * temperature fetch |
| 1072 | */ |
| 1073 | lvts_write_device(lvts_data, SET_SENSOR_NO_RCK_V4, i); |
| 1074 | lvts_write_device(lvts_data, |
| 1075 | SET_DEVICE_LOW_POWER_SINGLE_MODE_V4, i); |
| 1076 | } |
| 1077 | |
| 1078 | size = sizeof(buffer); |
| 1079 | offset = snprintf(buffer, size, "[COUNT_RC_NOW] "); |
| 1080 | for (i = 0; i < lvts_data->num_sensor; i++) |
| 1081 | offset += snprintf(buffer + offset, size - offset, "%d:%d ", i, |
| 1082 | cal_data->count_rc_now[i]); |
| 1083 | |
| 1084 | buffer[offset] = '\0'; |
| 1085 | dev_info(dev, "%s\n", buffer); |
| 1086 | |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static void set_calibration_data_v4(struct lvts_data *lvts_data) |
| 1091 | { |
| 1092 | struct tc_settings *tc = lvts_data->tc; |
| 1093 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1094 | unsigned int i, j, s_index, e_data; |
| 1095 | void __iomem *base; |
| 1096 | |
| 1097 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 1098 | base = GET_BASE_ADDR(i); |
| 1099 | |
| 1100 | for (j = 0; j < tc[i].num_sensor; j++) { |
| 1101 | s_index = tc[i].sensor_map[j]; |
| 1102 | if (IS_ENABLE(FEATURE_DEVICE_AUTO_RCK)) |
| 1103 | e_data = cal_data->count_r[s_index]; |
| 1104 | else |
| 1105 | e_data = (((unsigned long long)cal_data |
| 1106 | ->count_rc_now[s_index]) * |
| 1107 | cal_data->count_r[s_index]) >> |
| 1108 | 14; |
| 1109 | |
| 1110 | writel(e_data, LVTSEDATA00_0 + base + 0x4 * j); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | static void init_controller_v4(struct lvts_data *lvts_data) |
| 1116 | { |
| 1117 | struct device *dev = lvts_data->dev; |
| 1118 | unsigned int i; |
| 1119 | void __iomem *base; |
| 1120 | |
| 1121 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 1122 | base = GET_BASE_ADDR(i); |
| 1123 | |
| 1124 | lvts_write_device(lvts_data, |
| 1125 | SET_DEVICE_LOW_POWER_SINGLE_MODE_V4, i); |
| 1126 | |
| 1127 | writel(SET_SENSOR_INDEX, LVTSTSSEL_0 + base); |
| 1128 | writel(SET_CALC_SCALE_RULES, LVTSCALSCALE_0 + base); |
| 1129 | |
| 1130 | set_polling_speed(lvts_data, i); |
| 1131 | set_hw_filter(lvts_data, i); |
| 1132 | |
| 1133 | dev_info(dev, |
| 1134 | "lvts%d: read all %d sensors in %d us, one in %d us\n", |
| 1135 | i, GET_TC_SENSOR_NUM(i), GROUP_LATENCY_US(i), |
| 1136 | SENSOR_LATENCY_US(i)); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | /* |
| 1141 | * LVTS v5 common code |
| 1142 | */ |
| 1143 | static void device_enable_and_init_v5(struct lvts_data *lvts_data) |
| 1144 | { |
| 1145 | unsigned int i; |
| 1146 | |
| 1147 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 1148 | lvts_write_device(lvts_data, STOP_COUNTING_V5, i); |
| 1149 | lvts_write_device(lvts_data, SET_COUNTING_WINDOW_20US2_V5, i); |
| 1150 | lvts_write_device(lvts_data, SET_COUNTING_WINDOW_20US1_V5, i); |
| 1151 | lvts_write_device(lvts_data, SET_RG_TSFM_LPDLY_V5, i); |
| 1152 | lvts_write_device(lvts_data, TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V5, |
| 1153 | i); |
| 1154 | lvts_write_device(lvts_data, TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V5, |
| 1155 | i); |
| 1156 | lvts_write_device(lvts_data, SET_TS_RSV_V5, i); |
| 1157 | lvts_write_device(lvts_data, SET_TS_EN_V5, i); |
developer | a97210b | 2023-04-25 14:55:53 +0800 | [diff] [blame^] | 1158 | lvts_write_device(lvts_data, SET_TS_V2VF_RSV_V5, i); |
developer | 2cdaeb1 | 2022-10-04 20:25:05 +0800 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | lvts_data->counting_window_us = 20; |
| 1162 | } |
| 1163 | |
| 1164 | static int device_read_count_rc_n_v5(struct lvts_data *lvts_data) |
| 1165 | { |
| 1166 | /* Resistor-Capacitor Calibration */ |
| 1167 | /* count_RC_N: count RC now */ |
| 1168 | struct device *dev = lvts_data->dev; |
| 1169 | struct tc_settings *tc = lvts_data->tc; |
| 1170 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1171 | unsigned int offset, size, s_index, data; |
| 1172 | void __iomem *base; |
| 1173 | int ret, i, j; |
| 1174 | char buffer[512]; |
| 1175 | |
| 1176 | cal_data->count_rc_now = |
| 1177 | devm_kcalloc(dev, lvts_data->num_sensor, |
| 1178 | sizeof(*cal_data->count_rc_now), GFP_KERNEL); |
| 1179 | if (!cal_data->count_rc_now) |
| 1180 | return -ENOMEM; |
| 1181 | |
| 1182 | for (i = 0; i < lvts_data->num_tc; i++) { |
| 1183 | base = GET_BASE_ADDR(i); |
| 1184 | lvts_write_device(lvts_data, SET_MANUAL_RCK_V5, i); |
| 1185 | |
| 1186 | for (j = 0; j < tc[i].num_sensor; j++) { |
| 1187 | s_index = tc[i].sensor_map[j]; |
| 1188 | |
| 1189 | lvts_write_device(lvts_data, SELECT_SENSOR_RCK_V5(j), |
| 1190 | i); |
| 1191 | lvts_write_device(lvts_data, SET_DEVICE_SINGLE_MODE_V5, |
| 1192 | i); |
| 1193 | lvts_write_device(lvts_data, |
| 1194 | SET_COUNTING_WINDOW_20US2_V5, i); |
| 1195 | lvts_write_device(lvts_data, |
| 1196 | SET_COUNTING_WINDOW_20US1_V5, i); |
| 1197 | lvts_write_device(lvts_data, KICK_OFF_RCK_COUNTING_V5, |
| 1198 | i); |
| 1199 | udelay(40); |
| 1200 | |
| 1201 | ret = readl_poll_timeout( |
| 1202 | LVTS_CONFIG_0 + base, data, |
| 1203 | !(data & DEVICE_SENSING_STATUS), 2, 200); |
| 1204 | if (ret) |
| 1205 | dev_err(dev, |
| 1206 | "Error: LVTS %d DEVICE_SENSING_STATUS didn't ready\n", |
| 1207 | i); |
| 1208 | |
| 1209 | data = lvts_read_device(lvts_data, 0x00, i); |
| 1210 | |
| 1211 | cal_data->count_rc_now[s_index] = |
| 1212 | (data & GENMASK(23, 0)); |
| 1213 | |
| 1214 | /* Recover Setting for Normal Access on |
| 1215 | * temperature fetch |
| 1216 | */ |
| 1217 | lvts_write_device(lvts_data, SET_SENSOR_NO_RCK_V5(j), |
| 1218 | i); |
| 1219 | lvts_write_device(lvts_data, |
| 1220 | SET_DEVICE_LOW_POWER_SINGLE_MODE_V5, |
| 1221 | i); |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | size = sizeof(buffer); |
| 1226 | offset = snprintf(buffer, size, "[COUNT_RC_NOW] "); |
| 1227 | for (i = 0; i < lvts_data->num_sensor; i++) |
| 1228 | offset += snprintf(buffer + offset, size - offset, "%d:%d ", i, |
| 1229 | cal_data->count_rc_now[i]); |
| 1230 | |
| 1231 | buffer[offset] = '\0'; |
| 1232 | dev_info(dev, "%s\n", buffer); |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | /* |
| 1238 | * LVTS MT6873 |
| 1239 | */ |
| 1240 | |
| 1241 | #define MT6873_NUM_LVTS (ARRAY_SIZE(mt6873_tc_settings)) |
| 1242 | |
| 1243 | enum mt6873_lvts_domain { |
| 1244 | MT6873_AP_DOMAIN, |
| 1245 | MT6873_MCU_DOMAIN, |
| 1246 | MT6873_NUM_DOMAIN |
| 1247 | }; |
| 1248 | |
| 1249 | enum mt6873_lvts_sensor_enum { |
| 1250 | MT6873_TS1_0, |
| 1251 | MT6873_TS1_1, |
| 1252 | MT6873_TS2_0, |
| 1253 | MT6873_TS2_1, |
| 1254 | MT6873_TS3_0, |
| 1255 | MT6873_TS3_1, |
| 1256 | MT6873_TS3_2, |
| 1257 | MT6873_TS3_3, |
| 1258 | MT6873_TS4_0, |
| 1259 | MT6873_TS4_1, |
| 1260 | MT6873_TS5_0, |
| 1261 | MT6873_TS5_1, |
| 1262 | MT6873_TS6_0, |
| 1263 | MT6873_TS6_1, |
| 1264 | MT6873_TS7_0, |
| 1265 | MT6873_TS7_1, |
| 1266 | MT6873_TS7_2, |
| 1267 | MT6873_NUM_TS |
| 1268 | }; |
| 1269 | |
| 1270 | static void mt6873_efuse_to_cal_data(struct lvts_data *lvts_data) |
| 1271 | { |
| 1272 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1273 | |
| 1274 | cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, 31, 24); |
| 1275 | cal_data->count_r[MT6873_TS1_0] = GET_CAL_DATA_BITMASK(1, 23, 0); |
| 1276 | cal_data->count_r[MT6873_TS1_1] = GET_CAL_DATA_BITMASK(2, 23, 0); |
| 1277 | cal_data->count_r[MT6873_TS2_0] = GET_CAL_DATA_BITMASK(3, 23, 0); |
| 1278 | cal_data->count_r[MT6873_TS2_1] = GET_CAL_DATA_BITMASK(4, 23, 0); |
| 1279 | cal_data->count_r[MT6873_TS3_0] = GET_CAL_DATA_BITMASK(5, 23, 0); |
| 1280 | cal_data->count_r[MT6873_TS3_1] = GET_CAL_DATA_BITMASK(6, 23, 0); |
| 1281 | cal_data->count_r[MT6873_TS3_2] = GET_CAL_DATA_BITMASK(7, 23, 0); |
| 1282 | cal_data->count_r[MT6873_TS3_3] = GET_CAL_DATA_BITMASK(8, 23, 0); |
| 1283 | cal_data->count_r[MT6873_TS4_0] = GET_CAL_DATA_BITMASK(9, 23, 0); |
| 1284 | cal_data->count_r[MT6873_TS4_1] = GET_CAL_DATA_BITMASK(10, 23, 0); |
| 1285 | cal_data->count_r[MT6873_TS5_0] = GET_CAL_DATA_BITMASK(11, 23, 0); |
| 1286 | cal_data->count_r[MT6873_TS5_1] = GET_CAL_DATA_BITMASK(12, 23, 0); |
| 1287 | cal_data->count_r[MT6873_TS6_0] = GET_CAL_DATA_BITMASK(13, 23, 0); |
| 1288 | cal_data->count_r[MT6873_TS6_1] = GET_CAL_DATA_BITMASK(14, 23, 0); |
| 1289 | cal_data->count_r[MT6873_TS7_0] = GET_CAL_DATA_BITMASK(15, 23, 0); |
| 1290 | cal_data->count_r[MT6873_TS7_1] = GET_CAL_DATA_BITMASK(16, 23, 0); |
| 1291 | cal_data->count_r[MT6873_TS7_2] = GET_CAL_DATA_BITMASK(17, 23, 0); |
| 1292 | |
| 1293 | cal_data->count_rc[MT6873_TS1_0] = GET_CAL_DATA_BITMASK(21, 23, 0); |
| 1294 | |
| 1295 | cal_data->count_rc[MT6873_TS2_0] = |
| 1296 | (GET_CAL_DATA_BITMASK(1, 31, 24) << 16) + |
| 1297 | (GET_CAL_DATA_BITMASK(2, 31, 24) << 8) + |
| 1298 | GET_CAL_DATA_BITMASK(3, 31, 24); |
| 1299 | |
| 1300 | cal_data->count_rc[MT6873_TS3_0] = |
| 1301 | (GET_CAL_DATA_BITMASK(4, 31, 24) << 16) + |
| 1302 | (GET_CAL_DATA_BITMASK(5, 31, 24) << 8) + |
| 1303 | GET_CAL_DATA_BITMASK(6, 31, 24); |
| 1304 | |
| 1305 | cal_data->count_rc[MT6873_TS4_0] = |
| 1306 | (GET_CAL_DATA_BITMASK(7, 31, 24) << 16) + |
| 1307 | (GET_CAL_DATA_BITMASK(8, 31, 24) << 8) + |
| 1308 | GET_CAL_DATA_BITMASK(9, 31, 24); |
| 1309 | |
| 1310 | cal_data->count_rc[MT6873_TS5_0] = |
| 1311 | (GET_CAL_DATA_BITMASK(10, 31, 24) << 16) + |
| 1312 | (GET_CAL_DATA_BITMASK(11, 31, 24) << 8) + |
| 1313 | GET_CAL_DATA_BITMASK(12, 31, 24); |
| 1314 | |
| 1315 | cal_data->count_rc[MT6873_TS6_0] = |
| 1316 | (GET_CAL_DATA_BITMASK(13, 31, 24) << 16) + |
| 1317 | (GET_CAL_DATA_BITMASK(14, 31, 24) << 8) + |
| 1318 | GET_CAL_DATA_BITMASK(15, 31, 24); |
| 1319 | |
| 1320 | cal_data->count_rc[MT6873_TS7_0] = |
| 1321 | (GET_CAL_DATA_BITMASK(16, 31, 24) << 16) + |
| 1322 | (GET_CAL_DATA_BITMASK(17, 31, 24) << 8) + |
| 1323 | GET_CAL_DATA_BITMASK(18, 31, 24); |
| 1324 | } |
| 1325 | |
| 1326 | static struct tc_settings mt6873_tc_settings[] = { |
| 1327 | [0] = { |
| 1328 | .domain_index = MT6873_MCU_DOMAIN, |
| 1329 | .addr_offset = 0x0, |
| 1330 | .num_sensor = 2, |
| 1331 | .sensor_map = {MT6873_TS1_0, MT6873_TS1_1}, |
| 1332 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1333 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1334 | .dominator_sensing_point = SENSING_POINT1, |
| 1335 | .hw_reboot_trip_point = 117000, |
| 1336 | .irq_bit = BIT(3), |
| 1337 | }, |
| 1338 | [1] = { |
| 1339 | .domain_index = MT6873_MCU_DOMAIN, |
| 1340 | .addr_offset = 0x100, |
| 1341 | .num_sensor = 2, |
| 1342 | .sensor_map = {MT6873_TS2_0, MT6873_TS2_1}, |
| 1343 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1344 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1345 | .dominator_sensing_point = SENSING_POINT0, |
| 1346 | .hw_reboot_trip_point = 117000, |
| 1347 | .irq_bit = BIT(4), |
| 1348 | }, |
| 1349 | [2] = { |
| 1350 | .domain_index = MT6873_MCU_DOMAIN, |
| 1351 | .addr_offset = 0x200, |
| 1352 | .num_sensor = 4, |
| 1353 | .sensor_map = {MT6873_TS3_0, MT6873_TS3_1, MT6873_TS3_2, |
| 1354 | MT6873_TS3_3}, |
| 1355 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1356 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1357 | .dominator_sensing_point = SENSING_POINT0, |
| 1358 | .hw_reboot_trip_point = 117000, |
| 1359 | .irq_bit = BIT(5), |
| 1360 | }, |
| 1361 | [3] = { |
| 1362 | .domain_index = MT6873_AP_DOMAIN, |
| 1363 | .addr_offset = 0x0, |
| 1364 | .num_sensor = 2, |
| 1365 | .sensor_map = {MT6873_TS4_0, MT6873_TS4_1}, |
| 1366 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1367 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1368 | .dominator_sensing_point = SENSING_POINT0, |
| 1369 | .hw_reboot_trip_point = 117000, |
| 1370 | .irq_bit = BIT(3), |
| 1371 | }, |
| 1372 | [4] = { |
| 1373 | .domain_index = MT6873_AP_DOMAIN, |
| 1374 | .addr_offset = 0x100, |
| 1375 | .num_sensor = 2, |
| 1376 | .sensor_map = {MT6873_TS5_0, MT6873_TS5_1}, |
| 1377 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1378 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1379 | .dominator_sensing_point = SENSING_POINT1, |
| 1380 | .hw_reboot_trip_point = 117000, |
| 1381 | .irq_bit = BIT(4), |
| 1382 | }, |
| 1383 | [5] = { |
| 1384 | .domain_index = MT6873_AP_DOMAIN, |
| 1385 | .addr_offset = 0x200, |
| 1386 | .num_sensor = 2, |
| 1387 | .sensor_map = {MT6873_TS6_0, MT6873_TS6_1}, |
| 1388 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1389 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1390 | .dominator_sensing_point = SENSING_POINT1, |
| 1391 | .hw_reboot_trip_point = 117000, |
| 1392 | .irq_bit = BIT(5), |
| 1393 | }, |
| 1394 | [6] = { |
| 1395 | .domain_index = MT6873_AP_DOMAIN, |
| 1396 | .addr_offset = 0x300, |
| 1397 | .num_sensor = 3, |
| 1398 | .sensor_map = {MT6873_TS7_0, MT6873_TS7_1, MT6873_TS7_2}, |
| 1399 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1400 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1401 | .dominator_sensing_point = SENSING_POINT2, |
| 1402 | .hw_reboot_trip_point = 117000, |
| 1403 | .irq_bit = BIT(6), |
| 1404 | } |
| 1405 | }; |
| 1406 | |
| 1407 | static struct lvts_data mt6873_lvts_data = { |
| 1408 | .num_domain = MT6873_NUM_DOMAIN, |
| 1409 | .num_tc = MT6873_NUM_LVTS, |
| 1410 | .tc = mt6873_tc_settings, |
| 1411 | .num_sensor = MT6873_NUM_TS, |
| 1412 | .ops = { |
| 1413 | .efuse_to_cal_data = mt6873_efuse_to_cal_data, |
| 1414 | .device_enable_and_init = device_enable_and_init_v4, |
| 1415 | .device_enable_auto_rck = device_enable_auto_rck_v4, |
| 1416 | .device_read_count_rc_n = device_read_count_rc_n_v4, |
| 1417 | .set_cal_data = set_calibration_data_v4, |
| 1418 | .init_controller = init_controller_v4, |
| 1419 | }, |
| 1420 | .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, |
| 1421 | .num_efuse_addr = 22, |
| 1422 | .num_efuse_block = 1, |
| 1423 | .cal_data = { |
| 1424 | .default_golden_temp = 50, |
| 1425 | .default_count_r = 35000, |
| 1426 | .default_count_rc = 2750, |
| 1427 | }, |
| 1428 | .coeff = { |
| 1429 | .a = -250460, |
| 1430 | .b = 250460, |
| 1431 | }, |
| 1432 | }; |
| 1433 | |
| 1434 | /* |
| 1435 | * LVTS MT7988 |
| 1436 | */ |
| 1437 | |
| 1438 | #define MT7988_NUM_LVTS (ARRAY_SIZE(mt7988_tc_settings)) |
| 1439 | |
| 1440 | enum mt7988_lvts_domain { MT7988_AP_DOMAIN, MT7988_NUM_DOMAIN }; |
| 1441 | |
| 1442 | enum mt7988_lvts_sensor_enum { |
| 1443 | MT7988_TS2_0, |
| 1444 | MT7988_TS2_1, |
| 1445 | MT7988_TS2_2, |
| 1446 | MT7988_TS2_3, |
| 1447 | MT7988_TS3_0, |
| 1448 | MT7988_TS3_1, |
| 1449 | MT7988_TS3_2, |
| 1450 | MT7988_TS3_3, |
| 1451 | MT7988_NUM_TS |
| 1452 | }; |
| 1453 | |
| 1454 | static void mt7988_efuse_to_cal_data(struct lvts_data *lvts_data) |
| 1455 | { |
| 1456 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1457 | |
| 1458 | cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, 31, 24); |
| 1459 | |
| 1460 | cal_data->count_r[MT7988_TS2_0] = GET_CAL_DATA_BITMASK(0, 23, 0); |
| 1461 | cal_data->count_r[MT7988_TS2_1] = GET_CAL_DATA_BITMASK(1, 23, 0); |
| 1462 | cal_data->count_r[MT7988_TS2_2] = GET_CAL_DATA_BITMASK(2, 23, 0); |
| 1463 | cal_data->count_r[MT7988_TS2_3] = GET_CAL_DATA_BITMASK(3, 23, 0); |
| 1464 | cal_data->count_rc[MT7988_TS2_0] = GET_CAL_DATA_BITMASK(4, 23, 0); |
| 1465 | |
| 1466 | cal_data->count_r[MT7988_TS3_0] = GET_CAL_DATA_BITMASK(5, 23, 0); |
| 1467 | cal_data->count_r[MT7988_TS3_1] = GET_CAL_DATA_BITMASK(6, 23, 0); |
| 1468 | cal_data->count_r[MT7988_TS3_2] = GET_CAL_DATA_BITMASK(7, 23, 0); |
| 1469 | cal_data->count_r[MT7988_TS3_3] = GET_CAL_DATA_BITMASK(8, 23, 0); |
| 1470 | cal_data->count_rc[MT7988_TS3_0] = GET_CAL_DATA_BITMASK(9, 23, 0); |
| 1471 | } |
| 1472 | |
| 1473 | static struct tc_settings mt7988_tc_settings[] = { |
| 1474 | [0] = { |
| 1475 | .domain_index = MT7988_AP_DOMAIN, |
| 1476 | .addr_offset = 0x0, |
| 1477 | .num_sensor = 4, |
| 1478 | .sensor_map = {MT7988_TS2_0, MT7988_TS2_1, MT7988_TS2_2, |
| 1479 | MT7988_TS2_3}, |
| 1480 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1481 | .hw_filter = LVTS_FILTER_16_OF_18, |
| 1482 | .dominator_sensing_point = SENSING_POINT0, |
| 1483 | .hw_reboot_trip_point = 117000, |
| 1484 | .irq_bit = BIT(4), |
| 1485 | }, |
| 1486 | [1] = { |
| 1487 | .domain_index = MT7988_AP_DOMAIN, |
| 1488 | .addr_offset = 0x100, |
| 1489 | .num_sensor = 4, |
| 1490 | .sensor_map = {MT7988_TS3_0, MT7988_TS3_1, MT7988_TS3_2, |
| 1491 | MT7988_TS3_3}, |
| 1492 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1493 | .hw_filter = LVTS_FILTER_16_OF_18, |
| 1494 | .dominator_sensing_point = SENSING_POINT0, |
| 1495 | .hw_reboot_trip_point = 117000, |
| 1496 | .irq_bit = BIT(5), |
| 1497 | } |
| 1498 | |
| 1499 | }; |
| 1500 | |
| 1501 | static struct lvts_data mt7988_lvts_data = { |
| 1502 | .num_domain = MT7988_NUM_DOMAIN, |
| 1503 | .num_tc = MT7988_NUM_LVTS, |
| 1504 | .tc = mt7988_tc_settings, |
| 1505 | .num_sensor = MT7988_NUM_TS, |
| 1506 | .ops = { |
| 1507 | .efuse_to_cal_data = mt7988_efuse_to_cal_data, |
| 1508 | .device_enable_and_init = device_enable_and_init_v5, |
| 1509 | .device_enable_auto_rck = device_enable_auto_rck_v4, |
| 1510 | .device_read_count_rc_n = device_read_count_rc_n_v5, |
| 1511 | .set_cal_data = set_calibration_data_v4, |
| 1512 | .init_controller = init_controller_v4, |
| 1513 | }, |
| 1514 | .feature_bitmap = 0, |
| 1515 | .num_efuse_addr = 10, |
| 1516 | .num_efuse_block = 1, |
| 1517 | .cal_data = { |
| 1518 | .default_golden_temp = 60, |
| 1519 | .default_count_r = 19380, |
| 1520 | .default_count_rc = 5330, |
| 1521 | }, |
| 1522 | .coeff = { |
| 1523 | .a = -204650, |
| 1524 | .b = 204650, |
| 1525 | }, |
| 1526 | }; |
| 1527 | |
| 1528 | /* |
| 1529 | * LVTS MT8195 |
| 1530 | */ |
| 1531 | |
| 1532 | #define MT8195_NUM_LVTS (ARRAY_SIZE(mt8195_tc_settings)) |
| 1533 | |
| 1534 | enum mt8195_lvts_domain { |
| 1535 | MT8195_AP_DOMAIN, |
| 1536 | MT8195_MCU_DOMAIN, |
| 1537 | MT8195_NUM_DOMAIN |
| 1538 | }; |
| 1539 | |
| 1540 | enum mt8195_lvts_sensor_enum { |
| 1541 | MT8195_TS1_0, |
| 1542 | MT8195_TS1_1, |
| 1543 | MT8195_TS2_0, |
| 1544 | MT8195_TS2_1, |
| 1545 | MT8195_TS3_0, |
| 1546 | MT8195_TS3_1, |
| 1547 | MT8195_TS3_2, |
| 1548 | MT8195_TS3_3, |
| 1549 | MT8195_TS4_0, |
| 1550 | MT8195_TS4_1, |
| 1551 | MT8195_TS5_0, |
| 1552 | MT8195_TS5_1, |
| 1553 | MT8195_TS6_0, |
| 1554 | MT8195_TS6_1, |
| 1555 | MT8195_TS6_2, |
| 1556 | MT8195_TS7_0, |
| 1557 | MT8195_TS7_1, |
| 1558 | MT8195_NUM_TS |
| 1559 | }; |
| 1560 | |
| 1561 | static void mt8195_efuse_to_cal_data(struct lvts_data *lvts_data) |
| 1562 | { |
| 1563 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1564 | |
| 1565 | cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, 31, 24); |
| 1566 | cal_data->count_r[MT8195_TS1_0] = GET_CAL_DATA_BITMASK(1, 23, 0); |
| 1567 | cal_data->count_r[MT8195_TS1_1] = |
| 1568 | (GET_CAL_DATA_BITMASK(2, 15, 0) << 8) + |
| 1569 | GET_CAL_DATA_BITMASK(1, 31, 24); |
| 1570 | cal_data->count_r[MT8195_TS2_0] = GET_CAL_DATA_BITMASK(3, 31, 8); |
| 1571 | cal_data->count_r[MT8195_TS2_1] = GET_CAL_DATA_BITMASK(4, 23, 0); |
| 1572 | cal_data->count_r[MT8195_TS3_0] = |
| 1573 | (GET_CAL_DATA_BITMASK(6, 7, 0) << 16) + |
| 1574 | GET_CAL_DATA_BITMASK(5, 31, 16); |
| 1575 | cal_data->count_r[MT8195_TS3_1] = GET_CAL_DATA_BITMASK(6, 31, 8); |
| 1576 | cal_data->count_r[MT8195_TS3_2] = GET_CAL_DATA_BITMASK(7, 23, 0); |
| 1577 | cal_data->count_r[MT8195_TS3_3] = |
| 1578 | (GET_CAL_DATA_BITMASK(8, 15, 0) << 8) + |
| 1579 | GET_CAL_DATA_BITMASK(7, 31, 24); |
| 1580 | cal_data->count_r[MT8195_TS4_0] = GET_CAL_DATA_BITMASK(9, 31, 8); |
| 1581 | cal_data->count_r[MT8195_TS4_1] = GET_CAL_DATA_BITMASK(10, 23, 0); |
| 1582 | cal_data->count_r[MT8195_TS5_0] = |
| 1583 | (GET_CAL_DATA_BITMASK(12, 7, 0) << 16) + |
| 1584 | GET_CAL_DATA_BITMASK(11, 31, 16); |
| 1585 | cal_data->count_r[MT8195_TS5_1] = GET_CAL_DATA_BITMASK(12, 31, 8); |
| 1586 | cal_data->count_r[MT8195_TS6_0] = |
| 1587 | (GET_CAL_DATA_BITMASK(14, 15, 0) << 8) + |
| 1588 | GET_CAL_DATA_BITMASK(13, 31, 24); |
| 1589 | cal_data->count_r[MT8195_TS6_1] = |
| 1590 | (GET_CAL_DATA_BITMASK(15, 7, 0) << 16) + |
| 1591 | GET_CAL_DATA_BITMASK(14, 31, 16); |
| 1592 | cal_data->count_r[MT8195_TS6_2] = GET_CAL_DATA_BITMASK(15, 31, 8); |
| 1593 | cal_data->count_r[MT8195_TS7_0] = |
| 1594 | (GET_CAL_DATA_BITMASK(17, 15, 0) << 8) + |
| 1595 | GET_CAL_DATA_BITMASK(16, 31, 24); |
| 1596 | cal_data->count_r[MT8195_TS7_1] = |
| 1597 | (GET_CAL_DATA_BITMASK(18, 7, 0) << 16) + |
| 1598 | GET_CAL_DATA_BITMASK(17, 31, 16); |
| 1599 | cal_data->count_rc[MT8195_TS1_0] = |
| 1600 | (GET_CAL_DATA_BITMASK(3, 7, 0) << 16) + |
| 1601 | GET_CAL_DATA_BITMASK(2, 31, 16); |
| 1602 | cal_data->count_rc[MT8195_TS2_0] = |
| 1603 | (GET_CAL_DATA_BITMASK(5, 15, 0) << 8) + |
| 1604 | GET_CAL_DATA_BITMASK(4, 31, 24); |
| 1605 | cal_data->count_rc[MT8195_TS3_0] = |
| 1606 | (GET_CAL_DATA_BITMASK(9, 7, 0) << 16) + |
| 1607 | GET_CAL_DATA_BITMASK(8, 31, 16); |
| 1608 | cal_data->count_rc[MT8195_TS4_0] = |
| 1609 | (GET_CAL_DATA_BITMASK(11, 15, 0) << 8) + |
| 1610 | GET_CAL_DATA_BITMASK(10, 31, 24); |
| 1611 | cal_data->count_rc[MT8195_TS5_0] = GET_CAL_DATA_BITMASK(13, 23, 0); |
| 1612 | cal_data->count_rc[MT8195_TS6_0] = GET_CAL_DATA_BITMASK(16, 23, 0); |
| 1613 | cal_data->count_rc[MT8195_TS7_0] = GET_CAL_DATA_BITMASK(18, 31, 8); |
| 1614 | } |
| 1615 | |
| 1616 | static struct tc_settings mt8195_tc_settings[] = { |
| 1617 | [0] = { |
| 1618 | .domain_index = MT8195_MCU_DOMAIN, |
| 1619 | .addr_offset = 0x0, |
| 1620 | .num_sensor = 2, |
| 1621 | .sensor_map = {MT8195_TS1_0, MT8195_TS1_1}, |
| 1622 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1623 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1624 | .dominator_sensing_point = SENSING_POINT1, |
| 1625 | .hw_reboot_trip_point = 117000, |
| 1626 | .irq_bit = BIT(3), |
| 1627 | }, |
| 1628 | [1] = { |
| 1629 | .domain_index = MT8195_MCU_DOMAIN, |
| 1630 | .addr_offset = 0x100, |
| 1631 | .num_sensor = 2, |
| 1632 | .sensor_map = {MT8195_TS2_0, MT8195_TS2_1}, |
| 1633 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1634 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1635 | .dominator_sensing_point = SENSING_POINT0, |
| 1636 | .hw_reboot_trip_point = 117000, |
| 1637 | .irq_bit = BIT(4), |
| 1638 | }, |
| 1639 | [2] = { |
| 1640 | .domain_index = MT8195_MCU_DOMAIN, |
| 1641 | .addr_offset = 0x200, |
| 1642 | .num_sensor = 4, |
| 1643 | .sensor_map = {MT8195_TS3_0, MT8195_TS3_1, MT8195_TS3_2, |
| 1644 | MT8195_TS3_3}, |
| 1645 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1646 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1647 | .dominator_sensing_point = SENSING_POINT0, |
| 1648 | .hw_reboot_trip_point = 117000, |
| 1649 | .irq_bit = BIT(5), |
| 1650 | }, |
| 1651 | [3] = { |
| 1652 | .domain_index = MT8195_AP_DOMAIN, |
| 1653 | .addr_offset = 0x0, |
| 1654 | .num_sensor = 2, |
| 1655 | .sensor_map = {MT8195_TS4_0, MT8195_TS4_1}, |
| 1656 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1657 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1658 | .dominator_sensing_point = SENSING_POINT0, |
| 1659 | .hw_reboot_trip_point = 117000, |
| 1660 | .irq_bit = BIT(3), |
| 1661 | }, |
| 1662 | [4] = { |
| 1663 | .domain_index = MT8195_AP_DOMAIN, |
| 1664 | .addr_offset = 0x100, |
| 1665 | .num_sensor = 2, |
| 1666 | .sensor_map = {MT8195_TS5_0, MT8195_TS5_1}, |
| 1667 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1668 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1669 | .dominator_sensing_point = SENSING_POINT1, |
| 1670 | .hw_reboot_trip_point = 117000, |
| 1671 | .irq_bit = BIT(4), |
| 1672 | }, |
| 1673 | [5] = { |
| 1674 | .domain_index = MT8195_AP_DOMAIN, |
| 1675 | .addr_offset = 0x200, |
| 1676 | .num_sensor = 3, |
| 1677 | .sensor_map = {MT8195_TS6_0, MT8195_TS6_1, MT8195_TS6_2}, |
| 1678 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1679 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1680 | .dominator_sensing_point = SENSING_POINT1, |
| 1681 | .hw_reboot_trip_point = 117000, |
| 1682 | .irq_bit = BIT(5), |
| 1683 | }, |
| 1684 | [6] = { |
| 1685 | .domain_index = MT8195_AP_DOMAIN, |
| 1686 | .addr_offset = 0x300, |
| 1687 | .num_sensor = 2, |
| 1688 | .sensor_map = {MT8195_TS7_0, MT8195_TS7_1}, |
| 1689 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1690 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1691 | .dominator_sensing_point = SENSING_POINT0, |
| 1692 | .hw_reboot_trip_point = 117000, |
| 1693 | .irq_bit = BIT(6), |
| 1694 | } |
| 1695 | }; |
| 1696 | |
| 1697 | static struct lvts_data mt8195_lvts_data = { |
| 1698 | .num_domain = MT8195_NUM_DOMAIN, |
| 1699 | .num_tc = MT8195_NUM_LVTS, |
| 1700 | .tc = mt8195_tc_settings, |
| 1701 | .num_sensor = MT8195_NUM_TS, |
| 1702 | .ops = { |
| 1703 | .efuse_to_cal_data = mt8195_efuse_to_cal_data, |
| 1704 | .device_enable_and_init = device_enable_and_init_v4, |
| 1705 | .device_enable_auto_rck = device_enable_auto_rck_v4, |
| 1706 | .device_read_count_rc_n = device_read_count_rc_n_v4, |
| 1707 | .set_cal_data = set_calibration_data_v4, |
| 1708 | .init_controller = init_controller_v4, |
| 1709 | }, |
| 1710 | .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, |
| 1711 | .num_efuse_addr = 22, |
| 1712 | .num_efuse_block = 2, |
| 1713 | .cal_data = { |
| 1714 | .default_golden_temp = 50, |
| 1715 | .default_count_r = 35000, |
| 1716 | .default_count_rc = 2750, |
| 1717 | }, |
| 1718 | .coeff = { |
| 1719 | .a = -250460, |
| 1720 | .b = 250460, |
| 1721 | }, |
| 1722 | }; |
| 1723 | |
| 1724 | /* |
| 1725 | * LVTS MT8139 |
| 1726 | */ |
| 1727 | |
| 1728 | #define MT8139_NUM_LVTS (ARRAY_SIZE(mt8139_tc_settings)) |
| 1729 | |
| 1730 | enum mt8139_lvts_domain { |
| 1731 | MT8139_AP_DOMAIN, |
| 1732 | MT8139_MCU_DOMAIN, |
| 1733 | MT8139_NUM_DOMAIN |
| 1734 | }; |
| 1735 | |
| 1736 | enum mt8139_lvts_sensor_enum { |
| 1737 | MT8139_TS1_0, |
| 1738 | MT8139_TS1_1, |
| 1739 | MT8139_TS1_2, |
| 1740 | MT8139_TS1_3, |
| 1741 | MT8139_TS2_0, |
| 1742 | MT8139_TS2_1, |
| 1743 | MT8139_TS2_2, |
| 1744 | MT8139_TS2_3, |
| 1745 | MT8139_TS3_0, |
| 1746 | MT8139_TS3_1, |
| 1747 | MT8139_TS3_2, |
| 1748 | MT8139_TS3_3, |
| 1749 | MT8139_NUM_TS |
| 1750 | }; |
| 1751 | |
| 1752 | static void mt8139_efuse_to_cal_data(struct lvts_data *lvts_data) |
| 1753 | { |
| 1754 | struct sensor_cal_data *cal_data = &lvts_data->cal_data; |
| 1755 | |
| 1756 | cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, 7, 0); |
| 1757 | cal_data->count_r[MT8139_TS1_0] = GET_CAL_DATA_BITMASK(0, 31, 8); |
| 1758 | cal_data->count_r[MT8139_TS1_1] = GET_CAL_DATA_BITMASK(1, 23, 0); |
| 1759 | cal_data->count_r[MT8139_TS1_2] = |
| 1760 | (GET_CAL_DATA_BITMASK(2, 15, 0) << 8) + |
| 1761 | GET_CAL_DATA_BITMASK(1, 31, 24); |
| 1762 | cal_data->count_r[MT8139_TS1_3] = |
| 1763 | (GET_CAL_DATA_BITMASK(3, 7, 0) << 16) + |
| 1764 | GET_CAL_DATA_BITMASK(2, 31, 16); |
| 1765 | cal_data->count_rc[MT8139_TS1_0] = GET_CAL_DATA_BITMASK(3, 31, 8); |
| 1766 | |
| 1767 | cal_data->count_r[MT8139_TS2_0] = GET_CAL_DATA_BITMASK(4, 23, 0); |
| 1768 | cal_data->count_r[MT8139_TS2_1] = |
| 1769 | (GET_CAL_DATA_BITMASK(5, 15, 0) << 8) + |
| 1770 | GET_CAL_DATA_BITMASK(4, 31, 24); |
| 1771 | cal_data->count_r[MT8139_TS2_2] = |
| 1772 | (GET_CAL_DATA_BITMASK(6, 7, 0) << 16) + |
| 1773 | GET_CAL_DATA_BITMASK(5, 31, 16); |
| 1774 | cal_data->count_r[MT8139_TS2_3] = GET_CAL_DATA_BITMASK(6, 31, 8); |
| 1775 | cal_data->count_rc[MT8139_TS2_0] = GET_CAL_DATA_BITMASK(7, 23, 0); |
| 1776 | |
| 1777 | cal_data->count_r[MT8139_TS3_0] = |
| 1778 | (GET_CAL_DATA_BITMASK(8, 15, 0) << 8) + |
| 1779 | GET_CAL_DATA_BITMASK(7, 31, 24); |
| 1780 | cal_data->count_r[MT8139_TS3_1] = |
| 1781 | (GET_CAL_DATA_BITMASK(9, 7, 0) << 16) + |
| 1782 | GET_CAL_DATA_BITMASK(8, 31, 16); |
| 1783 | cal_data->count_r[MT8139_TS3_2] = GET_CAL_DATA_BITMASK(9, 31, 8); |
| 1784 | cal_data->count_r[MT8139_TS3_3] = GET_CAL_DATA_BITMASK(10, 23, 0); |
| 1785 | cal_data->count_rc[MT8139_TS3_0] = |
| 1786 | (GET_CAL_DATA_BITMASK(11, 15, 0) << 8) + |
| 1787 | GET_CAL_DATA_BITMASK(10, 31, 24); |
| 1788 | } |
| 1789 | |
| 1790 | static struct tc_settings mt8139_tc_settings[] = { |
| 1791 | [0] = { |
| 1792 | .domain_index = MT8139_MCU_DOMAIN, |
| 1793 | .addr_offset = 0x0, |
| 1794 | .num_sensor = 4, |
| 1795 | .sensor_map = {MT8139_TS1_0, MT8139_TS1_1, MT8139_TS1_2, |
| 1796 | MT8139_TS1_3}, |
| 1797 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1798 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1799 | .dominator_sensing_point = SENSING_POINT1, |
| 1800 | .hw_reboot_trip_point = 117000, |
| 1801 | .irq_bit = BIT(3), |
| 1802 | }, |
| 1803 | [1] = { |
| 1804 | .domain_index = MT8139_AP_DOMAIN, |
| 1805 | .addr_offset = 0x0, |
| 1806 | .num_sensor = 4, |
| 1807 | .sensor_map = {MT8139_TS2_0, MT8139_TS2_1, MT8139_TS2_2, |
| 1808 | MT8139_TS2_3}, |
| 1809 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1810 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1811 | .dominator_sensing_point = SENSING_POINT0, |
| 1812 | .hw_reboot_trip_point = 117000, |
| 1813 | .irq_bit = BIT(4), |
| 1814 | }, |
| 1815 | [2] = { |
| 1816 | .domain_index = MT8139_AP_DOMAIN, |
| 1817 | .addr_offset = 0x100, |
| 1818 | .num_sensor = 4, |
| 1819 | .sensor_map = {MT8139_TS3_0, MT8139_TS3_1, MT8139_TS3_2, |
| 1820 | MT8139_TS3_3}, |
| 1821 | .tc_speed = SET_TC_SPEED_IN_US(118, 118, 118, 118), |
| 1822 | .hw_filter = LVTS_FILTER_2_OF_4, |
| 1823 | .dominator_sensing_point = SENSING_POINT0, |
| 1824 | .hw_reboot_trip_point = 117000, |
| 1825 | .irq_bit = BIT(5), |
| 1826 | } |
| 1827 | |
| 1828 | }; |
| 1829 | |
| 1830 | static struct lvts_data mt8139_lvts_data = { |
| 1831 | .num_domain = MT8139_NUM_DOMAIN, |
| 1832 | .num_tc = MT8139_NUM_LVTS, |
| 1833 | .tc = mt8139_tc_settings, |
| 1834 | .num_sensor = MT8139_NUM_TS, |
| 1835 | .ops = { |
| 1836 | .efuse_to_cal_data = mt8139_efuse_to_cal_data, |
| 1837 | .device_enable_and_init = device_enable_and_init_v4, |
| 1838 | .device_enable_auto_rck = device_enable_auto_rck_v4, |
| 1839 | .device_read_count_rc_n = device_read_count_rc_n_v4, |
| 1840 | .set_cal_data = set_calibration_data_v4, |
| 1841 | .init_controller = init_controller_v4, |
| 1842 | }, |
| 1843 | .feature_bitmap = 0, |
| 1844 | .num_efuse_addr = 48, |
| 1845 | .num_efuse_block = 1, |
| 1846 | .cal_data = { |
| 1847 | .default_golden_temp = 50, |
| 1848 | .default_count_r = 35000, |
| 1849 | .default_count_rc = 2750, |
| 1850 | }, |
| 1851 | .coeff = { |
| 1852 | .a = -250460, |
| 1853 | .b = 250460, |
| 1854 | }, |
| 1855 | }; |
| 1856 | |
| 1857 | /* |
| 1858 | * Support chips |
| 1859 | */ |
| 1860 | static const struct of_device_id lvts_of_match[] = { |
| 1861 | { |
| 1862 | .compatible = "mediatek,mt6873-lvts", |
| 1863 | .data = (void *)&mt6873_lvts_data, |
| 1864 | }, |
| 1865 | { |
| 1866 | .compatible = "mediatek,mt8195-lvts", |
| 1867 | .data = (void *)&mt8195_lvts_data, |
| 1868 | }, |
| 1869 | { |
| 1870 | .compatible = "mediatek,mt8139-lvts", |
| 1871 | .data = (void *)&mt8139_lvts_data, |
| 1872 | }, |
| 1873 | { |
| 1874 | .compatible = "mediatek,mt7988-lvts", |
| 1875 | .data = (void *)&mt7988_lvts_data, |
| 1876 | }, |
| 1877 | {}, |
| 1878 | }; |
| 1879 | MODULE_DEVICE_TABLE(of, lvts_of_match); |
| 1880 | |
| 1881 | static struct platform_driver soc_temp_lvts = { |
| 1882 | .probe = lvts_probe, |
| 1883 | .remove = lvts_remove, |
| 1884 | .suspend = lvts_suspend, |
| 1885 | .resume = lvts_resume, |
| 1886 | .driver = { |
| 1887 | .name = "mtk-soc-temp-lvts", |
| 1888 | .of_match_table = lvts_of_match, |
| 1889 | }, |
| 1890 | }; |
| 1891 | |
| 1892 | module_platform_driver(soc_temp_lvts); |
| 1893 | MODULE_AUTHOR("Yu-Chia Chang <ethan.chang@mediatek.com>"); |
| 1894 | MODULE_AUTHOR("Michael Kao <michael.kao@mediatek.com>"); |
| 1895 | MODULE_AUTHOR("Henry Yen <henry.yen@mediatek.com>"); |
| 1896 | MODULE_DESCRIPTION("Mediatek soc temperature driver"); |
| 1897 | MODULE_LICENSE("GPL v2"); |