Skip to content

Commit 9f15b43

Browse files
committed
Merge Intel DTS IOSF thermal driver changes for 6.6-rc1.
These fix a few issues in the Intel DTS IOSF thermal driver, clean up code in it and make it use trip point tables for registering thermal zones. * thermal-intel: thermal: intel: intel_soc_dts_iosf: Use struct thermal_trip thermal: intel: intel_soc_dts_iosf: Rework critical trip setup thermal: intel: intel_soc_dts_iosf: Add helper for resetting trip points thermal: intel: intel_soc_dts_iosf: Change initialization ordering thermal: intel: intel_soc_dts_iosf: Pass sensors to update_trip_temp() thermal: intel: intel_soc_dts_iosf: Untangle update_trip_temp() thermal: intel: intel_soc_dts_iosf: Always assume notification support thermal: intel: intel_soc_dts_iosf: Drop redundant symbol definition thermal: intel: intel_soc_dts_iosf: Always use 2 trips
2 parents f6a756e + 4effd28 commit 9f15b43

File tree

4 files changed

+78
-136
lines changed

4 files changed

+78
-136
lines changed

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev,
5959
* ACPI/MSR. So we don't want to fail for auxiliary DTSs.
6060
*/
6161
proc_priv->soc_dts = intel_soc_dts_iosf_init(
62-
INTEL_SOC_DTS_INTERRUPT_MSI, 2, 0);
62+
INTEL_SOC_DTS_INTERRUPT_MSI, false, 0);
6363

6464
if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) {
6565
ret = pci_enable_msi(pdev);

drivers/thermal/intel/intel_soc_dts_iosf.c

Lines changed: 67 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,11 @@
3737
/* DTS encoding for TJ MAX temperature */
3838
#define SOC_DTS_TJMAX_ENCODING 0x7F
3939

40-
/* Only 2 out of 4 is allowed for OSPM */
41-
#define SOC_MAX_DTS_TRIPS 2
42-
4340
/* Mask for two trips in status bits */
4441
#define SOC_DTS_TRIP_MASK 0x03
4542

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)
7845
{
7946
int status;
8047
u32 temp_out;
@@ -85,7 +52,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
8552
u32 store_te_out;
8653
u32 te_out;
8754
u32 int_enable_bit = SOC_DTS_TE_APICA_ENABLE;
88-
struct intel_soc_dts_sensors *sensors = dts->sensors;
8955

9056
if (sensors->intr_type == INTEL_SOC_DTS_INTERRUPT_MSI)
9157
int_enable_bit |= SOC_DTS_TE_MSI_ENABLE;
@@ -148,8 +114,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts,
148114
if (status)
149115
goto err_restore_te_out;
150116

151-
dts->trip_types[thres_index] = trip_type;
152-
153117
return 0;
154118
err_restore_te_out:
155119
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,
165129
return status;
166130
}
167131

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+
168148
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
169149
int temp)
170150
{
@@ -176,23 +156,12 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
176156
return -EINVAL;
177157

178158
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);
181160
mutex_unlock(&sensors->dts_update_lock);
182161

183162
return status;
184163
}
185164

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-
196165
static int sys_get_curr_temp(struct thermal_zone_device *tzd,
197166
int *temp)
198167
{
@@ -217,8 +186,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
217186

218187
static struct thermal_zone_device_ops tzone_ops = {
219188
.get_temp = sys_get_curr_temp,
220-
.get_trip_temp = sys_get_trip_temp,
221-
.get_trip_type = sys_get_trip_type,
222189
.set_trip_temp = sys_set_trip_temp,
223190
};
224191

@@ -253,14 +220,12 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts)
253220
}
254221

255222
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)
258224
{
225+
int writable_trip_cnt = SOC_MAX_DTS_TRIPS;
259226
char name[10];
260227
unsigned long trip;
261-
int trip_count = 0;
262-
int trip_mask = 0;
263-
int writable_trip_cnt = 0;
228+
int trip_mask;
264229
unsigned long ptps;
265230
u32 store_ptps;
266231
unsigned long i;
@@ -273,11 +238,11 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
273238
goto err_ret;
274239

275240
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);
281246

282247
/* Check if the writable trip we provide is not used by BIOS */
283248
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,
290255
trip_mask &= ~BIT(i / 8);
291256
}
292257
dts->trip_mask = trip_mask;
293-
dts->trip_count = trip_count;
294258
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);
300264
if (IS_ERR(dts->tzone)) {
301265
ret = PTR_ERR(dts->tzone);
302266
goto err_ret;
@@ -316,26 +280,6 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
316280
return ret;
317281
}
318282

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-
339283
void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors)
340284
{
341285
u32 sticky_out;
@@ -371,22 +315,24 @@ void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors)
371315
}
372316
EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_interrupt_handler);
373317

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)
377327
{
378328
struct intel_soc_dts_sensors *sensors;
379-
bool notification;
380329
int tj_max;
381330
int ret;
382331
int i;
383332

384333
if (!iosf_mbi_available())
385334
return ERR_PTR(-ENODEV);
386335

387-
if (!trip_count || read_only_trip_count > trip_count)
388-
return ERR_PTR(-EINVAL);
389-
390336
tj_max = intel_tcc_get_tjmax(-1);
391337
if (tj_max < 0)
392338
return ERR_PTR(tj_max);
@@ -399,37 +345,46 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
399345
mutex_init(&sensors->dts_update_lock);
400346
sensors->intr_type = intr_type;
401347
sensors->tj_max = tj_max * 1000;
402-
if (intr_type == INTEL_SOC_DTS_INTERRUPT_NONE)
403-
notification = false;
404-
else
405-
notification = true;
348+
406349
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
350+
enum thermal_trip_type trip_type;
351+
int temp;
352+
407353
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);
411357
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;
413370
}
414371

415372
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);
423374
if (ret)
424375
goto err_remove_zone;
425376
}
426377

427378
return sensors;
379+
428380
err_remove_zone:
429381
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i)
430382
remove_dts_thermal_zone(&sensors->soc_dts[i]);
431383

432-
err_free:
384+
err_reset_trips:
385+
for (i = 0; i < SOC_MAX_DTS_SENSORS; i++)
386+
dts_trips_reset(sensors, i);
387+
433388
kfree(sensors);
434389
return ERR_PTR(ret);
435390
}
@@ -440,9 +395,8 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors)
440395
int i;
441396

442397
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);
445398
remove_dts_thermal_zone(&sensors->soc_dts[i]);
399+
dts_trips_reset(sensors, i);
446400
}
447401
kfree(sensors);
448402
}

drivers/thermal/intel/intel_soc_dts_iosf.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
/* DTS0 and DTS 1 */
1313
#define SOC_MAX_DTS_SENSORS 2
1414

15+
/* Only 2 out of 4 is allowed for OSPM */
16+
#define SOC_MAX_DTS_TRIPS 2
17+
1518
enum intel_soc_dts_interrupt_type {
1619
INTEL_SOC_DTS_INTERRUPT_NONE,
1720
INTEL_SOC_DTS_INTERRUPT_APIC,
@@ -26,8 +29,7 @@ struct intel_soc_dts_sensor_entry {
2629
int id;
2730
u32 store_status;
2831
u32 trip_mask;
29-
u32 trip_count;
30-
enum thermal_trip_type trip_types[2];
32+
struct thermal_trip trips[SOC_MAX_DTS_TRIPS];
3133
struct thermal_zone_device *tzone;
3234
struct intel_soc_dts_sensors *sensors;
3335
};
@@ -40,12 +42,11 @@ struct intel_soc_dts_sensors {
4042
struct intel_soc_dts_sensor_entry soc_dts[SOC_MAX_DTS_SENSORS];
4143
};
4244

43-
struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
44-
enum intel_soc_dts_interrupt_type intr_type, int trip_count,
45-
int read_only_trip_count);
45+
46+
struct intel_soc_dts_sensors *
47+
intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
48+
bool critical_trip, int crit_offset);
4649
void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors);
4750
void intel_soc_dts_iosf_interrupt_handler(
4851
struct intel_soc_dts_sensors *sensors);
49-
int intel_soc_dts_iosf_add_read_only_critical_trip(
50-
struct intel_soc_dts_sensors *sensors, int critical_offset);
5152
#endif

drivers/thermal/intel/intel_soc_dts_thermal.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ static int __init intel_soc_thermal_init(void)
5151
return -ENODEV;
5252

5353
/* Create a zone with 2 trips with marked as read only */
54-
soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1);
54+
soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, true,
55+
crit_offset);
5556
if (IS_ERR(soc_dts)) {
5657
err = PTR_ERR(soc_dts);
5758
return err;
@@ -88,21 +89,7 @@ static int __init intel_soc_thermal_init(void)
8889
}
8990
}
9091

91-
err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
92-
crit_offset);
93-
if (err)
94-
goto error_trips;
95-
9692
return 0;
97-
98-
error_trips:
99-
if (soc_dts_thres_irq) {
100-
free_irq(soc_dts_thres_irq, soc_dts);
101-
acpi_unregister_gsi(soc_dts_thres_gsi);
102-
}
103-
intel_soc_dts_iosf_exit(soc_dts);
104-
105-
return err;
10693
}
10794

10895
static void __exit intel_soc_thermal_exit(void)

0 commit comments

Comments
 (0)