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