blob: 78c4ee7a422ebc2673f245f091bc04fa9e650f19 [file] [log] [blame]
Len Brownc8f7a622006-07-09 17:22:28 -04001/*
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Len Brownc8f7a622006-07-09 17:22:28 -040028#include <linux/init.h>
29#include <linux/types.h>
30#include <linux/notifier.h>
Kristen Carlson Accardi671adbe2006-12-04 14:49:43 -080031#include <linux/platform_device.h>
Al Viro914e2632006-10-18 13:55:46 -040032#include <linux/jiffies.h>
Randy Dunlap62a6d7f2007-03-26 21:38:49 -080033#include <linux/stddef.h>
Toshi Kanicd730182012-11-20 23:42:30 +000034#include <linux/acpi.h>
Len Brownc8f7a622006-07-09 17:22:28 -040035
Rashika3f9eed52013-12-17 15:00:04 +053036#include "internal.h"
37
Len Browna192a952009-07-28 16:45:54 -040038#define PREFIX "ACPI: "
39
Len Brown7cda93e2007-02-12 23:50:02 -050040#define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
Len Brownc8f7a622006-07-09 17:22:28 -040041
Len Brownf52fd662007-02-12 22:42:12 -050042ACPI_MODULE_NAME("dock");
Len Brownc8f7a622006-07-09 17:22:28 -040043MODULE_AUTHOR("Kristen Carlson Accardi");
Len Brown7cda93e2007-02-12 23:50:02 -050044MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
Len Brownc8f7a622006-07-09 17:22:28 -040045MODULE_LICENSE("GPL");
46
Rusty Russell90ab5ee2012-01-13 09:32:20 +103047static bool immediate_undock = 1;
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -070048module_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
Frank Seidela340af12007-12-07 13:20:42 +010054static const struct acpi_device_id dock_device_ids[] = {
55 {"LNXDOCK", 0},
56 {"", 0},
57};
58MODULE_DEVICE_TABLE(acpi, dock_device_ids);
59
Len Brownc8f7a622006-07-09 17:22:28 -040060struct dock_station {
61 acpi_handle handle;
62 unsigned long last_dock_time;
63 u32 flags;
Len Brownc8f7a622006-07-09 17:22:28 -040064 struct list_head dependent_devices;
Shaohua Lidb350b02008-08-28 10:03:58 +080065
Alex Chiang50d716e2009-10-01 11:59:23 -060066 struct list_head sibling;
Shaohua Lidb350b02008-08-28 10:03:58 +080067 struct platform_device *dock_device;
Len Brownc8f7a622006-07-09 17:22:28 -040068};
Shaohua Lidb350b02008-08-28 10:03:58 +080069static LIST_HEAD(dock_stations);
70static int dock_station_count;
Rafael J. Wysocki21a31012013-06-24 11:22:53 +020071static DEFINE_MUTEX(hotplug_lock);
Len Brownc8f7a622006-07-09 17:22:28 -040072
73struct dock_dependent_device {
74 struct list_head list;
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +010075 struct acpi_device *adev;
Rafael J. Wysocki21a31012013-06-24 11:22:53 +020076 const struct acpi_dock_ops *hp_ops;
77 void *hp_context;
78 unsigned int hp_refcount;
79 void (*hp_release)(void *);
Len Brownc8f7a622006-07-09 17:22:28 -040080};
81
82#define DOCK_DOCKING 0x00000001
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -070083#define DOCK_UNDOCKING 0x00000002
Shaohua Lidb350b02008-08-28 10:03:58 +080084#define DOCK_IS_DOCK 0x00000010
85#define DOCK_IS_ATA 0x00000020
86#define DOCK_IS_BAT 0x00000040
Kristen Carlson Accardi56690212006-08-01 14:59:19 -070087#define DOCK_EVENT 3
88#define UNDOCK_EVENT 2
Len Brownc8f7a622006-07-09 17:22:28 -040089
Rafael J. Wysockif09ce742013-07-05 03:03:25 +020090enum dock_callback_type {
91 DOCK_CALL_HANDLER,
92 DOCK_CALL_FIXUP,
93 DOCK_CALL_UEVENT,
94};
95
Len Brownc8f7a622006-07-09 17:22:28 -040096/*****************************************************************************
97 * Dock Dependent device functions *
98 *****************************************************************************/
99/**
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600100 * add_dock_dependent_device - associate a device with the dock station
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100101 * @ds: Dock station.
102 * @adev: Dependent ACPI device object.
Len Brownc8f7a622006-07-09 17:22:28 -0400103 *
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600104 * Add the dependent device to the dock's dependent device list.
Len Brownc8f7a622006-07-09 17:22:28 -0400105 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100106static int add_dock_dependent_device(struct dock_station *ds,
107 struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400108{
109 struct dock_dependent_device *dd;
110
111 dd = kzalloc(sizeof(*dd), GFP_KERNEL);
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600112 if (!dd)
113 return -ENOMEM;
Len Brownc8f7a622006-07-09 17:22:28 -0400114
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100115 dd->adev = adev;
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600116 INIT_LIST_HEAD(&dd->list);
Len Brownc8f7a622006-07-09 17:22:28 -0400117 list_add_tail(&dd->list, &ds->dependent_devices);
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600118
119 return 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400120}
121
Rafael J. Wysockia30c4c52013-06-30 23:50:24 +0200122static void remove_dock_dependent_devices(struct dock_station *ds)
123{
124 struct dock_dependent_device *dd, *aux;
125
126 list_for_each_entry_safe(dd, aux, &ds->dependent_devices, list) {
127 list_del(&dd->list);
128 kfree(dd);
129 }
130}
131
Len Brownc8f7a622006-07-09 17:22:28 -0400132/**
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200133 * dock_init_hotplug - Initialize a hotplug device on a docking station.
134 * @dd: Dock-dependent device.
135 * @ops: Dock operations to attach to the dependent device.
136 * @context: Data to pass to the @ops callbacks and @release.
137 * @init: Optional initialization routine to run after setting up context.
138 * @release: Optional release routine to run on removal.
Len Brownc8f7a622006-07-09 17:22:28 -0400139 */
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200140static int dock_init_hotplug(struct dock_dependent_device *dd,
141 const struct acpi_dock_ops *ops, void *context,
142 void (*init)(void *), void (*release)(void *))
Len Brownc8f7a622006-07-09 17:22:28 -0400143{
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200144 int ret = 0;
145
146 mutex_lock(&hotplug_lock);
Rafael J. Wysocki4ec24062013-06-30 23:47:14 +0200147 if (WARN_ON(dd->hp_context)) {
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200148 ret = -EEXIST;
149 } else {
150 dd->hp_refcount = 1;
151 dd->hp_ops = ops;
152 dd->hp_context = context;
153 dd->hp_release = release;
Rafael J. Wysocki4ec24062013-06-30 23:47:14 +0200154 if (init)
155 init(context);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200156 }
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200157 mutex_unlock(&hotplug_lock);
158 return ret;
Len Brownc8f7a622006-07-09 17:22:28 -0400159}
160
161/**
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200162 * dock_release_hotplug - Decrement hotplug reference counter of dock device.
163 * @dd: Dock-dependent device.
Len Brownc8f7a622006-07-09 17:22:28 -0400164 *
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200165 * Decrement the reference counter of @dd and if 0, detach its hotplug
166 * operations from it, reset its context pointer and run the optional release
167 * routine if present.
Len Brownc8f7a622006-07-09 17:22:28 -0400168 */
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200169static void dock_release_hotplug(struct dock_dependent_device *dd)
Len Brownc8f7a622006-07-09 17:22:28 -0400170{
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200171 mutex_lock(&hotplug_lock);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200172 if (dd->hp_context && !--dd->hp_refcount) {
Rafael J. Wysocki4ec24062013-06-30 23:47:14 +0200173 void (*release)(void *) = dd->hp_release;
174 void *context = dd->hp_context;
175
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200176 dd->hp_ops = NULL;
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200177 dd->hp_context = NULL;
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200178 dd->hp_release = NULL;
Rafael J. Wysocki4ec24062013-06-30 23:47:14 +0200179 if (release)
180 release(context);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200181 }
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200182 mutex_unlock(&hotplug_lock);
183}
184
185static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event,
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200186 enum dock_callback_type cb_type)
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200187{
Rafael J. Wysockiedf5bf32014-02-21 01:10:18 +0100188 struct acpi_device *adev = dd->adev;
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200189 acpi_notify_handler cb = NULL;
190 bool run = false;
191
Rafael J. Wysockiedf5bf32014-02-21 01:10:18 +0100192 acpi_lock_hp_context();
193
194 if (!adev->hp)
195 goto no_context;
196
197 if (cb_type == DOCK_CALL_FIXUP) {
198 void (*fixup)(struct acpi_device *);
199
200 fixup = adev->hp->fixup;
201 if (fixup) {
202 acpi_unlock_hp_context();
203 fixup(adev);
204 return;
205 }
206 } else {
207 int (*notify)(struct acpi_device *, u32);
208
209 notify = adev->hp->event;
210 if (notify) {
211 acpi_unlock_hp_context();
212 notify(adev, event);
213 return;
214 }
215 }
216
217 no_context:
218 acpi_unlock_hp_context();
219
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200220 mutex_lock(&hotplug_lock);
221
222 if (dd->hp_context) {
223 run = true;
224 dd->hp_refcount++;
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200225 if (dd->hp_ops) {
226 switch (cb_type) {
227 case DOCK_CALL_FIXUP:
228 cb = dd->hp_ops->fixup;
229 break;
230 case DOCK_CALL_UEVENT:
231 cb = dd->hp_ops->uevent;
232 break;
233 default:
234 cb = dd->hp_ops->handler;
235 }
236 }
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200237 }
238
239 mutex_unlock(&hotplug_lock);
240
241 if (!run)
242 return;
243
244 if (cb)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100245 cb(dd->adev->handle, event, dd->hp_context);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200246
247 dock_release_hotplug(dd);
Len Brownc8f7a622006-07-09 17:22:28 -0400248}
249
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100250static struct dock_station *find_dock_station(acpi_handle handle)
251{
252 struct dock_station *ds;
253
254 list_for_each_entry(ds, &dock_stations, sibling)
255 if (ds->handle == handle)
256 return ds;
257
258 return NULL;
259}
260
Len Brownc8f7a622006-07-09 17:22:28 -0400261/**
262 * find_dock_dependent_device - get a device dependent on this dock
263 * @ds: the dock station
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100264 * @adev: ACPI device object to find.
Len Brownc8f7a622006-07-09 17:22:28 -0400265 *
266 * iterate over the dependent device list for this dock. If the
267 * dependent device matches the handle, return.
268 */
269static struct dock_dependent_device *
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100270find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400271{
272 struct dock_dependent_device *dd;
273
Jiang Liued633e72013-06-29 00:24:35 +0800274 list_for_each_entry(dd, &ds->dependent_devices, list)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100275 if (adev == dd->adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400276 return dd;
Jiang Liued633e72013-06-29 00:24:35 +0800277
Len Brownc8f7a622006-07-09 17:22:28 -0400278 return NULL;
279}
280
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100281void register_dock_dependent_device(struct acpi_device *adev,
282 acpi_handle dshandle)
283{
284 struct dock_station *ds = find_dock_station(dshandle);
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100285
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100286 if (ds && !find_dock_dependent_device(ds, adev))
287 add_dock_dependent_device(ds, adev);
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100288}
289
Len Brownc8f7a622006-07-09 17:22:28 -0400290/*****************************************************************************
291 * Dock functions *
292 *****************************************************************************/
Shaohua Lidb350b02008-08-28 10:03:58 +0800293
Len Brownc8f7a622006-07-09 17:22:28 -0400294/**
295 * is_dock_device - see if a device is on a dock station
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100296 * @adev: ACPI device object to check.
Len Brownc8f7a622006-07-09 17:22:28 -0400297 *
298 * If this device is either the dock station itself,
299 * or is a device dependent on the dock station, then it
300 * is a dock device
301 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100302int is_dock_device(struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400303{
Shaohua Lidb350b02008-08-28 10:03:58 +0800304 struct dock_station *dock_station;
305
306 if (!dock_station_count)
Len Brownc8f7a622006-07-09 17:22:28 -0400307 return 0;
308
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100309 if (acpi_dock_match(adev->handle))
Len Brownc8f7a622006-07-09 17:22:28 -0400310 return 1;
Alex Chiang747479a2009-10-19 15:14:50 -0600311
312 list_for_each_entry(dock_station, &dock_stations, sibling)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100313 if (find_dock_dependent_device(dock_station, adev))
Shaohua Lidb350b02008-08-28 10:03:58 +0800314 return 1;
Len Brownc8f7a622006-07-09 17:22:28 -0400315
316 return 0;
317}
Len Brownc8f7a622006-07-09 17:22:28 -0400318EXPORT_SYMBOL_GPL(is_dock_device);
319
320/**
321 * dock_present - see if the dock station is present.
322 * @ds: the dock station
323 *
324 * execute the _STA method. note that present does not
325 * imply that we are docked.
326 */
327static int dock_present(struct dock_station *ds)
328{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400329 unsigned long long sta;
Len Brownc8f7a622006-07-09 17:22:28 -0400330 acpi_status status;
331
332 if (ds) {
333 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
334 if (ACPI_SUCCESS(status) && sta)
335 return 1;
336 }
337 return 0;
338}
339
Len Brownc8f7a622006-07-09 17:22:28 -0400340/**
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200341 * hot_remove_dock_devices - Remove dock station devices.
342 * @ds: Dock station.
343 */
344static void hot_remove_dock_devices(struct dock_station *ds)
345{
346 struct dock_dependent_device *dd;
347
348 /*
349 * Walk the list in reverse order so that devices that have been added
350 * last are removed first (in case there are some indirect dependencies
351 * between them).
352 */
353 list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
354 dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false);
355
356 list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100357 acpi_bus_trim(dd->adev);
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200358}
359
360/**
361 * hotplug_dock_devices - Insert devices on a dock station.
Len Brownc8f7a622006-07-09 17:22:28 -0400362 * @ds: the dock station
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200363 * @event: either bus check or device check request
Len Brownc8f7a622006-07-09 17:22:28 -0400364 *
365 * Some devices on the dock station need to have drivers called
366 * to perform hotplug operations after a dock event has occurred.
367 * Traverse the list of dock devices that have registered a
368 * hotplug handler, and call the handler.
369 */
370static void hotplug_dock_devices(struct dock_station *ds, u32 event)
371{
372 struct dock_dependent_device *dd;
373
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200374 /* Call driver specific post-dock fixups. */
375 list_for_each_entry(dd, &ds->dependent_devices, list)
376 dock_hotplug_event(dd, event, DOCK_CALL_FIXUP);
377
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200378 /* Call driver specific hotplug functions. */
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200379 list_for_each_entry(dd, &ds->dependent_devices, list)
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200380 dock_hotplug_event(dd, event, DOCK_CALL_HANDLER);
Len Brownc8f7a622006-07-09 17:22:28 -0400381
382 /*
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100383 * Check if all devices have been enumerated already. If not, run
384 * acpi_bus_scan() for them and that will cause scan handlers to be
385 * attached to device objects or acpi_drivers to be stopped/started if
386 * they are present.
Len Brownc8f7a622006-07-09 17:22:28 -0400387 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100388 list_for_each_entry(dd, &ds->dependent_devices, list) {
389 struct acpi_device *adev = dd->adev;
390
391 if (!acpi_device_enumerated(adev)) {
392 int ret = acpi_bus_scan(adev->handle);
393 if (ret)
394 dev_dbg(&adev->dev, "scan error %d\n", -ret);
395 }
396 }
Len Brownc8f7a622006-07-09 17:22:28 -0400397}
398
399static void dock_event(struct dock_station *ds, u32 event, int num)
400{
Shaohua Lidb350b02008-08-28 10:03:58 +0800401 struct device *dev = &ds->dock_device->dev;
Holger Macht66b56822007-08-10 13:10:32 -0700402 char event_string[13];
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700403 char *envp[] = { event_string, NULL };
Shaohua Li1253f7a2008-08-28 10:06:16 +0800404 struct dock_dependent_device *dd;
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700405
406 if (num == UNDOCK_EVENT)
Holger Macht66b56822007-08-10 13:10:32 -0700407 sprintf(event_string, "EVENT=undock");
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700408 else
Holger Macht66b56822007-08-10 13:10:32 -0700409 sprintf(event_string, "EVENT=dock");
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700410
Kristen Carlson Accardi56690212006-08-01 14:59:19 -0700411 /*
Kristen Carlson Accardi8ea86e02006-12-11 12:05:08 -0800412 * Indicate that the status of the dock station has
413 * changed.
Kristen Carlson Accardi56690212006-08-01 14:59:19 -0700414 */
Shaohua Li1253f7a2008-08-28 10:06:16 +0800415 if (num == DOCK_EVENT)
416 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
417
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200418 list_for_each_entry(dd, &ds->dependent_devices, list)
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200419 dock_hotplug_event(dd, event, DOCK_CALL_UEVENT);
Alex Chiang747479a2009-10-19 15:14:50 -0600420
Shaohua Li1253f7a2008-08-28 10:06:16 +0800421 if (num != DOCK_EVENT)
422 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
Len Brownc8f7a622006-07-09 17:22:28 -0400423}
424
425/**
Len Brownc8f7a622006-07-09 17:22:28 -0400426 * handle_dock - handle a dock event
427 * @ds: the dock station
428 * @dock: to dock, or undock - that is the question
429 *
430 * Execute the _DCK method in response to an acpi event
431 */
432static void handle_dock(struct dock_station *ds, int dock)
433{
434 acpi_status status;
435 struct acpi_object_list arg_list;
436 union acpi_object arg;
Zhang Rui6a868e12013-09-03 08:32:10 +0800437 unsigned long long value;
Len Brownc8f7a622006-07-09 17:22:28 -0400438
Toshi Kanicd730182012-11-20 23:42:30 +0000439 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
Len Brownc8f7a622006-07-09 17:22:28 -0400440
441 /* _DCK method has one argument */
442 arg_list.count = 1;
443 arg_list.pointer = &arg;
444 arg.type = ACPI_TYPE_INTEGER;
445 arg.integer.value = dock;
Zhang Rui6a868e12013-09-03 08:32:10 +0800446 status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value);
Shaohua Lidb350b02008-08-28 10:03:58 +0800447 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
Toshi Kanicd730182012-11-20 23:42:30 +0000448 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
449 status);
Len Brownc8f7a622006-07-09 17:22:28 -0400450}
451
452static inline void dock(struct dock_station *ds)
453{
454 handle_dock(ds, 1);
455}
456
457static inline void undock(struct dock_station *ds)
458{
459 handle_dock(ds, 0);
460}
461
462static inline void begin_dock(struct dock_station *ds)
463{
464 ds->flags |= DOCK_DOCKING;
465}
466
467static inline void complete_dock(struct dock_station *ds)
468{
469 ds->flags &= ~(DOCK_DOCKING);
470 ds->last_dock_time = jiffies;
471}
472
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700473static inline void begin_undock(struct dock_station *ds)
474{
475 ds->flags |= DOCK_UNDOCKING;
476}
477
478static inline void complete_undock(struct dock_station *ds)
479{
480 ds->flags &= ~(DOCK_UNDOCKING);
481}
482
Len Brownc8f7a622006-07-09 17:22:28 -0400483/**
484 * dock_in_progress - see if we are in the middle of handling a dock event
485 * @ds: the dock station
486 *
487 * Sometimes while docking, false dock events can be sent to the driver
488 * because good connections aren't made or some other reason. Ignore these
489 * if we are in the middle of doing something.
490 */
491static int dock_in_progress(struct dock_station *ds)
492{
493 if ((ds->flags & DOCK_DOCKING) ||
494 time_before(jiffies, (ds->last_dock_time + HZ)))
495 return 1;
496 return 0;
497}
498
499/**
Len Brownc8f7a622006-07-09 17:22:28 -0400500 * register_hotplug_dock_device - register a hotplug function
501 * @handle: the handle of the device
Shaohua Li1253f7a2008-08-28 10:06:16 +0800502 * @ops: handlers to call after docking
Len Brownc8f7a622006-07-09 17:22:28 -0400503 * @context: device specific data
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200504 * @init: Optional initialization routine to run after registration
505 * @release: Optional release routine to run on unregistration
Len Brownc8f7a622006-07-09 17:22:28 -0400506 *
507 * If a driver would like to perform a hotplug operation after a dock
508 * event, they can register an acpi_notifiy_handler to be called by
509 * the dock driver after _DCK is executed.
510 */
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200511int register_hotplug_dock_device(acpi_handle handle,
512 const struct acpi_dock_ops *ops, void *context,
513 void (*init)(void *), void (*release)(void *))
Len Brownc8f7a622006-07-09 17:22:28 -0400514{
515 struct dock_dependent_device *dd;
Shaohua Lidb350b02008-08-28 10:03:58 +0800516 struct dock_station *dock_station;
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100517 struct acpi_device *adev;
Shaohua Li61b83692008-08-28 10:07:14 +0800518 int ret = -EINVAL;
Len Brownc8f7a622006-07-09 17:22:28 -0400519
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200520 if (WARN_ON(!context))
521 return -EINVAL;
522
Shaohua Lidb350b02008-08-28 10:03:58 +0800523 if (!dock_station_count)
Len Brownc8f7a622006-07-09 17:22:28 -0400524 return -ENODEV;
525
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100526 ret = acpi_bus_get_device(handle, &adev);
527 if (ret)
528 return ret;
529
Len Brownc8f7a622006-07-09 17:22:28 -0400530 /*
531 * make sure this handle is for a device dependent on the dock,
532 * this would include the dock station itself
533 */
Alex Chiang50d716e2009-10-01 11:59:23 -0600534 list_for_each_entry(dock_station, &dock_stations, sibling) {
Shaohua Li61b83692008-08-28 10:07:14 +0800535 /*
536 * An ATA bay can be in a dock and itself can be ejected
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +0800537 * separately, so there are two 'dock stations' which need the
Shaohua Li61b83692008-08-28 10:07:14 +0800538 * ops
539 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100540 dd = find_dock_dependent_device(dock_station, adev);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200541 if (dd && !dock_init_hotplug(dd, ops, context, init, release))
Shaohua Li61b83692008-08-28 10:07:14 +0800542 ret = 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400543 }
544
Shaohua Li61b83692008-08-28 10:07:14 +0800545 return ret;
Len Brownc8f7a622006-07-09 17:22:28 -0400546}
Len Brownc8f7a622006-07-09 17:22:28 -0400547EXPORT_SYMBOL_GPL(register_hotplug_dock_device);
548
549/**
550 * unregister_hotplug_dock_device - remove yourself from the hotplug list
551 * @handle: the acpi handle of the device
552 */
553void unregister_hotplug_dock_device(acpi_handle handle)
554{
555 struct dock_dependent_device *dd;
Shaohua Lidb350b02008-08-28 10:03:58 +0800556 struct dock_station *dock_station;
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100557 struct acpi_device *adev;
Len Brownc8f7a622006-07-09 17:22:28 -0400558
Shaohua Lidb350b02008-08-28 10:03:58 +0800559 if (!dock_station_count)
Len Brownc8f7a622006-07-09 17:22:28 -0400560 return;
561
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100562 if (acpi_bus_get_device(handle, &adev))
563 return;
564
Alex Chiang50d716e2009-10-01 11:59:23 -0600565 list_for_each_entry(dock_station, &dock_stations, sibling) {
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100566 dd = find_dock_dependent_device(dock_station, adev);
Shaohua Lidb350b02008-08-28 10:03:58 +0800567 if (dd)
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200568 dock_release_hotplug(dd);
Shaohua Lidb350b02008-08-28 10:03:58 +0800569 }
Len Brownc8f7a622006-07-09 17:22:28 -0400570}
Len Brownc8f7a622006-07-09 17:22:28 -0400571EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
572
573/**
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800574 * handle_eject_request - handle an undock request checking for error conditions
575 *
576 * Check to make sure the dock device is still present, then undock and
577 * hotremove all the devices that may need removing.
578 */
579static int handle_eject_request(struct dock_station *ds, u32 event)
580{
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800581 if (dock_in_progress(ds))
582 return -EBUSY;
583
584 /*
585 * here we need to generate the undock
586 * event prior to actually doing the undock
587 * so that the device struct still exists.
Holger Machtafd73012008-08-06 17:56:01 +0200588 * Also, even send the dock event if the
589 * device is not present anymore
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800590 */
591 dock_event(ds, event, UNDOCK_EVENT);
Holger Machtafd73012008-08-06 17:56:01 +0200592
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200593 hot_remove_dock_devices(ds);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800594 undock(ds);
Jiang Liuc9b54712013-06-29 00:24:42 +0800595 acpi_evaluate_lck(ds->handle, 0);
596 acpi_evaluate_ej0(ds->handle);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800597 if (dock_present(ds)) {
Toshi Kanicd730182012-11-20 23:42:30 +0000598 acpi_handle_err(ds->handle, "Unable to undock!\n");
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800599 return -EBUSY;
600 }
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700601 complete_undock(ds);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800602 return 0;
603}
604
605/**
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100606 * dock_notify - Handle ACPI dock notification.
607 * @adev: Dock station's ACPI device object.
608 * @event: Event code.
Len Brownc8f7a622006-07-09 17:22:28 -0400609 *
610 * If we are notified to dock, then check to see if the dock is
611 * present and then dock. Notify all drivers of the dock event,
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800612 * and then hotplug and devices that may need hotplugging.
Len Brownc8f7a622006-07-09 17:22:28 -0400613 */
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100614int dock_notify(struct acpi_device *adev, u32 event)
Len Brownc8f7a622006-07-09 17:22:28 -0400615{
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100616 acpi_handle handle = adev->handle;
617 struct dock_station *ds = find_dock_station(handle);
Shaohua Lidb350b02008-08-28 10:03:58 +0800618 int surprise_removal = 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400619
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100620 if (!ds)
621 return -ENODEV;
622
Shaohua Lidb350b02008-08-28 10:03:58 +0800623 /*
624 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
625 * is sent and _DCK is present, it is assumed to mean an undock
626 * request.
627 */
628 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK)
629 event = ACPI_NOTIFY_EJECT_REQUEST;
630
631 /*
632 * dock station: BUS_CHECK - docked or surprise removal
633 * DEVICE_CHECK - undocked
634 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
635 *
636 * To simplify event handling, dock dependent device handler always
637 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
638 * ACPI_NOTIFY_EJECT_REQUEST for removal
639 */
Len Brownc8f7a622006-07-09 17:22:28 -0400640 switch (event) {
641 case ACPI_NOTIFY_BUS_CHECK:
Shaohua Lidb350b02008-08-28 10:03:58 +0800642 case ACPI_NOTIFY_DEVICE_CHECK:
Rafael J. Wysocki0a8e5c32014-02-10 13:44:20 +0100643 if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) {
Len Brownc8f7a622006-07-09 17:22:28 -0400644 begin_dock(ds);
645 dock(ds);
646 if (!dock_present(ds)) {
Toshi Kanicd730182012-11-20 23:42:30 +0000647 acpi_handle_err(handle, "Unable to dock!\n");
Shaohua Li8b595602008-08-28 10:02:03 +0800648 complete_dock(ds);
Len Brownc8f7a622006-07-09 17:22:28 -0400649 break;
650 }
Len Brownc8f7a622006-07-09 17:22:28 -0400651 hotplug_dock_devices(ds, event);
652 complete_dock(ds);
653 dock_event(ds, event, DOCK_EVENT);
Jiang Liuc9b54712013-06-29 00:24:42 +0800654 acpi_evaluate_lck(ds->handle, 1);
Lin Ming3a378982010-12-13 13:36:15 +0800655 acpi_update_all_gpes();
Shaohua Lidb350b02008-08-28 10:03:58 +0800656 break;
Len Brownc8f7a622006-07-09 17:22:28 -0400657 }
Shaohua Lidb350b02008-08-28 10:03:58 +0800658 if (dock_present(ds) || dock_in_progress(ds))
659 break;
660 /* This is a surprise removal */
661 surprise_removal = 1;
662 event = ACPI_NOTIFY_EJECT_REQUEST;
663 /* Fall back */
Len Brownc8f7a622006-07-09 17:22:28 -0400664 case ACPI_NOTIFY_EJECT_REQUEST:
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700665 begin_undock(ds);
Shaohua Lif730ae12008-08-28 10:05:45 +0800666 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
667 || surprise_removal)
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700668 handle_eject_request(ds, event);
669 else
670 dock_event(ds, event, UNDOCK_EVENT);
Len Brownc8f7a622006-07-09 17:22:28 -0400671 break;
Len Brownc8f7a622006-07-09 17:22:28 -0400672 }
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100673 return 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400674}
675
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800676/*
677 * show_docked - read method for "docked" file in sysfs
678 */
679static ssize_t show_docked(struct device *dev,
680 struct device_attribute *attr, char *buf)
681{
Alex Chiangfe06fba2009-10-19 15:14:45 -0600682 struct dock_station *dock_station = dev->platform_data;
Rafael J. Wysockiab62f9c2014-02-15 01:29:06 +0100683 struct acpi_device *adev = NULL;
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800684
Rafael J. Wysockiab62f9c2014-02-15 01:29:06 +0100685 acpi_bus_get_device(dock_station->handle, &adev);
686 return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800687}
Adrian Bunke5685b92007-10-24 18:24:42 +0200688static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800689
690/*
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700691 * show_flags - read method for flags file in sysfs
692 */
693static ssize_t show_flags(struct device *dev,
694 struct device_attribute *attr, char *buf)
695{
Alex Chiangfe06fba2009-10-19 15:14:45 -0600696 struct dock_station *dock_station = dev->platform_data;
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700697 return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
698
699}
Adrian Bunke5685b92007-10-24 18:24:42 +0200700static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700701
702/*
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800703 * write_undock - write method for "undock" file in sysfs
704 */
705static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
706 const char *buf, size_t count)
707{
708 int ret;
Alex Chiangfe06fba2009-10-19 15:14:45 -0600709 struct dock_station *dock_station = dev->platform_data;
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800710
711 if (!count)
712 return -EINVAL;
713
Rafael J. Wysocki81120062013-06-16 00:38:30 +0200714 acpi_scan_lock_acquire();
Holger Macht9171f8342008-03-12 01:07:27 +0100715 begin_undock(dock_station);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800716 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
Rafael J. Wysocki81120062013-06-16 00:38:30 +0200717 acpi_scan_lock_release();
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800718 return ret ? ret: count;
719}
Adrian Bunke5685b92007-10-24 18:24:42 +0200720static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800721
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800722/*
723 * show_dock_uid - read method for "uid" file in sysfs
724 */
725static ssize_t show_dock_uid(struct device *dev,
726 struct device_attribute *attr, char *buf)
727{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400728 unsigned long long lbuf;
Alex Chiangfe06fba2009-10-19 15:14:45 -0600729 struct dock_station *dock_station = dev->platform_data;
Kristen Carlson Accardi38ff4ff2007-05-09 15:04:24 -0700730 acpi_status status = acpi_evaluate_integer(dock_station->handle,
731 "_UID", NULL, &lbuf);
732 if (ACPI_FAILURE(status))
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800733 return 0;
Kristen Carlson Accardi38ff4ff2007-05-09 15:04:24 -0700734
Matthew Wilcox27663c52008-10-10 02:22:59 -0400735 return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800736}
Adrian Bunke5685b92007-10-24 18:24:42 +0200737static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800738
Shaohua Li8652b002008-08-28 10:07:45 +0800739static ssize_t show_dock_type(struct device *dev,
740 struct device_attribute *attr, char *buf)
741{
Alex Chiangfe06fba2009-10-19 15:14:45 -0600742 struct dock_station *dock_station = dev->platform_data;
Shaohua Li8652b002008-08-28 10:07:45 +0800743 char *type;
744
745 if (dock_station->flags & DOCK_IS_DOCK)
746 type = "dock_station";
747 else if (dock_station->flags & DOCK_IS_ATA)
748 type = "ata_bay";
749 else if (dock_station->flags & DOCK_IS_BAT)
750 type = "battery_bay";
751 else
752 type = "unknown";
753
754 return snprintf(buf, PAGE_SIZE, "%s\n", type);
755}
756static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
757
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600758static struct attribute *dock_attributes[] = {
759 &dev_attr_docked.attr,
760 &dev_attr_flags.attr,
761 &dev_attr_undock.attr,
762 &dev_attr_uid.attr,
763 &dev_attr_type.attr,
764 NULL
765};
766
767static struct attribute_group dock_attribute_group = {
768 .attrs = dock_attributes
769};
770
Len Brownc8f7a622006-07-09 17:22:28 -0400771/**
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100772 * acpi_dock_add - Add a new dock station
773 * @adev: Dock station ACPI device object.
Len Brownc8f7a622006-07-09 17:22:28 -0400774 *
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100775 * allocated and initialize a new dock station device.
Len Brownc8f7a622006-07-09 17:22:28 -0400776 */
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100777void acpi_dock_add(struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400778{
Rafael J. Wysocki2efbca42013-07-05 03:23:36 +0200779 struct dock_station *dock_station, ds = { NULL, };
Rafael J. Wysockiaf8874492014-02-16 00:09:47 +0100780 struct platform_device_info pdevinfo;
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100781 acpi_handle handle = adev->handle;
Alex Chiang747479a2009-10-19 15:14:50 -0600782 struct platform_device *dd;
Rafael J. Wysocki2efbca42013-07-05 03:23:36 +0200783 int ret;
Len Brownc8f7a622006-07-09 17:22:28 -0400784
Rafael J. Wysockiaf8874492014-02-16 00:09:47 +0100785 memset(&pdevinfo, 0, sizeof(pdevinfo));
786 pdevinfo.name = "dock";
787 pdevinfo.id = dock_station_count;
788 pdevinfo.acpi_node.companion = adev;
789 pdevinfo.data = &ds;
790 pdevinfo.size_data = sizeof(ds);
791 dd = platform_device_register_full(&pdevinfo);
Alex Chiang747479a2009-10-19 15:14:50 -0600792 if (IS_ERR(dd))
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100793 return;
Alex Chiang9751cb72009-10-19 15:14:40 -0600794
Alex Chiang747479a2009-10-19 15:14:50 -0600795 dock_station = dd->dev.platform_data;
796
Len Brownc8f7a622006-07-09 17:22:28 -0400797 dock_station->handle = handle;
Alex Chiang747479a2009-10-19 15:14:50 -0600798 dock_station->dock_device = dd;
Len Brownc8f7a622006-07-09 17:22:28 -0400799 dock_station->last_dock_time = jiffies - HZ;
Len Brownc8f7a622006-07-09 17:22:28 -0400800
Alex Chiang747479a2009-10-19 15:14:50 -0600801 INIT_LIST_HEAD(&dock_station->sibling);
Alex Chiang747479a2009-10-19 15:14:50 -0600802 INIT_LIST_HEAD(&dock_station->dependent_devices);
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700803
Kristen Carlson Accardi9ef2a9a2007-05-09 15:09:12 -0700804 /* we want the dock device to send uevents */
Alex Chiang747479a2009-10-19 15:14:50 -0600805 dev_set_uevent_suppress(&dd->dev, 0);
Kristen Carlson Accardi9ef2a9a2007-05-09 15:09:12 -0700806
Jiang Liuc9b54712013-06-29 00:24:42 +0800807 if (acpi_dock_match(handle))
Shaohua Lidb350b02008-08-28 10:03:58 +0800808 dock_station->flags |= DOCK_IS_DOCK;
Jiang Liuc9b54712013-06-29 00:24:42 +0800809 if (acpi_ata_match(handle))
Shaohua Lidb350b02008-08-28 10:03:58 +0800810 dock_station->flags |= DOCK_IS_ATA;
Rafael J. Wysockib43109f2014-02-16 00:09:34 +0100811 if (acpi_device_is_battery(adev))
Shaohua Lidb350b02008-08-28 10:03:58 +0800812 dock_station->flags |= DOCK_IS_BAT;
813
Alex Chiang747479a2009-10-19 15:14:50 -0600814 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
Shaohua Li8652b002008-08-28 10:07:45 +0800815 if (ret)
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600816 goto err_unregister;
Kristen Carlson Accardi671adbe2006-12-04 14:49:43 -0800817
Len Brownc8f7a622006-07-09 17:22:28 -0400818 /* add the dock station as a device dependent on itself */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100819 ret = add_dock_dependent_device(dock_station, adev);
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600820 if (ret)
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600821 goto err_rmgroup;
Len Brownc8f7a622006-07-09 17:22:28 -0400822
Shaohua Lidb350b02008-08-28 10:03:58 +0800823 dock_station_count++;
Alex Chiang50d716e2009-10-01 11:59:23 -0600824 list_add(&dock_station->sibling, &dock_stations);
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100825 adev->flags.is_dock_station = true;
826 dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n",
827 dock_station_count);
828 return;
Len Brownc8f7a622006-07-09 17:22:28 -0400829
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600830err_rmgroup:
Rafael J. Wysockia30c4c52013-06-30 23:50:24 +0200831 remove_dock_dependent_devices(dock_station);
Alex Chiang747479a2009-10-19 15:14:50 -0600832 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600833err_unregister:
Alex Chiang747479a2009-10-19 15:14:50 -0600834 platform_device_unregister(dd);
Toshi Kanicd730182012-11-20 23:42:30 +0000835 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
Len Brownc8f7a622006-07-09 17:22:28 -0400836}