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
32 #define _COMPONENT ACPI_POWER_CONTROL
36 /****************************************************************************
38 ****************************************************************************/
40 /****************************************************************************
42 * FUNCTION: bm_get_inferred_power_state
50 ****************************************************************************/
53 bm_get_inferred_power_state (
56 ACPI_STATUS status
= AE_OK
;
57 BM_HANDLE_LIST pr_list
;
58 BM_POWER_STATE list_state
= ACPI_STATE_UNKNOWN
;
59 char object_name
[5] = {'_','P','R','0','\0'};
62 FUNCTION_TRACE("bm_get_inferred_power_state");
65 return_ACPI_STATUS(AE_BAD_PARAMETER
);
68 MEMSET(&pr_list
, 0, sizeof(BM_HANDLE_LIST
));
70 device
->power
.state
= ACPI_STATE_D3
;
73 * Calculate Power State:
74 * ----------------------
75 * Try to infer the devices's power state by checking the state of
76 * the devices's power resources. We start by evaluating _PR0
77 * (resource requirements at D0) and work through _PR1 and _PR2.
78 * We know the current devices power state when all resources (for
79 * a give Dx state) are ON. If no power resources are on then the
80 * device is assumed to be off (D3).
82 for (i
=ACPI_STATE_D0
; i
<ACPI_STATE_D3
; i
++) {
84 status
= bm_evaluate_reference_list(device
->acpi_handle
,
85 object_name
, &pr_list
);
87 if (ACPI_SUCCESS(status
)) {
89 status
= bm_pr_list_get_state(&pr_list
,
92 if (ACPI_SUCCESS(status
)) {
94 if (list_state
== ACPI_STATE_D0
) {
95 device
->power
.state
= i
;
102 return_ACPI_STATUS(AE_OK
);
106 /****************************************************************************
108 ****************************************************************************/
110 /****************************************************************************
112 * FUNCTION: bm_get_power_state
120 ****************************************************************************/
126 ACPI_STATUS status
= AE_OK
;
127 BM_DEVICE
*device
= NULL
;
129 FUNCTION_TRACE("bm_get_power_state");
132 return_ACPI_STATUS(AE_BAD_PARAMETER
);
135 device
= &(node
->device
);
137 device
->power
.state
= ACPI_STATE_UNKNOWN
;
139 if (device
->flags
& BM_FLAGS_POWER_STATE
) {
140 status
= bm_evaluate_simple_integer(device
->acpi_handle
,
141 "_PSC", &(device
->power
.state
));
144 status
= bm_get_inferred_power_state(device
);
147 if (ACPI_SUCCESS(status
)) {
148 DEBUG_PRINT(ACPI_INFO
, ("Device [0x%02x] is at power state [D%d].\n", device
->handle
, device
->power
.state
));
151 DEBUG_PRINT(ACPI_INFO
, ("Error getting power state for device [0x%02x]\n", device
->handle
));
154 return_ACPI_STATUS(status
);
158 /****************************************************************************
160 * FUNCTION: bm_set_power_state
168 ****************************************************************************/
173 BM_POWER_STATE state
)
175 ACPI_STATUS status
= AE_OK
;
176 BM_DEVICE
*device
= NULL
;
177 BM_DEVICE
*parent_device
= NULL
;
178 BM_HANDLE_LIST current_list
;
179 BM_HANDLE_LIST target_list
;
180 char object_name
[5] = {'_','P','R','0','\0'};
182 FUNCTION_TRACE("bm_set_power_state");
184 if (!node
|| !node
->parent
|| (state
> ACPI_STATE_D3
)) {
185 return_ACPI_STATUS(AE_BAD_PARAMETER
);
188 MEMSET(¤t_list
, 0, sizeof(BM_HANDLE_LIST
));
189 MEMSET(&target_list
, 0, sizeof(BM_HANDLE_LIST
));
191 device
= &(node
->device
);
192 parent_device
= &(node
->parent
->device
);
195 * Check Parent's Power State:
196 * ---------------------------
197 * Can't be in a higher power state (lower Dx value) than parent.
199 if (state
< parent_device
->power
.state
) {
200 DEBUG_PRINT(ACPI_WARN
, ("Cannot set device [0x%02x] to a higher-powered state than parent_device.\n", device
->handle
));
201 return_ACPI_STATUS(AE_ERROR
);
207 * Get the power resources associated with the device's current
208 * and target power states.
210 if (device
->power
.state
!= ACPI_STATE_UNKNOWN
) {
211 object_name
[3] = '0' + device
->power
.state
;
212 bm_evaluate_reference_list(device
->acpi_handle
,
213 object_name
, ¤t_list
);
216 object_name
[3] = '0' + state
;
217 bm_evaluate_reference_list(device
->acpi_handle
, object_name
,
221 * Transition Resources:
222 * ---------------------
223 * Transition all power resources referenced by this device to
224 * the correct power state (taking into consideration sequencing
225 * and dependencies to other devices).
227 if (current_list
.count
|| target_list
.count
) {
228 status
= bm_pr_list_transition(¤t_list
, &target_list
);
230 if (ACPI_FAILURE(status
)) {
231 return_ACPI_STATUS(status
);
237 * Execute the _PSx method corresponding to the target Dx state,
240 object_name
[2] = 'S';
241 object_name
[3] = '0' + state
;
242 bm_evaluate_object(device
->acpi_handle
, object_name
, NULL
, NULL
);
244 if (ACPI_SUCCESS(status
)) {
245 DEBUG_PRINT(ACPI_INFO
, ("Device [0x%02x] is now at [D%d].\n", device
->handle
, state
));
246 device
->power
.state
= state
;
249 return_ACPI_STATUS(status
);
253 /****************************************************************************
255 * FUNCTION: bm_get_pm_capabilities
263 ****************************************************************************/
266 bm_get_pm_capabilities (
269 ACPI_STATUS status
= AE_OK
;
270 BM_DEVICE
*device
= NULL
;
271 BM_DEVICE
*parent_device
= NULL
;
272 ACPI_HANDLE acpi_handle
= NULL
;
273 BM_POWER_STATE dx_supported
= ACPI_STATE_UNKNOWN
;
274 char object_name
[5] = {'_','S','0','D','\0'};
277 FUNCTION_TRACE("bm_get_pm_capabilities");
279 if (!node
|| !node
->parent
) {
280 return_ACPI_STATUS(AE_BAD_PARAMETER
);
283 device
= &(node
->device
);
284 parent_device
= &(node
->parent
->device
);
287 * Power Management Flags:
288 * -----------------------
290 if (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PSC",
292 device
->power
.flags
|= BM_FLAGS_POWER_STATE
;
295 if (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_IRC",
297 device
->power
.flags
|= BM_FLAGS_INRUSH_CURRENT
;
300 if (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PRW",
302 device
->power
.flags
|= BM_FLAGS_WAKE_CAPABLE
;
306 * Device Power State:
307 * -------------------
308 * Note that we can't get the device's power state until we've
309 * initialized all power resources, so for now we just set to
312 device
->power
.state
= ACPI_STATE_UNKNOWN
;
315 * Dx Supported in S0:
316 * -------------------
317 * Figure out which Dx states are supported by this device for the
318 * S0 (working) state. Note that D0 and D3 are required (assumed).
320 device
->power
.dx_supported
[ACPI_STATE_S0
] = BM_FLAGS_D0_SUPPORT
|
323 if ((ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PR1",
325 (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PS1",
327 device
->power
.dx_supported
[ACPI_STATE_S0
] |=
331 if ((ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PR2",
333 (ACPI_SUCCESS(acpi_get_handle(device
->acpi_handle
, "_PS2",
335 device
->power
.dx_supported
[ACPI_STATE_S0
] |=
340 * Dx Supported in S1-S5:
341 * ----------------------
342 * Figure out which Dx states are supported by this device for
343 * all other Sx states.
345 for (i
= ACPI_STATE_S1
; i
<= ACPI_STATE_S5
; i
++) {
348 * D3 support is assumed (off is always possible!).
350 device
->power
.dx_supported
[i
] = BM_FLAGS_D3_SUPPORT
;
355 * Which returns the highest (power) Dx state supported in
356 * this system (Sx) state. We convert this value to a bit
357 * mask of supported states (conceptually simpler).
359 status
= bm_evaluate_simple_integer(device
->acpi_handle
,
360 object_name
, &dx_supported
);
361 if (ACPI_SUCCESS(status
)) {
362 switch (dx_supported
) {
364 device
->power
.dx_supported
[i
] |=
368 device
->power
.dx_supported
[i
] |=
372 device
->power
.dx_supported
[i
] |=
376 device
->power
.dx_supported
[i
] |=
384 * Mask of any states that _Sx_d falsely advertises
385 * (e.g.claims D1 support but neither _PR2 or _PS2
386 * exist). In other words, S1-S5 can't offer a Dx
387 * state that isn't supported by S0.
389 device
->power
.dx_supported
[i
] &=
390 device
->power
.dx_supported
[ACPI_STATE_S0
];
396 return_ACPI_STATUS(status
);