platform.c 18 KB

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