1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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>
37
38#define PREFIX "ACPI: "
39
40#define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
41
42ACPI_MODULE_NAME("dock");
43MODULE_AUTHOR("Kristen Carlson Accardi");
44MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
45MODULE_LICENSE("GPL");
46
47static bool immediate_undock = 1;
48module_param(immediate_undock, bool, 0644);
49MODULE_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 "
52 " before undocking");
53
54static struct atomic_notifier_head dock_notifier_list;
55
56static const struct acpi_device_id dock_device_ids[] = {
57 {"LNXDOCK", 0},
58 {"", 0},
59};
60MODULE_DEVICE_TABLE(acpi, dock_device_ids);
61
62struct dock_station {
63 acpi_handle handle;
64 unsigned long last_dock_time;
65 u32 flags;
66 spinlock_t dd_lock;
67 struct mutex hp_lock;
68 struct list_head dependent_devices;
69
70 struct list_head sibling;
71 struct platform_device *dock_device;
72};
73static LIST_HEAD(dock_stations);
74static int dock_station_count;
75static DEFINE_MUTEX(hotplug_lock);
76
77struct dock_dependent_device {
78 struct list_head list;
79 acpi_handle handle;
80 const struct acpi_dock_ops *hp_ops;
81 void *hp_context;
82 unsigned int hp_refcount;
83 void (*hp_release)(void *);
84};
85
86#define DOCK_DOCKING 0x00000001
87#define DOCK_UNDOCKING 0x00000002
88#define DOCK_IS_DOCK 0x00000010
89#define DOCK_IS_ATA 0x00000020
90#define DOCK_IS_BAT 0x00000040
91#define DOCK_EVENT 3
92#define UNDOCK_EVENT 2
93
94
95
96
97
98
99
100
101
102
103
104static int
105add_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
106{
107 struct dock_dependent_device *dd;
108
109 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
110 if (!dd)
111 return -ENOMEM;
112
113 dd->handle = handle;
114 INIT_LIST_HEAD(&dd->list);
115
116 spin_lock(&ds->dd_lock);
117 list_add_tail(&dd->list, &ds->dependent_devices);
118 spin_unlock(&ds->dd_lock);
119
120 return 0;
121}
122
123
124
125
126
127
128
129
130
131static int dock_init_hotplug(struct dock_dependent_device *dd,
132 const struct acpi_dock_ops *ops, void *context,
133 void (*init)(void *), void (*release)(void *))
134{
135 int ret = 0;
136
137 mutex_lock(&hotplug_lock);
138
139 if (dd->hp_context) {
140 ret = -EEXIST;
141 } else {
142 dd->hp_refcount = 1;
143 dd->hp_ops = ops;
144 dd->hp_context = context;
145 dd->hp_release = release;
146 }
147
148 if (!WARN_ON(ret) && init)
149 init(context);
150
151 mutex_unlock(&hotplug_lock);
152 return ret;
153}
154
155
156
157
158
159
160
161
162
163static void dock_release_hotplug(struct dock_dependent_device *dd)
164{
165 void (*release)(void *) = NULL;
166 void *context = NULL;
167
168 mutex_lock(&hotplug_lock);
169
170 if (dd->hp_context && !--dd->hp_refcount) {
171 dd->hp_ops = NULL;
172 context = dd->hp_context;
173 dd->hp_context = NULL;
174 release = dd->hp_release;
175 dd->hp_release = NULL;
176 }
177
178 if (release && context)
179 release(context);
180
181 mutex_unlock(&hotplug_lock);
182}
183
184static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event,
185 bool uevent)
186{
187 acpi_notify_handler cb = NULL;
188 bool run = false;
189
190 mutex_lock(&hotplug_lock);
191
192 if (dd->hp_context) {
193 run = true;
194 dd->hp_refcount++;
195 if (dd->hp_ops)
196 cb = uevent ? dd->hp_ops->uevent : dd->hp_ops->handler;
197 }
198
199 mutex_unlock(&hotplug_lock);
200
201 if (!run)
202 return;
203
204 if (cb)
205 cb(dd->handle, event, dd->hp_context);
206
207 dock_release_hotplug(dd);
208}
209
210
211
212
213
214
215
216
217
218static struct dock_dependent_device *
219find_dock_dependent_device(struct dock_station *ds, acpi_handle handle)
220{
221 struct dock_dependent_device *dd;
222
223 spin_lock(&ds->dd_lock);
224 list_for_each_entry(dd, &ds->dependent_devices, list) {
225 if (handle == dd->handle) {
226 spin_unlock(&ds->dd_lock);
227 return dd;
228 }
229 }
230 spin_unlock(&ds->dd_lock);
231 return NULL;
232}
233
234
235
236
237
238
239
240
241
242
243
244static int is_dock(acpi_handle handle)
245{
246 acpi_status status;
247 acpi_handle tmp;
248
249 status = acpi_get_handle(handle, "_DCK", &tmp);
250 if (ACPI_FAILURE(status))
251 return 0;
252 return 1;
253}
254
255static int is_ejectable(acpi_handle handle)
256{
257 acpi_status status;
258 acpi_handle tmp;
259
260 status = acpi_get_handle(handle, "_EJ0", &tmp);
261 if (ACPI_FAILURE(status))
262 return 0;
263 return 1;
264}
265
266static int is_ata(acpi_handle handle)
267{
268 acpi_handle tmp;
269
270 if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) ||
271 (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) ||
272 (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) ||
273 (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp))))
274 return 1;
275
276 return 0;
277}
278
279static int is_battery(acpi_handle handle)
280{
281 struct acpi_device_info *info;
282 int ret = 1;
283
284 if (!ACPI_SUCCESS(acpi_get_object_info(handle, &info)))
285 return 0;
286 if (!(info->valid & ACPI_VALID_HID))
287 ret = 0;
288 else
289 ret = !strcmp("PNP0C0A", info->hardware_id.string);
290
291 kfree(info);
292 return ret;
293}
294
295static int is_ejectable_bay(acpi_handle handle)
296{
297 acpi_handle phandle;
298
299 if (!is_ejectable(handle))
300 return 0;
301 if (is_battery(handle) || is_ata(handle))
302 return 1;
303 if (!acpi_get_parent(handle, &phandle) && is_ata(phandle))
304 return 1;
305 return 0;
306}
307
308
309
310
311
312
313
314
315
316int is_dock_device(acpi_handle handle)
317{
318 struct dock_station *dock_station;
319
320 if (!dock_station_count)
321 return 0;
322
323 if (is_dock(handle))
324 return 1;
325
326 list_for_each_entry(dock_station, &dock_stations, sibling)
327 if (find_dock_dependent_device(dock_station, handle))
328 return 1;
329
330 return 0;
331}
332EXPORT_SYMBOL_GPL(is_dock_device);
333
334
335
336
337
338
339
340
341static int dock_present(struct dock_station *ds)
342{
343 unsigned long long sta;
344 acpi_status status;
345
346 if (ds) {
347 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
348 if (ACPI_SUCCESS(status) && sta)
349 return 1;
350 }
351 return 0;
352}
353
354
355
356
357
358
359
360
361
362
363
364
365static struct acpi_device * dock_create_acpi_device(acpi_handle handle)
366{
367 struct acpi_device *device;
368 int ret;
369
370 if (acpi_bus_get_device(handle, &device)) {
371
372
373
374
375 ret = acpi_bus_scan(handle);
376 if (ret)
377 pr_debug("error adding bus, %x\n", -ret);
378
379 acpi_bus_get_device(handle, &device);
380 }
381 return device;
382}
383
384
385
386
387
388
389
390
391static void dock_remove_acpi_device(acpi_handle handle)
392{
393 struct acpi_device *device;
394
395 if (!acpi_bus_get_device(handle, &device))
396 acpi_bus_trim(device);
397}
398
399
400
401
402
403
404
405
406
407
408
409static void hotplug_dock_devices(struct dock_station *ds, u32 event)
410{
411 struct dock_dependent_device *dd;
412
413 mutex_lock(&ds->hp_lock);
414
415
416
417
418 list_for_each_entry(dd, &ds->dependent_devices, list)
419 dock_hotplug_event(dd, event, false);
420
421
422
423
424
425
426
427 list_for_each_entry(dd, &ds->dependent_devices, list) {
428 if (event == ACPI_NOTIFY_EJECT_REQUEST)
429 dock_remove_acpi_device(dd->handle);
430 else
431 dock_create_acpi_device(dd->handle);
432 }
433 mutex_unlock(&ds->hp_lock);
434}
435
436static void dock_event(struct dock_station *ds, u32 event, int num)
437{
438 struct device *dev = &ds->dock_device->dev;
439 char event_string[13];
440 char *envp[] = { event_string, NULL };
441 struct dock_dependent_device *dd;
442
443 if (num == UNDOCK_EVENT)
444 sprintf(event_string, "EVENT=undock");
445 else
446 sprintf(event_string, "EVENT=dock");
447
448
449
450
451
452 if (num == DOCK_EVENT)
453 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
454
455 list_for_each_entry(dd, &ds->dependent_devices, list)
456 dock_hotplug_event(dd, event, true);
457
458 if (num != DOCK_EVENT)
459 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
460}
461
462
463
464
465
466
467
468
469static void eject_dock(struct dock_station *ds)
470{
471 struct acpi_object_list arg_list;
472 union acpi_object arg;
473 acpi_status status;
474 acpi_handle tmp;
475
476
477 status = acpi_get_handle(ds->handle, "_EJ0", &tmp);
478 if (ACPI_FAILURE(status)) {
479 pr_debug("No _EJ0 support for dock device\n");
480 return;
481 }
482
483 arg_list.count = 1;
484 arg_list.pointer = &arg;
485 arg.type = ACPI_TYPE_INTEGER;
486 arg.integer.value = 1;
487
488 status = acpi_evaluate_object(ds->handle, "_EJ0", &arg_list, NULL);
489 if (ACPI_FAILURE(status))
490 pr_debug("Failed to evaluate _EJ0!\n");
491}
492
493
494
495
496
497
498
499
500static void handle_dock(struct dock_station *ds, int dock)
501{
502 acpi_status status;
503 struct acpi_object_list arg_list;
504 union acpi_object arg;
505 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
506
507 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
508
509
510 arg_list.count = 1;
511 arg_list.pointer = &arg;
512 arg.type = ACPI_TYPE_INTEGER;
513 arg.integer.value = dock;
514 status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer);
515 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
516 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
517 status);
518
519 kfree(buffer.pointer);
520}
521
522static inline void dock(struct dock_station *ds)
523{
524 handle_dock(ds, 1);
525}
526
527static inline void undock(struct dock_station *ds)
528{
529 handle_dock(ds, 0);
530}
531
532static inline void begin_dock(struct dock_station *ds)
533{
534 ds->flags |= DOCK_DOCKING;
535}
536
537static inline void complete_dock(struct dock_station *ds)
538{
539 ds->flags &= ~(DOCK_DOCKING);
540 ds->last_dock_time = jiffies;
541}
542
543static inline void begin_undock(struct dock_station *ds)
544{
545 ds->flags |= DOCK_UNDOCKING;
546}
547
548static inline void complete_undock(struct dock_station *ds)
549{
550 ds->flags &= ~(DOCK_UNDOCKING);
551}
552
553static void dock_lock(struct dock_station *ds, int lock)
554{
555 struct acpi_object_list arg_list;
556 union acpi_object arg;
557 acpi_status status;
558
559 arg_list.count = 1;
560 arg_list.pointer = &arg;
561 arg.type = ACPI_TYPE_INTEGER;
562 arg.integer.value = !!lock;
563 status = acpi_evaluate_object(ds->handle, "_LCK", &arg_list, NULL);
564 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
565 if (lock)
566 acpi_handle_warn(ds->handle,
567 "Locking device failed (0x%x)\n", status);
568 else
569 acpi_handle_warn(ds->handle,
570 "Unlocking device failed (0x%x)\n", status);
571 }
572}
573
574
575
576
577
578
579
580
581
582static int dock_in_progress(struct dock_station *ds)
583{
584 if ((ds->flags & DOCK_DOCKING) ||
585 time_before(jiffies, (ds->last_dock_time + HZ)))
586 return 1;
587 return 0;
588}
589
590
591
592
593
594
595
596
597
598
599int register_dock_notifier(struct notifier_block *nb)
600{
601 if (!dock_station_count)
602 return -ENODEV;
603
604 return atomic_notifier_chain_register(&dock_notifier_list, nb);
605}
606EXPORT_SYMBOL_GPL(register_dock_notifier);
607
608
609
610
611
612void unregister_dock_notifier(struct notifier_block *nb)
613{
614 if (!dock_station_count)
615 return;
616
617 atomic_notifier_chain_unregister(&dock_notifier_list, nb);
618}
619EXPORT_SYMBOL_GPL(unregister_dock_notifier);
620
621
622
623
624
625
626
627
628
629
630
631
632
633int register_hotplug_dock_device(acpi_handle handle,
634 const struct acpi_dock_ops *ops, void *context,
635 void (*init)(void *), void (*release)(void *))
636{
637 struct dock_dependent_device *dd;
638 struct dock_station *dock_station;
639 int ret = -EINVAL;
640
641 if (WARN_ON(!context))
642 return -EINVAL;
643
644 if (!dock_station_count)
645 return -ENODEV;
646
647
648
649
650
651 list_for_each_entry(dock_station, &dock_stations, sibling) {
652
653
654
655
656
657 dd = find_dock_dependent_device(dock_station, handle);
658 if (dd && !dock_init_hotplug(dd, ops, context, init, release))
659 ret = 0;
660 }
661
662 return ret;
663}
664EXPORT_SYMBOL_GPL(register_hotplug_dock_device);
665
666
667
668
669
670void unregister_hotplug_dock_device(acpi_handle handle)
671{
672 struct dock_dependent_device *dd;
673 struct dock_station *dock_station;
674
675 if (!dock_station_count)
676 return;
677
678 list_for_each_entry(dock_station, &dock_stations, sibling) {
679 dd = find_dock_dependent_device(dock_station, handle);
680 if (dd)
681 dock_release_hotplug(dd);
682 }
683}
684EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
685
686
687
688
689
690
691
692static int handle_eject_request(struct dock_station *ds, u32 event)
693{
694 if (dock_in_progress(ds))
695 return -EBUSY;
696
697
698
699
700
701
702
703
704 dock_event(ds, event, UNDOCK_EVENT);
705
706 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
707 undock(ds);
708 dock_lock(ds, 0);
709 eject_dock(ds);
710 if (dock_present(ds)) {
711 acpi_handle_err(ds->handle, "Unable to undock!\n");
712 return -EBUSY;
713 }
714 complete_undock(ds);
715 return 0;
716}
717
718
719
720
721
722
723
724
725
726
727
728static void dock_notify(acpi_handle handle, u32 event, void *data)
729{
730 struct dock_station *ds = data;
731 struct acpi_device *tmp;
732 int surprise_removal = 0;
733
734
735
736
737
738
739 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK)
740 event = ACPI_NOTIFY_EJECT_REQUEST;
741
742
743
744
745
746
747
748
749
750
751 switch (event) {
752 case ACPI_NOTIFY_BUS_CHECK:
753 case ACPI_NOTIFY_DEVICE_CHECK:
754 if (!dock_in_progress(ds) && acpi_bus_get_device(ds->handle,
755 &tmp)) {
756 begin_dock(ds);
757 dock(ds);
758 if (!dock_present(ds)) {
759 acpi_handle_err(handle, "Unable to dock!\n");
760 complete_dock(ds);
761 break;
762 }
763 atomic_notifier_call_chain(&dock_notifier_list,
764 event, NULL);
765 hotplug_dock_devices(ds, event);
766 complete_dock(ds);
767 dock_event(ds, event, DOCK_EVENT);
768 dock_lock(ds, 1);
769 acpi_update_all_gpes();
770 break;
771 }
772 if (dock_present(ds) || dock_in_progress(ds))
773 break;
774
775 surprise_removal = 1;
776 event = ACPI_NOTIFY_EJECT_REQUEST;
777
778 case ACPI_NOTIFY_EJECT_REQUEST:
779 begin_undock(ds);
780 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
781 || surprise_removal)
782 handle_eject_request(ds, event);
783 else
784 dock_event(ds, event, UNDOCK_EVENT);
785 break;
786 default:
787 acpi_handle_err(handle, "Unknown dock event %d\n", event);
788 }
789}
790
791struct dock_data {
792 acpi_handle handle;
793 unsigned long event;
794 struct dock_station *ds;
795};
796
797static void acpi_dock_deferred_cb(void *context)
798{
799 struct dock_data *data = context;
800
801 acpi_scan_lock_acquire();
802 dock_notify(data->handle, data->event, data->ds);
803 acpi_scan_lock_release();
804 kfree(data);
805}
806
807static int acpi_dock_notifier_call(struct notifier_block *this,
808 unsigned long event, void *data)
809{
810 struct dock_station *dock_station;
811 acpi_handle handle = data;
812
813 if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK
814 && event != ACPI_NOTIFY_EJECT_REQUEST)
815 return 0;
816
817 acpi_scan_lock_acquire();
818
819 list_for_each_entry(dock_station, &dock_stations, sibling) {
820 if (dock_station->handle == handle) {
821 struct dock_data *dd;
822 acpi_status status;
823
824 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
825 if (!dd)
826 break;
827
828 dd->handle = handle;
829 dd->event = event;
830 dd->ds = dock_station;
831 status = acpi_os_hotplug_execute(acpi_dock_deferred_cb,
832 dd);
833 if (ACPI_FAILURE(status))
834 kfree(dd);
835
836 break;
837 }
838 }
839
840 acpi_scan_lock_release();
841 return 0;
842}
843
844static struct notifier_block dock_acpi_notifier = {
845 .notifier_call = acpi_dock_notifier_call,
846};
847
848
849
850
851
852
853
854
855
856
857
858
859static acpi_status
860find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
861{
862 acpi_status status;
863 acpi_handle tmp, parent;
864 struct dock_station *ds = context;
865
866 status = acpi_bus_get_ejd(handle, &tmp);
867 if (ACPI_FAILURE(status)) {
868
869 status = acpi_get_parent(handle, &parent);
870 if (ACPI_FAILURE(status))
871 goto fdd_out;
872
873 status = acpi_bus_get_ejd(parent, &tmp);
874 if (ACPI_FAILURE(status))
875 goto fdd_out;
876 }
877
878 if (tmp == ds->handle)
879 add_dock_dependent_device(ds, handle);
880
881fdd_out:
882 return AE_OK;
883}
884
885
886
887
888static ssize_t show_docked(struct device *dev,
889 struct device_attribute *attr, char *buf)
890{
891 struct acpi_device *tmp;
892
893 struct dock_station *dock_station = dev->platform_data;
894
895 if (!acpi_bus_get_device(dock_station->handle, &tmp))
896 return snprintf(buf, PAGE_SIZE, "1\n");
897 return snprintf(buf, PAGE_SIZE, "0\n");
898}
899static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
900
901
902
903
904static ssize_t show_flags(struct device *dev,
905 struct device_attribute *attr, char *buf)
906{
907 struct dock_station *dock_station = dev->platform_data;
908 return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
909
910}
911static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
912
913
914
915
916static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
917 const char *buf, size_t count)
918{
919 int ret;
920 struct dock_station *dock_station = dev->platform_data;
921
922 if (!count)
923 return -EINVAL;
924
925 acpi_scan_lock_acquire();
926 begin_undock(dock_station);
927 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
928 acpi_scan_lock_release();
929 return ret ? ret: count;
930}
931static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
932
933
934
935
936static ssize_t show_dock_uid(struct device *dev,
937 struct device_attribute *attr, char *buf)
938{
939 unsigned long long lbuf;
940 struct dock_station *dock_station = dev->platform_data;
941 acpi_status status = acpi_evaluate_integer(dock_station->handle,
942 "_UID", NULL, &lbuf);
943 if (ACPI_FAILURE(status))
944 return 0;
945
946 return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
947}
948static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
949
950static ssize_t show_dock_type(struct device *dev,
951 struct device_attribute *attr, char *buf)
952{
953 struct dock_station *dock_station = dev->platform_data;
954 char *type;
955
956 if (dock_station->flags & DOCK_IS_DOCK)
957 type = "dock_station";
958 else if (dock_station->flags & DOCK_IS_ATA)
959 type = "ata_bay";
960 else if (dock_station->flags & DOCK_IS_BAT)
961 type = "battery_bay";
962 else
963 type = "unknown";
964
965 return snprintf(buf, PAGE_SIZE, "%s\n", type);
966}
967static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
968
969static struct attribute *dock_attributes[] = {
970 &dev_attr_docked.attr,
971 &dev_attr_flags.attr,
972 &dev_attr_undock.attr,
973 &dev_attr_uid.attr,
974 &dev_attr_type.attr,
975 NULL
976};
977
978static struct attribute_group dock_attribute_group = {
979 .attrs = dock_attributes
980};
981
982
983
984
985
986
987
988
989static int __init dock_add(acpi_handle handle)
990{
991 int ret, id;
992 struct dock_station ds, *dock_station;
993 struct platform_device *dd;
994
995 id = dock_station_count;
996 memset(&ds, 0, sizeof(ds));
997 dd = platform_device_register_data(NULL, "dock", id, &ds, sizeof(ds));
998 if (IS_ERR(dd))
999 return PTR_ERR(dd);
1000
1001 dock_station = dd->dev.platform_data;
1002
1003 dock_station->handle = handle;
1004 dock_station->dock_device = dd;
1005 dock_station->last_dock_time = jiffies - HZ;
1006
1007 mutex_init(&dock_station->hp_lock);
1008 spin_lock_init(&dock_station->dd_lock);
1009 INIT_LIST_HEAD(&dock_station->sibling);
1010 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
1011 INIT_LIST_HEAD(&dock_station->dependent_devices);
1012
1013
1014 dev_set_uevent_suppress(&dd->dev, 0);
1015
1016 if (is_dock(handle))
1017 dock_station->flags |= DOCK_IS_DOCK;
1018 if (is_ata(handle))
1019 dock_station->flags |= DOCK_IS_ATA;
1020 if (is_battery(handle))
1021 dock_station->flags |= DOCK_IS_BAT;
1022
1023 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
1024 if (ret)
1025 goto err_unregister;
1026
1027
1028 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1029 ACPI_UINT32_MAX, find_dock_devices, NULL,
1030 dock_station, NULL);
1031
1032
1033 ret = add_dock_dependent_device(dock_station, handle);
1034 if (ret)
1035 goto err_rmgroup;
1036
1037 dock_station_count++;
1038 list_add(&dock_station->sibling, &dock_stations);
1039 return 0;
1040
1041err_rmgroup:
1042 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
1043err_unregister:
1044 platform_device_unregister(dd);
1045 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
1046 return ret;
1047}
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058static __init acpi_status
1059find_dock_and_bay(acpi_handle handle, u32 lvl, void *context, void **rv)
1060{
1061 if (is_dock(handle) || is_ejectable_bay(handle))
1062 dock_add(handle);
1063
1064 return AE_OK;
1065}
1066
1067void __init acpi_dock_init(void)
1068{
1069 if (acpi_disabled)
1070 return;
1071
1072
1073 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1074 ACPI_UINT32_MAX, find_dock_and_bay, NULL, NULL, NULL);
1075
1076 if (!dock_station_count) {
1077 pr_info(PREFIX "No dock devices found.\n");
1078 return;
1079 }
1080
1081 register_acpi_bus_notifier(&dock_acpi_notifier);
1082 pr_info(PREFIX "%s: %d docks/bays found\n",
1083 ACPI_DOCK_DRIVER_DESCRIPTION, dock_station_count);
1084}
1085