Skip to content

Commit 684cbb4

Browse files
Nicolas Pitredlezcano
authored andcommitted
thermal/drivers/mediatek/lvts_thermal: Provision for gt variable location
The golden temperature calibration value in nvram is not always the 3rd byte. A future commit will prove this assumption wrong. Signed-off-by: Nicolas Pitre <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a4c1ab2 commit 684cbb4

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/thermal/mediatek/lvts_thermal.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct lvts_data {
116116
int num_lvts_ctrl;
117117
int temp_factor;
118118
int temp_offset;
119+
int gt_calib_bit_offset;
119120
};
120121

121122
struct lvts_sensor {
@@ -745,20 +746,21 @@ static int lvts_calibration_read(struct device *dev, struct lvts_domain *lvts_td
745746
return 0;
746747
}
747748

748-
static int lvts_golden_temp_init(struct device *dev, u8 *calib, int temp_offset)
749+
static int lvts_golden_temp_init(struct device *dev, u8 *calib,
750+
const struct lvts_data *lvts_data)
749751
{
750752
u32 gt;
751753

752754
/*
753-
* The golden temp information is contained in the 4th byte (index = 3)
754-
* of efuse data.
755+
* The golden temp information is contained in the first 32-bit
756+
* word of efuse data at a specific bit offset.
755757
*/
756-
gt = calib[3];
758+
gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff;
757759

758760
if (gt && gt < LVTS_GOLDEN_TEMP_MAX)
759761
golden_temp = gt;
760762

761-
golden_temp_offset = golden_temp * 500 + temp_offset;
763+
golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset;
762764

763765
return 0;
764766
}
@@ -777,7 +779,7 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
777779
if (ret)
778780
return ret;
779781

780-
ret = lvts_golden_temp_init(dev, lvts_td->calib, lvts_data->temp_offset);
782+
ret = lvts_golden_temp_init(dev, lvts_td->calib, lvts_data);
781783
if (ret)
782784
return ret;
783785

@@ -1600,41 +1602,47 @@ static const struct lvts_data mt7988_lvts_ap_data = {
16001602
.num_lvts_ctrl = ARRAY_SIZE(mt7988_lvts_ap_data_ctrl),
16011603
.temp_factor = LVTS_COEFF_A_MT7988,
16021604
.temp_offset = LVTS_COEFF_B_MT7988,
1605+
.gt_calib_bit_offset = 24,
16031606
};
16041607

16051608
static const struct lvts_data mt8186_lvts_data = {
16061609
.lvts_ctrl = mt8186_lvts_data_ctrl,
16071610
.num_lvts_ctrl = ARRAY_SIZE(mt8186_lvts_data_ctrl),
16081611
.temp_factor = LVTS_COEFF_A_MT7988,
16091612
.temp_offset = LVTS_COEFF_B_MT7988,
1613+
.gt_calib_bit_offset = 24,
16101614
};
16111615

16121616
static const struct lvts_data mt8192_lvts_mcu_data = {
16131617
.lvts_ctrl = mt8192_lvts_mcu_data_ctrl,
16141618
.num_lvts_ctrl = ARRAY_SIZE(mt8192_lvts_mcu_data_ctrl),
16151619
.temp_factor = LVTS_COEFF_A_MT8195,
16161620
.temp_offset = LVTS_COEFF_B_MT8195,
1621+
.gt_calib_bit_offset = 24,
16171622
};
16181623

16191624
static const struct lvts_data mt8192_lvts_ap_data = {
16201625
.lvts_ctrl = mt8192_lvts_ap_data_ctrl,
16211626
.num_lvts_ctrl = ARRAY_SIZE(mt8192_lvts_ap_data_ctrl),
16221627
.temp_factor = LVTS_COEFF_A_MT8195,
16231628
.temp_offset = LVTS_COEFF_B_MT8195,
1629+
.gt_calib_bit_offset = 24,
16241630
};
16251631

16261632
static const struct lvts_data mt8195_lvts_mcu_data = {
16271633
.lvts_ctrl = mt8195_lvts_mcu_data_ctrl,
16281634
.num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_mcu_data_ctrl),
16291635
.temp_factor = LVTS_COEFF_A_MT8195,
16301636
.temp_offset = LVTS_COEFF_B_MT8195,
1637+
.gt_calib_bit_offset = 24,
16311638
};
16321639

16331640
static const struct lvts_data mt8195_lvts_ap_data = {
16341641
.lvts_ctrl = mt8195_lvts_ap_data_ctrl,
16351642
.num_lvts_ctrl = ARRAY_SIZE(mt8195_lvts_ap_data_ctrl),
16361643
.temp_factor = LVTS_COEFF_A_MT8195,
16371644
.temp_offset = LVTS_COEFF_B_MT8195,
1645+
.gt_calib_bit_offset = 24,
16381646
};
16391647

16401648
static const struct of_device_id lvts_of_match[] = {

0 commit comments

Comments
 (0)