vs.c revision 1.42 1 /* $NetBSD: vs.c,v 1.42 2017/08/05 05:22:55 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.42 2017/08/05 05:22:55 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 #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(device_t, cfdata_t, void *);
70 static void vs_attach(device_t, device_t, void *);
71
72 static int vs_dmaintr(void *);
73 static int vs_dmaerrintr(void *);
74
75 /* MI audio layer interface */
76 static int vs_open(void *, int);
77 static void vs_close(void *);
78 static int vs_query_encoding(void *, struct audio_encoding *);
79 static int vs_set_params(void *, int, int, audio_params_t *,
80 audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
81 static int vs_trigger_output(void *, void *, void *, int,
82 void (*)(void *), void *, const audio_params_t *);
83 static int vs_trigger_input(void *, void *, void *, int,
84 void (*)(void *), void *, const audio_params_t *);
85 static int vs_halt_output(void *);
86 static int vs_halt_input(void *);
87 static int vs_allocmem(struct vs_softc *, size_t, size_t, size_t,
88 struct vs_dma *);
89 static void vs_freemem(struct vs_dma *);
90 static int vs_getdev(void *, struct audio_device *);
91 static int vs_set_port(void *, mixer_ctrl_t *);
92 static int vs_get_port(void *, mixer_ctrl_t *);
93 static int vs_query_devinfo(void *, mixer_devinfo_t *);
94 static void *vs_allocm(void *, int, size_t);
95 static void vs_freem(void *, void *, size_t);
96 static size_t vs_round_buffersize(void *, int, size_t);
97 static int vs_get_props(void *);
98 static void vs_get_locks(void *, kmutex_t **, kmutex_t **);
99
100 /* lower functions */
101 static int vs_round_sr(u_long);
102 static void vs_set_sr(struct vs_softc *, int);
103 static inline void vs_set_po(struct vs_softc *, u_long);
104
105 extern struct cfdriver vs_cd;
106
107 CFATTACH_DECL_NEW(vs, sizeof(struct vs_softc),
108 vs_match, vs_attach, NULL, NULL);
109
110 static int vs_attached;
111
112 static const struct audio_hw_if vs_hw_if = {
113 vs_open,
114 vs_close,
115 NULL, /* drain */
116 vs_query_encoding,
117 vs_set_params,
118 NULL, /* round_blocksize */
119 NULL, /* commit_settings */
120 NULL, /* init_output */
121 NULL, /* init_input */
122 NULL, /* start_output */
123 NULL, /* start_input */
124 vs_halt_output,
125 vs_halt_input,
126 NULL, /* speaker_ctl */
127 vs_getdev,
128 NULL, /* setfd */
129 vs_set_port,
130 vs_get_port,
131 vs_query_devinfo,
132 vs_allocm,
133 vs_freem,
134 vs_round_buffersize,
135 NULL, /* mappage */
136 vs_get_props,
137 vs_trigger_output,
138 vs_trigger_input,
139 NULL,
140 vs_get_locks,
141 };
142
143 static struct audio_device vs_device = {
144 "OKI MSM6258",
145 "",
146 "vs"
147 };
148
149 struct {
150 u_long rate;
151 u_char clk;
152 u_char den;
153 } vs_l2r[] = {
154 { VS_RATE_15K, VS_CLK_8MHZ, VS_SRATE_512 },
155 { VS_RATE_10K, VS_CLK_8MHZ, VS_SRATE_768 },
156 { VS_RATE_7K, VS_CLK_8MHZ, VS_SRATE_1024},
157 { VS_RATE_5K, VS_CLK_4MHZ, VS_SRATE_768 },
158 { VS_RATE_3K, VS_CLK_4MHZ, VS_SRATE_1024}
159 };
160
161 #define NUM_RATE (sizeof(vs_l2r)/sizeof(vs_l2r[0]))
162
163 extern stream_filter_factory_t null_filter;
164
165 static int
166 vs_match(device_t parent, cfdata_t cf, void *aux)
167 {
168 struct intio_attach_args *ia;
169
170 ia = aux;
171 if (strcmp(ia->ia_name, "vs") || vs_attached)
172 return 0;
173
174 if (ia->ia_addr == INTIOCF_ADDR_DEFAULT)
175 ia->ia_addr = VS_ADDR;
176 if (ia->ia_dma == INTIOCF_DMA_DEFAULT)
177 ia->ia_dma = VS_DMA;
178 if (ia->ia_dmaintr == INTIOCF_DMAINTR_DEFAULT)
179 ia->ia_dmaintr = VS_DMAINTR;
180
181 /* fixed parameters */
182 if (ia->ia_addr != VS_ADDR)
183 return 0;
184 if (ia->ia_dma != VS_DMA)
185 return 0;
186 if (ia->ia_dmaintr != VS_DMAINTR)
187 return 0;
188
189 #ifdef VS_DEBUG
190 vs_debug = 1;
191 #ifdef AUDIO_DEBUG
192 audiodebug = 2;
193 #endif
194 #endif
195
196 return 1;
197 }
198
199 static void
200 vs_attach(device_t parent, device_t self, void *aux)
201 {
202 struct vs_softc *sc;
203 bus_space_tag_t iot;
204 bus_space_handle_t ioh;
205 struct intio_attach_args *ia;
206
207 sc = device_private(self);
208 sc->sc_dev = self;
209 ia = aux;
210 vs_attached = 1;
211
212 printf("\n");
213
214 /* Re-map the I/O space */
215 iot = ia->ia_bst;
216 bus_space_map(iot, ia->ia_addr, 0x2000, BUS_SPACE_MAP_SHIFTED, &ioh);
217
218 /* Initialize sc */
219 sc->sc_iot = iot;
220 sc->sc_ioh = ioh;
221 sc->sc_hw_if = &vs_hw_if;
222 sc->sc_addr = (void *) ia->ia_addr;
223 sc->sc_dmas = NULL;
224 sc->sc_active = 0;
225 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
226 mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
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 aprint_normal_dev(self, "MSM6258V ADPCM voice synthesizer\n");
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;
250
251 DPRINTF(2, ("vs_dmaintr\n"));
252 sc = hdl;
253
254 mutex_spin_enter(&sc->sc_intr_lock);
255
256 if (sc->sc_pintr) {
257 /* start next transfer */
258 sc->sc_current.dmap += sc->sc_current.blksize;
259 if (sc->sc_current.dmap + sc->sc_current.blksize
260 > sc->sc_current.bufsize)
261 sc->sc_current.dmap -= sc->sc_current.bufsize;
262 dmac_start_xfer_offset(sc->sc_dma_ch->ch_softc,
263 sc->sc_current.xfer,
264 sc->sc_current.dmap,
265 sc->sc_current.blksize);
266 sc->sc_pintr(sc->sc_parg);
267 } else if (sc->sc_rintr) {
268 /* start next transfer */
269 sc->sc_current.dmap += sc->sc_current.blksize;
270 if (sc->sc_current.dmap + sc->sc_current.blksize
271 > sc->sc_current.bufsize)
272 sc->sc_current.dmap -= sc->sc_current.bufsize;
273 dmac_start_xfer_offset(sc->sc_dma_ch->ch_softc,
274 sc->sc_current.xfer,
275 sc->sc_current.dmap,
276 sc->sc_current.blksize);
277 sc->sc_rintr(sc->sc_rarg);
278 } else {
279 printf("vs_dmaintr: spurious interrupt\n");
280 }
281
282 mutex_spin_exit(&sc->sc_intr_lock);
283
284 return 1;
285 }
286
287 static int
288 vs_dmaerrintr(void *hdl)
289 {
290 struct vs_softc *sc;
291
292 sc = hdl;
293 DPRINTF(1, ("%s: DMA transfer error.\n", device_xname(sc->sc_dev)));
294 /* XXX */
295 vs_dmaintr(sc);
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;
309
310 DPRINTF(1, ("vs_open: flags=%d\n", flags));
311 sc = hdl;
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
322 DPRINTF(1, ("vs_close\n"));
323 }
324
325 static int
326 vs_query_encoding(void *hdl, struct audio_encoding *fp)
327 {
328
329 DPRINTF(1, ("vs_query_encoding\n"));
330
331 if (fp->index == 0) {
332 strcpy(fp->name, AudioEslinear);
333 fp->encoding = AUDIO_ENCODING_SLINEAR;
334 fp->precision = 8;
335 fp->flags = 0;
336 return 0;
337 }
338 if (fp->index == 1) {
339 strcpy(fp->name, AudioEslinear_be);
340 fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
341 fp->precision = 16;
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 stream_filter_factory_t *pconv;
383 stream_filter_factory_t *rconv;
384 int rate;
385
386 sc = hdl;
387
388 DPRINTF(1, ("vs_set_params: mode=%d enc=%d rate=%d prec=%d ch=%d: ",
389 setmode, play->encoding, play->sample_rate,
390 play->precision, play->channels));
391
392 /* *play and *rec are identical because !AUDIO_PROP_INDEPENDENT */
393
394 if (play->channels != 1) {
395 DPRINTF(1, ("channels not matched\n"));
396 return EINVAL;
397 }
398
399 rate = vs_round_sr(play->sample_rate);
400 if (rate < 0) {
401 DPRINTF(1, ("rate not matched\n"));
402 return EINVAL;
403 }
404
405 if (play->precision == 8 && play->encoding == AUDIO_ENCODING_SLINEAR) {
406 pconv = msm6258_linear8_to_adpcm;
407 rconv = msm6258_adpcm_to_linear8;
408 } else if (play->precision == 16 &&
409 play->encoding == AUDIO_ENCODING_SLINEAR_BE) {
410 pconv = msm6258_slinear16_to_adpcm;
411 rconv = msm6258_adpcm_to_slinear16;
412 } else {
413 DPRINTF(1, ("prec/enc not matched\n"));
414 return EINVAL;
415 }
416
417 sc->sc_current.prate = rate;
418 sc->sc_current.rrate = rate;
419
420 /* pfil and rfil are independent even if !AUDIO_PROP_INDEPENDENT */
421
422 if ((setmode & AUMODE_PLAY) != 0) {
423 pfil->append(pfil, null_filter, play);
424 play->encoding = AUDIO_ENCODING_ADPCM;
425 play->validbits = 4;
426 play->precision = 4;
427 pfil->append(pfil, pconv, play);
428 }
429 if ((setmode & AUMODE_RECORD) != 0) {
430 rfil->append(rfil, null_filter, rec);
431 rec->encoding = AUDIO_ENCODING_ADPCM;
432 rec->validbits = 4;
433 rec->precision = 4;
434 rfil->append(rfil, rconv, rec);
435 }
436
437 DPRINTF(1, ("accepted\n"));
438 return 0;
439 }
440
441 static void
442 vs_set_sr(struct vs_softc *sc, int rate)
443 {
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 const audio_params_t *p)
466 {
467 struct vs_softc *sc;
468 struct vs_dma *vd;
469 struct dmac_dma_xfer *xf;
470 struct dmac_channel_stat *chan;
471
472 DPRINTF(2, ("vs_trigger_output: start=%p, bsize=%d, intr=%p, arg=%p\n",
473 start, bsize, intr, arg));
474 sc = hdl;
475 chan = sc->sc_dma_ch;
476 sc->sc_pintr = intr;
477 sc->sc_parg = arg;
478 sc->sc_current.blksize = bsize;
479 sc->sc_current.bufsize = (char *)end - (char *)start;
480 sc->sc_current.dmap = 0;
481
482 /* Find DMA buffer. */
483 for (vd = sc->sc_dmas; vd != NULL && KVADDR(vd) != start;
484 vd = vd->vd_next)
485 continue;
486 if (vd == NULL) {
487 printf("%s: trigger_output: bad addr %p\n",
488 device_xname(sc->sc_dev), start);
489 return EINVAL;
490 }
491
492 vs_set_sr(sc, sc->sc_current.prate);
493 vs_set_po(sc, VS_PANOUT_LR);
494
495 xf = dmac_alloc_xfer(chan, sc->sc_dmat, vd->vd_map);
496 sc->sc_current.xfer = xf;
497 chan->ch_dcr = (DMAC_DCR_XRM_CSWOH | DMAC_DCR_OTYP_EASYNC |
498 DMAC_DCR_OPS_8BIT);
499 chan->ch_ocr = DMAC_OCR_REQG_EXTERNAL;
500 xf->dx_ocr = DMAC_OCR_DIR_MTD;
501 xf->dx_scr = DMAC_SCR_MAC_COUNT_UP | DMAC_SCR_DAC_NO_COUNT;
502 xf->dx_device = sc->sc_addr + MSM6258_DATA*2 + 1;
503
504 dmac_load_xfer(chan->ch_softc, xf);
505 dmac_start_xfer_offset(chan->ch_softc, xf, 0, sc->sc_current.blksize);
506 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 2);
507 sc->sc_active = 1;
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 const audio_params_t *p)
516 {
517 struct vs_softc *sc;
518 struct vs_dma *vd;
519 struct dmac_dma_xfer *xf;
520 struct dmac_channel_stat *chan;
521
522 DPRINTF(2, ("vs_trigger_input: start=%p, bsize=%d, intr=%p, arg=%p\n",
523 start, bsize, intr, arg));
524 sc = hdl;
525 chan = sc->sc_dma_ch;
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 continue;
536 if (vd == NULL) {
537 printf("%s: trigger_output: bad addr %p\n",
538 device_xname(sc->sc_dev), 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 sc->sc_active = 1;
556
557 return 0;
558 }
559
560 static int
561 vs_halt_output(void *hdl)
562 {
563 struct vs_softc *sc;
564
565 DPRINTF(1, ("vs_halt_output\n"));
566 sc = hdl;
567 if (sc->sc_active) {
568 /* stop ADPCM play */
569 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
570 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
571 sc->sc_active = 0;
572 }
573
574 return 0;
575 }
576
577 static int
578 vs_halt_input(void *hdl)
579 {
580 struct vs_softc *sc;
581
582 DPRINTF(1, ("vs_halt_input\n"));
583 sc = hdl;
584 if (sc->sc_active) {
585 /* stop ADPCM recoding */
586 dmac_abort_xfer(sc->sc_dma_ch->ch_softc, sc->sc_current.xfer);
587 bus_space_write_1(sc->sc_iot, sc->sc_ioh, MSM6258_STAT, 1);
588 sc->sc_active = 0;
589 }
590
591 return 0;
592 }
593
594 static int
595 vs_allocmem(struct vs_softc *sc, size_t size, size_t align, size_t boundary,
596 struct vs_dma *vd)
597 {
598 int error;
599
600 #ifdef DIAGNOSTIC
601 if (size > DMAC_MAXSEGSZ)
602 panic ("vs_allocmem: maximum size exceeded, %d", (int) size);
603 #endif
604
605 vd->vd_size = size;
606
607 error = bus_dmamem_alloc(vd->vd_dmat, vd->vd_size, align, boundary,
608 vd->vd_segs,
609 sizeof (vd->vd_segs) / sizeof (vd->vd_segs[0]),
610 &vd->vd_nsegs, BUS_DMA_WAITOK);
611 if (error)
612 goto out;
613
614 error = bus_dmamem_map(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs,
615 vd->vd_size, &vd->vd_addr,
616 BUS_DMA_WAITOK | BUS_DMA_COHERENT);
617 if (error)
618 goto free;
619
620 error = bus_dmamap_create(vd->vd_dmat, vd->vd_size, 1, DMAC_MAXSEGSZ,
621 0, BUS_DMA_WAITOK, &vd->vd_map);
622 if (error)
623 goto unmap;
624
625 error = bus_dmamap_load(vd->vd_dmat, vd->vd_map, vd->vd_addr,
626 vd->vd_size, NULL, BUS_DMA_WAITOK);
627 if (error)
628 goto destroy;
629
630 return 0;
631
632 destroy:
633 bus_dmamap_destroy(vd->vd_dmat, vd->vd_map);
634 unmap:
635 bus_dmamem_unmap(vd->vd_dmat, vd->vd_addr, vd->vd_size);
636 free:
637 bus_dmamem_free(vd->vd_dmat, vd->vd_segs, vd->vd_nsegs);
638 out:
639 return error;
640 }
641
642 static void
643 vs_freemem(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
656 DPRINTF(1, ("vs_getdev\n"));
657 *retp = vs_device;
658 return 0;
659 }
660
661 static int
662 vs_set_port(void *hdl, mixer_ctrl_t *cp)
663 {
664
665 DPRINTF(1, ("vs_set_port\n"));
666 return 0;
667 }
668
669 static int
670 vs_get_port(void *hdl, mixer_ctrl_t *cp)
671 {
672
673 DPRINTF(1, ("vs_get_port\n"));
674 return 0;
675 }
676
677 static int
678 vs_query_devinfo(void *hdl, mixer_devinfo_t *mi)
679 {
680
681 DPRINTF(1, ("vs_query_devinfo\n"));
682 switch (mi->index) {
683 default:
684 return EINVAL;
685 }
686 return 0;
687 }
688
689 static void *
690 vs_allocm(void *hdl, int direction, size_t size)
691 {
692 struct vs_softc *sc;
693 struct vs_dma *vd;
694 int error;
695
696 vd = kmem_alloc(sizeof(*vd), KM_SLEEP);
697 sc = hdl;
698 vd->vd_dmat = sc->sc_dmat;
699
700 error = vs_allocmem(sc, size, 32, 0, vd);
701 if (error) {
702 kmem_free(vd, sizeof(*vd));
703 return NULL;
704 }
705 vd->vd_next = sc->sc_dmas;
706 sc->sc_dmas = vd;
707
708 return KVADDR(vd);
709 }
710
711 static void
712 vs_freem(void *hdl, void *addr, size_t size)
713 {
714 struct vs_softc *sc;
715 struct vs_dma *p, **pp;
716
717 sc = hdl;
718 for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->vd_next) {
719 if (KVADDR(p) == addr) {
720 vs_freemem(p);
721 *pp = p->vd_next;
722 kmem_free(p, sizeof(*p));
723 return;
724 }
725 }
726 }
727
728 static size_t
729 vs_round_buffersize(void *hdl, int direction, size_t bufsize)
730 {
731
732 if (bufsize > DMAC_MAXSEGSZ)
733 bufsize = DMAC_MAXSEGSZ;
734 return bufsize;
735 }
736
737 #if 0
738 paddr_t
739 vs_mappage(void *addr, void *mem, off_t off, int prot)
740 {
741 struct vs_softc *sc;
742 struct vs_dma *p;
743
744 if (off < 0)
745 return -1;
746 sc = addr;
747 for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
748 p = p->vd_next)
749 continue;
750 if (p == NULL) {
751 printf("%s: mappage: bad addr %p\n",
752 device_xname(sc->sc_dev), start);
753 return -1;
754 }
755
756 return bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
757 off, prot, BUS_DMA_WAITOK);
758 }
759 #endif
760
761 static int
762 vs_get_props(void *hdl)
763 {
764
765 DPRINTF(1, ("vs_get_props\n"));
766 return 0 /* | dependent | half duplex | no mmap */;
767 }
768
769 static void
770 vs_get_locks(void *hdl, kmutex_t **intr, kmutex_t **thread)
771 {
772 struct vs_softc *sc;
773
774 DPRINTF(1, ("vs_get_locks\n"));
775 sc = hdl;
776 *intr = &sc->sc_intr_lock;
777 *thread = &sc->sc_lock;
778 }
779
780 #endif /* NAUDIO > 0 && NVS > 0*/
781