From fe9a2f77e5ad508b18671571c0b3f6f79ea709a8 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Fri, 2 Feb 2007 22:33:00 -0500 Subject: ACPI: dock: check if parent is on dock When determining if a device is on a dock station, we should check the parent of the device as well. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 90990a4b6526..688e83a16906 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -615,20 +615,28 @@ static acpi_status find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv) { acpi_status status; - acpi_handle tmp; + 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)) - return AE_OK; + if (ACPI_FAILURE(status)) { + /* try the parent device as well */ + status = acpi_get_parent(handle, &parent); + if (ACPI_FAILURE(status)) + goto fdd_out; + /* see if parent is dependent on dock */ + status = acpi_bus_get_ejd(parent, &tmp); + if (ACPI_FAILURE(status)) + goto fdd_out; + } if (tmp == ds->handle) { dd = alloc_dock_dependent_device(handle); if (dd) add_dock_dependent_device(ds, dd); } - +fdd_out: return AE_OK; } -- cgit v1.2.3 From 01b57e73728880b787c85e27ad06c249412813b1 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Fri, 20 Oct 2006 14:30:25 -0700 Subject: ACPI: bay: new driver adding removable drive bay support Signed-off-by: Kristen Carlson Accardi Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/Kconfig | 7 + drivers/acpi/Makefile | 3 +- drivers/acpi/bay.c | 592 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 601 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/bay.c diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index f4f000abc4e9..2caef098379e 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -139,6 +139,13 @@ config ACPI_DOCK help This driver adds support for ACPI controlled docking stations +config ACPI_BAY + tristate "Removable Drive Bay" + depends on EXPERIMENTAL + help + This driver adds support for ACPI controlled removable drive + bays such as the IBM ultrabay or the Dell Module Bay. + config ACPI_PROCESSOR tristate "Processor" default y diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index bce7ca27b429..1a738056558f 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -43,7 +43,8 @@ obj-$(CONFIG_ACPI_BUTTON) += button.o obj-$(CONFIG_ACPI_EC) += ec.o obj-$(CONFIG_ACPI_FAN) += fan.o obj-$(CONFIG_ACPI_DOCK) += dock.o -obj-$(CONFIG_ACPI_VIDEO) += video.o +obj-$(CONFIG_ACPI_BAY) += bay.o +obj-$(CONFIG_ACPI_VIDEO) += video.o obj-$(CONFIG_ACPI_HOTKEY) += hotkey.o obj-y += pci_root.o pci_link.o pci_irq.o pci_bind.o obj-$(CONFIG_ACPI_POWER) += power.o diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c new file mode 100644 index 000000000000..1cfc0b74b58c --- /dev/null +++ b/drivers/acpi/bay.c @@ -0,0 +1,592 @@ +/* + * bay.c - ACPI removable drive bay driver + * + * Copyright (C) 2006 Kristen Carlson Accardi + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver" + +ACPI_MODULE_NAME("bay") +MODULE_AUTHOR("Kristen Carlson Accardi"); +MODULE_DESCRIPTION(ACPI_BAY_DRIVER_NAME); +MODULE_LICENSE("GPL"); +#define ACPI_BAY_CLASS "bay" +#define ACPI_BAY_COMPONENT 0x10000000 +#define _COMPONENT ACPI_BAY_COMPONENT +#define bay_dprintk(h,s) {\ + char prefix[80] = {'\0'};\ + struct acpi_buffer buffer = {sizeof(prefix), prefix};\ + acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\ + printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); } + +static void bay_notify(acpi_handle handle, u32 event, void *data); +static int acpi_bay_add(struct acpi_device *device); +static int acpi_bay_remove(struct acpi_device *device, int type); +static int acpi_bay_match(struct acpi_device *device, + struct acpi_driver *driver); + +static struct acpi_driver acpi_bay_driver = { + .name = ACPI_BAY_DRIVER_NAME, + .class = ACPI_BAY_CLASS, + .ops = { + .add = acpi_bay_add, + .remove = acpi_bay_remove, + .match = acpi_bay_match, + }, +}; + +struct bay { + acpi_handle handle; + char *name; + struct list_head list; + struct proc_dir_entry *proc; +}; + +LIST_HEAD(drive_bays); + +static struct proc_dir_entry *acpi_bay_dir; + +/***************************************************************************** + * Drive Bay functions * + *****************************************************************************/ +/** + * is_ejectable - see if a device is ejectable + * @handle: acpi handle of the device + * + * If an acpi object has a _EJ0 method, then it is ejectable + */ +static int is_ejectable(acpi_handle handle) +{ + acpi_status status; + acpi_handle tmp; + + status = acpi_get_handle(handle, "_EJ0", &tmp); + if (ACPI_FAILURE(status)) + return 0; + return 1; +} + +/** + * bay_present - see if the bay device is present + * @bay: the drive bay + * + * execute the _STA method. + */ +static int bay_present(struct bay *bay) +{ + unsigned long sta; + acpi_status status; + + if (bay) { + status = acpi_evaluate_integer(bay->handle, "_STA", NULL, &sta); + if (ACPI_SUCCESS(status) && sta) + return 1; + } + return 0; +} + +/** + * eject_device - respond to an eject request + * @handle - the device to eject + * + * Call this devices _EJ0 method. + */ +static void eject_device(acpi_handle handle) +{ + struct acpi_object_list arg_list; + union acpi_object arg; + + bay_dprintk(handle, "Ejecting device"); + + arg_list.count = 1; + arg_list.pointer = &arg; + arg.type = ACPI_TYPE_INTEGER; + arg.integer.value = 1; + + if (ACPI_FAILURE(acpi_evaluate_object(handle, "_EJ0", + &arg_list, NULL))) + pr_debug("Failed to evaluate _EJ0!\n"); +} + + +/** + * is_ata - see if a device is an ata device + * @handle: acpi handle of the device + * + * If an acpi object has one of 4 ATA ACPI methods defined, + * then it is an ATA device + */ +static int is_ata(acpi_handle handle) +{ + acpi_handle tmp; + + if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) || + (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) || + (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) || + (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp)))) + return 1; + + return 0; +} + +/** + * parent_is_ata(acpi_handle handle) + * + */ +static int parent_is_ata(acpi_handle handle) +{ + acpi_handle phandle; + + if (acpi_get_parent(handle, &phandle)) + return 0; + + return is_ata(phandle); +} + +/** + * is_ejectable_bay - see if a device is an ejectable drive bay + * @handle: acpi handle of the device + * + * If an acpi object is ejectable and has one of the ACPI ATA + * methods defined, then we can safely call it an ejectable + * drive bay + */ +static int is_ejectable_bay(acpi_handle handle) +{ + if ((is_ata(handle) || parent_is_ata(handle)) && is_ejectable(handle)) + return 1; + return 0; +} + +/** + * eject_removable_drive - try to eject this drive + * @dev : the device structure of the drive + * + * If a device is a removable drive that requires an _EJ0 method + * to be executed in order to safely remove from the system, do + * it. ATM - always returns success + */ +int eject_removable_drive(struct device *dev) +{ + acpi_handle handle = DEVICE_ACPI_HANDLE(dev); + + if (handle) { + bay_dprintk(handle, "Got device handle"); + if (is_ejectable_bay(handle)) + eject_device(handle); + } else { + printk("No acpi handle for device\n"); + } + + /* should I return an error code? */ + return 0; +} +EXPORT_SYMBOL_GPL(eject_removable_drive); + +static int acpi_bay_add(struct acpi_device *device) +{ + bay_dprintk(device->handle, "adding bay device"); + strcpy(acpi_device_name(device), "Dockable Bay"); + strcpy(acpi_device_class(device), "bay"); + return 0; +} + +static int acpi_bay_status_seq_show(struct seq_file *seq, void *offset) +{ + struct bay *bay = (struct bay *)seq->private; + + if (!bay) + return 0; + + if (bay_present(bay)) + seq_printf(seq, "present\n"); + else + seq_printf(seq, "removed\n"); + + return 0; +} + +static ssize_t +acpi_bay_write_eject(struct file *file, + const char __user * buffer, + size_t count, loff_t * data) +{ + struct seq_file *m = (struct seq_file *)file->private_data; + struct bay *bay = (struct bay *)m->private; + char str[12] = { 0 }; + u32 state = 0; + + /* FIXME - our only valid value here is 1 */ + if (!bay || count + 1 > sizeof str) + return -EINVAL; + + if (copy_from_user(str, buffer, count)) + return -EFAULT; + + str[count] = 0; + state = simple_strtoul(str, NULL, 0); + if (state) + eject_device(bay->handle); + + return count; +} + +static int +acpi_bay_status_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_bay_status_seq_show, + PDE(inode)->data); +} + +static int +acpi_bay_eject_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_bay_status_seq_show, + PDE(inode)->data); +} + +static struct file_operations acpi_bay_status_fops = { + .open = acpi_bay_status_open_fs, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static struct file_operations acpi_bay_eject_fops = { + .open = acpi_bay_eject_open_fs, + .read = seq_read, + .write = acpi_bay_write_eject, + .llseek = seq_lseek, + .release = single_release, +}; +#if 0 +static struct file_operations acpi_bay_insert_fops = { + .open = acpi_bay_insert_open_fs, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif +static int acpi_bay_add_fs(struct bay *bay) +{ + struct proc_dir_entry *entry = NULL; + + if (!bay) + return -EINVAL; + + /* + * create a proc entry for this device + * we need to do this a little bit differently than normal + * acpi device drivers because our device may not be present + * at the moment, and therefore we have no acpi_device struct + */ + + bay->proc = proc_mkdir(bay->name, acpi_bay_dir); + + /* 'status' [R] */ + entry = create_proc_entry("status", + S_IRUGO, bay->proc); + if (!entry) + return -EIO; + else { + entry->proc_fops = &acpi_bay_status_fops; + entry->data = bay; + entry->owner = THIS_MODULE; + } + /* 'eject' [W] */ + entry = create_proc_entry("eject", + S_IWUGO, bay->proc); + if (!entry) + return -EIO; + else { + entry->proc_fops = &acpi_bay_eject_fops; + entry->data = bay; + entry->owner = THIS_MODULE; + } +#if 0 + /* 'insert' [W] */ + entry = create_proc_entry("insert", + S_IWUGO, bay->proc); + if (!entry) + return -EIO; + else { + entry->proc_fops = &acpi_bay_insert_fops; + entry->data = bay; + entry->owner = THIS_MODULE; + } +#endif + return 0; +} + +static void acpi_bay_remove_fs(struct bay *bay) +{ + if (!bay) + return; + + if (bay->proc) { + remove_proc_entry("status", bay->proc); + remove_proc_entry("eject", bay->proc); +#if 0 + remove_proc_entry("insert", bay->proc); +#endif + remove_proc_entry(bay->name, acpi_bay_dir); + bay->proc = NULL; + } +} + +static int bay_is_dock_device(acpi_handle handle) +{ + acpi_handle parent; + + acpi_get_parent(handle, &parent); + + /* if the device or it's parent is dependent on the + * dock, then we are a dock device + */ + return (is_dock_device(handle) || is_dock_device(parent)); +} + +static int bay_add(acpi_handle handle) +{ + acpi_status status; + struct bay *new_bay; + struct acpi_buffer nbuffer = {ACPI_ALLOCATE_BUFFER, NULL}; + acpi_get_name(handle, ACPI_FULL_PATHNAME, &nbuffer); + + bay_dprintk(handle, "Adding notify handler"); + + /* + * if this is the first bay device found, make the root + * proc entry + */ + if (acpi_bay_dir == NULL) + acpi_bay_dir = proc_mkdir(ACPI_BAY_CLASS, acpi_root_dir); + + /* + * Initialize bay device structure + */ + new_bay = kmalloc(GFP_ATOMIC, sizeof(*new_bay)); + INIT_LIST_HEAD(&new_bay->list); + new_bay->handle = handle; + new_bay->name = (char *)nbuffer.pointer; + list_add(&new_bay->list, &drive_bays); + acpi_bay_add_fs(new_bay); + + /* register for events on this device */ + status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + bay_notify, new_bay); + if (ACPI_FAILURE(status)) { + printk(KERN_ERR PREFIX "Error installing bay notify handler\n"); + } + + /* if we are on a dock station, we should register for dock + * notifications. + */ + if (bay_is_dock_device(handle)) { + bay_dprintk(handle, "Is dependent on dock\n"); + register_hotplug_dock_device(handle, bay_notify, new_bay); + } + printk(KERN_INFO PREFIX "Bay [%s] Added\n", new_bay->name); + return 0; +} + +static int acpi_bay_remove(struct acpi_device *device, int type) +{ + /*** FIXME: do something here */ + return 0; +} + +static int acpi_bay_match(struct acpi_device *device, + struct acpi_driver *driver) +{ + if (!device || !driver) + return -EINVAL; + + if (is_ejectable_bay(device->handle)) { + bay_dprintk(device->handle, "matching bay device"); + return 0; + } + + return -ENODEV; +} + +/** + * bay_create_acpi_device - add new devices to acpi + * @handle - handle of the device to add + * + * This function will create a new acpi_device for the given + * handle if one does not exist already. This should cause + * acpi to scan for drivers for the given devices, and call + * matching driver's add routine. + * + * Returns a pointer to the acpi_device corresponding to the handle. + */ +static struct acpi_device * bay_create_acpi_device(acpi_handle handle) +{ + struct acpi_device *device = NULL; + struct acpi_device *parent_device; + acpi_handle parent; + int ret; + + bay_dprintk(handle, "Trying to get device"); + if (acpi_bus_get_device(handle, &device)) { + /* + * no device created for this object, + * so we should create one. + */ + bay_dprintk(handle, "No device for handle"); + acpi_get_parent(handle, &parent); + if (acpi_bus_get_device(parent, &parent_device)) + parent_device = NULL; + + ret = acpi_bus_add(&device, parent_device, handle, + ACPI_BUS_TYPE_DEVICE); + if (ret) { + pr_debug("error adding bus, %x\n", + -ret); + return NULL; + } + } + return device; +} + +/** + * bay_notify - act upon an acpi bay notification + * @handle: the bay handle + * @event: the acpi event + * @data: our driver data struct + * + */ +static void bay_notify(acpi_handle handle, u32 event, void *data) +{ + struct acpi_device *dev; + struct bay *bay = data; + + bay_dprintk(handle, "Bay event"); + + switch(event) { + case ACPI_NOTIFY_BUS_CHECK: + printk("Bus Check\n"); + case ACPI_NOTIFY_DEVICE_CHECK: + printk("Device Check\n"); + dev = bay_create_acpi_device(handle); + if (dev) + acpi_bus_generate_event(dev, event, 0); + else + printk("No device for generating event\n"); + /* wouldn't it be a good idea to just rescan SATA + * right here? + */ + break; + case ACPI_NOTIFY_EJECT_REQUEST: + printk("Eject request\n"); + dev = bay_create_acpi_device(handle); + if (dev) + acpi_bus_generate_event(dev, event, 0); + else + printk("No device for generating eventn"); + + /* wouldn't it be a good idea to just call the + * eject_device here if we were a SATA device? + */ + break; + default: + printk("unknown event %d\n", event); + } +} + +static acpi_status +find_bay(acpi_handle handle, u32 lvl, void *context, void **rv) +{ + int *count = (int *)context; + + /* + * there could be more than one ejectable bay. + * so, just return AE_OK always so that every object + * will be checked. + */ + if (is_ejectable_bay(handle)) { + bay_dprintk(handle, "found ejectable bay"); + bay_add(handle); + (*count)++; + } + return AE_OK; +} + +static int __init bay_init(void) +{ + int bays = 0; + + acpi_bay_dir = NULL; + INIT_LIST_HEAD(&drive_bays); + + /* look for dockable drive bays */ + acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, find_bay, &bays, NULL); + + if (bays) { + if ((acpi_bus_register_driver(&acpi_bay_driver) < 0)) { + printk(KERN_ERR "Unable to register bay driver\n"); + if (acpi_bay_dir) + remove_proc_entry(ACPI_BAY_CLASS, + acpi_root_dir); + } + } + + if (!bays) + return -ENODEV; + + return 0; +} + +static void __exit bay_exit(void) +{ + struct bay *bay, *tmp; + + list_for_each_entry_safe(bay, tmp, &drive_bays, list) { + if (is_dock_device(bay->handle)) + unregister_hotplug_dock_device(bay->handle); + acpi_bay_remove_fs(bay); + acpi_remove_notify_handler(bay->handle, ACPI_SYSTEM_NOTIFY, + bay_notify); + kfree(bay->name); + kfree(bay); + } + + if (acpi_bay_dir) + remove_proc_entry(ACPI_BAY_CLASS, acpi_root_dir); + + acpi_bus_unregister_driver(&acpi_bay_driver); +} + +postcore_initcall(bay_init); +module_exit(bay_exit); + -- cgit v1.2.3 From 5447cbb278fd01c402180ab1e820b95101e782fa Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 21 Oct 2006 01:15:41 -0400 Subject: ACPI: bay: delete unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit drivers/acpi/bay.c: In function ‘bay_notify’: drivers/acpi/bay.c:491: warning: unused variable ‘bay’ Signed-off-by: Len Brown --- drivers/acpi/bay.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index 1cfc0b74b58c..412590d48011 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c @@ -488,7 +488,6 @@ static struct acpi_device * bay_create_acpi_device(acpi_handle handle) static void bay_notify(acpi_handle handle, u32 event, void *data) { struct acpi_device *dev; - struct bay *bay = data; bay_dprintk(handle, "Bay event"); -- cgit v1.2.3 From e9dd85e5bdff2a3981dfaa55869ba920e985ea8a Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Mon, 18 Dec 2006 18:06:00 -0500 Subject: ACPI: bay: remove prototype procfs code Remove all the procfs related code. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/bay.c | 154 +---------------------------------------------------- 1 file changed, 2 insertions(+), 152 deletions(-) diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index 412590d48011..0c0a6204d167 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -67,12 +66,10 @@ struct bay { acpi_handle handle; char *name; struct list_head list; - struct proc_dir_entry *proc; }; LIST_HEAD(drive_bays); -static struct proc_dir_entry *acpi_bay_dir; /***************************************************************************** * Drive Bay functions * @@ -219,147 +216,16 @@ static int acpi_bay_add(struct acpi_device *device) return 0; } -static int acpi_bay_status_seq_show(struct seq_file *seq, void *offset) -{ - struct bay *bay = (struct bay *)seq->private; - - if (!bay) - return 0; - - if (bay_present(bay)) - seq_printf(seq, "present\n"); - else - seq_printf(seq, "removed\n"); - - return 0; -} - -static ssize_t -acpi_bay_write_eject(struct file *file, - const char __user * buffer, - size_t count, loff_t * data) -{ - struct seq_file *m = (struct seq_file *)file->private_data; - struct bay *bay = (struct bay *)m->private; - char str[12] = { 0 }; - u32 state = 0; - - /* FIXME - our only valid value here is 1 */ - if (!bay || count + 1 > sizeof str) - return -EINVAL; - - if (copy_from_user(str, buffer, count)) - return -EFAULT; - - str[count] = 0; - state = simple_strtoul(str, NULL, 0); - if (state) - eject_device(bay->handle); - - return count; -} - -static int -acpi_bay_status_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_bay_status_seq_show, - PDE(inode)->data); -} - -static int -acpi_bay_eject_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_bay_status_seq_show, - PDE(inode)->data); -} - -static struct file_operations acpi_bay_status_fops = { - .open = acpi_bay_status_open_fs, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - -static struct file_operations acpi_bay_eject_fops = { - .open = acpi_bay_eject_open_fs, - .read = seq_read, - .write = acpi_bay_write_eject, - .llseek = seq_lseek, - .release = single_release, -}; -#if 0 -static struct file_operations acpi_bay_insert_fops = { - .open = acpi_bay_insert_open_fs, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; -#endif static int acpi_bay_add_fs(struct bay *bay) { - struct proc_dir_entry *entry = NULL; - if (!bay) return -EINVAL; - - /* - * create a proc entry for this device - * we need to do this a little bit differently than normal - * acpi device drivers because our device may not be present - * at the moment, and therefore we have no acpi_device struct - */ - - bay->proc = proc_mkdir(bay->name, acpi_bay_dir); - - /* 'status' [R] */ - entry = create_proc_entry("status", - S_IRUGO, bay->proc); - if (!entry) - return -EIO; - else { - entry->proc_fops = &acpi_bay_status_fops; - entry->data = bay; - entry->owner = THIS_MODULE; - } - /* 'eject' [W] */ - entry = create_proc_entry("eject", - S_IWUGO, bay->proc); - if (!entry) - return -EIO; - else { - entry->proc_fops = &acpi_bay_eject_fops; - entry->data = bay; - entry->owner = THIS_MODULE; - } -#if 0 - /* 'insert' [W] */ - entry = create_proc_entry("insert", - S_IWUGO, bay->proc); - if (!entry) - return -EIO; - else { - entry->proc_fops = &acpi_bay_insert_fops; - entry->data = bay; - entry->owner = THIS_MODULE; - } -#endif - return 0; } static void acpi_bay_remove_fs(struct bay *bay) { if (!bay) return; - - if (bay->proc) { - remove_proc_entry("status", bay->proc); - remove_proc_entry("eject", bay->proc); -#if 0 - remove_proc_entry("insert", bay->proc); -#endif - remove_proc_entry(bay->name, acpi_bay_dir); - bay->proc = NULL; - } } static int bay_is_dock_device(acpi_handle handle) @@ -383,13 +249,6 @@ static int bay_add(acpi_handle handle) bay_dprintk(handle, "Adding notify handler"); - /* - * if this is the first bay device found, make the root - * proc entry - */ - if (acpi_bay_dir == NULL) - acpi_bay_dir = proc_mkdir(ACPI_BAY_CLASS, acpi_root_dir); - /* * Initialize bay device structure */ @@ -544,21 +403,15 @@ static int __init bay_init(void) { int bays = 0; - acpi_bay_dir = NULL; INIT_LIST_HEAD(&drive_bays); /* look for dockable drive bays */ acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, find_bay, &bays, NULL); - if (bays) { - if ((acpi_bus_register_driver(&acpi_bay_driver) < 0)) { + if (bays) + if ((acpi_bus_register_driver(&acpi_bay_driver) < 0)) printk(KERN_ERR "Unable to register bay driver\n"); - if (acpi_bay_dir) - remove_proc_entry(ACPI_BAY_CLASS, - acpi_root_dir); - } - } if (!bays) return -ENODEV; @@ -580,9 +433,6 @@ static void __exit bay_exit(void) kfree(bay); } - if (acpi_bay_dir) - remove_proc_entry(ACPI_BAY_CLASS, acpi_root_dir); - acpi_bus_unregister_driver(&acpi_bay_driver); } -- cgit v1.2.3 From 2b167c01190b647c976e7fab312f2e3d3b3a785f Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Mon, 18 Dec 2006 18:07:00 -0500 Subject: ACPI: bay: make bay a platform driver Convert the bay driver to be a platform driver, so that we can have sysfs entries. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/bay.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index 0c0a6204d167..3f0ae7d341e7 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c @@ -30,6 +30,7 @@ #include #include #include +#include #define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver" @@ -45,7 +46,6 @@ MODULE_LICENSE("GPL"); struct acpi_buffer buffer = {sizeof(prefix), prefix};\ acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\ printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); } - static void bay_notify(acpi_handle handle, u32 event, void *data); static int acpi_bay_add(struct acpi_device *device); static int acpi_bay_remove(struct acpi_device *device, int type); @@ -66,6 +66,7 @@ struct bay { acpi_handle handle; char *name; struct list_head list; + struct platform_device *pdev; }; LIST_HEAD(drive_bays); @@ -133,6 +134,33 @@ static void eject_device(acpi_handle handle) pr_debug("Failed to evaluate _EJ0!\n"); } +/* + * show_present - read method for "present" file in sysfs + */ +static ssize_t show_present(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct bay *bay = dev_get_drvdata(dev); + return snprintf(buf, PAGE_SIZE, "%d\n", bay_present(bay)); + +} +DEVICE_ATTR(present, S_IRUGO, show_present, NULL); + +/* + * write_eject - write method for "eject" file in sysfs + */ +static ssize_t write_eject(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct bay *bay = dev_get_drvdata(dev); + + if (!count) + return -EINVAL; + + eject_device(bay->handle); + return count; +} +DEVICE_ATTR(eject, S_IWUSR, NULL, write_eject); /** * is_ata - see if a device is an ata device @@ -218,14 +246,31 @@ static int acpi_bay_add(struct acpi_device *device) static int acpi_bay_add_fs(struct bay *bay) { - if (!bay) - return -EINVAL; + int ret; + struct device *dev = &bay->pdev->dev; + + ret = device_create_file(dev, &dev_attr_present); + if (ret) + goto add_fs_err; + ret = device_create_file(dev, &dev_attr_eject); + if (ret) { + device_remove_file(dev, &dev_attr_present); + goto add_fs_err; + } + return 0; + + add_fs_err: + bay_dprintk(bay->handle, "Error adding sysfs files\n"); + return ret; } static void acpi_bay_remove_fs(struct bay *bay) { - if (!bay) - return; + struct device *dev = &bay->pdev->dev; + + /* cleanup sysfs */ + device_remove_file(dev, &dev_attr_present); + device_remove_file(dev, &dev_attr_eject); } static int bay_is_dock_device(acpi_handle handle) @@ -240,10 +285,11 @@ static int bay_is_dock_device(acpi_handle handle) return (is_dock_device(handle) || is_dock_device(parent)); } -static int bay_add(acpi_handle handle) +static int bay_add(acpi_handle handle, int id) { acpi_status status; struct bay *new_bay; + struct platform_device *pdev; struct acpi_buffer nbuffer = {ACPI_ALLOCATE_BUFFER, NULL}; acpi_get_name(handle, ACPI_FULL_PATHNAME, &nbuffer); @@ -252,12 +298,24 @@ static int bay_add(acpi_handle handle) /* * Initialize bay device structure */ - new_bay = kmalloc(GFP_ATOMIC, sizeof(*new_bay)); + new_bay = kzalloc(GFP_ATOMIC, sizeof(*new_bay)); INIT_LIST_HEAD(&new_bay->list); new_bay->handle = handle; new_bay->name = (char *)nbuffer.pointer; - list_add(&new_bay->list, &drive_bays); - acpi_bay_add_fs(new_bay); + + /* initialize platform device stuff */ + pdev = platform_device_register_simple(ACPI_BAY_CLASS, id, NULL, 0); + if (pdev == NULL) { + printk(KERN_ERR PREFIX "Error registering bay device\n"); + goto bay_add_err; + } + new_bay->pdev = pdev; + platform_set_drvdata(pdev, new_bay); + + if (acpi_bay_add_fs(new_bay)) { + platform_device_unregister(new_bay->pdev); + goto bay_add_err; + } /* register for events on this device */ status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, @@ -273,8 +331,14 @@ static int bay_add(acpi_handle handle) bay_dprintk(handle, "Is dependent on dock\n"); register_hotplug_dock_device(handle, bay_notify, new_bay); } + list_add(&new_bay->list, &drive_bays); printk(KERN_INFO PREFIX "Bay [%s] Added\n", new_bay->name); return 0; + +bay_add_err: + kfree(new_bay->name); + kfree(new_bay); + return -ENODEV; } static int acpi_bay_remove(struct acpi_device *device, int type) @@ -393,8 +457,8 @@ find_bay(acpi_handle handle, u32 lvl, void *context, void **rv) */ if (is_ejectable_bay(handle)) { bay_dprintk(handle, "found ejectable bay"); - bay_add(handle); - (*count)++; + if (!bay_add(handle, *count)) + (*count)++; } return AE_OK; } @@ -429,6 +493,7 @@ static void __exit bay_exit(void) acpi_bay_remove_fs(bay); acpi_remove_notify_handler(bay->handle, ACPI_SYSTEM_NOTIFY, bay_notify); + platform_device_unregister(bay->pdev); kfree(bay->name); kfree(bay); } -- cgit v1.2.3 From 5d22e1e83aac1f81f948ac8bff281487c11cc967 Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Mon, 4 Dec 2006 14:49:39 -0800 Subject: ACPI: bay: make drive_bays static Signed-off-by: Adrian Bunk Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/bay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index 3f0ae7d341e7..aa1b131c0fce 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c @@ -69,7 +69,7 @@ struct bay { struct platform_device *pdev; }; -LIST_HEAD(drive_bays); +static LIST_HEAD(drive_bays); /***************************************************************************** -- cgit v1.2.3 From 0ed1e38d513ea683ce125e698dd41d31441e0e8c Mon Sep 17 00:00:00 2001 From: Len Brown Date: Fri, 2 Feb 2007 22:39:16 -0500 Subject: ACPI: bay: new driver is EXPERIMENTAL Signed-off-by: Len Brown --- drivers/acpi/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 2caef098379e..b4bb000a6921 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -140,7 +140,7 @@ config ACPI_DOCK This driver adds support for ACPI controlled docking stations config ACPI_BAY - tristate "Removable Drive Bay" + tristate "Removable Drive Bay (EXPERIMENTAL)" depends on EXPERIMENTAL help This driver adds support for ACPI controlled removable drive -- cgit v1.2.3