]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/arm/kernel/dma-isa.c | |
3 | * | |
4 | * Copyright (C) 1999-2000 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 | * ISA DMA primitives | |
11 | * Taken from various sources, including: | |
12 | * linux/include/asm/dma.h: Defines for using and allocating dma channels. | |
13 | * Written by Hennus Bergman, 1992. | |
14 | * High DMA channel support & info by Hannu Savolainen and John Boyd, | |
15 | * Nov. 1992. | |
16 | * arch/arm/kernel/dma-ebsa285.c | |
17 | * Copyright (C) 1998 Phil Blundell | |
18 | */ | |
19 | #include <linux/ioport.h> | |
20 | #include <linux/init.h> | |
7cdad482 | 21 | #include <linux/dma-mapping.h> |
fced80c7 | 22 | #include <linux/io.h> |
1da177e4 LT |
23 | |
24 | #include <asm/dma.h> | |
1da177e4 LT |
25 | #include <asm/mach/dma.h> |
26 | ||
1da177e4 LT |
27 | #define ISA_DMA_MASK 0 |
28 | #define ISA_DMA_MODE 1 | |
29 | #define ISA_DMA_CLRFF 2 | |
30 | #define ISA_DMA_PGHI 3 | |
31 | #define ISA_DMA_PGLO 4 | |
32 | #define ISA_DMA_ADDR 5 | |
33 | #define ISA_DMA_COUNT 6 | |
34 | ||
35 | static unsigned int isa_dma_port[8][7] = { | |
36 | /* MASK MODE CLRFF PAGE_HI PAGE_LO ADDR COUNT */ | |
37 | { 0x0a, 0x0b, 0x0c, 0x487, 0x087, 0x00, 0x01 }, | |
38 | { 0x0a, 0x0b, 0x0c, 0x483, 0x083, 0x02, 0x03 }, | |
39 | { 0x0a, 0x0b, 0x0c, 0x481, 0x081, 0x04, 0x05 }, | |
40 | { 0x0a, 0x0b, 0x0c, 0x482, 0x082, 0x06, 0x07 }, | |
41 | { 0xd4, 0xd6, 0xd8, 0x000, 0x000, 0xc0, 0xc2 }, | |
42 | { 0xd4, 0xd6, 0xd8, 0x48b, 0x08b, 0xc4, 0xc6 }, | |
43 | { 0xd4, 0xd6, 0xd8, 0x489, 0x089, 0xc8, 0xca }, | |
44 | { 0xd4, 0xd6, 0xd8, 0x48a, 0x08a, 0xcc, 0xce } | |
45 | }; | |
46 | ||
1df81302 | 47 | static int isa_get_dma_residue(unsigned int chan, dma_t *dma) |
1da177e4 | 48 | { |
1df81302 | 49 | unsigned int io_port = isa_dma_port[chan][ISA_DMA_COUNT]; |
1da177e4 LT |
50 | int count; |
51 | ||
52 | count = 1 + inb(io_port); | |
53 | count |= inb(io_port) << 8; | |
54 | ||
1df81302 | 55 | return chan < 4 ? count : (count << 1); |
1da177e4 LT |
56 | } |
57 | ||
5ab6a91a CH |
58 | static struct device isa_dma_dev = { |
59 | .init_name = "fallback device", | |
60 | .coherent_dma_mask = ~(dma_addr_t)0, | |
61 | .dma_mask = &isa_dma_dev.coherent_dma_mask, | |
62 | }; | |
63 | ||
1df81302 | 64 | static void isa_enable_dma(unsigned int chan, dma_t *dma) |
1da177e4 LT |
65 | { |
66 | if (dma->invalid) { | |
67 | unsigned long address, length; | |
7cdad482 RK |
68 | unsigned int mode; |
69 | enum dma_data_direction direction; | |
1da177e4 | 70 | |
bc6447b8 | 71 | mode = (chan & 3) | dma->dma_mode; |
1da177e4 LT |
72 | switch (dma->dma_mode & DMA_MODE_MASK) { |
73 | case DMA_MODE_READ: | |
7cdad482 | 74 | direction = DMA_FROM_DEVICE; |
1da177e4 LT |
75 | break; |
76 | ||
77 | case DMA_MODE_WRITE: | |
7cdad482 | 78 | direction = DMA_TO_DEVICE; |
1da177e4 LT |
79 | break; |
80 | ||
81 | case DMA_MODE_CASCADE: | |
7cdad482 | 82 | direction = DMA_BIDIRECTIONAL; |
1da177e4 LT |
83 | break; |
84 | ||
85 | default: | |
7cdad482 | 86 | direction = DMA_NONE; |
1da177e4 LT |
87 | break; |
88 | } | |
89 | ||
7cdad482 | 90 | if (!dma->sg) { |
1da177e4 LT |
91 | /* |
92 | * Cope with ISA-style drivers which expect cache | |
93 | * coherence. | |
94 | */ | |
7cdad482 RK |
95 | dma->sg = &dma->buf; |
96 | dma->sgcount = 1; | |
97 | dma->buf.length = dma->count; | |
5ab6a91a | 98 | dma->buf.dma_address = dma_map_single(&isa_dma_dev, |
7cdad482 | 99 | dma->addr, dma->count, |
1da177e4 LT |
100 | direction); |
101 | } | |
102 | ||
103 | address = dma->buf.dma_address; | |
104 | length = dma->buf.length - 1; | |
105 | ||
1df81302 RK |
106 | outb(address >> 16, isa_dma_port[chan][ISA_DMA_PGLO]); |
107 | outb(address >> 24, isa_dma_port[chan][ISA_DMA_PGHI]); | |
1da177e4 | 108 | |
1df81302 | 109 | if (chan >= 4) { |
1da177e4 LT |
110 | address >>= 1; |
111 | length >>= 1; | |
112 | } | |
113 | ||
1df81302 | 114 | outb(0, isa_dma_port[chan][ISA_DMA_CLRFF]); |
1da177e4 | 115 | |
1df81302 RK |
116 | outb(address, isa_dma_port[chan][ISA_DMA_ADDR]); |
117 | outb(address >> 8, isa_dma_port[chan][ISA_DMA_ADDR]); | |
1da177e4 | 118 | |
1df81302 RK |
119 | outb(length, isa_dma_port[chan][ISA_DMA_COUNT]); |
120 | outb(length >> 8, isa_dma_port[chan][ISA_DMA_COUNT]); | |
1da177e4 | 121 | |
1df81302 | 122 | outb(mode, isa_dma_port[chan][ISA_DMA_MODE]); |
1da177e4 LT |
123 | dma->invalid = 0; |
124 | } | |
1df81302 | 125 | outb(chan & 3, isa_dma_port[chan][ISA_DMA_MASK]); |
1da177e4 LT |
126 | } |
127 | ||
1df81302 | 128 | static void isa_disable_dma(unsigned int chan, dma_t *dma) |
1da177e4 | 129 | { |
1df81302 | 130 | outb(chan | 4, isa_dma_port[chan][ISA_DMA_MASK]); |
1da177e4 LT |
131 | } |
132 | ||
133 | static struct dma_ops isa_dma_ops = { | |
134 | .type = "ISA", | |
135 | .enable = isa_enable_dma, | |
136 | .disable = isa_disable_dma, | |
137 | .residue = isa_get_dma_residue, | |
138 | }; | |
139 | ||
3170a5e8 AB |
140 | static struct resource dma_resources[] = { { |
141 | .name = "dma1", | |
142 | .start = 0x0000, | |
143 | .end = 0x000f | |
144 | }, { | |
145 | .name = "dma low page", | |
146 | .start = 0x0080, | |
147 | .end = 0x008f | |
148 | }, { | |
149 | .name = "dma2", | |
150 | .start = 0x00c0, | |
151 | .end = 0x00df | |
152 | }, { | |
153 | .name = "dma high page", | |
154 | .start = 0x0480, | |
155 | .end = 0x048f | |
156 | } }; | |
1da177e4 | 157 | |
2f757f2a RK |
158 | static dma_t isa_dma[8]; |
159 | ||
160 | /* | |
161 | * ISA DMA always starts at channel 0 | |
162 | */ | |
163 | void __init isa_init_dma(void) | |
1da177e4 LT |
164 | { |
165 | /* | |
166 | * Try to autodetect presence of an ISA DMA controller. | |
167 | * We do some minimal initialisation, and check that | |
168 | * channel 0's DMA address registers are writeable. | |
169 | */ | |
170 | outb(0xff, 0x0d); | |
171 | outb(0xff, 0xda); | |
172 | ||
173 | /* | |
174 | * Write high and low address, and then read them back | |
175 | * in the same order. | |
176 | */ | |
177 | outb(0x55, 0x00); | |
178 | outb(0xaa, 0x00); | |
179 | ||
180 | if (inb(0) == 0x55 && inb(0) == 0xaa) { | |
2f757f2a | 181 | unsigned int chan, i; |
1da177e4 | 182 | |
1df81302 | 183 | for (chan = 0; chan < 8; chan++) { |
2f757f2a | 184 | isa_dma[chan].d_ops = &isa_dma_ops; |
1df81302 | 185 | isa_disable_dma(chan, NULL); |
1da177e4 LT |
186 | } |
187 | ||
188 | outb(0x40, 0x0b); | |
189 | outb(0x41, 0x0b); | |
190 | outb(0x42, 0x0b); | |
191 | outb(0x43, 0x0b); | |
192 | ||
193 | outb(0xc0, 0xd6); | |
194 | outb(0x41, 0xd6); | |
195 | outb(0x42, 0xd6); | |
196 | outb(0x43, 0xd6); | |
197 | ||
198 | outb(0, 0xd4); | |
199 | ||
200 | outb(0x10, 0x08); | |
201 | outb(0x10, 0xd0); | |
202 | ||
203 | /* | |
204 | * Is this correct? According to my documentation, it | |
205 | * doesn't appear to be. It should be: | |
206 | * outb(0x3f, 0x40b); outb(0x3f, 0x4d6); | |
207 | */ | |
208 | outb(0x30, 0x40b); | |
209 | outb(0x31, 0x40b); | |
210 | outb(0x32, 0x40b); | |
211 | outb(0x33, 0x40b); | |
212 | outb(0x31, 0x4d6); | |
213 | outb(0x32, 0x4d6); | |
214 | outb(0x33, 0x4d6); | |
215 | ||
df1a2903 | 216 | for (i = 0; i < ARRAY_SIZE(dma_resources); i++) |
1da177e4 | 217 | request_resource(&ioport_resource, dma_resources + i); |
2f757f2a RK |
218 | |
219 | for (chan = 0; chan < 8; chan++) { | |
220 | int ret = isa_dma_add(chan, &isa_dma[chan]); | |
221 | if (ret) | |
4ed89f22 RK |
222 | pr_err("ISADMA%u: unable to register: %d\n", |
223 | chan, ret); | |
2f757f2a | 224 | } |
e8b8f5ef RK |
225 | |
226 | request_dma(DMA_ISA_CASCADE, "cascade"); | |
1da177e4 LT |
227 | } |
228 | } |