ACPICA: Add more conversions to predefined name repair module
[safe/jmp/linux-2.6] / drivers / acpi / dock.c
index f19f643..30be3c1 100644 (file)
@@ -33,6 +33,8 @@
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
+#define PREFIX "ACPI: "
+
 #define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
 
 ACPI_MODULE_NAME("dock");
@@ -65,7 +67,7 @@ struct dock_station {
        struct list_head dependent_devices;
        struct list_head hotplug_devices;
 
-       struct list_head sibiling;
+       struct list_head sibling;
        struct platform_device *dock_device;
 };
 static LIST_HEAD(dock_stations);
@@ -75,7 +77,7 @@ struct dock_dependent_device {
        struct list_head list;
        struct list_head hotplug_list;
        acpi_handle handle;
-       acpi_notify_handler handler;
+       struct acpi_dock_ops *ops;
        void *context;
 };
 
@@ -231,18 +233,16 @@ static int is_ata(acpi_handle handle)
 static int is_battery(acpi_handle handle)
 {
        struct acpi_device_info *info;
-       struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
        int ret = 1;
 
-       if (!ACPI_SUCCESS(acpi_get_object_info(handle, &buffer)))
+       if (!ACPI_SUCCESS(acpi_get_object_info(handle, &info)))
                return 0;
-       info = buffer.pointer;
        if (!(info->valid & ACPI_VALID_HID))
                ret = 0;
        else
-               ret = !strcmp("PNP0C0A", info->hardware_id.value);
+               ret = !strcmp("PNP0C0A", info->hardware_id.string);
 
-       kfree(buffer.pointer);
+       kfree(info);
        return ret;
 }
 
@@ -275,7 +275,7 @@ int is_dock_device(acpi_handle handle)
 
        if (is_dock(handle))
                return 1;
-       list_for_each_entry(dock_station, &dock_stations, sibiling) {
+       list_for_each_entry(dock_station, &dock_stations, sibling) {
                if (find_dock_dependent_device(dock_station, handle))
                        return 1;
        }
@@ -294,7 +294,7 @@ EXPORT_SYMBOL_GPL(is_dock_device);
  */
 static int dock_present(struct dock_station *ds)
 {
-       unsigned long sta;
+       unsigned long long sta;
        acpi_status status;
 
        if (ds) {
@@ -385,8 +385,8 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
         * First call driver specific hotplug functions
         */
        list_for_each_entry(dd, &ds->hotplug_devices, hotplug_list) {
-               if (dd->handler)
-                       dd->handler(dd->handle, event, dd->context);
+               if (dd->ops && dd->ops->handler)
+                       dd->ops->handler(dd->handle, event, dd->context);
        }
 
        /*
@@ -409,6 +409,7 @@ static void dock_event(struct dock_station *ds, u32 event, int num)
        struct device *dev = &ds->dock_device->dev;
        char event_string[13];
        char *envp[] = { event_string, NULL };
+       struct dock_dependent_device *dd;
 
        if (num == UNDOCK_EVENT)
                sprintf(event_string, "EVENT=undock");
@@ -419,7 +420,14 @@ static void dock_event(struct dock_station *ds, u32 event, int num)
         * Indicate that the status of the dock station has
         * changed.
         */
-       kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
+       if (num == DOCK_EVENT)
+               kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
+
+       list_for_each_entry(dd, &ds->hotplug_devices, hotplug_list)
+               if (dd->ops && dd->ops->uevent)
+                       dd->ops->uevent(dd->handle, event, dd->context);
+       if (num != DOCK_EVENT)
+               kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
 }
 
 /**
@@ -480,8 +488,9 @@ static void handle_dock(struct dock_station *ds, int dock)
        arg.integer.value = dock;
        status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer);
        if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
-               printk(KERN_ERR PREFIX "%s - failed to execute _DCK\n",
-                        (char *)name_buffer.pointer);
+               ACPI_EXCEPTION((AE_INFO, status, "%s - failed to execute"
+                       " _DCK\n", (char *)name_buffer.pointer));
+
        kfree(buffer.pointer);
        kfree(name_buffer.pointer);
 }
@@ -588,7 +597,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
 /**
  * register_hotplug_dock_device - register a hotplug function
  * @handle: the handle of the device
- * @handler: the acpi_notifier_handler to call after docking
+ * @ops: handlers to call after docking
  * @context: device specific data
  *
  * If a driver would like to perform a hotplug operation after a dock
@@ -596,11 +605,12 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
  * the dock driver after _DCK is executed.
  */
 int
-register_hotplug_dock_device(acpi_handle handle, acpi_notify_handler handler,
+register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
                             void *context)
 {
        struct dock_dependent_device *dd;
        struct dock_station *dock_station;
+       int ret = -EINVAL;
 
        if (!dock_station_count)
                return -ENODEV;
@@ -609,17 +619,22 @@ register_hotplug_dock_device(acpi_handle handle, acpi_notify_handler handler,
         * make sure this handle is for a device dependent on the dock,
         * this would include the dock station itself
         */
-       list_for_each_entry(dock_station, &dock_stations, sibiling) {
+       list_for_each_entry(dock_station, &dock_stations, sibling) {
+               /*
+                * An ATA bay can be in a dock and itself can be ejected
+                * seperately, so there are two 'dock stations' which need the
+                * ops
+                */
                dd = find_dock_dependent_device(dock_station, handle);
                if (dd) {
-                       dd->handler = handler;
+                       dd->ops = ops;
                        dd->context = context;
                        dock_add_hotplug_device(dock_station, dd);
-                       return 0;
+                       ret = 0;
                }
        }
 
-       return -EINVAL;
+       return ret;
 }
 
 EXPORT_SYMBOL_GPL(register_hotplug_dock_device);
@@ -636,7 +651,7 @@ void unregister_hotplug_dock_device(acpi_handle handle)
        if (!dock_station_count)
                return;
 
-       list_for_each_entry(dock_station, &dock_stations, sibiling) {
+       list_for_each_entry(dock_station, &dock_stations, sibling) {
                dd = find_dock_dependent_device(dock_station, handle);
                if (dd)
                        dock_del_hotplug_device(dock_station, dd);
@@ -772,7 +787,7 @@ static int acpi_dock_notifier_call(struct notifier_block *this,
        if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK
           && event != ACPI_NOTIFY_EJECT_REQUEST)
                return 0;
-       list_for_each_entry(dock_station, &dock_stations, sibiling) {
+       list_for_each_entry(dock_station, &dock_stations, sibling) {
                if (dock_station->handle == handle) {
                        struct dock_data *dock_data;
 
@@ -840,10 +855,14 @@ fdd_out:
 static ssize_t show_docked(struct device *dev,
                           struct device_attribute *attr, char *buf)
 {
+       struct acpi_device *tmp;
+
        struct dock_station *dock_station = *((struct dock_station **)
                dev->platform_data);
-       return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station));
 
+       if (ACPI_SUCCESS(acpi_bus_get_device(dock_station->handle, &tmp)))
+               return snprintf(buf, PAGE_SIZE, "1\n");
+       return snprintf(buf, PAGE_SIZE, "0\n");
 }
 static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
 
@@ -885,7 +904,7 @@ static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
 static ssize_t show_dock_uid(struct device *dev,
                             struct device_attribute *attr, char *buf)
 {
-       unsigned long lbuf;
+       unsigned long long lbuf;
        struct dock_station *dock_station = *((struct dock_station **)
                dev->platform_data);
        acpi_status status = acpi_evaluate_integer(dock_station->handle,
@@ -893,10 +912,30 @@ static ssize_t show_dock_uid(struct device *dev,
        if (ACPI_FAILURE(status))
            return 0;
 
-       return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf);
+       return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
 }
 static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
 
+static ssize_t show_dock_type(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       struct dock_station *dock_station = *((struct dock_station **)
+               dev->platform_data);
+       char *type;
+
+       if (dock_station->flags & DOCK_IS_DOCK)
+               type = "dock_station";
+       else if (dock_station->flags & DOCK_IS_ATA)
+               type = "ata_bay";
+       else if (dock_station->flags & DOCK_IS_BAT)
+               type = "battery_bay";
+       else
+               type = "unknown";
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", type);
+}
+static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
+
 /**
  * dock_add - add a new dock station
  * @handle: the dock station handle
@@ -919,7 +958,7 @@ static int dock_add(acpi_handle handle)
        dock_station->last_dock_time = jiffies - HZ;
        INIT_LIST_HEAD(&dock_station->dependent_devices);
        INIT_LIST_HEAD(&dock_station->hotplug_devices);
-       INIT_LIST_HEAD(&dock_station->sibiling);
+       INIT_LIST_HEAD(&dock_station->sibling);
        spin_lock_init(&dock_station->dd_lock);
        mutex_init(&dock_station->hp_lock);
        ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
@@ -938,7 +977,7 @@ static int dock_add(acpi_handle handle)
                sizeof(struct dock_station *));
 
        /* we want the dock device to send uevents */
-       dock_device->dev.uevent_suppress = 0;
+       dev_set_uevent_suppress(&dock_device->dev, 0);
 
        if (is_dock(handle))
                dock_station->flags |= DOCK_IS_DOCK;
@@ -949,7 +988,7 @@ static int dock_add(acpi_handle handle)
 
        ret = device_create_file(&dock_device->dev, &dev_attr_docked);
        if (ret) {
-               printk("Error %d adding sysfs file\n", ret);
+               printk(KERN_ERR "Error %d adding sysfs file\n", ret);
                platform_device_unregister(dock_device);
                kfree(dock_station);
                dock_station = NULL;
@@ -957,7 +996,7 @@ static int dock_add(acpi_handle handle)
        }
        ret = device_create_file(&dock_device->dev, &dev_attr_undock);
        if (ret) {
-               printk("Error %d adding sysfs file\n", ret);
+               printk(KERN_ERR "Error %d adding sysfs file\n", ret);
                device_remove_file(&dock_device->dev, &dev_attr_docked);
                platform_device_unregister(dock_device);
                kfree(dock_station);
@@ -966,7 +1005,7 @@ static int dock_add(acpi_handle handle)
        }
        ret = device_create_file(&dock_device->dev, &dev_attr_uid);
        if (ret) {
-               printk("Error %d adding sysfs file\n", ret);
+               printk(KERN_ERR "Error %d adding sysfs file\n", ret);
                device_remove_file(&dock_device->dev, &dev_attr_docked);
                device_remove_file(&dock_device->dev, &dev_attr_undock);
                platform_device_unregister(dock_device);
@@ -976,7 +1015,7 @@ static int dock_add(acpi_handle handle)
        }
        ret = device_create_file(&dock_device->dev, &dev_attr_flags);
        if (ret) {
-               printk("Error %d adding sysfs file\n", ret);
+               printk(KERN_ERR "Error %d adding sysfs file\n", ret);
                device_remove_file(&dock_device->dev, &dev_attr_docked);
                device_remove_file(&dock_device->dev, &dev_attr_undock);
                device_remove_file(&dock_device->dev, &dev_attr_uid);
@@ -985,11 +1024,14 @@ static int dock_add(acpi_handle handle)
                dock_station = NULL;
                return ret;
        }
+       ret = device_create_file(&dock_device->dev, &dev_attr_type);
+       if (ret)
+               printk(KERN_ERR"Error %d adding sysfs file\n", ret);
 
        /* Find dependent devices */
        acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
-                           ACPI_UINT32_MAX, find_dock_devices, dock_station,
-                           NULL);
+                           ACPI_UINT32_MAX, find_dock_devices, NULL,
+                           dock_station, NULL);
 
        /* add the dock station as a device dependent on itself */
        dd = alloc_dock_dependent_device(handle);
@@ -1002,10 +1044,11 @@ static int dock_add(acpi_handle handle)
        add_dock_dependent_device(dock_station, dd);
 
        dock_station_count++;
-       list_add(&dock_station->sibiling, &dock_stations);
+       list_add(&dock_station->sibling, &dock_stations);
        return 0;
 
 dock_add_err_unregister:
+       device_remove_file(&dock_device->dev, &dev_attr_type);
        device_remove_file(&dock_device->dev, &dev_attr_docked);
        device_remove_file(&dock_device->dev, &dev_attr_undock);
        device_remove_file(&dock_device->dev, &dev_attr_uid);
@@ -1033,6 +1076,7 @@ static int dock_remove(struct dock_station *dock_station)
            kfree(dd);
 
        /* cleanup sysfs */
+       device_remove_file(&dock_device->dev, &dev_attr_type);
        device_remove_file(&dock_device->dev, &dev_attr_docked);
        device_remove_file(&dock_device->dev, &dev_attr_undock);
        device_remove_file(&dock_device->dev, &dev_attr_uid);
@@ -1070,8 +1114,8 @@ find_dock(acpi_handle handle, u32 lvl, void *context, void **rv)
 static acpi_status
 find_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
-       /* If bay is in a dock, it's already handled */
-       if (is_ejectable_bay(handle) && !is_dock_device(handle))
+       /* If bay is a dock, it's already handled */
+       if (is_ejectable_bay(handle) && !is_dock(handle))
                dock_add(handle);
        return AE_OK;
 }
@@ -1083,11 +1127,11 @@ static int __init dock_init(void)
 
        /* look for a dock station */
        acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
-                           ACPI_UINT32_MAX, find_dock, NULL, NULL);
+                           ACPI_UINT32_MAX, find_dock, NULL, NULL, NULL);
 
        /* look for bay */
        acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
-                       ACPI_UINT32_MAX, find_bay, NULL, NULL);
+                       ACPI_UINT32_MAX, find_bay, NULL, NULL, NULL);
        if (!dock_station_count) {
                printk(KERN_INFO PREFIX "No dock devices found.\n");
                return 0;
@@ -1102,9 +1146,10 @@ static int __init dock_init(void)
 static void __exit dock_exit(void)
 {
        struct dock_station *dock_station;
+       struct dock_station *tmp;
 
        unregister_acpi_bus_notifier(&dock_acpi_notifier);
-       list_for_each_entry(dock_station, &dock_stations, sibiling)
+       list_for_each_entry_safe(dock_station, tmp, &dock_stations, sibling)
                dock_remove(dock_station);
 }