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