vs.c revision 1.3 1 /* $NetBSD: vs.c,v 1.3 2001/05/07 09:42:30 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 int vs_round_sr(u_long);
104 static void vs_set_sr(struct vs_softc *sc, int);
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 rate;
164 u_char clk;
165 u_char den;
166 } vs_l2r[] = {
167 { VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 },
168 { VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 },
169 { VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024},
170 { VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 },
171 { VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024}
172 };
173
174 #define NUM_RATE (sizeof(vs_l2r)/sizeof(vs_l2r[0]))
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.blksize;
262 if (sc->sc_current.dmap + sc->sc_current.blksize
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.blksize);
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.blksize;
273 if (sc->sc_current.dmap + sc->sc_current.blksize
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.blksize);
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, AudioEadpcm);
336 fp->encoding = AUDIO_ENCODING_ADPCM;
337 fp->precision = 4;
338 fp->flags = AUDIO_ENCODINGFLAG_EMULATE;
339 break;
340 case 2:
341 strcpy(fp->name, AudioEulinear);
342 fp->encoding = AUDIO_ENCODING_ULINEAR;
343 fp->precision = 8;
344 fp->flags = AUDIO_ENCODINGFLAG_EMULATE;
345 break;
346 default:
347 return EINVAL;
348 }
349 return 0;
350 }
351
352 static int
353 vs_round_sr(u_long rate)
354 {
355 int i;
356 int diff = rate;
357 int nearest = 0;
358
359 for (i = 0; i < NUM_RATE; i++) {
360 if (rate >= vs_l2r[i].rate) {
361 if (rate - vs_l2r[i].rate < diff) {
362 diff = rate - vs_l2r[i].rate;
363 nearest = i;
364 }
365 } else {
366 if (vs_l2r[i].rate - rate < diff) {
367 diff = vs_l2r[i].rate - rate;
368 nearest = i;
369 }
370 }
371 }
372 if (diff * 100 / rate > 15)
373 return -1;
374 else
375 return nearest;
376 }
377
378 static int
379 vs_set_params(void *hdl, int setmode, int usemode,
380 struct audio_params *play, struct audio_params *rec)
381 {
382 struct vs_softc *sc = hdl;
383 struct audio_params *p;
384 int mode;
385 int rate;
386
387 DPRINTF(("vs_set_params: setmode=%d, usemode=%d\n", setmode, usemode));
388
389 /* set first record info, then play info */
390 for (mode = AUMODE_RECORD; mode != -1;
391 mode = (mode == AUMODE_RECORD) ? AUMODE_PLAY : -1) {
392 if ((setmode & mode) == 0)
393 continue;
394
395 p = (mode == AUMODE_PLAY) ? play : rec;
396
397 if (p->channels != 1)
398 return (EINVAL);
399
400 rate = p->sample_rate;
401 p->sw_code = NULL;
402 p->factor = 1;
403 switch (p->encoding) {
404 case AUDIO_ENCODING_ULAW:
405 if (p->precision != 8)
406 return EINVAL;
407 if (mode == AUMODE_PLAY) {
408 p->sw_code = msm6258_mulaw_to_adpcm;
409 rate = p->sample_rate * 2;
410 } else {
411 p->sw_code = msm6258_adpcm_to_mulaw;
412 p->factor = 2;
413 }
414 break;
415 case AUDIO_ENCODING_ULINEAR_LE:
416 case AUDIO_ENCODING_ULINEAR_BE:
417 if (p->precision != 8)
418 return EINVAL;
419 if (mode == AUMODE_PLAY) {
420 p->sw_code = msm6258_ulinear8_to_adpcm;
421 rate = p->sample_rate * 2;
422 } else {
423 p->sw_code = msm6258_adpcm_to_ulinear8;
424 p->factor = 2;
425 }
426 break;
427 case AUDIO_ENCODING_ADPCM:
428 if (p->precision != 4)
429 return EINVAL;
430 break;
431 default:
432 DPRINTF(("vs_set_params: mode=%d, encoding=%d\n",
433 mode, p->encoding));
434 return (EINVAL);
435 }
436 rate = vs_round_sr(rate);
437 if (rate < 0)
438 return (EINVAL);
439 if (mode == AUMODE_PLAY)
440 sc->sc_current.prate = rate;
441 else
442 sc->sc_current.rrate = rate;
443 }
444
445 return 0;
446 }
447
448 static void
449 vs_set_sr(struct vs_softc *sc, int rate)
450 {
451 DPRINTF(("setting sample rate to %d, %d\n",
452 rate, (int)vs_l2r[rate].rate));
453 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
454 (bus_space_read_1 (sc->sc_iot, sc->sc_ppi,
455 PPI_PORTC) & 0xf0)
456 | vs_l2r[rate].den);
457 adpcm_chgclk(vs_l2r[rate].clk);
458 }
459
460 static inline void
461 vs_set_po(struct vs_softc *sc, u_long po)
462 {
463 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
464 (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
465 & 0xfc) | po);
466 }
467
468 static int
469 vs_trigger_output(void *hdl, void *start, void *end, int bsize,
470 void (*intr)(void *), void *arg,
471 struct audio_params *p)
472 {
473 struct vs_softc *sc = hdl;
474 struct vs_dma *vd;
475 struct dmac_dma_xfer *xf;
476 struct dmac_channel_stat *chan = sc->sc_dma_ch;
477
478 DPRINTF(("vs_trigger_output\n"));
479 DPRINTF(("trigger_output: start=%p, bsize=%d, intr=%p, arg=%p\n",
480 start, bsize, intr, arg));
481
482 sc->sc_pintr = intr;
483 sc->sc_parg = arg;
484 sc->sc_current.blksize = bsize;
485 sc->sc_current.bufsize = (char*)end - (char*)start;
486 sc->sc_current.dmap = 0;
487
488 /* Find DMA buffer. */
489 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
490 vd = vd->vd_next)
491 ;
492 if (vd == NULL) {
493 printf("%s: trigger_output: bad addr %p\n",
494 sc->sc_dev.dv_xname, start);
495 return (EINVAL);
496 }
497
498 vs_set_sr(sc, sc->sc_current.prate);
499 vs_set_po(sc, VS_PANOUT_LR);
500
501 xf = dmac_alloc_xfer (chan, sc->sc_dmat, vd->vd_map);
502 sc->sc_current.xfer = xf;
503 chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
504 DMAC_DCR_OPS_8BIT);
505 chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
506 xf->dx_ocr = DMAC_OCR_DIR_MTD;
507 xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
508 xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
509
510 dmac_load_xfer (chan->ch_softc, xf);
511 dmac_start_xfer_offset (chan->ch_softc, xf, 0, sc->sc_current.blksize);
512 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 2);
513
514 return 0;
515 }
516
517 static int
518 vs_trigger_input(void *hdl, void *start, void *end, int bsize,
519 void (*intr)(void *), void *arg,
520 struct audio_params *p)
521 {
522 struct vs_softc *sc = hdl;
523 struct vs_dma *vd;
524 struct dmac_dma_xfer *xf;
525 struct dmac_channel_stat *chan = sc->sc_dma_ch;
526
527 DPRINTF(("vs_trigger_input\n"));
528 DPRINTF(("trigger_input: start=%p, bsize=%d, intr=%p, arg=%p\n",
529 start, bsize, intr, arg));
530
531 sc->sc_rintr = intr;
532 sc->sc_rarg = arg;
533 sc->sc_current.blksize = bsize;
534 sc->sc_current.bufsize = (char*)end - (char*)start;
535 sc->sc_current.dmap = 0;
536
537 /* Find DMA buffer. */
538 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
539 vd = vd->vd_next)
540 ;
541 if (vd == NULL) {
542 printf("%s: trigger_output: bad addr %p\n",
543 sc->sc_dev.dv_xname, start);
544 return (EINVAL);
545 }
546
547 vs_set_sr(sc, sc->sc_current.rrate);
548 xf = dmac_alloc_xfer (chan, sc->sc_dmat, vd->vd_map);
549 sc->sc_current.xfer = xf;
550 chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
551 DMAC_DCR_OPS_8BIT);
552 chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
553 xf->dx_ocr = DMAC_OCR_DIR_DTM;
554 xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
555 xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
556
557 dmac_load_xfer (chan->ch_softc, xf);
558 dmac_start_xfer_offset (chan->ch_softc, xf, 0, sc->sc_current.blksize);
559 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 4);
560
561 return 0;
562 }
563
564 static int
565 vs_halt_output(void *hdl)
566 {
567 struct vs_softc *sc = hdl;
568
569 DPRINTF(("vs_halt_output\n"));
570
571 /* stop ADPCM play */
572 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
573 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
574
575 DPRINTF(("vs_halt_output: csr=%x,cer=%x\n", dmac->csr, dmac->cer));
576 return 0;
577 }
578
579 static int
580 vs_halt_input(void *hdl)
581 {
582 struct vs_softc *sc = hdl;
583
584 DPRINTF(("vs_halt_input\n"));
585
586 /* stop ADPCM recoding */
587 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
588 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
589
590 return 0;
591 }
592
593 static int
594 vs_allocmem(sc, size, align, boundary, flags, vd)
595 struct vs_softc *sc;
596 size_t size;
597 size_t align;
598 size_t boundary;
599 int flags;
600 struct vs_dma *vd;
601 {
602 int error, wait;
603
604 #ifdef DIAGNOSTIC
605 if (size > DMAC_MAXSEGSZ)
606 panic ("vs_allocmem: maximum size exceeded, %d", (int) size);
607 #endif
608
609 wait = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
610 vd->vd_size = size;
611
612 error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary,
613 vd->vd_segs,
614 sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]),
615 &vd->vd_nsegs, wait);
616 if (error)
617 goto out;
618
619 error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs,
620 vd->vd_size, &vd->vd_addr,
621 wait | BUS_DMA_COHERENT);
622 if (error)
623 goto free;
624
625 error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ,
626 0, wait, &vd->vd_map);
627 if (error)
628 goto unmap;
629
630 error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr,
631 vd->vd_size, NULL, wait);
632 if (error)
633 goto destroy;
634
635 return (0);
636
637 destroy:
638 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
639 unmap:
640 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
641 free:
642 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
643 out:
644 return (error);
645 }
646
647 static void
648 vs_freemem(vd)
649 struct vs_dma *vd;
650 {
651
652 bus_dmamap_unload(vd->vd_dmat, vd->vd_map);
653 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
654 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
655 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
656 }
657
658 static int
659 vs_getdev(void *hdl, struct audio_device *retp)
660 {
661 DPRINTF(("vs_getdev\n"));
662
663 *retp = vs_device;
664 return 0;
665 }
666
667 static int
668 vs_set_port(void *hdl, mixer_ctrl_t *cp)
669 {
670 DPRINTF(("vs_set_port\n"));
671 return 0;
672 }
673
674 static int
675 vs_get_port(void *hdl, mixer_ctrl_t *cp)
676 {
677 DPRINTF(("vs_get_port\n"));
678 return 0;
679 }
680
681 static int
682 vs_query_devinfo(void *hdl, mixer_devinfo_t *mi)
683 {
684 DPRINTF(("vs_query_devinfo\n"));
685 switch (mi->index) {
686 default:
687 return EINVAL;
688 }
689 return 0;
690 }
691
692 static void *
693 vs_allocm(hdl, direction, size, type, flags)
694 void *hdl;
695 int direction;
696 size_t size;
697 int type, flags;
698 {
699 struct vs_softc *sc = hdl;
700 struct vs_dma *vd;
701 int error;
702
703 if ((vd = malloc(size, type, flags)) == NULL)
704 return (NULL);
705
706 vd->vd_dmat = sc->sc_dmat;
707
708 error = vs_allocmem(sc, size, 32, 0, flags, vd);
709 if (error) {
710 free(vd, type);
711 return (NULL);
712 }
713 vd->vd_next = sc->sc_dmas;
714 sc->sc_dmas = vd;
715
716 return (KVADDR(vd));
717 }
718
719 static void
720 vs_freem(hdl, addr, type)
721 void *hdl;
722 void *addr;
723 int type;
724 {
725 struct vs_softc *sc = hdl;
726 struct vs_dma *p, **pp;
727
728 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) {
729 if (KVADDR(p) == addr) {
730 vs_freemem(p);
731 *pp = p->vd_next;
732 free(p, type);
733 return;
734 }
735 }
736 }
737
738 static size_t
739 vs_round_buffersize(void *hdl, int direction, size_t bufsize)
740 {
741 if (bufsize > DMAC_MAXSEGSZ)
742 bufsize = DMAC_MAXSEGSZ;
743
744 return bufsize;
745 }
746
747 #if 0
748 paddr_t
749 vs_mappage(addr, mem, off, prot)
750 void *addr;
751 void *mem;
752 off_t off;
753 int prot;
754 {
755 struct vs_softc *sc = addr;
756 struct vs_dma *p;
757
758 if (off < 0)
759 return (-1);
760 for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
761 p = p->vd_next)
762 ;
763 if (p == NULL) {
764 printf("%s: mappage: bad addr %p\n",
765 sc->sc_dev.dv_xname, start);
766 return (-1);
767 }
768
769 return (bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
770 off, prot, BUS_DMA_WAITOK));
771 }
772 #endif
773
774 static int
775 vs_get_props(void *hdl)
776 {
777 DPRINTF(("vs_get_props\n"));
778 return 0 /* | dependent | half duplex | no mmap */;
779 }
780 #endif /* NAUDIO > 0 && NVS > 0*/
781