aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/device_pm.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-01 20:40:18 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2012-11-14 18:15:16 -0500
commit86b3832c64b6d01092216d84dc6a6b300875d0bb (patch)
tree3d990b5bee64a33159a3cfef7712949176832f6f /drivers/acpi/device_pm.c
parentec2cd81ccfc055155ef4ca673f207168f516d287 (diff)
ACPI / PM: Move device power state selection routine to device_pm.c
The ACPI function for choosing device power state is now located in drivers/acpi/sleep.c, but drivers/acpi/device_pm.c is a more logical place for it, so move it there. However, instead of moving the function entirely, move its core only under a different name and with a different list of arguments, so that it is more flexible, and leave a wrapper around it in the original location. 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.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 2d2e0bc8891b..c017b801171c 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -23,7 +23,9 @@
23 */ 23 */
24 24
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/export.h>
26#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/pm_qos.h>
27 29
28#include <acpi/acpi.h> 30#include <acpi/acpi.h>
29#include <acpi/acpi_bus.h> 31#include <acpi/acpi_bus.h>
@@ -89,3 +91,108 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev,
89 mutex_unlock(&acpi_pm_notifier_lock); 91 mutex_unlock(&acpi_pm_notifier_lock);
90 return status; 92 return status;
91} 93}
94
95/**
96 * acpi_device_power_state - Get preferred power state of ACPI device.
97 * @dev: Device whose preferred target power state to return.
98 * @adev: ACPI device node corresponding to @dev.
99 * @target_state: System state to match the resultant device state.
100 * @d_max_in: Deepest low-power state to take into consideration.
101 * @d_min_p: Location to store the upper limit of the allowed states range.
102 * Return value: Preferred power state of the device on success, -ENODEV
103 * (if there's no 'struct acpi_device' for @dev) or -EINVAL on failure
104 *
105 * Find the lowest power (highest number) ACPI device power state that the
106 * device can be in while the system is in the state represented by
107 * @target_state. If @d_min_p is set, the highest power (lowest number) device
108 * power state that @dev can be in for the given system sleep state is stored
109 * at the location pointed to by it.
110 *
111 * Callers must ensure that @dev and @adev are valid pointers and that @adev
112 * actually corresponds to @dev before using this function.
113 */
114int acpi_device_power_state(struct device *dev, struct acpi_device *adev,
115 u32 target_state, int d_max_in, int *d_min_p)
116{
117 char acpi_method[] = "_SxD";
118 unsigned long long d_min, d_max;
119 bool wakeup = false;
120
121 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
122 return -EINVAL;
123
124 if (d_max_in > ACPI_STATE_D3_HOT) {
125 enum pm_qos_flags_status stat;
126
127 stat = dev_pm_qos_flags(dev, PM_QOS_FLAG_NO_POWER_OFF);
128 if (stat == PM_QOS_FLAGS_ALL)
129 d_max_in = ACPI_STATE_D3_HOT;
130 }
131
132 acpi_method[2] = '0' + target_state;
133 /*
134 * If the sleep state is S0, the lowest limit from ACPI is D3,
135 * but if the device has _S0W, we will use the value from _S0W
136 * as the lowest limit from ACPI. Finally, we will constrain
137 * the lowest limit with the specified one.
138 */
139 d_min = ACPI_STATE_D0;
140 d_max = ACPI_STATE_D3;
141
142 /*
143 * If present, _SxD methods return the minimum D-state (highest power
144 * state) we can use for the corresponding S-states. Otherwise, the
145 * minimum D-state is D0 (ACPI 3.x).
146 *
147 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
148 * provided -- that's our fault recovery, we ignore retval.
149 */
150 if (target_state > ACPI_STATE_S0) {
151 acpi_evaluate_integer(adev->handle, acpi_method, NULL, &d_min);
152 wakeup = device_may_wakeup(dev) && adev->wakeup.flags.valid
153 && adev->wakeup.sleep_state >= target_state;
154 } else if (dev_pm_qos_flags(dev, PM_QOS_FLAG_REMOTE_WAKEUP) !=
155 PM_QOS_FLAGS_NONE) {
156 wakeup = adev->wakeup.flags.valid;
157 }
158
159 /*
160 * If _PRW says we can wake up the system from the target sleep state,
161 * the D-state returned by _SxD is sufficient for that (we assume a
162 * wakeup-aware driver if wake is set). Still, if _SxW exists
163 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
164 * can wake the system. _S0W may be valid, too.
165 */
166 if (wakeup) {
167 acpi_status status;
168
169 acpi_method[3] = 'W';
170 status = acpi_evaluate_integer(adev->handle, acpi_method, NULL,
171 &d_max);
172 if (ACPI_FAILURE(status)) {
173 if (target_state != ACPI_STATE_S0 ||
174 status != AE_NOT_FOUND)
175 d_max = d_min;
176 } else if (d_max < d_min) {
177 /* Warn the user of the broken DSDT */
178 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
179 acpi_method);
180 /* Sanitize it */
181 d_min = d_max;
182 }
183 }
184
185 if (d_max_in < d_min)
186 return -EINVAL;
187 if (d_min_p)
188 *d_min_p = d_min;
189 /* constrain d_max with specified lowest limit (max number) */
190 if (d_max > d_max_in) {
191 for (d_max = d_max_in; d_max > d_min; d_max--) {
192 if (adev->power.states[d_max].flags.valid)
193 break;
194 }
195 }
196 return d_max;
197}
198EXPORT_SYMBOL_GPL(acpi_device_power_state);