ibmebus.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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. static struct device ibmebus_bus_device = { /* fake "parent" device */
  50. .init_name = "ibmebus",
  51. };
  52. struct bus_type ibmebus_bus_type;
  53. /* These devices will automatically be added to the bus during init */
  54. static const struct of_device_id ibmebus_matches[] __initconst = {
  55. { .compatible = "IBM,lhca" },
  56. { .compatible = "IBM,lhea" },
  57. {},
  58. };
  59. static void *ibmebus_alloc_coherent(struct device *dev,
  60. size_t size,
  61. dma_addr_t *dma_handle,
  62. gfp_t flag,
  63. struct dma_attrs *attrs)
  64. {
  65. void *mem;
  66. mem = kmalloc(size, flag);
  67. *dma_handle = (dma_addr_t)mem;
  68. return mem;
  69. }
  70. static void ibmebus_free_coherent(struct device *dev,
  71. size_t size, void *vaddr,
  72. dma_addr_t dma_handle,
  73. struct dma_attrs *attrs)
  74. {
  75. kfree(vaddr);
  76. }
  77. static dma_addr_t ibmebus_map_page(struct device *dev,
  78. struct page *page,
  79. unsigned long offset,
  80. size_t size,
  81. enum dma_data_direction direction,
  82. struct dma_attrs *attrs)
  83. {
  84. return (dma_addr_t)(page_address(page) + offset);
  85. }
  86. static void ibmebus_unmap_page(struct device *dev,
  87. dma_addr_t dma_addr,
  88. size_t size,
  89. enum dma_data_direction direction,
  90. struct dma_attrs *attrs)
  91. {
  92. return;
  93. }
  94. static int ibmebus_map_sg(struct device *dev,
  95. struct scatterlist *sgl,
  96. int nents, enum dma_data_direction direction,
  97. struct dma_attrs *attrs)
  98. {
  99. struct scatterlist *sg;
  100. int i;
  101. for_each_sg(sgl, sg, nents, i) {
  102. sg->dma_address = (dma_addr_t) sg_virt(sg);
  103. sg->dma_length = sg->length;
  104. }
  105. return nents;
  106. }
  107. static void ibmebus_unmap_sg(struct device *dev,
  108. struct scatterlist *sg,
  109. int nents, enum dma_data_direction direction,
  110. struct dma_attrs *attrs)
  111. {
  112. return;
  113. }
  114. static int ibmebus_dma_supported(struct device *dev, u64 mask)
  115. {
  116. return mask == DMA_BIT_MASK(64);
  117. }
  118. static u64 ibmebus_dma_get_required_mask(struct device *dev)
  119. {
  120. return DMA_BIT_MASK(64);
  121. }
  122. static struct dma_map_ops ibmebus_dma_ops = {
  123. .alloc = ibmebus_alloc_coherent,
  124. .free = ibmebus_free_coherent,
  125. .map_sg = ibmebus_map_sg,
  126. .unmap_sg = ibmebus_unmap_sg,
  127. .dma_supported = ibmebus_dma_supported,
  128. .get_required_mask = ibmebus_dma_get_required_mask,
  129. .map_page = ibmebus_map_page,
  130. .unmap_page = ibmebus_unmap_page,
  131. };
  132. static int ibmebus_match_path(struct device *dev, void *data)
  133. {
  134. struct device_node *dn = to_platform_device(dev)->dev.of_node;
  135. return (dn->full_name &&
  136. (strcasecmp((char *)data, dn->full_name) == 0));
  137. }
  138. static int ibmebus_match_node(struct device *dev, void *data)
  139. {
  140. return to_platform_device(dev)->dev.of_node == data;
  141. }
  142. static int ibmebus_create_device(struct device_node *dn)
  143. {
  144. struct platform_device *dev;
  145. int ret;
  146. dev = of_device_alloc(dn, NULL, &ibmebus_bus_device);
  147. if (!dev)
  148. return -ENOMEM;
  149. dev->dev.bus = &ibmebus_bus_type;
  150. dev->dev.archdata.dma_ops = &ibmebus_dma_ops;
  151. ret = of_device_add(dev);
  152. if (ret)
  153. platform_device_put(dev);
  154. return ret;
  155. }
  156. static int ibmebus_create_devices(const struct of_device_id *matches)
  157. {
  158. struct device_node *root, *child;
  159. struct device *dev;
  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. dev = bus_find_device(&ibmebus_bus_type, NULL, child,
  166. ibmebus_match_node);
  167. if (dev) {
  168. put_device(dev);
  169. continue;
  170. }
  171. ret = ibmebus_create_device(child);
  172. if (ret) {
  173. printk(KERN_ERR "%s: failed to create device (%i)",
  174. __func__, ret);
  175. of_node_put(child);
  176. break;
  177. }
  178. }
  179. of_node_put(root);
  180. return ret;
  181. }
  182. int ibmebus_register_driver(struct platform_driver *drv)
  183. {
  184. /* If the driver uses devices that ibmebus doesn't know, add them */
  185. ibmebus_create_devices(drv->driver.of_match_table);
  186. drv->driver.bus = &ibmebus_bus_type;
  187. return driver_register(&drv->driver);
  188. }
  189. EXPORT_SYMBOL(ibmebus_register_driver);
  190. void ibmebus_unregister_driver(struct platform_driver *drv)
  191. {
  192. driver_unregister(&drv->driver);
  193. }
  194. EXPORT_SYMBOL(ibmebus_unregister_driver);
  195. int ibmebus_request_irq(u32 ist, irq_handler_t handler,
  196. unsigned long irq_flags, const char *devname,
  197. void *dev_id)
  198. {
  199. unsigned int irq = irq_create_mapping(NULL, ist);
  200. if (irq == NO_IRQ)
  201. return -EINVAL;
  202. return request_irq(irq, handler, irq_flags, devname, dev_id);
  203. }
  204. EXPORT_SYMBOL(ibmebus_request_irq);
  205. void ibmebus_free_irq(u32 ist, void *dev_id)
  206. {
  207. unsigned int irq = irq_find_mapping(NULL, ist);
  208. free_irq(irq, dev_id);
  209. irq_dispose_mapping(irq);
  210. }
  211. EXPORT_SYMBOL(ibmebus_free_irq);
  212. static char *ibmebus_chomp(const char *in, size_t count)
  213. {
  214. char *out = kmalloc(count + 1, GFP_KERNEL);
  215. if (!out)
  216. return NULL;
  217. memcpy(out, in, count);
  218. out[count] = '\0';
  219. if (out[count - 1] == '\n')
  220. out[count - 1] = '\0';
  221. return out;
  222. }
  223. static ssize_t ibmebus_store_probe(struct bus_type *bus,
  224. const char *buf, size_t count)
  225. {
  226. struct device_node *dn = NULL;
  227. struct device *dev;
  228. char *path;
  229. ssize_t rc = 0;
  230. path = ibmebus_chomp(buf, count);
  231. if (!path)
  232. return -ENOMEM;
  233. dev = bus_find_device(&ibmebus_bus_type, NULL, path,
  234. ibmebus_match_path);
  235. if (dev) {
  236. put_device(dev);
  237. printk(KERN_WARNING "%s: %s has already been probed\n",
  238. __func__, path);
  239. rc = -EEXIST;
  240. goto out;
  241. }
  242. if ((dn = of_find_node_by_path(path))) {
  243. rc = ibmebus_create_device(dn);
  244. of_node_put(dn);
  245. } else {
  246. printk(KERN_WARNING "%s: no such device node: %s\n",
  247. __func__, path);
  248. rc = -ENODEV;
  249. }
  250. out:
  251. kfree(path);
  252. if (rc)
  253. return rc;
  254. return count;
  255. }
  256. static BUS_ATTR(probe, S_IWUSR, NULL, ibmebus_store_probe);
  257. static ssize_t ibmebus_store_remove(struct bus_type *bus,
  258. const char *buf, size_t count)
  259. {
  260. struct device *dev;
  261. char *path;
  262. path = ibmebus_chomp(buf, count);
  263. if (!path)
  264. return -ENOMEM;
  265. if ((dev = bus_find_device(&ibmebus_bus_type, NULL, path,
  266. ibmebus_match_path))) {
  267. of_device_unregister(to_platform_device(dev));
  268. put_device(dev);
  269. kfree(path);
  270. return count;
  271. } else {
  272. printk(KERN_WARNING "%s: %s not on the bus\n",
  273. __func__, path);
  274. kfree(path);
  275. return -ENODEV;
  276. }
  277. }
  278. static BUS_ATTR(remove, S_IWUSR, NULL, ibmebus_store_remove);
  279. static struct attribute *ibmbus_bus_attrs[] = {
  280. &bus_attr_probe.attr,
  281. &bus_attr_remove.attr,
  282. NULL,
  283. };
  284. ATTRIBUTE_GROUPS(ibmbus_bus);
  285. static int ibmebus_bus_bus_match(struct device *dev, struct device_driver *drv)
  286. {
  287. const struct of_device_id *matches = drv->of_match_table;
  288. if (!matches)
  289. return 0;
  290. return of_match_device(matches, dev) != NULL;
  291. }
  292. static int ibmebus_bus_device_probe(struct device *dev)
  293. {
  294. int error = -ENODEV;
  295. struct platform_driver *drv;
  296. struct platform_device *of_dev;
  297. drv = to_platform_driver(dev->driver);
  298. of_dev = to_platform_device(dev);
  299. if (!drv->probe)
  300. return error;
  301. of_dev_get(of_dev);
  302. if (of_driver_match_device(dev, dev->driver))
  303. error = drv->probe(of_dev);
  304. if (error)
  305. of_dev_put(of_dev);
  306. return error;
  307. }
  308. static int ibmebus_bus_device_remove(struct device *dev)
  309. {
  310. struct platform_device *of_dev = to_platform_device(dev);
  311. struct platform_driver *drv = to_platform_driver(dev->driver);
  312. if (dev->driver && drv->remove)
  313. drv->remove(of_dev);
  314. return 0;
  315. }
  316. static void ibmebus_bus_device_shutdown(struct device *dev)
  317. {
  318. struct platform_device *of_dev = to_platform_device(dev);
  319. struct platform_driver *drv = to_platform_driver(dev->driver);
  320. if (dev->driver && drv->shutdown)
  321. drv->shutdown(of_dev);
  322. }
  323. /*
  324. * ibmebus_bus_device_attrs
  325. */
  326. static ssize_t devspec_show(struct device *dev,
  327. struct device_attribute *attr, char *buf)
  328. {
  329. struct platform_device *ofdev;
  330. ofdev = to_platform_device(dev);
  331. return sprintf(buf, "%s\n", ofdev->dev.of_node->full_name);
  332. }
  333. static ssize_t name_show(struct device *dev,
  334. struct device_attribute *attr, char *buf)
  335. {
  336. struct platform_device *ofdev;
  337. ofdev = to_platform_device(dev);
  338. return sprintf(buf, "%s\n", ofdev->dev.of_node->name);
  339. }
  340. static ssize_t modalias_show(struct device *dev,
  341. struct device_attribute *attr, char *buf)
  342. {
  343. ssize_t len = of_device_get_modalias(dev, buf, PAGE_SIZE - 2);
  344. buf[len] = '\n';
  345. buf[len+1] = 0;
  346. return len+1;
  347. }
  348. struct device_attribute ibmebus_bus_device_attrs[] = {
  349. __ATTR_RO(devspec),
  350. __ATTR_RO(name),
  351. __ATTR_RO(modalias),
  352. __ATTR_NULL
  353. };
  354. #ifdef CONFIG_PM_SLEEP
  355. static int ibmebus_bus_legacy_suspend(struct device *dev, pm_message_t mesg)
  356. {
  357. struct platform_device *of_dev = to_platform_device(dev);
  358. struct platform_driver *drv = to_platform_driver(dev->driver);
  359. int ret = 0;
  360. if (dev->driver && drv->suspend)
  361. ret = drv->suspend(of_dev, mesg);
  362. return ret;
  363. }
  364. static int ibmebus_bus_legacy_resume(struct device *dev)
  365. {
  366. struct platform_device *of_dev = to_platform_device(dev);
  367. struct platform_driver *drv = to_platform_driver(dev->driver);
  368. int ret = 0;
  369. if (dev->driver && drv->resume)
  370. ret = drv->resume(of_dev);
  371. return ret;
  372. }
  373. static int ibmebus_bus_pm_prepare(struct device *dev)
  374. {
  375. struct device_driver *drv = dev->driver;
  376. int ret = 0;
  377. if (drv && drv->pm && drv->pm->prepare)
  378. ret = drv->pm->prepare(dev);
  379. return ret;
  380. }
  381. static void ibmebus_bus_pm_complete(struct device *dev)
  382. {
  383. struct device_driver *drv = dev->driver;
  384. if (drv && drv->pm && drv->pm->complete)
  385. drv->pm->complete(dev);
  386. }
  387. #ifdef CONFIG_SUSPEND
  388. static int ibmebus_bus_pm_suspend(struct device *dev)
  389. {
  390. struct device_driver *drv = dev->driver;
  391. int ret = 0;
  392. if (!drv)
  393. return 0;
  394. if (drv->pm) {
  395. if (drv->pm->suspend)
  396. ret = drv->pm->suspend(dev);
  397. } else {
  398. ret = ibmebus_bus_legacy_suspend(dev, PMSG_SUSPEND);
  399. }
  400. return ret;
  401. }
  402. static int ibmebus_bus_pm_suspend_noirq(struct device *dev)
  403. {
  404. struct device_driver *drv = dev->driver;
  405. int ret = 0;
  406. if (!drv)
  407. return 0;
  408. if (drv->pm) {
  409. if (drv->pm->suspend_noirq)
  410. ret = drv->pm->suspend_noirq(dev);
  411. }
  412. return ret;
  413. }
  414. static int ibmebus_bus_pm_resume(struct device *dev)
  415. {
  416. struct device_driver *drv = dev->driver;
  417. int ret = 0;
  418. if (!drv)
  419. return 0;
  420. if (drv->pm) {
  421. if (drv->pm->resume)
  422. ret = drv->pm->resume(dev);
  423. } else {
  424. ret = ibmebus_bus_legacy_resume(dev);
  425. }
  426. return ret;
  427. }
  428. static int ibmebus_bus_pm_resume_noirq(struct device *dev)
  429. {
  430. struct device_driver *drv = dev->driver;
  431. int ret = 0;
  432. if (!drv)
  433. return 0;
  434. if (drv->pm) {
  435. if (drv->pm->resume_noirq)
  436. ret = drv->pm->resume_noirq(dev);
  437. }
  438. return ret;
  439. }
  440. #else /* !CONFIG_SUSPEND */
  441. #define ibmebus_bus_pm_suspend NULL
  442. #define ibmebus_bus_pm_resume NULL
  443. #define ibmebus_bus_pm_suspend_noirq NULL
  444. #define ibmebus_bus_pm_resume_noirq NULL
  445. #endif /* !CONFIG_SUSPEND */
  446. #ifdef CONFIG_HIBERNATE_CALLBACKS
  447. static int ibmebus_bus_pm_freeze(struct device *dev)
  448. {
  449. struct device_driver *drv = dev->driver;
  450. int ret = 0;
  451. if (!drv)
  452. return 0;
  453. if (drv->pm) {
  454. if (drv->pm->freeze)
  455. ret = drv->pm->freeze(dev);
  456. } else {
  457. ret = ibmebus_bus_legacy_suspend(dev, PMSG_FREEZE);
  458. }
  459. return ret;
  460. }
  461. static int ibmebus_bus_pm_freeze_noirq(struct device *dev)
  462. {
  463. struct device_driver *drv = dev->driver;
  464. int ret = 0;
  465. if (!drv)
  466. return 0;
  467. if (drv->pm) {
  468. if (drv->pm->freeze_noirq)
  469. ret = drv->pm->freeze_noirq(dev);
  470. }
  471. return ret;
  472. }
  473. static int ibmebus_bus_pm_thaw(struct device *dev)
  474. {
  475. struct device_driver *drv = dev->driver;
  476. int ret = 0;
  477. if (!drv)
  478. return 0;
  479. if (drv->pm) {
  480. if (drv->pm->thaw)
  481. ret = drv->pm->thaw(dev);
  482. } else {
  483. ret = ibmebus_bus_legacy_resume(dev);
  484. }
  485. return ret;
  486. }
  487. static int ibmebus_bus_pm_thaw_noirq(struct device *dev)
  488. {
  489. struct device_driver *drv = dev->driver;
  490. int ret = 0;
  491. if (!drv)
  492. return 0;
  493. if (drv->pm) {
  494. if (drv->pm->thaw_noirq)
  495. ret = drv->pm->thaw_noirq(dev);
  496. }
  497. return ret;
  498. }
  499. static int ibmebus_bus_pm_poweroff(struct device *dev)
  500. {
  501. struct device_driver *drv = dev->driver;
  502. int ret = 0;
  503. if (!drv)
  504. return 0;
  505. if (drv->pm) {
  506. if (drv->pm->poweroff)
  507. ret = drv->pm->poweroff(dev);
  508. } else {
  509. ret = ibmebus_bus_legacy_suspend(dev, PMSG_HIBERNATE);
  510. }
  511. return ret;
  512. }
  513. static int ibmebus_bus_pm_poweroff_noirq(struct device *dev)
  514. {
  515. struct device_driver *drv = dev->driver;
  516. int ret = 0;
  517. if (!drv)
  518. return 0;
  519. if (drv->pm) {
  520. if (drv->pm->poweroff_noirq)
  521. ret = drv->pm->poweroff_noirq(dev);
  522. }
  523. return ret;
  524. }
  525. static int ibmebus_bus_pm_restore(struct device *dev)
  526. {
  527. struct device_driver *drv = dev->driver;
  528. int ret = 0;
  529. if (!drv)
  530. return 0;
  531. if (drv->pm) {
  532. if (drv->pm->restore)
  533. ret = drv->pm->restore(dev);
  534. } else {
  535. ret = ibmebus_bus_legacy_resume(dev);
  536. }
  537. return ret;
  538. }
  539. static int ibmebus_bus_pm_restore_noirq(struct device *dev)
  540. {
  541. struct device_driver *drv = dev->driver;
  542. int ret = 0;
  543. if (!drv)
  544. return 0;
  545. if (drv->pm) {
  546. if (drv->pm->restore_noirq)
  547. ret = drv->pm->restore_noirq(dev);
  548. }
  549. return ret;
  550. }
  551. #else /* !CONFIG_HIBERNATE_CALLBACKS */
  552. #define ibmebus_bus_pm_freeze NULL
  553. #define ibmebus_bus_pm_thaw NULL
  554. #define ibmebus_bus_pm_poweroff NULL
  555. #define ibmebus_bus_pm_restore NULL
  556. #define ibmebus_bus_pm_freeze_noirq NULL
  557. #define ibmebus_bus_pm_thaw_noirq NULL
  558. #define ibmebus_bus_pm_poweroff_noirq NULL
  559. #define ibmebus_bus_pm_restore_noirq NULL
  560. #endif /* !CONFIG_HIBERNATE_CALLBACKS */
  561. static struct dev_pm_ops ibmebus_bus_dev_pm_ops = {
  562. .prepare = ibmebus_bus_pm_prepare,
  563. .complete = ibmebus_bus_pm_complete,
  564. .suspend = ibmebus_bus_pm_suspend,
  565. .resume = ibmebus_bus_pm_resume,
  566. .freeze = ibmebus_bus_pm_freeze,
  567. .thaw = ibmebus_bus_pm_thaw,
  568. .poweroff = ibmebus_bus_pm_poweroff,
  569. .restore = ibmebus_bus_pm_restore,
  570. .suspend_noirq = ibmebus_bus_pm_suspend_noirq,
  571. .resume_noirq = ibmebus_bus_pm_resume_noirq,
  572. .freeze_noirq = ibmebus_bus_pm_freeze_noirq,
  573. .thaw_noirq = ibmebus_bus_pm_thaw_noirq,
  574. .poweroff_noirq = ibmebus_bus_pm_poweroff_noirq,
  575. .restore_noirq = ibmebus_bus_pm_restore_noirq,
  576. };
  577. #define IBMEBUS_BUS_PM_OPS_PTR (&ibmebus_bus_dev_pm_ops)
  578. #else /* !CONFIG_PM_SLEEP */
  579. #define IBMEBUS_BUS_PM_OPS_PTR NULL
  580. #endif /* !CONFIG_PM_SLEEP */
  581. struct bus_type ibmebus_bus_type = {
  582. .name = "ibmebus",
  583. .uevent = of_device_uevent_modalias,
  584. .bus_groups = ibmbus_bus_groups,
  585. .match = ibmebus_bus_bus_match,
  586. .probe = ibmebus_bus_device_probe,
  587. .remove = ibmebus_bus_device_remove,
  588. .shutdown = ibmebus_bus_device_shutdown,
  589. .dev_attrs = ibmebus_bus_device_attrs,
  590. .pm = IBMEBUS_BUS_PM_OPS_PTR,
  591. };
  592. EXPORT_SYMBOL(ibmebus_bus_type);
  593. static int __init ibmebus_bus_init(void)
  594. {
  595. int err;
  596. printk(KERN_INFO "IBM eBus Device Driver\n");
  597. err = bus_register(&ibmebus_bus_type);
  598. if (err) {
  599. printk(KERN_ERR "%s: failed to register IBM eBus.\n",
  600. __func__);
  601. return err;
  602. }
  603. err = device_register(&ibmebus_bus_device);
  604. if (err) {
  605. printk(KERN_WARNING "%s: device_register returned %i\n",
  606. __func__, err);
  607. bus_unregister(&ibmebus_bus_type);
  608. return err;
  609. }
  610. err = ibmebus_create_devices(ibmebus_matches);
  611. if (err) {
  612. device_unregister(&ibmebus_bus_device);
  613. bus_unregister(&ibmebus_bus_type);
  614. return err;
  615. }
  616. return 0;
  617. }
  618. postcore_initcall(ibmebus_bus_init);