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