Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 1 | /* |
| 2 | * dock.c - ACPI dock station driver |
| 3 | * |
Rafael J. Wysocki | 8cc2568 | 2014-02-21 01:11:46 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006, 2014, Intel Corp. |
| 5 | * Author: Kristen Carlson Accardi <kristen.c.accardi@intel.com> |
| 6 | * Rafael J. Wysocki <rafael.j.wysocki@intel.com> |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or (at |
| 13 | * your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 23 | * |
| 24 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | */ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 30 | #include <linux/init.h> |
| 31 | #include <linux/types.h> |
| 32 | #include <linux/notifier.h> |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 33 | #include <linux/platform_device.h> |
Al Viro | 914e263 | 2006-10-18 13:55:46 -0400 | [diff] [blame] | 34 | #include <linux/jiffies.h> |
Randy Dunlap | 62a6d7f | 2007-03-26 21:38:49 -0800 | [diff] [blame] | 35 | #include <linux/stddef.h> |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 36 | #include <linux/acpi.h> |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 37 | |
Rashika | 3f9eed5 | 2013-12-17 15:00:04 +0530 | [diff] [blame] | 38 | #include "internal.h" |
| 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 | struct dock_station { |
| 55 | acpi_handle handle; |
| 56 | unsigned long last_dock_time; |
| 57 | u32 flags; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 58 | struct list_head dependent_devices; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 59 | |
Alex Chiang | 50d716e | 2009-10-01 11:59:23 -0600 | [diff] [blame] | 60 | struct list_head sibling; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 61 | struct platform_device *dock_device; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 62 | }; |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 63 | static LIST_HEAD(dock_stations); |
| 64 | static int dock_station_count; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 65 | |
| 66 | struct dock_dependent_device { |
| 67 | struct list_head list; |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 68 | struct acpi_device *adev; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | #define DOCK_DOCKING 0x00000001 |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 72 | #define DOCK_UNDOCKING 0x00000002 |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 73 | #define DOCK_IS_DOCK 0x00000010 |
| 74 | #define DOCK_IS_ATA 0x00000020 |
| 75 | #define DOCK_IS_BAT 0x00000040 |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 76 | #define DOCK_EVENT 3 |
| 77 | #define UNDOCK_EVENT 2 |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 78 | |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 79 | enum dock_callback_type { |
| 80 | DOCK_CALL_HANDLER, |
| 81 | DOCK_CALL_FIXUP, |
| 82 | DOCK_CALL_UEVENT, |
| 83 | }; |
| 84 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 85 | /***************************************************************************** |
| 86 | * Dock Dependent device functions * |
| 87 | *****************************************************************************/ |
| 88 | /** |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 89 | * add_dock_dependent_device - associate a device with the dock station |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 90 | * @ds: Dock station. |
| 91 | * @adev: Dependent ACPI device object. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 92 | * |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 93 | * Add the dependent device to the dock's dependent device list. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 94 | */ |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 95 | static int add_dock_dependent_device(struct dock_station *ds, |
| 96 | struct acpi_device *adev) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 97 | { |
| 98 | struct dock_dependent_device *dd; |
| 99 | |
| 100 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 101 | if (!dd) |
| 102 | return -ENOMEM; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 103 | |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 104 | dd->adev = adev; |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 105 | INIT_LIST_HEAD(&dd->list); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 106 | list_add_tail(&dd->list, &ds->dependent_devices); |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 107 | |
| 108 | return 0; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 109 | } |
| 110 | |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 111 | 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] | 112 | enum dock_callback_type cb_type) |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 113 | { |
Rafael J. Wysocki | edf5bf3 | 2014-02-21 01:10:18 +0100 | [diff] [blame] | 114 | struct acpi_device *adev = dd->adev; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 115 | |
Rafael J. Wysocki | edf5bf3 | 2014-02-21 01:10:18 +0100 | [diff] [blame] | 116 | acpi_lock_hp_context(); |
| 117 | |
| 118 | if (!adev->hp) |
Rafael J. Wysocki | 2f16817 | 2014-02-21 01:11:30 +0100 | [diff] [blame] | 119 | goto out; |
Rafael J. Wysocki | edf5bf3 | 2014-02-21 01:10:18 +0100 | [diff] [blame] | 120 | |
| 121 | if (cb_type == DOCK_CALL_FIXUP) { |
| 122 | void (*fixup)(struct acpi_device *); |
| 123 | |
| 124 | fixup = adev->hp->fixup; |
| 125 | if (fixup) { |
| 126 | acpi_unlock_hp_context(); |
| 127 | fixup(adev); |
| 128 | return; |
| 129 | } |
Rafael J. Wysocki | be27b3d | 2014-02-21 01:10:27 +0100 | [diff] [blame] | 130 | } else if (cb_type == DOCK_CALL_UEVENT) { |
| 131 | void (*uevent)(struct acpi_device *, u32); |
| 132 | |
| 133 | uevent = adev->hp->uevent; |
| 134 | if (uevent) { |
| 135 | acpi_unlock_hp_context(); |
| 136 | uevent(adev, event); |
| 137 | return; |
| 138 | } |
Rafael J. Wysocki | edf5bf3 | 2014-02-21 01:10:18 +0100 | [diff] [blame] | 139 | } else { |
| 140 | int (*notify)(struct acpi_device *, u32); |
| 141 | |
Rafael J. Wysocki | be27b3d | 2014-02-21 01:10:27 +0100 | [diff] [blame] | 142 | notify = adev->hp->notify; |
Rafael J. Wysocki | edf5bf3 | 2014-02-21 01:10:18 +0100 | [diff] [blame] | 143 | if (notify) { |
| 144 | acpi_unlock_hp_context(); |
| 145 | notify(adev, event); |
| 146 | return; |
| 147 | } |
| 148 | } |
| 149 | |
Rafael J. Wysocki | 2f16817 | 2014-02-21 01:11:30 +0100 | [diff] [blame] | 150 | out: |
Rafael J. Wysocki | edf5bf3 | 2014-02-21 01:10:18 +0100 | [diff] [blame] | 151 | acpi_unlock_hp_context(); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 154 | static struct dock_station *find_dock_station(acpi_handle handle) |
| 155 | { |
| 156 | struct dock_station *ds; |
| 157 | |
| 158 | list_for_each_entry(ds, &dock_stations, sibling) |
| 159 | if (ds->handle == handle) |
| 160 | return ds; |
| 161 | |
| 162 | return NULL; |
| 163 | } |
| 164 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 165 | /** |
| 166 | * find_dock_dependent_device - get a device dependent on this dock |
| 167 | * @ds: the dock station |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 168 | * @adev: ACPI device object to find. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 169 | * |
| 170 | * iterate over the dependent device list for this dock. If the |
| 171 | * dependent device matches the handle, return. |
| 172 | */ |
| 173 | static struct dock_dependent_device * |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 174 | find_dock_dependent_device(struct dock_station *ds, struct acpi_device *adev) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 175 | { |
| 176 | struct dock_dependent_device *dd; |
| 177 | |
Jiang Liu | ed633e7 | 2013-06-29 00:24:35 +0800 | [diff] [blame] | 178 | list_for_each_entry(dd, &ds->dependent_devices, list) |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 179 | if (adev == dd->adev) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 180 | return dd; |
Jiang Liu | ed633e7 | 2013-06-29 00:24:35 +0800 | [diff] [blame] | 181 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 182 | return NULL; |
| 183 | } |
| 184 | |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 185 | void register_dock_dependent_device(struct acpi_device *adev, |
| 186 | acpi_handle dshandle) |
| 187 | { |
| 188 | struct dock_station *ds = find_dock_station(dshandle); |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 189 | |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 190 | if (ds && !find_dock_dependent_device(ds, adev)) |
| 191 | add_dock_dependent_device(ds, adev); |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 194 | /***************************************************************************** |
| 195 | * Dock functions * |
| 196 | *****************************************************************************/ |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 197 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 198 | /** |
| 199 | * is_dock_device - see if a device is on a dock station |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 200 | * @adev: ACPI device object to check. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 201 | * |
| 202 | * If this device is either the dock station itself, |
| 203 | * or is a device dependent on the dock station, then it |
| 204 | * is a dock device |
| 205 | */ |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 206 | int is_dock_device(struct acpi_device *adev) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 207 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 208 | struct dock_station *dock_station; |
| 209 | |
| 210 | if (!dock_station_count) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 211 | return 0; |
| 212 | |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 213 | if (acpi_dock_match(adev->handle)) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 214 | return 1; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 215 | |
| 216 | list_for_each_entry(dock_station, &dock_stations, sibling) |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 217 | if (find_dock_dependent_device(dock_station, adev)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 218 | return 1; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 219 | |
| 220 | return 0; |
| 221 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 222 | EXPORT_SYMBOL_GPL(is_dock_device); |
| 223 | |
| 224 | /** |
| 225 | * dock_present - see if the dock station is present. |
| 226 | * @ds: the dock station |
| 227 | * |
| 228 | * execute the _STA method. note that present does not |
| 229 | * imply that we are docked. |
| 230 | */ |
| 231 | static int dock_present(struct dock_station *ds) |
| 232 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 233 | unsigned long long sta; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 234 | acpi_status status; |
| 235 | |
| 236 | if (ds) { |
| 237 | status = acpi_evaluate_integer(ds->handle, "_STA", NULL, &sta); |
| 238 | if (ACPI_SUCCESS(status) && sta) |
| 239 | return 1; |
| 240 | } |
| 241 | return 0; |
| 242 | } |
| 243 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 244 | /** |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 245 | * hot_remove_dock_devices - Remove dock station devices. |
| 246 | * @ds: Dock station. |
| 247 | */ |
| 248 | static void hot_remove_dock_devices(struct dock_station *ds) |
| 249 | { |
| 250 | struct dock_dependent_device *dd; |
| 251 | |
| 252 | /* |
| 253 | * Walk the list in reverse order so that devices that have been added |
| 254 | * last are removed first (in case there are some indirect dependencies |
| 255 | * between them). |
| 256 | */ |
| 257 | list_for_each_entry_reverse(dd, &ds->dependent_devices, list) |
| 258 | dock_hotplug_event(dd, ACPI_NOTIFY_EJECT_REQUEST, false); |
| 259 | |
| 260 | list_for_each_entry_reverse(dd, &ds->dependent_devices, list) |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 261 | acpi_bus_trim(dd->adev); |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
| 265 | * hotplug_dock_devices - Insert devices on a dock station. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 266 | * @ds: the dock station |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 267 | * @event: either bus check or device check request |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 268 | * |
| 269 | * Some devices on the dock station need to have drivers called |
| 270 | * to perform hotplug operations after a dock event has occurred. |
| 271 | * Traverse the list of dock devices that have registered a |
| 272 | * hotplug handler, and call the handler. |
| 273 | */ |
| 274 | static void hotplug_dock_devices(struct dock_station *ds, u32 event) |
| 275 | { |
| 276 | struct dock_dependent_device *dd; |
| 277 | |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 278 | /* Call driver specific post-dock fixups. */ |
| 279 | list_for_each_entry(dd, &ds->dependent_devices, list) |
| 280 | dock_hotplug_event(dd, event, DOCK_CALL_FIXUP); |
| 281 | |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 282 | /* Call driver specific hotplug functions. */ |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 283 | list_for_each_entry(dd, &ds->dependent_devices, list) |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 284 | dock_hotplug_event(dd, event, DOCK_CALL_HANDLER); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 285 | |
| 286 | /* |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 287 | * Check if all devices have been enumerated already. If not, run |
| 288 | * acpi_bus_scan() for them and that will cause scan handlers to be |
| 289 | * attached to device objects or acpi_drivers to be stopped/started if |
| 290 | * they are present. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 291 | */ |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 292 | list_for_each_entry(dd, &ds->dependent_devices, list) { |
| 293 | struct acpi_device *adev = dd->adev; |
| 294 | |
| 295 | if (!acpi_device_enumerated(adev)) { |
| 296 | int ret = acpi_bus_scan(adev->handle); |
| 297 | if (ret) |
| 298 | dev_dbg(&adev->dev, "scan error %d\n", -ret); |
| 299 | } |
| 300 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | static void dock_event(struct dock_station *ds, u32 event, int num) |
| 304 | { |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 305 | struct device *dev = &ds->dock_device->dev; |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 306 | char event_string[13]; |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 307 | char *envp[] = { event_string, NULL }; |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 308 | struct dock_dependent_device *dd; |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 309 | |
| 310 | if (num == UNDOCK_EVENT) |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 311 | sprintf(event_string, "EVENT=undock"); |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 312 | else |
Holger Macht | 66b5682 | 2007-08-10 13:10:32 -0700 | [diff] [blame] | 313 | sprintf(event_string, "EVENT=dock"); |
Kristen Carlson Accardi | 79a8f70 | 2007-05-09 15:10:22 -0700 | [diff] [blame] | 314 | |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 315 | /* |
Kristen Carlson Accardi | 8ea86e0 | 2006-12-11 12:05:08 -0800 | [diff] [blame] | 316 | * Indicate that the status of the dock station has |
| 317 | * changed. |
Kristen Carlson Accardi | 5669021 | 2006-08-01 14:59:19 -0700 | [diff] [blame] | 318 | */ |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 319 | if (num == DOCK_EVENT) |
| 320 | kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); |
| 321 | |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 322 | list_for_each_entry(dd, &ds->dependent_devices, list) |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 323 | dock_hotplug_event(dd, event, DOCK_CALL_UEVENT); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 324 | |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 325 | if (num != DOCK_EVENT) |
| 326 | kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 330 | * handle_dock - handle a dock event |
| 331 | * @ds: the dock station |
| 332 | * @dock: to dock, or undock - that is the question |
| 333 | * |
| 334 | * Execute the _DCK method in response to an acpi event |
| 335 | */ |
| 336 | static void handle_dock(struct dock_station *ds, int dock) |
| 337 | { |
| 338 | acpi_status status; |
| 339 | struct acpi_object_list arg_list; |
| 340 | union acpi_object arg; |
Zhang Rui | 6a868e1 | 2013-09-03 08:32:10 +0800 | [diff] [blame] | 341 | unsigned long long value; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 342 | |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 343 | acpi_handle_info(ds->handle, "%s\n", dock ? "docking" : "undocking"); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 344 | |
| 345 | /* _DCK method has one argument */ |
| 346 | arg_list.count = 1; |
| 347 | arg_list.pointer = &arg; |
| 348 | arg.type = ACPI_TYPE_INTEGER; |
| 349 | arg.integer.value = dock; |
Zhang Rui | 6a868e1 | 2013-09-03 08:32:10 +0800 | [diff] [blame] | 350 | status = acpi_evaluate_integer(ds->handle, "_DCK", &arg_list, &value); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 351 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 352 | acpi_handle_err(ds->handle, "Failed to execute _DCK (0x%x)\n", |
| 353 | status); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static inline void dock(struct dock_station *ds) |
| 357 | { |
| 358 | handle_dock(ds, 1); |
| 359 | } |
| 360 | |
| 361 | static inline void undock(struct dock_station *ds) |
| 362 | { |
| 363 | handle_dock(ds, 0); |
| 364 | } |
| 365 | |
| 366 | static inline void begin_dock(struct dock_station *ds) |
| 367 | { |
| 368 | ds->flags |= DOCK_DOCKING; |
| 369 | } |
| 370 | |
| 371 | static inline void complete_dock(struct dock_station *ds) |
| 372 | { |
| 373 | ds->flags &= ~(DOCK_DOCKING); |
| 374 | ds->last_dock_time = jiffies; |
| 375 | } |
| 376 | |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 377 | static inline void begin_undock(struct dock_station *ds) |
| 378 | { |
| 379 | ds->flags |= DOCK_UNDOCKING; |
| 380 | } |
| 381 | |
| 382 | static inline void complete_undock(struct dock_station *ds) |
| 383 | { |
| 384 | ds->flags &= ~(DOCK_UNDOCKING); |
| 385 | } |
| 386 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 387 | /** |
| 388 | * dock_in_progress - see if we are in the middle of handling a dock event |
| 389 | * @ds: the dock station |
| 390 | * |
| 391 | * Sometimes while docking, false dock events can be sent to the driver |
| 392 | * because good connections aren't made or some other reason. Ignore these |
| 393 | * if we are in the middle of doing something. |
| 394 | */ |
| 395 | static int dock_in_progress(struct dock_station *ds) |
| 396 | { |
| 397 | if ((ds->flags & DOCK_DOCKING) || |
| 398 | time_before(jiffies, (ds->last_dock_time + HZ))) |
| 399 | return 1; |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | /** |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 404 | * handle_eject_request - handle an undock request checking for error conditions |
| 405 | * |
| 406 | * Check to make sure the dock device is still present, then undock and |
| 407 | * hotremove all the devices that may need removing. |
| 408 | */ |
| 409 | static int handle_eject_request(struct dock_station *ds, u32 event) |
| 410 | { |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 411 | if (dock_in_progress(ds)) |
| 412 | return -EBUSY; |
| 413 | |
| 414 | /* |
| 415 | * here we need to generate the undock |
| 416 | * event prior to actually doing the undock |
| 417 | * so that the device struct still exists. |
Holger Macht | afd7301 | 2008-08-06 17:56:01 +0200 | [diff] [blame] | 418 | * Also, even send the dock event if the |
| 419 | * device is not present anymore |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 420 | */ |
| 421 | dock_event(ds, event, UNDOCK_EVENT); |
Holger Macht | afd7301 | 2008-08-06 17:56:01 +0200 | [diff] [blame] | 422 | |
Rafael J. Wysocki | 37f9087 | 2013-06-30 23:46:42 +0200 | [diff] [blame] | 423 | hot_remove_dock_devices(ds); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 424 | undock(ds); |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 425 | acpi_evaluate_lck(ds->handle, 0); |
| 426 | acpi_evaluate_ej0(ds->handle); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 427 | if (dock_present(ds)) { |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 428 | acpi_handle_err(ds->handle, "Unable to undock!\n"); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 429 | return -EBUSY; |
| 430 | } |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 431 | complete_undock(ds); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | /** |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 436 | * dock_notify - Handle ACPI dock notification. |
| 437 | * @adev: Dock station's ACPI device object. |
| 438 | * @event: Event code. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 439 | * |
| 440 | * If we are notified to dock, then check to see if the dock is |
| 441 | * present and then dock. Notify all drivers of the dock event, |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 442 | * and then hotplug and devices that may need hotplugging. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 443 | */ |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 444 | int dock_notify(struct acpi_device *adev, u32 event) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 445 | { |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 446 | acpi_handle handle = adev->handle; |
| 447 | struct dock_station *ds = find_dock_station(handle); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 448 | int surprise_removal = 0; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 449 | |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 450 | if (!ds) |
| 451 | return -ENODEV; |
| 452 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 453 | /* |
| 454 | * According to acpi spec 3.0a, if a DEVICE_CHECK notification |
| 455 | * is sent and _DCK is present, it is assumed to mean an undock |
| 456 | * request. |
| 457 | */ |
| 458 | if ((ds->flags & DOCK_IS_DOCK) && event == ACPI_NOTIFY_DEVICE_CHECK) |
| 459 | event = ACPI_NOTIFY_EJECT_REQUEST; |
| 460 | |
| 461 | /* |
| 462 | * dock station: BUS_CHECK - docked or surprise removal |
| 463 | * DEVICE_CHECK - undocked |
| 464 | * other device: BUS_CHECK/DEVICE_CHECK - added or surprise removal |
| 465 | * |
| 466 | * To simplify event handling, dock dependent device handler always |
| 467 | * get ACPI_NOTIFY_BUS_CHECK/ACPI_NOTIFY_DEVICE_CHECK for add and |
| 468 | * ACPI_NOTIFY_EJECT_REQUEST for removal |
| 469 | */ |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 470 | switch (event) { |
| 471 | case ACPI_NOTIFY_BUS_CHECK: |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 472 | case ACPI_NOTIFY_DEVICE_CHECK: |
Rafael J. Wysocki | 0a8e5c3 | 2014-02-10 13:44:20 +0100 | [diff] [blame] | 473 | if (!dock_in_progress(ds) && !acpi_device_enumerated(adev)) { |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 474 | begin_dock(ds); |
| 475 | dock(ds); |
| 476 | if (!dock_present(ds)) { |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 477 | acpi_handle_err(handle, "Unable to dock!\n"); |
Shaohua Li | 8b59560 | 2008-08-28 10:02:03 +0800 | [diff] [blame] | 478 | complete_dock(ds); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 479 | break; |
| 480 | } |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 481 | hotplug_dock_devices(ds, event); |
| 482 | complete_dock(ds); |
| 483 | dock_event(ds, event, DOCK_EVENT); |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 484 | acpi_evaluate_lck(ds->handle, 1); |
Lin Ming | 3a37898 | 2010-12-13 13:36:15 +0800 | [diff] [blame] | 485 | acpi_update_all_gpes(); |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 486 | break; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 487 | } |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 488 | if (dock_present(ds) || dock_in_progress(ds)) |
| 489 | break; |
| 490 | /* This is a surprise removal */ |
| 491 | surprise_removal = 1; |
| 492 | event = ACPI_NOTIFY_EJECT_REQUEST; |
| 493 | /* Fall back */ |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 494 | case ACPI_NOTIFY_EJECT_REQUEST: |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 495 | begin_undock(ds); |
Shaohua Li | f730ae1 | 2008-08-28 10:05:45 +0800 | [diff] [blame] | 496 | if ((immediate_undock && !(ds->flags & DOCK_IS_ATA)) |
| 497 | || surprise_removal) |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 498 | handle_eject_request(ds, event); |
| 499 | else |
| 500 | dock_event(ds, event, UNDOCK_EVENT); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 501 | break; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 502 | } |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 503 | return 0; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 504 | } |
| 505 | |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 506 | /* |
| 507 | * show_docked - read method for "docked" file in sysfs |
| 508 | */ |
| 509 | static ssize_t show_docked(struct device *dev, |
| 510 | struct device_attribute *attr, char *buf) |
| 511 | { |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 512 | struct dock_station *dock_station = dev->platform_data; |
Rafael J. Wysocki | ab62f9c | 2014-02-15 01:29:06 +0100 | [diff] [blame] | 513 | struct acpi_device *adev = NULL; |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 514 | |
Rafael J. Wysocki | ab62f9c | 2014-02-15 01:29:06 +0100 | [diff] [blame] | 515 | acpi_bus_get_device(dock_station->handle, &adev); |
| 516 | return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev)); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 517 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 518 | static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 519 | |
| 520 | /* |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 521 | * show_flags - read method for flags file in sysfs |
| 522 | */ |
| 523 | static ssize_t show_flags(struct device *dev, |
| 524 | struct device_attribute *attr, char *buf) |
| 525 | { |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 526 | struct dock_station *dock_station = dev->platform_data; |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 527 | return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags); |
| 528 | |
| 529 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 530 | static DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 531 | |
| 532 | /* |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 533 | * write_undock - write method for "undock" file in sysfs |
| 534 | */ |
| 535 | static ssize_t write_undock(struct device *dev, struct device_attribute *attr, |
| 536 | const char *buf, size_t count) |
| 537 | { |
| 538 | int ret; |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 539 | struct dock_station *dock_station = dev->platform_data; |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 540 | |
| 541 | if (!count) |
| 542 | return -EINVAL; |
| 543 | |
Rafael J. Wysocki | 8112006 | 2013-06-16 00:38:30 +0200 | [diff] [blame] | 544 | acpi_scan_lock_acquire(); |
Holger Macht | 9171f83 | 2008-03-12 01:07:27 +0100 | [diff] [blame] | 545 | begin_undock(dock_station); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 546 | ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST); |
Rafael J. Wysocki | 8112006 | 2013-06-16 00:38:30 +0200 | [diff] [blame] | 547 | acpi_scan_lock_release(); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 548 | return ret ? ret: count; |
| 549 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 550 | static DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock); |
brandon@ifup.org | c80fdbe | 2006-12-04 14:49:58 -0800 | [diff] [blame] | 551 | |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 552 | /* |
| 553 | * show_dock_uid - read method for "uid" file in sysfs |
| 554 | */ |
| 555 | static ssize_t show_dock_uid(struct device *dev, |
| 556 | struct device_attribute *attr, char *buf) |
| 557 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 558 | unsigned long long lbuf; |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 559 | struct dock_station *dock_station = dev->platform_data; |
Kristen Carlson Accardi | 38ff4ff | 2007-05-09 15:04:24 -0700 | [diff] [blame] | 560 | acpi_status status = acpi_evaluate_integer(dock_station->handle, |
| 561 | "_UID", NULL, &lbuf); |
| 562 | if (ACPI_FAILURE(status)) |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 563 | return 0; |
Kristen Carlson Accardi | 38ff4ff | 2007-05-09 15:04:24 -0700 | [diff] [blame] | 564 | |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 565 | return snprintf(buf, PAGE_SIZE, "%llx\n", lbuf); |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 566 | } |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 567 | static DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); |
Ilya A. Volynets-Evenbakh | ac122bb | 2007-02-19 15:19:31 -0800 | [diff] [blame] | 568 | |
Shaohua Li | 8652b00 | 2008-08-28 10:07:45 +0800 | [diff] [blame] | 569 | static ssize_t show_dock_type(struct device *dev, |
| 570 | struct device_attribute *attr, char *buf) |
| 571 | { |
Alex Chiang | fe06fba | 2009-10-19 15:14:45 -0600 | [diff] [blame] | 572 | struct dock_station *dock_station = dev->platform_data; |
Shaohua Li | 8652b00 | 2008-08-28 10:07:45 +0800 | [diff] [blame] | 573 | char *type; |
| 574 | |
| 575 | if (dock_station->flags & DOCK_IS_DOCK) |
| 576 | type = "dock_station"; |
| 577 | else if (dock_station->flags & DOCK_IS_ATA) |
| 578 | type = "ata_bay"; |
| 579 | else if (dock_station->flags & DOCK_IS_BAT) |
| 580 | type = "battery_bay"; |
| 581 | else |
| 582 | type = "unknown"; |
| 583 | |
| 584 | return snprintf(buf, PAGE_SIZE, "%s\n", type); |
| 585 | } |
| 586 | static DEVICE_ATTR(type, S_IRUGO, show_dock_type, NULL); |
| 587 | |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 588 | static struct attribute *dock_attributes[] = { |
| 589 | &dev_attr_docked.attr, |
| 590 | &dev_attr_flags.attr, |
| 591 | &dev_attr_undock.attr, |
| 592 | &dev_attr_uid.attr, |
| 593 | &dev_attr_type.attr, |
| 594 | NULL |
| 595 | }; |
| 596 | |
| 597 | static struct attribute_group dock_attribute_group = { |
| 598 | .attrs = dock_attributes |
| 599 | }; |
| 600 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 601 | /** |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 602 | * acpi_dock_add - Add a new dock station |
| 603 | * @adev: Dock station ACPI device object. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 604 | * |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 605 | * allocated and initialize a new dock station device. |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 606 | */ |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 607 | void acpi_dock_add(struct acpi_device *adev) |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 608 | { |
Rafael J. Wysocki | 2efbca4 | 2013-07-05 03:23:36 +0200 | [diff] [blame] | 609 | struct dock_station *dock_station, ds = { NULL, }; |
Rafael J. Wysocki | af887449 | 2014-02-16 00:09:47 +0100 | [diff] [blame] | 610 | struct platform_device_info pdevinfo; |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 611 | acpi_handle handle = adev->handle; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 612 | struct platform_device *dd; |
Rafael J. Wysocki | 2efbca4 | 2013-07-05 03:23:36 +0200 | [diff] [blame] | 613 | int ret; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 614 | |
Rafael J. Wysocki | af887449 | 2014-02-16 00:09:47 +0100 | [diff] [blame] | 615 | memset(&pdevinfo, 0, sizeof(pdevinfo)); |
| 616 | pdevinfo.name = "dock"; |
| 617 | pdevinfo.id = dock_station_count; |
Rafael J. Wysocki | ce79348 | 2015-03-16 23:49:03 +0100 | [diff] [blame] | 618 | pdevinfo.fwnode = acpi_fwnode_handle(adev); |
Rafael J. Wysocki | af887449 | 2014-02-16 00:09:47 +0100 | [diff] [blame] | 619 | pdevinfo.data = &ds; |
| 620 | pdevinfo.size_data = sizeof(ds); |
| 621 | dd = platform_device_register_full(&pdevinfo); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 622 | if (IS_ERR(dd)) |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 623 | return; |
Alex Chiang | 9751cb7 | 2009-10-19 15:14:40 -0600 | [diff] [blame] | 624 | |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 625 | dock_station = dd->dev.platform_data; |
| 626 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 627 | dock_station->handle = handle; |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 628 | dock_station->dock_device = dd; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 629 | dock_station->last_dock_time = jiffies - HZ; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 630 | |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 631 | INIT_LIST_HEAD(&dock_station->sibling); |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 632 | INIT_LIST_HEAD(&dock_station->dependent_devices); |
Kristen Carlson Accardi | a0cd35f | 2007-05-09 15:08:15 -0700 | [diff] [blame] | 633 | |
Kristen Carlson Accardi | 9ef2a9a | 2007-05-09 15:09:12 -0700 | [diff] [blame] | 634 | /* we want the dock device to send uevents */ |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 635 | dev_set_uevent_suppress(&dd->dev, 0); |
Kristen Carlson Accardi | 9ef2a9a | 2007-05-09 15:09:12 -0700 | [diff] [blame] | 636 | |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 637 | if (acpi_dock_match(handle)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 638 | dock_station->flags |= DOCK_IS_DOCK; |
Jiang Liu | c9b5471 | 2013-06-29 00:24:42 +0800 | [diff] [blame] | 639 | if (acpi_ata_match(handle)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 640 | dock_station->flags |= DOCK_IS_ATA; |
Rafael J. Wysocki | b43109f | 2014-02-16 00:09:34 +0100 | [diff] [blame] | 641 | if (acpi_device_is_battery(adev)) |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 642 | dock_station->flags |= DOCK_IS_BAT; |
| 643 | |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 644 | ret = sysfs_create_group(&dd->dev.kobj, &dock_attribute_group); |
Shaohua Li | 8652b00 | 2008-08-28 10:07:45 +0800 | [diff] [blame] | 645 | if (ret) |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 646 | goto err_unregister; |
Kristen Carlson Accardi | 671adbe | 2006-12-04 14:49:43 -0800 | [diff] [blame] | 647 | |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 648 | /* add the dock station as a device dependent on itself */ |
Rafael J. Wysocki | 3b52b21 | 2014-02-21 01:10:09 +0100 | [diff] [blame] | 649 | ret = add_dock_dependent_device(dock_station, adev); |
Alex Chiang | f69cfdd | 2009-10-19 15:14:29 -0600 | [diff] [blame] | 650 | if (ret) |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 651 | goto err_rmgroup; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 652 | |
Shaohua Li | db350b0 | 2008-08-28 10:03:58 +0800 | [diff] [blame] | 653 | dock_station_count++; |
Alex Chiang | 50d716e | 2009-10-01 11:59:23 -0600 | [diff] [blame] | 654 | list_add(&dock_station->sibling, &dock_stations); |
Rafael J. Wysocki | 1e2380c | 2014-02-16 01:51:01 +0100 | [diff] [blame] | 655 | adev->flags.is_dock_station = true; |
| 656 | dev_info(&adev->dev, "ACPI dock station (docks/bays count: %d)\n", |
| 657 | dock_station_count); |
| 658 | return; |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 659 | |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 660 | err_rmgroup: |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 661 | sysfs_remove_group(&dd->dev.kobj, &dock_attribute_group); |
Rafael J. Wysocki | f311e1c | 2014-02-21 01:11:38 +0100 | [diff] [blame] | 662 | |
Alex Chiang | 5f46c2f | 2009-10-19 15:14:24 -0600 | [diff] [blame] | 663 | err_unregister: |
Alex Chiang | 747479a | 2009-10-19 15:14:50 -0600 | [diff] [blame] | 664 | platform_device_unregister(dd); |
Toshi Kani | cd73018 | 2012-11-20 23:42:30 +0000 | [diff] [blame] | 665 | acpi_handle_err(handle, "%s encountered error %d\n", __func__, ret); |
Len Brown | c8f7a62c | 2006-07-09 17:22:28 -0400 | [diff] [blame] | 666 | } |