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