vidcaudio.c revision 1.23 1 1.23 bjh21 /* $NetBSD: vidcaudio.c,v 1.23 2003/12/29 16:49:31 bjh21 Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 1995 Melvin Tang-Richardson
5 1.1 reinoud *
6 1.1 reinoud * Redistribution and use in source and binary forms, with or without
7 1.1 reinoud * modification, are permitted provided that the following conditions
8 1.1 reinoud * are met:
9 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
10 1.1 reinoud * notice, this list of conditions and the following disclaimer.
11 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
13 1.1 reinoud * documentation and/or other materials provided with the distribution.
14 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
15 1.1 reinoud * must display the following acknowledgement:
16 1.1 reinoud * This product includes software developed by the RiscBSD team.
17 1.1 reinoud * 4. The name of the author may not be used to endorse or promote products
18 1.1 reinoud * derived from this software without specific prior written permission.
19 1.1 reinoud *
20 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 reinoud * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 reinoud * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1 reinoud * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 reinoud * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 reinoud * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 reinoud * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 reinoud * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 reinoud * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 reinoud * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 reinoud */
31 1.1 reinoud
32 1.1 reinoud /*
33 1.1 reinoud * audio driver for the RiscPC 16 bit sound
34 1.1 reinoud *
35 1.1 reinoud * Interfaces with the NetBSD generic audio driver to provide SUN
36 1.1 reinoud * /dev/audio (partial) compatibility.
37 1.1 reinoud */
38 1.1 reinoud
39 1.1 reinoud #include <sys/param.h> /* proc.h */
40 1.5 bjh21
41 1.23 bjh21 __KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.23 2003/12/29 16:49:31 bjh21 Exp $");
42 1.5 bjh21
43 1.18 bjh21 #include <sys/audioio.h>
44 1.1 reinoud #include <sys/conf.h> /* autoconfig functions */
45 1.1 reinoud #include <sys/device.h> /* device calls */
46 1.18 bjh21 #include <sys/errno.h>
47 1.1 reinoud #include <sys/proc.h> /* device calls */
48 1.1 reinoud #include <sys/systm.h>
49 1.1 reinoud
50 1.1 reinoud #include <uvm/uvm_extern.h>
51 1.1 reinoud
52 1.1 reinoud #include <dev/audio_if.h>
53 1.1 reinoud
54 1.4 thorpej #include <machine/intr.h>
55 1.3 thorpej #include <arm/arm32/katelib.h>
56 1.1 reinoud
57 1.5 bjh21 #include <arm/iomd/vidcaudiovar.h>
58 1.1 reinoud #include <arm/iomd/iomdreg.h>
59 1.1 reinoud #include <arm/iomd/iomdvar.h>
60 1.1 reinoud #include <arm/iomd/vidc.h>
61 1.1 reinoud #include <arm/mainbus/mainbus.h>
62 1.1 reinoud #include <arm/iomd/waveform.h>
63 1.1 reinoud #include "vidcaudio.h"
64 1.1 reinoud
65 1.1 reinoud extern int *vidc_base;
66 1.1 reinoud
67 1.1 reinoud struct audio_general {
68 1.18 bjh21 vaddr_t silence;
69 1.18 bjh21 irqhandler_t ih;
70 1.1 reinoud
71 1.18 bjh21 void (*intr)(void *);
72 1.18 bjh21 void *arg;
73 1.1 reinoud
74 1.18 bjh21 paddr_t next_cur;
75 1.18 bjh21 paddr_t next_end;
76 1.18 bjh21 void (*next_intr)(void *);
77 1.18 bjh21 void *next_arg;
78 1.1 reinoud
79 1.18 bjh21 int buffer;
80 1.18 bjh21 int in_progress;
81 1.1 reinoud
82 1.18 bjh21 int open;
83 1.1 reinoud } ag;
84 1.1 reinoud
85 1.1 reinoud struct vidcaudio_softc {
86 1.18 bjh21 struct device device;
87 1.1 reinoud
88 1.18 bjh21 int open;
89 1.1 reinoud };
90 1.1 reinoud
91 1.18 bjh21 int vidcaudio_probe(struct device *, struct cfdata *, void *);
92 1.18 bjh21 void vidcaudio_attach(struct device *, struct device *, void *);
93 1.18 bjh21 int vidcaudio_open(void *, int);
94 1.18 bjh21 void vidcaudio_close(void *);
95 1.18 bjh21
96 1.18 bjh21 int vidcaudio_intr(void *);
97 1.18 bjh21 int vidcaudio_dma_program(vaddr_t, vaddr_t, void (*)(void *), void *);
98 1.18 bjh21 void vidcaudio_dummy_routine(void *);
99 1.18 bjh21 int vidcaudio_stereo(int, int);
100 1.18 bjh21 int vidcaudio_rate(int);
101 1.17 bjh21 void vidcaudio_shutdown(void);
102 1.1 reinoud
103 1.1 reinoud static int sound_dma_intr;
104 1.1 reinoud
105 1.12 thorpej CFATTACH_DECL(vidcaudio, sizeof(struct vidcaudio_softc),
106 1.13 thorpej vidcaudio_probe, vidcaudio_attach, NULL, NULL);
107 1.1 reinoud
108 1.17 bjh21 int vidcaudio_query_encoding(void *, struct audio_encoding *);
109 1.18 bjh21 int vidcaudio_set_params(void *, int, int, struct audio_params *,
110 1.18 bjh21 struct audio_params *);
111 1.17 bjh21 int vidcaudio_round_blocksize(void *, int);
112 1.17 bjh21 int vidcaudio_start_output(void *, void *, int, void (*)(void *), void *);
113 1.17 bjh21 int vidcaudio_start_input(void *, void *, int, void (*)(void *), void *);
114 1.17 bjh21 int vidcaudio_halt_output(void *);
115 1.17 bjh21 int vidcaudio_halt_input(void *);
116 1.17 bjh21 int vidcaudio_getdev(void *, struct audio_device *);
117 1.17 bjh21 int vidcaudio_set_port(void *, mixer_ctrl_t *);
118 1.17 bjh21 int vidcaudio_get_port(void *, mixer_ctrl_t *);
119 1.17 bjh21 int vidcaudio_query_devinfo(void *, mixer_devinfo_t *);
120 1.17 bjh21 int vidcaudio_get_props(void *);
121 1.1 reinoud
122 1.1 reinoud struct audio_device vidcaudio_device = {
123 1.1 reinoud "VidcAudio 8-bit",
124 1.1 reinoud "x",
125 1.1 reinoud "vidcaudio"
126 1.1 reinoud };
127 1.1 reinoud
128 1.1 reinoud struct audio_hw_if vidcaudio_hw_if = {
129 1.1 reinoud vidcaudio_open,
130 1.1 reinoud vidcaudio_close,
131 1.19 bjh21 NULL,
132 1.1 reinoud vidcaudio_query_encoding,
133 1.1 reinoud vidcaudio_set_params,
134 1.1 reinoud vidcaudio_round_blocksize,
135 1.19 bjh21 NULL,
136 1.19 bjh21 NULL,
137 1.19 bjh21 NULL,
138 1.1 reinoud vidcaudio_start_output,
139 1.1 reinoud vidcaudio_start_input,
140 1.1 reinoud vidcaudio_halt_output,
141 1.1 reinoud vidcaudio_halt_input,
142 1.23 bjh21 NULL,
143 1.1 reinoud vidcaudio_getdev,
144 1.19 bjh21 NULL,
145 1.1 reinoud vidcaudio_set_port,
146 1.1 reinoud vidcaudio_get_port,
147 1.1 reinoud vidcaudio_query_devinfo,
148 1.19 bjh21 NULL,
149 1.19 bjh21 NULL,
150 1.19 bjh21 NULL,
151 1.19 bjh21 NULL,
152 1.1 reinoud vidcaudio_get_props,
153 1.19 bjh21 NULL,
154 1.19 bjh21 NULL,
155 1.19 bjh21 NULL,
156 1.1 reinoud };
157 1.1 reinoud
158 1.1 reinoud
159 1.1 reinoud void
160 1.17 bjh21 vidcaudio_beep_generate(void)
161 1.1 reinoud {
162 1.18 bjh21
163 1.1 reinoud vidcaudio_dma_program(ag.silence, ag.silence+sizeof(beep_waveform)-16,
164 1.1 reinoud vidcaudio_dummy_routine, NULL);
165 1.1 reinoud }
166 1.1 reinoud
167 1.1 reinoud
168 1.1 reinoud int
169 1.17 bjh21 vidcaudio_probe(struct device *parent, struct cfdata *cf, void *aux)
170 1.1 reinoud {
171 1.1 reinoud int id;
172 1.1 reinoud
173 1.1 reinoud id = IOMD_ID;
174 1.1 reinoud
175 1.1 reinoud /* So far I only know about this IOMD */
176 1.1 reinoud switch (id) {
177 1.1 reinoud case RPC600_IOMD_ID:
178 1.18 bjh21 return 1;
179 1.1 reinoud break;
180 1.1 reinoud case ARM7500_IOC_ID:
181 1.1 reinoud case ARM7500FE_IOC_ID:
182 1.18 bjh21 return 1;
183 1.1 reinoud break;
184 1.1 reinoud default:
185 1.1 reinoud printf("vidcaudio: Unknown IOMD id=%04x", id);
186 1.1 reinoud break;
187 1.1 reinoud }
188 1.1 reinoud
189 1.18 bjh21 return 0;
190 1.1 reinoud }
191 1.1 reinoud
192 1.1 reinoud
193 1.1 reinoud void
194 1.17 bjh21 vidcaudio_attach(struct device *parent, struct device *self, void *aux)
195 1.1 reinoud {
196 1.1 reinoud struct vidcaudio_softc *sc = (void *)self;
197 1.1 reinoud int id;
198 1.1 reinoud
199 1.1 reinoud sc->open = 0;
200 1.1 reinoud ag.in_progress = 0;
201 1.1 reinoud
202 1.1 reinoud ag.next_cur = 0;
203 1.1 reinoud ag.next_end = 0;
204 1.1 reinoud ag.next_intr = NULL;
205 1.1 reinoud ag.next_arg = NULL;
206 1.1 reinoud
207 1.18 bjh21 vidcaudio_rate(32); /* 24*1024 */
208 1.1 reinoud
209 1.1 reinoud /* Program the silence buffer and reset the DMA channel */
210 1.14 thorpej ag.silence = uvm_km_alloc(kernel_map, PAGE_SIZE);
211 1.15 jdolecek if (ag.silence == 0)
212 1.10 provos panic("vidcaudio: Cannot allocate memory");
213 1.1 reinoud
214 1.14 thorpej memset((char *)ag.silence, 0, PAGE_SIZE);
215 1.1 reinoud memcpy((char *)ag.silence, (char *)beep_waveform, sizeof(beep_waveform));
216 1.1 reinoud
217 1.1 reinoud ag.buffer = 0;
218 1.1 reinoud
219 1.1 reinoud /* Install the irq handler for the DMA interrupt */
220 1.1 reinoud ag.ih.ih_func = vidcaudio_intr;
221 1.1 reinoud ag.ih.ih_arg = NULL;
222 1.1 reinoud ag.ih.ih_level = IPL_AUDIO;
223 1.1 reinoud ag.ih.ih_name = "vidcaudio";
224 1.1 reinoud
225 1.1 reinoud ag.intr = NULL;
226 1.1 reinoud /* ag.nextintr = NULL;*/
227 1.1 reinoud
228 1.1 reinoud id = IOMD_ID;
229 1.1 reinoud
230 1.1 reinoud switch (id) {
231 1.1 reinoud case RPC600_IOMD_ID:
232 1.1 reinoud sound_dma_intr = IRQ_DMASCH0;
233 1.1 reinoud break;
234 1.1 reinoud case ARM7500_IOC_ID:
235 1.1 reinoud case ARM7500FE_IOC_ID:
236 1.1 reinoud sound_dma_intr = IRQ_SDMA;
237 1.1 reinoud break;
238 1.1 reinoud }
239 1.1 reinoud
240 1.1 reinoud disable_irq(sound_dma_intr);
241 1.1 reinoud
242 1.1 reinoud if (irq_claim(sound_dma_intr, &(ag.ih)))
243 1.10 provos panic("vidcaudio: couldn't claim IRQ %d", sound_dma_intr);
244 1.1 reinoud
245 1.1 reinoud disable_irq(sound_dma_intr);
246 1.1 reinoud
247 1.1 reinoud printf("\n");
248 1.1 reinoud
249 1.21 bjh21 vidcaudio_dma_program(ag.silence, ag.silence + PAGE_SIZE - 16,
250 1.1 reinoud vidcaudio_dummy_routine, NULL);
251 1.1 reinoud
252 1.1 reinoud audio_attach_mi(&vidcaudio_hw_if, sc, &sc->device);
253 1.1 reinoud
254 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
255 1.1 reinoud printf(" UNDER DEVELOPMENT (nuts)\n");
256 1.1 reinoud #endif
257 1.1 reinoud }
258 1.1 reinoud
259 1.1 reinoud int
260 1.17 bjh21 vidcaudio_open(void *addr, int flags)
261 1.1 reinoud {
262 1.1 reinoud struct vidcaudio_softc *sc = addr;
263 1.1 reinoud
264 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
265 1.1 reinoud printf("DEBUG: vidcaudio_open called\n");
266 1.1 reinoud #endif
267 1.1 reinoud
268 1.1 reinoud if (sc->open)
269 1.1 reinoud return EBUSY;
270 1.1 reinoud
271 1.1 reinoud sc->open = 1;
272 1.1 reinoud ag.open = 1;
273 1.1 reinoud
274 1.1 reinoud return 0;
275 1.1 reinoud }
276 1.1 reinoud
277 1.1 reinoud void
278 1.17 bjh21 vidcaudio_close(void *addr)
279 1.1 reinoud {
280 1.1 reinoud struct vidcaudio_softc *sc = addr;
281 1.1 reinoud
282 1.1 reinoud vidcaudio_shutdown();
283 1.1 reinoud
284 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
285 1.1 reinoud printf("DEBUG: vidcaudio_close called\n");
286 1.1 reinoud #endif
287 1.1 reinoud
288 1.1 reinoud sc->open = 0;
289 1.1 reinoud ag.open = 0;
290 1.1 reinoud }
291 1.1 reinoud
292 1.18 bjh21 /*
293 1.18 bjh21 * Interface to the generic audio driver
294 1.18 bjh21 */
295 1.1 reinoud
296 1.1 reinoud int
297 1.17 bjh21 vidcaudio_query_encoding(void *addr, struct audio_encoding *fp)
298 1.1 reinoud {
299 1.18 bjh21
300 1.1 reinoud switch (fp->index) {
301 1.1 reinoud case 0:
302 1.1 reinoud strcpy(fp->name, "vidc");
303 1.1 reinoud fp->encoding = AUDIO_ENCODING_ULAW;
304 1.1 reinoud fp->precision = 8;
305 1.1 reinoud fp->flags = 0;
306 1.1 reinoud break;
307 1.1 reinoud
308 1.1 reinoud default:
309 1.18 bjh21 return EINVAL;
310 1.1 reinoud }
311 1.1 reinoud return 0;
312 1.1 reinoud }
313 1.1 reinoud
314 1.1 reinoud int
315 1.17 bjh21 vidcaudio_set_params(void *addr, int setmode, int usemode,
316 1.17 bjh21 struct audio_params *p, struct audio_params *r)
317 1.1 reinoud {
318 1.18 bjh21
319 1.16 bjh21 if (p->encoding != AUDIO_ENCODING_ULAW)
320 1.1 reinoud return EINVAL;
321 1.16 bjh21 /* FIXME Handle number of channels properly. */
322 1.1 reinoud vidcaudio_rate(4 * p->sample_rate / (3 * 1024)); /* XXX probably wrong */
323 1.1 reinoud
324 1.1 reinoud return 0;
325 1.1 reinoud }
326 1.1 reinoud
327 1.1 reinoud int
328 1.17 bjh21 vidcaudio_round_blocksize(void *addr, int blk)
329 1.1 reinoud {
330 1.18 bjh21
331 1.14 thorpej if (blk > PAGE_SIZE)
332 1.14 thorpej blk = PAGE_SIZE;
333 1.1 reinoud return (blk);
334 1.1 reinoud }
335 1.1 reinoud
336 1.14 thorpej #define ROUND(s) ( ((int)s) & (~(PAGE_SIZE-1)) )
337 1.1 reinoud
338 1.1 reinoud int
339 1.17 bjh21 vidcaudio_start_output(void *addr, void *p, int cc, void (*intr)(void *),
340 1.17 bjh21 void *arg)
341 1.1 reinoud {
342 1.18 bjh21
343 1.1 reinoud /* I can only DMA inside 1 page */
344 1.1 reinoud
345 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
346 1.20 bjh21 printf("vidcaudio_start_output (%d) %p %p\n", cc, intr, arg);
347 1.1 reinoud #endif
348 1.1 reinoud
349 1.1 reinoud if (ROUND(p) != ROUND(p+cc)) {
350 1.1 reinoud /*
351 1.1 reinoud * If it's over a page I can fix it up by copying it into
352 1.1 reinoud * my buffer
353 1.1 reinoud */
354 1.1 reinoud
355 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
356 1.1 reinoud printf("vidcaudio: DMA over page boundary requested."
357 1.1 reinoud " Fixing up\n");
358 1.1 reinoud #endif
359 1.14 thorpej memcpy(p, (char *)ag.silence, cc > PAGE_SIZE ? PAGE_SIZE : cc);
360 1.1 reinoud p = (void *)ag.silence;
361 1.1 reinoud
362 1.1 reinoud /*
363 1.1 reinoud * I can't DMA any more than that, but it is possible to
364 1.1 reinoud * fix it up by handling multiple buffers and only
365 1.1 reinoud * interrupting the audio driver after sending out all the
366 1.1 reinoud * stuff it gave me. That it more than I can be bothered
367 1.1 reinoud * to do right now and it probablly wont happen so I'll just
368 1.1 reinoud * truncate the buffer and tell the user.
369 1.1 reinoud */
370 1.1 reinoud
371 1.14 thorpej if (cc > PAGE_SIZE) {
372 1.1 reinoud printf("vidcaudio: DMA buffer truncated. I could fix this up\n");
373 1.14 thorpej cc = PAGE_SIZE;
374 1.1 reinoud }
375 1.1 reinoud }
376 1.8 thorpej vidcaudio_dma_program((vaddr_t)p, (vaddr_t)((char *)p+cc),
377 1.1 reinoud intr, arg);
378 1.1 reinoud return 0;
379 1.1 reinoud }
380 1.1 reinoud
381 1.1 reinoud int
382 1.17 bjh21 vidcaudio_start_input(void *addr, void *p, int cc, void (*intr)(void *),
383 1.17 bjh21 void *arg)
384 1.1 reinoud {
385 1.1 reinoud return EIO;
386 1.1 reinoud }
387 1.1 reinoud
388 1.1 reinoud int
389 1.17 bjh21 vidcaudio_halt_output(void *addr)
390 1.1 reinoud {
391 1.18 bjh21
392 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
393 1.1 reinoud printf("DEBUG: vidcaudio_halt_output\n");
394 1.1 reinoud #endif
395 1.1 reinoud return EIO;
396 1.1 reinoud }
397 1.1 reinoud
398 1.1 reinoud int
399 1.17 bjh21 vidcaudio_halt_input(void *addr)
400 1.1 reinoud {
401 1.18 bjh21
402 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
403 1.1 reinoud printf("DEBUG: vidcaudio_halt_input\n");
404 1.1 reinoud #endif
405 1.1 reinoud return EIO;
406 1.1 reinoud }
407 1.1 reinoud
408 1.1 reinoud int
409 1.17 bjh21 vidcaudio_getdev(void *addr, struct audio_device *retp)
410 1.1 reinoud {
411 1.18 bjh21
412 1.1 reinoud *retp = vidcaudio_device;
413 1.1 reinoud return 0;
414 1.1 reinoud }
415 1.1 reinoud
416 1.1 reinoud
417 1.1 reinoud int
418 1.17 bjh21 vidcaudio_set_port(void *addr, mixer_ctrl_t *cp)
419 1.1 reinoud {
420 1.18 bjh21
421 1.1 reinoud return EINVAL;
422 1.1 reinoud }
423 1.1 reinoud
424 1.1 reinoud int
425 1.17 bjh21 vidcaudio_get_port(void *addr, mixer_ctrl_t *cp)
426 1.1 reinoud {
427 1.18 bjh21
428 1.1 reinoud return EINVAL;
429 1.1 reinoud }
430 1.1 reinoud
431 1.1 reinoud int
432 1.17 bjh21 vidcaudio_query_devinfo(void *addr, mixer_devinfo_t *dip)
433 1.1 reinoud {
434 1.18 bjh21
435 1.1 reinoud return ENXIO;
436 1.1 reinoud }
437 1.1 reinoud
438 1.1 reinoud int
439 1.17 bjh21 vidcaudio_get_props(void *addr)
440 1.1 reinoud {
441 1.18 bjh21
442 1.1 reinoud return 0;
443 1.1 reinoud }
444 1.1 reinoud void
445 1.17 bjh21 vidcaudio_dummy_routine(void *arg)
446 1.1 reinoud {
447 1.18 bjh21
448 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
449 1.1 reinoud printf("vidcaudio_dummy_routine\n");
450 1.1 reinoud #endif
451 1.1 reinoud }
452 1.1 reinoud
453 1.1 reinoud int
454 1.17 bjh21 vidcaudio_rate(int rate)
455 1.1 reinoud {
456 1.18 bjh21
457 1.1 reinoud WriteWord(vidc_base, VIDC_SFR | rate);
458 1.1 reinoud return 0;
459 1.1 reinoud }
460 1.1 reinoud
461 1.1 reinoud int
462 1.17 bjh21 vidcaudio_stereo(int channel, int position)
463 1.1 reinoud {
464 1.18 bjh21
465 1.1 reinoud if (channel < 0) return EINVAL;
466 1.1 reinoud if (channel > 7) return EINVAL;
467 1.18 bjh21 channel = channel << 24 | VIDC_SIR0;
468 1.1 reinoud WriteWord(vidc_base, channel | position);
469 1.1 reinoud return 0;
470 1.1 reinoud }
471 1.1 reinoud
472 1.7 thorpej #define PHYS(x, y) pmap_extract(pmap_kernel(), ((x)&L2_S_FRAME), (paddr_t *)(y))
473 1.1 reinoud
474 1.1 reinoud /*
475 1.1 reinoud * Program the next buffer to be used
476 1.1 reinoud * This function must be re-entrant, maximum re-entrancy of 2
477 1.1 reinoud */
478 1.1 reinoud
479 1.1 reinoud #define FLAGS (0)
480 1.1 reinoud
481 1.1 reinoud int
482 1.17 bjh21 vidcaudio_dma_program(vaddr_t cur, vaddr_t end, void (*intr)(void *),
483 1.17 bjh21 void *arg)
484 1.1 reinoud {
485 1.1 reinoud paddr_t pa1, pa2;
486 1.1 reinoud
487 1.1 reinoud /* If there isn't a transfer in progress then start a new one */
488 1.1 reinoud if (ag.in_progress == 0) {
489 1.1 reinoud ag.buffer = 0;
490 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CR, 0x90); /* Reset State Machine */
491 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CR, 0x30); /* Reset State Machine */
492 1.1 reinoud
493 1.1 reinoud PHYS(cur, &pa1);
494 1.1 reinoud PHYS(end - 16, &pa2);
495 1.1 reinoud
496 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, pa1);
497 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, pa2|FLAGS);
498 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, pa1);
499 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, pa2|FLAGS);
500 1.1 reinoud
501 1.1 reinoud ag.in_progress = 1;
502 1.1 reinoud
503 1.1 reinoud ag.next_cur = ag.next_end = 0;
504 1.1 reinoud ag.next_intr = ag.next_arg = 0;
505 1.1 reinoud
506 1.1 reinoud ag.intr = intr;
507 1.1 reinoud ag.arg = arg;
508 1.1 reinoud
509 1.1 reinoud /*
510 1.1 reinoud * The driver 'clicks' between buffer swaps, leading me
511 1.1 reinoud * to think that the fifo is much small than on other
512 1.1 reinoud * sound cards so I'm going to have to do some tricks here
513 1.1 reinoud */
514 1.1 reinoud
515 1.18 bjh21 (*ag.intr)(ag.arg); /* Schedule the next buffer */
516 1.18 bjh21 ag.intr = vidcaudio_dummy_routine; /* Already done this */
517 1.1 reinoud ag.arg = NULL;
518 1.1 reinoud
519 1.1 reinoud #ifdef PRINT
520 1.1 reinoud printf("vidcaudio: start output\n");
521 1.1 reinoud #endif
522 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
523 1.1 reinoud printf("SE");
524 1.1 reinoud #endif
525 1.1 reinoud enable_irq(sound_dma_intr);
526 1.1 reinoud } else {
527 1.1 reinoud /* Otherwise schedule the next one */
528 1.1 reinoud if (ag.next_cur != 0) {
529 1.1 reinoud /* If there's one scheduled then complain */
530 1.1 reinoud printf("vidcaudio: Buffer already Q'ed\n");
531 1.1 reinoud return EIO;
532 1.1 reinoud } else {
533 1.1 reinoud /* We're OK to schedule it now */
534 1.1 reinoud ag.buffer = (++ag.buffer) & 1;
535 1.1 reinoud PHYS(cur, &ag.next_cur);
536 1.1 reinoud PHYS(end - 16, &ag.next_end);
537 1.1 reinoud ag.next_intr = intr;
538 1.1 reinoud ag.next_arg = arg;
539 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
540 1.1 reinoud printf("s");
541 1.1 reinoud #endif
542 1.1 reinoud }
543 1.1 reinoud }
544 1.1 reinoud return 0;
545 1.1 reinoud }
546 1.1 reinoud
547 1.1 reinoud void
548 1.1 reinoud vidcaudio_shutdown(void)
549 1.1 reinoud {
550 1.18 bjh21
551 1.1 reinoud /* Shut down the channel */
552 1.1 reinoud ag.intr = NULL;
553 1.1 reinoud ag.in_progress = 0;
554 1.1 reinoud #ifdef PRINT
555 1.1 reinoud printf("vidcaudio: stop output\n");
556 1.1 reinoud #endif
557 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, ag.silence);
558 1.18 bjh21 IOMD_WRITE_WORD(IOMD_SD0ENDB,
559 1.18 bjh21 (ag.silence + PAGE_SIZE - 16) | (1 << 30));
560 1.1 reinoud disable_irq(sound_dma_intr);
561 1.1 reinoud }
562 1.1 reinoud
563 1.1 reinoud int
564 1.17 bjh21 vidcaudio_intr(void *arg)
565 1.1 reinoud {
566 1.1 reinoud int status = IOMD_READ_BYTE(IOMD_SD0ST);
567 1.5 bjh21 void (*nintr)(void *);
568 1.1 reinoud void *narg;
569 1.5 bjh21 void (*xintr)(void *);
570 1.1 reinoud void *xarg;
571 1.1 reinoud int xcur, xend;
572 1.18 bjh21
573 1.1 reinoud IOMD_WRITE_WORD(IOMD_DMARQ, 0x10);
574 1.1 reinoud
575 1.1 reinoud #ifdef PRINT
576 1.1 reinoud printf ( "I" );
577 1.1 reinoud #endif
578 1.1 reinoud
579 1.1 reinoud if (ag.open == 0) {
580 1.1 reinoud vidcaudio_shutdown();
581 1.1 reinoud return 0;
582 1.1 reinoud }
583 1.1 reinoud
584 1.1 reinoud /* Have I got the generic audio device attached */
585 1.1 reinoud
586 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
587 1.1 reinoud printf ( "[B%01x]", status );
588 1.1 reinoud #endif
589 1.1 reinoud
590 1.1 reinoud nintr = ag.intr;
591 1.1 reinoud narg = ag.arg;
592 1.1 reinoud ag.intr = NULL;
593 1.1 reinoud
594 1.1 reinoud xintr = ag.next_intr;
595 1.1 reinoud xarg = ag.next_arg;
596 1.1 reinoud xcur = ag.next_cur;
597 1.1 reinoud xend = ag.next_end;
598 1.1 reinoud ag.next_cur = 0;
599 1.1 reinoud ag.intr = xintr;
600 1.1 reinoud ag.arg = xarg;
601 1.1 reinoud
602 1.1 reinoud if (nintr) {
603 1.22 bjh21 #ifdef VIDCAUDIO_DEBUG
604 1.1 reinoud printf("i");
605 1.1 reinoud #endif
606 1.1 reinoud (*nintr)(narg);
607 1.1 reinoud }
608 1.1 reinoud
609 1.1 reinoud if (xcur == 0) {
610 1.18 bjh21 vidcaudio_shutdown();
611 1.1 reinoud } else {
612 1.1 reinoud #define OVERRUN (0x04)
613 1.1 reinoud #define INTERRUPT (0x02)
614 1.1 reinoud #define BANK_A (0x00)
615 1.1 reinoud #define BANK_B (0x01)
616 1.1 reinoud switch (status & 0x7) {
617 1.1 reinoud case (INTERRUPT|BANK_A):
618 1.1 reinoud #ifdef PRINT
619 1.1 reinoud printf("B");
620 1.1 reinoud #endif
621 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, xcur);
622 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, xend|FLAGS);
623 1.1 reinoud break;
624 1.1 reinoud
625 1.1 reinoud case (INTERRUPT|BANK_B):
626 1.1 reinoud #ifdef PRINT
627 1.1 reinoud printf("A");
628 1.1 reinoud #endif
629 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, xcur);
630 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, xend|FLAGS);
631 1.1 reinoud break;
632 1.1 reinoud
633 1.1 reinoud case (OVERRUN|INTERRUPT|BANK_A):
634 1.1 reinoud #ifdef PRINT
635 1.1 reinoud printf("A");
636 1.1 reinoud #endif
637 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, xcur);
638 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, xend|FLAGS);
639 1.1 reinoud break;
640 1.1 reinoud
641 1.1 reinoud case (OVERRUN|INTERRUPT|BANK_B):
642 1.1 reinoud #ifdef PRINT
643 1.1 reinoud printf("B");
644 1.1 reinoud #endif
645 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, xcur);
646 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, xend|FLAGS);
647 1.1 reinoud break;
648 1.1 reinoud }
649 1.1 reinoud /*
650 1.1 reinoud ag.next_cur = 0;
651 1.1 reinoud ag.intr = xintr;
652 1.1 reinoud ag.arg = xarg;
653 1.1 reinoud */
654 1.1 reinoud }
655 1.1 reinoud #ifdef PRINT
656 1.1 reinoud printf ( "i" );
657 1.1 reinoud #endif
658 1.1 reinoud
659 1.1 reinoud if (ag.next_cur == 0) {
660 1.18 bjh21 (*ag.intr)(ag.arg); /* Schedule the next buffer */
661 1.18 bjh21 ag.intr = vidcaudio_dummy_routine; /* Already done this */
662 1.1 reinoud ag.arg = NULL;
663 1.1 reinoud }
664 1.18 bjh21 return 0 ; /* Pass interrupt on down the chain */
665 1.1 reinoud }
666