From 671adbec210efc15cef81b4616adae8bcd667296 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Mon, 4 Dec 2006 14:49:43 -0800 Subject: ACPI: dock: Make the dock station driver a platform device driver. Make the dock station driver a platform device driver so that we can create sysfs entries under /sys/device/platform. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index bf5b79ed3613..336d94cdf2a0 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,8 @@ MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME); MODULE_LICENSE("GPL"); static struct atomic_notifier_head dock_notifier_list; +static struct platform_device dock_device; +static char dock_device_name[] = "dock"; struct dock_station { acpi_handle handle; @@ -629,6 +632,15 @@ static int dock_add(acpi_handle handle) spin_lock_init(&dock_station->hp_lock); ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); + /* initialize platform device stuff */ + dock_device.name = dock_device_name; + ret = platform_device_register(&dock_device); + if (ret) { + printk(KERN_ERR PREFIX "Error registering dock device\n", ret); + kfree(dock_station); + return ret; + } + /* Find dependent devices */ acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, find_dock_devices, dock_station, @@ -638,7 +650,8 @@ static int dock_add(acpi_handle handle) dd = alloc_dock_dependent_device(handle); if (!dd) { kfree(dock_station); - return -ENOMEM; + ret = -ENOMEM; + goto dock_add_err_unregister; } add_dock_dependent_device(dock_station, dd); @@ -658,8 +671,10 @@ static int dock_add(acpi_handle handle) return 0; dock_add_err: - kfree(dock_station); kfree(dd); +dock_add_err_unregister: + platform_device_unregister(&dock_device); + kfree(dock_station); return ret; } @@ -686,6 +701,9 @@ static int dock_remove(void) if (ACPI_FAILURE(status)) printk(KERN_ERR "Error removing notify handler\n"); + /* cleanup sysfs */ + platform_device_unregister(&dock_device); + /* free dock station memory */ kfree(dock_station); return 0; -- cgit v1.2.3 From e67beb37df7a9da9d5d1e59c5358654d007a97c5 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Thu, 7 Dec 2006 04:17:35 -0500 Subject: ACPI: dock: fix build warning drivers/acpi/dock.c:689: warning: too many arguments for format Signed-off-by: Len Brown --- drivers/acpi/dock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 336d94cdf2a0..2c2f28db9fb2 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -636,7 +636,7 @@ static int dock_add(acpi_handle handle) dock_device.name = dock_device_name; ret = platform_device_register(&dock_device); if (ret) { - printk(KERN_ERR PREFIX "Error registering dock device\n", ret); + printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret); kfree(dock_station); return ret; } -- cgit v1.2.3 From c80fdbe81a617c82e2f95233f8ddcf046ffe21b3 Mon Sep 17 00:00:00 2001 From: "brandon@ifup.org" Date: Mon, 4 Dec 2006 14:49:58 -0800 Subject: ACPI: dock: Add a docked sysfs file to the dock driver. Add 2 sysfs files for user interface. 1) docked - 1/0 (read only) - indicates whether the software believes the laptop is docked in a docking station. 2) undock - (write only) - writing to this file causes the software to initiate an undock request to the firmware. Signed-off-by: Brandon Philips Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 95 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 16 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 2c2f28db9fb2..e4c1a4ff4e31 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -514,6 +514,37 @@ void unregister_hotplug_dock_device(acpi_handle handle) EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); +/** + * handle_eject_request - handle an undock request checking for error conditions + * + * Check to make sure the dock device is still present, then undock and + * hotremove all the devices that may need removing. + */ +static int handle_eject_request(struct dock_station *ds, u32 event) +{ + if (!dock_present(ds)) + return -ENODEV; + + if (dock_in_progress(ds)) + return -EBUSY; + + /* + * here we need to generate the undock + * event prior to actually doing the undock + * so that the device struct still exists. + */ + dock_event(ds, event, UNDOCK_EVENT); + hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST); + undock(ds); + eject_dock(ds); + if (dock_present(ds)) { + printk(KERN_ERR PREFIX "Unable to undock!\n"); + return -EBUSY; + } + + return 0; +} + /** * dock_notify - act upon an acpi dock notification * @handle: the dock station handle @@ -522,9 +553,7 @@ EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); * * If we are notified to dock, then check to see if the dock is * present and then dock. Notify all drivers of the dock event, - * and then hotplug and devices that may need hotplugging. For undock - * check to make sure the dock device is still present, then undock - * and hotremove all the devices that may need removing. + * and then hotplug and devices that may need hotplugging. */ static void dock_notify(acpi_handle handle, u32 event, void *data) { @@ -556,19 +585,7 @@ static void dock_notify(acpi_handle handle, u32 event, void *data) * to the driver who wish to hotplug. */ case ACPI_NOTIFY_EJECT_REQUEST: - if (!dock_in_progress(ds) && dock_present(ds)) { - /* - * here we need to generate the undock - * event prior to actually doing the undock - * so that the device struct still exists. - */ - dock_event(ds, event, UNDOCK_EVENT); - hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST); - undock(ds); - eject_dock(ds); - if (dock_present(ds)) - printk(KERN_ERR PREFIX "Unable to undock!\n"); - } + handle_eject_request(ds, event); break; default: printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); @@ -607,6 +624,33 @@ find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv) return AE_OK; } +/* + * show_docked - read method for "docked" file in sysfs + */ +static ssize_t show_docked(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station)); + +} +DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); + +/* + * write_undock - write method for "undock" file in sysfs + */ +static ssize_t write_undock(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + + if (!count) + return -EINVAL; + + ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST); + return ret ? ret: count; +} +DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); + /** * dock_add - add a new dock station * @handle: the dock station handle @@ -640,6 +684,21 @@ static int dock_add(acpi_handle handle) kfree(dock_station); return ret; } + ret = device_create_file(&dock_device.dev, &dev_attr_docked); + if (ret) { + printk("Error %d adding sysfs file\n", ret); + platform_device_unregister(&dock_device); + kfree(dock_station); + return ret; + } + ret = device_create_file(&dock_device.dev, &dev_attr_undock); + if (ret) { + printk("Error %d adding sysfs file\n", ret); + device_remove_file(&dock_device.dev, &dev_attr_docked); + platform_device_unregister(&dock_device); + kfree(dock_station); + return ret; + } /* Find dependent devices */ acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, @@ -673,6 +732,8 @@ static int dock_add(acpi_handle handle) dock_add_err: kfree(dd); dock_add_err_unregister: + 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); return ret; @@ -702,6 +763,8 @@ static int dock_remove(void) printk(KERN_ERR "Error removing notify handler\n"); /* cleanup sysfs */ + device_remove_file(&dock_device.dev, &dev_attr_docked); + device_remove_file(&dock_device.dev, &dev_attr_undock); platform_device_unregister(&dock_device); /* free dock station memory */ -- cgit v1.2.3 From 2548c06b72396e28abdb5dd572ab589c3c22f4b9 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Mon, 4 Dec 2006 14:50:17 -0800 Subject: ACPI: dock: Fix symbol conflict between acpiphp and dock Fix bug which will cause acpiphp to not be able to load when dock.ko cannot load. Signed-off-by: Prarit Bhargava Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index e4c1a4ff4e31..8c6828bee5d9 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -444,6 +444,9 @@ static int dock_in_progress(struct dock_station *ds) */ int register_dock_notifier(struct notifier_block *nb) { + if (!dock_station) + return -ENODEV; + return atomic_notifier_chain_register(&dock_notifier_list, nb); } @@ -455,6 +458,9 @@ EXPORT_SYMBOL_GPL(register_dock_notifier); */ void unregister_dock_notifier(struct notifier_block *nb) { + if (!dock_station) + return; + atomic_notifier_chain_unregister(&dock_notifier_list, nb); } @@ -807,7 +813,7 @@ static int __init dock_init(void) ACPI_UINT32_MAX, find_dock, &num, NULL); if (!num) - return -ENODEV; + printk(KERN_INFO "No dock devices found.\n"); return 0; } -- cgit v1.2.3 From 8ea86e0ba7c9d16ae0f35cb0c4165194fa573f7a Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Mon, 11 Dec 2006 12:05:08 -0800 Subject: ACPI: dock: add uevent to indicate change in device status Send a uevent to indicate a device change whenever we dock or undock, so that userspace may now check the dock status via sysfs. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Holger Macht Signed-off-by: Len Brown --- drivers/acpi/dock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/acpi') diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 8c6828bee5d9..215f5b30a1f1 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -326,10 +326,12 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event) static void dock_event(struct dock_station *ds, u32 event, int num) { + struct device *dev = &dock_device.dev; /* - * we don't do events until someone tells me that - * they would like to have them. + * Indicate that the status of the dock station has + * changed. */ + kobject_uevent(&dev->kobj, KOBJ_CHANGE); } /** -- cgit v1.2.3