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