]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/acpi/dock.c
ACPI / dock: Drop struct acpi_dock_ops and all code related to it
[mirror_ubuntu-zesty-kernel.git] / drivers / acpi / dock.c
CommitLineData
c8f7a62c
LB
1/*
2 * dock.c - ACPI dock station driver
3 *
4 * Copyright (C) 2006 Kristen Carlson Accardi <kristen.c.accardi@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
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.
12 *
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.
17 *
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.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
5a0e3ad6 27#include <linux/slab.h>
c8f7a62c
LB
28#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/notifier.h>
671adbec 31#include <linux/platform_device.h>
914e2637 32#include <linux/jiffies.h>
62a6d7fd 33#include <linux/stddef.h>
cd73018f 34#include <linux/acpi.h>
c8f7a62c 35
3f9eed5c
R
36#include "internal.h"
37
a192a958
LB
38#define PREFIX "ACPI: "
39
7cda93e0 40#define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
c8f7a62c 41
f52fd66d 42ACPI_MODULE_NAME("dock");
c8f7a62c 43MODULE_AUTHOR("Kristen Carlson Accardi");
7cda93e0 44MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
c8f7a62c
LB
45MODULE_LICENSE("GPL");
46
90ab5ee9 47static bool immediate_undock = 1;
a0cd35fd
KCA
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
a340af14
FS
54static const struct acpi_device_id dock_device_ids[] = {
55 {"LNXDOCK", 0},
56 {"", 0},
57};
58MODULE_DEVICE_TABLE(acpi, dock_device_ids);
59
c8f7a62c
LB
60struct dock_station {
61 acpi_handle handle;
62 unsigned long last_dock_time;
63 u32 flags;
c8f7a62c 64 struct list_head dependent_devices;
db350b08 65
50d716e4 66 struct list_head sibling;
db350b08 67 struct platform_device *dock_device;
c8f7a62c 68};
db350b08
SL
69static LIST_HEAD(dock_stations);
70static int dock_station_count;
c8f7a62c
LB
71
72struct dock_dependent_device {
73 struct list_head list;
3b52b21f 74 struct acpi_device *adev;
c8f7a62c
LB
75};
76
77#define DOCK_DOCKING 0x00000001
a0cd35fd 78#define DOCK_UNDOCKING 0x00000002
db350b08
SL
79#define DOCK_IS_DOCK 0x00000010
80#define DOCK_IS_ATA 0x00000020
81#define DOCK_IS_BAT 0x00000040
5669021e
KCA
82#define DOCK_EVENT 3
83#define UNDOCK_EVENT 2
c8f7a62c 84
f09ce741
RW
85enum dock_callback_type {
86 DOCK_CALL_HANDLER,
87 DOCK_CALL_FIXUP,
88 DOCK_CALL_UEVENT,
89};
90
c8f7a62c
LB
91/*****************************************************************************
92 * Dock Dependent device functions *
93 *****************************************************************************/
94/**
f69cfdd2 95 * add_dock_dependent_device - associate a device with the dock station
3b52b21f
RW
96 * @ds: Dock station.
97 * @adev: Dependent ACPI device object.
c8f7a62c 98 *
f69cfdd2 99 * Add the dependent device to the dock's dependent device list.
c8f7a62c 100 */
3b52b21f
RW
101static int add_dock_dependent_device(struct dock_station *ds,
102 struct acpi_device *adev)
c8f7a62c
LB
103{
104 struct dock_dependent_device *dd;
105
106 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
f69cfdd2
AC
107 if (!dd)
108 return -ENOMEM;
109
3b52b21f 110 dd->adev = adev;
f69cfdd2 111 INIT_LIST_HEAD(&dd->list);
c8f7a62c 112 list_add_tail(&dd->list, &ds->dependent_devices);
f69cfdd2
AC
113
114 return 0;
c8f7a62c
LB
115}
116
a30c4c5e
RW
117static void remove_dock_dependent_devices(struct dock_station *ds)
118{
119 struct dock_dependent_device *dd, *aux;
120
121 list_for_each_entry_safe(dd, aux, &ds->dependent_devices, list) {
122 list_del(&dd->list);
123 kfree(dd);
124 }
125}
126
21a31013 127static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event,
f09ce741 128 enum dock_callback_type cb_type)
21a31013 129{
edf5bf34 130 struct acpi_device *adev = dd->adev;
21a31013 131
edf5bf34
RW
132 acpi_lock_hp_context();
133
134 if (!adev->hp)
2f16817d 135 goto out;
edf5bf34
RW
136
137 if (cb_type == DOCK_CALL_FIXUP) {
138 void (*fixup)(struct acpi_device *);
139
140 fixup = adev->hp->fixup;
141 if (fixup) {
142 acpi_unlock_hp_context();
143 fixup(adev);
144 return;
145 }
be27b3dc
RW
146 } else if (cb_type == DOCK_CALL_UEVENT) {
147 void (*uevent)(struct acpi_device *, u32);
148
149 uevent = adev->hp->uevent;
150 if (uevent) {
151 acpi_unlock_hp_context();
152 uevent(adev, event);
153 return;
154 }
edf5bf34
RW
155 } else {
156 int (*notify)(struct acpi_device *, u32);
157
be27b3dc 158 notify = adev->hp->notify;
edf5bf34
RW
159 if (notify) {
160 acpi_unlock_hp_context();
161 notify(adev, event);
162 return;
163 }
164 }
165
2f16817d 166 out:
edf5bf34 167 acpi_unlock_hp_context();
c8f7a62c
LB
168}
169
1e2380cd
RW
170static struct dock_station *find_dock_station(acpi_handle handle)
171{
172 struct dock_station *ds;
173
174 list_for_each_entry(ds, &dock_stations, sibling)
175 if (ds->handle == handle)
176 return ds;
177
178 return NULL;
179}
180
c8f7a62c
LB
181/**
182 * find_dock_dependent_device - get a device dependent on this dock
183 * @ds: the dock station
3b52b21f 184 * @adev: ACPI device object to find.
c8f7a62c
LB
185 *
186 * iterate over the dependent device list for this dock. If the
187 * dependent device matches the handle, return.
188 */
189static struct dock_dependent_device *
3b52b21f 190find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev)
c8f7a62c
LB
191{
192 struct dock_dependent_device *dd;
193
ed633e70 194 list_for_each_entry(dd, &ds->dependent_devices, list)
3b52b21f 195 if (adev == dd->adev)
c8f7a62c 196 return dd;
ed633e70 197
c8f7a62c
LB
198 return NULL;
199}
200
1e2380cd
RW
201void register_dock_dependent_device(struct acpi_device *adev,
202 acpi_handle dshandle)
db350b08 203{
1e2380cd 204 struct dock_station *ds = find_dock_station(dshandle);
db350b08 205
3b52b21f
RW
206 if (ds && !find_dock_dependent_device(ds, adev))
207 add_dock_dependent_device(ds, adev);
db350b08
SL
208}
209
1e2380cd
RW
210/*****************************************************************************
211 * Dock functions *
212 *****************************************************************************/
db350b08 213
c8f7a62c
LB
214/**
215 * is_dock_device - see if a device is on a dock station
3b52b21f 216 * @adev: ACPI device object to check.
c8f7a62c
LB
217 *
218 * If this device is either the dock station itself,
219 * or is a device dependent on the dock station, then it
220 * is a dock device
221 */
3b52b21f 222int is_dock_device(struct acpi_device *adev)
c8f7a62c 223{
db350b08
SL
224 struct dock_station *dock_station;
225
226 if (!dock_station_count)
c8f7a62c
LB
227 return 0;
228
3b52b21f 229 if (acpi_dock_match(adev->handle))
c8f7a62c 230 return 1;
747479a3
AC
231
232 list_for_each_entry(dock_station, &dock_stations, sibling)
3b52b21f 233 if (find_dock_dependent_device(dock_station, adev))
db350b08 234 return 1;
c8f7a62c
LB
235
236 return 0;
237}
c8f7a62c
LB
238EXPORT_SYMBOL_GPL(is_dock_device);
239
240/**
241 * dock_present - see if the dock station is present.
242 * @ds: the dock station
243 *
244 * execute the _STA method. note that present does not
245 * imply that we are docked.
246 */
247static int dock_present(struct dock_station *ds)
248{
27663c58 249 unsigned long long sta;
c8f7a62c
LB
250 acpi_status status;
251
252 if (ds) {
253 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
254 if (ACPI_SUCCESS(status) && sta)
255 return 1;
256 }
257 return 0;
258}
259
c8f7a62c 260/**
37f90877
RW
261 * hot_remove_dock_devices - Remove dock station devices.
262 * @ds: Dock station.
263 */
264static void hot_remove_dock_devices(struct dock_station *ds)
265{
266 struct dock_dependent_device *dd;
267
268 /*
269 * Walk the list in reverse order so that devices that have been added
270 * last are removed first (in case there are some indirect dependencies
271 * between them).
272 */
273 list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
274 dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false);
275
276 list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
3b52b21f 277 acpi_bus_trim(dd->adev);
37f90877
RW
278}
279
280/**
281 * hotplug_dock_devices - Insert devices on a dock station.
c8f7a62c 282 * @ds: the dock station
37f90877 283 * @event: either bus check or device check request
c8f7a62c
LB
284 *
285 * Some devices on the dock station need to have drivers called
286 * to perform hotplug operations after a dock event has occurred.
287 * Traverse the list of dock devices that have registered a
288 * hotplug handler, and call the handler.
289 */
290static void hotplug_dock_devices(struct dock_station *ds, u32 event)
291{
292 struct dock_dependent_device *dd;
293
f09ce741
RW
294 /* Call driver specific post-dock fixups. */
295 list_for_each_entry(dd, &ds->dependent_devices, list)
296 dock_hotplug_event(dd, event, DOCK_CALL_FIXUP);
297
37f90877 298 /* Call driver specific hotplug functions. */
21a31013 299 list_for_each_entry(dd, &ds->dependent_devices, list)
f09ce741 300 dock_hotplug_event(dd, event, DOCK_CALL_HANDLER);
c8f7a62c
LB
301
302 /*
3b52b21f
RW
303 * Check if all devices have been enumerated already. If not, run
304 * acpi_bus_scan() for them and that will cause scan handlers to be
305 * attached to device objects or acpi_drivers to be stopped/started if
306 * they are present.
c8f7a62c 307 */
3b52b21f
RW
308 list_for_each_entry(dd, &ds->dependent_devices, list) {
309 struct acpi_device *adev = dd->adev;
310
311 if (!acpi_device_enumerated(adev)) {
312 int ret = acpi_bus_scan(adev->handle);
313 if (ret)
314 dev_dbg(&adev->dev, "scan error %d\n", -ret);
315 }
316 }
c8f7a62c
LB
317}
318
319static void dock_event(struct dock_station *ds, u32 event, int num)
320{
db350b08 321 struct device *dev = &ds->dock_device->dev;
66b56821 322 char event_string[13];
79a8f70b 323 char *envp[] = { event_string, NULL };
1253f7aa 324 struct dock_dependent_device *dd;
79a8f70b
KCA
325
326 if (num == UNDOCK_EVENT)
66b56821 327 sprintf(event_string, "EVENT=undock");
79a8f70b 328 else
66b56821 329 sprintf(event_string, "EVENT=dock");
79a8f70b 330
5669021e 331 /*
8ea86e0b
KCA
332 * Indicate that the status of the dock station has
333 * changed.
5669021e 334 */
1253f7aa
SL
335 if (num == DOCK_EVENT)
336 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
337
21a31013 338 list_for_each_entry(dd, &ds->dependent_devices, list)
f09ce741 339 dock_hotplug_event(dd, event, DOCK_CALL_UEVENT);
747479a3 340
1253f7aa
SL
341 if (num != DOCK_EVENT)
342 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
c8f7a62c
LB
343}
344
c8f7a62c
LB
345/**
346 * handle_dock - handle a dock event
347 * @ds: the dock station
348 * @dock: to dock, or undock - that is the question
349 *
350 * Execute the _DCK method in response to an acpi event
351 */
352static void handle_dock(struct dock_station *ds, int dock)
353{
354 acpi_status status;
355 struct acpi_object_list arg_list;
356 union acpi_object arg;
6a868e17 357 unsigned long long value;
c8f7a62c 358
cd73018f 359 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
c8f7a62c
LB
360
361 /* _DCK method has one argument */
362 arg_list.count = 1;
363 arg_list.pointer = &arg;
364 arg.type = ACPI_TYPE_INTEGER;
365 arg.integer.value = dock;
6a868e17 366 status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value);
db350b08 367 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
cd73018f
TK
368 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
369 status);
c8f7a62c
LB
370}
371
372static inline void dock(struct dock_station *ds)
373{
374 handle_dock(ds, 1);
375}
376
377static inline void undock(struct dock_station *ds)
378{
379 handle_dock(ds, 0);
380}
381
382static inline void begin_dock(struct dock_station *ds)
383{
384 ds->flags |= DOCK_DOCKING;
385}
386
387static inline void complete_dock(struct dock_station *ds)
388{
389 ds->flags &= ~(DOCK_DOCKING);
390 ds->last_dock_time = jiffies;
391}
392
a0cd35fd
KCA
393static inline void begin_undock(struct dock_station *ds)
394{
395 ds->flags |= DOCK_UNDOCKING;
396}
397
398static inline void complete_undock(struct dock_station *ds)
399{
400 ds->flags &= ~(DOCK_UNDOCKING);
401}
402
c8f7a62c
LB
403/**
404 * dock_in_progress - see if we are in the middle of handling a dock event
405 * @ds: the dock station
406 *
407 * Sometimes while docking, false dock events can be sent to the driver
408 * because good connections aren't made or some other reason. Ignore these
409 * if we are in the middle of doing something.
410 */
411static int dock_in_progress(struct dock_station *ds)
412{
413 if ((ds->flags & DOCK_DOCKING) ||
414 time_before(jiffies, (ds->last_dock_time + HZ)))
415 return 1;
416 return 0;
417}
418
c80fdbe8 419/**
420 * handle_eject_request - handle an undock request checking for error conditions
421 *
422 * Check to make sure the dock device is still present, then undock and
423 * hotremove all the devices that may need removing.
424 */
425static int handle_eject_request(struct dock_station *ds, u32 event)
426{
c80fdbe8 427 if (dock_in_progress(ds))
428 return -EBUSY;
429
430 /*
431 * here we need to generate the undock
432 * event prior to actually doing the undock
433 * so that the device struct still exists.
afd7301d
HM
434 * Also, even send the dock event if the
435 * device is not present anymore
c80fdbe8 436 */
437 dock_event(ds, event, UNDOCK_EVENT);
afd7301d 438
37f90877 439 hot_remove_dock_devices(ds);
c80fdbe8 440 undock(ds);
c9b5471f
JL
441 acpi_evaluate_lck(ds->handle, 0);
442 acpi_evaluate_ej0(ds->handle);
c80fdbe8 443 if (dock_present(ds)) {
cd73018f 444 acpi_handle_err(ds->handle, "Unable to undock!\n");
c80fdbe8 445 return -EBUSY;
446 }
a0cd35fd 447 complete_undock(ds);
c80fdbe8 448 return 0;
449}
450
c8f7a62c 451/**
1e2380cd
RW
452 * dock_notify - Handle ACPI dock notification.
453 * @adev: Dock station's ACPI device object.
454 * @event: Event code.
c8f7a62c
LB
455 *
456 * If we are notified to dock, then check to see if the dock is
457 * present and then dock. Notify all drivers of the dock event,
c80fdbe8 458 * and then hotplug and devices that may need hotplugging.
c8f7a62c 459 */
1e2380cd 460int dock_notify(struct acpi_device *adev, u32 event)
c8f7a62c 461{
1e2380cd
RW
462 acpi_handle handle = adev->handle;
463 struct dock_station *ds = find_dock_station(handle);
db350b08 464 int surprise_removal = 0;
c8f7a62c 465
1e2380cd
RW
466 if (!ds)
467 return -ENODEV;
468
db350b08
SL
469 /*
470 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
471 * is sent and _DCK is present, it is assumed to mean an undock
472 * request.
473 */
474 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK)
475 event = ACPI_NOTIFY_EJECT_REQUEST;
476
477 /*
478 * dock station: BUS_CHECK - docked or surprise removal
479 * DEVICE_CHECK - undocked
480 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
481 *
482 * To simplify event handling, dock dependent device handler always
483 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
484 * ACPI_NOTIFY_EJECT_REQUEST for removal
485 */
c8f7a62c
LB
486 switch (event) {
487 case ACPI_NOTIFY_BUS_CHECK:
db350b08 488 case ACPI_NOTIFY_DEVICE_CHECK:
0a8e5c3d 489 if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) {
c8f7a62c
LB
490 begin_dock(ds);
491 dock(ds);
492 if (!dock_present(ds)) {
cd73018f 493 acpi_handle_err(handle, "Unable to dock!\n");
8b59560a 494 complete_dock(ds);
c8f7a62c
LB
495 break;
496 }
c8f7a62c
LB
497 hotplug_dock_devices(ds, event);
498 complete_dock(ds);
499 dock_event(ds, event, DOCK_EVENT);
c9b5471f 500 acpi_evaluate_lck(ds->handle, 1);
3a37898d 501 acpi_update_all_gpes();
db350b08 502 break;
c8f7a62c 503 }
db350b08
SL
504 if (dock_present(ds) || dock_in_progress(ds))
505 break;
506 /* This is a surprise removal */
507 surprise_removal = 1;
508 event = ACPI_NOTIFY_EJECT_REQUEST;
509 /* Fall back */
c8f7a62c 510 case ACPI_NOTIFY_EJECT_REQUEST:
a0cd35fd 511 begin_undock(ds);
f730ae18
SL
512 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
513 || surprise_removal)
a0cd35fd
KCA
514 handle_eject_request(ds, event);
515 else
516 dock_event(ds, event, UNDOCK_EVENT);
c8f7a62c 517 break;
c8f7a62c 518 }
1e2380cd 519 return 0;
c8f7a62c
LB
520}
521
c80fdbe8 522/*
523 * show_docked - read method for "docked" file in sysfs
524 */
525static ssize_t show_docked(struct device *dev,
526 struct device_attribute *attr, char *buf)
527{
fe06fba2 528 struct dock_station *dock_station = dev->platform_data;
ab62f9cd 529 struct acpi_device *adev = NULL;
c80fdbe8 530
ab62f9cd
RW
531 acpi_bus_get_device(dock_station->handle, &adev);
532 return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
c80fdbe8 533}
e5685b9d 534static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
c80fdbe8 535
a0cd35fd
KCA
536/*
537 * show_flags - read method for flags file in sysfs
538 */
539static ssize_t show_flags(struct device *dev,
540 struct device_attribute *attr, char *buf)
541{
fe06fba2 542 struct dock_station *dock_station = dev->platform_data;
a0cd35fd
KCA
543 return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
544
545}
e5685b9d 546static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
a0cd35fd 547
c80fdbe8 548/*
549 * write_undock - write method for "undock" file in sysfs
550 */
551static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
552 const char *buf, size_t count)
553{
554 int ret;
fe06fba2 555 struct dock_station *dock_station = dev->platform_data;
c80fdbe8 556
557 if (!count)
558 return -EINVAL;
559
8112006f 560 acpi_scan_lock_acquire();
9171f834 561 begin_undock(dock_station);
c80fdbe8 562 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
8112006f 563 acpi_scan_lock_release();
c80fdbe8 564 return ret ? ret: count;
565}
e5685b9d 566static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
c80fdbe8 567
ac122bb6
IVE
568/*
569 * show_dock_uid - read method for "uid" file in sysfs
570 */
571static ssize_t show_dock_uid(struct device *dev,
572 struct device_attribute *attr, char *buf)
573{
27663c58 574 unsigned long long lbuf;
fe06fba2 575 struct dock_station *dock_station = dev->platform_data;
38ff4ffc
KCA
576 acpi_status status = acpi_evaluate_integer(dock_station->handle,
577 "_UID", NULL, &lbuf);
578 if (ACPI_FAILURE(status))
ac122bb6 579 return 0;
38ff4ffc 580
27663c58 581 return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
ac122bb6 582}
e5685b9d 583static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
ac122bb6 584
8652b00f
SL
585static ssize_t show_dock_type(struct device *dev,
586 struct device_attribute *attr, char *buf)
587{
fe06fba2 588 struct dock_station *dock_station = dev->platform_data;
8652b00f
SL
589 char *type;
590
591 if (dock_station->flags & DOCK_IS_DOCK)
592 type = "dock_station";
593 else if (dock_station->flags & DOCK_IS_ATA)
594 type = "ata_bay";
595 else if (dock_station->flags & DOCK_IS_BAT)
596 type = "battery_bay";
597 else
598 type = "unknown";
599
600 return snprintf(buf, PAGE_SIZE, "%s\n", type);
601}
602static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
603
5f46c2f2
AC
604static struct attribute *dock_attributes[] = {
605 &dev_attr_docked.attr,
606 &dev_attr_flags.attr,
607 &dev_attr_undock.attr,
608 &dev_attr_uid.attr,
609 &dev_attr_type.attr,
610 NULL
611};
612
613static struct attribute_group dock_attribute_group = {
614 .attrs = dock_attributes
615};
616
c8f7a62c 617/**
1e2380cd
RW
618 * acpi_dock_add - Add a new dock station
619 * @adev: Dock station ACPI device object.
c8f7a62c 620 *
1e2380cd 621 * allocated and initialize a new dock station device.
c8f7a62c 622 */
1e2380cd 623void acpi_dock_add(struct acpi_device *adev)
c8f7a62c 624{
2efbca4d 625 struct dock_station *dock_station, ds = { NULL, };
af887449 626 struct platform_device_info pdevinfo;
1e2380cd 627 acpi_handle handle = adev->handle;
747479a3 628 struct platform_device *dd;
2efbca4d 629 int ret;
c8f7a62c 630
af887449
RW
631 memset(&pdevinfo, 0, sizeof(pdevinfo));
632 pdevinfo.name = "dock";
633 pdevinfo.id = dock_station_count;
634 pdevinfo.acpi_node.companion = adev;
635 pdevinfo.data = &ds;
636 pdevinfo.size_data = sizeof(ds);
637 dd = platform_device_register_full(&pdevinfo);
747479a3 638 if (IS_ERR(dd))
1e2380cd 639 return;
747479a3
AC
640
641 dock_station = dd->dev.platform_data;
c8f7a62c 642
c8f7a62c 643 dock_station->handle = handle;
747479a3 644 dock_station->dock_device = dd;
c8f7a62c 645 dock_station->last_dock_time = jiffies - HZ;
747479a3 646
747479a3 647 INIT_LIST_HEAD(&dock_station->sibling);
747479a3 648 INIT_LIST_HEAD(&dock_station->dependent_devices);
a0cd35fd 649
9ef2a9a9 650 /* we want the dock device to send uevents */
747479a3 651 dev_set_uevent_suppress(&dd->dev, 0);
9ef2a9a9 652
c9b5471f 653 if (acpi_dock_match(handle))
db350b08 654 dock_station->flags |= DOCK_IS_DOCK;
c9b5471f 655 if (acpi_ata_match(handle))
db350b08 656 dock_station->flags |= DOCK_IS_ATA;
b43109fa 657 if (acpi_device_is_battery(adev))
db350b08
SL
658 dock_station->flags |= DOCK_IS_BAT;
659
747479a3 660 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
8652b00f 661 if (ret)
5f46c2f2 662 goto err_unregister;
671adbec 663
c8f7a62c 664 /* add the dock station as a device dependent on itself */
3b52b21f 665 ret = add_dock_dependent_device(dock_station, adev);
f69cfdd2 666 if (ret)
5f46c2f2 667 goto err_rmgroup;
c8f7a62c 668
db350b08 669 dock_station_count++;
50d716e4 670 list_add(&dock_station->sibling, &dock_stations);
1e2380cd
RW
671 adev->flags.is_dock_station = true;
672 dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n",
673 dock_station_count);
674 return;
c8f7a62c 675
5f46c2f2 676err_rmgroup:
a30c4c5e 677 remove_dock_dependent_devices(dock_station);
747479a3 678 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
5f46c2f2 679err_unregister:
747479a3 680 platform_device_unregister(dd);
cd73018f 681 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
c8f7a62c 682}