150
150
#define CALIB_BUF1_VALID_V2 (x ) (((x) >> 4) & 0x1)
151
151
#define CALIB_BUF1_O_SLOPE_SIGN_V2 (x ) (((x) >> 3) & 0x1)
152
152
153
+ /*
154
+ * Layout of the fuses providing the calibration data
155
+ * These macros can be used for MT7981 and MT7986.
156
+ */
157
+ #define CALIB_BUF0_ADC_GE_V3 (x ) (((x) >> 0) & 0x3ff)
158
+ #define CALIB_BUF0_DEGC_CALI_V3 (x ) (((x) >> 20) & 0x3f)
159
+ #define CALIB_BUF0_O_SLOPE_V3 (x ) (((x) >> 26) & 0x3f)
160
+ #define CALIB_BUF1_VTS_TS1_V3 (x ) (((x) >> 0) & 0x1ff)
161
+ #define CALIB_BUF1_VTS_TS2_V3 (x ) (((x) >> 21) & 0x1ff)
162
+ #define CALIB_BUF1_VTS_TSABB_V3 (x ) (((x) >> 9) & 0x1ff)
163
+ #define CALIB_BUF1_VALID_V3 (x ) (((x) >> 18) & 0x1)
164
+ #define CALIB_BUF1_O_SLOPE_SIGN_V3 (x ) (((x) >> 19) & 0x1)
165
+ #define CALIB_BUF1_ID_V3 (x ) (((x) >> 20) & 0x1)
166
+
153
167
enum {
154
168
VTS1 ,
155
169
VTS2 ,
@@ -163,6 +177,7 @@ enum {
163
177
enum mtk_thermal_version {
164
178
MTK_THERMAL_V1 = 1 ,
165
179
MTK_THERMAL_V2 ,
180
+ MTK_THERMAL_V3 ,
166
181
};
167
182
168
183
/* MT2701 thermal sensors */
@@ -245,6 +260,27 @@ enum mtk_thermal_version {
245
260
/* The calibration coefficient of sensor */
246
261
#define MT8183_CALIBRATION 153
247
262
263
+ /* AUXADC channel 11 is used for the temperature sensors */
264
+ #define MT7986_TEMP_AUXADC_CHANNEL 11
265
+
266
+ /* The total number of temperature sensors in the MT7986 */
267
+ #define MT7986_NUM_SENSORS 1
268
+
269
+ /* The number of banks in the MT7986 */
270
+ #define MT7986_NUM_ZONES 1
271
+
272
+ /* The number of sensing points per bank */
273
+ #define MT7986_NUM_SENSORS_PER_ZONE 1
274
+
275
+ /* MT7986 thermal sensors */
276
+ #define MT7986_TS1 0
277
+
278
+ /* The number of controller in the MT7986 */
279
+ #define MT7986_NUM_CONTROLLER 1
280
+
281
+ /* The calibration coefficient of sensor */
282
+ #define MT7986_CALIBRATION 165
283
+
248
284
struct mtk_thermal ;
249
285
250
286
struct thermal_bank_cfg {
@@ -388,6 +424,14 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, };
388
424
static const int mt7622_vts_index [MT7622_NUM_SENSORS ] = { VTS1 };
389
425
static const int mt7622_tc_offset [MT7622_NUM_CONTROLLER ] = { 0x0 , };
390
426
427
+ /* MT7986 thermal sensor data */
428
+ static const int mt7986_bank_data [MT7986_NUM_SENSORS ] = { MT7986_TS1 , };
429
+ static const int mt7986_msr [MT7986_NUM_SENSORS_PER_ZONE ] = { TEMP_MSR0 , };
430
+ static const int mt7986_adcpnp [MT7986_NUM_SENSORS_PER_ZONE ] = { TEMP_ADCPNP0 , };
431
+ static const int mt7986_mux_values [MT7986_NUM_SENSORS ] = { 0 , };
432
+ static const int mt7986_vts_index [MT7986_NUM_SENSORS ] = { VTS1 };
433
+ static const int mt7986_tc_offset [MT7986_NUM_CONTROLLER ] = { 0x0 , };
434
+
391
435
/*
392
436
* The MT8173 thermal controller has four banks. Each bank can read up to
393
437
* four temperature sensors simultaneously. The MT8173 has a total of 5
@@ -551,6 +595,30 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
551
595
.version = MTK_THERMAL_V1 ,
552
596
};
553
597
598
+ /*
599
+ * MT7986 uses AUXADC Channel 11 for raw data access.
600
+ */
601
+ static const struct mtk_thermal_data mt7986_thermal_data = {
602
+ .auxadc_channel = MT7986_TEMP_AUXADC_CHANNEL ,
603
+ .num_banks = MT7986_NUM_ZONES ,
604
+ .num_sensors = MT7986_NUM_SENSORS ,
605
+ .vts_index = mt7986_vts_index ,
606
+ .cali_val = MT7986_CALIBRATION ,
607
+ .num_controller = MT7986_NUM_CONTROLLER ,
608
+ .controller_offset = mt7986_tc_offset ,
609
+ .need_switch_bank = true,
610
+ .bank_data = {
611
+ {
612
+ .num_sensors = 1 ,
613
+ .sensors = mt7986_bank_data ,
614
+ },
615
+ },
616
+ .msr = mt7986_msr ,
617
+ .adcpnp = mt7986_adcpnp ,
618
+ .sensor_mux_values = mt7986_mux_values ,
619
+ .version = MTK_THERMAL_V3 ,
620
+ };
621
+
554
622
/**
555
623
* raw_to_mcelsius_v1 - convert a raw ADC value to mcelsius
556
624
* @mt: The thermal controller
@@ -605,6 +673,22 @@ static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw)
605
673
return (format_2 - tmp ) * 100 ;
606
674
}
607
675
676
+ static int raw_to_mcelsius_v3 (struct mtk_thermal * mt , int sensno , s32 raw )
677
+ {
678
+ s32 tmp ;
679
+
680
+ if (raw == 0 )
681
+ return 0 ;
682
+
683
+ raw &= 0xfff ;
684
+ tmp = 100000 * 15 / 16 * 10000 ;
685
+ tmp /= 4096 - 512 + mt -> adc_ge ;
686
+ tmp /= 1490 ;
687
+ tmp *= raw - mt -> vts [sensno ] - 2900 ;
688
+
689
+ return mt -> degc_cali * 500 - tmp ;
690
+ }
691
+
608
692
/**
609
693
* mtk_thermal_get_bank - get bank
610
694
* @bank: The bank
@@ -885,6 +969,25 @@ static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf)
885
969
return 0 ;
886
970
}
887
971
972
+ static int mtk_thermal_extract_efuse_v3 (struct mtk_thermal * mt , u32 * buf )
973
+ {
974
+ if (!CALIB_BUF1_VALID_V3 (buf [1 ]))
975
+ return - EINVAL ;
976
+
977
+ mt -> adc_ge = CALIB_BUF0_ADC_GE_V3 (buf [0 ]);
978
+ mt -> degc_cali = CALIB_BUF0_DEGC_CALI_V3 (buf [0 ]);
979
+ mt -> o_slope = CALIB_BUF0_O_SLOPE_V3 (buf [0 ]);
980
+ mt -> vts [VTS1 ] = CALIB_BUF1_VTS_TS1_V3 (buf [1 ]);
981
+ mt -> vts [VTS2 ] = CALIB_BUF1_VTS_TS2_V3 (buf [1 ]);
982
+ mt -> vts [VTSABB ] = CALIB_BUF1_VTS_TSABB_V3 (buf [1 ]);
983
+ mt -> o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V3 (buf [1 ]);
984
+
985
+ if (CALIB_BUF1_ID_V3 (buf [1 ]) == 0 )
986
+ mt -> o_slope = 0 ;
987
+
988
+ return 0 ;
989
+ }
990
+
888
991
static int mtk_thermal_get_calibration_data (struct device * dev ,
889
992
struct mtk_thermal * mt )
890
993
{
@@ -895,6 +998,7 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
895
998
896
999
/* Start with default values */
897
1000
mt -> adc_ge = 512 ;
1001
+ mt -> adc_oe = 512 ;
898
1002
for (i = 0 ; i < mt -> conf -> num_sensors ; i ++ )
899
1003
mt -> vts [i ] = 260 ;
900
1004
mt -> degc_cali = 40 ;
@@ -920,10 +1024,20 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
920
1024
goto out ;
921
1025
}
922
1026
923
- if (mt -> conf -> version == MTK_THERMAL_V1 )
1027
+ switch (mt -> conf -> version ) {
1028
+ case MTK_THERMAL_V1 :
924
1029
ret = mtk_thermal_extract_efuse_v1 (mt , buf );
925
- else
1030
+ break ;
1031
+ case MTK_THERMAL_V2 :
926
1032
ret = mtk_thermal_extract_efuse_v2 (mt , buf );
1033
+ break ;
1034
+ case MTK_THERMAL_V3 :
1035
+ ret = mtk_thermal_extract_efuse_v3 (mt , buf );
1036
+ break ;
1037
+ default :
1038
+ ret = - EINVAL ;
1039
+ break ;
1040
+ }
927
1041
928
1042
if (ret ) {
929
1043
dev_info (dev , "Device not calibrated, using default calibration values\n" );
@@ -953,6 +1067,10 @@ static const struct of_device_id mtk_thermal_of_match[] = {
953
1067
.compatible = "mediatek,mt7622-thermal" ,
954
1068
.data = (void * )& mt7622_thermal_data ,
955
1069
},
1070
+ {
1071
+ .compatible = "mediatek,mt7986-thermal" ,
1072
+ .data = (void * )& mt7986_thermal_data ,
1073
+ },
956
1074
{
957
1075
.compatible = "mediatek,mt8183-thermal" ,
958
1076
.data = (void * )& mt8183_thermal_data ,
@@ -1066,15 +1184,17 @@ static int mtk_thermal_probe(struct platform_device *pdev)
1066
1184
goto err_disable_clk_auxadc ;
1067
1185
}
1068
1186
1069
- if (mt -> conf -> version == MTK_THERMAL_V2 ) {
1187
+ if (mt -> conf -> version != MTK_THERMAL_V1 ) {
1070
1188
mtk_thermal_turn_on_buffer (apmixed_base );
1071
1189
mtk_thermal_release_periodic_ts (mt , auxadc_base );
1072
1190
}
1073
1191
1074
1192
if (mt -> conf -> version == MTK_THERMAL_V1 )
1075
1193
mt -> raw_to_mcelsius = raw_to_mcelsius_v1 ;
1076
- else
1194
+ else if ( mt -> conf -> version == MTK_THERMAL_V2 )
1077
1195
mt -> raw_to_mcelsius = raw_to_mcelsius_v2 ;
1196
+ else
1197
+ mt -> raw_to_mcelsius = raw_to_mcelsius_v3 ;
1078
1198
1079
1199
for (ctrl_id = 0 ; ctrl_id < mt -> conf -> num_controller ; ctrl_id ++ )
1080
1200
for (i = 0 ; i < mt -> conf -> num_banks ; i ++ )
0 commit comments