hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/thermal/thermal_core.c
....@@ -9,9 +9,9 @@
99
1010 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1111
12
-#include <linux/module.h>
1312 #include <linux/device.h>
1413 #include <linux/err.h>
14
+#include <linux/export.h>
1515 #include <linux/slab.h>
1616 #include <linux/kdev_t.h>
1717 #include <linux/idr.h>
....@@ -19,22 +19,15 @@
1919 #include <linux/reboot.h>
2020 #include <linux/string.h>
2121 #include <linux/of.h>
22
-#include <net/netlink.h>
23
-#include <net/genetlink.h>
2422 #include <linux/suspend.h>
25
-#ifdef CONFIG_ARCH_ROCKCHIP
26
-#include <soc/rockchip/rockchip_system_monitor.h>
27
-#endif
2823
2924 #define CREATE_TRACE_POINTS
3025 #include <trace/events/thermal.h>
26
+#undef CREATE_TRACE_POINTS
27
+#include <trace/hooks/thermal.h>
3128
3229 #include "thermal_core.h"
3330 #include "thermal_hwmon.h"
34
-
35
-MODULE_AUTHOR("Zhang Rui");
36
-MODULE_DESCRIPTION("Generic thermal management sysfs support");
37
-MODULE_LICENSE("GPL v2");
3831
3932 static DEFINE_IDA(thermal_tz_ida);
4033 static DEFINE_IDA(thermal_cdev_ida);
....@@ -224,6 +217,8 @@
224217 mutex_unlock(&tz->lock);
225218 mutex_unlock(&thermal_governor_lock);
226219
220
+ thermal_notify_tz_gov_change(tz->id, policy);
221
+
227222 return ret;
228223 }
229224
....@@ -245,36 +240,42 @@
245240 return count;
246241 }
247242
248
-static int __init thermal_register_governors(void)
243
+static void __init thermal_unregister_governors(void)
249244 {
250
- int result;
245
+ struct thermal_governor **governor;
251246
252
- result = thermal_gov_step_wise_register();
253
- if (result)
254
- return result;
255
-
256
- result = thermal_gov_fair_share_register();
257
- if (result)
258
- return result;
259
-
260
- result = thermal_gov_bang_bang_register();
261
- if (result)
262
- return result;
263
-
264
- result = thermal_gov_user_space_register();
265
- if (result)
266
- return result;
267
-
268
- return thermal_gov_power_allocator_register();
247
+ for_each_governor_table(governor)
248
+ thermal_unregister_governor(*governor);
269249 }
270250
271
-static void thermal_unregister_governors(void)
251
+static int __init thermal_register_governors(void)
272252 {
273
- thermal_gov_step_wise_unregister();
274
- thermal_gov_fair_share_unregister();
275
- thermal_gov_bang_bang_unregister();
276
- thermal_gov_user_space_unregister();
277
- thermal_gov_power_allocator_unregister();
253
+ int ret = 0;
254
+ struct thermal_governor **governor;
255
+
256
+ for_each_governor_table(governor) {
257
+ ret = thermal_register_governor(*governor);
258
+ if (ret) {
259
+ pr_err("Failed to register governor: '%s'",
260
+ (*governor)->name);
261
+ break;
262
+ }
263
+
264
+ pr_info("Registered thermal governor '%s'",
265
+ (*governor)->name);
266
+ }
267
+
268
+ if (ret) {
269
+ struct thermal_governor **gov;
270
+
271
+ for_each_governor_table(gov) {
272
+ if (gov == governor)
273
+ break;
274
+ thermal_unregister_governor(*gov);
275
+ }
276
+ }
277
+
278
+ return ret;
278279 }
279280
280281 /*
....@@ -292,22 +293,33 @@
292293 int delay)
293294 {
294295 if (delay > 1000)
295
- mod_delayed_work(system_freezable_wq, &tz->poll_queue,
296
+ mod_delayed_work(system_freezable_power_efficient_wq,
297
+ &tz->poll_queue,
296298 round_jiffies(msecs_to_jiffies(delay)));
297299 else if (delay)
298
- mod_delayed_work(system_freezable_wq, &tz->poll_queue,
300
+ mod_delayed_work(system_freezable_power_efficient_wq,
301
+ &tz->poll_queue,
299302 msecs_to_jiffies(delay));
300303 else
301304 cancel_delayed_work(&tz->poll_queue);
302305 }
303306
307
+static inline bool should_stop_polling(struct thermal_zone_device *tz)
308
+{
309
+ return !thermal_zone_device_is_enabled(tz);
310
+}
311
+
304312 static void monitor_thermal_zone(struct thermal_zone_device *tz)
305313 {
314
+ bool stop;
315
+
316
+ stop = should_stop_polling(tz);
317
+
306318 mutex_lock(&tz->lock);
307319
308
- if (tz->passive)
320
+ if (!stop && tz->passive)
309321 thermal_zone_device_set_polling(tz, tz->passive_delay);
310
- else if (tz->polling_delay)
322
+ else if (!stop && tz->polling_delay)
311323 thermal_zone_device_set_polling(tz, tz->polling_delay);
312324 else
313325 thermal_zone_device_set_polling(tz, 0);
....@@ -315,9 +327,7 @@
315327 mutex_unlock(&tz->lock);
316328 }
317329
318
-static void handle_non_critical_trips(struct thermal_zone_device *tz,
319
- int trip,
320
- enum thermal_trip_type trip_type)
330
+static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip)
321331 {
322332 tz->governor ? tz->governor->throttle(tz, trip) :
323333 def_governor->throttle(tz, trip);
....@@ -408,39 +418,35 @@
408418 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
409419 {
410420 enum thermal_trip_type type;
421
+ int trip_temp, hyst = 0;
411422
412423 /* Ignore disabled trip points */
413424 if (test_bit(trip, &tz->trips_disabled))
414425 return;
415426
427
+ tz->ops->get_trip_temp(tz, trip, &trip_temp);
416428 tz->ops->get_trip_type(tz, trip, &type);
429
+ if (tz->ops->get_trip_hyst)
430
+ tz->ops->get_trip_hyst(tz, trip, &hyst);
431
+
432
+ if (tz->last_temperature != THERMAL_TEMP_INVALID) {
433
+ if (tz->last_temperature < trip_temp &&
434
+ tz->temperature >= trip_temp)
435
+ thermal_notify_tz_trip_up(tz->id, trip);
436
+ if (tz->last_temperature >= trip_temp &&
437
+ tz->temperature < (trip_temp - hyst))
438
+ thermal_notify_tz_trip_down(tz->id, trip);
439
+ }
417440
418441 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
419442 handle_critical_trips(tz, trip, type);
420443 else
421
- handle_non_critical_trips(tz, trip, type);
444
+ handle_non_critical_trips(tz, trip);
422445 /*
423446 * Alright, we handled this trip successfully.
424447 * So, start monitoring again.
425448 */
426449 monitor_thermal_zone(tz);
427
-}
428
-
429
-static void store_temperature(struct thermal_zone_device *tz, int temp)
430
-{
431
- mutex_lock(&tz->lock);
432
- tz->last_temperature = tz->temperature;
433
- tz->temperature = temp;
434
- mutex_unlock(&tz->lock);
435
-
436
- trace_thermal_temperature(tz);
437
- if (tz->last_temperature == THERMAL_TEMP_INVALID ||
438
- tz->last_temperature == THERMAL_TEMP_INVALID_LOW)
439
- dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n",
440
- tz->temperature);
441
- else
442
- dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n",
443
- tz->last_temperature, tz->temperature);
444450 }
445451
446452 static void update_temperature(struct thermal_zone_device *tz)
....@@ -455,7 +461,15 @@
455461 ret);
456462 return;
457463 }
458
- store_temperature(tz, temp);
464
+
465
+ mutex_lock(&tz->lock);
466
+ tz->last_temperature = tz->temperature;
467
+ tz->temperature = temp;
468
+ mutex_unlock(&tz->lock);
469
+
470
+ trace_thermal_temperature(tz);
471
+
472
+ thermal_genl_sampling_temp(tz->id, temp);
459473 }
460474
461475 static void thermal_zone_device_init(struct thermal_zone_device *tz)
....@@ -474,38 +488,73 @@
474488 thermal_zone_device_init(tz);
475489 }
476490
477
-void thermal_zone_device_update_temp(struct thermal_zone_device *tz,
478
- enum thermal_notify_event event, int temp)
491
+static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
492
+ enum thermal_device_mode mode)
479493 {
480
- int count;
494
+ int ret = 0;
481495
482
- if (!tz || !tz->ops)
483
- return;
496
+ mutex_lock(&tz->lock);
484497
485
- if (atomic_read(&in_suspend) && (!tz->ops->is_wakeable ||
486
- !(tz->ops->is_wakeable(tz))))
487
- return;
498
+ /* do nothing if mode isn't changing */
499
+ if (mode == tz->mode) {
500
+ mutex_unlock(&tz->lock);
488501
489
- store_temperature(tz, temp);
502
+ return ret;
503
+ }
490504
491
- thermal_zone_set_trips(tz);
505
+ if (tz->ops->change_mode)
506
+ ret = tz->ops->change_mode(tz, mode);
492507
493
- tz->notify_event = event;
508
+ if (!ret)
509
+ tz->mode = mode;
494510
495
- for (count = 0; count < tz->trips; count++)
496
- handle_thermal_trip(tz, count);
511
+ mutex_unlock(&tz->lock);
512
+
513
+ thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
514
+
515
+ if (mode == THERMAL_DEVICE_ENABLED)
516
+ thermal_notify_tz_enable(tz->id);
517
+ else
518
+ thermal_notify_tz_disable(tz->id);
519
+
520
+ return ret;
497521 }
522
+
523
+int thermal_zone_device_enable(struct thermal_zone_device *tz)
524
+{
525
+ return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_ENABLED);
526
+}
527
+EXPORT_SYMBOL_GPL(thermal_zone_device_enable);
528
+
529
+int thermal_zone_device_disable(struct thermal_zone_device *tz)
530
+{
531
+ return thermal_zone_device_set_mode(tz, THERMAL_DEVICE_DISABLED);
532
+}
533
+EXPORT_SYMBOL_GPL(thermal_zone_device_disable);
534
+
535
+int thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
536
+{
537
+ enum thermal_device_mode mode;
538
+
539
+ mutex_lock(&tz->lock);
540
+
541
+ mode = tz->mode;
542
+
543
+ mutex_unlock(&tz->lock);
544
+
545
+ return mode == THERMAL_DEVICE_ENABLED;
546
+}
547
+EXPORT_SYMBOL_GPL(thermal_zone_device_is_enabled);
498548
499549 void thermal_zone_device_update(struct thermal_zone_device *tz,
500550 enum thermal_notify_event event)
501551 {
502552 int count;
503553
504
- if (!tz || !tz->ops)
554
+ if (should_stop_polling(tz))
505555 return;
506556
507
- if (atomic_read(&in_suspend) && (!tz->ops->is_wakeable ||
508
- !(tz->ops->is_wakeable(tz))))
557
+ if (atomic_read(&in_suspend))
509558 return;
510559
511560 if (!tz->ops->get_temp)
....@@ -558,7 +607,6 @@
558607 /**
559608 * power_actor_get_max_power() - get the maximum power that a cdev can consume
560609 * @cdev: pointer to &thermal_cooling_device
561
- * @tz: a valid thermal zone device pointer
562610 * @max_power: pointer in which to store the maximum power
563611 *
564612 * Calculate the maximum power consumption in milliwats that the
....@@ -568,18 +616,17 @@
568616 * power_actor API or -E* on other error.
569617 */
570618 int power_actor_get_max_power(struct thermal_cooling_device *cdev,
571
- struct thermal_zone_device *tz, u32 *max_power)
619
+ u32 *max_power)
572620 {
573621 if (!cdev_is_power_actor(cdev))
574622 return -EINVAL;
575623
576
- return cdev->ops->state2power(cdev, tz, 0, max_power);
624
+ return cdev->ops->state2power(cdev, 0, max_power);
577625 }
578626
579627 /**
580628 * power_actor_get_min_power() - get the mainimum power that a cdev can consume
581629 * @cdev: pointer to &thermal_cooling_device
582
- * @tz: a valid thermal zone device pointer
583630 * @min_power: pointer in which to store the minimum power
584631 *
585632 * Calculate the minimum power consumption in milliwatts that the
....@@ -589,7 +636,7 @@
589636 * power_actor API or -E* on other error.
590637 */
591638 int power_actor_get_min_power(struct thermal_cooling_device *cdev,
592
- struct thermal_zone_device *tz, u32 *min_power)
639
+ u32 *min_power)
593640 {
594641 unsigned long max_state;
595642 int ret;
....@@ -601,7 +648,7 @@
601648 if (ret)
602649 return ret;
603650
604
- return cdev->ops->state2power(cdev, tz, max_state, min_power);
651
+ return cdev->ops->state2power(cdev, max_state, min_power);
605652 }
606653
607654 /**
....@@ -625,16 +672,7 @@
625672 if (!cdev_is_power_actor(cdev))
626673 return -EINVAL;
627674
628
- ret = cdev->ops->power2state(cdev, instance->tz, power, &state);
629
-#ifdef CONFIG_ARCH_ROCKCHIP
630
- if (ret)
631
- state = THERMAL_CSTATE_INVALID;
632
- rockchip_system_monitor_adjust_cdev_state(cdev,
633
- instance->tz->temperature,
634
- &state);
635
- if (state == THERMAL_CSTATE_INVALID)
636
- ret = -EINVAL;
637
-#endif
675
+ ret = cdev->ops->power2state(cdev, power, &state);
638676 if (ret)
639677 return ret;
640678
....@@ -665,6 +703,73 @@
665703 THERMAL_WEIGHT_DEFAULT);
666704 }
667705 mutex_unlock(&thermal_list_lock);
706
+}
707
+
708
+int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
709
+ void *data)
710
+{
711
+ struct thermal_governor *gov;
712
+ int ret = 0;
713
+
714
+ mutex_lock(&thermal_governor_lock);
715
+ list_for_each_entry(gov, &thermal_governor_list, governor_list) {
716
+ ret = cb(gov, data);
717
+ if (ret)
718
+ break;
719
+ }
720
+ mutex_unlock(&thermal_governor_lock);
721
+
722
+ return ret;
723
+}
724
+
725
+int for_each_thermal_cooling_device(int (*cb)(struct thermal_cooling_device *,
726
+ void *), void *data)
727
+{
728
+ struct thermal_cooling_device *cdev;
729
+ int ret = 0;
730
+
731
+ mutex_lock(&thermal_list_lock);
732
+ list_for_each_entry(cdev, &thermal_cdev_list, node) {
733
+ ret = cb(cdev, data);
734
+ if (ret)
735
+ break;
736
+ }
737
+ mutex_unlock(&thermal_list_lock);
738
+
739
+ return ret;
740
+}
741
+
742
+int for_each_thermal_zone(int (*cb)(struct thermal_zone_device *, void *),
743
+ void *data)
744
+{
745
+ struct thermal_zone_device *tz;
746
+ int ret = 0;
747
+
748
+ mutex_lock(&thermal_list_lock);
749
+ list_for_each_entry(tz, &thermal_tz_list, node) {
750
+ ret = cb(tz, data);
751
+ if (ret)
752
+ break;
753
+ }
754
+ mutex_unlock(&thermal_list_lock);
755
+
756
+ return ret;
757
+}
758
+
759
+struct thermal_zone_device *thermal_zone_get_by_id(int id)
760
+{
761
+ struct thermal_zone_device *tz, *match = NULL;
762
+
763
+ mutex_lock(&thermal_list_lock);
764
+ list_for_each_entry(tz, &thermal_tz_list, node) {
765
+ if (tz->id == id) {
766
+ match = tz;
767
+ break;
768
+ }
769
+ }
770
+ mutex_unlock(&thermal_list_lock);
771
+
772
+ return match;
668773 }
669774
670775 void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
....@@ -780,9 +885,8 @@
780885 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
781886 sysfs_attr_init(&dev->attr.attr);
782887 dev->attr.attr.name = dev->attr_name;
783
- dev->attr.attr.mode = 0644;
888
+ dev->attr.attr.mode = 0444;
784889 dev->attr.show = trip_point_show;
785
- dev->attr.store = trip_point_store;
786890 result = device_create_file(&tz->device, &dev->attr);
787891 if (result)
788892 goto remove_symbol_link;
....@@ -1024,7 +1128,7 @@
10241128 result = device_register(&cdev->device);
10251129 if (result) {
10261130 ida_simple_remove(&thermal_cdev_ida, cdev->id);
1027
- kfree(cdev);
1131
+ put_device(&cdev->device);
10281132 return ERR_PTR(result);
10291133 }
10301134
....@@ -1090,6 +1194,55 @@
10901194 return __thermal_cooling_device_register(np, type, devdata, ops);
10911195 }
10921196 EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);
1197
+
1198
+static void thermal_cooling_device_release(struct device *dev, void *res)
1199
+{
1200
+ thermal_cooling_device_unregister(
1201
+ *(struct thermal_cooling_device **)res);
1202
+}
1203
+
1204
+/**
1205
+ * devm_thermal_of_cooling_device_register() - register an OF thermal cooling
1206
+ * device
1207
+ * @dev: a valid struct device pointer of a sensor device.
1208
+ * @np: a pointer to a device tree node.
1209
+ * @type: the thermal cooling device type.
1210
+ * @devdata: device private data.
1211
+ * @ops: standard thermal cooling devices callbacks.
1212
+ *
1213
+ * This function will register a cooling device with device tree node reference.
1214
+ * This interface function adds a new thermal cooling device (fan/processor/...)
1215
+ * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
1216
+ * to all the thermal zone devices registered at the same time.
1217
+ *
1218
+ * Return: a pointer to the created struct thermal_cooling_device or an
1219
+ * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
1220
+ */
1221
+struct thermal_cooling_device *
1222
+devm_thermal_of_cooling_device_register(struct device *dev,
1223
+ struct device_node *np,
1224
+ char *type, void *devdata,
1225
+ const struct thermal_cooling_device_ops *ops)
1226
+{
1227
+ struct thermal_cooling_device **ptr, *tcd;
1228
+
1229
+ ptr = devres_alloc(thermal_cooling_device_release, sizeof(*ptr),
1230
+ GFP_KERNEL);
1231
+ if (!ptr)
1232
+ return ERR_PTR(-ENOMEM);
1233
+
1234
+ tcd = __thermal_cooling_device_register(np, type, devdata, ops);
1235
+ if (IS_ERR(tcd)) {
1236
+ devres_free(ptr);
1237
+ return tcd;
1238
+ }
1239
+
1240
+ *ptr = tcd;
1241
+ devres_add(dev, ptr);
1242
+
1243
+ return tcd;
1244
+}
1245
+EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
10931246
10941247 static void __unbind(struct thermal_zone_device *tz, int mask,
10951248 struct thermal_cooling_device *cdev)
....@@ -1230,21 +1383,31 @@
12301383 struct thermal_zone_device *tz;
12311384 enum thermal_trip_type trip_type;
12321385 int trip_temp;
1386
+ int id;
12331387 int result;
12341388 int count;
12351389 struct thermal_governor *governor;
12361390
1237
- if (!type || strlen(type) == 0)
1391
+ if (!type || strlen(type) == 0) {
1392
+ pr_err("Error: No thermal zone type defined\n");
12381393 return ERR_PTR(-EINVAL);
1394
+ }
12391395
1240
- if (type && strlen(type) >= THERMAL_NAME_LENGTH)
1396
+ if (type && strlen(type) >= THERMAL_NAME_LENGTH) {
1397
+ pr_err("Error: Thermal zone name (%s) too long, should be under %d chars\n",
1398
+ type, THERMAL_NAME_LENGTH);
12411399 return ERR_PTR(-EINVAL);
1400
+ }
12421401
1243
- if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
1402
+ if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {
1403
+ pr_err("Error: Incorrect number of thermal trips\n");
12441404 return ERR_PTR(-EINVAL);
1405
+ }
12451406
1246
- if (!ops)
1407
+ if (!ops) {
1408
+ pr_err("Error: Thermal zone device ops not defined\n");
12471409 return ERR_PTR(-EINVAL);
1410
+ }
12481411
12491412 if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
12501413 return ERR_PTR(-EINVAL);
....@@ -1256,11 +1419,13 @@
12561419 INIT_LIST_HEAD(&tz->thermal_instances);
12571420 ida_init(&tz->ida);
12581421 mutex_init(&tz->lock);
1259
- result = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL);
1260
- if (result < 0)
1422
+ id = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL);
1423
+ if (id < 0) {
1424
+ result = id;
12611425 goto free_tz;
1426
+ }
12621427
1263
- tz->id = result;
1428
+ tz->id = id;
12641429 strlcpy(tz->type, type, sizeof(tz->type));
12651430 tz->ops = ops;
12661431 tz->tzp = tzp;
....@@ -1282,7 +1447,7 @@
12821447 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
12831448 result = device_register(&tz->device);
12841449 if (result)
1285
- goto remove_device_groups;
1450
+ goto release_device;
12861451
12871452 for (count = 0; count < trips; count++) {
12881453 if (tz->ops->get_trip_type(tz, count, &trip_type))
....@@ -1330,17 +1495,17 @@
13301495 if (atomic_cmpxchg(&tz->need_update, 1, 0))
13311496 thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
13321497
1498
+ thermal_notify_tz_create(tz->id, tz->type);
1499
+
13331500 return tz;
13341501
13351502 unregister:
1336
- ida_simple_remove(&thermal_tz_ida, tz->id);
1337
- device_unregister(&tz->device);
1338
- return ERR_PTR(result);
1339
-
1340
-remove_device_groups:
1341
- thermal_zone_destroy_device_groups(tz);
1503
+ device_del(&tz->device);
1504
+release_device:
1505
+ put_device(&tz->device);
1506
+ tz = NULL;
13421507 remove_id:
1343
- ida_simple_remove(&thermal_tz_ida, tz->id);
1508
+ ida_simple_remove(&thermal_tz_ida, id);
13441509 free_tz:
13451510 kfree(tz);
13461511 return ERR_PTR(result);
....@@ -1353,7 +1518,7 @@
13531518 */
13541519 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
13551520 {
1356
- int i;
1521
+ int i, tz_id;
13571522 const struct thermal_zone_params *tzp;
13581523 struct thermal_cooling_device *cdev;
13591524 struct thermal_zone_device *pos = NULL;
....@@ -1362,6 +1527,7 @@
13621527 return;
13631528
13641529 tzp = tz->tzp;
1530
+ tz_id = tz->id;
13651531
13661532 mutex_lock(&thermal_list_lock);
13671533 list_for_each_entry(pos, &thermal_tz_list, node)
....@@ -1403,6 +1569,8 @@
14031569 ida_destroy(&tz->ida);
14041570 mutex_destroy(&tz->lock);
14051571 device_unregister(&tz->device);
1572
+
1573
+ thermal_notify_tz_delete(tz_id);
14061574 }
14071575 EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
14081576
....@@ -1444,138 +1612,11 @@
14441612 }
14451613 EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
14461614
1447
-/**
1448
- * thermal_zone_get_cdev_by_name() - search for a cooling device and returns
1449
- * its ref.
1450
- * @name: thermal cdev name to fetch the temperature
1451
- *
1452
- * When only one cdev is found with the passed name, returns a reference to it.
1453
- *
1454
- * Return: On success returns a reference to an unique thermal cooling device
1455
- * with matching name equals to @name, an ERR_PTR otherwise (-EINVAL for
1456
- * invalid paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1457
- */
1458
-struct thermal_cooling_device *thermal_zone_get_cdev_by_name(const char *name)
1459
-{
1460
- struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
1461
- unsigned int found = 0;
1462
-
1463
- if (!name)
1464
- return ref;
1465
-
1466
- mutex_lock(&thermal_list_lock);
1467
- list_for_each_entry(pos, &thermal_cdev_list, node)
1468
- if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) {
1469
- found++;
1470
- ref = pos;
1471
- }
1472
- mutex_unlock(&thermal_list_lock);
1473
-
1474
- /* nothing has been found, thus an error code for it */
1475
- if (found == 0)
1476
- return ERR_PTR(-ENODEV);
1477
- if (found > 1)
1478
- return ERR_PTR(-EEXIST);
1479
- return ref;
1480
-
1481
-}
1482
-EXPORT_SYMBOL_GPL(thermal_zone_get_cdev_by_name);
1483
-
1484
-#ifdef CONFIG_NET
1485
-static const struct genl_multicast_group thermal_event_mcgrps[] = {
1486
- { .name = THERMAL_GENL_MCAST_GROUP_NAME, },
1487
-};
1488
-
1489
-static struct genl_family thermal_event_genl_family __ro_after_init = {
1490
- .module = THIS_MODULE,
1491
- .name = THERMAL_GENL_FAMILY_NAME,
1492
- .version = THERMAL_GENL_VERSION,
1493
- .maxattr = THERMAL_GENL_ATTR_MAX,
1494
- .mcgrps = thermal_event_mcgrps,
1495
- .n_mcgrps = ARRAY_SIZE(thermal_event_mcgrps),
1496
-};
1497
-
1498
-int thermal_generate_netlink_event(struct thermal_zone_device *tz,
1499
- enum events event)
1500
-{
1501
- struct sk_buff *skb;
1502
- struct nlattr *attr;
1503
- struct thermal_genl_event *thermal_event;
1504
- void *msg_header;
1505
- int size;
1506
- int result;
1507
- static unsigned int thermal_event_seqnum;
1508
-
1509
- if (!tz)
1510
- return -EINVAL;
1511
-
1512
- /* allocate memory */
1513
- size = nla_total_size(sizeof(struct thermal_genl_event)) +
1514
- nla_total_size(0);
1515
-
1516
- skb = genlmsg_new(size, GFP_ATOMIC);
1517
- if (!skb)
1518
- return -ENOMEM;
1519
-
1520
- /* add the genetlink message header */
1521
- msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
1522
- &thermal_event_genl_family, 0,
1523
- THERMAL_GENL_CMD_EVENT);
1524
- if (!msg_header) {
1525
- nlmsg_free(skb);
1526
- return -ENOMEM;
1527
- }
1528
-
1529
- /* fill the data */
1530
- attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
1531
- sizeof(struct thermal_genl_event));
1532
-
1533
- if (!attr) {
1534
- nlmsg_free(skb);
1535
- return -EINVAL;
1536
- }
1537
-
1538
- thermal_event = nla_data(attr);
1539
- if (!thermal_event) {
1540
- nlmsg_free(skb);
1541
- return -EINVAL;
1542
- }
1543
-
1544
- memset(thermal_event, 0, sizeof(struct thermal_genl_event));
1545
-
1546
- thermal_event->orig = tz->id;
1547
- thermal_event->event = event;
1548
-
1549
- /* send multicast genetlink message */
1550
- genlmsg_end(skb, msg_header);
1551
-
1552
- result = genlmsg_multicast(&thermal_event_genl_family, skb, 0,
1553
- 0, GFP_ATOMIC);
1554
- if (result)
1555
- dev_err(&tz->device, "Failed to send netlink event:%d", result);
1556
-
1557
- return result;
1558
-}
1559
-EXPORT_SYMBOL_GPL(thermal_generate_netlink_event);
1560
-
1561
-static int __init genetlink_init(void)
1562
-{
1563
- return genl_register_family(&thermal_event_genl_family);
1564
-}
1565
-
1566
-static void genetlink_exit(void)
1567
-{
1568
- genl_unregister_family(&thermal_event_genl_family);
1569
-}
1570
-#else /* !CONFIG_NET */
1571
-static inline int genetlink_init(void) { return 0; }
1572
-static inline void genetlink_exit(void) {}
1573
-#endif /* !CONFIG_NET */
1574
-
15751615 static int thermal_pm_notify(struct notifier_block *nb,
15761616 unsigned long mode, void *_unused)
15771617 {
15781618 struct thermal_zone_device *tz;
1619
+ int irq_wakeable = 0;
15791620
15801621 switch (mode) {
15811622 case PM_HIBERNATION_PREPARE:
....@@ -1588,9 +1629,13 @@
15881629 case PM_POST_SUSPEND:
15891630 atomic_set(&in_suspend, 0);
15901631 list_for_each_entry(tz, &thermal_tz_list, node) {
1591
- if (tz->ops && tz->ops->is_wakeable &&
1592
- tz->ops->is_wakeable(tz))
1632
+ if (!thermal_zone_device_is_enabled(tz))
15931633 continue;
1634
+
1635
+ trace_android_vh_thermal_pm_notify_suspend(tz, &irq_wakeable);
1636
+ if (irq_wakeable)
1637
+ continue;
1638
+
15941639 thermal_zone_device_init(tz);
15951640 thermal_zone_device_update(tz,
15961641 THERMAL_EVENT_UNSPECIFIED);
....@@ -1610,7 +1655,10 @@
16101655 {
16111656 int result;
16121657
1613
- mutex_init(&poweroff_lock);
1658
+ result = thermal_netlink_init();
1659
+ if (result)
1660
+ goto error;
1661
+
16141662 result = thermal_register_governors();
16151663 if (result)
16161664 goto error;
....@@ -1619,13 +1667,9 @@
16191667 if (result)
16201668 goto unregister_governors;
16211669
1622
- result = genetlink_init();
1623
- if (result)
1624
- goto unregister_class;
1625
-
16261670 result = of_parse_thermal_zones();
16271671 if (result)
1628
- goto exit_netlink;
1672
+ goto unregister_class;
16291673
16301674 result = register_pm_notifier(&thermal_pm_nb);
16311675 if (result)
....@@ -1634,8 +1678,6 @@
16341678
16351679 return 0;
16361680
1637
-exit_netlink:
1638
- genetlink_exit();
16391681 unregister_class:
16401682 class_unregister(&thermal_class);
16411683 unregister_governors:
....@@ -1648,19 +1690,4 @@
16481690 mutex_destroy(&poweroff_lock);
16491691 return result;
16501692 }
1651
-
1652
-static void __exit thermal_exit(void)
1653
-{
1654
- unregister_pm_notifier(&thermal_pm_nb);
1655
- of_thermal_destroy_zones();
1656
- genetlink_exit();
1657
- class_unregister(&thermal_class);
1658
- thermal_unregister_governors();
1659
- ida_destroy(&thermal_tz_ida);
1660
- ida_destroy(&thermal_cdev_ida);
1661
- mutex_destroy(&thermal_list_lock);
1662
- mutex_destroy(&thermal_governor_lock);
1663
-}
1664
-
1665
-fs_initcall(thermal_init);
1666
-module_exit(thermal_exit);
1693
+postcore_initcall(thermal_init);