150150#define CALIB_BUF1_VALID_V2 (x ) (((x) >> 4) & 0x1)
151151#define CALIB_BUF1_O_SLOPE_SIGN_V2 (x ) (((x) >> 3) & 0x1)
152152
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+
153167enum {
154168 VTS1 ,
155169 VTS2 ,
@@ -163,6 +177,7 @@ enum {
163177enum mtk_thermal_version {
164178 MTK_THERMAL_V1 = 1 ,
165179 MTK_THERMAL_V2 ,
180+ MTK_THERMAL_V3 ,
166181};
167182
168183/* MT2701 thermal sensors */
@@ -245,6 +260,27 @@ enum mtk_thermal_version {
245260/* The calibration coefficient of sensor */
246261#define MT8183_CALIBRATION 153
247262
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+
248284struct mtk_thermal ;
249285
250286struct thermal_bank_cfg {
@@ -388,6 +424,14 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, };
388424static const int mt7622_vts_index [MT7622_NUM_SENSORS ] = { VTS1 };
389425static const int mt7622_tc_offset [MT7622_NUM_CONTROLLER ] = { 0x0 , };
390426
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+
391435/*
392436 * The MT8173 thermal controller has four banks. Each bank can read up to
393437 * four temperature sensors simultaneously. The MT8173 has a total of 5
@@ -551,6 +595,30 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
551595 .version = MTK_THERMAL_V1 ,
552596};
553597
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+
554622/**
555623 * raw_to_mcelsius_v1 - convert a raw ADC value to mcelsius
556624 * @mt: The thermal controller
@@ -605,6 +673,22 @@ static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw)
605673 return (format_2 - tmp ) * 100 ;
606674}
607675
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+
608692/**
609693 * mtk_thermal_get_bank - get bank
610694 * @bank: The bank
@@ -885,6 +969,25 @@ static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf)
885969 return 0 ;
886970}
887971
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+
888991static int mtk_thermal_get_calibration_data (struct device * dev ,
889992 struct mtk_thermal * mt )
890993{
@@ -895,6 +998,7 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
895998
896999 /* Start with default values */
8971000 mt -> adc_ge = 512 ;
1001+ mt -> adc_oe = 512 ;
8981002 for (i = 0 ; i < mt -> conf -> num_sensors ; i ++ )
8991003 mt -> vts [i ] = 260 ;
9001004 mt -> degc_cali = 40 ;
@@ -920,10 +1024,20 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
9201024 goto out ;
9211025 }
9221026
923- if (mt -> conf -> version == MTK_THERMAL_V1 )
1027+ switch (mt -> conf -> version ) {
1028+ case MTK_THERMAL_V1 :
9241029 ret = mtk_thermal_extract_efuse_v1 (mt , buf );
925- else
1030+ break ;
1031+ case MTK_THERMAL_V2 :
9261032 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+ }
9271041
9281042 if (ret ) {
9291043 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[] = {
9531067 .compatible = "mediatek,mt7622-thermal" ,
9541068 .data = (void * )& mt7622_thermal_data ,
9551069 },
1070+ {
1071+ .compatible = "mediatek,mt7986-thermal" ,
1072+ .data = (void * )& mt7986_thermal_data ,
1073+ },
9561074 {
9571075 .compatible = "mediatek,mt8183-thermal" ,
9581076 .data = (void * )& mt8183_thermal_data ,
@@ -1066,15 +1184,17 @@ static int mtk_thermal_probe(struct platform_device *pdev)
10661184 goto err_disable_clk_auxadc ;
10671185 }
10681186
1069- if (mt -> conf -> version == MTK_THERMAL_V2 ) {
1187+ if (mt -> conf -> version != MTK_THERMAL_V1 ) {
10701188 mtk_thermal_turn_on_buffer (apmixed_base );
10711189 mtk_thermal_release_periodic_ts (mt , auxadc_base );
10721190 }
10731191
10741192 if (mt -> conf -> version == MTK_THERMAL_V1 )
10751193 mt -> raw_to_mcelsius = raw_to_mcelsius_v1 ;
1076- else
1194+ else if ( mt -> conf -> version == MTK_THERMAL_V2 )
10771195 mt -> raw_to_mcelsius = raw_to_mcelsius_v2 ;
1196+ else
1197+ mt -> raw_to_mcelsius = raw_to_mcelsius_v3 ;
10781198
10791199 for (ctrl_id = 0 ; ctrl_id < mt -> conf -> num_controller ; ctrl_id ++ )
10801200 for (i = 0 ; i < mt -> conf -> num_banks ; i ++ )
0 commit comments