Skip to content

Commit 5ae98b5

Browse files
committed
Merge back thermal core material for 6.12.
2 parents 6e6f58a + 107280e commit 5ae98b5

File tree

12 files changed

+151
-265
lines changed

12 files changed

+151
-265
lines changed

Documentation/driver-api/thermal/sysfs-api.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,7 @@ are supposed to implement the callback. If they don't, the thermal
459459
framework calculated the trend by comparing the previous and the current
460460
temperature values.
461461

462-
4.2. get_thermal_instance
463-
-------------------------
464-
465-
This function returns the thermal_instance corresponding to a given
466-
{thermal_zone, cooling_device, trip_point} combination. Returns NULL
467-
if such an instance does not exist.
468-
469-
4.3. thermal_cdev_update
462+
4.2. thermal_cdev_update
470463
------------------------
471464

472465
This function serves as an arbitrator to set the state of a cooling

drivers/thermal/broadcom/bcm2835_thermal.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,15 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
208208
*/
209209
val = readl(data->regs + BCM2835_TS_TSENSCTL);
210210
if (!(val & BCM2835_TS_TSENSCTL_RSTB)) {
211-
struct thermal_trip trip;
212-
int offset, slope;
211+
int offset, slope, crit_temp;
213212

214213
slope = thermal_zone_get_slope(tz);
215214
offset = thermal_zone_get_offset(tz);
216215
/*
217216
* For now we deal only with critical, otherwise
218217
* would need to iterate
219218
*/
220-
err = thermal_zone_get_trip(tz, 0, &trip);
219+
err = thermal_zone_get_crit_temp(tz, &crit_temp);
221220
if (err < 0) {
222221
dev_err(dev, "Not able to read trip_temp: %d\n", err);
223222
return err;
@@ -232,7 +231,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
232231
val |= (0xFE << BCM2835_TS_TSENSCTL_RSTDELAY_SHIFT);
233232

234233
/* trip_adc value from info */
235-
val |= bcm2835_thermal_temp2adc(trip.temperature,
234+
val |= bcm2835_thermal_temp2adc(crit_temp,
236235
offset,
237236
slope)
238237
<< BCM2835_TS_TSENSCTL_THOLD_SHIFT;

drivers/thermal/hisi_thermal.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,22 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
465465
return IRQ_HANDLED;
466466
}
467467

468+
static int hisi_trip_walk_cb(struct thermal_trip *trip, void *arg)
469+
{
470+
struct hisi_thermal_sensor *sensor = arg;
471+
472+
if (trip->type != THERMAL_TRIP_PASSIVE)
473+
return 0;
474+
475+
sensor->thres_temp = trip->temperature;
476+
/* Return nonzero to terminate the search. */
477+
return 1;
478+
}
479+
468480
static int hisi_thermal_register_sensor(struct platform_device *pdev,
469481
struct hisi_thermal_sensor *sensor)
470482
{
471-
int ret, i;
472-
struct thermal_trip trip;
483+
int ret;
473484

474485
sensor->tzd = devm_thermal_of_zone_register(&pdev->dev,
475486
sensor->id, sensor,
@@ -482,15 +493,7 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,
482493
return ret;
483494
}
484495

485-
for (i = 0; i < thermal_zone_get_num_trips(sensor->tzd); i++) {
486-
487-
thermal_zone_get_trip(sensor->tzd, i, &trip);
488-
489-
if (trip.type == THERMAL_TRIP_PASSIVE) {
490-
sensor->thres_temp = trip.temperature;
491-
break;
492-
}
493-
}
496+
thermal_zone_for_each_trip(sensor->tzd, hisi_trip_walk_cb, sensor);
494497

495498
return 0;
496499
}

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,6 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data)
291291
return IRQ_HANDLED;
292292
}
293293

294-
static int qpnp_tm_get_critical_trip_temp(struct qpnp_tm_chip *chip)
295-
{
296-
struct thermal_trip trip;
297-
int i, ret;
298-
299-
for (i = 0; i < thermal_zone_get_num_trips(chip->tz_dev); i++) {
300-
301-
ret = thermal_zone_get_trip(chip->tz_dev, i, &trip);
302-
if (ret)
303-
continue;
304-
305-
if (trip.type == THERMAL_TRIP_CRITICAL)
306-
return trip.temperature;
307-
}
308-
309-
return THERMAL_TEMP_INVALID;
310-
}
311-
312294
/*
313295
* This function initializes the internal temp value based on only the
314296
* current thermal stage and threshold. Setup threshold control and
@@ -343,7 +325,9 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip)
343325

344326
mutex_unlock(&chip->lock);
345327

346-
crit_temp = qpnp_tm_get_critical_trip_temp(chip);
328+
ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp);
329+
if (ret)
330+
crit_temp = THERMAL_TEMP_INVALID;
347331

348332
mutex_lock(&chip->lock);
349333

drivers/thermal/renesas/rcar_gen3_thermal.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,7 @@ static int rcar_gen3_thermal_probe(struct platform_device *pdev)
563563
if (ret)
564564
goto error_unregister;
565565

566-
ret = thermal_zone_get_num_trips(tsc->zone);
567-
if (ret < 0)
568-
goto error_unregister;
569-
570-
dev_info(dev, "Sensor %u: Loaded %d trip points\n", i, ret);
566+
dev_info(dev, "Sensor %u: Loaded\n", i);
571567
}
572568

573569
if (!priv->num_tscs) {

drivers/thermal/tegra/soctherm.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -682,24 +682,25 @@ static const struct thermal_zone_device_ops tegra_of_thermal_ops = {
682682
.set_trips = tegra_thermctl_set_trips,
683683
};
684684

685-
static int get_hot_temp(struct thermal_zone_device *tz, int *trip_id, int *temp)
685+
static int get_hot_trip_cb(struct thermal_trip *trip, void *arg)
686686
{
687-
int i, ret;
688-
struct thermal_trip trip;
687+
const struct thermal_trip **trip_ret = arg;
689688

690-
for (i = 0; i < thermal_zone_get_num_trips(tz); i++) {
689+
if (trip->type != THERMAL_TRIP_HOT)
690+
return 0;
691691

692-
ret = thermal_zone_get_trip(tz, i, &trip);
693-
if (ret)
694-
return -EINVAL;
692+
*trip_ret = trip;
693+
/* Return nonzero to terminate the search. */
694+
return 1;
695+
}
695696

696-
if (trip.type == THERMAL_TRIP_HOT) {
697-
*trip_id = i;
698-
return 0;
699-
}
700-
}
697+
static const struct thermal_trip *get_hot_trip(struct thermal_zone_device *tz)
698+
{
699+
const struct thermal_trip *trip = NULL;
701700

702-
return -EINVAL;
701+
thermal_zone_for_each_trip(tz, get_hot_trip_cb, &trip);
702+
703+
return trip;
703704
}
704705

705706
/**
@@ -731,8 +732,9 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
731732
struct thermal_zone_device *tz)
732733
{
733734
struct tegra_soctherm *ts = dev_get_drvdata(dev);
735+
const struct thermal_trip *hot_trip;
734736
struct soctherm_throt_cfg *stc;
735-
int i, trip, temperature, ret;
737+
int i, temperature, ret;
736738

737739
/* Get thermtrips. If missing, try to get critical trips. */
738740
temperature = tsensor_group_thermtrip_get(ts, sg->id);
@@ -749,8 +751,8 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
749751
dev_info(dev, "thermtrip: will shut down when %s reaches %d mC\n",
750752
sg->name, temperature);
751753

752-
ret = get_hot_temp(tz, &trip, &temperature);
753-
if (ret) {
754+
hot_trip = get_hot_trip(tz);
755+
if (!hot_trip) {
754756
dev_info(dev, "throttrip: %s: missing hot temperature\n",
755757
sg->name);
756758
return 0;
@@ -763,7 +765,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
763765
continue;
764766

765767
cdev = ts->throt_cfgs[i].cdev;
766-
if (get_thermal_instance(tz, cdev, trip))
768+
if (thermal_trip_is_bound_to_cdev(tz, hot_trip, cdev))
767769
stc = find_throttle_cfg_by_name(ts, cdev->type);
768770
else
769771
continue;

drivers/thermal/tegra/tegra30-tsensor.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -303,33 +303,37 @@ static int tegra_tsensor_disable_hw_channel(const struct tegra_tsensor *ts,
303303
return 0;
304304
}
305305

306-
static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
307-
int *hot_trip, int *crit_trip)
306+
struct trip_temps {
307+
int hot_trip;
308+
int crit_trip;
309+
};
310+
311+
static int tegra_tsensor_get_trips_cb(struct thermal_trip *trip, void *arg)
308312
{
309-
unsigned int i;
313+
struct trip_temps *temps = arg;
314+
315+
if (trip->type == THERMAL_TRIP_HOT)
316+
temps->hot_trip = trip->temperature;
317+
else if (trip->type == THERMAL_TRIP_CRITICAL)
318+
temps->crit_trip = trip->temperature;
319+
320+
return 0;
321+
}
310322

323+
static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
324+
struct trip_temps *temps)
325+
{
311326
/*
312327
* 90C is the maximal critical temperature of all Tegra30 SoC variants,
313328
* use it for the default trip if unspecified in a device-tree.
314329
*/
315-
*hot_trip = 85000;
316-
*crit_trip = 90000;
317-
318-
for (i = 0; i < thermal_zone_get_num_trips(tzd); i++) {
319-
320-
struct thermal_trip trip;
330+
temps->hot_trip = 85000;
331+
temps->crit_trip = 90000;
321332

322-
thermal_zone_get_trip(tzd, i, &trip);
323-
324-
if (trip.type == THERMAL_TRIP_HOT)
325-
*hot_trip = trip.temperature;
326-
327-
if (trip.type == THERMAL_TRIP_CRITICAL)
328-
*crit_trip = trip.temperature;
329-
}
333+
thermal_zone_for_each_trip(tzd, tegra_tsensor_get_trips_cb, temps);
330334

331335
/* clamp hardware trips to the calibration limits */
332-
*hot_trip = clamp(*hot_trip, 25000, 90000);
336+
temps->hot_trip = clamp(temps->hot_trip, 25000, 90000);
333337

334338
/*
335339
* Kernel will perform a normal system shut down if it will
@@ -338,15 +342,16 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
338342
* shut down gracefully before sending signal to the Power
339343
* Management controller.
340344
*/
341-
*crit_trip = clamp(*crit_trip + 5000, 25000, 90000);
345+
temps->crit_trip = clamp(temps->crit_trip + 5000, 25000, 90000);
342346
}
343347

344348
static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
345349
unsigned int id)
346350
{
347351
const struct tegra_tsensor_channel *tsc = &ts->ch[id];
348352
struct thermal_zone_device *tzd = tsc->tzd;
349-
int err, hot_trip = 0, crit_trip = 0;
353+
struct trip_temps temps = { 0 };
354+
int err;
350355
u32 val;
351356

352357
if (!tzd) {
@@ -357,24 +362,24 @@ static int tegra_tsensor_enable_hw_channel(const struct tegra_tsensor *ts,
357362
return 0;
358363
}
359364

360-
tegra_tsensor_get_hw_channel_trips(tzd, &hot_trip, &crit_trip);
365+
tegra_tsensor_get_hw_channel_trips(tzd, &temps);
361366

362367
dev_info_once(ts->dev, "ch%u: PMC emergency shutdown trip set to %dC\n",
363-
id, DIV_ROUND_CLOSEST(crit_trip, 1000));
368+
id, DIV_ROUND_CLOSEST(temps.crit_trip, 1000));
364369

365-
hot_trip = tegra_tsensor_temp_to_counter(ts, hot_trip);
366-
crit_trip = tegra_tsensor_temp_to_counter(ts, crit_trip);
370+
temps.hot_trip = tegra_tsensor_temp_to_counter(ts, temps.hot_trip);
371+
temps.crit_trip = tegra_tsensor_temp_to_counter(ts, temps.crit_trip);
367372

368373
/* program LEVEL2 counter threshold */
369374
val = readl_relaxed(tsc->regs + TSENSOR_SENSOR0_CONFIG1);
370375
val &= ~TSENSOR_SENSOR0_CONFIG1_TH2;
371-
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG1_TH2, hot_trip);
376+
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG1_TH2, temps.hot_trip);
372377
writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG1);
373378

374379
/* program LEVEL3 counter threshold */
375380
val = readl_relaxed(tsc->regs + TSENSOR_SENSOR0_CONFIG2);
376381
val &= ~TSENSOR_SENSOR0_CONFIG2_TH3;
377-
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG2_TH3, crit_trip);
382+
val |= FIELD_PREP(TSENSOR_SENSOR0_CONFIG2_TH3, temps.crit_trip);
378383
writel_relaxed(val, tsc->regs + TSENSOR_SENSOR0_CONFIG2);
379384

380385
/*

drivers/thermal/thermal_core.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@
1515
#include "thermal_netlink.h"
1616
#include "thermal_debugfs.h"
1717

18+
struct thermal_attr {
19+
struct device_attribute attr;
20+
char name[THERMAL_NAME_LENGTH];
21+
};
22+
23+
struct thermal_trip_attrs {
24+
struct thermal_attr type;
25+
struct thermal_attr temp;
26+
struct thermal_attr hyst;
27+
};
28+
1829
struct thermal_trip_desc {
1930
struct thermal_trip trip;
31+
struct thermal_trip_attrs trip_attrs;
2032
struct list_head notify_list_node;
2133
int notify_temp;
2234
int threshold;
@@ -56,9 +68,6 @@ struct thermal_governor {
5668
* @device: &struct device for this thermal zone
5769
* @removal: removal completion
5870
* @resume: resume completion
59-
* @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
60-
* @trip_type_attrs: attributes for trip points for sysfs: trip type
61-
* @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
6271
* @mode: current mode of this thermal zone
6372
* @devdata: private pointer for device private data
6473
* @num_trips: number of trip points the thermal zone supports
@@ -102,9 +111,6 @@ struct thermal_zone_device {
102111
struct completion removal;
103112
struct completion resume;
104113
struct attribute_group trips_attribute_group;
105-
struct thermal_attr *trip_temp_attrs;
106-
struct thermal_attr *trip_type_attrs;
107-
struct thermal_attr *trip_hyst_attrs;
108114
enum thermal_device_mode mode;
109115
void *devdata;
110116
int num_trips;
@@ -188,11 +194,6 @@ int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
188194

189195
struct thermal_zone_device *thermal_zone_get_by_id(int id);
190196

191-
struct thermal_attr {
192-
struct device_attribute attr;
193-
char name[THERMAL_NAME_LENGTH];
194-
};
195-
196197
static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
197198
{
198199
return cdev->ops->get_requested_power && cdev->ops->state2power &&
@@ -204,11 +205,6 @@ void __thermal_cdev_update(struct thermal_cooling_device *cdev);
204205

205206
int get_tz_trend(struct thermal_zone_device *tz, const struct thermal_trip *trip);
206207

207-
struct thermal_instance *
208-
get_thermal_instance(struct thermal_zone_device *tz,
209-
struct thermal_cooling_device *cdev,
210-
int trip);
211-
212208
/*
213209
* This structure is used to describe the behavior of
214210
* a certain cooling device on a certain trip point
@@ -262,11 +258,11 @@ const char *thermal_trip_type_name(enum thermal_trip_type trip_type);
262258
void thermal_zone_set_trips(struct thermal_zone_device *tz);
263259
int thermal_zone_trip_id(const struct thermal_zone_device *tz,
264260
const struct thermal_trip *trip);
265-
void thermal_zone_trip_updated(struct thermal_zone_device *tz,
266-
const struct thermal_trip *trip);
267261
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
268262
void thermal_zone_trip_down(struct thermal_zone_device *tz,
269263
const struct thermal_trip *trip);
264+
void thermal_zone_set_trip_hyst(struct thermal_zone_device *tz,
265+
struct thermal_trip *trip, int hyst);
270266

271267
/* sysfs I/F */
272268
int thermal_zone_create_device_groups(struct thermal_zone_device *tz);

0 commit comments

Comments
 (0)