ics2101.c revision 1.1 1 /* $NetBSD: ics2101.c,v 1.1 1995/07/19 19:58:49 brezak Exp $ */
2 /*-
3 * Copyright (c) 1995 John T. Kohl. All Rights Reserved.
4 * Copyright (c) 1994 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Ken Hornstein.
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 University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * $Id: ics2101.c,v 1.1 1995/07/19 19:58:49 brezak Exp $
39 */
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/errno.h>
44 #include <sys/ioctl.h>
45 #include <sys/syslog.h>
46 #include <sys/device.h>
47 #include <sys/proc.h>
48 #include <sys/buf.h>
49
50 #include <machine/cpu.h>
51 #include <machine/pio.h>
52
53 #include <sys/audioio.h>
54 #include <dev/audio_if.h>
55
56 #include <dev/isa/isavar.h>
57 #include <dev/isa/isadmavar.h>
58
59 #include <dev/ic/ics2101reg.h>
60 #include <dev/isa/ics2101var.h>
61
62
63 #define ICS_VALUE 0x01
64 #define ICS_MUTE 0x02
65 #define ICS_MUTE_MUTED 0x04
66
67 /* convert from [AUDIO_MIN_GAIN,AUDIO_MAX_GAIN] (0,255) to
68 [ICSMIX_MAX_ATTN,ICSMIX_MIN_ATTN] (0,127) */
69
70 #define cvt_value(val) ((val) >> 1)
71
72 /*
73 * Program one channel of the ICS mixer
74 */
75
76
77 static void
78 ics2101_mix_doit(sc, chan, side, value, flags)
79 struct ics2101_softc *sc;
80 unsigned int chan, side, value, flags;
81 {
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 register unsigned char ctrl_addr;
85 register unsigned char attn_addr;
86 register 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 outb(sc->sc_selio, ctrl_addr);
131 outb(sc->sc_dataio, normal);
132
133 outb(sc->sc_selio, attn_addr);
134 outb(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