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