ACPI: Add a docked sysfs file to the dock driver. Warning: Compile tested only Signed-off-by: Brandon Philips --- drivers/acpi/dock.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) Index: linux-2.6-rc/drivers/acpi/dock.c =================================================================== --- linux-2.6-rc.orig/drivers/acpi/dock.c +++ linux-2.6-rc/drivers/acpi/dock.c @@ -603,6 +603,36 @@ find_dock_devices(acpi_handle handle, u3 return AE_OK; } +#define ACPI_DEVICE_ATTR(_name,_mode,_show,_store) \ +static struct acpi_device_attribute acpi_device_attr_##_name = \ + __ATTR(_name, _mode, _show, _store) +/* + * show_docked - read method for "docked" file in sysfs + */ +static ssize_t show_docked(struct acpi_device *dev, char *buf) +{ + struct dock_station *ds = (struct dock_station *)dev->driver_data; + return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(ds)); + +} +ACPI_DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); + +static void dock_remove_sysfs_files(struct acpi_device *ad) +{ + sysfs_remove_file(&ad->kobj, &acpi_device_attr_docked.attr); +} + +static int dock_add_sysfs_files(struct acpi_device *ad) +{ + int ret; + + ret = sysfs_create_file(&ad->kobj, &acpi_device_attr_docked.attr); + if (ret) + dock_remove_sysfs_files(ad);; + + return ret; +} + /** * dock_add - add a new dock station * @handle: the dock station handle @@ -615,6 +645,7 @@ static int dock_add(acpi_handle handle) int ret; acpi_status status; struct dock_dependent_device *dd; + struct acpi_device *ad; /* allocate & initialize the dock_station private data */ dock_station = kzalloc(sizeof(*dock_station), GFP_KERNEL); @@ -652,6 +683,14 @@ static int dock_add(acpi_handle handle) goto dock_add_err; } + if ((ret = acpi_bus_get_device(handle, &ad))) + goto dock_add_err; + + ad->driver_data = (void *)dock_station; + + if (dock_add_sysfs_files(ad)) + printk(KERN_ERR PREFIX "Unable to create sysfs files\n"); + printk(KERN_INFO PREFIX "%s \n", ACPI_DOCK_DRIVER_NAME); return 0; @@ -669,6 +708,8 @@ static int dock_remove(void) { struct dock_dependent_device *dd, *tmp; acpi_status status; + struct acpi_device *ad; + int ret; if (!dock_station) return 0; @@ -685,6 +726,15 @@ static int dock_remove(void) if (ACPI_FAILURE(status)) printk(KERN_ERR "Error removing notify handler\n"); + ret = acpi_bus_get_device(dock_station->handle, &ad); + if (ret < 0) { + printk(KERN_ERR "Error getting docking station\n"); + goto error; + } + + dock_remove_sysfs_files(ad); + +error: /* free dock station memory */ kfree(dock_station); return 0;