ibmebus.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. * IBM PowerPC IBM eBus Infrastructure Support.
  3. *
  4. * Copyright (c) 2005 IBM Corporation
  5. * Joachim Fenkes <fenkes@de.ibm.com>
  6. * Heiko J Schick <schickhj@de.ibm.com>
  7. *
  8. * All rights reserved.
  9. *
  10. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  11. * BSD.
  12. *
  13. * OpenIB BSD License
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  33. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  34. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. */
  38. #include <linux/init.h>
  39. #include <linux/export.h>
  40. #include <linux/console.h>
  41. #include <linux/kobject.h>
  42. #include <linux/dma-mapping.h>
  43. #include <linux/interrupt.h>
  44. #include <linux/of.h>
  45. #include <linux/slab.h>
  46. #include <linux/stat.h>
  47. #include <linux/of_platform.h>
  48. #include <asm/ibmebus.h>
  49. #include <asm/abs_addr.h>
  50. static struct device ibmebus_bus_device = { /* fake "parent" device */
  51. .init_name = "ibmebus",
  52. };
  53. struct bus_type ibmebus_bus_type;
  54. /* These devices will automatically be added to the bus during init */
  55. static struct of_device_id __initdata ibmebus_matches[] = {
  56. { .compatible = "IBM,lhca" },
  57. { .compatible = "IBM,lhea" },
  58. {},
  59. };
  60. static void *ibmebus_alloc_coherent(struct device *dev,
  61. size_t size,
  62. dma_addr_t *dma_handle,
  63. gfp_t flag,
  64. struct dma_attrs *attrs)
  65. {
  66. void *mem;
  67. mem = kmalloc(size, flag);
  68. *dma_handle = (dma_addr_t)mem;
  69. return mem;
  70. }
  71. static void ibmebus_free_coherent(struct device *dev,
  72. size_t size, void *vaddr,
  73. dma_addr_t dma_handle,
  74. struct dma_attrs *attrs)
  75. {
  76. kfree(vaddr);
  77. }
  78. static dma_addr_t ibmebus_map_page(struct device *dev,
  79. struct page *page,
  80. unsigned long offset,
  81. size_t size,
  82. enum dma_data_direction direction,
  83. struct dma_attrs *attrs)
  84. {
  85. return (dma_addr_t)(page_address(page) + offset);
  86. }
  87. static void ibmebus_unmap_page(struct device *dev,
  88. dma_addr_t dma_addr,
  89. size_t size,
  90. enum dma_data_direction direction,
  91. struct dma_attrs *attrs)
  92. {
  93. return;
  94. }
  95. static int ibmebus_map_sg(struct device *dev,
  96. struct scatterlist *sgl,
  97. int nents, enum dma_data_direction direction,
  98. struct dma_attrs *attrs)
  99. {
  100. struct scatterlist *sg;
  101. int i;
  102. for_each_sg(sgl, sg, nents, i) {
  103. sg->dma_address = (dma_addr_t) sg_virt(sg);
  104. sg->dma_length = sg->length;
  105. }
  106. return nents;
  107. }
  108. static void ibmebus_unmap_sg(struct device *dev,
  109. struct scatterlist *sg,
  110. int nents, enum dma_data_direction direction,
  111. struct dma_attrs *attrs)
  112. {
  113. return;
  114. }
  115. static int ibmebus_dma_supported(struct device *dev, u64 mask)
  116. {
  117. return mask == DMA_BIT_MASK(64);
  118. }
  119. static u64 ibmebus_dma_get_required_mask(struct device *dev)
  120. {
  121. return DMA_BIT_MASK(64);
  122. }
  123. static struct dma_map_ops ibmebus_dma_ops = {
  124. .alloc = ibmebus_alloc_coherent,
  125. .free = ibmebus_free_coherent,
  126. .map_sg = ibmebus_map_sg,
  127. .unmap_sg = ibmebus_unmap_sg,
  128. .dma_supported = ibmebus_dma_supported,
  129. .get_required_mask = ibmebus_dma_get_required_mask,
  130. .map_page = ibmebus_map_page,
  131. .unmap_page = ibmebus_unmap_page,
  132. };
  133. static int ibmebus_match_path(struct device *dev, void *data)
  134. {
  135. struct device_node *dn = to_platform_device(dev)->dev.of_node;
  136. return (dn->full_name &&
  137. (strcasecmp((char *)data, dn->full_name) == 0));
  138. }
  139. static int ibmebus_match_node(struct device *dev, void *data)
  140. {
  141. return to_platform_device(dev)->dev.of_node == data;
  142. }
  143. static int ibmebus_create_device(struct device_node *dn)
  144. {
  145. struct platform_device *dev;
  146. int ret;
  147. dev = of_device_alloc(dn, NULL, &ibmebus_bus_device);
  148. if (!dev)
  149. return -ENOMEM;
  150. dev->dev.bus = &ibmebus_bus_type;
  151. dev->dev.archdata.dma_ops = &ibmebus_dma_ops;
  152. ret = of_device_add(dev);
  153. if (ret)
  154. platform_device_put(dev);
  155. return ret;
  156. }
  157. static int ibmebus_create_devices(const struct of_device_id *matches)
  158. {
  159. struct device_node *root, *child;
  160. int ret = 0;
  161. root = of_find_node_by_path("/");
  162. for_each_child_of_node(root, child) {
  163. if (!of_match_node(matches, child))
  164. continue;
  165. if (bus_find_device(&ibmebus_bus_type, NULL, child,
  166. ibmebus_match_node))
  167. continue;
  168. ret = ibmebus_create_device(child);
  169. if (ret) {
  170. printk(KERN_ERR "%s: failed to create device (%i)",
  171. __func__, ret);
  172. of_node_put(child);
  173. break;
  174. }
  175. }
  176. of_node_put(root);
  177. return ret;
  178. }
  179. int ibmebus_register_driver(struct of_platform_driver *drv)
  180. {
  181. /* If the driver uses devices that ibmebus doesn't know, add them */
  182. ibmebus_create_devices(drv->driver.of_match_table);
  183. drv->driver.bus = &ibmebus_bus_type;
  184. return driver_register(&drv->driver);
  185. }
  186. EXPORT_SYMBOL(ibmebus_register_driver);
  187. void ibmebus_unregister_driver(struct of_platform_driver *drv)
  188. {
  189. driver_unregister(&drv->driver);
  190. }
  191. EXPORT_SYMBOL(ibmebus_unregister_driver);
  192. int ibmebus_request_irq(u32 ist, irq_handler_t handler,
  193. unsigned long irq_flags, const char *devname,
  194. void *dev_id)
  195. {
  196. unsigned int irq = irq_create_mapping(NULL, ist);
  197. if (irq == NO_IRQ)
  198. return -EINVAL;
  199. return request_irq(irq, handler, irq_flags, devname, dev_id);
  200. }
  201. EXPORT_SYMBOL(ibmebus_request_irq);
  202. void ibmebus_free_irq(u32 ist, void *dev_id)
  203. {
  204. unsigned int irq = irq_find_mapping(NULL, ist);
  205. free_irq(irq, dev_id);
  206. irq_dispose_mapping(irq);
  207. }
  208. EXPORT_SYMBOL(ibmebus_free_irq);
  209. static char *ibmebus_chomp(const char *in, size_t count)
  210. {
  211. char *out = kmalloc(count + 1, GFP_KERNEL);
  212. if (!out)
  213. return NULL;
  214. memcpy(out, in, count);
  215. out[count] = '\0';
  216. if (out[count - 1] == '\n')
  217. out[count - 1] = '\0';
  218. return out;
  219. }
  220. static ssize_t ibmebus_store_probe(struct bus_type *bus,
  221. const char *buf, size_t count)
  222. {
  223. struct device_node *dn = NULL;
  224. char *path;
  225. ssize_t rc = 0;
  226. path = ibmebus_chomp(buf, count);
  227. if (!path)
  228. return -ENOMEM;
  229. if (bus_find_device(&ibmebus_bus_type, NULL, path,
  230. ibmebus_match_path)) {
  231. printk(KERN_WARNING "%s: %s has already been probed\n",
  232. __func__, path);
  233. rc = -EEXIST;
  234. goto out;
  235. }
  236. if ((dn = of_find_node_by_path(path))) {
  237. rc = ibmebus_create_device(dn);
  238. of_node_put(dn);
  239. } else {
  240. printk(KERN_WARNING "%s: no such device node: %s\n",
  241. __func__, path);
  242. rc = -ENODEV;
  243. }
  244. out:
  245. kfree(path);
  246. if (rc)
  247. return rc;
  248. return count;
  249. }
  250. static ssize_t ibmebus_store_remove(struct bus_type *bus,
  251. const char *buf, size_t count)
  252. {
  253. struct device *dev;
  254. char *path;
  255. path = ibmebus_chomp(buf, count);
  256. if (!path)
  257. return -ENOMEM;
  258. if ((dev = bus_find_device(&ibmebus_bus_type, NULL, path,
  259. ibmebus_match_path))) {
  260. of_device_unregister(to_platform_device(dev));
  261. kfree(path);
  262. return count;
  263. } else {
  264. printk(KERN_WARNING "%s: %s not on the bus\n",
  265. __func__, path);
  266. kfree(path);
  267. return -ENODEV;
  268. }
  269. }
  270. static struct bus_attribute ibmebus_bus_attrs[] = {
  271. __ATTR(probe, S_IWUSR, NULL, ibmebus_store_probe),
  272. __ATTR(remove, S_IWUSR, NULL, ibmebus_store_remove),
  273. __ATTR_NULL
  274. };
  275. static int ibmebus_bus_bus_match(struct device *dev, struct device_driver *drv)
  276. {
  277. const struct of_device_id *matches = drv->of_match_table;
  278. if (!matches)
  279. return 0;
  280. return of_match_device(matches, dev) != NULL;
  281. }
  282. static int ibmebus_bus_device_probe(struct device *dev)
  283. {
  284. int error = -ENODEV;
  285. struct of_platform_driver *drv;
  286. struct platform_device *of_dev;
  287. const struct of_device_id *match;
  288. drv = to_of_platform_driver(dev->driver);
  289. of_dev = to_platform_device(dev);
  290. if (!drv->probe)
  291. return error;
  292. of_dev_get(of_dev);
  293. match = of_match_device(drv->driver.of_match_table, dev);
  294. if (match)
  295. error = drv->probe(of_dev, match);
  296. if (error)
  297. of_dev_put(of_dev);
  298. return error;
  299. }
  300. static int ibmebus_bus_device_remove(struct device *dev)
  301. {
  302. struct platform_device *of_dev = to_platform_device(dev);
  303. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  304. if (dev->driver && drv->remove)
  305. drv->remove(of_dev);
  306. return 0;
  307. }
  308. static void ibmebus_bus_device_shutdown(struct device *dev)
  309. {
  310. struct platform_device *of_dev = to_platform_device(dev);
  311. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  312. if (dev->driver && drv->shutdown)
  313. drv->shutdown(of_dev);
  314. }
  315. /*
  316. * ibmebus_bus_device_attrs
  317. */
  318. static ssize_t devspec_show(struct device *dev,
  319. struct device_attribute *attr, char *buf)
  320. {
  321. struct platform_device *ofdev;
  322. ofdev = to_platform_device(dev);
  323. return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
  324. }
  325. static ssize_t name_show(struct device *dev,
  326. struct device_attribute *attr, char *buf)
  327. {
  328. struct platform_device *ofdev;
  329. ofdev = to_platform_device(dev);
  330. return sprintf(buf, "%s\n", ofdev->dev.of_node->name);
  331. }
  332. static ssize_t modalias_show(struct device *dev,
  333. struct device_attribute *attr, char *buf)
  334. {
  335. ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
  336. buf[len] = '\n';
  337. buf[len+1] = 0;
  338. return len+1;
  339. }
  340. struct device_attribute ibmebus_bus_device_attrs[] = {
  341. __ATTR_RO(devspec),
  342. __ATTR_RO(name),
  343. __ATTR_RO(modalias),
  344. __ATTR_NULL
  345. };
  346. #ifdef CONFIG_PM_SLEEP
  347. static int ibmebus_bus_legacy_suspend(struct device *dev, pm_message_t mesg)
  348. {
  349. struct platform_device *of_dev = to_platform_device(dev);
  350. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  351. int ret = 0;
  352. if (dev->driver && drv->suspend)
  353. ret = drv->suspend(of_dev, mesg);
  354. return ret;
  355. }
  356. static int ibmebus_bus_legacy_resume(struct device *dev)
  357. {
  358. struct platform_device *of_dev = to_platform_device(dev);
  359. struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
  360. int ret = 0;
  361. if (dev->driver && drv->resume)
  362. ret = drv->resume(of_dev);
  363. return ret;
  364. }
  365. static int ibmebus_bus_pm_prepare(struct device *dev)
  366. {
  367. struct device_driver *drv = dev->driver;
  368. int ret = 0;
  369. if (drv && drv->pm && drv->pm->prepare)
  370. ret = drv->pm->prepare(dev);
  371. return ret;
  372. }
  373. static void ibmebus_bus_pm_complete(struct device *dev)
  374. {
  375. struct device_driver *drv = dev->driver;
  376. if (drv && drv->pm && drv->pm->complete)
  377. drv->pm->complete(dev);
  378. }
  379. #ifdef CONFIG_SUSPEND
  380. static int ibmebus_bus_pm_suspend(struct device *dev)
  381. {
  382. struct device_driver *drv = dev->driver;
  383. int ret = 0;
  384. if (!drv)
  385. return 0;
  386. if (drv->pm) {
  387. if (drv->pm->suspend)
  388. ret = drv->pm->suspend(dev);
  389. } else {
  390. ret = ibmebus_bus_legacy_suspend(dev, PMSG_SUSPEND);
  391. }
  392. return ret;
  393. }
  394. static int ibmebus_bus_pm_suspend_noirq(struct device *dev)
  395. {
  396. struct device_driver *drv = dev->driver;
  397. int ret = 0;
  398. if (!drv)
  399. return 0;
  400. if (drv->pm) {
  401. if (drv->pm->suspend_noirq)
  402. ret = drv->pm->suspend_noirq(dev);
  403. }
  404. return ret;
  405. }
  406. static int ibmebus_bus_pm_resume(struct device *dev)
  407. {
  408. struct device_driver *drv = dev->driver;
  409. int ret = 0;
  410. if (!drv)
  411. return 0;
  412. if (drv->pm) {
  413. if (drv->pm->resume)
  414. ret = drv->pm->resume(dev);
  415. } else {
  416. ret = ibmebus_bus_legacy_resume(dev);
  417. }
  418. return ret;
  419. }
  420. static int ibmebus_bus_pm_resume_noirq(struct device *dev)
  421. {
  422. struct device_driver *drv = dev->driver;
  423. int ret = 0;
  424. if (!drv)
  425. return 0;
  426. if (drv->pm) {
  427. if (drv->pm->resume_noirq)
  428. ret = drv->pm->resume_noirq(dev);
  429. }
  430. return ret;
  431. }
  432. #else /* !CONFIG_SUSPEND */
  433. #define ibmebus_bus_pm_suspend NULL
  434. #define ibmebus_bus_pm_resume NULL
  435. #define ibmebus_bus_pm_suspend_noirq NULL
  436. #define ibmebus_bus_pm_resume_noirq NULL
  437. #endif /* !CONFIG_SUSPEND */
  438. #ifdef CONFIG_HIBERNATE_CALLBACKS
  439. static int ibmebus_bus_pm_freeze(struct device *dev)
  440. {
  441. struct device_driver *drv = dev->driver;
  442. int ret = 0;
  443. if (!drv)
  444. return 0;
  445. if (drv->pm) {
  446. if (drv->pm->freeze)
  447. ret = drv->pm->freeze(dev);
  448. } else {
  449. ret = ibmebus_bus_legacy_suspend(dev, PMSG_FREEZE);
  450. }
  451. return ret;
  452. }
  453. static int ibmebus_bus_pm_freeze_noirq(struct device *dev)
  454. {
  455. struct device_driver *drv = dev->driver;
  456. int ret = 0;
  457. if (!drv)
  458. return 0;
  459. if (drv->pm) {
  460. if (drv->pm->freeze_noirq)
  461. ret = drv->pm->freeze_noirq(dev);
  462. }
  463. return ret;
  464. }
  465. static int ibmebus_bus_pm_thaw(struct device *dev)
  466. {
  467. struct device_driver *drv = dev->driver;
  468. int ret = 0;
  469. if (!drv)
  470. return 0;
  471. if (drv->pm) {
  472. if (drv->pm->thaw)
  473. ret = drv->pm->thaw(dev);
  474. } else {
  475. ret = ibmebus_bus_legacy_resume(dev);
  476. }
  477. return ret;
  478. }
  479. static int ibmebus_bus_pm_thaw_noirq(struct device *dev)
  480. {
  481. struct device_driver *drv = dev->driver;
  482. int ret = 0;
  483. if (!drv)
  484. return 0;
  485. if (drv->pm) {
  486. if (drv->pm->thaw_noirq)
  487. ret = drv->pm->thaw_noirq(dev);
  488. }
  489. return ret;
  490. }
  491. static int ibmebus_bus_pm_poweroff(struct device *dev)
  492. {
  493. struct device_driver *drv = dev->driver;
  494. int ret = 0;
  495. if (!drv)
  496. return 0;
  497. if (drv->pm) {
  498. if (drv->pm->poweroff)
  499. ret = drv->pm->poweroff(dev);
  500. } else {
  501. ret = ibmebus_bus_legacy_suspend(dev, PMSG_HIBERNATE);
  502. }
  503. return ret;
  504. }
  505. static int ibmebus_bus_pm_poweroff_noirq(struct device *dev)
  506. {
  507. struct device_driver *drv = dev->driver;
  508. int ret = 0;
  509. if (!drv)
  510. return 0;
  511. if (drv->pm) {
  512. if (drv->pm->poweroff_noirq)
  513. ret = drv->pm->poweroff_noirq(dev);
  514. }
  515. return ret;
  516. }
  517. static int ibmebus_bus_pm_restore(struct device *dev)
  518. {
  519. struct device_driver *drv = dev->driver;
  520. int ret = 0;
  521. if (!drv)
  522. return 0;
  523. if (drv->pm) {
  524. if (drv->pm->restore)
  525. ret = drv->pm->restore(dev);
  526. } else {
  527. ret = ibmebus_bus_legacy_resume(dev);
  528. }
  529. return ret;
  530. }
  531. static int ibmebus_bus_pm_restore_noirq(struct device *dev)
  532. {
  533. struct device_driver *drv = dev->driver;
  534. int ret = 0;
  535. if (!drv)
  536. return 0;
  537. if (drv->pm) {
  538. if (drv->pm->restore_noirq)
  539. ret = drv->pm->restore_noirq(dev);
  540. }
  541. return ret;
  542. }
  543. #else /* !CONFIG_HIBERNATE_CALLBACKS */
  544. #define ibmebus_bus_pm_freeze NULL
  545. #define ibmebus_bus_pm_thaw NULL
  546. #define ibmebus_bus_pm_poweroff NULL
  547. #define ibmebus_bus_pm_restore NULL
  548. #define ibmebus_bus_pm_freeze_noirq NULL
  549. #define ibmebus_bus_pm_thaw_noirq NULL
  550. #define ibmebus_bus_pm_poweroff_noirq NULL
  551. #define ibmebus_bus_pm_restore_noirq NULL
  552. #endif /* !CONFIG_HIBERNATE_CALLBACKS */
  553. static struct dev_pm_ops ibmebus_bus_dev_pm_ops = {
  554. .prepare = ibmebus_bus_pm_prepare,
  555. .complete = ibmebus_bus_pm_complete,
  556. .suspend = ibmebus_bus_pm_suspend,
  557. .resume = ibmebus_bus_pm_resume,
  558. .freeze = ibmebus_bus_pm_freeze,
  559. .thaw = ibmebus_bus_pm_thaw,
  560. .poweroff = ibmebus_bus_pm_poweroff,
  561. .restore = ibmebus_bus_pm_restore,
  562. .suspend_noirq = ibmebus_bus_pm_suspend_noirq,
  563. .resume_noirq = ibmebus_bus_pm_resume_noirq,
  564. .freeze_noirq = ibmebus_bus_pm_freeze_noirq,
  565. .thaw_noirq = ibmebus_bus_pm_thaw_noirq,
  566. .poweroff_noirq = ibmebus_bus_pm_poweroff_noirq,
  567. .restore_noirq = ibmebus_bus_pm_restore_noirq,
  568. };
  569. #define IBMEBUS_BUS_PM_OPS_PTR (&ibmebus_bus_dev_pm_ops)
  570. #else /* !CONFIG_PM_SLEEP */
  571. #define IBMEBUS_BUS_PM_OPS_PTR NULL
  572. #endif /* !CONFIG_PM_SLEEP */
  573. struct bus_type ibmebus_bus_type = {
  574. .name = "ibmebus",
  575. .uevent = of_device_uevent_modalias,
  576. .bus_attrs = ibmebus_bus_attrs,
  577. .match = ibmebus_bus_bus_match,
  578. .probe = ibmebus_bus_device_probe,
  579. .remove = ibmebus_bus_device_remove,
  580. .shutdown = ibmebus_bus_device_shutdown,
  581. .dev_attrs = ibmebus_bus_device_attrs,
  582. .pm = IBMEBUS_BUS_PM_OPS_PTR,
  583. };
  584. EXPORT_SYMBOL(ibmebus_bus_type);
  585. static int __init ibmebus_bus_init(void)
  586. {
  587. int err;
  588. printk(KERN_INFO "IBM eBus Device Driver\n");
  589. err = bus_register(&ibmebus_bus_type);
  590. if (err) {
  591. printk(KERN_ERR "%s: failed to register IBM eBus.\n",
  592. __func__);
  593. return err;
  594. }
  595. err = device_register(&ibmebus_bus_device);
  596. if (err) {
  597. printk(KERN_WARNING "%s: device_register returned %i\n",
  598. __func__, err);
  599. bus_unregister(&ibmebus_bus_type);
  600. return err;
  601. }
  602. err = ibmebus_create_devices(ibmebus_matches);
  603. if (err) {
  604. device_unregister(&ibmebus_bus_device);
  605. bus_unregister(&ibmebus_bus_type);
  606. return err;
  607. }
  608. return 0;
  609. }
  610. postcore_initcall(ibmebus_bus_init);