vidcaudio.c revision 1.17 1 1.17 bjh21 /* $NetBSD: vidcaudio.c,v 1.17 2003/12/29 16:11:38 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.17 bjh21 __KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.17 2003/12/29 16:11:38 bjh21 Exp $");
42 1.5 bjh21
43 1.1 reinoud #include <sys/conf.h> /* autoconfig functions */
44 1.1 reinoud #include <sys/device.h> /* device calls */
45 1.1 reinoud #include <sys/proc.h> /* device calls */
46 1.1 reinoud #include <sys/audioio.h>
47 1.1 reinoud #include <sys/errno.h>
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 #undef DEBUG
68 1.1 reinoud
69 1.1 reinoud struct audio_general {
70 1.8 thorpej vaddr_t silence;
71 1.1 reinoud irqhandler_t ih;
72 1.1 reinoud
73 1.5 bjh21 void (*intr) (void *);
74 1.1 reinoud void *arg;
75 1.1 reinoud
76 1.8 thorpej paddr_t next_cur;
77 1.8 thorpej paddr_t next_end;
78 1.5 bjh21 void (*next_intr) (void *);
79 1.1 reinoud void *next_arg;
80 1.1 reinoud
81 1.1 reinoud int buffer;
82 1.1 reinoud int in_progress;
83 1.1 reinoud
84 1.1 reinoud int open;
85 1.1 reinoud } ag;
86 1.1 reinoud
87 1.1 reinoud struct vidcaudio_softc {
88 1.1 reinoud struct device device;
89 1.1 reinoud
90 1.1 reinoud int open;
91 1.1 reinoud };
92 1.1 reinoud
93 1.17 bjh21 int vidcaudio_probe(struct device *parent, struct cfdata *cf, void *aux);
94 1.17 bjh21 void vidcaudio_attach(struct device *parent, struct device *self, void *aux);
95 1.17 bjh21 int vidcaudio_open(void *addr, int flags);
96 1.17 bjh21 void vidcaudio_close(void *addr);
97 1.17 bjh21
98 1.17 bjh21 int vidcaudio_intr(void *arg);
99 1.17 bjh21 int vidcaudio_dma_program(vaddr_t cur, vaddr_t end, void (*intr)(void *), void *arg);
100 1.17 bjh21 void vidcaudio_dummy_routine(void *arg);
101 1.17 bjh21 int vidcaudio_stereo(int channel, int position);
102 1.17 bjh21 int vidcaudio_rate(int rate);
103 1.17 bjh21 void vidcaudio_shutdown(void);
104 1.1 reinoud
105 1.1 reinoud static int sound_dma_intr;
106 1.1 reinoud
107 1.12 thorpej CFATTACH_DECL(vidcaudio, sizeof(struct vidcaudio_softc),
108 1.13 thorpej vidcaudio_probe, vidcaudio_attach, NULL, NULL);
109 1.1 reinoud
110 1.17 bjh21 int vidcaudio_query_encoding(void *, struct audio_encoding *);
111 1.17 bjh21 int vidcaudio_set_params(void *, int, int, struct audio_params *, struct audio_params *);
112 1.17 bjh21 int vidcaudio_round_blocksize(void *, int);
113 1.17 bjh21 int vidcaudio_start_output(void *, void *, int, void (*)(void *), void *);
114 1.17 bjh21 int vidcaudio_start_input(void *, void *, int, void (*)(void *), void *);
115 1.17 bjh21 int vidcaudio_halt_output(void *);
116 1.17 bjh21 int vidcaudio_halt_input(void *);
117 1.17 bjh21 int vidcaudio_speaker_ctl(void *, int);
118 1.17 bjh21 int vidcaudio_getdev(void *, struct audio_device *);
119 1.17 bjh21 int vidcaudio_set_port(void *, mixer_ctrl_t *);
120 1.17 bjh21 int vidcaudio_get_port(void *, mixer_ctrl_t *);
121 1.17 bjh21 int vidcaudio_query_devinfo(void *, mixer_devinfo_t *);
122 1.17 bjh21 int vidcaudio_get_props(void *);
123 1.1 reinoud
124 1.1 reinoud struct audio_device vidcaudio_device = {
125 1.1 reinoud "VidcAudio 8-bit",
126 1.1 reinoud "x",
127 1.1 reinoud "vidcaudio"
128 1.1 reinoud };
129 1.1 reinoud
130 1.1 reinoud struct audio_hw_if vidcaudio_hw_if = {
131 1.1 reinoud vidcaudio_open,
132 1.1 reinoud vidcaudio_close,
133 1.1 reinoud 0,
134 1.1 reinoud vidcaudio_query_encoding,
135 1.1 reinoud vidcaudio_set_params,
136 1.1 reinoud vidcaudio_round_blocksize,
137 1.1 reinoud 0,
138 1.1 reinoud 0,
139 1.1 reinoud 0,
140 1.1 reinoud vidcaudio_start_output,
141 1.1 reinoud vidcaudio_start_input,
142 1.1 reinoud vidcaudio_halt_output,
143 1.1 reinoud vidcaudio_halt_input,
144 1.1 reinoud vidcaudio_speaker_ctl,
145 1.1 reinoud vidcaudio_getdev,
146 1.1 reinoud 0,
147 1.1 reinoud vidcaudio_set_port,
148 1.1 reinoud vidcaudio_get_port,
149 1.1 reinoud vidcaudio_query_devinfo,
150 1.1 reinoud 0,
151 1.1 reinoud 0,
152 1.1 reinoud 0,
153 1.1 reinoud 0,
154 1.1 reinoud vidcaudio_get_props,
155 1.1 reinoud 0,
156 1.1 reinoud 0,
157 1.1 reinoud 0,
158 1.1 reinoud };
159 1.1 reinoud
160 1.1 reinoud
161 1.1 reinoud void
162 1.17 bjh21 vidcaudio_beep_generate(void)
163 1.1 reinoud {
164 1.1 reinoud vidcaudio_dma_program(ag.silence, ag.silence+sizeof(beep_waveform)-16,
165 1.1 reinoud vidcaudio_dummy_routine, NULL);
166 1.1 reinoud }
167 1.1 reinoud
168 1.1 reinoud
169 1.1 reinoud int
170 1.17 bjh21 vidcaudio_probe(struct device *parent, struct cfdata *cf, void *aux)
171 1.1 reinoud {
172 1.1 reinoud int id;
173 1.1 reinoud
174 1.1 reinoud id = IOMD_ID;
175 1.1 reinoud
176 1.1 reinoud /* So far I only know about this IOMD */
177 1.1 reinoud switch (id) {
178 1.1 reinoud case RPC600_IOMD_ID:
179 1.1 reinoud return(1);
180 1.1 reinoud break;
181 1.1 reinoud case ARM7500_IOC_ID:
182 1.1 reinoud case ARM7500FE_IOC_ID:
183 1.1 reinoud return(1);
184 1.1 reinoud break;
185 1.1 reinoud default:
186 1.1 reinoud printf("vidcaudio: Unknown IOMD id=%04x", id);
187 1.1 reinoud break;
188 1.1 reinoud }
189 1.1 reinoud
190 1.1 reinoud return (0);
191 1.1 reinoud }
192 1.1 reinoud
193 1.1 reinoud
194 1.1 reinoud void
195 1.17 bjh21 vidcaudio_attach(struct device *parent, struct device *self, void *aux)
196 1.1 reinoud {
197 1.1 reinoud struct vidcaudio_softc *sc = (void *)self;
198 1.1 reinoud int id;
199 1.1 reinoud
200 1.1 reinoud sc->open = 0;
201 1.1 reinoud ag.in_progress = 0;
202 1.1 reinoud
203 1.1 reinoud ag.next_cur = 0;
204 1.1 reinoud ag.next_end = 0;
205 1.1 reinoud ag.next_intr = NULL;
206 1.1 reinoud ag.next_arg = NULL;
207 1.1 reinoud
208 1.1 reinoud vidcaudio_rate(32); /* 24*1024*/
209 1.1 reinoud
210 1.1 reinoud /* Program the silence buffer and reset the DMA channel */
211 1.14 thorpej ag.silence = uvm_km_alloc(kernel_map, PAGE_SIZE);
212 1.15 jdolecek if (ag.silence == 0)
213 1.10 provos panic("vidcaudio: Cannot allocate memory");
214 1.1 reinoud
215 1.14 thorpej memset((char *)ag.silence, 0, PAGE_SIZE);
216 1.1 reinoud memcpy((char *)ag.silence, (char *)beep_waveform, sizeof(beep_waveform));
217 1.1 reinoud
218 1.1 reinoud ag.buffer = 0;
219 1.1 reinoud
220 1.1 reinoud /* Install the irq handler for the DMA interrupt */
221 1.1 reinoud ag.ih.ih_func = vidcaudio_intr;
222 1.1 reinoud ag.ih.ih_arg = NULL;
223 1.1 reinoud ag.ih.ih_level = IPL_AUDIO;
224 1.1 reinoud ag.ih.ih_name = "vidcaudio";
225 1.1 reinoud
226 1.1 reinoud ag.intr = NULL;
227 1.1 reinoud /* ag.nextintr = NULL;*/
228 1.1 reinoud
229 1.1 reinoud id = IOMD_ID;
230 1.1 reinoud
231 1.1 reinoud switch (id) {
232 1.1 reinoud case RPC600_IOMD_ID:
233 1.1 reinoud sound_dma_intr = IRQ_DMASCH0;
234 1.1 reinoud break;
235 1.1 reinoud case ARM7500_IOC_ID:
236 1.1 reinoud case ARM7500FE_IOC_ID:
237 1.1 reinoud sound_dma_intr = IRQ_SDMA;
238 1.1 reinoud break;
239 1.1 reinoud }
240 1.1 reinoud
241 1.1 reinoud disable_irq(sound_dma_intr);
242 1.1 reinoud
243 1.1 reinoud if (irq_claim(sound_dma_intr, &(ag.ih)))
244 1.10 provos panic("vidcaudio: couldn't claim IRQ %d", sound_dma_intr);
245 1.1 reinoud
246 1.1 reinoud disable_irq(sound_dma_intr);
247 1.1 reinoud
248 1.1 reinoud printf("\n");
249 1.1 reinoud
250 1.14 thorpej vidcaudio_dma_program(ag.silence, ag.silence+PAGE_SIZE-16,
251 1.1 reinoud vidcaudio_dummy_routine, NULL);
252 1.1 reinoud
253 1.1 reinoud audio_attach_mi(&vidcaudio_hw_if, sc, &sc->device);
254 1.1 reinoud
255 1.1 reinoud #ifdef DEBUG
256 1.1 reinoud printf(" UNDER DEVELOPMENT (nuts)\n");
257 1.1 reinoud #endif
258 1.1 reinoud }
259 1.1 reinoud
260 1.1 reinoud int
261 1.17 bjh21 vidcaudio_open(void *addr, int flags)
262 1.1 reinoud {
263 1.1 reinoud struct vidcaudio_softc *sc = addr;
264 1.1 reinoud
265 1.1 reinoud #ifdef DEBUG
266 1.1 reinoud printf("DEBUG: vidcaudio_open called\n");
267 1.1 reinoud #endif
268 1.1 reinoud
269 1.1 reinoud if (sc->open)
270 1.1 reinoud return EBUSY;
271 1.1 reinoud
272 1.1 reinoud sc->open = 1;
273 1.1 reinoud ag.open = 1;
274 1.1 reinoud
275 1.1 reinoud return 0;
276 1.1 reinoud }
277 1.1 reinoud
278 1.1 reinoud void
279 1.17 bjh21 vidcaudio_close(void *addr)
280 1.1 reinoud {
281 1.1 reinoud struct vidcaudio_softc *sc = addr;
282 1.1 reinoud
283 1.1 reinoud vidcaudio_shutdown();
284 1.1 reinoud
285 1.1 reinoud #ifdef DEBUG
286 1.1 reinoud printf("DEBUG: vidcaudio_close called\n");
287 1.1 reinoud #endif
288 1.1 reinoud
289 1.1 reinoud sc->open = 0;
290 1.1 reinoud ag.open = 0;
291 1.1 reinoud }
292 1.1 reinoud
293 1.1 reinoud /* ************************************************************************* *
294 1.1 reinoud | Interface to the generic audio driver |
295 1.1 reinoud * ************************************************************************* */
296 1.1 reinoud
297 1.1 reinoud int
298 1.17 bjh21 vidcaudio_query_encoding(void *addr, struct audio_encoding *fp)
299 1.1 reinoud {
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.1 reinoud 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.16 bjh21 if (p->encoding != AUDIO_ENCODING_ULAW)
319 1.1 reinoud return EINVAL;
320 1.16 bjh21 /* FIXME Handle number of channels properly. */
321 1.1 reinoud vidcaudio_rate(4 * p->sample_rate / (3 * 1024)); /* XXX probably wrong */
322 1.1 reinoud
323 1.1 reinoud return 0;
324 1.1 reinoud }
325 1.1 reinoud
326 1.1 reinoud int
327 1.17 bjh21 vidcaudio_round_blocksize(void *addr, int blk)
328 1.1 reinoud {
329 1.14 thorpej if (blk > PAGE_SIZE)
330 1.14 thorpej blk = PAGE_SIZE;
331 1.1 reinoud return (blk);
332 1.1 reinoud }
333 1.1 reinoud
334 1.14 thorpej #define ROUND(s) ( ((int)s) & (~(PAGE_SIZE-1)) )
335 1.1 reinoud
336 1.1 reinoud int
337 1.17 bjh21 vidcaudio_start_output(void *addr, void *p, int cc, void (*intr)(void *),
338 1.17 bjh21 void *arg)
339 1.1 reinoud {
340 1.1 reinoud /* I can only DMA inside 1 page */
341 1.1 reinoud
342 1.1 reinoud #ifdef DEBUG
343 1.1 reinoud printf("vidcaudio_start_output (%d) %08x %08x\n", cc, intr, arg);
344 1.1 reinoud #endif
345 1.1 reinoud
346 1.1 reinoud if (ROUND(p) != ROUND(p+cc)) {
347 1.1 reinoud /*
348 1.1 reinoud * If it's over a page I can fix it up by copying it into
349 1.1 reinoud * my buffer
350 1.1 reinoud */
351 1.1 reinoud
352 1.1 reinoud #ifdef DEBUG
353 1.1 reinoud printf("vidcaudio: DMA over page boundary requested."
354 1.1 reinoud " Fixing up\n");
355 1.1 reinoud #endif
356 1.14 thorpej memcpy(p, (char *)ag.silence, cc > PAGE_SIZE ? PAGE_SIZE : cc);
357 1.1 reinoud p = (void *)ag.silence;
358 1.1 reinoud
359 1.1 reinoud /*
360 1.1 reinoud * I can't DMA any more than that, but it is possible to
361 1.1 reinoud * fix it up by handling multiple buffers and only
362 1.1 reinoud * interrupting the audio driver after sending out all the
363 1.1 reinoud * stuff it gave me. That it more than I can be bothered
364 1.1 reinoud * to do right now and it probablly wont happen so I'll just
365 1.1 reinoud * truncate the buffer and tell the user.
366 1.1 reinoud */
367 1.1 reinoud
368 1.14 thorpej if (cc > PAGE_SIZE) {
369 1.1 reinoud printf("vidcaudio: DMA buffer truncated. I could fix this up\n");
370 1.14 thorpej cc = PAGE_SIZE;
371 1.1 reinoud }
372 1.1 reinoud }
373 1.8 thorpej vidcaudio_dma_program((vaddr_t)p, (vaddr_t)((char *)p+cc),
374 1.1 reinoud intr, arg);
375 1.1 reinoud return 0;
376 1.1 reinoud }
377 1.1 reinoud
378 1.1 reinoud int
379 1.17 bjh21 vidcaudio_start_input(void *addr, void *p, int cc, void (*intr)(void *),
380 1.17 bjh21 void *arg)
381 1.1 reinoud {
382 1.1 reinoud return EIO;
383 1.1 reinoud }
384 1.1 reinoud
385 1.1 reinoud int
386 1.17 bjh21 vidcaudio_halt_output(void *addr)
387 1.1 reinoud {
388 1.1 reinoud #ifdef DEBUG
389 1.1 reinoud printf("DEBUG: vidcaudio_halt_output\n");
390 1.1 reinoud #endif
391 1.1 reinoud return EIO;
392 1.1 reinoud }
393 1.1 reinoud
394 1.1 reinoud int
395 1.17 bjh21 vidcaudio_halt_input(void *addr)
396 1.1 reinoud {
397 1.1 reinoud #ifdef DEBUG
398 1.1 reinoud printf("DEBUG: vidcaudio_halt_input\n");
399 1.1 reinoud #endif
400 1.1 reinoud return EIO;
401 1.1 reinoud }
402 1.1 reinoud
403 1.1 reinoud int
404 1.17 bjh21 vidcaudio_speaker_ctl(void *addr, int newstate)
405 1.1 reinoud {
406 1.1 reinoud #ifdef DEBUG
407 1.1 reinoud printf("DEBUG: vidcaudio_speaker_ctl\n");
408 1.1 reinoud #endif
409 1.1 reinoud return 0;
410 1.1 reinoud }
411 1.1 reinoud
412 1.1 reinoud int
413 1.17 bjh21 vidcaudio_getdev(void *addr, struct audio_device *retp)
414 1.1 reinoud {
415 1.1 reinoud *retp = vidcaudio_device;
416 1.1 reinoud return 0;
417 1.1 reinoud }
418 1.1 reinoud
419 1.1 reinoud
420 1.1 reinoud int
421 1.17 bjh21 vidcaudio_set_port(void *addr, mixer_ctrl_t *cp)
422 1.1 reinoud {
423 1.1 reinoud return EINVAL;
424 1.1 reinoud }
425 1.1 reinoud
426 1.1 reinoud int
427 1.17 bjh21 vidcaudio_get_port(void *addr, mixer_ctrl_t *cp)
428 1.1 reinoud {
429 1.1 reinoud return EINVAL;
430 1.1 reinoud }
431 1.1 reinoud
432 1.1 reinoud int
433 1.17 bjh21 vidcaudio_query_devinfo(void *addr, mixer_devinfo_t *dip)
434 1.1 reinoud {
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.1 reinoud return 0;
442 1.1 reinoud }
443 1.1 reinoud void
444 1.17 bjh21 vidcaudio_dummy_routine(void *arg)
445 1.1 reinoud {
446 1.1 reinoud #ifdef DEBUG
447 1.1 reinoud printf("vidcaudio_dummy_routine\n");
448 1.1 reinoud #endif
449 1.1 reinoud }
450 1.1 reinoud
451 1.1 reinoud int
452 1.17 bjh21 vidcaudio_rate(int rate)
453 1.1 reinoud {
454 1.1 reinoud WriteWord(vidc_base, VIDC_SFR | rate);
455 1.1 reinoud return 0;
456 1.1 reinoud }
457 1.1 reinoud
458 1.1 reinoud int
459 1.17 bjh21 vidcaudio_stereo(int channel, int position)
460 1.1 reinoud {
461 1.1 reinoud if (channel < 0) return EINVAL;
462 1.1 reinoud if (channel > 7) return EINVAL;
463 1.1 reinoud channel = channel<<24 | VIDC_SIR0;
464 1.1 reinoud WriteWord(vidc_base, channel | position);
465 1.1 reinoud return 0;
466 1.1 reinoud }
467 1.1 reinoud
468 1.7 thorpej #define PHYS(x, y) pmap_extract(pmap_kernel(), ((x)&L2_S_FRAME), (paddr_t *)(y))
469 1.1 reinoud
470 1.1 reinoud /*
471 1.1 reinoud * Program the next buffer to be used
472 1.1 reinoud * This function must be re-entrant, maximum re-entrancy of 2
473 1.1 reinoud */
474 1.1 reinoud
475 1.1 reinoud #define FLAGS (0)
476 1.1 reinoud
477 1.1 reinoud int
478 1.17 bjh21 vidcaudio_dma_program(vaddr_t cur, vaddr_t end, void (*intr)(void *),
479 1.17 bjh21 void *arg)
480 1.1 reinoud {
481 1.1 reinoud paddr_t pa1, pa2;
482 1.1 reinoud
483 1.1 reinoud /* If there isn't a transfer in progress then start a new one */
484 1.1 reinoud if (ag.in_progress == 0) {
485 1.1 reinoud ag.buffer = 0;
486 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CR, 0x90); /* Reset State Machine */
487 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CR, 0x30); /* Reset State Machine */
488 1.1 reinoud
489 1.1 reinoud PHYS(cur, &pa1);
490 1.1 reinoud PHYS(end - 16, &pa2);
491 1.1 reinoud
492 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, pa1);
493 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, pa2|FLAGS);
494 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, pa1);
495 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, pa2|FLAGS);
496 1.1 reinoud
497 1.1 reinoud ag.in_progress = 1;
498 1.1 reinoud
499 1.1 reinoud ag.next_cur = ag.next_end = 0;
500 1.1 reinoud ag.next_intr = ag.next_arg = 0;
501 1.1 reinoud
502 1.1 reinoud ag.intr = intr;
503 1.1 reinoud ag.arg = arg;
504 1.1 reinoud
505 1.1 reinoud /*
506 1.1 reinoud * The driver 'clicks' between buffer swaps, leading me
507 1.1 reinoud * to think that the fifo is much small than on other
508 1.1 reinoud * sound cards so I'm going to have to do some tricks here
509 1.1 reinoud */
510 1.1 reinoud
511 1.1 reinoud (*ag.intr)(ag.arg); /* Schedule the next buffer */
512 1.1 reinoud ag.intr = vidcaudio_dummy_routine; /* Already done this */
513 1.1 reinoud ag.arg = NULL;
514 1.1 reinoud
515 1.1 reinoud #ifdef PRINT
516 1.1 reinoud printf("vidcaudio: start output\n");
517 1.1 reinoud #endif
518 1.1 reinoud #ifdef DEBUG
519 1.1 reinoud printf("SE");
520 1.1 reinoud #endif
521 1.1 reinoud enable_irq(sound_dma_intr);
522 1.1 reinoud } else {
523 1.1 reinoud /* Otherwise schedule the next one */
524 1.1 reinoud if (ag.next_cur != 0) {
525 1.1 reinoud /* If there's one scheduled then complain */
526 1.1 reinoud printf("vidcaudio: Buffer already Q'ed\n");
527 1.1 reinoud return EIO;
528 1.1 reinoud } else {
529 1.1 reinoud /* We're OK to schedule it now */
530 1.1 reinoud ag.buffer = (++ag.buffer) & 1;
531 1.1 reinoud PHYS(cur, &ag.next_cur);
532 1.1 reinoud PHYS(end - 16, &ag.next_end);
533 1.1 reinoud ag.next_intr = intr;
534 1.1 reinoud ag.next_arg = arg;
535 1.1 reinoud #ifdef DEBUG
536 1.1 reinoud printf("s");
537 1.1 reinoud #endif
538 1.1 reinoud }
539 1.1 reinoud }
540 1.1 reinoud return 0;
541 1.1 reinoud }
542 1.1 reinoud
543 1.1 reinoud void
544 1.1 reinoud vidcaudio_shutdown(void)
545 1.1 reinoud {
546 1.1 reinoud /* Shut down the channel */
547 1.1 reinoud ag.intr = NULL;
548 1.1 reinoud ag.in_progress = 0;
549 1.1 reinoud #ifdef PRINT
550 1.1 reinoud printf("vidcaudio: stop output\n");
551 1.1 reinoud #endif
552 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, ag.silence);
553 1.14 thorpej IOMD_WRITE_WORD(IOMD_SD0ENDB, (ag.silence + PAGE_SIZE - 16) | (1<<30));
554 1.1 reinoud disable_irq(sound_dma_intr);
555 1.1 reinoud }
556 1.1 reinoud
557 1.1 reinoud int
558 1.17 bjh21 vidcaudio_intr(void *arg)
559 1.1 reinoud {
560 1.1 reinoud int status = IOMD_READ_BYTE(IOMD_SD0ST);
561 1.5 bjh21 void (*nintr)(void *);
562 1.1 reinoud void *narg;
563 1.5 bjh21 void (*xintr)(void *);
564 1.1 reinoud void *xarg;
565 1.1 reinoud int xcur, xend;
566 1.1 reinoud IOMD_WRITE_WORD(IOMD_DMARQ, 0x10);
567 1.1 reinoud
568 1.1 reinoud #ifdef PRINT
569 1.1 reinoud printf ( "I" );
570 1.1 reinoud #endif
571 1.1 reinoud
572 1.1 reinoud if (ag.open == 0) {
573 1.1 reinoud vidcaudio_shutdown();
574 1.1 reinoud return 0;
575 1.1 reinoud }
576 1.1 reinoud
577 1.1 reinoud /* Have I got the generic audio device attached */
578 1.1 reinoud
579 1.1 reinoud #ifdef DEBUG
580 1.1 reinoud printf ( "[B%01x]", status );
581 1.1 reinoud #endif
582 1.1 reinoud
583 1.1 reinoud nintr = ag.intr;
584 1.1 reinoud narg = ag.arg;
585 1.1 reinoud ag.intr = NULL;
586 1.1 reinoud
587 1.1 reinoud xintr = ag.next_intr;
588 1.1 reinoud xarg = ag.next_arg;
589 1.1 reinoud xcur = ag.next_cur;
590 1.1 reinoud xend = ag.next_end;
591 1.1 reinoud ag.next_cur = 0;
592 1.1 reinoud ag.intr = xintr;
593 1.1 reinoud ag.arg = xarg;
594 1.1 reinoud
595 1.1 reinoud if (nintr) {
596 1.1 reinoud #ifdef DEBUG
597 1.1 reinoud printf("i");
598 1.1 reinoud #endif
599 1.1 reinoud (*nintr)(narg);
600 1.1 reinoud }
601 1.1 reinoud
602 1.1 reinoud if (xcur == 0) {
603 1.1 reinoud vidcaudio_shutdown ();
604 1.1 reinoud } else {
605 1.1 reinoud #define OVERRUN (0x04)
606 1.1 reinoud #define INTERRUPT (0x02)
607 1.1 reinoud #define BANK_A (0x00)
608 1.1 reinoud #define BANK_B (0x01)
609 1.1 reinoud switch (status & 0x7) {
610 1.1 reinoud case (INTERRUPT|BANK_A):
611 1.1 reinoud #ifdef PRINT
612 1.1 reinoud printf("B");
613 1.1 reinoud #endif
614 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, xcur);
615 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, xend|FLAGS);
616 1.1 reinoud break;
617 1.1 reinoud
618 1.1 reinoud case (INTERRUPT|BANK_B):
619 1.1 reinoud #ifdef PRINT
620 1.1 reinoud printf("A");
621 1.1 reinoud #endif
622 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, xcur);
623 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, xend|FLAGS);
624 1.1 reinoud break;
625 1.1 reinoud
626 1.1 reinoud case (OVERRUN|INTERRUPT|BANK_A):
627 1.1 reinoud #ifdef PRINT
628 1.1 reinoud printf("A");
629 1.1 reinoud #endif
630 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURA, xcur);
631 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDA, xend|FLAGS);
632 1.1 reinoud break;
633 1.1 reinoud
634 1.1 reinoud case (OVERRUN|INTERRUPT|BANK_B):
635 1.1 reinoud #ifdef PRINT
636 1.1 reinoud printf("B");
637 1.1 reinoud #endif
638 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0CURB, xcur);
639 1.1 reinoud IOMD_WRITE_WORD(IOMD_SD0ENDB, xend|FLAGS);
640 1.1 reinoud break;
641 1.1 reinoud }
642 1.1 reinoud /*
643 1.1 reinoud ag.next_cur = 0;
644 1.1 reinoud ag.intr = xintr;
645 1.1 reinoud ag.arg = xarg;
646 1.1 reinoud */
647 1.1 reinoud }
648 1.1 reinoud #ifdef PRINT
649 1.1 reinoud printf ( "i" );
650 1.1 reinoud #endif
651 1.1 reinoud
652 1.1 reinoud if (ag.next_cur == 0) {
653 1.1 reinoud (*ag.intr)(ag.arg); /* Schedule the next buffer */
654 1.1 reinoud ag.intr = vidcaudio_dummy_routine; /* Already done this */
655 1.1 reinoud ag.arg = NULL;
656 1.1 reinoud }
657 1.1 reinoud return(0); /* Pass interrupt on down the chain */
658 1.1 reinoud }
659