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

Commit 6fb75c9

Browse files
committed
thermal: uniphier: Use thermal_zone_for_each_trip() for walking trip points
It is generally inefficient to iterate over trip indices and call thermal_zone_get_trip() every time to get the struct thermal_trip corresponding to the given trip index, so modify the uniphier thermal driver to use thermal_zone_for_each_trip() for walking trips. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com> Link: https://patch.msgid.link/2148114.bB369e8A3T@kreacher [ rjw: Add missing return statement, remove unused local variable ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent efde8bf commit 6fb75c9

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

drivers/thermal/uniphier_thermal.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,34 @@ static irqreturn_t uniphier_tm_alarm_irq_thread(int irq, void *_tdev)
239239
return IRQ_HANDLED;
240240
}
241241

242+
struct trip_walk_data {
243+
struct uniphier_tm_dev *tdev;
244+
int crit_temp;
245+
int index;
246+
};
247+
248+
static int uniphier_tm_trip_walk_cb(struct thermal_trip *trip, void *arg)
249+
{
250+
struct trip_walk_data *twd = arg;
251+
252+
if (trip->type == THERMAL_TRIP_CRITICAL &&
253+
trip->temperature < twd->crit_temp)
254+
twd->crit_temp = trip->temperature;
255+
256+
uniphier_tm_set_alert(twd->tdev, twd->index, trip->temperature);
257+
twd->tdev->alert_en[twd->index++] = true;
258+
259+
return 0;
260+
}
261+
242262
static int uniphier_tm_probe(struct platform_device *pdev)
243263
{
264+
struct trip_walk_data twd = { .crit_temp = INT_MAX, .index = 0 };
244265
struct device *dev = &pdev->dev;
245266
struct regmap *regmap;
246267
struct device_node *parent;
247268
struct uniphier_tm_dev *tdev;
248-
int i, ret, irq, crit_temp = INT_MAX;
269+
int ret, irq;
249270

250271
tdev = devm_kzalloc(dev, sizeof(*tdev), GFP_KERNEL);
251272
if (!tdev)
@@ -293,20 +314,10 @@ static int uniphier_tm_probe(struct platform_device *pdev)
293314
}
294315

295316
/* set alert temperatures */
296-
for (i = 0; i < thermal_zone_get_num_trips(tdev->tz_dev); i++) {
297-
struct thermal_trip trip;
317+
twd.tdev = tdev;
318+
thermal_zone_for_each_trip(tdev->tz_dev, uniphier_tm_trip_walk_cb, &twd);
298319

299-
ret = thermal_zone_get_trip(tdev->tz_dev, i, &trip);
300-
if (ret)
301-
return ret;
302-
303-
if (trip.type == THERMAL_TRIP_CRITICAL &&
304-
trip.temperature < crit_temp)
305-
crit_temp = trip.temperature;
306-
uniphier_tm_set_alert(tdev, i, trip.temperature);
307-
tdev->alert_en[i] = true;
308-
}
309-
if (crit_temp > CRITICAL_TEMP_LIMIT) {
320+
if (twd.crit_temp > CRITICAL_TEMP_LIMIT) {
310321
dev_err(dev, "critical trip is over limit(>%d), or not set\n",
311322
CRITICAL_TEMP_LIMIT);
312323
return -EINVAL;

0 commit comments

Comments
 (0)