2 * dock.c - ACPI dock station 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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/notifier.h>
31 #include <linux/platform_device.h>
32 #include <linux/jiffies.h>
33 #include <linux/stddef.h>
34 #include <linux/acpi.h>
35 #include <acpi/acpi_bus.h>
36 #include <acpi/acpi_drivers.h>
38 #define PREFIX "ACPI: "
40 #define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
42 ACPI_MODULE_NAME("dock");
43 MODULE_AUTHOR("Kristen Carlson Accardi");
44 MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION
);
45 MODULE_LICENSE("GPL");
47 static bool immediate_undock
= 1;
48 module_param(immediate_undock
, bool, 0644);
49 MODULE_PARM_DESC(immediate_undock
, "1 (default) will cause the driver to "
50 "undock immediately when the undock button is pressed, 0 will cause"
51 " the driver to wait for userspace to write the undock sysfs file "
54 static const struct acpi_device_id dock_device_ids
[] = {
58 MODULE_DEVICE_TABLE(acpi
, dock_device_ids
);
62 unsigned long last_dock_time
;
64 struct list_head dependent_devices
;
66 struct list_head sibling
;
67 struct platform_device
*dock_device
;
69 static LIST_HEAD(dock_stations
);
70 static int dock_station_count
;
71 static DEFINE_MUTEX(hotplug_lock
);
73 struct dock_dependent_device
{
74 struct list_head list
;
76 const struct acpi_dock_ops
*hp_ops
;
78 unsigned int hp_refcount
;
79 void (*hp_release
)(void *);
82 #define DOCK_DOCKING 0x00000001
83 #define DOCK_UNDOCKING 0x00000002
84 #define DOCK_IS_DOCK 0x00000010
85 #define DOCK_IS_ATA 0x00000020
86 #define DOCK_IS_BAT 0x00000040
88 #define UNDOCK_EVENT 2
90 enum dock_callback_type
{
96 /*****************************************************************************
97 * Dock Dependent device functions *
98 *****************************************************************************/
100 * add_dock_dependent_device - associate a device with the dock station
101 * @ds: The dock station
102 * @handle: handle of the dependent device
104 * Add the dependent device to the dock's dependent device list.
107 add_dock_dependent_device(struct dock_station
*ds
, acpi_handle handle
)
109 struct dock_dependent_device
*dd
;
111 dd
= kzalloc(sizeof(*dd
), GFP_KERNEL
);
116 INIT_LIST_HEAD(&dd
->list
);
117 list_add_tail(&dd
->list
, &ds
->dependent_devices
);
122 static void remove_dock_dependent_devices(struct dock_station
*ds
)
124 struct dock_dependent_device
*dd
, *aux
;
126 list_for_each_entry_safe(dd
, aux
, &ds
->dependent_devices
, list
) {
133 * dock_init_hotplug - Initialize a hotplug device on a docking station.
134 * @dd: Dock-dependent device.
135 * @ops: Dock operations to attach to the dependent device.
136 * @context: Data to pass to the @ops callbacks and @release.
137 * @init: Optional initialization routine to run after setting up context.
138 * @release: Optional release routine to run on removal.
140 static int dock_init_hotplug(struct dock_dependent_device
*dd
,
141 const struct acpi_dock_ops
*ops
, void *context
,
142 void (*init
)(void *), void (*release
)(void *))
146 mutex_lock(&hotplug_lock
);
147 if (WARN_ON(dd
->hp_context
)) {
152 dd
->hp_context
= context
;
153 dd
->hp_release
= release
;
157 mutex_unlock(&hotplug_lock
);
162 * dock_release_hotplug - Decrement hotplug reference counter of dock device.
163 * @dd: Dock-dependent device.
165 * Decrement the reference counter of @dd and if 0, detach its hotplug
166 * operations from it, reset its context pointer and run the optional release
167 * routine if present.
169 static void dock_release_hotplug(struct dock_dependent_device
*dd
)
171 mutex_lock(&hotplug_lock
);
172 if (dd
->hp_context
&& !--dd
->hp_refcount
) {
173 void (*release
)(void *) = dd
->hp_release
;
174 void *context
= dd
->hp_context
;
177 dd
->hp_context
= NULL
;
178 dd
->hp_release
= NULL
;
182 mutex_unlock(&hotplug_lock
);
185 static void dock_hotplug_event(struct dock_dependent_device
*dd
, u32 event
,
186 enum dock_callback_type cb_type
)
188 acpi_notify_handler cb
= NULL
;
191 mutex_lock(&hotplug_lock
);
193 if (dd
->hp_context
) {
198 case DOCK_CALL_FIXUP
:
199 cb
= dd
->hp_ops
->fixup
;
201 case DOCK_CALL_UEVENT
:
202 cb
= dd
->hp_ops
->uevent
;
205 cb
= dd
->hp_ops
->handler
;
210 mutex_unlock(&hotplug_lock
);
216 cb(dd
->handle
, event
, dd
->hp_context
);
218 dock_release_hotplug(dd
);
222 * find_dock_dependent_device - get a device dependent on this dock
223 * @ds: the dock station
224 * @handle: the acpi_handle of the device we want
226 * iterate over the dependent device list for this dock. If the
227 * dependent device matches the handle, return.
229 static struct dock_dependent_device
*
230 find_dock_dependent_device(struct dock_station
*ds
, acpi_handle handle
)
232 struct dock_dependent_device
*dd
;
234 list_for_each_entry(dd
, &ds
->dependent_devices
, list
)
235 if (handle
== dd
->handle
)
241 /*****************************************************************************
243 *****************************************************************************/
244 static int __init
is_battery(acpi_handle handle
)
246 struct acpi_device_info
*info
;
249 if (!ACPI_SUCCESS(acpi_get_object_info(handle
, &info
)))
251 if (!(info
->valid
& ACPI_VALID_HID
))
254 ret
= !strcmp("PNP0C0A", info
->hardware_id
.string
);
260 /* Check whether ACPI object is an ejectable battery or disk bay */
261 static bool __init
is_ejectable_bay(acpi_handle handle
)
263 if (acpi_has_method(handle
, "_EJ0") && is_battery(handle
))
266 return acpi_bay_match(handle
);
270 * is_dock_device - see if a device is on a dock station
271 * @handle: acpi handle of the device
273 * If this device is either the dock station itself,
274 * or is a device dependent on the dock station, then it
277 int is_dock_device(acpi_handle handle
)
279 struct dock_station
*dock_station
;
281 if (!dock_station_count
)
284 if (acpi_dock_match(handle
))
287 list_for_each_entry(dock_station
, &dock_stations
, sibling
)
288 if (find_dock_dependent_device(dock_station
, handle
))
293 EXPORT_SYMBOL_GPL(is_dock_device
);
296 * dock_present - see if the dock station is present.
297 * @ds: the dock station
299 * execute the _STA method. note that present does not
300 * imply that we are docked.
302 static int dock_present(struct dock_station
*ds
)
304 unsigned long long sta
;
308 status
= acpi_evaluate_integer(ds
->handle
, "_STA", NULL
, &sta
);
309 if (ACPI_SUCCESS(status
) && sta
)
316 * dock_create_acpi_device - add new devices to acpi
317 * @handle - handle of the device to add
319 * This function will create a new acpi_device for the given
320 * handle if one does not exist already. This should cause
321 * acpi to scan for drivers for the given devices, and call
322 * matching driver's add routine.
324 static void dock_create_acpi_device(acpi_handle handle
)
326 struct acpi_device
*device
;
329 if (acpi_bus_get_device(handle
, &device
)) {
331 * no device created for this object,
332 * so we should create one.
334 ret
= acpi_bus_scan(handle
);
336 pr_debug("error adding bus, %x\n", -ret
);
341 * dock_remove_acpi_device - remove the acpi_device struct from acpi
342 * @handle - the handle of the device to remove
344 * Tell acpi to remove the acpi_device. This should cause any loaded
345 * driver to have it's remove routine called.
347 static void dock_remove_acpi_device(acpi_handle handle
)
349 struct acpi_device
*device
;
351 if (!acpi_bus_get_device(handle
, &device
))
352 acpi_bus_trim(device
);
356 * hot_remove_dock_devices - Remove dock station devices.
359 static void hot_remove_dock_devices(struct dock_station
*ds
)
361 struct dock_dependent_device
*dd
;
364 * Walk the list in reverse order so that devices that have been added
365 * last are removed first (in case there are some indirect dependencies
368 list_for_each_entry_reverse(dd
, &ds
->dependent_devices
, list
)
369 dock_hotplug_event(dd
, ACPI_NOTIFY_EJECT_REQUEST
, false);
371 list_for_each_entry_reverse(dd
, &ds
->dependent_devices
, list
)
372 dock_remove_acpi_device(dd
->handle
);
376 * hotplug_dock_devices - Insert devices on a dock station.
377 * @ds: the dock station
378 * @event: either bus check or device check request
380 * Some devices on the dock station need to have drivers called
381 * to perform hotplug operations after a dock event has occurred.
382 * Traverse the list of dock devices that have registered a
383 * hotplug handler, and call the handler.
385 static void hotplug_dock_devices(struct dock_station
*ds
, u32 event
)
387 struct dock_dependent_device
*dd
;
389 /* Call driver specific post-dock fixups. */
390 list_for_each_entry(dd
, &ds
->dependent_devices
, list
)
391 dock_hotplug_event(dd
, event
, DOCK_CALL_FIXUP
);
393 /* Call driver specific hotplug functions. */
394 list_for_each_entry(dd
, &ds
->dependent_devices
, list
)
395 dock_hotplug_event(dd
, event
, DOCK_CALL_HANDLER
);
398 * Now make sure that an acpi_device is created for each dependent
399 * device. That will cause scan handlers to be attached to device
400 * objects or acpi_drivers to be stopped/started if they are present.
402 list_for_each_entry(dd
, &ds
->dependent_devices
, list
)
403 dock_create_acpi_device(dd
->handle
);
406 static void dock_event(struct dock_station
*ds
, u32 event
, int num
)
408 struct device
*dev
= &ds
->dock_device
->dev
;
409 char event_string
[13];
410 char *envp
[] = { event_string
, NULL
};
411 struct dock_dependent_device
*dd
;
413 if (num
== UNDOCK_EVENT
)
414 sprintf(event_string
, "EVENT=undock");
416 sprintf(event_string
, "EVENT=dock");
419 * Indicate that the status of the dock station has
422 if (num
== DOCK_EVENT
)
423 kobject_uevent_env(&dev
->kobj
, KOBJ_CHANGE
, envp
);
425 list_for_each_entry(dd
, &ds
->dependent_devices
, list
)
426 dock_hotplug_event(dd
, event
, DOCK_CALL_UEVENT
);
428 if (num
!= DOCK_EVENT
)
429 kobject_uevent_env(&dev
->kobj
, KOBJ_CHANGE
, envp
);
433 * handle_dock - handle a dock event
434 * @ds: the dock station
435 * @dock: to dock, or undock - that is the question
437 * Execute the _DCK method in response to an acpi event
439 static void handle_dock(struct dock_station
*ds
, int dock
)
442 struct acpi_object_list arg_list
;
443 union acpi_object arg
;
444 unsigned long long value
;
446 acpi_handle_info(ds
->handle
, "%s\n", dock
? "docking" : "undocking");
448 /* _DCK method has one argument */
450 arg_list
.pointer
= &arg
;
451 arg
.type
= ACPI_TYPE_INTEGER
;
452 arg
.integer
.value
= dock
;
453 status
= acpi_evaluate_integer(ds
->handle
, "_DCK", &arg_list
, &value
);
454 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
)
455 acpi_handle_err(ds
->handle
, "Failed to execute _DCK (0x%x)\n",
459 static inline void dock(struct dock_station
*ds
)
464 static inline void undock(struct dock_station
*ds
)
469 static inline void begin_dock(struct dock_station
*ds
)
471 ds
->flags
|= DOCK_DOCKING
;
474 static inline void complete_dock(struct dock_station
*ds
)
476 ds
->flags
&= ~(DOCK_DOCKING
);
477 ds
->last_dock_time
= jiffies
;
480 static inline void begin_undock(struct dock_station
*ds
)
482 ds
->flags
|= DOCK_UNDOCKING
;
485 static inline void complete_undock(struct dock_station
*ds
)
487 ds
->flags
&= ~(DOCK_UNDOCKING
);
491 * dock_in_progress - see if we are in the middle of handling a dock event
492 * @ds: the dock station
494 * Sometimes while docking, false dock events can be sent to the driver
495 * because good connections aren't made or some other reason. Ignore these
496 * if we are in the middle of doing something.
498 static int dock_in_progress(struct dock_station
*ds
)
500 if ((ds
->flags
& DOCK_DOCKING
) ||
501 time_before(jiffies
, (ds
->last_dock_time
+ HZ
)))
507 * register_hotplug_dock_device - register a hotplug function
508 * @handle: the handle of the device
509 * @ops: handlers to call after docking
510 * @context: device specific data
511 * @init: Optional initialization routine to run after registration
512 * @release: Optional release routine to run on unregistration
514 * If a driver would like to perform a hotplug operation after a dock
515 * event, they can register an acpi_notifiy_handler to be called by
516 * the dock driver after _DCK is executed.
518 int register_hotplug_dock_device(acpi_handle handle
,
519 const struct acpi_dock_ops
*ops
, void *context
,
520 void (*init
)(void *), void (*release
)(void *))
522 struct dock_dependent_device
*dd
;
523 struct dock_station
*dock_station
;
526 if (WARN_ON(!context
))
529 if (!dock_station_count
)
533 * make sure this handle is for a device dependent on the dock,
534 * this would include the dock station itself
536 list_for_each_entry(dock_station
, &dock_stations
, sibling
) {
538 * An ATA bay can be in a dock and itself can be ejected
539 * separately, so there are two 'dock stations' which need the
542 dd
= find_dock_dependent_device(dock_station
, handle
);
543 if (dd
&& !dock_init_hotplug(dd
, ops
, context
, init
, release
))
549 EXPORT_SYMBOL_GPL(register_hotplug_dock_device
);
552 * unregister_hotplug_dock_device - remove yourself from the hotplug list
553 * @handle: the acpi handle of the device
555 void unregister_hotplug_dock_device(acpi_handle handle
)
557 struct dock_dependent_device
*dd
;
558 struct dock_station
*dock_station
;
560 if (!dock_station_count
)
563 list_for_each_entry(dock_station
, &dock_stations
, sibling
) {
564 dd
= find_dock_dependent_device(dock_station
, handle
);
566 dock_release_hotplug(dd
);
569 EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device
);
572 * handle_eject_request - handle an undock request checking for error conditions
574 * Check to make sure the dock device is still present, then undock and
575 * hotremove all the devices that may need removing.
577 static int handle_eject_request(struct dock_station
*ds
, u32 event
)
579 if (dock_in_progress(ds
))
583 * here we need to generate the undock
584 * event prior to actually doing the undock
585 * so that the device struct still exists.
586 * Also, even send the dock event if the
587 * device is not present anymore
589 dock_event(ds
, event
, UNDOCK_EVENT
);
591 hot_remove_dock_devices(ds
);
593 acpi_evaluate_lck(ds
->handle
, 0);
594 acpi_evaluate_ej0(ds
->handle
);
595 if (dock_present(ds
)) {
596 acpi_handle_err(ds
->handle
, "Unable to undock!\n");
604 * dock_notify - act upon an acpi dock notification
606 * @event: the acpi event
608 * If we are notified to dock, then check to see if the dock is
609 * present and then dock. Notify all drivers of the dock event,
610 * and then hotplug and devices that may need hotplugging.
612 static void dock_notify(struct dock_station
*ds
, u32 event
)
614 acpi_handle handle
= ds
->handle
;
615 struct acpi_device
*ad
;
616 int surprise_removal
= 0;
619 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
620 * is sent and _DCK is present, it is assumed to mean an undock
623 if ((ds
->flags
& DOCK_IS_DOCK
) && event
== ACPI_NOTIFY_DEVICE_CHECK
)
624 event
= ACPI_NOTIFY_EJECT_REQUEST
;
627 * dock station: BUS_CHECK - docked or surprise removal
628 * DEVICE_CHECK - undocked
629 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
631 * To simplify event handling, dock dependent device handler always
632 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
633 * ACPI_NOTIFY_EJECT_REQUEST for removal
636 case ACPI_NOTIFY_BUS_CHECK
:
637 case ACPI_NOTIFY_DEVICE_CHECK
:
638 if (!dock_in_progress(ds
) && acpi_bus_get_device(handle
, &ad
)) {
641 if (!dock_present(ds
)) {
642 acpi_handle_err(handle
, "Unable to dock!\n");
646 hotplug_dock_devices(ds
, event
);
648 dock_event(ds
, event
, DOCK_EVENT
);
649 acpi_evaluate_lck(ds
->handle
, 1);
650 acpi_update_all_gpes();
653 if (dock_present(ds
) || dock_in_progress(ds
))
655 /* This is a surprise removal */
656 surprise_removal
= 1;
657 event
= ACPI_NOTIFY_EJECT_REQUEST
;
659 case ACPI_NOTIFY_EJECT_REQUEST
:
661 if ((immediate_undock
&& !(ds
->flags
& DOCK_IS_ATA
))
663 handle_eject_request(ds
, event
);
665 dock_event(ds
, event
, UNDOCK_EVENT
);
668 acpi_handle_err(handle
, "Unknown dock event %d\n", event
);
672 static void acpi_dock_deferred_cb(void *data
, u32 event
)
674 acpi_scan_lock_acquire();
675 dock_notify(data
, event
);
676 acpi_scan_lock_release();
679 static void dock_notify_handler(acpi_handle handle
, u32 event
, void *data
)
681 if (event
!= ACPI_NOTIFY_BUS_CHECK
&& event
!= ACPI_NOTIFY_DEVICE_CHECK
682 && event
!= ACPI_NOTIFY_EJECT_REQUEST
)
685 acpi_hotplug_execute(acpi_dock_deferred_cb
, data
, event
);
689 * find_dock_devices - find devices on the dock station
690 * @handle: the handle of the device we are examining
692 * @context: the dock station private data
695 * This function is called by acpi_walk_namespace. It will
696 * check to see if an object has an _EJD method. If it does, then it
697 * will see if it is dependent on the dock station.
699 static acpi_status __init
find_dock_devices(acpi_handle handle
, u32 lvl
,
700 void *context
, void **rv
)
702 struct dock_station
*ds
= context
;
703 acpi_handle ejd
= NULL
;
705 acpi_bus_get_ejd(handle
, &ejd
);
706 if (ejd
== ds
->handle
)
707 add_dock_dependent_device(ds
, handle
);
713 * show_docked - read method for "docked" file in sysfs
715 static ssize_t
show_docked(struct device
*dev
,
716 struct device_attribute
*attr
, char *buf
)
718 struct acpi_device
*tmp
;
720 struct dock_station
*dock_station
= dev
->platform_data
;
722 if (!acpi_bus_get_device(dock_station
->handle
, &tmp
))
723 return snprintf(buf
, PAGE_SIZE
, "1\n");
724 return snprintf(buf
, PAGE_SIZE
, "0\n");
726 static DEVICE_ATTR(docked
, S_IRUGO
, show_docked
, NULL
);
729 * show_flags - read method for flags file in sysfs
731 static ssize_t
show_flags(struct device
*dev
,
732 struct device_attribute
*attr
, char *buf
)
734 struct dock_station
*dock_station
= dev
->platform_data
;
735 return snprintf(buf
, PAGE_SIZE
, "%d\n", dock_station
->flags
);
738 static DEVICE_ATTR(flags
, S_IRUGO
, show_flags
, NULL
);
741 * write_undock - write method for "undock" file in sysfs
743 static ssize_t
write_undock(struct device
*dev
, struct device_attribute
*attr
,
744 const char *buf
, size_t count
)
747 struct dock_station
*dock_station
= dev
->platform_data
;
752 acpi_scan_lock_acquire();
753 begin_undock(dock_station
);
754 ret
= handle_eject_request(dock_station
, ACPI_NOTIFY_EJECT_REQUEST
);
755 acpi_scan_lock_release();
756 return ret
? ret
: count
;
758 static DEVICE_ATTR(undock
, S_IWUSR
, NULL
, write_undock
);
761 * show_dock_uid - read method for "uid" file in sysfs
763 static ssize_t
show_dock_uid(struct device
*dev
,
764 struct device_attribute
*attr
, char *buf
)
766 unsigned long long lbuf
;
767 struct dock_station
*dock_station
= dev
->platform_data
;
768 acpi_status status
= acpi_evaluate_integer(dock_station
->handle
,
769 "_UID", NULL
, &lbuf
);
770 if (ACPI_FAILURE(status
))
773 return snprintf(buf
, PAGE_SIZE
, "%llx\n", lbuf
);
775 static DEVICE_ATTR(uid
, S_IRUGO
, show_dock_uid
, NULL
);
777 static ssize_t
show_dock_type(struct device
*dev
,
778 struct device_attribute
*attr
, char *buf
)
780 struct dock_station
*dock_station
= dev
->platform_data
;
783 if (dock_station
->flags
& DOCK_IS_DOCK
)
784 type
= "dock_station";
785 else if (dock_station
->flags
& DOCK_IS_ATA
)
787 else if (dock_station
->flags
& DOCK_IS_BAT
)
788 type
= "battery_bay";
792 return snprintf(buf
, PAGE_SIZE
, "%s\n", type
);
794 static DEVICE_ATTR(type
, S_IRUGO
, show_dock_type
, NULL
);
796 static struct attribute
*dock_attributes
[] = {
797 &dev_attr_docked
.attr
,
798 &dev_attr_flags
.attr
,
799 &dev_attr_undock
.attr
,
805 static struct attribute_group dock_attribute_group
= {
806 .attrs
= dock_attributes
810 * dock_add - add a new dock station
811 * @handle: the dock station handle
813 * allocated and initialize a new dock station device. Find all devices
814 * that are on the dock station, and register for dock event notifications.
816 static int __init
dock_add(acpi_handle handle
)
818 struct dock_station
*dock_station
, ds
= { NULL
, };
819 struct platform_device
*dd
;
823 dd
= platform_device_register_data(NULL
, "dock", dock_station_count
,
828 dock_station
= dd
->dev
.platform_data
;
830 dock_station
->handle
= handle
;
831 dock_station
->dock_device
= dd
;
832 dock_station
->last_dock_time
= jiffies
- HZ
;
834 INIT_LIST_HEAD(&dock_station
->sibling
);
835 INIT_LIST_HEAD(&dock_station
->dependent_devices
);
837 /* we want the dock device to send uevents */
838 dev_set_uevent_suppress(&dd
->dev
, 0);
840 if (acpi_dock_match(handle
))
841 dock_station
->flags
|= DOCK_IS_DOCK
;
842 if (acpi_ata_match(handle
))
843 dock_station
->flags
|= DOCK_IS_ATA
;
844 if (is_battery(handle
))
845 dock_station
->flags
|= DOCK_IS_BAT
;
847 ret
= sysfs_create_group(&dd
->dev
.kobj
, &dock_attribute_group
);
851 /* Find dependent devices */
852 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
853 ACPI_UINT32_MAX
, find_dock_devices
, NULL
,
856 /* add the dock station as a device dependent on itself */
857 ret
= add_dock_dependent_device(dock_station
, handle
);
861 status
= acpi_install_notify_handler(handle
, ACPI_SYSTEM_NOTIFY
,
862 dock_notify_handler
, dock_station
);
863 if (ACPI_FAILURE(status
)) {
868 dock_station_count
++;
869 list_add(&dock_station
->sibling
, &dock_stations
);
873 remove_dock_dependent_devices(dock_station
);
874 sysfs_remove_group(&dd
->dev
.kobj
, &dock_attribute_group
);
876 platform_device_unregister(dd
);
877 acpi_handle_err(handle
, "%s encountered error %d\n", __func__
, ret
);
882 * find_dock_and_bay - look for dock stations and bays
883 * @handle: acpi handle of a device
888 * This is called by acpi_walk_namespace to look for dock stations and bays.
890 static acpi_status __init
891 find_dock_and_bay(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
893 if (acpi_dock_match(handle
) || is_ejectable_bay(handle
))
899 void __init
acpi_dock_init(void)
904 /* look for dock stations and bays */
905 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
906 ACPI_UINT32_MAX
, find_dock_and_bay
, NULL
, NULL
, NULL
);
908 if (!dock_station_count
) {
909 pr_info(PREFIX
"No dock devices found.\n");
913 pr_info(PREFIX
"%s: %d docks/bays found\n",
914 ACPI_DOCK_DRIVER_DESCRIPTION
, dock_station_count
);