Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pnpacpi -- PnP ACPI driver |
| 3 | * |
| 4 | * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr> |
| 5 | * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com> |
David Brownell | 55955aa | 2007-05-08 00:28:35 -0700 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
David Brownell | 55955aa | 2007-05-08 00:28:35 -0700 | [diff] [blame] | 21 | |
Paul Gortmaker | 26e6e9e | 2011-10-26 18:06:20 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/acpi.h> |
| 24 | #include <linux/pnp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 26 | #include <linux/mod_devicetable.h> |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 27 | |
Bjorn Helgaas | 1692b27b | 2008-04-28 16:33:51 -0600 | [diff] [blame] | 28 | #include "../base.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "pnpacpi.h" |
| 30 | |
Dmitry Torokhov | 420a0f6 | 2010-09-18 10:11:09 -0700 | [diff] [blame] | 31 | static int num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Compatible Device IDs |
| 35 | */ |
| 36 | #define TEST_HEX(c) \ |
| 37 | if (!(('0' <= (c) && (c) <= '9') || ('A' <= (c) && (c) <= 'F'))) \ |
| 38 | return 0 |
| 39 | #define TEST_ALPHA(c) \ |
Alan Cox | cdc87c5 | 2012-12-07 23:11:14 +0100 | [diff] [blame] | 40 | if (!('A' <= (c) && (c) <= 'Z')) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | return 0 |
Thomas Renninger | 620e112 | 2010-10-01 10:54:00 +0200 | [diff] [blame] | 42 | static int __init ispnpidacpi(const char *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
| 44 | TEST_ALPHA(id[0]); |
| 45 | TEST_ALPHA(id[1]); |
| 46 | TEST_ALPHA(id[2]); |
| 47 | TEST_HEX(id[3]); |
| 48 | TEST_HEX(id[4]); |
| 49 | TEST_HEX(id[5]); |
| 50 | TEST_HEX(id[6]); |
| 51 | if (id[7] != '\0') |
| 52 | return 0; |
| 53 | return 1; |
| 54 | } |
| 55 | |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 56 | static int pnpacpi_get_resources(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Bjorn Helgaas | 2f53432 | 2008-08-19 16:53:47 -0600 | [diff] [blame] | 58 | pnp_dbg(&dev->dev, "get resources\n"); |
Bjorn Helgaas | d152cf5 | 2008-04-28 16:34:39 -0600 | [diff] [blame] | 59 | return pnpacpi_parse_allocated_resource(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 62 | static int pnpacpi_set_resources(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 64 | struct acpi_device *acpi_dev; |
| 65 | acpi_handle handle; |
Rafael J. Wysocki | a8d2239 | 2014-04-30 22:36:33 +0200 | [diff] [blame] | 66 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Bjorn Helgaas | 2f53432 | 2008-08-19 16:53:47 -0600 | [diff] [blame] | 68 | pnp_dbg(&dev->dev, "set resources\n"); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 69 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 70 | acpi_dev = ACPI_COMPANION(&dev->dev); |
| 71 | if (!acpi_dev) { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 72 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
| 73 | return -ENODEV; |
| 74 | } |
| 75 | |
Rafael J. Wysocki | a6b5e88 | 2012-11-30 13:05:05 +0100 | [diff] [blame] | 76 | if (WARN_ON_ONCE(acpi_dev != dev->data)) |
| 77 | dev->data = acpi_dev; |
| 78 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 79 | handle = acpi_dev->handle; |
Rafael J. Wysocki | a8d2239 | 2014-04-30 22:36:33 +0200 | [diff] [blame] | 80 | if (acpi_has_method(handle, METHOD_NAME__SRS)) { |
| 81 | struct acpi_buffer buffer; |
| 82 | |
| 83 | ret = pnpacpi_build_resource_template(dev, &buffer); |
| 84 | if (ret) |
| 85 | return ret; |
| 86 | |
| 87 | ret = pnpacpi_encode_resources(dev, &buffer); |
| 88 | if (!ret) { |
| 89 | acpi_status status; |
| 90 | |
| 91 | status = acpi_set_current_resources(handle, &buffer); |
| 92 | if (ACPI_FAILURE(status)) |
| 93 | ret = -EIO; |
| 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 97 | if (!ret && acpi_device_power_manageable(acpi_dev)) |
| 98 | ret = acpi_device_set_power(acpi_dev, ACPI_STATE_D0); |
Rafael J. Wysocki | a8d2239 | 2014-04-30 22:36:33 +0200 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | static int pnpacpi_disable_resources(struct pnp_dev *dev) |
| 104 | { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 105 | struct acpi_device *acpi_dev; |
Rafael J. Wysocki | a8d2239 | 2014-04-30 22:36:33 +0200 | [diff] [blame] | 106 | acpi_status status; |
Witold Szczeponik | 6328a57 | 2009-03-30 19:31:06 +0200 | [diff] [blame] | 107 | |
| 108 | dev_dbg(&dev->dev, "disable resources\n"); |
David Brownell | 55955aa | 2007-05-08 00:28:35 -0700 | [diff] [blame] | 109 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 110 | acpi_dev = ACPI_COMPANION(&dev->dev); |
| 111 | if (!acpi_dev) { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 112 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
| 113 | return 0; |
| 114 | } |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 117 | if (acpi_device_power_manageable(acpi_dev)) |
| 118 | acpi_device_set_power(acpi_dev, ACPI_STATE_D3_COLD); |
Rafael J. Wysocki | a8d2239 | 2014-04-30 22:36:33 +0200 | [diff] [blame] | 119 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 120 | /* continue even if acpi_device_set_power() fails */ |
| 121 | status = acpi_evaluate_object(acpi_dev->handle, "_DIS", NULL, NULL); |
Rafael J. Wysocki | a8d2239 | 2014-04-30 22:36:33 +0200 | [diff] [blame] | 122 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) |
| 123 | return -ENODEV; |
| 124 | |
| 125 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 128 | #ifdef CONFIG_ACPI_SLEEP |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 129 | static bool pnpacpi_can_wakeup(struct pnp_dev *dev) |
| 130 | { |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 131 | struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 132 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 133 | if (!acpi_dev) { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 134 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
| 135 | return false; |
| 136 | } |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 137 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 138 | return acpi_bus_can_wakeup(acpi_dev->handle); |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 141 | static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) |
| 142 | { |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 143 | struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 144 | int error = 0; |
| 145 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 146 | if (!acpi_dev) { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 147 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
| 148 | return 0; |
| 149 | } |
Rafael J. Wysocki | 36e02b6 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 150 | |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 151 | if (device_can_wakeup(&dev->dev)) { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 152 | error = acpi_pm_device_sleep_wake(&dev->dev, |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 153 | device_may_wakeup(&dev->dev)); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 154 | if (error) |
| 155 | return error; |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 156 | } |
Rafael J. Wysocki | 36e02b6 | 2007-10-16 23:31:06 -0700 | [diff] [blame] | 157 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 158 | if (acpi_device_power_manageable(acpi_dev)) { |
Huang Ying | ee85f54 | 2012-06-23 10:23:48 +0800 | [diff] [blame] | 159 | int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, |
Rafael J. Wysocki | 8ad928d | 2013-07-30 14:36:20 +0200 | [diff] [blame] | 160 | ACPI_STATE_D3_COLD); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 161 | if (power_state < 0) |
| 162 | power_state = (state.event == PM_EVENT_ON) ? |
Rafael J. Wysocki | 8ad928d | 2013-07-30 14:36:20 +0200 | [diff] [blame] | 163 | ACPI_STATE_D0 : ACPI_STATE_D3_COLD; |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 164 | |
| 165 | /* |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 166 | * acpi_device_set_power() can fail (keyboard port can't be |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 167 | * powered-down?), and in any case, our return value is ignored |
| 168 | * by pnp_bus_suspend(). Hence we don't revert the wakeup |
| 169 | * setting if the set_power fails. |
| 170 | */ |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 171 | error = acpi_device_set_power(acpi_dev, power_state); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | return error; |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static int pnpacpi_resume(struct pnp_dev *dev) |
| 178 | { |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 179 | struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 180 | int error = 0; |
| 181 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 182 | if (!acpi_dev) { |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 183 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
| 184 | return -ENODEV; |
| 185 | } |
Bjorn Helgaas | c4da694 | 2009-11-17 17:05:14 -0700 | [diff] [blame] | 186 | |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 187 | if (device_may_wakeup(&dev->dev)) |
| 188 | acpi_pm_device_sleep_wake(&dev->dev, false); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 189 | |
Rafael J. Wysocki | e70dba6 | 2014-07-23 01:03:06 +0200 | [diff] [blame] | 190 | if (acpi_device_power_manageable(acpi_dev)) |
| 191 | error = acpi_device_set_power(acpi_dev, ACPI_STATE_D0); |
Rafael J. Wysocki | cc8e7a3 | 2011-01-10 21:23:16 +0100 | [diff] [blame] | 192 | |
| 193 | return error; |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 194 | } |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 195 | #endif |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 196 | |
Bjorn Helgaas | 9065ce4 | 2009-11-17 17:05:19 -0700 | [diff] [blame] | 197 | struct pnp_protocol pnpacpi_protocol = { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 198 | .name = "Plug and Play ACPI", |
| 199 | .get = pnpacpi_get_resources, |
| 200 | .set = pnpacpi_set_resources, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | .disable = pnpacpi_disable_resources, |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 202 | #ifdef CONFIG_ACPI_SLEEP |
Alan Stern | b14e033 | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 203 | .can_wakeup = pnpacpi_can_wakeup, |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 204 | .suspend = pnpacpi_suspend, |
| 205 | .resume = pnpacpi_resume, |
Len Brown | 673d5b4 | 2007-07-28 03:33:16 -0400 | [diff] [blame] | 206 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | }; |
Bjorn Helgaas | 9065ce4 | 2009-11-17 17:05:19 -0700 | [diff] [blame] | 208 | EXPORT_SYMBOL(pnpacpi_protocol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Rasmus Villemoes | 844142c | 2015-09-09 23:59:42 +0200 | [diff] [blame] | 210 | static const char *__init pnpacpi_get_id(struct acpi_device *device) |
Dmitry Torokhov | 420a0f6 | 2010-09-18 10:11:09 -0700 | [diff] [blame] | 211 | { |
| 212 | struct acpi_hardware_id *id; |
| 213 | |
| 214 | list_for_each_entry(id, &device->pnp.ids, list) { |
| 215 | if (ispnpidacpi(id->id)) |
| 216 | return id->id; |
| 217 | } |
| 218 | |
| 219 | return NULL; |
| 220 | } |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | static int __init pnpacpi_add_device(struct acpi_device *device) |
| 223 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | struct pnp_dev *dev; |
Rasmus Villemoes | 844142c | 2015-09-09 23:59:42 +0200 | [diff] [blame] | 225 | const char *pnpid; |
Bjorn Helgaas | 7f47fa6 | 2009-09-21 13:35:19 -0600 | [diff] [blame] | 226 | struct acpi_hardware_id *id; |
Dmitry Torokhov | 249135d | 2013-12-15 04:10:11 -0800 | [diff] [blame] | 227 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
Adrian Hunter | 2905875 | 2012-11-23 21:07:12 +0100 | [diff] [blame] | 229 | /* Skip devices that are already bound */ |
| 230 | if (device->physical_node_count) |
| 231 | return 0; |
| 232 | |
Zhao Yakui | 39a0ad8 | 2008-08-11 13:40:22 +0800 | [diff] [blame] | 233 | /* |
| 234 | * If a PnPacpi device is not present , the device |
| 235 | * driver should not be loaded. |
| 236 | */ |
Zhang Rui | 0e77e2c | 2013-09-03 08:32:08 +0800 | [diff] [blame] | 237 | if (!acpi_has_method(device->handle, "_CRS")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | return 0; |
| 239 | |
Dmitry Torokhov | 420a0f6 | 2010-09-18 10:11:09 -0700 | [diff] [blame] | 240 | pnpid = pnpacpi_get_id(device); |
| 241 | if (!pnpid) |
| 242 | return 0; |
| 243 | |
Zhang Rui | eec15ed | 2014-05-30 04:23:01 +0200 | [diff] [blame] | 244 | if (!device->status.present) |
Dmitry Torokhov | 420a0f6 | 2010-09-18 10:11:09 -0700 | [diff] [blame] | 245 | return 0; |
| 246 | |
| 247 | dev = pnp_alloc_dev(&pnpacpi_protocol, num, pnpid); |
Bjorn Helgaas | bda1e4e | 2008-04-28 16:33:54 -0600 | [diff] [blame] | 248 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return -ENOMEM; |
Bjorn Helgaas | bda1e4e | 2008-04-28 16:33:54 -0600 | [diff] [blame] | 250 | |
Rafael J. Wysocki | 2eb1eb0 | 2015-03-13 01:45:49 +0100 | [diff] [blame] | 251 | ACPI_COMPANION_SET(&dev->dev, device); |
Bjorn Helgaas | c4da694 | 2009-11-17 17:05:14 -0700 | [diff] [blame] | 252 | dev->data = device; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 253 | /* .enabled means the device can decode the resources */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | dev->active = device->status.enabled; |
Zhang Rui | 0e77e2c | 2013-09-03 08:32:08 +0800 | [diff] [blame] | 255 | if (acpi_has_method(device->handle, "_SRS")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | dev->capabilities |= PNP_CONFIGURABLE; |
| 257 | dev->capabilities |= PNP_READ; |
Shaohua Li | 856608e | 2008-01-12 19:37:49 -0500 | [diff] [blame] | 258 | if (device->flags.dynamic_status && (dev->capabilities & PNP_CONFIGURABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | dev->capabilities |= PNP_WRITE; |
| 260 | if (device->flags.removable) |
| 261 | dev->capabilities |= PNP_REMOVABLE; |
Zhang Rui | 0e77e2c | 2013-09-03 08:32:08 +0800 | [diff] [blame] | 262 | if (acpi_has_method(device->handle, "_DIS")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | dev->capabilities |= PNP_DISABLE; |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | if (strlen(acpi_device_name(device))) |
| 266 | strncpy(dev->name, acpi_device_name(device), sizeof(dev->name)); |
| 267 | else |
| 268 | strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name)); |
| 269 | |
Bjorn Helgaas | d152cf5 | 2008-04-28 16:34:39 -0600 | [diff] [blame] | 270 | if (dev->active) |
| 271 | pnpacpi_parse_allocated_resource(dev); |
David Brownell | 55955aa | 2007-05-08 00:28:35 -0700 | [diff] [blame] | 272 | |
Bjorn Helgaas | d152cf5 | 2008-04-28 16:34:39 -0600 | [diff] [blame] | 273 | if (dev->capabilities & PNP_CONFIGURABLE) |
| 274 | pnpacpi_parse_resource_option_data(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Bjorn Helgaas | 7f47fa6 | 2009-09-21 13:35:19 -0600 | [diff] [blame] | 276 | list_for_each_entry(id, &device->pnp.ids, list) { |
Dmitry Torokhov | 420a0f6 | 2010-09-18 10:11:09 -0700 | [diff] [blame] | 277 | if (!strcmp(id->id, pnpid)) |
Bjorn Helgaas | 7f47fa6 | 2009-09-21 13:35:19 -0600 | [diff] [blame] | 278 | continue; |
| 279 | if (!ispnpidacpi(id->id)) |
| 280 | continue; |
| 281 | pnp_add_id(dev, id->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* clear out the damaged flags */ |
| 285 | if (!dev->active) |
Bjorn Helgaas | f449000 | 2008-04-28 16:34:09 -0600 | [diff] [blame] | 286 | pnp_init_resources(dev); |
Dmitry Torokhov | 249135d | 2013-12-15 04:10:11 -0800 | [diff] [blame] | 287 | |
| 288 | error = pnp_add_device(dev); |
| 289 | if (error) { |
| 290 | put_device(&dev->dev); |
| 291 | return error; |
| 292 | } |
| 293 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 294 | num++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Rafael J. Wysocki | 2eb1eb0 | 2015-03-13 01:45:49 +0100 | [diff] [blame] | 296 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 300 | u32 lvl, void *context, |
| 301 | void **rv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
| 303 | struct acpi_device *device; |
| 304 | |
Zhang Rui | eec15ed | 2014-05-30 04:23:01 +0200 | [diff] [blame] | 305 | if (acpi_bus_get_device(handle, &device)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | return AE_CTRL_DEPTH; |
Zhang Rui | eec15ed | 2014-05-30 04:23:01 +0200 | [diff] [blame] | 307 | if (acpi_is_pnp_device(device)) |
| 308 | pnpacpi_add_device(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | return AE_OK; |
| 310 | } |
| 311 | |
| 312 | int pnpacpi_disabled __initdata; |
Adrian Bunk | b449f63 | 2005-11-07 01:01:48 -0800 | [diff] [blame] | 313 | static int __init pnpacpi_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | { |
| 315 | if (acpi_disabled || pnpacpi_disabled) { |
Bjorn Helgaas | c865d2f | 2008-08-19 16:53:26 -0600 | [diff] [blame] | 316 | printk(KERN_INFO "pnp: PnP ACPI: disabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 0; |
| 318 | } |
Bjorn Helgaas | c865d2f | 2008-08-19 16:53:26 -0600 | [diff] [blame] | 319 | printk(KERN_INFO "pnp: PnP ACPI init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | pnp_register_protocol(&pnpacpi_protocol); |
| 321 | acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL); |
Bjorn Helgaas | c865d2f | 2008-08-19 16:53:26 -0600 | [diff] [blame] | 322 | printk(KERN_INFO "pnp: PnP ACPI: found %d devices\n", num); |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 323 | pnp_platform_devices = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return 0; |
| 325 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 326 | |
Linus Torvalds | ed458df | 2008-10-10 08:00:17 -0700 | [diff] [blame] | 327 | fs_initcall(pnpacpi_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | static int __init pnpacpi_setup(char *str) |
| 330 | { |
| 331 | if (str == NULL) |
| 332 | return 1; |
| 333 | if (!strncmp(str, "off", 3)) |
| 334 | pnpacpi_disabled = 1; |
| 335 | return 1; |
| 336 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | __setup("pnpacpi=", pnpacpi_setup); |