of_device.c 17 KB

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