aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/sb/emu8000_patch.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /sound/isa/sb/emu8000_patch.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'sound/isa/sb/emu8000_patch.c')
-rw-r--r--sound/isa/sb/emu8000_patch.c303
1 files changed, 303 insertions, 0 deletions
diff --git a/sound/isa/sb/emu8000_patch.c b/sound/isa/sb/emu8000_patch.c
new file mode 100644
index 000000000000..4afc4a1bc140
--- /dev/null
+++ b/sound/isa/sb/emu8000_patch.c
@@ -0,0 +1,303 @@
1/*
2 * Patch routines for the emu8000 (AWE32/64)
3 *
4 * Copyright (C) 1999 Steve Ratcliffe
5 * Copyright (C) 1999-2000 Takashi Iwai <tiwai@suse.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include "emu8000_local.h"
23#include <asm/uaccess.h>
24#include <linux/moduleparam.h>
25
26static int emu8000_reset_addr = 0;
27module_param(emu8000_reset_addr, int, 0444);
28MODULE_PARM_DESC(emu8000_reset_addr, "reset write address at each time (makes slowdown)");
29
30
31/*
32 * Open up channels.
33 */
34static int
35snd_emu8000_open_dma(emu8000_t *emu, int write)
36{
37 int i;
38
39 /* reserve all 30 voices for loading */
40 for (i = 0; i < EMU8000_DRAM_VOICES; i++) {
41 snd_emux_lock_voice(emu->emu, i);
42 snd_emu8000_dma_chan(emu, i, write);
43 }
44
45 /* assign voice 31 and 32 to ROM */
46 EMU8000_VTFT_WRITE(emu, 30, 0);
47 EMU8000_PSST_WRITE(emu, 30, 0x1d8);
48 EMU8000_CSL_WRITE(emu, 30, 0x1e0);
49 EMU8000_CCCA_WRITE(emu, 30, 0x1d8);
50 EMU8000_VTFT_WRITE(emu, 31, 0);
51 EMU8000_PSST_WRITE(emu, 31, 0x1d8);
52 EMU8000_CSL_WRITE(emu, 31, 0x1e0);
53 EMU8000_CCCA_WRITE(emu, 31, 0x1d8);
54
55 return 0;
56}
57
58/*
59 * Close all dram channels.
60 */
61static void
62snd_emu8000_close_dma(emu8000_t *emu)
63{
64 int i;
65
66 for (i = 0; i < EMU8000_DRAM_VOICES; i++) {
67 snd_emu8000_dma_chan(emu, i, EMU8000_RAM_CLOSE);
68 snd_emux_unlock_voice(emu->emu, i);
69 }
70}
71
72/*
73 */
74
75#define BLANK_LOOP_START 4
76#define BLANK_LOOP_END 8
77#define BLANK_LOOP_SIZE 12
78#define BLANK_HEAD_SIZE 48
79
80/*
81 * Read a word from userland, taking care of conversions from
82 * 8bit samples etc.
83 */
84static unsigned short
85read_word(const void __user *buf, int offset, int mode)
86{
87 unsigned short c;
88 if (mode & SNDRV_SFNT_SAMPLE_8BITS) {
89 unsigned char cc;
90 get_user(cc, (unsigned char __user *)buf + offset);
91 c = cc << 8; /* convert 8bit -> 16bit */
92 } else {
93#ifdef SNDRV_LITTLE_ENDIAN
94 get_user(c, (unsigned short __user *)buf + offset);
95#else
96 unsigned short cc;
97 get_user(cc, (unsigned short __user *)buf + offset);
98 c = swab16(cc);
99#endif
100 }
101 if (mode & SNDRV_SFNT_SAMPLE_UNSIGNED)
102 c ^= 0x8000; /* unsigned -> signed */
103 return c;
104}
105
106/*
107 */
108static void
109snd_emu8000_write_wait(emu8000_t *emu)
110{
111 while ((EMU8000_SMALW_READ(emu) & 0x80000000) != 0) {
112 set_current_state(TASK_INTERRUPTIBLE);
113 schedule_timeout(1);
114 if (signal_pending(current))
115 break;
116 }
117}
118
119/*
120 * write sample word data
121 *
122 * You should not have to keep resetting the address each time
123 * as the chip is supposed to step on the next address automatically.
124 * It mostly does, but during writes of some samples at random it
125 * completely loses words (every one in 16 roughly but with no
126 * obvious pattern).
127 *
128 * This is therefore much slower than need be, but is at least
129 * working.
130 */
131inline static void
132write_word(emu8000_t *emu, int *offset, unsigned short data)
133{
134 if (emu8000_reset_addr) {
135 if (emu8000_reset_addr > 1)
136 snd_emu8000_write_wait(emu);
137 EMU8000_SMALW_WRITE(emu, *offset);
138 }
139 EMU8000_SMLD_WRITE(emu, data);
140 *offset += 1;
141}
142
143/*
144 * Write the sample to EMU800 memory. This routine is invoked out of
145 * the generic soundfont routines as a callback.
146 */
147int
148snd_emu8000_sample_new(snd_emux_t *rec, snd_sf_sample_t *sp,
149 snd_util_memhdr_t *hdr, const void __user *data, long count)
150{
151 int i;
152 int rc;
153 int offset;
154 int truesize;
155 int dram_offset, dram_start;
156 emu8000_t *emu;
157
158 emu = rec->hw;
159 snd_assert(sp != NULL, return -EINVAL);
160
161 if (sp->v.size == 0)
162 return 0;
163
164 /* be sure loop points start < end */
165 if (sp->v.loopstart > sp->v.loopend) {
166 int tmp = sp->v.loopstart;
167 sp->v.loopstart = sp->v.loopend;
168 sp->v.loopend = tmp;
169 }
170
171 /* compute true data size to be loaded */
172 truesize = sp->v.size;
173 if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP|SNDRV_SFNT_SAMPLE_REVERSE_LOOP))
174 truesize += sp->v.loopend - sp->v.loopstart;
175 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_NO_BLANK)
176 truesize += BLANK_LOOP_SIZE;
177
178 sp->block = snd_util_mem_alloc(hdr, truesize * 2);
179 if (sp->block == NULL) {
180 /*snd_printd("EMU8000: out of memory\n");*/
181 /* not ENOMEM (for compatibility) */
182 return -ENOSPC;
183 }
184
185 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS) {
186 if (!access_ok(VERIFY_READ, data, sp->v.size))
187 return -EFAULT;
188 } else {
189 if (!access_ok(VERIFY_READ, data, sp->v.size * 2))
190 return -EFAULT;
191 }
192
193 /* recalculate address offset */
194 sp->v.end -= sp->v.start;
195 sp->v.loopstart -= sp->v.start;
196 sp->v.loopend -= sp->v.start;
197 sp->v.start = 0;
198
199 /* dram position (in word) -- mem_offset is byte */
200 dram_offset = EMU8000_DRAM_OFFSET + (sp->block->offset >> 1);
201 dram_start = dram_offset;
202
203 /* set the total size (store onto obsolete checksum value) */
204 sp->v.truesize = truesize * 2; /* in bytes */
205
206 snd_emux_terminate_all(emu->emu);
207 if ((rc = snd_emu8000_open_dma(emu, EMU8000_RAM_WRITE)) != 0)
208 return rc;
209
210 /* Set the address to start writing at */
211 snd_emu8000_write_wait(emu);
212 EMU8000_SMALW_WRITE(emu, dram_offset);
213
214 /*snd_emu8000_init_fm(emu);*/
215
216#if 0
217 /* first block - write 48 samples for silence */
218 if (! sp->block->offset) {
219 for (i = 0; i < BLANK_HEAD_SIZE; i++) {
220 write_word(emu, &dram_offset, 0);
221 }
222 }
223#endif
224
225 offset = 0;
226 for (i = 0; i < sp->v.size; i++) {
227 unsigned short s;
228
229 s = read_word(data, offset, sp->v.mode_flags);
230 offset++;
231 write_word(emu, &dram_offset, s);
232
233 /* we may take too long time in this loop.
234 * so give controls back to kernel if needed.
235 */
236 cond_resched();
237
238 if (i == sp->v.loopend &&
239 (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP|SNDRV_SFNT_SAMPLE_REVERSE_LOOP)))
240 {
241 int looplen = sp->v.loopend - sp->v.loopstart;
242 int k;
243
244 /* copy reverse loop */
245 for (k = 1; k <= looplen; k++) {
246 s = read_word(data, offset - k, sp->v.mode_flags);
247 write_word(emu, &dram_offset, s);
248 }
249 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_BIDIR_LOOP) {
250 sp->v.loopend += looplen;
251 } else {
252 sp->v.loopstart += looplen;
253 sp->v.loopend += looplen;
254 }
255 sp->v.end += looplen;
256 }
257 }
258
259 /* if no blank loop is attached in the sample, add it */
260 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_NO_BLANK) {
261 for (i = 0; i < BLANK_LOOP_SIZE; i++) {
262 write_word(emu, &dram_offset, 0);
263 }
264 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_SINGLESHOT) {
265 sp->v.loopstart = sp->v.end + BLANK_LOOP_START;
266 sp->v.loopend = sp->v.end + BLANK_LOOP_END;
267 }
268 }
269
270 /* add dram offset */
271 sp->v.start += dram_start;
272 sp->v.end += dram_start;
273 sp->v.loopstart += dram_start;
274 sp->v.loopend += dram_start;
275
276 snd_emu8000_close_dma(emu);
277 snd_emu8000_init_fm(emu);
278
279 return 0;
280}
281
282/*
283 * free a sample block
284 */
285int
286snd_emu8000_sample_free(snd_emux_t *rec, snd_sf_sample_t *sp, snd_util_memhdr_t *hdr)
287{
288 if (sp->block) {
289 snd_util_mem_free(hdr, sp->block);
290 sp->block = NULL;
291 }
292 return 0;
293}
294
295
296/*
297 * sample_reset callback - terminate voices
298 */
299void
300snd_emu8000_sample_reset(snd_emux_t *rec)
301{
302 snd_emux_terminate_all(rec);
303}