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