dock.c 17.2 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 24
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *  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>
#include <linux/module.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
#define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver"
L
Len Brown 已提交
37

38
ACPI_MODULE_NAME("dock");
L
Len Brown 已提交
39
MODULE_AUTHOR("Kristen Carlson Accardi");
40
MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
L
Len Brown 已提交
41 42
MODULE_LICENSE("GPL");

43
static bool immediate_undock = 1;
44 45 46 47 48 49
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 已提交
50 51 52 53 54
struct dock_station {
	acpi_handle handle;
	unsigned long last_dock_time;
	u32 flags;
	struct list_head dependent_devices;
55

A
Alex Chiang 已提交
56
	struct list_head sibling;
57
	struct platform_device *dock_device;
L
Len Brown 已提交
58
};
59 60
static LIST_HEAD(dock_stations);
static int dock_station_count;
L
Len Brown 已提交
61 62 63

struct dock_dependent_device {
	struct list_head list;
64
	struct acpi_device *adev;
L
Len Brown 已提交
65 66 67
};

#define DOCK_DOCKING	0x00000001
68
#define DOCK_UNDOCKING  0x00000002
69 70 71
#define DOCK_IS_DOCK	0x00000010
#define DOCK_IS_ATA	0x00000020
#define DOCK_IS_BAT	0x00000040
72 73
#define DOCK_EVENT	3
#define UNDOCK_EVENT	2
L
Len Brown 已提交
74

75 76 77 78 79 80
enum dock_callback_type {
	DOCK_CALL_HANDLER,
	DOCK_CALL_FIXUP,
	DOCK_CALL_UEVENT,
};

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

	dd = kzalloc(sizeof(*dd), GFP_KERNEL);
97 98 99
	if (!dd)
		return -ENOMEM;

100
	dd->adev = adev;
101
	INIT_LIST_HEAD(&dd->list);
L
Len Brown 已提交
102
	list_add_tail(&dd->list, &ds->dependent_devices);
103 104

	return 0;
L
Len Brown 已提交
105 106
}

107
static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event,
108
			       enum dock_callback_type cb_type)
109
{
110
	struct acpi_device *adev = dd->adev;
111

112 113 114
	acpi_lock_hp_context();

	if (!adev->hp)
115
		goto out;
116 117 118 119 120 121 122 123 124 125

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

		fixup = adev->hp->fixup;
		if (fixup) {
			acpi_unlock_hp_context();
			fixup(adev);
			return;
		}
126 127 128 129 130 131 132 133 134
	} 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;
		}
135 136 137
	} else {
		int (*notify)(struct acpi_device *, u32);

138
		notify = adev->hp->notify;
139 140 141 142 143 144 145
		if (notify) {
			acpi_unlock_hp_context();
			notify(adev, event);
			return;
		}
	}

146
 out:
147
	acpi_unlock_hp_context();
L
Len Brown 已提交
148 149
}

150 151 152 153 154 155 156 157 158 159 160
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 已提交
161 162 163
/**
 * find_dock_dependent_device - get a device dependent on this dock
 * @ds: the dock station
164
 * @adev: ACPI device object to find.
L
Len Brown 已提交
165 166 167 168 169
 *
 * iterate over the dependent device list for this dock.  If the
 * dependent device matches the handle, return.
 */
static struct dock_dependent_device *
170
find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev)
L
Len Brown 已提交
171 172 173
{
	struct dock_dependent_device *dd;

174
	list_for_each_entry(dd, &ds->dependent_devices, list)
175
		if (adev == dd->adev)
L
Len Brown 已提交
176
			return dd;
177

L
Len Brown 已提交
178 179 180
	return NULL;
}

181 182
void register_dock_dependent_device(struct acpi_device *adev,
				    acpi_handle dshandle)
183
{
184
	struct dock_station *ds = find_dock_station(dshandle);
185

186 187
	if (ds && !find_dock_dependent_device(ds, adev))
		add_dock_dependent_device(ds, adev);
188 189
}

190 191 192
/*****************************************************************************
 *                         Dock functions                                    *
 *****************************************************************************/
193

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

	if (!dock_station_count)
L
Len Brown 已提交
207 208
		return 0;

209
	if (acpi_dock_match(adev->handle))
L
Len Brown 已提交
210
		return 1;
211 212

	list_for_each_entry(dock_station, &dock_stations, sibling)
213
		if (find_dock_dependent_device(dock_station, adev))
214
			return 1;
L
Len Brown 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228

	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)
{
229
	unsigned long long sta;
L
Len Brown 已提交
230 231 232 233 234 235 236 237 238 239 240
	acpi_status status;

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

/**
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
 * 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)
257
		acpi_bus_trim(dd->adev);
258 259 260 261
}

/**
 * hotplug_dock_devices - Insert devices on a dock station.
L
Len Brown 已提交
262
 * @ds: the dock station
263
 * @event: either bus check or device check request
L
Len Brown 已提交
264 265 266 267 268 269 270 271 272 273
 *
 * 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;

274 275 276 277
	/* Call driver specific post-dock fixups. */
	list_for_each_entry(dd, &ds->dependent_devices, list)
		dock_hotplug_event(dd, event, DOCK_CALL_FIXUP);

278
	/* Call driver specific hotplug functions. */
279
	list_for_each_entry(dd, &ds->dependent_devices, list)
280
		dock_hotplug_event(dd, event, DOCK_CALL_HANDLER);
L
Len Brown 已提交
281 282

	/*
283 284 285 286
	 * 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 已提交
287
	 */
288 289 290 291 292 293 294 295 296
	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 已提交
297 298 299 300
}

static void dock_event(struct dock_station *ds, u32 event, int num)
{
301
	struct device *dev = &ds->dock_device->dev;
302
	char event_string[13];
303
	char *envp[] = { event_string, NULL };
304
	struct dock_dependent_device *dd;
305 306

	if (num == UNDOCK_EVENT)
307
		sprintf(event_string, "EVENT=undock");
308
	else
309
		sprintf(event_string, "EVENT=dock");
310

311
	/*
312 313
	 * Indicate that the status of the dock station has
	 * changed.
314
	 */
315 316 317
	if (num == DOCK_EVENT)
		kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);

318
	list_for_each_entry(dd, &ds->dependent_devices, list)
319
		dock_hotplug_event(dd, event, DOCK_CALL_UEVENT);
320

321 322
	if (num != DOCK_EVENT)
		kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
L
Len Brown 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336
}

/**
 * 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;
337
	unsigned long long value;
L
Len Brown 已提交
338

339
	acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking");
L
Len Brown 已提交
340 341 342 343 344 345

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

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;
}

373 374 375 376 377 378 379 380 381 382
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 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
/**
 * 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;
}

399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
/**
 * 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.
414 415
	 * Also, even send the dock event if the
	 * device is not present anymore
416 417
	 */
	dock_event(ds, event, UNDOCK_EVENT);
418

419
	hot_remove_dock_devices(ds);
420
	undock(ds);
421 422
	acpi_evaluate_lck(ds->handle, 0);
	acpi_evaluate_ej0(ds->handle);
423
	if (dock_present(ds)) {
424
		acpi_handle_err(ds->handle, "Unable to undock!\n");
425 426
		return -EBUSY;
	}
427
	complete_undock(ds);
428 429 430
	return 0;
}

L
Len Brown 已提交
431
/**
432 433 434
 * dock_notify - Handle ACPI dock notification.
 * @adev: Dock station's ACPI device object.
 * @event: Event code.
L
Len Brown 已提交
435 436 437
 *
 * 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,
438
 * and then hotplug and devices that may need hotplugging.
L
Len Brown 已提交
439
 */
440
int dock_notify(struct acpi_device *adev, u32 event)
L
Len Brown 已提交
441
{
442 443
	acpi_handle handle = adev->handle;
	struct dock_station *ds = find_dock_station(handle);
444
	int surprise_removal = 0;
L
Len Brown 已提交
445

446 447 448
	if (!ds)
		return -ENODEV;

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
	/*
	 * 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 已提交
466 467
	switch (event) {
	case ACPI_NOTIFY_BUS_CHECK:
468
	case ACPI_NOTIFY_DEVICE_CHECK:
469
		if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) {
L
Len Brown 已提交
470 471 472
			begin_dock(ds);
			dock(ds);
			if (!dock_present(ds)) {
473
				acpi_handle_err(handle, "Unable to dock!\n");
S
Shaohua Li 已提交
474
				complete_dock(ds);
L
Len Brown 已提交
475 476 477 478 479
				break;
			}
			hotplug_dock_devices(ds, event);
			complete_dock(ds);
			dock_event(ds, event, DOCK_EVENT);
480
			acpi_evaluate_lck(ds->handle, 1);
481
			acpi_update_all_gpes();
482
			break;
L
Len Brown 已提交
483
		}
484 485 486 487 488 489
		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 已提交
490
	case ACPI_NOTIFY_EJECT_REQUEST:
491
		begin_undock(ds);
492 493
		if ((immediate_undock && !(ds->flags & DOCK_IS_ATA))
		   || surprise_removal)
494 495 496
			handle_eject_request(ds, event);
		else
			dock_event(ds, event, UNDOCK_EVENT);
L
Len Brown 已提交
497 498
		break;
	}
499
	return 0;
L
Len Brown 已提交
500 501
}

502 503 504 505 506 507
/*
 * show_docked - read method for "docked" file in sysfs
 */
static ssize_t show_docked(struct device *dev,
			   struct device_attribute *attr, char *buf)
{
508
	struct dock_station *dock_station = dev->platform_data;
509
	struct acpi_device *adev = NULL;
510

511 512
	acpi_bus_get_device(dock_station->handle, &adev);
	return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
513
}
A
Adrian Bunk 已提交
514
static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
515

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

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

528 529 530 531 532 533 534
/*
 * 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;
535
	struct dock_station *dock_station = dev->platform_data;
536 537 538 539

	if (!count)
		return -EINVAL;

540
	acpi_scan_lock_acquire();
541
	begin_undock(dock_station);
542
	ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
543
	acpi_scan_lock_release();
544 545
	return ret ? ret: count;
}
A
Adrian Bunk 已提交
546
static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
547

548 549 550 551 552 553
/*
 * 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)
{
554
	unsigned long long lbuf;
555
	struct dock_station *dock_station = dev->platform_data;
556 557 558
	acpi_status status = acpi_evaluate_integer(dock_station->handle,
					"_UID", NULL, &lbuf);
	if (ACPI_FAILURE(status))
559
	    return 0;
560

561
	return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf);
562
}
A
Adrian Bunk 已提交
563
static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
564

S
Shaohua Li 已提交
565 566 567
static ssize_t show_dock_type(struct device *dev,
		struct device_attribute *attr, char *buf)
{
568
	struct dock_station *dock_station = dev->platform_data;
S
Shaohua Li 已提交
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
	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);

584 585 586 587 588 589 590 591 592 593 594 595 596
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 已提交
597
/**
598 599
 * acpi_dock_add - Add a new dock station
 * @adev: Dock station ACPI device object.
L
Len Brown 已提交
600
 *
601
 * allocated and initialize a new dock station device.
L
Len Brown 已提交
602
 */
603
void acpi_dock_add(struct acpi_device *adev)
L
Len Brown 已提交
604
{
605
	struct dock_station *dock_station, ds = { NULL, };
606
	struct platform_device_info pdevinfo;
607
	acpi_handle handle = adev->handle;
608
	struct platform_device *dd;
609
	int ret;
L
Len Brown 已提交
610

611 612 613
	memset(&pdevinfo, 0, sizeof(pdevinfo));
	pdevinfo.name = "dock";
	pdevinfo.id = dock_station_count;
614
	pdevinfo.fwnode = acpi_fwnode_handle(adev);
615 616 617
	pdevinfo.data = &ds;
	pdevinfo.size_data = sizeof(ds);
	dd = platform_device_register_full(&pdevinfo);
618
	if (IS_ERR(dd))
619
		return;
620 621

	dock_station = dd->dev.platform_data;
L
Len Brown 已提交
622 623

	dock_station->handle = handle;
624
	dock_station->dock_device = dd;
L
Len Brown 已提交
625
	dock_station->last_dock_time = jiffies - HZ;
626 627 628

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

630
	/* we want the dock device to send uevents */
631
	dev_set_uevent_suppress(&dd->dev, 0);
632

633
	if (acpi_dock_match(handle))
634
		dock_station->flags |= DOCK_IS_DOCK;
635
	if (acpi_ata_match(handle))
636
		dock_station->flags |= DOCK_IS_ATA;
637
	if (acpi_device_is_battery(adev))
638 639
		dock_station->flags |= DOCK_IS_BAT;

640
	ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group);
S
Shaohua Li 已提交
641
	if (ret)
642
		goto err_unregister;
643

L
Len Brown 已提交
644
	/* add the dock station as a device dependent on itself */
645
	ret = add_dock_dependent_device(dock_station, adev);
646
	if (ret)
647
		goto err_rmgroup;
L
Len Brown 已提交
648

649
	dock_station_count++;
A
Alex Chiang 已提交
650
	list_add(&dock_station->sibling, &dock_stations);
651 652 653 654
	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 已提交
655

656
err_rmgroup:
657
	sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group);
658

659
err_unregister:
660
	platform_device_unregister(dd);
661
	acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret);
L
Len Brown 已提交
662
}