maple.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * Core maple bus functionality
  3. *
  4. * Copyright (C) 2007 Adrian McMenamin
  5. *
  6. * Based on 2.4 code by:
  7. *
  8. * Copyright (C) 2000-2001 YAEGASHI Takeshi
  9. * Copyright (C) 2001 M. R. Brown
  10. * Copyright (C) 2001 Paul Mundt
  11. *
  12. * and others.
  13. *
  14. * This file is subject to the terms and conditions of the GNU General Public
  15. * License. See the file "COPYING" in the main directory of this archive
  16. * for more details.
  17. */
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/device.h>
  21. #include <linux/module.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/list.h>
  24. #include <linux/io.h>
  25. #include <linux/slab.h>
  26. #include <linux/maple.h>
  27. #include <linux/dma-mapping.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/dma.h>
  30. #include <asm/io.h>
  31. #include <asm/mach/dma.h>
  32. #include <asm/mach/sysasic.h>
  33. #include <asm/mach/maple.h>
  34. MODULE_AUTHOR("Yaegshi Takeshi, Paul Mundt, M.R. Brown, Adrian McMenamin");
  35. MODULE_DESCRIPTION("Maple bus driver for Dreamcast");
  36. MODULE_LICENSE("GPL v2");
  37. MODULE_SUPPORTED_DEVICE("{{SEGA, Dreamcast/Maple}}");
  38. static void maple_dma_handler(struct work_struct *work);
  39. static void maple_vblank_handler(struct work_struct *work);
  40. static DECLARE_WORK(maple_dma_process, maple_dma_handler);
  41. static DECLARE_WORK(maple_vblank_process, maple_vblank_handler);
  42. static LIST_HEAD(maple_waitq);
  43. static LIST_HEAD(maple_sentq);
  44. static DEFINE_MUTEX(maple_list_lock);
  45. static struct maple_driver maple_dummy_driver;
  46. static struct device maple_bus;
  47. static int subdevice_map[MAPLE_PORTS];
  48. static unsigned long *maple_sendbuf, *maple_sendptr, *maple_lastptr;
  49. static unsigned long maple_pnp_time;
  50. static int started, scanning, liststatus;
  51. static struct kmem_cache *maple_queue_cache;
  52. struct maple_device_specify {
  53. int port;
  54. int unit;
  55. };
  56. /**
  57. * maple_driver_register - register a device driver
  58. * automatically makes the driver bus a maple bus
  59. * @drv: the driver to be registered
  60. */
  61. int maple_driver_register(struct device_driver *drv)
  62. {
  63. if (!drv)
  64. return -EINVAL;
  65. drv->bus = &maple_bus_type;
  66. return driver_register(drv);
  67. }
  68. EXPORT_SYMBOL_GPL(maple_driver_register);
  69. /* set hardware registers to enable next round of dma */
  70. static void maplebus_dma_reset(void)
  71. {
  72. ctrl_outl(MAPLE_MAGIC, MAPLE_RESET);
  73. /* set trig type to 0 for software trigger, 1 for hardware (VBLANK) */
  74. ctrl_outl(1, MAPLE_TRIGTYPE);
  75. ctrl_outl(MAPLE_2MBPS | MAPLE_TIMEOUT(50000), MAPLE_SPEED);
  76. ctrl_outl(PHYSADDR(maple_sendbuf), MAPLE_DMAADDR);
  77. ctrl_outl(1, MAPLE_ENABLE);
  78. }
  79. /**
  80. * maple_getcond_callback - setup handling MAPLE_COMMAND_GETCOND
  81. * @dev: device responding
  82. * @callback: handler callback
  83. * @interval: interval in jiffies between callbacks
  84. * @function: the function code for the device
  85. */
  86. void maple_getcond_callback(struct maple_device *dev,
  87. void (*callback) (struct mapleq * mq),
  88. unsigned long interval, unsigned long function)
  89. {
  90. dev->callback = callback;
  91. dev->interval = interval;
  92. dev->function = cpu_to_be32(function);
  93. dev->when = jiffies;
  94. }
  95. EXPORT_SYMBOL_GPL(maple_getcond_callback);
  96. static int maple_dma_done(void)
  97. {
  98. return (ctrl_inl(MAPLE_STATE) & 1) == 0;
  99. }
  100. static void maple_release_device(struct device *dev)
  101. {
  102. if (dev->type) {
  103. kfree(dev->type->name);
  104. kfree(dev->type);
  105. }
  106. }
  107. /**
  108. * maple_add_packet - add a single instruction to the queue
  109. * @mq: instruction to add to waiting queue
  110. */
  111. void maple_add_packet(struct mapleq *mq)
  112. {
  113. mutex_lock(&maple_list_lock);
  114. list_add(&mq->list, &maple_waitq);
  115. mutex_unlock(&maple_list_lock);
  116. }
  117. EXPORT_SYMBOL_GPL(maple_add_packet);
  118. static struct mapleq *maple_allocq(struct maple_device *dev)
  119. {
  120. struct mapleq *mq;
  121. mq = kmalloc(sizeof(*mq), GFP_KERNEL);
  122. if (!mq)
  123. return NULL;
  124. mq->dev = dev;
  125. mq->recvbufdcsp = kmem_cache_zalloc(maple_queue_cache, GFP_KERNEL);
  126. mq->recvbuf = (void *) P2SEGADDR(mq->recvbufdcsp);
  127. if (!mq->recvbuf) {
  128. kfree(mq);
  129. return NULL;
  130. }
  131. return mq;
  132. }
  133. static struct maple_device *maple_alloc_dev(int port, int unit)
  134. {
  135. struct maple_device *dev;
  136. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  137. if (!dev)
  138. return NULL;
  139. dev->port = port;
  140. dev->unit = unit;
  141. dev->mq = maple_allocq(dev);
  142. if (!dev->mq) {
  143. kfree(dev);
  144. return NULL;
  145. }
  146. return dev;
  147. }
  148. static void maple_free_dev(struct maple_device *mdev)
  149. {
  150. if (!mdev)
  151. return;
  152. if (mdev->mq) {
  153. kmem_cache_free(maple_queue_cache, mdev->mq->recvbufdcsp);
  154. kfree(mdev->mq);
  155. }
  156. kfree(mdev);
  157. }
  158. /* process the command queue into a maple command block
  159. * terminating command has bit 32 of first long set to 0
  160. */
  161. static void maple_build_block(struct mapleq *mq)
  162. {
  163. int port, unit, from, to, len;
  164. unsigned long *lsendbuf = mq->sendbuf;
  165. port = mq->dev->port & 3;
  166. unit = mq->dev->unit;
  167. len = mq->length;
  168. from = port << 6;
  169. to = (port << 6) | (unit > 0 ? (1 << (unit - 1)) & 0x1f : 0x20);
  170. *maple_lastptr &= 0x7fffffff;
  171. maple_lastptr = maple_sendptr;
  172. *maple_sendptr++ = (port << 16) | len | 0x80000000;
  173. *maple_sendptr++ = PHYSADDR(mq->recvbuf);
  174. *maple_sendptr++ =
  175. mq->command | (to << 8) | (from << 16) | (len << 24);
  176. while (len-- > 0)
  177. *maple_sendptr++ = *lsendbuf++;
  178. }
  179. /* build up command queue */
  180. static void maple_send(void)
  181. {
  182. int i;
  183. int maple_packets;
  184. struct mapleq *mq, *nmq;
  185. if (!list_empty(&maple_sentq))
  186. return;
  187. if (list_empty(&maple_waitq) || !maple_dma_done())
  188. return;
  189. maple_packets = 0;
  190. maple_sendptr = maple_lastptr = maple_sendbuf;
  191. list_for_each_entry_safe(mq, nmq, &maple_waitq, list) {
  192. maple_build_block(mq);
  193. list_move(&mq->list, &maple_sentq);
  194. if (maple_packets++ > MAPLE_MAXPACKETS)
  195. break;
  196. }
  197. if (maple_packets > 0) {
  198. for (i = 0; i < (1 << MAPLE_DMA_PAGES); i++)
  199. dma_cache_sync(0, maple_sendbuf + i * PAGE_SIZE,
  200. PAGE_SIZE, DMA_BIDIRECTIONAL);
  201. }
  202. }
  203. static int attach_matching_maple_driver(struct device_driver *driver,
  204. void *devptr)
  205. {
  206. struct maple_driver *maple_drv;
  207. struct maple_device *mdev;
  208. mdev = devptr;
  209. maple_drv = to_maple_driver(driver);
  210. if (mdev->devinfo.function & be32_to_cpu(maple_drv->function)) {
  211. if (maple_drv->connect(mdev) == 0) {
  212. mdev->driver = maple_drv;
  213. return 1;
  214. }
  215. }
  216. return 0;
  217. }
  218. static void maple_detach_driver(struct maple_device *mdev)
  219. {
  220. if (!mdev)
  221. return;
  222. if (mdev->driver) {
  223. if (mdev->driver->disconnect)
  224. mdev->driver->disconnect(mdev);
  225. }
  226. mdev->driver = NULL;
  227. if (mdev->registered) {
  228. maple_release_device(&mdev->dev);
  229. device_unregister(&mdev->dev);
  230. }
  231. mdev->registered = 0;
  232. maple_free_dev(mdev);
  233. }
  234. /* process initial MAPLE_COMMAND_DEVINFO for each device or port */
  235. static void maple_attach_driver(struct maple_device *dev)
  236. {
  237. char *p;
  238. char *recvbuf;
  239. unsigned long function;
  240. int matched, retval;
  241. recvbuf = dev->mq->recvbuf;
  242. memcpy(&dev->devinfo, recvbuf + 4, sizeof(dev->devinfo));
  243. memcpy(dev->product_name, dev->devinfo.product_name, 30);
  244. memcpy(dev->product_licence, dev->devinfo.product_licence, 60);
  245. dev->product_name[30] = '\0';
  246. dev->product_licence[60] = '\0';
  247. for (p = dev->product_name + 29; dev->product_name <= p; p--)
  248. if (*p == ' ')
  249. *p = '\0';
  250. else
  251. break;
  252. for (p = dev->product_licence + 59; dev->product_licence <= p; p--)
  253. if (*p == ' ')
  254. *p = '\0';
  255. else
  256. break;
  257. function = be32_to_cpu(dev->devinfo.function);
  258. if (function > 0x200) {
  259. /* Do this silently - as not a real device */
  260. function = 0;
  261. dev->driver = &maple_dummy_driver;
  262. sprintf(dev->dev.bus_id, "%d:0.port", dev->port);
  263. } else {
  264. printk(KERN_INFO
  265. "Maple bus at (%d, %d): Connected function 0x%lX\n",
  266. dev->port, dev->unit, function);
  267. matched =
  268. bus_for_each_drv(&maple_bus_type, NULL, dev,
  269. attach_matching_maple_driver);
  270. if (matched == 0) {
  271. /* Driver does not exist yet */
  272. printk(KERN_INFO
  273. "No maple driver found for this device\n");
  274. dev->driver = &maple_dummy_driver;
  275. }
  276. sprintf(dev->dev.bus_id, "%d:0%d.%lX", dev->port,
  277. dev->unit, function);
  278. }
  279. dev->function = function;
  280. dev->dev.bus = &maple_bus_type;
  281. dev->dev.parent = &maple_bus;
  282. dev->dev.release = &maple_release_device;
  283. retval = device_register(&dev->dev);
  284. if (retval) {
  285. printk(KERN_INFO
  286. "Maple bus: Attempt to register device (%x, %x) failed.\n",
  287. dev->port, dev->unit);
  288. maple_free_dev(dev);
  289. }
  290. dev->registered = 1;
  291. }
  292. /*
  293. * if device has been registered for the given
  294. * port and unit then return 1 - allows identification
  295. * of which devices need to be attached or detached
  296. */
  297. static int detach_maple_device(struct device *device, void *portptr)
  298. {
  299. struct maple_device_specify *ds;
  300. struct maple_device *mdev;
  301. ds = portptr;
  302. mdev = to_maple_dev(device);
  303. if (mdev->port == ds->port && mdev->unit == ds->unit)
  304. return 1;
  305. return 0;
  306. }
  307. static int setup_maple_commands(struct device *device, void *ignored)
  308. {
  309. struct maple_device *maple_dev = to_maple_dev(device);
  310. if ((maple_dev->interval > 0)
  311. && time_after(jiffies, maple_dev->when)) {
  312. maple_dev->when = jiffies + maple_dev->interval;
  313. maple_dev->mq->command = MAPLE_COMMAND_GETCOND;
  314. maple_dev->mq->sendbuf = &maple_dev->function;
  315. maple_dev->mq->length = 1;
  316. maple_add_packet(maple_dev->mq);
  317. liststatus++;
  318. } else {
  319. if (time_after(jiffies, maple_pnp_time)) {
  320. maple_dev->mq->command = MAPLE_COMMAND_DEVINFO;
  321. maple_dev->mq->length = 0;
  322. maple_add_packet(maple_dev->mq);
  323. liststatus++;
  324. }
  325. }
  326. return 0;
  327. }
  328. /* VBLANK bottom half - implemented via workqueue */
  329. static void maple_vblank_handler(struct work_struct *work)
  330. {
  331. if (!maple_dma_done())
  332. return;
  333. if (!list_empty(&maple_sentq))
  334. return;
  335. ctrl_outl(0, MAPLE_ENABLE);
  336. liststatus = 0;
  337. bus_for_each_dev(&maple_bus_type, NULL, NULL,
  338. setup_maple_commands);
  339. if (time_after(jiffies, maple_pnp_time))
  340. maple_pnp_time = jiffies + MAPLE_PNP_INTERVAL;
  341. if (liststatus && list_empty(&maple_sentq)) {
  342. INIT_LIST_HEAD(&maple_sentq);
  343. maple_send();
  344. }
  345. maplebus_dma_reset();
  346. }
  347. /* handle devices added via hotplugs - placing them on queue for DEVINFO*/
  348. static void maple_map_subunits(struct maple_device *mdev, int submask)
  349. {
  350. int retval, k, devcheck;
  351. struct maple_device *mdev_add;
  352. struct maple_device_specify ds;
  353. for (k = 0; k < 5; k++) {
  354. ds.port = mdev->port;
  355. ds.unit = k + 1;
  356. retval =
  357. bus_for_each_dev(&maple_bus_type, NULL, &ds,
  358. detach_maple_device);
  359. if (retval) {
  360. submask = submask >> 1;
  361. continue;
  362. }
  363. devcheck = submask & 0x01;
  364. if (devcheck) {
  365. mdev_add = maple_alloc_dev(mdev->port, k + 1);
  366. if (!mdev_add)
  367. return;
  368. mdev_add->mq->command = MAPLE_COMMAND_DEVINFO;
  369. mdev_add->mq->length = 0;
  370. maple_add_packet(mdev_add->mq);
  371. scanning = 1;
  372. }
  373. submask = submask >> 1;
  374. }
  375. }
  376. /* mark a device as removed */
  377. static void maple_clean_submap(struct maple_device *mdev)
  378. {
  379. int killbit;
  380. killbit = (mdev->unit > 0 ? (1 << (mdev->unit - 1)) & 0x1f : 0x20);
  381. killbit = ~killbit;
  382. killbit &= 0xFF;
  383. subdevice_map[mdev->port] = subdevice_map[mdev->port] & killbit;
  384. }
  385. /* handle empty port or hotplug removal */
  386. static void maple_response_none(struct maple_device *mdev,
  387. struct mapleq *mq)
  388. {
  389. if (mdev->unit != 0) {
  390. list_del(&mq->list);
  391. maple_clean_submap(mdev);
  392. printk(KERN_INFO
  393. "Maple bus device detaching at (%d, %d)\n",
  394. mdev->port, mdev->unit);
  395. maple_detach_driver(mdev);
  396. return;
  397. }
  398. if (!started) {
  399. printk(KERN_INFO "No maple devices attached to port %d\n",
  400. mdev->port);
  401. return;
  402. }
  403. maple_clean_submap(mdev);
  404. }
  405. /* preprocess hotplugs or scans */
  406. static void maple_response_devinfo(struct maple_device *mdev,
  407. char *recvbuf)
  408. {
  409. char submask;
  410. if ((!started) || (scanning == 2)) {
  411. maple_attach_driver(mdev);
  412. return;
  413. }
  414. if (mdev->unit == 0) {
  415. submask = recvbuf[2] & 0x1F;
  416. if (submask ^ subdevice_map[mdev->port]) {
  417. maple_map_subunits(mdev, submask);
  418. subdevice_map[mdev->port] = submask;
  419. }
  420. }
  421. }
  422. /* maple dma end bottom half - implemented via workqueue */
  423. static void maple_dma_handler(struct work_struct *work)
  424. {
  425. struct mapleq *mq, *nmq;
  426. struct maple_device *dev;
  427. char *recvbuf;
  428. enum maple_code code;
  429. if (!maple_dma_done())
  430. return;
  431. ctrl_outl(0, MAPLE_ENABLE);
  432. if (!list_empty(&maple_sentq)) {
  433. list_for_each_entry_safe(mq, nmq, &maple_sentq, list) {
  434. recvbuf = mq->recvbuf;
  435. code = recvbuf[0];
  436. dev = mq->dev;
  437. switch (code) {
  438. case MAPLE_RESPONSE_NONE:
  439. maple_response_none(dev, mq);
  440. break;
  441. case MAPLE_RESPONSE_DEVINFO:
  442. maple_response_devinfo(dev, recvbuf);
  443. break;
  444. case MAPLE_RESPONSE_DATATRF:
  445. if (dev->callback)
  446. dev->callback(mq);
  447. break;
  448. case MAPLE_RESPONSE_FILEERR:
  449. case MAPLE_RESPONSE_AGAIN:
  450. case MAPLE_RESPONSE_BADCMD:
  451. case MAPLE_RESPONSE_BADFUNC:
  452. printk(KERN_DEBUG
  453. "Maple non-fatal error 0x%X\n",
  454. code);
  455. break;
  456. case MAPLE_RESPONSE_ALLINFO:
  457. printk(KERN_DEBUG
  458. "Maple - extended device information not supported\n");
  459. break;
  460. case MAPLE_RESPONSE_OK:
  461. break;
  462. default:
  463. break;
  464. }
  465. }
  466. INIT_LIST_HEAD(&maple_sentq);
  467. if (scanning == 1) {
  468. maple_send();
  469. scanning = 2;
  470. } else
  471. scanning = 0;
  472. if (started == 0)
  473. started = 1;
  474. }
  475. maplebus_dma_reset();
  476. }
  477. static irqreturn_t maplebus_dma_interrupt(int irq, void *dev_id)
  478. {
  479. /* Load everything into the bottom half */
  480. schedule_work(&maple_dma_process);
  481. return IRQ_HANDLED;
  482. }
  483. static irqreturn_t maplebus_vblank_interrupt(int irq, void *dev_id)
  484. {
  485. schedule_work(&maple_vblank_process);
  486. return IRQ_HANDLED;
  487. }
  488. static struct irqaction maple_dma_irq = {
  489. .name = "maple bus DMA handler",
  490. .handler = maplebus_dma_interrupt,
  491. .flags = IRQF_SHARED,
  492. };
  493. static struct irqaction maple_vblank_irq = {
  494. .name = "maple bus VBLANK handler",
  495. .handler = maplebus_vblank_interrupt,
  496. .flags = IRQF_SHARED,
  497. };
  498. static int maple_set_dma_interrupt_handler(void)
  499. {
  500. return setup_irq(HW_EVENT_MAPLE_DMA, &maple_dma_irq);
  501. }
  502. static int maple_set_vblank_interrupt_handler(void)
  503. {
  504. return setup_irq(HW_EVENT_VSYNC, &maple_vblank_irq);
  505. }
  506. static int maple_get_dma_buffer(void)
  507. {
  508. maple_sendbuf =
  509. (void *) __get_free_pages(GFP_KERNEL | __GFP_ZERO,
  510. MAPLE_DMA_PAGES);
  511. if (!maple_sendbuf)
  512. return -ENOMEM;
  513. return 0;
  514. }
  515. static int match_maple_bus_driver(struct device *devptr,
  516. struct device_driver *drvptr)
  517. {
  518. struct maple_driver *maple_drv;
  519. struct maple_device *maple_dev;
  520. maple_drv = container_of(drvptr, struct maple_driver, drv);
  521. maple_dev = container_of(devptr, struct maple_device, dev);
  522. /* Trap empty port case */
  523. if (maple_dev->devinfo.function == 0xFFFFFFFF)
  524. return 0;
  525. else if (maple_dev->devinfo.function &
  526. be32_to_cpu(maple_drv->function))
  527. return 1;
  528. return 0;
  529. }
  530. static int maple_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
  531. {
  532. return 0;
  533. }
  534. static void maple_bus_release(struct device *dev)
  535. {
  536. }
  537. static struct maple_driver maple_dummy_driver = {
  538. .drv = {
  539. .name = "maple_dummy_driver",
  540. .bus = &maple_bus_type,
  541. },
  542. };
  543. struct bus_type maple_bus_type = {
  544. .name = "maple",
  545. .match = match_maple_bus_driver,
  546. .uevent = maple_bus_uevent,
  547. };
  548. EXPORT_SYMBOL_GPL(maple_bus_type);
  549. static struct device maple_bus = {
  550. .bus_id = "maple",
  551. .release = maple_bus_release,
  552. };
  553. static int __init maple_bus_init(void)
  554. {
  555. int retval, i;
  556. struct maple_device *mdev[MAPLE_PORTS];
  557. ctrl_outl(0, MAPLE_STATE);
  558. retval = device_register(&maple_bus);
  559. if (retval)
  560. goto cleanup;
  561. retval = bus_register(&maple_bus_type);
  562. if (retval)
  563. goto cleanup_device;
  564. retval = driver_register(&maple_dummy_driver.drv);
  565. if (retval)
  566. goto cleanup_bus;
  567. /* allocate memory for maple bus dma */
  568. retval = maple_get_dma_buffer();
  569. if (retval) {
  570. printk(KERN_INFO
  571. "Maple bus: Failed to allocate Maple DMA buffers\n");
  572. goto cleanup_basic;
  573. }
  574. /* set up DMA interrupt handler */
  575. retval = maple_set_dma_interrupt_handler();
  576. if (retval) {
  577. printk(KERN_INFO
  578. "Maple bus: Failed to grab maple DMA IRQ\n");
  579. goto cleanup_dma;
  580. }
  581. /* set up VBLANK interrupt handler */
  582. retval = maple_set_vblank_interrupt_handler();
  583. if (retval) {
  584. printk(KERN_INFO "Maple bus: Failed to grab VBLANK IRQ\n");
  585. goto cleanup_irq;
  586. }
  587. maple_queue_cache =
  588. kmem_cache_create("maple_queue_cache", 0x400, 0,
  589. SLAB_HWCACHE_ALIGN, NULL);
  590. if (!maple_queue_cache)
  591. goto cleanup_bothirqs;
  592. /* setup maple ports */
  593. for (i = 0; i < MAPLE_PORTS; i++) {
  594. mdev[i] = maple_alloc_dev(i, 0);
  595. if (!mdev[i]) {
  596. while (i-- > 0)
  597. maple_free_dev(mdev[i]);
  598. goto cleanup_cache;
  599. }
  600. mdev[i]->registered = 0;
  601. mdev[i]->mq->command = MAPLE_COMMAND_DEVINFO;
  602. mdev[i]->mq->length = 0;
  603. maple_attach_driver(mdev[i]);
  604. maple_add_packet(mdev[i]->mq);
  605. subdevice_map[i] = 0;
  606. }
  607. /* setup maplebus hardware */
  608. maplebus_dma_reset();
  609. /* initial detection */
  610. maple_send();
  611. maple_pnp_time = jiffies;
  612. printk(KERN_INFO "Maple bus core now registered.\n");
  613. return 0;
  614. cleanup_cache:
  615. kmem_cache_destroy(maple_queue_cache);
  616. cleanup_bothirqs:
  617. free_irq(HW_EVENT_VSYNC, 0);
  618. cleanup_irq:
  619. free_irq(HW_EVENT_MAPLE_DMA, 0);
  620. cleanup_dma:
  621. free_pages((unsigned long) maple_sendbuf, MAPLE_DMA_PAGES);
  622. cleanup_basic:
  623. driver_unregister(&maple_dummy_driver.drv);
  624. cleanup_bus:
  625. bus_unregister(&maple_bus_type);
  626. cleanup_device:
  627. device_unregister(&maple_bus);
  628. cleanup:
  629. printk(KERN_INFO "Maple bus registration failed\n");
  630. return retval;
  631. }
  632. subsys_initcall(maple_bus_init);