Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/base/power/domain.c - Common code related to device power domains. |
| 3 | * |
| 4 | * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp. |
| 5 | * |
| 6 | * This file is released under the GPLv2. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/io.h> |
| 12 | #include <linux/pm_runtime.h> |
| 13 | #include <linux/pm_domain.h> |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 14 | #include <linux/pm_qos.h> |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 15 | #include <linux/slab.h> |
| 16 | #include <linux/err.h> |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 17 | #include <linux/sched.h> |
| 18 | #include <linux/suspend.h> |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 19 | #include <linux/export.h> |
| 20 | |
| 21 | #define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \ |
| 22 | ({ \ |
| 23 | type (*__routine)(struct device *__d); \ |
| 24 | type __ret = (type)0; \ |
| 25 | \ |
| 26 | __routine = genpd->dev_ops.callback; \ |
| 27 | if (__routine) { \ |
| 28 | __ret = __routine(dev); \ |
| 29 | } else { \ |
| 30 | __routine = dev_gpd_data(dev)->ops.callback; \ |
| 31 | if (__routine) \ |
| 32 | __ret = __routine(dev); \ |
| 33 | } \ |
| 34 | __ret; \ |
| 35 | }) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 36 | |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 37 | #define GENPD_DEV_TIMED_CALLBACK(genpd, type, callback, dev, field, name) \ |
| 38 | ({ \ |
| 39 | ktime_t __start = ktime_get(); \ |
| 40 | type __retval = GENPD_DEV_CALLBACK(genpd, type, callback, dev); \ |
| 41 | s64 __elapsed = ktime_to_ns(ktime_sub(ktime_get(), __start)); \ |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 42 | struct gpd_timing_data *__td = &dev_gpd_data(dev)->td; \ |
| 43 | if (!__retval && __elapsed > __td->field) { \ |
| 44 | __td->field = __elapsed; \ |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 45 | dev_warn(dev, name " latency exceeded, new value %lld ns\n", \ |
| 46 | __elapsed); \ |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 47 | genpd->max_off_time_changed = true; \ |
| 48 | __td->constraint_changed = true; \ |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 49 | } \ |
| 50 | __retval; \ |
| 51 | }) |
| 52 | |
Rafael J. Wysocki | 5125bbf | 2011-07-13 12:31:52 +0200 | [diff] [blame] | 53 | static LIST_HEAD(gpd_list); |
| 54 | static DEFINE_MUTEX(gpd_list_lock); |
| 55 | |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 56 | #ifdef CONFIG_PM |
| 57 | |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 58 | struct generic_pm_domain *dev_to_genpd(struct device *dev) |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 59 | { |
| 60 | if (IS_ERR_OR_NULL(dev->pm_domain)) |
| 61 | return ERR_PTR(-EINVAL); |
| 62 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 63 | return pd_to_genpd(dev->pm_domain); |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 64 | } |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 65 | |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 66 | static int genpd_stop_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 67 | { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 68 | return GENPD_DEV_TIMED_CALLBACK(genpd, int, stop, dev, |
| 69 | stop_latency_ns, "stop"); |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 73 | { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 74 | return GENPD_DEV_TIMED_CALLBACK(genpd, int, start, dev, |
| 75 | start_latency_ns, "start"); |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 78 | static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 79 | { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 80 | return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev, |
| 81 | save_state_latency_ns, "state save"); |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static int genpd_restore_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 85 | { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 86 | return GENPD_DEV_TIMED_CALLBACK(genpd, int, restore_state, dev, |
| 87 | restore_state_latency_ns, |
| 88 | "state restore"); |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Rafael J. Wysocki | c4bb316 | 2011-08-08 23:43:04 +0200 | [diff] [blame] | 91 | static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 92 | { |
Rafael J. Wysocki | c4bb316 | 2011-08-08 23:43:04 +0200 | [diff] [blame] | 93 | bool ret = false; |
| 94 | |
| 95 | if (!WARN_ON(atomic_read(&genpd->sd_count) == 0)) |
| 96 | ret = !!atomic_dec_and_test(&genpd->sd_count); |
| 97 | |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | static void genpd_sd_counter_inc(struct generic_pm_domain *genpd) |
| 102 | { |
| 103 | atomic_inc(&genpd->sd_count); |
| 104 | smp_mb__after_atomic_inc(); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 107 | static void genpd_acquire_lock(struct generic_pm_domain *genpd) |
| 108 | { |
| 109 | DEFINE_WAIT(wait); |
| 110 | |
| 111 | mutex_lock(&genpd->lock); |
| 112 | /* |
| 113 | * Wait for the domain to transition into either the active, |
| 114 | * or the power off state. |
| 115 | */ |
| 116 | for (;;) { |
| 117 | prepare_to_wait(&genpd->status_wait_queue, &wait, |
| 118 | TASK_UNINTERRUPTIBLE); |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 119 | if (genpd->status == GPD_STATE_ACTIVE |
| 120 | || genpd->status == GPD_STATE_POWER_OFF) |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 121 | break; |
| 122 | mutex_unlock(&genpd->lock); |
| 123 | |
| 124 | schedule(); |
| 125 | |
| 126 | mutex_lock(&genpd->lock); |
| 127 | } |
| 128 | finish_wait(&genpd->status_wait_queue, &wait); |
| 129 | } |
| 130 | |
| 131 | static void genpd_release_lock(struct generic_pm_domain *genpd) |
| 132 | { |
| 133 | mutex_unlock(&genpd->lock); |
| 134 | } |
| 135 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 136 | static void genpd_set_active(struct generic_pm_domain *genpd) |
| 137 | { |
| 138 | if (genpd->resume_count == 0) |
| 139 | genpd->status = GPD_STATE_ACTIVE; |
| 140 | } |
| 141 | |
Rafael J. Wysocki | cbc9ef0 | 2012-07-03 19:07:42 +0200 | [diff] [blame^] | 142 | static void genpd_recalc_cpu_exit_latency(struct generic_pm_domain *genpd) |
| 143 | { |
| 144 | s64 usecs64; |
| 145 | |
| 146 | if (!genpd->cpu_data) |
| 147 | return; |
| 148 | |
| 149 | usecs64 = genpd->power_on_latency_ns; |
| 150 | do_div(usecs64, NSEC_PER_USEC); |
| 151 | usecs64 += genpd->cpu_data->saved_exit_latency; |
| 152 | genpd->cpu_data->idle_state->exit_latency = usecs64; |
| 153 | } |
| 154 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 155 | /** |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 156 | * __pm_genpd_poweron - Restore power to a given PM domain and its masters. |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 157 | * @genpd: PM domain to power up. |
| 158 | * |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 159 | * Restore power to @genpd and all of its masters so that it is possible to |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 160 | * resume a device belonging to it. |
| 161 | */ |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 162 | int __pm_genpd_poweron(struct generic_pm_domain *genpd) |
| 163 | __releases(&genpd->lock) __acquires(&genpd->lock) |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 164 | { |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 165 | struct gpd_link *link; |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 166 | DEFINE_WAIT(wait); |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 167 | int ret = 0; |
| 168 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 169 | /* If the domain's master is being waited for, we have to wait too. */ |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 170 | for (;;) { |
| 171 | prepare_to_wait(&genpd->status_wait_queue, &wait, |
| 172 | TASK_UNINTERRUPTIBLE); |
Rafael J. Wysocki | 17877eb | 2011-08-08 23:43:50 +0200 | [diff] [blame] | 173 | if (genpd->status != GPD_STATE_WAIT_MASTER) |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 174 | break; |
| 175 | mutex_unlock(&genpd->lock); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 176 | |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 177 | schedule(); |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 178 | |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 179 | mutex_lock(&genpd->lock); |
| 180 | } |
| 181 | finish_wait(&genpd->status_wait_queue, &wait); |
| 182 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 183 | if (genpd->status == GPD_STATE_ACTIVE |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 184 | || (genpd->prepared_count > 0 && genpd->suspend_power_off)) |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 185 | return 0; |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 186 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 187 | if (genpd->status != GPD_STATE_POWER_OFF) { |
| 188 | genpd_set_active(genpd); |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 189 | return 0; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Rafael J. Wysocki | cbc9ef0 | 2012-07-03 19:07:42 +0200 | [diff] [blame^] | 192 | if (genpd->cpu_data) { |
| 193 | cpuidle_pause_and_lock(); |
| 194 | genpd->cpu_data->idle_state->disabled = true; |
| 195 | cpuidle_resume_and_unlock(); |
| 196 | goto out; |
| 197 | } |
| 198 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 199 | /* |
| 200 | * The list is guaranteed not to change while the loop below is being |
| 201 | * executed, unless one of the masters' .power_on() callbacks fiddles |
| 202 | * with it. |
| 203 | */ |
| 204 | list_for_each_entry(link, &genpd->slave_links, slave_node) { |
| 205 | genpd_sd_counter_inc(link->master); |
Rafael J. Wysocki | 17877eb | 2011-08-08 23:43:50 +0200 | [diff] [blame] | 206 | genpd->status = GPD_STATE_WAIT_MASTER; |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 207 | |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 208 | mutex_unlock(&genpd->lock); |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 209 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 210 | ret = pm_genpd_poweron(link->master); |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 211 | |
| 212 | mutex_lock(&genpd->lock); |
| 213 | |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 214 | /* |
| 215 | * The "wait for parent" status is guaranteed not to change |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 216 | * while the master is powering on. |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 217 | */ |
| 218 | genpd->status = GPD_STATE_POWER_OFF; |
| 219 | wake_up_all(&genpd->status_wait_queue); |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 220 | if (ret) { |
| 221 | genpd_sd_counter_dec(link->master); |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 222 | goto err; |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 223 | } |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 226 | if (genpd->power_on) { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 227 | ktime_t time_start = ktime_get(); |
| 228 | s64 elapsed_ns; |
| 229 | |
Rafael J. Wysocki | fe202fd | 2011-08-05 21:45:11 +0200 | [diff] [blame] | 230 | ret = genpd->power_on(genpd); |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 231 | if (ret) |
| 232 | goto err; |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 233 | |
| 234 | elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); |
Rafael J. Wysocki | e84b2c2 | 2011-12-06 22:19:54 +0100 | [diff] [blame] | 235 | if (elapsed_ns > genpd->power_on_latency_ns) { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 236 | genpd->power_on_latency_ns = elapsed_ns; |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 237 | genpd->max_off_time_changed = true; |
Rafael J. Wysocki | cbc9ef0 | 2012-07-03 19:07:42 +0200 | [diff] [blame^] | 238 | genpd_recalc_cpu_exit_latency(genpd); |
Rafael J. Wysocki | e84b2c2 | 2011-12-06 22:19:54 +0100 | [diff] [blame] | 239 | if (genpd->name) |
| 240 | pr_warning("%s: Power-on latency exceeded, " |
| 241 | "new value %lld ns\n", genpd->name, |
| 242 | elapsed_ns); |
| 243 | } |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 244 | } |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 245 | |
Rafael J. Wysocki | cbc9ef0 | 2012-07-03 19:07:42 +0200 | [diff] [blame^] | 246 | out: |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 247 | genpd_set_active(genpd); |
| 248 | |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 249 | return 0; |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 250 | |
| 251 | err: |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 252 | list_for_each_entry_continue_reverse(link, &genpd->slave_links, slave_node) |
| 253 | genpd_sd_counter_dec(link->master); |
Rafael J. Wysocki | 9e08cf4 | 2011-08-08 23:43:22 +0200 | [diff] [blame] | 254 | |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | /** |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 259 | * pm_genpd_poweron - Restore power to a given PM domain and its masters. |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 260 | * @genpd: PM domain to power up. |
| 261 | */ |
| 262 | int pm_genpd_poweron(struct generic_pm_domain *genpd) |
| 263 | { |
| 264 | int ret; |
| 265 | |
| 266 | mutex_lock(&genpd->lock); |
| 267 | ret = __pm_genpd_poweron(genpd); |
| 268 | mutex_unlock(&genpd->lock); |
| 269 | return ret; |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | #endif /* CONFIG_PM */ |
| 273 | |
| 274 | #ifdef CONFIG_PM_RUNTIME |
| 275 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 276 | static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, |
| 277 | unsigned long val, void *ptr) |
| 278 | { |
| 279 | struct generic_pm_domain_data *gpd_data; |
| 280 | struct device *dev; |
| 281 | |
| 282 | gpd_data = container_of(nb, struct generic_pm_domain_data, nb); |
| 283 | |
| 284 | mutex_lock(&gpd_data->lock); |
| 285 | dev = gpd_data->base.dev; |
| 286 | if (!dev) { |
| 287 | mutex_unlock(&gpd_data->lock); |
| 288 | return NOTIFY_DONE; |
| 289 | } |
| 290 | mutex_unlock(&gpd_data->lock); |
| 291 | |
| 292 | for (;;) { |
| 293 | struct generic_pm_domain *genpd; |
| 294 | struct pm_domain_data *pdd; |
| 295 | |
| 296 | spin_lock_irq(&dev->power.lock); |
| 297 | |
| 298 | pdd = dev->power.subsys_data ? |
| 299 | dev->power.subsys_data->domain_data : NULL; |
| 300 | if (pdd) { |
| 301 | to_gpd_data(pdd)->td.constraint_changed = true; |
| 302 | genpd = dev_to_genpd(dev); |
| 303 | } else { |
| 304 | genpd = ERR_PTR(-ENODATA); |
| 305 | } |
| 306 | |
| 307 | spin_unlock_irq(&dev->power.lock); |
| 308 | |
| 309 | if (!IS_ERR(genpd)) { |
| 310 | mutex_lock(&genpd->lock); |
| 311 | genpd->max_off_time_changed = true; |
| 312 | mutex_unlock(&genpd->lock); |
| 313 | } |
| 314 | |
| 315 | dev = dev->parent; |
| 316 | if (!dev || dev->power.ignore_children) |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | return NOTIFY_DONE; |
| 321 | } |
| 322 | |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 323 | /** |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 324 | * __pm_genpd_save_device - Save the pre-suspend state of a device. |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 325 | * @pdd: Domain data of the device to save the state of. |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 326 | * @genpd: PM domain the device belongs to. |
| 327 | */ |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 328 | static int __pm_genpd_save_device(struct pm_domain_data *pdd, |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 329 | struct generic_pm_domain *genpd) |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 330 | __releases(&genpd->lock) __acquires(&genpd->lock) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 331 | { |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 332 | struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 333 | struct device *dev = pdd->dev; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 334 | int ret = 0; |
| 335 | |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 336 | if (gpd_data->need_restore) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 337 | return 0; |
| 338 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 339 | mutex_unlock(&genpd->lock); |
| 340 | |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 341 | genpd_start_dev(genpd, dev); |
| 342 | ret = genpd_save_dev(genpd, dev); |
| 343 | genpd_stop_dev(genpd, dev); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 344 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 345 | mutex_lock(&genpd->lock); |
| 346 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 347 | if (!ret) |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 348 | gpd_data->need_restore = true; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 349 | |
| 350 | return ret; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * __pm_genpd_restore_device - Restore the pre-suspend state of a device. |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 355 | * @pdd: Domain data of the device to restore the state of. |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 356 | * @genpd: PM domain the device belongs to. |
| 357 | */ |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 358 | static void __pm_genpd_restore_device(struct pm_domain_data *pdd, |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 359 | struct generic_pm_domain *genpd) |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 360 | __releases(&genpd->lock) __acquires(&genpd->lock) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 361 | { |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 362 | struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 363 | struct device *dev = pdd->dev; |
Rafael J. Wysocki | 80de3d7 | 2012-06-16 00:02:34 +0200 | [diff] [blame] | 364 | bool need_restore = gpd_data->need_restore; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 365 | |
Rafael J. Wysocki | 80de3d7 | 2012-06-16 00:02:34 +0200 | [diff] [blame] | 366 | gpd_data->need_restore = false; |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 367 | mutex_unlock(&genpd->lock); |
| 368 | |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 369 | genpd_start_dev(genpd, dev); |
Rafael J. Wysocki | 80de3d7 | 2012-06-16 00:02:34 +0200 | [diff] [blame] | 370 | if (need_restore) |
| 371 | genpd_restore_dev(genpd, dev); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 372 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 373 | mutex_lock(&genpd->lock); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /** |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 377 | * genpd_abort_poweroff - Check if a PM domain power off should be aborted. |
| 378 | * @genpd: PM domain to check. |
| 379 | * |
| 380 | * Return true if a PM domain's status changed to GPD_STATE_ACTIVE during |
| 381 | * a "power off" operation, which means that a "power on" has occured in the |
| 382 | * meantime, or if its resume_count field is different from zero, which means |
| 383 | * that one of its devices has been resumed in the meantime. |
| 384 | */ |
| 385 | static bool genpd_abort_poweroff(struct generic_pm_domain *genpd) |
| 386 | { |
Rafael J. Wysocki | 17877eb | 2011-08-08 23:43:50 +0200 | [diff] [blame] | 387 | return genpd->status == GPD_STATE_WAIT_MASTER |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 388 | || genpd->status == GPD_STATE_ACTIVE || genpd->resume_count > 0; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /** |
Rafael J. Wysocki | 56375fd | 2011-07-12 00:40:03 +0200 | [diff] [blame] | 392 | * genpd_queue_power_off_work - Queue up the execution of pm_genpd_poweroff(). |
| 393 | * @genpd: PM domait to power off. |
| 394 | * |
| 395 | * Queue up the execution of pm_genpd_poweroff() unless it's already been done |
| 396 | * before. |
| 397 | */ |
Rafael J. Wysocki | 0bc5b2d | 2011-07-14 20:59:07 +0200 | [diff] [blame] | 398 | void genpd_queue_power_off_work(struct generic_pm_domain *genpd) |
Rafael J. Wysocki | 56375fd | 2011-07-12 00:40:03 +0200 | [diff] [blame] | 399 | { |
| 400 | if (!work_pending(&genpd->power_off_work)) |
| 401 | queue_work(pm_wq, &genpd->power_off_work); |
| 402 | } |
| 403 | |
| 404 | /** |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 405 | * pm_genpd_poweroff - Remove power from a given PM domain. |
| 406 | * @genpd: PM domain to power down. |
| 407 | * |
| 408 | * If all of the @genpd's devices have been suspended and all of its subdomains |
| 409 | * have been powered down, run the runtime suspend callbacks provided by all of |
| 410 | * the @genpd's devices' drivers and remove power from @genpd. |
| 411 | */ |
| 412 | static int pm_genpd_poweroff(struct generic_pm_domain *genpd) |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 413 | __releases(&genpd->lock) __acquires(&genpd->lock) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 414 | { |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 415 | struct pm_domain_data *pdd; |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 416 | struct gpd_link *link; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 417 | unsigned int not_suspended; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 418 | int ret = 0; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 419 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 420 | start: |
| 421 | /* |
| 422 | * Do not try to power off the domain in the following situations: |
| 423 | * (1) The domain is already in the "power off" state. |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 424 | * (2) The domain is waiting for its master to power up. |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 425 | * (3) One of the domain's devices is being resumed right now. |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 426 | * (4) System suspend is in progress. |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 427 | */ |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 428 | if (genpd->status == GPD_STATE_POWER_OFF |
Rafael J. Wysocki | 17877eb | 2011-08-08 23:43:50 +0200 | [diff] [blame] | 429 | || genpd->status == GPD_STATE_WAIT_MASTER |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 430 | || genpd->resume_count > 0 || genpd->prepared_count > 0) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 431 | return 0; |
| 432 | |
Rafael J. Wysocki | c4bb316 | 2011-08-08 23:43:04 +0200 | [diff] [blame] | 433 | if (atomic_read(&genpd->sd_count) > 0) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 434 | return -EBUSY; |
| 435 | |
| 436 | not_suspended = 0; |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 437 | list_for_each_entry(pdd, &genpd->dev_list, list_node) |
Rafael J. Wysocki | 0aa2a22 | 2011-08-25 15:37:04 +0200 | [diff] [blame] | 438 | if (pdd->dev->driver && (!pm_runtime_suspended(pdd->dev) |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 439 | || pdd->dev->power.irq_safe || to_gpd_data(pdd)->always_on)) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 440 | not_suspended++; |
| 441 | |
| 442 | if (not_suspended > genpd->in_progress) |
| 443 | return -EBUSY; |
| 444 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 445 | if (genpd->poweroff_task) { |
| 446 | /* |
| 447 | * Another instance of pm_genpd_poweroff() is executing |
| 448 | * callbacks, so tell it to start over and return. |
| 449 | */ |
| 450 | genpd->status = GPD_STATE_REPEAT; |
| 451 | return 0; |
| 452 | } |
| 453 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 454 | if (genpd->gov && genpd->gov->power_down_ok) { |
| 455 | if (!genpd->gov->power_down_ok(&genpd->domain)) |
| 456 | return -EAGAIN; |
| 457 | } |
| 458 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 459 | genpd->status = GPD_STATE_BUSY; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 460 | genpd->poweroff_task = current; |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 461 | |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 462 | list_for_each_entry_reverse(pdd, &genpd->dev_list, list_node) { |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 463 | ret = atomic_read(&genpd->sd_count) == 0 ? |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 464 | __pm_genpd_save_device(pdd, genpd) : -EBUSY; |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 465 | |
| 466 | if (genpd_abort_poweroff(genpd)) |
| 467 | goto out; |
| 468 | |
Rafael J. Wysocki | 697a7f3 | 2011-07-12 00:39:48 +0200 | [diff] [blame] | 469 | if (ret) { |
| 470 | genpd_set_active(genpd); |
| 471 | goto out; |
| 472 | } |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 473 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 474 | if (genpd->status == GPD_STATE_REPEAT) { |
| 475 | genpd->poweroff_task = NULL; |
| 476 | goto start; |
| 477 | } |
| 478 | } |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 479 | |
Rafael J. Wysocki | cbc9ef0 | 2012-07-03 19:07:42 +0200 | [diff] [blame^] | 480 | if (genpd->cpu_data) { |
| 481 | /* |
| 482 | * If cpu_data is set, cpuidle should turn the domain off when |
| 483 | * the CPU in it is idle. In that case we don't decrement the |
| 484 | * subdomain counts of the master domains, so that power is not |
| 485 | * removed from the current domain prematurely as a result of |
| 486 | * cutting off the masters' power. |
| 487 | */ |
| 488 | genpd->status = GPD_STATE_POWER_OFF; |
| 489 | cpuidle_pause_and_lock(); |
| 490 | genpd->cpu_data->idle_state->disabled = false; |
| 491 | cpuidle_resume_and_unlock(); |
| 492 | goto out; |
| 493 | } |
| 494 | |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 495 | if (genpd->power_off) { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 496 | ktime_t time_start; |
| 497 | s64 elapsed_ns; |
| 498 | |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 499 | if (atomic_read(&genpd->sd_count) > 0) { |
| 500 | ret = -EBUSY; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 501 | goto out; |
| 502 | } |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 503 | |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 504 | time_start = ktime_get(); |
| 505 | |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 506 | /* |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 507 | * If sd_count > 0 at this point, one of the subdomains hasn't |
| 508 | * managed to call pm_genpd_poweron() for the master yet after |
Rafael J. Wysocki | 3c07cbc | 2011-08-08 23:43:14 +0200 | [diff] [blame] | 509 | * incrementing it. In that case pm_genpd_poweron() will wait |
| 510 | * for us to drop the lock, so we can call .power_off() and let |
| 511 | * the pm_genpd_poweron() restore power for us (this shouldn't |
| 512 | * happen very often). |
| 513 | */ |
Rafael J. Wysocki | d280540 | 2011-07-14 20:59:20 +0200 | [diff] [blame] | 514 | ret = genpd->power_off(genpd); |
| 515 | if (ret == -EBUSY) { |
| 516 | genpd_set_active(genpd); |
Rafael J. Wysocki | d280540 | 2011-07-14 20:59:20 +0200 | [diff] [blame] | 517 | goto out; |
| 518 | } |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 519 | |
| 520 | elapsed_ns = ktime_to_ns(ktime_sub(ktime_get(), time_start)); |
Rafael J. Wysocki | e84b2c2 | 2011-12-06 22:19:54 +0100 | [diff] [blame] | 521 | if (elapsed_ns > genpd->power_off_latency_ns) { |
Rafael J. Wysocki | 0140d8b | 2011-12-01 00:02:17 +0100 | [diff] [blame] | 522 | genpd->power_off_latency_ns = elapsed_ns; |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 523 | genpd->max_off_time_changed = true; |
Rafael J. Wysocki | e84b2c2 | 2011-12-06 22:19:54 +0100 | [diff] [blame] | 524 | if (genpd->name) |
| 525 | pr_warning("%s: Power-off latency exceeded, " |
| 526 | "new value %lld ns\n", genpd->name, |
| 527 | elapsed_ns); |
| 528 | } |
Rafael J. Wysocki | d280540 | 2011-07-14 20:59:20 +0200 | [diff] [blame] | 529 | } |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 530 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 531 | genpd->status = GPD_STATE_POWER_OFF; |
Rafael J. Wysocki | 221e9b5 | 2011-12-01 00:02:10 +0100 | [diff] [blame] | 532 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 533 | list_for_each_entry(link, &genpd->slave_links, slave_node) { |
| 534 | genpd_sd_counter_dec(link->master); |
| 535 | genpd_queue_power_off_work(link->master); |
| 536 | } |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 537 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 538 | out: |
| 539 | genpd->poweroff_task = NULL; |
| 540 | wake_up_all(&genpd->status_wait_queue); |
| 541 | return ret; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /** |
| 545 | * genpd_power_off_work_fn - Power off PM domain whose subdomain count is 0. |
| 546 | * @work: Work structure used for scheduling the execution of this function. |
| 547 | */ |
| 548 | static void genpd_power_off_work_fn(struct work_struct *work) |
| 549 | { |
| 550 | struct generic_pm_domain *genpd; |
| 551 | |
| 552 | genpd = container_of(work, struct generic_pm_domain, power_off_work); |
| 553 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 554 | genpd_acquire_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 555 | pm_genpd_poweroff(genpd); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 556 | genpd_release_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /** |
| 560 | * pm_genpd_runtime_suspend - Suspend a device belonging to I/O PM domain. |
| 561 | * @dev: Device to suspend. |
| 562 | * |
| 563 | * Carry out a runtime suspend of a device under the assumption that its |
| 564 | * pm_domain field points to the domain member of an object of type |
| 565 | * struct generic_pm_domain representing a PM domain consisting of I/O devices. |
| 566 | */ |
| 567 | static int pm_genpd_runtime_suspend(struct device *dev) |
| 568 | { |
| 569 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 570 | bool (*stop_ok)(struct device *__dev); |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 571 | int ret; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 572 | |
| 573 | dev_dbg(dev, "%s()\n", __func__); |
| 574 | |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 575 | genpd = dev_to_genpd(dev); |
| 576 | if (IS_ERR(genpd)) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 577 | return -EINVAL; |
| 578 | |
Rafael J. Wysocki | 0aa2a22 | 2011-08-25 15:37:04 +0200 | [diff] [blame] | 579 | might_sleep_if(!genpd->dev_irq_safe); |
| 580 | |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 581 | if (dev_gpd_data(dev)->always_on) |
| 582 | return -EBUSY; |
| 583 | |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 584 | stop_ok = genpd->gov ? genpd->gov->stop_ok : NULL; |
| 585 | if (stop_ok && !stop_ok(dev)) |
| 586 | return -EBUSY; |
| 587 | |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 588 | ret = genpd_stop_dev(genpd, dev); |
| 589 | if (ret) |
| 590 | return ret; |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 591 | |
Rafael J. Wysocki | 0aa2a22 | 2011-08-25 15:37:04 +0200 | [diff] [blame] | 592 | /* |
| 593 | * If power.irq_safe is set, this routine will be run with interrupts |
| 594 | * off, so it can't use mutexes. |
| 595 | */ |
| 596 | if (dev->power.irq_safe) |
| 597 | return 0; |
| 598 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 599 | mutex_lock(&genpd->lock); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 600 | genpd->in_progress++; |
| 601 | pm_genpd_poweroff(genpd); |
| 602 | genpd->in_progress--; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 603 | mutex_unlock(&genpd->lock); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | /** |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 609 | * pm_genpd_runtime_resume - Resume a device belonging to I/O PM domain. |
| 610 | * @dev: Device to resume. |
| 611 | * |
| 612 | * Carry out a runtime resume of a device under the assumption that its |
| 613 | * pm_domain field points to the domain member of an object of type |
| 614 | * struct generic_pm_domain representing a PM domain consisting of I/O devices. |
| 615 | */ |
| 616 | static int pm_genpd_runtime_resume(struct device *dev) |
| 617 | { |
| 618 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 619 | DEFINE_WAIT(wait); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 620 | int ret; |
| 621 | |
| 622 | dev_dbg(dev, "%s()\n", __func__); |
| 623 | |
Rafael J. Wysocki | 5248051 | 2011-07-01 22:13:10 +0200 | [diff] [blame] | 624 | genpd = dev_to_genpd(dev); |
| 625 | if (IS_ERR(genpd)) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 626 | return -EINVAL; |
| 627 | |
Rafael J. Wysocki | 0aa2a22 | 2011-08-25 15:37:04 +0200 | [diff] [blame] | 628 | might_sleep_if(!genpd->dev_irq_safe); |
| 629 | |
| 630 | /* If power.irq_safe, the PM domain is never powered off. */ |
| 631 | if (dev->power.irq_safe) |
Rafael J. Wysocki | 80de3d7 | 2012-06-16 00:02:34 +0200 | [diff] [blame] | 632 | return genpd_start_dev(genpd, dev); |
Rafael J. Wysocki | 0aa2a22 | 2011-08-25 15:37:04 +0200 | [diff] [blame] | 633 | |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 634 | mutex_lock(&genpd->lock); |
Rafael J. Wysocki | 3f24177 | 2011-08-08 23:43:29 +0200 | [diff] [blame] | 635 | ret = __pm_genpd_poweron(genpd); |
| 636 | if (ret) { |
| 637 | mutex_unlock(&genpd->lock); |
| 638 | return ret; |
| 639 | } |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 640 | genpd->status = GPD_STATE_BUSY; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 641 | genpd->resume_count++; |
| 642 | for (;;) { |
| 643 | prepare_to_wait(&genpd->status_wait_queue, &wait, |
| 644 | TASK_UNINTERRUPTIBLE); |
| 645 | /* |
| 646 | * If current is the powering off task, we have been called |
| 647 | * reentrantly from one of the device callbacks, so we should |
| 648 | * not wait. |
| 649 | */ |
| 650 | if (!genpd->poweroff_task || genpd->poweroff_task == current) |
| 651 | break; |
| 652 | mutex_unlock(&genpd->lock); |
| 653 | |
| 654 | schedule(); |
| 655 | |
| 656 | mutex_lock(&genpd->lock); |
| 657 | } |
| 658 | finish_wait(&genpd->status_wait_queue, &wait); |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 659 | __pm_genpd_restore_device(dev->power.subsys_data->domain_data, genpd); |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 660 | genpd->resume_count--; |
| 661 | genpd_set_active(genpd); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 662 | wake_up_all(&genpd->status_wait_queue); |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 663 | mutex_unlock(&genpd->lock); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 664 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 665 | return 0; |
| 666 | } |
| 667 | |
Rafael J. Wysocki | 17f2ae7 | 2011-08-14 13:34:31 +0200 | [diff] [blame] | 668 | /** |
| 669 | * pm_genpd_poweroff_unused - Power off all PM domains with no devices in use. |
| 670 | */ |
| 671 | void pm_genpd_poweroff_unused(void) |
| 672 | { |
| 673 | struct generic_pm_domain *genpd; |
| 674 | |
| 675 | mutex_lock(&gpd_list_lock); |
| 676 | |
| 677 | list_for_each_entry(genpd, &gpd_list, gpd_list_node) |
| 678 | genpd_queue_power_off_work(genpd); |
| 679 | |
| 680 | mutex_unlock(&gpd_list_lock); |
| 681 | } |
| 682 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 683 | #else |
| 684 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 685 | static inline int genpd_dev_pm_qos_notifier(struct notifier_block *nb, |
| 686 | unsigned long val, void *ptr) |
| 687 | { |
| 688 | return NOTIFY_DONE; |
| 689 | } |
| 690 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 691 | static inline void genpd_power_off_work_fn(struct work_struct *work) {} |
| 692 | |
| 693 | #define pm_genpd_runtime_suspend NULL |
| 694 | #define pm_genpd_runtime_resume NULL |
| 695 | |
| 696 | #endif /* CONFIG_PM_RUNTIME */ |
| 697 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 698 | #ifdef CONFIG_PM_SLEEP |
| 699 | |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 700 | static bool genpd_dev_active_wakeup(struct generic_pm_domain *genpd, |
| 701 | struct device *dev) |
| 702 | { |
| 703 | return GENPD_DEV_CALLBACK(genpd, bool, active_wakeup, dev); |
| 704 | } |
| 705 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 706 | static int genpd_suspend_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 707 | { |
| 708 | return GENPD_DEV_CALLBACK(genpd, int, suspend, dev); |
| 709 | } |
| 710 | |
| 711 | static int genpd_suspend_late(struct generic_pm_domain *genpd, struct device *dev) |
| 712 | { |
| 713 | return GENPD_DEV_CALLBACK(genpd, int, suspend_late, dev); |
| 714 | } |
| 715 | |
| 716 | static int genpd_resume_early(struct generic_pm_domain *genpd, struct device *dev) |
| 717 | { |
| 718 | return GENPD_DEV_CALLBACK(genpd, int, resume_early, dev); |
| 719 | } |
| 720 | |
| 721 | static int genpd_resume_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 722 | { |
| 723 | return GENPD_DEV_CALLBACK(genpd, int, resume, dev); |
| 724 | } |
| 725 | |
| 726 | static int genpd_freeze_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 727 | { |
| 728 | return GENPD_DEV_CALLBACK(genpd, int, freeze, dev); |
| 729 | } |
| 730 | |
| 731 | static int genpd_freeze_late(struct generic_pm_domain *genpd, struct device *dev) |
| 732 | { |
| 733 | return GENPD_DEV_CALLBACK(genpd, int, freeze_late, dev); |
| 734 | } |
| 735 | |
| 736 | static int genpd_thaw_early(struct generic_pm_domain *genpd, struct device *dev) |
| 737 | { |
| 738 | return GENPD_DEV_CALLBACK(genpd, int, thaw_early, dev); |
| 739 | } |
| 740 | |
| 741 | static int genpd_thaw_dev(struct generic_pm_domain *genpd, struct device *dev) |
| 742 | { |
| 743 | return GENPD_DEV_CALLBACK(genpd, int, thaw, dev); |
| 744 | } |
| 745 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 746 | /** |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 747 | * pm_genpd_sync_poweroff - Synchronously power off a PM domain and its masters. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 748 | * @genpd: PM domain to power off, if possible. |
| 749 | * |
| 750 | * Check if the given PM domain can be powered off (during system suspend or |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 751 | * hibernation) and do that if so. Also, in that case propagate to its masters. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 752 | * |
| 753 | * This function is only called in "noirq" stages of system power transitions, |
| 754 | * so it need not acquire locks (all of the "noirq" callbacks are executed |
| 755 | * sequentially, so it is guaranteed that it will never run twice in parallel). |
| 756 | */ |
| 757 | static void pm_genpd_sync_poweroff(struct generic_pm_domain *genpd) |
| 758 | { |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 759 | struct gpd_link *link; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 760 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 761 | if (genpd->status == GPD_STATE_POWER_OFF) |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 762 | return; |
| 763 | |
Rafael J. Wysocki | c4bb316 | 2011-08-08 23:43:04 +0200 | [diff] [blame] | 764 | if (genpd->suspended_count != genpd->device_count |
| 765 | || atomic_read(&genpd->sd_count) > 0) |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 766 | return; |
| 767 | |
| 768 | if (genpd->power_off) |
| 769 | genpd->power_off(genpd); |
| 770 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 771 | genpd->status = GPD_STATE_POWER_OFF; |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 772 | |
| 773 | list_for_each_entry(link, &genpd->slave_links, slave_node) { |
| 774 | genpd_sd_counter_dec(link->master); |
| 775 | pm_genpd_sync_poweroff(link->master); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
| 779 | /** |
Rafael J. Wysocki | 4ecd6e6 | 2011-07-12 00:39:57 +0200 | [diff] [blame] | 780 | * resume_needed - Check whether to resume a device before system suspend. |
| 781 | * @dev: Device to check. |
| 782 | * @genpd: PM domain the device belongs to. |
| 783 | * |
| 784 | * There are two cases in which a device that can wake up the system from sleep |
| 785 | * states should be resumed by pm_genpd_prepare(): (1) if the device is enabled |
| 786 | * to wake up the system and it has to remain active for this purpose while the |
| 787 | * system is in the sleep state and (2) if the device is not enabled to wake up |
| 788 | * the system from sleep states and it generally doesn't generate wakeup signals |
| 789 | * by itself (those signals are generated on its behalf by other parts of the |
| 790 | * system). In the latter case it may be necessary to reconfigure the device's |
| 791 | * wakeup settings during system suspend, because it may have been set up to |
| 792 | * signal remote wakeup from the system's working state as needed by runtime PM. |
| 793 | * Return 'true' in either of the above cases. |
| 794 | */ |
| 795 | static bool resume_needed(struct device *dev, struct generic_pm_domain *genpd) |
| 796 | { |
| 797 | bool active_wakeup; |
| 798 | |
| 799 | if (!device_can_wakeup(dev)) |
| 800 | return false; |
| 801 | |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 802 | active_wakeup = genpd_dev_active_wakeup(genpd, dev); |
Rafael J. Wysocki | 4ecd6e6 | 2011-07-12 00:39:57 +0200 | [diff] [blame] | 803 | return device_may_wakeup(dev) ? active_wakeup : !active_wakeup; |
| 804 | } |
| 805 | |
| 806 | /** |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 807 | * pm_genpd_prepare - Start power transition of a device in a PM domain. |
| 808 | * @dev: Device to start the transition of. |
| 809 | * |
| 810 | * Start a power transition of a device (during a system-wide power transition) |
| 811 | * under the assumption that its pm_domain field points to the domain member of |
| 812 | * an object of type struct generic_pm_domain representing a PM domain |
| 813 | * consisting of I/O devices. |
| 814 | */ |
| 815 | static int pm_genpd_prepare(struct device *dev) |
| 816 | { |
| 817 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | b6c10c8 | 2011-07-12 00:39:21 +0200 | [diff] [blame] | 818 | int ret; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 819 | |
| 820 | dev_dbg(dev, "%s()\n", __func__); |
| 821 | |
| 822 | genpd = dev_to_genpd(dev); |
| 823 | if (IS_ERR(genpd)) |
| 824 | return -EINVAL; |
| 825 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 826 | /* |
| 827 | * If a wakeup request is pending for the device, it should be woken up |
| 828 | * at this point and a system wakeup event should be reported if it's |
| 829 | * set up to wake up the system from sleep states. |
| 830 | */ |
| 831 | pm_runtime_get_noresume(dev); |
| 832 | if (pm_runtime_barrier(dev) && device_may_wakeup(dev)) |
| 833 | pm_wakeup_event(dev, 0); |
| 834 | |
| 835 | if (pm_wakeup_pending()) { |
| 836 | pm_runtime_put_sync(dev); |
| 837 | return -EBUSY; |
| 838 | } |
| 839 | |
Rafael J. Wysocki | 4ecd6e6 | 2011-07-12 00:39:57 +0200 | [diff] [blame] | 840 | if (resume_needed(dev, genpd)) |
| 841 | pm_runtime_resume(dev); |
| 842 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 843 | genpd_acquire_lock(genpd); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 844 | |
Rafael J. Wysocki | 65533bb | 2012-03-13 22:39:37 +0100 | [diff] [blame] | 845 | if (genpd->prepared_count++ == 0) { |
| 846 | genpd->suspended_count = 0; |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 847 | genpd->suspend_power_off = genpd->status == GPD_STATE_POWER_OFF; |
Rafael J. Wysocki | 65533bb | 2012-03-13 22:39:37 +0100 | [diff] [blame] | 848 | } |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 849 | |
| 850 | genpd_release_lock(genpd); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 851 | |
| 852 | if (genpd->suspend_power_off) { |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 853 | pm_runtime_put_noidle(dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | /* |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 858 | * The PM domain must be in the GPD_STATE_ACTIVE state at this point, |
| 859 | * so pm_genpd_poweron() will return immediately, but if the device |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 860 | * is suspended (e.g. it's been stopped by genpd_stop_dev()), we need |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 861 | * to make it operational. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 862 | */ |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 863 | pm_runtime_resume(dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 864 | __pm_runtime_disable(dev, false); |
| 865 | |
Rafael J. Wysocki | b6c10c8 | 2011-07-12 00:39:21 +0200 | [diff] [blame] | 866 | ret = pm_generic_prepare(dev); |
| 867 | if (ret) { |
| 868 | mutex_lock(&genpd->lock); |
| 869 | |
| 870 | if (--genpd->prepared_count == 0) |
| 871 | genpd->suspend_power_off = false; |
| 872 | |
| 873 | mutex_unlock(&genpd->lock); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 874 | pm_runtime_enable(dev); |
Rafael J. Wysocki | b6c10c8 | 2011-07-12 00:39:21 +0200 | [diff] [blame] | 875 | } |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 876 | |
| 877 | pm_runtime_put_sync(dev); |
Rafael J. Wysocki | b6c10c8 | 2011-07-12 00:39:21 +0200 | [diff] [blame] | 878 | return ret; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /** |
| 882 | * pm_genpd_suspend - Suspend a device belonging to an I/O PM domain. |
| 883 | * @dev: Device to suspend. |
| 884 | * |
| 885 | * Suspend a device under the assumption that its pm_domain field points to the |
| 886 | * domain member of an object of type struct generic_pm_domain representing |
| 887 | * a PM domain consisting of I/O devices. |
| 888 | */ |
| 889 | static int pm_genpd_suspend(struct device *dev) |
| 890 | { |
| 891 | struct generic_pm_domain *genpd; |
| 892 | |
| 893 | dev_dbg(dev, "%s()\n", __func__); |
| 894 | |
| 895 | genpd = dev_to_genpd(dev); |
| 896 | if (IS_ERR(genpd)) |
| 897 | return -EINVAL; |
| 898 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 899 | return genpd->suspend_power_off ? 0 : genpd_suspend_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 903 | * pm_genpd_suspend_late - Late suspend of a device from an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 904 | * @dev: Device to suspend. |
| 905 | * |
| 906 | * Carry out a late suspend of a device under the assumption that its |
| 907 | * pm_domain field points to the domain member of an object of type |
| 908 | * struct generic_pm_domain representing a PM domain consisting of I/O devices. |
| 909 | */ |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 910 | static int pm_genpd_suspend_late(struct device *dev) |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 911 | { |
| 912 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 913 | |
| 914 | dev_dbg(dev, "%s()\n", __func__); |
| 915 | |
| 916 | genpd = dev_to_genpd(dev); |
| 917 | if (IS_ERR(genpd)) |
| 918 | return -EINVAL; |
| 919 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 920 | return genpd->suspend_power_off ? 0 : genpd_suspend_late(genpd, dev); |
| 921 | } |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 922 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 923 | /** |
| 924 | * pm_genpd_suspend_noirq - Completion of suspend of device in an I/O PM domain. |
| 925 | * @dev: Device to suspend. |
| 926 | * |
| 927 | * Stop the device and remove power from the domain if all devices in it have |
| 928 | * been stopped. |
| 929 | */ |
| 930 | static int pm_genpd_suspend_noirq(struct device *dev) |
| 931 | { |
| 932 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 933 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 934 | dev_dbg(dev, "%s()\n", __func__); |
| 935 | |
| 936 | genpd = dev_to_genpd(dev); |
| 937 | if (IS_ERR(genpd)) |
| 938 | return -EINVAL; |
| 939 | |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 940 | if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 941 | || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) |
Rafael J. Wysocki | d4f2d87 | 2011-07-01 22:13:29 +0200 | [diff] [blame] | 942 | return 0; |
| 943 | |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 944 | genpd_stop_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 945 | |
| 946 | /* |
| 947 | * Since all of the "noirq" callbacks are executed sequentially, it is |
| 948 | * guaranteed that this function will never run twice in parallel for |
| 949 | * the same PM domain, so it is not necessary to use locking here. |
| 950 | */ |
| 951 | genpd->suspended_count++; |
| 952 | pm_genpd_sync_poweroff(genpd); |
| 953 | |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 958 | * pm_genpd_resume_noirq - Start of resume of device in an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 959 | * @dev: Device to resume. |
| 960 | * |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 961 | * Restore power to the device's PM domain, if necessary, and start the device. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 962 | */ |
| 963 | static int pm_genpd_resume_noirq(struct device *dev) |
| 964 | { |
| 965 | struct generic_pm_domain *genpd; |
| 966 | |
| 967 | dev_dbg(dev, "%s()\n", __func__); |
| 968 | |
| 969 | genpd = dev_to_genpd(dev); |
| 970 | if (IS_ERR(genpd)) |
| 971 | return -EINVAL; |
| 972 | |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 973 | if (genpd->suspend_power_off || dev_gpd_data(dev)->always_on |
Rafael J. Wysocki | cc85b20 | 2012-03-13 22:39:31 +0100 | [diff] [blame] | 974 | || (dev->power.wakeup_path && genpd_dev_active_wakeup(genpd, dev))) |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 975 | return 0; |
| 976 | |
| 977 | /* |
| 978 | * Since all of the "noirq" callbacks are executed sequentially, it is |
| 979 | * guaranteed that this function will never run twice in parallel for |
| 980 | * the same PM domain, so it is not necessary to use locking here. |
| 981 | */ |
| 982 | pm_genpd_poweron(genpd); |
| 983 | genpd->suspended_count--; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 984 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 985 | return genpd_start_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 989 | * pm_genpd_resume_early - Early resume of a device in an I/O PM domain. |
| 990 | * @dev: Device to resume. |
| 991 | * |
| 992 | * Carry out an early resume of a device under the assumption that its |
| 993 | * pm_domain field points to the domain member of an object of type |
| 994 | * struct generic_pm_domain representing a power domain consisting of I/O |
| 995 | * devices. |
| 996 | */ |
| 997 | static int pm_genpd_resume_early(struct device *dev) |
| 998 | { |
| 999 | struct generic_pm_domain *genpd; |
| 1000 | |
| 1001 | dev_dbg(dev, "%s()\n", __func__); |
| 1002 | |
| 1003 | genpd = dev_to_genpd(dev); |
| 1004 | if (IS_ERR(genpd)) |
| 1005 | return -EINVAL; |
| 1006 | |
| 1007 | return genpd->suspend_power_off ? 0 : genpd_resume_early(genpd, dev); |
| 1008 | } |
| 1009 | |
| 1010 | /** |
| 1011 | * pm_genpd_resume - Resume of device in an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1012 | * @dev: Device to resume. |
| 1013 | * |
| 1014 | * Resume a device under the assumption that its pm_domain field points to the |
| 1015 | * domain member of an object of type struct generic_pm_domain representing |
| 1016 | * a power domain consisting of I/O devices. |
| 1017 | */ |
| 1018 | static int pm_genpd_resume(struct device *dev) |
| 1019 | { |
| 1020 | struct generic_pm_domain *genpd; |
| 1021 | |
| 1022 | dev_dbg(dev, "%s()\n", __func__); |
| 1023 | |
| 1024 | genpd = dev_to_genpd(dev); |
| 1025 | if (IS_ERR(genpd)) |
| 1026 | return -EINVAL; |
| 1027 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1028 | return genpd->suspend_power_off ? 0 : genpd_resume_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1032 | * pm_genpd_freeze - Freezing a device in an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1033 | * @dev: Device to freeze. |
| 1034 | * |
| 1035 | * Freeze a device under the assumption that its pm_domain field points to the |
| 1036 | * domain member of an object of type struct generic_pm_domain representing |
| 1037 | * a power domain consisting of I/O devices. |
| 1038 | */ |
| 1039 | static int pm_genpd_freeze(struct device *dev) |
| 1040 | { |
| 1041 | struct generic_pm_domain *genpd; |
| 1042 | |
| 1043 | dev_dbg(dev, "%s()\n", __func__); |
| 1044 | |
| 1045 | genpd = dev_to_genpd(dev); |
| 1046 | if (IS_ERR(genpd)) |
| 1047 | return -EINVAL; |
| 1048 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1049 | return genpd->suspend_power_off ? 0 : genpd_freeze_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1053 | * pm_genpd_freeze_late - Late freeze of a device in an I/O PM domain. |
| 1054 | * @dev: Device to freeze. |
| 1055 | * |
| 1056 | * Carry out a late freeze of a device under the assumption that its |
| 1057 | * pm_domain field points to the domain member of an object of type |
| 1058 | * struct generic_pm_domain representing a power domain consisting of I/O |
| 1059 | * devices. |
| 1060 | */ |
| 1061 | static int pm_genpd_freeze_late(struct device *dev) |
| 1062 | { |
| 1063 | struct generic_pm_domain *genpd; |
| 1064 | |
| 1065 | dev_dbg(dev, "%s()\n", __func__); |
| 1066 | |
| 1067 | genpd = dev_to_genpd(dev); |
| 1068 | if (IS_ERR(genpd)) |
| 1069 | return -EINVAL; |
| 1070 | |
| 1071 | return genpd->suspend_power_off ? 0 : genpd_freeze_late(genpd, dev); |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * pm_genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1076 | * @dev: Device to freeze. |
| 1077 | * |
| 1078 | * Carry out a late freeze of a device under the assumption that its |
| 1079 | * pm_domain field points to the domain member of an object of type |
| 1080 | * struct generic_pm_domain representing a power domain consisting of I/O |
| 1081 | * devices. |
| 1082 | */ |
| 1083 | static int pm_genpd_freeze_noirq(struct device *dev) |
| 1084 | { |
| 1085 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1086 | |
| 1087 | dev_dbg(dev, "%s()\n", __func__); |
| 1088 | |
| 1089 | genpd = dev_to_genpd(dev); |
| 1090 | if (IS_ERR(genpd)) |
| 1091 | return -EINVAL; |
| 1092 | |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 1093 | return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ? |
| 1094 | 0 : genpd_stop_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1098 | * pm_genpd_thaw_noirq - Early thaw of device in an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1099 | * @dev: Device to thaw. |
| 1100 | * |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1101 | * Start the device, unless power has been removed from the domain already |
| 1102 | * before the system transition. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1103 | */ |
| 1104 | static int pm_genpd_thaw_noirq(struct device *dev) |
| 1105 | { |
| 1106 | struct generic_pm_domain *genpd; |
| 1107 | |
| 1108 | dev_dbg(dev, "%s()\n", __func__); |
| 1109 | |
| 1110 | genpd = dev_to_genpd(dev); |
| 1111 | if (IS_ERR(genpd)) |
| 1112 | return -EINVAL; |
| 1113 | |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 1114 | return genpd->suspend_power_off || dev_gpd_data(dev)->always_on ? |
| 1115 | 0 : genpd_start_dev(genpd, dev); |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1116 | } |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1117 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1118 | /** |
| 1119 | * pm_genpd_thaw_early - Early thaw of device in an I/O PM domain. |
| 1120 | * @dev: Device to thaw. |
| 1121 | * |
| 1122 | * Carry out an early thaw of a device under the assumption that its |
| 1123 | * pm_domain field points to the domain member of an object of type |
| 1124 | * struct generic_pm_domain representing a power domain consisting of I/O |
| 1125 | * devices. |
| 1126 | */ |
| 1127 | static int pm_genpd_thaw_early(struct device *dev) |
| 1128 | { |
| 1129 | struct generic_pm_domain *genpd; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1130 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1131 | dev_dbg(dev, "%s()\n", __func__); |
| 1132 | |
| 1133 | genpd = dev_to_genpd(dev); |
| 1134 | if (IS_ERR(genpd)) |
| 1135 | return -EINVAL; |
| 1136 | |
| 1137 | return genpd->suspend_power_off ? 0 : genpd_thaw_early(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
| 1141 | * pm_genpd_thaw - Thaw a device belonging to an I/O power domain. |
| 1142 | * @dev: Device to thaw. |
| 1143 | * |
| 1144 | * Thaw a device under the assumption that its pm_domain field points to the |
| 1145 | * domain member of an object of type struct generic_pm_domain representing |
| 1146 | * a power domain consisting of I/O devices. |
| 1147 | */ |
| 1148 | static int pm_genpd_thaw(struct device *dev) |
| 1149 | { |
| 1150 | struct generic_pm_domain *genpd; |
| 1151 | |
| 1152 | dev_dbg(dev, "%s()\n", __func__); |
| 1153 | |
| 1154 | genpd = dev_to_genpd(dev); |
| 1155 | if (IS_ERR(genpd)) |
| 1156 | return -EINVAL; |
| 1157 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1158 | return genpd->suspend_power_off ? 0 : genpd_thaw_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /** |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1162 | * pm_genpd_restore_noirq - Start of restore of device in an I/O PM domain. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1163 | * @dev: Device to resume. |
| 1164 | * |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1165 | * Make sure the domain will be in the same power state as before the |
| 1166 | * hibernation the system is resuming from and start the device if necessary. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1167 | */ |
| 1168 | static int pm_genpd_restore_noirq(struct device *dev) |
| 1169 | { |
| 1170 | struct generic_pm_domain *genpd; |
| 1171 | |
| 1172 | dev_dbg(dev, "%s()\n", __func__); |
| 1173 | |
| 1174 | genpd = dev_to_genpd(dev); |
| 1175 | if (IS_ERR(genpd)) |
| 1176 | return -EINVAL; |
| 1177 | |
| 1178 | /* |
| 1179 | * Since all of the "noirq" callbacks are executed sequentially, it is |
| 1180 | * guaranteed that this function will never run twice in parallel for |
| 1181 | * the same PM domain, so it is not necessary to use locking here. |
Rafael J. Wysocki | 65533bb | 2012-03-13 22:39:37 +0100 | [diff] [blame] | 1182 | * |
| 1183 | * At this point suspended_count == 0 means we are being run for the |
| 1184 | * first time for the given domain in the present cycle. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1185 | */ |
Rafael J. Wysocki | 65533bb | 2012-03-13 22:39:37 +0100 | [diff] [blame] | 1186 | if (genpd->suspended_count++ == 0) { |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1187 | /* |
Rafael J. Wysocki | 65533bb | 2012-03-13 22:39:37 +0100 | [diff] [blame] | 1188 | * The boot kernel might put the domain into arbitrary state, |
| 1189 | * so make it appear as powered off to pm_genpd_poweron(), so |
| 1190 | * that it tries to power it on in case it was really off. |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1191 | */ |
Rafael J. Wysocki | 65533bb | 2012-03-13 22:39:37 +0100 | [diff] [blame] | 1192 | genpd->status = GPD_STATE_POWER_OFF; |
| 1193 | if (genpd->suspend_power_off) { |
| 1194 | /* |
| 1195 | * If the domain was off before the hibernation, make |
| 1196 | * sure it will be off going forward. |
| 1197 | */ |
| 1198 | if (genpd->power_off) |
| 1199 | genpd->power_off(genpd); |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1203 | } |
| 1204 | |
Rafael J. Wysocki | 18dd2ec | 2012-03-19 10:38:14 +0100 | [diff] [blame] | 1205 | if (genpd->suspend_power_off) |
| 1206 | return 0; |
| 1207 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1208 | pm_genpd_poweron(genpd); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1209 | |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 1210 | return dev_gpd_data(dev)->always_on ? 0 : genpd_start_dev(genpd, dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * pm_genpd_complete - Complete power transition of a device in a power domain. |
| 1215 | * @dev: Device to complete the transition of. |
| 1216 | * |
| 1217 | * Complete a power transition of a device (during a system-wide power |
| 1218 | * transition) under the assumption that its pm_domain field points to the |
| 1219 | * domain member of an object of type struct generic_pm_domain representing |
| 1220 | * a power domain consisting of I/O devices. |
| 1221 | */ |
| 1222 | static void pm_genpd_complete(struct device *dev) |
| 1223 | { |
| 1224 | struct generic_pm_domain *genpd; |
| 1225 | bool run_complete; |
| 1226 | |
| 1227 | dev_dbg(dev, "%s()\n", __func__); |
| 1228 | |
| 1229 | genpd = dev_to_genpd(dev); |
| 1230 | if (IS_ERR(genpd)) |
| 1231 | return; |
| 1232 | |
| 1233 | mutex_lock(&genpd->lock); |
| 1234 | |
| 1235 | run_complete = !genpd->suspend_power_off; |
| 1236 | if (--genpd->prepared_count == 0) |
| 1237 | genpd->suspend_power_off = false; |
| 1238 | |
| 1239 | mutex_unlock(&genpd->lock); |
| 1240 | |
| 1241 | if (run_complete) { |
| 1242 | pm_generic_complete(dev); |
Rafael J. Wysocki | 6f00ff7 | 2011-07-12 00:39:10 +0200 | [diff] [blame] | 1243 | pm_runtime_set_active(dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1244 | pm_runtime_enable(dev); |
Rafael J. Wysocki | 6f00ff7 | 2011-07-12 00:39:10 +0200 | [diff] [blame] | 1245 | pm_runtime_idle(dev); |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | #else |
| 1250 | |
| 1251 | #define pm_genpd_prepare NULL |
| 1252 | #define pm_genpd_suspend NULL |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1253 | #define pm_genpd_suspend_late NULL |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1254 | #define pm_genpd_suspend_noirq NULL |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1255 | #define pm_genpd_resume_early NULL |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1256 | #define pm_genpd_resume_noirq NULL |
| 1257 | #define pm_genpd_resume NULL |
| 1258 | #define pm_genpd_freeze NULL |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1259 | #define pm_genpd_freeze_late NULL |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1260 | #define pm_genpd_freeze_noirq NULL |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1261 | #define pm_genpd_thaw_early NULL |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1262 | #define pm_genpd_thaw_noirq NULL |
| 1263 | #define pm_genpd_thaw NULL |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1264 | #define pm_genpd_restore_noirq NULL |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1265 | #define pm_genpd_complete NULL |
| 1266 | |
| 1267 | #endif /* CONFIG_PM_SLEEP */ |
| 1268 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1269 | /** |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1270 | * __pm_genpd_add_device - Add a device to an I/O PM domain. |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1271 | * @genpd: PM domain to add the device to. |
| 1272 | * @dev: Device to be added. |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1273 | * @td: Set of PM QoS timing parameters to attach to the device. |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1274 | */ |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1275 | int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, |
| 1276 | struct gpd_timing_data *td) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1277 | { |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 1278 | struct generic_pm_domain_data *gpd_data; |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 1279 | struct pm_domain_data *pdd; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1280 | int ret = 0; |
| 1281 | |
| 1282 | dev_dbg(dev, "%s()\n", __func__); |
| 1283 | |
| 1284 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)) |
| 1285 | return -EINVAL; |
| 1286 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1287 | gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL); |
| 1288 | if (!gpd_data) |
| 1289 | return -ENOMEM; |
| 1290 | |
| 1291 | mutex_init(&gpd_data->lock); |
| 1292 | gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; |
| 1293 | dev_pm_qos_add_notifier(dev, &gpd_data->nb); |
| 1294 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1295 | genpd_acquire_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1296 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1297 | if (genpd->prepared_count > 0) { |
| 1298 | ret = -EAGAIN; |
| 1299 | goto out; |
| 1300 | } |
| 1301 | |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 1302 | list_for_each_entry(pdd, &genpd->dev_list, list_node) |
| 1303 | if (pdd->dev == dev) { |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1304 | ret = -EINVAL; |
| 1305 | goto out; |
| 1306 | } |
| 1307 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1308 | genpd->device_count++; |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1309 | genpd->max_off_time_changed = true; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1310 | |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 1311 | dev_pm_get_subsys_data(dev); |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1312 | |
| 1313 | mutex_lock(&gpd_data->lock); |
| 1314 | spin_lock_irq(&dev->power.lock); |
| 1315 | dev->pm_domain = &genpd->domain; |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 1316 | dev->power.subsys_data->domain_data = &gpd_data->base; |
| 1317 | gpd_data->base.dev = dev; |
Rafael J. Wysocki | cd0ea67 | 2011-09-26 20:22:02 +0200 | [diff] [blame] | 1318 | list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); |
Rafael J. Wysocki | ca1d72f | 2012-05-14 21:45:52 +0200 | [diff] [blame] | 1319 | gpd_data->need_restore = genpd->status == GPD_STATE_POWER_OFF; |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1320 | if (td) |
| 1321 | gpd_data->td = *td; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1322 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1323 | gpd_data->td.constraint_changed = true; |
| 1324 | gpd_data->td.effective_constraint_ns = -1; |
| 1325 | spin_unlock_irq(&dev->power.lock); |
| 1326 | mutex_unlock(&gpd_data->lock); |
| 1327 | |
| 1328 | genpd_release_lock(genpd); |
| 1329 | |
| 1330 | return 0; |
| 1331 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1332 | out: |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1333 | genpd_release_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1334 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1335 | dev_pm_qos_remove_notifier(dev, &gpd_data->nb); |
| 1336 | kfree(gpd_data); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1337 | return ret; |
| 1338 | } |
| 1339 | |
| 1340 | /** |
Thomas Abraham | c8aa130 | 2012-01-27 15:22:07 +0900 | [diff] [blame] | 1341 | * __pm_genpd_of_add_device - Add a device to an I/O PM domain. |
| 1342 | * @genpd_node: Device tree node pointer representing a PM domain to which the |
| 1343 | * the device is added to. |
| 1344 | * @dev: Device to be added. |
| 1345 | * @td: Set of PM QoS timing parameters to attach to the device. |
| 1346 | */ |
| 1347 | int __pm_genpd_of_add_device(struct device_node *genpd_node, struct device *dev, |
| 1348 | struct gpd_timing_data *td) |
| 1349 | { |
| 1350 | struct generic_pm_domain *genpd = NULL, *gpd; |
| 1351 | |
| 1352 | dev_dbg(dev, "%s()\n", __func__); |
| 1353 | |
| 1354 | if (IS_ERR_OR_NULL(genpd_node) || IS_ERR_OR_NULL(dev)) |
| 1355 | return -EINVAL; |
| 1356 | |
| 1357 | mutex_lock(&gpd_list_lock); |
| 1358 | list_for_each_entry(gpd, &gpd_list, gpd_list_node) { |
| 1359 | if (gpd->of_node == genpd_node) { |
| 1360 | genpd = gpd; |
| 1361 | break; |
| 1362 | } |
| 1363 | } |
| 1364 | mutex_unlock(&gpd_list_lock); |
| 1365 | |
| 1366 | if (!genpd) |
| 1367 | return -EINVAL; |
| 1368 | |
| 1369 | return __pm_genpd_add_device(genpd, dev, td); |
| 1370 | } |
| 1371 | |
| 1372 | /** |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1373 | * pm_genpd_remove_device - Remove a device from an I/O PM domain. |
| 1374 | * @genpd: PM domain to remove the device from. |
| 1375 | * @dev: Device to be removed. |
| 1376 | */ |
| 1377 | int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
| 1378 | struct device *dev) |
| 1379 | { |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1380 | struct generic_pm_domain_data *gpd_data; |
Rafael J. Wysocki | 4605ab6 | 2011-08-25 15:34:12 +0200 | [diff] [blame] | 1381 | struct pm_domain_data *pdd; |
Rafael J. Wysocki | efa6902 | 2012-05-01 21:33:53 +0200 | [diff] [blame] | 1382 | int ret = 0; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1383 | |
| 1384 | dev_dbg(dev, "%s()\n", __func__); |
| 1385 | |
Rafael J. Wysocki | efa6902 | 2012-05-01 21:33:53 +0200 | [diff] [blame] | 1386 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev) |
| 1387 | || IS_ERR_OR_NULL(dev->pm_domain) |
| 1388 | || pd_to_genpd(dev->pm_domain) != genpd) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1389 | return -EINVAL; |
| 1390 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1391 | genpd_acquire_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1392 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1393 | if (genpd->prepared_count > 0) { |
| 1394 | ret = -EAGAIN; |
| 1395 | goto out; |
| 1396 | } |
| 1397 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1398 | genpd->device_count--; |
| 1399 | genpd->max_off_time_changed = true; |
| 1400 | |
| 1401 | spin_lock_irq(&dev->power.lock); |
Rafael J. Wysocki | efa6902 | 2012-05-01 21:33:53 +0200 | [diff] [blame] | 1402 | dev->pm_domain = NULL; |
| 1403 | pdd = dev->power.subsys_data->domain_data; |
| 1404 | list_del_init(&pdd->list_node); |
| 1405 | dev->power.subsys_data->domain_data = NULL; |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1406 | spin_unlock_irq(&dev->power.lock); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1407 | |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1408 | gpd_data = to_gpd_data(pdd); |
| 1409 | mutex_lock(&gpd_data->lock); |
| 1410 | pdd->dev = NULL; |
| 1411 | mutex_unlock(&gpd_data->lock); |
| 1412 | |
| 1413 | genpd_release_lock(genpd); |
| 1414 | |
| 1415 | dev_pm_qos_remove_notifier(dev, &gpd_data->nb); |
| 1416 | kfree(gpd_data); |
| 1417 | dev_pm_put_subsys_data(dev); |
| 1418 | return 0; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1419 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1420 | out: |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1421 | genpd_release_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1422 | |
| 1423 | return ret; |
| 1424 | } |
| 1425 | |
| 1426 | /** |
Rafael J. Wysocki | 1e78a0c | 2012-03-13 22:39:48 +0100 | [diff] [blame] | 1427 | * pm_genpd_dev_always_on - Set/unset the "always on" flag for a given device. |
| 1428 | * @dev: Device to set/unset the flag for. |
| 1429 | * @val: The new value of the device's "always on" flag. |
| 1430 | */ |
| 1431 | void pm_genpd_dev_always_on(struct device *dev, bool val) |
| 1432 | { |
| 1433 | struct pm_subsys_data *psd; |
| 1434 | unsigned long flags; |
| 1435 | |
| 1436 | spin_lock_irqsave(&dev->power.lock, flags); |
| 1437 | |
| 1438 | psd = dev_to_psd(dev); |
| 1439 | if (psd && psd->domain_data) |
| 1440 | to_gpd_data(psd->domain_data)->always_on = val; |
| 1441 | |
| 1442 | spin_unlock_irqrestore(&dev->power.lock, flags); |
| 1443 | } |
| 1444 | EXPORT_SYMBOL_GPL(pm_genpd_dev_always_on); |
| 1445 | |
| 1446 | /** |
Rafael J. Wysocki | ca1d72f | 2012-05-14 21:45:52 +0200 | [diff] [blame] | 1447 | * pm_genpd_dev_need_restore - Set/unset the device's "need restore" flag. |
| 1448 | * @dev: Device to set/unset the flag for. |
| 1449 | * @val: The new value of the device's "need restore" flag. |
| 1450 | */ |
| 1451 | void pm_genpd_dev_need_restore(struct device *dev, bool val) |
| 1452 | { |
| 1453 | struct pm_subsys_data *psd; |
| 1454 | unsigned long flags; |
| 1455 | |
| 1456 | spin_lock_irqsave(&dev->power.lock, flags); |
| 1457 | |
| 1458 | psd = dev_to_psd(dev); |
| 1459 | if (psd && psd->domain_data) |
| 1460 | to_gpd_data(psd->domain_data)->need_restore = val; |
| 1461 | |
| 1462 | spin_unlock_irqrestore(&dev->power.lock, flags); |
| 1463 | } |
| 1464 | EXPORT_SYMBOL_GPL(pm_genpd_dev_need_restore); |
| 1465 | |
| 1466 | /** |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1467 | * pm_genpd_add_subdomain - Add a subdomain to an I/O PM domain. |
| 1468 | * @genpd: Master PM domain to add the subdomain to. |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1469 | * @subdomain: Subdomain to be added. |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1470 | */ |
| 1471 | int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1472 | struct generic_pm_domain *subdomain) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1473 | { |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1474 | struct gpd_link *link; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1475 | int ret = 0; |
| 1476 | |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1477 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1478 | return -EINVAL; |
| 1479 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1480 | start: |
| 1481 | genpd_acquire_lock(genpd); |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1482 | mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1483 | |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1484 | if (subdomain->status != GPD_STATE_POWER_OFF |
| 1485 | && subdomain->status != GPD_STATE_ACTIVE) { |
| 1486 | mutex_unlock(&subdomain->lock); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1487 | genpd_release_lock(genpd); |
| 1488 | goto start; |
| 1489 | } |
| 1490 | |
| 1491 | if (genpd->status == GPD_STATE_POWER_OFF |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1492 | && subdomain->status != GPD_STATE_POWER_OFF) { |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1493 | ret = -EINVAL; |
| 1494 | goto out; |
| 1495 | } |
| 1496 | |
Huang Ying | 4fcac10 | 2012-05-07 21:35:45 +0200 | [diff] [blame] | 1497 | list_for_each_entry(link, &genpd->master_links, master_node) { |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1498 | if (link->slave == subdomain && link->master == genpd) { |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1499 | ret = -EINVAL; |
| 1500 | goto out; |
| 1501 | } |
| 1502 | } |
| 1503 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1504 | link = kzalloc(sizeof(*link), GFP_KERNEL); |
| 1505 | if (!link) { |
| 1506 | ret = -ENOMEM; |
| 1507 | goto out; |
| 1508 | } |
| 1509 | link->master = genpd; |
| 1510 | list_add_tail(&link->master_node, &genpd->master_links); |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1511 | link->slave = subdomain; |
| 1512 | list_add_tail(&link->slave_node, &subdomain->slave_links); |
| 1513 | if (subdomain->status != GPD_STATE_POWER_OFF) |
Rafael J. Wysocki | c4bb316 | 2011-08-08 23:43:04 +0200 | [diff] [blame] | 1514 | genpd_sd_counter_inc(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1515 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1516 | out: |
Rafael J. Wysocki | bc0403f | 2011-08-08 23:43:59 +0200 | [diff] [blame] | 1517 | mutex_unlock(&subdomain->lock); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1518 | genpd_release_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1519 | |
| 1520 | return ret; |
| 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * pm_genpd_remove_subdomain - Remove a subdomain from an I/O PM domain. |
| 1525 | * @genpd: Master PM domain to remove the subdomain from. |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1526 | * @subdomain: Subdomain to be removed. |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1527 | */ |
| 1528 | int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1529 | struct generic_pm_domain *subdomain) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1530 | { |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1531 | struct gpd_link *link; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1532 | int ret = -EINVAL; |
| 1533 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1534 | if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(subdomain)) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1535 | return -EINVAL; |
| 1536 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1537 | start: |
| 1538 | genpd_acquire_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1539 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1540 | list_for_each_entry(link, &genpd->master_links, master_node) { |
| 1541 | if (link->slave != subdomain) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1542 | continue; |
| 1543 | |
| 1544 | mutex_lock_nested(&subdomain->lock, SINGLE_DEPTH_NESTING); |
| 1545 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1546 | if (subdomain->status != GPD_STATE_POWER_OFF |
| 1547 | && subdomain->status != GPD_STATE_ACTIVE) { |
| 1548 | mutex_unlock(&subdomain->lock); |
| 1549 | genpd_release_lock(genpd); |
| 1550 | goto start; |
| 1551 | } |
| 1552 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1553 | list_del(&link->master_node); |
| 1554 | list_del(&link->slave_node); |
| 1555 | kfree(link); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1556 | if (subdomain->status != GPD_STATE_POWER_OFF) |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1557 | genpd_sd_counter_dec(genpd); |
| 1558 | |
| 1559 | mutex_unlock(&subdomain->lock); |
| 1560 | |
| 1561 | ret = 0; |
| 1562 | break; |
| 1563 | } |
| 1564 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1565 | genpd_release_lock(genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1566 | |
| 1567 | return ret; |
| 1568 | } |
| 1569 | |
| 1570 | /** |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1571 | * pm_genpd_add_callbacks - Add PM domain callbacks to a given device. |
| 1572 | * @dev: Device to add the callbacks to. |
| 1573 | * @ops: Set of callbacks to add. |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1574 | * @td: Timing data to add to the device along with the callbacks (optional). |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1575 | */ |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1576 | int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops, |
| 1577 | struct gpd_timing_data *td) |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1578 | { |
| 1579 | struct pm_domain_data *pdd; |
| 1580 | int ret = 0; |
| 1581 | |
| 1582 | if (!(dev && dev->power.subsys_data && ops)) |
| 1583 | return -EINVAL; |
| 1584 | |
| 1585 | pm_runtime_disable(dev); |
| 1586 | device_pm_lock(); |
| 1587 | |
| 1588 | pdd = dev->power.subsys_data->domain_data; |
| 1589 | if (pdd) { |
| 1590 | struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); |
| 1591 | |
| 1592 | gpd_data->ops = *ops; |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1593 | if (td) |
| 1594 | gpd_data->td = *td; |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1595 | } else { |
| 1596 | ret = -EINVAL; |
| 1597 | } |
| 1598 | |
| 1599 | device_pm_unlock(); |
| 1600 | pm_runtime_enable(dev); |
| 1601 | |
| 1602 | return ret; |
| 1603 | } |
| 1604 | EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks); |
| 1605 | |
| 1606 | /** |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1607 | * __pm_genpd_remove_callbacks - Remove PM domain callbacks from a given device. |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1608 | * @dev: Device to remove the callbacks from. |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1609 | * @clear_td: If set, clear the device's timing data too. |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1610 | */ |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1611 | int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td) |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1612 | { |
| 1613 | struct pm_domain_data *pdd; |
| 1614 | int ret = 0; |
| 1615 | |
| 1616 | if (!(dev && dev->power.subsys_data)) |
| 1617 | return -EINVAL; |
| 1618 | |
| 1619 | pm_runtime_disable(dev); |
| 1620 | device_pm_lock(); |
| 1621 | |
| 1622 | pdd = dev->power.subsys_data->domain_data; |
| 1623 | if (pdd) { |
| 1624 | struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); |
| 1625 | |
| 1626 | gpd_data->ops = (struct gpd_dev_ops){ 0 }; |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1627 | if (clear_td) |
| 1628 | gpd_data->td = (struct gpd_timing_data){ 0 }; |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1629 | } else { |
| 1630 | ret = -EINVAL; |
| 1631 | } |
| 1632 | |
| 1633 | device_pm_unlock(); |
| 1634 | pm_runtime_enable(dev); |
| 1635 | |
| 1636 | return ret; |
| 1637 | } |
Rafael J. Wysocki | b02c999 | 2011-12-01 00:02:05 +0100 | [diff] [blame] | 1638 | EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks); |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1639 | |
Rafael J. Wysocki | cbc9ef0 | 2012-07-03 19:07:42 +0200 | [diff] [blame^] | 1640 | int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state) |
| 1641 | { |
| 1642 | struct cpuidle_driver *cpuidle_drv; |
| 1643 | struct gpd_cpu_data *cpu_data; |
| 1644 | struct cpuidle_state *idle_state; |
| 1645 | int ret = 0; |
| 1646 | |
| 1647 | if (IS_ERR_OR_NULL(genpd) || state < 0) |
| 1648 | return -EINVAL; |
| 1649 | |
| 1650 | genpd_acquire_lock(genpd); |
| 1651 | |
| 1652 | if (genpd->cpu_data) { |
| 1653 | ret = -EEXIST; |
| 1654 | goto out; |
| 1655 | } |
| 1656 | cpu_data = kzalloc(sizeof(*cpu_data), GFP_KERNEL); |
| 1657 | if (!cpu_data) { |
| 1658 | ret = -ENOMEM; |
| 1659 | goto out; |
| 1660 | } |
| 1661 | cpuidle_drv = cpuidle_driver_ref(); |
| 1662 | if (!cpuidle_drv) { |
| 1663 | ret = -ENODEV; |
| 1664 | goto out; |
| 1665 | } |
| 1666 | if (cpuidle_drv->state_count <= state) { |
| 1667 | ret = -EINVAL; |
| 1668 | goto err; |
| 1669 | } |
| 1670 | idle_state = &cpuidle_drv->states[state]; |
| 1671 | if (!idle_state->disabled) { |
| 1672 | ret = -EAGAIN; |
| 1673 | goto err; |
| 1674 | } |
| 1675 | cpu_data->idle_state = idle_state; |
| 1676 | cpu_data->saved_exit_latency = idle_state->exit_latency; |
| 1677 | genpd->cpu_data = cpu_data; |
| 1678 | genpd_recalc_cpu_exit_latency(genpd); |
| 1679 | |
| 1680 | out: |
| 1681 | genpd_release_lock(genpd); |
| 1682 | return ret; |
| 1683 | |
| 1684 | err: |
| 1685 | cpuidle_driver_unref(); |
| 1686 | goto out; |
| 1687 | } |
| 1688 | |
| 1689 | int genpd_detach_cpuidle(struct generic_pm_domain *genpd) |
| 1690 | { |
| 1691 | struct gpd_cpu_data *cpu_data; |
| 1692 | struct cpuidle_state *idle_state; |
| 1693 | int ret = 0; |
| 1694 | |
| 1695 | if (IS_ERR_OR_NULL(genpd)) |
| 1696 | return -EINVAL; |
| 1697 | |
| 1698 | genpd_acquire_lock(genpd); |
| 1699 | |
| 1700 | cpu_data = genpd->cpu_data; |
| 1701 | if (!cpu_data) { |
| 1702 | ret = -ENODEV; |
| 1703 | goto out; |
| 1704 | } |
| 1705 | idle_state = cpu_data->idle_state; |
| 1706 | if (!idle_state->disabled) { |
| 1707 | ret = -EAGAIN; |
| 1708 | goto out; |
| 1709 | } |
| 1710 | idle_state->exit_latency = cpu_data->saved_exit_latency; |
| 1711 | cpuidle_driver_unref(); |
| 1712 | genpd->cpu_data = NULL; |
| 1713 | kfree(cpu_data); |
| 1714 | |
| 1715 | out: |
| 1716 | genpd_release_lock(genpd); |
| 1717 | return ret; |
| 1718 | } |
| 1719 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1720 | /* Default device callbacks for generic PM domains. */ |
| 1721 | |
Rafael J. Wysocki | d5e4cbf | 2011-11-27 13:11:36 +0100 | [diff] [blame] | 1722 | /** |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1723 | * pm_genpd_default_save_state - Default "save device state" for PM domians. |
| 1724 | * @dev: Device to handle. |
| 1725 | */ |
| 1726 | static int pm_genpd_default_save_state(struct device *dev) |
| 1727 | { |
| 1728 | int (*cb)(struct device *__dev); |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1729 | |
| 1730 | cb = dev_gpd_data(dev)->ops.save_state; |
| 1731 | if (cb) |
| 1732 | return cb(dev); |
| 1733 | |
Rafael J. Wysocki | 0b589741 | 2012-06-16 00:02:22 +0200 | [diff] [blame] | 1734 | if (dev->type && dev->type->pm) |
| 1735 | cb = dev->type->pm->runtime_suspend; |
| 1736 | else if (dev->class && dev->class->pm) |
| 1737 | cb = dev->class->pm->runtime_suspend; |
| 1738 | else if (dev->bus && dev->bus->pm) |
| 1739 | cb = dev->bus->pm->runtime_suspend; |
| 1740 | else |
| 1741 | cb = NULL; |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1742 | |
Rafael J. Wysocki | 0b589741 | 2012-06-16 00:02:22 +0200 | [diff] [blame] | 1743 | if (!cb && dev->driver && dev->driver->pm) |
| 1744 | cb = dev->driver->pm->runtime_suspend; |
| 1745 | |
| 1746 | return cb ? cb(dev) : 0; |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | /** |
| 1750 | * pm_genpd_default_restore_state - Default PM domians "restore device state". |
| 1751 | * @dev: Device to handle. |
| 1752 | */ |
| 1753 | static int pm_genpd_default_restore_state(struct device *dev) |
| 1754 | { |
| 1755 | int (*cb)(struct device *__dev); |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1756 | |
| 1757 | cb = dev_gpd_data(dev)->ops.restore_state; |
| 1758 | if (cb) |
| 1759 | return cb(dev); |
| 1760 | |
Rafael J. Wysocki | 0b589741 | 2012-06-16 00:02:22 +0200 | [diff] [blame] | 1761 | if (dev->type && dev->type->pm) |
| 1762 | cb = dev->type->pm->runtime_resume; |
| 1763 | else if (dev->class && dev->class->pm) |
| 1764 | cb = dev->class->pm->runtime_resume; |
| 1765 | else if (dev->bus && dev->bus->pm) |
| 1766 | cb = dev->bus->pm->runtime_resume; |
| 1767 | else |
| 1768 | cb = NULL; |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1769 | |
Rafael J. Wysocki | 0b589741 | 2012-06-16 00:02:22 +0200 | [diff] [blame] | 1770 | if (!cb && dev->driver && dev->driver->pm) |
| 1771 | cb = dev->driver->pm->runtime_resume; |
| 1772 | |
| 1773 | return cb ? cb(dev) : 0; |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1774 | } |
| 1775 | |
Rafael J. Wysocki | 0f1d698 | 2012-01-14 00:39:25 +0100 | [diff] [blame] | 1776 | #ifdef CONFIG_PM_SLEEP |
| 1777 | |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1778 | /** |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1779 | * pm_genpd_default_suspend - Default "device suspend" for PM domians. |
| 1780 | * @dev: Device to handle. |
| 1781 | */ |
| 1782 | static int pm_genpd_default_suspend(struct device *dev) |
| 1783 | { |
Rafael J. Wysocki | c991485 | 2011-12-06 23:16:47 +0100 | [diff] [blame] | 1784 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.suspend; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1785 | |
| 1786 | return cb ? cb(dev) : pm_generic_suspend(dev); |
| 1787 | } |
| 1788 | |
| 1789 | /** |
| 1790 | * pm_genpd_default_suspend_late - Default "late device suspend" for PM domians. |
| 1791 | * @dev: Device to handle. |
| 1792 | */ |
| 1793 | static int pm_genpd_default_suspend_late(struct device *dev) |
| 1794 | { |
Rafael J. Wysocki | c991485 | 2011-12-06 23:16:47 +0100 | [diff] [blame] | 1795 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.suspend_late; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1796 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1797 | return cb ? cb(dev) : pm_generic_suspend_late(dev); |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | /** |
| 1801 | * pm_genpd_default_resume_early - Default "early device resume" for PM domians. |
| 1802 | * @dev: Device to handle. |
| 1803 | */ |
| 1804 | static int pm_genpd_default_resume_early(struct device *dev) |
| 1805 | { |
Rafael J. Wysocki | c991485 | 2011-12-06 23:16:47 +0100 | [diff] [blame] | 1806 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.resume_early; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1807 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1808 | return cb ? cb(dev) : pm_generic_resume_early(dev); |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /** |
| 1812 | * pm_genpd_default_resume - Default "device resume" for PM domians. |
| 1813 | * @dev: Device to handle. |
| 1814 | */ |
| 1815 | static int pm_genpd_default_resume(struct device *dev) |
| 1816 | { |
Rafael J. Wysocki | c991485 | 2011-12-06 23:16:47 +0100 | [diff] [blame] | 1817 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.resume; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1818 | |
| 1819 | return cb ? cb(dev) : pm_generic_resume(dev); |
| 1820 | } |
| 1821 | |
| 1822 | /** |
| 1823 | * pm_genpd_default_freeze - Default "device freeze" for PM domians. |
| 1824 | * @dev: Device to handle. |
| 1825 | */ |
| 1826 | static int pm_genpd_default_freeze(struct device *dev) |
| 1827 | { |
| 1828 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.freeze; |
| 1829 | |
| 1830 | return cb ? cb(dev) : pm_generic_freeze(dev); |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * pm_genpd_default_freeze_late - Default "late device freeze" for PM domians. |
| 1835 | * @dev: Device to handle. |
| 1836 | */ |
| 1837 | static int pm_genpd_default_freeze_late(struct device *dev) |
| 1838 | { |
| 1839 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.freeze_late; |
| 1840 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1841 | return cb ? cb(dev) : pm_generic_freeze_late(dev); |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | /** |
| 1845 | * pm_genpd_default_thaw_early - Default "early device thaw" for PM domians. |
| 1846 | * @dev: Device to handle. |
| 1847 | */ |
| 1848 | static int pm_genpd_default_thaw_early(struct device *dev) |
| 1849 | { |
| 1850 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.thaw_early; |
| 1851 | |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1852 | return cb ? cb(dev) : pm_generic_thaw_early(dev); |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | /** |
| 1856 | * pm_genpd_default_thaw - Default "device thaw" for PM domians. |
| 1857 | * @dev: Device to handle. |
| 1858 | */ |
| 1859 | static int pm_genpd_default_thaw(struct device *dev) |
| 1860 | { |
| 1861 | int (*cb)(struct device *__dev) = dev_gpd_data(dev)->ops.thaw; |
| 1862 | |
| 1863 | return cb ? cb(dev) : pm_generic_thaw(dev); |
| 1864 | } |
| 1865 | |
Rafael J. Wysocki | 0f1d698 | 2012-01-14 00:39:25 +0100 | [diff] [blame] | 1866 | #else /* !CONFIG_PM_SLEEP */ |
| 1867 | |
| 1868 | #define pm_genpd_default_suspend NULL |
| 1869 | #define pm_genpd_default_suspend_late NULL |
| 1870 | #define pm_genpd_default_resume_early NULL |
| 1871 | #define pm_genpd_default_resume NULL |
| 1872 | #define pm_genpd_default_freeze NULL |
| 1873 | #define pm_genpd_default_freeze_late NULL |
| 1874 | #define pm_genpd_default_thaw_early NULL |
| 1875 | #define pm_genpd_default_thaw NULL |
| 1876 | |
| 1877 | #endif /* !CONFIG_PM_SLEEP */ |
| 1878 | |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1879 | /** |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1880 | * pm_genpd_init - Initialize a generic I/O PM domain object. |
| 1881 | * @genpd: PM domain object to initialize. |
| 1882 | * @gov: PM domain governor to associate with the domain (may be NULL). |
| 1883 | * @is_off: Initial value of the domain's power_is_off field. |
| 1884 | */ |
| 1885 | void pm_genpd_init(struct generic_pm_domain *genpd, |
| 1886 | struct dev_power_governor *gov, bool is_off) |
| 1887 | { |
| 1888 | if (IS_ERR_OR_NULL(genpd)) |
| 1889 | return; |
| 1890 | |
Rafael J. Wysocki | 5063ce1 | 2011-08-08 23:43:40 +0200 | [diff] [blame] | 1891 | INIT_LIST_HEAD(&genpd->master_links); |
| 1892 | INIT_LIST_HEAD(&genpd->slave_links); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1893 | INIT_LIST_HEAD(&genpd->dev_list); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1894 | mutex_init(&genpd->lock); |
| 1895 | genpd->gov = gov; |
| 1896 | INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); |
| 1897 | genpd->in_progress = 0; |
Rafael J. Wysocki | c4bb316 | 2011-08-08 23:43:04 +0200 | [diff] [blame] | 1898 | atomic_set(&genpd->sd_count, 0); |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 1899 | genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE; |
| 1900 | init_waitqueue_head(&genpd->status_wait_queue); |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 1901 | genpd->poweroff_task = NULL; |
| 1902 | genpd->resume_count = 0; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1903 | genpd->device_count = 0; |
Rafael J. Wysocki | 221e9b5 | 2011-12-01 00:02:10 +0100 | [diff] [blame] | 1904 | genpd->max_off_time_ns = -1; |
Rafael J. Wysocki | 6ff7bb0d0 | 2012-05-01 21:34:07 +0200 | [diff] [blame] | 1905 | genpd->max_off_time_changed = true; |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 1906 | genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend; |
| 1907 | genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume; |
| 1908 | genpd->domain.ops.runtime_idle = pm_generic_runtime_idle; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1909 | genpd->domain.ops.prepare = pm_genpd_prepare; |
| 1910 | genpd->domain.ops.suspend = pm_genpd_suspend; |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1911 | genpd->domain.ops.suspend_late = pm_genpd_suspend_late; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1912 | genpd->domain.ops.suspend_noirq = pm_genpd_suspend_noirq; |
| 1913 | genpd->domain.ops.resume_noirq = pm_genpd_resume_noirq; |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1914 | genpd->domain.ops.resume_early = pm_genpd_resume_early; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1915 | genpd->domain.ops.resume = pm_genpd_resume; |
| 1916 | genpd->domain.ops.freeze = pm_genpd_freeze; |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1917 | genpd->domain.ops.freeze_late = pm_genpd_freeze_late; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1918 | genpd->domain.ops.freeze_noirq = pm_genpd_freeze_noirq; |
| 1919 | genpd->domain.ops.thaw_noirq = pm_genpd_thaw_noirq; |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1920 | genpd->domain.ops.thaw_early = pm_genpd_thaw_early; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1921 | genpd->domain.ops.thaw = pm_genpd_thaw; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1922 | genpd->domain.ops.poweroff = pm_genpd_suspend; |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1923 | genpd->domain.ops.poweroff_late = pm_genpd_suspend_late; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1924 | genpd->domain.ops.poweroff_noirq = pm_genpd_suspend_noirq; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1925 | genpd->domain.ops.restore_noirq = pm_genpd_restore_noirq; |
Rafael J. Wysocki | 0496c8a | 2012-01-29 20:39:02 +0100 | [diff] [blame] | 1926 | genpd->domain.ops.restore_early = pm_genpd_resume_early; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1927 | genpd->domain.ops.restore = pm_genpd_resume; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 1928 | genpd->domain.ops.complete = pm_genpd_complete; |
Rafael J. Wysocki | ecf0047 | 2011-11-27 13:11:44 +0100 | [diff] [blame] | 1929 | genpd->dev_ops.save_state = pm_genpd_default_save_state; |
| 1930 | genpd->dev_ops.restore_state = pm_genpd_default_restore_state; |
Rafael J. Wysocki | c991485 | 2011-12-06 23:16:47 +0100 | [diff] [blame] | 1931 | genpd->dev_ops.suspend = pm_genpd_default_suspend; |
| 1932 | genpd->dev_ops.suspend_late = pm_genpd_default_suspend_late; |
| 1933 | genpd->dev_ops.resume_early = pm_genpd_default_resume_early; |
| 1934 | genpd->dev_ops.resume = pm_genpd_default_resume; |
Rafael J. Wysocki | d23b9b0 | 2011-11-27 13:11:51 +0100 | [diff] [blame] | 1935 | genpd->dev_ops.freeze = pm_genpd_default_freeze; |
| 1936 | genpd->dev_ops.freeze_late = pm_genpd_default_freeze_late; |
| 1937 | genpd->dev_ops.thaw_early = pm_genpd_default_thaw_early; |
| 1938 | genpd->dev_ops.thaw = pm_genpd_default_thaw; |
Rafael J. Wysocki | 5125bbf | 2011-07-13 12:31:52 +0200 | [diff] [blame] | 1939 | mutex_lock(&gpd_list_lock); |
| 1940 | list_add(&genpd->gpd_list_node, &gpd_list); |
| 1941 | mutex_unlock(&gpd_list_lock); |
| 1942 | } |