Pull acpica into test branch
authorLen Brown <len.brown@intel.com>
Sat, 3 Feb 2007 06:08:52 +0000 (01:08 -0500)
committerLen Brown <len.brown@intel.com>
Sat, 3 Feb 2007 06:08:52 +0000 (01:08 -0500)
drivers/acpi/Kconfig
drivers/acpi/glue.c
drivers/acpi/pci_root.c
drivers/acpi/video.c

index f4f000abc4e9f497e08bb80c64af2a627e3bdb84..50e295b08c94dfb23f266e83478455d4a3449cc0 100644 (file)
@@ -107,7 +107,7 @@ config ACPI_BUTTON
 
 config ACPI_VIDEO
        tristate "Video"
-       depends on X86
+       depends on X86 && BACKLIGHT_CLASS_DEVICE
        help
          This driver implement the ACPI Extensions For Display Adapters
          for integrated graphics devices on motherboard, as specified in
index 8a0324b43e53869adcf9f98a29c513a38b1c2d15..7b6c9ff9bebe17d92cb954bc1e6d34e2fac1d946 100644 (file)
@@ -86,129 +86,6 @@ static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
        return ret;
 }
 
-/* Get PCI root bridge's handle from its segment and bus number */
-struct acpi_find_pci_root {
-       unsigned int seg;
-       unsigned int bus;
-       acpi_handle handle;
-};
-
-static acpi_status
-do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
-{
-       unsigned long *busnr = data;
-       struct acpi_resource_address64 address;
-
-       if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
-           resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
-           resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
-               return AE_OK;
-
-       acpi_resource_to_address64(resource, &address);
-       if ((address.address_length > 0) &&
-           (address.resource_type == ACPI_BUS_NUMBER_RANGE))
-               *busnr = address.minimum;
-
-       return AE_OK;
-}
-
-static int get_root_bridge_busnr(acpi_handle handle)
-{
-       acpi_status status;
-       unsigned long bus, bbn;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-
-       status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
-                                      &bbn);
-       if (status == AE_NOT_FOUND) {
-               /* Assume bus = 0 */
-               printk(KERN_INFO PREFIX
-                      "Assume root bridge [%s] bus is 0\n",
-                      (char *)buffer.pointer);
-               status = AE_OK;
-               bbn = 0;
-       }
-       if (ACPI_FAILURE(status)) {
-               bbn = -ENODEV;
-               goto exit;
-       }
-       if (bbn > 0)
-               goto exit;
-
-       /* _BBN in some systems return 0 for all root bridges */
-       bus = -1;
-       status = acpi_walk_resources(handle, METHOD_NAME__CRS,
-                                    do_root_bridge_busnr_callback, &bus);
-       /* If _CRS failed, we just use _BBN */
-       if (ACPI_FAILURE(status) || (bus == -1))
-               goto exit;
-       /* We select _CRS */
-       if (bbn != bus) {
-               printk(KERN_INFO PREFIX
-                      "_BBN and _CRS returns different value for %s. Select _CRS\n",
-                      (char *)buffer.pointer);
-               bbn = bus;
-       }
-      exit:
-       kfree(buffer.pointer);
-       return (int)bbn;
-}
-
-static acpi_status
-find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
-{
-       struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
-       unsigned long seg, bus;
-       acpi_status status;
-       int tmp;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-
-       acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-
-       status = acpi_evaluate_integer(handle, METHOD_NAME__SEG, NULL, &seg);
-       if (status == AE_NOT_FOUND) {
-               /* Assume seg = 0 */
-               status = AE_OK;
-               seg = 0;
-       }
-       if (ACPI_FAILURE(status)) {
-               status = AE_CTRL_DEPTH;
-               goto exit;
-       }
-
-       tmp = get_root_bridge_busnr(handle);
-       if (tmp < 0) {
-               printk(KERN_ERR PREFIX
-                      "Find root bridge failed for %s\n",
-                      (char *)buffer.pointer);
-               status = AE_CTRL_DEPTH;
-               goto exit;
-       }
-       bus = tmp;
-
-       if (seg == find->seg && bus == find->bus)
-       {
-               find->handle = handle;
-               status = AE_CTRL_TERMINATE;
-       }
-       else
-               status = AE_OK;
-      exit:
-       kfree(buffer.pointer);
-       return status;
-}
-
-acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
-{
-       struct acpi_find_pci_root find = { seg, bus, NULL };
-
-       acpi_get_devices(PCI_ROOT_HID_STRING, find_pci_rootbridge, &find, NULL);
-       return find.handle;
-}
-EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
-
 /* Get device's handler per its address under its parent */
 struct acpi_find_child {
        acpi_handle handle;
index a860efa2c562670768e447ada93eea69b03277d1..1f06229040acecac32880cd9fb1e9f508d168cd6 100644 (file)
@@ -117,6 +117,19 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
 
 EXPORT_SYMBOL(acpi_pci_unregister_driver);
 
+acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
+{
+       struct acpi_pci_root *tmp;
+       
+       list_for_each_entry(tmp, &acpi_pci_roots, node) {
+               if ((tmp->id.segment == (u16) seg) && (tmp->id.bus == (u16) bus))
+                       return tmp->device->handle;
+       }
+       return NULL;            
+}
+
+EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
+
 static acpi_status
 get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
 {
index 3d54680d0333c34464b1df9e5fe2631b63050079..a695aeb8b2a74f89ca56e0e53923ae6938e2d731 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 
+#include <linux/backlight.h>
 #include <asm/uaccess.h>
 
 #include <acpi/acpi_bus.h>
 
 #define ACPI_VIDEO_HEAD_INVALID                (~0u - 1)
 #define ACPI_VIDEO_HEAD_END            (~0u)
+#define MAX_NAME_LEN   20
+
+#define ACPI_VIDEO_DISPLAY_CRT 1
+#define ACPI_VIDEO_DISPLAY_TV  2
+#define ACPI_VIDEO_DISPLAY_DVI 3
+#define ACPI_VIDEO_DISPLAY_LCD 4
 
 #define _COMPONENT             ACPI_VIDEO_COMPONENT
 ACPI_MODULE_NAME("acpi_video")
@@ -133,20 +140,21 @@ struct acpi_video_device_flags {
        u8 crt:1;
        u8 lcd:1;
        u8 tvout:1;
+       u8 dvi:1;
        u8 bios:1;
        u8 unknown:1;
-       u8 reserved:3;
+       u8 reserved:2;
 };
 
 struct acpi_video_device_cap {
        u8 _ADR:1;              /*Return the unique ID */
        u8 _BCL:1;              /*Query list of brightness control levels supported */
        u8 _BCM:1;              /*Set the brightness level */
+       u8 _BQC:1;              /* Get current brightness level */
        u8 _DDC:1;              /*Return the EDID for this device */
        u8 _DCS:1;              /*Return status of output device */
        u8 _DGS:1;              /*Query graphics state */
        u8 _DSS:1;              /*Device state set */
-       u8 _reserved:1;
 };
 
 struct acpi_video_device_brightness {
@@ -163,6 +171,8 @@ struct acpi_video_device {
        struct acpi_video_bus *video;
        struct acpi_device *dev;
        struct acpi_video_device_brightness *brightness;
+       struct backlight_device *backlight;
+       struct backlight_properties *data;
 };
 
 /* bus */
@@ -257,11 +267,35 @@ static void acpi_video_device_bind(struct acpi_video_bus *video,
                                   struct acpi_video_device *device);
 static int acpi_video_device_enumerate(struct acpi_video_bus *video);
 static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
+static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
+                       int level);
+static int acpi_video_device_lcd_get_level_current(
+                       struct acpi_video_device *device,
+                       unsigned long *level);
 static int acpi_video_get_next_level(struct acpi_video_device *device,
                                     u32 level_current, u32 event);
 static void acpi_video_switch_brightness(struct acpi_video_device *device,
                                         int event);
 
+/*backlight device sysfs support*/
+static int acpi_video_get_brightness(struct backlight_device *bd)
+{
+       unsigned long cur_level;
+       struct acpi_video_device *vd =
+               (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
+       acpi_video_device_lcd_get_level_current(vd, &cur_level);
+       return (int) cur_level;
+}
+
+static int acpi_video_set_brightness(struct backlight_device *bd)
+{
+       int request_level = bd->props->brightness;
+       struct acpi_video_device *vd =
+               (struct acpi_video_device *)class_get_devdata(&bd->class_dev);
+       acpi_video_device_lcd_set_level(vd, request_level);
+       return 0;
+}
+
 /* --------------------------------------------------------------------------
                                Video Management
    -------------------------------------------------------------------------- */
@@ -499,6 +533,7 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
        acpi_integer status;
        acpi_handle h_dummy1;
        int i;
+       u32 max_level = 0;
        union acpi_object *obj = NULL;
        struct acpi_video_device_brightness *br = NULL;
 
@@ -514,6 +549,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
                device->cap._BCM = 1;
        }
+       if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
+               device->cap._BQC = 1;
        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
                device->cap._DDC = 1;
        }
@@ -550,6 +587,8 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
                                        continue;
                                }
                                br->levels[count] = (u32) o->integer.value;
+                               if (br->levels[count] > max_level)
+                                       max_level = br->levels[count];
                                count++;
                        }
                      out:
@@ -568,6 +607,37 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
 
        kfree(obj);
 
+       if (device->cap._BCL && device->cap._BCM && device->cap._BQC){
+               unsigned long tmp;
+               static int count = 0;
+               char *name;
+               struct backlight_properties *acpi_video_data;
+
+               name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
+               if (!name)
+                       return;
+
+               acpi_video_data = kzalloc(
+                       sizeof(struct backlight_properties),
+                       GFP_KERNEL);
+               if (!acpi_video_data){
+                       kfree(name);
+                       return;
+               }
+               acpi_video_data->owner = THIS_MODULE;
+               acpi_video_data->get_brightness =
+                       acpi_video_get_brightness;
+               acpi_video_data->update_status =
+                       acpi_video_set_brightness;
+               sprintf(name, "acpi_video%d", count++);
+               device->data = acpi_video_data;
+               acpi_video_data->max_brightness = max_level;
+               acpi_video_device_lcd_get_level_current(device, &tmp);
+               acpi_video_data->brightness = (int)tmp;
+               device->backlight = backlight_device_register(name,
+                       NULL, device, acpi_video_data);
+               kfree(name);
+       }
        return;
 }
 
@@ -668,6 +738,8 @@ static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
                seq_printf(seq, "LCD\n");
        else if (dev->flags.tvout)
                seq_printf(seq, "TVOUT\n");
+       else if (dev->flags.dvi)
+               seq_printf(seq, "DVI\n");
        else
                seq_printf(seq, "UNKNOWN\n");
 
@@ -1242,6 +1314,16 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
    -------------------------------------------------------------------------- */
 
 /* device interface */
+static struct acpi_video_device_attrib*
+acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
+{
+       int count;
+
+       for(count = 0; count < video->attached_count; count++)
+               if((video->attached_array[count].value.int_val & 0xffff) == device_id)
+                       return &(video->attached_array[count].value.attrib);
+       return NULL;
+}
 
 static int
 acpi_video_bus_get_one_device(struct acpi_device *device,
@@ -1250,7 +1332,7 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
        unsigned long device_id;
        int status;
        struct acpi_video_device *data;
-
+       struct acpi_video_device_attrib* attribute;
 
        if (!device || !video)
                return -EINVAL;
@@ -1271,20 +1353,30 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
                data->video = video;
                data->dev = device;
 
-               switch (device_id & 0xffff) {
-               case 0x0100:
-                       data->flags.crt = 1;
-                       break;
-               case 0x0400:
-                       data->flags.lcd = 1;
-                       break;
-               case 0x0200:
-                       data->flags.tvout = 1;
-                       break;
-               default:
+               attribute = acpi_video_get_device_attr(video, device_id);
+
+               if((attribute != NULL) && attribute->device_id_scheme) {
+                       switch (attribute->display_type) {
+                       case ACPI_VIDEO_DISPLAY_CRT:
+                               data->flags.crt = 1;
+                               break;
+                       case ACPI_VIDEO_DISPLAY_TV:
+                               data->flags.tvout = 1;
+                               break;
+                       case ACPI_VIDEO_DISPLAY_DVI:
+                               data->flags.dvi = 1;
+                               break;
+                       case ACPI_VIDEO_DISPLAY_LCD:
+                               data->flags.lcd = 1;
+                               break;
+                       default:
+                               data->flags.unknown = 1;
+                               break;
+                       }
+                       if(attribute->bios_can_detect)
+                               data->flags.bios = 1;
+               } else
                        data->flags.unknown = 1;
-                       break;
-               }
 
                acpi_video_device_bind(video, data);
                acpi_video_device_find_cap(data);
@@ -1588,7 +1680,10 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
        status = acpi_remove_notify_handler(device->dev->handle,
                                            ACPI_DEVICE_NOTIFY,
                                            acpi_video_device_notify);
-
+       if (device->backlight){
+               backlight_device_unregister(device->backlight);
+               kfree(device->data);
+       }
        return 0;
 }