vs.c revision 1.8 1 /* $NetBSD: vs.c,v 1.8 2001/10/03 00:04:49 augustss 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_trigger_output __P((void *, void *, void *, int,
81 void (*)(void *), void *,
82 struct audio_params *));
83 static int vs_trigger_input __P((void *, void *, void *, int,
84 void (*)(void *), void *,
85 struct audio_params *));
86 static int vs_halt_output __P((void *));
87 static int vs_halt_input __P((void *));
88 static int vs_allocmem __P((struct vs_softc *, size_t, size_t, size_t, int,
89 struct vs_dma *));
90 static void vs_freemem __P((struct vs_dma *));
91 static int vs_getdev __P((void *, struct audio_device *));
92 static int vs_set_port __P((void *, mixer_ctrl_t *));
93 static int vs_get_port __P((void *, mixer_ctrl_t *));
94 static int vs_query_devinfo __P((void *, mixer_devinfo_t *));
95 static void *vs_allocm __P((void *, int, size_t, int, int));
96 static void vs_freem __P((void *, void *, int));
97 static size_t vs_round_buffersize __P((void *, int, size_t));
98 static int vs_get_props __P((void *));
99
100 /* lower functions */
101 static int vs_round_sr(u_long);
102 static void vs_set_sr(struct vs_softc *sc, int);
103 static inline void vs_set_po(struct vs_softc *sc, u_long);
104
105 extern struct cfdata vs_cd;
106
107 struct cfattach vs_ca = {
108 sizeof(struct vs_softc), vs_match, vs_attach
109 };
110
111 static struct audio_hw_if vs_hw_if = {
112 vs_open,
113 vs_close,
114 NULL, /* drain */
115
116 vs_query_encoding,
117 vs_set_params,
118 NULL, /* round_blocksize */
119 NULL, /* commit_settings */
120
121 NULL, /* init_output */
122 NULL, /* init_input */
123 NULL, /* start_output */
124 NULL, /* start_input */
125
126 vs_halt_output,
127 vs_halt_input,
128 NULL, /* speaker_ctl */
129
130 vs_getdev,
131 NULL, /* setfd */
132
133 vs_set_port,
134 vs_get_port,
135 vs_query_devinfo,
136
137 vs_allocm,
138 vs_freem,
139 vs_round_buffersize,
140 NULL, /* mappage */
141
142 vs_get_props,
143
144 vs_trigger_output,
145 vs_trigger_input,
146
147 NULL,
148 };
149
150 static struct audio_device vs_device = {
151 "OKI MSM6258",
152 "",
153 "vs"
154 };
155
156 struct {
157 u_long rate;
158 u_char clk;
159 u_char den;
160 } vs_l2r[] = {
161 { VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 },
162 { VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 },
163 { VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024},
164 { VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 },
165 { VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024}
166 };
167
168 #define NUM_RATE (sizeof(vs_l2r)/sizeof(vs_l2r[0]))
169
170 static int
171 vs_match(struct device *parent, struct cfdata *cf, void *aux)
172 {
173 struct intio_attach_args *ia = aux;
174
175 if (strcmp(ia->ia_name, "vs") || cf->cf_unit > 0)
176 return 0;
177
178 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
179 ia->ia_addr = VS_ADDR;
180 if (ia->ia_dma == INTIOCF_DMA_DEFAULT)
181 ia->ia_dma = VS_DMA;
182 if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT)
183 ia->ia_dmaintr = VS_DMAINTR;
184
185 /* fixed parameters */
186 if (ia->ia_addr != VS_ADDR)
187 return 0;
188 if (ia->ia_dma != VS_DMA)
189 return 0;
190 if (ia->ia_dmaintr != VS_DMAINTR)
191 return 0;
192
193 #ifdef AUDIO_DEBUG
194 audiodebug = 2;
195 #endif
196
197 return 1;
198 }
199
200 static void
201 vs_attach(struct device *parent, struct device *self, void *aux)
202 {
203 struct vs_softc *sc = (struct vs_softc *)self;
204 bus_space_tag_t iot;
205 bus_space_handle_t ioh;
206 struct intio_attach_args *ia = aux;
207
208 printf("\n");
209
210 /* Re-map the I/O space */
211 iot = ia->ia_bst;
212 bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh);
213
214 /* Initialize sc */
215 sc->sc_iot = iot;
216 sc->sc_ioh = ioh;
217 sc->sc_hw_if = &vs_hw_if;
218 sc->sc_addr = (caddr_t) ia->ia_addr;
219 sc->sc_dmas = NULL;
220
221 /* Initialize codec */
222 sc->sc_codec = msm6258_codec_init();
223 if (sc->sc_codec == NULL) {
224 printf ("Could not init codec\n");
225 return;
226 }
227
228 /* XXX */
229 bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED,
230 &sc->sc_ppi);
231
232 /* Initialize DMAC */
233 sc->sc_dmat = ia->ia_dmat;
234 sc->sc_dma_ch = dmac_alloc_channel(parent, ia->ia_dma, "vs",
235 ia->ia_dmaintr, vs_dmaintr, sc,
236 ia->ia_dmaintr+1, vs_dmaerrintr, sc);
237
238 printf("%s: MSM6258V ADPCM voice synthesizer\n", sc->sc_dev.dv_xname);
239
240 audio_attach_mi(&vs_hw_if, sc, &sc->sc_dev);
241 }
242
243 /*
244 * vs interrupt handler
245 */
246 static int
247 vs_dmaintr(void *hdl)
248 {
249 struct vs_softc *sc = hdl;
250
251 DPRINTF(("vs_dmaintr\n"));
252
253 if (sc->sc_pintr) {
254 /* start next transfer */
255 sc->sc_current.dmap += sc->sc_current.blksize;
256 if (sc->sc_current.dmap + sc->sc_current.blksize
257 > sc->sc_current.bufsize)
258 sc->sc_current.dmap -= sc->sc_current.bufsize;
259 dmac_start_xfer_offset (sc->sc_dma_ch->ch_softc,
260 sc->sc_current.xfer,
261 sc->sc_current.dmap,
262 sc->sc_current.blksize);
263 sc->sc_pintr(sc->sc_parg);
264 } else if (sc->sc_rintr) {
265 /* start next transfer */
266 sc->sc_current.dmap += sc->sc_current.blksize;
267 if (sc->sc_current.dmap + sc->sc_current.blksize
268 > sc->sc_current.bufsize)
269 sc->sc_current.dmap -= sc->sc_current.bufsize;
270 dmac_start_xfer_offset (sc->sc_dma_ch->ch_softc,
271 sc->sc_current.xfer,
272 sc->sc_current.dmap,
273 sc->sc_current.blksize);
274 sc->sc_rintr(sc->sc_rarg);
275 } else {
276 printf ("vs_dmaintr: spurious interrupt\n");
277 }
278
279 return 1;
280 }
281
282 static int
283 vs_dmaerrintr(void *hdl)
284 {
285 struct vs_softc *sc = hdl;
286
287 DPRINTF(("%s: DMA transfer error.\n", sc->sc_dev.dv_xname));
288 /* XXX */
289 vs_dmaintr(hdl);
290
291 return 1;
292 }
293
294
295 /*
296 * audio MD layer interfaces
297 */
298
299 static int
300 vs_open(void *hdl, int flags)
301 {
302 struct vs_softc *sc = hdl;
303
304 DPRINTF(("%s: open: flags=%d\n", sc->sc_dev.dv_xname, flags));
305
306 sc->sc_pintr = NULL;
307 sc->sc_rintr = NULL;
308
309 return 0;
310 }
311
312 static void
313 vs_close(void *hdl)
314 {
315 DPRINTF(("vs_close\n"));
316 }
317
318 static int
319 vs_query_encoding(void *hdl, struct audio_encoding *fp)
320 {
321 DPRINTF(("vs_query_encoding\n"));
322 switch (fp->index) {
323 case 0:
324 strcpy(fp->name, AudioEadpcm);
325 fp->encoding = AUDIO_ENCODING_ADPCM;
326 fp->precision = 4;
327 fp->flags = 0;
328 break;
329 case 1:
330 strcpy(fp->name, AudioEulinear);
331 fp->encoding = AUDIO_ENCODING_ULINEAR;
332 fp->precision = 8;
333 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
334 break;
335 case 2:
336 strcpy(fp->name, AudioEmulaw);
337 fp->encoding = AUDIO_ENCODING_ULAW;
338 fp->precision = 8;
339 fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
340 break;
341 default:
342 return EINVAL;
343 }
344 return 0;
345 }
346
347 static int
348 vs_round_sr(u_long rate)
349 {
350 int i;
351 int diff = rate;
352 int nearest = 0;
353
354 for (i = 0; i < NUM_RATE; i++) {
355 if (rate >= vs_l2r[i].rate) {
356 if (rate - vs_l2r[i].rate < diff) {
357 diff = rate - vs_l2r[i].rate;
358 nearest = i;
359 }
360 } else {
361 if (vs_l2r[i].rate - rate < diff) {
362 diff = vs_l2r[i].rate - rate;
363 nearest = i;
364 }
365 }
366 }
367 if (diff * 100 / rate > 15)
368 return -1;
369 else
370 return nearest;
371 }
372
373 static int
374 vs_set_params(void *hdl, int setmode, int usemode,
375 struct audio_params *play, struct audio_params *rec)
376 {
377 struct vs_softc *sc = hdl;
378 struct audio_params *p;
379 int mode;
380 int rate;
381
382 DPRINTF(("vs_set_params: setmode=%d, usemode=%d\n", setmode, usemode));
383
384 /* set first record info, then play info */
385 for (mode = AUMODE_RECORD; mode != -1;
386 mode = (mode == AUMODE_RECORD) ? AUMODE_PLAY : -1) {
387 if ((setmode & mode) == 0)
388 continue;
389
390 p = (mode == AUMODE_PLAY) ? play : rec;
391
392 if (p->channels != 1)
393 return (EINVAL);
394
395 rate = p->sample_rate;
396 p->sw_code = NULL;
397 p->factor = 1;
398 switch (p->encoding) {
399 case AUDIO_ENCODING_ULAW:
400 if (p->precision != 8)
401 return EINVAL;
402 if (mode == AUMODE_PLAY) {
403 p->sw_code = msm6258_mulaw_to_adpcm;
404 rate = p->sample_rate * 2;
405 } else {
406 p->sw_code = msm6258_adpcm_to_mulaw;
407 p->factor = 2;
408 }
409 break;
410 case AUDIO_ENCODING_ULINEAR_LE:
411 case AUDIO_ENCODING_ULINEAR_BE:
412 if (p->precision != 8)
413 return EINVAL;
414 if (mode == AUMODE_PLAY) {
415 p->sw_code = msm6258_ulinear8_to_adpcm;
416 rate = p->sample_rate * 2;
417 } else {
418 p->sw_code = msm6258_adpcm_to_ulinear8;
419 p->factor = 2;
420 }
421 break;
422 case AUDIO_ENCODING_ADPCM:
423 if (p->precision != 4)
424 return EINVAL;
425 break;
426 default:
427 DPRINTF(("vs_set_params: mode=%d, encoding=%d\n",
428 mode, p->encoding));
429 return (EINVAL);
430 }
431 rate = vs_round_sr(rate);
432 if (rate < 0)
433 return (EINVAL);
434 if (mode == AUMODE_PLAY)
435 sc->sc_current.prate = rate;
436 else
437 sc->sc_current.rrate = rate;
438 }
439
440 return 0;
441 }
442
443 static void
444 vs_set_sr(struct vs_softc *sc, int rate)
445 {
446 DPRINTF(("setting sample rate to %d, %d\n",
447 rate, (int)vs_l2r[rate].rate));
448 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
449 (bus_space_read_1 (sc->sc_iot, sc->sc_ppi,
450 PPI_PORTC) & 0xf0)
451 | vs_l2r[rate].den);
452 adpcm_chgclk(vs_l2r[rate].clk);
453 }
454
455 static inline void
456 vs_set_po(struct vs_softc *sc, u_long po)
457 {
458 bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
459 (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
460 & 0xfc) | po);
461 }
462
463 static int
464 vs_trigger_output(void *hdl, void *start, void *end, int bsize,
465 void (*intr)(void *), void *arg,
466 struct audio_params *p)
467 {
468 struct vs_softc *sc = hdl;
469 struct vs_dma *vd;
470 struct dmac_dma_xfer *xf;
471 struct dmac_channel_stat *chan = sc->sc_dma_ch;
472
473 DPRINTF(("vs_trigger_output\n"));
474 DPRINTF(("trigger_output: start=%p, bsize=%d, intr=%p, arg=%p\n",
475 start, bsize, intr, arg));
476
477 sc->sc_pintr = intr;
478 sc->sc_parg = arg;
479 sc->sc_current.blksize = bsize;
480 sc->sc_current.bufsize = (char*)end - (char*)start;
481 sc->sc_current.dmap = 0;
482
483 /* Find DMA buffer. */
484 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
485 vd = vd->vd_next)
486 ;
487 if (vd == NULL) {
488 printf("%s: trigger_output: bad addr %p\n",
489 sc->sc_dev.dv_xname, start);
490 return (EINVAL);
491 }
492
493 vs_set_sr(sc, sc->sc_current.prate);
494 vs_set_po(sc, VS_PANOUT_LR);
495
496 xf = dmac_alloc_xfer (chan, sc->sc_dmat, vd->vd_map);
497 sc->sc_current.xfer = xf;
498 chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
499 DMAC_DCR_OPS_8BIT);
500 chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
501 xf->dx_ocr = DMAC_OCR_DIR_MTD;
502 xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
503 xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
504
505 dmac_load_xfer (chan->ch_softc, xf);
506 dmac_start_xfer_offset (chan->ch_softc, xf, 0, sc->sc_current.blksize);
507 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 2);
508
509 return 0;
510 }
511
512 static int
513 vs_trigger_input(void *hdl, void *start, void *end, int bsize,
514 void (*intr)(void *), void *arg,
515 struct audio_params *p)
516 {
517 struct vs_softc *sc = hdl;
518 struct vs_dma *vd;
519 struct dmac_dma_xfer *xf;
520 struct dmac_channel_stat *chan = sc->sc_dma_ch;
521
522 DPRINTF(("vs_trigger_input\n"));
523 DPRINTF(("trigger_input: start=%p, bsize=%d, intr=%p, arg=%p\n",
524 start, bsize, intr, arg));
525
526 sc->sc_rintr = intr;
527 sc->sc_rarg = arg;
528 sc->sc_current.blksize = bsize;
529 sc->sc_current.bufsize = (char*)end - (char*)start;
530 sc->sc_current.dmap = 0;
531
532 /* Find DMA buffer. */
533 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
534 vd = vd->vd_next)
535 ;
536 if (vd == NULL) {
537 printf("%s: trigger_output: bad addr %p\n",
538 sc->sc_dev.dv_xname, start);
539 return (EINVAL);
540 }
541
542 vs_set_sr(sc, sc->sc_current.rrate);
543 xf = dmac_alloc_xfer (chan, sc->sc_dmat, vd->vd_map);
544 sc->sc_current.xfer = xf;
545 chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
546 DMAC_DCR_OPS_8BIT);
547 chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
548 xf->dx_ocr = DMAC_OCR_DIR_DTM;
549 xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
550 xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
551
552 dmac_load_xfer (chan->ch_softc, xf);
553 dmac_start_xfer_offset (chan->ch_softc, xf, 0, sc->sc_current.blksize);
554 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 4);
555
556 return 0;
557 }
558
559 static int
560 vs_halt_output(void *hdl)
561 {
562 struct vs_softc *sc = hdl;
563
564 DPRINTF(("vs_halt_output\n"));
565
566 /* stop ADPCM play */
567 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
568 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
569
570 return 0;
571 }
572
573 static int
574 vs_halt_input(void *hdl)
575 {
576 struct vs_softc *sc = hdl;
577
578 DPRINTF(("vs_halt_input\n"));
579
580 /* stop ADPCM recoding */
581 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
582 bus_space_write_1 (sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
583
584 return 0;
585 }
586
587 static int
588 vs_allocmem(sc, size, align, boundary, flags, vd)
589 struct vs_softc *sc;
590 size_t size;
591 size_t align;
592 size_t boundary;
593 int flags;
594 struct vs_dma *vd;
595 {
596 int error, wait;
597
598 #ifdef DIAGNOSTIC
599 if (size > DMAC_MAXSEGSZ)
600 panic ("vs_allocmem: maximum size exceeded, %d", (int) size);
601 #endif
602
603 wait = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
604 vd->vd_size = size;
605
606 error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary,
607 vd->vd_segs,
608 sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]),
609 &vd->vd_nsegs, wait);
610 if (error)
611 goto out;
612
613 error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs,
614 vd->vd_size, &vd->vd_addr,
615 wait | BUS_DMA_COHERENT);
616 if (error)
617 goto free;
618
619 error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ,
620 0, wait, &vd->vd_map);
621 if (error)
622 goto unmap;
623
624 error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr,
625 vd->vd_size, NULL, wait);
626 if (error)
627 goto destroy;
628
629 return (0);
630
631 destroy:
632 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
633 unmap:
634 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
635 free:
636 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
637 out:
638 return (error);
639 }
640
641 static void
642 vs_freemem(vd)
643 struct vs_dma *vd;
644 {
645
646 bus_dmamap_unload(vd->vd_dmat, vd->vd_map);
647 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
648 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
649 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
650 }
651
652 static int
653 vs_getdev(void *hdl, struct audio_device *retp)
654 {
655 DPRINTF(("vs_getdev\n"));
656
657 *retp = vs_device;
658 return 0;
659 }
660
661 static int
662 vs_set_port(void *hdl, mixer_ctrl_t *cp)
663 {
664 DPRINTF(("vs_set_port\n"));
665 return 0;
666 }
667
668 static int
669 vs_get_port(void *hdl, mixer_ctrl_t *cp)
670 {
671 DPRINTF(("vs_get_port\n"));
672 return 0;
673 }
674
675 static int
676 vs_query_devinfo(void *hdl, mixer_devinfo_t *mi)
677 {
678 DPRINTF(("vs_query_devinfo\n"));
679 switch (mi->index) {
680 default:
681 return EINVAL;
682 }
683 return 0;
684 }
685
686 static void *
687 vs_allocm(hdl, direction, size, type, flags)
688 void *hdl;
689 int direction;
690 size_t size;
691 int type, flags;
692 {
693 struct vs_softc *sc = hdl;
694 struct vs_dma *vd;
695 int error;
696
697 if ((vd = malloc(size, type, flags)) == NULL)
698 return (NULL);
699
700 vd->vd_dmat = sc->sc_dmat;
701
702 error = vs_allocmem(sc, size, 32, 0, flags, vd);
703 if (error) {
704 free(vd, type);
705 return (NULL);
706 }
707 vd->vd_next = sc->sc_dmas;
708 sc->sc_dmas = vd;
709
710 return (KVADDR(vd));
711 }
712
713 static void
714 vs_freem(hdl, addr, type)
715 void *hdl;
716 void *addr;
717 int type;
718 {
719 struct vs_softc *sc = hdl;
720 struct vs_dma *p, **pp;
721
722 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) {
723 if (KVADDR(p) == addr) {
724 vs_freemem(p);
725 *pp = p->vd_next;
726 free(p, type);
727 return;
728 }
729 }
730 }
731
732 static size_t
733 vs_round_buffersize(void *hdl, int direction, size_t bufsize)
734 {
735 if (bufsize > DMAC_MAXSEGSZ)
736 bufsize = DMAC_MAXSEGSZ;
737
738 return bufsize;
739 }
740
741 #if 0
742 paddr_t
743 vs_mappage(addr, mem, off, prot)
744 void *addr;
745 void *mem;
746 off_t off;
747 int prot;
748 {
749 struct vs_softc *sc = addr;
750 struct vs_dma *p;
751
752 if (off < 0)
753 return (-1);
754 for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
755 p = p->vd_next)
756 ;
757 if (p == NULL) {
758 printf("%s: mappage: bad addr %p\n",
759 sc->sc_dev.dv_xname, start);
760 return (-1);
761 }
762
763 return (bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
764 off, prot, BUS_DMA_WAITOK));
765 }
766 #endif
767
768 static int
769 vs_get_props(void *hdl)
770 {
771 DPRINTF(("vs_get_props\n"));
772 return 0 /* | dependent | half duplex | no mmap */;
773 }
774 #endif /* NAUDIO > 0 && NVS > 0*/
775