37
37
/* DTS encoding for TJ MAX temperature */
38
38
#define SOC_DTS_TJMAX_ENCODING 0x7F
39
39
40
- /* Only 2 out of 4 is allowed for OSPM */
41
- #define SOC_MAX_DTS_TRIPS 2
42
-
43
40
/* Mask for two trips in status bits */
44
41
#define SOC_DTS_TRIP_MASK 0x03
45
42
46
- /* DTS0 and DTS 1 */
47
- #define SOC_MAX_DTS_SENSORS 2
48
-
49
- static int sys_get_trip_temp (struct thermal_zone_device * tzd , int trip ,
50
- int * temp )
51
- {
52
- int status ;
53
- u32 out ;
54
- struct intel_soc_dts_sensor_entry * dts ;
55
- struct intel_soc_dts_sensors * sensors ;
56
-
57
- dts = thermal_zone_device_priv (tzd );
58
- sensors = dts -> sensors ;
59
- mutex_lock (& sensors -> dts_update_lock );
60
- status = iosf_mbi_read (BT_MBI_UNIT_PMC , MBI_REG_READ ,
61
- SOC_DTS_OFFSET_PTPS , & out );
62
- mutex_unlock (& sensors -> dts_update_lock );
63
- if (status )
64
- return status ;
65
-
66
- out = (out >> (trip * 8 )) & SOC_DTS_TJMAX_ENCODING ;
67
- if (!out )
68
- * temp = 0 ;
69
- else
70
- * temp = sensors -> tj_max - out * 1000 ;
71
-
72
- return 0 ;
73
- }
74
-
75
- static int update_trip_temp (struct intel_soc_dts_sensor_entry * dts ,
76
- int thres_index , int temp ,
77
- enum thermal_trip_type trip_type )
43
+ static int update_trip_temp (struct intel_soc_dts_sensors * sensors ,
44
+ int thres_index , int temp )
78
45
{
79
46
int status ;
80
47
u32 temp_out ;
@@ -85,7 +52,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
85
52
u32 store_te_out ;
86
53
u32 te_out ;
87
54
u32 int_enable_bit = SOC_DTS_TE_APICA_ENABLE ;
88
- struct intel_soc_dts_sensors * sensors = dts -> sensors ;
89
55
90
56
if (sensors -> intr_type == INTEL_SOC_DTS_INTERRUPT_MSI )
91
57
int_enable_bit |= SOC_DTS_TE_MSI_ENABLE ;
@@ -148,8 +114,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
148
114
if (status )
149
115
goto err_restore_te_out ;
150
116
151
- dts -> trip_types [thres_index ] = trip_type ;
152
-
153
117
return 0 ;
154
118
err_restore_te_out :
155
119
iosf_mbi_write (BT_MBI_UNIT_PMC , MBI_REG_WRITE ,
@@ -165,6 +129,22 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
165
129
return status ;
166
130
}
167
131
132
+ static int configure_trip (struct intel_soc_dts_sensor_entry * dts ,
133
+ int thres_index , enum thermal_trip_type trip_type ,
134
+ int temp )
135
+ {
136
+ int ret ;
137
+
138
+ ret = update_trip_temp (dts -> sensors , thres_index , temp );
139
+ if (ret )
140
+ return ret ;
141
+
142
+ dts -> trips [thres_index ].temperature = temp ;
143
+ dts -> trips [thres_index ].type = trip_type ;
144
+
145
+ return 0 ;
146
+ }
147
+
168
148
static int sys_set_trip_temp (struct thermal_zone_device * tzd , int trip ,
169
149
int temp )
170
150
{
@@ -176,23 +156,12 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
176
156
return - EINVAL ;
177
157
178
158
mutex_lock (& sensors -> dts_update_lock );
179
- status = update_trip_temp (dts , trip , temp ,
180
- dts -> trip_types [trip ]);
159
+ status = update_trip_temp (sensors , trip , temp );
181
160
mutex_unlock (& sensors -> dts_update_lock );
182
161
183
162
return status ;
184
163
}
185
164
186
- static int sys_get_trip_type (struct thermal_zone_device * tzd ,
187
- int trip , enum thermal_trip_type * type )
188
- {
189
- struct intel_soc_dts_sensor_entry * dts = thermal_zone_device_priv (tzd );
190
-
191
- * type = dts -> trip_types [trip ];
192
-
193
- return 0 ;
194
- }
195
-
196
165
static int sys_get_curr_temp (struct thermal_zone_device * tzd ,
197
166
int * temp )
198
167
{
@@ -217,8 +186,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
217
186
218
187
static struct thermal_zone_device_ops tzone_ops = {
219
188
.get_temp = sys_get_curr_temp ,
220
- .get_trip_temp = sys_get_trip_temp ,
221
- .get_trip_type = sys_get_trip_type ,
222
189
.set_trip_temp = sys_set_trip_temp ,
223
190
};
224
191
@@ -253,14 +220,12 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts)
253
220
}
254
221
255
222
static int add_dts_thermal_zone (int id , struct intel_soc_dts_sensor_entry * dts ,
256
- bool notification_support , int trip_cnt ,
257
- int read_only_trip_cnt )
223
+ bool critical_trip )
258
224
{
225
+ int writable_trip_cnt = SOC_MAX_DTS_TRIPS ;
259
226
char name [10 ];
260
227
unsigned long trip ;
261
- int trip_count = 0 ;
262
- int trip_mask = 0 ;
263
- int writable_trip_cnt = 0 ;
228
+ int trip_mask ;
264
229
unsigned long ptps ;
265
230
u32 store_ptps ;
266
231
unsigned long i ;
@@ -273,11 +238,11 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
273
238
goto err_ret ;
274
239
275
240
dts -> id = id ;
276
- if ( notification_support ) {
277
- trip_count = min ( SOC_MAX_DTS_TRIPS , trip_cnt );
278
- writable_trip_cnt = trip_count - read_only_trip_cnt ;
279
- trip_mask = GENMASK ( writable_trip_cnt - 1 , 0 );
280
- }
241
+
242
+ if ( critical_trip )
243
+ writable_trip_cnt -- ;
244
+
245
+ trip_mask = GENMASK ( writable_trip_cnt - 1 , 0 );
281
246
282
247
/* Check if the writable trip we provide is not used by BIOS */
283
248
ret = iosf_mbi_read (BT_MBI_UNIT_PMC , MBI_REG_READ ,
@@ -290,13 +255,12 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
290
255
trip_mask &= ~BIT (i / 8 );
291
256
}
292
257
dts -> trip_mask = trip_mask ;
293
- dts -> trip_count = trip_count ;
294
258
snprintf (name , sizeof (name ), "soc_dts%d" , id );
295
- dts -> tzone = thermal_zone_device_register (name ,
296
- trip_count ,
297
- trip_mask ,
298
- dts , & tzone_ops ,
299
- NULL , 0 , 0 );
259
+ dts -> tzone = thermal_zone_device_register_with_trips (name , dts -> trips ,
260
+ SOC_MAX_DTS_TRIPS ,
261
+ trip_mask ,
262
+ dts , & tzone_ops ,
263
+ NULL , 0 , 0 );
300
264
if (IS_ERR (dts -> tzone )) {
301
265
ret = PTR_ERR (dts -> tzone );
302
266
goto err_ret ;
@@ -316,26 +280,6 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
316
280
return ret ;
317
281
}
318
282
319
- int intel_soc_dts_iosf_add_read_only_critical_trip (
320
- struct intel_soc_dts_sensors * sensors , int critical_offset )
321
- {
322
- int i , j ;
323
-
324
- for (i = 0 ; i < SOC_MAX_DTS_SENSORS ; ++ i ) {
325
- struct intel_soc_dts_sensor_entry * entry = & sensors -> soc_dts [i ];
326
- int temp = sensors -> tj_max - critical_offset ;
327
- unsigned long count = entry -> trip_count ;
328
- unsigned long mask = entry -> trip_mask ;
329
-
330
- j = find_first_zero_bit (& mask , count );
331
- if (j < count )
332
- return update_trip_temp (entry , j , temp , THERMAL_TRIP_CRITICAL );
333
- }
334
-
335
- return - EINVAL ;
336
- }
337
- EXPORT_SYMBOL_GPL (intel_soc_dts_iosf_add_read_only_critical_trip );
338
-
339
283
void intel_soc_dts_iosf_interrupt_handler (struct intel_soc_dts_sensors * sensors )
340
284
{
341
285
u32 sticky_out ;
@@ -371,22 +315,24 @@ void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors)
371
315
}
372
316
EXPORT_SYMBOL_GPL (intel_soc_dts_iosf_interrupt_handler );
373
317
374
- struct intel_soc_dts_sensors * intel_soc_dts_iosf_init (
375
- enum intel_soc_dts_interrupt_type intr_type , int trip_count ,
376
- int read_only_trip_count )
318
+ static void dts_trips_reset (struct intel_soc_dts_sensors * sensors , int dts_index )
319
+ {
320
+ configure_trip (& sensors -> soc_dts [dts_index ], 0 , 0 , 0 );
321
+ configure_trip (& sensors -> soc_dts [dts_index ], 1 , 0 , 0 );
322
+ }
323
+
324
+ struct intel_soc_dts_sensors *
325
+ intel_soc_dts_iosf_init (enum intel_soc_dts_interrupt_type intr_type ,
326
+ bool critical_trip , int crit_offset )
377
327
{
378
328
struct intel_soc_dts_sensors * sensors ;
379
- bool notification ;
380
329
int tj_max ;
381
330
int ret ;
382
331
int i ;
383
332
384
333
if (!iosf_mbi_available ())
385
334
return ERR_PTR (- ENODEV );
386
335
387
- if (!trip_count || read_only_trip_count > trip_count )
388
- return ERR_PTR (- EINVAL );
389
-
390
336
tj_max = intel_tcc_get_tjmax (-1 );
391
337
if (tj_max < 0 )
392
338
return ERR_PTR (tj_max );
@@ -399,37 +345,46 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
399
345
mutex_init (& sensors -> dts_update_lock );
400
346
sensors -> intr_type = intr_type ;
401
347
sensors -> tj_max = tj_max * 1000 ;
402
- if (intr_type == INTEL_SOC_DTS_INTERRUPT_NONE )
403
- notification = false;
404
- else
405
- notification = true;
348
+
406
349
for (i = 0 ; i < SOC_MAX_DTS_SENSORS ; ++ i ) {
350
+ enum thermal_trip_type trip_type ;
351
+ int temp ;
352
+
407
353
sensors -> soc_dts [i ].sensors = sensors ;
408
- ret = add_dts_thermal_zone ( i , & sensors -> soc_dts [ i ],
409
- notification , trip_count ,
410
- read_only_trip_count );
354
+
355
+ ret = configure_trip ( & sensors -> soc_dts [ i ], 0 ,
356
+ THERMAL_TRIP_PASSIVE , 0 );
411
357
if (ret )
412
- goto err_free ;
358
+ goto err_reset_trips ;
359
+
360
+ if (critical_trip ) {
361
+ trip_type = THERMAL_TRIP_CRITICAL ;
362
+ temp = sensors -> tj_max - crit_offset ;
363
+ } else {
364
+ trip_type = THERMAL_TRIP_PASSIVE ;
365
+ temp = 0 ;
366
+ }
367
+ ret = configure_trip (& sensors -> soc_dts [i ], 1 , trip_type , temp );
368
+ if (ret )
369
+ goto err_reset_trips ;
413
370
}
414
371
415
372
for (i = 0 ; i < SOC_MAX_DTS_SENSORS ; ++ i ) {
416
- ret = update_trip_temp (& sensors -> soc_dts [i ], 0 , 0 ,
417
- THERMAL_TRIP_PASSIVE );
418
- if (ret )
419
- goto err_remove_zone ;
420
-
421
- ret = update_trip_temp (& sensors -> soc_dts [i ], 1 , 0 ,
422
- THERMAL_TRIP_PASSIVE );
373
+ ret = add_dts_thermal_zone (i , & sensors -> soc_dts [i ], critical_trip );
423
374
if (ret )
424
375
goto err_remove_zone ;
425
376
}
426
377
427
378
return sensors ;
379
+
428
380
err_remove_zone :
429
381
for (i = 0 ; i < SOC_MAX_DTS_SENSORS ; ++ i )
430
382
remove_dts_thermal_zone (& sensors -> soc_dts [i ]);
431
383
432
- err_free :
384
+ err_reset_trips :
385
+ for (i = 0 ; i < SOC_MAX_DTS_SENSORS ; i ++ )
386
+ dts_trips_reset (sensors , i );
387
+
433
388
kfree (sensors );
434
389
return ERR_PTR (ret );
435
390
}
@@ -440,9 +395,8 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors)
440
395
int i ;
441
396
442
397
for (i = 0 ; i < SOC_MAX_DTS_SENSORS ; ++ i ) {
443
- update_trip_temp (& sensors -> soc_dts [i ], 0 , 0 , 0 );
444
- update_trip_temp (& sensors -> soc_dts [i ], 1 , 0 , 0 );
445
398
remove_dts_thermal_zone (& sensors -> soc_dts [i ]);
399
+ dts_trips_reset (sensors , i );
446
400
}
447
401
kfree (sensors );
448
402
}
0 commit comments