Merge branch 'misc' into release
authorLen Brown <len.brown@intel.com>
Wed, 12 Jan 2011 10:14:15 +0000 (05:14 -0500)
committerLen Brown <len.brown@intel.com>
Wed, 12 Jan 2011 10:14:15 +0000 (05:14 -0500)
1  2 
drivers/thermal/thermal_sys.c
include/linux/thermal.h

index 760e045c93c8f34e96d0dd2563dd7544d69bfae3,bde3477c1c6b75293f2181ba93ae3dc1677bea85..7d0e63c79280c37c6a88e9be1e8834eea11eba31
@@@ -32,8 -32,6 +32,8 @@@
  #include <linux/thermal.h>
  #include <linux/spinlock.h>
  #include <linux/reboot.h>
 +#include <net/netlink.h>
 +#include <net/genetlink.h>
  
  MODULE_AUTHOR("Zhang Rui");
  MODULE_DESCRIPTION("Generic thermal management sysfs support");
@@@ -60,22 -58,6 +60,22 @@@ static LIST_HEAD(thermal_tz_list)
  static LIST_HEAD(thermal_cdev_list);
  static DEFINE_MUTEX(thermal_list_lock);
  
 +static unsigned int thermal_event_seqnum;
 +
 +static struct genl_family thermal_event_genl_family = {
 +      .id = GENL_ID_GENERATE,
 +      .name = THERMAL_GENL_FAMILY_NAME,
 +      .version = THERMAL_GENL_VERSION,
 +      .maxattr = THERMAL_GENL_ATTR_MAX,
 +};
 +
 +static struct genl_multicast_group thermal_event_mcgrp = {
 +      .name = THERMAL_GENL_MCAST_GROUP_NAME,
 +};
 +
 +static int genetlink_init(void);
 +static void genetlink_exit(void);
 +
  static int get_idr(struct idr *idr, struct mutex *lock, int *id)
  {
        int err;
@@@ -841,11 -823,8 +841,8 @@@ static struct class thermal_class = 
   * @devdata:  device private data.
   * @ops:              standard thermal cooling devices callbacks.
   */
- struct thermal_cooling_device *thermal_cooling_device_register(char *type,
-                                                              void *devdata,
-                                                              struct
-                                                              thermal_cooling_device_ops
-                                                              *ops)
+ struct thermal_cooling_device *thermal_cooling_device_register(
+      char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
  {
        struct thermal_cooling_device *cdev;
        struct thermal_zone_device *pos;
@@@ -1066,13 -1045,9 +1063,9 @@@ EXPORT_SYMBOL(thermal_zone_device_updat
   * section 11.1.5.1 of the ACPI specification 3.0.
   */
  struct thermal_zone_device *thermal_zone_device_register(char *type,
-                                                        int trips,
-                                                        void *devdata, struct
-                                                        thermal_zone_device_ops
-                                                        *ops, int tc1, int
-                                                        tc2,
-                                                        int passive_delay,
-                                                        int polling_delay)
+       int trips, void *devdata,
+       const struct thermal_zone_device_ops *ops,
+       int tc1, int tc2, int passive_delay, int polling_delay)
  {
        struct thermal_zone_device *tz;
        struct thermal_cooling_device *pos;
@@@ -1232,82 -1207,6 +1225,82 @@@ void thermal_zone_device_unregister(str
  
  EXPORT_SYMBOL(thermal_zone_device_unregister);
  
 +int generate_netlink_event(u32 orig, enum events event)
 +{
 +      struct sk_buff *skb;
 +      struct nlattr *attr;
 +      struct thermal_genl_event *thermal_event;
 +      void *msg_header;
 +      int size;
 +      int result;
 +
 +      /* allocate memory */
 +      size = nla_total_size(sizeof(struct thermal_genl_event)) + \
 +                              nla_total_size(0);
 +
 +      skb = genlmsg_new(size, GFP_ATOMIC);
 +      if (!skb)
 +              return -ENOMEM;
 +
 +      /* add the genetlink message header */
 +      msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
 +                               &thermal_event_genl_family, 0,
 +                               THERMAL_GENL_CMD_EVENT);
 +      if (!msg_header) {
 +              nlmsg_free(skb);
 +              return -ENOMEM;
 +      }
 +
 +      /* fill the data */
 +      attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT, \
 +                      sizeof(struct thermal_genl_event));
 +
 +      if (!attr) {
 +              nlmsg_free(skb);
 +              return -EINVAL;
 +      }
 +
 +      thermal_event = nla_data(attr);
 +      if (!thermal_event) {
 +              nlmsg_free(skb);
 +              return -EINVAL;
 +      }
 +
 +      memset(thermal_event, 0, sizeof(struct thermal_genl_event));
 +
 +      thermal_event->orig = orig;
 +      thermal_event->event = event;
 +
 +      /* send multicast genetlink message */
 +      result = genlmsg_end(skb, msg_header);
 +      if (result < 0) {
 +              nlmsg_free(skb);
 +              return result;
 +      }
 +
 +      result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
 +      if (result)
 +              printk(KERN_INFO "failed to send netlink event:%d", result);
 +
 +      return result;
 +}
 +EXPORT_SYMBOL(generate_netlink_event);
 +
 +static int genetlink_init(void)
 +{
 +      int result;
 +
 +      result = genl_register_family(&thermal_event_genl_family);
 +      if (result)
 +              return result;
 +
 +      result = genl_register_mc_group(&thermal_event_genl_family,
 +                                      &thermal_event_mcgrp);
 +      if (result)
 +              genl_unregister_family(&thermal_event_genl_family);
 +      return result;
 +}
 +
  static int __init thermal_init(void)
  {
        int result = 0;
                mutex_destroy(&thermal_idr_lock);
                mutex_destroy(&thermal_list_lock);
        }
 +      result = genetlink_init();
        return result;
  }
  
 +static void genetlink_exit(void)
 +{
 +      genl_unregister_family(&thermal_event_genl_family);
 +}
 +
  static void __exit thermal_exit(void)
  {
        class_unregister(&thermal_class);
        idr_destroy(&thermal_cdev_idr);
        mutex_destroy(&thermal_idr_lock);
        mutex_destroy(&thermal_list_lock);
 +      genetlink_exit();
  }
  
 -subsys_initcall(thermal_init);
 +fs_initcall(thermal_init);
  module_exit(thermal_exit);
diff --combined include/linux/thermal.h
index 78464496127951cc4ab674390d1fe6d85fd16fd3,06626904daa09ef53262cbb66c8d6786f1ac93cc..8651556dbd52aa7fe12d7d7b57b861b270544cfa
@@@ -77,7 -77,7 +77,7 @@@ struct thermal_cooling_device 
        char type[THERMAL_NAME_LENGTH];
        struct device device;
        void *devdata;
-       struct thermal_cooling_device_ops *ops;
+       const struct thermal_cooling_device_ops *ops;
        struct list_head node;
  };
  
@@@ -114,7 -114,7 +114,7 @@@ struct thermal_zone_device 
        int last_temperature;
        bool passive;
        unsigned int forced_passive;
-       struct thermal_zone_device_ops *ops;
+       const struct thermal_zone_device_ops *ops;
        struct list_head cooling_devices;
        struct idr idr;
        struct mutex lock;      /* protect cooling devices list */
        struct thermal_hwmon_attr temp_crit;    /* hwmon sys attr */
  #endif
  };
 +/* Adding event notification support elements */
 +#define THERMAL_GENL_FAMILY_NAME                "thermal_event"
 +#define THERMAL_GENL_VERSION                    0x01
 +#define THERMAL_GENL_MCAST_GROUP_NAME           "thermal_mc_group"
 +
 +enum events {
 +      THERMAL_AUX0,
 +      THERMAL_AUX1,
 +      THERMAL_CRITICAL,
 +      THERMAL_DEV_FAULT,
 +};
 +
 +struct thermal_genl_event {
 +      u32 orig;
 +      enum events event;
 +};
 +/* attributes of thermal_genl_family */
 +enum {
 +      THERMAL_GENL_ATTR_UNSPEC,
 +      THERMAL_GENL_ATTR_EVENT,
 +      __THERMAL_GENL_ATTR_MAX,
 +};
 +#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
 +
 +/* commands supported by the thermal_genl_family */
 +enum {
 +      THERMAL_GENL_CMD_UNSPEC,
 +      THERMAL_GENL_CMD_EVENT,
 +      __THERMAL_GENL_CMD_MAX,
 +};
 +#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
  
  struct thermal_zone_device *thermal_zone_device_register(char *, int, void *,
-                                                        struct
-                                                        thermal_zone_device_ops
-                                                        *, int tc1, int tc2,
-                                                        int passive_freq,
-                                                        int polling_freq);
+               const struct thermal_zone_device_ops *, int tc1, int tc2,
+               int passive_freq, int polling_freq);
  void thermal_zone_device_unregister(struct thermal_zone_device *);
  
  int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
@@@ -173,10 -139,7 +170,8 @@@ int thermal_zone_unbind_cooling_device(
                                       struct thermal_cooling_device *);
  void thermal_zone_device_update(struct thermal_zone_device *);
  struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
-                                                              struct
-                                                              thermal_cooling_device_ops
-                                                              *);
+               const struct thermal_cooling_device_ops *);
  void thermal_cooling_device_unregister(struct thermal_cooling_device *);
 +extern int generate_netlink_event(u32 orig, enum events event);
  
  #endif /* __THERMAL_H__ */