bus.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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>
  13. #include <linux/string.h>
  14. #include <linux/slab.h>
  15. #include <linux/io.h>
  16. #include <linux/pm.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/pm_domain.h>
  19. #include <linux/amba/bus.h>
  20. #include <linux/sizes.h>
  21. #include <linux/limits.h>
  22. #include <asm/irq.h>
  23. #define to_amba_driver(d) container_of(d, struct amba_driver, drv)
  24. static const struct amba_id *
  25. amba_lookup(const struct amba_id *table, struct amba_device *dev)
  26. {
  27. int ret = 0;
  28. while (table->mask) {
  29. ret = (dev->periphid & table->mask) == table->id;
  30. if (ret)
  31. break;
  32. table++;
  33. }
  34. return ret ? table : NULL;
  35. }
  36. static int amba_match(struct device *dev, struct device_driver *drv)
  37. {
  38. struct amba_device *pcdev = to_amba_device(dev);
  39. struct amba_driver *pcdrv = to_amba_driver(drv);
  40. /* When driver_override is set, only bind to the matching driver */
  41. if (pcdev->driver_override)
  42. return !strcmp(pcdev->driver_override, drv->name);
  43. return amba_lookup(pcdrv->id_table, pcdev) != NULL;
  44. }
  45. static int amba_uevent(struct device *dev, struct kobj_uevent_env *env)
  46. {
  47. struct amba_device *pcdev = to_amba_device(dev);
  48. int retval = 0;
  49. retval = add_uevent_var(env, "AMBA_ID=%08x", pcdev->periphid);
  50. if (retval)
  51. return retval;
  52. retval = add_uevent_var(env, "MODALIAS=amba:d%08X", pcdev->periphid);
  53. return retval;
  54. }
  55. static ssize_t driver_override_show(struct device *_dev,
  56. struct device_attribute *attr, char *buf)
  57. {
  58. struct amba_device *dev = to_amba_device(_dev);
  59. if (!dev->driver_override)
  60. return 0;
  61. return sprintf(buf, "%s\n", dev->driver_override);
  62. }
  63. static ssize_t driver_override_store(struct device *_dev,
  64. struct device_attribute *attr,
  65. const char *buf, size_t count)
  66. {
  67. struct amba_device *dev = to_amba_device(_dev);
  68. char *driver_override, *old = dev->driver_override, *cp;
  69. if (count > PATH_MAX)
  70. return -EINVAL;
  71. driver_override = kstrndup(buf, count, GFP_KERNEL);
  72. if (!driver_override)
  73. return -ENOMEM;
  74. cp = strchr(driver_override, '\n');
  75. if (cp)
  76. *cp = '\0';
  77. if (strlen(driver_override)) {
  78. dev->driver_override = driver_override;
  79. } else {
  80. kfree(driver_override);
  81. dev->driver_override = NULL;
  82. }
  83. kfree(old);
  84. return count;
  85. }
  86. #define amba_attr_func(name,fmt,arg...) \
  87. static ssize_t name##_show(struct device *_dev, \
  88. struct device_attribute *attr, char *buf) \
  89. { \
  90. struct amba_device *dev = to_amba_device(_dev); \
  91. return sprintf(buf, fmt, arg); \
  92. }
  93. #define amba_attr(name,fmt,arg...) \
  94. amba_attr_func(name,fmt,arg) \
  95. static DEVICE_ATTR(name, S_IRUGO, name##_show, NULL)
  96. amba_attr_func(id, "%08x\n", dev->periphid);
  97. amba_attr(irq0, "%u\n", dev->irq[0]);
  98. amba_attr(irq1, "%u\n", dev->irq[1]);
  99. amba_attr_func(resource, "\t%016llx\t%016llx\t%016lx\n",
  100. (unsigned long long)dev->res.start, (unsigned long long)dev->res.end,
  101. dev->res.flags);
  102. static struct device_attribute amba_dev_attrs[] = {
  103. __ATTR_RO(id),
  104. __ATTR_RO(resource),
  105. __ATTR_RW(driver_override),
  106. __ATTR_NULL,
  107. };
  108. #ifdef CONFIG_PM
  109. /*
  110. * Hooks to provide runtime PM of the pclk (bus clock). It is safe to
  111. * enable/disable the bus clock at runtime PM suspend/resume as this
  112. * does not result in loss of context.
  113. */
  114. static int amba_pm_runtime_suspend(struct device *dev)
  115. {
  116. struct amba_device *pcdev = to_amba_device(dev);
  117. int ret = pm_generic_runtime_suspend(dev);
  118. if (ret == 0 && dev->driver) {
  119. if (pm_runtime_is_irq_safe(dev))
  120. clk_disable(pcdev->pclk);
  121. else
  122. clk_disable_unprepare(pcdev->pclk);
  123. }
  124. return ret;
  125. }
  126. static int amba_pm_runtime_resume(struct device *dev)
  127. {
  128. struct amba_device *pcdev = to_amba_device(dev);
  129. int ret;
  130. if (dev->driver) {
  131. if (pm_runtime_is_irq_safe(dev))
  132. ret = clk_enable(pcdev->pclk);
  133. else
  134. ret = clk_prepare_enable(pcdev->pclk);
  135. /* Failure is probably fatal to the system, but... */
  136. if (ret)
  137. return ret;
  138. }
  139. return pm_generic_runtime_resume(dev);
  140. }
  141. #endif /* CONFIG_PM */
  142. static const struct dev_pm_ops amba_pm = {
  143. .suspend = pm_generic_suspend,
  144. .resume = pm_generic_resume,
  145. .freeze = pm_generic_freeze,
  146. .thaw = pm_generic_thaw,
  147. .poweroff = pm_generic_poweroff,
  148. .restore = pm_generic_restore,
  149. SET_RUNTIME_PM_OPS(
  150. amba_pm_runtime_suspend,
  151. amba_pm_runtime_resume,
  152. NULL
  153. )
  154. };
  155. /*
  156. * Primecells are part of the Advanced Microcontroller Bus Architecture,
  157. * so we call the bus "amba".
  158. */
  159. struct bus_type amba_bustype = {
  160. .name = "amba",
  161. .dev_attrs = amba_dev_attrs,
  162. .match = amba_match,
  163. .uevent = amba_uevent,
  164. .pm = &amba_pm,
  165. };
  166. static int __init amba_init(void)
  167. {
  168. return bus_register(&amba_bustype);
  169. }
  170. postcore_initcall(amba_init);
  171. static int amba_get_enable_pclk(struct amba_device *pcdev)
  172. {
  173. int ret;
  174. pcdev->pclk = clk_get(&pcdev->dev, "apb_pclk");
  175. if (IS_ERR(pcdev->pclk))
  176. return PTR_ERR(pcdev->pclk);
  177. ret = clk_prepare_enable(pcdev->pclk);
  178. if (ret)
  179. clk_put(pcdev->pclk);
  180. return ret;
  181. }
  182. static void amba_put_disable_pclk(struct amba_device *pcdev)
  183. {
  184. clk_disable_unprepare(pcdev->pclk);
  185. clk_put(pcdev->pclk);
  186. }
  187. /*
  188. * These are the device model conversion veneers; they convert the
  189. * device model structures to our more specific structures.
  190. */
  191. static int amba_probe(struct device *dev)
  192. {
  193. struct amba_device *pcdev = to_amba_device(dev);
  194. struct amba_driver *pcdrv = to_amba_driver(dev->driver);
  195. const struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
  196. int ret;
  197. do {
  198. ret = dev_pm_domain_attach(dev, true);
  199. if (ret == -EPROBE_DEFER)
  200. break;
  201. ret = amba_get_enable_pclk(pcdev);
  202. if (ret) {
  203. dev_pm_domain_detach(dev, true);
  204. break;
  205. }
  206. pm_runtime_get_noresume(dev);
  207. pm_runtime_set_active(dev);
  208. pm_runtime_enable(dev);
  209. ret = pcdrv->probe(pcdev, id);
  210. if (ret == 0)
  211. break;
  212. pm_runtime_disable(dev);
  213. pm_runtime_set_suspended(dev);
  214. pm_runtime_put_noidle(dev);
  215. amba_put_disable_pclk(pcdev);
  216. dev_pm_domain_detach(dev, true);
  217. } while (0);
  218. return ret;
  219. }
  220. static int amba_remove(struct device *dev)
  221. {
  222. struct amba_device *pcdev = to_amba_device(dev);
  223. struct amba_driver *drv = to_amba_driver(dev->driver);
  224. int ret;
  225. pm_runtime_get_sync(dev);
  226. ret = drv->remove(pcdev);
  227. pm_runtime_put_noidle(dev);
  228. /* Undo the runtime PM settings in amba_probe() */
  229. pm_runtime_disable(dev);
  230. pm_runtime_set_suspended(dev);
  231. pm_runtime_put_noidle(dev);
  232. amba_put_disable_pclk(pcdev);
  233. dev_pm_domain_detach(dev, true);
  234. return ret;
  235. }
  236. static void amba_shutdown(struct device *dev)
  237. {
  238. struct amba_driver *drv = to_amba_driver(dev->driver);
  239. drv->shutdown(to_amba_device(dev));
  240. }
  241. /**
  242. * amba_driver_register - register an AMBA device driver
  243. * @drv: amba device driver structure
  244. *
  245. * Register an AMBA device driver with the Linux device model
  246. * core. If devices pre-exist, the drivers probe function will
  247. * be called.
  248. */
  249. int amba_driver_register(struct amba_driver *drv)
  250. {
  251. drv->drv.bus = &amba_bustype;
  252. #define SETFN(fn) if (drv->fn) drv->drv.fn = amba_##fn
  253. SETFN(probe);
  254. SETFN(remove);
  255. SETFN(shutdown);
  256. return driver_register(&drv->drv);
  257. }
  258. /**
  259. * amba_driver_unregister - remove an AMBA device driver
  260. * @drv: AMBA device driver structure to remove
  261. *
  262. * Unregister an AMBA device driver from the Linux device
  263. * model. The device model will call the drivers remove function
  264. * for each device the device driver is currently handling.
  265. */
  266. void amba_driver_unregister(struct amba_driver *drv)
  267. {
  268. driver_unregister(&drv->drv);
  269. }
  270. static void amba_device_release(struct device *dev)
  271. {
  272. struct amba_device *d = to_amba_device(dev);
  273. if (d->res.parent)
  274. release_resource(&d->res);
  275. kfree(d);
  276. }
  277. static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
  278. {
  279. u32 size;
  280. void __iomem *tmp;
  281. int i, ret;
  282. WARN_ON(dev->irq[0] == (unsigned int)-1);
  283. WARN_ON(dev->irq[1] == (unsigned int)-1);
  284. ret = request_resource(parent, &dev->res);
  285. if (ret)
  286. goto err_out;
  287. /* Hard-coded primecell ID instead of plug-n-play */
  288. if (dev->periphid != 0)
  289. goto skip_probe;
  290. /*
  291. * Dynamically calculate the size of the resource
  292. * and use this for iomap
  293. */
  294. size = resource_size(&dev->res);
  295. tmp = ioremap(dev->res.start, size);
  296. if (!tmp) {
  297. ret = -ENOMEM;
  298. goto err_release;
  299. }
  300. ret = dev_pm_domain_attach(&dev->dev, true);
  301. if (ret == -EPROBE_DEFER) {
  302. iounmap(tmp);
  303. goto err_release;
  304. }
  305. ret = amba_get_enable_pclk(dev);
  306. if (ret == 0) {
  307. u32 pid, cid;
  308. /*
  309. * Read pid and cid based on size of resource
  310. * they are located at end of region
  311. */
  312. for (pid = 0, i = 0; i < 4; i++)
  313. pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) <<
  314. (i * 8);
  315. for (cid = 0, i = 0; i < 4; i++)
  316. cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
  317. (i * 8);
  318. amba_put_disable_pclk(dev);
  319. if (cid == AMBA_CID || cid == CORESIGHT_CID)
  320. dev->periphid = pid;
  321. if (!dev->periphid)
  322. ret = -ENODEV;
  323. }
  324. iounmap(tmp);
  325. dev_pm_domain_detach(&dev->dev, true);
  326. if (ret)
  327. goto err_release;
  328. skip_probe:
  329. ret = device_add(&dev->dev);
  330. if (ret)
  331. goto err_release;
  332. if (dev->irq[0])
  333. ret = device_create_file(&dev->dev, &dev_attr_irq0);
  334. if (ret == 0 && dev->irq[1])
  335. ret = device_create_file(&dev->dev, &dev_attr_irq1);
  336. if (ret == 0)
  337. return ret;
  338. device_unregister(&dev->dev);
  339. err_release:
  340. release_resource(&dev->res);
  341. err_out:
  342. return ret;
  343. }
  344. /*
  345. * Registration of AMBA device require reading its pid and cid registers.
  346. * To do this, the device must be turned on (if it is a part of power domain)
  347. * and have clocks enabled. However in some cases those resources might not be
  348. * yet available. Returning EPROBE_DEFER is not a solution in such case,
  349. * because callers don't handle this special error code. Instead such devices
  350. * are added to the special list and their registration is retried from
  351. * periodic worker, until all resources are available and registration succeeds.
  352. */
  353. struct deferred_device {
  354. struct amba_device *dev;
  355. struct resource *parent;
  356. struct list_head node;
  357. };
  358. static LIST_HEAD(deferred_devices);
  359. static DEFINE_MUTEX(deferred_devices_lock);
  360. static void amba_deferred_retry_func(struct work_struct *dummy);
  361. static DECLARE_DELAYED_WORK(deferred_retry_work, amba_deferred_retry_func);
  362. #define DEFERRED_DEVICE_TIMEOUT (msecs_to_jiffies(5 * 1000))
  363. static void amba_deferred_retry_func(struct work_struct *dummy)
  364. {
  365. struct deferred_device *ddev, *tmp;
  366. mutex_lock(&deferred_devices_lock);
  367. list_for_each_entry_safe(ddev, tmp, &deferred_devices, node) {
  368. int ret = amba_device_try_add(ddev->dev, ddev->parent);
  369. if (ret == -EPROBE_DEFER)
  370. continue;
  371. list_del_init(&ddev->node);
  372. kfree(ddev);
  373. }
  374. if (!list_empty(&deferred_devices))
  375. schedule_delayed_work(&deferred_retry_work,
  376. DEFERRED_DEVICE_TIMEOUT);
  377. mutex_unlock(&deferred_devices_lock);
  378. }
  379. /**
  380. * amba_device_add - add a previously allocated AMBA device structure
  381. * @dev: AMBA device allocated by amba_device_alloc
  382. * @parent: resource parent for this devices resources
  383. *
  384. * Claim the resource, and read the device cell ID if not already
  385. * initialized. Register the AMBA device with the Linux device
  386. * manager.
  387. */
  388. int amba_device_add(struct amba_device *dev, struct resource *parent)
  389. {
  390. int ret = amba_device_try_add(dev, parent);
  391. if (ret == -EPROBE_DEFER) {
  392. struct deferred_device *ddev;
  393. ddev = kmalloc(sizeof(*ddev), GFP_KERNEL);
  394. if (!ddev)
  395. return -ENOMEM;
  396. ddev->dev = dev;
  397. ddev->parent = parent;
  398. ret = 0;
  399. mutex_lock(&deferred_devices_lock);
  400. if (list_empty(&deferred_devices))
  401. schedule_delayed_work(&deferred_retry_work,
  402. DEFERRED_DEVICE_TIMEOUT);
  403. list_add_tail(&ddev->node, &deferred_devices);
  404. mutex_unlock(&deferred_devices_lock);
  405. }
  406. return ret;
  407. }
  408. EXPORT_SYMBOL_GPL(amba_device_add);
  409. static struct amba_device *
  410. amba_aphb_device_add(struct device *parent, const char *name,
  411. resource_size_t base, size_t size, int irq1, int irq2,
  412. void *pdata, unsigned int periphid, u64 dma_mask,
  413. struct resource *resbase)
  414. {
  415. struct amba_device *dev;
  416. int ret;
  417. dev = amba_device_alloc(name, base, size);
  418. if (!dev)
  419. return ERR_PTR(-ENOMEM);
  420. dev->dev.coherent_dma_mask = dma_mask;
  421. dev->irq[0] = irq1;
  422. dev->irq[1] = irq2;
  423. dev->periphid = periphid;
  424. dev->dev.platform_data = pdata;
  425. dev->dev.parent = parent;
  426. ret = amba_device_add(dev, resbase);
  427. if (ret) {
  428. amba_device_put(dev);
  429. return ERR_PTR(ret);
  430. }
  431. return dev;
  432. }
  433. struct amba_device *
  434. amba_apb_device_add(struct device *parent, const char *name,
  435. resource_size_t base, size_t size, int irq1, int irq2,
  436. void *pdata, unsigned int periphid)
  437. {
  438. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  439. periphid, 0, &iomem_resource);
  440. }
  441. EXPORT_SYMBOL_GPL(amba_apb_device_add);
  442. struct amba_device *
  443. amba_ahb_device_add(struct device *parent, const char *name,
  444. resource_size_t base, size_t size, int irq1, int irq2,
  445. void *pdata, unsigned int periphid)
  446. {
  447. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  448. periphid, ~0ULL, &iomem_resource);
  449. }
  450. EXPORT_SYMBOL_GPL(amba_ahb_device_add);
  451. struct amba_device *
  452. amba_apb_device_add_res(struct device *parent, const char *name,
  453. resource_size_t base, size_t size, int irq1,
  454. int irq2, void *pdata, unsigned int periphid,
  455. struct resource *resbase)
  456. {
  457. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  458. periphid, 0, resbase);
  459. }
  460. EXPORT_SYMBOL_GPL(amba_apb_device_add_res);
  461. struct amba_device *
  462. amba_ahb_device_add_res(struct device *parent, const char *name,
  463. resource_size_t base, size_t size, int irq1,
  464. int irq2, void *pdata, unsigned int periphid,
  465. struct resource *resbase)
  466. {
  467. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  468. periphid, ~0ULL, resbase);
  469. }
  470. EXPORT_SYMBOL_GPL(amba_ahb_device_add_res);
  471. static void amba_device_initialize(struct amba_device *dev, const char *name)
  472. {
  473. device_initialize(&dev->dev);
  474. if (name)
  475. dev_set_name(&dev->dev, "%s", name);
  476. dev->dev.release = amba_device_release;
  477. dev->dev.bus = &amba_bustype;
  478. dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
  479. dev->res.name = dev_name(&dev->dev);
  480. }
  481. /**
  482. * amba_device_alloc - allocate an AMBA device
  483. * @name: sysfs name of the AMBA device
  484. * @base: base of AMBA device
  485. * @size: size of AMBA device
  486. *
  487. * Allocate and initialize an AMBA device structure. Returns %NULL
  488. * on failure.
  489. */
  490. struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
  491. size_t size)
  492. {
  493. struct amba_device *dev;
  494. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  495. if (dev) {
  496. amba_device_initialize(dev, name);
  497. dev->res.start = base;
  498. dev->res.end = base + size - 1;
  499. dev->res.flags = IORESOURCE_MEM;
  500. }
  501. return dev;
  502. }
  503. EXPORT_SYMBOL_GPL(amba_device_alloc);
  504. /**
  505. * amba_device_register - register an AMBA device
  506. * @dev: AMBA device to register
  507. * @parent: parent memory resource
  508. *
  509. * Setup the AMBA device, reading the cell ID if present.
  510. * Claim the resource, and register the AMBA device with
  511. * the Linux device manager.
  512. */
  513. int amba_device_register(struct amba_device *dev, struct resource *parent)
  514. {
  515. amba_device_initialize(dev, dev->dev.init_name);
  516. dev->dev.init_name = NULL;
  517. return amba_device_add(dev, parent);
  518. }
  519. /**
  520. * amba_device_put - put an AMBA device
  521. * @dev: AMBA device to put
  522. */
  523. void amba_device_put(struct amba_device *dev)
  524. {
  525. put_device(&dev->dev);
  526. }
  527. EXPORT_SYMBOL_GPL(amba_device_put);
  528. /**
  529. * amba_device_unregister - unregister an AMBA device
  530. * @dev: AMBA device to remove
  531. *
  532. * Remove the specified AMBA device from the Linux device
  533. * manager. All files associated with this object will be
  534. * destroyed, and device drivers notified that the device has
  535. * been removed. The AMBA device's resources including
  536. * the amba_device structure will be freed once all
  537. * references to it have been dropped.
  538. */
  539. void amba_device_unregister(struct amba_device *dev)
  540. {
  541. device_unregister(&dev->dev);
  542. }
  543. struct find_data {
  544. struct amba_device *dev;
  545. struct device *parent;
  546. const char *busid;
  547. unsigned int id;
  548. unsigned int mask;
  549. };
  550. static int amba_find_match(struct device *dev, void *data)
  551. {
  552. struct find_data *d = data;
  553. struct amba_device *pcdev = to_amba_device(dev);
  554. int r;
  555. r = (pcdev->periphid & d->mask) == d->id;
  556. if (d->parent)
  557. r &= d->parent == dev->parent;
  558. if (d->busid)
  559. r &= strcmp(dev_name(dev), d->busid) == 0;
  560. if (r) {
  561. get_device(dev);
  562. d->dev = pcdev;
  563. }
  564. return r;
  565. }
  566. /**
  567. * amba_find_device - locate an AMBA device given a bus id
  568. * @busid: bus id for device (or NULL)
  569. * @parent: parent device (or NULL)
  570. * @id: peripheral ID (or 0)
  571. * @mask: peripheral ID mask (or 0)
  572. *
  573. * Return the AMBA device corresponding to the supplied parameters.
  574. * If no device matches, returns NULL.
  575. *
  576. * NOTE: When a valid device is found, its refcount is
  577. * incremented, and must be decremented before the returned
  578. * reference.
  579. */
  580. struct amba_device *
  581. amba_find_device(const char *busid, struct device *parent, unsigned int id,
  582. unsigned int mask)
  583. {
  584. struct find_data data;
  585. data.dev = NULL;
  586. data.parent = parent;
  587. data.busid = busid;
  588. data.id = id;
  589. data.mask = mask;
  590. bus_for_each_dev(&amba_bustype, NULL, &data, amba_find_match);
  591. return data.dev;
  592. }
  593. /**
  594. * amba_request_regions - request all mem regions associated with device
  595. * @dev: amba_device structure for device
  596. * @name: name, or NULL to use driver name
  597. */
  598. int amba_request_regions(struct amba_device *dev, const char *name)
  599. {
  600. int ret = 0;
  601. u32 size;
  602. if (!name)
  603. name = dev->dev.driver->name;
  604. size = resource_size(&dev->res);
  605. if (!request_mem_region(dev->res.start, size, name))
  606. ret = -EBUSY;
  607. return ret;
  608. }
  609. /**
  610. * amba_release_regions - release mem regions associated with device
  611. * @dev: amba_device structure for device
  612. *
  613. * Release regions claimed by a successful call to amba_request_regions.
  614. */
  615. void amba_release_regions(struct amba_device *dev)
  616. {
  617. u32 size;
  618. size = resource_size(&dev->res);
  619. release_mem_region(dev->res.start, size);
  620. }
  621. EXPORT_SYMBOL(amba_driver_register);
  622. EXPORT_SYMBOL(amba_driver_unregister);
  623. EXPORT_SYMBOL(amba_device_register);
  624. EXPORT_SYMBOL(amba_device_unregister);
  625. EXPORT_SYMBOL(amba_find_device);
  626. EXPORT_SYMBOL(amba_request_regions);
  627. EXPORT_SYMBOL(amba_release_regions);