Skip to content

Commit 5340f76

Browse files
committed
thermal: core: Add flags to struct thermal_trip
In order to allow thermal zone creators to specify the writability of trip point temperature and hysteresis on a per-trip basis, add a flags field to struct thermal_trip and define flags to represent the desired trip properties. Also make thermal_zone_device_register_with_trips() set the THERMAL_TRIP_FLAG_RW_TEMP flag for all trips covered by the writable trips mask passed to it and modify the thermal sysfs code to look at the trip flags instead of using the writable trips mask directly or checking the presence of the .set_trip_hyst() zone callback. Additionally, make trip_point_temp_store() and trip_point_hyst_store() fail with an error code if the trip passed to one of them has THERMAL_TRIP_FLAG_RW_TEMP or THERMAL_TRIP_FLAG_RW_HYST, respectively, clear in its flags. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent da19833 commit 5340f76

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

drivers/thermal/thermal_core.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ thermal_zone_device_register_with_trips(const char *type,
12781278
int passive_delay, int polling_delay)
12791279
{
12801280
struct thermal_zone_device *tz;
1281+
struct thermal_trip *trip;
12811282
int id;
12821283
int result;
12831284
struct thermal_governor *governor;
@@ -1356,13 +1357,19 @@ thermal_zone_device_register_with_trips(const char *type,
13561357
tz->devdata = devdata;
13571358
tz->num_trips = num_trips;
13581359
memcpy(tz->trips, trips, num_trips * sizeof(*trips));
1360+
for_each_trip(tz, trip) {
1361+
if (mask & 1)
1362+
trip->flags |= THERMAL_TRIP_FLAG_RW_TEMP;
1363+
1364+
mask >>= 1;
1365+
}
13591366

13601367
thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
13611368
thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);
13621369

13631370
/* sys I/F */
13641371
/* Add nodes that are always present via .groups */
1365-
result = thermal_zone_create_device_groups(tz, mask);
1372+
result = thermal_zone_create_device_groups(tz);
13661373
if (result)
13671374
goto remove_id;
13681375

drivers/thermal/thermal_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void thermal_zone_trip_updated(struct thermal_zone_device *tz,
131131
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
132132

133133
/* sysfs I/F */
134-
int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
134+
int thermal_zone_create_device_groups(struct thermal_zone_device *tz);
135135
void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
136136
void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
137137
void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);

drivers/thermal/thermal_sysfs.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,16 @@ static const struct attribute_group *thermal_zone_attribute_groups[] = {
392392
/**
393393
* create_trip_attrs() - create attributes for trip points
394394
* @tz: the thermal zone device
395-
* @mask: Writeable trip point bitmap.
396395
*
397396
* helper function to instantiate sysfs entries for every trip
398397
* point and its properties of a struct thermal_zone_device.
399398
*
400399
* Return: 0 on success, the proper error value otherwise.
401400
*/
402-
static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
401+
static int create_trip_attrs(struct thermal_zone_device *tz)
403402
{
403+
const struct thermal_trip *trip;
404404
struct attribute **attrs;
405-
int indx;
406405

407406
/* This function works only for zones with at least one trip */
408407
if (tz->num_trips <= 0)
@@ -437,7 +436,9 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
437436
return -ENOMEM;
438437
}
439438

440-
for (indx = 0; indx < tz->num_trips; indx++) {
439+
for_each_trip(tz, trip) {
440+
int indx = thermal_zone_trip_id(tz, trip);
441+
441442
/* create trip type attribute */
442443
snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
443444
"trip_point_%d_type", indx);
@@ -458,7 +459,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
458459
tz->trip_temp_attrs[indx].name;
459460
tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
460461
tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
461-
if (mask & (1 << indx)) {
462+
if (trip->flags & THERMAL_TRIP_FLAG_RW_TEMP) {
462463
tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
463464
tz->trip_temp_attrs[indx].attr.store =
464465
trip_point_temp_store;
@@ -473,7 +474,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
473474
tz->trip_hyst_attrs[indx].name;
474475
tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
475476
tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
476-
if (tz->ops.set_trip_hyst) {
477+
if (trip->flags & THERMAL_TRIP_FLAG_RW_HYST) {
477478
tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
478479
tz->trip_hyst_attrs[indx].attr.store =
479480
trip_point_hyst_store;
@@ -505,8 +506,7 @@ static void destroy_trip_attrs(struct thermal_zone_device *tz)
505506
kfree(tz->trips_attribute_group.attrs);
506507
}
507508

508-
int thermal_zone_create_device_groups(struct thermal_zone_device *tz,
509-
int mask)
509+
int thermal_zone_create_device_groups(struct thermal_zone_device *tz)
510510
{
511511
const struct attribute_group **groups;
512512
int i, size, result;
@@ -522,7 +522,7 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz,
522522
groups[i] = thermal_zone_attribute_groups[i];
523523

524524
if (tz->num_trips) {
525-
result = create_trip_attrs(tz, mask);
525+
result = create_trip_attrs(tz);
526526
if (result) {
527527
kfree(groups);
528528

include/linux/thermal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,23 @@ enum thermal_notify_event {
6464
* @threshold: trip crossing notification threshold miliCelsius
6565
* @type: trip point type
6666
* @priv: pointer to driver data associated with this trip
67+
* @flags: flags representing binary properties of the trip
6768
*/
6869
struct thermal_trip {
6970
int temperature;
7071
int hysteresis;
7172
int threshold;
7273
enum thermal_trip_type type;
74+
u8 flags;
7375
void *priv;
7476
};
7577

78+
#define THERMAL_TRIP_FLAG_RW_TEMP BIT(0)
79+
#define THERMAL_TRIP_FLAG_RW_HYST BIT(1)
80+
81+
#define THERMAL_TRIP_FLAG_RW (THERMAL_TRIP_FLAG_RW_TEMP | \
82+
THERMAL_TRIP_FLAG_RW_HYST)
83+
7684
struct thermal_zone_device_ops {
7785
int (*bind) (struct thermal_zone_device *,
7886
struct thermal_cooling_device *);

0 commit comments

Comments
 (0)