platform.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
  3. * <benh@kernel.crashing.org>
  4. * and Arnd Bergmann, IBM Corp.
  5. * Merged from powerpc/kernel/of_platform.c and
  6. * sparc{,64}/kernel/of_device.c by Stephen Rothwell
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. *
  13. */
  14. #include <linux/errno.h>
  15. #include <linux/module.h>
  16. #include <linux/device.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/slab.h>
  19. #include <linux/of_address.h>
  20. #include <linux/of_device.h>
  21. #include <linux/of_irq.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/platform_device.h>
  24. static int platform_driver_probe_shim(struct platform_device *pdev)
  25. {
  26. struct platform_driver *pdrv;
  27. struct of_platform_driver *ofpdrv;
  28. const struct of_device_id *match;
  29. pdrv = container_of(pdev->dev.driver, struct platform_driver, driver);
  30. ofpdrv = container_of(pdrv, struct of_platform_driver, platform_driver);
  31. /* There is an unlikely chance that an of_platform driver might match
  32. * on a non-OF platform device. If so, then of_match_device() will
  33. * come up empty. Return -EINVAL in this case so other drivers get
  34. * the chance to bind. */
  35. match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev);
  36. return match ? ofpdrv->probe(pdev, match) : -EINVAL;
  37. }
  38. static void platform_driver_shutdown_shim(struct platform_device *pdev)
  39. {
  40. struct platform_driver *pdrv;
  41. struct of_platform_driver *ofpdrv;
  42. pdrv = container_of(pdev->dev.driver, struct platform_driver, driver);
  43. ofpdrv = container_of(pdrv, struct of_platform_driver, platform_driver);
  44. ofpdrv->shutdown(pdev);
  45. }
  46. /**
  47. * of_register_platform_driver
  48. */
  49. int of_register_platform_driver(struct of_platform_driver *drv)
  50. {
  51. /* setup of_platform_driver to platform_driver adaptors */
  52. drv->platform_driver.driver = drv->driver;
  53. if (drv->probe)
  54. drv->platform_driver.probe = platform_driver_probe_shim;
  55. drv->platform_driver.remove = drv->remove;
  56. if (drv->shutdown)
  57. drv->platform_driver.shutdown = platform_driver_shutdown_shim;
  58. drv->platform_driver.suspend = drv->suspend;
  59. drv->platform_driver.resume = drv->resume;
  60. return platform_driver_register(&drv->platform_driver);
  61. }
  62. EXPORT_SYMBOL(of_register_platform_driver);
  63. void of_unregister_platform_driver(struct of_platform_driver *drv)
  64. {
  65. platform_driver_unregister(&drv->platform_driver);
  66. }
  67. EXPORT_SYMBOL(of_unregister_platform_driver);
  68. #if defined(CONFIG_PPC_DCR)
  69. #include <asm/dcr.h>
  70. #endif
  71. extern struct device_attribute of_platform_device_attrs[];
  72. static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
  73. {
  74. const struct of_device_id *matches = drv->of_match_table;
  75. if (!matches)
  76. return 0;
  77. return of_match_device(matches, dev) != NULL;
  78. }
  79. static int of_platform_device_probe(struct device *dev)
  80. {
  81. int error = -ENODEV;
  82. struct of_platform_driver *drv;
  83. struct of_device *of_dev;
  84. const struct of_device_id *match;
  85. drv = to_of_platform_driver(dev->driver);
  86. of_dev = to_of_device(dev);
  87. if (!drv->probe)
  88. return error;
  89. of_dev_get(of_dev);
  90. match = of_match_device(drv->driver.of_match_table, dev);
  91. if (match)
  92. error = drv->probe(of_dev, match);
  93. if (error)
  94. of_dev_put(of_dev);
  95. return error;
  96. }
  97. static int of_platform_device_remove(struct device *dev)
  98. {
  99. struct of_device *of_dev = to_of_device(dev);
  100. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  101. if (dev->driver && drv->remove)
  102. drv->remove(of_dev);
  103. return 0;
  104. }
  105. static void of_platform_device_shutdown(struct device *dev)
  106. {
  107. struct of_device *of_dev = to_of_device(dev);
  108. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  109. if (dev->driver && drv->shutdown)
  110. drv->shutdown(of_dev);
  111. }
  112. #ifdef CONFIG_PM_SLEEP
  113. static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg)
  114. {
  115. struct of_device *of_dev = to_of_device(dev);
  116. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  117. int ret = 0;
  118. if (dev->driver && drv->suspend)
  119. ret = drv->suspend(of_dev, mesg);
  120. return ret;
  121. }
  122. static int of_platform_legacy_resume(struct device *dev)
  123. {
  124. struct of_device *of_dev = to_of_device(dev);
  125. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  126. int ret = 0;
  127. if (dev->driver && drv->resume)
  128. ret = drv->resume(of_dev);
  129. return ret;
  130. }
  131. static int of_platform_pm_prepare(struct device *dev)
  132. {
  133. struct device_driver *drv = dev->driver;
  134. int ret = 0;
  135. if (drv && drv->pm && drv->pm->prepare)
  136. ret = drv->pm->prepare(dev);
  137. return ret;
  138. }
  139. static void of_platform_pm_complete(struct device *dev)
  140. {
  141. struct device_driver *drv = dev->driver;
  142. if (drv && drv->pm && drv->pm->complete)
  143. drv->pm->complete(dev);
  144. }
  145. #ifdef CONFIG_SUSPEND
  146. static int of_platform_pm_suspend(struct device *dev)
  147. {
  148. struct device_driver *drv = dev->driver;
  149. int ret = 0;
  150. if (!drv)
  151. return 0;
  152. if (drv->pm) {
  153. if (drv->pm->suspend)
  154. ret = drv->pm->suspend(dev);
  155. } else {
  156. ret = of_platform_legacy_suspend(dev, PMSG_SUSPEND);
  157. }
  158. return ret;
  159. }
  160. static int of_platform_pm_suspend_noirq(struct device *dev)
  161. {
  162. struct device_driver *drv = dev->driver;
  163. int ret = 0;
  164. if (!drv)
  165. return 0;
  166. if (drv->pm) {
  167. if (drv->pm->suspend_noirq)
  168. ret = drv->pm->suspend_noirq(dev);
  169. }
  170. return ret;
  171. }
  172. static int of_platform_pm_resume(struct device *dev)
  173. {
  174. struct device_driver *drv = dev->driver;
  175. int ret = 0;
  176. if (!drv)
  177. return 0;
  178. if (drv->pm) {
  179. if (drv->pm->resume)
  180. ret = drv->pm->resume(dev);
  181. } else {
  182. ret = of_platform_legacy_resume(dev);
  183. }
  184. return ret;
  185. }
  186. static int of_platform_pm_resume_noirq(struct device *dev)
  187. {
  188. struct device_driver *drv = dev->driver;
  189. int ret = 0;
  190. if (!drv)
  191. return 0;
  192. if (drv->pm) {
  193. if (drv->pm->resume_noirq)
  194. ret = drv->pm->resume_noirq(dev);
  195. }
  196. return ret;
  197. }
  198. #else /* !CONFIG_SUSPEND */
  199. #define of_platform_pm_suspend NULL
  200. #define of_platform_pm_resume NULL
  201. #define of_platform_pm_suspend_noirq NULL
  202. #define of_platform_pm_resume_noirq NULL
  203. #endif /* !CONFIG_SUSPEND */
  204. #ifdef CONFIG_HIBERNATION
  205. static int of_platform_pm_freeze(struct device *dev)
  206. {
  207. struct device_driver *drv = dev->driver;
  208. int ret = 0;
  209. if (!drv)
  210. return 0;
  211. if (drv->pm) {
  212. if (drv->pm->freeze)
  213. ret = drv->pm->freeze(dev);
  214. } else {
  215. ret = of_platform_legacy_suspend(dev, PMSG_FREEZE);
  216. }
  217. return ret;
  218. }
  219. static int of_platform_pm_freeze_noirq(struct device *dev)
  220. {
  221. struct device_driver *drv = dev->driver;
  222. int ret = 0;
  223. if (!drv)
  224. return 0;
  225. if (drv->pm) {
  226. if (drv->pm->freeze_noirq)
  227. ret = drv->pm->freeze_noirq(dev);
  228. }
  229. return ret;
  230. }
  231. static int of_platform_pm_thaw(struct device *dev)
  232. {
  233. struct device_driver *drv = dev->driver;
  234. int ret = 0;
  235. if (!drv)
  236. return 0;
  237. if (drv->pm) {
  238. if (drv->pm->thaw)
  239. ret = drv->pm->thaw(dev);
  240. } else {
  241. ret = of_platform_legacy_resume(dev);
  242. }
  243. return ret;
  244. }
  245. static int of_platform_pm_thaw_noirq(struct device *dev)
  246. {
  247. struct device_driver *drv = dev->driver;
  248. int ret = 0;
  249. if (!drv)
  250. return 0;
  251. if (drv->pm) {
  252. if (drv->pm->thaw_noirq)
  253. ret = drv->pm->thaw_noirq(dev);
  254. }
  255. return ret;
  256. }
  257. static int of_platform_pm_poweroff(struct device *dev)
  258. {
  259. struct device_driver *drv = dev->driver;
  260. int ret = 0;
  261. if (!drv)
  262. return 0;
  263. if (drv->pm) {
  264. if (drv->pm->poweroff)
  265. ret = drv->pm->poweroff(dev);
  266. } else {
  267. ret = of_platform_legacy_suspend(dev, PMSG_HIBERNATE);
  268. }
  269. return ret;
  270. }
  271. static int of_platform_pm_poweroff_noirq(struct device *dev)
  272. {
  273. struct device_driver *drv = dev->driver;
  274. int ret = 0;
  275. if (!drv)
  276. return 0;
  277. if (drv->pm) {
  278. if (drv->pm->poweroff_noirq)
  279. ret = drv->pm->poweroff_noirq(dev);
  280. }
  281. return ret;
  282. }
  283. static int of_platform_pm_restore(struct device *dev)
  284. {
  285. struct device_driver *drv = dev->driver;
  286. int ret = 0;
  287. if (!drv)
  288. return 0;
  289. if (drv->pm) {
  290. if (drv->pm->restore)
  291. ret = drv->pm->restore(dev);
  292. } else {
  293. ret = of_platform_legacy_resume(dev);
  294. }
  295. return ret;
  296. }
  297. static int of_platform_pm_restore_noirq(struct device *dev)
  298. {
  299. struct device_driver *drv = dev->driver;
  300. int ret = 0;
  301. if (!drv)
  302. return 0;
  303. if (drv->pm) {
  304. if (drv->pm->restore_noirq)
  305. ret = drv->pm->restore_noirq(dev);
  306. }
  307. return ret;
  308. }
  309. #else /* !CONFIG_HIBERNATION */
  310. #define of_platform_pm_freeze NULL
  311. #define of_platform_pm_thaw NULL
  312. #define of_platform_pm_poweroff NULL
  313. #define of_platform_pm_restore NULL
  314. #define of_platform_pm_freeze_noirq NULL
  315. #define of_platform_pm_thaw_noirq NULL
  316. #define of_platform_pm_poweroff_noirq NULL
  317. #define of_platform_pm_restore_noirq NULL
  318. #endif /* !CONFIG_HIBERNATION */
  319. static struct dev_pm_ops of_platform_dev_pm_ops = {
  320. .prepare = of_platform_pm_prepare,
  321. .complete = of_platform_pm_complete,
  322. .suspend = of_platform_pm_suspend,
  323. .resume = of_platform_pm_resume,
  324. .freeze = of_platform_pm_freeze,
  325. .thaw = of_platform_pm_thaw,
  326. .poweroff = of_platform_pm_poweroff,
  327. .restore = of_platform_pm_restore,
  328. .suspend_noirq = of_platform_pm_suspend_noirq,
  329. .resume_noirq = of_platform_pm_resume_noirq,
  330. .freeze_noirq = of_platform_pm_freeze_noirq,
  331. .thaw_noirq = of_platform_pm_thaw_noirq,
  332. .poweroff_noirq = of_platform_pm_poweroff_noirq,
  333. .restore_noirq = of_platform_pm_restore_noirq,
  334. };
  335. #define OF_PLATFORM_PM_OPS_PTR (&of_platform_dev_pm_ops)
  336. #else /* !CONFIG_PM_SLEEP */
  337. #define OF_PLATFORM_PM_OPS_PTR NULL
  338. #endif /* !CONFIG_PM_SLEEP */
  339. int of_bus_type_init(struct bus_type *bus, const char *name)
  340. {
  341. bus->name = name;
  342. bus->match = of_platform_bus_match;
  343. bus->probe = of_platform_device_probe;
  344. bus->remove = of_platform_device_remove;
  345. bus->shutdown = of_platform_device_shutdown;
  346. bus->dev_attrs = of_platform_device_attrs;
  347. bus->pm = OF_PLATFORM_PM_OPS_PTR;
  348. return bus_register(bus);
  349. }
  350. int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
  351. {
  352. /*
  353. * Temporary: of_platform_bus used to be distinct from the platform
  354. * bus. It isn't anymore, and so drivers on the platform bus need
  355. * to be registered in a special way.
  356. *
  357. * After all of_platform_bus_type drivers are converted to
  358. * platform_drivers, this exception can be removed.
  359. */
  360. if (bus == &platform_bus_type)
  361. return of_register_platform_driver(drv);
  362. /* register with core */
  363. drv->driver.bus = bus;
  364. return driver_register(&drv->driver);
  365. }
  366. EXPORT_SYMBOL(of_register_driver);
  367. void of_unregister_driver(struct of_platform_driver *drv)
  368. {
  369. if (drv->driver.bus == &platform_bus_type)
  370. of_unregister_platform_driver(drv);
  371. else
  372. driver_unregister(&drv->driver);
  373. }
  374. EXPORT_SYMBOL(of_unregister_driver);
  375. #if !defined(CONFIG_SPARC)
  376. /*
  377. * The following routines scan a subtree and registers a device for
  378. * each applicable node.
  379. *
  380. * Note: sparc doesn't use these routines because it has a different
  381. * mechanism for creating devices from device tree nodes.
  382. */
  383. /**
  384. * of_device_make_bus_id - Use the device node data to assign a unique name
  385. * @dev: pointer to device structure that is linked to a device tree node
  386. *
  387. * This routine will first try using either the dcr-reg or the reg property
  388. * value to derive a unique name. As a last resort it will use the node
  389. * name followed by a unique number.
  390. */
  391. static void of_device_make_bus_id(struct device *dev)
  392. {
  393. static atomic_t bus_no_reg_magic;
  394. struct device_node *node = dev->of_node;
  395. const u32 *reg;
  396. u64 addr;
  397. int magic;
  398. #ifdef CONFIG_PPC_DCR
  399. /*
  400. * If it's a DCR based device, use 'd' for native DCRs
  401. * and 'D' for MMIO DCRs.
  402. */
  403. reg = of_get_property(node, "dcr-reg", NULL);
  404. if (reg) {
  405. #ifdef CONFIG_PPC_DCR_NATIVE
  406. dev_set_name(dev, "d%x.%s", *reg, node->name);
  407. #else /* CONFIG_PPC_DCR_NATIVE */
  408. u64 addr = of_translate_dcr_address(node, *reg, NULL);
  409. if (addr != OF_BAD_ADDR) {
  410. dev_set_name(dev, "D%llx.%s",
  411. (unsigned long long)addr, node->name);
  412. return;
  413. }
  414. #endif /* !CONFIG_PPC_DCR_NATIVE */
  415. }
  416. #endif /* CONFIG_PPC_DCR */
  417. /*
  418. * For MMIO, get the physical address
  419. */
  420. reg = of_get_property(node, "reg", NULL);
  421. if (reg) {
  422. addr = of_translate_address(node, reg);
  423. if (addr != OF_BAD_ADDR) {
  424. dev_set_name(dev, "%llx.%s",
  425. (unsigned long long)addr, node->name);
  426. return;
  427. }
  428. }
  429. /*
  430. * No BusID, use the node name and add a globally incremented
  431. * counter (and pray...)
  432. */
  433. magic = atomic_add_return(1, &bus_no_reg_magic);
  434. dev_set_name(dev, "%s.%d", node->name, magic - 1);
  435. }
  436. /**
  437. * of_device_alloc - Allocate and initialize an of_device
  438. * @np: device node to assign to device
  439. * @bus_id: Name to assign to the device. May be null to use default name.
  440. * @parent: Parent device.
  441. */
  442. struct of_device *of_device_alloc(struct device_node *np,
  443. const char *bus_id,
  444. struct device *parent)
  445. {
  446. struct of_device *dev;
  447. int rc, i, num_reg = 0, num_irq = 0;
  448. struct resource *res, temp_res;
  449. /* First count how many resources are needed */
  450. while (of_address_to_resource(np, num_reg, &temp_res) == 0)
  451. num_reg++;
  452. while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ)
  453. num_irq++;
  454. /* Allocate memory for both the struct device and the resource table */
  455. dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)),
  456. GFP_KERNEL);
  457. if (!dev)
  458. return NULL;
  459. res = (struct resource *) &dev[1];
  460. /* Populate the resource table */
  461. if (num_irq || num_reg) {
  462. dev->num_resources = num_reg + num_irq;
  463. dev->resource = res;
  464. for (i = 0; i < num_reg; i++, res++) {
  465. rc = of_address_to_resource(np, i, res);
  466. WARN_ON(rc);
  467. }
  468. for (i = 0; i < num_irq; i++, res++) {
  469. rc = of_irq_to_resource(np, i, res);
  470. WARN_ON(rc == NO_IRQ);
  471. }
  472. }
  473. dev->dev.of_node = of_node_get(np);
  474. #if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE)
  475. dev->dev.dma_mask = &dev->archdata.dma_mask;
  476. #endif
  477. dev->dev.parent = parent;
  478. dev->dev.release = of_release_dev;
  479. if (bus_id)
  480. dev_set_name(&dev->dev, "%s", bus_id);
  481. else
  482. of_device_make_bus_id(&dev->dev);
  483. return dev;
  484. }
  485. EXPORT_SYMBOL(of_device_alloc);
  486. /**
  487. * of_platform_device_create - Alloc, initialize and register an of_device
  488. * @np: pointer to node to create device for
  489. * @bus_id: name to assign device
  490. * @parent: Linux device model parent device.
  491. */
  492. struct of_device *of_platform_device_create(struct device_node *np,
  493. const char *bus_id,
  494. struct device *parent)
  495. {
  496. struct of_device *dev;
  497. dev = of_device_alloc(np, bus_id, parent);
  498. if (!dev)
  499. return NULL;
  500. #if defined(CONFIG_PPC) || defined(CONFIG_MICROBLAZE)
  501. dev->archdata.dma_mask = 0xffffffffUL;
  502. #endif
  503. dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  504. dev->dev.bus = &platform_bus_type;
  505. /* We do not fill the DMA ops for platform devices by default.
  506. * This is currently the responsibility of the platform code
  507. * to do such, possibly using a device notifier
  508. */
  509. if (of_device_register(dev) != 0) {
  510. of_device_free(dev);
  511. return NULL;
  512. }
  513. return dev;
  514. }
  515. EXPORT_SYMBOL(of_platform_device_create);
  516. /**
  517. * of_platform_bus_create - Create an OF device for a bus node and all its
  518. * children. Optionally recursively instantiate matching busses.
  519. * @bus: device node of the bus to instantiate
  520. * @matches: match table, NULL to use the default, OF_NO_DEEP_PROBE to
  521. * disallow recursive creation of child busses
  522. */
  523. static int of_platform_bus_create(const struct device_node *bus,
  524. const struct of_device_id *matches,
  525. struct device *parent)
  526. {
  527. struct device_node *child;
  528. struct of_device *dev;
  529. int rc = 0;
  530. for_each_child_of_node(bus, child) {
  531. pr_debug(" create child: %s\n", child->full_name);
  532. dev = of_platform_device_create(child, NULL, parent);
  533. if (dev == NULL)
  534. rc = -ENOMEM;
  535. else if (!of_match_node(matches, child))
  536. continue;
  537. if (rc == 0) {
  538. pr_debug(" and sub busses\n");
  539. rc = of_platform_bus_create(child, matches, &dev->dev);
  540. }
  541. if (rc) {
  542. of_node_put(child);
  543. break;
  544. }
  545. }
  546. return rc;
  547. }
  548. /**
  549. * of_platform_bus_probe - Probe the device-tree for platform busses
  550. * @root: parent of the first level to probe or NULL for the root of the tree
  551. * @matches: match table, NULL to use the default
  552. * @parent: parent to hook devices from, NULL for toplevel
  553. *
  554. * Note that children of the provided root are not instantiated as devices
  555. * unless the specified root itself matches the bus list and is not NULL.
  556. */
  557. int of_platform_bus_probe(struct device_node *root,
  558. const struct of_device_id *matches,
  559. struct device *parent)
  560. {
  561. struct device_node *child;
  562. struct of_device *dev;
  563. int rc = 0;
  564. if (matches == NULL)
  565. matches = of_default_bus_ids;
  566. if (matches == OF_NO_DEEP_PROBE)
  567. return -EINVAL;
  568. if (root == NULL)
  569. root = of_find_node_by_path("/");
  570. else
  571. of_node_get(root);
  572. if (root == NULL)
  573. return -EINVAL;
  574. pr_debug("of_platform_bus_probe()\n");
  575. pr_debug(" starting at: %s\n", root->full_name);
  576. /* Do a self check of bus type, if there's a match, create
  577. * children
  578. */
  579. if (of_match_node(matches, root)) {
  580. pr_debug(" root match, create all sub devices\n");
  581. dev = of_platform_device_create(root, NULL, parent);
  582. if (dev == NULL) {
  583. rc = -ENOMEM;
  584. goto bail;
  585. }
  586. pr_debug(" create all sub busses\n");
  587. rc = of_platform_bus_create(root, matches, &dev->dev);
  588. goto bail;
  589. }
  590. for_each_child_of_node(root, child) {
  591. if (!of_match_node(matches, child))
  592. continue;
  593. pr_debug(" match: %s\n", child->full_name);
  594. dev = of_platform_device_create(child, NULL, parent);
  595. if (dev == NULL)
  596. rc = -ENOMEM;
  597. else
  598. rc = of_platform_bus_create(child, matches, &dev->dev);
  599. if (rc) {
  600. of_node_put(child);
  601. break;
  602. }
  603. }
  604. bail:
  605. of_node_put(root);
  606. return rc;
  607. }
  608. EXPORT_SYMBOL(of_platform_bus_probe);
  609. #endif /* !CONFIG_SPARC */