linux-omap 2.6.37: replace various patch with upstream versions and rediff
[openembedded.git] / recipes / linux / linux-2.6.18 / avr32-dma-controller-framework.patch
blob0f6301303bcd05f9d921ce4cc52a02186888f570
1 From 740c72fe92a5536060ac6debbfe0a26c0b9b8770 Mon Sep 17 00:00:00 2001
2 From: Haavard Skinnemoen <hskinnemoen@atmel.com>
3 Date: Mon, 11 Sep 2006 17:59:59 +0200
4 Subject: [PATCH] AVR32: DMA controller framework
6 This patch puts the DMA controller framework used in earlier BSPs back.
7 It was removed before the AVR32 patches went into -mm, and it should
8 be removed here as well as soon as we have an alternative.
10 ---
11 arch/avr32/kernel/Makefile | 1
12 arch/avr32/kernel/dma-controller.c | 34 +++++++
13 include/asm-avr32/dma-controller.h | 165 ++++++++++++++++++++++++++++++++++++
14 3 files changed, 200 insertions(+), 0 deletions(-)
16 diff --git a/arch/avr32/kernel/Makefile b/arch/avr32/kernel/Makefile
17 index 90e5aff..b6afc0c 100644
18 --- a/arch/avr32/kernel/Makefile
19 +++ b/arch/avr32/kernel/Makefile
20 @@ -9,6 +9,7 @@ obj-y += syscall_table.o syscall-stub
21 obj-y += setup.o traps.o semaphore.o ptrace.o
22 obj-y += signal.o sys_avr32.o process.o time.o
23 obj-y += init_task.o switch_to.o cpu.o
24 +obj-y += dma-controller.o
25 obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
26 obj-$(CONFIG_KPROBES) += kprobes.o
28 diff --git a/arch/avr32/kernel/dma-controller.c b/arch/avr32/kernel/dma-controller.c
29 new file mode 100644
30 index 0000000..fb654b3
31 --- /dev/null
32 +++ b/arch/avr32/kernel/dma-controller.c
33 @@ -0,0 +1,34 @@
34 +/*
35 + * Preliminary DMA controller framework for AVR32
36 + *
37 + * Copyright (C) 2005-2006 Atmel Corporation
38 + *
39 + * This program is free software; you can redistribute it and/or modify
40 + * it under the terms of the GNU General Public License version 2 as
41 + * published by the Free Software Foundation.
42 + */
43 +#include <asm/dma-controller.h>
45 +static LIST_HEAD(controllers);
47 +int register_dma_controller(struct dma_controller *dmac)
49 + static int next_id;
51 + dmac->id = next_id++;
52 + list_add_tail(&dmac->list, &controllers);
54 + return 0;
56 +EXPORT_SYMBOL(register_dma_controller);
58 +struct dma_controller *find_dma_controller(int id)
60 + struct dma_controller *dmac;
62 + list_for_each_entry(dmac, &controllers, list)
63 + if (dmac->id == id)
64 + return dmac;
65 + return NULL;
67 +EXPORT_SYMBOL(find_dma_controller);
68 diff --git a/include/asm-avr32/dma-controller.h b/include/asm-avr32/dma-controller.h
69 new file mode 100644
70 index 0000000..8c67601
71 --- /dev/null
72 +++ b/include/asm-avr32/dma-controller.h
73 @@ -0,0 +1,165 @@
74 +/*
75 + * Copyright (C) 2005-2006 Atmel Corporation
76 + *
77 + * This program is free software; you can redistribute it and/or modify
78 + * it under the terms of the GNU General Public License version 2 as
79 + * published by the Free Software Foundation.
80 + */
81 +#ifndef __ASM_AVR32_DMA_CONTROLLER_H
82 +#define __ASM_AVR32_DMA_CONTROLLER_H
84 +#include <linux/device.h>
86 +#define DMA_DIR_MEM_TO_MEM 0x0000
87 +#define DMA_DIR_MEM_TO_PERIPH 0x0001
88 +#define DMA_DIR_PERIPH_TO_MEM 0x0002
89 +#define DMA_DIR_PERIPH_TO_PERIPH 0x0003
91 +#define DMA_WIDTH_8BIT 0
92 +#define DMA_WIDTH_16BIT 1
93 +#define DMA_WIDTH_32BIT 2
95 +struct dma_request {
96 + struct dma_controller *dmac;
97 + struct list_head list;
99 + unsigned short channel;
101 + void (*xfer_complete)(struct dma_request *req);
102 + void (*block_complete)(struct dma_request *req);
103 + void (*error)(struct dma_request *req);
106 +struct dma_request_sg {
107 + struct dma_request req;
109 + int nr_sg;
110 + struct scatterlist *sg;
111 + unsigned long block_size;
113 + dma_addr_t data_reg;
114 + unsigned short periph_id;
116 + unsigned char direction;
117 + unsigned char width;
119 +#define to_dma_request_sg(_req) \
120 + container_of(_req, struct dma_request_sg, req)
122 +struct dma_request_cyclic {
123 + struct dma_request req;
125 + int periods;
126 + unsigned long buffer_size;
128 + dma_addr_t buffer_start;
129 + dma_addr_t data_reg;
131 + unsigned short periph_id;
132 + unsigned char direction;
133 + unsigned char width;
135 + void *dev_id;
137 +#define to_dma_request_cyclic(_req) \
138 + container_of(_req, struct dma_request_cyclic, req)
140 +struct dma_request_memcpy {
141 + struct dma_request req;
143 + dma_addr_t src_addr;
144 + unsigned int src_width;
145 + unsigned int src_stride;
147 + dma_addr_t dst_addr;
148 + unsigned int dst_width;
149 + unsigned int dst_stride;
151 + size_t length;
153 + unsigned short src_reverse:1;
154 + unsigned short dst_reverse:1;
156 +#define to_dma_request_memcpy(_req) \
157 + container_of(_req, struct dma_request_memcpy, req)
159 +struct dma_controller {
160 + struct list_head list;
161 + int id;
162 + struct device *dev;
164 + int (*alloc_channel)(struct dma_controller *dmac);
165 + void (*release_channel)(struct dma_controller *dmac,
166 + int channel);
167 + int (*prepare_request_sg)(struct dma_controller *dmac,
168 + struct dma_request_sg *req);
169 + int (*prepare_request_cyclic)(struct dma_controller *dmac,
170 + struct dma_request_cyclic *req);
171 + int (*prepare_request_memcpy)(struct dma_controller *dmac,
172 + struct dma_request_memcpy *req);
173 + int (*start_request)(struct dma_controller *dmac,
174 + unsigned int channel);
175 + int (*stop_request)(struct dma_controller *dmac,
176 + unsigned int channel);
177 + dma_addr_t (*get_current_pos)(struct dma_controller *dmac,
178 + unsigned int channel);
181 +static inline int
182 +dma_alloc_channel(struct dma_controller *dmac)
184 + return dmac->alloc_channel(dmac);
187 +static inline void
188 +dma_release_channel(struct dma_controller *dmac, int chan)
190 + dmac->release_channel(dmac, chan);
193 +static inline int
194 +dma_prepare_request_sg(struct dma_controller *dmac,
195 + struct dma_request_sg *req)
197 + return dmac->prepare_request_sg(dmac, req);
200 +static inline int
201 +dma_prepare_request_cyclic(struct dma_controller *dmac,
202 + struct dma_request_cyclic *req)
204 + return dmac->prepare_request_cyclic(dmac, req);
207 +static inline int
208 +dma_prepare_request_memcpy(struct dma_controller *dmac,
209 + struct dma_request_memcpy *req)
211 + return dmac->prepare_request_memcpy(dmac, req);
214 +static inline int
215 +dma_start_request(struct dma_controller *dmac,
216 + unsigned int channel)
218 + return dmac->start_request(dmac, channel);
221 +static inline int
222 +dma_stop_request(struct dma_controller *dmac,
223 + unsigned int channel)
225 + return dmac->stop_request(dmac, channel);
228 +static inline dma_addr_t
229 +dma_get_current_pos(struct dma_controller *dmac,
230 + unsigned int channel)
232 + return dmac->get_current_pos(dmac, channel);
235 +extern int register_dma_controller(struct dma_controller *dmac);
236 +extern struct dma_controller *find_dma_controller(int id);
238 +#endif /* __ASM_AVR32_DMA_CONTROLLER_H */
240 1.4.1.1