80
80
#define LVTS_SENSOR_MAX 4
81
81
#define LVTS_GOLDEN_TEMP_MAX 62
82
82
#define LVTS_GOLDEN_TEMP_DEFAULT 50
83
- #define LVTS_COEFF_A -250460
84
- #define LVTS_COEFF_B 250460
83
+ #define LVTS_COEFF_A_MT8195 -250460
84
+ #define LVTS_COEFF_B_MT8195 250460
85
85
86
86
#define LVTS_MSR_IMMEDIATE_MODE 0
87
87
#define LVTS_MSR_FILTERED_MODE 1
94
94
#define LVTS_MINIMUM_THRESHOLD 20000
95
95
96
96
static int golden_temp = LVTS_GOLDEN_TEMP_DEFAULT ;
97
- static int coeff_b = LVTS_COEFF_B ;
97
+ static int golden_temp_offset ;
98
98
99
99
struct lvts_sensor_data {
100
100
int dt_id ;
@@ -112,6 +112,8 @@ struct lvts_ctrl_data {
112
112
struct lvts_data {
113
113
const struct lvts_ctrl_data * lvts_ctrl ;
114
114
int num_lvts_ctrl ;
115
+ int temp_factor ;
116
+ int temp_offset ;
115
117
};
116
118
117
119
struct lvts_sensor {
@@ -126,6 +128,7 @@ struct lvts_sensor {
126
128
127
129
struct lvts_ctrl {
128
130
struct lvts_sensor sensors [LVTS_SENSOR_MAX ];
131
+ const struct lvts_data * lvts_data ;
129
132
u32 calibration [LVTS_SENSOR_MAX ];
130
133
u32 hw_tshut_raw_temp ;
131
134
int num_lvts_sensor ;
@@ -247,28 +250,31 @@ static void lvts_debugfs_exit(struct lvts_domain *lvts_td) { }
247
250
248
251
#endif
249
252
250
- static int lvts_raw_to_temp (u32 raw_temp )
253
+ static int lvts_raw_to_temp (u32 raw_temp , int temp_factor )
251
254
{
252
255
int temperature ;
253
256
254
- temperature = ((s64 )(raw_temp & 0xFFFF ) * LVTS_COEFF_A ) >> 14 ;
255
- temperature += coeff_b ;
257
+ temperature = ((s64 )(raw_temp & 0xFFFF ) * temp_factor ) >> 14 ;
258
+ temperature += golden_temp_offset ;
256
259
257
260
return temperature ;
258
261
}
259
262
260
- static u32 lvts_temp_to_raw (int temperature )
263
+ static u32 lvts_temp_to_raw (int temperature , int temp_factor )
261
264
{
262
- u32 raw_temp = ((s64 )(coeff_b - temperature )) << 14 ;
265
+ u32 raw_temp = ((s64 )(golden_temp_offset - temperature )) << 14 ;
263
266
264
- raw_temp = div_s64 (raw_temp , - LVTS_COEFF_A );
267
+ raw_temp = div_s64 (raw_temp , - temp_factor );
265
268
266
269
return raw_temp ;
267
270
}
268
271
269
272
static int lvts_get_temp (struct thermal_zone_device * tz , int * temp )
270
273
{
271
274
struct lvts_sensor * lvts_sensor = thermal_zone_device_priv (tz );
275
+ struct lvts_ctrl * lvts_ctrl = container_of (lvts_sensor , struct lvts_ctrl ,
276
+ sensors [lvts_sensor -> id ]);
277
+ const struct lvts_data * lvts_data = lvts_ctrl -> lvts_data ;
272
278
void __iomem * msr = lvts_sensor -> msr ;
273
279
u32 value ;
274
280
int rc ;
@@ -301,7 +307,7 @@ static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
301
307
if (rc )
302
308
return - EAGAIN ;
303
309
304
- * temp = lvts_raw_to_temp (value & 0xFFFF );
310
+ * temp = lvts_raw_to_temp (value & 0xFFFF , lvts_data -> temp_factor );
305
311
306
312
return 0 ;
307
313
}
@@ -348,10 +354,13 @@ static bool lvts_should_update_thresh(struct lvts_ctrl *lvts_ctrl, int high)
348
354
static int lvts_set_trips (struct thermal_zone_device * tz , int low , int high )
349
355
{
350
356
struct lvts_sensor * lvts_sensor = thermal_zone_device_priv (tz );
351
- struct lvts_ctrl * lvts_ctrl = container_of (lvts_sensor , struct lvts_ctrl , sensors [lvts_sensor -> id ]);
357
+ struct lvts_ctrl * lvts_ctrl = container_of (lvts_sensor , struct lvts_ctrl ,
358
+ sensors [lvts_sensor -> id ]);
359
+ const struct lvts_data * lvts_data = lvts_ctrl -> lvts_data ;
352
360
void __iomem * base = lvts_sensor -> base ;
353
- u32 raw_low = lvts_temp_to_raw (low != - INT_MAX ? low : LVTS_MINIMUM_THRESHOLD );
354
- u32 raw_high = lvts_temp_to_raw (high );
361
+ u32 raw_low = lvts_temp_to_raw (low != - INT_MAX ? low : LVTS_MINIMUM_THRESHOLD ,
362
+ lvts_data -> temp_factor );
363
+ u32 raw_high = lvts_temp_to_raw (high , lvts_data -> temp_factor );
355
364
bool should_update_thresh ;
356
365
357
366
lvts_sensor -> low_thresh = low ;
@@ -692,7 +701,7 @@ static int lvts_calibration_read(struct device *dev, struct lvts_domain *lvts_td
692
701
return 0 ;
693
702
}
694
703
695
- static int lvts_golden_temp_init (struct device * dev , u32 * value )
704
+ static int lvts_golden_temp_init (struct device * dev , u32 * value , int temp_offset )
696
705
{
697
706
u32 gt ;
698
707
@@ -701,7 +710,7 @@ static int lvts_golden_temp_init(struct device *dev, u32 *value)
701
710
if (gt && gt < LVTS_GOLDEN_TEMP_MAX )
702
711
golden_temp = gt ;
703
712
704
- coeff_b = golden_temp * 500 + LVTS_COEFF_B ;
713
+ golden_temp_offset = golden_temp * 500 + temp_offset ;
705
714
706
715
return 0 ;
707
716
}
@@ -724,7 +733,7 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
724
733
* The golden temp information is contained in the first chunk
725
734
* of efuse data.
726
735
*/
727
- ret = lvts_golden_temp_init (dev , (u32 * )lvts_td -> calib );
736
+ ret = lvts_golden_temp_init (dev , (u32 * )lvts_td -> calib , lvts_data -> temp_offset );
728
737
if (ret )
729
738
return ret ;
730
739
@@ -735,6 +744,7 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
735
744
for (i = 0 ; i < lvts_data -> num_lvts_ctrl ; i ++ ) {
736
745
737
746
lvts_ctrl [i ].base = lvts_td -> base + lvts_data -> lvts_ctrl [i ].offset ;
747
+ lvts_ctrl [i ].lvts_data = lvts_data ;
738
748
739
749
ret = lvts_sensor_init (dev , & lvts_ctrl [i ],
740
750
& lvts_data -> lvts_ctrl [i ]);
@@ -758,7 +768,8 @@ static int lvts_ctrl_init(struct device *dev, struct lvts_domain *lvts_td,
758
768
* after initializing the calibration.
759
769
*/
760
770
lvts_ctrl [i ].hw_tshut_raw_temp =
761
- lvts_temp_to_raw (lvts_data -> lvts_ctrl [i ].hw_tshut_temp );
771
+ lvts_temp_to_raw (lvts_data -> lvts_ctrl [i ].hw_tshut_temp ,
772
+ lvts_data -> temp_factor );
762
773
763
774
lvts_ctrl [i ].low_thresh = INT_MIN ;
764
775
lvts_ctrl [i ].high_thresh = INT_MIN ;
@@ -1223,6 +1234,8 @@ static int lvts_probe(struct platform_device *pdev)
1223
1234
if (irq < 0 )
1224
1235
return irq ;
1225
1236
1237
+ golden_temp_offset = lvts_data -> temp_offset ;
1238
+
1226
1239
ret = lvts_domain_init (dev , lvts_td , lvts_data );
1227
1240
if (ret )
1228
1241
return dev_err_probe (dev , ret , "Failed to initialize the lvts domain\n" );
@@ -1336,11 +1349,15 @@ static const struct lvts_ctrl_data mt8195_lvts_ap_data_ctrl[] = {
1336
1349
static const struct lvts_data mt8195_lvts_mcu_data = {
1337
1350
.lvts_ctrl = mt8195_lvts_mcu_data_ctrl ,
1338
1351
.num_lvts_ctrl = ARRAY_SIZE (mt8195_lvts_mcu_data_ctrl ),
1352
+ .temp_factor = LVTS_COEFF_A_MT8195 ,
1353
+ .temp_offset = LVTS_COEFF_B_MT8195 ,
1339
1354
};
1340
1355
1341
1356
static const struct lvts_data mt8195_lvts_ap_data = {
1342
1357
.lvts_ctrl = mt8195_lvts_ap_data_ctrl ,
1343
1358
.num_lvts_ctrl = ARRAY_SIZE (mt8195_lvts_ap_data_ctrl ),
1359
+ .temp_factor = LVTS_COEFF_A_MT8195 ,
1360
+ .temp_offset = LVTS_COEFF_B_MT8195 ,
1344
1361
};
1345
1362
1346
1363
static const struct of_device_id lvts_of_match [] = {
0 commit comments