vs.c revision 1.1 1 /* $NetBSD: vs.c,v 1.1 2001/05/02 13:00:20 minoura Exp $ */
2
3 /*
4 * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Tetsuya Isaki.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /*
34 * VS - OKI MSM6258 ADPCM voice synthesizer device driver.
35 */
36
37 #include "audio.h"
38 #include "vs.h"
39 #if NAUDIO > 0 && NVS > 0
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/device.h>
44
45 #include <sys/audioio.h>
46 #include <dev/audio_if.h>
47
48 #include <machine/bus.h>
49 #include <machine/cpu.h>
50
51 #include <dev/ic/msm6258var.h>
52
53 #include <arch/x68k/dev/dmacvar.h>
54 #include <arch/x68k/dev/intiovar.h>
55 #include <arch/x68k/dev/opmreg.h>
56
57 #include <arch/x68k/dev/vsvar.h>
58
59 #ifdef VS_DEBUG
60 #define DPRINTF(x) printf x
61 #ifdef AUDIO_DEBUG
62 extern int audiodebug;
63 #endif
64 #else
65 #define DPRINTF(x)
66 #endif
67
68 static int vs_match __P((struct device *, struct cfdata *, void *));
69 static void vs_attach __P((struct device *, struct device *, void *));
70
71 static int vs_dmaintr __P((void *));
72 static int vs_dmaerrintr __P((void *));
73
74 /* MI audio layer interface */
75 static int vs_open __P((void *, int));
76 static void vs_close __P((void *));
77 static int vs_query_encoding __P((void *, struct audio_encoding *));
78 static int vs_set_params __P((void *, int, int, struct audio_params *,
79 struct audio_params *));
80 static int vs_init_output __P((void *, void *, int));
81 static int vs_init_input __P((void *, void *, int));
82 static int vs_trigger_output __P((void *, void *, void *, int,
83 void (*)(void *), void *,
84 struct audio_params *));
85 static int vs_trigger_input __P((void *, void *, void *, int,
86 void (*)(void *), void *,
87 struct audio_params *));
88 static int vs_halt_output __P((void *));
89 static int vs_halt_input __P((void *));
90 static int vs_allocmem __P((struct vs_softc *, size_t, size_t, size_t, int,
91 struct vs_dma *));
92 static void vs_freemem __P((struct vs_dma *));
93 static int vs_getdev __P((void *, struct audio_device *));
94 static int vs_set_port __P((void *, mixer_ctrl_t *));
95 static int vs_get_port __P((void *, mixer_ctrl_t *));
96 static int vs_query_devinfo __P((void *, mixer_devinfo_t *));
97 static void *vs_allocm __P((void *, int, size_t, int, int));
98 static void vs_freem __P((void *, void *, int));
99 static size_t vs_round_buffersize __P((void *, int, size_t));
100 static int vs_get_props __P((void *));
101
102 /* lower functions */
103 static u_long vs_round_sr(u_long);
104 static void vs_set_sr(struct vs_softc *sc, u_long);
105 static inline void vs_set_po(struct vs_softc *sc, u_long);
106 static int adpcm_estimindex[];
107 static int adpcm_estim[];
108 static u_char adpcm_estimindex_correct[];
109 static inline u_char pcm2adpcm_step __P((short, short *, signed char *));
110 static void vs_ulinear8_to_adpcm __P((void *, u_char *, int));
111 static void vs_mulaw_to_adpcm __P((void *, u_char *, int));
112
113 extern struct cfdata vs_cd;
114
115 struct cfattach vs_ca = {
116 sizeof(struct vs_softc), vs_match, vs_attach
117 };
118
119 static struct audio_hw_if vs_hw_if = {
120 vs_open,
121 vs_close,
122 NULL, /* drain */
123
124 vs_query_encoding,
125 vs_set_params,
126 NULL, /* round_blocksize */
127 NULL, /* commit_settings */
128
129 NULL, /* init_output */
130 NULL, /* init_input */
131 NULL, /* start_output */
132 NULL, /* start_input */
133
134 vs_halt_output,
135 vs_halt_input,
136 NULL, /* speaker_ctl */
137
138 vs_getdev,
139 NULL, /* setfd */
140
141 vs_set_port,
142 vs_get_port,
143 vs_query_devinfo,
144
145 vs_allocm,
146 vs_freem,
147 vs_round_buffersize,
148 NULL, /* mappage */
149
150 vs_get_props,
151
152 vs_trigger_output,
153 vs_trigger_input,
154 };
155
156 static struct audio_device vs_device = {
157 "OKI MSM6258",
158 "",
159 "vs"
160 };
161
162 struct {
163 u_long low;
164 u_long rate;
165 u_char clk;
166 u_char den;
167 } vs_l2r[] = {
168 { 13021, VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 },
169 { 9115, VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 },
170 { 6510, VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024},
171 { 4557, VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 },
172 { 0, VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024}
173 };
174
175
176 static int
177 vs_match(struct device *parent, struct cfdata *cf, void *aux)
178 {
179 struct intio_attach_args *ia = aux;
180
181 if (strcmp(ia->ia_name, "vs") || cf->cf_unit > 0)
182 return 0;
183
184 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
185 ia->ia_addr = VS_ADDR;
186 if (ia->ia_dma == INTIOCF_DMA_DEFAULT)
187 ia->ia_dma = VS_DMA;
188 if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT)
189 ia->ia_dmaintr = VS_DMAINTR;
190
191 /* fixed parameters */
192 if (ia->ia_addr != VS_ADDR)
193 return 0;
194 if (ia->ia_dma != VS_DMA)
195 return 0;
196 if (ia->ia_dmaintr != VS_DMAINTR)
197 return 0;
198
199 #ifdef AUDIO_DEBUG
200 audiodebug = 2;
201 #endif
202
203 return 1;
204 }
205
206 static void
207 vs_attach(struct device *parent, struct device *self, void *aux)
208 {
209 struct vs_softc *sc = (struct vs_softc *)self;
210 bus_space_tag_t iot;
211 bus_space_handle_t ioh;
212 struct intio_attach_args *ia = aux;
213
214 printf("\n");
215
216 /* Re-map the I/O space */
217 iot = ia->ia_bst;
218 bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh);
219
220 /* Initialize sc */
221 sc->sc_iot = iot;
222 sc->sc_ioh = ioh;
223 sc->sc_hw_if = &vs_hw_if;
224 sc->sc_addr = (caddr_t) ia->ia_addr;
225 sc->sc_dmas = NULL;
226
227 /* Initialize codec */
228 sc->sc_codec = msm6258_codec_init();
229 if (sc->sc_codec == NULL) {
230 printf ("Could not init codec\n");
231 return;
232 }
233
234 /* XXX */
235 bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED,
236 &sc->sc_ppi);
237
238 /* Initialize DMAC */
239 sc->sc_dmat = ia->ia_dmat;
240 sc->sc_dma_ch = dmac_alloc_channel(parent, ia->ia_dma, "vs",
241 ia->ia_dmaintr, vs_dmaintr, sc,
242 ia->ia_dmaintr+1, vs_dmaerrintr, sc);
243
244 printf("%s: MSM6258V ADPCM voice synthesizer\n", sc->sc_dev.dv_xname);
245
246 audio_attach_mi(&vs_hw_if, sc, &sc->sc_dev);
247 }
248
249 /*
250 * vs interrupt handler
251 */
252 static int
253 vs_dmaintr(void *hdl)
254 {
255 struct vs_softc *sc = hdl;
256
257 DPRINTF(("vs_dmaintr\n"));
258
259 if (sc->sc_pintr) {
260 /* start next transfer */
261 sc->sc_current.dmap += sc->sc_current.rawblk;
262 if (sc->sc_current.dmap + sc->sc_current.rawblk
263 > sc->sc_current.bufsize)
264 sc->sc_current.dmap -= sc->sc_current.bufsize;
265 dmac_start_xfer_offset (sc->sc_dma_ch->ch_softc,
266 sc->sc_current.xfer,
267 sc->sc_current.dmap,
268 sc->sc_current.hwblk);
269 sc->sc_pintr(sc->sc_parg);
270 } else if (sc->sc_rintr) {
271 /* start next transfer */
272 sc->sc_current.dmap += sc->sc_current.rawblk;
273 if (sc->sc_current.dmap + sc->sc_current.rawblk
274 >= sc->sc_current.bufsize)
275 dmac_start_xfer_offset (sc->sc_dma_ch->ch_softc,
276 sc->sc_current.xfer,
277 sc->sc_current.dmap,
278 sc->sc_current.hwblk);
279 sc->sc_rintr(sc->sc_rarg);
280 } else {
281 printf ("vs_dmaintr: spurious interrupt\n");
282 }
283
284 return 1;
285 }
286
287 static int
288 vs_dmaerrintr(void *hdl)
289 {
290 struct vs_softc *sc = hdl;
291
292 DPRINTF(("%s: DMA transfer error.\n", sc->sc_dev.dv_xname));
293 /* XXX */
294 vs_dmaintr(hdl);
295
296 return 1;
297 }
298
299
300 /*
301 * audio MD layer interfaces
302 */
303
304 static int
305 vs_open(void *hdl, int flags)
306 {
307 struct vs_softc *sc = hdl;
308
309 DPRINTF(("%s: open: flags=%d\n", sc->sc_dev.dv_xname, flags));
310
311 sc->sc_pintr = NULL;
312 sc->sc_rintr = NULL;
313
314 return 0;
315 }
316
317 static void
318 vs_close(void *hdl)
319 {
320 DPRINTF(("vs_close\n"));
321 }
322
323 static int
324 vs_query_encoding(void *hdl, struct audio_encoding *fp)
325 {
326 DPRINTF(("vs_query_encoding\n"));
327 switch (fp->index) {
328 case 0:
329 strcpy(fp->name, AudioEmulaw);
330 fp->encoding = AUDIO_ENCODING_ULAW;
331 fp->precision = 8;
332 fp->flags = 0;
333 break;
334 case 1:
335 strcpy(fp->name, AudioEulinear);
336 fp->encoding = AUDIO_ENCODING_ULINEAR;
337 fp->precision = 8;
338 fp->flags = 0;
339 break;
340 case 2:
341 strcpy(fp->name, AudioEadpcm);
342 fp->encoding = AUDIO_ENCODING_ADPCM;
343 fp->precision = 4;
344 fp->flags = 0;
345 break;
346 default:
347 return EINVAL;
348 }
349 return 0;
350 }
351
352 static u_long
353 vs_round_sr(u_long rate)
354 {
355 int i;
356 for (i = 0; i < 5; i++) {
357 if (rate >= vs_l2r[i].low)
358 return vs_l2r[i].rate;
359 }
360 /*NOTREACHED*/
361 }
362
363 static int
364 vs_set_params(void *hdl, int setmode, int usemode,
365 struct audio_params *play, struct audio_params *rec)
366 {
367 struct vs_softc *sc = hdl;
368 struct audio_params *p;
369 int mode;
370
371 DPRINTF(("vs_set_params: setmode=%d, usemode=%d\n", setmode, usemode));
372
373 sc->sc_current.pdenom = 1;
374 /* set first record info, then play info */
375 for (mode = AUMODE_RECORD; mode != -1;
376 mode = (mode == AUMODE_RECORD) ? AUMODE_PLAY : -1) {
377 if ((setmode & mode) == 0)
378 continue;
379
380 p = (mode == AUMODE_PLAY) ? play : rec;
381
382 if (p->channels != 1)
383 return (EINVAL);
384
385 p->sample_rate = vs_round_sr(p->sample_rate);
386
387 p->sw_code = NULL;
388 p->factor = 1;
389 switch (p->encoding) {
390 case AUDIO_ENCODING_ULAW:
391 if (p->precision != 8)
392 return EINVAL;
393 if (mode == AUMODE_PLAY) {
394 p->sw_code = msm6258_mulaw_to_adpcm;
395 sc->sc_current.pdenom = 2;
396 } else {
397 p->sw_code = msm6258_adpcm_to_mulaw;
398 p->factor = 2;
399 }
400 break;
401 case AUDIO_ENCODING_ULINEAR_LE:
402 case AUDIO_ENCODING_ULINEAR_BE:
403 if (p->precision != 8)
404 return EINVAL;
405 if (mode == AUMODE_PLAY) {
406 p->sw_code = msm6258_ulinear8_to_adpcm;
407 sc->sc_current.pdenom = 2;
408 } else {
409 p->sw_code = msm6258_adpcm_to_ulinear8;
410 p->factor = 2;
411 }
412 break;
413 case AUDIO_ENCODING_ADPCM:
414 if (p->precision != 4)
415 return EINVAL;
416 p->sw_code = NULL;
417 break;
418 default:
419 DPRINTF(("vs_set_params: mode=%d, encoding=%d\n",
420 mode, p->encoding));
421 return (EINVAL);
422 }
423 }
424
425 return 0;
426 }
427
428 static void
429 vs_set_sr(struct vs_softc *sc, u_long rate)
430 {
431 int i;
432 for (i = 0; i < 5; i++) {
433 if (rate >= vs_l2r[i].low) {
434 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
435 (bus_space_read_1 (sc->sc_iot,
436 sc->sc_ppi,
437 PPI_PORTC) & 0xf0)
438 | vs_l2r[i].den);
439 adpcm_chgclk(vs_l2r[i].clk);
440 return;
441 }
442 }
443 /*NOTREACHED*/
444 }
445
446 static inline void
447 vs_set_po(struct vs_softc *sc, u_long po)
448 {
449 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
450 (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
451 & 0xfc) | po);
452 }
453
454 static int
455 vs_trigger_output(void *hdl, void *start, void *end, int bsize,
456 void (*intr)(void *), void *arg,
457 struct audio_params *p)
458 {
459 struct vs_softc *sc = hdl;
460 struct vs_dma *vd;
461 struct dmac_dma_xfer *xf;
462 struct dmac_channel_stat *chan = sc->sc_dma_ch;
463
464 DPRINTF(("vs_trigger_output\n"));
465 DPRINTF(("trigger_output: start=%p, bsize=%d, intr=%p, arg=%p\n",
466 start, bsize, intr, arg));
467
468 sc->sc_pintr = intr;
469 sc->sc_parg = arg;
470 sc->sc_current.rawblk = bsize;
471 sc->sc_current.hwblk = bsize / sc->sc_current.pdenom;;
472 sc->sc_current.bufsize = (char*)end - (char*)start;
473 sc->sc_current.dmap = 0;
474
475 /* Find DMA buffer. */
476 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
477 vd = vd->vd_next)
478 ;
479 if (vd == NULL) {
480 printf("%s: trigger_output: bad addr %p\n",
481 sc->sc_dev.dv_xname, start);
482 return (EINVAL);
483 }
484
485 vs_set_sr(sc, p->sample_rate);
486 vs_set_po(sc, VS_PANOUT_LR);
487 xf = dmac_alloc_xfer (chan, sc->sc_dmat, vd->vd_map);
488 sc->sc_current.xfer = xf;
489 chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
490 DMAC_DCR_OPS_8BIT);
491 chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
492 xf->dx_ocr = DMAC_OCR_DIR_MTD;
493 xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
494 xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
495 if (sc->sc_current.pdenom == 2)
496 chan->ch_ocr |= DMAC_OCR_SIZE_BYTE_NOPACK;
497 dmac_load_xfer (chan->ch_softc, xf);
498 dmac_start_xfer_offset (chan->ch_softc, xf, 0, sc->sc_current.hwblk);
499 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 2);
500
501 return 0;
502 }
503
504 static int
505 vs_trigger_input(void *hdl, void *start, void *end, int bsize,
506 void (*intr)(void *), void *arg,
507 struct audio_params *p)
508 {
509 struct vs_softc *sc = hdl;
510 struct vs_dma *vd;
511
512 DPRINTF(("vs_trigger_input\n"));
513 DPRINTF(("trigger_input: start=%p, bsize=%d, intr=%p, arg=%p\n",
514 start, bsize, intr, arg));
515
516 sc->sc_rintr = intr;
517 sc->sc_rarg = arg;
518 sc->sc_current.rawblk = bsize;
519 sc->sc_current.hwblk = bsize;
520 sc->sc_current.bufsize = (char*)end - (char*)start;
521 sc->sc_current.dmap = 0;
522
523 /* Find DMA buffer. */
524 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
525 vd = vd->vd_next)
526 ;
527 if (vd == NULL) {
528 printf("%s: trigger_output: bad addr %p\n",
529 sc->sc_dev.dv_xname, start);
530 return (EINVAL);
531 }
532
533 vs_set_sr(sc, p->sample_rate);
534 sc->sc_current.xfer
535 = dmac_prepare_xfer (sc->sc_dma_ch, sc->sc_dmat, vd->vd_map,
536 DMAC_OCR_DIR_DTM,
537 DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT,
538 sc->sc_addr + MSM6258_DATA*2);
539 dmac_start_xfer_offset (sc->sc_dma_ch->ch_softc, sc->sc_current.xfer,
540 0, sc->sc_current.hwblk);
541 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 4);
542
543 return 0;
544 }
545
546 static int
547 vs_halt_output(void *hdl)
548 {
549 struct vs_softc *sc = hdl;
550
551 DPRINTF(("vs_halt_output\n"));
552
553 /* stop ADPCM play */
554 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
555 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
556
557 DPRINTF(("vs_halt_output: csr=%x,cer=%x\n", dmac->csr, dmac->cer));
558 return 0;
559 }
560
561 static int
562 vs_halt_input(void *hdl)
563 {
564 struct vs_softc *sc = hdl;
565
566 DPRINTF(("vs_halt_input\n"));
567
568 /* stop ADPCM recoding */
569 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
570 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
571
572 return 0;
573 }
574
575 static int
576 vs_allocmem(sc, size, align, boundary, flags, vd)
577 struct vs_softc *sc;
578 size_t size;
579 size_t align;
580 size_t boundary;
581 int flags;
582 struct vs_dma *vd;
583 {
584 int error, wait;
585
586 #ifdef DIAGNOSTIC
587 if (size > DMAC_MAXSEGSZ)
588 panic ("vs_allocmem: maximum size exceeded, %d", (int) size);
589 #endif
590
591 wait = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
592 vd->vd_size = size;
593
594 error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary,
595 vd->vd_segs,
596 sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]),
597 &vd->vd_nsegs, wait);
598 if (error)
599 goto out;
600
601 error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs,
602 vd->vd_size, &vd->vd_addr,
603 wait | BUS_DMA_COHERENT);
604 if (error)
605 goto free;
606
607 error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ,
608 0, wait, &vd->vd_map);
609 if (error)
610 goto unmap;
611
612 error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr,
613 vd->vd_size, NULL, wait);
614 if (error)
615 goto destroy;
616
617 return (0);
618
619 destroy:
620 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
621 unmap:
622 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
623 free:
624 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
625 out:
626 return (error);
627 }
628
629 static void
630 vs_freemem(vd)
631 struct vs_dma *vd;
632 {
633
634 bus_dmamap_unload(vd->vd_dmat, vd->vd_map);
635 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
636 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
637 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
638 }
639
640 static int
641 vs_getdev(void *hdl, struct audio_device *retp)
642 {
643 DPRINTF(("vs_getdev\n"));
644
645 *retp = vs_device;
646 return 0;
647 }
648
649 static int
650 vs_set_port(void *hdl, mixer_ctrl_t *cp)
651 {
652 DPRINTF(("vs_set_port\n"));
653 return 0;
654 }
655
656 static int
657 vs_get_port(void *hdl, mixer_ctrl_t *cp)
658 {
659 DPRINTF(("vs_get_port\n"));
660 return 0;
661 }
662
663 static int
664 vs_query_devinfo(void *hdl, mixer_devinfo_t *mi)
665 {
666 DPRINTF(("vs_query_devinfo\n"));
667 switch (mi->index) {
668 default:
669 return EINVAL;
670 }
671 return 0;
672 }
673
674 static void *
675 vs_allocm(hdl, direction, size, type, flags)
676 void *hdl;
677 int direction;
678 size_t size;
679 int type, flags;
680 {
681 struct vs_softc *sc = hdl;
682 struct vs_dma *vd;
683 int error;
684
685 if ((vd = malloc(size, type, flags)) == NULL)
686 return (NULL);
687
688 vd->vd_dmat = sc->sc_dmat;
689
690 error = vs_allocmem(sc, size, 32, 0, flags, vd);
691 if (error) {
692 free(vd, type);
693 return (NULL);
694 }
695 vd->vd_next = sc->sc_dmas;
696 sc->sc_dmas = vd;
697
698 return (KVADDR(vd));
699 }
700
701 static void
702 vs_freem(hdl, addr, type)
703 void *hdl;
704 void *addr;
705 int type;
706 {
707 struct vs_softc *sc = hdl;
708 struct vs_dma *p, **pp;
709
710 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) {
711 if (KVADDR(p) == addr) {
712 vs_freemem(p);
713 *pp = p->vd_next;
714 free(p, type);
715 return;
716 }
717 }
718 }
719
720 static size_t
721 vs_round_buffersize(void *hdl, int direction, size_t bufsize)
722 {
723 if (bufsize > DMAC_MAXSEGSZ)
724 bufsize = DMAC_MAXSEGSZ;
725
726 return bufsize;
727 }
728
729 #if 0
730 paddr_t
731 vs_mappage(addr, mem, off, prot)
732 void *addr;
733 void *mem;
734 off_t off;
735 int prot;
736 {
737 struct vs_softc *sc = addr;
738 struct vs_dma *p;
739
740 if (off < 0)
741 return (-1);
742 for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
743 p = p->vd_next)
744 ;
745 if (p == NULL) {
746 printf("%s: mappage: bad addr %p\n",
747 sc->sc_dev.dv_xname, start);
748 return (-1);
749 }
750
751 return (bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
752 off, prot, BUS_DMA_WAITOK));
753 }
754 #endif
755
756 static int
757 vs_get_props(void *hdl)
758 {
759 DPRINTF(("vs_get_props\n"));
760 return 0 /* | dependent | half duplex | no mmap */;
761 }
762 #endif /* NAUDIO > 0 && NVS > 0*/
763