]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/acpi/dock.c
Merge branch 'v28-range-hrtimers-for-linus-v2' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-omap-h63xx.git] / drivers / acpi / dock.c
index 2563bc62987d4e9e72263cac52225b76478e2b81..5b30b8d91d716126cdd3305d61ee8fd625eea016 100644 (file)
@@ -75,7 +75,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;
 };
 
@@ -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;
@@ -610,16 +620,21 @@ register_hotplug_dock_device(acpi_handle handle, acpi_notify_handler handler,
         * this would include the dock station itself
         */
        list_for_each_entry(dock_station, &dock_stations, sibiling) {
+               /*
+                * 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);
@@ -738,7 +753,8 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
                /* Fall back */
        case ACPI_NOTIFY_EJECT_REQUEST:
                begin_undock(ds);
-               if (immediate_undock || surprise_removal)
+               if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
+                  || surprise_removal)
                        handle_eject_request(ds, event);
                else
                        dock_event(ds, event, UNDOCK_EVENT);
@@ -748,6 +764,20 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
        }
 }
 
+struct dock_data {
+       acpi_handle handle;
+       unsigned long event;
+       struct dock_station *ds;
+};
+
+static void acpi_dock_deferred_cb(void *context)
+{
+       struct dock_data *data = (struct dock_data *)context;
+
+       dock_notify(data->handle, data->event, data->ds);
+       kfree(data);
+}
+
 static int acpi_dock_notifier_call(struct notifier_block *this,
        unsigned long event, void *data)
 {
@@ -759,7 +789,16 @@ static int acpi_dock_notifier_call(struct notifier_block *this,
                return 0;
        list_for_each_entry(dock_station, &dock_stations, sibiling) {
                if (dock_station->handle == handle) {
-                       dock_notify(handle, event, dock_station);
+                       struct dock_data *dock_data;
+
+                       dock_data = kmalloc(sizeof(*dock_data), GFP_KERNEL);
+                       if (!dock_data)
+                               return 0;
+                       dock_data->handle = handle;
+                       dock_data->event = event;
+                       dock_data->ds = dock_station;
+                       acpi_os_hotplug_execute(acpi_dock_deferred_cb,
+                               dock_data);
                        return 0 ;
                }
        }
@@ -861,7 +900,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,
@@ -869,10 +908,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
@@ -961,6 +1020,9 @@ 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,
@@ -982,6 +1044,7 @@ static int dock_add(acpi_handle handle)
        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);
@@ -1009,6 +1072,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);
@@ -1046,8 +1110,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;
 }