dock.c 17.1 KB
Newer Older
L
Len Brown 已提交
1 2 3
/*
 *  dock.c - ACPI dock station driver
 *
4 5 6
 *  Copyright (C) 2006, 2014, Intel Corp.
 *  Author: Kristen Carlson Accardi <kristen.c.accardi@intel.com>
 *          Rafael J. Wysocki <rafael.j.wysocki@intel.com>
L
Len Brown 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or (at
 *  your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#include <linux/kernel.h>
24
#include <linux/moduleparam.h>
25
#include <linux/slab.h>
L
Len Brown 已提交
26 27 28
#include <linux/init.h>
#include <linux/types.h>
#include <linux/notifier.h>
29
#include <linux/platform_device.h>
30
#include <linux/jiffies.h>
R
Randy Dunlap 已提交
31
#include <linux/stddef.h>
32
#include <linux/acpi.h>
L
Len Brown 已提交
33

34 35
#include "internal.h"

36
ACPI_MODULE_NAME("dock");
L
Len Brown 已提交
37

38
static bool immediate_undock = 1;
39 40 41 42 43 44
module_param(immediate_undock, bool, 0644);
MODULE_PARM_DESC(immediate_undock, "1 (default) will cause the driver to "
	"undock immediately when the undock button is pressed, 0 will cause"
	" the driver to wait for userspace to write the undock sysfs file "
	" before undocking");

L
Len Brown 已提交
45 46 47 48 49
struct dock_station {
	acpi_handle handle;
	unsigned long last_dock_time;
	u32 flags;
	struct list_head dependent_devices;
50

A
Alex Chiang 已提交
51
	struct list_head sibling;
52
	struct platform_device *dock_device;
L
Len Brown 已提交
53
};
54 55
static LIST_HEAD(dock_stations);
static int dock_station_count;
L
Len Brown 已提交
56 57 58

struct dock_dependent_device {
	struct list_head list;
59
	struct acpi_device *adev;
L
Len Brown 已提交
60 61 62
};

#define DOCK_DOCKING	0x00000001
63
#define DOCK_UNDOCKING  0x00000002
64 65 66
#define DOCK_IS_DOCK	0x00000010
#define DOCK_IS_ATA	0x00000020
#define DOCK_IS_BAT	0x00000040
67 68
#define DOCK_EVENT	3
#define UNDOCK_EVENT	2
L
Len Brown 已提交
69

70 71 72 73 74 75
enum dock_callback_type {
	DOCK_CALL_HANDLER,
	DOCK_CALL_FIXUP,
	DOCK_CALL_UEVENT,
};

L
Len Brown 已提交
76 77 78 79
/*****************************************************************************
 *                         Dock Dependent device functions                   *
 *****************************************************************************/
/**
80
 * add_dock_dependent_device - associate a device with the dock station
81 82
 * @ds: Dock station.
 * @adev: Dependent ACPI device object.
L
Len Brown 已提交
83
 *
84
 * Add the dependent device to the dock's dependent device list.
L
Len Brown 已提交
85
 */
86 87
static int add_dock_dependent_device(struct dock_station *ds,
				     struct acpi_device *adev)
L
Len Brown 已提交
88 89 90 91
{
	struct dock_dependent_device *dd;

	dd = kzalloc(sizeof(*dd), GFP_KERNEL);
92 93 94
	if (!dd)
		return -ENOMEM;

95
	dd->adev = adev;
96
	INIT_LIST_HEAD(&dd->list);
L
Len Brown 已提交
97
	list_add_tail(&dd->list, &ds->dependent_devices);
98 99

	return 0;
L
Len Brown 已提交
100 101
}

102
static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event,
103
			       enum dock_callback_type cb_type)
104
{
105
	struct acpi_device *adev = dd->adev;
106

107 108 109
	acpi_lock_hp_context();

	if (!adev->hp)
110
		goto out;
111 112 113 114 115 116 117 118 119 120

	if (cb_type == DOCK_CALL_FIXUP) {
		void (*fixup)(struct acpi_device *);

		fixup = adev->hp->fixup;
		if (fixup) {
			acpi_unlock_hp_context();
			fixup(adev);
			return;
		}
121 122 123 124 125 126 127 128 129
	} else if (cb_type == DOCK_CALL_UEVENT) {
		void (*uevent)(struct acpi_device *, u32);

		uevent = adev->hp->uevent;
		if (uevent) {
			acpi_unlock_hp_context();
			uevent(adev, event);
			return;
		}
130 131 132
	} else {
		int (*notify)(struct acpi_device *, u32);

133
		notify = adev->hp->notify;
134 135 136 137 138 139 140
		if (notify) {
			acpi_unlock_hp_context();
			notify(adev, event);
			return;
		}
	}

141
 out:
142
	acpi_unlock_hp_context();
L
Len Brown 已提交
143 144
}

145 146 147 148 149 150 151 152 153 154 155
static struct dock_station *find_dock_station(acpi_handle handle)
{
	struct dock_station *ds;

	list_for_each_entry(ds, &dock_stations, sibling)
		if (ds->handle == handle)
			return ds;

	return NULL;
}

L
Len Brown 已提交
156 157 158
/**
 * find_dock_dependent_device - get a device dependent on this dock
 * @ds: the dock station
159
 * @adev: ACPI device object to find.
L
Len Brown 已提交
160 161 162 163 164
 *
 * iterate over the dependent device list for this dock.  If the
 * dependent device matches the handle, return.
 */
static struct dock_dependent_device *
165
find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev)
L
Len Brown 已提交
166 167 168
{
	struct dock_dependent_device *dd;

169
	list_for_each_entry(dd, &ds->dependent_devices, list)
170
		if (adev == dd->adev)
L
Len Brown 已提交
171
			return dd;
172

L
Len Brown 已提交
173 174 175
	return NULL;
}

176 177
void register_dock_dependent_device(struct acpi_device *adev,
				    acpi_handle dshandle)
178
{
179
	struct dock_station *ds = find_dock_station(dshandle);
180

181 182
	if (ds && !find_dock_dependent_device(ds, adev))
		add_dock_dependent_device(ds, adev);
183 184
}

185 186 187
/*****************************************************************************
 *                         Dock functions                                    *
 *****************************************************************************/
188

L
Len Brown 已提交
189 190
/**
 * is_dock_device - see if a device is on a dock station
191
 * @adev: ACPI device object to check.
L
Len Brown 已提交
192 193 194 195 196
 *
 * If this device is either the dock station itself,
 * or is a device dependent on the dock station, then it
 * is a dock device
 */
197
int is_dock_device(struct acpi_device *adev)
L
Len Brown 已提交
198
{
199 200 201
	struct dock_station *dock_station;

	if (!dock_station_count)
L
Len Brown 已提交
202 203
		return 0;

204
	if (acpi_dock_match(adev->handle))
L
Len Brown 已提交
205
		return 1;
206 207

	list_for_each_entry(dock_station, &dock_stations, sibling)
208
		if (find_dock_dependent_device(dock_station, adev))
209
			return 1;
L
Len Brown 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223

	return 0;
}
EXPORT_SYMBOL_GPL(is_dock_device);

/**
 * dock_present - see if the dock station is present.
 * @ds: the dock station
 *
 * execute the _STA method.  note that present does not
 * imply that we are docked.
 */
static int dock_present(struct dock_station *ds)
{
224
	unsigned long long sta;
L
Len Brown 已提交
225 226 227 228 229 230 231 232 233 234 235
	acpi_status status;

	if (ds) {
		status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta);
		if (ACPI_SUCCESS(status) && sta)
			return 1;
	}
	return 0;
}

/**
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
 * hot_remove_dock_devices - Remove dock station devices.
 * @ds: Dock station.
 */
static void hot_remove_dock_devices(struct dock_station *ds)
{
	struct dock_dependent_device *dd;

	/*
	 * Walk the list in reverse order so that devices that have been added
	 * last are removed first (in case there are some indirect dependencies
	 * between them).
	 */
	list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
		dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false);

	list_for_each_entry_reverse(dd, &ds->dependent_devices, list)
252
		acpi_bus_trim(dd->adev);
253 254 255 256
}

/**
 * hotplug_dock_devices - Insert devices on a dock station.
L
Len Brown 已提交
257
 * @ds: the dock station
258
 * @event: either bus check or device check request
L
Len Brown 已提交
259 260 261 262 263 264 265 266 267 268
 *
 * Some devices on the dock station need to have drivers called
 * to perform hotplug operations after a dock event has occurred.
 * Traverse the list of dock devices that have registered a
 * hotplug handler, and call the handler.
 */
static void hotplug_dock_devices(struct dock_station *ds, u32 event)
{
	struct dock_dependent_device *dd;

269 270 271 272
	/* Call driver specific post-dock fixups. */
	list_for_each_entry(dd, &ds->dependent_devices, list)
		dock_hotplug_event(dd, event, DOCK_CALL_FIXUP);

273
	/* Call driver specific hotplug functions. */
274
	list_for_each_entry(dd, &ds->dependent_devices, list)
275
		dock_hotplug_event(dd, event, DOCK_CALL_HANDLER);
L
Len Brown 已提交
276 277

	/*
278 279 280 281
	 * Check if all devices have been enumerated already.  If not, run
	 * acpi_bus_scan() for them and that will cause scan handlers to be
	 * attached to device objects or acpi_drivers to be stopped/started if
	 * they are present.
L
Len Brown 已提交
282
	 */
283 284 285 286 287 288 289 290 291
	list_for_each_entry(dd, &ds->dependent_devices, list) {
		struct acpi_device *adev = dd->adev;

		if (!acpi_device_enumerated(adev)) {
			int ret = acpi_bus_scan(adev->handle);
			if (ret)
				dev_dbg(&adev->dev, "scan error %d\n", -ret);
		}
	}
L
Len Brown 已提交
292 293 294 295
}

static void dock_event(struct dock_station *ds, u32 event, int num)
{
296
	struct device *dev = &ds->dock_device->dev;
297
	char event_string[13];
298
	char *envp[] = { event_string, NULL };
299
	struct dock_dependent_device *dd;
300 301

	if (num == UNDOCK_EVENT)
302
		sprintf(event_string, "EVENT=undock");
303
	else
304
		sprintf(event_string, "EVENT=dock");
305

306
	/*
307 308
	 * Indicate that the status of the dock station has
	 * changed.
309
	 */
310 311 312
	if (num == DOCK_EVENT)
		kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);

313
	list_for_each_entry(dd, &ds->dependent_devices, list)
314
		dock_hotplug_event(dd, event, DOCK_CALL_UEVENT);
315

316 317
	if (num != DOCK_EVENT)
		kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
L
Len Brown 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331
}

/**
 * handle_dock - handle a dock event
 * @ds: the dock station
 * @dock: to dock, or undock - that is the question
 *
 * Execute the _DCK method in response to an acpi event
 */
static void handle_dock(struct dock_station *ds, int dock)
{
	acpi_status status;
	struct acpi_object_list arg_list;
	union acpi_object arg;
332
	unsigned long long value;
L
Len Brown 已提交
333

334
	acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
L
Len Brown 已提交
335 336 337 338 339 340

	/* _DCK method has one argument */
	arg_list.count = 1;
	arg_list.pointer = &arg;
	arg.type = ACPI_TYPE_INTEGER;
	arg.integer.value = dock;
341
	status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value);
342
	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
343 344
		acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n",
				status);
L
Len Brown 已提交
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
}

static inline void dock(struct dock_station *ds)
{
	handle_dock(ds, 1);
}

static inline void undock(struct dock_station *ds)
{
	handle_dock(ds, 0);
}

static inline void begin_dock(struct dock_station *ds)
{
	ds->flags |= DOCK_DOCKING;
}

static inline void complete_dock(struct dock_station *ds)
{
	ds->flags &= ~(DOCK_DOCKING);
	ds->last_dock_time = jiffies;
}

368 369 370 371 372 373 374 375 376 377
static inline void begin_undock(struct dock_station *ds)
{
	ds->flags |= DOCK_UNDOCKING;
}

static inline void complete_undock(struct dock_station *ds)
{
	ds->flags &= ~(DOCK_UNDOCKING);
}

L
Len Brown 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
/**
 * dock_in_progress - see if we are in the middle of handling a dock event
 * @ds: the dock station
 *
 * Sometimes while docking, false dock events can be sent to the driver
 * because good connections aren't made or some other reason.  Ignore these
 * if we are in the middle of doing something.
 */
static int dock_in_progress(struct dock_station *ds)
{
	if ((ds->flags & DOCK_DOCKING) ||
	    time_before(jiffies, (ds->last_dock_time + HZ)))
		return 1;
	return 0;
}

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
/**
 * handle_eject_request - handle an undock request checking for error conditions
 *
 * Check to make sure the dock device is still present, then undock and
 * hotremove all the devices that may need removing.
 */
static int handle_eject_request(struct dock_station *ds, u32 event)
{
	if (dock_in_progress(ds))
		return -EBUSY;

	/*
	 * here we need to generate the undock
	 * event prior to actually doing the undock
	 * so that the device struct still exists.
409 410
	 * Also, even send the dock event if the
	 * device is not present anymore
411 412
	 */
	dock_event(ds, event, UNDOCK_EVENT);
413

414
	hot_remove_dock_devices(ds);
415
	undock(ds);
416 417
	acpi_evaluate_lck(ds->handle, 0);
	acpi_evaluate_ej0(ds->handle);
418
	if (dock_present(ds)) {
419
		acpi_handle_err(ds->handle, "Unable to undock!\n");
420 421
		return -EBUSY;
	}
422
	complete_undock(ds);
423 424 425
	return 0;
}

L
Len Brown 已提交
426
/**
427 428 429
 * dock_notify - Handle ACPI dock notification.
 * @adev: Dock station's ACPI device object.
 * @event: Event code.
L
Len Brown 已提交
430 431 432
 *
 * If we are notified to dock, then check to see if the dock is
 * present and then dock.  Notify all drivers of the dock event,
433
 * and then hotplug and devices that may need hotplugging.
L
Len Brown 已提交
434
 */
435
int dock_notify(struct acpi_device *adev, u32 event)
L
Len Brown 已提交
436
{
437 438
	acpi_handle handle = adev->handle;
	struct dock_station *ds = find_dock_station(handle);
439
	int surprise_removal = 0;
L
Len Brown 已提交
440

441 442 443
	if (!ds)
		return -ENODEV;

444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
	/*
	 * According to acpi spec 3.0a, if a DEVICE_CHECK notification
	 * is sent and _DCK is present, it is assumed to mean an undock
	 * request.
	 */
	if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK)
		event = ACPI_NOTIFY_EJECT_REQUEST;

	/*
	 * dock station: BUS_CHECK - docked or surprise removal
	 *		 DEVICE_CHECK - undocked
	 * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal
	 *
	 * To simplify event handling, dock dependent device handler always
	 * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and
	 * ACPI_NOTIFY_EJECT_REQUEST for removal
	 */
L
Len Brown 已提交
461 462
	switch (event) {
	case ACPI_NOTIFY_BUS_CHECK:
463
	case ACPI_NOTIFY_DEVICE_CHECK:
464
		if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) {
L
Len Brown 已提交
465 466 467
			begin_dock(ds);
			dock(ds);
			if (!dock_present(ds)) {
468
				acpi_handle_err(handle, "Unable to dock!\n");
S
Shaohua Li 已提交
469
				complete_dock(ds);
L
Len Brown 已提交
470 471 472 473 474
				break;
			}
			hotplug_dock_devices(ds, event);
			complete_dock(ds);
			dock_event(ds, event, DOCK_EVENT);
475
			acpi_evaluate_lck(ds->handle, 1);
476
			acpi_update_all_gpes();
477
			break;
L
Len Brown 已提交
478
		}
479 480 481 482 483 484
		if (dock_present(ds) || dock_in_progress(ds))
			break;
		/* This is a surprise removal */
		surprise_removal = 1;
		event = ACPI_NOTIFY_EJECT_REQUEST;
		/* Fall back */
L
Len Brown 已提交
485
	case ACPI_NOTIFY_EJECT_REQUEST:
486
		begin_undock(ds);
487 488
		if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
		   || surprise_removal)
489 490 491
			handle_eject_request(ds, event);
		else
			dock_event(ds, event, UNDOCK_EVENT);
L
Len Brown 已提交
492 493
		break;
	}
494
	return 0;
L
Len Brown 已提交
495 496
}

497 498 499 500 501 502
/*
 * show_docked - read method for "docked" file in sysfs
 */
static ssize_t show_docked(struct device *dev,
			   struct device_attribute *attr, char *buf)
{
503
	struct dock_station *dock_station = dev->platform_data;
504
	struct acpi_device *adev = NULL;
505

506 507
	acpi_bus_get_device(dock_station->handle, &adev);
	return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
508
}
A
Adrian Bunk 已提交
509
static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
510

511 512 513 514 515 516
/*
 * show_flags - read method for flags file in sysfs
 */
static ssize_t show_flags(struct device *dev,
			  struct device_attribute *attr, char *buf)
{
517
	struct dock_station *dock_station = dev->platform_data;
518 519 520
	return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);

}
A
Adrian Bunk 已提交
521
static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
522

523 524 525 526 527 528 529
/*
 * write_undock - write method for "undock" file in sysfs
 */
static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
			   const char *buf, size_t count)
{
	int ret;
530
	struct dock_station *dock_station = dev->platform_data;
531 532 533 534

	if (!count)
		return -EINVAL;

535
	acpi_scan_lock_acquire();
536
	begin_undock(dock_station);
537
	ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
538
	acpi_scan_lock_release();
539 540
	return ret ? ret: count;
}
A
Adrian Bunk 已提交
541
static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
542

543 544 545 546 547 548
/*
 * show_dock_uid - read method for "uid" file in sysfs
 */
static ssize_t show_dock_uid(struct device *dev,
			     struct device_attribute *attr, char *buf)
{
549
	unsigned long long lbuf;
550
	struct dock_station *dock_station = dev->platform_data;
551 552 553
	acpi_status status = acpi_evaluate_integer(dock_station->handle,
					"_UID", NULL, &lbuf);
	if (ACPI_FAILURE(status))
554
	    return 0;
555

556
	return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
557
}
A
Adrian Bunk 已提交
558
static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
559

S
Shaohua Li 已提交
560 561 562
static ssize_t show_dock_type(struct device *dev,
		struct device_attribute *attr, char *buf)
{
563
	struct dock_station *dock_station = dev->platform_data;
S
Shaohua Li 已提交
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	char *type;

	if (dock_station->flags & DOCK_IS_DOCK)
		type = "dock_station";
	else if (dock_station->flags & DOCK_IS_ATA)
		type = "ata_bay";
	else if (dock_station->flags & DOCK_IS_BAT)
		type = "battery_bay";
	else
		type = "unknown";

	return snprintf(buf, PAGE_SIZE, "%s\n", type);
}
static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL);

579 580 581 582 583 584 585 586 587 588 589 590 591
static struct attribute *dock_attributes[] = {
	&dev_attr_docked.attr,
	&dev_attr_flags.attr,
	&dev_attr_undock.attr,
	&dev_attr_uid.attr,
	&dev_attr_type.attr,
	NULL
};

static struct attribute_group dock_attribute_group = {
	.attrs = dock_attributes
};

L
Len Brown 已提交
592
/**
593 594
 * acpi_dock_add - Add a new dock station
 * @adev: Dock station ACPI device object.
L
Len Brown 已提交
595
 *
596
 * allocated and initialize a new dock station device.
L
Len Brown 已提交
597
 */
598
void acpi_dock_add(struct acpi_device *adev)
L
Len Brown 已提交
599
{
600
	struct dock_station *dock_station, ds = { NULL, };
601
	struct platform_device_info pdevinfo;
602
	acpi_handle handle = adev->handle;
603
	struct platform_device *dd;
604
	int ret;
L
Len Brown 已提交
605

606 607 608
	memset(&pdevinfo, 0, sizeof(pdevinfo));
	pdevinfo.name = "dock";
	pdevinfo.id = dock_station_count;
609
	pdevinfo.fwnode = acpi_fwnode_handle(adev);
610 611 612
	pdevinfo.data = &ds;
	pdevinfo.size_data = sizeof(ds);
	dd = platform_device_register_full(&pdevinfo);
613
	if (IS_ERR(dd))
614
		return;
615 616

	dock_station = dd->dev.platform_data;
L
Len Brown 已提交
617 618

	dock_station->handle = handle;
619
	dock_station->dock_device = dd;
L
Len Brown 已提交
620
	dock_station->last_dock_time = jiffies - HZ;
621 622 623

	INIT_LIST_HEAD(&dock_station->sibling);
	INIT_LIST_HEAD(&dock_station->dependent_devices);
624

625
	/* we want the dock device to send uevents */
626
	dev_set_uevent_suppress(&dd->dev, 0);
627

628
	if (acpi_dock_match(handle))
629
		dock_station->flags |= DOCK_IS_DOCK;
630
	if (acpi_ata_match(handle))
631
		dock_station->flags |= DOCK_IS_ATA;
632
	if (acpi_device_is_battery(adev))
633 634
		dock_station->flags |= DOCK_IS_BAT;

635
	ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
S
Shaohua Li 已提交
636
	if (ret)
637
		goto err_unregister;
638

L
Len Brown 已提交
639
	/* add the dock station as a device dependent on itself */
640
	ret = add_dock_dependent_device(dock_station, adev);
641
	if (ret)
642
		goto err_rmgroup;
L
Len Brown 已提交
643

644
	dock_station_count++;
A
Alex Chiang 已提交
645
	list_add(&dock_station->sibling, &dock_stations);
646 647 648 649
	adev->flags.is_dock_station = true;
	dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n",
		 dock_station_count);
	return;
L
Len Brown 已提交
650

651
err_rmgroup:
652
	sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
653

654
err_unregister:
655
	platform_device_unregister(dd);
656
	acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
L
Len Brown 已提交
657
}