Deleted Added
full compact
sb16.c (68414) sb16.c (70134)
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * Copyright 1997,1998 Luigi Rizzo.
4 *
5 * Derived from files in the Voxware 3.5 distribution,
6 * Copyright by Hannu Savolainen 1994, under the same copyright
7 * conditions.
8 * All rights reserved.

--- 14 unchanged lines hidden (view full) ---

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
29 * SUCH DAMAGE.
30 *
1/*
2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
3 * Copyright 1997,1998 Luigi Rizzo.
4 *
5 * Derived from files in the Voxware 3.5 distribution,
6 * Copyright by Hannu Savolainen 1994, under the same copyright
7 * conditions.
8 * All rights reserved.

--- 14 unchanged lines hidden (view full) ---

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
29 * SUCH DAMAGE.
30 *
31 * $FreeBSD: head/sys/dev/sound/isa/sb16.c 68414 2000-11-07 00:38:59Z cg $
31 * $FreeBSD: head/sys/dev/sound/isa/sb16.c 70134 2000-12-18 01:36:41Z cg $
32 */
33
34#include <dev/sound/pcm/sound.h>
35
36#include <dev/sound/isa/sb.h>
37#include <dev/sound/chip.h>
38
32 */
33
34#include <dev/sound/pcm/sound.h>
35
36#include <dev/sound/isa/sb.h>
37#include <dev/sound/chip.h>
38
39#include "mixer_if.h"
40
39#define SB16_BUFFSIZE 4096
40#define PLAIN_SB16(x) ((((x)->bd_flags) & (BD_F_SB16|BD_F_SB16X)) == BD_F_SB16)
41
41#define SB16_BUFFSIZE 4096
42#define PLAIN_SB16(x) ((((x)->bd_flags) & (BD_F_SB16|BD_F_SB16X)) == BD_F_SB16)
43
42/* channel interface */
43static void *sb16chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir);
44static int sb16chan_setformat(void *data, u_int32_t format);
45static int sb16chan_setspeed(void *data, u_int32_t speed);
46static int sb16chan_setblocksize(void *data, u_int32_t blocksize);
47static int sb16chan_trigger(void *data, int go);
48static int sb16chan_getptr(void *data);
49static pcmchan_caps *sb16chan_getcaps(void *data);
50static int sb16chan_reset(void *data);
51static int sb16chan_resetdone(void *data);
52
53static u_int32_t sb16_fmt8[] = {
54 AFMT_U8,
55 AFMT_STEREO | AFMT_U8,
56 0
57};
58static pcmchan_caps sb16_caps8 = {5000, 45000, sb16_fmt8, 0};
59
60static u_int32_t sb16_fmt16[] = {

--- 7 unchanged lines hidden (view full) ---

68 AFMT_U8,
69 AFMT_STEREO | AFMT_U8,
70 AFMT_S16_LE,
71 AFMT_STEREO | AFMT_S16_LE,
72 0
73};
74static pcmchan_caps sb16x_caps = {5000, 49000, sb16x_fmt, 0};
75
44static u_int32_t sb16_fmt8[] = {
45 AFMT_U8,
46 AFMT_STEREO | AFMT_U8,
47 0
48};
49static pcmchan_caps sb16_caps8 = {5000, 45000, sb16_fmt8, 0};
50
51static u_int32_t sb16_fmt16[] = {

--- 7 unchanged lines hidden (view full) ---

59 AFMT_U8,
60 AFMT_STEREO | AFMT_U8,
61 AFMT_S16_LE,
62 AFMT_STEREO | AFMT_S16_LE,
63 0
64};
65static pcmchan_caps sb16x_caps = {5000, 49000, sb16x_fmt, 0};
66
76static pcm_channel sb_chantemplate = {
77 sb16chan_init,
78 NULL,
79 sb16chan_setformat,
80 sb16chan_setspeed,
81 sb16chan_setblocksize,
82 sb16chan_trigger,
83 sb16chan_getptr,
84 sb16chan_getcaps,
85 NULL, /* free */
86 sb16chan_reset, /* reset */
87 sb16chan_resetdone, /* resetdone */
88 NULL, /* nop3 */
89 NULL, /* nop4 */
90 NULL, /* nop5 */
91 NULL, /* nop6 */
92 NULL, /* nop7 */
93};
94
95struct sb_info;
96
97struct sb_chinfo {
98 struct sb_info *parent;
99 pcm_channel *channel;
100 snd_dbuf *buffer;
101 int dir, run, dch;
102 u_int32_t fmt, spd, blksz;

--- 10 unchanged lines hidden (view full) ---

113 int bd_id;
114 u_long bd_flags; /* board-specific flags */
115 int dl, dh, prio, prio16;
116 struct sb_chinfo pch, rch;
117};
118
119static int sb_rd(struct sb_info *sb, int reg);
120static void sb_wr(struct sb_info *sb, int reg, u_int8_t val);
67struct sb_info;
68
69struct sb_chinfo {
70 struct sb_info *parent;
71 pcm_channel *channel;
72 snd_dbuf *buffer;
73 int dir, run, dch;
74 u_int32_t fmt, spd, blksz;

--- 10 unchanged lines hidden (view full) ---

85 int bd_id;
86 u_long bd_flags; /* board-specific flags */
87 int dl, dh, prio, prio16;
88 struct sb_chinfo pch, rch;
89};
90
91static int sb_rd(struct sb_info *sb, int reg);
92static void sb_wr(struct sb_info *sb, int reg, u_int8_t val);
121static int sb_dspready(struct sb_info *sb);
122static int sb_cmd(struct sb_info *sb, u_char val);
123/* static int sb_cmd1(struct sb_info *sb, u_char cmd, int val); */
124static int sb_cmd2(struct sb_info *sb, u_char cmd, int val);
125static u_int sb_get_byte(struct sb_info *sb);
126static void sb_setmixer(struct sb_info *sb, u_int port, u_int value);
127static int sb_getmixer(struct sb_info *sb, u_int port);
128static int sb_reset_dsp(struct sb_info *sb);
129
130static void sb_intr(void *arg);
131
93static int sb_cmd(struct sb_info *sb, u_char val);
94/* static int sb_cmd1(struct sb_info *sb, u_char cmd, int val); */
95static int sb_cmd2(struct sb_info *sb, u_char cmd, int val);
96static u_int sb_get_byte(struct sb_info *sb);
97static void sb_setmixer(struct sb_info *sb, u_int port, u_int value);
98static int sb_getmixer(struct sb_info *sb, u_int port);
99static int sb_reset_dsp(struct sb_info *sb);
100
101static void sb_intr(void *arg);
102
132static int sb16mix_init(snd_mixer *m);
133static int sb16mix_set(snd_mixer *m, unsigned dev, unsigned left, unsigned right);
134static int sb16mix_setrecsrc(snd_mixer *m, u_int32_t src);
135
136static snd_mixer sb16_mixer = {
137 "SoundBlaster 16 mixer",
138 sb16mix_init,
139 NULL,
140 NULL,
141 sb16mix_set,
142 sb16mix_setrecsrc,
143};
144
145static devclass_t pcm_devclass;
146
147/*
148 * Common code for the midi and pcm functions
149 *
150 * sb_cmd write a single byte to the CMD port.
151 * sb_cmd1 write a CMD + 1 byte arg
152 * sb_cmd2 write a CMD + 2 byte arg

--- 20 unchanged lines hidden (view full) ---

173
174static void
175sb_wr(struct sb_info *sb, int reg, u_int8_t val)
176{
177 port_wr(sb->io_base, reg, val);
178}
179
180static int
103static devclass_t pcm_devclass;
104
105/*
106 * Common code for the midi and pcm functions
107 *
108 * sb_cmd write a single byte to the CMD port.
109 * sb_cmd1 write a CMD + 1 byte arg
110 * sb_cmd2 write a CMD + 2 byte arg

--- 20 unchanged lines hidden (view full) ---

131
132static void
133sb_wr(struct sb_info *sb, int reg, u_int8_t val)
134{
135 port_wr(sb->io_base, reg, val);
136}
137
138static int
181sb_dspready(struct sb_info *sb)
182{
183 return ((sb_rd(sb, SBDSP_STATUS) & 0x80) == 0);
184}
185
186static int
187sb_dspwr(struct sb_info *sb, u_char val)
188{
189 int i;
190
191 for (i = 0; i < 1000; i++) {
139sb_dspwr(struct sb_info *sb, u_char val)
140{
141 int i;
142
143 for (i = 0; i < 1000; i++) {
192 if (sb_dspready(sb)) {
193 sb_wr(sb, SBDSP_CMD, val);
194 return 1;
144 if ((sb_rd(sb, SBDSP_STATUS) & 0x80))
145 DELAY((i > 100)? 1000 : 10);
146 else {
147 sb_wr(sb, SBDSP_CMD, val);
148 return 1;
195 }
149 }
196 if (i > 10) DELAY((i > 100)? 1000 : 10);
197 }
198 printf("sb_dspwr(0x%02x) timed out.\n", val);
199 return 0;
200}
201
202static int
203sb_cmd(struct sb_info *sb, u_char val)
204{

--- 188 unchanged lines hidden (view full) ---

393 * However, since users like to have feedback, we only disable
394 * the mic -- permanently.
395 */
396 sb_setmixer(sb, SB16_OMASK, 0x1f & ~1);
397
398 return src;
399}
400
150 }
151 printf("sb_dspwr(0x%02x) timed out.\n", val);
152 return 0;
153}
154
155static int
156sb_cmd(struct sb_info *sb, u_char val)
157{

--- 188 unchanged lines hidden (view full) ---

346 * However, since users like to have feedback, we only disable
347 * the mic -- permanently.
348 */
349 sb_setmixer(sb, SB16_OMASK, 0x1f & ~1);
350
351 return src;
352}
353
354static kobj_method_t sb16mix_mixer_methods[] = {
355 KOBJMETHOD(mixer_init, sb16mix_init),
356 KOBJMETHOD(mixer_set, sb16mix_set),
357 KOBJMETHOD(mixer_setrecsrc, sb16mix_setrecsrc),
358 { 0, 0 }
359};
360MIXER_DECLARE(sb16mix_mixer);
361
401/************************************************************/
402
403static void
404sb16_release_resources(struct sb_info *sb, device_t dev)
405{
406 if (sb->irq) {
407 if (sb->ih)
408 bus_teardown_intr(dev, sb->irq, sb->ih);

--- 212 unchanged lines hidden (view full) ---

621 sb->bd_flags |= BD_F_DMARUN2;
622 }
623
624 return 0;
625}
626
627/* channel interface */
628static void *
362/************************************************************/
363
364static void
365sb16_release_resources(struct sb_info *sb, device_t dev)
366{
367 if (sb->irq) {
368 if (sb->ih)
369 bus_teardown_intr(dev, sb->irq, sb->ih);

--- 212 unchanged lines hidden (view full) ---

582 sb->bd_flags |= BD_F_DMARUN2;
583 }
584
585 return 0;
586}
587
588/* channel interface */
589static void *
629sb16chan_init(void *devinfo, snd_dbuf *b, pcm_channel *c, int dir)
590sb16chan_init(kobj_t obj, void *devinfo, snd_dbuf *b, pcm_channel *c, int dir)
630{
631 struct sb_info *sb = devinfo;
632 struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch;
633
634 ch->parent = sb;
635 ch->channel = c;
636 ch->buffer = b;
637 ch->buffer->bufsize = SB16_BUFFSIZE;
638 ch->dir = dir;
639
640 if (chn_allocbuf(ch->buffer, sb->parent_dmat) == -1)
641 return NULL;
642
643 return ch;
644}
645
646static int
591{
592 struct sb_info *sb = devinfo;
593 struct sb_chinfo *ch = (dir == PCMDIR_PLAY)? &sb->pch : &sb->rch;
594
595 ch->parent = sb;
596 ch->channel = c;
597 ch->buffer = b;
598 ch->buffer->bufsize = SB16_BUFFSIZE;
599 ch->dir = dir;
600
601 if (chn_allocbuf(ch->buffer, sb->parent_dmat) == -1)
602 return NULL;
603
604 return ch;
605}
606
607static int
647sb16chan_setformat(void *data, u_int32_t format)
608sb16chan_setformat(kobj_t obj, void *data, u_int32_t format)
648{
649 struct sb_chinfo *ch = data;
650 struct sb_info *sb = ch->parent;
651
652 ch->fmt = format;
653 sb->prio = ch->dir;
654 sb->prio16 = (ch->fmt & AFMT_16BIT)? 1 : 0;
655
656 return 0;
657}
658
659static int
609{
610 struct sb_chinfo *ch = data;
611 struct sb_info *sb = ch->parent;
612
613 ch->fmt = format;
614 sb->prio = ch->dir;
615 sb->prio16 = (ch->fmt & AFMT_16BIT)? 1 : 0;
616
617 return 0;
618}
619
620static int
660sb16chan_setspeed(void *data, u_int32_t speed)
621sb16chan_setspeed(kobj_t obj, void *data, u_int32_t speed)
661{
662 struct sb_chinfo *ch = data;
663
664 ch->spd = speed;
665 return speed;
666}
667
668static int
622{
623 struct sb_chinfo *ch = data;
624
625 ch->spd = speed;
626 return speed;
627}
628
629static int
669sb16chan_setblocksize(void *data, u_int32_t blocksize)
630sb16chan_setblocksize(kobj_t obj, void *data, u_int32_t blocksize)
670{
671 struct sb_chinfo *ch = data;
672
673 ch->blksz = blocksize;
674 return blocksize;
675}
676
677static int
631{
632 struct sb_chinfo *ch = data;
633
634 ch->blksz = blocksize;
635 return blocksize;
636}
637
638static int
678sb16chan_trigger(void *data, int go)
639sb16chan_trigger(kobj_t obj, void *data, int go)
679{
680 struct sb_chinfo *ch = data;
681 struct sb_info *sb = ch->parent;
682
683 if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
684 return 0;
685
686 if (go == PCMTRIG_START)
687 ch->run = 1;
688 else
689 ch->run = 0;
690
691 sb_setup(sb);
692
693 return 0;
694}
695
696static int
640{
641 struct sb_chinfo *ch = data;
642 struct sb_info *sb = ch->parent;
643
644 if (go == PCMTRIG_EMLDMAWR || go == PCMTRIG_EMLDMARD)
645 return 0;
646
647 if (go == PCMTRIG_START)
648 ch->run = 1;
649 else
650 ch->run = 0;
651
652 sb_setup(sb);
653
654 return 0;
655}
656
657static int
697sb16chan_getptr(void *data)
658sb16chan_getptr(kobj_t obj, void *data)
698{
699 struct sb_chinfo *ch = data;
700
701 return buf_isadmaptr(ch->buffer);
702}
703
704static pcmchan_caps *
659{
660 struct sb_chinfo *ch = data;
661
662 return buf_isadmaptr(ch->buffer);
663}
664
665static pcmchan_caps *
705sb16chan_getcaps(void *data)
666sb16chan_getcaps(kobj_t obj, void *data)
706{
707 struct sb_chinfo *ch = data;
708 struct sb_info *sb = ch->parent;
709
710 if ((sb->prio == 0) || (sb->prio == ch->dir))
711 return &sb16x_caps;
712 else
713 return sb->prio16? &sb16_caps8 : &sb16_caps16;
714}
715
716static int
667{
668 struct sb_chinfo *ch = data;
669 struct sb_info *sb = ch->parent;
670
671 if ((sb->prio == 0) || (sb->prio == ch->dir))
672 return &sb16x_caps;
673 else
674 return sb->prio16? &sb16_caps8 : &sb16_caps16;
675}
676
677static int
717sb16chan_reset(void *data)
678sb16chan_resetdone(kobj_t obj, void *data)
718{
679{
719/*
720 struct sb_chinfo *ch = data;
721 struct sb_info *sb = ch->parent;
680 struct sb_chinfo *ch = data;
681 struct sb_info *sb = ch->parent;
722*/
723 return 0;
724}
725
682
726static int
727sb16chan_resetdone(void *data)
728{
729 struct sb_chinfo *ch = data;
730 struct sb_info *sb = ch->parent;
731
732 sb->prio = 0;
733
734 return 0;
735}
736
683 sb->prio = 0;
684
685 return 0;
686}
687
688static kobj_method_t sb16chan_methods[] = {
689 KOBJMETHOD(channel_init, sb16chan_init),
690 KOBJMETHOD(channel_resetdone, sb16chan_resetdone),
691 KOBJMETHOD(channel_setformat, sb16chan_setformat),
692 KOBJMETHOD(channel_setspeed, sb16chan_setspeed),
693 KOBJMETHOD(channel_setblocksize, sb16chan_setblocksize),
694 KOBJMETHOD(channel_trigger, sb16chan_trigger),
695 KOBJMETHOD(channel_getptr, sb16chan_getptr),
696 KOBJMETHOD(channel_getcaps, sb16chan_getcaps),
697 { 0, 0 }
698};
699CHANNEL_DECLARE(sb16chan);
700
737/************************************************************/
738
739static int
740sb16_probe(device_t dev)
741{
742 char buf[64];
743 uintptr_t func, ver, r, f;
744

--- 30 unchanged lines hidden (view full) ---

775 BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
776 sb->bd_id = ver & 0x0000ffff;
777 sb->bd_flags = (ver & 0xffff0000) >> 16;
778
779 if (sb16_alloc_resources(sb, dev))
780 goto no;
781 if (sb_reset_dsp(sb))
782 goto no;
701/************************************************************/
702
703static int
704sb16_probe(device_t dev)
705{
706 char buf[64];
707 uintptr_t func, ver, r, f;
708

--- 30 unchanged lines hidden (view full) ---

739 BUS_READ_IVAR(device_get_parent(dev), dev, 1, &ver);
740 sb->bd_id = ver & 0x0000ffff;
741 sb->bd_flags = (ver & 0xffff0000) >> 16;
742
743 if (sb16_alloc_resources(sb, dev))
744 goto no;
745 if (sb_reset_dsp(sb))
746 goto no;
783 if (mixer_init(dev, &sb16_mixer, sb))
747 if (mixer_init(dev, &sb16mix_mixer_class, sb))
784 goto no;
785 if (bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &sb->ih))
786 goto no;
787
788 if (!sb->drq2 || (sb->bd_flags & BD_F_SB16X))
789 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
790
791 sb->dl = rman_get_start(sb->drq1);

--- 15 unchanged lines hidden (view full) ---

807 rman_get_start(sb->io_base), rman_get_start(sb->irq),
808 rman_get_start(sb->drq1));
809 if (sb->drq2)
810 snprintf(status + strlen(status), SND_STATUSLEN - strlen(status),
811 ":%ld", rman_get_start(sb->drq2));
812
813 if (pcm_register(dev, sb, 1, 1))
814 goto no;
748 goto no;
749 if (bus_setup_intr(dev, sb->irq, INTR_TYPE_TTY, sb_intr, sb, &sb->ih))
750 goto no;
751
752 if (!sb->drq2 || (sb->bd_flags & BD_F_SB16X))
753 pcm_setflags(dev, pcm_getflags(dev) | SD_F_SIMPLEX);
754
755 sb->dl = rman_get_start(sb->drq1);

--- 15 unchanged lines hidden (view full) ---

771 rman_get_start(sb->io_base), rman_get_start(sb->irq),
772 rman_get_start(sb->drq1));
773 if (sb->drq2)
774 snprintf(status + strlen(status), SND_STATUSLEN - strlen(status),
775 ":%ld", rman_get_start(sb->drq2));
776
777 if (pcm_register(dev, sb, 1, 1))
778 goto no;
815 pcm_addchan(dev, PCMDIR_REC, &sb_chantemplate, sb);
816 pcm_addchan(dev, PCMDIR_PLAY, &sb_chantemplate, sb);
779 pcm_addchan(dev, PCMDIR_REC, &sb16chan_class, sb);
780 pcm_addchan(dev, PCMDIR_PLAY, &sb16chan_class, sb);
817
818 pcm_setstatus(dev, status);
819
820 return 0;
821
822no:
823 sb16_release_resources(sb, dev);
824 return ENXIO;

--- 39 unchanged lines hidden ---
781
782 pcm_setstatus(dev, status);
783
784 return 0;
785
786no:
787 sb16_release_resources(sb, dev);
788 return ENXIO;

--- 39 unchanged lines hidden ---