Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[deliverable/linux.git] / drivers / amba / bus.c
CommitLineData
1da177e4
LT
1/*
2 * linux/arch/arm/common/amba.c
3 *
4 * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/device.h>
4e57b681
TS
13#include <linux/string.h>
14#include <linux/slab.h>
934848da 15#include <linux/io.h>
ba74ec7f
RV
16#include <linux/pm.h>
17#include <linux/pm_runtime.h>
a62c80e5 18#include <linux/amba/bus.h>
a875cfbb 19#include <linux/sizes.h>
1da177e4 20
934848da 21#include <asm/irq.h>
1da177e4 22
1da177e4
LT
23#define to_amba_driver(d) container_of(d, struct amba_driver, drv)
24
c862aab0
RK
25static const struct amba_id *
26amba_lookup(const struct amba_id *table, struct amba_device *dev)
1da177e4
LT
27{
28 int ret = 0;
29
30 while (table->mask) {
31 ret = (dev->periphid & table->mask) == table->id;
32 if (ret)
33 break;
34 table++;
35 }
36
37 return ret ? table : NULL;
38}
39
40static int amba_match(struct device *dev, struct device_driver *drv)
41{
42 struct amba_device *pcdev = to_amba_device(dev);
43 struct amba_driver *pcdrv = to_amba_driver(drv);
44
45 return amba_lookup(pcdrv->id_table, pcdev) != NULL;
46}
47
7eff2e7a 48static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
1da177e4
LT
49{
50 struct amba_device *pcdev = to_amba_device(dev);
7eff2e7a 51 int retval = 0;
1da177e4 52
7eff2e7a 53 retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid);
523817bd
DM
54 if (retval)
55 return retval;
56
57 retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid);
bf62456e 58 return retval;
1da177e4 59}
1da177e4 60
96b13f5c
RK
61#define amba_attr_func(name,fmt,arg...) \
62static ssize_t name##_show(struct device *_dev, \
63 struct device_attribute *attr, char *buf) \
64{ \
65 struct amba_device *dev = to_amba_device(_dev); \
66 return sprintf(buf, fmt, arg); \
67}
68
69#define amba_attr(name,fmt,arg...) \
70amba_attr_func(name,fmt,arg) \
71static DEVICE_ATTR(name, S_IRUGO, name##_show, NULL)
72
73amba_attr_func(id, "%08x\n", dev->periphid);
74amba_attr(irq0, "%u\n", dev->irq[0]);
75amba_attr(irq1, "%u\n", dev->irq[1]);
76amba_attr_func(resource, "\t%016llx\t%016llx\t%016lx\n",
77 (unsigned long long)dev->res.start, (unsigned long long)dev->res.end,
78 dev->res.flags);
79
80static struct device_attribute amba_dev_attrs[] = {
81 __ATTR_RO(id),
82 __ATTR_RO(resource),
83 __ATTR_NULL,
84};
85
ba74ec7f
RV
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
8114ab76 112#endif /* CONFIG_PM_SLEEP */
ba74ec7f
RV
113
114#ifdef CONFIG_SUSPEND
115
116static int amba_pm_suspend(struct device *dev)
117{
118 struct device_driver *drv = dev->driver;
119 int ret = 0;
120
121 if (!drv)
122 return 0;
123
124 if (drv->pm) {
125 if (drv->pm->suspend)
126 ret = drv->pm->suspend(dev);
127 } else {
128 ret = amba_legacy_suspend(dev, PMSG_SUSPEND);
129 }
130
131 return ret;
132}
133
ba74ec7f
RV
134static int amba_pm_resume(struct device *dev)
135{
136 struct device_driver *drv = dev->driver;
137 int ret = 0;
138
139 if (!drv)
140 return 0;
141
142 if (drv->pm) {
143 if (drv->pm->resume)
144 ret = drv->pm->resume(dev);
145 } else {
146 ret = amba_legacy_resume(dev);
147 }
148
149 return ret;
150}
151
ba74ec7f
RV
152#else /* !CONFIG_SUSPEND */
153
154#define amba_pm_suspend NULL
155#define amba_pm_resume NULL
ba74ec7f
RV
156
157#endif /* !CONFIG_SUSPEND */
158
1f112cee 159#ifdef CONFIG_HIBERNATE_CALLBACKS
ba74ec7f
RV
160
161static int amba_pm_freeze(struct device *dev)
162{
163 struct device_driver *drv = dev->driver;
164 int ret = 0;
165
166 if (!drv)
167 return 0;
168
169 if (drv->pm) {
170 if (drv->pm->freeze)
171 ret = drv->pm->freeze(dev);
172 } else {
173 ret = amba_legacy_suspend(dev, PMSG_FREEZE);
174 }
175
176 return ret;
177}
178
ba74ec7f
RV
179static int amba_pm_thaw(struct device *dev)
180{
181 struct device_driver *drv = dev->driver;
182 int ret = 0;
183
184 if (!drv)
185 return 0;
186
187 if (drv->pm) {
188 if (drv->pm->thaw)
189 ret = drv->pm->thaw(dev);
190 } else {
191 ret = amba_legacy_resume(dev);
192 }
193
194 return ret;
195}
196
ba74ec7f
RV
197static int amba_pm_poweroff(struct device *dev)
198{
199 struct device_driver *drv = dev->driver;
200 int ret = 0;
201
202 if (!drv)
203 return 0;
204
205 if (drv->pm) {
206 if (drv->pm->poweroff)
207 ret = drv->pm->poweroff(dev);
208 } else {
209 ret = amba_legacy_suspend(dev, PMSG_HIBERNATE);
210 }
211
212 return ret;
213}
214
ba74ec7f
RV
215static int amba_pm_restore(struct device *dev)
216{
217 struct device_driver *drv = dev->driver;
218 int ret = 0;
219
220 if (!drv)
221 return 0;
222
223 if (drv->pm) {
224 if (drv->pm->restore)
225 ret = drv->pm->restore(dev);
226 } else {
227 ret = amba_legacy_resume(dev);
228 }
229
230 return ret;
231}
232
1f112cee 233#else /* !CONFIG_HIBERNATE_CALLBACKS */
ba74ec7f
RV
234
235#define amba_pm_freeze NULL
236#define amba_pm_thaw NULL
237#define amba_pm_poweroff NULL
238#define amba_pm_restore NULL
ba74ec7f 239
1f112cee 240#endif /* !CONFIG_HIBERNATE_CALLBACKS */
ba74ec7f 241
92b97f0a
RK
242#ifdef CONFIG_PM_RUNTIME
243/*
244 * Hooks to provide runtime PM of the pclk (bus clock). It is safe to
245 * enable/disable the bus clock at runtime PM suspend/resume as this
1e45860f 246 * does not result in loss of context.
92b97f0a
RK
247 */
248static int amba_pm_runtime_suspend(struct device *dev)
249{
250 struct amba_device *pcdev = to_amba_device(dev);
251 int ret = pm_generic_runtime_suspend(dev);
252
253 if (ret == 0 && dev->driver)
254 clk_disable(pcdev->pclk);
255
256 return ret;
257}
258
259static int amba_pm_runtime_resume(struct device *dev)
260{
261 struct amba_device *pcdev = to_amba_device(dev);
262 int ret;
263
264 if (dev->driver) {
265 ret = clk_enable(pcdev->pclk);
266 /* Failure is probably fatal to the system, but... */
267 if (ret)
268 return ret;
269 }
270
271 return pm_generic_runtime_resume(dev);
272}
273#endif
274
ba74ec7f
RV
275#ifdef CONFIG_PM
276
277static const struct dev_pm_ops amba_pm = {
ba74ec7f
RV
278 .suspend = amba_pm_suspend,
279 .resume = amba_pm_resume,
280 .freeze = amba_pm_freeze,
281 .thaw = amba_pm_thaw,
282 .poweroff = amba_pm_poweroff,
283 .restore = amba_pm_restore,
ba74ec7f 284 SET_RUNTIME_PM_OPS(
92b97f0a
RK
285 amba_pm_runtime_suspend,
286 amba_pm_runtime_resume,
45f0a85c 287 NULL
ba74ec7f
RV
288 )
289};
290
291#define AMBA_PM (&amba_pm)
292
293#else /* !CONFIG_PM */
294
295#define AMBA_PM NULL
296
297#endif /* !CONFIG_PM */
298
1da177e4
LT
299/*
300 * Primecells are part of the Advanced Microcontroller Bus Architecture,
301 * so we call the bus "amba".
302 */
394d5aef 303struct bus_type amba_bustype = {
1da177e4 304 .name = "amba",
96b13f5c 305 .dev_attrs = amba_dev_attrs,
1da177e4 306 .match = amba_match,
6d20b035 307 .uevent = amba_uevent,
ba74ec7f 308 .pm = AMBA_PM,
1da177e4
LT
309};
310
311static int __init amba_init(void)
312{
313 return bus_register(&amba_bustype);
314}
315
316postcore_initcall(amba_init);
317
7cfe2494
RK
318static int amba_get_enable_pclk(struct amba_device *pcdev)
319{
320 struct clk *pclk = clk_get(&pcdev->dev, "apb_pclk");
321 int ret;
322
323 pcdev->pclk = pclk;
324
325 if (IS_ERR(pclk))
326 return PTR_ERR(pclk);
327
ac3e2fa6
RK
328 ret = clk_prepare(pclk);
329 if (ret) {
330 clk_put(pclk);
331 return ret;
332 }
333
7cfe2494 334 ret = clk_enable(pclk);
ac3e2fa6
RK
335 if (ret) {
336 clk_unprepare(pclk);
7cfe2494 337 clk_put(pclk);
ac3e2fa6 338 }
7cfe2494
RK
339
340 return ret;
341}
342
343static void amba_put_disable_pclk(struct amba_device *pcdev)
344{
345 struct clk *pclk = pcdev->pclk;
346
347 clk_disable(pclk);
ac3e2fa6 348 clk_unprepare(pclk);
7cfe2494
RK
349 clk_put(pclk);
350}
351
1da177e4
LT
352/*
353 * These are the device model conversion veneers; they convert the
354 * device model structures to our more specific structures.
355 */
356static int amba_probe(struct device *dev)
357{
358 struct amba_device *pcdev = to_amba_device(dev);
359 struct amba_driver *pcdrv = to_amba_driver(dev->driver);
c862aab0 360 const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
7cfe2494 361 int ret;
1da177e4 362
7cfe2494
RK
363 do {
364 ret = amba_get_enable_pclk(pcdev);
365 if (ret)
366 break;
367
92b97f0a
RK
368 pm_runtime_get_noresume(dev);
369 pm_runtime_set_active(dev);
370 pm_runtime_enable(dev);
371
7cfe2494
RK
372 ret = pcdrv->probe(pcdev, id);
373 if (ret == 0)
374 break;
1da177e4 375
92b97f0a
RK
376 pm_runtime_disable(dev);
377 pm_runtime_set_suspended(dev);
378 pm_runtime_put_noidle(dev);
379
7cfe2494
RK
380 amba_put_disable_pclk(pcdev);
381 } while (0);
382
383 return ret;
1da177e4
LT
384}
385
386static int amba_remove(struct device *dev)
387{
7cfe2494 388 struct amba_device *pcdev = to_amba_device(dev);
1da177e4 389 struct amba_driver *drv = to_amba_driver(dev->driver);
92b97f0a
RK
390 int ret;
391
392 pm_runtime_get_sync(dev);
393 ret = drv->remove(pcdev);
394 pm_runtime_put_noidle(dev);
395
396 /* Undo the runtime PM settings in amba_probe() */
397 pm_runtime_disable(dev);
398 pm_runtime_set_suspended(dev);
399 pm_runtime_put_noidle(dev);
7cfe2494
RK
400
401 amba_put_disable_pclk(pcdev);
402
403 return ret;
1da177e4
LT
404}
405
406static void amba_shutdown(struct device *dev)
407{
408 struct amba_driver *drv = to_amba_driver(dev->driver);
409 drv->shutdown(to_amba_device(dev));
410}
411
412/**
413 * amba_driver_register - register an AMBA device driver
414 * @drv: amba device driver structure
415 *
416 * Register an AMBA device driver with the Linux device model
417 * core. If devices pre-exist, the drivers probe function will
418 * be called.
419 */
420int amba_driver_register(struct amba_driver *drv)
421{
422 drv->drv.bus = &amba_bustype;
423
424#define SETFN(fn) if (drv->fn) drv->drv.fn = amba_##fn
425 SETFN(probe);
426 SETFN(remove);
427 SETFN(shutdown);
428
429 return driver_register(&drv->drv);
430}
431
432/**
433 * amba_driver_unregister - remove an AMBA device driver
434 * @drv: AMBA device driver structure to remove
435 *
436 * Unregister an AMBA device driver from the Linux device
437 * model. The device model will call the drivers remove function
438 * for each device the device driver is currently handling.
439 */
440void amba_driver_unregister(struct amba_driver *drv)
441{
442 driver_unregister(&drv->drv);
443}
444
445
446static void amba_device_release(struct device *dev)
447{
448 struct amba_device *d = to_amba_device(dev);
449
450 if (d->res.parent)
451 release_resource(&d->res);
452 kfree(d);
453}
454
1da177e4 455/**
d5dc9271
RK
456 * amba_device_add - add a previously allocated AMBA device structure
457 * @dev: AMBA device allocated by amba_device_alloc
458 * @parent: resource parent for this devices resources
1da177e4 459 *
d5dc9271
RK
460 * Claim the resource, and read the device cell ID if not already
461 * initialized. Register the AMBA device with the Linux device
462 * manager.
1da177e4 463 */
d5dc9271 464int amba_device_add(struct amba_device *dev, struct resource *parent)
1da177e4 465{
8afe0b96 466 u32 size;
1da177e4
LT
467 void __iomem *tmp;
468 int i, ret;
469
2eac58d5
RK
470 WARN_ON(dev->irq[0] == (unsigned int)-1);
471 WARN_ON(dev->irq[1] == (unsigned int)-1);
472
1da177e4 473 ret = request_resource(parent, &dev->res);
96b13f5c
RK
474 if (ret)
475 goto err_out;
476
97ceed1f
LW
477 /* Hard-coded primecell ID instead of plug-n-play */
478 if (dev->periphid != 0)
479 goto skip_probe;
480
8afe0b96
LC
481 /*
482 * Dynamically calculate the size of the resource
483 * and use this for iomap
484 */
485 size = resource_size(&dev->res);
486 tmp = ioremap(dev->res.start, size);
96b13f5c
RK
487 if (!tmp) {
488 ret = -ENOMEM;
489 goto err_release;
1da177e4 490 }
96b13f5c 491
7cfe2494
RK
492 ret = amba_get_enable_pclk(dev);
493 if (ret == 0) {
494 u32 pid, cid;
96b13f5c 495
7cfe2494
RK
496 /*
497 * Read pid and cid based on size of resource
498 * they are located at end of region
499 */
500 for (pid = 0, i = 0; i < 4; i++)
501 pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) <<
502 (i * 8);
503 for (cid = 0, i = 0; i < 4; i++)
504 cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
505 (i * 8);
96b13f5c 506
7cfe2494 507 amba_put_disable_pclk(dev);
96b13f5c 508
01723a95 509 if (cid == AMBA_CID)
7cfe2494
RK
510 dev->periphid = pid;
511
512 if (!dev->periphid)
513 ret = -ENODEV;
96b13f5c
RK
514 }
515
7cfe2494
RK
516 iounmap(tmp);
517
518 if (ret)
519 goto err_release;
520
97ceed1f 521 skip_probe:
557dca5f 522 ret = device_add(&dev->dev);
96b13f5c
RK
523 if (ret)
524 goto err_release;
525
dfb85185 526 if (dev->irq[0])
96b13f5c 527 ret = device_create_file(&dev->dev, &dev_attr_irq0);
dfb85185 528 if (ret == 0 && dev->irq[1])
96b13f5c
RK
529 ret = device_create_file(&dev->dev, &dev_attr_irq1);
530 if (ret == 0)
531 return ret;
532
533 device_unregister(&dev->dev);
534
535 err_release:
536 release_resource(&dev->res);
537 err_out:
1da177e4
LT
538 return ret;
539}
d5dc9271
RK
540EXPORT_SYMBOL_GPL(amba_device_add);
541
6026aa90
LW
542static struct amba_device *
543amba_aphb_device_add(struct device *parent, const char *name,
544 resource_size_t base, size_t size, int irq1, int irq2,
3ad909bc
LW
545 void *pdata, unsigned int periphid, u64 dma_mask,
546 struct resource *resbase)
6026aa90
LW
547{
548 struct amba_device *dev;
549 int ret;
550
551 dev = amba_device_alloc(name, base, size);
552 if (!dev)
553 return ERR_PTR(-ENOMEM);
554
555 dev->dma_mask = dma_mask;
556 dev->dev.coherent_dma_mask = dma_mask;
557 dev->irq[0] = irq1;
558 dev->irq[1] = irq2;
559 dev->periphid = periphid;
560 dev->dev.platform_data = pdata;
561 dev->dev.parent = parent;
562
3ad909bc 563 ret = amba_device_add(dev, resbase);
6026aa90
LW
564 if (ret) {
565 amba_device_put(dev);
566 return ERR_PTR(ret);
567 }
568
569 return dev;
570}
571
572struct amba_device *
573amba_apb_device_add(struct device *parent, const char *name,
574 resource_size_t base, size_t size, int irq1, int irq2,
575 void *pdata, unsigned int periphid)
576{
577 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
3ad909bc 578 periphid, 0, &iomem_resource);
6026aa90
LW
579}
580EXPORT_SYMBOL_GPL(amba_apb_device_add);
581
582struct amba_device *
583amba_ahb_device_add(struct device *parent, const char *name,
584 resource_size_t base, size_t size, int irq1, int irq2,
585 void *pdata, unsigned int periphid)
586{
587 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
3ad909bc 588 periphid, ~0ULL, &iomem_resource);
6026aa90
LW
589}
590EXPORT_SYMBOL_GPL(amba_ahb_device_add);
591
3ad909bc
LW
592struct amba_device *
593amba_apb_device_add_res(struct device *parent, const char *name,
594 resource_size_t base, size_t size, int irq1,
595 int irq2, void *pdata, unsigned int periphid,
596 struct resource *resbase)
597{
598 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
599 periphid, 0, resbase);
600}
601EXPORT_SYMBOL_GPL(amba_apb_device_add_res);
602
603struct amba_device *
604amba_ahb_device_add_res(struct device *parent, const char *name,
605 resource_size_t base, size_t size, int irq1,
606 int irq2, void *pdata, unsigned int periphid,
607 struct resource *resbase)
608{
609 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
610 periphid, ~0ULL, resbase);
611}
612EXPORT_SYMBOL_GPL(amba_ahb_device_add_res);
613
614
d5dc9271
RK
615static void amba_device_initialize(struct amba_device *dev, const char *name)
616{
617 device_initialize(&dev->dev);
618 if (name)
619 dev_set_name(&dev->dev, "%s", name);
620 dev->dev.release = amba_device_release;
621 dev->dev.bus = &amba_bustype;
622 dev->dev.dma_mask = &dev->dma_mask;
623 dev->res.name = dev_name(&dev->dev);
624}
625
626/**
627 * amba_device_alloc - allocate an AMBA device
628 * @name: sysfs name of the AMBA device
629 * @base: base of AMBA device
630 * @size: size of AMBA device
631 *
632 * Allocate and initialize an AMBA device structure. Returns %NULL
633 * on failure.
634 */
635struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
636 size_t size)
637{
638 struct amba_device *dev;
639
640 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
641 if (dev) {
642 amba_device_initialize(dev, name);
643 dev->res.start = base;
644 dev->res.end = base + size - 1;
645 dev->res.flags = IORESOURCE_MEM;
646 }
647
648 return dev;
649}
650EXPORT_SYMBOL_GPL(amba_device_alloc);
651
652/**
653 * amba_device_register - register an AMBA device
654 * @dev: AMBA device to register
655 * @parent: parent memory resource
656 *
657 * Setup the AMBA device, reading the cell ID if present.
658 * Claim the resource, and register the AMBA device with
659 * the Linux device manager.
660 */
661int amba_device_register(struct amba_device *dev, struct resource *parent)
662{
663 amba_device_initialize(dev, dev->dev.init_name);
664 dev->dev.init_name = NULL;
665
666 if (!dev->dev.coherent_dma_mask && dev->dma_mask)
667 dev_warn(&dev->dev, "coherent dma mask is unset\n");
668
669 return amba_device_add(dev, parent);
670}
671
672/**
673 * amba_device_put - put an AMBA device
674 * @dev: AMBA device to put
675 */
676void amba_device_put(struct amba_device *dev)
677{
678 put_device(&dev->dev);
679}
680EXPORT_SYMBOL_GPL(amba_device_put);
1da177e4
LT
681
682/**
683 * amba_device_unregister - unregister an AMBA device
684 * @dev: AMBA device to remove
685 *
686 * Remove the specified AMBA device from the Linux device
687 * manager. All files associated with this object will be
688 * destroyed, and device drivers notified that the device has
689 * been removed. The AMBA device's resources including
690 * the amba_device structure will be freed once all
691 * references to it have been dropped.
692 */
693void amba_device_unregister(struct amba_device *dev)
694{
695 device_unregister(&dev->dev);
696}
697
698
699struct find_data {
700 struct amba_device *dev;
701 struct device *parent;
702 const char *busid;
703 unsigned int id;
704 unsigned int mask;
705};
706
707static int amba_find_match(struct device *dev, void *data)
708{
709 struct find_data *d = data;
710 struct amba_device *pcdev = to_amba_device(dev);
711 int r;
712
713 r = (pcdev->periphid & d->mask) == d->id;
714 if (d->parent)
715 r &= d->parent == dev->parent;
716 if (d->busid)
9d6b4c82 717 r &= strcmp(dev_name(dev), d->busid) == 0;
1da177e4
LT
718
719 if (r) {
720 get_device(dev);
721 d->dev = pcdev;
722 }
723
724 return r;
725}
726
727/**
728 * amba_find_device - locate an AMBA device given a bus id
729 * @busid: bus id for device (or NULL)
730 * @parent: parent device (or NULL)
731 * @id: peripheral ID (or 0)
732 * @mask: peripheral ID mask (or 0)
733 *
734 * Return the AMBA device corresponding to the supplied parameters.
735 * If no device matches, returns NULL.
736 *
737 * NOTE: When a valid device is found, its refcount is
738 * incremented, and must be decremented before the returned
739 * reference.
740 */
741struct amba_device *
742amba_find_device(const char *busid, struct device *parent, unsigned int id,
743 unsigned int mask)
744{
745 struct find_data data;
746
747 data.dev = NULL;
748 data.parent = parent;
749 data.busid = busid;
750 data.id = id;
751 data.mask = mask;
752
753 bus_for_each_dev(&amba_bustype, NULL, &data, amba_find_match);
754
755 return data.dev;
756}
757
758/**
759 * amba_request_regions - request all mem regions associated with device
760 * @dev: amba_device structure for device
761 * @name: name, or NULL to use driver name
762 */
763int amba_request_regions(struct amba_device *dev, const char *name)
764{
765 int ret = 0;
8afe0b96 766 u32 size;
1da177e4
LT
767
768 if (!name)
769 name = dev->dev.driver->name;
770
8afe0b96
LC
771 size = resource_size(&dev->res);
772
773 if (!request_mem_region(dev->res.start, size, name))
1da177e4
LT
774 ret = -EBUSY;
775
776 return ret;
777}
778
779/**
25985edc 780 * amba_release_regions - release mem regions associated with device
1da177e4
LT
781 * @dev: amba_device structure for device
782 *
783 * Release regions claimed by a successful call to amba_request_regions.
784 */
785void amba_release_regions(struct amba_device *dev)
786{
8afe0b96
LC
787 u32 size;
788
789 size = resource_size(&dev->res);
790 release_mem_region(dev->res.start, size);
1da177e4
LT
791}
792
793EXPORT_SYMBOL(amba_driver_register);
794EXPORT_SYMBOL(amba_driver_unregister);
795EXPORT_SYMBOL(amba_device_register);
796EXPORT_SYMBOL(amba_device_unregister);
797EXPORT_SYMBOL(amba_find_device);
798EXPORT_SYMBOL(amba_request_regions);
799EXPORT_SYMBOL(amba_release_regions);
This page took 0.708637 seconds and 5 git commands to generate.