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> |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 34 | #include <linux/acpi.h> |
Len Brown | c8f7a62 | 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 | c8f7a62 | 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 | c8f7a62 | 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 | c8f7a62 | 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 | |
Frank Seidel | a340af1 | 2007-12-07 13:20:42 +0100 | [diff] [blame] | 54 | static const struct acpi_device_id dock_device_ids[] = { |
| 55 | {"LNXDOCK", 0}, |
| 56 | {"", 0}, |
| 57 | }; |
| 58 | MODULE_DEVICE_TABLE(acpi, dock_device_ids); |
| 59 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 60 | struct dock_station { |
| 61 | acpi_handle handle; |
| 62 | unsigned long last_dock_time; |
| 63 | u32 flags; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 64 | struct list_head dependent_devices; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 65 | |
Alex Chiang | 50d716e | 2009-10-01 11:59:23 -0600 | [diff] [blame] | 66 | struct list_head sibling; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 67 | struct platform_device *dock_device; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 68 | }; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 69 | static LIST_HEAD(dock_stations); |
| 70 | static int dock_station_count; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 71 | static DEFINE_MUTEX(hotplug_lock); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 72 | |
| 73 | struct dock_dependent_device { |
| 74 | struct list_head list; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 75 | acpi_handle handle; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 76 | const struct acpi_dock_ops *hp_ops; |
| 77 | void *hp_context; |
| 78 | unsigned int hp_refcount; |
| 79 | void (*hp_release)(void *); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | #define DOCK_DOCKING 0x00000001 |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 83 | #define DOCK_UNDOCKING 0x00000002 |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 84 | #define DOCK_IS_DOCK 0x00000010 |
| 85 | #define DOCK_IS_ATA 0x00000020 |
| 86 | #define DOCK_IS_BAT 0x00000040 |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 87 | #define DOCK_EVENT 3 |
| 88 | #define UNDOCK_EVENT 2 |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 89 | |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 90 | enum dock_callback_type { |
| 91 | DOCK_CALL_HANDLER, |
| 92 | DOCK_CALL_FIXUP, |
| 93 | DOCK_CALL_UEVENT, |
| 94 | }; |
| 95 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 96 | /***************************************************************************** |
| 97 | * Dock Dependent device functions * |
| 98 | *****************************************************************************/ |
| 99 | /** |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 100 | * add_dock_dependent_device - associate a device with the dock station |
| 101 | * @ds: The dock station |
| 102 | * @handle: handle of the dependent device |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 103 | * |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 104 | * Add the dependent device to the dock's dependent device list. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 105 | */ |
Jiang Liu | d423c08 | 2013-06-29 00:24:36 +0800 | [diff] [blame] | 106 | static int __init |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 107 | add_dock_dependent_device(struct dock_station *ds, acpi_handle handle) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 108 | { |
| 109 | struct dock_dependent_device *dd; |
| 110 | |
| 111 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 112 | if (!dd) |
| 113 | return -ENOMEM; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 114 | |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 115 | dd->handle = handle; |
| 116 | INIT_LIST_HEAD(&dd->list); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 117 | list_add_tail(&dd->list, &ds->dependent_devices); |
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 | |
Rafael J. Wysocki | a30c4c5 | 2013-06-30 23:50:24 +0200 | [diff] [blame] | 122 | static void remove_dock_dependent_devices(struct dock_station *ds) |
| 123 | { |
| 124 | struct dock_dependent_device *dd, *aux; |
| 125 | |
| 126 | list_for_each_entry_safe(dd, aux, &ds->dependent_devices, list) { |
| 127 | list_del(&dd->list); |
| 128 | kfree(dd); |
| 129 | } |
| 130 | } |
| 131 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 132 | /** |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 133 | * dock_init_hotplug - Initialize a hotplug device on a docking station. |
| 134 | * @dd: Dock-dependent device. |
| 135 | * @ops: Dock operations to attach to the dependent device. |
| 136 | * @context: Data to pass to the @ops callbacks and @release. |
| 137 | * @init: Optional initialization routine to run after setting up context. |
| 138 | * @release: Optional release routine to run on removal. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 139 | */ |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 140 | static int dock_init_hotplug(struct dock_dependent_device *dd, |
| 141 | const struct acpi_dock_ops *ops, void *context, |
| 142 | void (*init)(void *), void (*release)(void *)) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 143 | { |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 144 | int ret = 0; |
| 145 | |
| 146 | mutex_lock(&hotplug_lock); |
Rafael J. Wysocki | 4ec2406 | 2013-06-30 23:47:14 +0200 | [diff] [blame] | 147 | if (WARN_ON(dd->hp_context)) { |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 148 | ret = -EEXIST; |
| 149 | } else { |
| 150 | dd->hp_refcount = 1; |
| 151 | dd->hp_ops = ops; |
| 152 | dd->hp_context = context; |
| 153 | dd->hp_release = release; |
Rafael J. Wysocki | 4ec2406 | 2013-06-30 23:47:14 +0200 | [diff] [blame] | 154 | if (init) |
| 155 | init(context); |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 156 | } |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 157 | mutex_unlock(&hotplug_lock); |
| 158 | return ret; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 162 | * dock_release_hotplug - Decrement hotplug reference counter of dock device. |
| 163 | * @dd: Dock-dependent device. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 164 | * |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 165 | * Decrement the reference counter of @dd and if 0, detach its hotplug |
| 166 | * operations from it, reset its context pointer and run the optional release |
| 167 | * routine if present. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 168 | */ |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 169 | static void dock_release_hotplug(struct dock_dependent_device *dd) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 170 | { |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 171 | mutex_lock(&hotplug_lock); |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 172 | if (dd->hp_context && !--dd->hp_refcount) { |
Rafael J. Wysocki | 4ec2406 | 2013-06-30 23:47:14 +0200 | [diff] [blame] | 173 | void (*release)(void *) = dd->hp_release; |
| 174 | void *context = dd->hp_context; |
| 175 | |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 176 | dd->hp_ops = NULL; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 177 | dd->hp_context = NULL; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 178 | dd->hp_release = NULL; |
Rafael J. Wysocki | 4ec2406 | 2013-06-30 23:47:14 +0200 | [diff] [blame] | 179 | if (release) |
| 180 | release(context); |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 181 | } |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 182 | mutex_unlock(&hotplug_lock); |
| 183 | } |
| 184 | |
| 185 | static void dock_hotplug_event(struct dock_dependent_device *dd, u32 event, |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 186 | enum dock_callback_type cb_type) |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 187 | { |
| 188 | acpi_notify_handler cb = NULL; |
| 189 | bool run = false; |
| 190 | |
| 191 | mutex_lock(&hotplug_lock); |
| 192 | |
| 193 | if (dd->hp_context) { |
| 194 | run = true; |
| 195 | dd->hp_refcount++; |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 196 | if (dd->hp_ops) { |
| 197 | switch (cb_type) { |
| 198 | case DOCK_CALL_FIXUP: |
| 199 | cb = dd->hp_ops->fixup; |
| 200 | break; |
| 201 | case DOCK_CALL_UEVENT: |
| 202 | cb = dd->hp_ops->uevent; |
| 203 | break; |
| 204 | default: |
| 205 | cb = dd->hp_ops->handler; |
| 206 | } |
| 207 | } |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | mutex_unlock(&hotplug_lock); |
| 211 | |
| 212 | if (!run) |
| 213 | return; |
| 214 | |
| 215 | if (cb) |
| 216 | cb(dd->handle, event, dd->hp_context); |
| 217 | |
| 218 | dock_release_hotplug(dd); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * find_dock_dependent_device - get a device dependent on this dock |
| 223 | * @ds: the dock station |
| 224 | * @handle: the acpi_handle of the device we want |
| 225 | * |
| 226 | * iterate over the dependent device list for this dock. If the |
| 227 | * dependent device matches the handle, return. |
| 228 | */ |
| 229 | static struct dock_dependent_device * |
| 230 | find_dock_dependent_device(struct dock_station *ds, acpi_handle handle) |
| 231 | { |
| 232 | struct dock_dependent_device *dd; |
| 233 | |
Jiang Liu | ed633e7 | 2013-06-29 00:24:35 +0800 | [diff] [blame] | 234 | list_for_each_entry(dd, &ds->dependent_devices, list) |
| 235 | if (handle == dd->handle) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 236 | return dd; |
Jiang Liu | ed633e7 | 2013-06-29 00:24:35 +0800 | [diff] [blame] | 237 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 238 | return NULL; |
| 239 | } |
| 240 | |
| 241 | /***************************************************************************** |
| 242 | * Dock functions * |
| 243 | *****************************************************************************/ |
Jiang Liu | d423c08 | 2013-06-29 00:24:36 +0800 | [diff] [blame] | 244 | static int __init is_battery(acpi_handle handle) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 245 | { |
| 246 | struct acpi_device_info *info; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 247 | int ret = 1; |
| 248 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 249 | if (!ACPI_SUCCESS(acpi_get_object_info(handle, &info))) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 250 | return 0; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 251 | if (!(info->valid & ACPI_VALID_HID)) |
| 252 | ret = 0; |
| 253 | else |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 254 | ret = !strcmp("PNP0C0A", info->hardware_id.string); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 255 | |
Bob Moore | 15b8dd5 | 2009-06-29 13:39:29 +0800 | [diff] [blame] | 256 | kfree(info); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 257 | return ret; |
| 258 | } |
| 259 | |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 260 | /* Check whether ACPI object is an ejectable battery or disk bay */ |
| 261 | static bool __init is_ejectable_bay(acpi_handle handle) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 262 | { |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 263 | if (acpi_has_method(handle, "_EJ0") && is_battery(handle)) |
| 264 | return true; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 265 | |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 266 | return acpi_bay_match(handle); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 267 | } |
| 268 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 269 | /** |
| 270 | * is_dock_device - see if a device is on a dock station |
| 271 | * @handle: acpi handle of the device |
| 272 | * |
| 273 | * If this device is either the dock station itself, |
| 274 | * or is a device dependent on the dock station, then it |
| 275 | * is a dock device |
| 276 | */ |
| 277 | int is_dock_device(acpi_handle handle) |
| 278 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 279 | struct dock_station *dock_station; |
| 280 | |
| 281 | if (!dock_station_count) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 282 | return 0; |
| 283 | |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 284 | if (acpi_dock_match(handle)) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 285 | return 1; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 286 | |
| 287 | list_for_each_entry(dock_station, &dock_stations, sibling) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 288 | if (find_dock_dependent_device(dock_station, handle)) |
| 289 | return 1; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 290 | |
| 291 | return 0; |
| 292 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 293 | EXPORT_SYMBOL_GPL(is_dock_device); |
| 294 | |
| 295 | /** |
| 296 | * dock_present - see if the dock station is present. |
| 297 | * @ds: the dock station |
| 298 | * |
| 299 | * execute the _STA method. note that present does not |
| 300 | * imply that we are docked. |
| 301 | */ |
| 302 | static int dock_present(struct dock_station *ds) |
| 303 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 304 | unsigned long long sta; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 305 | acpi_status status; |
| 306 | |
| 307 | if (ds) { |
| 308 | status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta); |
| 309 | if (ACPI_SUCCESS(status) && sta) |
| 310 | return 1; |
| 311 | } |
| 312 | return 0; |
| 313 | } |
| 314 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 315 | /** |
| 316 | * dock_create_acpi_device - add new devices to acpi |
| 317 | * @handle - handle of the device to add |
| 318 | * |
| 319 | * This function will create a new acpi_device for the given |
| 320 | * handle if one does not exist already. This should cause |
| 321 | * acpi to scan for drivers for the given devices, and call |
| 322 | * matching driver's add routine. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 323 | */ |
Jiang Liu | 472d963 | 2013-06-29 00:24:37 +0800 | [diff] [blame] | 324 | static void dock_create_acpi_device(acpi_handle handle) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 325 | { |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 326 | struct acpi_device *device; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 327 | int ret; |
| 328 | |
| 329 | if (acpi_bus_get_device(handle, &device)) { |
| 330 | /* |
| 331 | * no device created for this object, |
| 332 | * so we should create one. |
| 333 | */ |
Rafael J. Wysocki | b8bd759 | 2013-01-19 01:27:35 +0100 | [diff] [blame] | 334 | ret = acpi_bus_scan(handle); |
Rafael J. Wysocki | 636458d | 2012-12-21 00:36:47 +0100 | [diff] [blame] | 335 | if (ret) |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 336 | pr_debug("error adding bus, %x\n", -ret); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 337 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | /** |
| 341 | * dock_remove_acpi_device - remove the acpi_device struct from acpi |
| 342 | * @handle - the handle of the device to remove |
| 343 | * |
| 344 | * Tell acpi to remove the acpi_device. This should cause any loaded |
| 345 | * driver to have it's remove routine called. |
| 346 | */ |
| 347 | static void dock_remove_acpi_device(acpi_handle handle) |
| 348 | { |
| 349 | struct acpi_device *device; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 350 | |
Rafael J. Wysocki | bfee26d | 2013-01-26 00:27:44 +0100 | [diff] [blame] | 351 | if (!acpi_bus_get_device(handle, &device)) |
| 352 | acpi_bus_trim(device); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 353 | } |
| 354 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 355 | /** |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 356 | * hot_remove_dock_devices - Remove dock station devices. |
| 357 | * @ds: Dock station. |
| 358 | */ |
| 359 | static void hot_remove_dock_devices(struct dock_station *ds) |
| 360 | { |
| 361 | struct dock_dependent_device *dd; |
| 362 | |
| 363 | /* |
| 364 | * Walk the list in reverse order so that devices that have been added |
| 365 | * last are removed first (in case there are some indirect dependencies |
| 366 | * between them). |
| 367 | */ |
| 368 | list_for_each_entry_reverse(dd, &ds->dependent_devices, list) |
| 369 | dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false); |
| 370 | |
| 371 | list_for_each_entry_reverse(dd, &ds->dependent_devices, list) |
| 372 | dock_remove_acpi_device(dd->handle); |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * hotplug_dock_devices - Insert devices on a dock station. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 377 | * @ds: the dock station |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 378 | * @event: either bus check or device check request |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 379 | * |
| 380 | * Some devices on the dock station need to have drivers called |
| 381 | * to perform hotplug operations after a dock event has occurred. |
| 382 | * Traverse the list of dock devices that have registered a |
| 383 | * hotplug handler, and call the handler. |
| 384 | */ |
| 385 | static void hotplug_dock_devices(struct dock_station *ds, u32 event) |
| 386 | { |
| 387 | struct dock_dependent_device *dd; |
| 388 | |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 389 | /* Call driver specific post-dock fixups. */ |
| 390 | list_for_each_entry(dd, &ds->dependent_devices, list) |
| 391 | dock_hotplug_event(dd, event, DOCK_CALL_FIXUP); |
| 392 | |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 393 | /* Call driver specific hotplug functions. */ |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 394 | list_for_each_entry(dd, &ds->dependent_devices, list) |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 395 | dock_hotplug_event(dd, event, DOCK_CALL_HANDLER); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 396 | |
| 397 | /* |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 398 | * Now make sure that an acpi_device is created for each dependent |
| 399 | * device. That will cause scan handlers to be attached to device |
| 400 | * objects or acpi_drivers to be stopped/started if they are present. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 401 | */ |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 402 | list_for_each_entry(dd, &ds->dependent_devices, list) |
| 403 | dock_create_acpi_device(dd->handle); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static void dock_event(struct dock_station *ds, u32 event, int num) |
| 407 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 408 | struct device *dev = &ds->dock_device->dev; |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 409 | char event_string[13]; |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 410 | char *envp[] = { event_string, NULL }; |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 411 | struct dock_dependent_device *dd; |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 412 | |
| 413 | if (num == UNDOCK_EVENT) |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 414 | sprintf(event_string, "EVENT=undock"); |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 415 | else |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 416 | sprintf(event_string, "EVENT=dock"); |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 417 | |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 418 | /* |
Kristen Carlson Accardi | 8ea86e0 | 2006-12-11 12:05:08 -0800 | [diff] [blame] | 419 | * Indicate that the status of the dock station has |
| 420 | * changed. |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 421 | */ |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 422 | if (num == DOCK_EVENT) |
| 423 | kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); |
| 424 | |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 425 | list_for_each_entry(dd, &ds->dependent_devices, list) |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 426 | dock_hotplug_event(dd, event, DOCK_CALL_UEVENT); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 427 | |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 428 | if (num != DOCK_EVENT) |
| 429 | kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 433 | * handle_dock - handle a dock event |
| 434 | * @ds: the dock station |
| 435 | * @dock: to dock, or undock - that is the question |
| 436 | * |
| 437 | * Execute the _DCK method in response to an acpi event |
| 438 | */ |
| 439 | static void handle_dock(struct dock_station *ds, int dock) |
| 440 | { |
| 441 | acpi_status status; |
| 442 | struct acpi_object_list arg_list; |
| 443 | union acpi_object arg; |
Zhang Rui | 6a868e1 | 2013-09-03 08:32:10 +0800 | [diff] [blame] | 444 | unsigned long long value; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 445 | |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 446 | acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking"); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 447 | |
| 448 | /* _DCK method has one argument */ |
| 449 | arg_list.count = 1; |
| 450 | arg_list.pointer = &arg; |
| 451 | arg.type = ACPI_TYPE_INTEGER; |
| 452 | arg.integer.value = dock; |
Zhang Rui | 6a868e1 | 2013-09-03 08:32:10 +0800 | [diff] [blame] | 453 | status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 454 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 455 | acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n", |
| 456 | status); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static inline void dock(struct dock_station *ds) |
| 460 | { |
| 461 | handle_dock(ds, 1); |
| 462 | } |
| 463 | |
| 464 | static inline void undock(struct dock_station *ds) |
| 465 | { |
| 466 | handle_dock(ds, 0); |
| 467 | } |
| 468 | |
| 469 | static inline void begin_dock(struct dock_station *ds) |
| 470 | { |
| 471 | ds->flags |= DOCK_DOCKING; |
| 472 | } |
| 473 | |
| 474 | static inline void complete_dock(struct dock_station *ds) |
| 475 | { |
| 476 | ds->flags &= ~(DOCK_DOCKING); |
| 477 | ds->last_dock_time = jiffies; |
| 478 | } |
| 479 | |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 480 | static inline void begin_undock(struct dock_station *ds) |
| 481 | { |
| 482 | ds->flags |= DOCK_UNDOCKING; |
| 483 | } |
| 484 | |
| 485 | static inline void complete_undock(struct dock_station *ds) |
| 486 | { |
| 487 | ds->flags &= ~(DOCK_UNDOCKING); |
| 488 | } |
| 489 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 490 | /** |
| 491 | * dock_in_progress - see if we are in the middle of handling a dock event |
| 492 | * @ds: the dock station |
| 493 | * |
| 494 | * Sometimes while docking, false dock events can be sent to the driver |
| 495 | * because good connections aren't made or some other reason. Ignore these |
| 496 | * if we are in the middle of doing something. |
| 497 | */ |
| 498 | static int dock_in_progress(struct dock_station *ds) |
| 499 | { |
| 500 | if ((ds->flags & DOCK_DOCKING) || |
| 501 | time_before(jiffies, (ds->last_dock_time + HZ))) |
| 502 | return 1; |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | /** |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 507 | * register_hotplug_dock_device - register a hotplug function |
| 508 | * @handle: the handle of the device |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 509 | * @ops: handlers to call after docking |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 510 | * @context: device specific data |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 511 | * @init: Optional initialization routine to run after registration |
| 512 | * @release: Optional release routine to run on unregistration |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 513 | * |
| 514 | * If a driver would like to perform a hotplug operation after a dock |
| 515 | * event, they can register an acpi_notifiy_handler to be called by |
| 516 | * the dock driver after _DCK is executed. |
| 517 | */ |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 518 | int register_hotplug_dock_device(acpi_handle handle, |
| 519 | const struct acpi_dock_ops *ops, void *context, |
| 520 | void (*init)(void *), void (*release)(void *)) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 521 | { |
| 522 | struct dock_dependent_device *dd; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 523 | struct dock_station *dock_station; |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame] | 524 | int ret = -EINVAL; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 525 | |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 526 | if (WARN_ON(!context)) |
| 527 | return -EINVAL; |
| 528 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 529 | if (!dock_station_count) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 530 | return -ENODEV; |
| 531 | |
| 532 | /* |
| 533 | * make sure this handle is for a device dependent on the dock, |
| 534 | * this would include the dock station itself |
| 535 | */ |
Alex Chiang | 50d716e | 2009-10-01 11:59:23 -0600 | [diff] [blame] | 536 | list_for_each_entry(dock_station, &dock_stations, sibling) { |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame] | 537 | /* |
| 538 | * 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] | 539 | * separately, so there are two 'dock stations' which need the |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame] | 540 | * ops |
| 541 | */ |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 542 | dd = find_dock_dependent_device(dock_station, handle); |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 543 | if (dd && !dock_init_hotplug(dd, ops, context, init, release)) |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame] | 544 | ret = 0; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 545 | } |
| 546 | |
Shaohua Li | 61b8369 | 2008-08-28 10:07:14 +0800 | [diff] [blame] | 547 | return ret; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 548 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 549 | EXPORT_SYMBOL_GPL(register_hotplug_dock_device); |
| 550 | |
| 551 | /** |
| 552 | * unregister_hotplug_dock_device - remove yourself from the hotplug list |
| 553 | * @handle: the acpi handle of the device |
| 554 | */ |
| 555 | void unregister_hotplug_dock_device(acpi_handle handle) |
| 556 | { |
| 557 | struct dock_dependent_device *dd; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 558 | struct dock_station *dock_station; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 559 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 560 | if (!dock_station_count) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 561 | return; |
| 562 | |
Alex Chiang | 50d716e | 2009-10-01 11:59:23 -0600 | [diff] [blame] | 563 | list_for_each_entry(dock_station, &dock_stations, sibling) { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 564 | dd = find_dock_dependent_device(dock_station, handle); |
| 565 | if (dd) |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 566 | dock_release_hotplug(dd); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 567 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 568 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 569 | EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); |
| 570 | |
| 571 | /** |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 572 | * handle_eject_request - handle an undock request checking for error conditions |
| 573 | * |
| 574 | * Check to make sure the dock device is still present, then undock and |
| 575 | * hotremove all the devices that may need removing. |
| 576 | */ |
| 577 | static int handle_eject_request(struct dock_station *ds, u32 event) |
| 578 | { |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 579 | if (dock_in_progress(ds)) |
| 580 | return -EBUSY; |
| 581 | |
| 582 | /* |
| 583 | * here we need to generate the undock |
| 584 | * event prior to actually doing the undock |
| 585 | * so that the device struct still exists. |
Holger Macht | afd7301 | 2008-08-06 17:56:01 +0200 | [diff] [blame] | 586 | * Also, even send the dock event if the |
| 587 | * device is not present anymore |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 588 | */ |
| 589 | dock_event(ds, event, UNDOCK_EVENT); |
Holger Macht | afd7301 | 2008-08-06 17:56:01 +0200 | [diff] [blame] | 590 | |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 591 | hot_remove_dock_devices(ds); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 592 | undock(ds); |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 593 | acpi_evaluate_lck(ds->handle, 0); |
| 594 | acpi_evaluate_ej0(ds->handle); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 595 | if (dock_present(ds)) { |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 596 | acpi_handle_err(ds->handle, "Unable to undock!\n"); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 597 | return -EBUSY; |
| 598 | } |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 599 | complete_undock(ds); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | /** |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 604 | * dock_notify - act upon an acpi dock notification |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 605 | * @ds: dock station |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 606 | * @event: the acpi event |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 607 | * |
| 608 | * If we are notified to dock, then check to see if the dock is |
| 609 | * present and then dock. Notify all drivers of the dock event, |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 610 | * and then hotplug and devices that may need hotplugging. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 611 | */ |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 612 | static void dock_notify(struct dock_station *ds, u32 event) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 613 | { |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 614 | acpi_handle handle = ds->handle; |
| 615 | struct acpi_device *ad; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 616 | int surprise_removal = 0; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 617 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 618 | /* |
| 619 | * According to acpi spec 3.0a, if a DEVICE_CHECK notification |
| 620 | * is sent and _DCK is present, it is assumed to mean an undock |
| 621 | * request. |
| 622 | */ |
| 623 | if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK) |
| 624 | event = ACPI_NOTIFY_EJECT_REQUEST; |
| 625 | |
| 626 | /* |
| 627 | * dock station: BUS_CHECK - docked or surprise removal |
| 628 | * DEVICE_CHECK - undocked |
| 629 | * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal |
| 630 | * |
| 631 | * To simplify event handling, dock dependent device handler always |
| 632 | * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and |
| 633 | * ACPI_NOTIFY_EJECT_REQUEST for removal |
| 634 | */ |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 635 | switch (event) { |
| 636 | case ACPI_NOTIFY_BUS_CHECK: |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 637 | case ACPI_NOTIFY_DEVICE_CHECK: |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 638 | if (!dock_in_progress(ds) && acpi_bus_get_device(handle, &ad)) { |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 639 | begin_dock(ds); |
| 640 | dock(ds); |
| 641 | if (!dock_present(ds)) { |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 642 | acpi_handle_err(handle, "Unable to dock!\n"); |
Shaohua Li | 8b59560 | 2008-08-28 10:02:03 +0800 | [diff] [blame] | 643 | complete_dock(ds); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 644 | break; |
| 645 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 646 | hotplug_dock_devices(ds, event); |
| 647 | complete_dock(ds); |
| 648 | dock_event(ds, event, DOCK_EVENT); |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 649 | acpi_evaluate_lck(ds->handle, 1); |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 650 | acpi_update_all_gpes(); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 651 | break; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 652 | } |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 653 | if (dock_present(ds) || dock_in_progress(ds)) |
| 654 | break; |
| 655 | /* This is a surprise removal */ |
| 656 | surprise_removal = 1; |
| 657 | event = ACPI_NOTIFY_EJECT_REQUEST; |
| 658 | /* Fall back */ |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 659 | case ACPI_NOTIFY_EJECT_REQUEST: |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 660 | begin_undock(ds); |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 661 | if ((immediate_undock && !(ds->flags & DOCK_IS_ATA)) |
| 662 | || surprise_removal) |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 663 | handle_eject_request(ds, event); |
| 664 | else |
| 665 | dock_event(ds, event, UNDOCK_EVENT); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 666 | break; |
| 667 | default: |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 668 | acpi_handle_err(handle, "Unknown dock event %d\n", event); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
Rafael J. Wysocki | 7b98118 | 2013-11-07 01:45:40 +0100 | [diff] [blame] | 672 | static void acpi_dock_deferred_cb(void *data, u32 event) |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 673 | { |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 674 | acpi_scan_lock_acquire(); |
Rafael J. Wysocki | 7b98118 | 2013-11-07 01:45:40 +0100 | [diff] [blame] | 675 | dock_notify(data, event); |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 676 | acpi_scan_lock_release(); |
Zhang Rui | 19cd847 | 2008-08-28 10:05:06 +0800 | [diff] [blame] | 677 | } |
| 678 | |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 679 | static void dock_notify_handler(acpi_handle handle, u32 event, void *data) |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 680 | { |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 681 | if (event != ACPI_NOTIFY_BUS_CHECK && event != ACPI_NOTIFY_DEVICE_CHECK |
| 682 | && event != ACPI_NOTIFY_EJECT_REQUEST) |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 683 | return; |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 684 | |
Rafael J. Wysocki | 7b98118 | 2013-11-07 01:45:40 +0100 | [diff] [blame] | 685 | acpi_hotplug_execute(acpi_dock_deferred_cb, data, event); |
Shaohua Li | 6bd00a6 | 2008-08-28 10:04:29 +0800 | [diff] [blame] | 686 | } |
| 687 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 688 | /** |
| 689 | * find_dock_devices - find devices on the dock station |
| 690 | * @handle: the handle of the device we are examining |
| 691 | * @lvl: unused |
| 692 | * @context: the dock station private data |
| 693 | * @rv: unused |
| 694 | * |
| 695 | * This function is called by acpi_walk_namespace. It will |
| 696 | * check to see if an object has an _EJD method. If it does, then it |
| 697 | * will see if it is dependent on the dock station. |
| 698 | */ |
Rafael J. Wysocki | 96c0a4d | 2013-06-30 23:46:02 +0200 | [diff] [blame] | 699 | static acpi_status __init find_dock_devices(acpi_handle handle, u32 lvl, |
| 700 | void *context, void **rv) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 701 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 702 | struct dock_station *ds = context; |
Rafael J. Wysocki | 96c0a4d | 2013-06-30 23:46:02 +0200 | [diff] [blame] | 703 | acpi_handle ejd = NULL; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 704 | |
Rafael J. Wysocki | 96c0a4d | 2013-06-30 23:46:02 +0200 | [diff] [blame] | 705 | acpi_bus_get_ejd(handle, &ejd); |
| 706 | if (ejd == ds->handle) |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 707 | add_dock_dependent_device(ds, handle); |
| 708 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 709 | return AE_OK; |
| 710 | } |
| 711 | |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 712 | /* |
| 713 | * show_docked - read method for "docked" file in sysfs |
| 714 | */ |
| 715 | static ssize_t show_docked(struct device *dev, |
| 716 | struct device_attribute *attr, char *buf) |
| 717 | { |
Holger Macht | fc5a9f8 | 2009-01-20 12:18:24 +0100 | [diff] [blame] | 718 | struct acpi_device *tmp; |
| 719 | |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 720 | struct dock_station *dock_station = dev->platform_data; |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 721 | |
Yasuaki Ishimatsu | 02df734 | 2013-01-31 03:23:53 +0000 | [diff] [blame] | 722 | if (!acpi_bus_get_device(dock_station->handle, &tmp)) |
Holger Macht | fc5a9f8 | 2009-01-20 12:18:24 +0100 | [diff] [blame] | 723 | return snprintf(buf, PAGE_SIZE, "1\n"); |
| 724 | return snprintf(buf, PAGE_SIZE, "0\n"); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 725 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 726 | static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 727 | |
| 728 | /* |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 729 | * show_flags - read method for flags file in sysfs |
| 730 | */ |
| 731 | static ssize_t show_flags(struct device *dev, |
| 732 | struct device_attribute *attr, char *buf) |
| 733 | { |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 734 | struct dock_station *dock_station = dev->platform_data; |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 735 | return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags); |
| 736 | |
| 737 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 738 | static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 739 | |
| 740 | /* |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 741 | * write_undock - write method for "undock" file in sysfs |
| 742 | */ |
| 743 | static ssize_t write_undock(struct device *dev, struct device_attribute *attr, |
| 744 | const char *buf, size_t count) |
| 745 | { |
| 746 | int ret; |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 747 | struct dock_station *dock_station = dev->platform_data; |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 748 | |
| 749 | if (!count) |
| 750 | return -EINVAL; |
| 751 | |
Rafael J. Wysocki | 8112006 | 2013-06-16 00:38:30 +0200 | [diff] [blame] | 752 | acpi_scan_lock_acquire(); |
Holger Macht | 9171f83 | 2008-03-12 01:07:27 +0100 | [diff] [blame] | 753 | begin_undock(dock_station); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 754 | ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST); |
Rafael J. Wysocki | 8112006 | 2013-06-16 00:38:30 +0200 | [diff] [blame] | 755 | acpi_scan_lock_release(); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 756 | return ret ? ret: count; |
| 757 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 758 | static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 759 | |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 760 | /* |
| 761 | * show_dock_uid - read method for "uid" file in sysfs |
| 762 | */ |
| 763 | static ssize_t show_dock_uid(struct device *dev, |
| 764 | struct device_attribute *attr, char *buf) |
| 765 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 766 | unsigned long long lbuf; |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 767 | struct dock_station *dock_station = dev->platform_data; |
Kristen Carlson Accardi | 38ff4ff | 2007-05-09 15:04:24 -0700 | [diff] [blame] | 768 | acpi_status status = acpi_evaluate_integer(dock_station->handle, |
| 769 | "_UID", NULL, &lbuf); |
| 770 | if (ACPI_FAILURE(status)) |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 771 | return 0; |
Kristen Carlson Accardi | 38ff4ff | 2007-05-09 15:04:24 -0700 | [diff] [blame] | 772 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 773 | return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf); |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 774 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 775 | static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 776 | |
Shaohua Li | 8652b00 | 2008-08-28 10:07:45 +0800 | [diff] [blame] | 777 | static ssize_t show_dock_type(struct device *dev, |
| 778 | struct device_attribute *attr, char *buf) |
| 779 | { |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 780 | struct dock_station *dock_station = dev->platform_data; |
Shaohua Li | 8652b00 | 2008-08-28 10:07:45 +0800 | [diff] [blame] | 781 | char *type; |
| 782 | |
| 783 | if (dock_station->flags & DOCK_IS_DOCK) |
| 784 | type = "dock_station"; |
| 785 | else if (dock_station->flags & DOCK_IS_ATA) |
| 786 | type = "ata_bay"; |
| 787 | else if (dock_station->flags & DOCK_IS_BAT) |
| 788 | type = "battery_bay"; |
| 789 | else |
| 790 | type = "unknown"; |
| 791 | |
| 792 | return snprintf(buf, PAGE_SIZE, "%s\n", type); |
| 793 | } |
| 794 | static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL); |
| 795 | |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 796 | static struct attribute *dock_attributes[] = { |
| 797 | &dev_attr_docked.attr, |
| 798 | &dev_attr_flags.attr, |
| 799 | &dev_attr_undock.attr, |
| 800 | &dev_attr_uid.attr, |
| 801 | &dev_attr_type.attr, |
| 802 | NULL |
| 803 | }; |
| 804 | |
| 805 | static struct attribute_group dock_attribute_group = { |
| 806 | .attrs = dock_attributes |
| 807 | }; |
| 808 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 809 | /** |
| 810 | * dock_add - add a new dock station |
| 811 | * @handle: the dock station handle |
| 812 | * |
| 813 | * allocated and initialize a new dock station device. Find all devices |
| 814 | * that are on the dock station, and register for dock event notifications. |
| 815 | */ |
Uwe Kleine-König | d38a5ed | 2010-10-19 09:13:39 +0200 | [diff] [blame] | 816 | static int __init dock_add(acpi_handle handle) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 817 | { |
Rafael J. Wysocki | 2efbca4 | 2013-07-05 03:23:36 +0200 | [diff] [blame] | 818 | struct dock_station *dock_station, ds = { NULL, }; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 819 | struct platform_device *dd; |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 820 | acpi_status status; |
Rafael J. Wysocki | 2efbca4 | 2013-07-05 03:23:36 +0200 | [diff] [blame] | 821 | int ret; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 822 | |
Rafael J. Wysocki | 2efbca4 | 2013-07-05 03:23:36 +0200 | [diff] [blame] | 823 | dd = platform_device_register_data(NULL, "dock", dock_station_count, |
| 824 | &ds, sizeof(ds)); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 825 | if (IS_ERR(dd)) |
| 826 | return PTR_ERR(dd); |
Alex Chiang | 9751cb7 | 2009-10-19 15:14:40 -0600 | [diff] [blame] | 827 | |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 828 | dock_station = dd->dev.platform_data; |
| 829 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 830 | dock_station->handle = handle; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 831 | dock_station->dock_device = dd; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 832 | dock_station->last_dock_time = jiffies - HZ; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 833 | |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 834 | INIT_LIST_HEAD(&dock_station->sibling); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 835 | INIT_LIST_HEAD(&dock_station->dependent_devices); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 836 | |
Kristen Carlson Accardi | 9ef2a9a | 2007-05-09 15:09:12 -0700 | [diff] [blame] | 837 | /* we want the dock device to send uevents */ |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 838 | dev_set_uevent_suppress(&dd->dev, 0); |
Kristen Carlson Accardi | 9ef2a9a | 2007-05-09 15:09:12 -0700 | [diff] [blame] | 839 | |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 840 | if (acpi_dock_match(handle)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 841 | dock_station->flags |= DOCK_IS_DOCK; |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 842 | if (acpi_ata_match(handle)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 843 | dock_station->flags |= DOCK_IS_ATA; |
| 844 | if (is_battery(handle)) |
| 845 | dock_station->flags |= DOCK_IS_BAT; |
| 846 | |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 847 | ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group); |
Shaohua Li | 8652b00 | 2008-08-28 10:07:45 +0800 | [diff] [blame] | 848 | if (ret) |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 849 | goto err_unregister; |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 850 | |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 851 | /* Find dependent devices */ |
| 852 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 853 | ACPI_UINT32_MAX, find_dock_devices, NULL, |
| 854 | dock_station, NULL); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 855 | |
| 856 | /* add the dock station as a device dependent on itself */ |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 857 | ret = add_dock_dependent_device(dock_station, handle); |
| 858 | if (ret) |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 859 | goto err_rmgroup; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 860 | |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 861 | status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 862 | dock_notify_handler, dock_station); |
Wei Yongjun | 0177f29 | 2013-07-17 08:33:25 +0800 | [diff] [blame] | 863 | if (ACPI_FAILURE(status)) { |
| 864 | ret = -ENODEV; |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 865 | goto err_rmgroup; |
Wei Yongjun | 0177f29 | 2013-07-17 08:33:25 +0800 | [diff] [blame] | 866 | } |
Rafael J. Wysocki | 59401cc | 2013-06-30 23:48:49 +0200 | [diff] [blame] | 867 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 868 | dock_station_count++; |
Alex Chiang | 50d716e | 2009-10-01 11:59:23 -0600 | [diff] [blame] | 869 | list_add(&dock_station->sibling, &dock_stations); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 870 | return 0; |
| 871 | |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 872 | err_rmgroup: |
Rafael J. Wysocki | a30c4c5 | 2013-06-30 23:50:24 +0200 | [diff] [blame] | 873 | remove_dock_dependent_devices(dock_station); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 874 | sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group); |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 875 | err_unregister: |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 876 | platform_device_unregister(dd); |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 877 | acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 878 | return ret; |
| 879 | } |
| 880 | |
| 881 | /** |
Toshi Kani | 8ab0ab2 | 2012-10-23 01:30:26 +0200 | [diff] [blame] | 882 | * find_dock_and_bay - look for dock stations and bays |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 883 | * @handle: acpi handle of a device |
| 884 | * @lvl: unused |
Toshi Kani | 8ab0ab2 | 2012-10-23 01:30:26 +0200 | [diff] [blame] | 885 | * @context: unused |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 886 | * @rv: unused |
| 887 | * |
Toshi Kani | 8ab0ab2 | 2012-10-23 01:30:26 +0200 | [diff] [blame] | 888 | * This is called by acpi_walk_namespace to look for dock stations and bays. |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 889 | */ |
Hanjun Guo | 027951e | 2013-08-13 18:31:13 +0800 | [diff] [blame] | 890 | static acpi_status __init |
Toshi Kani | 8ab0ab2 | 2012-10-23 01:30:26 +0200 | [diff] [blame] | 891 | find_dock_and_bay(acpi_handle handle, u32 lvl, void *context, void **rv) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 892 | { |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 893 | if (acpi_dock_match(handle) || is_ejectable_bay(handle)) |
Zhang Rui | 1ee4d61 | 2010-03-22 15:46:49 +0800 | [diff] [blame] | 894 | dock_add(handle); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 895 | |
Zhang Rui | 1ee4d61 | 2010-03-22 15:46:49 +0800 | [diff] [blame] | 896 | return AE_OK; |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 897 | } |
| 898 | |
Rafael J. Wysocki | 2ce65fe | 2013-07-04 13:25:04 +0200 | [diff] [blame] | 899 | void __init acpi_dock_init(void) |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 900 | { |
Len Brown | 816c2ed | 2008-06-24 22:57:12 -0400 | [diff] [blame] | 901 | if (acpi_disabled) |
Rafael J. Wysocki | 2ce65fe | 2013-07-04 13:25:04 +0200 | [diff] [blame] | 902 | return; |
Len Brown | 816c2ed | 2008-06-24 22:57:12 -0400 | [diff] [blame] | 903 | |
Toshi Kani | 8ab0ab2 | 2012-10-23 01:30:26 +0200 | [diff] [blame] | 904 | /* look for dock stations and bays */ |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 905 | acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, |
Toshi Kani | 8ab0ab2 | 2012-10-23 01:30:26 +0200 | [diff] [blame] | 906 | ACPI_UINT32_MAX, find_dock_and_bay, NULL, NULL, NULL); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 907 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 908 | if (!dock_station_count) { |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 909 | pr_info(PREFIX "No dock devices found.\n"); |
Rafael J. Wysocki | 2ce65fe | 2013-07-04 13:25:04 +0200 | [diff] [blame] | 910 | return; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 911 | } |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 912 | |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 913 | pr_info(PREFIX "%s: %d docks/bays found\n", |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 914 | ACPI_DOCK_DRIVER_DESCRIPTION, dock_station_count); |
Len Brown | c8f7a62 | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 915 | } |