ACPI: bay: remove prototype procfs code
[linux-2.6.git] / drivers / acpi / bay.c
blob0c0a6204d167a85ea55e4edf0ac9bc55665ae6b2
1 /*
2 * bay.c - ACPI removable drive bay driver
4 * Copyright (C) 2006 Kristen Carlson Accardi <kristen.c.accardi@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/types.h>
28 #include <linux/notifier.h>
29 #include <acpi/acpi_bus.h>
30 #include <acpi/acpi_drivers.h>
31 #include <linux/seq_file.h>
32 #include <asm/uaccess.h>
34 #define ACPI_BAY_DRIVER_NAME "ACPI Removable Drive Bay Driver"
36 ACPI_MODULE_NAME("bay")
37 MODULE_AUTHOR("Kristen Carlson Accardi");
38 MODULE_DESCRIPTION(ACPI_BAY_DRIVER_NAME);
39 MODULE_LICENSE("GPL");
40 #define ACPI_BAY_CLASS "bay"
41 #define ACPI_BAY_COMPONENT 0x10000000
42 #define _COMPONENT ACPI_BAY_COMPONENT
43 #define bay_dprintk(h,s) {\
44 char prefix[80] = {'\0'};\
45 struct acpi_buffer buffer = {sizeof(prefix), prefix};\
46 acpi_get_name(h, ACPI_FULL_PATHNAME, &buffer);\
47 printk(KERN_DEBUG PREFIX "%s: %s\n", prefix, s); }
49 static void bay_notify(acpi_handle handle, u32 event, void *data);
50 static int acpi_bay_add(struct acpi_device *device);
51 static int acpi_bay_remove(struct acpi_device *device, int type);
52 static int acpi_bay_match(struct acpi_device *device,
53 struct acpi_driver *driver);
55 static struct acpi_driver acpi_bay_driver = {
56 .name = ACPI_BAY_DRIVER_NAME,
57 .class = ACPI_BAY_CLASS,
58 .ops = {
59 .add = acpi_bay_add,
60 .remove = acpi_bay_remove,
61 .match = acpi_bay_match,
65 struct bay {
66 acpi_handle handle;
67 char *name;
68 struct list_head list;
71 LIST_HEAD(drive_bays);
74 /*****************************************************************************
75 * Drive Bay functions *
76 *****************************************************************************/
77 /**
78 * is_ejectable - see if a device is ejectable
79 * @handle: acpi handle of the device
81 * If an acpi object has a _EJ0 method, then it is ejectable
83 static int is_ejectable(acpi_handle handle)
85 acpi_status status;
86 acpi_handle tmp;
88 status = acpi_get_handle(handle, "_EJ0", &tmp);
89 if (ACPI_FAILURE(status))
90 return 0;
91 return 1;
94 /**
95 * bay_present - see if the bay device is present
96 * @bay: the drive bay
98 * execute the _STA method.
100 static int bay_present(struct bay *bay)
102 unsigned long sta;
103 acpi_status status;
105 if (bay) {
106 status = acpi_evaluate_integer(bay->handle, "_STA", NULL, &sta);
107 if (ACPI_SUCCESS(status) && sta)
108 return 1;
110 return 0;
114 * eject_device - respond to an eject request
115 * @handle - the device to eject
117 * Call this devices _EJ0 method.
119 static void eject_device(acpi_handle handle)
121 struct acpi_object_list arg_list;
122 union acpi_object arg;
124 bay_dprintk(handle, "Ejecting device");
126 arg_list.count = 1;
127 arg_list.pointer = &arg;
128 arg.type = ACPI_TYPE_INTEGER;
129 arg.integer.value = 1;
131 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_EJ0",
132 &arg_list, NULL)))
133 pr_debug("Failed to evaluate _EJ0!\n");
138 * is_ata - see if a device is an ata device
139 * @handle: acpi handle of the device
141 * If an acpi object has one of 4 ATA ACPI methods defined,
142 * then it is an ATA device
144 static int is_ata(acpi_handle handle)
146 acpi_handle tmp;
148 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
149 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
150 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
151 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
152 return 1;
154 return 0;
158 * parent_is_ata(acpi_handle handle)
161 static int parent_is_ata(acpi_handle handle)
163 acpi_handle phandle;
165 if (acpi_get_parent(handle, &phandle))
166 return 0;
168 return is_ata(phandle);
172 * is_ejectable_bay - see if a device is an ejectable drive bay
173 * @handle: acpi handle of the device
175 * If an acpi object is ejectable and has one of the ACPI ATA
176 * methods defined, then we can safely call it an ejectable
177 * drive bay
179 static int is_ejectable_bay(acpi_handle handle)
181 if ((is_ata(handle) || parent_is_ata(handle)) && is_ejectable(handle))
182 return 1;
183 return 0;
187 * eject_removable_drive - try to eject this drive
188 * @dev : the device structure of the drive
190 * If a device is a removable drive that requires an _EJ0 method
191 * to be executed in order to safely remove from the system, do
192 * it. ATM - always returns success
194 int eject_removable_drive(struct device *dev)
196 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
198 if (handle) {
199 bay_dprintk(handle, "Got device handle");
200 if (is_ejectable_bay(handle))
201 eject_device(handle);
202 } else {
203 printk("No acpi handle for device\n");
206 /* should I return an error code? */
207 return 0;
209 EXPORT_SYMBOL_GPL(eject_removable_drive);
211 static int acpi_bay_add(struct acpi_device *device)
213 bay_dprintk(device->handle, "adding bay device");
214 strcpy(acpi_device_name(device), "Dockable Bay");
215 strcpy(acpi_device_class(device), "bay");
216 return 0;
219 static int acpi_bay_add_fs(struct bay *bay)
221 if (!bay)
222 return -EINVAL;
225 static void acpi_bay_remove_fs(struct bay *bay)
227 if (!bay)
228 return;
231 static int bay_is_dock_device(acpi_handle handle)
233 acpi_handle parent;
235 acpi_get_parent(handle, &parent);
237 /* if the device or it's parent is dependent on the
238 * dock, then we are a dock device
240 return (is_dock_device(handle) || is_dock_device(parent));
243 static int bay_add(acpi_handle handle)
245 acpi_status status;
246 struct bay *new_bay;
247 struct acpi_buffer nbuffer = {ACPI_ALLOCATE_BUFFER, NULL};
248 acpi_get_name(handle, ACPI_FULL_PATHNAME, &nbuffer);
250 bay_dprintk(handle, "Adding notify handler");
253 * Initialize bay device structure
255 new_bay = kmalloc(GFP_ATOMIC, sizeof(*new_bay));
256 INIT_LIST_HEAD(&new_bay->list);
257 new_bay->handle = handle;
258 new_bay->name = (char *)nbuffer.pointer;
259 list_add(&new_bay->list, &drive_bays);
260 acpi_bay_add_fs(new_bay);
262 /* register for events on this device */
263 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
264 bay_notify, new_bay);
265 if (ACPI_FAILURE(status)) {
266 printk(KERN_ERR PREFIX "Error installing bay notify handler\n");
269 /* if we are on a dock station, we should register for dock
270 * notifications.
272 if (bay_is_dock_device(handle)) {
273 bay_dprintk(handle, "Is dependent on dock\n");
274 register_hotplug_dock_device(handle, bay_notify, new_bay);
276 printk(KERN_INFO PREFIX "Bay [%s] Added\n", new_bay->name);
277 return 0;
280 static int acpi_bay_remove(struct acpi_device *device, int type)
282 /*** FIXME: do something here */
283 return 0;
286 static int acpi_bay_match(struct acpi_device *device,
287 struct acpi_driver *driver)
289 if (!device || !driver)
290 return -EINVAL;
292 if (is_ejectable_bay(device->handle)) {
293 bay_dprintk(device->handle, "matching bay device");
294 return 0;
297 return -ENODEV;
301 * bay_create_acpi_device - add new devices to acpi
302 * @handle - handle of the device to add
304 * This function will create a new acpi_device for the given
305 * handle if one does not exist already. This should cause
306 * acpi to scan for drivers for the given devices, and call
307 * matching driver's add routine.
309 * Returns a pointer to the acpi_device corresponding to the handle.
311 static struct acpi_device * bay_create_acpi_device(acpi_handle handle)
313 struct acpi_device *device = NULL;
314 struct acpi_device *parent_device;
315 acpi_handle parent;
316 int ret;
318 bay_dprintk(handle, "Trying to get device");
319 if (acpi_bus_get_device(handle, &device)) {
321 * no device created for this object,
322 * so we should create one.
324 bay_dprintk(handle, "No device for handle");
325 acpi_get_parent(handle, &parent);
326 if (acpi_bus_get_device(parent, &parent_device))
327 parent_device = NULL;
329 ret = acpi_bus_add(&device, parent_device, handle,
330 ACPI_BUS_TYPE_DEVICE);
331 if (ret) {
332 pr_debug("error adding bus, %x\n",
333 -ret);
334 return NULL;
337 return device;
341 * bay_notify - act upon an acpi bay notification
342 * @handle: the bay handle
343 * @event: the acpi event
344 * @data: our driver data struct
347 static void bay_notify(acpi_handle handle, u32 event, void *data)
349 struct acpi_device *dev;
351 bay_dprintk(handle, "Bay event");
353 switch(event) {
354 case ACPI_NOTIFY_BUS_CHECK:
355 printk("Bus Check\n");
356 case ACPI_NOTIFY_DEVICE_CHECK:
357 printk("Device Check\n");
358 dev = bay_create_acpi_device(handle);
359 if (dev)
360 acpi_bus_generate_event(dev, event, 0);
361 else
362 printk("No device for generating event\n");
363 /* wouldn't it be a good idea to just rescan SATA
364 * right here?
366 break;
367 case ACPI_NOTIFY_EJECT_REQUEST:
368 printk("Eject request\n");
369 dev = bay_create_acpi_device(handle);
370 if (dev)
371 acpi_bus_generate_event(dev, event, 0);
372 else
373 printk("No device for generating eventn");
375 /* wouldn't it be a good idea to just call the
376 * eject_device here if we were a SATA device?
378 break;
379 default:
380 printk("unknown event %d\n", event);
384 static acpi_status
385 find_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
387 int *count = (int *)context;
390 * there could be more than one ejectable bay.
391 * so, just return AE_OK always so that every object
392 * will be checked.
394 if (is_ejectable_bay(handle)) {
395 bay_dprintk(handle, "found ejectable bay");
396 bay_add(handle);
397 (*count)++;
399 return AE_OK;
402 static int __init bay_init(void)
404 int bays = 0;
406 INIT_LIST_HEAD(&drive_bays);
408 /* look for dockable drive bays */
409 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
410 ACPI_UINT32_MAX, find_bay, &bays, NULL);
412 if (bays)
413 if ((acpi_bus_register_driver(&acpi_bay_driver) < 0))
414 printk(KERN_ERR "Unable to register bay driver\n");
416 if (!bays)
417 return -ENODEV;
419 return 0;
422 static void __exit bay_exit(void)
424 struct bay *bay, *tmp;
426 list_for_each_entry_safe(bay, tmp, &drive_bays, list) {
427 if (is_dock_device(bay->handle))
428 unregister_hotplug_dock_device(bay->handle);
429 acpi_bay_remove_fs(bay);
430 acpi_remove_notify_handler(bay->handle, ACPI_SYSTEM_NOTIFY,
431 bay_notify);
432 kfree(bay->name);
433 kfree(bay);
436 acpi_bus_unregister_driver(&acpi_bay_driver);
439 postcore_initcall(bay_init);
440 module_exit(bay_exit);