Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Core maple bus functionality |
| 3 | * |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 4 | * Copyright (C) 2007 - 2009 Adrian McMenamin |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 5 | * Copyright (C) 2001 - 2008 Paul Mundt |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 6 | * Copyright (C) 2000 - 2001 YAEGASHI Takeshi |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 7 | * Copyright (C) 2001 M. R. Brown |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file "COPYING" in the main directory of this archive |
| 11 | * for more details. |
| 12 | */ |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/device.h> |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/maple.h> |
| 21 | #include <linux/dma-mapping.h> |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 22 | #include <linux/delay.h> |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 23 | #include <asm/cacheflush.h> |
| 24 | #include <asm/dma.h> |
| 25 | #include <asm/io.h> |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 26 | #include <mach/dma.h> |
| 27 | #include <mach/sysasic.h> |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 28 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 29 | MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>"); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 30 | MODULE_DESCRIPTION("Maple bus driver for Dreamcast"); |
| 31 | MODULE_LICENSE("GPL v2"); |
| 32 | MODULE_SUPPORTED_DEVICE("{{SEGA, Dreamcast/Maple}}"); |
| 33 | |
| 34 | static void maple_dma_handler(struct work_struct *work); |
| 35 | static void maple_vblank_handler(struct work_struct *work); |
| 36 | |
| 37 | static DECLARE_WORK(maple_dma_process, maple_dma_handler); |
| 38 | static DECLARE_WORK(maple_vblank_process, maple_vblank_handler); |
| 39 | |
| 40 | static LIST_HEAD(maple_waitq); |
| 41 | static LIST_HEAD(maple_sentq); |
| 42 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 43 | /* mutex to protect queue of waiting packets */ |
| 44 | static DEFINE_MUTEX(maple_wlist_lock); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 45 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 46 | static struct maple_driver maple_unsupported_device; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 47 | static struct device maple_bus; |
| 48 | static int subdevice_map[MAPLE_PORTS]; |
| 49 | static unsigned long *maple_sendbuf, *maple_sendptr, *maple_lastptr; |
| 50 | static unsigned long maple_pnp_time; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 51 | static int started, scanning, fullscan; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 52 | static struct kmem_cache *maple_queue_cache; |
| 53 | |
| 54 | struct maple_device_specify { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 55 | int port; |
| 56 | int unit; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 57 | }; |
| 58 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 59 | static bool checked[MAPLE_PORTS]; |
| 60 | static bool empty[MAPLE_PORTS]; |
| 61 | static struct maple_device *baseunits[MAPLE_PORTS]; |
Adrian McMenamin | bd49666 | 2008-02-24 14:30:23 +0000 | [diff] [blame] | 62 | |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 63 | /** |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 64 | * maple_driver_register - register a maple driver |
| 65 | * @drv: maple driver to be registered. |
| 66 | * |
| 67 | * Registers the passed in @drv, while updating the bus type. |
| 68 | * Devices with matching function IDs will be automatically probed. |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 69 | */ |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 70 | int maple_driver_register(struct maple_driver *drv) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 71 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 72 | if (!drv) |
| 73 | return -EINVAL; |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 74 | |
| 75 | drv->drv.bus = &maple_bus_type; |
| 76 | |
| 77 | return driver_register(&drv->drv); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 78 | } |
| 79 | EXPORT_SYMBOL_GPL(maple_driver_register); |
| 80 | |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 81 | /** |
| 82 | * maple_driver_unregister - unregister a maple driver. |
| 83 | * @drv: maple driver to unregister. |
| 84 | * |
| 85 | * Cleans up after maple_driver_register(). To be invoked in the exit |
| 86 | * path of any module drivers. |
| 87 | */ |
| 88 | void maple_driver_unregister(struct maple_driver *drv) |
| 89 | { |
| 90 | driver_unregister(&drv->drv); |
| 91 | } |
Paul Mundt | 6178706 | 2008-08-04 10:58:24 +0900 | [diff] [blame] | 92 | EXPORT_SYMBOL_GPL(maple_driver_unregister); |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 93 | |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 94 | /* set hardware registers to enable next round of dma */ |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 95 | static void maple_dma_reset(void) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 96 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 97 | ctrl_outl(MAPLE_MAGIC, MAPLE_RESET); |
| 98 | /* set trig type to 0 for software trigger, 1 for hardware (VBLANK) */ |
| 99 | ctrl_outl(1, MAPLE_TRIGTYPE); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 100 | /* |
| 101 | * Maple system register |
| 102 | * bits 31 - 16 timeout in units of 20nsec |
| 103 | * bit 12 hard trigger - set 0 to keep responding to VBLANK |
| 104 | * bits 9 - 8 set 00 for 2 Mbps, 01 for 1 Mbps |
| 105 | * bits 3 - 0 delay (in 1.3ms) between VBLANK and start of DMA |
| 106 | * max delay is 11 |
| 107 | */ |
| 108 | ctrl_outl(MAPLE_2MBPS | MAPLE_TIMEOUT(0xFFFF), MAPLE_SPEED); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 109 | ctrl_outl(PHYSADDR(maple_sendbuf), MAPLE_DMAADDR); |
| 110 | ctrl_outl(1, MAPLE_ENABLE); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * maple_getcond_callback - setup handling MAPLE_COMMAND_GETCOND |
| 115 | * @dev: device responding |
| 116 | * @callback: handler callback |
| 117 | * @interval: interval in jiffies between callbacks |
| 118 | * @function: the function code for the device |
| 119 | */ |
| 120 | void maple_getcond_callback(struct maple_device *dev, |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 121 | void (*callback) (struct mapleq *mq), |
| 122 | unsigned long interval, unsigned long function) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 123 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 124 | dev->callback = callback; |
| 125 | dev->interval = interval; |
| 126 | dev->function = cpu_to_be32(function); |
| 127 | dev->when = jiffies; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 128 | } |
| 129 | EXPORT_SYMBOL_GPL(maple_getcond_callback); |
| 130 | |
| 131 | static int maple_dma_done(void) |
| 132 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 133 | return (ctrl_inl(MAPLE_STATE) & 1) == 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void maple_release_device(struct device *dev) |
| 137 | { |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 138 | struct maple_device *mdev; |
| 139 | struct mapleq *mq; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 140 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 141 | mdev = to_maple_dev(dev); |
| 142 | mq = mdev->mq; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 143 | kmem_cache_free(maple_queue_cache, mq->recvbuf); |
| 144 | kfree(mq); |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 145 | kfree(mdev); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 146 | } |
| 147 | |
Paul Mundt | 6a9545b | 2008-08-04 12:51:06 +0900 | [diff] [blame] | 148 | /** |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 149 | * maple_add_packet - add a single instruction to the maple bus queue |
Paul Mundt | 6a9545b | 2008-08-04 12:51:06 +0900 | [diff] [blame] | 150 | * @mdev: maple device |
| 151 | * @function: function on device being queried |
| 152 | * @command: maple command to add |
| 153 | * @length: length of command string (in 32 bit words) |
| 154 | * @data: remainder of command string |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 155 | */ |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 156 | int maple_add_packet(struct maple_device *mdev, u32 function, u32 command, |
| 157 | size_t length, void *data) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 158 | { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 159 | int ret = 0; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 160 | void *sendbuf = NULL; |
| 161 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 162 | if (length) { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 163 | sendbuf = kzalloc(length * 4, GFP_KERNEL); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 164 | if (!sendbuf) { |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 165 | ret = -ENOMEM; |
| 166 | goto out; |
| 167 | } |
| 168 | ((__be32 *)sendbuf)[0] = cpu_to_be32(function); |
| 169 | } |
| 170 | |
| 171 | mdev->mq->command = command; |
| 172 | mdev->mq->length = length; |
| 173 | if (length > 1) |
| 174 | memcpy(sendbuf + 4, data, (length - 1) * 4); |
| 175 | mdev->mq->sendbuf = sendbuf; |
| 176 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 177 | mutex_lock(&maple_wlist_lock); |
| 178 | list_add_tail(&mdev->mq->list, &maple_waitq); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 179 | mutex_unlock(&maple_wlist_lock); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 180 | out: |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 181 | return ret; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 182 | } |
| 183 | EXPORT_SYMBOL_GPL(maple_add_packet); |
| 184 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 185 | static struct mapleq *maple_allocq(struct maple_device *mdev) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 186 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 187 | struct mapleq *mq; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 188 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 189 | mq = kzalloc(sizeof(*mq), GFP_KERNEL); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 190 | if (!mq) |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 191 | goto failed_nomem; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 192 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 193 | INIT_LIST_HEAD(&mq->list); |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 194 | mq->dev = mdev; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 195 | mq->recvbuf = kmem_cache_zalloc(maple_queue_cache, GFP_KERNEL); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 196 | if (!mq->recvbuf) |
| 197 | goto failed_p2; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 198 | mq->recvbuf->buf = &((mq->recvbuf->bufx)[0]); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 199 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 200 | return mq; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 201 | |
| 202 | failed_p2: |
| 203 | kfree(mq); |
| 204 | failed_nomem: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 205 | dev_err(&mdev->dev, "could not allocate memory for device (%d, %d)\n", |
| 206 | mdev->port, mdev->unit); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 207 | return NULL; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static struct maple_device *maple_alloc_dev(int port, int unit) |
| 211 | { |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 212 | struct maple_device *mdev; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 213 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 214 | /* zero this out to avoid kobj subsystem |
| 215 | * thinking it has already been registered */ |
| 216 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 217 | mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); |
| 218 | if (!mdev) |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 219 | return NULL; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 220 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 221 | mdev->port = port; |
| 222 | mdev->unit = unit; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 223 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 224 | mdev->mq = maple_allocq(mdev); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 225 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 226 | if (!mdev->mq) { |
| 227 | kfree(mdev); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 230 | mdev->dev.bus = &maple_bus_type; |
| 231 | mdev->dev.parent = &maple_bus; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 232 | init_waitqueue_head(&mdev->maple_wait); |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 233 | return mdev; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static void maple_free_dev(struct maple_device *mdev) |
| 237 | { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 238 | kmem_cache_free(maple_queue_cache, mdev->mq->recvbuf); |
| 239 | kfree(mdev->mq); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 240 | kfree(mdev); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* process the command queue into a maple command block |
| 244 | * terminating command has bit 32 of first long set to 0 |
| 245 | */ |
| 246 | static void maple_build_block(struct mapleq *mq) |
| 247 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 248 | int port, unit, from, to, len; |
| 249 | unsigned long *lsendbuf = mq->sendbuf; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 250 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 251 | port = mq->dev->port & 3; |
| 252 | unit = mq->dev->unit; |
| 253 | len = mq->length; |
| 254 | from = port << 6; |
| 255 | to = (port << 6) | (unit > 0 ? (1 << (unit - 1)) & 0x1f : 0x20); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 256 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 257 | *maple_lastptr &= 0x7fffffff; |
| 258 | maple_lastptr = maple_sendptr; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 259 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 260 | *maple_sendptr++ = (port << 16) | len | 0x80000000; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 261 | *maple_sendptr++ = PHYSADDR(mq->recvbuf->buf); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 262 | *maple_sendptr++ = |
| 263 | mq->command | (to << 8) | (from << 16) | (len << 24); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 264 | while (len-- > 0) |
| 265 | *maple_sendptr++ = *lsendbuf++; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /* build up command queue */ |
| 269 | static void maple_send(void) |
| 270 | { |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 271 | int i, maple_packets = 0; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 272 | struct mapleq *mq, *nmq; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 273 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 274 | if (!maple_dma_done()) |
| 275 | return; |
| 276 | |
| 277 | /* disable DMA */ |
| 278 | ctrl_outl(0, MAPLE_ENABLE); |
| 279 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 280 | if (!list_empty(&maple_sentq)) |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 281 | goto finish; |
| 282 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 283 | mutex_lock(&maple_wlist_lock); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 284 | if (list_empty(&maple_waitq)) { |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 285 | mutex_unlock(&maple_wlist_lock); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 286 | goto finish; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 287 | } |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 288 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 289 | maple_lastptr = maple_sendbuf; |
| 290 | maple_sendptr = maple_sendbuf; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 291 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 292 | list_for_each_entry_safe(mq, nmq, &maple_waitq, list) { |
| 293 | maple_build_block(mq); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 294 | list_del_init(&mq->list); |
| 295 | list_add_tail(&mq->list, &maple_sentq); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 296 | if (maple_packets++ > MAPLE_MAXPACKETS) |
| 297 | break; |
| 298 | } |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 299 | mutex_unlock(&maple_wlist_lock); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 300 | if (maple_packets > 0) { |
| 301 | for (i = 0; i < (1 << MAPLE_DMA_PAGES); i++) |
| 302 | dma_cache_sync(0, maple_sendbuf + i * PAGE_SIZE, |
| 303 | PAGE_SIZE, DMA_BIDIRECTIONAL); |
| 304 | } |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 305 | |
| 306 | finish: |
| 307 | maple_dma_reset(); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 308 | } |
| 309 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 310 | /* check if there is a driver registered likely to match this device */ |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 311 | static int maple_check_matching_driver(struct device_driver *driver, |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 312 | void *devptr) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 313 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 314 | struct maple_driver *maple_drv; |
| 315 | struct maple_device *mdev; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 316 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 317 | mdev = devptr; |
| 318 | maple_drv = to_maple_driver(driver); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 319 | if (mdev->devinfo.function & cpu_to_be32(maple_drv->function)) |
| 320 | return 1; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 321 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static void maple_detach_driver(struct maple_device *mdev) |
| 325 | { |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 326 | device_unregister(&mdev->dev); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* process initial MAPLE_COMMAND_DEVINFO for each device or port */ |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 330 | static void maple_attach_driver(struct maple_device *mdev) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 331 | { |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 332 | char *p, *recvbuf; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 333 | unsigned long function; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 334 | int matched, error; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 335 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 336 | recvbuf = mdev->mq->recvbuf->buf; |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 337 | /* copy the data as individual elements in |
| 338 | * case of memory optimisation */ |
| 339 | memcpy(&mdev->devinfo.function, recvbuf + 4, 4); |
| 340 | memcpy(&mdev->devinfo.function_data[0], recvbuf + 8, 12); |
| 341 | memcpy(&mdev->devinfo.area_code, recvbuf + 20, 1); |
| 342 | memcpy(&mdev->devinfo.connector_direction, recvbuf + 21, 1); |
| 343 | memcpy(&mdev->devinfo.product_name[0], recvbuf + 22, 30); |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 344 | memcpy(&mdev->devinfo.standby_power, recvbuf + 112, 2); |
| 345 | memcpy(&mdev->devinfo.max_power, recvbuf + 114, 2); |
| 346 | memcpy(mdev->product_name, mdev->devinfo.product_name, 30); |
| 347 | mdev->product_name[30] = '\0'; |
| 348 | memcpy(mdev->product_licence, mdev->devinfo.product_licence, 60); |
| 349 | mdev->product_licence[60] = '\0'; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 350 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 351 | for (p = mdev->product_name + 29; mdev->product_name <= p; p--) |
| 352 | if (*p == ' ') |
| 353 | *p = '\0'; |
| 354 | else |
| 355 | break; |
| 356 | for (p = mdev->product_licence + 59; mdev->product_licence <= p; p--) |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 357 | if (*p == ' ') |
| 358 | *p = '\0'; |
| 359 | else |
| 360 | break; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 361 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 362 | function = be32_to_cpu(mdev->devinfo.function); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 363 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 364 | dev_info(&mdev->dev, "detected %s: function 0x%lX: at (%d, %d)\n", |
| 365 | mdev->product_name, function, mdev->port, mdev->unit); |
| 366 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 367 | if (function > 0x200) { |
| 368 | /* Do this silently - as not a real device */ |
| 369 | function = 0; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 370 | mdev->driver = &maple_unsupported_device; |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 371 | sprintf(mdev->dev.bus_id, "%d:0.port", mdev->port); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 372 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 373 | } else { |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 374 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 375 | matched = |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 376 | bus_for_each_drv(&maple_bus_type, NULL, mdev, |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 377 | maple_check_matching_driver); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 378 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 379 | if (matched == 0) { |
| 380 | /* Driver does not exist yet */ |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 381 | dev_info(&mdev->dev, "no driver found\n"); |
| 382 | mdev->driver = &maple_unsupported_device; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 383 | } |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 384 | sprintf(mdev->dev.bus_id, "%d:0%d.%lX", mdev->port, |
| 385 | mdev->unit, function); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 386 | } |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 387 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 388 | mdev->function = function; |
| 389 | mdev->dev.release = &maple_release_device; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 390 | |
| 391 | atomic_set(&mdev->busy, 0); |
| 392 | error = device_register(&mdev->dev); |
| 393 | if (error) { |
| 394 | dev_warn(&mdev->dev, "could not register device at" |
| 395 | " (%d, %d), with error 0x%X\n", mdev->unit, |
| 396 | mdev->port, error); |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 397 | maple_free_dev(mdev); |
| 398 | mdev = NULL; |
| 399 | return; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 400 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* |
| 404 | * if device has been registered for the given |
| 405 | * port and unit then return 1 - allows identification |
| 406 | * of which devices need to be attached or detached |
| 407 | */ |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 408 | static int check_maple_device(struct device *device, void *portptr) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 409 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 410 | struct maple_device_specify *ds; |
| 411 | struct maple_device *mdev; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 412 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 413 | ds = portptr; |
| 414 | mdev = to_maple_dev(device); |
| 415 | if (mdev->port == ds->port && mdev->unit == ds->unit) |
| 416 | return 1; |
| 417 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | static int setup_maple_commands(struct device *device, void *ignored) |
| 421 | { |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 422 | int add; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 423 | struct maple_device *mdev = to_maple_dev(device); |
| 424 | if (mdev->interval > 0 && atomic_read(&mdev->busy) == 0 && |
| 425 | time_after(jiffies, mdev->when)) { |
| 426 | /* bounce if we cannot add */ |
| 427 | add = maple_add_packet(mdev, |
| 428 | be32_to_cpu(mdev->devinfo.function), |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 429 | MAPLE_COMMAND_GETCOND, 1, NULL); |
| 430 | if (!add) |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 431 | mdev->when = jiffies + mdev->interval; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 432 | } else { |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 433 | if (time_after(jiffies, maple_pnp_time)) |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 434 | /* Ensure we don't have block reads and devinfo |
| 435 | * calls interfering with one another - so flag the |
| 436 | * device as busy */ |
| 437 | if (atomic_read(&mdev->busy) == 0) { |
| 438 | atomic_set(&mdev->busy, 1); |
| 439 | maple_add_packet(mdev, 0, |
| 440 | MAPLE_COMMAND_DEVINFO, 0, NULL); |
| 441 | } |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 442 | } |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 443 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /* VBLANK bottom half - implemented via workqueue */ |
| 447 | static void maple_vblank_handler(struct work_struct *work) |
| 448 | { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 449 | int x, locking; |
| 450 | struct maple_device *mdev; |
| 451 | |
| 452 | if (!maple_dma_done()) |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 453 | return; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 454 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 455 | ctrl_outl(0, MAPLE_ENABLE); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 456 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 457 | if (!list_empty(&maple_sentq)) |
| 458 | goto finish; |
| 459 | |
| 460 | /* |
| 461 | * Set up essential commands - to fetch data and |
| 462 | * check devices are still present |
| 463 | */ |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 464 | bus_for_each_dev(&maple_bus_type, NULL, NULL, |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 465 | setup_maple_commands); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 466 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 467 | if (time_after(jiffies, maple_pnp_time)) { |
| 468 | /* |
| 469 | * Scan the empty ports - bus is flakey and may have |
| 470 | * mis-reported emptyness |
| 471 | */ |
| 472 | for (x = 0; x < MAPLE_PORTS; x++) { |
| 473 | if (checked[x] && empty[x]) { |
| 474 | mdev = baseunits[x]; |
| 475 | if (!mdev) |
| 476 | break; |
| 477 | atomic_set(&mdev->busy, 1); |
| 478 | locking = maple_add_packet(mdev, 0, |
| 479 | MAPLE_COMMAND_DEVINFO, 0, NULL); |
| 480 | if (!locking) |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 485 | maple_pnp_time = jiffies + MAPLE_PNP_INTERVAL; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 486 | } |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 487 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 488 | finish: |
| 489 | maple_send(); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 490 | } |
| 491 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 492 | /* handle devices added via hotplugs - placing them on queue for DEVINFO */ |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 493 | static void maple_map_subunits(struct maple_device *mdev, int submask) |
| 494 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 495 | int retval, k, devcheck; |
| 496 | struct maple_device *mdev_add; |
| 497 | struct maple_device_specify ds; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 498 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 499 | ds.port = mdev->port; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 500 | for (k = 0; k < 5; k++) { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 501 | ds.unit = k + 1; |
| 502 | retval = |
| 503 | bus_for_each_dev(&maple_bus_type, NULL, &ds, |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 504 | check_maple_device); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 505 | if (retval) { |
| 506 | submask = submask >> 1; |
| 507 | continue; |
| 508 | } |
| 509 | devcheck = submask & 0x01; |
| 510 | if (devcheck) { |
| 511 | mdev_add = maple_alloc_dev(mdev->port, k + 1); |
| 512 | if (!mdev_add) |
| 513 | return; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 514 | atomic_set(&mdev_add->busy, 1); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 515 | maple_add_packet(mdev_add, 0, MAPLE_COMMAND_DEVINFO, |
| 516 | 0, NULL); |
| 517 | /* mark that we are checking sub devices */ |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 518 | scanning = 1; |
| 519 | } |
| 520 | submask = submask >> 1; |
| 521 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | /* mark a device as removed */ |
| 525 | static void maple_clean_submap(struct maple_device *mdev) |
| 526 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 527 | int killbit; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 528 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 529 | killbit = (mdev->unit > 0 ? (1 << (mdev->unit - 1)) & 0x1f : 0x20); |
| 530 | killbit = ~killbit; |
| 531 | killbit &= 0xFF; |
| 532 | subdevice_map[mdev->port] = subdevice_map[mdev->port] & killbit; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /* handle empty port or hotplug removal */ |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 536 | static void maple_response_none(struct maple_device *mdev) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 537 | { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 538 | maple_clean_submap(mdev); |
| 539 | |
| 540 | if (likely(mdev->unit != 0)) { |
| 541 | /* |
| 542 | * Block devices play up |
| 543 | * and give the impression they have |
| 544 | * been removed even when still in place or |
| 545 | * trip the mtd layer when they have |
| 546 | * really gone - this code traps that eventuality |
| 547 | * and ensures we aren't overloaded with useless |
| 548 | * error messages |
| 549 | */ |
| 550 | if (mdev->can_unload) { |
| 551 | if (!mdev->can_unload(mdev)) { |
| 552 | atomic_set(&mdev->busy, 2); |
| 553 | wake_up(&mdev->maple_wait); |
| 554 | return; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | dev_info(&mdev->dev, "detaching device at (%d, %d)\n", |
| 559 | mdev->port, mdev->unit); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 560 | maple_detach_driver(mdev); |
| 561 | return; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 562 | } else { |
| 563 | if (!started || !fullscan) { |
| 564 | if (checked[mdev->port] == false) { |
| 565 | checked[mdev->port] = true; |
| 566 | empty[mdev->port] = true; |
| 567 | dev_info(&mdev->dev, "no devices" |
| 568 | " to port %d\n", mdev->port); |
| 569 | } |
| 570 | return; |
Adrian McMenamin | bd49666 | 2008-02-24 14:30:23 +0000 | [diff] [blame] | 571 | } |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 572 | } |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 573 | /* Some hardware devices generate false detach messages on unit 0 */ |
| 574 | atomic_set(&mdev->busy, 0); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /* preprocess hotplugs or scans */ |
| 578 | static void maple_response_devinfo(struct maple_device *mdev, |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 579 | char *recvbuf) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 580 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 581 | char submask; |
Adrian McMenamin | bd49666 | 2008-02-24 14:30:23 +0000 | [diff] [blame] | 582 | if (!started || (scanning == 2) || !fullscan) { |
| 583 | if ((mdev->unit == 0) && (checked[mdev->port] == false)) { |
| 584 | checked[mdev->port] = true; |
| 585 | maple_attach_driver(mdev); |
| 586 | } else { |
| 587 | if (mdev->unit != 0) |
| 588 | maple_attach_driver(mdev); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 589 | if (mdev->unit == 0) { |
| 590 | empty[mdev->port] = false; |
| 591 | maple_attach_driver(mdev); |
| 592 | } |
Adrian McMenamin | bd49666 | 2008-02-24 14:30:23 +0000 | [diff] [blame] | 593 | } |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 594 | } |
| 595 | if (mdev->unit == 0) { |
| 596 | submask = recvbuf[2] & 0x1F; |
| 597 | if (submask ^ subdevice_map[mdev->port]) { |
| 598 | maple_map_subunits(mdev, submask); |
| 599 | subdevice_map[mdev->port] = submask; |
| 600 | } |
| 601 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 602 | } |
| 603 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 604 | static void maple_response_fileerr(struct maple_device *mdev, void *recvbuf) |
| 605 | { |
| 606 | if (mdev->fileerr_handler) { |
| 607 | mdev->fileerr_handler(mdev, recvbuf); |
| 608 | return; |
| 609 | } else |
| 610 | dev_warn(&mdev->dev, "device at (%d, %d) reports" |
| 611 | "file error 0x%X\n", mdev->port, mdev->unit, |
| 612 | ((int *)recvbuf)[1]); |
| 613 | } |
| 614 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 615 | static void maple_port_rescan(void) |
| 616 | { |
| 617 | int i; |
| 618 | struct maple_device *mdev; |
| 619 | |
| 620 | fullscan = 1; |
| 621 | for (i = 0; i < MAPLE_PORTS; i++) { |
| 622 | if (checked[i] == false) { |
| 623 | fullscan = 0; |
| 624 | mdev = baseunits[i]; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 625 | maple_add_packet(mdev, 0, MAPLE_COMMAND_DEVINFO, |
| 626 | 0, NULL); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 631 | /* maple dma end bottom half - implemented via workqueue */ |
| 632 | static void maple_dma_handler(struct work_struct *work) |
| 633 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 634 | struct mapleq *mq, *nmq; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 635 | struct maple_device *mdev; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 636 | char *recvbuf; |
| 637 | enum maple_code code; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 638 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 639 | if (!maple_dma_done()) |
| 640 | return; |
| 641 | ctrl_outl(0, MAPLE_ENABLE); |
| 642 | if (!list_empty(&maple_sentq)) { |
| 643 | list_for_each_entry_safe(mq, nmq, &maple_sentq, list) { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 644 | mdev = mq->dev; |
| 645 | recvbuf = mq->recvbuf->buf; |
| 646 | dma_cache_sync(&mdev->dev, recvbuf, 0x400, |
| 647 | DMA_FROM_DEVICE); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 648 | code = recvbuf[0]; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 649 | kfree(mq->sendbuf); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 650 | list_del_init(&mq->list); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 651 | switch (code) { |
| 652 | case MAPLE_RESPONSE_NONE: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 653 | maple_response_none(mdev); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 654 | break; |
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 | case MAPLE_RESPONSE_DEVINFO: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 657 | maple_response_devinfo(mdev, recvbuf); |
| 658 | atomic_set(&mdev->busy, 0); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 659 | break; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 660 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 661 | case MAPLE_RESPONSE_DATATRF: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 662 | if (mdev->callback) |
| 663 | mdev->callback(mq); |
| 664 | atomic_set(&mdev->busy, 0); |
| 665 | wake_up(&mdev->maple_wait); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 666 | break; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 667 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 668 | case MAPLE_RESPONSE_FILEERR: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 669 | maple_response_fileerr(mdev, recvbuf); |
| 670 | atomic_set(&mdev->busy, 0); |
| 671 | wake_up(&mdev->maple_wait); |
| 672 | break; |
| 673 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 674 | case MAPLE_RESPONSE_AGAIN: |
| 675 | case MAPLE_RESPONSE_BADCMD: |
| 676 | case MAPLE_RESPONSE_BADFUNC: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 677 | dev_warn(&mdev->dev, "non-fatal error" |
| 678 | " 0x%X at (%d, %d)\n", code, |
| 679 | mdev->port, mdev->unit); |
| 680 | atomic_set(&mdev->busy, 0); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 681 | break; |
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 | case MAPLE_RESPONSE_ALLINFO: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 684 | dev_notice(&mdev->dev, "extended" |
| 685 | " device information request for (%d, %d)" |
| 686 | " but call is not supported\n", mdev->port, |
| 687 | mdev->unit); |
| 688 | atomic_set(&mdev->busy, 0); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 689 | break; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 690 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 691 | case MAPLE_RESPONSE_OK: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 692 | atomic_set(&mdev->busy, 0); |
| 693 | wake_up(&mdev->maple_wait); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 694 | break; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 695 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 696 | default: |
| 697 | break; |
| 698 | } |
| 699 | } |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 700 | /* if scanning is 1 then we have subdevices to check */ |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 701 | if (scanning == 1) { |
| 702 | maple_send(); |
| 703 | scanning = 2; |
| 704 | } else |
| 705 | scanning = 0; |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 706 | /*check if we have actually tested all ports yet */ |
| 707 | if (!fullscan) |
| 708 | maple_port_rescan(); |
| 709 | /* mark that we have been through the first scan */ |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 710 | started = 1; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 711 | } |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 712 | maple_send(); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 713 | } |
| 714 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 715 | static irqreturn_t maple_dma_interrupt(int irq, void *dev_id) |
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 | /* Load everything into the bottom half */ |
| 718 | schedule_work(&maple_dma_process); |
| 719 | return IRQ_HANDLED; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 720 | } |
| 721 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 722 | static irqreturn_t maple_vblank_interrupt(int irq, void *dev_id) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 723 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 724 | schedule_work(&maple_vblank_process); |
| 725 | return IRQ_HANDLED; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 726 | } |
| 727 | |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 728 | static int maple_set_dma_interrupt_handler(void) |
| 729 | { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 730 | return request_irq(HW_EVENT_MAPLE_DMA, maple_dma_interrupt, |
| 731 | IRQF_SHARED, "maple bus DMA", &maple_unsupported_device); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static int maple_set_vblank_interrupt_handler(void) |
| 735 | { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 736 | return request_irq(HW_EVENT_VSYNC, maple_vblank_interrupt, |
| 737 | IRQF_SHARED, "maple bus VBLANK", &maple_unsupported_device); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | static int maple_get_dma_buffer(void) |
| 741 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 742 | maple_sendbuf = |
| 743 | (void *) __get_free_pages(GFP_KERNEL | __GFP_ZERO, |
| 744 | MAPLE_DMA_PAGES); |
| 745 | if (!maple_sendbuf) |
| 746 | return -ENOMEM; |
| 747 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 748 | } |
| 749 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 750 | static int maple_match_bus_driver(struct device *devptr, |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 751 | struct device_driver *drvptr) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 752 | { |
Paul Mundt | 6387029 | 2008-08-04 10:39:46 +0900 | [diff] [blame] | 753 | struct maple_driver *maple_drv = to_maple_driver(drvptr); |
| 754 | struct maple_device *maple_dev = to_maple_dev(devptr); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 755 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 756 | /* Trap empty port case */ |
| 757 | if (maple_dev->devinfo.function == 0xFFFFFFFF) |
| 758 | return 0; |
| 759 | else if (maple_dev->devinfo.function & |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 760 | cpu_to_be32(maple_drv->function)) |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 761 | return 1; |
| 762 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 763 | } |
| 764 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 765 | static int maple_bus_uevent(struct device *dev, |
| 766 | struct kobj_uevent_env *env) |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 767 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 768 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | static void maple_bus_release(struct device *dev) |
| 772 | { |
| 773 | } |
| 774 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 775 | static struct maple_driver maple_unsupported_device = { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 776 | .drv = { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 777 | .name = "maple_unsupported_device", |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 778 | .bus = &maple_bus_type, |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 779 | }, |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 780 | }; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 781 | /** |
| 782 | * maple_bus_type - core maple bus structure |
| 783 | */ |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 784 | struct bus_type maple_bus_type = { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 785 | .name = "maple", |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 786 | .match = maple_match_bus_driver, |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 787 | .uevent = maple_bus_uevent, |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 788 | }; |
| 789 | EXPORT_SYMBOL_GPL(maple_bus_type); |
| 790 | |
| 791 | static struct device maple_bus = { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 792 | .bus_id = "maple", |
| 793 | .release = maple_bus_release, |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 794 | }; |
| 795 | |
| 796 | static int __init maple_bus_init(void) |
| 797 | { |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 798 | int retval, i; |
| 799 | struct maple_device *mdev[MAPLE_PORTS]; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 800 | |
| 801 | ctrl_outl(0, MAPLE_ENABLE); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 802 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 803 | retval = device_register(&maple_bus); |
| 804 | if (retval) |
| 805 | goto cleanup; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 806 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 807 | retval = bus_register(&maple_bus_type); |
| 808 | if (retval) |
| 809 | goto cleanup_device; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 810 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 811 | retval = driver_register(&maple_unsupported_device.drv); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 812 | if (retval) |
| 813 | goto cleanup_bus; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 814 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 815 | /* allocate memory for maple bus dma */ |
| 816 | retval = maple_get_dma_buffer(); |
| 817 | if (retval) { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 818 | dev_err(&maple_bus, "failed to allocate DMA buffers\n"); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 819 | goto cleanup_basic; |
| 820 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 821 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 822 | /* set up DMA interrupt handler */ |
| 823 | retval = maple_set_dma_interrupt_handler(); |
| 824 | if (retval) { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 825 | dev_err(&maple_bus, "bus failed to grab maple " |
| 826 | "DMA IRQ\n"); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 827 | goto cleanup_dma; |
| 828 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 829 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 830 | /* set up VBLANK interrupt handler */ |
| 831 | retval = maple_set_vblank_interrupt_handler(); |
| 832 | if (retval) { |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 833 | dev_err(&maple_bus, "bus failed to grab VBLANK IRQ\n"); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 834 | goto cleanup_irq; |
| 835 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 836 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 837 | maple_queue_cache = KMEM_CACHE(maple_buffer, SLAB_HWCACHE_ALIGN); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 838 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 839 | if (!maple_queue_cache) |
| 840 | goto cleanup_bothirqs; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 841 | |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 842 | INIT_LIST_HEAD(&maple_waitq); |
| 843 | INIT_LIST_HEAD(&maple_sentq); |
| 844 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 845 | /* setup maple ports */ |
| 846 | for (i = 0; i < MAPLE_PORTS; i++) { |
Adrian McMenamin | bd49666 | 2008-02-24 14:30:23 +0000 | [diff] [blame] | 847 | checked[i] = false; |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 848 | empty[i] = false; |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 849 | mdev[i] = maple_alloc_dev(i, 0); |
| 850 | if (!mdev[i]) { |
| 851 | while (i-- > 0) |
| 852 | maple_free_dev(mdev[i]); |
| 853 | goto cleanup_cache; |
| 854 | } |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 855 | baseunits[i] = mdev[i]; |
| 856 | atomic_set(&mdev[i]->busy, 1); |
Adrian McMenamin | 1795cf4 | 2008-07-29 22:10:56 +0900 | [diff] [blame] | 857 | maple_add_packet(mdev[i], 0, MAPLE_COMMAND_DEVINFO, 0, NULL); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 858 | subdevice_map[i] = 0; |
| 859 | } |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 860 | |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 861 | maple_pnp_time = jiffies + HZ; |
| 862 | /* prepare initial queue */ |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 863 | maple_send(); |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 864 | dev_info(&maple_bus, "bus core now registered\n"); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 865 | |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 866 | return 0; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 867 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 868 | cleanup_cache: |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 869 | kmem_cache_destroy(maple_queue_cache); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 870 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 871 | cleanup_bothirqs: |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 872 | free_irq(HW_EVENT_VSYNC, 0); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 873 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 874 | cleanup_irq: |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 875 | free_irq(HW_EVENT_MAPLE_DMA, 0); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 876 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 877 | cleanup_dma: |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 878 | free_pages((unsigned long) maple_sendbuf, MAPLE_DMA_PAGES); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 879 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 880 | cleanup_basic: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 881 | driver_unregister(&maple_unsupported_device.drv); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 882 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 883 | cleanup_bus: |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 884 | bus_unregister(&maple_bus_type); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 885 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 886 | cleanup_device: |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 887 | device_unregister(&maple_bus); |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 888 | |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 889 | cleanup: |
Adrian McMenamin | b233b28 | 2009-02-27 16:07:32 +0900 | [diff] [blame^] | 890 | printk(KERN_ERR "Maple bus registration failed\n"); |
Adrian McMenamin | b948237 | 2008-02-06 22:46:21 +0000 | [diff] [blame] | 891 | return retval; |
Adrian McMenamin | 17be2d2 | 2007-09-21 15:55:55 +0900 | [diff] [blame] | 892 | } |
Adrian McMenamin | b3c69e2 | 2008-02-06 23:51:21 +0000 | [diff] [blame] | 893 | /* Push init to later to ensure hardware gets detected */ |
| 894 | fs_initcall(maple_bus_init); |