of_device.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. #include <linux/string.h>
  2. #include <linux/kernel.h>
  3. #include <linux/init.h>
  4. #include <linux/module.h>
  5. #include <linux/mod_devicetable.h>
  6. #include <linux/slab.h>
  7. #include <asm/errno.h>
  8. #include <asm/of_device.h>
  9. /**
  10. * of_match_device - Tell if an of_device structure has a matching
  11. * of_match structure
  12. * @ids: array of of device match structures to search in
  13. * @dev: the of device structure to match against
  14. *
  15. * Used by a driver to check whether an of_device present in the
  16. * system is in its list of supported devices.
  17. */
  18. const struct of_device_id *of_match_device(const struct of_device_id *matches,
  19. const struct of_device *dev)
  20. {
  21. if (!dev->node)
  22. return NULL;
  23. while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
  24. int match = 1;
  25. if (matches->name[0])
  26. match &= dev->node->name
  27. && !strcmp(matches->name, dev->node->name);
  28. if (matches->type[0])
  29. match &= dev->node->type
  30. && !strcmp(matches->type, dev->node->type);
  31. if (matches->compatible[0])
  32. match &= of_device_is_compatible(dev->node,
  33. matches->compatible);
  34. if (match)
  35. return matches;
  36. matches++;
  37. }
  38. return NULL;
  39. }
  40. static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
  41. {
  42. struct of_device * of_dev = to_of_device(dev);
  43. struct of_platform_driver * of_drv = to_of_platform_driver(drv);
  44. const struct of_device_id * matches = of_drv->match_table;
  45. if (!matches)
  46. return 0;
  47. return of_match_device(matches, of_dev) != NULL;
  48. }
  49. struct of_device *of_dev_get(struct of_device *dev)
  50. {
  51. struct device *tmp;
  52. if (!dev)
  53. return NULL;
  54. tmp = get_device(&dev->dev);
  55. if (tmp)
  56. return to_of_device(tmp);
  57. else
  58. return NULL;
  59. }
  60. void of_dev_put(struct of_device *dev)
  61. {
  62. if (dev)
  63. put_device(&dev->dev);
  64. }
  65. static int of_device_probe(struct device *dev)
  66. {
  67. int error = -ENODEV;
  68. struct of_platform_driver *drv;
  69. struct of_device *of_dev;
  70. const struct of_device_id *match;
  71. drv = to_of_platform_driver(dev->driver);
  72. of_dev = to_of_device(dev);
  73. if (!drv->probe)
  74. return error;
  75. of_dev_get(of_dev);
  76. match = of_match_device(drv->match_table, of_dev);
  77. if (match)
  78. error = drv->probe(of_dev, match);
  79. if (error)
  80. of_dev_put(of_dev);
  81. return error;
  82. }
  83. static int of_device_remove(struct device *dev)
  84. {
  85. struct of_device * of_dev = to_of_device(dev);
  86. struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
  87. if (dev->driver && drv->remove)
  88. drv->remove(of_dev);
  89. return 0;
  90. }
  91. static int of_device_suspend(struct device *dev, pm_message_t state)
  92. {
  93. struct of_device * of_dev = to_of_device(dev);
  94. struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
  95. int error = 0;
  96. if (dev->driver && drv->suspend)
  97. error = drv->suspend(of_dev, state);
  98. return error;
  99. }
  100. static int of_device_resume(struct device * dev)
  101. {
  102. struct of_device * of_dev = to_of_device(dev);
  103. struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
  104. int error = 0;
  105. if (dev->driver && drv->resume)
  106. error = drv->resume(of_dev);
  107. return error;
  108. }
  109. static int node_match(struct device *dev, void *data)
  110. {
  111. struct of_device *op = to_of_device(dev);
  112. struct device_node *dp = data;
  113. return (op->node == dp);
  114. }
  115. struct of_device *of_find_device_by_node(struct device_node *dp)
  116. {
  117. struct device *dev = bus_find_device(&of_bus_type, NULL,
  118. dp, node_match);
  119. if (dev)
  120. return to_of_device(dev);
  121. return NULL;
  122. }
  123. EXPORT_SYMBOL(of_find_device_by_node);
  124. #ifdef CONFIG_PCI
  125. struct bus_type ebus_bus_type = {
  126. .name = "ebus",
  127. .match = of_platform_bus_match,
  128. .probe = of_device_probe,
  129. .remove = of_device_remove,
  130. .suspend = of_device_suspend,
  131. .resume = of_device_resume,
  132. };
  133. EXPORT_SYMBOL(ebus_bus_type);
  134. #endif
  135. #ifdef CONFIG_SBUS
  136. struct bus_type sbus_bus_type = {
  137. .name = "sbus",
  138. .match = of_platform_bus_match,
  139. .probe = of_device_probe,
  140. .remove = of_device_remove,
  141. .suspend = of_device_suspend,
  142. .resume = of_device_resume,
  143. };
  144. EXPORT_SYMBOL(sbus_bus_type);
  145. #endif
  146. struct bus_type of_bus_type = {
  147. .name = "of",
  148. .match = of_platform_bus_match,
  149. .probe = of_device_probe,
  150. .remove = of_device_remove,
  151. .suspend = of_device_suspend,
  152. .resume = of_device_resume,
  153. };
  154. EXPORT_SYMBOL(of_bus_type);
  155. static inline u64 of_read_addr(const u32 *cell, int size)
  156. {
  157. u64 r = 0;
  158. while (size--)
  159. r = (r << 32) | *(cell++);
  160. return r;
  161. }
  162. static void __init get_cells(struct device_node *dp,
  163. int *addrc, int *sizec)
  164. {
  165. if (addrc)
  166. *addrc = of_n_addr_cells(dp);
  167. if (sizec)
  168. *sizec = of_n_size_cells(dp);
  169. }
  170. /* Max address size we deal with */
  171. #define OF_MAX_ADDR_CELLS 4
  172. struct of_bus {
  173. const char *name;
  174. const char *addr_prop_name;
  175. int (*match)(struct device_node *parent);
  176. void (*count_cells)(struct device_node *child,
  177. int *addrc, int *sizec);
  178. int (*map)(u32 *addr, const u32 *range,
  179. int na, int ns, int pna);
  180. unsigned int (*get_flags)(const u32 *addr);
  181. };
  182. /*
  183. * Default translator (generic bus)
  184. */
  185. static void of_bus_default_count_cells(struct device_node *dev,
  186. int *addrc, int *sizec)
  187. {
  188. get_cells(dev, addrc, sizec);
  189. }
  190. /* Make sure the least significant 64-bits are in-range. Even
  191. * for 3 or 4 cell values it is a good enough approximation.
  192. */
  193. static int of_out_of_range(const u32 *addr, const u32 *base,
  194. const u32 *size, int na, int ns)
  195. {
  196. u64 a = of_read_addr(addr, na);
  197. u64 b = of_read_addr(base, na);
  198. if (a < b)
  199. return 1;
  200. b += of_read_addr(size, ns);
  201. if (a >= b)
  202. return 1;
  203. return 0;
  204. }
  205. static int of_bus_default_map(u32 *addr, const u32 *range,
  206. int na, int ns, int pna)
  207. {
  208. u32 result[OF_MAX_ADDR_CELLS];
  209. int i;
  210. if (ns > 2) {
  211. printk("of_device: Cannot handle size cells (%d) > 2.", ns);
  212. return -EINVAL;
  213. }
  214. if (of_out_of_range(addr, range, range + na + pna, na, ns))
  215. return -EINVAL;
  216. /* Start with the parent range base. */
  217. memcpy(result, range + na, pna * 4);
  218. /* Add in the child address offset. */
  219. for (i = 0; i < na; i++)
  220. result[pna - 1 - i] +=
  221. (addr[na - 1 - i] -
  222. range[na - 1 - i]);
  223. memcpy(addr, result, pna * 4);
  224. return 0;
  225. }
  226. static unsigned int of_bus_default_get_flags(const u32 *addr)
  227. {
  228. return IORESOURCE_MEM;
  229. }
  230. /*
  231. * PCI bus specific translator
  232. */
  233. static int of_bus_pci_match(struct device_node *np)
  234. {
  235. if (!strcmp(np->type, "pci") || !strcmp(np->type, "pciex")) {
  236. /* Do not do PCI specific frobbing if the
  237. * PCI bridge lacks a ranges property. We
  238. * want to pass it through up to the next
  239. * parent as-is, not with the PCI translate
  240. * method which chops off the top address cell.
  241. */
  242. if (!of_find_property(np, "ranges", NULL))
  243. return 0;
  244. return 1;
  245. }
  246. return 0;
  247. }
  248. static void of_bus_pci_count_cells(struct device_node *np,
  249. int *addrc, int *sizec)
  250. {
  251. if (addrc)
  252. *addrc = 3;
  253. if (sizec)
  254. *sizec = 2;
  255. }
  256. static int of_bus_pci_map(u32 *addr, const u32 *range,
  257. int na, int ns, int pna)
  258. {
  259. u32 result[OF_MAX_ADDR_CELLS];
  260. int i;
  261. /* Check address type match */
  262. if ((addr[0] ^ range[0]) & 0x03000000)
  263. return -EINVAL;
  264. if (of_out_of_range(addr + 1, range + 1, range + na + pna,
  265. na - 1, ns))
  266. return -EINVAL;
  267. /* Start with the parent range base. */
  268. memcpy(result, range + na, pna * 4);
  269. /* Add in the child address offset, skipping high cell. */
  270. for (i = 0; i < na - 1; i++)
  271. result[pna - 1 - i] +=
  272. (addr[na - 1 - i] -
  273. range[na - 1 - i]);
  274. memcpy(addr, result, pna * 4);
  275. return 0;
  276. }
  277. static unsigned int of_bus_pci_get_flags(const u32 *addr)
  278. {
  279. unsigned int flags = 0;
  280. u32 w = addr[0];
  281. switch((w >> 24) & 0x03) {
  282. case 0x01:
  283. flags |= IORESOURCE_IO;
  284. case 0x02: /* 32 bits */
  285. case 0x03: /* 64 bits */
  286. flags |= IORESOURCE_MEM;
  287. }
  288. if (w & 0x40000000)
  289. flags |= IORESOURCE_PREFETCH;
  290. return flags;
  291. }
  292. /*
  293. * SBUS bus specific translator
  294. */
  295. static int of_bus_sbus_match(struct device_node *np)
  296. {
  297. return !strcmp(np->name, "sbus") ||
  298. !strcmp(np->name, "sbi");
  299. }
  300. static void of_bus_sbus_count_cells(struct device_node *child,
  301. int *addrc, int *sizec)
  302. {
  303. if (addrc)
  304. *addrc = 2;
  305. if (sizec)
  306. *sizec = 1;
  307. }
  308. static int of_bus_sbus_map(u32 *addr, const u32 *range, int na, int ns, int pna)
  309. {
  310. return of_bus_default_map(addr, range, na, ns, pna);
  311. }
  312. static unsigned int of_bus_sbus_get_flags(const u32 *addr)
  313. {
  314. return IORESOURCE_MEM;
  315. }
  316. /*
  317. * Array of bus specific translators
  318. */
  319. static struct of_bus of_busses[] = {
  320. /* PCI */
  321. {
  322. .name = "pci",
  323. .addr_prop_name = "assigned-addresses",
  324. .match = of_bus_pci_match,
  325. .count_cells = of_bus_pci_count_cells,
  326. .map = of_bus_pci_map,
  327. .get_flags = of_bus_pci_get_flags,
  328. },
  329. /* SBUS */
  330. {
  331. .name = "sbus",
  332. .addr_prop_name = "reg",
  333. .match = of_bus_sbus_match,
  334. .count_cells = of_bus_sbus_count_cells,
  335. .map = of_bus_sbus_map,
  336. .get_flags = of_bus_sbus_get_flags,
  337. },
  338. /* Default */
  339. {
  340. .name = "default",
  341. .addr_prop_name = "reg",
  342. .match = NULL,
  343. .count_cells = of_bus_default_count_cells,
  344. .map = of_bus_default_map,
  345. .get_flags = of_bus_default_get_flags,
  346. },
  347. };
  348. static struct of_bus *of_match_bus(struct device_node *np)
  349. {
  350. int i;
  351. for (i = 0; i < ARRAY_SIZE(of_busses); i ++)
  352. if (!of_busses[i].match || of_busses[i].match(np))
  353. return &of_busses[i];
  354. BUG();
  355. return NULL;
  356. }
  357. static int __init build_one_resource(struct device_node *parent,
  358. struct of_bus *bus,
  359. struct of_bus *pbus,
  360. u32 *addr,
  361. int na, int ns, int pna)
  362. {
  363. const u32 *ranges;
  364. unsigned int rlen;
  365. int rone;
  366. ranges = of_get_property(parent, "ranges", &rlen);
  367. if (ranges == NULL || rlen == 0) {
  368. u32 result[OF_MAX_ADDR_CELLS];
  369. int i;
  370. memset(result, 0, pna * 4);
  371. for (i = 0; i < na; i++)
  372. result[pna - 1 - i] =
  373. addr[na - 1 - i];
  374. memcpy(addr, result, pna * 4);
  375. return 0;
  376. }
  377. /* Now walk through the ranges */
  378. rlen /= 4;
  379. rone = na + pna + ns;
  380. for (; rlen >= rone; rlen -= rone, ranges += rone) {
  381. if (!bus->map(addr, ranges, na, ns, pna))
  382. return 0;
  383. }
  384. return 1;
  385. }
  386. static int of_resource_verbose;
  387. static void __init build_device_resources(struct of_device *op,
  388. struct device *parent)
  389. {
  390. struct of_device *p_op;
  391. struct of_bus *bus;
  392. int na, ns;
  393. int index, num_reg;
  394. const void *preg;
  395. if (!parent)
  396. return;
  397. p_op = to_of_device(parent);
  398. bus = of_match_bus(p_op->node);
  399. bus->count_cells(op->node, &na, &ns);
  400. preg = of_get_property(op->node, bus->addr_prop_name, &num_reg);
  401. if (!preg || num_reg == 0)
  402. return;
  403. /* Convert to num-cells. */
  404. num_reg /= 4;
  405. /* Conver to num-entries. */
  406. num_reg /= na + ns;
  407. for (index = 0; index < num_reg; index++) {
  408. struct resource *r = &op->resource[index];
  409. u32 addr[OF_MAX_ADDR_CELLS];
  410. const u32 *reg = (preg + (index * ((na + ns) * 4)));
  411. struct device_node *dp = op->node;
  412. struct device_node *pp = p_op->node;
  413. struct of_bus *pbus, *dbus;
  414. u64 size, result = OF_BAD_ADDR;
  415. unsigned long flags;
  416. int dna, dns;
  417. int pna, pns;
  418. size = of_read_addr(reg + na, ns);
  419. flags = bus->get_flags(reg);
  420. memcpy(addr, reg, na * 4);
  421. /* If the immediate parent has no ranges property to apply,
  422. * just use a 1<->1 mapping.
  423. */
  424. if (of_find_property(pp, "ranges", NULL) == NULL) {
  425. result = of_read_addr(addr, na);
  426. goto build_res;
  427. }
  428. dna = na;
  429. dns = ns;
  430. dbus = bus;
  431. while (1) {
  432. dp = pp;
  433. pp = dp->parent;
  434. if (!pp) {
  435. result = of_read_addr(addr, dna);
  436. break;
  437. }
  438. pbus = of_match_bus(pp);
  439. pbus->count_cells(dp, &pna, &pns);
  440. if (build_one_resource(dp, dbus, pbus, addr,
  441. dna, dns, pna))
  442. break;
  443. dna = pna;
  444. dns = pns;
  445. dbus = pbus;
  446. }
  447. build_res:
  448. memset(r, 0, sizeof(*r));
  449. if (of_resource_verbose)
  450. printk("%s reg[%d] -> %llx\n",
  451. op->node->full_name, index,
  452. result);
  453. if (result != OF_BAD_ADDR) {
  454. r->start = result & 0xffffffff;
  455. r->end = result + size - 1;
  456. r->flags = flags | ((result >> 32ULL) & 0xffUL);
  457. }
  458. r->name = op->node->name;
  459. }
  460. }
  461. static struct of_device * __init scan_one_device(struct device_node *dp,
  462. struct device *parent)
  463. {
  464. struct of_device *op = kzalloc(sizeof(*op), GFP_KERNEL);
  465. const struct linux_prom_irqs *intr;
  466. int len, i;
  467. if (!op)
  468. return NULL;
  469. op->node = dp;
  470. op->clock_freq = of_getintprop_default(dp, "clock-frequency",
  471. (25*1000*1000));
  472. op->portid = of_getintprop_default(dp, "upa-portid", -1);
  473. if (op->portid == -1)
  474. op->portid = of_getintprop_default(dp, "portid", -1);
  475. intr = of_get_property(dp, "intr", &len);
  476. if (intr) {
  477. op->num_irqs = len / sizeof(struct linux_prom_irqs);
  478. for (i = 0; i < op->num_irqs; i++)
  479. op->irqs[i] = intr[i].pri;
  480. } else {
  481. const unsigned int *irq =
  482. of_get_property(dp, "interrupts", &len);
  483. if (irq) {
  484. op->num_irqs = len / sizeof(unsigned int);
  485. for (i = 0; i < op->num_irqs; i++)
  486. op->irqs[i] = irq[i];
  487. } else {
  488. op->num_irqs = 0;
  489. }
  490. }
  491. if (sparc_cpu_model == sun4d) {
  492. static int pil_to_sbus[] = {
  493. 0, 0, 1, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 0,
  494. };
  495. struct device_node *io_unit, *sbi = dp->parent;
  496. const struct linux_prom_registers *regs;
  497. int board, slot;
  498. while (sbi) {
  499. if (!strcmp(sbi->name, "sbi"))
  500. break;
  501. sbi = sbi->parent;
  502. }
  503. if (!sbi)
  504. goto build_resources;
  505. regs = of_get_property(dp, "reg", NULL);
  506. if (!regs)
  507. goto build_resources;
  508. slot = regs->which_io;
  509. /* If SBI's parent is not io-unit or the io-unit lacks
  510. * a "board#" property, something is very wrong.
  511. */
  512. if (!sbi->parent || strcmp(sbi->parent->name, "io-unit")) {
  513. printk("%s: Error, parent is not io-unit.\n",
  514. sbi->full_name);
  515. goto build_resources;
  516. }
  517. io_unit = sbi->parent;
  518. board = of_getintprop_default(io_unit, "board#", -1);
  519. if (board == -1) {
  520. printk("%s: Error, lacks board# property.\n",
  521. io_unit->full_name);
  522. goto build_resources;
  523. }
  524. for (i = 0; i < op->num_irqs; i++) {
  525. int this_irq = op->irqs[i];
  526. int sbusl = pil_to_sbus[this_irq];
  527. if (sbusl)
  528. this_irq = (((board + 1) << 5) +
  529. (sbusl << 2) +
  530. slot);
  531. op->irqs[i] = this_irq;
  532. }
  533. }
  534. build_resources:
  535. build_device_resources(op, parent);
  536. op->dev.parent = parent;
  537. op->dev.bus = &of_bus_type;
  538. if (!parent)
  539. strcpy(op->dev.bus_id, "root");
  540. else
  541. sprintf(op->dev.bus_id, "%08x", dp->node);
  542. if (of_device_register(op)) {
  543. printk("%s: Could not register of device.\n",
  544. dp->full_name);
  545. kfree(op);
  546. op = NULL;
  547. }
  548. return op;
  549. }
  550. static void __init scan_tree(struct device_node *dp, struct device *parent)
  551. {
  552. while (dp) {
  553. struct of_device *op = scan_one_device(dp, parent);
  554. if (op)
  555. scan_tree(dp->child, &op->dev);
  556. dp = dp->sibling;
  557. }
  558. }
  559. static void __init scan_of_devices(void)
  560. {
  561. struct device_node *root = of_find_node_by_path("/");
  562. struct of_device *parent;
  563. parent = scan_one_device(root, NULL);
  564. if (!parent)
  565. return;
  566. scan_tree(root->child, &parent->dev);
  567. }
  568. static int __init of_bus_driver_init(void)
  569. {
  570. int err;
  571. err = bus_register(&of_bus_type);
  572. #ifdef CONFIG_PCI
  573. if (!err)
  574. err = bus_register(&ebus_bus_type);
  575. #endif
  576. #ifdef CONFIG_SBUS
  577. if (!err)
  578. err = bus_register(&sbus_bus_type);
  579. #endif
  580. if (!err)
  581. scan_of_devices();
  582. return err;
  583. }
  584. postcore_initcall(of_bus_driver_init);
  585. static int __init of_debug(char *str)
  586. {
  587. int val = 0;
  588. get_option(&str, &val);
  589. if (val & 1)
  590. of_resource_verbose = 1;
  591. return 1;
  592. }
  593. __setup("of_debug=", of_debug);
  594. int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus)
  595. {
  596. /* initialize common driver fields */
  597. drv->driver.name = drv->name;
  598. drv->driver.bus = bus;
  599. /* register with core */
  600. return driver_register(&drv->driver);
  601. }
  602. void of_unregister_driver(struct of_platform_driver *drv)
  603. {
  604. driver_unregister(&drv->driver);
  605. }
  606. static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
  607. {
  608. struct of_device *ofdev;
  609. ofdev = to_of_device(dev);
  610. return sprintf(buf, "%s", ofdev->node->full_name);
  611. }
  612. static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
  613. /**
  614. * of_release_dev - free an of device structure when all users of it are finished.
  615. * @dev: device that's been disconnected
  616. *
  617. * Will be called only by the device core when all users of this of device are
  618. * done.
  619. */
  620. void of_release_dev(struct device *dev)
  621. {
  622. struct of_device *ofdev;
  623. ofdev = to_of_device(dev);
  624. kfree(ofdev);
  625. }
  626. int of_device_register(struct of_device *ofdev)
  627. {
  628. int rc;
  629. BUG_ON(ofdev->node == NULL);
  630. rc = device_register(&ofdev->dev);
  631. if (rc)
  632. return rc;
  633. rc = device_create_file(&ofdev->dev, &dev_attr_devspec);
  634. if (rc)
  635. device_unregister(&ofdev->dev);
  636. return rc;
  637. }
  638. void of_device_unregister(struct of_device *ofdev)
  639. {
  640. device_remove_file(&ofdev->dev, &dev_attr_devspec);
  641. device_unregister(&ofdev->dev);
  642. }
  643. struct of_device* of_platform_device_create(struct device_node *np,
  644. const char *bus_id,
  645. struct device *parent,
  646. struct bus_type *bus)
  647. {
  648. struct of_device *dev;
  649. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  650. if (!dev)
  651. return NULL;
  652. dev->dev.parent = parent;
  653. dev->dev.bus = bus;
  654. dev->dev.release = of_release_dev;
  655. strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
  656. if (of_device_register(dev) != 0) {
  657. kfree(dev);
  658. return NULL;
  659. }
  660. return dev;
  661. }
  662. EXPORT_SYMBOL(of_match_device);
  663. EXPORT_SYMBOL(of_register_driver);
  664. EXPORT_SYMBOL(of_unregister_driver);
  665. EXPORT_SYMBOL(of_device_register);
  666. EXPORT_SYMBOL(of_device_unregister);
  667. EXPORT_SYMBOL(of_dev_get);
  668. EXPORT_SYMBOL(of_dev_put);
  669. EXPORT_SYMBOL(of_platform_device_create);
  670. EXPORT_SYMBOL(of_release_dev);