Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1 | /* |
| 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> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/notifier.h> |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 30 | #include <linux/platform_device.h> |
Al Viro | 914e263 | 2006-10-18 13:55:46 -0400 | [diff] [blame] | 31 | #include <linux/jiffies.h> |
Randy Dunlap | 62a6d7f | 2007-03-26 21:38:49 -0800 | [diff] [blame] | 32 | #include <linux/stddef.h> |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 33 | #include <acpi/acpi_bus.h> |
| 34 | #include <acpi/acpi_drivers.h> |
| 35 | |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 36 | #define ACPI_DOCK_DRIVER_DESCRIPTION "ACPI Dock Station Driver" |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 37 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 38 | ACPI_MODULE_NAME("dock"); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 39 | MODULE_AUTHOR("Kristen Carlson Accardi"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 40 | MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 41 | MODULE_LICENSE("GPL"); |
| 42 | |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 43 | static int immediate_undock = 1; |
| 44 | module_param(immediate_undock, bool, 0644); |
| 45 | MODULE_PARM_DESC(immediate_undock, "1 (default) will cause the driver to " |
| 46 | "undock immediately when the undock button is pressed, 0 will cause" |
| 47 | " the driver to wait for userspace to write the undock sysfs file " |
| 48 | " before undocking"); |
| 49 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 50 | static struct atomic_notifier_head dock_notifier_list; |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 51 | static char dock_device_name[] = "dock"; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 52 | |
Frank Seidel | a340af1 | 2007-12-07 13:20:42 +0100 | [diff] [blame] | 53 | static const struct acpi_device_id dock_device_ids[] = { |
| 54 | {"LNXDOCK", 0}, |
| 55 | {"", 0}, |
| 56 | }; |
| 57 | MODULE_DEVICE_TABLE(acpi, dock_device_ids); |
| 58 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 59 | struct dock_station { |
| 60 | acpi_handle handle; |
| 61 | unsigned long last_dock_time; |
| 62 | u32 flags; |
| 63 | spinlock_t dd_lock; |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 64 | struct mutex hp_lock; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 65 | struct list_head dependent_devices; |
| 66 | struct list_head hotplug_devices; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 67 | |
| 68 | struct list_head sibiling; |
| 69 | struct platform_device *dock_device; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 70 | }; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 71 | static LIST_HEAD(dock_stations); |
| 72 | static int dock_station_count; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 73 | |
| 74 | struct dock_dependent_device { |
| 75 | struct list_head list; |
| 76 | struct list_head hotplug_list; |
| 77 | acpi_handle handle; |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 78 | struct acpi_dock_ops *ops; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 79 | void *context; |
| 80 | }; |
| 81 | |
| 82 | #define DOCK_DOCKING 0x00000001 |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 83 | #define DOCK_UNDOCKING 0x00000002 |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 84 | #define DOCK_IS_DOCK 0x00000010 |
| 85 | #define DOCK_IS_ATA 0x00000020 |
| 86 | #define DOCK_IS_BAT 0x00000040 |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 87 | #define DOCK_EVENT 3 |
| 88 | #define UNDOCK_EVENT 2 |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 89 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 90 | /***************************************************************************** |
| 91 | * Dock Dependent device functions * |
| 92 | *****************************************************************************/ |
| 93 | /** |
| 94 | * alloc_dock_dependent_device - allocate and init a dependent device |
| 95 | * @handle: the acpi_handle of the dependent device |
| 96 | * |
| 97 | * Allocate memory for a dependent device structure for a device referenced |
| 98 | * by the acpi handle |
| 99 | */ |
| 100 | static struct dock_dependent_device * |
| 101 | alloc_dock_dependent_device(acpi_handle handle) |
| 102 | { |
| 103 | struct dock_dependent_device *dd; |
| 104 | |
| 105 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); |
| 106 | if (dd) { |
| 107 | dd->handle = handle; |
| 108 | INIT_LIST_HEAD(&dd->list); |
| 109 | INIT_LIST_HEAD(&dd->hotplug_list); |
| 110 | } |
| 111 | return dd; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * add_dock_dependent_device - associate a device with the dock station |
| 116 | * @ds: The dock station |
| 117 | * @dd: The dependent device |
| 118 | * |
| 119 | * Add the dependent device to the dock's dependent device list. |
| 120 | */ |
| 121 | static void |
| 122 | add_dock_dependent_device(struct dock_station *ds, |
| 123 | struct dock_dependent_device *dd) |
| 124 | { |
| 125 | spin_lock(&ds->dd_lock); |
| 126 | list_add_tail(&dd->list, &ds->dependent_devices); |
| 127 | spin_unlock(&ds->dd_lock); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * dock_add_hotplug_device - associate a hotplug handler with the dock station |
| 132 | * @ds: The dock station |
| 133 | * @dd: The dependent device struct |
| 134 | * |
| 135 | * Add the dependent device to the dock's hotplug device list |
| 136 | */ |
| 137 | static void |
| 138 | dock_add_hotplug_device(struct dock_station *ds, |
| 139 | struct dock_dependent_device *dd) |
| 140 | { |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 141 | mutex_lock(&ds->hp_lock); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 142 | list_add_tail(&dd->hotplug_list, &ds->hotplug_devices); |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 143 | mutex_unlock(&ds->hp_lock); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
| 147 | * dock_del_hotplug_device - remove a hotplug handler from the dock station |
| 148 | * @ds: The dock station |
| 149 | * @dd: the dependent device struct |
| 150 | * |
| 151 | * Delete the dependent device from the dock's hotplug device list |
| 152 | */ |
| 153 | static void |
| 154 | dock_del_hotplug_device(struct dock_station *ds, |
| 155 | struct dock_dependent_device *dd) |
| 156 | { |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 157 | mutex_lock(&ds->hp_lock); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 158 | list_del(&dd->hotplug_list); |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 159 | mutex_unlock(&ds->hp_lock); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * find_dock_dependent_device - get a device dependent on this dock |
| 164 | * @ds: the dock station |
| 165 | * @handle: the acpi_handle of the device we want |
| 166 | * |
| 167 | * iterate over the dependent device list for this dock. If the |
| 168 | * dependent device matches the handle, return. |
| 169 | */ |
| 170 | static struct dock_dependent_device * |
| 171 | find_dock_dependent_device(struct dock_station *ds, acpi_handle handle) |
| 172 | { |
| 173 | struct dock_dependent_device *dd; |
| 174 | |
| 175 | spin_lock(&ds->dd_lock); |
| 176 | list_for_each_entry(dd, &ds->dependent_devices, list) { |
| 177 | if (handle == dd->handle) { |
| 178 | spin_unlock(&ds->dd_lock); |
| 179 | return dd; |
| 180 | } |
| 181 | } |
| 182 | spin_unlock(&ds->dd_lock); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | /***************************************************************************** |
| 187 | * Dock functions * |
| 188 | *****************************************************************************/ |
| 189 | /** |
| 190 | * is_dock - see if a device is a dock station |
| 191 | * @handle: acpi handle of the device |
| 192 | * |
| 193 | * If an acpi object has a _DCK method, then it is by definition a dock |
| 194 | * station, so return true. |
| 195 | */ |
| 196 | static int is_dock(acpi_handle handle) |
| 197 | { |
| 198 | acpi_status status; |
| 199 | acpi_handle tmp; |
| 200 | |
| 201 | status = acpi_get_handle(handle, "_DCK", &tmp); |
| 202 | if (ACPI_FAILURE(status)) |
| 203 | return 0; |
| 204 | return 1; |
| 205 | } |
| 206 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 207 | static int is_ejectable(acpi_handle handle) |
| 208 | { |
| 209 | acpi_status status; |
| 210 | acpi_handle tmp; |
| 211 | |
| 212 | status = acpi_get_handle(handle, "_EJ0", &tmp); |
| 213 | if (ACPI_FAILURE(status)) |
| 214 | return 0; |
| 215 | return 1; |
| 216 | } |
| 217 | |
| 218 | static int is_ata(acpi_handle handle) |
| 219 | { |
| 220 | acpi_handle tmp; |
| 221 | |
| 222 | if ((ACPI_SUCCESS(acpi_get_handle(handle, "_GTF", &tmp))) || |
| 223 | (ACPI_SUCCESS(acpi_get_handle(handle, "_GTM", &tmp))) || |
| 224 | (ACPI_SUCCESS(acpi_get_handle(handle, "_STM", &tmp))) || |
| 225 | (ACPI_SUCCESS(acpi_get_handle(handle, "_SDD", &tmp)))) |
| 226 | return 1; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int is_battery(acpi_handle handle) |
| 232 | { |
| 233 | struct acpi_device_info *info; |
| 234 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 235 | int ret = 1; |
| 236 | |
| 237 | if (!ACPI_SUCCESS(acpi_get_object_info(handle, &buffer))) |
| 238 | return 0; |
| 239 | info = buffer.pointer; |
| 240 | if (!(info->valid & ACPI_VALID_HID)) |
| 241 | ret = 0; |
| 242 | else |
| 243 | ret = !strcmp("PNP0C0A", info->hardware_id.value); |
| 244 | |
| 245 | kfree(buffer.pointer); |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | static int is_ejectable_bay(acpi_handle handle) |
| 250 | { |
| 251 | acpi_handle phandle; |
| 252 | if (!is_ejectable(handle)) |
| 253 | return 0; |
| 254 | if (is_battery(handle) || is_ata(handle)) |
| 255 | return 1; |
| 256 | if (!acpi_get_parent(handle, &phandle) && is_ata(phandle)) |
| 257 | return 1; |
| 258 | return 0; |
| 259 | } |
| 260 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 261 | /** |
| 262 | * is_dock_device - see if a device is on a dock station |
| 263 | * @handle: acpi handle of the device |
| 264 | * |
| 265 | * If this device is either the dock station itself, |
| 266 | * or is a device dependent on the dock station, then it |
| 267 | * is a dock device |
| 268 | */ |
| 269 | int is_dock_device(acpi_handle handle) |
| 270 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 271 | struct dock_station *dock_station; |
| 272 | |
| 273 | if (!dock_station_count) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 274 | return 0; |
| 275 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 276 | if (is_dock(handle)) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 277 | return 1; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 278 | list_for_each_entry(dock_station, &dock_stations, sibiling) { |
| 279 | if (find_dock_dependent_device(dock_station, handle)) |
| 280 | return 1; |
| 281 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | EXPORT_SYMBOL_GPL(is_dock_device); |
| 287 | |
| 288 | /** |
| 289 | * dock_present - see if the dock station is present. |
| 290 | * @ds: the dock station |
| 291 | * |
| 292 | * execute the _STA method. note that present does not |
| 293 | * imply that we are docked. |
| 294 | */ |
| 295 | static int dock_present(struct dock_station *ds) |
| 296 | { |
| 297 | unsigned long sta; |
| 298 | acpi_status status; |
| 299 | |
| 300 | if (ds) { |
| 301 | status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta); |
| 302 | if (ACPI_SUCCESS(status) && sta) |
| 303 | return 1; |
| 304 | } |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | |
| 310 | /** |
| 311 | * dock_create_acpi_device - add new devices to acpi |
| 312 | * @handle - handle of the device to add |
| 313 | * |
| 314 | * This function will create a new acpi_device for the given |
| 315 | * handle if one does not exist already. This should cause |
| 316 | * acpi to scan for drivers for the given devices, and call |
| 317 | * matching driver's add routine. |
| 318 | * |
| 319 | * Returns a pointer to the acpi_device corresponding to the handle. |
| 320 | */ |
| 321 | static struct acpi_device * dock_create_acpi_device(acpi_handle handle) |
| 322 | { |
| 323 | struct acpi_device *device = NULL; |
| 324 | struct acpi_device *parent_device; |
| 325 | acpi_handle parent; |
| 326 | int ret; |
| 327 | |
| 328 | if (acpi_bus_get_device(handle, &device)) { |
| 329 | /* |
| 330 | * no device created for this object, |
| 331 | * so we should create one. |
| 332 | */ |
| 333 | acpi_get_parent(handle, &parent); |
| 334 | if (acpi_bus_get_device(parent, &parent_device)) |
| 335 | parent_device = NULL; |
| 336 | |
| 337 | ret = acpi_bus_add(&device, parent_device, handle, |
| 338 | ACPI_BUS_TYPE_DEVICE); |
| 339 | if (ret) { |
| 340 | pr_debug("error adding bus, %x\n", |
| 341 | -ret); |
| 342 | return NULL; |
| 343 | } |
| 344 | } |
| 345 | return device; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * dock_remove_acpi_device - remove the acpi_device struct from acpi |
| 350 | * @handle - the handle of the device to remove |
| 351 | * |
| 352 | * Tell acpi to remove the acpi_device. This should cause any loaded |
| 353 | * driver to have it's remove routine called. |
| 354 | */ |
| 355 | static void dock_remove_acpi_device(acpi_handle handle) |
| 356 | { |
| 357 | struct acpi_device *device; |
| 358 | int ret; |
| 359 | |
| 360 | if (!acpi_bus_get_device(handle, &device)) { |
| 361 | ret = acpi_bus_trim(device, 1); |
| 362 | if (ret) |
| 363 | pr_debug("error removing bus, %x\n", -ret); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | |
| 368 | /** |
| 369 | * hotplug_dock_devices - insert or remove devices on the dock station |
| 370 | * @ds: the dock station |
| 371 | * @event: either bus check or eject request |
| 372 | * |
| 373 | * Some devices on the dock station need to have drivers called |
| 374 | * to perform hotplug operations after a dock event has occurred. |
| 375 | * Traverse the list of dock devices that have registered a |
| 376 | * hotplug handler, and call the handler. |
| 377 | */ |
| 378 | static void hotplug_dock_devices(struct dock_station *ds, u32 event) |
| 379 | { |
| 380 | struct dock_dependent_device *dd; |
| 381 | |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 382 | mutex_lock(&ds->hp_lock); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * First call driver specific hotplug functions |
| 386 | */ |
| 387 | list_for_each_entry(dd, &ds->hotplug_devices, hotplug_list) { |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 388 | if (dd->ops && dd->ops->handler) |
| 389 | dd->ops->handler(dd->handle, event, dd->context); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Now make sure that an acpi_device is created for each |
| 394 | * dependent device, or removed if this is an eject request. |
| 395 | * This will cause acpi_drivers to be stopped/started if they |
| 396 | * exist |
| 397 | */ |
| 398 | list_for_each_entry(dd, &ds->dependent_devices, list) { |
| 399 | if (event == ACPI_NOTIFY_EJECT_REQUEST) |
| 400 | dock_remove_acpi_device(dd->handle); |
| 401 | else |
| 402 | dock_create_acpi_device(dd->handle); |
| 403 | } |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 404 | mutex_unlock(&ds->hp_lock); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void dock_event(struct dock_station *ds, u32 event, int num) |
| 408 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 409 | struct device *dev = &ds->dock_device->dev; |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 410 | char event_string[13]; |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 411 | char *envp[] = { event_string, NULL }; |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 412 | struct dock_dependent_device *dd; |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 413 | |
| 414 | if (num == UNDOCK_EVENT) |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 415 | sprintf(event_string, "EVENT=undock"); |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 416 | else |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 417 | sprintf(event_string, "EVENT=dock"); |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 418 | |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 419 | /* |
Kristen Carlson Accardi | 8ea86e0 | 2006-12-11 12:05:08 -0800 | [diff] [blame] | 420 | * Indicate that the status of the dock station has |
| 421 | * changed. |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 422 | */ |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 423 | if (num == DOCK_EVENT) |
| 424 | kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); |
| 425 | |
| 426 | list_for_each_entry(dd, &ds->hotplug_devices, hotplug_list) |
| 427 | if (dd->ops && dd->ops->uevent) |
| 428 | dd->ops->uevent(dd->handle, event, dd->context); |
| 429 | if (num != DOCK_EVENT) |
| 430 | kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /** |
| 434 | * eject_dock - respond to a dock eject request |
| 435 | * @ds: the dock station |
| 436 | * |
| 437 | * This is called after _DCK is called, to execute the dock station's |
| 438 | * _EJ0 method. |
| 439 | */ |
| 440 | static void eject_dock(struct dock_station *ds) |
| 441 | { |
| 442 | struct acpi_object_list arg_list; |
| 443 | union acpi_object arg; |
| 444 | acpi_status status; |
| 445 | acpi_handle tmp; |
| 446 | |
| 447 | /* all dock devices should have _EJ0, but check anyway */ |
| 448 | status = acpi_get_handle(ds->handle, "_EJ0", &tmp); |
| 449 | if (ACPI_FAILURE(status)) { |
| 450 | pr_debug("No _EJ0 support for dock device\n"); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | arg_list.count = 1; |
| 455 | arg_list.pointer = &arg; |
| 456 | arg.type = ACPI_TYPE_INTEGER; |
| 457 | arg.integer.value = 1; |
| 458 | |
| 459 | if (ACPI_FAILURE(acpi_evaluate_object(ds->handle, "_EJ0", |
| 460 | &arg_list, NULL))) |
| 461 | pr_debug("Failed to evaluate _EJ0!\n"); |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * handle_dock - handle a dock event |
| 466 | * @ds: the dock station |
| 467 | * @dock: to dock, or undock - that is the question |
| 468 | * |
| 469 | * Execute the _DCK method in response to an acpi event |
| 470 | */ |
| 471 | static void handle_dock(struct dock_station *ds, int dock) |
| 472 | { |
| 473 | acpi_status status; |
| 474 | struct acpi_object_list arg_list; |
| 475 | union acpi_object arg; |
| 476 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 477 | struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 478 | |
| 479 | acpi_get_name(ds->handle, ACPI_FULL_PATHNAME, &name_buffer); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 480 | |
Dmitry Torokhov | 9254bc8 | 2007-07-18 01:10:24 -0400 | [diff] [blame] | 481 | printk(KERN_INFO PREFIX "%s - %s\n", |
| 482 | (char *)name_buffer.pointer, dock ? "docking" : "undocking"); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 483 | |
| 484 | /* _DCK method has one argument */ |
| 485 | arg_list.count = 1; |
| 486 | arg_list.pointer = &arg; |
| 487 | arg.type = ACPI_TYPE_INTEGER; |
| 488 | arg.integer.value = dock; |
| 489 | status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 490 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) |
Dmitry Torokhov | 9254bc8 | 2007-07-18 01:10:24 -0400 | [diff] [blame] | 491 | printk(KERN_ERR PREFIX "%s - failed to execute _DCK\n", |
| 492 | (char *)name_buffer.pointer); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 493 | kfree(buffer.pointer); |
| 494 | kfree(name_buffer.pointer); |
| 495 | } |
| 496 | |
| 497 | static inline void dock(struct dock_station *ds) |
| 498 | { |
| 499 | handle_dock(ds, 1); |
| 500 | } |
| 501 | |
| 502 | static inline void undock(struct dock_station *ds) |
| 503 | { |
| 504 | handle_dock(ds, 0); |
| 505 | } |
| 506 | |
| 507 | static inline void begin_dock(struct dock_station *ds) |
| 508 | { |
| 509 | ds->flags |= DOCK_DOCKING; |
| 510 | } |
| 511 | |
| 512 | static inline void complete_dock(struct dock_station *ds) |
| 513 | { |
| 514 | ds->flags &= ~(DOCK_DOCKING); |
| 515 | ds->last_dock_time = jiffies; |
| 516 | } |
| 517 | |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 518 | static inline void begin_undock(struct dock_station *ds) |
| 519 | { |
| 520 | ds->flags |= DOCK_UNDOCKING; |
| 521 | } |
| 522 | |
| 523 | static inline void complete_undock(struct dock_station *ds) |
| 524 | { |
| 525 | ds->flags &= ~(DOCK_UNDOCKING); |
| 526 | } |
| 527 | |
Shaohua Li | 406f692 | 2008-08-28 10:03:26 +0800 | [diff] [blame] | 528 | static void dock_lock(struct dock_station *ds, int lock) |
| 529 | { |
| 530 | struct acpi_object_list arg_list; |
| 531 | union acpi_object arg; |
| 532 | acpi_status status; |
| 533 | |
| 534 | arg_list.count = 1; |
| 535 | arg_list.pointer = &arg; |
| 536 | arg.type = ACPI_TYPE_INTEGER; |
| 537 | arg.integer.value = !!lock; |
| 538 | status = acpi_evaluate_object(ds->handle, "_LCK", &arg_list, NULL); |
| 539 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 540 | if (lock) |
| 541 | printk(KERN_WARNING PREFIX "Locking device failed\n"); |
| 542 | else |
| 543 | printk(KERN_WARNING PREFIX "Unlocking device failed\n"); |
| 544 | } |
| 545 | } |
| 546 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 547 | /** |
| 548 | * dock_in_progress - see if we are in the middle of handling a dock event |
| 549 | * @ds: the dock station |
| 550 | * |
| 551 | * Sometimes while docking, false dock events can be sent to the driver |
| 552 | * because good connections aren't made or some other reason. Ignore these |
| 553 | * if we are in the middle of doing something. |
| 554 | */ |
| 555 | static int dock_in_progress(struct dock_station *ds) |
| 556 | { |
| 557 | if ((ds->flags & DOCK_DOCKING) || |
| 558 | time_before(jiffies, (ds->last_dock_time + HZ))) |
| 559 | return 1; |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | /** |
| 564 | * register_dock_notifier - add yourself to the dock notifier list |
| 565 | * @nb: the callers notifier block |
| 566 | * |
| 567 | * If a driver wishes to be notified about dock events, they can |
| 568 | * use this function to put a notifier block on the dock notifier list. |
| 569 | * this notifier call chain will be called after a dock event, but |
| 570 | * before hotplugging any new devices. |
| 571 | */ |
| 572 | int register_dock_notifier(struct notifier_block *nb) |
| 573 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 574 | if (!dock_station_count) |
Prarit Bhargava | 2548c06 | 2006-12-04 14:50:17 -0800 | [diff] [blame] | 575 | return -ENODEV; |
| 576 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 577 | return atomic_notifier_chain_register(&dock_notifier_list, nb); |
| 578 | } |
| 579 | |
| 580 | EXPORT_SYMBOL_GPL(register_dock_notifier); |
| 581 | |
| 582 | /** |
| 583 | * unregister_dock_notifier - remove yourself from the dock notifier list |
| 584 | * @nb: the callers notifier block |
| 585 | */ |
| 586 | void unregister_dock_notifier(struct notifier_block *nb) |
| 587 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 588 | if (!dock_station_count) |
Prarit Bhargava | 2548c06 | 2006-12-04 14:50:17 -0800 | [diff] [blame] | 589 | return; |
| 590 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 591 | atomic_notifier_chain_unregister(&dock_notifier_list, nb); |
| 592 | } |
| 593 | |
| 594 | EXPORT_SYMBOL_GPL(unregister_dock_notifier); |
| 595 | |
| 596 | /** |
| 597 | * register_hotplug_dock_device - register a hotplug function |
| 598 | * @handle: the handle of the device |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 599 | * @ops: handlers to call after docking |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 600 | * @context: device specific data |
| 601 | * |
| 602 | * If a driver would like to perform a hotplug operation after a dock |
| 603 | * event, they can register an acpi_notifiy_handler to be called by |
| 604 | * the dock driver after _DCK is executed. |
| 605 | */ |
| 606 | int |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 607 | register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops, |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 608 | void *context) |
| 609 | { |
| 610 | struct dock_dependent_device *dd; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 611 | struct dock_station *dock_station; |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame^] | 612 | int ret = -EINVAL; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 613 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 614 | if (!dock_station_count) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 615 | return -ENODEV; |
| 616 | |
| 617 | /* |
| 618 | * make sure this handle is for a device dependent on the dock, |
| 619 | * this would include the dock station itself |
| 620 | */ |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 621 | list_for_each_entry(dock_station, &dock_stations, sibiling) { |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame^] | 622 | /* |
| 623 | * An ATA bay can be in a dock and itself can be ejected |
| 624 | * seperately, so there are two 'dock stations' which need the |
| 625 | * ops |
| 626 | */ |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 627 | dd = find_dock_dependent_device(dock_station, handle); |
| 628 | if (dd) { |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 629 | dd->ops = ops; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 630 | dd->context = context; |
| 631 | dock_add_hotplug_device(dock_station, dd); |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame^] | 632 | ret = 0; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 633 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 634 | } |
| 635 | |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame^] | 636 | return ret; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | EXPORT_SYMBOL_GPL(register_hotplug_dock_device); |
| 640 | |
| 641 | /** |
| 642 | * unregister_hotplug_dock_device - remove yourself from the hotplug list |
| 643 | * @handle: the acpi handle of the device |
| 644 | */ |
| 645 | void unregister_hotplug_dock_device(acpi_handle handle) |
| 646 | { |
| 647 | struct dock_dependent_device *dd; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 648 | struct dock_station *dock_station; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 649 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 650 | if (!dock_station_count) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 651 | return; |
| 652 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 653 | list_for_each_entry(dock_station, &dock_stations, sibiling) { |
| 654 | dd = find_dock_dependent_device(dock_station, handle); |
| 655 | if (dd) |
| 656 | dock_del_hotplug_device(dock_station, dd); |
| 657 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); |
| 661 | |
| 662 | /** |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 663 | * handle_eject_request - handle an undock request checking for error conditions |
| 664 | * |
| 665 | * Check to make sure the dock device is still present, then undock and |
| 666 | * hotremove all the devices that may need removing. |
| 667 | */ |
| 668 | static int handle_eject_request(struct dock_station *ds, u32 event) |
| 669 | { |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 670 | if (dock_in_progress(ds)) |
| 671 | return -EBUSY; |
| 672 | |
| 673 | /* |
| 674 | * here we need to generate the undock |
| 675 | * event prior to actually doing the undock |
| 676 | * so that the device struct still exists. |
Holger Macht | afd7301 | 2008-08-06 17:56:01 +0200 | [diff] [blame] | 677 | * Also, even send the dock event if the |
| 678 | * device is not present anymore |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 679 | */ |
| 680 | dock_event(ds, event, UNDOCK_EVENT); |
Holger Macht | afd7301 | 2008-08-06 17:56:01 +0200 | [diff] [blame] | 681 | |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 682 | hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST); |
| 683 | undock(ds); |
Shaohua Li | 406f692 | 2008-08-28 10:03:26 +0800 | [diff] [blame] | 684 | dock_lock(ds, 0); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 685 | eject_dock(ds); |
| 686 | if (dock_present(ds)) { |
| 687 | printk(KERN_ERR PREFIX "Unable to undock!\n"); |
| 688 | return -EBUSY; |
| 689 | } |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 690 | complete_undock(ds); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | /** |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 695 | * dock_notify - act upon an acpi dock notification |
| 696 | * @handle: the dock station handle |
| 697 | * @event: the acpi event |
| 698 | * @data: our driver data struct |
| 699 | * |
| 700 | * If we are notified to dock, then check to see if the dock is |
| 701 | * present and then dock. Notify all drivers of the dock event, |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 702 | * and then hotplug and devices that may need hotplugging. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 703 | */ |
| 704 | static void dock_notify(acpi_handle handle, u32 event, void *data) |
| 705 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 706 | struct dock_station *ds = data; |
Shaohua Li | 8b59560 | 2008-08-28 10:02:03 +0800 | [diff] [blame] | 707 | struct acpi_device *tmp; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 708 | int surprise_removal = 0; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 709 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 710 | /* |
| 711 | * According to acpi spec 3.0a, if a DEVICE_CHECK notification |
| 712 | * is sent and _DCK is present, it is assumed to mean an undock |
| 713 | * request. |
| 714 | */ |
| 715 | if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK) |
| 716 | event = ACPI_NOTIFY_EJECT_REQUEST; |
| 717 | |
| 718 | /* |
| 719 | * dock station: BUS_CHECK - docked or surprise removal |
| 720 | * DEVICE_CHECK - undocked |
| 721 | * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal |
| 722 | * |
| 723 | * To simplify event handling, dock dependent device handler always |
| 724 | * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and |
| 725 | * ACPI_NOTIFY_EJECT_REQUEST for removal |
| 726 | */ |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 727 | switch (event) { |
| 728 | case ACPI_NOTIFY_BUS_CHECK: |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 729 | case ACPI_NOTIFY_DEVICE_CHECK: |
Shaohua Li | 8b59560 | 2008-08-28 10:02:03 +0800 | [diff] [blame] | 730 | if (!dock_in_progress(ds) && acpi_bus_get_device(ds->handle, |
| 731 | &tmp)) { |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 732 | begin_dock(ds); |
| 733 | dock(ds); |
| 734 | if (!dock_present(ds)) { |
| 735 | printk(KERN_ERR PREFIX "Unable to dock!\n"); |
Shaohua Li | 8b59560 | 2008-08-28 10:02:03 +0800 | [diff] [blame] | 736 | complete_dock(ds); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 737 | break; |
| 738 | } |
| 739 | atomic_notifier_call_chain(&dock_notifier_list, |
| 740 | event, NULL); |
| 741 | hotplug_dock_devices(ds, event); |
| 742 | complete_dock(ds); |
| 743 | dock_event(ds, event, DOCK_EVENT); |
Shaohua Li | 406f692 | 2008-08-28 10:03:26 +0800 | [diff] [blame] | 744 | dock_lock(ds, 1); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 745 | break; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 746 | } |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 747 | if (dock_present(ds) || dock_in_progress(ds)) |
| 748 | break; |
| 749 | /* This is a surprise removal */ |
| 750 | surprise_removal = 1; |
| 751 | event = ACPI_NOTIFY_EJECT_REQUEST; |
| 752 | /* Fall back */ |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 753 | case ACPI_NOTIFY_EJECT_REQUEST: |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 754 | begin_undock(ds); |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 755 | if ((immediate_undock && !(ds->flags & DOCK_IS_ATA)) |
| 756 | || surprise_removal) |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 757 | handle_eject_request(ds, event); |
| 758 | else |
| 759 | dock_event(ds, event, UNDOCK_EVENT); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 760 | break; |
| 761 | default: |
| 762 | printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); |
| 763 | } |
| 764 | } |
| 765 | |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 766 | struct dock_data { |
| 767 | acpi_handle handle; |
| 768 | unsigned long event; |
| 769 | struct dock_station *ds; |
| 770 | }; |
| 771 | |
| 772 | static void acpi_dock_deferred_cb(void *context) |
| 773 | { |
| 774 | struct dock_data *data = (struct dock_data *)context; |
| 775 | |
| 776 | dock_notify(data->handle, data->event, data->ds); |
| 777 | kfree(data); |
| 778 | } |
| 779 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 780 | static int acpi_dock_notifier_call(struct notifier_block *this, |
| 781 | unsigned long event, void *data) |
| 782 | { |
| 783 | struct dock_station *dock_station; |
| 784 | acpi_handle handle = (acpi_handle)data; |
| 785 | |
| 786 | if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK |
| 787 | && event != ACPI_NOTIFY_EJECT_REQUEST) |
| 788 | return 0; |
| 789 | list_for_each_entry(dock_station, &dock_stations, sibiling) { |
| 790 | if (dock_station->handle == handle) { |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 791 | struct dock_data *dock_data; |
| 792 | |
| 793 | dock_data = kmalloc(sizeof(*dock_data), GFP_KERNEL); |
| 794 | if (!dock_data) |
| 795 | return 0; |
| 796 | dock_data->handle = handle; |
| 797 | dock_data->event = event; |
| 798 | dock_data->ds = dock_station; |
| 799 | acpi_os_hotplug_execute(acpi_dock_deferred_cb, |
| 800 | dock_data); |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 801 | return 0 ; |
| 802 | } |
| 803 | } |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | static struct notifier_block dock_acpi_notifier = { |
| 808 | .notifier_call = acpi_dock_notifier_call, |
| 809 | }; |
| 810 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 811 | /** |
| 812 | * find_dock_devices - find devices on the dock station |
| 813 | * @handle: the handle of the device we are examining |
| 814 | * @lvl: unused |
| 815 | * @context: the dock station private data |
| 816 | * @rv: unused |
| 817 | * |
| 818 | * This function is called by acpi_walk_namespace. It will |
| 819 | * check to see if an object has an _EJD method. If it does, then it |
| 820 | * will see if it is dependent on the dock station. |
| 821 | */ |
| 822 | static acpi_status |
| 823 | find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 824 | { |
| 825 | acpi_status status; |
Kristen Carlson Accardi | fe9a2f7 | 2007-02-02 22:33:00 -0500 | [diff] [blame] | 826 | acpi_handle tmp, parent; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 827 | struct dock_station *ds = context; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 828 | struct dock_dependent_device *dd; |
| 829 | |
| 830 | status = acpi_bus_get_ejd(handle, &tmp); |
Kristen Carlson Accardi | fe9a2f7 | 2007-02-02 22:33:00 -0500 | [diff] [blame] | 831 | if (ACPI_FAILURE(status)) { |
| 832 | /* try the parent device as well */ |
| 833 | status = acpi_get_parent(handle, &parent); |
| 834 | if (ACPI_FAILURE(status)) |
| 835 | goto fdd_out; |
| 836 | /* see if parent is dependent on dock */ |
| 837 | status = acpi_bus_get_ejd(parent, &tmp); |
| 838 | if (ACPI_FAILURE(status)) |
| 839 | goto fdd_out; |
| 840 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 841 | |
| 842 | if (tmp == ds->handle) { |
| 843 | dd = alloc_dock_dependent_device(handle); |
| 844 | if (dd) |
| 845 | add_dock_dependent_device(ds, dd); |
| 846 | } |
Kristen Carlson Accardi | fe9a2f7 | 2007-02-02 22:33:00 -0500 | [diff] [blame] | 847 | fdd_out: |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 848 | return AE_OK; |
| 849 | } |
| 850 | |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 851 | /* |
| 852 | * show_docked - read method for "docked" file in sysfs |
| 853 | */ |
| 854 | static ssize_t show_docked(struct device *dev, |
| 855 | struct device_attribute *attr, char *buf) |
| 856 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 857 | struct dock_station *dock_station = *((struct dock_station **) |
| 858 | dev->platform_data); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 859 | return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station)); |
| 860 | |
| 861 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 862 | static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 863 | |
| 864 | /* |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 865 | * show_flags - read method for flags file in sysfs |
| 866 | */ |
| 867 | static ssize_t show_flags(struct device *dev, |
| 868 | struct device_attribute *attr, char *buf) |
| 869 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 870 | struct dock_station *dock_station = *((struct dock_station **) |
| 871 | dev->platform_data); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 872 | return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags); |
| 873 | |
| 874 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 875 | static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 876 | |
| 877 | /* |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 878 | * write_undock - write method for "undock" file in sysfs |
| 879 | */ |
| 880 | static ssize_t write_undock(struct device *dev, struct device_attribute *attr, |
| 881 | const char *buf, size_t count) |
| 882 | { |
| 883 | int ret; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 884 | struct dock_station *dock_station = *((struct dock_station **) |
| 885 | dev->platform_data); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 886 | |
| 887 | if (!count) |
| 888 | return -EINVAL; |
| 889 | |
Holger Macht | 9171f83 | 2008-03-12 01:07:27 +0100 | [diff] [blame] | 890 | begin_undock(dock_station); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 891 | ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST); |
| 892 | return ret ? ret: count; |
| 893 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 894 | static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 895 | |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 896 | /* |
| 897 | * show_dock_uid - read method for "uid" file in sysfs |
| 898 | */ |
| 899 | static ssize_t show_dock_uid(struct device *dev, |
| 900 | struct device_attribute *attr, char *buf) |
| 901 | { |
| 902 | unsigned long lbuf; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 903 | struct dock_station *dock_station = *((struct dock_station **) |
| 904 | dev->platform_data); |
Kristen Carlson Accardi | 38ff4ff | 2007-05-09 15:04:24 -0700 | [diff] [blame] | 905 | acpi_status status = acpi_evaluate_integer(dock_station->handle, |
| 906 | "_UID", NULL, &lbuf); |
| 907 | if (ACPI_FAILURE(status)) |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 908 | return 0; |
Kristen Carlson Accardi | 38ff4ff | 2007-05-09 15:04:24 -0700 | [diff] [blame] | 909 | |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 910 | return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf); |
| 911 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 912 | static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 913 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 914 | /** |
| 915 | * dock_add - add a new dock station |
| 916 | * @handle: the dock station handle |
| 917 | * |
| 918 | * allocated and initialize a new dock station device. Find all devices |
| 919 | * that are on the dock station, and register for dock event notifications. |
| 920 | */ |
| 921 | static int dock_add(acpi_handle handle) |
| 922 | { |
| 923 | int ret; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 924 | struct dock_dependent_device *dd; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 925 | struct dock_station *dock_station; |
| 926 | struct platform_device *dock_device; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 927 | |
| 928 | /* allocate & initialize the dock_station private data */ |
| 929 | dock_station = kzalloc(sizeof(*dock_station), GFP_KERNEL); |
| 930 | if (!dock_station) |
| 931 | return -ENOMEM; |
| 932 | dock_station->handle = handle; |
| 933 | dock_station->last_dock_time = jiffies - HZ; |
| 934 | INIT_LIST_HEAD(&dock_station->dependent_devices); |
| 935 | INIT_LIST_HEAD(&dock_station->hotplug_devices); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 936 | INIT_LIST_HEAD(&dock_station->sibiling); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 937 | spin_lock_init(&dock_station->dd_lock); |
Kristen Carlson Accardi | 8b0dc86 | 2006-10-30 11:18:45 -0800 | [diff] [blame] | 938 | mutex_init(&dock_station->hp_lock); |
Kristen Accardi | 07a18684 | 2006-07-10 14:19:15 -0400 | [diff] [blame] | 939 | ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 940 | |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 941 | /* initialize platform device stuff */ |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 942 | dock_station->dock_device = |
| 943 | platform_device_register_simple(dock_device_name, |
| 944 | dock_station_count, NULL, 0); |
| 945 | dock_device = dock_station->dock_device; |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 946 | if (IS_ERR(dock_device)) { |
| 947 | kfree(dock_station); |
| 948 | dock_station = NULL; |
| 949 | return PTR_ERR(dock_device); |
| 950 | } |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 951 | platform_device_add_data(dock_device, &dock_station, |
| 952 | sizeof(struct dock_station *)); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 953 | |
Kristen Carlson Accardi | 9ef2a9a | 2007-05-09 15:09:12 -0700 | [diff] [blame] | 954 | /* we want the dock device to send uevents */ |
| 955 | dock_device->dev.uevent_suppress = 0; |
| 956 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 957 | if (is_dock(handle)) |
| 958 | dock_station->flags |= DOCK_IS_DOCK; |
| 959 | if (is_ata(handle)) |
| 960 | dock_station->flags |= DOCK_IS_ATA; |
| 961 | if (is_battery(handle)) |
| 962 | dock_station->flags |= DOCK_IS_BAT; |
| 963 | |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 964 | ret = device_create_file(&dock_device->dev, &dev_attr_docked); |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 965 | if (ret) { |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 966 | printk("Error %d adding sysfs file\n", ret); |
| 967 | platform_device_unregister(dock_device); |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 968 | kfree(dock_station); |
Chuck Ebbert | 22fe4c2 | 2007-05-09 15:05:48 -0700 | [diff] [blame] | 969 | dock_station = NULL; |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 970 | return ret; |
| 971 | } |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 972 | ret = device_create_file(&dock_device->dev, &dev_attr_undock); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 973 | if (ret) { |
| 974 | printk("Error %d adding sysfs file\n", ret); |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 975 | device_remove_file(&dock_device->dev, &dev_attr_docked); |
| 976 | platform_device_unregister(dock_device); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 977 | kfree(dock_station); |
Chuck Ebbert | 22fe4c2 | 2007-05-09 15:05:48 -0700 | [diff] [blame] | 978 | dock_station = NULL; |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 979 | return ret; |
| 980 | } |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 981 | ret = device_create_file(&dock_device->dev, &dev_attr_uid); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 982 | if (ret) { |
| 983 | printk("Error %d adding sysfs file\n", ret); |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 984 | device_remove_file(&dock_device->dev, &dev_attr_docked); |
| 985 | device_remove_file(&dock_device->dev, &dev_attr_undock); |
| 986 | platform_device_unregister(dock_device); |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 987 | kfree(dock_station); |
Chuck Ebbert | 22fe4c2 | 2007-05-09 15:05:48 -0700 | [diff] [blame] | 988 | dock_station = NULL; |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 989 | return ret; |
| 990 | } |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 991 | ret = device_create_file(&dock_device->dev, &dev_attr_flags); |
| 992 | if (ret) { |
| 993 | printk("Error %d adding sysfs file\n", ret); |
| 994 | device_remove_file(&dock_device->dev, &dev_attr_docked); |
| 995 | device_remove_file(&dock_device->dev, &dev_attr_undock); |
| 996 | device_remove_file(&dock_device->dev, &dev_attr_uid); |
| 997 | platform_device_unregister(dock_device); |
| 998 | kfree(dock_station); |
| 999 | dock_station = NULL; |
| 1000 | return ret; |
| 1001 | } |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 1002 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1003 | /* Find dependent devices */ |
| 1004 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
| 1005 | ACPI_UINT32_MAX, find_dock_devices, dock_station, |
| 1006 | NULL); |
| 1007 | |
| 1008 | /* add the dock station as a device dependent on itself */ |
| 1009 | dd = alloc_dock_dependent_device(handle); |
| 1010 | if (!dd) { |
| 1011 | kfree(dock_station); |
Chuck Ebbert | 22fe4c2 | 2007-05-09 15:05:48 -0700 | [diff] [blame] | 1012 | dock_station = NULL; |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 1013 | ret = -ENOMEM; |
| 1014 | goto dock_add_err_unregister; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1015 | } |
| 1016 | add_dock_dependent_device(dock_station, dd); |
| 1017 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1018 | dock_station_count++; |
| 1019 | list_add(&dock_station->sibiling, &dock_stations); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1020 | return 0; |
| 1021 | |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 1022 | dock_add_err_unregister: |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 1023 | device_remove_file(&dock_device->dev, &dev_attr_docked); |
| 1024 | device_remove_file(&dock_device->dev, &dev_attr_undock); |
| 1025 | device_remove_file(&dock_device->dev, &dev_attr_uid); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 1026 | device_remove_file(&dock_device->dev, &dev_attr_flags); |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 1027 | platform_device_unregister(dock_device); |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 1028 | kfree(dock_station); |
Chuck Ebbert | 22fe4c2 | 2007-05-09 15:05:48 -0700 | [diff] [blame] | 1029 | dock_station = NULL; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * dock_remove - free up resources related to the dock station |
| 1035 | */ |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1036 | static int dock_remove(struct dock_station *dock_station) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1037 | { |
| 1038 | struct dock_dependent_device *dd, *tmp; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1039 | struct platform_device *dock_device = dock_station->dock_device; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1040 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1041 | if (!dock_station_count) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1042 | return 0; |
| 1043 | |
| 1044 | /* remove dependent devices */ |
| 1045 | list_for_each_entry_safe(dd, tmp, &dock_station->dependent_devices, |
| 1046 | list) |
| 1047 | kfree(dd); |
| 1048 | |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 1049 | /* cleanup sysfs */ |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 1050 | device_remove_file(&dock_device->dev, &dev_attr_docked); |
| 1051 | device_remove_file(&dock_device->dev, &dev_attr_undock); |
| 1052 | device_remove_file(&dock_device->dev, &dev_attr_uid); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 1053 | device_remove_file(&dock_device->dev, &dev_attr_flags); |
Kristen Carlson Accardi | 0f6f280 | 2007-05-09 15:07:04 -0700 | [diff] [blame] | 1054 | platform_device_unregister(dock_device); |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 1055 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1056 | /* free dock station memory */ |
| 1057 | kfree(dock_station); |
Chuck Ebbert | 22fe4c2 | 2007-05-09 15:05:48 -0700 | [diff] [blame] | 1058 | dock_station = NULL; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * find_dock - look for a dock station |
| 1064 | * @handle: acpi handle of a device |
| 1065 | * @lvl: unused |
| 1066 | * @context: counter of dock stations found |
| 1067 | * @rv: unused |
| 1068 | * |
| 1069 | * This is called by acpi_walk_namespace to look for dock stations. |
| 1070 | */ |
| 1071 | static acpi_status |
| 1072 | find_dock(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 1073 | { |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1074 | acpi_status status = AE_OK; |
| 1075 | |
| 1076 | if (is_dock(handle)) { |
| 1077 | if (dock_add(handle) >= 0) { |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1078 | status = AE_CTRL_TERMINATE; |
| 1079 | } |
| 1080 | } |
| 1081 | return status; |
| 1082 | } |
| 1083 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1084 | static acpi_status |
| 1085 | find_bay(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 1086 | { |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame^] | 1087 | /* If bay is a dock, it's already handled */ |
| 1088 | if (is_ejectable_bay(handle) && !is_dock(handle)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1089 | dock_add(handle); |
| 1090 | return AE_OK; |
| 1091 | } |
| 1092 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1093 | static int __init dock_init(void) |
| 1094 | { |
Len Brown | 816c2ed | 2008-06-24 22:57:12 -0400 | [diff] [blame] | 1095 | if (acpi_disabled) |
| 1096 | return 0; |
| 1097 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1098 | /* look for a dock station */ |
| 1099 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1100 | ACPI_UINT32_MAX, find_dock, NULL, NULL); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1101 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1102 | /* look for bay */ |
| 1103 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
| 1104 | ACPI_UINT32_MAX, find_bay, NULL, NULL); |
| 1105 | if (!dock_station_count) { |
| 1106 | printk(KERN_INFO PREFIX "No dock devices found.\n"); |
| 1107 | return 0; |
| 1108 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1109 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 1110 | register_acpi_bus_notifier(&dock_acpi_notifier); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1111 | printk(KERN_INFO PREFIX "%s: %d docks/bays found\n", |
| 1112 | ACPI_DOCK_DRIVER_DESCRIPTION, dock_station_count); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1113 | return 0; |
| 1114 | } |
| 1115 | |
| 1116 | static void __exit dock_exit(void) |
| 1117 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1118 | struct dock_station *dock_station; |
| 1119 | |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 1120 | unregister_acpi_bus_notifier(&dock_acpi_notifier); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1121 | list_for_each_entry(dock_station, &dock_stations, sibiling) |
| 1122 | dock_remove(dock_station); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 1125 | /* |
| 1126 | * Must be called before drivers of devices in dock, otherwise we can't know |
| 1127 | * which devices are in a dock |
| 1128 | */ |
| 1129 | subsys_initcall(dock_init); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1130 | module_exit(dock_exit); |