/
armada_thermal.c
846 lines (679 loc) · 21.6 KB
/
armada_thermal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
/*
* Marvell Armada 370/XP thermal sensor driver
*
* Copyright (C) 2013 Marvell
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/device.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include <linux/thermal.h>
#include <linux/interrupt.h>
#define THERMAL_VALID_MASK 0x1
#define MCELSIUS(temp) ((temp) * 1000)
#define CELSIUS(temp) ((temp) / 1000)
/* Thermal Manager Control and Status Register */
#define PMU_TDC0_SW_RST_MASK (0x1 << 1)
#define PMU_TM_DISABLE_OFFS 0
#define PMU_TM_DISABLE_MASK (0x1 << PMU_TM_DISABLE_OFFS)
#define PMU_TDC0_REF_CAL_CNT_OFFS 11
#define PMU_TDC0_REF_CAL_CNT_MASK (0x1ff << PMU_TDC0_REF_CAL_CNT_OFFS)
#define PMU_TDC0_OTF_CAL_MASK (0x1 << 30)
#define PMU_TDC0_START_CAL_MASK (0x1 << 25)
#define A375_UNIT_CONTROL_SHIFT 27
#define A375_UNIT_CONTROL_MASK 0x7
#define A375_READOUT_INVERT BIT(15)
#define A375_HW_RESETn BIT(8)
#define TSEN_HW_RESET BIT(8)
#define TSEN_CONTROL_MSB_OFFSET 4
#define TSEN_TSEN_TC_TRIM_MASK 0x7
#define AP806_START BIT(0)
#define AP806_RESET BIT(1)
#define AP806_ENABLE BIT(2)
#define AP806_INIT_TIMEOUT 10
/* For AP806 TSEN output format is signed as a 2s complement number
ranging from-512 to +511*/
#define AP806_TSEN_OUTPUT_MSB 512
#define AP806_TSEN_OUTPUT_COMP 1024
#define AP806_TSEN_INT_MASK (0x1 << 22) /* Server Int Mask */
#define CP110_TSEN_INT_MASK (0x1 << 20) /* Server Int Mask */
#define TSEN_INT_SUM_MASK (0x1 << 1)
/* Statically defined overheat threshold Celsius */
#define THRESH_DEFAULT_TEMP 100
#define THRESH_DEFAULT_HYST 2
#define TSEN_THRESH_OFFSET 16
#define TSEN_THRESH_HYST_MASK 0x3
#define TSEN_THRESH_HYST_OFFSET 26
#define EXT_TSEN_THRESH_OFFSET 3
#define EXT_TSEN_THRESH_HYST_MASK 0x3
#define EXT_TSEN_THRESH_HYST_OFFSET 19
struct armada_thermal_data;
/* Marvell EBU Thermal Sensor Dev Structure */
struct armada_thermal_priv {
void __iomem *sensor;
void __iomem *control;
void __iomem *dfx;
struct armada_thermal_data *data;
struct platform_device *pdev;
};
struct armada_thermal_data {
/* Initialize the sensor */
void (*init_sensor)(struct platform_device *pdev,
struct armada_thermal_priv *);
/* Test for a valid sensor value (optional) */
bool (*is_valid)(struct armada_thermal_priv *);
/* overheat interrupt handler */
irqreturn_t (*temp_irq_handler)(int irq, void *data);
/* Formula coefficients: temp = (b + m * reg) / div */
unsigned long coef_b;
unsigned long coef_m;
unsigned long coef_div;
bool inverted;
/* Register shift and mask to access the sensor temperature */
unsigned int temp_shift;
unsigned int temp_mask;
unsigned int is_valid_shift;
/* DFX interrupt support (optional) */
bool dfx_interrupt;
/* for handling non-DT based thermal zones */
struct thermal_zone_device_ops *ops;
/* for handling DT based thermal zones */
struct thermal_zone_of_device_ops *ops_of;
};
inline unsigned int tsen_thresh_val_calc(unsigned int celsius_temp,
struct armada_thermal_data *data)
{
int thresh_val;
thresh_val = ((MCELSIUS(celsius_temp) * data->coef_div) +
data->coef_b) / data->coef_m;
return thresh_val & data->temp_mask;
}
inline unsigned int tsen_thresh_celsius_calc(int thresh_val,
int hyst, struct armada_thermal_data *data)
{
unsigned int mcelsius_temp;
mcelsius_temp = (((data->coef_m * (thresh_val + hyst)) -
data->coef_b) / data->coef_div);
return CELSIUS(mcelsius_temp);
}
inline unsigned int ap806_thresh_val_calc(unsigned int celsius_temp,
struct armada_thermal_data *data)
{
int thresh_val;
thresh_val = (int)((MCELSIUS(celsius_temp) * data->coef_div) -
data->coef_b) / (int)data->coef_m;
/* TSEN output format is signed as a 2s complement number
** ranging from-512 to +511. when MSB is set, need to
** calculate the complement number
*/
if (thresh_val < 0)
thresh_val += AP806_TSEN_OUTPUT_COMP;
return thresh_val & data->temp_mask;
}
inline unsigned int ap806_thresh_celsius_calc(int thresh_val, int hyst,
struct armada_thermal_data *data)
{
unsigned int mcelsius_temp;
/* This calculation is the opposite to the calculation done in
* ap806_thresh_val_calc(). In order to get the right result,
* need to revert the 2s complement calculation,
* which occurs when threshold bigger then TSEN max value(511).
*/
if (thresh_val >= AP806_TSEN_OUTPUT_MSB)
thresh_val -= AP806_TSEN_OUTPUT_COMP;
mcelsius_temp = (((data->coef_m * (thresh_val + hyst)) +
data->coef_b) / data->coef_div);
return CELSIUS(mcelsius_temp);
}
static void tsen_temp_set_threshold(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
int temp, reg, hyst;
unsigned int thresh;
struct armada_thermal_data *data = priv->data;
struct device_node *np = pdev->dev.of_node;
/* get threshold value from DT */
if (of_property_read_u32(np, "threshold", &thresh)) {
thresh = THRESH_DEFAULT_TEMP;
dev_warn(&pdev->dev, "no threshold in DT, using default\n");
}
/* get hysteresis value from DT */
if (of_property_read_u32(np, "hysteresis", &hyst)) {
hyst = THRESH_DEFAULT_HYST;
dev_warn(&pdev->dev, "no hysteresis in DT, using default\n");
}
temp = tsen_thresh_val_calc(thresh, data);
reg = readl_relaxed(priv->control + TSEN_CONTROL_MSB_OFFSET);
/* Set Threshold */
reg &= ~(data->temp_mask << TSEN_THRESH_OFFSET);
reg |= (temp << TSEN_THRESH_OFFSET);
/* Set Hysteresis */
reg &= ~(TSEN_THRESH_HYST_MASK << TSEN_THRESH_HYST_OFFSET);
reg |= (hyst << TSEN_THRESH_HYST_OFFSET);
writel(reg, priv->control + TSEN_CONTROL_MSB_OFFSET);
/* hysteresis calculation is 2^(2+n) */
hyst = 1 << (hyst + 2);
temp = tsen_thresh_val_calc(thresh, data);
dev_info(&pdev->dev, "Overheat threshold between %d..%d\n",
tsen_thresh_celsius_calc(temp, -hyst, data),
tsen_thresh_celsius_calc(temp, hyst, data));
}
static void ap806_temp_set_threshold(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
int temp, reg, hyst;
unsigned int thresh;
struct armada_thermal_data *data = priv->data;
struct device_node *np = pdev->dev.of_node;
/* get threshold value from DT */
if (of_property_read_u32(np, "threshold", &thresh)) {
thresh = THRESH_DEFAULT_TEMP;
dev_warn(&pdev->dev, "no threshold in DT, using default\n");
}
/* get hysteresis value from DT */
if (of_property_read_u32(np, "hysteresis", &hyst)) {
hyst = THRESH_DEFAULT_HYST;
dev_warn(&pdev->dev, "no hysteresis in DT, using default\n");
}
temp = ap806_thresh_val_calc(thresh, data);
pr_debug("armada_thermal: Threshold is %d Hyst is %d\n", thresh, hyst);
reg = readl_relaxed(priv->control + TSEN_CONTROL_MSB_OFFSET);
/* Set Threshold */
reg &= ~(data->temp_mask << EXT_TSEN_THRESH_OFFSET);
reg |= (temp << EXT_TSEN_THRESH_OFFSET);
/* Set Hysteresis */
reg &= ~(EXT_TSEN_THRESH_HYST_MASK << TSEN_THRESH_HYST_OFFSET);
reg |= (hyst << EXT_TSEN_THRESH_HYST_OFFSET);
writel(reg, priv->control + TSEN_CONTROL_MSB_OFFSET);
/* hysteresis calculation is 2^(2+n) */
hyst = 1 << (hyst + 2);
dev_info(&pdev->dev, "Overheat threshold between %d..%d\n",
ap806_thresh_celsius_calc(temp, -hyst, data),
ap806_thresh_celsius_calc(temp, hyst, data));
}
static void armadaxp_init_sensor(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
unsigned long reg;
reg = readl_relaxed(priv->control);
reg |= PMU_TDC0_OTF_CAL_MASK;
writel(reg, priv->control);
/* Reference calibration value */
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
writel(reg, priv->control);
/* Reset the sensor */
reg = readl_relaxed(priv->control);
writel((reg | PMU_TDC0_SW_RST_MASK), priv->control);
writel(reg, priv->control);
/* Enable the sensor */
reg = readl_relaxed(priv->sensor);
reg &= ~PMU_TM_DISABLE_MASK;
writel(reg, priv->sensor);
}
static void armada370_init_sensor(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
unsigned long reg;
reg = readl_relaxed(priv->control);
reg |= PMU_TDC0_OTF_CAL_MASK;
writel(reg, priv->control);
/* Reference calibration value */
reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
writel(reg, priv->control);
reg &= ~PMU_TDC0_START_CAL_MASK;
writel(reg, priv->control);
mdelay(10);
}
static void armada375_init_sensor(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
unsigned long reg;
reg = readl(priv->control + 4);
reg &= ~(A375_UNIT_CONTROL_MASK << A375_UNIT_CONTROL_SHIFT);
reg &= ~A375_READOUT_INVERT;
reg &= ~A375_HW_RESETn;
writel(reg, priv->control + 4);
mdelay(20);
reg |= A375_HW_RESETn;
writel(reg, priv->control + 4);
mdelay(50);
}
static void tsen_init_sensor(struct armada_thermal_priv *priv)
{
unsigned long reg = readl_relaxed(priv->control +
TSEN_CONTROL_MSB_OFFSET);
/* Reset hardware once */
if (!(reg & TSEN_HW_RESET)) {
reg |= TSEN_HW_RESET;
writel(reg, priv->control + TSEN_CONTROL_MSB_OFFSET);
mdelay(10);
}
/* set Tsen Tc Trim to correct default value (errata #132698) */
reg = readl_relaxed(priv->control);
reg &= ~TSEN_TSEN_TC_TRIM_MASK;
reg |= 0x3;
writel(reg, priv->control);
}
static void armada380_init_sensor(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
unsigned long reg;
/* start the sensor */
tsen_init_sensor(priv);
/* Set thresholds */
tsen_temp_set_threshold(pdev, priv);
/* Clear on Read DFX temperature irqs cause */
reg = readl_relaxed(priv->dfx + 0x10);
/* Unmask DFX Temperature overheat and cooldown irqs */
reg = readl_relaxed(priv->dfx + 0x14);
reg |= (0x3 << 1);
writel(reg, priv->dfx + 0x14);
/* Unmask DFX Server irq */
reg = readl_relaxed(priv->dfx + 0x4);
reg |= (0x3 << 1);
writel(reg, priv->dfx + 0x4);
}
static void armada_ap806_init_sensor(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
unsigned int timeout;
unsigned long reg = readl_relaxed(priv->control);
reg &= ~AP806_RESET;
reg |= AP806_START;
reg |= AP806_ENABLE;
writel(reg, priv->control);
timeout = AP806_INIT_TIMEOUT;
if (priv->data->is_valid) {
do {
mdelay(10);
if (priv->data->is_valid(priv))
break;
timeout--;
} while (timeout != 0);
}
/* Set thresholds */
ap806_temp_set_threshold(pdev, priv);
/* Clear on Read DFX temperature irqs cause */
reg = readl_relaxed(priv->dfx + 0x8);
/* Unmask DFX Temperature overheat and cooldown irqs */
reg = readl_relaxed(priv->dfx + 0xC);
reg |= AP806_TSEN_INT_MASK;
writel(reg, priv->dfx + 0xC);
/* Unmask DFX Server irq */
reg = readl_relaxed(priv->dfx + 0x4);
reg |= TSEN_INT_SUM_MASK;
writel(reg, priv->dfx + 0x4);
}
static void cp110_init_sensor(struct platform_device *pdev,
struct armada_thermal_priv *priv)
{
unsigned long reg;
/* start the sensor */
tsen_init_sensor(priv);
/* Set thresholds */
tsen_temp_set_threshold(pdev, priv);
/* Clear on Read DFX temperature irqs cause */
reg = readl_relaxed(priv->dfx + 0x8);
/* Unmask DFX Temperature overheat and cooldown irqs */
reg = readl_relaxed(priv->dfx + 0xC);
reg |= CP110_TSEN_INT_MASK;
writel(reg, priv->dfx + 0xC);
/* Unmask DFX Server irq */
reg = readl_relaxed(priv->dfx + 0x4);
reg |= TSEN_INT_SUM_MASK;
writel(reg, priv->dfx + 0x4);
}
static bool armada_is_valid(struct armada_thermal_priv *priv)
{
unsigned long reg = readl_relaxed(priv->sensor);
return (reg >> priv->data->is_valid_shift) & THERMAL_VALID_MASK;
}
static int armada_get_temp(struct thermal_zone_device *thermal,
int *temp)
{
struct armada_thermal_priv *priv = thermal->devdata;
unsigned long reg;
long m, b, div;
/* Valid check */
if (priv->data->is_valid && !priv->data->is_valid(priv)) {
dev_err(&thermal->device,
"Temperature sensor reading not valid\n");
return -EIO;
}
reg = readl_relaxed(priv->sensor);
reg = (reg >> priv->data->temp_shift) & priv->data->temp_mask;
/* Get formula coeficients */
b = priv->data->coef_b;
m = priv->data->coef_m;
div = priv->data->coef_div;
if (priv->data->inverted)
*temp = ((m * (long)reg) - b) / div;
else
*temp = (b - (m * (long)reg)) / div;
return 0;
}
static int armada_ap806_get_temp(void *thermal_priv, int *temp)
{
struct armada_thermal_priv *priv = (struct armada_thermal_priv *)thermal_priv;
unsigned long reg;
unsigned long m, b, div;
/* Valid check */
if (priv->data->is_valid && !priv->data->is_valid(priv)) {
dev_err(&(priv->pdev->dev),
"Temperature sensor reading not valid\n");
return -EIO;
}
reg = readl_relaxed(priv->sensor);
reg = (reg >> priv->data->temp_shift) & priv->data->temp_mask;
/* TSEN output format is signed as a 2s complement number
ranging from-512 to +511. when MSB is set, need to
calculate the complement number */
if (reg >= AP806_TSEN_OUTPUT_MSB)
reg = reg - AP806_TSEN_OUTPUT_COMP;
/* Get formula coefficients */
b = priv->data->coef_b;
m = priv->data->coef_m;
div = priv->data->coef_div;
*temp = ((m * reg) + b) / div;
return 0;
}
static int armada_cp110_get_temp(struct thermal_zone_device *thermal, int *temp)
{
struct armada_thermal_priv *priv = thermal->devdata;
unsigned long reg;
long m, b, div;
/* Valid check */
if (priv->data->is_valid && !priv->data->is_valid(priv)) {
dev_err(&thermal->device,
"Temperature sensor reading not valid\n");
return -EIO;
}
reg = readl_relaxed(priv->sensor);
reg = (reg >> priv->data->temp_shift) & priv->data->temp_mask;
/* Get formula coefficients */
b = priv->data->coef_b;
m = priv->data->coef_m;
div = priv->data->coef_div;
*temp = ((m * (long)reg) - b) / div;
return 0;
}
static struct thermal_zone_device_ops armada_ops = {
.get_temp = armada_get_temp,
};
static struct thermal_zone_of_device_ops armada_ap806_ops = {
.get_temp = armada_ap806_get_temp,
};
static struct thermal_zone_device_ops armada_cp110_ops = {
.get_temp = armada_cp110_get_temp,
};
static irqreturn_t a38x_temp_irq_handler(int irq, void *data)
{
struct armada_thermal_priv *priv = (struct armada_thermal_priv *)data;
struct device *dev = &priv->pdev->dev;
u32 reg;
/* Mask Temp irq */
reg = readl_relaxed(priv->dfx + 0x14);
reg &= ~(0x3 << 1);
writel(reg, priv->dfx + 0x14);
/* Clear Temp irq cause */
reg = readl_relaxed(priv->dfx + 0x10);
if (reg & (0x3 << 1))
dev_warn(dev, "Overheat critical %s threshold temperature reached\n",
(reg & (1 << 1)) ? "high" : "low");
/* UnMask Temp irq */
reg = readl_relaxed(priv->dfx + 0x14);
reg |= (0x3 << 1);
writel(reg, priv->dfx + 0x14);
return IRQ_HANDLED;
}
static irqreturn_t ap806_temp_irq_handler(int irq, void *data)
{
struct armada_thermal_priv *priv = (struct armada_thermal_priv *)data;
struct device *dev = &priv->pdev->dev;
u32 reg;
/* Mask Temp irq */
reg = readl_relaxed(priv->dfx + 0xC);
reg &= ~AP806_TSEN_INT_MASK;
writel(reg, priv->dfx + 0xC);
/* Read & Clear Temp irq cause */
reg = readl_relaxed(priv->dfx + 0x8);
if (reg & AP806_TSEN_INT_MASK)
dev_warn(dev, "Overheat critical high threshold temperature reached\n");
/* UnMask Temp irq */
reg = readl_relaxed(priv->dfx + 0xC);
reg |= AP806_TSEN_INT_MASK;
writel(reg, priv->dfx + 0xC);
return IRQ_HANDLED;
}
irqreturn_t cp110_temp_irq_handler(int irq, void *data)
{
struct armada_thermal_priv *priv = (struct armada_thermal_priv *)data;
struct device *dev = &priv->pdev->dev;
u32 reg;
/* Mask Temp irq */
reg = readl_relaxed(priv->dfx + 0xC);
reg &= ~CP110_TSEN_INT_MASK;
writel(reg, priv->dfx + 0xC);
/* Clear Temp irq cause */
reg = readl_relaxed(priv->dfx + 0x8);
if (reg & CP110_TSEN_INT_MASK)
dev_warn(dev, "Overheat critical high threshold temperature reached\n");
/* UnMask Temp irq */
reg = readl_relaxed(priv->dfx + 0xC);
reg |= CP110_TSEN_INT_MASK;
writel(reg, priv->dfx + 0xC);
return IRQ_HANDLED;
}
static const struct armada_thermal_data armadaxp_data = {
.init_sensor = armadaxp_init_sensor,
.temp_shift = 10,
.temp_mask = 0x1ff,
.coef_b = 3153000000UL,
.coef_m = 10000000UL,
.coef_div = 13825,
.ops = &armada_ops,
};
static const struct armada_thermal_data armada370_data = {
.is_valid = armada_is_valid,
.init_sensor = armada370_init_sensor,
.is_valid_shift = 9,
.temp_shift = 10,
.temp_mask = 0x1ff,
.coef_b = 3153000000UL,
.coef_m = 10000000UL,
.coef_div = 13825,
.ops = &armada_ops,
};
static const struct armada_thermal_data armada375_data = {
.is_valid = armada_is_valid,
.init_sensor = armada375_init_sensor,
.is_valid_shift = 10,
.temp_shift = 0,
.temp_mask = 0x1ff,
.coef_b = 3171900000UL,
.coef_m = 10000000UL,
.coef_div = 13616,
.ops = &armada_ops,
};
static const struct armada_thermal_data armada380_data = {
.is_valid = armada_is_valid,
.init_sensor = armada380_init_sensor,
.temp_irq_handler = a38x_temp_irq_handler,
.is_valid_shift = 10,
.temp_shift = 0,
.temp_mask = 0x3ff,
.coef_b = 1172499100UL,
.coef_m = 2000096UL,
.coef_div = 4201,
.inverted = true,
.dfx_interrupt = 1,
.ops = &armada_ops,
};
static const struct armada_thermal_data armada_ap806_data = {
.is_valid = armada_is_valid,
.init_sensor = armada_ap806_init_sensor,
.temp_irq_handler = ap806_temp_irq_handler,
.is_valid_shift = 16,
.temp_shift = 0,
.temp_mask = 0x3ff,
.coef_b = 153400,
.coef_m = 425,
.coef_div = 1,
.inverted = true,
.dfx_interrupt = 1,
.ops_of = &armada_ap806_ops,
};
static const struct armada_thermal_data armada_cp110_data = {
.is_valid = armada_is_valid,
.init_sensor = cp110_init_sensor,
.temp_irq_handler = cp110_temp_irq_handler,
.is_valid_shift = 10,
.temp_shift = 0,
.temp_mask = 0x3ff,
.coef_b = 2791000UL,
.coef_m = 4761UL,
.coef_div = 10,
.inverted = true,
.dfx_interrupt = 1,
.ops = &armada_cp110_ops,
};
static const struct of_device_id armada_thermal_id_table[] = {
{
.compatible = "marvell,armadaxp-thermal",
.data = &armadaxp_data,
},
{
.compatible = "marvell,armada370-thermal",
.data = &armada370_data,
},
{
.compatible = "marvell,armada375-thermal",
.data = &armada375_data,
},
{
.compatible = "marvell,armada380-thermal",
.data = &armada380_data,
},
{
.compatible = "marvell,armada-ap806-thermal",
.data = &armada_ap806_data,
},
{
.compatible = "marvell,armada-cp110-thermal",
.data = &armada_cp110_data,
},
{
/* sentinel */
},
};
MODULE_DEVICE_TABLE(of, armada_thermal_id_table);
static int armada_thermal_probe(struct platform_device *pdev)
{
struct thermal_zone_device *thermal;
const struct of_device_id *match;
struct armada_thermal_priv *priv;
struct resource *res;
int irq;
match = of_match_device(armada_thermal_id_table, &pdev->dev);
if (!match)
return -ENODEV;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
/* Register device in thermal data structure */
priv->pdev = pdev;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
priv->sensor = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->sensor))
return PTR_ERR(priv->sensor);
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
priv->control = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->control))
return PTR_ERR(priv->control);
priv->data = (struct armada_thermal_data *)match->data;
if (priv->data->dfx_interrupt) {
/* DFX interrupts are supported by some of the devices */
res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
priv->dfx = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->dfx))
return PTR_ERR(priv->dfx);
}
/* Init sensor */
priv->data->init_sensor(pdev, priv);
/*
* AP806 thermal sensor registers as a sensor of a Device Tree thermal zone,
* so it's binded differently from rest of thermal sensors supported by this driver.
*/
if (of_device_is_compatible(pdev->dev.of_node,
"marvell,armada-ap806-thermal"))
thermal = thermal_zone_of_sensor_register(&pdev->dev, 0, priv, &armada_ap806_ops);
else
thermal = thermal_zone_device_register("armada_thermal", 0, 0,
priv, priv->data->ops, NULL, 0, 0);
if (IS_ERR(thermal)) {
dev_err(&pdev->dev,
"Failed to register thermal zone device\n");
return PTR_ERR(thermal);
}
/* Register overheat interrupt */
irq = platform_get_irq(pdev, 0);
if (irq >= 0) {
if (priv->data->temp_irq_handler == NULL)
dev_warn(&pdev->dev, "Interrupt handler was not implemented.\n");
/* Register handler */
if (devm_request_irq(&pdev->dev, irq, priv->data->temp_irq_handler,
0, pdev->name, priv) < 0)
dev_warn(&pdev->dev, "Interrupt %d is not available.\n", irq);
} else {
pr_debug("armada_thermal: no irq was assigned\n");
}
platform_set_drvdata(pdev, thermal);
return 0;
}
static int armada_thermal_exit(struct platform_device *pdev)
{
struct thermal_zone_device *armada_thermal =
platform_get_drvdata(pdev);
thermal_zone_device_unregister(armada_thermal);
return 0;
}
static int armada_thermal_resume(struct platform_device *pdev)
{
struct thermal_zone_device *thermal =
platform_get_drvdata(pdev);
struct armada_thermal_priv *priv = thermal->devdata;
priv->data->init_sensor(pdev, priv);
return 0;
}
static struct platform_driver armada_thermal_driver = {
.probe = armada_thermal_probe,
.remove = armada_thermal_exit,
#ifdef CONFIG_PM
.resume = armada_thermal_resume,
#endif
.driver = {
.name = "armada_thermal",
.of_match_table = armada_thermal_id_table,
},
};
module_platform_driver(armada_thermal_driver);
MODULE_AUTHOR("Ezequiel Garcia <ezequiel.garcia@free-electrons.com>");
MODULE_DESCRIPTION("Armada 370/380/XP/70x0/80x0 thermal driver");
MODULE_LICENSE("GPL v2");