device_pm.c (a2367807b8d2c0aca5afb92fead2537dcd3d10b0) device_pm.c (9c0f45e388fb9f9003ea22f98b84ffbab65ba554)
1/*
2 * drivers/acpi/device_pm.c - ACPI device power management routines.
3 *
4 * Copyright (C) 2012, Intel Corp.
5 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *

--- 172 unchanged lines hidden (view full) ---

181
182 out:
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
184 device->pnp.bus_id, acpi_power_state_string(*state)));
185
186 return 0;
187}
188
1/*
2 * drivers/acpi/device_pm.c - ACPI device power management routines.
3 *
4 * Copyright (C) 2012, Intel Corp.
5 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *

--- 172 unchanged lines hidden (view full) ---

181
182 out:
183 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is %s\n",
184 device->pnp.bus_id, acpi_power_state_string(*state)));
185
186 return 0;
187}
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/**
190 * acpi_device_set_power - Set power state of an ACPI device.
191 * @device: Device to set the power state of.
192 * @state: New power state to set.
193 *
194 * Callers must ensure that the device is power manageable before using this
195 * function.
196 */
197int acpi_device_set_power(struct acpi_device *device, int state)
198{
199 int result = 0;
202/**
203 * acpi_device_set_power - Set power state of an ACPI device.
204 * @device: Device to set the power state of.
205 * @state: New power state to set.
206 *
207 * Callers must ensure that the device is power manageable before using this
208 * function.
209 */
210int acpi_device_set_power(struct acpi_device *device, int state)
211{
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;
203
204 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
205 return -EINVAL;
206
207 /* Make sure this is a valid target state */
208
209 if (state == device->power.state) {

--- 13 unchanged lines hidden (view full) ---

223 " state than parent\n");
224 return -ENODEV;
225 }
226
227 /* For D3cold we should first transition into D3hot. */
228 if (state == ACPI_STATE_D3_COLD
229 && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) {
230 state = ACPI_STATE_D3_HOT;
213 bool cut_power = false;
214
215 if (!device || (state < ACPI_STATE_D0) || (state > ACPI_STATE_D3_COLD))
216 return -EINVAL;
217
218 /* Make sure this is a valid target state */
219
220 if (state == device->power.state) {

--- 13 unchanged lines hidden (view full) ---

234 " state than parent\n");
235 return -ENODEV;
236 }
237
238 /* For D3cold we should first transition into D3hot. */
239 if (state == ACPI_STATE_D3_COLD
240 && device->power.states[ACPI_STATE_D3_COLD].flags.os_accessible) {
241 state = ACPI_STATE_D3_HOT;
231 object_name[3] = '3';
232 cut_power = true;
233 }
234
235 /*
236 * Transition Power
237 * ----------------
238 * On transitions to a high-powered state we first apply power (via
239 * power resources) then evalute _PSx. Conversly for transitions to

--- 6 unchanged lines hidden (view full) ---

246 "Cannot transition to non-D0 state from D3\n");
247 return -ENODEV;
248 }
249 if (device->power.flags.power_resources) {
250 result = acpi_power_transition(device, state);
251 if (result)
252 goto end;
253 }
242 cut_power = true;
243 }
244
245 /*
246 * Transition Power
247 * ----------------
248 * On transitions to a high-powered state we first apply power (via
249 * power resources) then evalute _PSx. Conversly for transitions to

--- 6 unchanged lines hidden (view full) ---

256 "Cannot transition to non-D0 state from D3\n");
257 return -ENODEV;
258 }
259 if (device->power.flags.power_resources) {
260 result = acpi_power_transition(device, state);
261 if (result)
262 goto end;
263 }
254 if (device->power.states[state].flags.explicit_set) {
255 status = acpi_evaluate_object(device->handle,
256 object_name, NULL, NULL);
257 if (ACPI_FAILURE(status)) {
258 result = -ENODEV;
259 goto end;
260 }
261 }
264 result = acpi_dev_pm_explicit_set(device, state);
265 if (result)
266 goto end;
262 } else {
267 } else {
263 if (device->power.states[state].flags.explicit_set) {
264 status = acpi_evaluate_object(device->handle,
265 object_name, NULL, NULL);
266 if (ACPI_FAILURE(status)) {
267 result = -ENODEV;
268 goto end;
269 }
270 }
268 result = acpi_dev_pm_explicit_set(device, state);
269 if (result)
270 goto end;
271
271 if (device->power.flags.power_resources) {
272 result = acpi_power_transition(device, state);
273 if (result)
274 goto end;
275 }
276 }
277
278 if (cut_power)

--- 51 unchanged lines hidden (view full) ---

330 if (result)
331 return result;
332
333 if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) {
334 result = acpi_power_on_resources(device, state);
335 if (result)
336 return result;
337
272 if (device->power.flags.power_resources) {
273 result = acpi_power_transition(device, state);
274 if (result)
275 goto end;
276 }
277 }
278
279 if (cut_power)

--- 51 unchanged lines hidden (view full) ---

331 if (result)
332 return result;
333
334 if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) {
335 result = acpi_power_on_resources(device, state);
336 if (result)
337 return result;
338
338 if (device->power.states[state].flags.explicit_set) {
339 char method[5] = { '_', 'P', 'S', '0' + state, '\0' };
340 acpi_status status;
341
342 status = acpi_evaluate_object(device->handle, method,
343 NULL, NULL);
344 if (ACPI_FAILURE(status))
345 return -ENODEV;
346 }
339 result = acpi_dev_pm_explicit_set(device, state);
340 if (result)
341 return result;
347 }
348 device->power.state = state;
349 return 0;
350}
351
352int acpi_bus_update_power(acpi_handle handle, int *state_p)
353{
354 struct acpi_device *device;

--- 667 unchanged lines hidden ---
342 }
343 device->power.state = state;
344 return 0;
345}
346
347int acpi_bus_update_power(acpi_handle handle, int *state_p)
348{
349 struct acpi_device *device;

--- 667 unchanged lines hidden ---