ics2101.c revision 1.3 1 /* $NetBSD: ics2101.c,v 1.3 1996/02/05 02:22:11 jtc Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ken Hornstein and John Kohl.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/errno.h>
42 #include <sys/ioctl.h>
43 #include <sys/syslog.h>
44 #include <sys/device.h>
45 #include <sys/proc.h>
46 #include <sys/buf.h>
47
48 #include <machine/cpu.h>
49 #include <machine/pio.h>
50
51 #include <sys/audioio.h>
52 #include <dev/audio_if.h>
53
54 #include <dev/isa/isavar.h>
55 #include <dev/isa/isadmavar.h>
56
57 #include <dev/ic/ics2101reg.h>
58 #include <dev/isa/ics2101var.h>
59
60
61 #define ICS_VALUE 0x01
62 #define ICS_MUTE 0x02
63 #define ICS_MUTE_MUTED 0x04
64
65 /* convert from [AUDIO_MIN_GAIN,AUDIO_MAX_GAIN] (0,255) to
66 [ICSMIX_MAX_ATTN,ICSMIX_MIN_ATTN] (0,127) */
67
68 #define cvt_value(val) ((val) >> 1)
69
70 /*
71 * Program one channel of the ICS mixer
72 */
73
74
75 static void
76 ics2101_mix_doit(sc, chan, side, value, flags)
77 struct ics2101_softc *sc;
78 unsigned int chan, side, value, flags;
79 {
80 unsigned char flip_left[6] = {0x01, 0x01, 0x01, 0x02, 0x01, 0x02};
81 unsigned char flip_right[6] = {0x02, 0x02, 0x02, 0x01, 0x02, 0x01};
82 register unsigned char ctrl_addr;
83 register unsigned char attn_addr;
84 register unsigned char normal;
85 int s;
86
87 if (chan < ICSMIX_CHAN_0 || chan > ICSMIX_CHAN_5)
88 return;
89 if (side != ICSMIX_LEFT && side != ICSMIX_RIGHT)
90 return;
91
92 if (flags & ICS_MUTE) {
93 value = cvt_value(sc->sc_setting[chan][side]);
94 sc->sc_mute[chan][side] = flags & ICS_MUTE_MUTED;
95 } else if (flags & ICS_VALUE) {
96 sc->sc_setting[chan][side] = value;
97 value = cvt_value(value);
98 if (value > ICSMIX_MIN_ATTN)
99 value = ICSMIX_MIN_ATTN;
100 } else
101 return;
102
103 ctrl_addr = chan << 3;
104 attn_addr = chan << 3;
105
106 if (side == ICSMIX_LEFT) {
107 ctrl_addr |= ICSMIX_CTRL_LEFT;
108 attn_addr |= ICSMIX_ATTN_LEFT;
109 if (sc->sc_mute[chan][side])
110 normal = 0x0;
111 else if (sc->sc_flags & ICS_FLIP)
112 normal = flip_left[chan];
113 else
114 normal = 0x01;
115 } else {
116 ctrl_addr |= ICSMIX_CTRL_RIGHT;
117 attn_addr |= ICSMIX_ATTN_RIGHT;
118 if (sc->sc_mute[chan][side])
119 normal = 0x0;
120 else if (sc->sc_flags & ICS_FLIP)
121 normal = flip_right[chan];
122 else
123 normal = 0x02;
124 }
125
126 s = splaudio();
127
128 outb(sc->sc_selio, ctrl_addr);
129 outb(sc->sc_dataio, normal);
130
131 outb(sc->sc_selio, attn_addr);
132 outb(sc->sc_dataio, (unsigned char) value);
133
134 splx(s);
135 }
136
137 void
138 ics2101_mix_mute(sc, chan, side, domute)
139 struct ics2101_softc *sc;
140 unsigned int chan, side, domute;
141 {
142 ics2101_mix_doit(sc, chan, side, 0,
143 domute ? ICS_MUTE|ICS_MUTE_MUTED : ICS_MUTE);
144 }
145
146 void
147 ics2101_mix_attenuate(sc, chan, side, value)
148 struct ics2101_softc *sc;
149 unsigned int chan, side, value;
150 {
151 ics2101_mix_doit(sc, chan, side, value, ICS_VALUE);
152 }
153