bus.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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. NULL
  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->dev.coherent_dma_mask = dma_mask;
  440. dev->irq[0] = irq1;
  441. dev->irq[1] = irq2;
  442. dev->periphid = periphid;
  443. dev->dev.platform_data = pdata;
  444. dev->dev.parent = parent;
  445. ret = amba_device_add(dev, resbase);
  446. if (ret) {
  447. amba_device_put(dev);
  448. return ERR_PTR(ret);
  449. }
  450. return dev;
  451. }
  452. struct amba_device *
  453. amba_apb_device_add(struct device *parent, const char *name,
  454. resource_size_t base, size_t size, int irq1, int irq2,
  455. void *pdata, unsigned int periphid)
  456. {
  457. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  458. periphid, 0, &iomem_resource);
  459. }
  460. EXPORT_SYMBOL_GPL(amba_apb_device_add);
  461. struct amba_device *
  462. amba_ahb_device_add(struct device *parent, const char *name,
  463. resource_size_t base, size_t size, int irq1, int irq2,
  464. void *pdata, unsigned int periphid)
  465. {
  466. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  467. periphid, ~0ULL, &iomem_resource);
  468. }
  469. EXPORT_SYMBOL_GPL(amba_ahb_device_add);
  470. struct amba_device *
  471. amba_apb_device_add_res(struct device *parent, const char *name,
  472. resource_size_t base, size_t size, int irq1,
  473. int irq2, void *pdata, unsigned int periphid,
  474. struct resource *resbase)
  475. {
  476. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  477. periphid, 0, resbase);
  478. }
  479. EXPORT_SYMBOL_GPL(amba_apb_device_add_res);
  480. struct amba_device *
  481. amba_ahb_device_add_res(struct device *parent, const char *name,
  482. resource_size_t base, size_t size, int irq1,
  483. int irq2, void *pdata, unsigned int periphid,
  484. struct resource *resbase)
  485. {
  486. return amba_aphb_device_add(parent, name, base, size, irq1, irq2, pdata,
  487. periphid, ~0ULL, resbase);
  488. }
  489. EXPORT_SYMBOL_GPL(amba_ahb_device_add_res);
  490. static void amba_device_initialize(struct amba_device *dev, const char *name)
  491. {
  492. device_initialize(&dev->dev);
  493. if (name)
  494. dev_set_name(&dev->dev, "%s", name);
  495. dev->dev.release = amba_device_release;
  496. dev->dev.bus = &amba_bustype;
  497. dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
  498. dev->res.name = dev_name(&dev->dev);
  499. }
  500. /**
  501. * amba_device_alloc - allocate an AMBA device
  502. * @name: sysfs name of the AMBA device
  503. * @base: base of AMBA device
  504. * @size: size of AMBA device
  505. *
  506. * Allocate and initialize an AMBA device structure. Returns %NULL
  507. * on failure.
  508. */
  509. struct amba_device *amba_device_alloc(const char *name, resource_size_t base,
  510. size_t size)
  511. {
  512. struct amba_device *dev;
  513. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  514. if (dev) {
  515. amba_device_initialize(dev, name);
  516. dev->res.start = base;
  517. dev->res.end = base + size - 1;
  518. dev->res.flags = IORESOURCE_MEM;
  519. }
  520. return dev;
  521. }
  522. EXPORT_SYMBOL_GPL(amba_device_alloc);
  523. /**
  524. * amba_device_register - register an AMBA device
  525. * @dev: AMBA device to register
  526. * @parent: parent memory resource
  527. *
  528. * Setup the AMBA device, reading the cell ID if present.
  529. * Claim the resource, and register the AMBA device with
  530. * the Linux device manager.
  531. */
  532. int amba_device_register(struct amba_device *dev, struct resource *parent)
  533. {
  534. amba_device_initialize(dev, dev->dev.init_name);
  535. dev->dev.init_name = NULL;
  536. return amba_device_add(dev, parent);
  537. }
  538. /**
  539. * amba_device_put - put an AMBA device
  540. * @dev: AMBA device to put
  541. */
  542. void amba_device_put(struct amba_device *dev)
  543. {
  544. put_device(&dev->dev);
  545. }
  546. EXPORT_SYMBOL_GPL(amba_device_put);
  547. /**
  548. * amba_device_unregister - unregister an AMBA device
  549. * @dev: AMBA device to remove
  550. *
  551. * Remove the specified AMBA device from the Linux device
  552. * manager. All files associated with this object will be
  553. * destroyed, and device drivers notified that the device has
  554. * been removed. The AMBA device's resources including
  555. * the amba_device structure will be freed once all
  556. * references to it have been dropped.
  557. */
  558. void amba_device_unregister(struct amba_device *dev)
  559. {
  560. device_unregister(&dev->dev);
  561. }
  562. struct find_data {
  563. struct amba_device *dev;
  564. struct device *parent;
  565. const char *busid;
  566. unsigned int id;
  567. unsigned int mask;
  568. };
  569. static int amba_find_match(struct device *dev, void *data)
  570. {
  571. struct find_data *d = data;
  572. struct amba_device *pcdev = to_amba_device(dev);
  573. int r;
  574. r = (pcdev->periphid & d->mask) == d->id;
  575. if (d->parent)
  576. r &= d->parent == dev->parent;
  577. if (d->busid)
  578. r &= strcmp(dev_name(dev), d->busid) == 0;
  579. if (r) {
  580. get_device(dev);
  581. d->dev = pcdev;
  582. }
  583. return r;
  584. }
  585. /**
  586. * amba_find_device - locate an AMBA device given a bus id
  587. * @busid: bus id for device (or NULL)
  588. * @parent: parent device (or NULL)
  589. * @id: peripheral ID (or 0)
  590. * @mask: peripheral ID mask (or 0)
  591. *
  592. * Return the AMBA device corresponding to the supplied parameters.
  593. * If no device matches, returns NULL.
  594. *
  595. * NOTE: When a valid device is found, its refcount is
  596. * incremented, and must be decremented before the returned
  597. * reference.
  598. */
  599. struct amba_device *
  600. amba_find_device(const char *busid, struct device *parent, unsigned int id,
  601. unsigned int mask)
  602. {
  603. struct find_data data;
  604. data.dev = NULL;
  605. data.parent = parent;
  606. data.busid = busid;
  607. data.id = id;
  608. data.mask = mask;
  609. bus_for_each_dev(&amba_bustype, NULL, &data, amba_find_match);
  610. return data.dev;
  611. }
  612. /**
  613. * amba_request_regions - request all mem regions associated with device
  614. * @dev: amba_device structure for device
  615. * @name: name, or NULL to use driver name
  616. */
  617. int amba_request_regions(struct amba_device *dev, const char *name)
  618. {
  619. int ret = 0;
  620. u32 size;
  621. if (!name)
  622. name = dev->dev.driver->name;
  623. size = resource_size(&dev->res);
  624. if (!request_mem_region(dev->res.start, size, name))
  625. ret = -EBUSY;
  626. return ret;
  627. }
  628. /**
  629. * amba_release_regions - release mem regions associated with device
  630. * @dev: amba_device structure for device
  631. *
  632. * Release regions claimed by a successful call to amba_request_regions.
  633. */
  634. void amba_release_regions(struct amba_device *dev)
  635. {
  636. u32 size;
  637. size = resource_size(&dev->res);
  638. release_mem_region(dev->res.start, size);
  639. }
  640. EXPORT_SYMBOL(amba_driver_register);
  641. EXPORT_SYMBOL(amba_driver_unregister);
  642. EXPORT_SYMBOL(amba_device_register);
  643. EXPORT_SYMBOL(amba_device_unregister);
  644. EXPORT_SYMBOL(amba_find_device);
  645. EXPORT_SYMBOL(amba_request_regions);
  646. EXPORT_SYMBOL(amba_release_regions);