Deleted Added
sdiff udiff text old ( 68414 ) new ( 70134 )
full compact
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 $
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#define SB16_BUFFSIZE 4096
40#define PLAIN_SB16(x) ((((x)->bd_flags) & (BD_F_SB16|BD_F_SB16X)) == BD_F_SB16)
41
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
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);
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
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
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++) {
192 if (sb_dspready(sb)) {
193 sb_wr(sb, SBDSP_CMD, val);
194 return 1;
195 }
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
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 *
629sb16chan_init(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
647sb16chan_setformat(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
660sb16chan_setspeed(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
669sb16chan_setblocksize(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
678sb16chan_trigger(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
697sb16chan_getptr(void *data)
698{
699 struct sb_chinfo *ch = data;
700
701 return buf_isadmaptr(ch->buffer);
702}
703
704static pcmchan_caps *
705sb16chan_getcaps(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
717sb16chan_reset(void *data)
718{
719/*
720 struct sb_chinfo *ch = data;
721 struct sb_info *sb = ch->parent;
722*/
723 return 0;
724}
725
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
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;
783 if (mixer_init(dev, &sb16_mixer, 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;
815 pcm_addchan(dev, PCMDIR_REC, &sb_chantemplate, sb);
816 pcm_addchan(dev, PCMDIR_PLAY, &sb_chantemplate, 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 ---