blob: b90dc1ec109d9157834e40fa5ae57802208debdc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Tim Schmielau4e57b682005-10-30 15:03:48 -080013#include <linux/string.h>
14#include <linux/slab.h>
Russell King934848d2009-01-08 09:58:51 +000015#include <linux/io.h>
Rabin Vincentba74ec72011-02-23 04:33:17 +010016#include <linux/pm.h>
17#include <linux/pm_runtime.h>
Russell Kinga62c80e2006-01-07 13:52:45 +000018#include <linux/amba/bus.h>
Alessandro Rubinia875cfb2012-06-24 12:46:16 +010019#include <linux/sizes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Russell King934848d2009-01-08 09:58:51 +000021#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#define to_amba_driver(d) container_of(d, struct amba_driver, drv)
24
Russell Kingc862aab2011-02-19 15:55:26 +000025static const struct amba_id *
26amba_lookup(const struct amba_id *table, struct amba_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
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
Kay Sievers7eff2e72007-08-14 15:15:12 +020048static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 struct amba_device *pcdev = to_amba_device(dev);
Kay Sievers7eff2e72007-08-14 15:15:12 +020051 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Kay Sievers7eff2e72007-08-14 15:15:12 +020053 retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid);
Dave Martin523817b2011-10-05 14:44:57 +010054 if (retval)
55 return retval;
56
57 retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid);
Eric Rannaudbf624562007-03-30 22:23:12 -070058 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Russell King96b13f52006-11-30 14:04:49 +000061#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
Russell King92b97f02011-08-14 09:13:48 +010086#ifdef CONFIG_PM_RUNTIME
87/*
88 * Hooks to provide runtime PM of the pclk (bus clock). It is safe to
89 * enable/disable the bus clock at runtime PM suspend/resume as this
Mark Brown1e458602012-04-13 13:11:50 +010090 * does not result in loss of context.
Russell King92b97f02011-08-14 09:13:48 +010091 */
92static int amba_pm_runtime_suspend(struct device *dev)
93{
94 struct amba_device *pcdev = to_amba_device(dev);
95 int ret = pm_generic_runtime_suspend(dev);
96
97 if (ret == 0 && dev->driver)
98 clk_disable(pcdev->pclk);
99
100 return ret;
101}
102
103static int amba_pm_runtime_resume(struct device *dev)
104{
105 struct amba_device *pcdev = to_amba_device(dev);
106 int ret;
107
108 if (dev->driver) {
109 ret = clk_enable(pcdev->pclk);
110 /* Failure is probably fatal to the system, but... */
111 if (ret)
112 return ret;
113 }
114
115 return pm_generic_runtime_resume(dev);
116}
117#endif
118
Rabin Vincentba74ec72011-02-23 04:33:17 +0100119static const struct dev_pm_ops amba_pm = {
Ulf Hansson26825cf2013-12-09 10:38:20 +0100120 .suspend = pm_generic_suspend,
121 .resume = pm_generic_resume,
122 .freeze = pm_generic_freeze,
123 .thaw = pm_generic_thaw,
124 .poweroff = pm_generic_poweroff,
125 .restore = pm_generic_restore,
Rabin Vincentba74ec72011-02-23 04:33:17 +0100126 SET_RUNTIME_PM_OPS(
Russell King92b97f02011-08-14 09:13:48 +0100127 amba_pm_runtime_suspend,
128 amba_pm_runtime_resume,
Rafael J. Wysocki45f0a852013-06-03 21:49:52 +0200129 NULL
Rabin Vincentba74ec72011-02-23 04:33:17 +0100130 )
131};
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/*
134 * Primecells are part of the Advanced Microcontroller Bus Architecture,
135 * so we call the bus "amba".
136 */
Rob Herring394d5ae2011-02-12 15:58:25 +0100137struct bus_type amba_bustype = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .name = "amba",
Russell King96b13f52006-11-30 14:04:49 +0000139 .dev_attrs = amba_dev_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .match = amba_match,
Paul Jackson6d20b032005-11-25 20:04:26 -0800141 .uevent = amba_uevent,
Ulf Hansson26825cf2013-12-09 10:38:20 +0100142 .pm = &amba_pm,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143};
144
145static int __init amba_init(void)
146{
147 return bus_register(&amba_bustype);
148}
149
150postcore_initcall(amba_init);
151
Russell King7cfe2492010-07-15 10:47:14 +0100152static int amba_get_enable_pclk(struct amba_device *pcdev)
153{
154 struct clk *pclk = clk_get(&pcdev->dev, "apb_pclk");
155 int ret;
156
157 pcdev->pclk = pclk;
158
159 if (IS_ERR(pclk))
160 return PTR_ERR(pclk);
161
Russell Kingac3e2fa2011-09-22 12:20:55 +0100162 ret = clk_prepare(pclk);
163 if (ret) {
Russell King7cfe2492010-07-15 10:47:14 +0100164 clk_put(pclk);
Russell Kingac3e2fa2011-09-22 12:20:55 +0100165 return ret;
166 }
167
168 ret = clk_enable(pclk);
169 if (ret) {
170 clk_unprepare(pclk);
171 clk_put(pclk);
172 }
Russell King7cfe2492010-07-15 10:47:14 +0100173
174 return ret;
175}
176
177static void amba_put_disable_pclk(struct amba_device *pcdev)
178{
179 struct clk *pclk = pcdev->pclk;
180
181 clk_disable(pclk);
Russell Kingac3e2fa2011-09-22 12:20:55 +0100182 clk_unprepare(pclk);
Russell King7cfe2492010-07-15 10:47:14 +0100183 clk_put(pclk);
184}
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/*
187 * These are the device model conversion veneers; they convert the
188 * device model structures to our more specific structures.
189 */
190static int amba_probe(struct device *dev)
191{
192 struct amba_device *pcdev = to_amba_device(dev);
193 struct amba_driver *pcdrv = to_amba_driver(dev->driver);
Russell Kingc862aab2011-02-19 15:55:26 +0000194 const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
Russell King7cfe2492010-07-15 10:47:14 +0100195 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Russell King7cfe2492010-07-15 10:47:14 +0100197 do {
198 ret = amba_get_enable_pclk(pcdev);
199 if (ret)
200 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Russell King92b97f02011-08-14 09:13:48 +0100202 pm_runtime_get_noresume(dev);
203 pm_runtime_set_active(dev);
204 pm_runtime_enable(dev);
205
Russell King7cfe2492010-07-15 10:47:14 +0100206 ret = pcdrv->probe(pcdev, id);
207 if (ret == 0)
208 break;
209
Russell King92b97f02011-08-14 09:13:48 +0100210 pm_runtime_disable(dev);
211 pm_runtime_set_suspended(dev);
212 pm_runtime_put_noidle(dev);
213
Russell King7cfe2492010-07-15 10:47:14 +0100214 amba_put_disable_pclk(pcdev);
215 } while (0);
216
217 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
219
220static int amba_remove(struct device *dev)
221{
Russell King7cfe2492010-07-15 10:47:14 +0100222 struct amba_device *pcdev = to_amba_device(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 struct amba_driver *drv = to_amba_driver(dev->driver);
Russell King92b97f02011-08-14 09:13:48 +0100224 int ret;
225
226 pm_runtime_get_sync(dev);
227 ret = drv->remove(pcdev);
228 pm_runtime_put_noidle(dev);
229
230 /* Undo the runtime PM settings in amba_probe() */
231 pm_runtime_disable(dev);
232 pm_runtime_set_suspended(dev);
233 pm_runtime_put_noidle(dev);
Russell King7cfe2492010-07-15 10:47:14 +0100234
235 amba_put_disable_pclk(pcdev);
236
237 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
240static void amba_shutdown(struct device *dev)
241{
242 struct amba_driver *drv = to_amba_driver(dev->driver);
243 drv->shutdown(to_amba_device(dev));
244}
245
246/**
247 * amba_driver_register - register an AMBA device driver
248 * @drv: amba device driver structure
249 *
250 * Register an AMBA device driver with the Linux device model
251 * core. If devices pre-exist, the drivers probe function will
252 * be called.
253 */
254int amba_driver_register(struct amba_driver *drv)
255{
256 drv->drv.bus = &amba_bustype;
257
258#define SETFN(fn) if (drv->fn) drv->drv.fn = amba_##fn
259 SETFN(probe);
260 SETFN(remove);
261 SETFN(shutdown);
262
263 return driver_register(&drv->drv);
264}
265
266/**
267 * amba_driver_unregister - remove an AMBA device driver
268 * @drv: AMBA device driver structure to remove
269 *
270 * Unregister an AMBA device driver from the Linux device
271 * model. The device model will call the drivers remove function
272 * for each device the device driver is currently handling.
273 */
274void amba_driver_unregister(struct amba_driver *drv)
275{
276 driver_unregister(&drv->drv);
277}
278
279
280static void amba_device_release(struct device *dev)
281{
282 struct amba_device *d = to_amba_device(dev);
283
284 if (d->res.parent)
285 release_resource(&d->res);
286 kfree(d);
287}
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289/**
Russell Kingd5dc9272011-12-18 11:07:47 +0000290 * amba_device_add - add a previously allocated AMBA device structure
291 * @dev: AMBA device allocated by amba_device_alloc
292 * @parent: resource parent for this devices resources
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 *
Russell Kingd5dc9272011-12-18 11:07:47 +0000294 * Claim the resource, and read the device cell ID if not already
295 * initialized. Register the AMBA device with the Linux device
296 * manager.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 */
Russell Kingd5dc9272011-12-18 11:07:47 +0000298int amba_device_add(struct amba_device *dev, struct resource *parent)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Leo Chen8afe0b92009-07-28 23:34:59 +0100300 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 void __iomem *tmp;
302 int i, ret;
303
Russell King2eac58d2011-12-18 11:43:56 +0000304 WARN_ON(dev->irq[0] == (unsigned int)-1);
305 WARN_ON(dev->irq[1] == (unsigned int)-1);
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 ret = request_resource(parent, &dev->res);
Russell King96b13f52006-11-30 14:04:49 +0000308 if (ret)
309 goto err_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Linus Walleij97ceed12011-03-24 16:12:40 +0100311 /* Hard-coded primecell ID instead of plug-n-play */
312 if (dev->periphid != 0)
313 goto skip_probe;
314
Leo Chen8afe0b92009-07-28 23:34:59 +0100315 /*
316 * Dynamically calculate the size of the resource
317 * and use this for iomap
318 */
319 size = resource_size(&dev->res);
320 tmp = ioremap(dev->res.start, size);
Russell King96b13f52006-11-30 14:04:49 +0000321 if (!tmp) {
322 ret = -ENOMEM;
323 goto err_release;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 }
Russell King96b13f52006-11-30 14:04:49 +0000325
Russell King7cfe2492010-07-15 10:47:14 +0100326 ret = amba_get_enable_pclk(dev);
327 if (ret == 0) {
328 u32 pid, cid;
329
330 /*
331 * Read pid and cid based on size of resource
332 * they are located at end of region
333 */
334 for (pid = 0, i = 0; i < 4; i++)
335 pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) <<
336 (i * 8);
337 for (cid = 0, i = 0; i < 4; i++)
338 cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
339 (i * 8);
340
341 amba_put_disable_pclk(dev);
342
Linus Walleij01723a92010-09-07 22:43:19 +0100343 if (cid == AMBA_CID)
Russell King7cfe2492010-07-15 10:47:14 +0100344 dev->periphid = pid;
345
346 if (!dev->periphid)
347 ret = -ENODEV;
348 }
Russell King96b13f52006-11-30 14:04:49 +0000349
350 iounmap(tmp);
351
Russell King7cfe2492010-07-15 10:47:14 +0100352 if (ret)
Russell King96b13f52006-11-30 14:04:49 +0000353 goto err_release;
Russell King96b13f52006-11-30 14:04:49 +0000354
Linus Walleij97ceed12011-03-24 16:12:40 +0100355 skip_probe:
Russell King557dca52009-07-05 22:39:08 +0100356 ret = device_add(&dev->dev);
Russell King96b13f52006-11-30 14:04:49 +0000357 if (ret)
358 goto err_release;
359
Russell Kingdfb85182012-05-03 11:33:15 +0100360 if (dev->irq[0])
Russell King96b13f52006-11-30 14:04:49 +0000361 ret = device_create_file(&dev->dev, &dev_attr_irq0);
Russell Kingdfb85182012-05-03 11:33:15 +0100362 if (ret == 0 && dev->irq[1])
Russell King96b13f52006-11-30 14:04:49 +0000363 ret = device_create_file(&dev->dev, &dev_attr_irq1);
364 if (ret == 0)
365 return ret;
366
367 device_unregister(&dev->dev);
368
369 err_release:
370 release_resource(&dev->res);
371 err_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 return ret;
373}
Russell Kingd5dc9272011-12-18 11:07:47 +0000374EXPORT_SYMBOL_GPL(amba_device_add);
375
Linus Walleij6026aa92012-04-03 11:58:42 +0100376static struct amba_device *
377amba_aphb_device_add(struct device *parent, const char *name,
378 resource_size_t base, size_t size, int irq1, int irq2,
Linus Walleij3ad909b2012-11-30 16:30:43 +0100379 void *pdata, unsigned int periphid, u64 dma_mask,
380 struct resource *resbase)
Linus Walleij6026aa92012-04-03 11:58:42 +0100381{
382 struct amba_device *dev;
383 int ret;
384
385 dev = amba_device_alloc(name, base, size);
386 if (!dev)
387 return ERR_PTR(-ENOMEM);
388
Linus Walleij6026aa92012-04-03 11:58:42 +0100389 dev->dev.coherent_dma_mask = dma_mask;
390 dev->irq[0] = irq1;
391 dev->irq[1] = irq2;
392 dev->periphid = periphid;
393 dev->dev.platform_data = pdata;
394 dev->dev.parent = parent;
395
Linus Walleij3ad909b2012-11-30 16:30:43 +0100396 ret = amba_device_add(dev, resbase);
Linus Walleij6026aa92012-04-03 11:58:42 +0100397 if (ret) {
398 amba_device_put(dev);
399 return ERR_PTR(ret);
400 }
401
402 return dev;
403}
404
405struct amba_device *
406amba_apb_device_add(struct device *parent, const char *name,
407 resource_size_t base, size_t size, int irq1, int irq2,
408 void *pdata, unsigned int periphid)
409{
410 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
Linus Walleij3ad909b2012-11-30 16:30:43 +0100411 periphid, 0, &iomem_resource);
Linus Walleij6026aa92012-04-03 11:58:42 +0100412}
413EXPORT_SYMBOL_GPL(amba_apb_device_add);
414
415struct amba_device *
416amba_ahb_device_add(struct device *parent, const char *name,
417 resource_size_t base, size_t size, int irq1, int irq2,
418 void *pdata, unsigned int periphid)
419{
420 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
Linus Walleij3ad909b2012-11-30 16:30:43 +0100421 periphid, ~0ULL, &iomem_resource);
Linus Walleij6026aa92012-04-03 11:58:42 +0100422}
423EXPORT_SYMBOL_GPL(amba_ahb_device_add);
424
Linus Walleij3ad909b2012-11-30 16:30:43 +0100425struct amba_device *
426amba_apb_device_add_res(struct device *parent, const char *name,
427 resource_size_t base, size_t size, int irq1,
428 int irq2, void *pdata, unsigned int periphid,
429 struct resource *resbase)
430{
431 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
432 periphid, 0, resbase);
433}
434EXPORT_SYMBOL_GPL(amba_apb_device_add_res);
435
436struct amba_device *
437amba_ahb_device_add_res(struct device *parent, const char *name,
438 resource_size_t base, size_t size, int irq1,
439 int irq2, void *pdata, unsigned int periphid,
440 struct resource *resbase)
441{
442 return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
443 periphid, ~0ULL, resbase);
444}
445EXPORT_SYMBOL_GPL(amba_ahb_device_add_res);
446
447
Russell Kingd5dc9272011-12-18 11:07:47 +0000448static void amba_device_initialize(struct amba_device *dev, const char *name)
449{
450 device_initialize(&dev->dev);
451 if (name)
452 dev_set_name(&dev->dev, "%s", name);
453 dev->dev.release = amba_device_release;
454 dev->dev.bus = &amba_bustype;
Russell King446b2a92013-06-27 10:25:33 +0100455 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
Russell Kingd5dc9272011-12-18 11:07:47 +0000456 dev->res.name = dev_name(&dev->dev);
457}
458
459/**
460 * amba_device_alloc - allocate an AMBA device
461 * @name: sysfs name of the AMBA device
462 * @base: base of AMBA device
463 * @size: size of AMBA device
464 *
465 * Allocate and initialize an AMBA device structure. Returns %NULL
466 * on failure.
467 */
468struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
469 size_t size)
470{
471 struct amba_device *dev;
472
473 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
474 if (dev) {
475 amba_device_initialize(dev, name);
476 dev->res.start = base;
477 dev->res.end = base + size - 1;
478 dev->res.flags = IORESOURCE_MEM;
479 }
480
481 return dev;
482}
483EXPORT_SYMBOL_GPL(amba_device_alloc);
484
485/**
486 * amba_device_register - register an AMBA device
487 * @dev: AMBA device to register
488 * @parent: parent memory resource
489 *
490 * Setup the AMBA device, reading the cell ID if present.
491 * Claim the resource, and register the AMBA device with
492 * the Linux device manager.
493 */
494int amba_device_register(struct amba_device *dev, struct resource *parent)
495{
496 amba_device_initialize(dev, dev->dev.init_name);
497 dev->dev.init_name = NULL;
498
Russell Kingd5dc9272011-12-18 11:07:47 +0000499 return amba_device_add(dev, parent);
500}
501
502/**
503 * amba_device_put - put an AMBA device
504 * @dev: AMBA device to put
505 */
506void amba_device_put(struct amba_device *dev)
507{
508 put_device(&dev->dev);
509}
510EXPORT_SYMBOL_GPL(amba_device_put);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512/**
513 * amba_device_unregister - unregister an AMBA device
514 * @dev: AMBA device to remove
515 *
516 * Remove the specified AMBA device from the Linux device
517 * manager. All files associated with this object will be
518 * destroyed, and device drivers notified that the device has
519 * been removed. The AMBA device's resources including
520 * the amba_device structure will be freed once all
521 * references to it have been dropped.
522 */
523void amba_device_unregister(struct amba_device *dev)
524{
525 device_unregister(&dev->dev);
526}
527
528
529struct find_data {
530 struct amba_device *dev;
531 struct device *parent;
532 const char *busid;
533 unsigned int id;
534 unsigned int mask;
535};
536
537static int amba_find_match(struct device *dev, void *data)
538{
539 struct find_data *d = data;
540 struct amba_device *pcdev = to_amba_device(dev);
541 int r;
542
543 r = (pcdev->periphid & d->mask) == d->id;
544 if (d->parent)
545 r &= d->parent == dev->parent;
546 if (d->busid)
Kay Sievers9d6b4c82009-03-24 16:38:22 -0700547 r &= strcmp(dev_name(dev), d->busid) == 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 if (r) {
550 get_device(dev);
551 d->dev = pcdev;
552 }
553
554 return r;
555}
556
557/**
558 * amba_find_device - locate an AMBA device given a bus id
559 * @busid: bus id for device (or NULL)
560 * @parent: parent device (or NULL)
561 * @id: peripheral ID (or 0)
562 * @mask: peripheral ID mask (or 0)
563 *
564 * Return the AMBA device corresponding to the supplied parameters.
565 * If no device matches, returns NULL.
566 *
567 * NOTE: When a valid device is found, its refcount is
568 * incremented, and must be decremented before the returned
569 * reference.
570 */
571struct amba_device *
572amba_find_device(const char *busid, struct device *parent, unsigned int id,
573 unsigned int mask)
574{
575 struct find_data data;
576
577 data.dev = NULL;
578 data.parent = parent;
579 data.busid = busid;
580 data.id = id;
581 data.mask = mask;
582
583 bus_for_each_dev(&amba_bustype, NULL, &data, amba_find_match);
584
585 return data.dev;
586}
587
588/**
589 * amba_request_regions - request all mem regions associated with device
590 * @dev: amba_device structure for device
591 * @name: name, or NULL to use driver name
592 */
593int amba_request_regions(struct amba_device *dev, const char *name)
594{
595 int ret = 0;
Leo Chen8afe0b92009-07-28 23:34:59 +0100596 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598 if (!name)
599 name = dev->dev.driver->name;
600
Leo Chen8afe0b92009-07-28 23:34:59 +0100601 size = resource_size(&dev->res);
602
603 if (!request_mem_region(dev->res.start, size, name))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 ret = -EBUSY;
605
606 return ret;
607}
608
609/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300610 * amba_release_regions - release mem regions associated with device
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 * @dev: amba_device structure for device
612 *
613 * Release regions claimed by a successful call to amba_request_regions.
614 */
615void amba_release_regions(struct amba_device *dev)
616{
Leo Chen8afe0b92009-07-28 23:34:59 +0100617 u32 size;
618
619 size = resource_size(&dev->res);
620 release_mem_region(dev->res.start, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
623EXPORT_SYMBOL(amba_driver_register);
624EXPORT_SYMBOL(amba_driver_unregister);
625EXPORT_SYMBOL(amba_device_register);
626EXPORT_SYMBOL(amba_device_unregister);
627EXPORT_SYMBOL(amba_find_device);
628EXPORT_SYMBOL(amba_request_regions);
629EXPORT_SYMBOL(amba_release_regions);