Skip to content

Commit 54bf1e5

Browse files
Henry Yendlezcano
authored andcommitted
thermal: mediatek: Prepare to add support for other platforms
It is known that Mediatek owns two thermal systems, which only differ in the way of reading calibration data and converting temperature. MT8173, MT8183, MT2701 and MT2712 belongs to version 1 thermal system, and MT7622 belongs to version 2. In order to handle both systems, the suffix _V1 is appended to the current code, and then the second patch will add _V2 functions with the same purpose but different implementation. Signed-off-by: Henry Yen <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Tested-By: Frank Wunderlich <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0de967f commit 54bf1e5

File tree

1 file changed

+62
-52
lines changed

1 file changed

+62
-52
lines changed

drivers/thermal/mtk_thermal.c

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@
120120
* MT2701 has 3 sensors and needs 3 VTS calibration data.
121121
* MT2712 has 4 sensors and needs 4 VTS calibration data.
122122
*/
123-
#define CALIB_BUF0_VALID BIT(0)
124-
#define CALIB_BUF1_ADC_GE(x) (((x) >> 22) & 0x3ff)
125-
#define CALIB_BUF0_VTS_TS1(x) (((x) >> 17) & 0x1ff)
126-
#define CALIB_BUF0_VTS_TS2(x) (((x) >> 8) & 0x1ff)
127-
#define CALIB_BUF1_VTS_TS3(x) (((x) >> 0) & 0x1ff)
128-
#define CALIB_BUF2_VTS_TS4(x) (((x) >> 23) & 0x1ff)
129-
#define CALIB_BUF2_VTS_TS5(x) (((x) >> 5) & 0x1ff)
130-
#define CALIB_BUF2_VTS_TSABB(x) (((x) >> 14) & 0x1ff)
131-
#define CALIB_BUF0_DEGC_CALI(x) (((x) >> 1) & 0x3f)
132-
#define CALIB_BUF0_O_SLOPE(x) (((x) >> 26) & 0x3f)
133-
#define CALIB_BUF0_O_SLOPE_SIGN(x) (((x) >> 7) & 0x1)
134-
#define CALIB_BUF1_ID(x) (((x) >> 9) & 0x1)
123+
#define CALIB_BUF0_VALID_V1 BIT(0)
124+
#define CALIB_BUF1_ADC_GE_V1(x) (((x) >> 22) & 0x3ff)
125+
#define CALIB_BUF0_VTS_TS1_V1(x) (((x) >> 17) & 0x1ff)
126+
#define CALIB_BUF0_VTS_TS2_V1(x) (((x) >> 8) & 0x1ff)
127+
#define CALIB_BUF1_VTS_TS3_V1(x) (((x) >> 0) & 0x1ff)
128+
#define CALIB_BUF2_VTS_TS4_V1(x) (((x) >> 23) & 0x1ff)
129+
#define CALIB_BUF2_VTS_TS5_V1(x) (((x) >> 5) & 0x1ff)
130+
#define CALIB_BUF2_VTS_TSABB_V1(x) (((x) >> 14) & 0x1ff)
131+
#define CALIB_BUF0_DEGC_CALI_V1(x) (((x) >> 1) & 0x3f)
132+
#define CALIB_BUF0_O_SLOPE_V1(x) (((x) >> 26) & 0x3f)
133+
#define CALIB_BUF0_O_SLOPE_SIGN_V1(x) (((x) >> 7) & 0x1)
134+
#define CALIB_BUF1_ID_V1(x) (((x) >> 9) & 0x1)
135135

136136
enum {
137137
VTS1,
@@ -525,7 +525,7 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
525525
* This converts the raw ADC value to mcelsius using the SoC specific
526526
* calibration constants
527527
*/
528-
static int raw_to_mcelsius(struct mtk_thermal *mt, int sensno, s32 raw)
528+
static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw)
529529
{
530530
s32 tmp;
531531

@@ -594,9 +594,9 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
594594
raw = readl(mt->thermal_base +
595595
conf->msr[conf->bank_data[bank->id].sensors[i]]);
596596

597-
temp = raw_to_mcelsius(mt,
598-
conf->bank_data[bank->id].sensors[i],
599-
raw);
597+
temp = raw_to_mcelsius_v1(mt,
598+
conf->bank_data[bank->id].sensors[i],
599+
raw);
600600

601601
/*
602602
* The first read of a sensor often contains very high bogus
@@ -758,6 +758,51 @@ static u64 of_get_phys_base(struct device_node *np)
758758
return of_translate_address(np, regaddr_p);
759759
}
760760

761+
static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf)
762+
{
763+
int i;
764+
765+
if (!(buf[0] & CALIB_BUF0_VALID_V1))
766+
return -EINVAL;
767+
768+
mt->adc_ge = CALIB_BUF1_ADC_GE_V1(buf[1]);
769+
770+
for (i = 0; i < mt->conf->num_sensors; i++) {
771+
switch (mt->conf->vts_index[i]) {
772+
case VTS1:
773+
mt->vts[VTS1] = CALIB_BUF0_VTS_TS1_V1(buf[0]);
774+
break;
775+
case VTS2:
776+
mt->vts[VTS2] = CALIB_BUF0_VTS_TS2_V1(buf[0]);
777+
break;
778+
case VTS3:
779+
mt->vts[VTS3] = CALIB_BUF1_VTS_TS3_V1(buf[1]);
780+
break;
781+
case VTS4:
782+
mt->vts[VTS4] = CALIB_BUF2_VTS_TS4_V1(buf[2]);
783+
break;
784+
case VTS5:
785+
mt->vts[VTS5] = CALIB_BUF2_VTS_TS5_V1(buf[2]);
786+
break;
787+
case VTSABB:
788+
mt->vts[VTSABB] =
789+
CALIB_BUF2_VTS_TSABB_V1(buf[2]);
790+
break;
791+
default:
792+
break;
793+
}
794+
}
795+
796+
mt->degc_cali = CALIB_BUF0_DEGC_CALI_V1(buf[0]);
797+
if (CALIB_BUF1_ID_V1(buf[1]) &
798+
CALIB_BUF0_O_SLOPE_SIGN_V1(buf[0]))
799+
mt->o_slope = -CALIB_BUF0_O_SLOPE_V1(buf[0]);
800+
else
801+
mt->o_slope = CALIB_BUF0_O_SLOPE_V1(buf[0]);
802+
803+
return 0;
804+
}
805+
761806
static int mtk_thermal_get_calibration_data(struct device *dev,
762807
struct mtk_thermal *mt)
763808
{
@@ -793,43 +838,8 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
793838
goto out;
794839
}
795840

796-
if (buf[0] & CALIB_BUF0_VALID) {
797-
mt->adc_ge = CALIB_BUF1_ADC_GE(buf[1]);
798-
799-
for (i = 0; i < mt->conf->num_sensors; i++) {
800-
switch (mt->conf->vts_index[i]) {
801-
case VTS1:
802-
mt->vts[VTS1] = CALIB_BUF0_VTS_TS1(buf[0]);
803-
break;
804-
case VTS2:
805-
mt->vts[VTS2] = CALIB_BUF0_VTS_TS2(buf[0]);
806-
break;
807-
case VTS3:
808-
mt->vts[VTS3] = CALIB_BUF1_VTS_TS3(buf[1]);
809-
break;
810-
case VTS4:
811-
mt->vts[VTS4] = CALIB_BUF2_VTS_TS4(buf[2]);
812-
break;
813-
case VTS5:
814-
mt->vts[VTS5] = CALIB_BUF2_VTS_TS5(buf[2]);
815-
break;
816-
case VTSABB:
817-
mt->vts[VTSABB] = CALIB_BUF2_VTS_TSABB(buf[2]);
818-
break;
819-
default:
820-
break;
821-
}
822-
}
823-
824-
mt->degc_cali = CALIB_BUF0_DEGC_CALI(buf[0]);
825-
if (CALIB_BUF1_ID(buf[1]) &
826-
CALIB_BUF0_O_SLOPE_SIGN(buf[0]))
827-
mt->o_slope = -CALIB_BUF0_O_SLOPE(buf[0]);
828-
else
829-
mt->o_slope = CALIB_BUF0_O_SLOPE(buf[0]);
830-
} else {
841+
if (mtk_thermal_extract_efuse_v1(mt, buf))
831842
dev_info(dev, "Device not calibrated, using default calibration values\n");
832-
}
833843

834844
out:
835845
kfree(buf);

0 commit comments

Comments
 (0)