aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/device_pm.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-01-22 06:55:52 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-01-22 06:55:52 -0500
commit9c0f45e388fb9f9003ea22f98b84ffbab65ba554 (patch)
treeb112cd21f1d1f2e625b667b6f5ffdaa75b0aba4e /drivers/acpi/device_pm.c
parenta2367807b8d2c0aca5afb92fead2537dcd3d10b0 (diff)
ACPI / PM: Introduce helper for executing _PSn methods
To reduce code duplication between acpi_device_set_power() and acpi_bus_init_power(), introduce a new helper function for executing ACPI devices' _PSn (n = 0..3) methods, acpi_dev_pm_explicit_set(). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/device_pm.c')
-rw-r--r--drivers/acpi/device_pm.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index c87853f583d8..d7f3908c2e88 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -186,6 +186,19 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
186 return 0; 186 return 0;
187} 187}
188 188
189static int acpi_dev_pm_explicit_set(struct acpi_device *adev, int state)
190{
191 if (adev->power.states[state].flags.explicit_set) {
192 char method[5] = { '_', 'P', 'S', '0' + state, '\0' };
193 acpi_status status;
194
195 status = acpi_evaluate_object(adev->handle, method, NULL, NULL);
196 if (ACPI_FAILURE(status))
197 return -ENODEV;
198 }
199 return 0;
200}
201
189/** 202/**
190 * acpi_device_set_power - Set power state of an ACPI device. 203 * acpi_device_set_power - Set power state of an ACPI device.
191 * @device: Device to set the power state of. 204 * @device: Device to set the power state of.
@@ -197,8 +210,6 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
197int acpi_device_set_power(struct acpi_device *device, int state) 210int acpi_device_set_power(struct acpi_device *device, int state)
198{ 211{
199 int result = 0; 212 int result = 0;
200 acpi_status status = AE_OK;
201 char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
202 bool cut_power = false; 213 bool cut_power = false;
203 214
204 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD)) 215 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
@@ -228,7 +239,6 @@ int acpi_device_set_power(struct acpi_device *device, int state)
228 if (state == ACPI_STATE_D3_COLD 239 if (state == ACPI_STATE_D3_COLD
229 && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) { 240 && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) {
230 state = ACPI_STATE_D3_HOT; 241 state = ACPI_STATE_D3_HOT;
231 object_name[3] = '3';
232 cut_power = true; 242 cut_power = true;
233 } 243 }
234 244
@@ -251,23 +261,14 @@ int acpi_device_set_power(struct acpi_device *device, int state)
251 if (result) 261 if (result)
252 goto end; 262 goto end;
253 } 263 }
254 if (device->power.states[state].flags.explicit_set) { 264 result = acpi_dev_pm_explicit_set(device, state);
255 status = acpi_evaluate_object(device->handle, 265 if (result)
256 object_name, NULL, NULL); 266 goto end;
257 if (ACPI_FAILURE(status)) {
258 result = -ENODEV;
259 goto end;
260 }
261 }
262 } else { 267 } else {
263 if (device->power.states[state].flags.explicit_set) { 268 result = acpi_dev_pm_explicit_set(device, state);
264 status = acpi_evaluate_object(device->handle, 269 if (result)
265 object_name, NULL, NULL); 270 goto end;
266 if (ACPI_FAILURE(status)) { 271
267 result = -ENODEV;
268 goto end;
269 }
270 }
271 if (device->power.flags.power_resources) { 272 if (device->power.flags.power_resources) {
272 result = acpi_power_transition(device, state); 273 result = acpi_power_transition(device, state);
273 if (result) 274 if (result)
@@ -335,15 +336,9 @@ int acpi_bus_init_power(struct acpi_device *device)
335 if (result) 336 if (result)
336 return result; 337 return result;
337 338
338 if (device->power.states[state].flags.explicit_set) { 339 result = acpi_dev_pm_explicit_set(device, state);
339 char method[5] = { '_', 'P', 'S', '0' + state, '\0' }; 340 if (result)
340 acpi_status status; 341 return result;
341
342 status = acpi_evaluate_object(device->handle, method,
343 NULL, NULL);
344 if (ACPI_FAILURE(status))
345 return -ENODEV;
346 }
347 } 342 }
348 device->power.state = state; 343 device->power.state = state;
349 return 0; 344 return 0;