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
;
68 struct list_head dependent_devices
;
69 struct list_head hotplug_devices
;
71 struct list_head sibling
;
72 struct platform_device
*dock_device
;
74 static LIST_HEAD(dock_stations
);
75 static int dock_station_count
;
77 struct dock_dependent_device
{
78 struct list_head list
;
79 struct list_head hotplug_list
;
81 const struct acpi_dock_ops
*ops
;
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 INIT_LIST_HEAD(&dd
->hotplug_list
);
116 spin_lock(&ds
->dd_lock
);
117 list_add_tail(&dd
->list
, &ds
->dependent_devices
);
118 spin_unlock(&ds
->dd_lock
);
124 * dock_add_hotplug_device - associate a hotplug handler with the dock station
125 * @ds: The dock station
126 * @dd: The dependent device struct
128 * Add the dependent device to the dock's hotplug device list
131 dock_add_hotplug_device(struct dock_station
*ds
,
132 struct dock_dependent_device
*dd
)
134 mutex_lock(&ds
->hp_lock
);
135 list_add_tail(&dd
->hotplug_list
, &ds
->hotplug_devices
);
136 mutex_unlock(&ds
->hp_lock
);
140 * dock_del_hotplug_device - remove a hotplug handler from the dock station
141 * @ds: The dock station
142 * @dd: the dependent device struct
144 * Delete the dependent device from the dock's hotplug device list
147 dock_del_hotplug_device(struct dock_station
*ds
,
148 struct dock_dependent_device
*dd
)
150 mutex_lock(&ds
->hp_lock
);
151 list_del(&dd
->hotplug_list
);
152 mutex_unlock(&ds
->hp_lock
);
156 * find_dock_dependent_device - get a device dependent on this dock
157 * @ds: the dock station
158 * @handle: the acpi_handle of the device we want
160 * iterate over the dependent device list for this dock. If the
161 * dependent device matches the handle, return.
163 static struct dock_dependent_device
*
164 find_dock_dependent_device(struct dock_station
*ds
, acpi_handle handle
)
166 struct dock_dependent_device
*dd
;
168 spin_lock(&ds
->dd_lock
);
169 list_for_each_entry(dd
, &ds
->dependent_devices
, list
) {
170 if (handle
== dd
->handle
) {
171 spin_unlock(&ds
->dd_lock
);
175 spin_unlock(&ds
->dd_lock
);
179 /*****************************************************************************
181 *****************************************************************************/
183 * is_dock - see if a device is a dock station
184 * @handle: acpi handle of the device
186 * If an acpi object has a _DCK method, then it is by definition a dock
187 * station, so return true.
189 static int is_dock(acpi_handle handle
)
194 status
= acpi_get_handle(handle
, "_DCK", &tmp
);
195 if (ACPI_FAILURE(status
))
200 static int is_ejectable(acpi_handle handle
)
205 status
= acpi_get_handle(handle
, "_EJ0", &tmp
);
206 if (ACPI_FAILURE(status
))
211 static int is_ata(acpi_handle handle
)
215 if ((ACPI_SUCCESS(acpi_get_handle(handle
, "_GTF", &tmp
))) ||
216 (ACPI_SUCCESS(acpi_get_handle(handle
, "_GTM", &tmp
))) ||
217 (ACPI_SUCCESS(acpi_get_handle(handle
, "_STM", &tmp
))) ||
218 (ACPI_SUCCESS(acpi_get_handle(handle
, "_SDD", &tmp
))))
224 static int is_battery(acpi_handle handle
)
226 struct acpi_device_info
*info
;
229 if (!ACPI_SUCCESS(acpi_get_object_info(handle
, &info
)))
231 if (!(info
->valid
& ACPI_VALID_HID
))
234 ret
= !strcmp("PNP0C0A", info
->hardware_id
.string
);
240 static int is_ejectable_bay(acpi_handle handle
)
244 if (!is_ejectable(handle
))
246 if (is_battery(handle
) || is_ata(handle
))
248 if (!acpi_get_parent(handle
, &phandle
) && is_ata(phandle
))
254 * is_dock_device - see if a device is on a dock station
255 * @handle: acpi handle of the device
257 * If this device is either the dock station itself,
258 * or is a device dependent on the dock station, then it
261 int is_dock_device(acpi_handle handle
)
263 struct dock_station
*dock_station
;
265 if (!dock_station_count
)
271 list_for_each_entry(dock_station
, &dock_stations
, sibling
)
272 if (find_dock_dependent_device(dock_station
, handle
))
277 EXPORT_SYMBOL_GPL(is_dock_device
);
280 * dock_present - see if the dock station is present.
281 * @ds: the dock station
283 * execute the _STA method. note that present does not
284 * imply that we are docked.
286 static int dock_present(struct dock_station
*ds
)
288 unsigned long long sta
;
292 status
= acpi_evaluate_integer(ds
->handle
, "_STA", NULL
, &sta
);
293 if (ACPI_SUCCESS(status
) && sta
)
300 * dock_create_acpi_device - add new devices to acpi
301 * @handle - handle of the device to add
303 * This function will create a new acpi_device for the given
304 * handle if one does not exist already. This should cause
305 * acpi to scan for drivers for the given devices, and call
306 * matching driver's add routine.
308 * Returns a pointer to the acpi_device corresponding to the handle.
310 static struct acpi_device
* dock_create_acpi_device(acpi_handle handle
)
312 struct acpi_device
*device
;
315 if (acpi_bus_get_device(handle
, &device
)) {
317 * no device created for this object,
318 * so we should create one.
320 ret
= acpi_bus_scan(handle
);
322 pr_debug("error adding bus, %x\n", -ret
);
324 acpi_bus_get_device(handle
, &device
);
330 * dock_remove_acpi_device - remove the acpi_device struct from acpi
331 * @handle - the handle of the device to remove
333 * Tell acpi to remove the acpi_device. This should cause any loaded
334 * driver to have it's remove routine called.
336 static void dock_remove_acpi_device(acpi_handle handle
)
338 struct acpi_device
*device
;
340 if (!acpi_bus_get_device(handle
, &device
))
341 acpi_bus_trim(device
);
345 * hotplug_dock_devices - insert or remove devices on the dock station
346 * @ds: the dock station
347 * @event: either bus check or eject request
349 * Some devices on the dock station need to have drivers called
350 * to perform hotplug operations after a dock event has occurred.
351 * Traverse the list of dock devices that have registered a
352 * hotplug handler, and call the handler.
354 static void hotplug_dock_devices(struct dock_station
*ds
, u32 event
)
356 struct dock_dependent_device
*dd
;
358 mutex_lock(&ds
->hp_lock
);
361 * First call driver specific hotplug functions
363 list_for_each_entry(dd
, &ds
->hotplug_devices
, hotplug_list
)
364 if (dd
->ops
&& dd
->ops
->handler
)
365 dd
->ops
->handler(dd
->handle
, event
, dd
->context
);
368 * Now make sure that an acpi_device is created for each
369 * dependent device, or removed if this is an eject request.
370 * This will cause acpi_drivers to be stopped/started if they
373 list_for_each_entry(dd
, &ds
->dependent_devices
, list
) {
374 if (event
== ACPI_NOTIFY_EJECT_REQUEST
)
375 dock_remove_acpi_device(dd
->handle
);
377 dock_create_acpi_device(dd
->handle
);
379 mutex_unlock(&ds
->hp_lock
);
382 static void dock_event(struct dock_station
*ds
, u32 event
, int num
)
384 struct device
*dev
= &ds
->dock_device
->dev
;
385 char event_string
[13];
386 char *envp
[] = { event_string
, NULL
};
387 struct dock_dependent_device
*dd
;
389 if (num
== UNDOCK_EVENT
)
390 sprintf(event_string
, "EVENT=undock");
392 sprintf(event_string
, "EVENT=dock");
395 * Indicate that the status of the dock station has
398 if (num
== DOCK_EVENT
)
399 kobject_uevent_env(&dev
->kobj
, KOBJ_CHANGE
, envp
);
401 list_for_each_entry(dd
, &ds
->hotplug_devices
, hotplug_list
)
402 if (dd
->ops
&& dd
->ops
->uevent
)
403 dd
->ops
->uevent(dd
->handle
, event
, dd
->context
);
405 if (num
!= DOCK_EVENT
)
406 kobject_uevent_env(&dev
->kobj
, KOBJ_CHANGE
, envp
);
410 * eject_dock - respond to a dock eject request
411 * @ds: the dock station
413 * This is called after _DCK is called, to execute the dock station's
416 static void eject_dock(struct dock_station
*ds
)
418 struct acpi_object_list arg_list
;
419 union acpi_object arg
;
423 /* all dock devices should have _EJ0, but check anyway */
424 status
= acpi_get_handle(ds
->handle
, "_EJ0", &tmp
);
425 if (ACPI_FAILURE(status
)) {
426 pr_debug("No _EJ0 support for dock device\n");
431 arg_list
.pointer
= &arg
;
432 arg
.type
= ACPI_TYPE_INTEGER
;
433 arg
.integer
.value
= 1;
435 status
= acpi_evaluate_object(ds
->handle
, "_EJ0", &arg_list
, NULL
);
436 if (ACPI_FAILURE(status
))
437 pr_debug("Failed to evaluate _EJ0!\n");
441 * handle_dock - handle a dock event
442 * @ds: the dock station
443 * @dock: to dock, or undock - that is the question
445 * Execute the _DCK method in response to an acpi event
447 static void handle_dock(struct dock_station
*ds
, int dock
)
450 struct acpi_object_list arg_list
;
451 union acpi_object arg
;
452 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
454 acpi_handle_info(ds
->handle
, "%s\n", dock
? "docking" : "undocking");
456 /* _DCK method has one argument */
458 arg_list
.pointer
= &arg
;
459 arg
.type
= ACPI_TYPE_INTEGER
;
460 arg
.integer
.value
= dock
;
461 status
= acpi_evaluate_object(ds
->handle
, "_DCK", &arg_list
, &buffer
);
462 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
)
463 acpi_handle_err(ds
->handle
, "Failed to execute _DCK (0x%x)\n",
466 kfree(buffer
.pointer
);
469 static inline void dock(struct dock_station
*ds
)
474 static inline void undock(struct dock_station
*ds
)
479 static inline void begin_dock(struct dock_station
*ds
)
481 ds
->flags
|= DOCK_DOCKING
;
484 static inline void complete_dock(struct dock_station
*ds
)
486 ds
->flags
&= ~(DOCK_DOCKING
);
487 ds
->last_dock_time
= jiffies
;
490 static inline void begin_undock(struct dock_station
*ds
)
492 ds
->flags
|= DOCK_UNDOCKING
;
495 static inline void complete_undock(struct dock_station
*ds
)
497 ds
->flags
&= ~(DOCK_UNDOCKING
);
500 static void dock_lock(struct dock_station
*ds
, int lock
)
502 struct acpi_object_list arg_list
;
503 union acpi_object arg
;
507 arg_list
.pointer
= &arg
;
508 arg
.type
= ACPI_TYPE_INTEGER
;
509 arg
.integer
.value
= !!lock
;
510 status
= acpi_evaluate_object(ds
->handle
, "_LCK", &arg_list
, NULL
);
511 if (ACPI_FAILURE(status
) && status
!= AE_NOT_FOUND
) {
513 acpi_handle_warn(ds
->handle
,
514 "Locking device failed (0x%x)\n", status
);
516 acpi_handle_warn(ds
->handle
,
517 "Unlocking device failed (0x%x)\n", status
);
522 * dock_in_progress - see if we are in the middle of handling a dock event
523 * @ds: the dock station
525 * Sometimes while docking, false dock events can be sent to the driver
526 * because good connections aren't made or some other reason. Ignore these
527 * if we are in the middle of doing something.
529 static int dock_in_progress(struct dock_station
*ds
)
531 if ((ds
->flags
& DOCK_DOCKING
) ||
532 time_before(jiffies
, (ds
->last_dock_time
+ HZ
)))
538 * register_dock_notifier - add yourself to the dock notifier list
539 * @nb: the callers notifier block
541 * If a driver wishes to be notified about dock events, they can
542 * use this function to put a notifier block on the dock notifier list.
543 * this notifier call chain will be called after a dock event, but
544 * before hotplugging any new devices.
546 int register_dock_notifier(struct notifier_block
*nb
)
548 if (!dock_station_count
)
551 return atomic_notifier_chain_register(&dock_notifier_list
, nb
);
553 EXPORT_SYMBOL_GPL(register_dock_notifier
);
556 * unregister_dock_notifier - remove yourself from the dock notifier list
557 * @nb: the callers notifier block
559 void unregister_dock_notifier(struct notifier_block
*nb
)
561 if (!dock_station_count
)
564 atomic_notifier_chain_unregister(&dock_notifier_list
, nb
);
566 EXPORT_SYMBOL_GPL(unregister_dock_notifier
);
569 * register_hotplug_dock_device - register a hotplug function
570 * @handle: the handle of the device
571 * @ops: handlers to call after docking
572 * @context: device specific data
574 * If a driver would like to perform a hotplug operation after a dock
575 * event, they can register an acpi_notifiy_handler to be called by
576 * the dock driver after _DCK is executed.
579 register_hotplug_dock_device(acpi_handle handle
, const struct acpi_dock_ops
*ops
,
582 struct dock_dependent_device
*dd
;
583 struct dock_station
*dock_station
;
586 if (!dock_station_count
)
590 * make sure this handle is for a device dependent on the dock,
591 * this would include the dock station itself
593 list_for_each_entry(dock_station
, &dock_stations
, sibling
) {
595 * An ATA bay can be in a dock and itself can be ejected
596 * separately, so there are two 'dock stations' which need the
599 dd
= find_dock_dependent_device(dock_station
, handle
);
602 dd
->context
= context
;
603 dock_add_hotplug_device(dock_station
, dd
);
610 EXPORT_SYMBOL_GPL(register_hotplug_dock_device
);
613 * unregister_hotplug_dock_device - remove yourself from the hotplug list
614 * @handle: the acpi handle of the device
616 void unregister_hotplug_dock_device(acpi_handle handle
)
618 struct dock_dependent_device
*dd
;
619 struct dock_station
*dock_station
;
621 if (!dock_station_count
)
624 list_for_each_entry(dock_station
, &dock_stations
, sibling
) {
625 dd
= find_dock_dependent_device(dock_station
, handle
);
627 dock_del_hotplug_device(dock_station
, dd
);
630 EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device
);
633 * handle_eject_request - handle an undock request checking for error conditions
635 * Check to make sure the dock device is still present, then undock and
636 * hotremove all the devices that may need removing.
638 static int handle_eject_request(struct dock_station
*ds
, u32 event
)
640 if (dock_in_progress(ds
))
644 * here we need to generate the undock
645 * event prior to actually doing the undock
646 * so that the device struct still exists.
647 * Also, even send the dock event if the
648 * device is not present anymore
650 dock_event(ds
, event
, UNDOCK_EVENT
);
652 hotplug_dock_devices(ds
, ACPI_NOTIFY_EJECT_REQUEST
);
656 if (dock_present(ds
)) {
657 acpi_handle_err(ds
->handle
, "Unable to undock!\n");
665 * dock_notify - act upon an acpi dock notification
666 * @handle: the dock station handle
667 * @event: the acpi event
668 * @data: our driver data struct
670 * If we are notified to dock, then check to see if the dock is
671 * present and then dock. Notify all drivers of the dock event,
672 * and then hotplug and devices that may need hotplugging.
674 static void dock_notify(acpi_handle handle
, u32 event
, void *data
)
676 struct dock_station
*ds
= data
;
677 struct acpi_device
*tmp
;
678 int surprise_removal
= 0;
681 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
682 * is sent and _DCK is present, it is assumed to mean an undock
685 if ((ds
->flags
& DOCK_IS_DOCK
) && event
== ACPI_NOTIFY_DEVICE_CHECK
)
686 event
= ACPI_NOTIFY_EJECT_REQUEST
;
689 * dock station: BUS_CHECK - docked or surprise removal
690 * DEVICE_CHECK - undocked
691 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
693 * To simplify event handling, dock dependent device handler always
694 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
695 * ACPI_NOTIFY_EJECT_REQUEST for removal
698 case ACPI_NOTIFY_BUS_CHECK
:
699 case ACPI_NOTIFY_DEVICE_CHECK
:
700 if (!dock_in_progress(ds
) && acpi_bus_get_device(ds
->handle
,
704 if (!dock_present(ds
)) {
705 acpi_handle_err(handle
, "Unable to dock!\n");
709 atomic_notifier_call_chain(&dock_notifier_list
,
711 hotplug_dock_devices(ds
, event
);
713 dock_event(ds
, event
, DOCK_EVENT
);
715 acpi_update_all_gpes();
718 if (dock_present(ds
) || dock_in_progress(ds
))
720 /* This is a surprise removal */
721 surprise_removal
= 1;
722 event
= ACPI_NOTIFY_EJECT_REQUEST
;
724 case ACPI_NOTIFY_EJECT_REQUEST
:
726 if ((immediate_undock
&& !(ds
->flags
& DOCK_IS_ATA
))
728 handle_eject_request(ds
, event
);
730 dock_event(ds
, event
, UNDOCK_EVENT
);
733 acpi_handle_err(handle
, "Unknown dock event %d\n", event
);
740 struct dock_station
*ds
;
743 static void acpi_dock_deferred_cb(void *context
)
745 struct dock_data
*data
= context
;
747 acpi_scan_lock_acquire();
748 dock_notify(data
->handle
, data
->event
, data
->ds
);
749 acpi_scan_lock_release();
753 static int acpi_dock_notifier_call(struct notifier_block
*this,
754 unsigned long event
, void *data
)
756 struct dock_station
*dock_station
;
757 acpi_handle handle
= data
;
759 if (event
!= ACPI_NOTIFY_BUS_CHECK
&& event
!= ACPI_NOTIFY_DEVICE_CHECK
760 && event
!= ACPI_NOTIFY_EJECT_REQUEST
)
763 acpi_scan_lock_acquire();
765 list_for_each_entry(dock_station
, &dock_stations
, sibling
) {
766 if (dock_station
->handle
== handle
) {
767 struct dock_data
*dd
;
770 dd
= kmalloc(sizeof(*dd
), GFP_KERNEL
);
776 dd
->ds
= dock_station
;
777 status
= acpi_os_hotplug_execute(acpi_dock_deferred_cb
,
779 if (ACPI_FAILURE(status
))
786 acpi_scan_lock_release();
790 static struct notifier_block dock_acpi_notifier
= {
791 .notifier_call
= acpi_dock_notifier_call
,
795 * find_dock_devices - find devices on the dock station
796 * @handle: the handle of the device we are examining
798 * @context: the dock station private data
801 * This function is called by acpi_walk_namespace. It will
802 * check to see if an object has an _EJD method. If it does, then it
803 * will see if it is dependent on the dock station.
806 find_dock_devices(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
809 acpi_handle tmp
, parent
;
810 struct dock_station
*ds
= context
;
812 status
= acpi_bus_get_ejd(handle
, &tmp
);
813 if (ACPI_FAILURE(status
)) {
814 /* try the parent device as well */
815 status
= acpi_get_parent(handle
, &parent
);
816 if (ACPI_FAILURE(status
))
818 /* see if parent is dependent on dock */
819 status
= acpi_bus_get_ejd(parent
, &tmp
);
820 if (ACPI_FAILURE(status
))
824 if (tmp
== ds
->handle
)
825 add_dock_dependent_device(ds
, handle
);
832 * show_docked - read method for "docked" file in sysfs
834 static ssize_t
show_docked(struct device
*dev
,
835 struct device_attribute
*attr
, char *buf
)
837 struct acpi_device
*tmp
;
839 struct dock_station
*dock_station
= dev
->platform_data
;
841 if (!acpi_bus_get_device(dock_station
->handle
, &tmp
))
842 return snprintf(buf
, PAGE_SIZE
, "1\n");
843 return snprintf(buf
, PAGE_SIZE
, "0\n");
845 static DEVICE_ATTR(docked
, S_IRUGO
, show_docked
, NULL
);
848 * show_flags - read method for flags file in sysfs
850 static ssize_t
show_flags(struct device
*dev
,
851 struct device_attribute
*attr
, char *buf
)
853 struct dock_station
*dock_station
= dev
->platform_data
;
854 return snprintf(buf
, PAGE_SIZE
, "%d\n", dock_station
->flags
);
857 static DEVICE_ATTR(flags
, S_IRUGO
, show_flags
, NULL
);
860 * write_undock - write method for "undock" file in sysfs
862 static ssize_t
write_undock(struct device
*dev
, struct device_attribute
*attr
,
863 const char *buf
, size_t count
)
866 struct dock_station
*dock_station
= dev
->platform_data
;
871 begin_undock(dock_station
);
872 ret
= handle_eject_request(dock_station
, ACPI_NOTIFY_EJECT_REQUEST
);
873 return ret
? ret
: count
;
875 static DEVICE_ATTR(undock
, S_IWUSR
, NULL
, write_undock
);
878 * show_dock_uid - read method for "uid" file in sysfs
880 static ssize_t
show_dock_uid(struct device
*dev
,
881 struct device_attribute
*attr
, char *buf
)
883 unsigned long long lbuf
;
884 struct dock_station
*dock_station
= dev
->platform_data
;
885 acpi_status status
= acpi_evaluate_integer(dock_station
->handle
,
886 "_UID", NULL
, &lbuf
);
887 if (ACPI_FAILURE(status
))
890 return snprintf(buf
, PAGE_SIZE
, "%llx\n", lbuf
);
892 static DEVICE_ATTR(uid
, S_IRUGO
, show_dock_uid
, NULL
);
894 static ssize_t
show_dock_type(struct device
*dev
,
895 struct device_attribute
*attr
, char *buf
)
897 struct dock_station
*dock_station
= dev
->platform_data
;
900 if (dock_station
->flags
& DOCK_IS_DOCK
)
901 type
= "dock_station";
902 else if (dock_station
->flags
& DOCK_IS_ATA
)
904 else if (dock_station
->flags
& DOCK_IS_BAT
)
905 type
= "battery_bay";
909 return snprintf(buf
, PAGE_SIZE
, "%s\n", type
);
911 static DEVICE_ATTR(type
, S_IRUGO
, show_dock_type
, NULL
);
913 static struct attribute
*dock_attributes
[] = {
914 &dev_attr_docked
.attr
,
915 &dev_attr_flags
.attr
,
916 &dev_attr_undock
.attr
,
922 static struct attribute_group dock_attribute_group
= {
923 .attrs
= dock_attributes
927 * dock_add - add a new dock station
928 * @handle: the dock station handle
930 * allocated and initialize a new dock station device. Find all devices
931 * that are on the dock station, and register for dock event notifications.
933 static int __init
dock_add(acpi_handle handle
)
936 struct dock_station ds
, *dock_station
;
937 struct platform_device
*dd
;
939 id
= dock_station_count
;
940 memset(&ds
, 0, sizeof(ds
));
941 dd
= platform_device_register_data(NULL
, "dock", id
, &ds
, sizeof(ds
));
945 dock_station
= dd
->dev
.platform_data
;
947 dock_station
->handle
= handle
;
948 dock_station
->dock_device
= dd
;
949 dock_station
->last_dock_time
= jiffies
- HZ
;
951 mutex_init(&dock_station
->hp_lock
);
952 spin_lock_init(&dock_station
->dd_lock
);
953 INIT_LIST_HEAD(&dock_station
->sibling
);
954 INIT_LIST_HEAD(&dock_station
->hotplug_devices
);
955 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list
);
956 INIT_LIST_HEAD(&dock_station
->dependent_devices
);
958 /* we want the dock device to send uevents */
959 dev_set_uevent_suppress(&dd
->dev
, 0);
962 dock_station
->flags
|= DOCK_IS_DOCK
;
964 dock_station
->flags
|= DOCK_IS_ATA
;
965 if (is_battery(handle
))
966 dock_station
->flags
|= DOCK_IS_BAT
;
968 ret
= sysfs_create_group(&dd
->dev
.kobj
, &dock_attribute_group
);
972 /* Find dependent devices */
973 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
974 ACPI_UINT32_MAX
, find_dock_devices
, NULL
,
977 /* add the dock station as a device dependent on itself */
978 ret
= add_dock_dependent_device(dock_station
, handle
);
982 dock_station_count
++;
983 list_add(&dock_station
->sibling
, &dock_stations
);
987 sysfs_remove_group(&dd
->dev
.kobj
, &dock_attribute_group
);
989 platform_device_unregister(dd
);
990 acpi_handle_err(handle
, "%s encountered error %d\n", __func__
, ret
);
995 * dock_remove - free up resources related to the dock station
997 static int dock_remove(struct dock_station
*ds
)
999 struct dock_dependent_device
*dd
, *tmp
;
1000 struct platform_device
*dock_device
= ds
->dock_device
;
1002 if (!dock_station_count
)
1005 /* remove dependent devices */
1006 list_for_each_entry_safe(dd
, tmp
, &ds
->dependent_devices
, list
)
1009 list_del(&ds
->sibling
);
1012 sysfs_remove_group(&dock_device
->dev
.kobj
, &dock_attribute_group
);
1013 platform_device_unregister(dock_device
);
1019 * find_dock_and_bay - look for dock stations and bays
1020 * @handle: acpi handle of a device
1025 * This is called by acpi_walk_namespace to look for dock stations and bays.
1027 static __init acpi_status
1028 find_dock_and_bay(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
1030 if (is_dock(handle
) || is_ejectable_bay(handle
))
1036 static int __init
dock_init(void)
1041 /* look for dock stations and bays */
1042 acpi_walk_namespace(ACPI_TYPE_DEVICE
, ACPI_ROOT_OBJECT
,
1043 ACPI_UINT32_MAX
, find_dock_and_bay
, NULL
, NULL
, NULL
);
1045 if (!dock_station_count
) {
1046 pr_info(PREFIX
"No dock devices found.\n");
1050 register_acpi_bus_notifier(&dock_acpi_notifier
);
1051 pr_info(PREFIX
"%s: %d docks/bays found\n",
1052 ACPI_DOCK_DRIVER_DESCRIPTION
, dock_station_count
);
1056 static void __exit
dock_exit(void)
1058 struct dock_station
*tmp
, *dock_station
;
1060 unregister_acpi_bus_notifier(&dock_acpi_notifier
);
1061 list_for_each_entry_safe(dock_station
, tmp
, &dock_stations
, sibling
)
1062 dock_remove(dock_station
);
1066 * Must be called before drivers of devices in dock, otherwise we can't know
1067 * which devices are in a dock
1069 subsys_initcall(dock_init
);
1070 module_exit(dock_exit
);