Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 0728c81

Browse files
committed
thermal: trip: Pass trip pointer to .set_trip_temp() thermal zone callback
Out of several drivers implementing the .set_trip_temp() thermal zone operation, three don't actually use the trip ID argument passed to it, two call __thermal_zone_get_trip() to get a struct thermal_trip corresponding to the given trip ID, and the other use the trip ID as an index into their own data structures with the assumption that it will always match the ordering of entries in the trips table passed to the core during thermal zone registration, which is fragile and not really guaranteed. Even though the trip IDs used by the core are in fact their indices in the trips table passed to it by the thermal zone creator, that is purely a matter of convenience and should not be relied on for correctness. For this reason, modify trip_point_temp_store() to pass a (const) trip pointer to .set_trip_temp() and adjust the drivers implementing it accordingly. This helps to simplify the drivers invoking __thermal_zone_get_trip() from their .set_trip_temp() callback functions because they will not need to do it now and the other drivers can store their internal trip indices in the priv field in struct thermal_trip and their .set_trip_temp() callback functions can get those indices from there. The intel_quark_dts thermal driver can instead use the trip type to determine the requisite trip index. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/8392906.T7Z3S40VBb@rjwysocki.net [ rjw: Add missing colon and 2 empty code lines ] [ rjw: Add missing change in imx_thermal.c and adjust the changelog ] [ rjw: Drop an unused local variable ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 81caa5d commit 0728c81

File tree

11 files changed

+58
-41
lines changed

11 files changed

+58
-41
lines changed

drivers/net/wireless/intel/iwlwifi/mvm/tt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
638638
}
639639

640640
static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
641-
int trip, int temp)
641+
const struct thermal_trip *trip, int temp)
642642
{
643643
struct iwl_mvm *mvm = thermal_zone_device_priv(device);
644644
int ret;

drivers/thermal/imx_thermal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ static int imx_change_mode(struct thermal_zone_device *tz,
331331
return 0;
332332
}
333333

334-
static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
335-
int temp)
334+
static int imx_set_trip_temp(struct thermal_zone_device *tz,
335+
const struct thermal_trip *trip, int temp)
336336
{
337337
struct imx_thermal_data *data = thermal_zone_device_priv(tz);
338338
int ret;

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
3939
}
4040

4141
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
42-
int trip, int temp)
42+
const struct thermal_trip *trip, int temp)
4343
{
4444
struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
45-
char name[] = {'P', 'A', 'T', '0' + trip, '\0'};
45+
unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
46+
char name[] = {'P', 'A', 'T', '0' + trip_index, '\0'};
4647
acpi_status status;
4748

48-
if (trip > 9)
49+
if (trip_index > 9)
4950
return -EINVAL;
5051

5152
status = acpi_execute_simple_method(d->adev->handle, name,
@@ -144,6 +145,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
144145
zone_trips[i].type = THERMAL_TRIP_PASSIVE;
145146
zone_trips[i].temperature = THERMAL_TEMP_INVALID;
146147
zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
148+
zone_trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
147149
}
148150

149151
trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
194194
return 0;
195195
}
196196

197-
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
197+
static int sys_set_trip_temp(struct thermal_zone_device *tzd,
198+
const struct thermal_trip *trip, int temp)
198199
{
199200
struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd);
200201
int tjmax, _temp;

drivers/thermal/intel/intel_quark_dts_thermal.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int get_trip_temp(int trip)
195195
}
196196

197197
static int update_trip_temp(struct soc_sensor_entry *aux_entry,
198-
int trip, int temp)
198+
int trip_index, int temp)
199199
{
200200
u32 out;
201201
u32 temp_out;
@@ -230,9 +230,9 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
230230
*/
231231
temp_out = temp + QRK_DTS_TEMP_BASE;
232232
out = (store_ptps & ~(QRK_DTS_MASK_TP_THRES <<
233-
(trip * QRK_DTS_SHIFT_TP)));
233+
(trip_index * QRK_DTS_SHIFT_TP)));
234234
out |= (temp_out & QRK_DTS_MASK_TP_THRES) <<
235-
(trip * QRK_DTS_SHIFT_TP);
235+
(trip_index * QRK_DTS_SHIFT_TP);
236236

237237
ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE,
238238
QRK_DTS_REG_OFFSET_PTPS, out);
@@ -242,10 +242,26 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
242242
return ret;
243243
}
244244

245-
static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
246-
int temp)
245+
static inline int sys_set_trip_temp(struct thermal_zone_device *tzd,
246+
const struct thermal_trip *trip,
247+
int temp)
247248
{
248-
return update_trip_temp(thermal_zone_device_priv(tzd), trip, temp);
249+
unsigned int trip_index;
250+
251+
switch (trip->type) {
252+
case THERMAL_TRIP_HOT:
253+
trip_index = QRK_DTS_ID_TP_HOT;
254+
break;
255+
256+
case THERMAL_TRIP_CRITICAL:
257+
trip_index = QRK_DTS_ID_TP_CRITICAL;
258+
break;
259+
260+
default:
261+
return -EINVAL;
262+
}
263+
264+
return update_trip_temp(thermal_zone_device_priv(tzd), trip_index, temp);
249265
}
250266

251267
static int sys_get_curr_temp(struct thermal_zone_device *tzd,

drivers/thermal/intel/intel_soc_dts_iosf.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,20 @@ static int update_trip_temp(struct intel_soc_dts_sensors *sensors,
129129
return status;
130130
}
131131

132-
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
132+
static int sys_set_trip_temp(struct thermal_zone_device *tzd,
133+
const struct thermal_trip *trip,
133134
int temp)
134135
{
135136
struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd);
136137
struct intel_soc_dts_sensors *sensors = dts->sensors;
138+
unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
137139
int status;
138140

139141
if (temp > sensors->tj_max)
140142
return -EINVAL;
141143

142144
mutex_lock(&sensors->dts_update_lock);
143-
status = update_trip_temp(sensors, trip, temp);
145+
status = update_trip_temp(sensors, trip_index, temp);
144146
mutex_unlock(&sensors->dts_update_lock);
145147

146148
return status;
@@ -293,11 +295,12 @@ static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index
293295
}
294296

295297
static void set_trip(struct thermal_trip *trip, enum thermal_trip_type type,
296-
u8 flags, int temp)
298+
u8 flags, int temp, unsigned int index)
297299
{
298300
trip->type = type;
299301
trip->flags = flags;
300302
trip->temperature = temp;
303+
trip->priv = THERMAL_INT_TO_TRIP_PRIV(index);
301304
}
302305

303306
struct intel_soc_dts_sensors *
@@ -332,18 +335,18 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
332335
sensors->soc_dts[i].sensors = sensors;
333336

334337
set_trip(&trips[i][0], THERMAL_TRIP_PASSIVE,
335-
THERMAL_TRIP_FLAG_RW_TEMP, 0);
338+
THERMAL_TRIP_FLAG_RW_TEMP, 0, 0);
336339

337340
ret = update_trip_temp(sensors, 0, 0);
338341
if (ret)
339342
goto err_reset_trips;
340343

341344
if (critical_trip) {
342345
temp = sensors->tj_max - crit_offset;
343-
set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp);
346+
set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp, 1);
344347
} else {
345348
set_trip(&trips[i][1], THERMAL_TRIP_PASSIVE,
346-
THERMAL_TRIP_FLAG_RW_TEMP, 0);
349+
THERMAL_TRIP_FLAG_RW_TEMP, 0, 1);
347350
temp = 0;
348351
}
349352

drivers/thermal/intel/x86_pkg_temp_thermal.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
119119
}
120120

121121
static int
122-
sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
122+
sys_set_trip_temp(struct thermal_zone_device *tzd,
123+
const struct thermal_trip *trip, int temp)
123124
{
124125
struct zone_device *zonedev = thermal_zone_device_priv(tzd);
126+
unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
125127
u32 l, h, mask, shift, intr;
126128
int tj_max, val, ret;
127129

@@ -132,15 +134,15 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
132134

133135
val = (tj_max - temp)/1000;
134136

135-
if (trip >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f)
137+
if (trip_index >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f)
136138
return -EINVAL;
137139

138140
ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
139141
&l, &h);
140142
if (ret < 0)
141143
return ret;
142144

143-
if (trip) {
145+
if (trip_index) {
144146
mask = THERM_MASK_THRESHOLD1;
145147
shift = THERM_SHIFT_THRESHOLD1;
146148
intr = THERM_INT_THRESHOLD1_ENABLE;
@@ -296,6 +298,7 @@ static int pkg_temp_thermal_trips_init(int cpu, int tj_max,
296298

297299
trips[i].type = THERMAL_TRIP_PASSIVE;
298300
trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
301+
trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
299302

300303
pr_debug("%s: cpu=%d, trip=%d, temp=%d\n",
301304
__func__, cpu, i, trips[i].temperature);

drivers/thermal/qcom/qcom-spmi-temp-alarm.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,13 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
261261
return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg);
262262
}
263263

264-
static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp)
264+
static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz,
265+
const struct thermal_trip *trip, int temp)
265266
{
266267
struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz);
267-
struct thermal_trip trip;
268268
int ret;
269269

270-
ret = __thermal_zone_get_trip(chip->tz_dev, trip_id, &trip);
271-
if (ret)
272-
return ret;
273-
274-
if (trip.type != THERMAL_TRIP_CRITICAL)
270+
if (trip->type != THERMAL_TRIP_CRITICAL)
275271
return 0;
276272

277273
mutex_lock(&chip->lock);

drivers/thermal/tegra/soctherm.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,23 +582,18 @@ static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)
582582
return temp;
583583
}
584584

585-
static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp)
585+
static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz,
586+
const struct thermal_trip *trip, int temp)
586587
{
587588
struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz);
588589
struct tegra_soctherm *ts = zone->ts;
589-
struct thermal_trip trip;
590590
const struct tegra_tsensor_group *sg = zone->sg;
591591
struct device *dev = zone->dev;
592-
int ret;
593592

594593
if (!tz)
595594
return -EINVAL;
596595

597-
ret = __thermal_zone_get_trip(tz, trip_id, &trip);
598-
if (ret)
599-
return ret;
600-
601-
if (trip.type == THERMAL_TRIP_CRITICAL) {
596+
if (trip->type == THERMAL_TRIP_CRITICAL) {
602597
/*
603598
* If thermtrips property is set in DT,
604599
* doesn't need to program critical type trip to HW,
@@ -609,7 +604,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip
609604
else
610605
return 0;
611606

612-
} else if (trip.type == THERMAL_TRIP_HOT) {
607+
} else if (trip->type == THERMAL_TRIP_HOT) {
613608
int i;
614609

615610
for (i = 0; i < THROTTLE_SIZE; i++) {
@@ -620,7 +615,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip
620615
continue;
621616

622617
cdev = ts->throt_cfgs[i].cdev;
623-
if (get_thermal_instance(tz, cdev, trip_id))
618+
if (thermal_trip_is_bound_to_cdev(tz, trip, cdev))
624619
stc = find_throttle_cfg_by_name(ts, cdev->type);
625620
else
626621
continue;

drivers/thermal/thermal_sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
113113

114114
if (temp != trip->temperature) {
115115
if (tz->ops.set_trip_temp) {
116-
ret = tz->ops.set_trip_temp(tz, trip_id, temp);
116+
ret = tz->ops.set_trip_temp(tz, trip, temp);
117117
if (ret)
118118
goto unlock;
119119
}

0 commit comments

Comments
 (0)