Skip to content

Commit 22b61a1

Browse files
Russell KingRussell King
authored andcommitted
Merge branch 'dma' into devel
Conflicts: arch/arm/plat-mxc/dma-mx1-mx2.c
2 parents 423145a + fa4e998 commit 22b61a1

13 files changed

Lines changed: 292 additions & 238 deletions

File tree

‎arch/arm/include/asm/dma.h‎

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,17 @@
1919
#include <asm/system.h>
2020
#include <asm/scatterlist.h>
2121

22-
typedef unsigned int dmach_t;
23-
2422
#include <mach/isa-dma.h>
2523

2624
/*
27-
* DMA modes
25+
* The DMA modes reflect the settings for the ISA DMA controller
2826
*/
29-
typedef unsigned int dmamode_t;
30-
31-
#define DMA_MODE_MASK 3
27+
#define DMA_MODE_MASK 0xcc
3228

33-
#define DMA_MODE_READ 0
34-
#define DMA_MODE_WRITE 1
35-
#define DMA_MODE_CASCADE 2
36-
#define DMA_AUTOINIT 4
29+
#define DMA_MODE_READ 0x44
30+
#define DMA_MODE_WRITE 0x48
31+
#define DMA_MODE_CASCADE 0xc0
32+
#define DMA_AUTOINIT 0x10
3733

3834
extern spinlock_t dma_spin_lock;
3935

@@ -52,70 +48,70 @@ static inline void release_dma_lock(unsigned long flags)
5248
/* Clear the 'DMA Pointer Flip Flop'.
5349
* Write 0 for LSB/MSB, 1 for MSB/LSB access.
5450
*/
55-
#define clear_dma_ff(channel)
51+
#define clear_dma_ff(chan)
5652

5753
/* Set only the page register bits of the transfer address.
5854
*
5955
* NOTE: This is an architecture specific function, and should
6056
* be hidden from the drivers
6157
*/
62-
extern void set_dma_page(dmach_t channel, char pagenr);
58+
extern void set_dma_page(unsigned int chan, char pagenr);
6359

6460
/* Request a DMA channel
6561
*
6662
* Some architectures may need to do allocate an interrupt
6763
*/
68-
extern int request_dma(dmach_t channel, const char * device_id);
64+
extern int request_dma(unsigned int chan, const char * device_id);
6965

7066
/* Free a DMA channel
7167
*
7268
* Some architectures may need to do free an interrupt
7369
*/
74-
extern void free_dma(dmach_t channel);
70+
extern void free_dma(unsigned int chan);
7571

7672
/* Enable DMA for this channel
7773
*
7874
* On some architectures, this may have other side effects like
7975
* enabling an interrupt and setting the DMA registers.
8076
*/
81-
extern void enable_dma(dmach_t channel);
77+
extern void enable_dma(unsigned int chan);
8278

8379
/* Disable DMA for this channel
8480
*
8581
* On some architectures, this may have other side effects like
8682
* disabling an interrupt or whatever.
8783
*/
88-
extern void disable_dma(dmach_t channel);
84+
extern void disable_dma(unsigned int chan);
8985

9086
/* Test whether the specified channel has an active DMA transfer
9187
*/
92-
extern int dma_channel_active(dmach_t channel);
88+
extern int dma_channel_active(unsigned int chan);
9389

9490
/* Set the DMA scatter gather list for this channel
9591
*
9692
* This should not be called if a DMA channel is enabled,
9793
* especially since some DMA architectures don't update the
9894
* DMA address immediately, but defer it to the enable_dma().
9995
*/
100-
extern void set_dma_sg(dmach_t channel, struct scatterlist *sg, int nr_sg);
96+
extern void set_dma_sg(unsigned int chan, struct scatterlist *sg, int nr_sg);
10197

10298
/* Set the DMA address for this channel
10399
*
104100
* This should not be called if a DMA channel is enabled,
105101
* especially since some DMA architectures don't update the
106102
* DMA address immediately, but defer it to the enable_dma().
107103
*/
108-
extern void __set_dma_addr(dmach_t channel, void *addr);
109-
#define set_dma_addr(channel, addr) \
110-
__set_dma_addr(channel, bus_to_virt(addr))
104+
extern void __set_dma_addr(unsigned int chan, void *addr);
105+
#define set_dma_addr(chan, addr) \
106+
__set_dma_addr(chan, bus_to_virt(addr))
111107

112108
/* Set the DMA byte count for this channel
113109
*
114110
* This should not be called if a DMA channel is enabled,
115111
* especially since some DMA architectures don't update the
116112
* DMA count immediately, but defer it to the enable_dma().
117113
*/
118-
extern void set_dma_count(dmach_t channel, unsigned long count);
114+
extern void set_dma_count(unsigned int chan, unsigned long count);
119115

120116
/* Set the transfer direction for this channel
121117
*
@@ -124,19 +120,19 @@ extern void set_dma_count(dmach_t channel, unsigned long count);
124120
* DMA transfer direction immediately, but defer it to the
125121
* enable_dma().
126122
*/
127-
extern void set_dma_mode(dmach_t channel, dmamode_t mode);
123+
extern void set_dma_mode(unsigned int chan, unsigned int mode);
128124

129125
/* Set the transfer speed for this channel
130126
*/
131-
extern void set_dma_speed(dmach_t channel, int cycle_ns);
127+
extern void set_dma_speed(unsigned int chan, int cycle_ns);
132128

133129
/* Get DMA residue count. After a DMA transfer, this
134130
* should return zero. Reading this while a DMA transfer is
135131
* still in progress will return unpredictable results.
136132
* If called before the channel has been used, it may return 1.
137133
* Otherwise, it returns the number of _bytes_ left to transfer.
138134
*/
139-
extern int get_dma_residue(dmach_t channel);
135+
extern int get_dma_residue(unsigned int chan);
140136

141137
#ifndef NO_DMA
142138
#define NO_DMA 255

‎arch/arm/include/asm/mach/dma.h‎

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ struct dma_struct;
1515
typedef struct dma_struct dma_t;
1616

1717
struct dma_ops {
18-
int (*request)(dmach_t, dma_t *); /* optional */
19-
void (*free)(dmach_t, dma_t *); /* optional */
20-
void (*enable)(dmach_t, dma_t *); /* mandatory */
21-
void (*disable)(dmach_t, dma_t *); /* mandatory */
22-
int (*residue)(dmach_t, dma_t *); /* optional */
23-
int (*setspeed)(dmach_t, dma_t *, int); /* optional */
24-
char *type;
18+
int (*request)(unsigned int, dma_t *); /* optional */
19+
void (*free)(unsigned int, dma_t *); /* optional */
20+
void (*enable)(unsigned int, dma_t *); /* mandatory */
21+
void (*disable)(unsigned int, dma_t *); /* mandatory */
22+
int (*residue)(unsigned int, dma_t *); /* optional */
23+
int (*setspeed)(unsigned int, dma_t *, int); /* optional */
24+
const char *type;
2525
};
2626

2727
struct dma_struct {
@@ -34,24 +34,21 @@ struct dma_struct {
3434
unsigned int active:1; /* Transfer active */
3535
unsigned int invalid:1; /* Address/Count changed */
3636

37-
dmamode_t dma_mode; /* DMA mode */
37+
unsigned int dma_mode; /* DMA mode */
3838
int speed; /* DMA speed */
3939

4040
unsigned int lock; /* Device is allocated */
4141
const char *device_id; /* Device name */
4242

43-
unsigned int dma_base; /* Controller base address */
44-
int dma_irq; /* Controller IRQ */
45-
struct scatterlist cur_sg; /* Current controller buffer */
46-
unsigned int state;
47-
48-
struct dma_ops *d_ops;
43+
const struct dma_ops *d_ops;
4944
};
5045

51-
/* Prototype: void arch_dma_init(dma)
52-
* Purpose : Initialise architecture specific DMA
53-
* Params : dma - pointer to array of DMA structures
46+
/*
47+
* isa_dma_add - add an ISA-style DMA channel
5448
*/
55-
extern void arch_dma_init(dma_t *dma);
49+
extern int isa_dma_add(unsigned int, dma_t *dma);
5650

57-
extern void isa_init_dma(dma_t *dma);
51+
/*
52+
* Add the ISA DMA controller. Always takes channels 0-7.
53+
*/
54+
extern void isa_init_dma(void);

‎arch/arm/kernel/dma-isa.c‎

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
#include <asm/dma.h>
2525
#include <asm/mach/dma.h>
2626

27-
#define ISA_DMA_MODE_READ 0x44
28-
#define ISA_DMA_MODE_WRITE 0x48
29-
#define ISA_DMA_MODE_CASCADE 0xc0
30-
#define ISA_DMA_AUTOINIT 0x10
31-
3227
#define ISA_DMA_MASK 0
3328
#define ISA_DMA_MODE 1
3429
#define ISA_DMA_CLRFF 2
@@ -49,38 +44,35 @@ static unsigned int isa_dma_port[8][7] = {
4944
{ 0xd4, 0xd6, 0xd8, 0x48a, 0x08a, 0xcc, 0xce }
5045
};
5146

52-
static int isa_get_dma_residue(dmach_t channel, dma_t *dma)
47+
static int isa_get_dma_residue(unsigned int chan, dma_t *dma)
5348
{
54-
unsigned int io_port = isa_dma_port[channel][ISA_DMA_COUNT];
49+
unsigned int io_port = isa_dma_port[chan][ISA_DMA_COUNT];
5550
int count;
5651

5752
count = 1 + inb(io_port);
5853
count |= inb(io_port) << 8;
5954

60-
return channel < 4 ? count : (count << 1);
55+
return chan < 4 ? count : (count << 1);
6156
}
6257

63-
static void isa_enable_dma(dmach_t channel, dma_t *dma)
58+
static void isa_enable_dma(unsigned int chan, dma_t *dma)
6459
{
6560
if (dma->invalid) {
6661
unsigned long address, length;
6762
unsigned int mode;
6863
enum dma_data_direction direction;
6964

70-
mode = channel & 3;
65+
mode = (chan & 3) | dma->dma_mode;
7166
switch (dma->dma_mode & DMA_MODE_MASK) {
7267
case DMA_MODE_READ:
73-
mode |= ISA_DMA_MODE_READ;
7468
direction = DMA_FROM_DEVICE;
7569
break;
7670

7771
case DMA_MODE_WRITE:
78-
mode |= ISA_DMA_MODE_WRITE;
7972
direction = DMA_TO_DEVICE;
8073
break;
8174

8275
case DMA_MODE_CASCADE:
83-
mode |= ISA_DMA_MODE_CASCADE;
8476
direction = DMA_BIDIRECTIONAL;
8577
break;
8678

@@ -105,34 +97,31 @@ static void isa_enable_dma(dmach_t channel, dma_t *dma)
10597
address = dma->buf.dma_address;
10698
length = dma->buf.length - 1;
10799

108-
outb(address >> 16, isa_dma_port[channel][ISA_DMA_PGLO]);
109-
outb(address >> 24, isa_dma_port[channel][ISA_DMA_PGHI]);
100+
outb(address >> 16, isa_dma_port[chan][ISA_DMA_PGLO]);
101+
outb(address >> 24, isa_dma_port[chan][ISA_DMA_PGHI]);
110102

111-
if (channel >= 4) {
103+
if (chan >= 4) {
112104
address >>= 1;
113105
length >>= 1;
114106
}
115107

116-
outb(0, isa_dma_port[channel][ISA_DMA_CLRFF]);
117-
118-
outb(address, isa_dma_port[channel][ISA_DMA_ADDR]);
119-
outb(address >> 8, isa_dma_port[channel][ISA_DMA_ADDR]);
108+
outb(0, isa_dma_port[chan][ISA_DMA_CLRFF]);
120109

121-
outb(length, isa_dma_port[channel][ISA_DMA_COUNT]);
122-
outb(length >> 8, isa_dma_port[channel][ISA_DMA_COUNT]);
110+
outb(address, isa_dma_port[chan][ISA_DMA_ADDR]);
111+
outb(address >> 8, isa_dma_port[chan][ISA_DMA_ADDR]);
123112

124-
if (dma->dma_mode & DMA_AUTOINIT)
125-
mode |= ISA_DMA_AUTOINIT;
113+
outb(length, isa_dma_port[chan][ISA_DMA_COUNT]);
114+
outb(length >> 8, isa_dma_port[chan][ISA_DMA_COUNT]);
126115

127-
outb(mode, isa_dma_port[channel][ISA_DMA_MODE]);
116+
outb(mode, isa_dma_port[chan][ISA_DMA_MODE]);
128117
dma->invalid = 0;
129118
}
130-
outb(channel & 3, isa_dma_port[channel][ISA_DMA_MASK]);
119+
outb(chan & 3, isa_dma_port[chan][ISA_DMA_MASK]);
131120
}
132121

133-
static void isa_disable_dma(dmach_t channel, dma_t *dma)
122+
static void isa_disable_dma(unsigned int chan, dma_t *dma)
134123
{
135-
outb(channel | 4, isa_dma_port[channel][ISA_DMA_MASK]);
124+
outb(chan | 4, isa_dma_port[chan][ISA_DMA_MASK]);
136125
}
137126

138127
static struct dma_ops isa_dma_ops = {
@@ -160,7 +149,12 @@ static struct resource dma_resources[] = { {
160149
.end = 0x048f
161150
} };
162151

163-
void __init isa_init_dma(dma_t *dma)
152+
static dma_t isa_dma[8];
153+
154+
/*
155+
* ISA DMA always starts at channel 0
156+
*/
157+
void __init isa_init_dma(void)
164158
{
165159
/*
166160
* Try to autodetect presence of an ISA DMA controller.
@@ -178,11 +172,11 @@ void __init isa_init_dma(dma_t *dma)
178172
outb(0xaa, 0x00);
179173

180174
if (inb(0) == 0x55 && inb(0) == 0xaa) {
181-
int channel, i;
175+
unsigned int chan, i;
182176

183-
for (channel = 0; channel < 8; channel++) {
184-
dma[channel].d_ops = &isa_dma_ops;
185-
isa_disable_dma(channel, NULL);
177+
for (chan = 0; chan < 8; chan++) {
178+
isa_dma[chan].d_ops = &isa_dma_ops;
179+
isa_disable_dma(chan, NULL);
186180
}
187181

188182
outb(0x40, 0x0b);
@@ -217,5 +211,12 @@ void __init isa_init_dma(dma_t *dma)
217211

218212
for (i = 0; i < ARRAY_SIZE(dma_resources); i++)
219213
request_resource(&ioport_resource, dma_resources + i);
214+
215+
for (chan = 0; chan < 8; chan++) {
216+
int ret = isa_dma_add(chan, &isa_dma[chan]);
217+
if (ret)
218+
printk(KERN_ERR "ISADMA%u: unable to register: %d\n",
219+
chan, ret);
220+
}
220221
}
221222
}

0 commit comments

Comments
 (0)