aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/amba/bus.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/amba/bus.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/amba/bus.c')
-rw-r--r--drivers/amba/bus.c396
1 files changed, 367 insertions, 29 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index d31590e7011b..d74926e0939e 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -13,16 +13,17 @@
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
24static struct amba_id * 25static const struct amba_id *
25amba_lookup(struct amba_id *table, struct amba_device *dev) 26amba_lookup(const struct amba_id *table, struct amba_device *dev)
26{ 27{
27 int ret = 0; 28 int ret = 0;
28 29
@@ -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
60static 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
70static 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...) \
81static ssize_t name##_show(struct device *_dev, \ 62static ssize_t name##_show(struct device *_dev, \
82 struct device_attribute *attr, char *buf) \ 63 struct device_attribute *attr, char *buf) \
@@ -102,17 +83,330 @@ static struct device_attribute amba_dev_attrs[] = {
102 __ATTR_NULL, 83 __ATTR_NULL,
103}; 84};
104 85
86#ifdef CONFIG_PM_SLEEP
87
88static 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
100static 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
112static 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
123static 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
140static 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
158static 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
174static 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
192static 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_HIBERNATE_CALLBACKS
218
219static 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
237static 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
253static 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
271static 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
287static 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
305static 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
321static 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
339static 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_HIBERNATE_CALLBACKS */
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_HIBERNATE_CALLBACKS */
367
368#ifdef CONFIG_PM
369
370static 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".
108 */ 403 */
109static struct bus_type amba_bustype = { 404struct bus_type amba_bustype = {
110 .name = "amba", 405 .name = "amba",
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
118static int __init amba_init(void) 412static int __init amba_init(void)
@@ -147,6 +441,39 @@ static void amba_put_disable_pclk(struct amba_device *pcdev)
147 clk_put(pclk); 441 clk_put(pclk);
148} 442}
149 443
444static int amba_get_enable_vcore(struct amba_device *pcdev)
445{
446 struct regulator *vcore = regulator_get(&pcdev->dev, "vcore");
447 int ret;
448
449 pcdev->vcore = vcore;
450
451 if (IS_ERR(vcore)) {
452 /* It is OK not to supply a vcore regulator */
453 if (PTR_ERR(vcore) == -ENODEV)
454 return 0;
455 return PTR_ERR(vcore);
456 }
457
458 ret = regulator_enable(vcore);
459 if (ret) {
460 regulator_put(vcore);
461 pcdev->vcore = ERR_PTR(-ENODEV);
462 }
463
464 return ret;
465}
466
467static void amba_put_disable_vcore(struct amba_device *pcdev)
468{
469 struct regulator *vcore = pcdev->vcore;
470
471 if (!IS_ERR(vcore)) {
472 regulator_disable(vcore);
473 regulator_put(vcore);
474 }
475}
476
150/* 477/*
151 * These are the device model conversion veneers; they convert the 478 * These are the device model conversion veneers; they convert the
152 * device model structures to our more specific structures. 479 * device model structures to our more specific structures.
@@ -155,10 +482,14 @@ static int amba_probe(struct device *dev)
155{ 482{
156 struct amba_device *pcdev = to_amba_device(dev); 483 struct amba_device *pcdev = to_amba_device(dev);
157 struct amba_driver *pcdrv = to_amba_driver(dev->driver); 484 struct amba_driver *pcdrv = to_amba_driver(dev->driver);
158 struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev); 485 const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
159 int ret; 486 int ret;
160 487
161 do { 488 do {
489 ret = amba_get_enable_vcore(pcdev);
490 if (ret)
491 break;
492
162 ret = amba_get_enable_pclk(pcdev); 493 ret = amba_get_enable_pclk(pcdev);
163 if (ret) 494 if (ret)
164 break; 495 break;
@@ -168,6 +499,7 @@ static int amba_probe(struct device *dev)
168 break; 499 break;
169 500
170 amba_put_disable_pclk(pcdev); 501 amba_put_disable_pclk(pcdev);
502 amba_put_disable_vcore(pcdev);
171 } while (0); 503 } while (0);
172 504
173 return ret; 505 return ret;
@@ -180,6 +512,7 @@ static int amba_remove(struct device *dev)
180 int ret = drv->remove(pcdev); 512 int ret = drv->remove(pcdev);
181 513
182 amba_put_disable_pclk(pcdev); 514 amba_put_disable_pclk(pcdev);
515 amba_put_disable_vcore(pcdev);
183 516
184 return ret; 517 return ret;
185} 518}
@@ -270,6 +603,10 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
270 if (ret) 603 if (ret)
271 goto err_out; 604 goto err_out;
272 605
606 /* Hard-coded primecell ID instead of plug-n-play */
607 if (dev->periphid != 0)
608 goto skip_probe;
609
273 /* 610 /*
274 * Dynamically calculate the size of the resource 611 * Dynamically calculate the size of the resource
275 * and use this for iomap 612 * and use this for iomap
@@ -298,7 +635,7 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
298 635
299 amba_put_disable_pclk(dev); 636 amba_put_disable_pclk(dev);
300 637
301 if (cid == 0xb105f00d) 638 if (cid == AMBA_CID)
302 dev->periphid = pid; 639 dev->periphid = pid;
303 640
304 if (!dev->periphid) 641 if (!dev->periphid)
@@ -310,6 +647,7 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
310 if (ret) 647 if (ret)
311 goto err_release; 648 goto err_release;
312 649
650 skip_probe:
313 ret = device_add(&dev->dev); 651 ret = device_add(&dev->dev);
314 if (ret) 652 if (ret)
315 goto err_release; 653 goto err_release;
@@ -427,7 +765,7 @@ int amba_request_regions(struct amba_device *dev, const char *name)
427} 765}
428 766
429/** 767/**
430 * amba_release_regions - release mem regions assoicated with device 768 * amba_release_regions - release mem regions associated with device
431 * @dev: amba_device structure for device 769 * @dev: amba_device structure for device
432 * 770 *
433 * Release regions claimed by a successful call to amba_request_regions. 771 * Release regions claimed by a successful call to amba_request_regions.