]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/acpi/dock.c
ACPI: dock: add struct dock_station * directly to platform device data
[karo-tx-linux.git] / drivers / acpi / dock.c
index 7338b6a3e049aa061d00bf13b469ffb086d5276a..cfcd8eeb3b2ab43694d731a929185d3a4d89b803 100644 (file)
@@ -50,7 +50,6 @@ MODULE_PARM_DESC(immediate_undock, "1 (default) will cause the driver to "
        " before undocking");
 
 static struct atomic_notifier_head dock_notifier_list;
-static char dock_device_name[] = "dock";
 
 static const struct acpi_device_id dock_device_ids[] = {
        {"LNXDOCK", 0},
@@ -93,40 +92,30 @@ struct dock_dependent_device {
  *                         Dock Dependent device functions                   *
  *****************************************************************************/
 /**
- *  alloc_dock_dependent_device - allocate and init a dependent device
- *  @handle: the acpi_handle of the dependent device
+ * add_dock_dependent_device - associate a device with the dock station
+ * @ds: The dock station
+ * @handle: handle of the dependent device
  *
- *  Allocate memory for a dependent device structure for a device referenced
- *  by the acpi handle
+ * Add the dependent device to the dock's dependent device list.
  */
-static struct dock_dependent_device *
-alloc_dock_dependent_device(acpi_handle handle)
+static int
+add_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
 {
        struct dock_dependent_device *dd;
 
        dd = kzalloc(sizeof(*dd), GFP_KERNEL);
-       if (dd) {
-               dd->handle = handle;
-               INIT_LIST_HEAD(&dd->list);
-               INIT_LIST_HEAD(&dd->hotplug_list);
-       }
-       return dd;
-}
+       if (!dd)
+               return -ENOMEM;
+
+       dd->handle = handle;
+       INIT_LIST_HEAD(&dd->list);
+       INIT_LIST_HEAD(&dd->hotplug_list);
 
-/**
- * add_dock_dependent_device - associate a device with the dock station
- * @ds: The dock station
- * @dd: The dependent device
- *
- * Add the dependent device to the dock's dependent device list.
- */
-static void
-add_dock_dependent_device(struct dock_station *ds,
-                         struct dock_dependent_device *dd)
-{
        spin_lock(&ds->dd_lock);
        list_add_tail(&dd->list, &ds->dependent_devices);
        spin_unlock(&ds->dd_lock);
+
+       return 0;
 }
 
 /**
@@ -826,7 +815,6 @@ find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
        acpi_status status;
        acpi_handle tmp, parent;
        struct dock_station *ds = context;
-       struct dock_dependent_device *dd;
 
        status = acpi_bus_get_ejd(handle, &tmp);
        if (ACPI_FAILURE(status)) {
@@ -840,11 +828,9 @@ find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
                        goto fdd_out;
        }
 
-       if (tmp == ds->handle) {
-               dd = alloc_dock_dependent_device(handle);
-               if (dd)
-                       add_dock_dependent_device(ds, dd);
-       }
+       if (tmp == ds->handle)
+               add_dock_dependent_device(ds, handle);
+
 fdd_out:
        return AE_OK;
 }
@@ -857,8 +843,7 @@ static ssize_t show_docked(struct device *dev,
 {
        struct acpi_device *tmp;
 
-       struct dock_station *dock_station = *((struct dock_station **)
-               dev->platform_data);
+       struct dock_station *dock_station = dev->platform_data;
 
        if (ACPI_SUCCESS(acpi_bus_get_device(dock_station->handle, &tmp)))
                return snprintf(buf, PAGE_SIZE, "1\n");
@@ -872,8 +857,7 @@ static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
 static ssize_t show_flags(struct device *dev,
                          struct device_attribute *attr, char *buf)
 {
-       struct dock_station *dock_station = *((struct dock_station **)
-               dev->platform_data);
+       struct dock_station *dock_station = dev->platform_data;
        return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
 
 }
@@ -886,8 +870,7 @@ static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
                           const char *buf, size_t count)
 {
        int ret;
-       struct dock_station *dock_station = *((struct dock_station **)
-               dev->platform_data);
+       struct dock_station *dock_station = dev->platform_data;
 
        if (!count)
                return -EINVAL;
@@ -905,8 +888,7 @@ static ssize_t show_dock_uid(struct device *dev,
                             struct device_attribute *attr, char *buf)
 {
        unsigned long long lbuf;
-       struct dock_station *dock_station = *((struct dock_station **)
-               dev->platform_data);
+       struct dock_station *dock_station = dev->platform_data;
        acpi_status status = acpi_evaluate_integer(dock_station->handle,
                                        "_UID", NULL, &lbuf);
        if (ACPI_FAILURE(status))
@@ -919,8 +901,7 @@ 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);
+       struct dock_station *dock_station = dev->platform_data;
        char *type;
 
        if (dock_station->flags & DOCK_IS_DOCK)
@@ -936,6 +917,19 @@ static ssize_t show_dock_type(struct device *dev,
 }
 static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
 
+static struct attribute *dock_attributes[] = {
+       &dev_attr_docked.attr,
+       &dev_attr_flags.attr,
+       &dev_attr_undock.attr,
+       &dev_attr_uid.attr,
+       &dev_attr_type.attr,
+       NULL
+};
+
+static struct attribute_group dock_attribute_group = {
+       .attrs = dock_attributes
+};
+
 /**
  * dock_add - add a new dock station
  * @handle: the dock station handle
@@ -945,16 +939,20 @@ static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
  */
 static int dock_add(acpi_handle handle)
 {
-       int ret;
-       struct dock_dependent_device *dd;
-       struct dock_station *dock_station;
+       int ret, id;
+       struct dock_station ds, *dock_station;
        struct platform_device *dock_device;
 
-       /* allocate & initialize the dock_station private data */
-       dock_station = kzalloc(sizeof(*dock_station), GFP_KERNEL);
-       if (!dock_station)
-               return -ENOMEM;
+       id = dock_station_count;
+       dock_device =
+               platform_device_register_data(NULL, "dock",
+                       id, &ds, sizeof(ds));
+       if (IS_ERR(dock_device))
+               return PTR_ERR(dock_device);
+
+       dock_station = dock_device->dev.platform_data;
        dock_station->handle = handle;
+       dock_station->dock_device = dock_device;
        dock_station->last_dock_time = jiffies - HZ;
        INIT_LIST_HEAD(&dock_station->dependent_devices);
        INIT_LIST_HEAD(&dock_station->hotplug_devices);
@@ -963,19 +961,6 @@ static int dock_add(acpi_handle handle)
        mutex_init(&dock_station->hp_lock);
        ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
 
-       /* initialize platform device stuff */
-       dock_station->dock_device =
-               platform_device_register_simple(dock_device_name,
-                       dock_station_count, NULL, 0);
-       dock_device = dock_station->dock_device;
-       if (IS_ERR(dock_device)) {
-               kfree(dock_station);
-               dock_station = NULL;
-               return PTR_ERR(dock_device);
-       }
-       platform_device_add_data(dock_device, &dock_station,
-               sizeof(struct dock_station *));
-
        /* we want the dock device to send uevents */
        dev_set_uevent_suppress(&dock_device->dev, 0);
 
@@ -986,47 +971,9 @@ static int dock_add(acpi_handle handle)
        if (is_battery(handle))
                dock_station->flags |= DOCK_IS_BAT;
 
-       ret = device_create_file(&dock_device->dev, &dev_attr_docked);
-       if (ret) {
-               printk(KERN_ERR "Error %d adding sysfs file\n", ret);
-               platform_device_unregister(dock_device);
-               kfree(dock_station);
-               dock_station = NULL;
-               return ret;
-       }
-       ret = device_create_file(&dock_device->dev, &dev_attr_undock);
-       if (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);
-               dock_station = NULL;
-               return ret;
-       }
-       ret = device_create_file(&dock_device->dev, &dev_attr_uid);
-       if (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);
-               kfree(dock_station);
-               dock_station = NULL;
-               return ret;
-       }
-       ret = device_create_file(&dock_device->dev, &dev_attr_flags);
-       if (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);
-               platform_device_unregister(dock_device);
-               kfree(dock_station);
-               dock_station = NULL;
-               return ret;
-       }
-       ret = device_create_file(&dock_device->dev, &dev_attr_type);
+       ret = sysfs_create_group(&dock_device->dev.kobj, &dock_attribute_group);
        if (ret)
-               printk(KERN_ERR"Error %d adding sysfs file\n", ret);
+               goto err_unregister;
 
        /* Find dependent devices */
        acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
@@ -1034,28 +981,19 @@ static int dock_add(acpi_handle handle)
                            NULL);
 
        /* add the dock station as a device dependent on itself */
-       dd = alloc_dock_dependent_device(handle);
-       if (!dd) {
-               kfree(dock_station);
-               dock_station = NULL;
-               ret = -ENOMEM;
-               goto dock_add_err_unregister;
-       }
-       add_dock_dependent_device(dock_station, dd);
+       ret = add_dock_dependent_device(dock_station, handle);
+       if (ret)
+               goto err_rmgroup;
 
        dock_station_count++;
        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);
-       device_remove_file(&dock_device->dev, &dev_attr_flags);
+err_rmgroup:
+       sysfs_remove_group(&dock_device->dev.kobj, &dock_attribute_group);
+err_unregister:
        platform_device_unregister(dock_device);
-       kfree(dock_station);
-       dock_station = NULL;
+       printk(KERN_ERR "%s encountered error %d\n", __func__, ret);
        return ret;
 }
 
@@ -1075,17 +1013,12 @@ static int dock_remove(struct dock_station *dock_station)
                                 list)
            kfree(dd);
 
+       list_del(&dock_station->sibling);
+
        /* 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);
-       device_remove_file(&dock_device->dev, &dev_attr_flags);
+       sysfs_remove_group(&dock_device->dev.kobj, &dock_attribute_group);
        platform_device_unregister(dock_device);
 
-       /* free dock station memory */
-       kfree(dock_station);
-       dock_station = NULL;
        return 0;
 }