ics2101.c revision 1.8 1 /* $NetBSD: ics2101.c,v 1.8 2000/03/30 12:45:33 augustss 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 FOUNDATION OR CONTRIBUTORS
30 * BE 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
50 #include <sys/audioio.h>
51 #include <dev/audio_if.h>
52
53 #include <dev/isa/isavar.h>
54 #include <dev/isa/isadmavar.h>
55
56 #include <dev/ic/ics2101reg.h>
57 #include <dev/isa/ics2101var.h>
58
59
60 #define ICS_VALUE 0x01
61 #define ICS_MUTE 0x02
62 #define ICS_MUTE_MUTED 0x04
63
64 /* convert from [AUDIO_MIN_GAIN,AUDIO_MAX_GAIN] (0,255) to
65 [ICSMIX_MAX_ATTN,ICSMIX_MIN_ATTN] (0,127) */
66
67 #define cvt_value(val) ((val) >> 1)
68
69 static void ics2101_mix_doit __P((struct ics2101_softc *, u_int, u_int, u_int,
70 u_int));
71 /*
72 * Program one channel of the ICS mixer
73 */
74
75
76 static void
77 ics2101_mix_doit(sc, chan, side, value, flags)
78 struct ics2101_softc *sc;
79 u_int chan, side, value, flags;
80 {
81 bus_space_tag_t iot = sc->sc_iot;
82 unsigned char flip_left[6] = {0x01, 0x01, 0x01, 0x02, 0x01, 0x02};
83 unsigned char flip_right[6] = {0x02, 0x02, 0x02, 0x01, 0x02, 0x01};
84 unsigned char ctrl_addr;
85 unsigned char attn_addr;
86 unsigned char normal;
87 int s;
88
89 if (chan < ICSMIX_CHAN_0 || chan > ICSMIX_CHAN_5)
90 return;
91 if (side != ICSMIX_LEFT && side != ICSMIX_RIGHT)
92 return;
93
94 if (flags & ICS_MUTE) {
95 value = cvt_value(sc->sc_setting[chan][side]);
96 sc->sc_mute[chan][side] = flags & ICS_MUTE_MUTED;
97 } else if (flags & ICS_VALUE) {
98 sc->sc_setting[chan][side] = value;
99 value = cvt_value(value);
100 if (value > ICSMIX_MIN_ATTN)
101 value = ICSMIX_MIN_ATTN;
102 } else
103 return;
104
105 ctrl_addr = chan << 3;
106 attn_addr = chan << 3;
107
108 if (side == ICSMIX_LEFT) {
109 ctrl_addr |= ICSMIX_CTRL_LEFT;
110 attn_addr |= ICSMIX_ATTN_LEFT;
111 if (sc->sc_mute[chan][side])
112 normal = 0x0;
113 else if (sc->sc_flags & ICS_FLIP)
114 normal = flip_left[chan];
115 else
116 normal = 0x01;
117 } else {
118 ctrl_addr |= ICSMIX_CTRL_RIGHT;
119 attn_addr |= ICSMIX_ATTN_RIGHT;
120 if (sc->sc_mute[chan][side])
121 normal = 0x0;
122 else if (sc->sc_flags & ICS_FLIP)
123 normal = flip_right[chan];
124 else
125 normal = 0x02;
126 }
127
128 s = splaudio();
129
130 bus_space_write_1(iot, sc->sc_selio_ioh, sc->sc_selio, ctrl_addr);
131 bus_space_write_1(iot, sc->sc_dataio_ioh, sc->sc_dataio, normal);
132
133 bus_space_write_1(iot, sc->sc_selio_ioh, sc->sc_selio, attn_addr);
134 bus_space_write_1(iot, sc->sc_dataio_ioh, sc->sc_dataio, (unsigned char) value);
135
136 splx(s);
137 }
138
139 void
140 ics2101_mix_mute(sc, chan, side, domute)
141 struct ics2101_softc *sc;
142 unsigned int chan, side, domute;
143 {
144 ics2101_mix_doit(sc, chan, side, 0,
145 domute ? ICS_MUTE|ICS_MUTE_MUTED : ICS_MUTE);
146 }
147
148 void
149 ics2101_mix_attenuate(sc, chan, side, value)
150 struct ics2101_softc *sc;
151 unsigned int chan, side, value;
152 {
153 ics2101_mix_doit(sc, chan, side, value, ICS_VALUE);
154 }
155