38
38
#define TEMP_MONIDET0 0x014
39
39
#define TEMP_MONIDET1 0x018
40
40
#define TEMP_MSRCTL0 0x038
41
+ #define TEMP_MSRCTL1 0x03c
41
42
#define TEMP_AHBPOLL 0x040
42
43
#define TEMP_AHBTO 0x044
43
44
#define TEMP_ADCPNP0 0x048
133
134
#define CALIB_BUF0_O_SLOPE_SIGN_V1 (x ) (((x) >> 7) & 0x1)
134
135
#define CALIB_BUF1_ID_V1 (x ) (((x) >> 9) & 0x1)
135
136
137
+ /*
138
+ * Layout of the fuses providing the calibration data
139
+ * These macros could be used for MT7622.
140
+ */
141
+ #define CALIB_BUF0_ADC_OE_V2 (x ) (((x) >> 22) & 0x3ff)
142
+ #define CALIB_BUF0_ADC_GE_V2 (x ) (((x) >> 12) & 0x3ff)
143
+ #define CALIB_BUF0_DEGC_CALI_V2 (x ) (((x) >> 6) & 0x3f)
144
+ #define CALIB_BUF0_O_SLOPE_V2 (x ) (((x) >> 0) & 0x3f)
145
+ #define CALIB_BUF1_VTS_TS1_V2 (x ) (((x) >> 23) & 0x1ff)
146
+ #define CALIB_BUF1_VTS_TS2_V2 (x ) (((x) >> 14) & 0x1ff)
147
+ #define CALIB_BUF1_VTS_TSABB_V2 (x ) (((x) >> 5) & 0x1ff)
148
+ #define CALIB_BUF1_VALID_V2 (x ) (((x) >> 4) & 0x1)
149
+ #define CALIB_BUF1_O_SLOPE_SIGN_V2 (x ) (((x) >> 3) & 0x1)
150
+
136
151
enum {
137
152
VTS1 ,
138
153
VTS2 ,
@@ -143,6 +158,11 @@ enum {
143
158
MAX_NUM_VTS ,
144
159
};
145
160
161
+ enum mtk_thermal_version {
162
+ MTK_THERMAL_V1 = 1 ,
163
+ MTK_THERMAL_V2 ,
164
+ };
165
+
146
166
/* MT2701 thermal sensors */
147
167
#define MT2701_TS1 0
148
168
#define MT2701_TS2 1
@@ -245,6 +265,7 @@ struct mtk_thermal_data {
245
265
const int * controller_offset ;
246
266
bool need_switch_bank ;
247
267
struct thermal_bank_cfg bank_data [MAX_NUM_ZONES ];
268
+ enum mtk_thermal_version version ;
248
269
};
249
270
250
271
struct mtk_thermal {
@@ -258,8 +279,10 @@ struct mtk_thermal {
258
279
259
280
/* Calibration values */
260
281
s32 adc_ge ;
282
+ s32 adc_oe ;
261
283
s32 degc_cali ;
262
284
s32 o_slope ;
285
+ s32 o_slope_sign ;
263
286
s32 vts [MAX_NUM_VTS ];
264
287
265
288
const struct mtk_thermal_data * conf ;
@@ -398,6 +421,7 @@ static const struct mtk_thermal_data mt8173_thermal_data = {
398
421
.msr = mt8173_msr ,
399
422
.adcpnp = mt8173_adcpnp ,
400
423
.sensor_mux_values = mt8173_mux_values ,
424
+ .version = MTK_THERMAL_V1 ,
401
425
};
402
426
403
427
/*
@@ -428,6 +452,7 @@ static const struct mtk_thermal_data mt2701_thermal_data = {
428
452
.msr = mt2701_msr ,
429
453
.adcpnp = mt2701_adcpnp ,
430
454
.sensor_mux_values = mt2701_mux_values ,
455
+ .version = MTK_THERMAL_V1 ,
431
456
};
432
457
433
458
/*
@@ -458,6 +483,7 @@ static const struct mtk_thermal_data mt2712_thermal_data = {
458
483
.msr = mt2712_msr ,
459
484
.adcpnp = mt2712_adcpnp ,
460
485
.sensor_mux_values = mt2712_mux_values ,
486
+ .version = MTK_THERMAL_V1 ,
461
487
};
462
488
463
489
/*
@@ -482,6 +508,7 @@ static const struct mtk_thermal_data mt7622_thermal_data = {
482
508
.msr = mt7622_msr ,
483
509
.adcpnp = mt7622_adcpnp ,
484
510
.sensor_mux_values = mt7622_mux_values ,
511
+ .version = MTK_THERMAL_V2 ,
485
512
};
486
513
487
514
/*
@@ -514,6 +541,7 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
514
541
.msr = mt8183_msr ,
515
542
.adcpnp = mt8183_adcpnp ,
516
543
.sensor_mux_values = mt8183_mux_values ,
544
+ .version = MTK_THERMAL_V1 ,
517
545
};
518
546
519
547
/**
@@ -540,6 +568,36 @@ static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw)
540
568
return mt -> degc_cali * 500 - tmp ;
541
569
}
542
570
571
+ static int raw_to_mcelsius_v2 (struct mtk_thermal * mt , int sensno , s32 raw )
572
+ {
573
+ s32 format_1 = 0 ;
574
+ s32 format_2 = 0 ;
575
+ s32 g_oe = 1 ;
576
+ s32 g_gain = 1 ;
577
+ s32 g_x_roomt = 0 ;
578
+ s32 tmp = 0 ;
579
+
580
+ if (raw == 0 )
581
+ return 0 ;
582
+
583
+ raw &= 0xfff ;
584
+ g_gain = 10000 + (((mt -> adc_ge - 512 ) * 10000 ) >> 12 );
585
+ g_oe = mt -> adc_oe - 512 ;
586
+ format_1 = mt -> vts [VTS2 ] + 3105 - g_oe ;
587
+ format_2 = (mt -> degc_cali * 10 ) >> 1 ;
588
+ g_x_roomt = (((format_1 * 10000 ) >> 12 ) * 10000 ) / g_gain ;
589
+
590
+ tmp = (((((raw - g_oe ) * 10000 ) >> 12 ) * 10000 ) / g_gain ) - g_x_roomt ;
591
+ tmp = tmp * 10 * 100 / 11 ;
592
+
593
+ if (mt -> o_slope_sign == 0 )
594
+ tmp = tmp / (165 - mt -> o_slope );
595
+ else
596
+ tmp = tmp / (165 + mt -> o_slope );
597
+
598
+ return (format_2 - tmp ) * 100 ;
599
+ }
600
+
543
601
/**
544
602
* mtk_thermal_get_bank - get bank
545
603
* @bank: The bank
@@ -594,9 +652,13 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
594
652
raw = readl (mt -> thermal_base +
595
653
conf -> msr [conf -> bank_data [bank -> id ].sensors [i ]]);
596
654
597
- temp = raw_to_mcelsius_v1 (mt ,
598
- conf -> bank_data [bank -> id ].sensors [i ],
599
- raw );
655
+ if (mt -> conf -> version == MTK_THERMAL_V1 ) {
656
+ temp = raw_to_mcelsius_v1 (
657
+ mt , conf -> bank_data [bank -> id ].sensors [i ], raw );
658
+ } else {
659
+ temp = raw_to_mcelsius_v2 (
660
+ mt , conf -> bank_data [bank -> id ].sensors [i ], raw );
661
+ }
600
662
601
663
/*
602
664
* The first read of a sensor often contains very high bogus
@@ -698,9 +760,11 @@ static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num,
698
760
writel (auxadc_phys_base + AUXADC_CON1_CLR_V ,
699
761
controller_base + TEMP_ADCMUXADDR );
700
762
701
- /* AHB address for pnp sensor mux selection */
702
- writel (apmixed_phys_base + APMIXED_SYS_TS_CON1 ,
703
- controller_base + TEMP_PNPMUXADDR );
763
+ if (mt -> conf -> version == MTK_THERMAL_V1 ) {
764
+ /* AHB address for pnp sensor mux selection */
765
+ writel (apmixed_phys_base + APMIXED_SYS_TS_CON1 ,
766
+ controller_base + TEMP_PNPMUXADDR );
767
+ }
704
768
705
769
/* AHB value for auxadc enable */
706
770
writel (BIT (conf -> auxadc_channel ), controller_base + TEMP_ADCEN );
@@ -803,6 +867,23 @@ static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf)
803
867
return 0 ;
804
868
}
805
869
870
+ static int mtk_thermal_extract_efuse_v2 (struct mtk_thermal * mt , u32 * buf )
871
+ {
872
+ if (!CALIB_BUF1_VALID_V2 (buf [1 ]))
873
+ return - EINVAL ;
874
+
875
+ mt -> adc_oe = CALIB_BUF0_ADC_OE_V2 (buf [0 ]);
876
+ mt -> adc_ge = CALIB_BUF0_ADC_GE_V2 (buf [0 ]);
877
+ mt -> degc_cali = CALIB_BUF0_DEGC_CALI_V2 (buf [0 ]);
878
+ mt -> o_slope = CALIB_BUF0_O_SLOPE_V2 (buf [0 ]);
879
+ mt -> vts [VTS1 ] = CALIB_BUF1_VTS_TS1_V2 (buf [1 ]);
880
+ mt -> vts [VTS2 ] = CALIB_BUF1_VTS_TS2_V2 (buf [1 ]);
881
+ mt -> vts [VTSABB ] = CALIB_BUF1_VTS_TSABB_V2 (buf [1 ]);
882
+ mt -> o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V2 (buf [1 ]);
883
+
884
+ return 0 ;
885
+ }
886
+
806
887
static int mtk_thermal_get_calibration_data (struct device * dev ,
807
888
struct mtk_thermal * mt )
808
889
{
@@ -838,8 +919,15 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
838
919
goto out ;
839
920
}
840
921
841
- if (mtk_thermal_extract_efuse_v1 (mt , buf ))
922
+ if (mt -> conf -> version == MTK_THERMAL_V1 )
923
+ ret = mtk_thermal_extract_efuse_v1 (mt , buf );
924
+ else
925
+ ret = mtk_thermal_extract_efuse_v2 (mt , buf );
926
+
927
+ if (ret ) {
842
928
dev_info (dev , "Device not calibrated, using default calibration values\n" );
929
+ ret = 0 ;
930
+ }
843
931
844
932
out :
845
933
kfree (buf );
@@ -872,6 +960,28 @@ static const struct of_device_id mtk_thermal_of_match[] = {
872
960
};
873
961
MODULE_DEVICE_TABLE (of , mtk_thermal_of_match );
874
962
963
+ static void mtk_thermal_turn_on_buffer (void __iomem * apmixed_base )
964
+ {
965
+ int tmp ;
966
+
967
+ tmp = readl (apmixed_base + APMIXED_SYS_TS_CON1 );
968
+ tmp &= ~(0x37 );
969
+ tmp |= 0x1 ;
970
+ writel (tmp , apmixed_base + APMIXED_SYS_TS_CON1 );
971
+ udelay (200 );
972
+ }
973
+
974
+ static void mtk_thermal_release_periodic_ts (struct mtk_thermal * mt ,
975
+ void __iomem * auxadc_base )
976
+ {
977
+ int tmp ;
978
+
979
+ writel (0x800 , auxadc_base + AUXADC_CON1_SET_V );
980
+ writel (0x1 , mt -> thermal_base + TEMP_MONCTL0 );
981
+ tmp = readl (mt -> thermal_base + TEMP_MSRCTL1 );
982
+ writel ((tmp & (~0x10e )), mt -> thermal_base + TEMP_MSRCTL1 );
983
+ }
984
+
875
985
static int mtk_thermal_probe (struct platform_device * pdev )
876
986
{
877
987
int ret , i , ctrl_id ;
@@ -880,6 +990,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
880
990
struct resource * res ;
881
991
u64 auxadc_phys_base , apmixed_phys_base ;
882
992
struct thermal_zone_device * tzdev ;
993
+ void __iomem * apmixed_base , * auxadc_base ;
883
994
884
995
mt = devm_kzalloc (& pdev -> dev , sizeof (* mt ), GFP_KERNEL );
885
996
if (!mt )
@@ -914,6 +1025,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
914
1025
return - ENODEV ;
915
1026
}
916
1027
1028
+ auxadc_base = of_iomap (auxadc , 0 );
917
1029
auxadc_phys_base = of_get_phys_base (auxadc );
918
1030
919
1031
of_node_put (auxadc );
@@ -929,6 +1041,7 @@ static int mtk_thermal_probe(struct platform_device *pdev)
929
1041
return - ENODEV ;
930
1042
}
931
1043
1044
+ apmixed_base = of_iomap (apmixedsys , 0 );
932
1045
apmixed_phys_base = of_get_phys_base (apmixedsys );
933
1046
934
1047
of_node_put (apmixedsys );
@@ -954,6 +1067,11 @@ static int mtk_thermal_probe(struct platform_device *pdev)
954
1067
goto err_disable_clk_auxadc ;
955
1068
}
956
1069
1070
+ if (mt -> conf -> version == MTK_THERMAL_V2 ) {
1071
+ mtk_thermal_turn_on_buffer (apmixed_base );
1072
+ mtk_thermal_release_periodic_ts (mt , auxadc_base );
1073
+ }
1074
+
957
1075
for (ctrl_id = 0 ; ctrl_id < mt -> conf -> num_controller ; ctrl_id ++ )
958
1076
for (i = 0 ; i < mt -> conf -> num_banks ; i ++ )
959
1077
mtk_thermal_init_bank (mt , i , apmixed_phys_base ,
0 commit comments