Skip to content

Commit ac5d9ec

Browse files
andrzejtpdlezcano
authored andcommitted
thermal: Add mode helpers
Prepare for making the drivers not access tzd's private members. Signed-off-by: Andrzej Pietrasiewicz <[email protected]> Reviewed-by: Bartlomiej Zolnierkiewicz <[email protected]> [staticize thermal_zone_device_set_mode()] Signed-off-by: kernel test robot <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1ee1482 commit ac5d9ec

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

drivers/thermal/thermal_core.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,59 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz)
459459
thermal_zone_device_init(tz);
460460
}
461461

462+
static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
463+
enum thermal_device_mode mode)
464+
{
465+
int ret = 0;
466+
467+
mutex_lock(&tz->lock);
468+
469+
/* do nothing if mode isn't changing */
470+
if (mode == tz->mode) {
471+
mutex_unlock(&tz->lock);
472+
473+
return ret;
474+
}
475+
476+
if (tz->ops->set_mode)
477+
ret = tz->ops->set_mode(tz, mode);
478+
479+
if (!ret)
480+
tz->mode = mode;
481+
482+
mutex_unlock(&tz->lock);
483+
484+
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
485+
486+
return ret;
487+
}
488+
489+
int thermal_zone_device_enable(struct thermal_zone_device *tz)
490+
{
491+
return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED);
492+
}
493+
EXPORT_SYMBOL_GPL(thermal_zone_device_enable);
494+
495+
int thermal_zone_device_disable(struct thermal_zone_device *tz)
496+
{
497+
return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED);
498+
}
499+
EXPORT_SYMBOL_GPL(thermal_zone_device_disable);
500+
501+
int thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
502+
{
503+
enum thermal_device_mode mode;
504+
505+
mutex_lock(&tz->lock);
506+
507+
mode = tz->mode;
508+
509+
mutex_unlock(&tz->lock);
510+
511+
return mode == THERMAL_DEVICE_ENABLED;
512+
}
513+
EXPORT_SYMBOL_GPL(thermal_zone_device_is_enabled);
514+
462515
void thermal_zone_device_update(struct thermal_zone_device *tz,
463516
enum thermal_notify_event event)
464517
{

include/linux/thermal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz);
416416

417417
void thermal_cdev_update(struct thermal_cooling_device *);
418418
void thermal_notify_framework(struct thermal_zone_device *, int);
419+
int thermal_zone_device_enable(struct thermal_zone_device *tz);
420+
int thermal_zone_device_disable(struct thermal_zone_device *tz);
421+
int thermal_zone_device_is_enabled(struct thermal_zone_device *tz);
419422
#else
420423
static inline struct thermal_zone_device *thermal_zone_device_register(
421424
const char *type, int trips, int mask, void *devdata,
@@ -463,6 +466,16 @@ static inline void thermal_cdev_update(struct thermal_cooling_device *cdev)
463466
static inline void thermal_notify_framework(struct thermal_zone_device *tz,
464467
int trip)
465468
{ }
469+
470+
static inline int thermal_zone_device_enable(struct thermal_zone_device *tz)
471+
{ return -ENODEV; }
472+
473+
static inline int thermal_zone_device_disable(struct thermal_zone_device *tz)
474+
{ return -ENODEV; }
475+
476+
static inline int
477+
thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
478+
{ return -ENODEV; }
466479
#endif /* CONFIG_THERMAL */
467480

468481
#endif /* __THERMAL_H__ */

0 commit comments

Comments
 (0)