FreeBSD kernel sound device code
via82c686.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2000 David Jones <dej@ox.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifdef HAVE_KERNEL_OPTION_HEADERS
30#include "opt_snd.h"
31#endif
32
33#include <dev/sound/pcm/sound.h>
34#include <dev/sound/pcm/ac97.h>
35
36#include <dev/pci/pcireg.h>
37#include <dev/pci/pcivar.h>
38#include <sys/sysctl.h>
39
41
42SND_DECLARE_FILE("$FreeBSD$");
43
44#define VIA_PCI_ID 0x30581106
45#define NSEGS 4 /* Number of segments in SGD table */
46
47#define SEGS_PER_CHAN (NSEGS/2)
48
49#define TIMEOUT 50
50#define VIA_DEFAULT_BUFSZ 0x1000
51
52#undef DEB
53#define DEB(x)
54
55/* we rely on this struct being packed to 64 bits */
56struct via_dma_op {
57 u_int32_t ptr;
58 u_int32_t flags;
59#define VIA_DMAOP_EOL 0x80000000
60#define VIA_DMAOP_FLAG 0x40000000
61#define VIA_DMAOP_STOP 0x20000000
62#define VIA_DMAOP_COUNT(x) ((x)&0x00FFFFFF)
63};
64
65struct via_info;
66
67struct via_chinfo {
68 struct via_info *parent;
69 struct pcm_channel *channel;
70 struct snd_dbuf *buffer;
71 struct via_dma_op *sgd_table;
72 bus_addr_t sgd_addr;
73 int dir, blksz;
75};
76
77struct via_info {
78 bus_space_tag_t st;
79 bus_space_handle_t sh;
80 bus_dma_tag_t parent_dmat;
81 bus_dma_tag_t sgd_dmat;
82 bus_dmamap_t sgd_dmamap;
83 bus_addr_t sgd_addr;
84
85 struct resource *reg, *irq;
86 int regid, irqid;
87 void *ih;
88 struct ac97_info *codec;
89
90 unsigned int bufsz;
91
93 struct via_dma_op *sgd_table;
94 u_int16_t codec_caps;
95 struct mtx *lock;
96};
97
98static u_int32_t via_fmt[] = {
99 SND_FORMAT(AFMT_U8, 1, 0),
100 SND_FORMAT(AFMT_U8, 2, 0),
101 SND_FORMAT(AFMT_S16_LE, 1, 0),
102 SND_FORMAT(AFMT_S16_LE, 2, 0),
103 0
104};
105static struct pcmchan_caps via_vracaps = {4000, 48000, via_fmt, 0};
106static struct pcmchan_caps via_caps = {48000, 48000, via_fmt, 0};
107
108static __inline u_int32_t
109via_rd(struct via_info *via, int regno, int size)
110{
111
112 switch (size) {
113 case 1:
114 return bus_space_read_1(via->st, via->sh, regno);
115 case 2:
116 return bus_space_read_2(via->st, via->sh, regno);
117 case 4:
118 return bus_space_read_4(via->st, via->sh, regno);
119 default:
120 return 0xFFFFFFFF;
121 }
122}
123
124static __inline void
125via_wr(struct via_info *via, int regno, u_int32_t data, int size)
126{
127
128 switch (size) {
129 case 1:
130 bus_space_write_1(via->st, via->sh, regno, data);
131 break;
132 case 2:
133 bus_space_write_2(via->st, via->sh, regno, data);
134 break;
135 case 4:
136 bus_space_write_4(via->st, via->sh, regno, data);
137 break;
138 }
139}
140
141/* -------------------------------------------------------------------- */
142/* Codec interface */
143
144static int
146{
147 int i;
148
149 /* poll until codec not busy */
150 for (i = 0; (i < TIMEOUT) &&
151 (via_rd(via, VIA_CODEC_CTL, 4) & VIA_CODEC_BUSY); i++)
152 DELAY(1);
153 if (i >= TIMEOUT) {
154 printf("via: codec busy\n");
155 return 1;
156 }
157
158 return 0;
159}
160
161static int
163{
164 int i;
165
166 /* poll until codec valid */
167 for (i = 0; (i < TIMEOUT) &&
168 !(via_rd(via, VIA_CODEC_CTL, 4) & VIA_CODEC_PRIVALID); i++)
169 DELAY(1);
170 if (i >= TIMEOUT) {
171 printf("via: codec invalid\n");
172 return 1;
173 }
174
175 return 0;
176}
177
178static int
179via_write_codec(kobj_t obj, void *addr, int reg, u_int32_t val)
180{
181 struct via_info *via = addr;
182
183 if (via_waitready_codec(via)) return -1;
184
186
187 return 0;
188}
189
190static int
191via_read_codec(kobj_t obj, void *addr, int reg)
192{
193 struct via_info *via = addr;
194
195 if (via_waitready_codec(via))
196 return -1;
197
199
200 if (via_waitready_codec(via))
201 return -1;
202
203 if (via_waitvalid_codec(via))
204 return -1;
205
206 return via_rd(via, VIA_CODEC_CTL, 2);
207}
208
209static kobj_method_t via_ac97_methods[] = {
210 KOBJMETHOD(ac97_read, via_read_codec),
211 KOBJMETHOD(ac97_write, via_write_codec),
213};
214AC97_DECLARE(via_ac97);
215
216/* -------------------------------------------------------------------- */
217
218static int
220{
221 u_int32_t phys_addr, flag;
222 int i, segs, seg_size;
223
224 /*
225 * Build the scatter/gather DMA (SGD) table.
226 * There are four slots in the table: two for play, two for record.
227 * This creates two half-buffers, one of which is playing; the other
228 * is feeding.
229 */
230 seg_size = ch->blksz;
231 segs = sndbuf_getsize(ch->buffer) / seg_size;
232 phys_addr = sndbuf_getbufaddr(ch->buffer);
233
234 for (i = 0; i < segs; i++) {
235 flag = (i == segs - 1)? VIA_DMAOP_EOL : VIA_DMAOP_FLAG;
236 ch->sgd_table[i].ptr = phys_addr + (i * seg_size);
237 ch->sgd_table[i].flags = flag | seg_size;
238 }
239
240 return 0;
241}
242
243/* channel interface */
244static void *
245viachan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
246{
247 struct via_info *via = devinfo;
248 struct via_chinfo *ch;
249
250 snd_mtxlock(via->lock);
251 if (dir == PCMDIR_PLAY) {
252 ch = &via->pch;
256 ch->mode = VIA_PLAY_MODE;
257 ch->sgd_addr = via->sgd_addr;
258 ch->sgd_table = &via->sgd_table[0];
259 } else {
260 ch = &via->rch;
264 ch->mode = VIA_RECORD_MODE;
265 ch->sgd_addr = via->sgd_addr + sizeof(struct via_dma_op) * SEGS_PER_CHAN;
266 ch->sgd_table = &via->sgd_table[SEGS_PER_CHAN];
267 }
268
269 ch->parent = via;
270 ch->channel = c;
271 ch->buffer = b;
272 ch->dir = dir;
273 snd_mtxunlock(via->lock);
274
275 if (sndbuf_alloc(ch->buffer, via->parent_dmat, 0, via->bufsz) != 0)
276 return NULL;
277
278 return ch;
279}
280
281static int
282viachan_setformat(kobj_t obj, void *data, u_int32_t format)
283{
284 struct via_chinfo *ch = data;
285 struct via_info *via = ch->parent;
286 int mode, mode_set;
287
288 mode_set = 0;
289 if (AFMT_CHANNEL(format) > 1)
290 mode_set |= VIA_RPMODE_STEREO;
291 if (format & AFMT_S16_LE)
292 mode_set |= VIA_RPMODE_16BIT;
293
294 DEB(printf("set format: dir = %d, format=%x\n", ch->dir, format));
295 snd_mtxlock(via->lock);
296 mode = via_rd(via, ch->mode, 1);
298 mode |= mode_set;
299 via_wr(via, ch->mode, mode, 1);
300 snd_mtxunlock(via->lock);
301
302 return 0;
303}
304
305static u_int32_t
306viachan_setspeed(kobj_t obj, void *data, u_int32_t speed)
307{
308 struct via_chinfo *ch = data;
309 struct via_info *via = ch->parent;
310 int reg;
311
312 /*
313 * Basic AC'97 defines a 48 kHz sample rate only. For other rates,
314 * upsampling is required.
315 *
316 * The VT82C686A does not perform upsampling, and neither do we.
317 * If the codec supports variable-rate audio (i.e. does the upsampling
318 * itself), then negotiate the rate with the codec. Otherwise,
319 * return 48 kHz cuz that's all you got.
320 */
321 if (via->codec_caps & AC97_EXTCAP_VRA) {
323 return ac97_setrate(via->codec, reg, speed);
324 } else
325 return 48000;
326}
327
328static u_int32_t
329viachan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
330{
331 struct via_chinfo *ch = data;
332
333 ch->blksz = blocksize;
335
336 return ch->blksz;
337}
338
339static int
340viachan_trigger(kobj_t obj, void *data, int go)
341{
342 struct via_chinfo *ch = data;
343 struct via_info *via = ch->parent;
344 struct via_dma_op *ado;
345 bus_addr_t sgd_addr = ch->sgd_addr;
346
347 if (!PCMTRIG_COMMON(go))
348 return 0;
349
350 ado = ch->sgd_table;
351 DEB(printf("ado located at va=%p pa=%x\n", ado, sgd_addr));
352
353 snd_mtxlock(via->lock);
354 if (go == PCMTRIG_START) {
355 via_buildsgdt(ch);
356 via_wr(via, ch->base, sgd_addr, 4);
357 via_wr(via, ch->ctrl, VIA_RPCTRL_START, 1);
358 } else
359 via_wr(via, ch->ctrl, VIA_RPCTRL_TERMINATE, 1);
360 snd_mtxunlock(via->lock);
361
362 DEB(printf("viachan_trigger: go=%d\n", go));
363 return 0;
364}
365
366static u_int32_t
367viachan_getptr(kobj_t obj, void *data)
368{
369 struct via_chinfo *ch = data;
370 struct via_info *via = ch->parent;
371 struct via_dma_op *ado;
372 bus_addr_t sgd_addr = ch->sgd_addr;
373 u_int32_t ptr, base, base1, len, seg;
374
375 ado = ch->sgd_table;
376 snd_mtxlock(via->lock);
377 base1 = via_rd(via, ch->base, 4);
378 len = via_rd(via, ch->count, 4);
379 base = via_rd(via, ch->base, 4);
380 if (base != base1) /* Avoid race hazard */
381 len = via_rd(via, ch->count, 4);
382 snd_mtxunlock(via->lock);
383
384 DEB(printf("viachan_getptr: len / base = %x / %x\n", len, base));
385
386 /* Base points to SGD segment to do, one past current */
387
388 /* Determine how many segments have been done */
389 seg = (base - sgd_addr) / sizeof(struct via_dma_op);
390 if (seg == 0)
391 seg = SEGS_PER_CHAN;
392
393 /* Now work out offset: seg less count */
394 ptr = (seg * sndbuf_getsize(ch->buffer) / SEGS_PER_CHAN) - len;
395 if (ch->dir == PCMDIR_REC) {
396 /* DMA appears to operate on memory 'lines' of 32 bytes */
397 /* so don't return any part line - it isn't in RAM yet */
398 ptr = ptr & ~0x1f;
399 }
400
401 DEB(printf("return ptr=%u\n", ptr));
402 return ptr;
403}
404
405static struct pcmchan_caps *
406viachan_getcaps(kobj_t obj, void *data)
407{
408 struct via_chinfo *ch = data;
409 struct via_info *via = ch->parent;
410
411 return (via->codec_caps & AC97_EXTCAP_VRA)? &via_vracaps : &via_caps;
412}
413
414static kobj_method_t viachan_methods[] = {
415 KOBJMETHOD(channel_init, viachan_init),
416 KOBJMETHOD(channel_setformat, viachan_setformat),
417 KOBJMETHOD(channel_setspeed, viachan_setspeed),
418 KOBJMETHOD(channel_setblocksize, viachan_setblocksize),
419 KOBJMETHOD(channel_trigger, viachan_trigger),
420 KOBJMETHOD(channel_getptr, viachan_getptr),
421 KOBJMETHOD(channel_getcaps, viachan_getcaps),
423};
425
426/* -------------------------------------------------------------------- */
427
428static void
429via_intr(void *p)
430{
431 struct via_info *via = p;
432
433 /* DEB(printf("viachan_intr\n")); */
434 /* Read channel */
435 snd_mtxlock(via->lock);
436 if (via_rd(via, VIA_PLAY_STAT, 1) & VIA_RPSTAT_INTR) {
438 snd_mtxunlock(via->lock);
439 chn_intr(via->pch.channel);
440 snd_mtxlock(via->lock);
441 }
442
443 /* Write channel */
444 if (via_rd(via, VIA_RECORD_STAT, 1) & VIA_RPSTAT_INTR) {
446 snd_mtxunlock(via->lock);
447 chn_intr(via->rch.channel);
448 return;
449 }
450 snd_mtxunlock(via->lock);
451}
452
453/*
454 * Probe and attach the card
455 */
456static int
457via_probe(device_t dev)
458{
459 if (pci_get_devid(dev) == VIA_PCI_ID) {
460 device_set_desc(dev, "VIA VT82C686A");
461 return BUS_PROBE_DEFAULT;
462 }
463 return ENXIO;
464}
465
466static void
467dma_cb(void *p, bus_dma_segment_t *bds, int a, int b)
468{
469 struct via_info *via = (struct via_info *)p;
470 via->sgd_addr = bds->ds_addr;
471}
472
473static int
475{
476 struct via_info *via = NULL;
477 char status[SND_STATUSLEN];
478 u_int32_t data, cnt;
479
480 via = malloc(sizeof(*via), M_DEVBUF, M_WAITOK | M_ZERO);
481 via->lock = snd_mtxcreate(device_get_nameunit(dev),
482 "snd_via82c686 softc");
483
484 pci_enable_busmaster(dev);
485
486 /* Wake up and reset AC97 if necessary */
487 data = pci_read_config(dev, VIA_AC97STATUS, 1);
488
489 if ((data & VIA_AC97STATUS_RDY) == 0) {
490 /* Cold reset per ac97r2.3 spec (page 95) */
491 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_EN, 1); /* Assert low */
492 DELAY(100); /* Wait T_rst_low */
493 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_EN | VIA_ACLINK_NRST, 1); /* Assert high */
494 DELAY(5); /* Wait T_rst2clk */
495 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_EN, 1); /* Assert low */
496 } else {
497 /* Warm reset */
498 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_EN, 1); /* Force no sync */
499 DELAY(100);
500 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_EN | VIA_ACLINK_SYNC, 1); /* Sync */
501 DELAY(5); /* Wait T_sync_high */
502 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_EN, 1); /* Force no sync */
503 DELAY(5); /* Wait T_sync2clk */
504 }
505
506 /* Power everything up */
507 pci_write_config(dev, VIA_ACLINKCTRL, VIA_ACLINK_DESIRED, 1);
508
509 /* Wait for codec to become ready (largest reported delay here 310ms) */
510 for (cnt = 0; cnt < 2000; cnt++) {
511 data = pci_read_config(dev, VIA_AC97STATUS, 1);
513 break;
514 DELAY(5000);
515 }
516
517 via->regid = PCIR_BAR(0);
518 via->reg = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
519 &via->regid, RF_ACTIVE);
520 if (!via->reg) {
521 device_printf(dev, "cannot allocate bus resource.");
522 goto bad;
523 }
524 via->st = rman_get_bustag(via->reg);
525 via->sh = rman_get_bushandle(via->reg);
526
527 via->bufsz = pcm_getbuffersize(dev, 4096, VIA_DEFAULT_BUFSZ, 65536);
528
529 via->irqid = 0;
530 via->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &via->irqid,
531 RF_ACTIVE | RF_SHAREABLE);
532 if (!via->irq || snd_setup_intr(dev, via->irq, INTR_MPSAFE, via_intr, via, &via->ih)) {
533 device_printf(dev, "unable to map interrupt\n");
534 goto bad;
535 }
536
539
540 via->codec = AC97_CREATE(dev, via, via_ac97);
541 if (!via->codec)
542 goto bad;
543
545 goto bad;
546
547 via->codec_caps = ac97_getextcaps(via->codec);
550
551 /* DMA tag for buffers */
552 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev), /*alignment*/2,
553 /*boundary*/0,
554 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
555 /*highaddr*/BUS_SPACE_MAXADDR,
556 /*filter*/NULL, /*filterarg*/NULL,
557 /*maxsize*/via->bufsz, /*nsegments*/1, /*maxsegz*/0x3ffff,
558 /*flags*/0, /*lockfunc*/NULL,
559 /*lockarg*/NULL, &via->parent_dmat) != 0) {
560 device_printf(dev, "unable to create dma tag\n");
561 goto bad;
562 }
563
564 /*
565 * DMA tag for SGD table. The 686 uses scatter/gather DMA and
566 * requires a list in memory of work to do. We need only 16 bytes
567 * for this list, and it is wasteful to allocate 16K.
568 */
569 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev), /*alignment*/2,
570 /*boundary*/0,
571 /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
572 /*highaddr*/BUS_SPACE_MAXADDR,
573 /*filter*/NULL, /*filterarg*/NULL,
574 /*maxsize*/NSEGS * sizeof(struct via_dma_op),
575 /*nsegments*/1, /*maxsegz*/0x3ffff,
576 /*flags*/0, /*lockfunc*/NULL,
577 /*lockarg*/NULL, &via->sgd_dmat) != 0) {
578 device_printf(dev, "unable to create dma tag\n");
579 goto bad;
580 }
581
582 if (bus_dmamem_alloc(via->sgd_dmat, (void **)&via->sgd_table,
583 BUS_DMA_NOWAIT, &via->sgd_dmamap) != 0)
584 goto bad;
585 if (bus_dmamap_load(via->sgd_dmat, via->sgd_dmamap, via->sgd_table,
586 NSEGS * sizeof(struct via_dma_op), dma_cb, via, 0) != 0)
587 goto bad;
588
589 snprintf(status, SND_STATUSLEN, "at io 0x%jx irq %jd %s",
590 rman_get_start(via->reg), rman_get_start(via->irq),
591 PCM_KLDSTRING(snd_via82c686));
592
593 /* Register */
594 if (pcm_register(dev, via, 1, 1)) goto bad;
595 pcm_addchan(dev, PCMDIR_PLAY, &viachan_class, via);
596 pcm_addchan(dev, PCMDIR_REC, &viachan_class, via);
598 return 0;
599bad:
600 if (via->codec) ac97_destroy(via->codec);
601 if (via->reg) bus_release_resource(dev, SYS_RES_IOPORT, via->regid, via->reg);
602 if (via->ih) bus_teardown_intr(dev, via->irq, via->ih);
603 if (via->irq) bus_release_resource(dev, SYS_RES_IRQ, via->irqid, via->irq);
604 if (via->parent_dmat) bus_dma_tag_destroy(via->parent_dmat);
605 if (via->sgd_addr) bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap);
606 if (via->sgd_table) bus_dmamem_free(via->sgd_dmat, via->sgd_table, via->sgd_dmamap);
607 if (via->sgd_dmat) bus_dma_tag_destroy(via->sgd_dmat);
608 if (via->lock) snd_mtxfree(via->lock);
609 if (via) free(via, M_DEVBUF);
610 return ENXIO;
611}
612
613static int
615{
616 int r;
617 struct via_info *via = NULL;
618
620 if (r)
621 return r;
622
623 via = pcm_getdevinfo(dev);
624 bus_release_resource(dev, SYS_RES_IOPORT, via->regid, via->reg);
625 bus_teardown_intr(dev, via->irq, via->ih);
626 bus_release_resource(dev, SYS_RES_IRQ, via->irqid, via->irq);
627 bus_dma_tag_destroy(via->parent_dmat);
628 bus_dmamap_unload(via->sgd_dmat, via->sgd_dmamap);
629 bus_dmamem_free(via->sgd_dmat, via->sgd_table, via->sgd_dmamap);
630 bus_dma_tag_destroy(via->sgd_dmat);
631 snd_mtxfree(via->lock);
632 free(via, M_DEVBUF);
633 return 0;
634}
635
636static device_method_t via_methods[] = {
637 DEVMETHOD(device_probe, via_probe),
638 DEVMETHOD(device_attach, via_attach),
639 DEVMETHOD(device_detach, via_detach),
640 { 0, 0}
641};
642
643static driver_t via_driver = {
644 "pcm",
647};
648
649DRIVER_MODULE(snd_via82c686, pci, via_driver, pcm_devclass, 0, 0);
651MODULE_VERSION(snd_via82c686, 1);
int ac97_setextmode(struct ac97_info *codec, u_int16_t mode)
Definition: ac97.c:383
u_int16_t ac97_getextcaps(struct ac97_info *codec)
Definition: ac97.c:405
kobj_class_t ac97_getmixerclass(void)
Definition: ac97.c:1097
void ac97_destroy(struct ac97_info *codec)
Definition: ac97.c:860
int ac97_setrate(struct ac97_info *codec, int which, int rate)
Definition: ac97.c:352
#define AC97_EXTCAP_VRM
Definition: ac97.h:70
#define AC97_CREATE(dev, devinfo, cls)
Definition: ac97.h:89
#define AC97_REGEXT_FDACRATE
Definition: ac97.h:75
#define AC97_REGEXT_LADCRATE
Definition: ac97.h:78
#define AC97_EXTCAP_VRA
Definition: ac97.h:68
u_int32_t data
Definition: ac97_if.m:60
int regno
Definition: ac97_if.m:53
void * devinfo
Definition: ac97_if.m:47
uint32_t format
Definition: audio_dai_if.m:39
uint32_t speed
Definition: audio_dai_if.m:86
int go
Definition: audio_dai_if.m:64
int sndbuf_alloc(struct snd_dbuf *b, bus_dma_tag_t dmatag, int dmaflags, unsigned int size)
Definition: buffer.c:93
bus_addr_t sndbuf_getbufaddr(struct snd_dbuf *buf)
Definition: buffer.c:66
unsigned int sndbuf_getsize(struct snd_dbuf *b)
Definition: buffer.c:435
int sndbuf_resize(struct snd_dbuf *b, unsigned int blkcnt, unsigned int blksz)
Definition: buffer.c:164
void chn_intr(struct pcm_channel *c)
Definition: channel.c:660
#define PCMDIR_PLAY
Definition: channel.h:339
#define PCMTRIG_START
Definition: channel.h:344
#define PCMDIR_REC
Definition: channel.h:341
#define PCMTRIG_COMMON(x)
Definition: channel.h:350
struct pcm_channel * c
Definition: channel_if.m:106
METHOD int free
Definition: channel_if.m:110
u_int32_t blocksize
Definition: channel_if.m:140
struct snd_dbuf * b
Definition: channel_if.m:105
uint16_t len
uint16_t base
Definition: hdaa.c:124
uint8_t reg
Definition: hdac.c:211
int dir
Definition: hdac_if.m:45
uint8_t size
uint8_t r
#define KOBJMETHOD_END
Definition: midi.c:76
int mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
Definition: mixer.c:725
unsigned dev
Definition: mixer_if.m:59
bool * status
u_int32_t val
uint64_t * addr
#define PCIR_BAR(x)
void * snd_mtxcreate(const char *desc, const char *type)
Definition: sound.c:88
void * pcm_getdevinfo(device_t dev)
Definition: sound.c:832
int pcm_setstatus(device_t dev, char *str)
Definition: sound.c:766
devclass_t pcm_devclass
Definition: sound.c:49
void snd_mtxfree(void *m)
Definition: sound.c:98
int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
Definition: sound.c:692
int pcm_unregister(device_t dev)
Definition: sound.c:1170
int pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
Definition: sound.c:1080
int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
Definition: sound.c:117
unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
Definition: sound.c:840
#define PCM_KLDSTRING(a)
Definition: sound.h:619
#define SND_FORMAT(f, c, e)
Definition: sound.h:238
#define SOUND_PREFVER
Definition: sound.h:103
#define SOUND_MAXVER
Definition: sound.h:104
#define snd_mtxlock(m)
Definition: sound.h:347
#define AFMT_CHANNEL(v)
Definition: sound.h:227
#define snd_mtxunlock(m)
Definition: sound.h:348
#define SOUND_MINVER
Definition: sound.h:102
#define PCM_SOFTC_SIZE
Definition: sound.h:96
#define SND_STATUSLEN
Definition: sound.h:98
Definition: ac97.c:59
struct via_dma_op * sgd_table
Definition: via8233.c:95
unsigned int blksz
Definition: via8233.c:98
int base
Definition: via82c686.c:74
bus_addr_t sgd_addr
Definition: via8233.c:96
int count
Definition: via82c686.c:74
int blksz
Definition: via82c686.c:73
int mode
Definition: via82c686.c:74
int dir
Definition: via8233.c:97
struct via_info * parent
Definition: via8233.c:92
struct pcm_channel * channel
Definition: via8233.c:93
int ctrl
Definition: via82c686.c:74
struct snd_dbuf * buffer
Definition: via8233.c:94
u_int32_t ptr
Definition: via82c686.c:57
volatile uint32_t flags
Definition: via8233.c:82
u_int32_t flags
Definition: via82c686.c:58
volatile uint32_t ptr
Definition: via8233.c:81
bus_dma_tag_t sgd_dmat
Definition: via8233.c:108
struct mtx * lock
Definition: via8233.c:126
uint16_t codec_caps
Definition: via8233.c:123
bus_space_handle_t sh
Definition: via8233.c:106
void * ih
Definition: via8233.c:114
bus_addr_t sgd_addr
Definition: via8233.c:110
u_int16_t codec_caps
Definition: via82c686.c:94
struct via_chinfo rch[NWRCHANS]
Definition: via8233.c:121
int regid
Definition: via8233.c:113
bus_space_tag_t st
Definition: via8233.c:105
int irqid
Definition: via8233.c:113
struct via_dma_op * sgd_table
Definition: via8233.c:122
bus_dmamap_t sgd_dmamap
Definition: via8233.c:109
struct resource * reg
Definition: via8233.c:112
struct resource * irq
Definition: via8233.c:112
struct via_chinfo pch[NDXSCHANS+NMSGDCHANS]
Definition: via8233.c:120
bus_dma_tag_t parent_dmat
Definition: via8233.c:107
unsigned int bufsz
Definition: via8233.c:117
struct ac97_info * codec
Definition: via8233.c:115
#define VIA_CODEC_BUSY
Definition: via8233.h:164
#define VIA_CODEC_PRIVALID
Definition: via8233.h:165
#define VIA_CODEC_INDEX(x)
Definition: via8233.h:166
static kobj_method_t viachan_methods[]
Definition: via82c686.c:414
DRIVER_MODULE(snd_via82c686, pci, via_driver, pcm_devclass, 0, 0)
#define VIA_DEFAULT_BUFSZ
Definition: via82c686.c:50
static __inline u_int32_t via_rd(struct via_info *via, int regno, int size)
Definition: via82c686.c:109
static int via_waitvalid_codec(struct via_info *via)
Definition: via82c686.c:162
#define SEGS_PER_CHAN
Definition: via82c686.c:47
static u_int32_t viachan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
Definition: via82c686.c:329
static void * viachan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
Definition: via82c686.c:245
static device_method_t via_methods[]
Definition: via82c686.c:636
static driver_t via_driver
Definition: via82c686.c:643
static void dma_cb(void *p, bus_dma_segment_t *bds, int a, int b)
Definition: via82c686.c:467
static u_int32_t via_fmt[]
Definition: via82c686.c:98
static u_int32_t viachan_getptr(kobj_t obj, void *data)
Definition: via82c686.c:367
#define NSEGS
Definition: via82c686.c:45
static int via_waitready_codec(struct via_info *via)
Definition: via82c686.c:145
static int via_attach(device_t dev)
Definition: via82c686.c:474
#define TIMEOUT
Definition: via82c686.c:49
static int via_buildsgdt(struct via_chinfo *ch)
Definition: via82c686.c:219
static struct pcmchan_caps via_vracaps
Definition: via82c686.c:105
static int via_read_codec(kobj_t obj, void *addr, int reg)
Definition: via82c686.c:191
static int via_detach(device_t dev)
Definition: via82c686.c:614
SND_DECLARE_FILE("$FreeBSD$")
static struct pcmchan_caps * viachan_getcaps(kobj_t obj, void *data)
Definition: via82c686.c:406
static int viachan_setformat(kobj_t obj, void *data, u_int32_t format)
Definition: via82c686.c:282
MODULE_VERSION(snd_via82c686, 1)
static u_int32_t viachan_setspeed(kobj_t obj, void *data, u_int32_t speed)
Definition: via82c686.c:306
static int viachan_trigger(kobj_t obj, void *data, int go)
Definition: via82c686.c:340
#define VIA_PCI_ID
Definition: via82c686.c:44
static void via_intr(void *p)
Definition: via82c686.c:429
#define VIA_DMAOP_FLAG
Definition: via82c686.c:60
MODULE_DEPEND(snd_via82c686, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER)
#define VIA_DMAOP_EOL
Definition: via82c686.c:59
static int via_write_codec(kobj_t obj, void *addr, int reg, u_int32_t val)
Definition: via82c686.c:179
static kobj_method_t via_ac97_methods[]
Definition: via82c686.c:209
CHANNEL_DECLARE(viachan)
AC97_DECLARE(via_ac97)
static __inline void via_wr(struct via_info *via, int regno, u_int32_t data, int size)
Definition: via82c686.c:125
static int via_probe(device_t dev)
Definition: via82c686.c:457
static struct pcmchan_caps via_caps
Definition: via82c686.c:106
#define DEB(x)
Definition: via82c686.c:53
#define VIA_RPCTRL_START
Definition: via82c686.h:68
#define VIA_AC97STATUS_RDY
Definition: via82c686.h:48
#define VIA_RPSTAT_INTR
Definition: via82c686.h:65
#define VIA_PLAY_CONTROL
Definition: via82c686.h:66
#define VIA_PLAY_DMAOPS_BASE
Definition: via82c686.h:77
#define VIA_RPMODE_16BIT
Definition: via82c686.h:75
#define VIA_RECORD_DMAOPS_BASE
Definition: via82c686.h:78
#define VIA_RECORD_DMAOPS_COUNT
Definition: via82c686.h:80
#define VIA_RECORD_CONTROL
Definition: via82c686.h:67
#define VIA_PLAY_MODE
Definition: via82c686.h:70
#define VIA_CODEC_READ
Definition: via82c686.h:83
#define VIA_ACLINK_SYNC
Definition: via82c686.h:55
#define VIA_RPCTRL_TERMINATE
Definition: via82c686.h:69
#define VIA_RECORD_STAT
Definition: via82c686.h:64
#define VIA_ACLINK_EN
Definition: via82c686.h:53
#define VIA_ACLINK_DESIRED
Definition: via82c686.h:60
#define VIA_RPMODE_INTR_FLAG
Definition: via82c686.h:72
#define VIA_AC97STATUS
Definition: via82c686.h:47
#define VIA_RPMODE_STEREO
Definition: via82c686.h:74
#define VIA_PLAY_DMAOPS_COUNT
Definition: via82c686.h:79
#define VIA_PLAY_STAT
Definition: via82c686.h:63
#define VIA_RECORD_MODE
Definition: via82c686.h:71
#define VIA_RPMODE_AUTOSTART
Definition: via82c686.h:76
#define VIA_ACLINK_NRST
Definition: via82c686.h:54
#define VIA_ACLINKCTRL
Definition: via82c686.h:52
#define VIA_RPMODE_INTR_EOL
Definition: via82c686.h:73
#define VIA_CODEC_CTL
Definition: via82c686.h:82