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