blob: a88fad9ff2346a62d1ee3e8fc4ad38c643b40fcc [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 }
Rafael J. Wysockibe27b3d2014-02-21 01:10:27 +0100206 } else if (cb_type == DOCK_CALL_UEVENT) {
207 void (*uevent)(struct acpi_device *, u32);
208
209 uevent = adev->hp->uevent;
210 if (uevent) {
211 acpi_unlock_hp_context();
212 uevent(adev, event);
213 return;
214 }
Rafael J. Wysockiedf5bf32014-02-21 01:10:18 +0100215 } else {
216 int (*notify)(struct acpi_device *, u32);
217
Rafael J. Wysockibe27b3d2014-02-21 01:10:27 +0100218 notify = adev->hp->notify;
Rafael J. Wysockiedf5bf32014-02-21 01:10:18 +0100219 if (notify) {
220 acpi_unlock_hp_context();
221 notify(adev, event);
222 return;
223 }
224 }
225
226 no_context:
227 acpi_unlock_hp_context();
228
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200229 mutex_lock(&hotplug_lock);
230
231 if (dd->hp_context) {
232 run = true;
233 dd->hp_refcount++;
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200234 if (dd->hp_ops) {
235 switch (cb_type) {
236 case DOCK_CALL_FIXUP:
237 cb = dd->hp_ops->fixup;
238 break;
239 case DOCK_CALL_UEVENT:
240 cb = dd->hp_ops->uevent;
241 break;
242 default:
243 cb = dd->hp_ops->handler;
244 }
245 }
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200246 }
247
248 mutex_unlock(&hotplug_lock);
249
250 if (!run)
251 return;
252
253 if (cb)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100254 cb(dd->adev->handle, event, dd->hp_context);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200255
256 dock_release_hotplug(dd);
Len Brownc8f7a622006-07-09 17:22:28 -0400257}
258
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100259static struct dock_station *find_dock_station(acpi_handle handle)
260{
261 struct dock_station *ds;
262
263 list_for_each_entry(ds, &dock_stations, sibling)
264 if (ds->handle == handle)
265 return ds;
266
267 return NULL;
268}
269
Len Brownc8f7a622006-07-09 17:22:28 -0400270/**
271 * find_dock_dependent_device - get a device dependent on this dock
272 * @ds: the dock station
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100273 * @adev: ACPI device object to find.
Len Brownc8f7a622006-07-09 17:22:28 -0400274 *
275 * iterate over the dependent device list for this dock. If the
276 * dependent device matches the handle, return.
277 */
278static struct dock_dependent_device *
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100279find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400280{
281 struct dock_dependent_device *dd;
282
Jiang Liued633e72013-06-29 00:24:35 +0800283 list_for_each_entry(dd, &ds->dependent_devices, list)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100284 if (adev == dd->adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400285 return dd;
Jiang Liued633e72013-06-29 00:24:35 +0800286
Len Brownc8f7a622006-07-09 17:22:28 -0400287 return NULL;
288}
289
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100290void register_dock_dependent_device(struct acpi_device *adev,
291 acpi_handle dshandle)
292{
293 struct dock_station *ds = find_dock_station(dshandle);
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100294
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100295 if (ds && !find_dock_dependent_device(ds, adev))
296 add_dock_dependent_device(ds, adev);
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100297}
298
Len Brownc8f7a622006-07-09 17:22:28 -0400299/*****************************************************************************
300 * Dock functions *
301 *****************************************************************************/
Shaohua Lidb350b02008-08-28 10:03:58 +0800302
Len Brownc8f7a622006-07-09 17:22:28 -0400303/**
304 * is_dock_device - see if a device is on a dock station
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100305 * @adev: ACPI device object to check.
Len Brownc8f7a622006-07-09 17:22:28 -0400306 *
307 * If this device is either the dock station itself,
308 * or is a device dependent on the dock station, then it
309 * is a dock device
310 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100311int is_dock_device(struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400312{
Shaohua Lidb350b02008-08-28 10:03:58 +0800313 struct dock_station *dock_station;
314
315 if (!dock_station_count)
Len Brownc8f7a622006-07-09 17:22:28 -0400316 return 0;
317
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100318 if (acpi_dock_match(adev->handle))
Len Brownc8f7a622006-07-09 17:22:28 -0400319 return 1;
Alex Chiang747479a2009-10-19 15:14:50 -0600320
321 list_for_each_entry(dock_station, &dock_stations, sibling)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100322 if (find_dock_dependent_device(dock_station, adev))
Shaohua Lidb350b02008-08-28 10:03:58 +0800323 return 1;
Len Brownc8f7a622006-07-09 17:22:28 -0400324
325 return 0;
326}
Len Brownc8f7a622006-07-09 17:22:28 -0400327EXPORT_SYMBOL_GPL(is_dock_device);
328
329/**
330 * dock_present - see if the dock station is present.
331 * @ds: the dock station
332 *
333 * execute the _STA method. note that present does not
334 * imply that we are docked.
335 */
336static int dock_present(struct dock_station *ds)
337{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400338 unsigned long long sta;
Len Brownc8f7a622006-07-09 17:22:28 -0400339 acpi_status status;
340
341 if (ds) {
342 status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
343 if (ACPI_SUCCESS(status) && sta)
344 return 1;
345 }
346 return 0;
347}
348
Len Brownc8f7a622006-07-09 17:22:28 -0400349/**
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200350 * hot_remove_dock_devices - Remove dock station devices.
351 * @ds: Dock station.
352 */
353static void hot_remove_dock_devices(struct dock_station *ds)
354{
355 struct dock_dependent_device *dd;
356
357 /*
358 * Walk the list in reverse order so that devices that have been added
359 * last are removed first (in case there are some indirect dependencies
360 * between them).
361 */
362 list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
363 dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false);
364
365 list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100366 acpi_bus_trim(dd->adev);
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200367}
368
369/**
370 * hotplug_dock_devices - Insert devices on a dock station.
Len Brownc8f7a622006-07-09 17:22:28 -0400371 * @ds: the dock station
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200372 * @event: either bus check or device check request
Len Brownc8f7a622006-07-09 17:22:28 -0400373 *
374 * Some devices on the dock station need to have drivers called
375 * to perform hotplug operations after a dock event has occurred.
376 * Traverse the list of dock devices that have registered a
377 * hotplug handler, and call the handler.
378 */
379static void hotplug_dock_devices(struct dock_station *ds, u32 event)
380{
381 struct dock_dependent_device *dd;
382
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200383 /* Call driver specific post-dock fixups. */
384 list_for_each_entry(dd, &ds->dependent_devices, list)
385 dock_hotplug_event(dd, event, DOCK_CALL_FIXUP);
386
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200387 /* Call driver specific hotplug functions. */
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200388 list_for_each_entry(dd, &ds->dependent_devices, list)
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200389 dock_hotplug_event(dd, event, DOCK_CALL_HANDLER);
Len Brownc8f7a622006-07-09 17:22:28 -0400390
391 /*
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100392 * Check if all devices have been enumerated already. If not, run
393 * acpi_bus_scan() for them and that will cause scan handlers to be
394 * attached to device objects or acpi_drivers to be stopped/started if
395 * they are present.
Len Brownc8f7a622006-07-09 17:22:28 -0400396 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100397 list_for_each_entry(dd, &ds->dependent_devices, list) {
398 struct acpi_device *adev = dd->adev;
399
400 if (!acpi_device_enumerated(adev)) {
401 int ret = acpi_bus_scan(adev->handle);
402 if (ret)
403 dev_dbg(&adev->dev, "scan error %d\n", -ret);
404 }
405 }
Len Brownc8f7a622006-07-09 17:22:28 -0400406}
407
408static void dock_event(struct dock_station *ds, u32 event, int num)
409{
Shaohua Lidb350b02008-08-28 10:03:58 +0800410 struct device *dev = &ds->dock_device->dev;
Holger Macht66b56822007-08-10 13:10:32 -0700411 char event_string[13];
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700412 char *envp[] = { event_string, NULL };
Shaohua Li1253f7a2008-08-28 10:06:16 +0800413 struct dock_dependent_device *dd;
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700414
415 if (num == UNDOCK_EVENT)
Holger Macht66b56822007-08-10 13:10:32 -0700416 sprintf(event_string, "EVENT=undock");
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700417 else
Holger Macht66b56822007-08-10 13:10:32 -0700418 sprintf(event_string, "EVENT=dock");
Kristen Carlson Accardi79a8f702007-05-09 15:10:22 -0700419
Kristen Carlson Accardi56690212006-08-01 14:59:19 -0700420 /*
Kristen Carlson Accardi8ea86e02006-12-11 12:05:08 -0800421 * Indicate that the status of the dock station has
422 * changed.
Kristen Carlson Accardi56690212006-08-01 14:59:19 -0700423 */
Shaohua Li1253f7a2008-08-28 10:06:16 +0800424 if (num == DOCK_EVENT)
425 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
426
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200427 list_for_each_entry(dd, &ds->dependent_devices, list)
Rafael J. Wysockif09ce742013-07-05 03:03:25 +0200428 dock_hotplug_event(dd, event, DOCK_CALL_UEVENT);
Alex Chiang747479a2009-10-19 15:14:50 -0600429
Shaohua Li1253f7a2008-08-28 10:06:16 +0800430 if (num != DOCK_EVENT)
431 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
Len Brownc8f7a622006-07-09 17:22:28 -0400432}
433
434/**
Len Brownc8f7a622006-07-09 17:22:28 -0400435 * handle_dock - handle a dock event
436 * @ds: the dock station
437 * @dock: to dock, or undock - that is the question
438 *
439 * Execute the _DCK method in response to an acpi event
440 */
441static void handle_dock(struct dock_station *ds, int dock)
442{
443 acpi_status status;
444 struct acpi_object_list arg_list;
445 union acpi_object arg;
Zhang Rui6a868e12013-09-03 08:32:10 +0800446 unsigned long long value;
Len Brownc8f7a622006-07-09 17:22:28 -0400447
Toshi Kanicd730182012-11-20 23:42:30 +0000448 acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
Len Brownc8f7a622006-07-09 17:22:28 -0400449
450 /* _DCK method has one argument */
451 arg_list.count = 1;
452 arg_list.pointer = &arg;
453 arg.type = ACPI_TYPE_INTEGER;
454 arg.integer.value = dock;
Zhang Rui6a868e12013-09-03 08:32:10 +0800455 status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value);
Shaohua Lidb350b02008-08-28 10:03:58 +0800456 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
Toshi Kanicd730182012-11-20 23:42:30 +0000457 acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
458 status);
Len Brownc8f7a622006-07-09 17:22:28 -0400459}
460
461static inline void dock(struct dock_station *ds)
462{
463 handle_dock(ds, 1);
464}
465
466static inline void undock(struct dock_station *ds)
467{
468 handle_dock(ds, 0);
469}
470
471static inline void begin_dock(struct dock_station *ds)
472{
473 ds->flags |= DOCK_DOCKING;
474}
475
476static inline void complete_dock(struct dock_station *ds)
477{
478 ds->flags &= ~(DOCK_DOCKING);
479 ds->last_dock_time = jiffies;
480}
481
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700482static inline void begin_undock(struct dock_station *ds)
483{
484 ds->flags |= DOCK_UNDOCKING;
485}
486
487static inline void complete_undock(struct dock_station *ds)
488{
489 ds->flags &= ~(DOCK_UNDOCKING);
490}
491
Len Brownc8f7a622006-07-09 17:22:28 -0400492/**
493 * dock_in_progress - see if we are in the middle of handling a dock event
494 * @ds: the dock station
495 *
496 * Sometimes while docking, false dock events can be sent to the driver
497 * because good connections aren't made or some other reason. Ignore these
498 * if we are in the middle of doing something.
499 */
500static int dock_in_progress(struct dock_station *ds)
501{
502 if ((ds->flags & DOCK_DOCKING) ||
503 time_before(jiffies, (ds->last_dock_time + HZ)))
504 return 1;
505 return 0;
506}
507
508/**
Len Brownc8f7a622006-07-09 17:22:28 -0400509 * register_hotplug_dock_device - register a hotplug function
510 * @handle: the handle of the device
Shaohua Li1253f7a2008-08-28 10:06:16 +0800511 * @ops: handlers to call after docking
Len Brownc8f7a622006-07-09 17:22:28 -0400512 * @context: device specific data
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200513 * @init: Optional initialization routine to run after registration
514 * @release: Optional release routine to run on unregistration
Len Brownc8f7a622006-07-09 17:22:28 -0400515 *
516 * If a driver would like to perform a hotplug operation after a dock
517 * event, they can register an acpi_notifiy_handler to be called by
518 * the dock driver after _DCK is executed.
519 */
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200520int register_hotplug_dock_device(acpi_handle handle,
521 const struct acpi_dock_ops *ops, void *context,
522 void (*init)(void *), void (*release)(void *))
Len Brownc8f7a622006-07-09 17:22:28 -0400523{
524 struct dock_dependent_device *dd;
Shaohua Lidb350b02008-08-28 10:03:58 +0800525 struct dock_station *dock_station;
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100526 struct acpi_device *adev;
Shaohua Li61b83692008-08-28 10:07:14 +0800527 int ret = -EINVAL;
Len Brownc8f7a622006-07-09 17:22:28 -0400528
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200529 if (WARN_ON(!context))
530 return -EINVAL;
531
Shaohua Lidb350b02008-08-28 10:03:58 +0800532 if (!dock_station_count)
Len Brownc8f7a622006-07-09 17:22:28 -0400533 return -ENODEV;
534
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100535 ret = acpi_bus_get_device(handle, &adev);
536 if (ret)
537 return ret;
538
Len Brownc8f7a622006-07-09 17:22:28 -0400539 /*
540 * make sure this handle is for a device dependent on the dock,
541 * this would include the dock station itself
542 */
Alex Chiang50d716e2009-10-01 11:59:23 -0600543 list_for_each_entry(dock_station, &dock_stations, sibling) {
Shaohua Li61b83692008-08-28 10:07:14 +0800544 /*
545 * An ATA bay can be in a dock and itself can be ejected
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800546 * separately, so there are two 'dock stations' which need the
Shaohua Li61b83692008-08-28 10:07:14 +0800547 * ops
548 */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100549 dd = find_dock_dependent_device(dock_station, adev);
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200550 if (dd && !dock_init_hotplug(dd, ops, context, init, release))
Shaohua Li61b83692008-08-28 10:07:14 +0800551 ret = 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400552 }
553
Shaohua Li61b83692008-08-28 10:07:14 +0800554 return ret;
Len Brownc8f7a622006-07-09 17:22:28 -0400555}
Len Brownc8f7a622006-07-09 17:22:28 -0400556EXPORT_SYMBOL_GPL(register_hotplug_dock_device);
557
558/**
559 * unregister_hotplug_dock_device - remove yourself from the hotplug list
560 * @handle: the acpi handle of the device
561 */
562void unregister_hotplug_dock_device(acpi_handle handle)
563{
564 struct dock_dependent_device *dd;
Shaohua Lidb350b02008-08-28 10:03:58 +0800565 struct dock_station *dock_station;
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100566 struct acpi_device *adev;
Len Brownc8f7a622006-07-09 17:22:28 -0400567
Shaohua Lidb350b02008-08-28 10:03:58 +0800568 if (!dock_station_count)
Len Brownc8f7a622006-07-09 17:22:28 -0400569 return;
570
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100571 if (acpi_bus_get_device(handle, &adev))
572 return;
573
Alex Chiang50d716e2009-10-01 11:59:23 -0600574 list_for_each_entry(dock_station, &dock_stations, sibling) {
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100575 dd = find_dock_dependent_device(dock_station, adev);
Shaohua Lidb350b02008-08-28 10:03:58 +0800576 if (dd)
Rafael J. Wysocki21a31012013-06-24 11:22:53 +0200577 dock_release_hotplug(dd);
Shaohua Lidb350b02008-08-28 10:03:58 +0800578 }
Len Brownc8f7a622006-07-09 17:22:28 -0400579}
Len Brownc8f7a622006-07-09 17:22:28 -0400580EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
581
582/**
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800583 * handle_eject_request - handle an undock request checking for error conditions
584 *
585 * Check to make sure the dock device is still present, then undock and
586 * hotremove all the devices that may need removing.
587 */
588static int handle_eject_request(struct dock_station *ds, u32 event)
589{
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800590 if (dock_in_progress(ds))
591 return -EBUSY;
592
593 /*
594 * here we need to generate the undock
595 * event prior to actually doing the undock
596 * so that the device struct still exists.
Holger Machtafd73012008-08-06 17:56:01 +0200597 * Also, even send the dock event if the
598 * device is not present anymore
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800599 */
600 dock_event(ds, event, UNDOCK_EVENT);
Holger Machtafd73012008-08-06 17:56:01 +0200601
Rafael J. Wysocki37f90872013-06-30 23:46:42 +0200602 hot_remove_dock_devices(ds);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800603 undock(ds);
Jiang Liuc9b54712013-06-29 00:24:42 +0800604 acpi_evaluate_lck(ds->handle, 0);
605 acpi_evaluate_ej0(ds->handle);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800606 if (dock_present(ds)) {
Toshi Kanicd730182012-11-20 23:42:30 +0000607 acpi_handle_err(ds->handle, "Unable to undock!\n");
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800608 return -EBUSY;
609 }
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700610 complete_undock(ds);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800611 return 0;
612}
613
614/**
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100615 * dock_notify - Handle ACPI dock notification.
616 * @adev: Dock station's ACPI device object.
617 * @event: Event code.
Len Brownc8f7a622006-07-09 17:22:28 -0400618 *
619 * If we are notified to dock, then check to see if the dock is
620 * present and then dock. Notify all drivers of the dock event,
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800621 * and then hotplug and devices that may need hotplugging.
Len Brownc8f7a622006-07-09 17:22:28 -0400622 */
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100623int dock_notify(struct acpi_device *adev, u32 event)
Len Brownc8f7a622006-07-09 17:22:28 -0400624{
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100625 acpi_handle handle = adev->handle;
626 struct dock_station *ds = find_dock_station(handle);
Shaohua Lidb350b02008-08-28 10:03:58 +0800627 int surprise_removal = 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400628
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100629 if (!ds)
630 return -ENODEV;
631
Shaohua Lidb350b02008-08-28 10:03:58 +0800632 /*
633 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
634 * is sent and _DCK is present, it is assumed to mean an undock
635 * request.
636 */
637 if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK)
638 event = ACPI_NOTIFY_EJECT_REQUEST;
639
640 /*
641 * dock station: BUS_CHECK - docked or surprise removal
642 * DEVICE_CHECK - undocked
643 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
644 *
645 * To simplify event handling, dock dependent device handler always
646 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
647 * ACPI_NOTIFY_EJECT_REQUEST for removal
648 */
Len Brownc8f7a622006-07-09 17:22:28 -0400649 switch (event) {
650 case ACPI_NOTIFY_BUS_CHECK:
Shaohua Lidb350b02008-08-28 10:03:58 +0800651 case ACPI_NOTIFY_DEVICE_CHECK:
Rafael J. Wysocki0a8e5c32014-02-10 13:44:20 +0100652 if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) {
Len Brownc8f7a622006-07-09 17:22:28 -0400653 begin_dock(ds);
654 dock(ds);
655 if (!dock_present(ds)) {
Toshi Kanicd730182012-11-20 23:42:30 +0000656 acpi_handle_err(handle, "Unable to dock!\n");
Shaohua Li8b595602008-08-28 10:02:03 +0800657 complete_dock(ds);
Len Brownc8f7a622006-07-09 17:22:28 -0400658 break;
659 }
Len Brownc8f7a622006-07-09 17:22:28 -0400660 hotplug_dock_devices(ds, event);
661 complete_dock(ds);
662 dock_event(ds, event, DOCK_EVENT);
Jiang Liuc9b54712013-06-29 00:24:42 +0800663 acpi_evaluate_lck(ds->handle, 1);
Lin Ming3a378982010-12-13 13:36:15 +0800664 acpi_update_all_gpes();
Shaohua Lidb350b02008-08-28 10:03:58 +0800665 break;
Len Brownc8f7a622006-07-09 17:22:28 -0400666 }
Shaohua Lidb350b02008-08-28 10:03:58 +0800667 if (dock_present(ds) || dock_in_progress(ds))
668 break;
669 /* This is a surprise removal */
670 surprise_removal = 1;
671 event = ACPI_NOTIFY_EJECT_REQUEST;
672 /* Fall back */
Len Brownc8f7a622006-07-09 17:22:28 -0400673 case ACPI_NOTIFY_EJECT_REQUEST:
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700674 begin_undock(ds);
Shaohua Lif730ae12008-08-28 10:05:45 +0800675 if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
676 || surprise_removal)
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700677 handle_eject_request(ds, event);
678 else
679 dock_event(ds, event, UNDOCK_EVENT);
Len Brownc8f7a622006-07-09 17:22:28 -0400680 break;
Len Brownc8f7a622006-07-09 17:22:28 -0400681 }
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100682 return 0;
Len Brownc8f7a622006-07-09 17:22:28 -0400683}
684
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800685/*
686 * show_docked - read method for "docked" file in sysfs
687 */
688static ssize_t show_docked(struct device *dev,
689 struct device_attribute *attr, char *buf)
690{
Alex Chiangfe06fba2009-10-19 15:14:45 -0600691 struct dock_station *dock_station = dev->platform_data;
Rafael J. Wysockiab62f9c2014-02-15 01:29:06 +0100692 struct acpi_device *adev = NULL;
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800693
Rafael J. Wysockiab62f9c2014-02-15 01:29:06 +0100694 acpi_bus_get_device(dock_station->handle, &adev);
695 return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800696}
Adrian Bunke5685b92007-10-24 18:24:42 +0200697static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800698
699/*
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700700 * show_flags - read method for flags file in sysfs
701 */
702static ssize_t show_flags(struct device *dev,
703 struct device_attribute *attr, char *buf)
704{
Alex Chiangfe06fba2009-10-19 15:14:45 -0600705 struct dock_station *dock_station = dev->platform_data;
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700706 return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
707
708}
Adrian Bunke5685b92007-10-24 18:24:42 +0200709static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700710
711/*
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800712 * write_undock - write method for "undock" file in sysfs
713 */
714static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
715 const char *buf, size_t count)
716{
717 int ret;
Alex Chiangfe06fba2009-10-19 15:14:45 -0600718 struct dock_station *dock_station = dev->platform_data;
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800719
720 if (!count)
721 return -EINVAL;
722
Rafael J. Wysocki81120062013-06-16 00:38:30 +0200723 acpi_scan_lock_acquire();
Holger Macht9171f832008-03-12 01:07:27 +0100724 begin_undock(dock_station);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800725 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
Rafael J. Wysocki81120062013-06-16 00:38:30 +0200726 acpi_scan_lock_release();
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800727 return ret ? ret: count;
728}
Adrian Bunke5685b92007-10-24 18:24:42 +0200729static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
brandon@ifup.orgc80fdbe2006-12-04 14:49:58 -0800730
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800731/*
732 * show_dock_uid - read method for "uid" file in sysfs
733 */
734static ssize_t show_dock_uid(struct device *dev,
735 struct device_attribute *attr, char *buf)
736{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400737 unsigned long long lbuf;
Alex Chiangfe06fba2009-10-19 15:14:45 -0600738 struct dock_station *dock_station = dev->platform_data;
Kristen Carlson Accardi38ff4ff2007-05-09 15:04:24 -0700739 acpi_status status = acpi_evaluate_integer(dock_station->handle,
740 "_UID", NULL, &lbuf);
741 if (ACPI_FAILURE(status))
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800742 return 0;
Kristen Carlson Accardi38ff4ff2007-05-09 15:04:24 -0700743
Matthew Wilcox27663c52008-10-10 02:22:59 -0400744 return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800745}
Adrian Bunke5685b92007-10-24 18:24:42 +0200746static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
Ilya A. Volynets-Evenbakhac122bb2007-02-19 15:19:31 -0800747
Shaohua Li8652b002008-08-28 10:07:45 +0800748static ssize_t show_dock_type(struct device *dev,
749 struct device_attribute *attr, char *buf)
750{
Alex Chiangfe06fba2009-10-19 15:14:45 -0600751 struct dock_station *dock_station = dev->platform_data;
Shaohua Li8652b002008-08-28 10:07:45 +0800752 char *type;
753
754 if (dock_station->flags & DOCK_IS_DOCK)
755 type = "dock_station";
756 else if (dock_station->flags & DOCK_IS_ATA)
757 type = "ata_bay";
758 else if (dock_station->flags & DOCK_IS_BAT)
759 type = "battery_bay";
760 else
761 type = "unknown";
762
763 return snprintf(buf, PAGE_SIZE, "%s\n", type);
764}
765static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);
766
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600767static struct attribute *dock_attributes[] = {
768 &dev_attr_docked.attr,
769 &dev_attr_flags.attr,
770 &dev_attr_undock.attr,
771 &dev_attr_uid.attr,
772 &dev_attr_type.attr,
773 NULL
774};
775
776static struct attribute_group dock_attribute_group = {
777 .attrs = dock_attributes
778};
779
Len Brownc8f7a622006-07-09 17:22:28 -0400780/**
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100781 * acpi_dock_add - Add a new dock station
782 * @adev: Dock station ACPI device object.
Len Brownc8f7a622006-07-09 17:22:28 -0400783 *
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100784 * allocated and initialize a new dock station device.
Len Brownc8f7a622006-07-09 17:22:28 -0400785 */
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100786void acpi_dock_add(struct acpi_device *adev)
Len Brownc8f7a622006-07-09 17:22:28 -0400787{
Rafael J. Wysocki2efbca42013-07-05 03:23:36 +0200788 struct dock_station *dock_station, ds = { NULL, };
Rafael J. Wysockiaf8874492014-02-16 00:09:47 +0100789 struct platform_device_info pdevinfo;
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100790 acpi_handle handle = adev->handle;
Alex Chiang747479a2009-10-19 15:14:50 -0600791 struct platform_device *dd;
Rafael J. Wysocki2efbca42013-07-05 03:23:36 +0200792 int ret;
Len Brownc8f7a622006-07-09 17:22:28 -0400793
Rafael J. Wysockiaf8874492014-02-16 00:09:47 +0100794 memset(&pdevinfo, 0, sizeof(pdevinfo));
795 pdevinfo.name = "dock";
796 pdevinfo.id = dock_station_count;
797 pdevinfo.acpi_node.companion = adev;
798 pdevinfo.data = &ds;
799 pdevinfo.size_data = sizeof(ds);
800 dd = platform_device_register_full(&pdevinfo);
Alex Chiang747479a2009-10-19 15:14:50 -0600801 if (IS_ERR(dd))
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100802 return;
Alex Chiang9751cb72009-10-19 15:14:40 -0600803
Alex Chiang747479a2009-10-19 15:14:50 -0600804 dock_station = dd->dev.platform_data;
805
Len Brownc8f7a622006-07-09 17:22:28 -0400806 dock_station->handle = handle;
Alex Chiang747479a2009-10-19 15:14:50 -0600807 dock_station->dock_device = dd;
Len Brownc8f7a622006-07-09 17:22:28 -0400808 dock_station->last_dock_time = jiffies - HZ;
Len Brownc8f7a622006-07-09 17:22:28 -0400809
Alex Chiang747479a2009-10-19 15:14:50 -0600810 INIT_LIST_HEAD(&dock_station->sibling);
Alex Chiang747479a2009-10-19 15:14:50 -0600811 INIT_LIST_HEAD(&dock_station->dependent_devices);
Kristen Carlson Accardia0cd35f2007-05-09 15:08:15 -0700812
Kristen Carlson Accardi9ef2a9a2007-05-09 15:09:12 -0700813 /* we want the dock device to send uevents */
Alex Chiang747479a2009-10-19 15:14:50 -0600814 dev_set_uevent_suppress(&dd->dev, 0);
Kristen Carlson Accardi9ef2a9a2007-05-09 15:09:12 -0700815
Jiang Liuc9b54712013-06-29 00:24:42 +0800816 if (acpi_dock_match(handle))
Shaohua Lidb350b02008-08-28 10:03:58 +0800817 dock_station->flags |= DOCK_IS_DOCK;
Jiang Liuc9b54712013-06-29 00:24:42 +0800818 if (acpi_ata_match(handle))
Shaohua Lidb350b02008-08-28 10:03:58 +0800819 dock_station->flags |= DOCK_IS_ATA;
Rafael J. Wysockib43109f2014-02-16 00:09:34 +0100820 if (acpi_device_is_battery(adev))
Shaohua Lidb350b02008-08-28 10:03:58 +0800821 dock_station->flags |= DOCK_IS_BAT;
822
Alex Chiang747479a2009-10-19 15:14:50 -0600823 ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
Shaohua Li8652b002008-08-28 10:07:45 +0800824 if (ret)
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600825 goto err_unregister;
Kristen Carlson Accardi671adbe2006-12-04 14:49:43 -0800826
Len Brownc8f7a622006-07-09 17:22:28 -0400827 /* add the dock station as a device dependent on itself */
Rafael J. Wysocki3b52b212014-02-21 01:10:09 +0100828 ret = add_dock_dependent_device(dock_station, adev);
Alex Chiangf69cfdd2009-10-19 15:14:29 -0600829 if (ret)
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600830 goto err_rmgroup;
Len Brownc8f7a622006-07-09 17:22:28 -0400831
Shaohua Lidb350b02008-08-28 10:03:58 +0800832 dock_station_count++;
Alex Chiang50d716e2009-10-01 11:59:23 -0600833 list_add(&dock_station->sibling, &dock_stations);
Rafael J. Wysocki1e2380c2014-02-16 01:51:01 +0100834 adev->flags.is_dock_station = true;
835 dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n",
836 dock_station_count);
837 return;
Len Brownc8f7a622006-07-09 17:22:28 -0400838
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600839err_rmgroup:
Rafael J. Wysockia30c4c52013-06-30 23:50:24 +0200840 remove_dock_dependent_devices(dock_station);
Alex Chiang747479a2009-10-19 15:14:50 -0600841 sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
Alex Chiang5f46c2f2009-10-19 15:14:24 -0600842err_unregister:
Alex Chiang747479a2009-10-19 15:14:50 -0600843 platform_device_unregister(dd);
Toshi Kanicd730182012-11-20 23:42:30 +0000844 acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
Len Brownc8f7a622006-07-09 17:22:28 -0400845}