Skip to content

Commit 55cdf0a

Browse files
committed
thermal: core: Add notifications call in the framework
The generic netlink protocol is implemented but the different notification functions are not yet connected to the core code. These changes add the notification calls in the different corresponding places. Reviewed-by: Amit Kucheria <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Zhang Rui <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1ce50e7 commit 55cdf0a

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

drivers/thermal/thermal_core.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz,
215215
mutex_unlock(&tz->lock);
216216
mutex_unlock(&thermal_governor_lock);
217217

218+
thermal_notify_tz_gov_change(tz->id, policy);
219+
218220
return ret;
219221
}
220222

@@ -415,12 +417,25 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
415417
static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
416418
{
417419
enum thermal_trip_type type;
420+
int trip_temp, hyst = 0;
418421

419422
/* Ignore disabled trip points */
420423
if (test_bit(trip, &tz->trips_disabled))
421424
return;
422425

426+
tz->ops->get_trip_temp(tz, trip, &trip_temp);
423427
tz->ops->get_trip_type(tz, trip, &type);
428+
if (tz->ops->get_trip_hyst)
429+
tz->ops->get_trip_hyst(tz, trip, &hyst);
430+
431+
if (tz->last_temperature != THERMAL_TEMP_INVALID) {
432+
if (tz->last_temperature < trip_temp &&
433+
tz->temperature >= trip_temp)
434+
thermal_notify_tz_trip_up(tz->id, trip);
435+
if (tz->last_temperature >= trip_temp &&
436+
tz->temperature < (trip_temp - hyst))
437+
thermal_notify_tz_trip_down(tz->id, trip);
438+
}
424439

425440
if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
426441
handle_critical_trips(tz, trip, type);
@@ -452,6 +467,8 @@ static void update_temperature(struct thermal_zone_device *tz)
452467
mutex_unlock(&tz->lock);
453468

454469
trace_thermal_temperature(tz);
470+
471+
thermal_genl_sampling_temp(tz->id, temp);
455472
}
456473

457474
static void thermal_zone_device_init(struct thermal_zone_device *tz)
@@ -1469,6 +1486,8 @@ thermal_zone_device_register(const char *type, int trips, int mask,
14691486
if (atomic_cmpxchg(&tz->need_update, 1, 0))
14701487
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
14711488

1489+
thermal_notify_tz_create(tz->id, tz->type);
1490+
14721491
return tz;
14731492

14741493
unregister:
@@ -1540,6 +1559,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
15401559
ida_destroy(&tz->ida);
15411560
mutex_destroy(&tz->lock);
15421561
device_unregister(&tz->device);
1562+
1563+
thermal_notify_tz_delete(tz->id);
15431564
}
15441565
EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
15451566

drivers/thermal/thermal_helpers.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
175175
mutex_unlock(&tz->lock);
176176
}
177177

178+
static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
179+
int target)
180+
{
181+
if (cdev->ops->set_cur_state(cdev, target))
182+
return;
183+
184+
thermal_notify_cdev_state_update(cdev->id, target);
185+
thermal_cooling_device_stats_update(cdev, target);
186+
}
187+
178188
void thermal_cdev_update(struct thermal_cooling_device *cdev)
179189
{
180190
struct thermal_instance *instance;
@@ -197,8 +207,7 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
197207
target = instance->target;
198208
}
199209

200-
if (!cdev->ops->set_cur_state(cdev, target))
201-
thermal_cooling_device_stats_update(cdev, target);
210+
thermal_cdev_set_cur_state(cdev, target);
202211

203212
cdev->updated = true;
204213
mutex_unlock(&cdev->lock);

drivers/thermal/thermal_sysfs.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
112112
{
113113
struct thermal_zone_device *tz = to_thermal_zone(dev);
114114
int trip, ret;
115-
int temperature;
115+
int temperature, hyst = 0;
116+
enum thermal_trip_type type;
116117

117118
if (!tz->ops->set_trip_temp)
118119
return -EPERM;
@@ -127,6 +128,18 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
127128
if (ret)
128129
return ret;
129130

131+
if (tz->ops->get_trip_hyst) {
132+
ret = tz->ops->get_trip_hyst(tz, trip, &hyst);
133+
if (ret)
134+
return ret;
135+
}
136+
137+
ret = tz->ops->get_trip_type(tz, trip, &type);
138+
if (ret)
139+
return ret;
140+
141+
thermal_notify_tz_trip_change(tz->id, trip, type, temperature, hyst);
142+
130143
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
131144

132145
return count;

0 commit comments

Comments
 (0)