Skip to content

Commit f4118db

Browse files
committed
thermal: intel: int340x: Use generic trip points table
Modify int340x_thermal_zone_add() to register the thermal zone along with a trip points table, which allows the trip-related zone callbacks to be dropped, because they are not needed any more. In order to consolidate the code, use ACPI trip library functions to populate generic trip points in int340x_thermal_read_trips() and to update them in int340x_thermal_update_trips(). Signed-off-by: Daniel Lezcano <[email protected]> Co-developed-by: Daniel Lezcano <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 9e9b7e1 commit f4118db

File tree

3 files changed

+84
-180
lines changed

3 files changed

+84
-180
lines changed

drivers/thermal/intel/int340x_thermal/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config INT340X_THERMAL
99
select THERMAL_GOV_USER_SPACE
1010
select ACPI_THERMAL_REL
1111
select ACPI_FAN
12+
select THERMAL_ACPI
1213
select INTEL_SOC_DTS_IOSF_CORE
1314
select INTEL_TCC
1415
select PROC_THERMAL_MMIO_RAPL if POWERCAP

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 81 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -37,65 +37,6 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
3737
return 0;
3838
}
3939

40-
static int int340x_thermal_get_trip_temp(struct thermal_zone_device *zone,
41-
int trip, int *temp)
42-
{
43-
struct int34x_thermal_zone *d = zone->devdata;
44-
int i;
45-
46-
if (trip < d->aux_trip_nr)
47-
*temp = d->aux_trips[trip];
48-
else if (trip == d->crt_trip_id)
49-
*temp = d->crt_temp;
50-
else if (trip == d->psv_trip_id)
51-
*temp = d->psv_temp;
52-
else if (trip == d->hot_trip_id)
53-
*temp = d->hot_temp;
54-
else {
55-
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
56-
if (d->act_trips[i].valid &&
57-
d->act_trips[i].id == trip) {
58-
*temp = d->act_trips[i].temp;
59-
break;
60-
}
61-
}
62-
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
63-
return -EINVAL;
64-
}
65-
66-
return 0;
67-
}
68-
69-
static int int340x_thermal_get_trip_type(struct thermal_zone_device *zone,
70-
int trip,
71-
enum thermal_trip_type *type)
72-
{
73-
struct int34x_thermal_zone *d = zone->devdata;
74-
int i;
75-
76-
if (trip < d->aux_trip_nr)
77-
*type = THERMAL_TRIP_PASSIVE;
78-
else if (trip == d->crt_trip_id)
79-
*type = THERMAL_TRIP_CRITICAL;
80-
else if (trip == d->hot_trip_id)
81-
*type = THERMAL_TRIP_HOT;
82-
else if (trip == d->psv_trip_id)
83-
*type = THERMAL_TRIP_PASSIVE;
84-
else {
85-
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
86-
if (d->act_trips[i].valid &&
87-
d->act_trips[i].id == trip) {
88-
*type = THERMAL_TRIP_ACTIVE;
89-
break;
90-
}
91-
}
92-
if (i == INT340X_THERMAL_MAX_ACT_TRIP_COUNT)
93-
return -EINVAL;
94-
}
95-
96-
return 0;
97-
}
98-
9940
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
10041
int trip, int temp)
10142
{
@@ -109,25 +50,6 @@ static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
10950
if (ACPI_FAILURE(status))
11051
return -EIO;
11152

112-
d->aux_trips[trip] = temp;
113-
114-
return 0;
115-
}
116-
117-
118-
static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,
119-
int trip, int *temp)
120-
{
121-
struct int34x_thermal_zone *d = zone->devdata;
122-
acpi_status status;
123-
unsigned long long hyst;
124-
125-
status = acpi_evaluate_integer(d->adev->handle, "GTSH", NULL, &hyst);
126-
if (ACPI_FAILURE(status))
127-
*temp = 0;
128-
else
129-
*temp = hyst * 100;
130-
13153
return 0;
13254
}
13355

@@ -138,58 +60,35 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone)
13860

13961
static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
14062
.get_temp = int340x_thermal_get_zone_temp,
141-
.get_trip_temp = int340x_thermal_get_trip_temp,
142-
.get_trip_type = int340x_thermal_get_trip_type,
14363
.set_trip_temp = int340x_thermal_set_trip_temp,
144-
.get_trip_hyst = int340x_thermal_get_trip_hyst,
14564
.critical = int340x_thermal_critical,
14665
};
14766

148-
static int int340x_thermal_get_trip_config(acpi_handle handle, char *name,
149-
int *temp)
67+
static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
68+
struct thermal_trip *zone_trips,
69+
int trip_cnt)
15070
{
151-
unsigned long long r;
152-
acpi_status status;
71+
int i, ret;
15372

154-
status = acpi_evaluate_integer(handle, name, NULL, &r);
155-
if (ACPI_FAILURE(status))
156-
return -EIO;
73+
ret = thermal_acpi_trip_critical(zone_adev, &zone_trips[trip_cnt]);
74+
if (!ret)
75+
trip_cnt++;
15776

158-
*temp = deci_kelvin_to_millicelsius(r);
77+
ret = thermal_acpi_trip_hot(zone_adev, &zone_trips[trip_cnt]);
78+
if (!ret)
79+
trip_cnt++;
15980

160-
return 0;
161-
}
162-
163-
static int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone)
164-
{
165-
int trip_cnt = int34x_zone->aux_trip_nr;
166-
int i;
167-
168-
int34x_zone->crt_trip_id = -1;
169-
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_CRT",
170-
&int34x_zone->crt_temp))
171-
int34x_zone->crt_trip_id = trip_cnt++;
172-
173-
int34x_zone->hot_trip_id = -1;
174-
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_HOT",
175-
&int34x_zone->hot_temp))
176-
int34x_zone->hot_trip_id = trip_cnt++;
177-
178-
int34x_zone->psv_trip_id = -1;
179-
if (!int340x_thermal_get_trip_config(int34x_zone->adev->handle, "_PSV",
180-
&int34x_zone->psv_temp))
181-
int34x_zone->psv_trip_id = trip_cnt++;
81+
ret = thermal_acpi_trip_passive(zone_adev, &zone_trips[trip_cnt]);
82+
if (!ret)
83+
trip_cnt++;
18284

18385
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
184-
char name[5] = { '_', 'A', 'C', '0' + i, '\0' };
18586

186-
if (int340x_thermal_get_trip_config(int34x_zone->adev->handle,
187-
name,
188-
&int34x_zone->act_trips[i].temp))
87+
ret = thermal_acpi_trip_active(zone_adev, i, &zone_trips[trip_cnt]);
88+
if (ret)
18989
break;
19090

191-
int34x_zone->act_trips[i].id = trip_cnt++;
192-
int34x_zone->act_trips[i].valid = true;
91+
trip_cnt++;
19392
}
19493

19594
return trip_cnt;
@@ -204,10 +103,12 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
204103
int (*get_temp) (struct thermal_zone_device *, int *))
205104
{
206105
struct int34x_thermal_zone *int34x_thermal_zone;
207-
acpi_status status;
208-
unsigned long long trip_cnt;
106+
struct thermal_trip *zone_trips;
107+
unsigned long long trip_cnt = 0;
108+
unsigned long long hyst;
209109
int trip_mask = 0;
210-
int ret;
110+
acpi_status status;
111+
int i, ret;
211112

212113
int34x_thermal_zone = kzalloc(sizeof(*int34x_thermal_zone),
213114
GFP_KERNEL);
@@ -227,33 +128,42 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
227128
int34x_thermal_zone->ops->get_temp = get_temp;
228129

229130
status = acpi_evaluate_integer(adev->handle, "PATC", NULL, &trip_cnt);
230-
if (ACPI_FAILURE(status))
231-
trip_cnt = 0;
232-
else {
233-
int i;
234-
235-
int34x_thermal_zone->aux_trips =
236-
kcalloc(trip_cnt,
237-
sizeof(*int34x_thermal_zone->aux_trips),
238-
GFP_KERNEL);
239-
if (!int34x_thermal_zone->aux_trips) {
240-
ret = -ENOMEM;
241-
goto err_trip_alloc;
242-
}
243-
trip_mask = BIT(trip_cnt) - 1;
131+
if (!ACPI_FAILURE(status)) {
244132
int34x_thermal_zone->aux_trip_nr = trip_cnt;
245-
for (i = 0; i < trip_cnt; ++i)
246-
int34x_thermal_zone->aux_trips[i] = THERMAL_TEMP_INVALID;
133+
trip_mask = BIT(trip_cnt) - 1;
134+
}
135+
136+
zone_trips = kzalloc(sizeof(*zone_trips) * (trip_cnt + INT340X_THERMAL_MAX_TRIP_COUNT),
137+
GFP_KERNEL);
138+
if (!zone_trips) {
139+
ret = -ENOMEM;
140+
goto err_trips_alloc;
141+
}
142+
143+
for (i = 0; i < trip_cnt; i++) {
144+
zone_trips[i].type = THERMAL_TRIP_PASSIVE;
145+
zone_trips[i].temperature = THERMAL_TEMP_INVALID;
247146
}
248147

249-
trip_cnt = int340x_thermal_read_trips(int34x_thermal_zone);
148+
trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);
149+
150+
status = acpi_evaluate_integer(adev->handle, "GTSH", NULL, &hyst);
151+
if (ACPI_SUCCESS(status))
152+
hyst *= 100;
153+
else
154+
hyst = 0;
155+
156+
for (i = 0; i < trip_cnt; ++i)
157+
zone_trips[i].hysteresis = hyst;
158+
159+
int34x_thermal_zone->trips = zone_trips;
250160

251161
int34x_thermal_zone->lpat_table = acpi_lpat_get_conversion_table(
252162
adev->handle);
253163

254-
int34x_thermal_zone->zone = thermal_zone_device_register(
164+
int34x_thermal_zone->zone = thermal_zone_device_register_with_trips(
255165
acpi_device_bid(adev),
256-
trip_cnt,
166+
zone_trips, trip_cnt,
257167
trip_mask, int34x_thermal_zone,
258168
int34x_thermal_zone->ops,
259169
&int340x_thermal_params,
@@ -271,9 +181,9 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
271181
err_enable:
272182
thermal_zone_device_unregister(int34x_thermal_zone->zone);
273183
err_thermal_zone:
184+
kfree(int34x_thermal_zone->trips);
274185
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
275-
kfree(int34x_thermal_zone->aux_trips);
276-
err_trip_alloc:
186+
err_trips_alloc:
277187
kfree(int34x_thermal_zone->ops);
278188
err_ops_alloc:
279189
kfree(int34x_thermal_zone);
@@ -286,50 +196,49 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone
286196
{
287197
thermal_zone_device_unregister(int34x_thermal_zone->zone);
288198
acpi_lpat_free_conversion_table(int34x_thermal_zone->lpat_table);
289-
kfree(int34x_thermal_zone->aux_trips);
199+
kfree(int34x_thermal_zone->trips);
290200
kfree(int34x_thermal_zone->ops);
291201
kfree(int34x_thermal_zone);
292202
}
293203
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
294204

295205
void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
296206
{
297-
acpi_handle zone_handle = int34x_zone->adev->handle;
298-
int i, err;
207+
struct acpi_device *zone_adev = int34x_zone->adev;
208+
struct thermal_trip *zone_trips = int34x_zone->trips;
209+
int trip_cnt = int34x_zone->zone->num_trips;
210+
int act_trip_nr = 0;
211+
int i;
299212

300213
mutex_lock(&int34x_zone->zone->lock);
301214

302-
if (int34x_zone->crt_trip_id > 0) {
303-
err = int340x_thermal_get_trip_config(zone_handle, "_CRT",
304-
&int34x_zone->crt_temp);
305-
if (err)
306-
int34x_zone->crt_temp = THERMAL_TEMP_INVALID;
307-
}
308-
309-
if (int34x_zone->hot_trip_id > 0) {
310-
err = int340x_thermal_get_trip_config(zone_handle, "_HOT",
311-
&int34x_zone->hot_temp);
312-
if (err)
313-
int34x_zone->hot_temp = THERMAL_TEMP_INVALID;
314-
}
315-
316-
if (int34x_zone->psv_trip_id > 0) {
317-
err = int340x_thermal_get_trip_config(zone_handle, "_PSV",
318-
&int34x_zone->psv_temp);
319-
if (err)
320-
int34x_zone->psv_temp = THERMAL_TEMP_INVALID;
321-
}
215+
for (i = int34x_zone->aux_trip_nr; i < trip_cnt; i++) {
216+
struct thermal_trip trip;
217+
int err;
322218

323-
for (i = 0; i < INT340X_THERMAL_MAX_ACT_TRIP_COUNT; i++) {
324-
char name[5] = { '_', 'A', 'C', '0' + i, '\0' };
325-
326-
if (!int34x_zone->act_trips[i].valid)
219+
switch (zone_trips[i].type) {
220+
case THERMAL_TRIP_CRITICAL:
221+
err = thermal_acpi_trip_critical(zone_adev, &trip);
222+
break;
223+
case THERMAL_TRIP_HOT:
224+
err = thermal_acpi_trip_hot(zone_adev, &trip);
327225
break;
226+
case THERMAL_TRIP_PASSIVE:
227+
err = thermal_acpi_trip_passive(zone_adev, &trip);
228+
break;
229+
case THERMAL_TRIP_ACTIVE:
230+
err = thermal_acpi_trip_active(zone_adev, act_trip_nr++,
231+
&trip);
232+
break;
233+
default:
234+
err = -ENODEV;
235+
}
236+
if (err) {
237+
zone_trips[i].temperature = THERMAL_TEMP_INVALID;
238+
continue;
239+
}
328240

329-
err = int340x_thermal_get_trip_config(zone_handle, name,
330-
&int34x_zone->act_trips[i].temp);
331-
if (err)
332-
int34x_zone->act_trips[i].temp = THERMAL_TEMP_INVALID;
241+
zone_trips[i].temperature = trip.temperature;
333242
}
334243

335244
mutex_unlock(&int34x_zone->zone->lock);

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <acpi/acpi_lpat.h>
1111

1212
#define INT340X_THERMAL_MAX_ACT_TRIP_COUNT 10
13+
#define INT340X_THERMAL_MAX_TRIP_COUNT INT340X_THERMAL_MAX_ACT_TRIP_COUNT + 3
1314

1415
struct active_trip {
1516
int temp;
@@ -19,15 +20,8 @@ struct active_trip {
1920

2021
struct int34x_thermal_zone {
2122
struct acpi_device *adev;
22-
struct active_trip act_trips[INT340X_THERMAL_MAX_ACT_TRIP_COUNT];
23-
unsigned long *aux_trips;
23+
struct thermal_trip *trips;
2424
int aux_trip_nr;
25-
int psv_temp;
26-
int psv_trip_id;
27-
int crt_temp;
28-
int crt_trip_id;
29-
int hot_temp;
30-
int hot_trip_id;
3125
struct thermal_zone_device *zone;
3226
struct thermal_zone_device_ops *ops;
3327
void *priv_data;

0 commit comments

Comments
 (0)