1 /*****************************************************************************
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 Andrew Grover
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define _COMPONENT ACPI_POWER_CONTROL
34 /****************************************************************************
36 ****************************************************************************/
38 /****************************************************************************
40 * FUNCTION: bm_get_inferred_power_state
48 ****************************************************************************/
51 bm_get_inferred_power_state (
54 ACPI_STATUS status
= AE_OK
;
55 BM_HANDLE_LIST pr_list
;
56 BM_POWER_STATE list_state
= ACPI_STATE_UNKNOWN
;
57 char object_name
[5] = {'_','P','R','0','\0'};
60 FUNCTION_TRACE("bm_get_inferred_power_state");
63 return_ACPI_STATUS(AE_BAD_PARAMETER
);
66 MEMSET(&pr_list
, 0, sizeof(BM_HANDLE_LIST
));
68 device
->power
.state
= ACPI_STATE_D3
;
71 * Calculate Power State:
72 * ----------------------
73 * Try to infer the devices's power state by checking the state of
74 * the devices's power resources. We start by evaluating _PR0
75 * (resource requirements at D0) and work through _PR1 and _PR2.
76 * We know the current devices power state when all resources (for
77 * a give Dx state) are ON. If no power resources are on then the
78 * device is assumed to be off (D3).
80 for (i
=ACPI_STATE_D0
; i
<ACPI_STATE_D3
; i
++) {
82 status
= bm_evaluate_reference_list(device
->acpi_handle
,
83 object_name
, &pr_list
);
85 if (ACPI_SUCCESS(status
)) {
87 status
= bm_pr_list_get_state(&pr_list
,
90 if (ACPI_SUCCESS(status
)) {
92 if (list_state
== ACPI_STATE_D0
) {
93 device
->power
.state
= i
;
100 return_ACPI_STATUS(AE_OK
);
104 /****************************************************************************
106 ****************************************************************************/
108 /****************************************************************************
110 * FUNCTION: bm_get_power_state
118 ****************************************************************************/
124 ACPI_STATUS status
= AE_OK
;
125 BM_DEVICE
*device
= NULL
;
127 FUNCTION_TRACE("bm_get_power_state");
130 return_ACPI_STATUS(AE_BAD_PARAMETER
);
133 device
= &(node
->device
);
135 device
->power
.state
= ACPI_STATE_UNKNOWN
;
137 if (device
->flags
& BM_FLAGS_POWER_STATE
) {
138 status
= bm_evaluate_simple_integer(device
->acpi_handle
,
139 "_PSC", &(device
->power
.state
));
142 status
= bm_get_inferred_power_state(device
);
145 if (ACPI_SUCCESS(status
)) {
146 DEBUG_PRINT(ACPI_INFO
, ("Device [0x%02x] is at power state [D%d].\n", device
->handle
, device
->power
.state
));
149 DEBUG_PRINT(ACPI_INFO
, ("Error getting power state for device [0x%02x]\n", device
->handle
));
152 return_ACPI_STATUS(status
);
156 /****************************************************************************
158 * FUNCTION: bm_set_power_state
166 ****************************************************************************/
171 BM_POWER_STATE state
)
173 ACPI_STATUS status
= AE_OK
;
174 BM_DEVICE
*device
= NULL
;
175 BM_DEVICE
*parent_device
= NULL
;
176 BM_HANDLE_LIST current_list
;
177 BM_HANDLE_LIST target_list
;
178 char object_name
[5] = {'_','P','R','0','\0'};
180 FUNCTION_TRACE("bm_set_power_state");
182 if (!node
|| !node
->parent
|| (state
> ACPI_STATE_D3
)) {
183 return_ACPI_STATUS(AE_BAD_PARAMETER
);
186 MEMSET(¤t_list
, 0, sizeof(BM_HANDLE_LIST
));
187 MEMSET(&target_list
, 0, sizeof(BM_HANDLE_LIST
));
189 device
= &(node
->device
);
190 parent_device
= &(node
->parent
->device
);
193 * Check Parent's Power State:
194 * ---------------------------
195 * Can't be in a higher power state (lower Dx value) than parent.
197 if (state
< parent_device
->power
.state
) {
198 DEBUG_PRINT(ACPI_WARN
, ("Cannot set device [0x%02x] to a higher-powered state than parent_device.\n", device
->handle
));
199 return_ACPI_STATUS(AE_ERROR
);
205 * Get the power resources associated with the device's current
206 * and target power states.
208 if (device
->power
.state
!= ACPI_STATE_UNKNOWN
) {
209 object_name
[3] = '0' + device
->power
.state
;
210 bm_evaluate_reference_list(device
->acpi_handle
,
211 object_name
, ¤t_list
);
214 object_name
[3] = '0' + state
;
215 bm_evaluate_reference_list(device
->acpi_handle
, object_name
,
219 * Transition Resources:
220 * ---------------------
221 * Transition all power resources referenced by this device to
222 * the correct power state (taking into consideration sequencing
223 * and dependencies to other devices).
225 if (current_list
.count
|| target_list
.count
) {
226 status
= bm_pr_list_transition(¤t_list
, &target_list
);
228 if (ACPI_FAILURE(status
)) {
229 return_ACPI_STATUS(status
);
235 * Execute the _PSx method corresponding to the target Dx state,
238 object_name
[2] = 'S';
239 object_name
[3] = '0' + state
;
240 bm_evaluate_object(device
->acpi_handle
, object_name
, NULL
, NULL
);
242 if (ACPI_SUCCESS(status
)) {
243 DEBUG_PRINT(ACPI_INFO
, ("Device [0x%02x] is now at [D%d].\n", device
->handle
, state
));
244 device
->power
.state
= state
;
247 return_ACPI_STATUS(status
);
251 /****************************************************************************
253 * FUNCTION: bm_get_pm_capabilities
261 ****************************************************************************/
264 bm_get_pm_capabilities (
267 ACPI_STATUS status
= AE_OK
;
268 BM_DEVICE
*device
= NULL
;
269 BM_DEVICE
*parent_device
= NULL
;
270 ACPI_HANDLE acpi_handle
= NULL
;
271 BM_POWER_STATE dx_supported
= ACPI_STATE_UNKNOWN
;
272 char object_name
[5] = {'_','S','0','D','\0'};
275 FUNCTION_TRACE("bm_get_pm_capabilities");
277 if (!node
|| !node
->parent
) {
278 return_ACPI_STATUS(AE_BAD_PARAMETER
);
281 device
= &(node
->device
);
282 parent_device
= &(node
->parent
->device
);
285 * Power Management Flags:
286 * -----------------------
288 if (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PSC",
290 device
->power
.flags
|= BM_FLAGS_POWER_STATE
;
293 if (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_IRC",
295 device
->power
.flags
|= BM_FLAGS_INRUSH_CURRENT
;
298 if (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PRW",
300 device
->power
.flags
|= BM_FLAGS_WAKE_CAPABLE
;
304 * Device Power State:
305 * -------------------
306 * Note that we can't get the device's power state until we've
307 * initialized all power resources, so for now we just set to
310 device
->power
.state
= ACPI_STATE_UNKNOWN
;
313 * Dx Supported in S0:
314 * -------------------
315 * Figure out which Dx states are supported by this device for the
316 * S0 (working) state. Note that D0 and D3 are required (assumed).
318 device
->power
.dx_supported
[ACPI_STATE_S0
] = BM_FLAGS_D0_SUPPORT
|
321 if ((ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PR1",
323 (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PS1",
325 device
->power
.dx_supported
[ACPI_STATE_S0
] |=
329 if ((ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PR2",
331 (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PS2",
333 device
->power
.dx_supported
[ACPI_STATE_S0
] |=
338 * Dx Supported in S1-S5:
339 * ----------------------
340 * Figure out which Dx states are supported by this device for
341 * all other Sx states.
343 for (i
= ACPI_STATE_S1
; i
<= ACPI_STATE_S5
; i
++) {
346 * D3 support is assumed (off is always possible!).
348 device
->power
.dx_supported
[i
] = BM_FLAGS_D3_SUPPORT
;
353 * Which returns the highest (power) Dx state supported in
354 * this system (Sx) state. We convert this value to a bit
355 * mask of supported states (conceptually simpler).
357 status
= bm_evaluate_simple_integer(device
->acpi_handle
,
358 object_name
, &dx_supported
);
359 if (ACPI_SUCCESS(status
)) {
360 switch (dx_supported
) {
362 device
->power
.dx_supported
[i
] |=
366 device
->power
.dx_supported
[i
] |=
370 device
->power
.dx_supported
[i
] |=
374 device
->power
.dx_supported
[i
] |=
382 * Mask of any states that _Sx_d falsely advertises
383 * (e.g.claims D1 support but neither _PR2 or _PS2
384 * exist). In other words, S1-S5 can't offer a Dx
385 * state that isn't supported by S0.
387 device
->power
.dx_supported
[i
] &=
388 device
->power
.dx_supported
[ACPI_STATE_S0
];
394 return_ACPI_STATUS(status
);