Skip to content

Commit d7203ee

Browse files
committed
thermal/core: Add critical and hot ops
Currently there is no way to the sensors to directly call an ops in interrupt mode without calling thermal_zone_device_update assuming all the trip points are defined. A sensor may want to do something special if a trip point is hot or critical. This patch adds the critical and hot ops to the thermal zone device, so a sensor can directly invoke them or let the thermal framework to call the sensor specific ones. Tested-by: Kai-Heng Feng <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 433178e commit d7203ee

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

drivers/thermal/thermal_core.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,25 @@ static void thermal_emergency_poweroff(void)
380380
msecs_to_jiffies(poweroff_delay_ms));
381381
}
382382

383+
void thermal_zone_device_critical(struct thermal_zone_device *tz)
384+
{
385+
dev_emerg(&tz->device, "%s: critical temperature reached, "
386+
"shutting down\n", tz->type);
387+
388+
mutex_lock(&poweroff_lock);
389+
if (!power_off_triggered) {
390+
/*
391+
* Queue a backup emergency shutdown in the event of
392+
* orderly_poweroff failure
393+
*/
394+
thermal_emergency_poweroff();
395+
orderly_poweroff(true);
396+
power_off_triggered = true;
397+
}
398+
mutex_unlock(&poweroff_lock);
399+
}
400+
EXPORT_SYMBOL(thermal_zone_device_critical);
401+
383402
static void handle_critical_trips(struct thermal_zone_device *tz,
384403
int trip, enum thermal_trip_type trip_type)
385404
{
@@ -396,22 +415,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
396415
if (tz->ops->notify)
397416
tz->ops->notify(tz, trip, trip_type);
398417

399-
if (trip_type == THERMAL_TRIP_CRITICAL) {
400-
dev_emerg(&tz->device,
401-
"critical temperature reached (%d C), shutting down\n",
402-
tz->temperature / 1000);
403-
mutex_lock(&poweroff_lock);
404-
if (!power_off_triggered) {
405-
/*
406-
* Queue a backup emergency shutdown in the event of
407-
* orderly_poweroff failure
408-
*/
409-
thermal_emergency_poweroff();
410-
orderly_poweroff(true);
411-
power_off_triggered = true;
412-
}
413-
mutex_unlock(&poweroff_lock);
414-
}
418+
if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
419+
tz->ops->hot(tz);
420+
else if (trip_type == THERMAL_TRIP_CRITICAL)
421+
tz->ops->critical(tz);
415422
}
416423

417424
static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
@@ -1336,6 +1343,10 @@ thermal_zone_device_register(const char *type, int trips, int mask,
13361343

13371344
tz->id = id;
13381345
strlcpy(tz->type, type, sizeof(tz->type));
1346+
1347+
if (!ops->critical)
1348+
ops->critical = thermal_zone_device_critical;
1349+
13391350
tz->ops = ops;
13401351
tz->tzp = tzp;
13411352
tz->device.class = &thermal_class;

include/linux/thermal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct thermal_zone_device_ops {
7979
enum thermal_trend *);
8080
int (*notify) (struct thermal_zone_device *, int,
8181
enum thermal_trip_type);
82+
void (*hot)(struct thermal_zone_device *);
83+
void (*critical)(struct thermal_zone_device *);
8284
};
8385

8486
struct thermal_cooling_device_ops {
@@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);
399401
void thermal_notify_framework(struct thermal_zone_device *, int);
400402
int thermal_zone_device_enable(struct thermal_zone_device *tz);
401403
int thermal_zone_device_disable(struct thermal_zone_device *tz);
404+
void thermal_zone_device_critical(struct thermal_zone_device *tz);
402405
#else
403406
static inline struct thermal_zone_device *thermal_zone_device_register(
404407
const char *type, int trips, int mask, void *devdata,

0 commit comments

Comments
 (0)