diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-07-22 19:03:06 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-07-22 19:03:06 -0400 |
commit | e70dba6020eaaceb1d3619dfb535c719900c7091 (patch) | |
tree | 9b23819ba984bbe382c3650f19f523b8a195de16 | |
parent | f1b1dc845cb1418b2b0de35491b0da87498ea6a8 (diff) |
ACPI / PNP: Use ACPI_COMPANION() instead of ACPI_HANDLE()
The ACPI_HANDLE() macro evaluates ACPI_COMPANION() internally to
return the handle of the device's ACPI companion, so it is much
more straightforward and efficient to use ACPI_COMPANION()
directly to obtain the device's ACPI companion object instead of
using ACPI_HANDLE() and acpi_bus_get_device() on the returned
handle for the same thing.
Do that in several places in the ACPI PNP core code.
Also use acpi_device_set_power() and acpi_device_power_manageable()
instead of acpi_bus_set_power() and acpi_bus_power_manageable(),
respectively, because the former two are more efficient if the
ACPI device object is already available.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/pnp/pnpacpi/core.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 3bebedaee8e1..d2b780aade89 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c | |||
@@ -67,8 +67,8 @@ static int pnpacpi_set_resources(struct pnp_dev *dev) | |||
67 | 67 | ||
68 | pnp_dbg(&dev->dev, "set resources\n"); | 68 | pnp_dbg(&dev->dev, "set resources\n"); |
69 | 69 | ||
70 | handle = ACPI_HANDLE(&dev->dev); | 70 | acpi_dev = ACPI_COMPANION(&dev->dev); |
71 | if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { | 71 | if (!acpi_dev) { |
72 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); | 72 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
73 | return -ENODEV; | 73 | return -ENODEV; |
74 | } | 74 | } |
@@ -76,6 +76,7 @@ static int pnpacpi_set_resources(struct pnp_dev *dev) | |||
76 | if (WARN_ON_ONCE(acpi_dev != dev->data)) | 76 | if (WARN_ON_ONCE(acpi_dev != dev->data)) |
77 | dev->data = acpi_dev; | 77 | dev->data = acpi_dev; |
78 | 78 | ||
79 | handle = acpi_dev->handle; | ||
79 | if (acpi_has_method(handle, METHOD_NAME__SRS)) { | 80 | if (acpi_has_method(handle, METHOD_NAME__SRS)) { |
80 | struct acpi_buffer buffer; | 81 | struct acpi_buffer buffer; |
81 | 82 | ||
@@ -93,8 +94,8 @@ static int pnpacpi_set_resources(struct pnp_dev *dev) | |||
93 | } | 94 | } |
94 | kfree(buffer.pointer); | 95 | kfree(buffer.pointer); |
95 | } | 96 | } |
96 | if (!ret && acpi_bus_power_manageable(handle)) | 97 | if (!ret && acpi_device_power_manageable(acpi_dev)) |
97 | ret = acpi_bus_set_power(handle, ACPI_STATE_D0); | 98 | ret = acpi_device_set_power(acpi_dev, ACPI_STATE_D0); |
98 | 99 | ||
99 | return ret; | 100 | return ret; |
100 | } | 101 | } |
@@ -102,23 +103,22 @@ static int pnpacpi_set_resources(struct pnp_dev *dev) | |||
102 | static int pnpacpi_disable_resources(struct pnp_dev *dev) | 103 | static int pnpacpi_disable_resources(struct pnp_dev *dev) |
103 | { | 104 | { |
104 | struct acpi_device *acpi_dev; | 105 | struct acpi_device *acpi_dev; |
105 | acpi_handle handle; | ||
106 | acpi_status status; | 106 | acpi_status status; |
107 | 107 | ||
108 | dev_dbg(&dev->dev, "disable resources\n"); | 108 | dev_dbg(&dev->dev, "disable resources\n"); |
109 | 109 | ||
110 | handle = ACPI_HANDLE(&dev->dev); | 110 | acpi_dev = ACPI_COMPANION(&dev->dev); |
111 | if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { | 111 | if (!acpi_dev) { |
112 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); | 112 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | 115 | ||
116 | /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ | 116 | /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ |
117 | if (acpi_bus_power_manageable(handle)) | 117 | if (acpi_device_power_manageable(acpi_dev)) |
118 | acpi_bus_set_power(handle, ACPI_STATE_D3_COLD); | 118 | acpi_device_set_power(acpi_dev, ACPI_STATE_D3_COLD); |
119 | 119 | ||
120 | /* continue even if acpi_bus_set_power() fails */ | 120 | /* continue even if acpi_device_set_power() fails */ |
121 | status = acpi_evaluate_object(handle, "_DIS", NULL, NULL); | 121 | status = acpi_evaluate_object(acpi_dev->handle, "_DIS", NULL, NULL); |
122 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) | 122 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) |
123 | return -ENODEV; | 123 | return -ENODEV; |
124 | 124 | ||
@@ -128,26 +128,22 @@ static int pnpacpi_disable_resources(struct pnp_dev *dev) | |||
128 | #ifdef CONFIG_ACPI_SLEEP | 128 | #ifdef CONFIG_ACPI_SLEEP |
129 | static bool pnpacpi_can_wakeup(struct pnp_dev *dev) | 129 | static bool pnpacpi_can_wakeup(struct pnp_dev *dev) |
130 | { | 130 | { |
131 | struct acpi_device *acpi_dev; | 131 | struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); |
132 | acpi_handle handle; | ||
133 | 132 | ||
134 | handle = ACPI_HANDLE(&dev->dev); | 133 | if (!acpi_dev) { |
135 | if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { | ||
136 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); | 134 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
137 | return false; | 135 | return false; |
138 | } | 136 | } |
139 | 137 | ||
140 | return acpi_bus_can_wakeup(handle); | 138 | return acpi_bus_can_wakeup(acpi_dev->handle); |
141 | } | 139 | } |
142 | 140 | ||
143 | static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) | 141 | static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) |
144 | { | 142 | { |
145 | struct acpi_device *acpi_dev; | 143 | struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); |
146 | acpi_handle handle; | ||
147 | int error = 0; | 144 | int error = 0; |
148 | 145 | ||
149 | handle = ACPI_HANDLE(&dev->dev); | 146 | if (!acpi_dev) { |
150 | if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { | ||
151 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); | 147 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
152 | return 0; | 148 | return 0; |
153 | } | 149 | } |
@@ -159,7 +155,7 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) | |||
159 | return error; | 155 | return error; |
160 | } | 156 | } |
161 | 157 | ||
162 | if (acpi_bus_power_manageable(handle)) { | 158 | if (acpi_device_power_manageable(acpi_dev)) { |
163 | int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, | 159 | int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, |
164 | ACPI_STATE_D3_COLD); | 160 | ACPI_STATE_D3_COLD); |
165 | if (power_state < 0) | 161 | if (power_state < 0) |
@@ -167,12 +163,12 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) | |||
167 | ACPI_STATE_D0 : ACPI_STATE_D3_COLD; | 163 | ACPI_STATE_D0 : ACPI_STATE_D3_COLD; |
168 | 164 | ||
169 | /* | 165 | /* |
170 | * acpi_bus_set_power() often fails (keyboard port can't be | 166 | * acpi_device_set_power() can fail (keyboard port can't be |
171 | * powered-down?), and in any case, our return value is ignored | 167 | * powered-down?), and in any case, our return value is ignored |
172 | * by pnp_bus_suspend(). Hence we don't revert the wakeup | 168 | * by pnp_bus_suspend(). Hence we don't revert the wakeup |
173 | * setting if the set_power fails. | 169 | * setting if the set_power fails. |
174 | */ | 170 | */ |
175 | error = acpi_bus_set_power(handle, power_state); | 171 | error = acpi_device_set_power(acpi_dev, power_state); |
176 | } | 172 | } |
177 | 173 | ||
178 | return error; | 174 | return error; |
@@ -180,11 +176,10 @@ static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) | |||
180 | 176 | ||
181 | static int pnpacpi_resume(struct pnp_dev *dev) | 177 | static int pnpacpi_resume(struct pnp_dev *dev) |
182 | { | 178 | { |
183 | struct acpi_device *acpi_dev; | 179 | struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); |
184 | acpi_handle handle = ACPI_HANDLE(&dev->dev); | ||
185 | int error = 0; | 180 | int error = 0; |
186 | 181 | ||
187 | if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { | 182 | if (!acpi_dev) { |
188 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); | 183 | dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); |
189 | return -ENODEV; | 184 | return -ENODEV; |
190 | } | 185 | } |
@@ -192,8 +187,8 @@ static int pnpacpi_resume(struct pnp_dev *dev) | |||
192 | if (device_may_wakeup(&dev->dev)) | 187 | if (device_may_wakeup(&dev->dev)) |
193 | acpi_pm_device_sleep_wake(&dev->dev, false); | 188 | acpi_pm_device_sleep_wake(&dev->dev, false); |
194 | 189 | ||
195 | if (acpi_bus_power_manageable(handle)) | 190 | if (acpi_device_power_manageable(acpi_dev)) |
196 | error = acpi_bus_set_power(handle, ACPI_STATE_D0); | 191 | error = acpi_device_set_power(acpi_dev, ACPI_STATE_D0); |
197 | 192 | ||
198 | return error; | 193 | return error; |
199 | } | 194 | } |