diff options
author | Rabin Vincent <rabin.vincent@stericsson.com> | 2011-02-22 22:33:17 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2011-02-23 11:26:46 -0500 |
commit | ba74ec7f6b2bf9e1b5d0f2c5cef08766944cb2c8 (patch) | |
tree | 3b781d98bb3b18de0ccc30c71316092fd9b9df94 /drivers | |
parent | 2d00880fa842e7dd34f5bb5eb3b5f8337b068be5 (diff) |
ARM: 6758/1: amba: support pm ops
Support pm_ops in the AMBA bus, required to allow drivers to use runtime pm.
The implementation of AMBA bus pm ops is based on the platform bus
implementation.
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/amba/bus.c | 340 |
1 files changed, 317 insertions, 23 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 43088996a07a..6d2bb2524b6e 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c | |||
@@ -13,12 +13,13 @@ | |||
13 | #include <linux/string.h> | 13 | #include <linux/string.h> |
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/io.h> | 15 | #include <linux/io.h> |
16 | #include <linux/pm.h> | ||
17 | #include <linux/pm_runtime.h> | ||
16 | #include <linux/amba/bus.h> | 18 | #include <linux/amba/bus.h> |
17 | 19 | ||
18 | #include <asm/irq.h> | 20 | #include <asm/irq.h> |
19 | #include <asm/sizes.h> | 21 | #include <asm/sizes.h> |
20 | 22 | ||
21 | #define to_amba_device(d) container_of(d, struct amba_device, dev) | ||
22 | #define to_amba_driver(d) container_of(d, struct amba_driver, drv) | 23 | #define to_amba_driver(d) container_of(d, struct amba_driver, drv) |
23 | 24 | ||
24 | static const struct amba_id * | 25 | static const struct amba_id * |
@@ -57,26 +58,6 @@ static int amba_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
57 | #define amba_uevent NULL | 58 | #define amba_uevent NULL |
58 | #endif | 59 | #endif |
59 | 60 | ||
60 | static int amba_suspend(struct device *dev, pm_message_t state) | ||
61 | { | ||
62 | struct amba_driver *drv = to_amba_driver(dev->driver); | ||
63 | int ret = 0; | ||
64 | |||
65 | if (dev->driver && drv->suspend) | ||
66 | ret = drv->suspend(to_amba_device(dev), state); | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | static int amba_resume(struct device *dev) | ||
71 | { | ||
72 | struct amba_driver *drv = to_amba_driver(dev->driver); | ||
73 | int ret = 0; | ||
74 | |||
75 | if (dev->driver && drv->resume) | ||
76 | ret = drv->resume(to_amba_device(dev)); | ||
77 | return ret; | ||
78 | } | ||
79 | |||
80 | #define amba_attr_func(name,fmt,arg...) \ | 61 | #define amba_attr_func(name,fmt,arg...) \ |
81 | static ssize_t name##_show(struct device *_dev, \ | 62 | static ssize_t name##_show(struct device *_dev, \ |
82 | struct device_attribute *attr, char *buf) \ | 63 | struct device_attribute *attr, char *buf) \ |
@@ -102,6 +83,320 @@ static struct device_attribute amba_dev_attrs[] = { | |||
102 | __ATTR_NULL, | 83 | __ATTR_NULL, |
103 | }; | 84 | }; |
104 | 85 | ||
86 | #ifdef CONFIG_PM_SLEEP | ||
87 | |||
88 | static int amba_legacy_suspend(struct device *dev, pm_message_t mesg) | ||
89 | { | ||
90 | struct amba_driver *adrv = to_amba_driver(dev->driver); | ||
91 | struct amba_device *adev = to_amba_device(dev); | ||
92 | int ret = 0; | ||
93 | |||
94 | if (dev->driver && adrv->suspend) | ||
95 | ret = adrv->suspend(adev, mesg); | ||
96 | |||
97 | return ret; | ||
98 | } | ||
99 | |||
100 | static int amba_legacy_resume(struct device *dev) | ||
101 | { | ||
102 | struct amba_driver *adrv = to_amba_driver(dev->driver); | ||
103 | struct amba_device *adev = to_amba_device(dev); | ||
104 | int ret = 0; | ||
105 | |||
106 | if (dev->driver && adrv->resume) | ||
107 | ret = adrv->resume(adev); | ||
108 | |||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | static int amba_pm_prepare(struct device *dev) | ||
113 | { | ||
114 | struct device_driver *drv = dev->driver; | ||
115 | int ret = 0; | ||
116 | |||
117 | if (drv && drv->pm && drv->pm->prepare) | ||
118 | ret = drv->pm->prepare(dev); | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | static void amba_pm_complete(struct device *dev) | ||
124 | { | ||
125 | struct device_driver *drv = dev->driver; | ||
126 | |||
127 | if (drv && drv->pm && drv->pm->complete) | ||
128 | drv->pm->complete(dev); | ||
129 | } | ||
130 | |||
131 | #else /* !CONFIG_PM_SLEEP */ | ||
132 | |||
133 | #define amba_pm_prepare NULL | ||
134 | #define amba_pm_complete NULL | ||
135 | |||
136 | #endif /* !CONFIG_PM_SLEEP */ | ||
137 | |||
138 | #ifdef CONFIG_SUSPEND | ||
139 | |||
140 | static int amba_pm_suspend(struct device *dev) | ||
141 | { | ||
142 | struct device_driver *drv = dev->driver; | ||
143 | int ret = 0; | ||
144 | |||
145 | if (!drv) | ||
146 | return 0; | ||
147 | |||
148 | if (drv->pm) { | ||
149 | if (drv->pm->suspend) | ||
150 | ret = drv->pm->suspend(dev); | ||
151 | } else { | ||
152 | ret = amba_legacy_suspend(dev, PMSG_SUSPEND); | ||
153 | } | ||
154 | |||
155 | return ret; | ||
156 | } | ||
157 | |||
158 | static int amba_pm_suspend_noirq(struct device *dev) | ||
159 | { | ||
160 | struct device_driver *drv = dev->driver; | ||
161 | int ret = 0; | ||
162 | |||
163 | if (!drv) | ||
164 | return 0; | ||
165 | |||
166 | if (drv->pm) { | ||
167 | if (drv->pm->suspend_noirq) | ||
168 | ret = drv->pm->suspend_noirq(dev); | ||
169 | } | ||
170 | |||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | static int amba_pm_resume(struct device *dev) | ||
175 | { | ||
176 | struct device_driver *drv = dev->driver; | ||
177 | int ret = 0; | ||
178 | |||
179 | if (!drv) | ||
180 | return 0; | ||
181 | |||
182 | if (drv->pm) { | ||
183 | if (drv->pm->resume) | ||
184 | ret = drv->pm->resume(dev); | ||
185 | } else { | ||
186 | ret = amba_legacy_resume(dev); | ||
187 | } | ||
188 | |||
189 | return ret; | ||
190 | } | ||
191 | |||
192 | static int amba_pm_resume_noirq(struct device *dev) | ||
193 | { | ||
194 | struct device_driver *drv = dev->driver; | ||
195 | int ret = 0; | ||
196 | |||
197 | if (!drv) | ||
198 | return 0; | ||
199 | |||
200 | if (drv->pm) { | ||
201 | if (drv->pm->resume_noirq) | ||
202 | ret = drv->pm->resume_noirq(dev); | ||
203 | } | ||
204 | |||
205 | return ret; | ||
206 | } | ||
207 | |||
208 | #else /* !CONFIG_SUSPEND */ | ||
209 | |||
210 | #define amba_pm_suspend NULL | ||
211 | #define amba_pm_resume NULL | ||
212 | #define amba_pm_suspend_noirq NULL | ||
213 | #define amba_pm_resume_noirq NULL | ||
214 | |||
215 | #endif /* !CONFIG_SUSPEND */ | ||
216 | |||
217 | #ifdef CONFIG_HIBERNATION | ||
218 | |||
219 | static int amba_pm_freeze(struct device *dev) | ||
220 | { | ||
221 | struct device_driver *drv = dev->driver; | ||
222 | int ret = 0; | ||
223 | |||
224 | if (!drv) | ||
225 | return 0; | ||
226 | |||
227 | if (drv->pm) { | ||
228 | if (drv->pm->freeze) | ||
229 | ret = drv->pm->freeze(dev); | ||
230 | } else { | ||
231 | ret = amba_legacy_suspend(dev, PMSG_FREEZE); | ||
232 | } | ||
233 | |||
234 | return ret; | ||
235 | } | ||
236 | |||
237 | static int amba_pm_freeze_noirq(struct device *dev) | ||
238 | { | ||
239 | struct device_driver *drv = dev->driver; | ||
240 | int ret = 0; | ||
241 | |||
242 | if (!drv) | ||
243 | return 0; | ||
244 | |||
245 | if (drv->pm) { | ||
246 | if (drv->pm->freeze_noirq) | ||
247 | ret = drv->pm->freeze_noirq(dev); | ||
248 | } | ||
249 | |||
250 | return ret; | ||
251 | } | ||
252 | |||
253 | static int amba_pm_thaw(struct device *dev) | ||
254 | { | ||
255 | struct device_driver *drv = dev->driver; | ||
256 | int ret = 0; | ||
257 | |||
258 | if (!drv) | ||
259 | return 0; | ||
260 | |||
261 | if (drv->pm) { | ||
262 | if (drv->pm->thaw) | ||
263 | ret = drv->pm->thaw(dev); | ||
264 | } else { | ||
265 | ret = amba_legacy_resume(dev); | ||
266 | } | ||
267 | |||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | static int amba_pm_thaw_noirq(struct device *dev) | ||
272 | { | ||
273 | struct device_driver *drv = dev->driver; | ||
274 | int ret = 0; | ||
275 | |||
276 | if (!drv) | ||
277 | return 0; | ||
278 | |||
279 | if (drv->pm) { | ||
280 | if (drv->pm->thaw_noirq) | ||
281 | ret = drv->pm->thaw_noirq(dev); | ||
282 | } | ||
283 | |||
284 | return ret; | ||
285 | } | ||
286 | |||
287 | static int amba_pm_poweroff(struct device *dev) | ||
288 | { | ||
289 | struct device_driver *drv = dev->driver; | ||
290 | int ret = 0; | ||
291 | |||
292 | if (!drv) | ||
293 | return 0; | ||
294 | |||
295 | if (drv->pm) { | ||
296 | if (drv->pm->poweroff) | ||
297 | ret = drv->pm->poweroff(dev); | ||
298 | } else { | ||
299 | ret = amba_legacy_suspend(dev, PMSG_HIBERNATE); | ||
300 | } | ||
301 | |||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | static int amba_pm_poweroff_noirq(struct device *dev) | ||
306 | { | ||
307 | struct device_driver *drv = dev->driver; | ||
308 | int ret = 0; | ||
309 | |||
310 | if (!drv) | ||
311 | return 0; | ||
312 | |||
313 | if (drv->pm) { | ||
314 | if (drv->pm->poweroff_noirq) | ||
315 | ret = drv->pm->poweroff_noirq(dev); | ||
316 | } | ||
317 | |||
318 | return ret; | ||
319 | } | ||
320 | |||
321 | static int amba_pm_restore(struct device *dev) | ||
322 | { | ||
323 | struct device_driver *drv = dev->driver; | ||
324 | int ret = 0; | ||
325 | |||
326 | if (!drv) | ||
327 | return 0; | ||
328 | |||
329 | if (drv->pm) { | ||
330 | if (drv->pm->restore) | ||
331 | ret = drv->pm->restore(dev); | ||
332 | } else { | ||
333 | ret = amba_legacy_resume(dev); | ||
334 | } | ||
335 | |||
336 | return ret; | ||
337 | } | ||
338 | |||
339 | static int amba_pm_restore_noirq(struct device *dev) | ||
340 | { | ||
341 | struct device_driver *drv = dev->driver; | ||
342 | int ret = 0; | ||
343 | |||
344 | if (!drv) | ||
345 | return 0; | ||
346 | |||
347 | if (drv->pm) { | ||
348 | if (drv->pm->restore_noirq) | ||
349 | ret = drv->pm->restore_noirq(dev); | ||
350 | } | ||
351 | |||
352 | return ret; | ||
353 | } | ||
354 | |||
355 | #else /* !CONFIG_HIBERNATION */ | ||
356 | |||
357 | #define amba_pm_freeze NULL | ||
358 | #define amba_pm_thaw NULL | ||
359 | #define amba_pm_poweroff NULL | ||
360 | #define amba_pm_restore NULL | ||
361 | #define amba_pm_freeze_noirq NULL | ||
362 | #define amba_pm_thaw_noirq NULL | ||
363 | #define amba_pm_poweroff_noirq NULL | ||
364 | #define amba_pm_restore_noirq NULL | ||
365 | |||
366 | #endif /* !CONFIG_HIBERNATION */ | ||
367 | |||
368 | #ifdef CONFIG_PM | ||
369 | |||
370 | static const struct dev_pm_ops amba_pm = { | ||
371 | .prepare = amba_pm_prepare, | ||
372 | .complete = amba_pm_complete, | ||
373 | .suspend = amba_pm_suspend, | ||
374 | .resume = amba_pm_resume, | ||
375 | .freeze = amba_pm_freeze, | ||
376 | .thaw = amba_pm_thaw, | ||
377 | .poweroff = amba_pm_poweroff, | ||
378 | .restore = amba_pm_restore, | ||
379 | .suspend_noirq = amba_pm_suspend_noirq, | ||
380 | .resume_noirq = amba_pm_resume_noirq, | ||
381 | .freeze_noirq = amba_pm_freeze_noirq, | ||
382 | .thaw_noirq = amba_pm_thaw_noirq, | ||
383 | .poweroff_noirq = amba_pm_poweroff_noirq, | ||
384 | .restore_noirq = amba_pm_restore_noirq, | ||
385 | SET_RUNTIME_PM_OPS( | ||
386 | pm_generic_runtime_suspend, | ||
387 | pm_generic_runtime_resume, | ||
388 | pm_generic_runtime_idle | ||
389 | ) | ||
390 | }; | ||
391 | |||
392 | #define AMBA_PM (&amba_pm) | ||
393 | |||
394 | #else /* !CONFIG_PM */ | ||
395 | |||
396 | #define AMBA_PM NULL | ||
397 | |||
398 | #endif /* !CONFIG_PM */ | ||
399 | |||
105 | /* | 400 | /* |
106 | * Primecells are part of the Advanced Microcontroller Bus Architecture, | 401 | * Primecells are part of the Advanced Microcontroller Bus Architecture, |
107 | * so we call the bus "amba". | 402 | * so we call the bus "amba". |
@@ -111,8 +406,7 @@ struct bus_type amba_bustype = { | |||
111 | .dev_attrs = amba_dev_attrs, | 406 | .dev_attrs = amba_dev_attrs, |
112 | .match = amba_match, | 407 | .match = amba_match, |
113 | .uevent = amba_uevent, | 408 | .uevent = amba_uevent, |
114 | .suspend = amba_suspend, | 409 | .pm = AMBA_PM, |
115 | .resume = amba_resume, | ||
116 | }; | 410 | }; |
117 | 411 | ||
118 | static int __init amba_init(void) | 412 | static int __init amba_init(void) |