2 * linux/arch/arm/kernel/dma-isa.c
4 * Copyright (C) 1999-2000 Russell King
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.
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,
16 * arch/arm/kernel/dma-ebsa285.c
17 * Copyright (C) 1998 Phil Blundell
19 #include <linux/ioport.h>
20 #include <linux/init.h>
21 #include <linux/dma-mapping.h>
25 #include <asm/mach/dma.h>
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
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 }
47 static int isa_get_dma_residue(unsigned int chan
, dma_t
*dma
)
49 unsigned int io_port
= isa_dma_port
[chan
][ISA_DMA_COUNT
];
52 count
= 1 + inb(io_port
);
53 count
|= inb(io_port
) << 8;
55 return chan
< 4 ? count
: (count
<< 1);
58 static void isa_enable_dma(unsigned int chan
, dma_t
*dma
)
61 unsigned long address
, length
;
63 enum dma_data_direction direction
;
65 mode
= (chan
& 3) | dma
->dma_mode
;
66 switch (dma
->dma_mode
& DMA_MODE_MASK
) {
68 direction
= DMA_FROM_DEVICE
;
72 direction
= DMA_TO_DEVICE
;
75 case DMA_MODE_CASCADE
:
76 direction
= DMA_BIDIRECTIONAL
;
86 * Cope with ISA-style drivers which expect cache
91 dma
->buf
.length
= dma
->count
;
92 dma
->buf
.dma_address
= dma_map_single(NULL
,
93 dma
->addr
, dma
->count
,
97 address
= dma
->buf
.dma_address
;
98 length
= dma
->buf
.length
- 1;
100 outb(address
>> 16, isa_dma_port
[chan
][ISA_DMA_PGLO
]);
101 outb(address
>> 24, isa_dma_port
[chan
][ISA_DMA_PGHI
]);
108 outb(0, isa_dma_port
[chan
][ISA_DMA_CLRFF
]);
110 outb(address
, isa_dma_port
[chan
][ISA_DMA_ADDR
]);
111 outb(address
>> 8, isa_dma_port
[chan
][ISA_DMA_ADDR
]);
113 outb(length
, isa_dma_port
[chan
][ISA_DMA_COUNT
]);
114 outb(length
>> 8, isa_dma_port
[chan
][ISA_DMA_COUNT
]);
116 outb(mode
, isa_dma_port
[chan
][ISA_DMA_MODE
]);
119 outb(chan
& 3, isa_dma_port
[chan
][ISA_DMA_MASK
]);
122 static void isa_disable_dma(unsigned int chan
, dma_t
*dma
)
124 outb(chan
| 4, isa_dma_port
[chan
][ISA_DMA_MASK
]);
127 static struct dma_ops isa_dma_ops
= {
129 .enable
= isa_enable_dma
,
130 .disable
= isa_disable_dma
,
131 .residue
= isa_get_dma_residue
,
134 static struct resource dma_resources
[] = { {
139 .name
= "dma low page",
147 .name
= "dma high page",
152 static dma_t isa_dma
[8];
155 * ISA DMA always starts at channel 0
157 void __init
isa_init_dma(void)
160 * Try to autodetect presence of an ISA DMA controller.
161 * We do some minimal initialisation, and check that
162 * channel 0's DMA address registers are writeable.
168 * Write high and low address, and then read them back
174 if (inb(0) == 0x55 && inb(0) == 0xaa) {
175 unsigned int chan
, i
;
177 for (chan
= 0; chan
< 8; chan
++) {
178 isa_dma
[chan
].d_ops
= &isa_dma_ops
;
179 isa_disable_dma(chan
, NULL
);
198 * Is this correct? According to my documentation, it
199 * doesn't appear to be. It should be:
200 * outb(0x3f, 0x40b); outb(0x3f, 0x4d6);
210 for (i
= 0; i
< ARRAY_SIZE(dma_resources
); i
++)
211 request_resource(&ioport_resource
, dma_resources
+ i
);
213 for (chan
= 0; chan
< 8; chan
++) {
214 int ret
= isa_dma_add(chan
, &isa_dma
[chan
]);
216 pr_err("ISADMA%u: unable to register: %d\n",
220 request_dma(DMA_ISA_CASCADE
, "cascade");