thermal: rockchip: add temperature dump when panic
[firefly-linux-kernel-4.4.55.git] / drivers / thermal / rockchip_thermal.c
1 /*
2  * Copyright (c) 2014-2016, Fuzhou Rockchip Electronics Co., Ltd
3  * Caesar Wang <wxt@rock-chips.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14
15 #include <linux/clk.h>
16 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/io.h>
19 #include <linux/module.h>
20 #include <linux/of.h>
21 #include <linux/of_address.h>
22 #include <linux/of_irq.h>
23 #include <linux/platform_device.h>
24 #include <linux/regmap.h>
25 #include <linux/reset.h>
26 #include <linux/thermal.h>
27 #include <linux/mfd/syscon.h>
28 #include <linux/pinctrl/consumer.h>
29
30 /**
31  * If the temperature over a period of time High,
32  * the resulting TSHUT gave CRU module,let it reset the entire chip,
33  * or via GPIO give PMIC.
34  */
35 enum tshut_mode {
36         TSHUT_MODE_CRU = 0,
37         TSHUT_MODE_GPIO,
38 };
39
40 /**
41  * The system Temperature Sensors tshut(tshut) polarity
42  * the bit 8 is tshut polarity.
43  * 0: low active, 1: high active
44  */
45 enum tshut_polarity {
46         TSHUT_LOW_ACTIVE = 0,
47         TSHUT_HIGH_ACTIVE,
48 };
49
50 /**
51  * The system has two Temperature Sensors.
52  * sensor0 is for CPU, and sensor1 is for GPU.
53  */
54 enum sensor_id {
55         SENSOR_CPU = 0,
56         SENSOR_GPU,
57 };
58
59 /**
60  * The conversion table has the adc value and temperature.
61  * ADC_DECREMENT: the adc value is of diminishing.(e.g. rk3288_code_table)
62  * ADC_INCREMENT: the adc value is incremental.(e.g. rk3368_code_table)
63  */
64 enum adc_sort_mode {
65         ADC_DECREMENT = 0,
66         ADC_INCREMENT,
67 };
68
69 /**
70  * The max sensors is two in rockchip SoCs.
71  * Two sensors: CPU and GPU sensor.
72  */
73 #define SOC_MAX_SENSORS 2
74
75 /**
76  * struct chip_tsadc_table - hold information about chip-specific differences
77  * @id: conversion table
78  * @length: size of conversion table
79  * @data_mask: mask to apply on data inputs
80  * @mode: sort mode of this adc variant (incrementing or decrementing)
81  */
82 struct chip_tsadc_table {
83         const struct tsadc_table *id;
84         unsigned int length;
85         u32 data_mask;
86         enum adc_sort_mode mode;
87 };
88
89 /**
90  * struct rockchip_tsadc_chip - hold the private data of tsadc chip
91  * @chn_id[SOC_MAX_SENSORS]: the sensor id of chip correspond to the channel
92  * @chn_num: the channel number of tsadc chip
93  * @tshut_temp: the hardware-controlled shutdown temperature value
94  * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO)
95  * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
96  * @initialize: SoC special initialize tsadc controller method
97  * @irq_ack: clear the interrupt
98  * @get_temp: get the temperature
99  * @set_alarm_temp: set the high temperature interrupt
100  * @set_tshut_temp: set the hardware-controlled shutdown temperature
101  * @set_tshut_mode: set the hardware-controlled shutdown mode
102  * @table: the chip-specific conversion table
103  */
104 struct rockchip_tsadc_chip {
105         /* The sensor id of chip correspond to the ADC channel */
106         int chn_id[SOC_MAX_SENSORS];
107         int chn_num;
108
109         /* The hardware-controlled tshut property */
110         int tshut_temp;
111         enum tshut_mode tshut_mode;
112         enum tshut_polarity tshut_polarity;
113
114         /* Chip-wide methods */
115         void (*initialize)(struct regmap *grf,
116                            void __iomem *reg, enum tshut_polarity p);
117         void (*irq_ack)(void __iomem *reg);
118         void (*control)(void __iomem *reg, bool on);
119
120         /* Per-sensor methods */
121         int (*get_temp)(struct chip_tsadc_table table,
122                         int chn, void __iomem *reg, int *temp);
123         void (*set_alarm_temp)(struct chip_tsadc_table table,
124                                int chn, void __iomem *reg, int temp);
125         void (*set_tshut_temp)(struct chip_tsadc_table table,
126                                int chn, void __iomem *reg, int temp);
127         void (*set_tshut_mode)(int chn, void __iomem *reg, enum tshut_mode m);
128
129         /* Per-table methods */
130         struct chip_tsadc_table table;
131 };
132
133 /**
134  * struct rockchip_thermal_sensor - hold the information of thermal sensor
135  * @thermal:  pointer to the platform/configuration data
136  * @tzd: pointer to a thermal zone
137  * @id: identifier of the thermal sensor
138  */
139 struct rockchip_thermal_sensor {
140         struct rockchip_thermal_data *thermal;
141         struct thermal_zone_device *tzd;
142         int id;
143 };
144
145 /**
146  * struct rockchip_thermal_data - hold the private data of thermal driver
147  * @chip: pointer to the platform/configuration data
148  * @pdev: platform device of thermal
149  * @reset: the reset controller of tsadc
150  * @sensors[SOC_MAX_SENSORS]: the thermal sensor
151  * @clk: the controller clock is divided by the exteral 24MHz
152  * @pclk: the advanced peripherals bus clock
153  * @grf: the general register file will be used to do static set by software
154  * @regs: the base address of tsadc controller
155  * @tshut_temp: the hardware-controlled shutdown temperature value
156  * @tshut_mode: the hardware-controlled shutdown mode (0:CRU 1:GPIO)
157  * @tshut_polarity: the hardware-controlled active polarity (0:LOW 1:HIGH)
158  */
159 struct rockchip_thermal_data {
160         const struct rockchip_tsadc_chip *chip;
161         struct platform_device *pdev;
162         struct reset_control *reset;
163
164         struct rockchip_thermal_sensor sensors[SOC_MAX_SENSORS];
165
166         struct clk *clk;
167         struct clk *pclk;
168
169         struct regmap *grf;
170         void __iomem *regs;
171
172         int tshut_temp;
173         enum tshut_mode tshut_mode;
174         enum tshut_polarity tshut_polarity;
175 };
176
177 /**
178  * TSADC Sensor Register description:
179  *
180  * TSADCV2_* are used for RK3288 SoCs, the other chips can reuse it.
181  * TSADCV3_* are used for newer SoCs than RK3288. (e.g: RK3228, RK3399)
182  *
183  */
184 #define TSADCV2_USER_CON                        0x00
185 #define TSADCV2_AUTO_CON                        0x04
186 #define TSADCV2_INT_EN                          0x08
187 #define TSADCV2_INT_PD                          0x0c
188 #define TSADCV2_DATA(chn)                       (0x20 + (chn) * 0x04)
189 #define TSADCV2_COMP_INT(chn)                   (0x30 + (chn) * 0x04)
190 #define TSADCV2_COMP_SHUT(chn)                  (0x40 + (chn) * 0x04)
191 #define TSADCV2_HIGHT_INT_DEBOUNCE              0x60
192 #define TSADCV2_HIGHT_TSHUT_DEBOUNCE            0x64
193 #define TSADCV2_AUTO_PERIOD                     0x68
194 #define TSADCV2_AUTO_PERIOD_HT                  0x6c
195
196 #define TSADCV2_AUTO_EN                         BIT(0)
197 #define TSADCV2_AUTO_SRC_EN(chn)                BIT(4 + (chn))
198 #define TSADCV2_AUTO_TSHUT_POLARITY_HIGH        BIT(8)
199
200 #define TSADCV3_AUTO_Q_SEL_EN                   BIT(1)
201
202 #define TSADCV2_INT_SRC_EN(chn)                 BIT(chn)
203 #define TSADCV2_SHUT_2GPIO_SRC_EN(chn)          BIT(4 + (chn))
204 #define TSADCV2_SHUT_2CRU_SRC_EN(chn)           BIT(8 + (chn))
205
206 #define TSADCV2_INT_PD_CLEAR_MASK               ~BIT(8)
207 #define TSADCV3_INT_PD_CLEAR_MASK               ~BIT(16)
208
209 #define TSADCV2_DATA_MASK                       0xfff
210 #define TSADCV3_DATA_MASK                       0x3ff
211
212 #define TSADCV2_HIGHT_INT_DEBOUNCE_COUNT        4
213 #define TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT      4
214 #define TSADCV2_AUTO_PERIOD_TIME                250 /* 250ms */
215 #define TSADCV2_AUTO_PERIOD_HT_TIME             50  /* 50ms */
216 #define TSADCV3_AUTO_PERIOD_TIME                1875 /* 2.5ms */
217 #define TSADCV3_AUTO_PERIOD_HT_TIME             1875 /* 2.5ms */
218
219 #define TSADCV2_USER_INTER_PD_SOC               0x340 /* 13 clocks */
220
221 #define GRF_SARADC_TESTBIT                      0x0e644
222 #define GRF_TSADC_TESTBIT_L                     0x0e648
223 #define GRF_TSADC_TESTBIT_H                     0x0e64c
224
225 #define GRF_SARADC_TESTBIT_ON                   (0x10001 << 2)
226 #define GRF_TSADC_TESTBIT_H_ON                  (0x10001 << 2)
227 #define GRF_TSADC_VCM_EN_L                      (0x10001 << 7)
228 #define GRF_TSADC_VCM_EN_H                      (0x10001 << 7)
229
230 /**
231  * struct tsadc_table - code to temperature conversion table
232  * @code: the value of adc channel
233  * @temp: the temperature
234  * Note:
235  * code to temperature mapping of the temperature sensor is a piece wise linear
236  * curve.Any temperature, code faling between to 2 give temperatures can be
237  * linearly interpolated.
238  * Code to Temperature mapping should be updated based on manufacturer results.
239  */
240 struct tsadc_table {
241         u32 code;
242         int temp;
243 };
244
245 static const struct tsadc_table rk3228_code_table[] = {
246         {0, -40000},
247         {588, -40000},
248         {593, -35000},
249         {598, -30000},
250         {603, -25000},
251         {608, -20000},
252         {613, -15000},
253         {618, -10000},
254         {623, -5000},
255         {629, 0},
256         {634, 5000},
257         {639, 10000},
258         {644, 15000},
259         {649, 20000},
260         {654, 25000},
261         {660, 30000},
262         {665, 35000},
263         {670, 40000},
264         {675, 45000},
265         {681, 50000},
266         {686, 55000},
267         {691, 60000},
268         {696, 65000},
269         {702, 70000},
270         {707, 75000},
271         {712, 80000},
272         {717, 85000},
273         {723, 90000},
274         {728, 95000},
275         {733, 100000},
276         {738, 105000},
277         {744, 110000},
278         {749, 115000},
279         {754, 120000},
280         {760, 125000},
281         {TSADCV2_DATA_MASK, 125000},
282 };
283
284 static const struct tsadc_table rk3288_code_table[] = {
285         {TSADCV2_DATA_MASK, -40000},
286         {3800, -40000},
287         {3792, -35000},
288         {3783, -30000},
289         {3774, -25000},
290         {3765, -20000},
291         {3756, -15000},
292         {3747, -10000},
293         {3737, -5000},
294         {3728, 0},
295         {3718, 5000},
296         {3708, 10000},
297         {3698, 15000},
298         {3688, 20000},
299         {3678, 25000},
300         {3667, 30000},
301         {3656, 35000},
302         {3645, 40000},
303         {3634, 45000},
304         {3623, 50000},
305         {3611, 55000},
306         {3600, 60000},
307         {3588, 65000},
308         {3575, 70000},
309         {3563, 75000},
310         {3550, 80000},
311         {3537, 85000},
312         {3524, 90000},
313         {3510, 95000},
314         {3496, 100000},
315         {3482, 105000},
316         {3467, 110000},
317         {3452, 115000},
318         {3437, 120000},
319         {3421, 125000},
320 };
321
322 static const struct tsadc_table rk3368_code_table[] = {
323         {0, -40000},
324         {106, -40000},
325         {108, -35000},
326         {110, -30000},
327         {112, -25000},
328         {114, -20000},
329         {116, -15000},
330         {118, -10000},
331         {120, -5000},
332         {122, 0},
333         {124, 5000},
334         {126, 10000},
335         {128, 15000},
336         {130, 20000},
337         {132, 25000},
338         {134, 30000},
339         {136, 35000},
340         {138, 40000},
341         {140, 45000},
342         {142, 50000},
343         {144, 55000},
344         {146, 60000},
345         {148, 65000},
346         {150, 70000},
347         {152, 75000},
348         {154, 80000},
349         {156, 85000},
350         {158, 90000},
351         {160, 95000},
352         {162, 100000},
353         {163, 105000},
354         {165, 110000},
355         {167, 115000},
356         {169, 120000},
357         {171, 125000},
358         {TSADCV3_DATA_MASK, 125000},
359 };
360
361 static const struct tsadc_table rk3399_code_table[] = {
362         {0, -40000},
363         {402, -40000},
364         {410, -35000},
365         {419, -30000},
366         {427, -25000},
367         {436, -20000},
368         {444, -15000},
369         {453, -10000},
370         {461, -5000},
371         {470, 0},
372         {478, 5000},
373         {487, 10000},
374         {496, 15000},
375         {504, 20000},
376         {513, 25000},
377         {521, 30000},
378         {530, 35000},
379         {538, 40000},
380         {547, 45000},
381         {555, 50000},
382         {564, 55000},
383         {573, 60000},
384         {581, 65000},
385         {590, 70000},
386         {599, 75000},
387         {607, 80000},
388         {616, 85000},
389         {624, 90000},
390         {633, 95000},
391         {642, 100000},
392         {650, 105000},
393         {659, 110000},
394         {668, 115000},
395         {677, 120000},
396         {685, 125000},
397         {TSADCV3_DATA_MASK, 125000},
398 };
399
400 static u32 rk_tsadcv2_temp_to_code(struct chip_tsadc_table table,
401                                    int temp)
402 {
403         int high, low, mid;
404         u32 error = table.data_mask;
405
406         low = 0;
407         high = table.length - 1;
408         mid = (high + low) / 2;
409
410         /* Return mask code data when the temp is over table range */
411         if (temp < table.id[low].temp || temp > table.id[high].temp)
412                 goto exit;
413
414         while (low <= high) {
415                 if (temp == table.id[mid].temp)
416                         return table.id[mid].code;
417                 else if (temp < table.id[mid].temp)
418                         high = mid - 1;
419                 else
420                         low = mid + 1;
421                 mid = (low + high) / 2;
422         }
423
424 exit:
425         pr_err("%s: Invalid conversion table: code=%d, temperature=%d\n",
426                __func__, error, temp);
427
428         return error;
429 }
430
431 static int rk_tsadcv2_code_to_temp(struct chip_tsadc_table table, u32 code,
432                                    int *temp)
433 {
434         unsigned int low = 1;
435         unsigned int high = table.length - 1;
436         unsigned int mid = (low + high) / 2;
437         unsigned int num;
438         unsigned long denom;
439
440         WARN_ON(table.length < 2);
441
442         switch (table.mode) {
443         case ADC_DECREMENT:
444                 code &= table.data_mask;
445                 if (code < table.id[high].code)
446                         return -EAGAIN;         /* Incorrect reading */
447
448                 while (low <= high) {
449                         if (code >= table.id[mid].code &&
450                             code < table.id[mid - 1].code)
451                                 break;
452                         else if (code < table.id[mid].code)
453                                 low = mid + 1;
454                         else
455                                 high = mid - 1;
456
457                         mid = (low + high) / 2;
458                 }
459                 break;
460         case ADC_INCREMENT:
461                 code &= table.data_mask;
462                 if (code < table.id[low].code)
463                         return -EAGAIN;         /* Incorrect reading */
464
465                 while (low <= high) {
466                         if (code <= table.id[mid].code &&
467                             code > table.id[mid - 1].code)
468                                 break;
469                         else if (code > table.id[mid].code)
470                                 low = mid + 1;
471                         else
472                                 high = mid - 1;
473
474                         mid = (low + high) / 2;
475                 }
476                 break;
477         default:
478                 pr_err("%s: Invalid the conversion table mode=%d\n",
479                        __func__, table.mode);
480         }
481
482         /*
483          * The 5C granularity provided by the table is too much. Let's
484          * assume that the relationship between sensor readings and
485          * temperature between 2 table entries is linear and interpolate
486          * to produce less granular result.
487          */
488         num = table.id[mid].temp - table.id[mid - 1].temp;
489         num *= abs(table.id[mid - 1].code - code);
490         denom = abs(table.id[mid - 1].code - table.id[mid].code);
491         *temp = table.id[mid - 1].temp + (num / denom);
492
493         return 0;
494 }
495
496 /**
497  * rk_tsadcv2_initialize - initialize TASDC Controller.
498  *
499  * (1) Set TSADC_V2_AUTO_PERIOD:
500  *     Configure the interleave between every two accessing of
501  *     TSADC in normal operation.
502  *
503  * (2) Set TSADCV2_AUTO_PERIOD_HT:
504  *     Configure the interleave between every two accessing of
505  *     TSADC after the temperature is higher than COM_SHUT or COM_INT.
506  *
507  * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE:
508  *     If the temperature is higher than COMP_INT or COMP_SHUT for
509  *     "debounce" times, TSADC controller will generate interrupt or TSHUT.
510  */
511 static void rk_tsadcv2_initialize(struct regmap *grf, void __iomem *regs,
512                                   enum tshut_polarity tshut_polarity)
513 {
514         if (tshut_polarity == TSHUT_HIGH_ACTIVE)
515                 writel_relaxed(0U | TSADCV2_AUTO_TSHUT_POLARITY_HIGH,
516                                regs + TSADCV2_AUTO_CON);
517         else
518                 writel_relaxed(0U & ~TSADCV2_AUTO_TSHUT_POLARITY_HIGH,
519                                regs + TSADCV2_AUTO_CON);
520
521         writel_relaxed(TSADCV2_AUTO_PERIOD_TIME, regs + TSADCV2_AUTO_PERIOD);
522         writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_COUNT,
523                        regs + TSADCV2_HIGHT_INT_DEBOUNCE);
524         writel_relaxed(TSADCV2_AUTO_PERIOD_HT_TIME,
525                        regs + TSADCV2_AUTO_PERIOD_HT);
526         writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT,
527                        regs + TSADCV2_HIGHT_TSHUT_DEBOUNCE);
528
529         if (IS_ERR(grf)) {
530                 pr_warn("%s: Missing rockchip,grf property\n", __func__);
531                 return;
532         }
533 }
534
535 /**
536  * rk_tsadcv3_initialize - initialize TASDC Controller.
537  *
538  * (1) The tsadc control power sequence.
539  *
540  * (2) Set TSADC_V2_AUTO_PERIOD:
541  *     Configure the interleave between every two accessing of
542  *     TSADC in normal operation.
543  *
544  * (2) Set TSADCV2_AUTO_PERIOD_HT:
545  *     Configure the interleave between every two accessing of
546  *     TSADC after the temperature is higher than COM_SHUT or COM_INT.
547  *
548  * (3) Set TSADCV2_HIGH_INT_DEBOUNCE and TSADC_HIGHT_TSHUT_DEBOUNCE:
549  *     If the temperature is higher than COMP_INT or COMP_SHUT for
550  *     "debounce" times, TSADC controller will generate interrupt or TSHUT.
551  */
552 static void rk_tsadcv3_initialize(struct regmap *grf, void __iomem *regs,
553                                   enum tshut_polarity tshut_polarity)
554 {
555         /* The tsadc control power sequence */
556         if (IS_ERR(grf)) {
557                 /* Set interleave value to workround ic time sync issue */
558                 writel_relaxed(TSADCV2_USER_INTER_PD_SOC, regs +
559                                TSADCV2_USER_CON);
560
561                 writel_relaxed(TSADCV2_AUTO_PERIOD_TIME, regs + TSADCV2_AUTO_PERIOD);
562                 writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_COUNT,
563                                regs + TSADCV2_HIGHT_INT_DEBOUNCE);
564                 writel_relaxed(TSADCV2_AUTO_PERIOD_HT_TIME,
565                                regs + TSADCV2_AUTO_PERIOD_HT);
566                 writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT,
567                                regs + TSADCV2_HIGHT_TSHUT_DEBOUNCE);
568
569         } else {
570                 /* Enable the voltage common mode feature */
571                 regmap_write(grf, GRF_TSADC_TESTBIT_L, GRF_TSADC_VCM_EN_L);
572                 regmap_write(grf, GRF_TSADC_TESTBIT_H, GRF_TSADC_VCM_EN_H);
573
574                 udelay(100); /* The spec note says at least 15 us */
575                 regmap_write(grf, GRF_SARADC_TESTBIT, GRF_SARADC_TESTBIT_ON);
576                 regmap_write(grf, GRF_TSADC_TESTBIT_H, GRF_TSADC_TESTBIT_H_ON);
577                 udelay(200); /* The spec note says at least 90 us */
578
579                 writel_relaxed(TSADCV3_AUTO_PERIOD_TIME, regs + TSADCV2_AUTO_PERIOD);
580                 writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_COUNT,
581                                regs + TSADCV2_HIGHT_INT_DEBOUNCE);
582                 writel_relaxed(TSADCV3_AUTO_PERIOD_HT_TIME,
583                                regs + TSADCV2_AUTO_PERIOD_HT);
584                 writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT,
585                                regs + TSADCV2_HIGHT_TSHUT_DEBOUNCE);
586         }
587
588         if (tshut_polarity == TSHUT_HIGH_ACTIVE)
589                 writel_relaxed(0U | TSADCV2_AUTO_TSHUT_POLARITY_HIGH,
590                                regs + TSADCV2_AUTO_CON);
591         else
592                 writel_relaxed(0U & ~TSADCV2_AUTO_TSHUT_POLARITY_HIGH,
593                                regs + TSADCV2_AUTO_CON);
594 }
595
596 static void rk_tsadcv2_irq_ack(void __iomem *regs)
597 {
598         u32 val;
599
600         val = readl_relaxed(regs + TSADCV2_INT_PD);
601         writel_relaxed(val & TSADCV2_INT_PD_CLEAR_MASK, regs + TSADCV2_INT_PD);
602 }
603
604 static void rk_tsadcv3_irq_ack(void __iomem *regs)
605 {
606         u32 val;
607
608         val = readl_relaxed(regs + TSADCV2_INT_PD);
609         writel_relaxed(val & TSADCV3_INT_PD_CLEAR_MASK, regs + TSADCV2_INT_PD);
610 }
611
612 static void rk_tsadcv2_control(void __iomem *regs, bool enable)
613 {
614         u32 val;
615
616         val = readl_relaxed(regs + TSADCV2_AUTO_CON);
617         if (enable)
618                 val |= TSADCV2_AUTO_EN;
619         else
620                 val &= ~TSADCV2_AUTO_EN;
621
622         writel_relaxed(val, regs + TSADCV2_AUTO_CON);
623 }
624
625 /**
626  * rk_tsadcv3_control - the tsadc controller is enabled or disabled.
627  *
628  * NOTE: TSADC controller works at auto mode, and some SoCs need set the
629  * tsadc_q_sel bit on TSADCV2_AUTO_CON[1]. The (1024 - tsadc_q) as output
630  * adc value if setting this bit to enable.
631  */
632 static void rk_tsadcv3_control(void __iomem *regs, bool enable)
633 {
634         u32 val;
635
636         val = readl_relaxed(regs + TSADCV2_AUTO_CON);
637         if (enable)
638                 val |= TSADCV2_AUTO_EN | TSADCV3_AUTO_Q_SEL_EN;
639         else
640                 val &= ~TSADCV2_AUTO_EN;
641
642         writel_relaxed(val, regs + TSADCV2_AUTO_CON);
643 }
644
645 static int rk_tsadcv2_get_temp(struct chip_tsadc_table table,
646                                int chn, void __iomem *regs, int *temp)
647 {
648         u32 val;
649
650         val = readl_relaxed(regs + TSADCV2_DATA(chn));
651
652         return rk_tsadcv2_code_to_temp(table, val, temp);
653 }
654
655 static void rk_tsadcv2_alarm_temp(struct chip_tsadc_table table,
656                                   int chn, void __iomem *regs, int temp)
657 {
658         u32 alarm_value, int_en;
659
660         /* Make sure the value is valid */
661         alarm_value = rk_tsadcv2_temp_to_code(table, temp);
662         if (alarm_value == table.data_mask)
663                 return;
664
665         writel_relaxed(alarm_value & table.data_mask,
666                        regs + TSADCV2_COMP_INT(chn));
667
668         int_en = readl_relaxed(regs + TSADCV2_INT_EN);
669         int_en |= TSADCV2_INT_SRC_EN(chn);
670         writel_relaxed(int_en, regs + TSADCV2_INT_EN);
671 }
672
673 static void rk_tsadcv2_tshut_temp(struct chip_tsadc_table table,
674                                   int chn, void __iomem *regs, int temp)
675 {
676         u32 tshut_value, val;
677
678         /* Make sure the value is valid */
679         tshut_value = rk_tsadcv2_temp_to_code(table, temp);
680         if (tshut_value == table.data_mask)
681                 return;
682
683         writel_relaxed(tshut_value, regs + TSADCV2_COMP_SHUT(chn));
684
685         /* TSHUT will be valid */
686         val = readl_relaxed(regs + TSADCV2_AUTO_CON);
687         writel_relaxed(val | TSADCV2_AUTO_SRC_EN(chn), regs + TSADCV2_AUTO_CON);
688 }
689
690 static void rk_tsadcv2_tshut_mode(int chn, void __iomem *regs,
691                                   enum tshut_mode mode)
692 {
693         u32 val;
694
695         val = readl_relaxed(regs + TSADCV2_INT_EN);
696         if (mode == TSHUT_MODE_GPIO) {
697                 val &= ~TSADCV2_SHUT_2CRU_SRC_EN(chn);
698                 val |= TSADCV2_SHUT_2GPIO_SRC_EN(chn);
699         } else {
700                 val &= ~TSADCV2_SHUT_2GPIO_SRC_EN(chn);
701                 val |= TSADCV2_SHUT_2CRU_SRC_EN(chn);
702         }
703
704         writel_relaxed(val, regs + TSADCV2_INT_EN);
705 }
706
707 static const struct rockchip_tsadc_chip rk3228_tsadc_data = {
708         .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
709         .chn_num = 1, /* one channel for tsadc */
710
711         .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
712         .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
713         .tshut_temp = 95000,
714
715         .initialize = rk_tsadcv2_initialize,
716         .irq_ack = rk_tsadcv3_irq_ack,
717         .control = rk_tsadcv3_control,
718         .get_temp = rk_tsadcv2_get_temp,
719         .set_alarm_temp = rk_tsadcv2_alarm_temp,
720         .set_tshut_temp = rk_tsadcv2_tshut_temp,
721         .set_tshut_mode = rk_tsadcv2_tshut_mode,
722
723         .table = {
724                 .id = rk3228_code_table,
725                 .length = ARRAY_SIZE(rk3228_code_table),
726                 .data_mask = TSADCV3_DATA_MASK,
727                 .mode = ADC_INCREMENT,
728         },
729 };
730
731 static const struct rockchip_tsadc_chip rk3288_tsadc_data = {
732         .chn_id[SENSOR_CPU] = 1, /* cpu sensor is channel 1 */
733         .chn_id[SENSOR_GPU] = 2, /* gpu sensor is channel 2 */
734         .chn_num = 2, /* two channels for tsadc */
735
736         .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
737         .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
738         .tshut_temp = 95000,
739
740         .initialize = rk_tsadcv2_initialize,
741         .irq_ack = rk_tsadcv2_irq_ack,
742         .control = rk_tsadcv2_control,
743         .get_temp = rk_tsadcv2_get_temp,
744         .set_alarm_temp = rk_tsadcv2_alarm_temp,
745         .set_tshut_temp = rk_tsadcv2_tshut_temp,
746         .set_tshut_mode = rk_tsadcv2_tshut_mode,
747
748         .table = {
749                 .id = rk3288_code_table,
750                 .length = ARRAY_SIZE(rk3288_code_table),
751                 .data_mask = TSADCV2_DATA_MASK,
752                 .mode = ADC_DECREMENT,
753         },
754 };
755
756 static const struct rockchip_tsadc_chip rk3366_tsadc_data = {
757         .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
758         .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
759         .chn_num = 2, /* two channels for tsadc */
760
761         .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
762         .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
763         .tshut_temp = 95000,
764
765         .initialize = rk_tsadcv3_initialize,
766         .irq_ack = rk_tsadcv3_irq_ack,
767         .control = rk_tsadcv3_control,
768         .get_temp = rk_tsadcv2_get_temp,
769         .set_alarm_temp = rk_tsadcv2_alarm_temp,
770         .set_tshut_temp = rk_tsadcv2_tshut_temp,
771         .set_tshut_mode = rk_tsadcv2_tshut_mode,
772
773         .table = {
774                 .id = rk3228_code_table,
775                 .length = ARRAY_SIZE(rk3228_code_table),
776                 .data_mask = TSADCV3_DATA_MASK,
777                 .mode = ADC_INCREMENT,
778         },
779 };
780
781 static const struct rockchip_tsadc_chip rk3368_tsadc_data = {
782         .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
783         .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
784         .chn_num = 2, /* two channels for tsadc */
785
786         .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
787         .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
788         .tshut_temp = 95000,
789
790         .initialize = rk_tsadcv2_initialize,
791         .irq_ack = rk_tsadcv2_irq_ack,
792         .control = rk_tsadcv2_control,
793         .get_temp = rk_tsadcv2_get_temp,
794         .set_alarm_temp = rk_tsadcv2_alarm_temp,
795         .set_tshut_temp = rk_tsadcv2_tshut_temp,
796         .set_tshut_mode = rk_tsadcv2_tshut_mode,
797
798         .table = {
799                 .id = rk3368_code_table,
800                 .length = ARRAY_SIZE(rk3368_code_table),
801                 .data_mask = TSADCV3_DATA_MASK,
802                 .mode = ADC_INCREMENT,
803         },
804 };
805
806 static const struct rockchip_tsadc_chip rk3399_tsadc_data = {
807         .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */
808         .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */
809         .chn_num = 2, /* two channels for tsadc */
810
811         .tshut_mode = TSHUT_MODE_GPIO, /* default TSHUT via GPIO give PMIC */
812         .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */
813         .tshut_temp = 95000,
814
815         .initialize = rk_tsadcv3_initialize,
816         .irq_ack = rk_tsadcv3_irq_ack,
817         .control = rk_tsadcv3_control,
818         .get_temp = rk_tsadcv2_get_temp,
819         .set_alarm_temp = rk_tsadcv2_alarm_temp,
820         .set_tshut_temp = rk_tsadcv2_tshut_temp,
821         .set_tshut_mode = rk_tsadcv2_tshut_mode,
822
823         .table = {
824                 .id = rk3399_code_table,
825                 .length = ARRAY_SIZE(rk3399_code_table),
826                 .data_mask = TSADCV3_DATA_MASK,
827                 .mode = ADC_INCREMENT,
828         },
829 };
830
831 static const struct of_device_id of_rockchip_thermal_match[] = {
832         {
833                 .compatible = "rockchip,rk3228-tsadc",
834                 .data = (void *)&rk3228_tsadc_data,
835         },
836         {
837                 .compatible = "rockchip,rk3288-tsadc",
838                 .data = (void *)&rk3288_tsadc_data,
839         },
840         {
841                 .compatible = "rockchip,rk3366-tsadc",
842                 .data = (void *)&rk3366_tsadc_data,
843         },
844         {
845                 .compatible = "rockchip,rk3368-tsadc",
846                 .data = (void *)&rk3368_tsadc_data,
847         },
848         {
849                 .compatible = "rockchip,rk3399-tsadc",
850                 .data = (void *)&rk3399_tsadc_data,
851         },
852         { /* end */ },
853 };
854 MODULE_DEVICE_TABLE(of, of_rockchip_thermal_match);
855
856 static void
857 rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)
858 {
859         struct thermal_zone_device *tzd = sensor->tzd;
860
861         tzd->ops->set_mode(tzd,
862                 on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
863 }
864
865 static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)
866 {
867         struct rockchip_thermal_data *thermal = dev;
868         int i;
869
870         dev_dbg(&thermal->pdev->dev, "thermal alarm\n");
871
872         thermal->chip->irq_ack(thermal->regs);
873
874         for (i = 0; i < thermal->chip->chn_num; i++)
875                 thermal_zone_device_update(thermal->sensors[i].tzd);
876
877         return IRQ_HANDLED;
878 }
879
880 static int rockchip_thermal_set_trips(void *_sensor, int low, int high)
881 {
882         struct rockchip_thermal_sensor *sensor = _sensor;
883         struct rockchip_thermal_data *thermal = sensor->thermal;
884         const struct rockchip_tsadc_chip *tsadc = thermal->chip;
885
886         dev_dbg(&thermal->pdev->dev, "%s: sensor %d: low: %d, high %d\n",
887                 __func__, sensor->id, low, high);
888
889         tsadc->set_alarm_temp(tsadc->table,
890                               sensor->id, thermal->regs, high);
891
892         return 0;
893 }
894
895 static int rockchip_thermal_get_temp(void *_sensor, int *out_temp)
896 {
897         struct rockchip_thermal_sensor *sensor = _sensor;
898         struct rockchip_thermal_data *thermal = sensor->thermal;
899         const struct rockchip_tsadc_chip *tsadc = sensor->thermal->chip;
900         int retval;
901
902         retval = tsadc->get_temp(tsadc->table,
903                                  sensor->id, thermal->regs, out_temp);
904         dev_dbg(&thermal->pdev->dev, "sensor %d - temp: %d, retval: %d\n",
905                 sensor->id, *out_temp, retval);
906
907         return retval;
908 }
909
910 static const struct thermal_zone_of_device_ops rockchip_of_thermal_ops = {
911         .get_temp = rockchip_thermal_get_temp,
912         .set_trips = rockchip_thermal_set_trips,
913 };
914
915 static int rockchip_configure_from_dt(struct device *dev,
916                                       struct device_node *np,
917                                       struct rockchip_thermal_data *thermal)
918 {
919         u32 shut_temp, tshut_mode, tshut_polarity;
920
921         if (of_property_read_u32(np, "rockchip,hw-tshut-temp", &shut_temp)) {
922                 dev_warn(dev,
923                          "Missing tshut temp property, using default %d\n",
924                          thermal->chip->tshut_temp);
925                 thermal->tshut_temp = thermal->chip->tshut_temp;
926         } else {
927                 if (shut_temp > INT_MAX) {
928                         dev_err(dev, "Invalid tshut temperature specified: %d\n",
929                                 shut_temp);
930                         return -ERANGE;
931                 }
932                 thermal->tshut_temp = shut_temp;
933         }
934
935         if (of_property_read_u32(np, "rockchip,hw-tshut-mode", &tshut_mode)) {
936                 dev_warn(dev,
937                          "Missing tshut mode property, using default (%s)\n",
938                          thermal->chip->tshut_mode == TSHUT_MODE_GPIO ?
939                                 "gpio" : "cru");
940                 thermal->tshut_mode = thermal->chip->tshut_mode;
941         } else {
942                 thermal->tshut_mode = tshut_mode;
943         }
944
945         if (thermal->tshut_mode > 1) {
946                 dev_err(dev, "Invalid tshut mode specified: %d\n",
947                         thermal->tshut_mode);
948                 return -EINVAL;
949         }
950
951         if (of_property_read_u32(np, "rockchip,hw-tshut-polarity",
952                                  &tshut_polarity)) {
953                 dev_warn(dev,
954                          "Missing tshut-polarity property, using default (%s)\n",
955                          thermal->chip->tshut_polarity == TSHUT_LOW_ACTIVE ?
956                                 "low" : "high");
957                 thermal->tshut_polarity = thermal->chip->tshut_polarity;
958         } else {
959                 thermal->tshut_polarity = tshut_polarity;
960         }
961
962         if (thermal->tshut_polarity > 1) {
963                 dev_err(dev, "Invalid tshut-polarity specified: %d\n",
964                         thermal->tshut_polarity);
965                 return -EINVAL;
966         }
967
968         /* The tsadc wont to handle the error in here since some SoCs didn't
969          * need this property.
970          */
971         thermal->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
972
973         return 0;
974 }
975
976 static int
977 rockchip_thermal_register_sensor(struct platform_device *pdev,
978                                  struct rockchip_thermal_data *thermal,
979                                  struct rockchip_thermal_sensor *sensor,
980                                  int id)
981 {
982         const struct rockchip_tsadc_chip *tsadc = thermal->chip;
983         int error;
984
985         tsadc->set_tshut_mode(id, thermal->regs, thermal->tshut_mode);
986         tsadc->set_tshut_temp(tsadc->table, id, thermal->regs,
987                               thermal->tshut_temp);
988
989         sensor->thermal = thermal;
990         sensor->id = id;
991         sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, id,
992                                         sensor, &rockchip_of_thermal_ops);
993         if (IS_ERR(sensor->tzd)) {
994                 error = PTR_ERR(sensor->tzd);
995                 dev_err(&pdev->dev, "failed to register sensor %d: %d\n",
996                         id, error);
997                 return error;
998         }
999
1000         return 0;
1001 }
1002
1003 /**
1004  * Reset TSADC Controller, reset all tsadc registers.
1005  */
1006 static void rockchip_thermal_reset_controller(struct reset_control *reset)
1007 {
1008         reset_control_assert(reset);
1009         usleep_range(10, 20);
1010         reset_control_deassert(reset);
1011 }
1012
1013 static struct platform_device *thermal_device;
1014
1015 void rockchip_dump_temperature(void)
1016 {
1017         struct rockchip_thermal_data *thermal;
1018         struct platform_device *pdev;
1019         int i;
1020
1021         if (!thermal_device)
1022                 return;
1023
1024         pdev = thermal_device;
1025         thermal = platform_get_drvdata(pdev);
1026
1027         for (i = 0; i < thermal->chip->chn_num; i++) {
1028                 struct rockchip_thermal_sensor *sensor = &thermal->sensors[i];
1029                 struct thermal_zone_device *tz = sensor->tzd;
1030
1031                 if (tz->temperature != THERMAL_TEMP_INVALID)
1032                         dev_warn(&pdev->dev, "channal %d: temperature(%d C)\n",
1033                                  i, tz->temperature / 1000);
1034         }
1035
1036         if (thermal->regs) {
1037                 pr_warn("THERMAL REGS:\n");
1038                 print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET,
1039                                32, 4, thermal->regs, 0x88, false);
1040         }
1041 }
1042 EXPORT_SYMBOL_GPL(rockchip_dump_temperature);
1043
1044 static int rockchip_thermal_panic(struct notifier_block *this,
1045                                   unsigned long ev, void *ptr)
1046 {
1047         rockchip_dump_temperature();
1048         return NOTIFY_DONE;
1049 }
1050
1051 static struct notifier_block rockchip_thermal_panic_block = {
1052         .notifier_call = rockchip_thermal_panic,
1053 };
1054
1055 static int rockchip_thermal_probe(struct platform_device *pdev)
1056 {
1057         struct device_node *np = pdev->dev.of_node;
1058         struct rockchip_thermal_data *thermal;
1059         const struct of_device_id *match;
1060         struct resource *res;
1061         int irq;
1062         int i;
1063         int error;
1064
1065         match = of_match_node(of_rockchip_thermal_match, np);
1066         if (!match)
1067                 return -ENXIO;
1068
1069         irq = platform_get_irq(pdev, 0);
1070         if (irq < 0) {
1071                 dev_err(&pdev->dev, "no irq resource?\n");
1072                 return -EINVAL;
1073         }
1074
1075         thermal = devm_kzalloc(&pdev->dev, sizeof(struct rockchip_thermal_data),
1076                                GFP_KERNEL);
1077         if (!thermal)
1078                 return -ENOMEM;
1079
1080         thermal->pdev = pdev;
1081
1082         thermal->chip = (const struct rockchip_tsadc_chip *)match->data;
1083         if (!thermal->chip)
1084                 return -EINVAL;
1085
1086         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1087         thermal->regs = devm_ioremap_resource(&pdev->dev, res);
1088         if (IS_ERR(thermal->regs))
1089                 return PTR_ERR(thermal->regs);
1090
1091         thermal->reset = devm_reset_control_get(&pdev->dev, "tsadc-apb");
1092         if (IS_ERR(thermal->reset)) {
1093                 error = PTR_ERR(thermal->reset);
1094                 dev_err(&pdev->dev, "failed to get tsadc reset: %d\n", error);
1095                 return error;
1096         }
1097
1098         thermal->clk = devm_clk_get(&pdev->dev, "tsadc");
1099         if (IS_ERR(thermal->clk)) {
1100                 error = PTR_ERR(thermal->clk);
1101                 dev_err(&pdev->dev, "failed to get tsadc clock: %d\n", error);
1102                 return error;
1103         }
1104
1105         thermal->pclk = devm_clk_get(&pdev->dev, "apb_pclk");
1106         if (IS_ERR(thermal->pclk)) {
1107                 error = PTR_ERR(thermal->pclk);
1108                 dev_err(&pdev->dev, "failed to get apb_pclk clock: %d\n",
1109                         error);
1110                 return error;
1111         }
1112
1113         error = clk_prepare_enable(thermal->clk);
1114         if (error) {
1115                 dev_err(&pdev->dev, "failed to enable converter clock: %d\n",
1116                         error);
1117                 return error;
1118         }
1119
1120         error = clk_prepare_enable(thermal->pclk);
1121         if (error) {
1122                 dev_err(&pdev->dev, "failed to enable pclk: %d\n", error);
1123                 goto err_disable_clk;
1124         }
1125
1126         rockchip_thermal_reset_controller(thermal->reset);
1127
1128         error = rockchip_configure_from_dt(&pdev->dev, np, thermal);
1129         if (error) {
1130                 dev_err(&pdev->dev, "failed to parse device tree data: %d\n",
1131                         error);
1132                 goto err_disable_pclk;
1133         }
1134
1135         thermal->chip->initialize(thermal->grf, thermal->regs,
1136                                   thermal->tshut_polarity);
1137
1138         for (i = 0; i < thermal->chip->chn_num; i++) {
1139                 error = rockchip_thermal_register_sensor(pdev, thermal,
1140                                                 &thermal->sensors[i],
1141                                                 thermal->chip->chn_id[i]);
1142                 if (error) {
1143                         dev_err(&pdev->dev,
1144                                 "failed to register sensor[%d] : error = %d\n",
1145                                 i, error);
1146                         goto err_disable_pclk;
1147                 }
1148         }
1149
1150         error = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1151                                           &rockchip_thermal_alarm_irq_thread,
1152                                           IRQF_ONESHOT,
1153                                           "rockchip_thermal", thermal);
1154         if (error) {
1155                 dev_err(&pdev->dev,
1156                         "failed to request tsadc irq: %d\n", error);
1157                 goto err_disable_pclk;
1158         }
1159
1160         thermal->chip->control(thermal->regs, true);
1161
1162         for (i = 0; i < thermal->chip->chn_num; i++)
1163                 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
1164
1165         platform_set_drvdata(pdev, thermal);
1166
1167         thermal_device = pdev;
1168
1169         atomic_notifier_chain_register(&panic_notifier_list,
1170                                        &rockchip_thermal_panic_block);
1171
1172         return 0;
1173
1174 err_disable_pclk:
1175         clk_disable_unprepare(thermal->pclk);
1176 err_disable_clk:
1177         clk_disable_unprepare(thermal->clk);
1178
1179         return error;
1180 }
1181
1182 static int rockchip_thermal_remove(struct platform_device *pdev)
1183 {
1184         struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
1185         int i;
1186
1187         for (i = 0; i < thermal->chip->chn_num; i++) {
1188                 struct rockchip_thermal_sensor *sensor = &thermal->sensors[i];
1189
1190                 rockchip_thermal_toggle_sensor(sensor, false);
1191         }
1192
1193         thermal->chip->control(thermal->regs, false);
1194
1195         clk_disable_unprepare(thermal->pclk);
1196         clk_disable_unprepare(thermal->clk);
1197
1198         return 0;
1199 }
1200
1201 static int __maybe_unused rockchip_thermal_suspend(struct device *dev)
1202 {
1203         struct platform_device *pdev = to_platform_device(dev);
1204         struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
1205         int i;
1206
1207         for (i = 0; i < thermal->chip->chn_num; i++)
1208                 rockchip_thermal_toggle_sensor(&thermal->sensors[i], false);
1209
1210         thermal->chip->control(thermal->regs, false);
1211
1212         clk_disable(thermal->pclk);
1213         clk_disable(thermal->clk);
1214
1215         pinctrl_pm_select_sleep_state(dev);
1216
1217         return 0;
1218 }
1219
1220 static int __maybe_unused rockchip_thermal_resume(struct device *dev)
1221 {
1222         struct platform_device *pdev = to_platform_device(dev);
1223         struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
1224         int i;
1225         int error;
1226
1227         error = clk_enable(thermal->clk);
1228         if (error)
1229                 return error;
1230
1231         error = clk_enable(thermal->pclk);
1232         if (error) {
1233                 clk_disable(thermal->clk);
1234                 return error;
1235         }
1236
1237         rockchip_thermal_reset_controller(thermal->reset);
1238
1239         thermal->chip->initialize(thermal->grf, thermal->regs,
1240                                   thermal->tshut_polarity);
1241
1242         for (i = 0; i < thermal->chip->chn_num; i++) {
1243                 int id = thermal->sensors[i].id;
1244
1245                 thermal->chip->set_tshut_mode(id, thermal->regs,
1246                                               thermal->tshut_mode);
1247                 thermal->chip->set_tshut_temp(thermal->chip->table,
1248                                               id, thermal->regs,
1249                                               thermal->tshut_temp);
1250         }
1251
1252         thermal->chip->control(thermal->regs, true);
1253
1254         for (i = 0; i < thermal->chip->chn_num; i++)
1255                 rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
1256
1257         pinctrl_pm_select_default_state(dev);
1258
1259         return 0;
1260 }
1261
1262 static SIMPLE_DEV_PM_OPS(rockchip_thermal_pm_ops,
1263                          rockchip_thermal_suspend, rockchip_thermal_resume);
1264
1265 static struct platform_driver rockchip_thermal_driver = {
1266         .driver = {
1267                 .name = "rockchip-thermal",
1268                 .pm = &rockchip_thermal_pm_ops,
1269                 .of_match_table = of_rockchip_thermal_match,
1270         },
1271         .probe = rockchip_thermal_probe,
1272         .remove = rockchip_thermal_remove,
1273 };
1274
1275 module_platform_driver(rockchip_thermal_driver);
1276
1277 MODULE_DESCRIPTION("ROCKCHIP THERMAL Driver");
1278 MODULE_AUTHOR("Rockchip, Inc.");
1279 MODULE_LICENSE("GPL v2");
1280 MODULE_ALIAS("platform:rockchip-thermal");