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