V4L/DVB (5320): Filled in limiting values in tda827x.c
[safe/jmp/linux-2.6] / drivers / acpi / thermal.c
index 56358e1..589b98b 100644 (file)
@@ -36,7 +36,8 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
-#include <linux/sched.h>
+#include <linux/timer.h>
+#include <linux/jiffies.h>
 #include <linux/kmod.h>
 #include <linux/seq_file.h>
 #include <asm/uaccess.h>
@@ -46,7 +47,6 @@
 
 #define ACPI_THERMAL_COMPONENT         0x04000000
 #define ACPI_THERMAL_CLASS             "thermal_zone"
-#define ACPI_THERMAL_DRIVER_NAME       "ACPI Thermal Zone Driver"
 #define ACPI_THERMAL_DEVICE_NAME       "Thermal Zone"
 #define ACPI_THERMAL_FILE_STATE                "state"
 #define ACPI_THERMAL_FILE_TEMPERATURE  "temperature"
 #define CELSIUS_TO_KELVIN(t)   ((t+273)*10)
 
 #define _COMPONENT             ACPI_THERMAL_COMPONENT
-ACPI_MODULE_NAME("acpi_thermal")
+ACPI_MODULE_NAME("thermal");
 
 MODULE_AUTHOR("Paul Diefenbaugh");
-MODULE_DESCRIPTION(ACPI_THERMAL_DRIVER_NAME);
+MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
 MODULE_LICENSE("GPL");
 
 static int tzp;
@@ -82,7 +82,7 @@ MODULE_PARM_DESC(tzp, "Thermal zone polling frequency, in 1/10 seconds.\n");
 
 static int acpi_thermal_add(struct acpi_device *device);
 static int acpi_thermal_remove(struct acpi_device *device, int type);
-static int acpi_thermal_resume(struct acpi_device *device, int state);
+static int acpi_thermal_resume(struct acpi_device *device);
 static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
 static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
 static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
@@ -98,7 +98,7 @@ static ssize_t acpi_thermal_write_polling(struct file *, const char __user *,
                                          size_t, loff_t *);
 
 static struct acpi_driver acpi_thermal_driver = {
-       .name = ACPI_THERMAL_DRIVER_NAME,
+       .name = "thermal",
        .class = ACPI_THERMAL_CLASS,
        .ids = ACPI_THERMAL_HID,
        .ops = {
@@ -162,7 +162,6 @@ struct acpi_thermal_flags {
 };
 
 struct acpi_thermal {
-       acpi_handle handle;
        struct acpi_device * device;
        acpi_bus_id name;
        unsigned long temperature;
@@ -177,21 +176,21 @@ struct acpi_thermal {
        struct timer_list timer;
 };
 
-static struct file_operations acpi_thermal_state_fops = {
+static const struct file_operations acpi_thermal_state_fops = {
        .open = acpi_thermal_state_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
        .release = single_release,
 };
 
-static struct file_operations acpi_thermal_temp_fops = {
+static const struct file_operations acpi_thermal_temp_fops = {
        .open = acpi_thermal_temp_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
        .release = single_release,
 };
 
-static struct file_operations acpi_thermal_trip_fops = {
+static const struct file_operations acpi_thermal_trip_fops = {
        .open = acpi_thermal_trip_open_fs,
        .read = seq_read,
        .write = acpi_thermal_write_trip_points,
@@ -199,7 +198,7 @@ static struct file_operations acpi_thermal_trip_fops = {
        .release = single_release,
 };
 
-static struct file_operations acpi_thermal_cooling_fops = {
+static const struct file_operations acpi_thermal_cooling_fops = {
        .open = acpi_thermal_cooling_open_fs,
        .read = seq_read,
        .write = acpi_thermal_write_cooling_mode,
@@ -207,7 +206,7 @@ static struct file_operations acpi_thermal_cooling_fops = {
        .release = single_release,
 };
 
-static struct file_operations acpi_thermal_polling_fops = {
+static const struct file_operations acpi_thermal_polling_fops = {
        .open = acpi_thermal_polling_open_fs,
        .read = seq_read,
        .write = acpi_thermal_write_polling,
@@ -270,7 +269,7 @@ static int acpi_thermal_set_polling(struct acpi_thermal *tz, int seconds)
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                          "Polling frequency set to %lu seconds\n",
-                         tz->polling_frequency));
+                         tz->polling_frequency/10));
 
        return 0;
 }
@@ -664,7 +663,7 @@ static void acpi_thermal_run(unsigned long data)
 static void acpi_thermal_check(void *data)
 {
        int result = 0;
-       struct acpi_thermal *tz = (struct acpi_thermal *)data;
+       struct acpi_thermal *tz = data;
        unsigned long sleep_time = 0;
        int i = 0;
        struct acpi_thermal_state state;
@@ -759,7 +758,8 @@ static void acpi_thermal_check(void *data)
                        del_timer(&(tz->timer));
        } else {
                if (timer_pending(&(tz->timer)))
-                       mod_timer(&(tz->timer), (HZ * sleep_time) / 1000);
+                       mod_timer(&(tz->timer),
+                                       jiffies + (HZ * sleep_time) / 1000);
                else {
                        tz->timer.data = (unsigned long)tz;
                        tz->timer.function = acpi_thermal_run;
@@ -779,7 +779,7 @@ static struct proc_dir_entry *acpi_thermal_dir;
 
 static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
 {
-       struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
+       struct acpi_thermal *tz = seq->private;
 
 
        if (!tz)
@@ -814,7 +814,7 @@ static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
 static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
 {
        int result = 0;
-       struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
+       struct acpi_thermal *tz = seq->private;
 
 
        if (!tz)
@@ -838,7 +838,7 @@ static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
 
 static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
 {
-       struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
+       struct acpi_thermal *tz = seq->private;
        int i = 0;
        int j = 0;
 
@@ -894,8 +894,8 @@ acpi_thermal_write_trip_points(struct file *file,
                               const char __user * buffer,
                               size_t count, loff_t * ppos)
 {
-       struct seq_file *m = (struct seq_file *)file->private_data;
-       struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
+       struct seq_file *m = file->private_data;
+       struct acpi_thermal *tz = m->private;
 
        char *limit_string;
        int num, critical, hot, passive;
@@ -903,12 +903,10 @@ acpi_thermal_write_trip_points(struct file *file,
        int i = 0;
 
 
-       limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
+       limit_string = kzalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
        if (!limit_string)
                return -ENOMEM;
 
-       memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN);
-
        active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL);
        if (!active) {
                kfree(limit_string);
@@ -954,7 +952,7 @@ acpi_thermal_write_trip_points(struct file *file,
 
 static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
 {
-       struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
+       struct acpi_thermal *tz = seq->private;
 
 
        if (!tz)
@@ -985,8 +983,8 @@ acpi_thermal_write_cooling_mode(struct file *file,
                                const char __user * buffer,
                                size_t count, loff_t * ppos)
 {
-       struct seq_file *m = (struct seq_file *)file->private_data;
-       struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
+       struct seq_file *m = file->private_data;
+       struct acpi_thermal *tz = m->private;
        int result = 0;
        char mode_string[12] = { '\0' };
 
@@ -1015,7 +1013,7 @@ acpi_thermal_write_cooling_mode(struct file *file,
 
 static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
 {
-       struct acpi_thermal *tz = (struct acpi_thermal *)seq->private;
+       struct acpi_thermal *tz = seq->private;
 
 
        if (!tz)
@@ -1044,8 +1042,8 @@ acpi_thermal_write_polling(struct file *file,
                           const char __user * buffer,
                           size_t count, loff_t * ppos)
 {
-       struct seq_file *m = (struct seq_file *)file->private_data;
-       struct acpi_thermal *tz = (struct acpi_thermal *)m->private;
+       struct seq_file *m = file->private_data;
+       struct acpi_thermal *tz = m->private;
        int result = 0;
        char polling_string[12] = { '\0' };
        int seconds = 0;
@@ -1171,7 +1169,7 @@ static int acpi_thermal_remove_fs(struct acpi_device *device)
 
 static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
 {
-       struct acpi_thermal *tz = (struct acpi_thermal *)data;
+       struct acpi_thermal *tz = data;
        struct acpi_device *device = NULL;
 
 
@@ -1272,12 +1270,10 @@ static int acpi_thermal_add(struct acpi_device *device)
        if (!device)
                return -EINVAL;
 
-       tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
+       tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
        if (!tz)
                return -ENOMEM;
-       memset(tz, 0, sizeof(struct acpi_thermal));
 
-       tz->handle = device->handle;
        tz->device = device;
        strcpy(tz->name, device->pnp.bus_id);
        strcpy(acpi_device_name(device), ACPI_THERMAL_DEVICE_NAME);
@@ -1326,7 +1322,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
        if (!device || !acpi_driver_data(device))
                return -EINVAL;
 
-       tz = (struct acpi_thermal *)acpi_driver_data(device);
+       tz = acpi_driver_data(device);
 
        /* avoid timer adding new defer task */
        tz->zombie = 1;
@@ -1358,14 +1354,33 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
        return 0;
 }
 
-static int acpi_thermal_resume(struct acpi_device *device, int state)
+static int acpi_thermal_resume(struct acpi_device *device)
 {
        struct acpi_thermal *tz = NULL;
+       int i, j, power_state, result;
+
 
        if (!device || !acpi_driver_data(device))
                return -EINVAL;
 
-       tz = (struct acpi_thermal *)acpi_driver_data(device);
+       tz = acpi_driver_data(device);
+
+       for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
+               if (!(&tz->trips.active[i]))
+                       break;
+               if (!tz->trips.active[i].flags.valid)
+                       break;
+               tz->trips.active[i].flags.enabled = 1;
+               for (j = 0; j < tz->trips.active[i].devices.count; j++) {
+                       result = acpi_bus_get_power(tz->trips.active[i].devices.
+                           handles[j], &power_state);
+                       if (result || (power_state != ACPI_STATE_D0)) {
+                               tz->trips.active[i].flags.enabled = 0;
+                               break;
+                       }
+               }
+               tz->state.active |= tz->trips.active[i].flags.enabled;
+       }
 
        acpi_thermal_check(tz);