Merge branch 'release-2.6.27' of git://git.kernel.org/pub/scm/linux/kernel/git/ak...
[pandora-kernel.git] / drivers / acpi / video.c
index 33c502e..e8a51a1 100644 (file)
@@ -190,6 +190,7 @@ struct acpi_video_device {
 /* bus */
 static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
 static struct file_operations acpi_video_bus_info_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_bus_info_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -198,6 +199,7 @@ static struct file_operations acpi_video_bus_info_fops = {
 
 static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
 static struct file_operations acpi_video_bus_ROM_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_bus_ROM_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -207,6 +209,7 @@ static struct file_operations acpi_video_bus_ROM_fops = {
 static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
                                            struct file *file);
 static struct file_operations acpi_video_bus_POST_info_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_bus_POST_info_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -215,6 +218,7 @@ static struct file_operations acpi_video_bus_POST_info_fops = {
 
 static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
 static struct file_operations acpi_video_bus_POST_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_bus_POST_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -223,6 +227,7 @@ static struct file_operations acpi_video_bus_POST_fops = {
 
 static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
 static struct file_operations acpi_video_bus_DOS_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_bus_DOS_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -233,6 +238,7 @@ static struct file_operations acpi_video_bus_DOS_fops = {
 static int acpi_video_device_info_open_fs(struct inode *inode,
                                          struct file *file);
 static struct file_operations acpi_video_device_info_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_device_info_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -242,6 +248,7 @@ static struct file_operations acpi_video_device_info_fops = {
 static int acpi_video_device_state_open_fs(struct inode *inode,
                                           struct file *file);
 static struct file_operations acpi_video_device_state_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_device_state_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -251,6 +258,7 @@ static struct file_operations acpi_video_device_state_fops = {
 static int acpi_video_device_brightness_open_fs(struct inode *inode,
                                                struct file *file);
 static struct file_operations acpi_video_device_brightness_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_device_brightness_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -260,6 +268,7 @@ static struct file_operations acpi_video_device_brightness_fops = {
 static int acpi_video_device_EDID_open_fs(struct inode *inode,
                                          struct file *file);
 static struct file_operations acpi_video_device_EDID_fops = {
+       .owner = THIS_MODULE,
        .open = acpi_video_device_EDID_open_fs,
        .read = seq_read,
        .llseek = seq_lseek,
@@ -622,6 +631,76 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
  *     device  : video output device (LCD, CRT, ..)
  *
  *  Return Value:
+ *     Maximum brightness level
+ *
+ *  Allocate and initialize device->brightness.
+ */
+
+static int
+acpi_video_init_brightness(struct acpi_video_device *device)
+{
+       union acpi_object *obj = NULL;
+       int i, max_level = 0, count = 0;
+       union acpi_object *o;
+       struct acpi_video_device_brightness *br = NULL;
+
+       if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
+                                               "LCD brightness level\n"));
+               goto out;
+       }
+
+       if (obj->package.count < 2)
+               goto out;
+
+       br = kzalloc(sizeof(*br), GFP_KERNEL);
+       if (!br) {
+               printk(KERN_ERR "can't allocate memory\n");
+               goto out;
+       }
+
+       br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
+                               GFP_KERNEL);
+       if (!br->levels)
+               goto out_free;
+
+       for (i = 0; i < obj->package.count; i++) {
+               o = (union acpi_object *)&obj->package.elements[i];
+               if (o->type != ACPI_TYPE_INTEGER) {
+                       printk(KERN_ERR PREFIX "Invalid data\n");
+                       continue;
+               }
+               br->levels[count] = (u32) o->integer.value;
+
+               if (br->levels[count] > max_level)
+                       max_level = br->levels[count];
+               count++;
+       }
+
+       if (count < 2)
+               goto out_free_levels;
+
+       br->count = count;
+       device->brightness = br;
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels\n", count));
+       kfree(obj);
+       return max_level;
+
+out_free_levels:
+       kfree(br->levels);
+out_free:
+       kfree(br);
+out:
+       device->brightness = NULL;
+       kfree(obj);
+       return 0;
+}
+
+/*
+ *  Arg:
+ *     device  : video output device (LCD, CRT, ..)
+ *
+ *  Return Value:
  *     None
  *
  *  Find out all required AML methods defined under the output
@@ -631,10 +710,7 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
 static void acpi_video_device_find_cap(struct acpi_video_device *device)
 {
        acpi_handle h_dummy1;
-       int i;
        u32 max_level = 0;
-       union acpi_object *obj = NULL;
-       struct acpi_video_device_brightness *br = NULL;
 
 
        memset(&device->cap, 0, sizeof(device->cap));
@@ -663,55 +739,9 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
                device->cap._DSS = 1;
        }
 
-       if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
-
-               if (obj->package.count >= 2) {
-                       int count = 0;
-                       union acpi_object *o;
-
-                       br = kzalloc(sizeof(*br), GFP_KERNEL);
-                       if (!br) {
-                               printk(KERN_ERR "can't allocate memory\n");
-                       } else {
-                               br->levels = kmalloc(obj->package.count *
-                                                    sizeof *(br->levels), GFP_KERNEL);
-                               if (!br->levels)
-                                       goto out;
-
-                               for (i = 0; i < obj->package.count; i++) {
-                                       o = (union acpi_object *)&obj->package.
-                                           elements[i];
-                                       if (o->type != ACPI_TYPE_INTEGER) {
-                                               printk(KERN_ERR PREFIX "Invalid data\n");
-                                               continue;
-                                       }
-                                       br->levels[count] = (u32) o->integer.value;
-
-                                       if (br->levels[count] > max_level)
-                                               max_level = br->levels[count];
-                                       count++;
-                               }
-                             out:
-                               if (count < 2) {
-                                       kfree(br->levels);
-                                       kfree(br);
-                               } else {
-                                       br->count = count;
-                                       device->brightness = br;
-                                       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                                         "found %d brightness levels\n",
-                                                         count));
-                               }
-                       }
-               }
+       max_level = acpi_video_init_brightness(device);
 
-       } else {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
-       }
-
-       kfree(obj);
-
-       if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
+       if (device->cap._BCL && device->cap._BCM && max_level > 0) {
                int result;
                static int count = 0;
                char *name;
@@ -723,7 +753,17 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
                device->backlight = backlight_device_register(name,
                        NULL, device, &acpi_backlight_ops);
                device->backlight->props.max_brightness = device->brightness->count-3;
-               device->backlight->props.brightness = acpi_video_get_brightness(device->backlight);
+               /*
+                * If there exists the _BQC object, the _BQC object will be
+                * called to get the current backlight brightness. Otherwise
+                * the brightness will be set to the maximum.
+                */
+               if (device->cap._BQC)
+                       device->backlight->props.brightness =
+                               acpi_video_get_brightness(device->backlight);
+               else
+                       device->backlight->props.brightness =
+                               device->backlight->props.max_brightness;
                backlight_update_status(device->backlight);
                kfree(name);
 
@@ -732,9 +772,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
                if (IS_ERR(device->cdev))
                        return;
 
-               printk(KERN_INFO PREFIX
-                       "%s is registered as cooling_device%d\n",
-                       device->dev->dev.bus_id, device->cdev->id);
+               dev_info(&device->dev->dev, "registered as cooling_device%d\n",
+                        device->cdev->id);
                result = sysfs_create_link(&device->dev->dev.kobj,
                                &device->cdev->device.kobj,
                                "thermal_cooling");
@@ -1061,47 +1100,39 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
        device_dir->owner = THIS_MODULE;
 
        /* 'info' [R] */
-       entry = create_proc_entry("info", S_IRUGO, device_dir);
+       entry = proc_create_data("info", S_IRUGO, device_dir,
+                       &acpi_video_device_info_fops, acpi_driver_data(device));
        if (!entry)
                goto err_remove_dir;
 
-       entry->proc_fops = &acpi_video_device_info_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'state' [R/W] */
-       entry = create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
-                                 device_dir);
+       acpi_video_device_state_fops.write = acpi_video_device_write_state;
+       entry = proc_create_data("state", S_IFREG | S_IRUGO | S_IWUSR,
+                                device_dir,
+                                &acpi_video_device_state_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_info;
 
-       acpi_video_device_state_fops.write = acpi_video_device_write_state;
-       entry->proc_fops = &acpi_video_device_state_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'brightness' [R/W] */
-       entry = create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
-                                 device_dir);
+       acpi_video_device_brightness_fops.write =
+               acpi_video_device_write_brightness;
+       entry = proc_create_data("brightness", S_IFREG | S_IRUGO | S_IWUSR,
+                                device_dir,
+                                &acpi_video_device_brightness_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_state;
 
-       acpi_video_device_brightness_fops.write =
-                       acpi_video_device_write_brightness;
-       entry->proc_fops = &acpi_video_device_brightness_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'EDID' [R] */
-       entry = create_proc_entry("EDID", S_IRUGO, device_dir);
+       entry = proc_create_data("EDID", S_IRUGO, device_dir,
+                                &acpi_video_device_EDID_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_brightness;
 
-       entry->proc_fops = &acpi_video_device_EDID_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        acpi_device_dir(device) = device_dir;
+
        return 0;
 
  err_remove_brightness:
@@ -1347,54 +1378,44 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
        device_dir->owner = THIS_MODULE;
 
        /* 'info' [R] */
-       entry = create_proc_entry("info", S_IRUGO, device_dir);
+       entry = proc_create_data("info", S_IRUGO, device_dir,
+                                &acpi_video_bus_info_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_dir;
 
-       entry->proc_fops = &acpi_video_bus_info_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'ROM' [R] */
-       entry = create_proc_entry("ROM", S_IRUGO, device_dir);
+       entry = proc_create_data("ROM", S_IRUGO, device_dir,
+                                &acpi_video_bus_ROM_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_info;
 
-       entry->proc_fops = &acpi_video_bus_ROM_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'POST_info' [R] */
-       entry = create_proc_entry("POST_info", S_IRUGO, device_dir);
+       entry = proc_create_data("POST_info", S_IRUGO, device_dir,
+                                &acpi_video_bus_POST_info_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_rom;
 
-       entry->proc_fops = &acpi_video_bus_POST_info_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'POST' [R/W] */
-       entry = create_proc_entry("POST", S_IFREG | S_IRUGO | S_IWUSR,
-                                 device_dir);
+       acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
+       entry = proc_create_data("POST", S_IFREG | S_IRUGO | S_IWUSR,
+                                device_dir,
+                                &acpi_video_bus_POST_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_post_info;
 
-       acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
-       entry->proc_fops = &acpi_video_bus_POST_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        /* 'DOS' [R/W] */
-       entry = create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IWUSR,
-                             device_dir);
+       acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
+       entry = proc_create_data("DOS", S_IFREG | S_IRUGO | S_IWUSR,
+                                device_dir,
+                                &acpi_video_bus_DOS_fops,
+                                acpi_driver_data(device));
        if (!entry)
                goto err_remove_post;
 
-       acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
-       entry->proc_fops = &acpi_video_bus_DOS_fops;
-       entry->data = acpi_driver_data(device);
-       entry->owner = THIS_MODULE;
-
        video->dir = acpi_device_dir(device) = device_dir;
        return 0;
 
@@ -1704,6 +1725,8 @@ static void
 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
 {
        unsigned long level_current, level_next;
+       if (!device->brightness)
+               return;
        acpi_video_device_lcd_get_level_current(device, &level_current);
        level_next = acpi_video_get_next_level(device, level_current, event);
        acpi_video_device_lcd_set_level(device, level_next);
@@ -1722,7 +1745,8 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
 
                status = acpi_video_bus_get_one_device(dev, video);
                if (ACPI_FAILURE(status)) {
-                       ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
+                       ACPI_DEBUG_PRINT((ACPI_DB_WARN,
+                                       "Cant attach device"));
                        continue;
                }
        }