1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2023 MediaTek Inc.
4 * Author: Balsam CHIHI <bchihi@baylibre.com>
8 #include <linux/clk-provider.h>
9 #include <linux/delay.h>
10 #include <linux/debugfs.h>
11 #include <linux/init.h>
12 #include <linux/interrupt.h>
13 #include <linux/iopoll.h>
14 #include <linux/kernel.h>
15 #include <linux/nvmem-consumer.h>
17 #include <linux/platform_device.h>
18 #include <linux/reset.h>
19 #include <linux/thermal.h>
20 #include <dt-bindings/thermal/mediatek,lvts-thermal.h>
22 #include "../thermal_hwmon.h"
24 #define LVTS_MONCTL0(__base) (__base + 0x0000)
25 #define LVTS_MONCTL1(__base) (__base + 0x0004)
26 #define LVTS_MONCTL2(__base) (__base + 0x0008)
27 #define LVTS_MONINT(__base) (__base + 0x000C)
28 #define LVTS_MONINTSTS(__base) (__base + 0x0010)
29 #define LVTS_MONIDET0(__base) (__base + 0x0014)
30 #define LVTS_MONIDET1(__base) (__base + 0x0018)
31 #define LVTS_MONIDET2(__base) (__base + 0x001C)
32 #define LVTS_MONIDET3(__base) (__base + 0x0020)
33 #define LVTS_H2NTHRE(__base) (__base + 0x0024)
34 #define LVTS_HTHRE(__base) (__base + 0x0028)
35 #define LVTS_OFFSETH(__base) (__base + 0x0030)
36 #define LVTS_OFFSETL(__base) (__base + 0x0034)
37 #define LVTS_MSRCTL0(__base) (__base + 0x0038)
38 #define LVTS_MSRCTL1(__base) (__base + 0x003C)
39 #define LVTS_TSSEL(__base) (__base + 0x0040)
40 #define LVTS_CALSCALE(__base) (__base + 0x0048)
41 #define LVTS_ID(__base) (__base + 0x004C)
42 #define LVTS_CONFIG(__base) (__base + 0x0050)
43 #define LVTS_EDATA00(__base) (__base + 0x0054)
44 #define LVTS_EDATA01(__base) (__base + 0x0058)
45 #define LVTS_EDATA02(__base) (__base + 0x005C)
46 #define LVTS_EDATA03(__base) (__base + 0x0060)
47 #define LVTS_MSR0(__base) (__base + 0x0090)
48 #define LVTS_MSR1(__base) (__base + 0x0094)
49 #define LVTS_MSR2(__base) (__base + 0x0098)
50 #define LVTS_MSR3(__base) (__base + 0x009C)
51 #define LVTS_IMMD0(__base) (__base + 0x00A0)
52 #define LVTS_IMMD1(__base) (__base + 0x00A4)
53 #define LVTS_IMMD2(__base) (__base + 0x00A8)
54 #define LVTS_IMMD3(__base) (__base + 0x00AC)
55 #define LVTS_PROTCTL(__base) (__base + 0x00C0)
56 #define LVTS_PROTTA(__base) (__base + 0x00C4)
57 #define LVTS_PROTTB(__base) (__base + 0x00C8)
58 #define LVTS_PROTTC(__base) (__base + 0x00CC)
59 #define LVTS_CLKEN(__base) (__base + 0x00E4)
61 #define LVTS_PERIOD_UNIT 0
62 #define LVTS_GROUP_INTERVAL 0
63 #define LVTS_FILTER_INTERVAL 0
64 #define LVTS_SENSOR_INTERVAL 0
65 #define LVTS_HW_FILTER 0x0
66 #define LVTS_TSSEL_CONF 0x13121110
67 #define LVTS_CALSCALE_CONF 0x300
68 #define LVTS_MONINT_CONF 0x8300318C
70 #define LVTS_MONINT_OFFSET_SENSOR0 0xC
71 #define LVTS_MONINT_OFFSET_SENSOR1 0x180
72 #define LVTS_MONINT_OFFSET_SENSOR2 0x3000
73 #define LVTS_MONINT_OFFSET_SENSOR3 0x3000000
75 #define LVTS_INT_SENSOR0 0x0009001F
76 #define LVTS_INT_SENSOR1 0x001203E0
77 #define LVTS_INT_SENSOR2 0x00247C00
78 #define LVTS_INT_SENSOR3 0x1FC00000
80 #define LVTS_SENSOR_MAX 4
81 #define LVTS_GOLDEN_TEMP_MAX 62
82 #define LVTS_GOLDEN_TEMP_DEFAULT 50
83 #define LVTS_COEFF_A_MT8195 -250460
84 #define LVTS_COEFF_B_MT8195 250460
85 #define LVTS_COEFF_A_MT7988 -204650
86 #define LVTS_COEFF_B_MT7988 204650
88 #define LVTS_MSR_IMMEDIATE_MODE 0
89 #define LVTS_MSR_FILTERED_MODE 1
91 #define LVTS_MSR_READ_TIMEOUT_US 400
92 #define LVTS_MSR_READ_WAIT_US (LVTS_MSR_READ_TIMEOUT_US / 2)
94 #define LVTS_HW_SHUTDOWN_MT7988 105000
95 #define LVTS_HW_SHUTDOWN_MT8192 105000
96 #define LVTS_HW_SHUTDOWN_MT8195 105000
98 #define LVTS_MINIMUM_THRESHOLD 20000
100 static int golden_temp = LVTS_GOLDEN_TEMP_DEFAULT;
101 static int golden_temp_offset;
103 struct lvts_sensor_data {
107 struct lvts_ctrl_data {
108 struct lvts_sensor_data lvts_sensor[LVTS_SENSOR_MAX];
109 int cal_offset[LVTS_SENSOR_MAX];
117 const struct lvts_ctrl_data *lvts_ctrl;
124 struct thermal_zone_device *tz;
134 struct lvts_sensor sensors[LVTS_SENSOR_MAX];
135 const struct lvts_data *lvts_data;
136 u32 calibration[LVTS_SENSOR_MAX];
137 u32 hw_tshut_raw_temp;
146 struct lvts_ctrl *lvts_ctrl;
147 struct reset_control *reset;
153 #ifdef CONFIG_DEBUG_FS
154 struct dentry *dom_dentry;
158 #ifdef CONFIG_MTK_LVTS_THERMAL_DEBUGFS
160 #define LVTS_DEBUG_FS_REGS(__reg) \
162 .name = __stringify(__reg), \
163 .offset = __reg(0), \
166 static const struct debugfs_reg32 lvts_regs[] = {
167 LVTS_DEBUG_FS_REGS(LVTS_MONCTL0),
168 LVTS_DEBUG_FS_REGS(LVTS_MONCTL1),
169 LVTS_DEBUG_FS_REGS(LVTS_MONCTL2),
170 LVTS_DEBUG_FS_REGS(LVTS_MONINT),
171 LVTS_DEBUG_FS_REGS(LVTS_MONINTSTS),
172 LVTS_DEBUG_FS_REGS(LVTS_MONIDET0),
173 LVTS_DEBUG_FS_REGS(LVTS_MONIDET1),
174 LVTS_DEBUG_FS_REGS(LVTS_MONIDET2),
175 LVTS_DEBUG_FS_REGS(LVTS_MONIDET3),
176 LVTS_DEBUG_FS_REGS(LVTS_H2NTHRE),
177 LVTS_DEBUG_FS_REGS(LVTS_HTHRE),
178 LVTS_DEBUG_FS_REGS(LVTS_OFFSETH),
179 LVTS_DEBUG_FS_REGS(LVTS_OFFSETL),
180 LVTS_DEBUG_FS_REGS(LVTS_MSRCTL0),
181 LVTS_DEBUG_FS_REGS(LVTS_MSRCTL1),
182 LVTS_DEBUG_FS_REGS(LVTS_TSSEL),
183 LVTS_DEBUG_FS_REGS(LVTS_CALSCALE),
184 LVTS_DEBUG_FS_REGS(LVTS_ID),
185 LVTS_DEBUG_FS_REGS(LVTS_CONFIG),
186 LVTS_DEBUG_FS_REGS(LVTS_EDATA00),
187 LVTS_DEBUG_FS_REGS(LVTS_EDATA01),
188 LVTS_DEBUG_FS_REGS(LVTS_EDATA02),
189 LVTS_DEBUG_FS_REGS(LVTS_EDATA03),
190 LVTS_DEBUG_FS_REGS(LVTS_MSR0),
191 LVTS_DEBUG_FS_REGS(LVTS_MSR1),
192 LVTS_DEBUG_FS_REGS(LVTS_MSR2),
193 LVTS_DEBUG_FS_REGS(LVTS_MSR3),
194 LVTS_DEBUG_FS_REGS(LVTS_IMMD0),
195 LVTS_DEBUG_FS_REGS(LVTS_IMMD1),
196 LVTS_DEBUG_FS_REGS(LVTS_IMMD2),
197 LVTS_DEBUG_FS_REGS(LVTS_IMMD3),
198 LVTS_DEBUG_FS_REGS(LVTS_PROTCTL),
199 LVTS_DEBUG_FS_REGS(LVTS_PROTTA),
200 LVTS_DEBUG_FS_REGS(LVTS_PROTTB),
201 LVTS_DEBUG_FS_REGS(LVTS_PROTTC),
202 LVTS_DEBUG_FS_REGS(LVTS_CLKEN),
205 static int lvts_debugfs_init(struct device *dev, struct lvts_domain *lvts_td)
207 struct debugfs_regset32 *regset;
208 struct lvts_ctrl *lvts_ctrl;
209 struct dentry *dentry;
213 lvts_td->dom_dentry = debugfs_create_dir(dev_name(dev), NULL);
214 if (IS_ERR(lvts_td->dom_dentry))
217 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) {
219 lvts_ctrl = &lvts_td->lvts_ctrl[i];
221 sprintf(name, "controller%d", i);
222 dentry = debugfs_create_dir(name, lvts_td->dom_dentry);
226 regset = devm_kzalloc(dev, sizeof(*regset), GFP_KERNEL);
230 regset->base = lvts_ctrl->base;
231 regset->regs = lvts_regs;
232 regset->nregs = ARRAY_SIZE(lvts_regs);
234 debugfs_create_regset32("registers", 0400, dentry, regset);
240 static void lvts_debugfs_exit(struct lvts_domain *lvts_td)
242 debugfs_remove_recursive(lvts_td->dom_dentry);
247 static inline int lvts_debugfs_init(struct device *dev,
248 struct lvts_domain *lvts_td)
253 static void lvts_debugfs_exit(struct lvts_domain *lvts_td) { }
257 static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
261 temperature = ((s64)(raw_temp & 0xFFFF) * temp_factor) >> 14;
262 temperature += golden_temp_offset;
267 static u32 lvts_temp_to_raw(int temperature, int temp_factor)
269 u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
271 raw_temp = div_s64(raw_temp, -temp_factor);
276 static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
278 struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
279 struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl,
280 sensors[lvts_sensor->id]);
281 const struct lvts_data *lvts_data = lvts_ctrl->lvts_data;
282 void __iomem *msr = lvts_sensor->msr;
287 * Measurement registers:
289 * LVTS_MSR[0-3] / LVTS_IMMD[0-3]
294 * 16 : Valid temperature
295 * 15-0 : Raw temperature
297 rc = readl_poll_timeout(msr, value, value & BIT(16),
298 LVTS_MSR_READ_WAIT_US, LVTS_MSR_READ_TIMEOUT_US);
301 * As the thermal zone temperature will read before the
302 * hardware sensor is fully initialized, we have to check the
303 * validity of the temperature returned when reading the
304 * measurement register. The thermal controller will set the
305 * valid bit temperature only when it is totally initialized.
307 * Otherwise, we may end up with garbage values out of the
308 * functionning temperature and directly jump to a system
314 *temp = lvts_raw_to_temp(value & 0xFFFF, lvts_data->temp_factor);
319 static void lvts_update_irq_mask(struct lvts_ctrl *lvts_ctrl)
322 LVTS_MONINT_OFFSET_SENSOR0,
323 LVTS_MONINT_OFFSET_SENSOR1,
324 LVTS_MONINT_OFFSET_SENSOR2,
325 LVTS_MONINT_OFFSET_SENSOR3,
330 value = readl(LVTS_MONINT(lvts_ctrl->base));
332 for (i = 0; i < ARRAY_SIZE(masks); i++) {
333 if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh
334 && lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh)
340 writel(value, LVTS_MONINT(lvts_ctrl->base));
343 static bool lvts_should_update_thresh(struct lvts_ctrl *lvts_ctrl, int high)
347 if (high > lvts_ctrl->high_thresh)
350 for (i = 0; i < lvts_ctrl->num_lvts_sensor; i++)
351 if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh
352 && lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh)
358 static int lvts_set_trips(struct thermal_zone_device *tz, int low, int high)
360 struct lvts_sensor *lvts_sensor = thermal_zone_device_priv(tz);
361 struct lvts_ctrl *lvts_ctrl = container_of(lvts_sensor, struct lvts_ctrl,
362 sensors[lvts_sensor->id]);
363 const struct lvts_data *lvts_data = lvts_ctrl->lvts_data;
364 void __iomem *base = lvts_sensor->base;
365 u32 raw_low = lvts_temp_to_raw(low != -INT_MAX ? low : LVTS_MINIMUM_THRESHOLD,
366 lvts_data->temp_factor);
367 u32 raw_high = lvts_temp_to_raw(high, lvts_data->temp_factor);
368 bool should_update_thresh;
370 lvts_sensor->low_thresh = low;
371 lvts_sensor->high_thresh = high;
373 should_update_thresh = lvts_should_update_thresh(lvts_ctrl, high);
374 if (should_update_thresh) {
375 lvts_ctrl->high_thresh = high;
376 lvts_ctrl->low_thresh = low;
378 lvts_update_irq_mask(lvts_ctrl);
380 if (!should_update_thresh)
384 * Low offset temperature threshold
390 * 14-0 : Raw temperature for threshold
392 pr_debug("%s: Setting low limit temperature interrupt: %d\n",
393 thermal_zone_device_type(tz), low);
394 writel(raw_low, LVTS_OFFSETL(base));
397 * High offset temperature threshold
403 * 14-0 : Raw temperature for threshold
405 pr_debug("%s: Setting high limit temperature interrupt: %d\n",
406 thermal_zone_device_type(tz), high);
407 writel(raw_high, LVTS_OFFSETH(base));
412 static irqreturn_t lvts_ctrl_irq_handler(struct lvts_ctrl *lvts_ctrl)
414 irqreturn_t iret = IRQ_NONE;
425 * Interrupt monitoring status
431 * 31 : Interrupt for stage 3
432 * 30 : Interrupt for stage 2
433 * 29 : Interrupt for state 1
434 * 28 : Interrupt using filter on sensor 3
436 * 27 : Interrupt using immediate on sensor 3
437 * 26 : Interrupt normal to hot on sensor 3
438 * 25 : Interrupt high offset on sensor 3
439 * 24 : Interrupt low offset on sensor 3
441 * 23 : Interrupt hot threshold on sensor 3
442 * 22 : Interrupt cold threshold on sensor 3
443 * 21 : Interrupt using filter on sensor 2
444 * 20 : Interrupt using filter on sensor 1
446 * 19 : Interrupt using filter on sensor 0
447 * 18 : Interrupt using immediate on sensor 2
448 * 17 : Interrupt using immediate on sensor 1
449 * 16 : Interrupt using immediate on sensor 0
451 * 15 : Interrupt device access timeout interrupt
452 * 14 : Interrupt normal to hot on sensor 2
453 * 13 : Interrupt high offset interrupt on sensor 2
454 * 12 : Interrupt low offset interrupt on sensor 2
456 * 11 : Interrupt hot threshold on sensor 2
457 * 10 : Interrupt cold threshold on sensor 2
458 * 9 : Interrupt normal to hot on sensor 1
459 * 8 : Interrupt high offset interrupt on sensor 1
461 * 7 : Interrupt low offset interrupt on sensor 1
462 * 6 : Interrupt hot threshold on sensor 1
463 * 5 : Interrupt cold threshold on sensor 1
464 * 4 : Interrupt normal to hot on sensor 0
466 * 3 : Interrupt high offset interrupt on sensor 0
467 * 2 : Interrupt low offset interrupt on sensor 0
468 * 1 : Interrupt hot threshold on sensor 0
469 * 0 : Interrupt cold threshold on sensor 0
471 * We are interested in the sensor(s) responsible of the
472 * interrupt event. We update the thermal framework with the
473 * thermal zone associated with the sensor. The framework will
474 * take care of the rest whatever the kind of interrupt, we
475 * are only interested in which sensor raised the interrupt.
477 * sensor 3 interrupt: 0001 1111 1100 0000 0000 0000 0000 0000
479 * sensor 2 interrupt: 0000 0000 0010 0100 0111 1100 0000 0000
481 * sensor 1 interrupt: 0000 0000 0001 0010 0000 0011 1110 0000
483 * sensor 0 interrupt: 0000 0000 0000 1001 0000 0000 0001 1111
486 value = readl(LVTS_MONINTSTS(lvts_ctrl->base));
489 * Let's figure out which sensors raised the interrupt
491 * NOTE: the masks array must be ordered with the index
492 * corresponding to the sensor id eg. index=0, mask for
495 for (i = 0; i < ARRAY_SIZE(masks); i++) {
497 if (!(value & masks[i]))
500 thermal_zone_device_update(lvts_ctrl->sensors[i].tz,
501 THERMAL_TRIP_VIOLATED);
506 * Write back to clear the interrupt status (W1C)
508 writel(value, LVTS_MONINTSTS(lvts_ctrl->base));
514 * Temperature interrupt handler. Even if the driver supports more
515 * interrupt modes, we use the interrupt when the temperature crosses
516 * the hot threshold the way up and the way down (modulo the
519 * Each thermal domain has a couple of interrupts, one for hardware
520 * reset and another one for all the thermal events happening on the
523 * The interrupt is configured for thermal events when crossing the
524 * hot temperature limit. At each interrupt, we check in every
525 * controller if there is an interrupt pending.
527 static irqreturn_t lvts_irq_handler(int irq, void *data)
529 struct lvts_domain *lvts_td = data;
530 irqreturn_t aux, iret = IRQ_NONE;
533 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) {
535 aux = lvts_ctrl_irq_handler(&lvts_td->lvts_ctrl[i]);
536 if (aux != IRQ_HANDLED)
545 static struct thermal_zone_device_ops lvts_ops = {
546 .get_temp = lvts_get_temp,
547 .set_trips = lvts_set_trips,
550 static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
551 const struct lvts_ctrl_data *lvts_ctrl_data)
553 struct lvts_sensor *lvts_sensor = lvts_ctrl->sensors;
554 void __iomem *msr_regs[] = {
555 LVTS_MSR0(lvts_ctrl->base),
556 LVTS_MSR1(lvts_ctrl->base),
557 LVTS_MSR2(lvts_ctrl->base),
558 LVTS_MSR3(lvts_ctrl->base)
561 void __iomem *imm_regs[] = {
562 LVTS_IMMD0(lvts_ctrl->base),
563 LVTS_IMMD1(lvts_ctrl->base),
564 LVTS_IMMD2(lvts_ctrl->base),
565 LVTS_IMMD3(lvts_ctrl->base)
570 for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++) {
572 int dt_id = lvts_ctrl_data->lvts_sensor[i].dt_id;
575 * At this point, we don't know which id matches which
576 * sensor. Let's set arbitrally the id from the index.
578 lvts_sensor[i].id = i;
581 * The thermal zone registration will set the trip
582 * point interrupt in the thermal controller
583 * register. But this one will be reset in the
584 * initialization after. So we need to post pone the
585 * thermal zone creation after the controller is
586 * setup. For this reason, we store the device tree
587 * node id from the data in the sensor structure
589 lvts_sensor[i].dt_id = dt_id;
592 * We assign the base address of the thermal
593 * controller as a back pointer. So it will be
594 * accessible from the different thermal framework ops
595 * as we pass the lvts_sensor pointer as thermal zone
598 lvts_sensor[i].base = lvts_ctrl->base;
601 * Each sensor has its own register address to read from.
603 lvts_sensor[i].msr = lvts_ctrl_data->mode == LVTS_MSR_IMMEDIATE_MODE ?
604 imm_regs[i] : msr_regs[i];
606 lvts_sensor[i].low_thresh = INT_MIN;
607 lvts_sensor[i].high_thresh = INT_MIN;
610 lvts_ctrl->num_lvts_sensor = lvts_ctrl_data->num_lvts_sensor;
616 * The efuse blob values follows the sensor enumeration per thermal
617 * controller. The decoding of the stream is as follow:
620 * Stream index map for MCU Domain mt8192 :
622 * <-----mcu-tc#0-----> <-----sensor#0-----> <-----sensor#1----->
623 * 0x01 | 0x02 | 0x03 | 0x04 | 0x05 | 0x06 | 0x07 | 0x08 | 0x09 | 0x0A | 0x0B
625 * <-----sensor#2-----> <-----sensor#3----->
626 * 0x0C | 0x0D | 0x0E | 0x0F | 0x10 | 0x11 | 0x12 | 0x13
628 * <-----sensor#4-----> <-----sensor#5-----> <-----sensor#6-----> <-----sensor#7----->
629 * 0x14 | 0x15 | 0x16 | 0x17 | 0x18 | 0x19 | 0x1A | 0x1B | 0x1C | 0x1D | 0x1E | 0x1F | 0x20 | 0x21 | 0x22 | 0x23
631 * Stream index map for AP Domain mt8192 :
633 * <-----sensor#0-----> <-----sensor#1----->
634 * 0x24 | 0x25 | 0x26 | 0x27 | 0x28 | 0x29 | 0x2A | 0x2B
636 * <-----sensor#2-----> <-----sensor#3----->
637 * 0x2C | 0x2D | 0x2E | 0x2F | 0x30 | 0x31 | 0x32 | 0x33
639 * <-----sensor#4-----> <-----sensor#5----->
640 * 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 | 0x3A | 0x3B
642 * <-----sensor#6-----> <-----sensor#7-----> <-----sensor#8----->
643 * 0x3C | 0x3D | 0x3E | 0x3F | 0x40 | 0x41 | 0x42 | 0x43 | 0x44 | 0x45 | 0x46 | 0x47
646 * Stream index map for MCU Domain mt8195 :
648 * <-----mcu-tc#0-----> <-----sensor#0-----> <-----sensor#1----->
649 * 0x01 | 0x02 | 0x03 | 0x04 | 0x05 | 0x06 | 0x07 | 0x08 | 0x09
651 * <-----mcu-tc#1-----> <-----sensor#2-----> <-----sensor#3----->
652 * 0x0A | 0x0B | 0x0C | 0x0D | 0x0E | 0x0F | 0x10 | 0x11 | 0x12
654 * <-----mcu-tc#2-----> <-----sensor#4-----> <-----sensor#5-----> <-----sensor#6-----> <-----sensor#7----->
655 * 0x13 | 0x14 | 0x15 | 0x16 | 0x17 | 0x18 | 0x19 | 0x1A | 0x1B | 0x1C | 0x1D | 0x1E | 0x1F | 0x20 | 0x21
657 * Stream index map for AP Domain mt8195 :
659 * <-----ap--tc#0-----> <-----sensor#0-----> <-----sensor#1----->
660 * 0x22 | 0x23 | 0x24 | 0x25 | 0x26 | 0x27 | 0x28 | 0x29 | 0x2A
662 * <-----ap--tc#1-----> <-----sensor#2-----> <-----sensor#3----->
663 * 0x2B | 0x2C | 0x2D | 0x2E | 0x2F | 0x30 | 0x31 | 0x32 | 0x33
665 * <-----ap--tc#2-----> <-----sensor#4-----> <-----sensor#5-----> <-----sensor#6----->
666 * 0x34 | 0x35 | 0x36 | 0x37 | 0x38 | 0x39 | 0x3A | 0x3B | 0x3C | 0x3D | 0x3E | 0x3F
668 * <-----ap--tc#3-----> <-----sensor#7-----> <-----sensor#8----->
669 * 0x40 | 0x41 | 0x42 | 0x43 | 0x44 | 0x45 | 0x46 | 0x47 | 0x48
671 * The data description gives the offset of the calibration data in
672 * this bytes stream for each sensor.
674 static int lvts_calibration_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
675 const struct lvts_ctrl_data *lvts_ctrl_data,
676 u8 *efuse_calibration)
680 for (i = 0; i < lvts_ctrl_data->num_lvts_sensor; i++)
681 memcpy(&lvts_ctrl->calibration[i],
682 efuse_calibration + lvts_ctrl_data->cal_offset[i], 2);
688 * The efuse bytes stream can be split into different chunk of
689 * nvmems. This function reads and concatenate those into a single
690 * buffer so it can be read sequentially when initializing the
693 static int lvts_calibration_read(struct device *dev, struct lvts_domain *lvts_td,
694 const struct lvts_data *lvts_data)
696 struct device_node *np = dev_of_node(dev);
697 struct nvmem_cell *cell;
698 struct property *prop;
699 const char *cell_name;
701 of_property_for_each_string(np, "nvmem-cell-names", prop, cell_name) {
705 cell = of_nvmem_cell_get(np, cell_name);
707 dev_err(dev, "Failed to get cell '%s'\n", cell_name);
708 return PTR_ERR(cell);
711 efuse = nvmem_cell_read(cell, &len);
713 nvmem_cell_put(cell);
716 dev_err(dev, "Failed to read cell '%s'\n", cell_name);
717 return PTR_ERR(efuse);
720 lvts_td->calib = devm_krealloc(dev, lvts_td->calib,
721 lvts_td->calib_len + len, GFP_KERNEL);
722 if (!lvts_td->calib) {
727 memcpy(lvts_td->calib + lvts_td->calib_len, efuse, len);
729 lvts_td->calib_len += len;
737 static int lvts_golden_temp_init(struct device *dev, u32 *value, int temp_offset)
743 if (gt && gt < LVTS_GOLDEN_TEMP_MAX)
746 golden_temp_offset = golden_temp * 500 + temp_offset;
751 static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
752 const struct lvts_data *lvts_data)
754 size_t size = sizeof(*lvts_td->lvts_ctrl) * lvts_data->num_lvts_ctrl;
755 struct lvts_ctrl *lvts_ctrl;
759 * Create the calibration bytes stream from efuse data
761 ret = lvts_calibration_read(dev, lvts_td, lvts_data);
766 * The golden temp information is contained in the first chunk
769 ret = lvts_golden_temp_init(dev, (u32 *)lvts_td->calib, lvts_data->temp_offset);
773 lvts_ctrl = devm_kzalloc(dev, size, GFP_KERNEL);
777 for (i = 0; i < lvts_data->num_lvts_ctrl; i++) {
779 lvts_ctrl[i].base = lvts_td->base + lvts_data->lvts_ctrl[i].offset;
780 lvts_ctrl[i].lvts_data = lvts_data;
782 ret = lvts_sensor_init(dev, &lvts_ctrl[i],
783 &lvts_data->lvts_ctrl[i]);
787 ret = lvts_calibration_init(dev, &lvts_ctrl[i],
788 &lvts_data->lvts_ctrl[i],
794 * The mode the ctrl will use to read the temperature
795 * (filtered or immediate)
797 lvts_ctrl[i].mode = lvts_data->lvts_ctrl[i].mode;
800 * The temperature to raw temperature must be done
801 * after initializing the calibration.
803 lvts_ctrl[i].hw_tshut_raw_temp =
804 lvts_temp_to_raw(lvts_data->lvts_ctrl[i].hw_tshut_temp,
805 lvts_data->temp_factor);
807 lvts_ctrl[i].low_thresh = INT_MIN;
808 lvts_ctrl[i].high_thresh = INT_MIN;
812 * We no longer need the efuse bytes stream, let's free it
814 devm_kfree(dev, lvts_td->calib);
816 lvts_td->lvts_ctrl = lvts_ctrl;
817 lvts_td->num_lvts_ctrl = lvts_data->num_lvts_ctrl;
823 * At this point the configuration register is the only place in the
824 * driver where we write multiple values. Per hardware constraint,
825 * each write in the configuration register must be separated by a
828 static void lvts_write_config(struct lvts_ctrl *lvts_ctrl, u32 *cmds, int nr_cmds)
833 * Configuration register
835 for (i = 0; i < nr_cmds; i++) {
836 writel(cmds[i], LVTS_CONFIG(lvts_ctrl->base));
841 static int lvts_irq_init(struct lvts_ctrl *lvts_ctrl)
844 * LVTS_PROTCTL : Thermal Protection Sensor Selection
848 * 19-18 : Sensor to base the protection on
850 * 00 : Average of 4 sensors
851 * 01 : Max of 4 sensors
852 * 10 : Selected sensor with bits 19-18
855 writel(BIT(16), LVTS_PROTCTL(lvts_ctrl->base));
858 * LVTS_PROTTA : Stage 1 temperature threshold
859 * LVTS_PROTTB : Stage 2 temperature threshold
860 * LVTS_PROTTC : Stage 3 temperature threshold
864 * 14-0: Raw temperature threshold
866 * writel(0x0, LVTS_PROTTA(lvts_ctrl->base));
867 * writel(0x0, LVTS_PROTTB(lvts_ctrl->base));
869 writel(lvts_ctrl->hw_tshut_raw_temp, LVTS_PROTTC(lvts_ctrl->base));
872 * LVTS_MONINT : Interrupt configuration register
874 * The LVTS_MONINT register layout is the same as the LVTS_MONINTSTS
875 * register, except we set the bits to enable the interrupt.
877 writel(LVTS_MONINT_CONF, LVTS_MONINT(lvts_ctrl->base));
882 static int lvts_domain_reset(struct device *dev, struct reset_control *reset)
886 ret = reset_control_assert(reset);
890 return reset_control_deassert(reset);
894 * Enable or disable the clocks of a specified thermal controller
896 static int lvts_ctrl_set_enable(struct lvts_ctrl *lvts_ctrl, int enable)
899 * LVTS_CLKEN : Internal LVTS clock
903 * 0 : enable / disable clock
905 writel(enable, LVTS_CLKEN(lvts_ctrl->base));
910 static int lvts_ctrl_connect(struct device *dev, struct lvts_ctrl *lvts_ctrl)
912 u32 id, cmds[] = { 0xC103FFFF, 0xC502FF55 };
914 lvts_write_config(lvts_ctrl, cmds, ARRAY_SIZE(cmds));
917 * LVTS_ID : Get ID and status of the thermal controller
921 * 0-5 : thermal controller id
922 * 7 : thermal controller connection is valid
924 id = readl(LVTS_ID(lvts_ctrl->base));
931 static int lvts_ctrl_initialize(struct device *dev, struct lvts_ctrl *lvts_ctrl)
934 * Write device mask: 0xC1030000
937 0xC1030E01, 0xC1030CFC, 0xC1030A8C, 0xC103098D, 0xC10308F1,
938 0xC10307A6, 0xC10306B8, 0xC1030500, 0xC1030420, 0xC1030300,
939 0xC1030030, 0xC10300F6, 0xC1030050, 0xC1030060, 0xC10300AC,
940 0xC10300FC, 0xC103009D, 0xC10300F1, 0xC10300E1
943 lvts_write_config(lvts_ctrl, cmds, ARRAY_SIZE(cmds));
948 static int lvts_ctrl_calibrate(struct device *dev, struct lvts_ctrl *lvts_ctrl)
951 void __iomem *lvts_edata[] = {
952 LVTS_EDATA00(lvts_ctrl->base),
953 LVTS_EDATA01(lvts_ctrl->base),
954 LVTS_EDATA02(lvts_ctrl->base),
955 LVTS_EDATA03(lvts_ctrl->base)
959 * LVTS_EDATA0X : Efuse calibration reference value for sensor X
963 * 20-0 : Efuse value for normalization data
965 for (i = 0; i < LVTS_SENSOR_MAX; i++)
966 writel(lvts_ctrl->calibration[i], lvts_edata[i]);
971 static int lvts_ctrl_configure(struct device *dev, struct lvts_ctrl *lvts_ctrl)
976 * LVTS_TSSEL : Sensing point index numbering
985 value = LVTS_TSSEL_CONF;
986 writel(value, LVTS_TSSEL(lvts_ctrl->base));
989 * LVTS_CALSCALE : ADC voltage round
992 value = LVTS_CALSCALE_CONF;
995 * LVTS_MSRCTL0 : Sensor filtering strategy
1000 * 001 : Avg 2 samples
1001 * 010 : 4 samples, drop min and max, avg 2 samples
1002 * 011 : 6 samples, drop min and max, avg 4 samples
1003 * 100 : 10 samples, drop min and max, avg 8 samples
1004 * 101 : 18 samples, drop min and max, avg 16 samples
1008 * 0-2 : Sensor0 filter
1009 * 3-5 : Sensor1 filter
1010 * 6-8 : Sensor2 filter
1011 * 9-11 : Sensor3 filter
1013 value = LVTS_HW_FILTER << 9 | LVTS_HW_FILTER << 6 |
1014 LVTS_HW_FILTER << 3 | LVTS_HW_FILTER;
1015 writel(value, LVTS_MSRCTL0(lvts_ctrl->base));
1018 * LVTS_MONCTL1 : Period unit and group interval configuration
1020 * The clock source of LVTS thermal controller is 26MHz.
1022 * The period unit is a time base for all the interval delays
1023 * specified in the registers. By default we use 12. The time
1024 * conversion is done by multiplying by 256 and 1/26.10^6
1026 * An interval delay multiplied by the period unit gives the
1027 * duration in seconds.
1029 * - Filter interval delay is a delay between two samples of
1032 * - Sensor interval delay is a delay between two samples of
1033 * different sensors.
1035 * - Group interval delay is a delay between different rounds.
1038 * If Period unit = C, filter delay = 1, sensor delay = 2, group delay = 1,
1039 * and two sensors, TS1 and TS2, are in a LVTS thermal controller
1041 * Period unit time = C * 1/26M * 256 = 12 * 38.46ns * 256 = 118.149us
1042 * Filter interval delay = 1 * Period unit = 118.149us
1043 * Sensor interval delay = 2 * Period unit = 236.298us
1044 * Group interval delay = 1 * Period unit = 118.149us
1046 * TS1 TS1 ... TS1 TS2 TS2 ... TS2 TS1...
1047 * <--> Filter interval delay
1048 * <--> Sensor interval delay
1049 * <--> Group interval delay
1051 * 29 - 20 : Group interval
1052 * 16 - 13 : Send a single interrupt when crossing the hot threshold (1)
1053 * or an interrupt everytime the hot threshold is crossed (0)
1054 * 9 - 0 : Period unit
1057 value = LVTS_GROUP_INTERVAL << 20 | LVTS_PERIOD_UNIT;
1058 writel(value, LVTS_MONCTL1(lvts_ctrl->base));
1061 * LVTS_MONCTL2 : Filtering and sensor interval
1065 * 25-16 : Interval unit in PERIOD_UNIT between sample on
1066 * the same sensor, filter interval
1067 * 9-0 : Interval unit in PERIOD_UNIT between each sensor
1070 value = LVTS_FILTER_INTERVAL << 16 | LVTS_SENSOR_INTERVAL;
1071 writel(value, LVTS_MONCTL2(lvts_ctrl->base));
1073 return lvts_irq_init(lvts_ctrl);
1076 static int lvts_ctrl_start(struct device *dev, struct lvts_ctrl *lvts_ctrl)
1078 struct lvts_sensor *lvts_sensors = lvts_ctrl->sensors;
1079 struct thermal_zone_device *tz;
1083 * Bitmaps to enable each sensor on immediate and filtered modes, as
1084 * described in MSRCTL1 and MONCTL0 registers below, respectively.
1086 u32 sensor_imm_bitmap[] = { BIT(4), BIT(5), BIT(6), BIT(9) };
1087 u32 sensor_filt_bitmap[] = { BIT(0), BIT(1), BIT(2), BIT(3) };
1089 u32 *sensor_bitmap = lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE ?
1090 sensor_imm_bitmap : sensor_filt_bitmap;
1092 for (i = 0; i < lvts_ctrl->num_lvts_sensor; i++) {
1094 int dt_id = lvts_sensors[i].dt_id;
1096 tz = devm_thermal_of_zone_register(dev, dt_id, &lvts_sensors[i],
1100 * This thermal zone is not described in the
1101 * device tree. It is not an error from the
1102 * thermal OF code POV, we just continue.
1104 if (PTR_ERR(tz) == -ENODEV)
1110 devm_thermal_add_hwmon_sysfs(dev, tz);
1113 * The thermal zone pointer will be needed in the
1114 * interrupt handler, we store it in the sensor
1115 * structure. The thermal domain structure will be
1116 * passed to the interrupt handler private data as the
1117 * interrupt is shared for all the controller
1118 * belonging to the thermal domain.
1120 lvts_sensors[i].tz = tz;
1123 * This sensor was correctly associated with a thermal
1124 * zone, let's set the corresponding bit in the sensor
1125 * map, so we can enable the temperature monitoring in
1126 * the hardware thermal controller.
1128 sensor_map |= sensor_bitmap[i];
1132 * The initialization of the thermal zones give us
1133 * which sensor point to enable. If any thermal zone
1134 * was not described in the device tree, it won't be
1135 * enabled here in the sensor map.
1137 if (lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE) {
1139 * LVTS_MSRCTL1 : Measurement control
1143 * 9: Ignore MSRCTL0 config and do immediate measurement on sensor3
1144 * 6: Ignore MSRCTL0 config and do immediate measurement on sensor2
1145 * 5: Ignore MSRCTL0 config and do immediate measurement on sensor1
1146 * 4: Ignore MSRCTL0 config and do immediate measurement on sensor0
1148 * That configuration will ignore the filtering and the delays
1149 * introduced in MONCTL1 and MONCTL2
1151 writel(sensor_map, LVTS_MSRCTL1(lvts_ctrl->base));
1155 * 9: Single point access flow
1156 * 0-3: Enable sensing point 0-3
1158 writel(sensor_map | BIT(9), LVTS_MONCTL0(lvts_ctrl->base));
1164 static int lvts_domain_init(struct device *dev, struct lvts_domain *lvts_td,
1165 const struct lvts_data *lvts_data)
1167 struct lvts_ctrl *lvts_ctrl;
1170 ret = lvts_ctrl_init(dev, lvts_td, lvts_data);
1174 ret = lvts_domain_reset(dev, lvts_td->reset);
1176 dev_dbg(dev, "Failed to reset domain");
1180 for (i = 0; i < lvts_td->num_lvts_ctrl; i++) {
1182 lvts_ctrl = &lvts_td->lvts_ctrl[i];
1185 * Initialization steps:
1187 * - Enable the clock
1188 * - Connect to the LVTS
1189 * - Initialize the LVTS
1190 * - Prepare the calibration data
1191 * - Select monitored sensors
1192 * [ Configure sampling ]
1193 * [ Configure the interrupt ]
1194 * - Start measurement
1196 ret = lvts_ctrl_set_enable(lvts_ctrl, true);
1198 dev_dbg(dev, "Failed to enable LVTS clock");
1202 ret = lvts_ctrl_connect(dev, lvts_ctrl);
1204 dev_dbg(dev, "Failed to connect to LVTS controller");
1208 ret = lvts_ctrl_initialize(dev, lvts_ctrl);
1210 dev_dbg(dev, "Failed to initialize controller");
1214 ret = lvts_ctrl_calibrate(dev, lvts_ctrl);
1216 dev_dbg(dev, "Failed to calibrate controller");
1220 ret = lvts_ctrl_configure(dev, lvts_ctrl);
1222 dev_dbg(dev, "Failed to configure controller");
1226 ret = lvts_ctrl_start(dev, lvts_ctrl);
1228 dev_dbg(dev, "Failed to start controller");
1233 return lvts_debugfs_init(dev, lvts_td);
1236 static int lvts_probe(struct platform_device *pdev)
1238 const struct lvts_data *lvts_data;
1239 struct lvts_domain *lvts_td;
1240 struct device *dev = &pdev->dev;
1241 struct resource *res;
1244 lvts_td = devm_kzalloc(dev, sizeof(*lvts_td), GFP_KERNEL);
1248 lvts_data = of_device_get_match_data(dev);
1250 lvts_td->clk = devm_clk_get_enabled(dev, NULL);
1251 if (IS_ERR(lvts_td->clk))
1252 return dev_err_probe(dev, PTR_ERR(lvts_td->clk), "Failed to retrieve clock\n");
1254 res = platform_get_mem_or_io(pdev, 0);
1256 return dev_err_probe(dev, (-ENXIO), "No IO resource\n");
1258 lvts_td->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
1259 if (IS_ERR(lvts_td->base))
1260 return dev_err_probe(dev, PTR_ERR(lvts_td->base), "Failed to map io resource\n");
1262 lvts_td->reset = devm_reset_control_get_by_index(dev, 0);
1263 if (IS_ERR(lvts_td->reset))
1264 return dev_err_probe(dev, PTR_ERR(lvts_td->reset), "Failed to get reset control\n");
1266 irq = platform_get_irq(pdev, 0);
1270 golden_temp_offset = lvts_data->temp_offset;
1272 ret = lvts_domain_init(dev, lvts_td, lvts_data);
1274 return dev_err_probe(dev, ret, "Failed to initialize the lvts domain\n");
1277 * At this point the LVTS is initialized and enabled. We can
1278 * safely enable the interrupt.
1280 ret = devm_request_threaded_irq(dev, irq, NULL, lvts_irq_handler,
1281 IRQF_ONESHOT, dev_name(dev), lvts_td);
1283 return dev_err_probe(dev, ret, "Failed to request interrupt\n");
1285 platform_set_drvdata(pdev, lvts_td);
1290 static void lvts_remove(struct platform_device *pdev)
1292 struct lvts_domain *lvts_td;
1295 lvts_td = platform_get_drvdata(pdev);
1297 for (i = 0; i < lvts_td->num_lvts_ctrl; i++)
1298 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], false);
1300 lvts_debugfs_exit(lvts_td);
1303 static const struct lvts_ctrl_data mt7988_lvts_ap_data_ctrl[] = {
1305 .cal_offset = { 0x00, 0x04, 0x08, 0x0c },
1307 { .dt_id = MT7988_CPU_0 },
1308 { .dt_id = MT7988_CPU_1 },
1309 { .dt_id = MT7988_ETH2P5G_0 },
1310 { .dt_id = MT7988_ETH2P5G_1 }
1312 .num_lvts_sensor = 4,
1314 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT7988,
1317 .cal_offset = { 0x14, 0x18, 0x1c, 0x20 },
1319 { .dt_id = MT7988_TOPS_0},
1320 { .dt_id = MT7988_TOPS_1},
1321 { .dt_id = MT7988_ETHWARP_0},
1322 { .dt_id = MT7988_ETHWARP_1}
1324 .num_lvts_sensor = 4,
1326 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT7988,
1330 static int lvts_suspend(struct device *dev)
1332 struct lvts_domain *lvts_td;
1335 lvts_td = dev_get_drvdata(dev);
1337 for (i = 0; i < lvts_td->num_lvts_ctrl; i++)
1338 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], false);
1340 clk_disable_unprepare(lvts_td->clk);
1345 static int lvts_resume(struct device *dev)
1347 struct lvts_domain *lvts_td;
1350 lvts_td = dev_get_drvdata(dev);
1352 ret = clk_prepare_enable(lvts_td->clk);
1356 for (i = 0; i < lvts_td->num_lvts_ctrl; i++)
1357 lvts_ctrl_set_enable(&lvts_td->lvts_ctrl[i], true);
1362 static const struct lvts_ctrl_data mt8192_lvts_mcu_data_ctrl[] = {
1364 .cal_offset = { 0x04, 0x08 },
1366 { .dt_id = MT8192_MCU_BIG_CPU0 },
1367 { .dt_id = MT8192_MCU_BIG_CPU1 }
1369 .num_lvts_sensor = 2,
1371 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1372 .mode = LVTS_MSR_FILTERED_MODE,
1375 .cal_offset = { 0x0c, 0x10 },
1377 { .dt_id = MT8192_MCU_BIG_CPU2 },
1378 { .dt_id = MT8192_MCU_BIG_CPU3 }
1380 .num_lvts_sensor = 2,
1382 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1383 .mode = LVTS_MSR_FILTERED_MODE,
1386 .cal_offset = { 0x14, 0x18, 0x1c, 0x20 },
1388 { .dt_id = MT8192_MCU_LITTLE_CPU0 },
1389 { .dt_id = MT8192_MCU_LITTLE_CPU1 },
1390 { .dt_id = MT8192_MCU_LITTLE_CPU2 },
1391 { .dt_id = MT8192_MCU_LITTLE_CPU3 }
1393 .num_lvts_sensor = 4,
1395 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1396 .mode = LVTS_MSR_FILTERED_MODE,
1400 static const struct lvts_ctrl_data mt8192_lvts_ap_data_ctrl[] = {
1402 .cal_offset = { 0x24, 0x28 },
1404 { .dt_id = MT8192_AP_VPU0 },
1405 { .dt_id = MT8192_AP_VPU1 }
1407 .num_lvts_sensor = 2,
1409 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1412 .cal_offset = { 0x2c, 0x30 },
1414 { .dt_id = MT8192_AP_GPU0 },
1415 { .dt_id = MT8192_AP_GPU1 }
1417 .num_lvts_sensor = 2,
1419 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1422 .cal_offset = { 0x34, 0x38 },
1424 { .dt_id = MT8192_AP_INFRA },
1425 { .dt_id = MT8192_AP_CAM },
1427 .num_lvts_sensor = 2,
1429 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1432 .cal_offset = { 0x3c, 0x40, 0x44 },
1434 { .dt_id = MT8192_AP_MD0 },
1435 { .dt_id = MT8192_AP_MD1 },
1436 { .dt_id = MT8192_AP_MD2 }
1438 .num_lvts_sensor = 3,
1440 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8192,
1444 static const struct lvts_ctrl_data mt8195_lvts_mcu_data_ctrl[] = {
1446 .cal_offset = { 0x04, 0x07 },
1448 { .dt_id = MT8195_MCU_BIG_CPU0 },
1449 { .dt_id = MT8195_MCU_BIG_CPU1 }
1451 .num_lvts_sensor = 2,
1453 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1456 .cal_offset = { 0x0d, 0x10 },
1458 { .dt_id = MT8195_MCU_BIG_CPU2 },
1459 { .dt_id = MT8195_MCU_BIG_CPU3 }
1461 .num_lvts_sensor = 2,
1463 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1466 .cal_offset = { 0x16, 0x19, 0x1c, 0x1f },
1468 { .dt_id = MT8195_MCU_LITTLE_CPU0 },
1469 { .dt_id = MT8195_MCU_LITTLE_CPU1 },
1470 { .dt_id = MT8195_MCU_LITTLE_CPU2 },
1471 { .dt_id = MT8195_MCU_LITTLE_CPU3 }
1473 .num_lvts_sensor = 4,
1475 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1479 static const struct lvts_ctrl_data mt8195_lvts_ap_data_ctrl[] = {
1481 .cal_offset = { 0x25, 0x28 },
1483 { .dt_id = MT8195_AP_VPU0 },
1484 { .dt_id = MT8195_AP_VPU1 }
1486 .num_lvts_sensor = 2,
1488 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1491 .cal_offset = { 0x2e, 0x31 },
1493 { .dt_id = MT8195_AP_GPU0 },
1494 { .dt_id = MT8195_AP_GPU1 }
1496 .num_lvts_sensor = 2,
1498 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1501 .cal_offset = { 0x37, 0x3a, 0x3d },
1503 { .dt_id = MT8195_AP_VDEC },
1504 { .dt_id = MT8195_AP_IMG },
1505 { .dt_id = MT8195_AP_INFRA },
1507 .num_lvts_sensor = 3,
1509 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1512 .cal_offset = { 0x43, 0x46 },
1514 { .dt_id = MT8195_AP_CAM0 },
1515 { .dt_id = MT8195_AP_CAM1 }
1517 .num_lvts_sensor = 2,
1519 .hw_tshut_temp = LVTS_HW_SHUTDOWN_MT8195,
1523 static const struct lvts_data mt7988_lvts_ap_data = {
1524 .lvts_ctrl = mt7988_lvts_ap_data_ctrl,
1525 .num_lvts_ctrl = ARRAY_SIZE(mt7988_lvts_ap_data_ctrl),
1526 .temp_factor = LVTS_COEFF_A_MT7988,
1527 .temp_offset = LVTS_COEFF_B_MT7988,
1530 static const struct lvts_data mt8192_lvts_mcu_data = {
1531 .lvts_ctrl = mt8192_lvts_mcu_data_ctrl,
1532 .num_lvts_ctrl = ARRAY_SIZE(mt8192_lvts_mcu_data_ctrl),
1535 static const struct lvts_data mt8192_lvts_ap_data = {
1536 .lvts_ctrl = mt8192_lvts_ap_data_ctrl,
1537 .num_lvts_ctrl = ARRAY_SIZE(mt8192_lvts_ap_data_ctrl),
1540 static const struct lvts_data mt8195_lvts_mcu_data = {
1541 .lvts_ctrl = mt8195_lvts_mcu_data_ctrl,
1542 .num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_mcu_data_ctrl),
1543 .temp_factor = LVTS_COEFF_A_MT8195,
1544 .temp_offset = LVTS_COEFF_B_MT8195,
1547 static const struct lvts_data mt8195_lvts_ap_data = {
1548 .lvts_ctrl = mt8195_lvts_ap_data_ctrl,
1549 .num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_ap_data_ctrl),
1550 .temp_factor = LVTS_COEFF_A_MT8195,
1551 .temp_offset = LVTS_COEFF_B_MT8195,
1554 static const struct of_device_id lvts_of_match[] = {
1555 { .compatible = "mediatek,mt7988-lvts-ap", .data = &mt7988_lvts_ap_data },
1556 { .compatible = "mediatek,mt8192-lvts-mcu", .data = &mt8192_lvts_mcu_data },
1557 { .compatible = "mediatek,mt8192-lvts-ap", .data = &mt8192_lvts_ap_data },
1558 { .compatible = "mediatek,mt8195-lvts-mcu", .data = &mt8195_lvts_mcu_data },
1559 { .compatible = "mediatek,mt8195-lvts-ap", .data = &mt8195_lvts_ap_data },
1562 MODULE_DEVICE_TABLE(of, lvts_of_match);
1564 static const struct dev_pm_ops lvts_pm_ops = {
1565 NOIRQ_SYSTEM_SLEEP_PM_OPS(lvts_suspend, lvts_resume)
1568 static struct platform_driver lvts_driver = {
1569 .probe = lvts_probe,
1570 .remove_new = lvts_remove,
1572 .name = "mtk-lvts-thermal",
1573 .of_match_table = lvts_of_match,
1577 module_platform_driver(lvts_driver);
1579 MODULE_AUTHOR("Balsam CHIHI <bchihi@baylibre.com>");
1580 MODULE_DESCRIPTION("MediaTek LVTS Thermal Driver");
1581 MODULE_LICENSE("GPL");