2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3 * Copyright (c) 1997,1998 Luigi Rizzo
5 * Derived from files in the Voxware 3.5 distribution,
6 * Copyright by Hannu Savolainen 1994, under the same copyright
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #ifdef HAVE_KERNEL_OPTION_HEADERS
36 #include <dev/sound/pcm/sound.h>
38 #include <dev/sound/isa/sb.h>
39 #include <dev/sound/chip.h>
41 #include <isa/isavar.h>
45 SND_DECLARE_FILE("$FreeBSD$");
47 #define SB16_BUFFSIZE 4096
48 #define PLAIN_SB16(x) ((((x)->bd_flags) & (BD_F_SB16|BD_F_SB16X)) == BD_F_SB16)
50 static u_int32_t sb16_fmt8[] = {
51 SND_FORMAT(AFMT_U8, 1, 0),
52 SND_FORMAT(AFMT_U8, 2, 0),
55 static struct pcmchan_caps sb16_caps8 = {5000, 45000, sb16_fmt8, 0};
57 static u_int32_t sb16_fmt16[] = {
58 SND_FORMAT(AFMT_S16_LE, 1, 0),
59 SND_FORMAT(AFMT_S16_LE, 2, 0),
62 static struct pcmchan_caps sb16_caps16 = {5000, 45000, sb16_fmt16, 0};
64 static u_int32_t sb16x_fmt[] = {
65 SND_FORMAT(AFMT_U8, 1, 0),
66 SND_FORMAT(AFMT_U8, 2, 0),
67 SND_FORMAT(AFMT_S16_LE, 1, 0),
68 SND_FORMAT(AFMT_S16_LE, 2, 0),
71 static struct pcmchan_caps sb16x_caps = {5000, 49000, sb16x_fmt, 0};
76 struct sb_info *parent;
77 struct pcm_channel *channel;
78 struct snd_dbuf *buffer;
80 u_int32_t fmt, spd, blksz;
84 struct resource *io_base; /* I/O address for the board */
86 struct resource *drq1;
87 struct resource *drq2;
89 bus_dma_tag_t parent_dmat;
93 u_long bd_flags; /* board-specific flags */
95 struct sb_chinfo pch, rch;
100 static void sb_lock(struct sb_info *sb);
101 static void sb_unlock(struct sb_info *sb);
102 static int sb_rd(struct sb_info *sb, int reg);
103 static void sb_wr(struct sb_info *sb, int reg, u_int8_t val);
104 static int sb_cmd(struct sb_info *sb, u_char val);
105 /* static int sb_cmd1(struct sb_info *sb, u_char cmd, int val); */
106 static int sb_cmd2(struct sb_info *sb, u_char cmd, int val);
107 static u_int sb_get_byte(struct sb_info *sb);
108 static void sb_setmixer(struct sb_info *sb, u_int port, u_int value);
109 static int sb_getmixer(struct sb_info *sb, u_int port);
110 static int sb_reset_dsp(struct sb_info *sb);
112 static void sb_intr(void *arg);
116 * Common code for the midi and pcm functions
118 * sb_cmd write a single byte to the CMD port.
119 * sb_cmd1 write a CMD + 1 byte arg
120 * sb_cmd2 write a CMD + 2 byte arg
121 * sb_get_byte returns a single byte from the DSP data port
125 sb_lock(struct sb_info *sb) {
127 sbc_lock(device_get_softc(sb->parent_dev));
131 sb_lockassert(struct sb_info *sb) {
133 sbc_lockassert(device_get_softc(sb->parent_dev));
137 sb_unlock(struct sb_info *sb) {
139 sbc_unlock(device_get_softc(sb->parent_dev));
143 port_rd(struct resource *port, int off)
145 return bus_space_read_1(rman_get_bustag(port), rman_get_bushandle(port), off);
149 port_wr(struct resource *port, int off, u_int8_t data)
151 bus_space_write_1(rman_get_bustag(port), rman_get_bushandle(port), off, data);
155 sb_rd(struct sb_info *sb, int reg)
157 return port_rd(sb->io_base, reg);
161 sb_wr(struct sb_info *sb, int reg, u_int8_t val)
163 port_wr(sb->io_base, reg, val);
167 sb_dspwr(struct sb_info *sb, u_char val)
171 for (i = 0; i < 1000; i++) {
172 if ((sb_rd(sb, SBDSP_STATUS) & 0x80))
173 DELAY((i > 100)? 1000 : 10);
175 sb_wr(sb, SBDSP_CMD, val);
179 #if __FreeBSD_version > 500000
180 if (curthread->td_intr_nesting_level == 0)
181 printf("sb_dspwr(0x%02x) timed out.\n", val);
187 sb_cmd(struct sb_info *sb, u_char val)
190 printf("sb_cmd: %x\n", val);
192 return sb_dspwr(sb, val);
197 sb_cmd1(struct sb_info *sb, u_char cmd, int val)
200 printf("sb_cmd1: %x, %x\n", cmd, val);
202 if (sb_dspwr(sb, cmd)) {
203 return sb_dspwr(sb, val & 0xff);
209 sb_cmd2(struct sb_info *sb, u_char cmd, int val)
214 printf("sb_cmd2: %x, %x\n", cmd, val);
218 if (sb_dspwr(sb, cmd)) {
219 if (sb_dspwr(sb, val & 0xff)) {
220 if (sb_dspwr(sb, (val >> 8) & 0xff)) {
230 * in the SB, there is a set of indirect "mixer" registers with
231 * address at offset 4, data at offset 5
234 sb_setmixer(struct sb_info *sb, u_int port, u_int value)
237 sb_wr(sb, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
239 sb_wr(sb, SB_MIX_DATA, (u_char) (value & 0xff));
245 sb_getmixer(struct sb_info *sb, u_int port)
250 sb_wr(sb, SB_MIX_ADDR, (u_char) (port & 0xff)); /* Select register */
252 val = sb_rd(sb, SB_MIX_DATA);
259 sb_get_byte(struct sb_info *sb)
263 for (i = 1000; i > 0; i--) {
264 if (sb_rd(sb, DSP_DATA_AVAIL) & 0x80)
265 return sb_rd(sb, DSP_READ);
273 sb_reset_dsp(struct sb_info *sb)
278 sb_wr(sb, SBDSP_RST, 3);
280 sb_wr(sb, SBDSP_RST, 0);
283 DEB(printf("sb_reset_dsp 0x%lx failed\n",
284 rman_get_start(sb->io_base)));
285 return ENXIO; /* Sorry */
290 /************************************************************/
299 static const struct sb16_mixent sb16_mixtab[32] = {
300 [SOUND_MIXER_VOLUME] = { 0x30, 5, 3, 1 },
301 [SOUND_MIXER_PCM] = { 0x32, 5, 3, 1 },
302 [SOUND_MIXER_SYNTH] = { 0x34, 5, 3, 1 },
303 [SOUND_MIXER_CD] = { 0x36, 5, 3, 1 },
304 [SOUND_MIXER_LINE] = { 0x38, 5, 3, 1 },
305 [SOUND_MIXER_MIC] = { 0x3a, 5, 3, 0 },
306 [SOUND_MIXER_SPEAKER] = { 0x3b, 5, 3, 0 },
307 [SOUND_MIXER_IGAIN] = { 0x3f, 2, 6, 1 },
308 [SOUND_MIXER_OGAIN] = { 0x41, 2, 6, 1 },
309 [SOUND_MIXER_TREBLE] = { 0x44, 4, 4, 1 },
310 [SOUND_MIXER_BASS] = { 0x46, 4, 4, 1 },
311 [SOUND_MIXER_LINE1] = { 0x52, 5, 3, 1 }
315 sb16mix_init(struct snd_mixer *m)
317 struct sb_info *sb = mix_getdevinfo(m);
319 mix_setdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
320 SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD |
321 SOUND_MASK_IGAIN | SOUND_MASK_OGAIN | SOUND_MASK_LINE1 |
322 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE);
324 mix_setrecdevs(m, SOUND_MASK_SYNTH | SOUND_MASK_LINE |
325 SOUND_MASK_LINE1 | SOUND_MASK_MIC | SOUND_MASK_CD);
327 sb_setmixer(sb, 0x3c, 0x1f); /* make all output active */
329 sb_setmixer(sb, 0x3d, 0); /* make all inputs-l off */
330 sb_setmixer(sb, 0x3e, 0); /* make all inputs-r off */
336 rel2abs_volume(int x, int max)
340 temp = ((x * max) + 50) / 100;
349 sb16mix_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
351 struct sb_info *sb = mix_getdevinfo(m);
352 const struct sb16_mixent *e;
355 e = &sb16_mixtab[dev];
356 max = (1 << e->bits) - 1;
358 left = rel2abs_volume(left, max);
359 right = rel2abs_volume(right, max);
361 sb_setmixer(sb, e->reg, left << e->ofs);
363 sb_setmixer(sb, e->reg + 1, right << e->ofs);
367 left = (left * 100) / max;
368 right = (right * 100) / max;
370 return left | (right << 8);
374 sb16mix_setrecsrc(struct snd_mixer *m, u_int32_t src)
376 struct sb_info *sb = mix_getdevinfo(m);
377 u_char recdev_l, recdev_r;
381 if (src & SOUND_MASK_MIC) {
382 recdev_l |= 0x01; /* mono mic */
386 if (src & SOUND_MASK_CD) {
387 recdev_l |= 0x04; /* l cd */
388 recdev_r |= 0x02; /* r cd */
391 if (src & SOUND_MASK_LINE) {
392 recdev_l |= 0x10; /* l line */
393 recdev_r |= 0x08; /* r line */
396 if (src & SOUND_MASK_SYNTH) {
397 recdev_l |= 0x40; /* l midi */
398 recdev_r |= 0x20; /* r midi */
401 sb_setmixer(sb, SB16_IMASK_L, recdev_l);
402 sb_setmixer(sb, SB16_IMASK_R, recdev_r);
404 /* Switch on/off FM tuner source */
405 if (src & SOUND_MASK_LINE1)
406 sb_setmixer(sb, 0x4a, 0x0c);
408 sb_setmixer(sb, 0x4a, 0x00);
411 * since the same volume controls apply to the input and
412 * output sections, the best approach to have a consistent
413 * behaviour among cards would be to disable the output path
414 * on devices which are used to record.
415 * However, since users like to have feedback, we only disable
416 * the mic -- permanently.
418 sb_setmixer(sb, SB16_OMASK, 0x1f & ~1);
423 static kobj_method_t sb16mix_mixer_methods[] = {
424 KOBJMETHOD(mixer_init, sb16mix_init),
425 KOBJMETHOD(mixer_set, sb16mix_set),
426 KOBJMETHOD(mixer_setrecsrc, sb16mix_setrecsrc),
429 MIXER_DECLARE(sb16mix_mixer);
431 /************************************************************/
434 sb16_release_resources(struct sb_info *sb, device_t dev)
438 bus_teardown_intr(dev, sb->irq, sb->ih);
439 bus_release_resource(dev, SYS_RES_IRQ, 0, sb->irq);
443 if (sb->drq2 != sb->drq1) {
444 isa_dma_release(rman_get_start(sb->drq2));
445 bus_release_resource(dev, SYS_RES_DRQ, 1, sb->drq2);
450 isa_dma_release(rman_get_start(sb->drq1));
451 bus_release_resource(dev, SYS_RES_DRQ, 0, sb->drq1);
455 bus_release_resource(dev, SYS_RES_IOPORT, 0, sb->io_base);
458 if (sb->parent_dmat) {
459 bus_dma_tag_destroy(sb->parent_dmat);
466 sb16_alloc_resources(struct sb_info *sb, device_t dev)
472 sb->io_base = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
477 sb->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
482 sb->drq1 = bus_alloc_resource_any(dev, SYS_RES_DRQ, &rid,
487 sb->drq2 = bus_alloc_resource_any(dev, SYS_RES_DRQ, &rid,
490 if (sb->io_base && sb->drq1 && sb->irq) {
491 isa_dma_acquire(rman_get_start(sb->drq1));
492 isa_dmainit(rman_get_start(sb->drq1), sb->bufsize);
495 isa_dma_acquire(rman_get_start(sb->drq2));
496 isa_dmainit(rman_get_start(sb->drq2), sb->bufsize);
499 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
505 /* sbc does locking for us */
509 struct sb_info *sb = (struct sb_info *)arg;
513 * The Vibra16X has separate flags for 8 and 16 bit transfers, but
514 * I have no idea how to tell capture from playback interrupts...
519 c = sb_getmixer(sb, IRQ_STAT);
521 sb_rd(sb, DSP_DATA_AVAIL); /* 8-bit int ack */
524 sb_rd(sb, DSP_DATA_AVL16); /* 16-bit int ack */
528 * this tells us if the source is 8-bit or 16-bit dma. We
529 * have to check the io channel to map it to read or write...
532 if (sb->bd_flags & BD_F_SB16X) {
533 if (c & 1) { /* 8-bit format */
534 if (sb->pch.fmt & AFMT_8BIT)
536 if (sb->rch.fmt & AFMT_8BIT)
539 if (c & 2) { /* 16-bit format */
540 if (sb->pch.fmt & AFMT_16BIT)
542 if (sb->rch.fmt & AFMT_16BIT)
546 if (c & 1) { /* 8-bit dma */
547 if (sb->pch.dch == 1)
549 if (sb->rch.dch == 1)
552 if (c & 2) { /* 16-bit dma */
553 if (sb->pch.dch == 2)
555 if (sb->rch.dch == 2)
560 printf("sb_intr: reason=%d c=0x%x\n", reason, c);
562 if ((reason & 1) && (sb->pch.run))
563 chn_intr(sb->pch.channel);
565 if ((reason & 2) && (sb->rch.run))
566 chn_intr(sb->rch.channel);
570 sb_setup(struct sb_info *sb)
572 struct sb_chinfo *ch;
577 if (sb->bd_flags & BD_F_DMARUN)
578 sndbuf_dma(sb->pch.buffer, PCMTRIG_STOP);
579 if (sb->bd_flags & BD_F_DMARUN2)
580 sndbuf_dma(sb->rch.buffer, PCMTRIG_STOP);
581 sb->bd_flags &= ~(BD_F_DMARUN | BD_F_DMARUN2);
585 if (sb->bd_flags & BD_F_SB16X) {
586 /* full-duplex doesn't work! */
587 pprio = sb->pch.run? 1 : 0;
588 sndbuf_dmasetup(sb->pch.buffer, pprio? sb->drq1 : sb->drq2);
589 sb->pch.dch = pprio? 1 : 0;
590 sndbuf_dmasetup(sb->rch.buffer, pprio? sb->drq2 : sb->drq1);
591 sb->rch.dch = pprio? 2 : 1;
593 if (sb->pch.run && sb->rch.run) {
594 pprio = (sb->rch.fmt & AFMT_16BIT)? 0 : 1;
595 sndbuf_dmasetup(sb->pch.buffer, pprio? sb->drq2 : sb->drq1);
596 sb->pch.dch = pprio? 2 : 1;
597 sndbuf_dmasetup(sb->rch.buffer, pprio? sb->drq1 : sb->drq2);
598 sb->rch.dch = pprio? 1 : 2;
601 sndbuf_dmasetup(sb->pch.buffer, (sb->pch.fmt & AFMT_16BIT)? sb->drq2 : sb->drq1);
602 sb->pch.dch = (sb->pch.fmt & AFMT_16BIT)? 2 : 1;
603 sndbuf_dmasetup(sb->rch.buffer, (sb->pch.fmt & AFMT_16BIT)? sb->drq1 : sb->drq2);
604 sb->rch.dch = (sb->pch.fmt & AFMT_16BIT)? 1 : 2;
605 } else if (sb->rch.run) {
606 sndbuf_dmasetup(sb->pch.buffer, (sb->rch.fmt & AFMT_16BIT)? sb->drq1 : sb->drq2);
607 sb->pch.dch = (sb->rch.fmt & AFMT_16BIT)? 1 : 2;
608 sndbuf_dmasetup(sb->rch.buffer, (sb->rch.fmt & AFMT_16BIT)? sb->drq2 : sb->drq1);
609 sb->rch.dch = (sb->rch.fmt & AFMT_16BIT)? 2 : 1;
614 sndbuf_dmasetdir(sb->pch.buffer, PCMDIR_PLAY);
615 sndbuf_dmasetdir(sb->rch.buffer, PCMDIR_REC);
618 printf("setup: [pch = %d, pfmt = %d, pgo = %d] [rch = %d, rfmt = %d, rgo = %d]\n",
619 sb->pch.dch, sb->pch.fmt, sb->pch.run, sb->rch.dch, sb->rch.fmt, sb->rch.run);
625 if (ch->fmt & AFMT_16BIT)
630 RANGE(ch->spd, 5000, 45000);
631 sb_cmd(sb, DSP_CMD_OUT16);
632 sb_cmd(sb, ch->spd >> 8);
633 sb_cmd(sb, ch->spd & 0xff);
635 /* play format, length */
636 v = DSP_F16_AUTO | DSP_F16_FIFO_ON | DSP_F16_DAC;
637 v |= (ch->fmt & AFMT_16BIT)? DSP_DMA16 : DSP_DMA8;
640 v = (AFMT_CHANNEL(ch->fmt) > 1)? DSP_F16_STEREO : 0;
641 v |= (ch->fmt & AFMT_SIGNED)? DSP_F16_SIGNED : 0;
643 sndbuf_dma(ch->buffer, PCMTRIG_START);
644 sb->bd_flags |= BD_F_DMARUN;
650 if (ch->fmt & AFMT_16BIT)
655 RANGE(ch->spd, 5000, 45000);
656 sb_cmd(sb, DSP_CMD_IN16);
657 sb_cmd(sb, ch->spd >> 8);
658 sb_cmd(sb, ch->spd & 0xff);
660 /* record format, length */
661 v = DSP_F16_AUTO | DSP_F16_FIFO_ON | DSP_F16_ADC;
662 v |= (ch->fmt & AFMT_16BIT)? DSP_DMA16 : DSP_DMA8;
665 v = (AFMT_CHANNEL(ch->fmt) > 1)? DSP_F16_STEREO : 0;
666 v |= (ch->fmt & AFMT_SIGNED)? DSP_F16_SIGNED : 0;
668 sndbuf_dma(ch->buffer, PCMTRIG_START);
669 sb->bd_flags |= BD_F_DMARUN2;
676 /* channel interface */
678 sb16chan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
680 struct sb_info *sb = devinfo;
681 struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch;
688 if (sndbuf_alloc(ch->buffer, sb->parent_dmat, 0, sb->bufsize) != 0)
695 sb16chan_setformat(kobj_t obj, void *data, u_int32_t format)
697 struct sb_chinfo *ch = data;
698 struct sb_info *sb = ch->parent;
702 sb->prio16 = (ch->fmt & AFMT_16BIT)? 1 : 0;
708 sb16chan_setspeed(kobj_t obj, void *data, u_int32_t speed)
710 struct sb_chinfo *ch = data;
717 sb16chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
719 struct sb_chinfo *ch = data;
721 ch->blksz = blocksize;
726 sb16chan_trigger(kobj_t obj, void *data, int go)
728 struct sb_chinfo *ch = data;
729 struct sb_info *sb = ch->parent;
731 if (!PCMTRIG_COMMON(go))
734 if (go == PCMTRIG_START)
745 sb16chan_getptr(kobj_t obj, void *data)
747 struct sb_chinfo *ch = data;
749 return sndbuf_dmaptr(ch->buffer);
752 static struct pcmchan_caps *
753 sb16chan_getcaps(kobj_t obj, void *data)
755 struct sb_chinfo *ch = data;
756 struct sb_info *sb = ch->parent;
758 if ((sb->prio == 0) || (sb->prio == ch->dir))
761 return sb->prio16? &sb16_caps8 : &sb16_caps16;
765 sb16chan_resetdone(kobj_t obj, void *data)
767 struct sb_chinfo *ch = data;
768 struct sb_info *sb = ch->parent;
775 static kobj_method_t sb16chan_methods[] = {
776 KOBJMETHOD(channel_init, sb16chan_init),
777 KOBJMETHOD(channel_resetdone, sb16chan_resetdone),
778 KOBJMETHOD(channel_setformat, sb16chan_setformat),
779 KOBJMETHOD(channel_setspeed, sb16chan_setspeed),
780 KOBJMETHOD(channel_setblocksize, sb16chan_setblocksize),
781 KOBJMETHOD(channel_trigger, sb16chan_trigger),
782 KOBJMETHOD(channel_getptr, sb16chan_getptr),
783 KOBJMETHOD(channel_getcaps, sb16chan_getcaps),
786 CHANNEL_DECLARE(sb16chan);
788 /************************************************************/
791 sb16_probe(device_t dev)
794 uintptr_t func, ver, r, f;
796 /* The parent device has already been probed. */
797 r = BUS_READ_IVAR(device_get_parent(dev), dev, 0, &func);
801 r = BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
802 f = (ver & 0xffff0000) >> 16;
805 snprintf(buf, sizeof buf, "SB16 DSP %d.%02d%s", (int) ver >> 8, (int) ver & 0xff,
806 (f & BD_F_SB16X)? " (ViBRA16X)" : "");
807 device_set_desc_copy(dev, buf);
814 sb16_attach(device_t dev)
818 char status[SND_STATUSLEN], status2[SND_STATUSLEN];
820 sb = malloc(sizeof(*sb), M_DEVBUF, M_WAITOK | M_ZERO);
821 sb->parent_dev = device_get_parent(dev);
822 BUS_READ_IVAR(sb->parent_dev, dev, 1, &ver);
823 sb->bd_id = ver & 0x0000ffff;
824 sb->bd_flags = (ver & 0xffff0000) >> 16;
825 sb->bufsize = pcm_getbuffersize(dev, 4096, SB16_BUFFSIZE, 65536);
827 if (sb16_alloc_resources(sb, dev))
830 if (sb_reset_dsp(sb)) {
835 if (mixer_init(dev, &sb16mix_mixer_class, sb))
837 if (snd_setup_intr(dev, sb->irq, 0, sb_intr, sb, &sb->ih))
840 if (sb->bd_flags & BD_F_SB16X)
841 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
845 if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev), /*alignment*/2,
847 /*lowaddr*/BUS_SPACE_MAXADDR_24BIT,
848 /*highaddr*/BUS_SPACE_MAXADDR,
849 /*filter*/NULL, /*filterarg*/NULL,
850 /*maxsize*/sb->bufsize, /*nsegments*/1,
851 /*maxsegz*/0x3ffff, /*flags*/0,
852 /*lockfunc*/busdma_lock_mutex, /*lockarg*/&Giant,
853 &sb->parent_dmat) != 0) {
854 device_printf(dev, "unable to create dma tag\n");
858 if (!(pcm_getflags(dev) & SD_F_SIMPLEX))
859 snprintf(status2, SND_STATUSLEN, ":%ld", rman_get_start(sb->drq2));
863 snprintf(status, SND_STATUSLEN, "at io 0x%lx irq %ld drq %ld%s bufsz %u %s",
864 rman_get_start(sb->io_base), rman_get_start(sb->irq),
865 rman_get_start(sb->drq1), status2, sb->bufsize,
866 PCM_KLDSTRING(snd_sb16));
868 if (pcm_register(dev, sb, 1, 1))
870 pcm_addchan(dev, PCMDIR_REC, &sb16chan_class, sb);
871 pcm_addchan(dev, PCMDIR_PLAY, &sb16chan_class, sb);
873 pcm_setstatus(dev, status);
878 sb16_release_resources(sb, dev);
883 sb16_detach(device_t dev)
888 r = pcm_unregister(dev);
892 sb = pcm_getdevinfo(dev);
893 sb16_release_resources(sb, dev);
897 static device_method_t sb16_methods[] = {
898 /* Device interface */
899 DEVMETHOD(device_probe, sb16_probe),
900 DEVMETHOD(device_attach, sb16_attach),
901 DEVMETHOD(device_detach, sb16_detach),
906 static driver_t sb16_driver = {
912 DRIVER_MODULE(snd_sb16, sbc, sb16_driver, pcm_devclass, 0, 0);
913 MODULE_DEPEND(snd_sb16, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
914 MODULE_DEPEND(snd_sb16, snd_sbc, 1, 1, 1);
915 MODULE_VERSION(snd_sb16, 1);