thermal: Add notifier call chain for hot/critical events
authorDuncan Laurie <dlaurie@chromium.org>
Wed, 18 Jul 2012 18:05:53 +0000 (11:05 -0700)
committerGerrit <chrome-bot@google.com>
Wed, 18 Jul 2012 20:11:05 +0000 (13:11 -0700)
This will allow drivers to register a callback for important
thermal events and log critical thresholds that cause the system
to shut down.

There are other places this might work, but after consideration
I think it makes sense to have the chain at this level:

The ACPI thermal driver has an existing notify function that is
eventually called into, but that would limit the notifier to only
working on systems that use ACPI.

The cpufreq driver is already getting a notify callback executed
in this path (tz->ops->notify) but the threshold info is not passed
to the cpu_cooling notifier chain so it is not useful for logging.

BUG=chrome-os-partner:9381
TEST=build ok, no visible changes in this commit

Change-Id: I8806c0bf844a08580d936d971aa80a3ec579080a
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27775
Reviewed-by: Olof Johansson <olofj@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
drivers/thermal/thermal_sys.c
include/linux/thermal.h

index 7484a4a..c2dcbe9 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/slab.h>
 #include <linux/kdev_t.h>
 #include <linux/idr.h>
+#include <linux/notifier.h>
 #include <linux/thermal.h>
 #include <linux/spinlock.h>
 #include <linux/reboot.h>
@@ -1059,6 +1060,36 @@ void thermal_cooling_device_unregister(struct
 }
 EXPORT_SYMBOL(thermal_cooling_device_unregister);
 
+BLOCKING_NOTIFIER_HEAD(thermal_notifier_list);
+
+/**
+ * register_thermal_notifier - Register function to be called for
+ *                             critical thermal events.
+ *
+ * @nb: Info about notifier function to be called
+ *
+ * Currently always returns zero, as blocking_notifier_chain_register()
+ * always returns zero.
+ */
+int register_thermal_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_register(&thermal_notifier_list, nb);
+}
+EXPORT_SYMBOL(register_thermal_notifier);
+
+/**
+ * unregister_thermal_notifier - Unregister thermal notifier
+ *
+ * @nb: Hook to be unregistered
+ *
+ * Returns zero on success, or %-ENOENT on failure.
+ */
+int unregister_thermal_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_unregister(&thermal_notifier_list, nb);
+}
+EXPORT_SYMBOL(unregister_thermal_notifier);
+
 /**
  * thermal_zone_device_update - force an update of a thermal zone's state
  * @ttz:       the thermal zone to update
@@ -1090,6 +1121,9 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
                                if (tz->ops->notify)
                                        ret = tz->ops->notify(tz, count,
                                                              trip_type);
+                               blocking_notifier_call_chain(
+                                       &thermal_notifier_list,
+                                       trip_type, NULL);
                                if (!ret) {
                                        pr_emerg("Critical temperature reached (%ld C), shutting down\n",
                                                 temp/1000);
@@ -1098,9 +1132,13 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
                        }
                        break;
                case THERMAL_TRIP_HOT:
-                       if (temp >= trip_temp)
+                       if (temp >= trip_temp) {
                                if (tz->ops->notify)
                                        tz->ops->notify(tz, count, trip_type);
+                               blocking_notifier_call_chain(
+                                       &thermal_notifier_list,
+                                       trip_type, NULL);
+                       }
                        break;
                case THERMAL_TRIP_ACTIVE:
                        list_for_each_entry(instance, &tz->cooling_devices,
index 145d89c..3026ebb 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <linux/idr.h>
 #include <linux/device.h>
+#include <linux/notifier.h>
 #include <linux/workqueue.h>
 
 struct thermal_zone_device;
@@ -174,4 +175,7 @@ static inline int thermal_generate_netlink_event(u32 orig, enum events event)
 }
 #endif
 
+extern int register_thermal_notifier(struct notifier_block *);
+extern int unregister_thermal_notifier(struct notifier_block *);
+
 #endif /* __THERMAL_H__ */