Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-rpc/dma.c |
| 3 | * |
| 4 | * Copyright (C) 1998 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * DMA functions specific to RiscPC architecture |
| 11 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/mman.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/interrupt.h> |
Russell King | 7cdad48 | 2006-01-04 15:08:30 +0000 | [diff] [blame] | 15 | #include <linux/dma-mapping.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 16 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #include <asm/page.h> |
| 19 | #include <asm/dma.h> |
| 20 | #include <asm/fiq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/irq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 22 | #include <mach/hardware.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include <asm/mach/dma.h> |
| 26 | #include <asm/hardware/iomd.h> |
| 27 | |
Russell King | 308d333 | 2009-02-21 21:36:22 +0000 | [diff] [blame] | 28 | struct iomd_dma { |
| 29 | struct dma_struct dma; |
| 30 | unsigned int state; |
| 31 | unsigned long base; /* Controller base address */ |
| 32 | int irq; /* Controller IRQ */ |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 33 | dma_addr_t cur_addr; |
| 34 | unsigned int cur_len; |
Russell King | fa4e998 | 2009-02-21 21:38:56 +0000 | [diff] [blame] | 35 | dma_addr_t dma_addr; |
| 36 | unsigned int dma_len; |
Russell King | 308d333 | 2009-02-21 21:36:22 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #if 0 |
| 40 | typedef enum { |
| 41 | dma_size_8 = 1, |
| 42 | dma_size_16 = 2, |
| 43 | dma_size_32 = 4, |
| 44 | dma_size_128 = 16 |
| 45 | } dma_size_t; |
| 46 | #endif |
| 47 | |
| 48 | #define TRANSFER_SIZE 2 |
| 49 | |
| 50 | #define CURA (0) |
| 51 | #define ENDA (IOMD_IO0ENDA - IOMD_IO0CURA) |
| 52 | #define CURB (IOMD_IO0CURB - IOMD_IO0CURA) |
| 53 | #define ENDB (IOMD_IO0ENDB - IOMD_IO0CURA) |
| 54 | #define CR (IOMD_IO0CR - IOMD_IO0CURA) |
| 55 | #define ST (IOMD_IO0ST - IOMD_IO0CURA) |
| 56 | |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 57 | static void iomd_get_next_sg(struct iomd_dma *idma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | unsigned long end, offset, flags = 0; |
| 60 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 61 | if (idma->dma.sg) { |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 62 | idma->cur_addr = idma->dma_addr; |
| 63 | offset = idma->cur_addr & ~PAGE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Russell King | fa4e998 | 2009-02-21 21:38:56 +0000 | [diff] [blame] | 65 | end = offset + idma->dma_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | if (end > PAGE_SIZE) |
| 68 | end = PAGE_SIZE; |
| 69 | |
| 70 | if (offset + TRANSFER_SIZE >= end) |
| 71 | flags |= DMA_END_L; |
| 72 | |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 73 | idma->cur_len = end - TRANSFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Russell King | fa4e998 | 2009-02-21 21:38:56 +0000 | [diff] [blame] | 75 | idma->dma_len -= end - offset; |
| 76 | idma->dma_addr += end - offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Russell King | fa4e998 | 2009-02-21 21:38:56 +0000 | [diff] [blame] | 78 | if (idma->dma_len == 0) { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 79 | if (idma->dma.sgcount > 1) { |
Russell King | 9e28d7e | 2008-12-08 19:03:58 +0000 | [diff] [blame] | 80 | idma->dma.sg = sg_next(idma->dma.sg); |
Russell King | fa4e998 | 2009-02-21 21:38:56 +0000 | [diff] [blame] | 81 | idma->dma_addr = idma->dma.sg->dma_address; |
| 82 | idma->dma_len = idma->dma.sg->length; |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 83 | idma->dma.sgcount--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } else { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 85 | idma->dma.sg = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | flags |= DMA_END_S; |
| 87 | } |
| 88 | } |
| 89 | } else { |
| 90 | flags = DMA_END_S | DMA_END_L; |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 91 | idma->cur_addr = 0; |
| 92 | idma->cur_len = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 95 | idma->cur_len |= flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 98 | static irqreturn_t iomd_dma_handle(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 100 | struct iomd_dma *idma = dev_id; |
| 101 | unsigned long base = idma->base; |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 102 | unsigned int state = idma->state; |
| 103 | unsigned int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | status = iomd_readb(base + ST); |
| 107 | if (!(status & DMA_ST_INT)) |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 108 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 110 | if ((state ^ status) & DMA_ST_AB) |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 111 | iomd_get_next_sg(idma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | switch (status & (DMA_ST_OFL | DMA_ST_AB)) { |
| 114 | case DMA_ST_OFL: /* OIA */ |
| 115 | case DMA_ST_AB: /* .IB */ |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 116 | iomd_writel(idma->cur_addr, base + CURA); |
| 117 | iomd_writel(idma->cur_len, base + ENDA); |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 118 | state = DMA_ST_AB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | break; |
| 120 | |
| 121 | case DMA_ST_OFL | DMA_ST_AB: /* OIB */ |
| 122 | case 0: /* .IA */ |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 123 | iomd_writel(idma->cur_addr, base + CURB); |
| 124 | iomd_writel(idma->cur_len, base + ENDB); |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 125 | state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | break; |
| 127 | } |
| 128 | |
| 129 | if (status & DMA_ST_OFL && |
Russell King | 8194468 | 2019-05-02 17:37:51 +0100 | [diff] [blame] | 130 | idma->cur_len == (DMA_END_S|DMA_END_L)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | break; |
| 132 | } while (1); |
| 133 | |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 134 | state = ~DMA_ST_AB; |
Russell King | ffd9a1b | 2019-05-02 17:19:18 +0100 | [diff] [blame] | 135 | disable_irq_nosync(irq); |
Russell King | 39694ed | 2019-05-02 17:43:36 +0100 | [diff] [blame^] | 136 | out: |
| 137 | idma->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | return IRQ_HANDLED; |
| 139 | } |
| 140 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 141 | static int iomd_request_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 143 | struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); |
| 144 | |
| 145 | return request_irq(idma->irq, iomd_dma_handle, |
Michael Opdenacker | 78f6db9 | 2014-03-04 22:04:50 +0100 | [diff] [blame] | 146 | 0, idma->dma.device_id, idma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 149 | static void iomd_free_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 151 | struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); |
| 152 | |
| 153 | free_irq(idma->irq, idma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 156 | static void iomd_enable_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 158 | struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); |
| 159 | unsigned long dma_base = idma->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | unsigned int ctrl = TRANSFER_SIZE | DMA_CR_E; |
| 161 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 162 | if (idma->dma.invalid) { |
| 163 | idma->dma.invalid = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Cope with ISA-style drivers which expect cache |
| 167 | * coherence. |
| 168 | */ |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 169 | if (!idma->dma.sg) { |
| 170 | idma->dma.sg = &idma->dma.buf; |
| 171 | idma->dma.sgcount = 1; |
| 172 | idma->dma.buf.length = idma->dma.count; |
| 173 | idma->dma.buf.dma_address = dma_map_single(NULL, |
| 174 | idma->dma.addr, idma->dma.count, |
| 175 | idma->dma.dma_mode == DMA_MODE_READ ? |
Russell King | 7cdad48 | 2006-01-04 15:08:30 +0000 | [diff] [blame] | 176 | DMA_FROM_DEVICE : DMA_TO_DEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Russell King | ffd9a1b | 2019-05-02 17:19:18 +0100 | [diff] [blame] | 179 | idma->dma_addr = idma->dma.sg->dma_address; |
| 180 | idma->dma_len = idma->dma.sg->length; |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | iomd_writeb(DMA_CR_C, dma_base + CR); |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 183 | idma->state = DMA_ST_AB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 185 | |
| 186 | if (idma->dma.dma_mode == DMA_MODE_READ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | ctrl |= DMA_CR_D; |
| 188 | |
| 189 | iomd_writeb(ctrl, dma_base + CR); |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 190 | enable_irq(idma->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 193 | static void iomd_disable_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 195 | struct iomd_dma *idma = container_of(dma, struct iomd_dma, dma); |
| 196 | unsigned long dma_base = idma->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | unsigned long flags; |
| 198 | |
| 199 | local_irq_save(flags); |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 200 | if (idma->state != ~DMA_ST_AB) |
| 201 | disable_irq(idma->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | iomd_writeb(0, dma_base + CR); |
| 203 | local_irq_restore(flags); |
| 204 | } |
| 205 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 206 | static int iomd_set_dma_speed(unsigned int chan, dma_t *dma, int cycle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | int tcr, speed; |
| 209 | |
| 210 | if (cycle < 188) |
| 211 | speed = 3; |
| 212 | else if (cycle <= 250) |
| 213 | speed = 2; |
| 214 | else if (cycle < 438) |
| 215 | speed = 1; |
| 216 | else |
| 217 | speed = 0; |
| 218 | |
| 219 | tcr = iomd_readb(IOMD_DMATCR); |
| 220 | speed &= 3; |
| 221 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 222 | switch (chan) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | case DMA_0: |
| 224 | tcr = (tcr & ~0x03) | speed; |
| 225 | break; |
| 226 | |
| 227 | case DMA_1: |
| 228 | tcr = (tcr & ~0x0c) | (speed << 2); |
| 229 | break; |
| 230 | |
| 231 | case DMA_2: |
| 232 | tcr = (tcr & ~0x30) | (speed << 4); |
| 233 | break; |
| 234 | |
| 235 | case DMA_3: |
| 236 | tcr = (tcr & ~0xc0) | (speed << 6); |
| 237 | break; |
| 238 | |
| 239 | default: |
| 240 | break; |
| 241 | } |
| 242 | |
| 243 | iomd_writeb(tcr, IOMD_DMATCR); |
| 244 | |
| 245 | return speed; |
| 246 | } |
| 247 | |
| 248 | static struct dma_ops iomd_dma_ops = { |
| 249 | .type = "IOMD", |
| 250 | .request = iomd_request_dma, |
| 251 | .free = iomd_free_dma, |
| 252 | .enable = iomd_enable_dma, |
| 253 | .disable = iomd_disable_dma, |
| 254 | .setspeed = iomd_set_dma_speed, |
| 255 | }; |
| 256 | |
| 257 | static struct fiq_handler fh = { |
| 258 | .name = "floppydma" |
| 259 | }; |
| 260 | |
Russell King | 308d333 | 2009-02-21 21:36:22 +0000 | [diff] [blame] | 261 | struct floppy_dma { |
| 262 | struct dma_struct dma; |
| 263 | unsigned int fiq; |
| 264 | }; |
| 265 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 266 | static void floppy_enable_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 268 | struct floppy_dma *fdma = container_of(dma, struct floppy_dma, dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | void *fiqhandler_start; |
| 270 | unsigned int fiqhandler_length; |
| 271 | struct pt_regs regs; |
| 272 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 273 | if (fdma->dma.sg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | BUG(); |
| 275 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 276 | if (fdma->dma.dma_mode == DMA_MODE_READ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | extern unsigned char floppy_fiqin_start, floppy_fiqin_end; |
| 278 | fiqhandler_start = &floppy_fiqin_start; |
| 279 | fiqhandler_length = &floppy_fiqin_end - &floppy_fiqin_start; |
| 280 | } else { |
| 281 | extern unsigned char floppy_fiqout_start, floppy_fiqout_end; |
| 282 | fiqhandler_start = &floppy_fiqout_start; |
| 283 | fiqhandler_length = &floppy_fiqout_end - &floppy_fiqout_start; |
| 284 | } |
| 285 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 286 | regs.ARM_r9 = fdma->dma.count; |
| 287 | regs.ARM_r10 = (unsigned long)fdma->dma.addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | regs.ARM_fp = (unsigned long)FLOPPYDMA_BASE; |
| 289 | |
| 290 | if (claim_fiq(&fh)) { |
| 291 | printk("floppydma: couldn't claim FIQ.\n"); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | set_fiq_handler(fiqhandler_start, fiqhandler_length); |
| 296 | set_fiq_regs(®s); |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 297 | enable_fiq(fdma->fiq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 300 | static void floppy_disable_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 302 | struct floppy_dma *fdma = container_of(dma, struct floppy_dma, dma); |
| 303 | disable_fiq(fdma->fiq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | release_fiq(&fh); |
| 305 | } |
| 306 | |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 307 | static int floppy_get_residue(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | struct pt_regs regs; |
| 310 | get_fiq_regs(®s); |
| 311 | return regs.ARM_r9; |
| 312 | } |
| 313 | |
| 314 | static struct dma_ops floppy_dma_ops = { |
| 315 | .type = "FIQDMA", |
| 316 | .enable = floppy_enable_dma, |
| 317 | .disable = floppy_disable_dma, |
| 318 | .residue = floppy_get_residue, |
| 319 | }; |
| 320 | |
| 321 | /* |
| 322 | * This is virtual DMA - we don't need anything here. |
| 323 | */ |
Russell King | 1df8130 | 2008-12-08 15:58:50 +0000 | [diff] [blame] | 324 | static void sound_enable_disable_dma(unsigned int chan, dma_t *dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | } |
| 327 | |
| 328 | static struct dma_ops sound_dma_ops = { |
| 329 | .type = "VIRTUAL", |
| 330 | .enable = sound_enable_disable_dma, |
| 331 | .disable = sound_enable_disable_dma, |
| 332 | }; |
| 333 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 334 | static struct iomd_dma iomd_dma[6]; |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 335 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 336 | static struct floppy_dma floppy_dma = { |
| 337 | .dma = { |
| 338 | .d_ops = &floppy_dma_ops, |
| 339 | }, |
| 340 | .fiq = FIQ_FLOPPYDATA, |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | static dma_t sound_dma = { |
| 344 | .d_ops = &sound_dma_ops, |
| 345 | }; |
| 346 | |
| 347 | static int __init rpc_dma_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 349 | unsigned int i; |
| 350 | int ret; |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | iomd_writeb(0, IOMD_IO0CR); |
| 353 | iomd_writeb(0, IOMD_IO1CR); |
| 354 | iomd_writeb(0, IOMD_IO2CR); |
| 355 | iomd_writeb(0, IOMD_IO3CR); |
| 356 | |
| 357 | iomd_writeb(0xa0, IOMD_DMATCR); |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | /* |
| 360 | * Setup DMA channels 2,3 to be for podules |
| 361 | * and channels 0,1 for internal devices |
| 362 | */ |
| 363 | iomd_writeb(DMA_EXT_IO3|DMA_EXT_IO2, IOMD_DMAEXT); |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 364 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 365 | iomd_dma[DMA_0].base = IOMD_IO0CURA; |
| 366 | iomd_dma[DMA_0].irq = IRQ_DMA0; |
| 367 | iomd_dma[DMA_1].base = IOMD_IO1CURA; |
| 368 | iomd_dma[DMA_1].irq = IRQ_DMA1; |
| 369 | iomd_dma[DMA_2].base = IOMD_IO2CURA; |
| 370 | iomd_dma[DMA_2].irq = IRQ_DMA2; |
| 371 | iomd_dma[DMA_3].base = IOMD_IO3CURA; |
| 372 | iomd_dma[DMA_3].irq = IRQ_DMA3; |
| 373 | iomd_dma[DMA_S0].base = IOMD_SD0CURA; |
| 374 | iomd_dma[DMA_S0].irq = IRQ_DMAS0; |
| 375 | iomd_dma[DMA_S1].base = IOMD_SD1CURA; |
| 376 | iomd_dma[DMA_S1].irq = IRQ_DMAS1; |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 377 | |
| 378 | for (i = DMA_0; i <= DMA_S1; i++) { |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 379 | iomd_dma[i].dma.d_ops = &iomd_dma_ops; |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 380 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 381 | ret = isa_dma_add(i, &iomd_dma[i].dma); |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 382 | if (ret) |
| 383 | printk("IOMDDMA%u: unable to register: %d\n", i, ret); |
| 384 | } |
| 385 | |
Russell King | ad9dd94 | 2008-12-08 17:35:48 +0000 | [diff] [blame] | 386 | ret = isa_dma_add(DMA_VIRTUAL_FLOPPY, &floppy_dma.dma); |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 387 | if (ret) |
| 388 | printk("IOMDFLOPPY: unable to register: %d\n", ret); |
| 389 | ret = isa_dma_add(DMA_VIRTUAL_SOUND, &sound_dma); |
| 390 | if (ret) |
| 391 | printk("IOMDSOUND: unable to register: %d\n", ret); |
| 392 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
Russell King | 2f757f2 | 2008-12-08 16:33:30 +0000 | [diff] [blame] | 394 | core_initcall(rpc_dma_init); |