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 struct atomic_notifier_head dock_notifier_list;
56 static const struct acpi_device_id dock_device_ids[] = {
60 MODULE_DEVICE_TABLE(acpi, dock_device_ids);
64 unsigned long last_dock_time;
67 struct list_head dependent_devices;
69 struct list_head sibling;
70 struct platform_device *dock_device;
72 static LIST_HEAD(dock_stations);
73 static int dock_station_count;
74 static DEFINE_MUTEX(hotplug_lock);
76 struct dock_dependent_device {
77 struct list_head list;
79 const struct acpi_dock_ops *hp_ops;
81 unsigned int hp_refcount;
82 void (*hp_release)(void *);
85 #define DOCK_DOCKING 0x00000001
86 #define DOCK_UNDOCKING 0x00000002
87 #define DOCK_IS_DOCK 0x00000010
88 #define DOCK_IS_ATA 0x00000020
89 #define DOCK_IS_BAT 0x00000040
91 #define UNDOCK_EVENT 2
93 /*****************************************************************************
94 * Dock Dependent device functions *
95 *****************************************************************************/
97 * add_dock_dependent_device - associate a device with the dock station
98 * @ds: The dock station
99 * @handle: handle of the dependent device
101 * Add the dependent device to the dock's dependent device list.
104 add_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
106 struct dock_dependent_device *dd;
108 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
113 INIT_LIST_HEAD(&dd->list);
114 list_add_tail(&dd->list, &ds->dependent_devices);
120 * dock_init_hotplug - Initialize a hotplug device on a docking station.
121 * @dd: Dock-dependent device.
122 * @ops: Dock operations to attach to the dependent device.
123 * @context: Data to pass to the @ops callbacks and @release.
124 * @init: Optional initialization routine to run after setting up context.
125 * @release: Optional release routine to run on removal.
127 static int dock_init_hotplug(struct dock_dependent_device *dd,
128 const struct acpi_dock_ops *ops, void *context,
129 void (*init)(void *), void (*release)(void *))
133 mutex_lock(&hotplug_lock);
135 if (dd->hp_context) {
140 dd->hp_context = context;
141 dd->hp_release = release;
144 if (!WARN_ON(ret) && init)
147 mutex_unlock(&hotplug_lock);
152 * dock_release_hotplug - Decrement hotplug reference counter of dock device.
153 * @dd: Dock-dependent device.
155 * Decrement the reference counter of @dd and if 0, detach its hotplug
156 * operations from it, reset its context pointer and run the optional release
157 * routine if present.
159 static void dock_release_hotplug(struct dock_dependent_device *dd)
161 void (*release)(void *) = NULL;
162 void *context = NULL;
164 mutex_lock(&hotplug_lock);
166 if (dd->hp_context && !--dd->hp_refcount) {
168 context = dd->hp_context;
169 dd->hp_context = NULL;
170 release = dd->hp_release;
171 dd->hp_release = NULL;
174 if (release && context)
177 mutex_unlock(&hotplug_lock);
180 static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event,
183 acpi_notify_handler cb = NULL;
186 mutex_lock(&hotplug_lock);
188 if (dd->hp_context) {
192 cb = uevent ? dd->hp_ops->uevent : dd->hp_ops->handler;
195 mutex_unlock(&hotplug_lock);
201 cb(dd->handle, event, dd->hp_context);
203 dock_release_hotplug(dd);
207 * find_dock_dependent_device - get a device dependent on this dock
208 * @ds: the dock station
209 * @handle: the acpi_handle of the device we want
211 * iterate over the dependent device list for this dock. If the
212 * dependent device matches the handle, return.
214 static struct dock_dependent_device *
215 find_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
217 struct dock_dependent_device *dd;
219 list_for_each_entry(dd, &ds->dependent_devices, list)
220 if (handle == dd->handle)
226 /*****************************************************************************
228 *****************************************************************************/
229 static int __init is_battery(acpi_handle handle)
231 struct acpi_device_info *info;
234 if (!ACPI_SUCCESS(acpi_get_object_info(handle, &info)))
236 if (!(info->valid & ACPI_VALID_HID))
239 ret = !strcmp("PNP0C0A", info->hardware_id.string);
245 /* Check whether ACPI object is an ejectable battery or disk bay */
246 static bool __init is_ejectable_bay(acpi_handle handle)
248 if (acpi_has_method(handle, "_EJ0") && is_battery(handle))
251 return acpi_bay_match(handle);
255 * is_dock_device - see if a device is on a dock station
256 * @handle: acpi handle of the device
258 * If this device is either the dock station itself,
259 * or is a device dependent on the dock station, then it
262 int is_dock_device(acpi_handle handle)
264 struct dock_station *dock_station;
266 if (!dock_station_count)
269 if (acpi_dock_match(handle))
272 list_for_each_entry(dock_station, &dock_stations, sibling)
273 if (find_dock_dependent_device(dock_station, handle))
278 EXPORT_SYMBOL_GPL(is_dock_device);
281 * dock_present - see if the dock station is present.
282 * @ds: the dock station
284 * execute the _STA method. note that present does not
285 * imply that we are docked.
287 static int dock_present(struct dock_station *ds)
289 unsigned long long sta;
293 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
294 if (ACPI_SUCCESS(status) && sta)
301 * dock_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 static void dock_create_acpi_device(acpi_handle handle)
311 struct acpi_device *device;
314 if (acpi_bus_get_device(handle, &device)) {
316 * no device created for this object,
317 * so we should create one.
319 ret = acpi_bus_scan(handle);
321 pr_debug("error adding bus, %x\n", -ret);
326 * dock_remove_acpi_device - remove the acpi_device struct from acpi
327 * @handle - the handle of the device to remove
329 * Tell acpi to remove the acpi_device. This should cause any loaded
330 * driver to have it's remove routine called.
332 static void dock_remove_acpi_device(acpi_handle handle)
334 struct acpi_device *device;
336 if (!acpi_bus_get_device(handle, &device))
337 acpi_bus_trim(device);
341 * hotplug_dock_devices - insert or remove devices on the dock station
342 * @ds: the dock station
343 * @event: either bus check or eject request
345 * Some devices on the dock station need to have drivers called
346 * to perform hotplug operations after a dock event has occurred.
347 * Traverse the list of dock devices that have registered a
348 * hotplug handler, and call the handler.
350 static void hotplug_dock_devices(struct dock_station *ds, u32 event)
352 struct dock_dependent_device *dd;
354 mutex_lock(&ds->hp_lock);
357 * First call driver specific hotplug functions
359 list_for_each_entry(dd, &ds->dependent_devices, list)
360 dock_hotplug_event(dd, event, false);
363 * Now make sure that an acpi_device is created for each
364 * dependent device, or removed if this is an eject request.
365 * This will cause acpi_drivers to be stopped/started if they
368 list_for_each_entry(dd, &ds->dependent_devices, list) {
369 if (event == ACPI_NOTIFY_EJECT_REQUEST)
370 dock_remove_acpi_device(dd->handle);
372 dock_create_acpi_device(dd->handle);
374 mutex_unlock(&ds->hp_lock);
377 static void dock_event(struct dock_station *ds, u32 event, int num)
379 struct device *dev = &ds->dock_device->dev;
380 char event_string[13];
381 char *envp[] = { event_string, NULL };
382 struct dock_dependent_device *dd;
384 if (num == UNDOCK_EVENT)
385 sprintf(event_string, "EVENT=undock");
387 sprintf(event_string, "EVENT=dock");
390 * Indicate that the status of the dock station has
393 if (num == DOCK_EVENT)
394 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
396 list_for_each_entry(dd, &ds->dependent_devices, list)
397 dock_hotplug_event(dd, event, true);
399 if (num != DOCK_EVENT)
400 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
404 * handle_dock - handle a dock event
405 * @ds: the dock station
406 * @dock: to dock, or undock - that is the question
408 * Execute the _DCK method in response to an acpi event
410 static void handle_dock(struct dock_station *ds, int dock)
413 struct acpi_object_list arg_list;
414 union acpi_object arg;
415 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
417 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
419 /* _DCK method has one argument */
421 arg_list.pointer = &arg;
422 arg.type = ACPI_TYPE_INTEGER;
423 arg.integer.value = dock;
424 status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer);
425 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
426 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
429 kfree(buffer.pointer);
432 static inline void dock(struct dock_station *ds)
437 static inline void undock(struct dock_station *ds)
442 static inline void begin_dock(struct dock_station *ds)
444 ds->flags |= DOCK_DOCKING;
447 static inline void complete_dock(struct dock_station *ds)
449 ds->flags &= ~(DOCK_DOCKING);
450 ds->last_dock_time = jiffies;
453 static inline void begin_undock(struct dock_station *ds)
455 ds->flags |= DOCK_UNDOCKING;
458 static inline void complete_undock(struct dock_station *ds)
460 ds->flags &= ~(DOCK_UNDOCKING);
464 * dock_in_progress - see if we are in the middle of handling a dock event
465 * @ds: the dock station
467 * Sometimes while docking, false dock events can be sent to the driver
468 * because good connections aren't made or some other reason. Ignore these
469 * if we are in the middle of doing something.
471 static int dock_in_progress(struct dock_station *ds)
473 if ((ds->flags & DOCK_DOCKING) ||
474 time_before(jiffies, (ds->last_dock_time + HZ)))
480 * register_dock_notifier - add yourself to the dock notifier list
481 * @nb: the callers notifier block
483 * If a driver wishes to be notified about dock events, they can
484 * use this function to put a notifier block on the dock notifier list.
485 * this notifier call chain will be called after a dock event, but
486 * before hotplugging any new devices.
488 int register_dock_notifier(struct notifier_block *nb)
490 if (!dock_station_count)
493 return atomic_notifier_chain_register(&dock_notifier_list, nb);
495 EXPORT_SYMBOL_GPL(register_dock_notifier);
498 * unregister_dock_notifier - remove yourself from the dock notifier list
499 * @nb: the callers notifier block
501 void unregister_dock_notifier(struct notifier_block *nb)
503 if (!dock_station_count)
506 atomic_notifier_chain_unregister(&dock_notifier_list, nb);
508 EXPORT_SYMBOL_GPL(unregister_dock_notifier);
511 * register_hotplug_dock_device - register a hotplug function
512 * @handle: the handle of the device
513 * @ops: handlers to call after docking
514 * @context: device specific data
515 * @init: Optional initialization routine to run after registration
516 * @release: Optional release routine to run on unregistration
518 * If a driver would like to perform a hotplug operation after a dock
519 * event, they can register an acpi_notifiy_handler to be called by
520 * the dock driver after _DCK is executed.
522 int register_hotplug_dock_device(acpi_handle handle,
523 const struct acpi_dock_ops *ops, void *context,
524 void (*init)(void *), void (*release)(void *))
526 struct dock_dependent_device *dd;
527 struct dock_station *dock_station;
530 if (WARN_ON(!context))
533 if (!dock_station_count)
537 * make sure this handle is for a device dependent on the dock,
538 * this would include the dock station itself
540 list_for_each_entry(dock_station, &dock_stations, sibling) {
542 * An ATA bay can be in a dock and itself can be ejected
543 * separately, so there are two 'dock stations' which need the
546 dd = find_dock_dependent_device(dock_station, handle);
547 if (dd && !dock_init_hotplug(dd, ops, context, init, release))
553 EXPORT_SYMBOL_GPL(register_hotplug_dock_device);
556 * unregister_hotplug_dock_device - remove yourself from the hotplug list
557 * @handle: the acpi handle of the device
559 void unregister_hotplug_dock_device(acpi_handle handle)
561 struct dock_dependent_device *dd;
562 struct dock_station *dock_station;
564 if (!dock_station_count)
567 list_for_each_entry(dock_station, &dock_stations, sibling) {
568 dd = find_dock_dependent_device(dock_station, handle);
570 dock_release_hotplug(dd);
573 EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
576 * handle_eject_request - handle an undock request checking for error conditions
578 * Check to make sure the dock device is still present, then undock and
579 * hotremove all the devices that may need removing.
581 static int handle_eject_request(struct dock_station *ds, u32 event)
583 if (dock_in_progress(ds))
587 * here we need to generate the undock
588 * event prior to actually doing the undock
589 * so that the device struct still exists.
590 * Also, even send the dock event if the
591 * device is not present anymore
593 dock_event(ds, event, UNDOCK_EVENT);
595 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
597 acpi_evaluate_lck(ds->handle, 0);
598 acpi_evaluate_ej0(ds->handle);
599 if (dock_present(ds)) {
600 acpi_handle_err(ds->handle, "Unable to undock!\n");
608 * dock_notify - act upon an acpi dock notification
609 * @handle: the dock station handle
610 * @event: the acpi event
611 * @data: our driver data struct
613 * If we are notified to dock, then check to see if the dock is
614 * present and then dock. Notify all drivers of the dock event,
615 * and then hotplug and devices that may need hotplugging.
617 static void dock_notify(acpi_handle handle, u32 event, void *data)
619 struct dock_station *ds = data;
620 struct acpi_device *tmp;
621 int surprise_removal = 0;
624 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
625 * is sent and _DCK is present, it is assumed to mean an undock
628 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK)
629 event = ACPI_NOTIFY_EJECT_REQUEST;
632 * dock station: BUS_CHECK - docked or surprise removal
633 * DEVICE_CHECK - undocked
634 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
636 * To simplify event handling, dock dependent device handler always
637 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
638 * ACPI_NOTIFY_EJECT_REQUEST for removal
641 case ACPI_NOTIFY_BUS_CHECK:
642 case ACPI_NOTIFY_DEVICE_CHECK:
643 if (!dock_in_progress(ds) && acpi_bus_get_device(ds->handle,
647 if (!dock_present(ds)) {
648 acpi_handle_err(handle, "Unable to dock!\n");
652 atomic_notifier_call_chain(&dock_notifier_list,
654 hotplug_dock_devices(ds, event);
656 dock_event(ds, event, DOCK_EVENT);
657 acpi_evaluate_lck(ds->handle, 1);
658 acpi_update_all_gpes();
661 if (dock_present(ds) || dock_in_progress(ds))
663 /* This is a surprise removal */
664 surprise_removal = 1;
665 event = ACPI_NOTIFY_EJECT_REQUEST;
667 case ACPI_NOTIFY_EJECT_REQUEST:
669 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
671 handle_eject_request(ds, event);
673 dock_event(ds, event, UNDOCK_EVENT);
676 acpi_handle_err(handle, "Unknown dock event %d\n", event);
683 struct dock_station *ds;
686 static void acpi_dock_deferred_cb(void *context)
688 struct dock_data *data = context;
690 acpi_scan_lock_acquire();
691 dock_notify(data->handle, data->event, data->ds);
692 acpi_scan_lock_release();
696 static int acpi_dock_notifier_call(struct notifier_block *this,
697 unsigned long event, void *data)
699 struct dock_station *dock_station;
700 acpi_handle handle = data;
702 if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK
703 && event != ACPI_NOTIFY_EJECT_REQUEST)
706 acpi_scan_lock_acquire();
708 list_for_each_entry(dock_station, &dock_stations, sibling) {
709 if (dock_station->handle == handle) {
710 struct dock_data *dd;
713 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
719 dd->ds = dock_station;
720 status = acpi_os_hotplug_execute(acpi_dock_deferred_cb,
722 if (ACPI_FAILURE(status))
729 acpi_scan_lock_release();
733 static struct notifier_block dock_acpi_notifier = {
734 .notifier_call = acpi_dock_notifier_call,
738 * find_dock_devices - find devices on the dock station
739 * @handle: the handle of the device we are examining
741 * @context: the dock station private data
744 * This function is called by acpi_walk_namespace. It will
745 * check to see if an object has an _EJD method. If it does, then it
746 * will see if it is dependent on the dock station.
748 static acpi_status __init
749 find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
752 acpi_handle tmp, parent;
753 struct dock_station *ds = context;
755 status = acpi_bus_get_ejd(handle, &tmp);
756 if (ACPI_FAILURE(status)) {
757 /* try the parent device as well */
758 status = acpi_get_parent(handle, &parent);
759 if (ACPI_FAILURE(status))
761 /* see if parent is dependent on dock */
762 status = acpi_bus_get_ejd(parent, &tmp);
763 if (ACPI_FAILURE(status))
767 if (tmp == ds->handle)
768 add_dock_dependent_device(ds, handle);
775 * show_docked - read method for "docked" file in sysfs
777 static ssize_t show_docked(struct device *dev,
778 struct device_attribute *attr, char *buf)
780 struct acpi_device *tmp;
782 struct dock_station *dock_station = dev->platform_data;
784 if (!acpi_bus_get_device(dock_station->handle, &tmp))
785 return snprintf(buf, PAGE_SIZE, "1\n");
786 return snprintf(buf, PAGE_SIZE, "0\n");
788 static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
791 * show_flags - read method for flags file in sysfs
793 static ssize_t show_flags(struct device *dev,
794 struct device_attribute *attr, char *buf)
796 struct dock_station *dock_station = dev->platform_data;
797 return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
800 static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
803 * write_undock - write method for "undock" file in sysfs
805 static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
806 const char *buf, size_t count)
809 struct dock_station *dock_station = dev->platform_data;
814 acpi_scan_lock_acquire();
815 begin_undock(dock_station);
816 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
817 acpi_scan_lock_release();
818 return ret ? ret: count;
820 static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
823 * show_dock_uid - read method for "uid" file in sysfs
825 static ssize_t show_dock_uid(struct device *dev,
826 struct device_attribute *attr, char *buf)
828 unsigned long long lbuf;
829 struct dock_station *dock_station = dev->platform_data;
830 acpi_status status = acpi_evaluate_integer(dock_station->handle,
831 "_UID", NULL, &lbuf);
832 if (ACPI_FAILURE(status))
835 return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
837 static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
839 static ssize_t show_dock_type(struct device *dev,
840 struct device_attribute *attr, char *buf)
842 struct dock_station *dock_station = dev->platform_data;
845 if (dock_station->flags & DOCK_IS_DOCK)
846 type = "dock_station";
847 else if (dock_station->flags & DOCK_IS_ATA)
849 else if (dock_station->flags & DOCK_IS_BAT)
850 type = "battery_bay";
854 return snprintf(buf, PAGE_SIZE, "%s\n", type);
856 static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
858 static struct attribute *dock_attributes[] = {
859 &dev_attr_docked.attr,
860 &dev_attr_flags.attr,
861 &dev_attr_undock.attr,
867 static struct attribute_group dock_attribute_group = {
868 .attrs = dock_attributes
872 * dock_add - add a new dock station
873 * @handle: the dock station handle
875 * allocated and initialize a new dock station device. Find all devices
876 * that are on the dock station, and register for dock event notifications.
878 static int __init dock_add(acpi_handle handle)
881 struct dock_station ds, *dock_station;
882 struct platform_device *dd;
884 id = dock_station_count;
885 memset(&ds, 0, sizeof(ds));
886 dd = platform_device_register_data(NULL, "dock", id, &ds, sizeof(ds));
890 dock_station = dd->dev.platform_data;
892 dock_station->handle = handle;
893 dock_station->dock_device = dd;
894 dock_station->last_dock_time = jiffies - HZ;
896 mutex_init(&dock_station->hp_lock);
897 INIT_LIST_HEAD(&dock_station->sibling);
898 INIT_LIST_HEAD(&dock_station->dependent_devices);
900 /* we want the dock device to send uevents */
901 dev_set_uevent_suppress(&dd->dev, 0);
903 if (acpi_dock_match(handle))
904 dock_station->flags |= DOCK_IS_DOCK;
905 if (acpi_ata_match(handle))
906 dock_station->flags |= DOCK_IS_ATA;
907 if (is_battery(handle))
908 dock_station->flags |= DOCK_IS_BAT;
910 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
914 /* Find dependent devices */
915 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
916 ACPI_UINT32_MAX, find_dock_devices, NULL,
919 /* add the dock station as a device dependent on itself */
920 ret = add_dock_dependent_device(dock_station, handle);
924 dock_station_count++;
925 list_add(&dock_station->sibling, &dock_stations);
929 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
931 platform_device_unregister(dd);
932 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
937 * find_dock_and_bay - look for dock stations and bays
938 * @handle: acpi handle of a device
943 * This is called by acpi_walk_namespace to look for dock stations and bays.
945 static __init acpi_status
946 find_dock_and_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
948 if (acpi_dock_match(handle) || is_ejectable_bay(handle))
954 void __init acpi_dock_init(void)
959 /* look for dock stations and bays */
960 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
961 ACPI_UINT32_MAX, find_dock_and_bay, NULL, NULL, NULL);
963 if (!dock_station_count) {
964 pr_info(PREFIX "No dock devices found.\n");
968 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
969 register_acpi_bus_notifier(&dock_acpi_notifier);
970 pr_info(PREFIX "%s: %d docks/bays found\n",
971 ACPI_DOCK_DRIVER_DESCRIPTION, dock_station_count);