bus.c 17 KB

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