ac97.c revision 1.94 1 1.94 dsl /* $NetBSD: ac97.c,v 1.94 2012/06/02 21:36:44 dsl Exp $ */
2 1.14 thorpej /* $OpenBSD: ac97.c,v 1.8 2000/07/19 09:01:35 csapuntz Exp $ */
3 1.1 augustss
4 1.1 augustss /*
5 1.14 thorpej * Copyright (c) 1999, 2000 Constantine Sapuntzakis
6 1.1 augustss *
7 1.1 augustss * Author: Constantine Sapuntzakis <csapuntz (at) stanford.edu>
8 1.1 augustss *
9 1.1 augustss * Redistribution and use in source and binary forms, with or without
10 1.1 augustss * modification, are permitted provided that the following conditions
11 1.1 augustss * are met:
12 1.1 augustss * 1. Redistributions of source code must retain the above copyright
13 1.1 augustss * notice, this list of conditions and the following disclaimer.
14 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 augustss * notice, this list of conditions and the following disclaimer in the
16 1.1 augustss * documentation and/or other materials provided with the distribution.
17 1.14 thorpej * 3. The name of the author may not be used to endorse or promote
18 1.14 thorpej * products derived from this software without specific prior written
19 1.14 thorpej * permission.
20 1.14 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
21 1.14 thorpej * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 1.14 thorpej * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.14 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
24 1.14 thorpej * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.14 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 1.14 thorpej * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 1.14 thorpej * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 1.14 thorpej * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.14 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30 1.14 thorpej * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31 1.14 thorpej * DAMAGE
32 1.1 augustss */
33 1.1 augustss
34 1.1 augustss /* Partially inspired by FreeBSD's sys/dev/pcm/ac97.c. It came with
35 1.1 augustss the following copyright */
36 1.1 augustss
37 1.1 augustss /*
38 1.1 augustss * Copyright (c) 1999 Cameron Grant <gandalf (at) vilnya.demon.co.uk>
39 1.1 augustss * All rights reserved.
40 1.1 augustss *
41 1.1 augustss * Redistribution and use in source and binary forms, with or without
42 1.1 augustss * modification, are permitted provided that the following conditions
43 1.1 augustss * are met:
44 1.1 augustss * 1. Redistributions of source code must retain the above copyright
45 1.1 augustss * notice, this list of conditions and the following disclaimer.
46 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
47 1.1 augustss * notice, this list of conditions and the following disclaimer in the
48 1.1 augustss * documentation and/or other materials provided with the distribution.
49 1.1 augustss *
50 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
51 1.1 augustss * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 1.1 augustss * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 1.1 augustss * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
54 1.1 augustss * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 1.1 augustss * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 1.1 augustss * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 1.1 augustss * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 1.1 augustss * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 1.1 augustss * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 1.1 augustss * SUCH DAMAGE.
61 1.1 augustss *
62 1.1 augustss * $FreeBSD$
63 1.1 augustss */
64 1.21 lukem
65 1.21 lukem #include <sys/cdefs.h>
66 1.94 dsl __KERNEL_RCSID(0, "$NetBSD: ac97.c,v 1.94 2012/06/02 21:36:44 dsl Exp $");
67 1.1 augustss
68 1.1 augustss #include <sys/param.h>
69 1.1 augustss #include <sys/systm.h>
70 1.1 augustss #include <sys/kernel.h>
71 1.1 augustss #include <sys/malloc.h>
72 1.1 augustss #include <sys/device.h>
73 1.68 jmcneill #include <sys/sysctl.h>
74 1.1 augustss
75 1.1 augustss #include <sys/audioio.h>
76 1.1 augustss #include <dev/audio_if.h>
77 1.10 thorpej
78 1.10 thorpej #include <dev/ic/ac97reg.h>
79 1.9 thorpej #include <dev/ic/ac97var.h>
80 1.1 augustss
81 1.50 kent struct ac97_softc;
82 1.50 kent struct ac97_source_info;
83 1.60 thorpej static int ac97_mixer_get_port(struct ac97_codec_if *, mixer_ctrl_t *);
84 1.60 thorpej static int ac97_mixer_set_port(struct ac97_codec_if *, mixer_ctrl_t *);
85 1.65 kent static void ac97_detach(struct ac97_codec_if *);
86 1.82 kent static void ac97_lock(struct ac97_codec_if *);
87 1.82 kent static void ac97_unlock(struct ac97_codec_if *);
88 1.60 thorpej static int ac97_query_devinfo(struct ac97_codec_if *, mixer_devinfo_t *);
89 1.60 thorpej static int ac97_get_portnum_by_name(struct ac97_codec_if *, const char *,
90 1.60 thorpej const char *, const char *);
91 1.60 thorpej static void ac97_restore_shadow(struct ac97_codec_if *);
92 1.66 kent static int ac97_set_rate(struct ac97_codec_if *, int, u_int *);
93 1.60 thorpej static void ac97_set_clock(struct ac97_codec_if *, unsigned int);
94 1.66 kent static uint16_t ac97_get_extcaps(struct ac97_codec_if *);
95 1.60 thorpej static int ac97_add_port(struct ac97_softc *,
96 1.60 thorpej const struct ac97_source_info *);
97 1.60 thorpej static int ac97_str_equal(const char *, const char *);
98 1.60 thorpej static int ac97_check_capability(struct ac97_softc *, int);
99 1.60 thorpej static void ac97_setup_source_info(struct ac97_softc *);
100 1.66 kent static void ac97_read(struct ac97_softc *, uint8_t, uint16_t *);
101 1.60 thorpej static void ac97_setup_defaults(struct ac97_softc *);
102 1.66 kent static int ac97_write(struct ac97_softc *, uint8_t, uint16_t);
103 1.60 thorpej
104 1.60 thorpej static void ac97_ad198x_init(struct ac97_softc *);
105 1.60 thorpej static void ac97_alc650_init(struct ac97_softc *);
106 1.91 kiyohara static void ac97_ucb1400_init(struct ac97_softc *);
107 1.60 thorpej static void ac97_vt1616_init(struct ac97_softc *);
108 1.50 kent
109 1.68 jmcneill static int ac97_modem_offhook_set(struct ac97_softc *, int, int);
110 1.68 jmcneill static int ac97_sysctl_verify(SYSCTLFN_ARGS);
111 1.68 jmcneill
112 1.33 kent #define Ac97Nphone "phone"
113 1.72 jmcneill #define Ac97Nline1 "line1"
114 1.72 jmcneill #define Ac97Nline2 "line2"
115 1.72 jmcneill #define Ac97Nhandset "handset"
116 1.33 kent
117 1.50 kent static const struct audio_mixer_enum
118 1.84 christos ac97_on_off = { 2, { { { AudioNoff, 0 } , 0 },
119 1.84 christos { { AudioNon, 0 } , 1 },
120 1.88 gmcgarry { { "", 0 } , 0 },
121 1.88 gmcgarry { { "", 0 } , 0 },
122 1.88 gmcgarry { { "", 0 } , 0 },
123 1.88 gmcgarry { { "", 0 } , 0 },
124 1.88 gmcgarry { { "", 0 } , 0 },
125 1.88 gmcgarry { { "", 0 } , 0 },
126 1.88 gmcgarry { { "", 0 } , 0 },
127 1.88 gmcgarry { { "", 0 } , 0 },
128 1.88 gmcgarry { { "", 0 } , 0 },
129 1.88 gmcgarry { { "", 0 } , 0 },
130 1.88 gmcgarry { { "", 0 } , 0 },
131 1.88 gmcgarry { { "", 0 } , 0 },
132 1.88 gmcgarry { { "", 0 } , 0 },
133 1.88 gmcgarry { { "", 0 } , 0 },
134 1.88 gmcgarry { { "", 0 } , 0 },
135 1.88 gmcgarry { { "", 0 } , 0 },
136 1.88 gmcgarry { { "", 0 } , 0 },
137 1.88 gmcgarry { { "", 0 } , 0 },
138 1.88 gmcgarry { { "", 0 } , 0 },
139 1.88 gmcgarry { { "", 0 } , 0 },
140 1.88 gmcgarry { { "", 0 } , 0 },
141 1.88 gmcgarry { { "", 0 } , 0 },
142 1.88 gmcgarry { { "", 0 } , 0 },
143 1.88 gmcgarry { { "", 0 } , 0 },
144 1.88 gmcgarry { { "", 0 } , 0 },
145 1.88 gmcgarry { { "", 0 } , 0 },
146 1.88 gmcgarry { { "", 0 } , 0 },
147 1.88 gmcgarry { { "", 0 } , 0 },
148 1.88 gmcgarry { { "", 0 } , 0 },
149 1.88 gmcgarry { { "", 0 } , 0 }, } };
150 1.50 kent
151 1.50 kent static const struct audio_mixer_enum
152 1.84 christos ac97_mic_select = { 2, { { { AudioNmicrophone "0", 0 }, 0 },
153 1.84 christos { { AudioNmicrophone "1", 0 }, 1 },
154 1.88 gmcgarry { { "", 0 } , 0 },
155 1.88 gmcgarry { { "", 0 } , 0 },
156 1.88 gmcgarry { { "", 0 } , 0 },
157 1.88 gmcgarry { { "", 0 } , 0 },
158 1.88 gmcgarry { { "", 0 } , 0 },
159 1.88 gmcgarry { { "", 0 } , 0 },
160 1.88 gmcgarry { { "", 0 } , 0 },
161 1.88 gmcgarry { { "", 0 } , 0 },
162 1.88 gmcgarry { { "", 0 } , 0 },
163 1.88 gmcgarry { { "", 0 } , 0 },
164 1.88 gmcgarry { { "", 0 } , 0 },
165 1.88 gmcgarry { { "", 0 } , 0 },
166 1.88 gmcgarry { { "", 0 } , 0 },
167 1.88 gmcgarry { { "", 0 } , 0 },
168 1.88 gmcgarry { { "", 0 } , 0 },
169 1.88 gmcgarry { { "", 0 } , 0 },
170 1.88 gmcgarry { { "", 0 } , 0 },
171 1.88 gmcgarry { { "", 0 } , 0 },
172 1.88 gmcgarry { { "", 0 } , 0 },
173 1.88 gmcgarry { { "", 0 } , 0 },
174 1.88 gmcgarry { { "", 0 } , 0 },
175 1.88 gmcgarry { { "", 0 } , 0 },
176 1.88 gmcgarry { { "", 0 } , 0 },
177 1.88 gmcgarry { { "", 0 } , 0 },
178 1.88 gmcgarry { { "", 0 } , 0 },
179 1.88 gmcgarry { { "", 0 } , 0 },
180 1.88 gmcgarry { { "", 0 } , 0 },
181 1.88 gmcgarry { { "", 0 } , 0 },
182 1.88 gmcgarry { { "", 0 } , 0 },
183 1.88 gmcgarry { { "", 0 } , 0 }, } };
184 1.50 kent
185 1.50 kent static const struct audio_mixer_enum
186 1.84 christos ac97_mono_select = { 2, { { { AudioNmixerout, 0 }, 0 },
187 1.84 christos { { AudioNmicrophone, 0 }, 1 },
188 1.88 gmcgarry { { "", 0 } , 0 },
189 1.88 gmcgarry { { "", 0 } , 0 },
190 1.88 gmcgarry { { "", 0 } , 0 },
191 1.88 gmcgarry { { "", 0 } , 0 },
192 1.88 gmcgarry { { "", 0 } , 0 },
193 1.88 gmcgarry { { "", 0 } , 0 },
194 1.88 gmcgarry { { "", 0 } , 0 },
195 1.88 gmcgarry { { "", 0 } , 0 },
196 1.88 gmcgarry { { "", 0 } , 0 },
197 1.88 gmcgarry { { "", 0 } , 0 },
198 1.88 gmcgarry { { "", 0 } , 0 },
199 1.88 gmcgarry { { "", 0 } , 0 },
200 1.88 gmcgarry { { "", 0 } , 0 },
201 1.88 gmcgarry { { "", 0 } , 0 },
202 1.88 gmcgarry { { "", 0 } , 0 },
203 1.88 gmcgarry { { "", 0 } , 0 },
204 1.88 gmcgarry { { "", 0 } , 0 },
205 1.88 gmcgarry { { "", 0 } , 0 },
206 1.88 gmcgarry { { "", 0 } , 0 },
207 1.88 gmcgarry { { "", 0 } , 0 },
208 1.88 gmcgarry { { "", 0 } , 0 },
209 1.88 gmcgarry { { "", 0 } , 0 },
210 1.88 gmcgarry { { "", 0 } , 0 },
211 1.88 gmcgarry { { "", 0 } , 0 },
212 1.88 gmcgarry { { "", 0 } , 0 },
213 1.88 gmcgarry { { "", 0 } , 0 },
214 1.88 gmcgarry { { "", 0 } , 0 },
215 1.88 gmcgarry { { "", 0 } , 0 },
216 1.88 gmcgarry { { "", 0 } , 0 },
217 1.88 gmcgarry { { "", 0 } , 0 }, } };
218 1.50 kent
219 1.50 kent static const struct audio_mixer_enum
220 1.84 christos ac97_source = { 8, { { { AudioNmicrophone, 0 } , 0 },
221 1.84 christos { { AudioNcd, 0 }, 1 },
222 1.84 christos { { AudioNvideo, 0 }, 2 },
223 1.84 christos { { AudioNaux, 0 }, 3 },
224 1.84 christos { { AudioNline, 0 }, 4 },
225 1.84 christos { { AudioNmixerout, 0 }, 5 },
226 1.84 christos { { AudioNmixerout AudioNmono, 0 }, 6 },
227 1.84 christos { { Ac97Nphone, 0 }, 7 },
228 1.88 gmcgarry { { "", 0 } , 0 },
229 1.88 gmcgarry { { "", 0 } , 0 },
230 1.88 gmcgarry { { "", 0 } , 0 },
231 1.88 gmcgarry { { "", 0 } , 0 },
232 1.88 gmcgarry { { "", 0 } , 0 },
233 1.88 gmcgarry { { "", 0 } , 0 },
234 1.88 gmcgarry { { "", 0 } , 0 },
235 1.88 gmcgarry { { "", 0 } , 0 },
236 1.88 gmcgarry { { "", 0 } , 0 },
237 1.88 gmcgarry { { "", 0 } , 0 },
238 1.88 gmcgarry { { "", 0 } , 0 },
239 1.88 gmcgarry { { "", 0 } , 0 },
240 1.88 gmcgarry { { "", 0 } , 0 },
241 1.88 gmcgarry { { "", 0 } , 0 },
242 1.88 gmcgarry { { "", 0 } , 0 },
243 1.88 gmcgarry { { "", 0 } , 0 },
244 1.88 gmcgarry { { "", 0 } , 0 },
245 1.88 gmcgarry { { "", 0 } , 0 },
246 1.88 gmcgarry { { "", 0 } , 0 },
247 1.88 gmcgarry { { "", 0 } , 0 },
248 1.88 gmcgarry { { "", 0 } , 0 },
249 1.88 gmcgarry { { "", 0 } , 0 },
250 1.88 gmcgarry { { "", 0 } , 0 },
251 1.88 gmcgarry { { "", 0 } , 0 }, } };
252 1.1 augustss
253 1.19 erh /*
254 1.36 kent * Due to different values for each source that uses these structures,
255 1.19 erh * the ac97_query_devinfo function sets delta in mixer_devinfo_t using
256 1.19 erh * ac97_source_info.bits.
257 1.19 erh */
258 1.50 kent static const struct audio_mixer_value
259 1.84 christos ac97_volume_stereo = { { AudioNvolume, 0 }, 2, 0 };
260 1.1 augustss
261 1.50 kent static const struct audio_mixer_value
262 1.84 christos ac97_volume_mono = { { AudioNvolume, 0 }, 1, 0 };
263 1.1 augustss
264 1.1 augustss #define WRAP(a) &a, sizeof(a)
265 1.1 augustss
266 1.69 jmcneill struct ac97_source_info {
267 1.18 jdolecek const char *class;
268 1.18 jdolecek const char *device;
269 1.18 jdolecek const char *qualifier;
270 1.33 kent
271 1.1 augustss int type;
272 1.18 jdolecek const void *info;
273 1.1 augustss int info_size;
274 1.1 augustss
275 1.66 kent uint8_t reg;
276 1.82 kent int32_t default_value;
277 1.83 kent unsigned bits:3;
278 1.83 kent unsigned ofs:4;
279 1.83 kent unsigned mute:1;
280 1.83 kent unsigned polarity:1; /* Does 0 == MAX or MIN */
281 1.83 kent unsigned checkbits:1;
282 1.33 kent enum {
283 1.33 kent CHECK_NONE = 0,
284 1.33 kent CHECK_SURROUND,
285 1.33 kent CHECK_CENTER,
286 1.33 kent CHECK_LFE,
287 1.33 kent CHECK_HEADPHONES,
288 1.33 kent CHECK_TONE,
289 1.33 kent CHECK_MIC,
290 1.33 kent CHECK_LOUDNESS,
291 1.69 jmcneill CHECK_3D,
292 1.69 jmcneill CHECK_LINE1,
293 1.69 jmcneill CHECK_LINE2,
294 1.82 kent CHECK_HANDSET,
295 1.82 kent CHECK_SPDIF
296 1.33 kent } req_feature;
297 1.1 augustss
298 1.1 augustss int prev;
299 1.33 kent int next;
300 1.1 augustss int mixer_class;
301 1.69 jmcneill };
302 1.69 jmcneill
303 1.69 jmcneill static const struct ac97_source_info audio_source_info[] = {
304 1.33 kent { AudioCinputs, NULL, NULL,
305 1.84 christos AUDIO_MIXER_CLASS, NULL, 0,
306 1.84 christos 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
307 1.84 christos { AudioCoutputs, NULL, 0,
308 1.84 christos AUDIO_MIXER_CLASS, NULL, 0,
309 1.84 christos 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
310 1.84 christos { AudioCrecord, NULL, 0,
311 1.84 christos AUDIO_MIXER_CLASS, NULL, 0,
312 1.84 christos 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
313 1.1 augustss /* Stereo master volume*/
314 1.84 christos { AudioCoutputs, AudioNmaster, 0,
315 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
316 1.84 christos AC97_REG_MASTER_VOLUME, 0x8000, 5, 0, 1, 0, 1, 0, 0, 0, 0,
317 1.1 augustss },
318 1.1 augustss /* Mono volume */
319 1.33 kent { AudioCoutputs, AudioNmono, NULL,
320 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
321 1.84 christos AC97_REG_MASTER_VOLUME_MONO, 0x8000, 6, 0, 1, 0, 1, 0, 0, 0, 0,
322 1.1 augustss },
323 1.33 kent { AudioCoutputs, AudioNmono, AudioNsource,
324 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_mono_select),
325 1.84 christos AC97_REG_GP, 0x0000, 1, 9, 0, 0, 0, 0, 0, 0, 0,
326 1.1 augustss },
327 1.1 augustss /* Headphone volume */
328 1.33 kent { AudioCoutputs, AudioNheadphone, NULL,
329 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
330 1.84 christos AC97_REG_HEADPHONE_VOLUME, 0x8000, 5, 0, 1, 0, 1, CHECK_HEADPHONES, 0, 0, 0,
331 1.33 kent },
332 1.33 kent /* Surround volume - logic hard coded for mute */
333 1.33 kent { AudioCoutputs, AudioNsurround, NULL,
334 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
335 1.84 christos AC97_REG_SURR_MASTER, 0x8080, 5, 0, 1, 0, 1, CHECK_SURROUND, 0, 0, 0
336 1.33 kent },
337 1.33 kent /* Center volume*/
338 1.33 kent { AudioCoutputs, AudioNcenter, NULL,
339 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
340 1.84 christos AC97_REG_CENTER_LFE_MASTER, 0x8080, 5, 0, 0, 0, 1, CHECK_CENTER, 0, 0, 0
341 1.33 kent },
342 1.33 kent { AudioCoutputs, AudioNcenter, AudioNmute,
343 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
344 1.84 christos AC97_REG_CENTER_LFE_MASTER, 0x8080, 1, 7, 0, 0, 0, CHECK_CENTER, 0, 0, 0
345 1.33 kent },
346 1.33 kent /* LFE volume*/
347 1.33 kent { AudioCoutputs, AudioNlfe, NULL,
348 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
349 1.84 christos AC97_REG_CENTER_LFE_MASTER, 0x8080, 5, 8, 0, 0, 1, CHECK_LFE, 0, 0, 0
350 1.33 kent },
351 1.33 kent { AudioCoutputs, AudioNlfe, AudioNmute,
352 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
353 1.84 christos AC97_REG_CENTER_LFE_MASTER, 0x8080, 1, 15, 0, 0, 0, CHECK_LFE, 0, 0, 0
354 1.1 augustss },
355 1.63 kent /* Tone - bass */
356 1.63 kent { AudioCoutputs, AudioNbass, NULL,
357 1.63 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
358 1.84 christos AC97_REG_MASTER_TONE, 0x0f0f, 4, 8, 0, 0, 0, CHECK_TONE, 0, 0, 0
359 1.63 kent },
360 1.63 kent /* Tone - treble */
361 1.63 kent { AudioCoutputs, AudioNtreble, NULL,
362 1.63 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
363 1.84 christos AC97_REG_MASTER_TONE, 0x0f0f, 4, 0, 0, 0, 0, CHECK_TONE, 0, 0, 0
364 1.1 augustss },
365 1.1 augustss /* PC Beep Volume */
366 1.33 kent { AudioCinputs, AudioNspeaker, NULL,
367 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
368 1.84 christos AC97_REG_PCBEEP_VOLUME, 0x0000, 4, 1, 1, 0, 0, 0, 0, 0, 0,
369 1.1 augustss },
370 1.33 kent
371 1.1 augustss /* Phone */
372 1.33 kent { AudioCinputs, Ac97Nphone, NULL,
373 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
374 1.84 christos AC97_REG_PHONE_VOLUME, 0x8008, 5, 0, 1, 0, 0, 0, 0, 0, 0,
375 1.1 augustss },
376 1.1 augustss /* Mic Volume */
377 1.33 kent { AudioCinputs, AudioNmicrophone, NULL,
378 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
379 1.84 christos AC97_REG_MIC_VOLUME, 0x8008, 5, 0, 1, 0, 0, 0, 0, 0, 0,
380 1.1 augustss },
381 1.33 kent { AudioCinputs, AudioNmicrophone, AudioNpreamp,
382 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
383 1.84 christos AC97_REG_MIC_VOLUME, 0x8008, 1, 6, 0, 0, 0, 0, 0, 0, 0,
384 1.1 augustss },
385 1.33 kent { AudioCinputs, AudioNmicrophone, AudioNsource,
386 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_mic_select),
387 1.84 christos AC97_REG_GP, 0x0000, 1, 8, 0, 0, 0, 0, 0, 0, 0,
388 1.1 augustss },
389 1.1 augustss /* Line in Volume */
390 1.33 kent { AudioCinputs, AudioNline, NULL,
391 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
392 1.84 christos AC97_REG_LINEIN_VOLUME, 0x8808, 5, 0, 1, 0, 0, 0, 0, 0, 0,
393 1.1 augustss },
394 1.1 augustss /* CD Volume */
395 1.33 kent { AudioCinputs, AudioNcd, NULL,
396 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
397 1.84 christos AC97_REG_CD_VOLUME, 0x8808, 5, 0, 1, 0, 0, 0, 0, 0, 0,
398 1.1 augustss },
399 1.1 augustss /* Video Volume */
400 1.33 kent { AudioCinputs, AudioNvideo, NULL,
401 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
402 1.84 christos AC97_REG_VIDEO_VOLUME, 0x8808, 5, 0, 1, 0, 0, 0, 0, 0, 0,
403 1.1 augustss },
404 1.1 augustss /* AUX volume */
405 1.33 kent { AudioCinputs, AudioNaux, NULL,
406 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
407 1.84 christos AC97_REG_AUX_VOLUME, 0x8808, 5, 0, 1, 0, 0, 0, 0, 0, 0,
408 1.1 augustss },
409 1.1 augustss /* PCM out volume */
410 1.33 kent { AudioCinputs, AudioNdac, NULL,
411 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
412 1.84 christos AC97_REG_PCMOUT_VOLUME, 0x8808, 5, 0, 1, 0, 0, 0, 0, 0, 0,
413 1.1 augustss },
414 1.1 augustss /* Record Source - some logic for this is hard coded - see below */
415 1.33 kent { AudioCrecord, AudioNsource, NULL,
416 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_source),
417 1.84 christos AC97_REG_RECORD_SELECT, 0x0000, 3, 0, 0, 0, 0, 0, 0, 0, 0,
418 1.1 augustss },
419 1.1 augustss /* Record Gain */
420 1.33 kent { AudioCrecord, AudioNvolume, NULL,
421 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
422 1.84 christos AC97_REG_RECORD_GAIN, 0x8000, 4, 0, 1, 1, 0, 0, 0, 0, 0,
423 1.1 augustss },
424 1.1 augustss /* Record Gain mic */
425 1.33 kent { AudioCrecord, AudioNmicrophone, NULL,
426 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
427 1.84 christos AC97_REG_RECORD_GAIN_MIC, 0x8000, 4, 0, 1, 1, 0, CHECK_MIC, 0, 0, 0
428 1.1 augustss },
429 1.1 augustss /* */
430 1.33 kent { AudioCoutputs, AudioNloudness, NULL,
431 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
432 1.84 christos AC97_REG_GP, 0x0000, 1, 12, 0, 0, 0, CHECK_LOUDNESS, 0, 0, 0
433 1.33 kent },
434 1.33 kent { AudioCoutputs, AudioNspatial, NULL,
435 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
436 1.84 christos AC97_REG_GP, 0x0000, 1, 13, 0, 1, 0, CHECK_3D, 0, 0, 0
437 1.33 kent },
438 1.33 kent { AudioCoutputs, AudioNspatial, "center",
439 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
440 1.84 christos AC97_REG_3D_CONTROL, 0x0000, 4, 8, 0, 1, 0, CHECK_3D, 0, 0, 0
441 1.33 kent },
442 1.33 kent { AudioCoutputs, AudioNspatial, "depth",
443 1.33 kent AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
444 1.84 christos AC97_REG_3D_CONTROL, 0x0000, 4, 0, 0, 1, 0, CHECK_3D, 0, 0, 0
445 1.1 augustss },
446 1.1 augustss
447 1.82 kent /* SPDIF */
448 1.82 kent { "spdif", NULL, NULL,
449 1.82 kent AUDIO_MIXER_CLASS, NULL, 0,
450 1.84 christos 0, 0, 0, 0, 0, 0, 0, CHECK_SPDIF, 0, 0, 0
451 1.84 christos },
452 1.82 kent { "spdif", "enable", NULL,
453 1.82 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
454 1.84 christos AC97_REG_EXT_AUDIO_CTRL, -1, 1, 2, 0, 0, 0, CHECK_SPDIF, 0, 0, 0
455 1.84 christos },
456 1.82 kent
457 1.1 augustss /* Missing features: Simulated Stereo, POP, Loopback mode */
458 1.60 thorpej };
459 1.1 augustss
460 1.69 jmcneill static const struct ac97_source_info modem_source_info[] = {
461 1.69 jmcneill /* Classes */
462 1.72 jmcneill { AudioCinputs, NULL, NULL,
463 1.84 christos AUDIO_MIXER_CLASS, NULL, 0,
464 1.84 christos 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
465 1.72 jmcneill { AudioCoutputs, NULL, NULL,
466 1.84 christos AUDIO_MIXER_CLASS, NULL, 0,
467 1.84 christos 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
468 1.82 kent { AudioCinputs, Ac97Nline1, NULL,
469 1.69 jmcneill AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
470 1.84 christos AC97_REG_LINE1_LEVEL, 0x8080, 4, 0, 0, 1, 0, CHECK_LINE1, 0, 0, 0
471 1.69 jmcneill },
472 1.72 jmcneill { AudioCoutputs, Ac97Nline1, NULL,
473 1.69 jmcneill AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
474 1.84 christos AC97_REG_LINE1_LEVEL, 0x8080, 4, 8, 0, 1, 0, CHECK_LINE1, 0, 0, 0
475 1.69 jmcneill },
476 1.72 jmcneill { AudioCinputs, Ac97Nline1, AudioNmute,
477 1.69 jmcneill AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
478 1.84 christos AC97_REG_LINE1_LEVEL, 0x8080, 1, 7, 0, 0, 0, CHECK_LINE1, 0, 0, 0
479 1.69 jmcneill },
480 1.72 jmcneill { AudioCoutputs, Ac97Nline1, AudioNmute,
481 1.69 jmcneill AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
482 1.84 christos AC97_REG_LINE1_LEVEL, 0x8080, 1, 15, 0, 0, 0, CHECK_LINE1, 0, 0, 0
483 1.69 jmcneill },
484 1.69 jmcneill };
485 1.69 jmcneill
486 1.69 jmcneill #define AUDIO_SOURCE_INFO_SIZE \
487 1.69 jmcneill (sizeof(audio_source_info)/sizeof(audio_source_info[0]))
488 1.69 jmcneill #define MODEM_SOURCE_INFO_SIZE \
489 1.69 jmcneill (sizeof(modem_source_info)/sizeof(modem_source_info[0]))
490 1.71 jmcneill #define SOURCE_INFO_SIZE(as) ((as)->type == AC97_CODEC_TYPE_MODEM ? \
491 1.82 kent MODEM_SOURCE_INFO_SIZE : AUDIO_SOURCE_INFO_SIZE)
492 1.1 augustss
493 1.1 augustss /*
494 1.85 alc * Check out http://www.intel.com/support/motherboards/desktop/sb/cs-025406.htm for
495 1.85 alc * AC'97 Component Specification
496 1.1 augustss */
497 1.1 augustss
498 1.1 augustss struct ac97_softc {
499 1.28 kent /* ac97_codec_if must be at the first of ac97_softc. */
500 1.14 thorpej struct ac97_codec_if codec_if;
501 1.1 augustss
502 1.14 thorpej struct ac97_host_if *host_if;
503 1.1 augustss
504 1.92 jmcneill kmutex_t *lock;
505 1.92 jmcneill
506 1.69 jmcneill #define AUDIO_MAX_SOURCES (2 * AUDIO_SOURCE_INFO_SIZE)
507 1.69 jmcneill #define MODEM_MAX_SOURCES (2 * MODEM_SOURCE_INFO_SIZE)
508 1.69 jmcneill struct ac97_source_info audio_source_info[AUDIO_MAX_SOURCES];
509 1.69 jmcneill struct ac97_source_info modem_source_info[MODEM_MAX_SOURCES];
510 1.69 jmcneill struct ac97_source_info *source_info;
511 1.1 augustss int num_source_info;
512 1.14 thorpej
513 1.14 thorpej enum ac97_host_flags host_flags;
514 1.28 kent unsigned int ac97_clock; /* usually 48000 */
515 1.28 kent #define AC97_STANDARD_CLOCK 48000U
516 1.74 scw uint16_t power_all;
517 1.80 jmcneill uint16_t power_reg; /* -> AC97_REG_POWER */
518 1.66 kent uint16_t caps; /* -> AC97_REG_RESET */
519 1.66 kent uint16_t ext_id; /* -> AC97_REG_EXT_AUDIO_ID */
520 1.67 jmcneill uint16_t ext_mid; /* -> AC97_REG_EXT_MODEM_ID */
521 1.66 kent uint16_t shadow_reg[128];
522 1.68 jmcneill
523 1.82 kent int lock_counter;
524 1.69 jmcneill int type;
525 1.69 jmcneill
526 1.68 jmcneill /* sysctl */
527 1.68 jmcneill struct sysctllog *log;
528 1.68 jmcneill int offhook_line1_mib;
529 1.68 jmcneill int offhook_line2_mib;
530 1.68 jmcneill int offhook_line1;
531 1.68 jmcneill int offhook_line2;
532 1.1 augustss };
533 1.1 augustss
534 1.60 thorpej static struct ac97_codec_if_vtbl ac97civ = {
535 1.28 kent ac97_mixer_get_port,
536 1.1 augustss ac97_mixer_set_port,
537 1.1 augustss ac97_query_devinfo,
538 1.14 thorpej ac97_get_portnum_by_name,
539 1.14 thorpej ac97_restore_shadow,
540 1.28 kent ac97_get_extcaps,
541 1.28 kent ac97_set_rate,
542 1.28 kent ac97_set_clock,
543 1.65 kent ac97_detach,
544 1.82 kent ac97_lock,
545 1.82 kent ac97_unlock,
546 1.1 augustss };
547 1.7 thorpej
548 1.7 thorpej static const struct ac97_codecid {
549 1.66 kent uint32_t id;
550 1.66 kent uint32_t mask;
551 1.7 thorpej const char *name;
552 1.33 kent void (*init)(struct ac97_softc *);
553 1.1 augustss } ac97codecid[] = {
554 1.36 kent /*
555 1.36 kent * Analog Devices SoundMAX
556 1.36 kent * http://www.soundmax.com/products/information/codecs.html
557 1.36 kent * http://www.analog.com/productSelection/pdf/AD1881A_0.pdf
558 1.36 kent * http://www.analog.com/productSelection/pdf/AD1885_0.pdf
559 1.44 kent * http://www.analog.com/UploadedFiles/Data_Sheets/206585810AD1980_0.pdf
560 1.36 kent * http://www.analog.com/productSelection/pdf/AD1981A_0.pdf
561 1.36 kent * http://www.analog.com/productSelection/pdf/AD1981B_0.pdf
562 1.48 kent * http://www.analog.com/UploadedFiles/Data_Sheets/180644528AD1985_0.pdf
563 1.36 kent */
564 1.31 kent { AC97_CODEC_ID('A', 'D', 'S', 3),
565 1.84 christos 0xffffffff, "Analog Devices AD1819B", NULL, },
566 1.34 kent { AC97_CODEC_ID('A', 'D', 'S', 0x40),
567 1.84 christos 0xffffffff, "Analog Devices AD1881", NULL, },
568 1.34 kent { AC97_CODEC_ID('A', 'D', 'S', 0x48),
569 1.84 christos 0xffffffff, "Analog Devices AD1881A", NULL, },
570 1.34 kent { AC97_CODEC_ID('A', 'D', 'S', 0x60),
571 1.84 christos 0xffffffff, "Analog Devices AD1885", NULL, },
572 1.34 kent { AC97_CODEC_ID('A', 'D', 'S', 0x61),
573 1.84 christos 0xffffffff, "Analog Devices AD1886", NULL, },
574 1.34 kent { AC97_CODEC_ID('A', 'D', 'S', 0x63),
575 1.84 christos 0xffffffff, "Analog Devices AD1886A", NULL, },
576 1.55 kent { AC97_CODEC_ID('A', 'D', 'S', 0x68),
577 1.55 kent 0xffffffff, "Analog Devices AD1888", ac97_ad198x_init },
578 1.38 matt { AC97_CODEC_ID('A', 'D', 'S', 0x70),
579 1.51 kent 0xffffffff, "Analog Devices AD1980", ac97_ad198x_init },
580 1.34 kent { AC97_CODEC_ID('A', 'D', 'S', 0x72),
581 1.84 christos 0xffffffff, "Analog Devices AD1981A", NULL, },
582 1.36 kent { AC97_CODEC_ID('A', 'D', 'S', 0x74),
583 1.84 christos 0xffffffff, "Analog Devices AD1981B", NULL, },
584 1.48 kent { AC97_CODEC_ID('A', 'D', 'S', 0x75),
585 1.51 kent 0xffffffff, "Analog Devices AD1985", ac97_ad198x_init },
586 1.33 kent { AC97_CODEC_ID('A', 'D', 'S', 0),
587 1.84 christos AC97_VENDOR_ID_MASK, "Analog Devices unknown", NULL, },
588 1.31 kent
589 1.33 kent /*
590 1.33 kent * Datasheets:
591 1.81 uebayasi * http://www.asahi-kasei.co.jp/akm/japanese/product/ak4543/ek4543.pdf
592 1.81 uebayasi * http://www.asahi-kasei.co.jp/akm/japanese/product/ak4544a/ek4544a.pdf
593 1.81 uebayasi * http://www.asahi-kasei.co.jp/akm/japanese/product/ak4545/ak4545_f00e.pdf
594 1.33 kent */
595 1.31 kent { AC97_CODEC_ID('A', 'K', 'M', 0),
596 1.84 christos 0xffffffff, "Asahi Kasei AK4540", NULL, },
597 1.33 kent { AC97_CODEC_ID('A', 'K', 'M', 1),
598 1.84 christos 0xffffffff, "Asahi Kasei AK4542", NULL, },
599 1.31 kent { AC97_CODEC_ID('A', 'K', 'M', 2),
600 1.84 christos 0xffffffff, "Asahi Kasei AK4541/AK4543", NULL, },
601 1.33 kent { AC97_CODEC_ID('A', 'K', 'M', 5),
602 1.84 christos 0xffffffff, "Asahi Kasei AK4544", NULL, },
603 1.33 kent { AC97_CODEC_ID('A', 'K', 'M', 6),
604 1.84 christos 0xffffffff, "Asahi Kasei AK4544A", NULL, },
605 1.33 kent { AC97_CODEC_ID('A', 'K', 'M', 7),
606 1.84 christos 0xffffffff, "Asahi Kasei AK4545", NULL, },
607 1.33 kent { AC97_CODEC_ID('A', 'K', 'M', 0),
608 1.84 christos AC97_VENDOR_ID_MASK, "Asahi Kasei unknown", NULL, },
609 1.31 kent
610 1.33 kent /*
611 1.33 kent * Realtek & Avance Logic
612 1.33 kent * http://www.realtek.com.tw/downloads/downloads1-3.aspx?lineid=5&famid=All&series=All&Spec=True
613 1.54 kent *
614 1.54 kent * ALC650 and ALC658 support VRA, but it supports only 8000, 11025,
615 1.54 kent * 12000, 16000, 22050, 24000, 32000, 44100, and 48000 Hz.
616 1.33 kent */
617 1.34 kent { AC97_CODEC_ID('A', 'L', 'C', 0x00),
618 1.84 christos 0xfffffff0, "Realtek RL5306", NULL, },
619 1.34 kent { AC97_CODEC_ID('A', 'L', 'C', 0x10),
620 1.84 christos 0xfffffff0, "Realtek RL5382", NULL, },
621 1.33 kent { AC97_CODEC_ID('A', 'L', 'C', 0x20),
622 1.84 christos 0xfffffff0, "Realtek RL5383/RL5522/ALC100", NULL, },
623 1.31 kent { AC97_CODEC_ID('A', 'L', 'G', 0x10),
624 1.84 christos 0xffffffff, "Avance Logic ALC200/ALC201", NULL, },
625 1.31 kent { AC97_CODEC_ID('A', 'L', 'G', 0x20),
626 1.54 kent 0xfffffff0, "Avance Logic ALC650", ac97_alc650_init },
627 1.31 kent { AC97_CODEC_ID('A', 'L', 'G', 0x30),
628 1.84 christos 0xffffffff, "Avance Logic ALC101", NULL, },
629 1.31 kent { AC97_CODEC_ID('A', 'L', 'G', 0x40),
630 1.84 christos 0xffffffff, "Avance Logic ALC202", NULL, },
631 1.31 kent { AC97_CODEC_ID('A', 'L', 'G', 0x50),
632 1.84 christos 0xffffffff, "Avance Logic ALC250", NULL, },
633 1.54 kent { AC97_CODEC_ID('A', 'L', 'G', 0x60),
634 1.84 christos 0xfffffff0, "Avance Logic ALC655", NULL, },
635 1.93 mbalmer { AC97_CODEC_ID('A', 'L', 'G', 0x70),
636 1.93 mbalmer 0xffffffff, "Avance Logic ALC203", NULL, },
637 1.54 kent { AC97_CODEC_ID('A', 'L', 'G', 0x80),
638 1.84 christos 0xfffffff0, "Avance Logic ALC658", NULL, },
639 1.54 kent { AC97_CODEC_ID('A', 'L', 'G', 0x90),
640 1.84 christos 0xfffffff0, "Avance Logic ALC850", NULL, },
641 1.33 kent { AC97_CODEC_ID('A', 'L', 'C', 0),
642 1.84 christos AC97_VENDOR_ID_MASK, "Realtek unknown", NULL, },
643 1.33 kent { AC97_CODEC_ID('A', 'L', 'G', 0),
644 1.84 christos AC97_VENDOR_ID_MASK, "Avance Logic unknown", NULL, },
645 1.31 kent
646 1.56 kent /**
647 1.56 kent * C-Media Electronics Inc.
648 1.56 kent * http://www.cmedia.com.tw/doc/CMI9739%206CH%20Audio%20Codec%20SPEC_Ver12.pdf
649 1.56 kent */
650 1.56 kent { AC97_CODEC_ID('C', 'M', 'I', 0x61),
651 1.84 christos 0xffffffff, "C-Media CMI9739", NULL, },
652 1.56 kent { AC97_CODEC_ID('C', 'M', 'I', 0),
653 1.84 christos AC97_VENDOR_ID_MASK, "C-Media unknown", NULL, },
654 1.56 kent
655 1.31 kent /* Cirrus Logic, Crystal series:
656 1.31 kent * 'C' 'R' 'Y' 0x0[0-7] - CS4297
657 1.31 kent * 0x1[0-7] - CS4297A
658 1.31 kent * 0x2[0-7] - CS4298
659 1.31 kent * 0x2[8-f] - CS4294
660 1.31 kent * 0x3[0-7] - CS4299
661 1.31 kent * 0x4[8-f] - CS4201
662 1.31 kent * 0x5[8-f] - CS4205
663 1.31 kent * 0x6[0-7] - CS4291
664 1.31 kent * 0x7[0-7] - CS4202
665 1.31 kent * Datasheets:
666 1.31 kent * http://www.cirrus.com/pubs/cs4297A-5.pdf?DocumentID=593
667 1.31 kent * http://www.cirrus.com/pubs/cs4294.pdf?DocumentID=32
668 1.31 kent * http://www.cirrus.com/pubs/cs4299-5.pdf?DocumentID=594
669 1.31 kent * http://www.cirrus.com/pubs/cs4201-2.pdf?DocumentID=492
670 1.31 kent * http://www.cirrus.com/pubs/cs4205-2.pdf?DocumentID=492
671 1.31 kent * http://www.cirrus.com/pubs/cs4202-1.pdf?DocumentID=852
672 1.31 kent */
673 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x00),
674 1.84 christos 0xfffffff8, "Crystal CS4297", NULL, },
675 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x10),
676 1.84 christos 0xfffffff8, "Crystal CS4297A", NULL, },
677 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x20),
678 1.84 christos 0xfffffff8, "Crystal CS4298", NULL, },
679 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x28),
680 1.84 christos 0xfffffff8, "Crystal CS4294", NULL, },
681 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x30),
682 1.84 christos 0xfffffff8, "Crystal CS4299", NULL, },
683 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x48),
684 1.84 christos 0xfffffff8, "Crystal CS4201", NULL, },
685 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x58),
686 1.84 christos 0xfffffff8, "Crystal CS4205", NULL, },
687 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x60),
688 1.84 christos 0xfffffff8, "Crystal CS4291", NULL, },
689 1.31 kent { AC97_CODEC_ID('C', 'R', 'Y', 0x70),
690 1.84 christos 0xfffffff8, "Crystal CS4202", NULL, },
691 1.33 kent { AC97_CODEC_ID('C', 'R', 'Y', 0),
692 1.84 christos AC97_VENDOR_ID_MASK, "Cirrus Logic unknown", NULL, },
693 1.33 kent
694 1.84 christos { 0x45838308, 0xffffffff, "ESS Technology ES1921", NULL, },
695 1.84 christos { 0x45838300, AC97_VENDOR_ID_MASK, "ESS Technology unknown", NULL, },
696 1.31 kent
697 1.34 kent { AC97_CODEC_ID('H', 'R', 'S', 0),
698 1.84 christos 0xffffffff, "Intersil HMP9701", NULL, },
699 1.34 kent { AC97_CODEC_ID('H', 'R', 'S', 0),
700 1.84 christos AC97_VENDOR_ID_MASK, "Intersil unknown", NULL, },
701 1.34 kent
702 1.35 kent /*
703 1.35 kent * IC Ensemble (VIA)
704 1.35 kent * http://www.viatech.com/en/datasheet/DS1616.pdf
705 1.35 kent */
706 1.34 kent { AC97_CODEC_ID('I', 'C', 'E', 0x01),
707 1.84 christos 0xffffffff, "ICEnsemble ICE1230/VT1611", NULL, },
708 1.34 kent { AC97_CODEC_ID('I', 'C', 'E', 0x11),
709 1.84 christos 0xffffffff, "ICEnsemble ICE1232/VT1611A", NULL, },
710 1.35 kent { AC97_CODEC_ID('I', 'C', 'E', 0x14),
711 1.84 christos 0xffffffff, "ICEnsemble ICE1232A", NULL, },
712 1.35 kent { AC97_CODEC_ID('I', 'C', 'E', 0x51),
713 1.35 kent 0xffffffff, "VIA Technologies VT1616", ac97_vt1616_init },
714 1.58 kent { AC97_CODEC_ID('I', 'C', 'E', 0x52),
715 1.58 kent 0xffffffff, "VIA Technologies VT1616i", ac97_vt1616_init },
716 1.34 kent { AC97_CODEC_ID('I', 'C', 'E', 0),
717 1.84 christos AC97_VENDOR_ID_MASK, "ICEnsemble/VIA unknown", NULL, },
718 1.34 kent
719 1.34 kent { AC97_CODEC_ID('N', 'S', 'C', 0),
720 1.84 christos 0xffffffff, "National Semiconductor LM454[03568]", NULL, },
721 1.31 kent { AC97_CODEC_ID('N', 'S', 'C', 49),
722 1.84 christos 0xffffffff, "National Semiconductor LM4549", NULL, },
723 1.33 kent { AC97_CODEC_ID('N', 'S', 'C', 0),
724 1.84 christos AC97_VENDOR_ID_MASK, "National Semiconductor unknown", NULL, },
725 1.41 bsh
726 1.41 bsh { AC97_CODEC_ID('P', 'S', 'C', 4),
727 1.91 kiyohara 0xffffffff, "Philips Semiconductor UCB1400", ac97_ucb1400_init, },
728 1.41 bsh { AC97_CODEC_ID('P', 'S', 'C', 0),
729 1.84 christos AC97_VENDOR_ID_MASK, "Philips Semiconductor unknown", NULL, },
730 1.33 kent
731 1.31 kent { AC97_CODEC_ID('S', 'I', 'L', 34),
732 1.84 christos 0xffffffff, "Silicon Laboratory Si3036", NULL, },
733 1.31 kent { AC97_CODEC_ID('S', 'I', 'L', 35),
734 1.84 christos 0xffffffff, "Silicon Laboratory Si3038", NULL, },
735 1.33 kent { AC97_CODEC_ID('S', 'I', 'L', 0),
736 1.84 christos AC97_VENDOR_ID_MASK, "Silicon Laboratory unknown", NULL, },
737 1.33 kent
738 1.31 kent { AC97_CODEC_ID('T', 'R', 'A', 2),
739 1.84 christos 0xffffffff, "TriTech TR28022", NULL, },
740 1.31 kent { AC97_CODEC_ID('T', 'R', 'A', 3),
741 1.84 christos 0xffffffff, "TriTech TR28023", NULL, },
742 1.31 kent { AC97_CODEC_ID('T', 'R', 'A', 6),
743 1.84 christos 0xffffffff, "TriTech TR28026", NULL, },
744 1.31 kent { AC97_CODEC_ID('T', 'R', 'A', 8),
745 1.84 christos 0xffffffff, "TriTech TR28028", NULL, },
746 1.31 kent { AC97_CODEC_ID('T', 'R', 'A', 35),
747 1.84 christos 0xffffffff, "TriTech TR28602", NULL, },
748 1.33 kent { AC97_CODEC_ID('T', 'R', 'A', 0),
749 1.84 christos AC97_VENDOR_ID_MASK, "TriTech unknown", NULL, },
750 1.33 kent
751 1.34 kent { AC97_CODEC_ID('T', 'X', 'N', 0x20),
752 1.84 christos 0xffffffff, "Texas Instruments TLC320AD9xC", NULL, },
753 1.34 kent { AC97_CODEC_ID('T', 'X', 'N', 0),
754 1.84 christos AC97_VENDOR_ID_MASK, "Texas Instruments unknown", NULL, },
755 1.34 kent
756 1.34 kent /*
757 1.34 kent * VIA
758 1.34 kent * http://www.viatech.com/en/multimedia/audio.jsp
759 1.34 kent */
760 1.34 kent { AC97_CODEC_ID('V', 'I', 'A', 0x61),
761 1.84 christos 0xffffffff, "VIA Technologies VT1612A", NULL, },
762 1.34 kent { AC97_CODEC_ID('V', 'I', 'A', 0),
763 1.84 christos AC97_VENDOR_ID_MASK, "VIA Technologies unknown", NULL, },
764 1.34 kent
765 1.34 kent { AC97_CODEC_ID('W', 'E', 'C', 1),
766 1.84 christos 0xffffffff, "Winbond W83971D", NULL, },
767 1.34 kent { AC97_CODEC_ID('W', 'E', 'C', 0),
768 1.84 christos AC97_VENDOR_ID_MASK, "Winbond unknown", NULL, },
769 1.34 kent
770 1.33 kent /*
771 1.33 kent * http://www.wolfsonmicro.com/product_list.asp?cid=64
772 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.56/WM9701A.pdf - 00
773 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.57/WM9703.pdf - 03
774 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.58/WM9704M.pdf - 04
775 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.59/WM9704Q.pdf - 04
776 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.184/WM9705_Rev34.pdf - 05
777 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.60/WM9707.pdf - 03
778 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.136/WM9708.pdf - 03
779 1.34 kent * http://www.wolfsonmicro.com/download.asp/did.243/WM9710.pdf - 05
780 1.33 kent */
781 1.31 kent { AC97_CODEC_ID('W', 'M', 'L', 0),
782 1.84 christos 0xffffffff, "Wolfson WM9701A", NULL, },
783 1.34 kent { AC97_CODEC_ID('W', 'M', 'L', 3),
784 1.84 christos 0xffffffff, "Wolfson WM9703/WM9707/WM9708", NULL, },
785 1.34 kent { AC97_CODEC_ID('W', 'M', 'L', 4),
786 1.84 christos 0xffffffff, "Wolfson WM9704", NULL, },
787 1.34 kent { AC97_CODEC_ID('W', 'M', 'L', 5),
788 1.84 christos 0xffffffff, "Wolfson WM9705/WM9710", NULL, },
789 1.33 kent { AC97_CODEC_ID('W', 'M', 'L', 0),
790 1.84 christos AC97_VENDOR_ID_MASK, "Wolfson unknown", NULL, },
791 1.33 kent
792 1.33 kent /*
793 1.33 kent * http://www.yamaha.co.jp/english/product/lsi/us/products/pcaudio.html
794 1.33 kent * Datasheets:
795 1.33 kent * http://www.yamaha.co.jp/english/product/lsi/us/products/pdf/4MF743A20.pdf
796 1.33 kent * http://www.yamaha.co.jp/english/product/lsi/us/products/pdf/4MF753A20.pdf
797 1.33 kent */
798 1.31 kent { AC97_CODEC_ID('Y', 'M', 'H', 0),
799 1.84 christos 0xffffffff, "Yamaha YMF743-S", NULL, },
800 1.31 kent { AC97_CODEC_ID('Y', 'M', 'H', 3),
801 1.84 christos 0xffffffff, "Yamaha YMF753-S", NULL, },
802 1.33 kent { AC97_CODEC_ID('Y', 'M', 'H', 0),
803 1.84 christos AC97_VENDOR_ID_MASK, "Yamaha unknown", NULL, },
804 1.33 kent
805 1.33 kent /*
806 1.53 mrg * http://www.sigmatel.com/products/technical_docs.htm
807 1.53 mrg * and
808 1.53 mrg * http://www.sigmatel.com/documents/c-major-brochure-9-0.pdf
809 1.33 kent */
810 1.84 christos { 0x83847600, 0xffffffff, "SigmaTel STAC9700", NULL, },
811 1.84 christos { 0x83847604, 0xffffffff, "SigmaTel STAC9701/3/4/5", NULL, },
812 1.84 christos { 0x83847605, 0xffffffff, "SigmaTel STAC9704", NULL, },
813 1.84 christos { 0x83847608, 0xffffffff, "SigmaTel STAC9708", NULL, },
814 1.84 christos { 0x83847609, 0xffffffff, "SigmaTel STAC9721/23", NULL, },
815 1.84 christos { 0x83847644, 0xffffffff, "SigmaTel STAC9744/45", NULL, },
816 1.84 christos { 0x83847650, 0xffffffff, "SigmaTel STAC9750/51", NULL, },
817 1.84 christos { 0x83847652, 0xffffffff, "SigmaTel STAC9752/53", NULL, },
818 1.84 christos { 0x83847656, 0xffffffff, "SigmaTel STAC9756/57", NULL, },
819 1.84 christos { 0x83847658, 0xffffffff, "SigmaTel STAC9758/59", NULL, },
820 1.84 christos { 0x83847666, 0xffffffff, "SigmaTel STAC9766/67", NULL, },
821 1.84 christos { 0x83847684, 0xffffffff, "SigmaTel STAC9783/84", NULL, },
822 1.84 christos { 0x83847600, AC97_VENDOR_ID_MASK, "SigmaTel unknown", NULL, },
823 1.33 kent
824 1.69 jmcneill /* Conexant AC'97 modems -- good luck finding datasheets! */
825 1.70 jmcneill { AC97_CODEC_ID('C', 'X', 'T', 33),
826 1.84 christos 0xffffffff, "Conexant HSD11246", NULL, },
827 1.69 jmcneill { AC97_CODEC_ID('C', 'X', 'T', 34),
828 1.84 christos 0xffffffff, "Conexant D480 MDC V.92 Modem", NULL, },
829 1.78 rpaulo { AC97_CODEC_ID('C', 'X', 'T', 48),
830 1.84 christos 0xffffffff, "Conexant CXT48", NULL, },
831 1.69 jmcneill { AC97_CODEC_ID('C', 'X', 'T', 0),
832 1.84 christos AC97_VENDOR_ID_MASK, "Conexant unknown", NULL, },
833 1.69 jmcneill
834 1.31 kent { 0,
835 1.84 christos 0, NULL, NULL, },
836 1.1 augustss };
837 1.1 augustss
838 1.18 jdolecek static const char * const ac97enhancement[] = {
839 1.2 soren "no 3D stereo",
840 1.1 augustss "Analog Devices Phat Stereo",
841 1.24 ichiro "Creative",
842 1.1 augustss "National Semi 3D",
843 1.1 augustss "Yamaha Ymersion",
844 1.1 augustss "BBE 3D",
845 1.24 ichiro "Crystal Semi 3D",
846 1.1 augustss "Qsound QXpander",
847 1.1 augustss "Spatializer 3D",
848 1.1 augustss "SRS 3D",
849 1.1 augustss "Platform Tech 3D",
850 1.1 augustss "AKM 3D",
851 1.1 augustss "Aureal",
852 1.1 augustss "AZTECH 3D",
853 1.1 augustss "Binaura 3D",
854 1.1 augustss "ESS Technology",
855 1.1 augustss "Harman International VMAx",
856 1.1 augustss "Nvidea 3D",
857 1.1 augustss "Philips Incredible Sound",
858 1.1 augustss "Texas Instruments' 3D",
859 1.1 augustss "VLSI Technology 3D",
860 1.1 augustss "TriTech 3D",
861 1.1 augustss "Realtek 3D",
862 1.1 augustss "Samsung 3D",
863 1.1 augustss "Wolfson Microelectronics 3D",
864 1.1 augustss "Delta Integration 3D",
865 1.1 augustss "SigmaTel 3D",
866 1.33 kent "KS Waves 3D",
867 1.1 augustss "Rockwell 3D",
868 1.1 augustss "Unknown 3D",
869 1.1 augustss "Unknown 3D",
870 1.1 augustss "Unknown 3D",
871 1.1 augustss };
872 1.1 augustss
873 1.18 jdolecek static const char * const ac97feature[] = {
874 1.27 kent "dedicated mic channel",
875 1.1 augustss "reserved",
876 1.1 augustss "tone",
877 1.1 augustss "simulated stereo",
878 1.1 augustss "headphone",
879 1.1 augustss "bass boost",
880 1.1 augustss "18 bit DAC",
881 1.1 augustss "20 bit DAC",
882 1.1 augustss "18 bit ADC",
883 1.1 augustss "20 bit ADC"
884 1.1 augustss };
885 1.1 augustss
886 1.1 augustss
887 1.1 augustss /* #define AC97_DEBUG 10 */
888 1.61 kent /* #define AC97_IO_DEBUG */
889 1.1 augustss
890 1.1 augustss #ifdef AUDIO_DEBUG
891 1.1 augustss #define DPRINTF(x) if (ac97debug) printf x
892 1.1 augustss #define DPRINTFN(n,x) if (ac97debug>(n)) printf x
893 1.1 augustss #ifdef AC97_DEBUG
894 1.1 augustss int ac97debug = AC97_DEBUG;
895 1.1 augustss #else
896 1.1 augustss int ac97debug = 0;
897 1.1 augustss #endif
898 1.1 augustss #else
899 1.1 augustss #define DPRINTF(x)
900 1.1 augustss #define DPRINTFN(n,x)
901 1.1 augustss #endif
902 1.1 augustss
903 1.61 kent #ifdef AC97_IO_DEBUG
904 1.61 kent static const char *ac97_register_names[0x80 / 2] = {
905 1.61 kent "RESET", "MASTER_VOLUME", "HEADPHONE_VOLUME", "MASTER_VOLUME_MONO",
906 1.61 kent "MASTER_TONE", "PCBEEP_VOLUME", "PHONE_VOLUME", "MIC_VOLUME",
907 1.61 kent "LINEIN_VOLUME", "CD_VOLUME", "VIDEO_VOLUME", "AUX_VOLUME",
908 1.61 kent "PCMOUT_VOLUME", "RECORD_SELECT", "RECORD_GATIN", "RECORD_GAIN_MIC",
909 1.61 kent "GP", "3D_CONTROL", "AUDIO_INT", "POWER",
910 1.61 kent "EXT_AUDIO_ID", "EXT_AUDIO_CTRL", "PCM_FRONT_DAC_RATE", "PCM_SURR_DAC_RATE",
911 1.61 kent "PCM_LFE_DAC_RATE", "PCM_LR_ADC_RATE", "PCM_MIC_ADC_RATE", "CENTER_LFE_MASTER",
912 1.61 kent "SURR_MASTER", "SPDIF_CTRL", "EXT_MODEM_ID", "EXT_MODEM_CTRL",
913 1.61 kent "LINE1_RATE", "LINE2_RATE", "HANDSET_RATE", "LINE1_LEVEL",
914 1.61 kent "LINE2_LEVEL", "HANDSET_LEVEL", "GPIO_PIN_CONFIG", "GPIO_PIN_POLARITY",
915 1.61 kent "GPIO_PIN_STICKY", "GPIO_PIN_WAKEUP", "GPIO_PIN_STATUS", "MISC_MODEM_CTRL",
916 1.61 kent "0x58", "VENDOR-5A", "VENDOR-5C", "VENDOR-5E",
917 1.61 kent "0x60", "0x62", "0x64", "0x66",
918 1.61 kent "0x68", "0x6a", "0x6c", "0x6e",
919 1.61 kent "VENDOR-70", "VENDOR-72", "VENDOR-74", "VENDOR-76",
920 1.61 kent "VENDOR-78", "VENDOR-7A", "VENDOR_ID1", "VENDOR_ID2"
921 1.61 kent };
922 1.61 kent #endif
923 1.61 kent
924 1.80 jmcneill /*
925 1.80 jmcneill * XXX Some cards have an inverted AC97_POWER_EAMP bit.
926 1.80 jmcneill * These cards will produce no sound unless AC97_HOST_INVERTED_EAMP is set.
927 1.80 jmcneill */
928 1.80 jmcneill
929 1.80 jmcneill #define POWER_EAMP_ON(as) ((as->host_flags & AC97_HOST_INVERTED_EAMP) \
930 1.80 jmcneill ? AC97_POWER_EAMP : 0)
931 1.80 jmcneill #define POWER_EAMP_OFF(as) ((as->host_flags & AC97_HOST_INVERTED_EAMP) \
932 1.80 jmcneill ? 0 : AC97_POWER_EAMP)
933 1.80 jmcneill
934 1.60 thorpej static void
935 1.66 kent ac97_read(struct ac97_softc *as, uint8_t reg, uint16_t *val)
936 1.14 thorpej {
937 1.92 jmcneill KASSERT(mutex_owned(as->lock));
938 1.92 jmcneill
939 1.14 thorpej if (as->host_flags & AC97_HOST_DONT_READ &&
940 1.14 thorpej (reg != AC97_REG_VENDOR_ID1 && reg != AC97_REG_VENDOR_ID2 &&
941 1.14 thorpej reg != AC97_REG_RESET)) {
942 1.14 thorpej *val = as->shadow_reg[reg >> 1];
943 1.14 thorpej return;
944 1.14 thorpej }
945 1.14 thorpej
946 1.39 simonb if (as->host_if->read(as->host_if->arg, reg, val)) {
947 1.14 thorpej *val = as->shadow_reg[reg >> 1];
948 1.14 thorpej }
949 1.14 thorpej }
950 1.14 thorpej
951 1.60 thorpej static int
952 1.66 kent ac97_write(struct ac97_softc *as, uint8_t reg, uint16_t val)
953 1.14 thorpej {
954 1.92 jmcneill KASSERT(mutex_owned(as->lock));
955 1.92 jmcneill
956 1.61 kent #ifndef AC97_IO_DEBUG
957 1.14 thorpej as->shadow_reg[reg >> 1] = val;
958 1.50 kent return as->host_if->write(as->host_if->arg, reg, val);
959 1.61 kent #else
960 1.61 kent int ret;
961 1.61 kent uint16_t actual;
962 1.61 kent
963 1.61 kent as->shadow_reg[reg >> 1] = val;
964 1.61 kent ret = as->host_if->write(as->host_if->arg, reg, val);
965 1.61 kent as->host_if->read(as->host_if->arg, reg, &actual);
966 1.61 kent if (val != actual && reg < 0x80) {
967 1.61 kent printf("ac97_write: reg=%s, written=0x%04x, read=0x%04x\n",
968 1.61 kent ac97_register_names[reg / 2], val, actual);
969 1.61 kent }
970 1.61 kent return ret;
971 1.61 kent #endif
972 1.14 thorpej }
973 1.14 thorpej
974 1.60 thorpej static void
975 1.50 kent ac97_setup_defaults(struct ac97_softc *as)
976 1.14 thorpej {
977 1.14 thorpej int idx;
978 1.18 jdolecek const struct ac97_source_info *si;
979 1.14 thorpej
980 1.92 jmcneill KASSERT(mutex_owned(as->lock));
981 1.92 jmcneill
982 1.14 thorpej memset(as->shadow_reg, 0, sizeof(as->shadow_reg));
983 1.14 thorpej
984 1.69 jmcneill for (idx = 0; idx < AUDIO_SOURCE_INFO_SIZE; idx++) {
985 1.69 jmcneill si = &audio_source_info[idx];
986 1.82 kent if (si->default_value >= 0)
987 1.82 kent ac97_write(as, si->reg, si->default_value);
988 1.69 jmcneill }
989 1.69 jmcneill for (idx = 0; idx < MODEM_SOURCE_INFO_SIZE; idx++) {
990 1.69 jmcneill si = &modem_source_info[idx];
991 1.82 kent if (si->default_value >= 0)
992 1.82 kent ac97_write(as, si->reg, si->default_value);
993 1.14 thorpej }
994 1.14 thorpej }
995 1.14 thorpej
996 1.60 thorpej static void
997 1.50 kent ac97_restore_shadow(struct ac97_codec_if *self)
998 1.14 thorpej {
999 1.50 kent struct ac97_softc *as;
1000 1.50 kent const struct ac97_source_info *si;
1001 1.14 thorpej int idx;
1002 1.59 kent uint16_t val;
1003 1.14 thorpej
1004 1.50 kent as = (struct ac97_softc *) self;
1005 1.59 kent
1006 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1007 1.92 jmcneill
1008 1.74 scw if (as->type == AC97_CODEC_TYPE_AUDIO) {
1009 1.80 jmcneill /* restore AC97_REG_POWER */
1010 1.80 jmcneill ac97_write(as, AC97_REG_POWER, as->power_reg);
1011 1.74 scw /* make sure chip is fully operational */
1012 1.74 scw for (idx = 50000; idx >= 0; idx--) {
1013 1.74 scw ac97_read(as, AC97_REG_POWER, &val);
1014 1.74 scw if ((val & as->power_all) == as->power_all)
1015 1.74 scw break;
1016 1.74 scw DELAY(10);
1017 1.74 scw }
1018 1.74 scw
1019 1.74 scw /*
1020 1.74 scw * actually try changing a value!
1021 1.74 scw * The default value of AC97_REG_MASTER_VOLUME is 0x8000.
1022 1.74 scw */
1023 1.74 scw for (idx = 50000; idx >= 0; idx--) {
1024 1.74 scw ac97_write(as, AC97_REG_MASTER_VOLUME, 0x1010);
1025 1.74 scw ac97_read(as, AC97_REG_MASTER_VOLUME, &val);
1026 1.74 scw if (val == 0x1010)
1027 1.74 scw break;
1028 1.74 scw DELAY(10);
1029 1.74 scw }
1030 1.74 scw }
1031 1.64 kent
1032 1.69 jmcneill for (idx = 0; idx < SOURCE_INFO_SIZE(as); idx++) {
1033 1.71 jmcneill if (as->type == AC97_CODEC_TYPE_MODEM)
1034 1.69 jmcneill si = &modem_source_info[idx];
1035 1.69 jmcneill else
1036 1.69 jmcneill si = &audio_source_info[idx];
1037 1.59 kent /* don't "restore" to the reset reg! */
1038 1.59 kent if (si->reg != AC97_REG_RESET)
1039 1.59 kent ac97_write(as, si->reg, as->shadow_reg[si->reg >> 1]);
1040 1.42 scw }
1041 1.42 scw
1042 1.42 scw if (as->ext_id & (AC97_EXT_AUDIO_VRA | AC97_EXT_AUDIO_DRA
1043 1.42 scw | AC97_EXT_AUDIO_SPDIF | AC97_EXT_AUDIO_VRM
1044 1.42 scw | AC97_EXT_AUDIO_CDAC | AC97_EXT_AUDIO_SDAC
1045 1.42 scw | AC97_EXT_AUDIO_LDAC)) {
1046 1.42 scw ac97_write(as, AC97_REG_EXT_AUDIO_CTRL,
1047 1.42 scw as->shadow_reg[AC97_REG_EXT_AUDIO_CTRL >> 1]);
1048 1.14 thorpej }
1049 1.69 jmcneill if (as->ext_mid & (AC97_EXT_MODEM_LINE1 | AC97_EXT_MODEM_LINE2
1050 1.69 jmcneill | AC97_EXT_MODEM_HANDSET | AC97_EXT_MODEM_CID1
1051 1.69 jmcneill | AC97_EXT_MODEM_CID2 | AC97_EXT_MODEM_ID0
1052 1.69 jmcneill | AC97_EXT_MODEM_ID1)) {
1053 1.69 jmcneill ac97_write(as, AC97_REG_EXT_MODEM_CTRL,
1054 1.69 jmcneill as->shadow_reg[AC97_REG_EXT_MODEM_CTRL >> 1]);
1055 1.69 jmcneill }
1056 1.14 thorpej }
1057 1.1 augustss
1058 1.60 thorpej static int
1059 1.50 kent ac97_str_equal(const char *a, const char *b)
1060 1.1 augustss {
1061 1.50 kent return (a == b) || (a && b && (!strcmp(a, b)));
1062 1.1 augustss }
1063 1.1 augustss
1064 1.60 thorpej static int
1065 1.33 kent ac97_check_capability(struct ac97_softc *as, int check)
1066 1.33 kent {
1067 1.33 kent switch (check) {
1068 1.33 kent case CHECK_NONE:
1069 1.33 kent return 1;
1070 1.33 kent case CHECK_SURROUND:
1071 1.33 kent return as->ext_id & AC97_EXT_AUDIO_SDAC;
1072 1.33 kent case CHECK_CENTER:
1073 1.33 kent return as->ext_id & AC97_EXT_AUDIO_CDAC;
1074 1.33 kent case CHECK_LFE:
1075 1.33 kent return as->ext_id & AC97_EXT_AUDIO_LDAC;
1076 1.82 kent case CHECK_SPDIF:
1077 1.82 kent return as->ext_id & AC97_EXT_AUDIO_SPDIF;
1078 1.33 kent case CHECK_HEADPHONES:
1079 1.33 kent return as->caps & AC97_CAPS_HEADPHONES;
1080 1.33 kent case CHECK_TONE:
1081 1.33 kent return as->caps & AC97_CAPS_TONECTRL;
1082 1.33 kent case CHECK_MIC:
1083 1.33 kent return as->caps & AC97_CAPS_MICIN;
1084 1.33 kent case CHECK_LOUDNESS:
1085 1.33 kent return as->caps & AC97_CAPS_LOUDNESS;
1086 1.33 kent case CHECK_3D:
1087 1.33 kent return AC97_CAPS_ENHANCEMENT(as->caps) != 0;
1088 1.69 jmcneill case CHECK_LINE1:
1089 1.69 jmcneill return as->ext_mid & AC97_EXT_MODEM_LINE1;
1090 1.69 jmcneill case CHECK_LINE2:
1091 1.69 jmcneill return as->ext_mid & AC97_EXT_MODEM_LINE2;
1092 1.69 jmcneill case CHECK_HANDSET:
1093 1.69 jmcneill return as->ext_mid & AC97_EXT_MODEM_HANDSET;
1094 1.33 kent default:
1095 1.33 kent printf("%s: internal error: feature=%d\n", __func__, check);
1096 1.33 kent return 0;
1097 1.33 kent }
1098 1.33 kent }
1099 1.33 kent
1100 1.60 thorpej static void
1101 1.50 kent ac97_setup_source_info(struct ac97_softc *as)
1102 1.1 augustss {
1103 1.1 augustss int idx, ouridx;
1104 1.33 kent struct ac97_source_info *si, *si2;
1105 1.83 kent uint16_t value1, value2, value3;
1106 1.1 augustss
1107 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1108 1.92 jmcneill
1109 1.69 jmcneill for (idx = 0, ouridx = 0; idx < SOURCE_INFO_SIZE(as); idx++) {
1110 1.1 augustss si = &as->source_info[ouridx];
1111 1.71 jmcneill if (as->type == AC97_CODEC_TYPE_MODEM) {
1112 1.69 jmcneill memcpy(si, &modem_source_info[idx], sizeof(*si));
1113 1.69 jmcneill } else {
1114 1.69 jmcneill memcpy(si, &audio_source_info[idx], sizeof(*si));
1115 1.69 jmcneill }
1116 1.83 kent if (!ac97_check_capability(as, si->req_feature))
1117 1.83 kent continue;
1118 1.83 kent if (si->checkbits) {
1119 1.83 kent /* read the register value */
1120 1.83 kent ac97_read(as, si->reg, &value1);
1121 1.83 kent /* write 0b100000 */
1122 1.83 kent value2 = value1 & 0xffc0;
1123 1.83 kent value2 |= 0x20;
1124 1.83 kent ac97_write(as, si->reg, value2);
1125 1.83 kent /* verify */
1126 1.83 kent ac97_read(as, si->reg, &value3);
1127 1.83 kent if (value2 == value3) {
1128 1.83 kent si->bits = 6;
1129 1.83 kent } else {
1130 1.83 kent si->bits = 5;
1131 1.83 kent }
1132 1.83 kent DPRINTF(("%s: register=%02x bits=%d\n",
1133 1.83 kent __func__, si->reg, si->bits));
1134 1.83 kent ac97_write(as, si->reg, value1);
1135 1.83 kent }
1136 1.1 augustss
1137 1.1 augustss switch (si->type) {
1138 1.1 augustss case AUDIO_MIXER_CLASS:
1139 1.36 kent si->mixer_class = ouridx;
1140 1.1 augustss ouridx++;
1141 1.1 augustss break;
1142 1.1 augustss case AUDIO_MIXER_VALUE:
1143 1.1 augustss /* Todo - Test to see if it works */
1144 1.1 augustss ouridx++;
1145 1.1 augustss
1146 1.1 augustss /* Add an entry for mute, if necessary */
1147 1.1 augustss if (si->mute) {
1148 1.1 augustss si = &as->source_info[ouridx];
1149 1.71 jmcneill if (as->type == AC97_CODEC_TYPE_MODEM)
1150 1.69 jmcneill memcpy(si, &modem_source_info[idx],
1151 1.69 jmcneill sizeof(*si));
1152 1.69 jmcneill else
1153 1.69 jmcneill memcpy(si, &audio_source_info[idx],
1154 1.69 jmcneill sizeof(*si));
1155 1.1 augustss si->qualifier = AudioNmute;
1156 1.1 augustss si->type = AUDIO_MIXER_ENUM;
1157 1.1 augustss si->info = &ac97_on_off;
1158 1.1 augustss si->info_size = sizeof(ac97_on_off);
1159 1.1 augustss si->bits = 1;
1160 1.1 augustss si->ofs = 15;
1161 1.1 augustss si->mute = 0;
1162 1.1 augustss si->polarity = 0;
1163 1.1 augustss ouridx++;
1164 1.1 augustss }
1165 1.1 augustss break;
1166 1.1 augustss case AUDIO_MIXER_ENUM:
1167 1.1 augustss /* Todo - Test to see if it works */
1168 1.1 augustss ouridx++;
1169 1.1 augustss break;
1170 1.1 augustss default:
1171 1.40 thorpej aprint_error ("ac97: shouldn't get here\n");
1172 1.1 augustss break;
1173 1.1 augustss }
1174 1.1 augustss }
1175 1.1 augustss
1176 1.1 augustss as->num_source_info = ouridx;
1177 1.1 augustss
1178 1.1 augustss for (idx = 0; idx < as->num_source_info; idx++) {
1179 1.1 augustss int idx2, previdx;
1180 1.1 augustss
1181 1.1 augustss si = &as->source_info[idx];
1182 1.1 augustss
1183 1.1 augustss /* Find mixer class */
1184 1.1 augustss for (idx2 = 0; idx2 < as->num_source_info; idx2++) {
1185 1.1 augustss si2 = &as->source_info[idx2];
1186 1.1 augustss
1187 1.36 kent if (si2->type == AUDIO_MIXER_CLASS &&
1188 1.1 augustss ac97_str_equal(si->class,
1189 1.1 augustss si2->class)) {
1190 1.1 augustss si->mixer_class = idx2;
1191 1.1 augustss }
1192 1.1 augustss }
1193 1.1 augustss
1194 1.1 augustss
1195 1.1 augustss /* Setup prev and next pointers */
1196 1.1 augustss if (si->prev != 0)
1197 1.1 augustss continue;
1198 1.1 augustss
1199 1.1 augustss if (si->qualifier)
1200 1.1 augustss continue;
1201 1.1 augustss
1202 1.1 augustss si->prev = AUDIO_MIXER_LAST;
1203 1.1 augustss previdx = idx;
1204 1.1 augustss
1205 1.1 augustss for (idx2 = 0; idx2 < as->num_source_info; idx2++) {
1206 1.1 augustss if (idx2 == idx)
1207 1.1 augustss continue;
1208 1.1 augustss
1209 1.1 augustss si2 = &as->source_info[idx2];
1210 1.1 augustss
1211 1.1 augustss if (!si2->prev &&
1212 1.1 augustss ac97_str_equal(si->class, si2->class) &&
1213 1.1 augustss ac97_str_equal(si->device, si2->device)) {
1214 1.1 augustss as->source_info[previdx].next = idx2;
1215 1.1 augustss as->source_info[idx2].prev = previdx;
1216 1.36 kent
1217 1.1 augustss previdx = idx2;
1218 1.1 augustss }
1219 1.1 augustss }
1220 1.1 augustss
1221 1.1 augustss as->source_info[previdx].next = AUDIO_MIXER_LAST;
1222 1.1 augustss }
1223 1.1 augustss }
1224 1.1 augustss
1225 1.80 jmcneill /* backward compatibility */
1226 1.28 kent int
1227 1.92 jmcneill ac97_attach(struct ac97_host_if *host_if, device_t sc_dev, kmutex_t *lk)
1228 1.1 augustss {
1229 1.92 jmcneill return ac97_attach_type(host_if, sc_dev, AC97_CODEC_TYPE_AUDIO, lk);
1230 1.71 jmcneill }
1231 1.71 jmcneill
1232 1.71 jmcneill int
1233 1.92 jmcneill ac97_attach_type(struct ac97_host_if *host_if, device_t sc_dev, int type, kmutex_t *lk)
1234 1.71 jmcneill {
1235 1.1 augustss struct ac97_softc *as;
1236 1.1 augustss int error, i, j;
1237 1.59 kent uint32_t id;
1238 1.59 kent uint16_t id1, id2;
1239 1.59 kent uint16_t extstat, rate;
1240 1.59 kent uint16_t val;
1241 1.8 augustss mixer_ctrl_t ctl;
1242 1.33 kent void (*initfunc)(struct ac97_softc *);
1243 1.44 kent #define FLAGBUFLEN 140
1244 1.44 kent char flagbuf[FLAGBUFLEN];
1245 1.28 kent
1246 1.33 kent initfunc = NULL;
1247 1.23 tsutsui as = malloc(sizeof(struct ac97_softc), M_DEVBUF, M_WAITOK|M_ZERO);
1248 1.1 augustss
1249 1.2 soren if (as == NULL)
1250 1.50 kent return ENOMEM;
1251 1.14 thorpej
1252 1.14 thorpej as->codec_if.vtbl = &ac97civ;
1253 1.14 thorpej as->host_if = host_if;
1254 1.71 jmcneill as->type = type;
1255 1.92 jmcneill as->lock = lk;
1256 1.1 augustss
1257 1.14 thorpej if ((error = host_if->attach(host_if->arg, &as->codec_if))) {
1258 1.33 kent free(as, M_DEVBUF);
1259 1.50 kent return error;
1260 1.1 augustss }
1261 1.1 augustss
1262 1.92 jmcneill mutex_enter(as->lock);
1263 1.92 jmcneill
1264 1.80 jmcneill if (host_if->reset != NULL) {
1265 1.80 jmcneill if ((error = host_if->reset(host_if->arg))) {
1266 1.92 jmcneill mutex_exit(as->lock);
1267 1.80 jmcneill free(as, M_DEVBUF);
1268 1.80 jmcneill return error;
1269 1.80 jmcneill }
1270 1.62 kent }
1271 1.1 augustss
1272 1.14 thorpej if (host_if->flags)
1273 1.14 thorpej as->host_flags = host_if->flags(host_if->arg);
1274 1.74 scw
1275 1.74 scw /*
1276 1.74 scw * Assume codec has all four power bits.
1277 1.74 scw * XXXSCW: what to do for modems?
1278 1.74 scw */
1279 1.74 scw as->power_all = AC97_POWER_REF | AC97_POWER_ANL | AC97_POWER_DAC |
1280 1.74 scw AC97_POWER_ADC;
1281 1.72 jmcneill if (as->type == AC97_CODEC_TYPE_AUDIO) {
1282 1.72 jmcneill host_if->write(host_if->arg, AC97_REG_RESET, 0);
1283 1.74 scw
1284 1.74 scw /*
1285 1.74 scw * Power-up everything except the analogue mixer.
1286 1.74 scw * If this codec doesn't support analogue mixer power-down,
1287 1.74 scw * AC97_POWER_MIXER will read back as zero.
1288 1.74 scw */
1289 1.74 scw host_if->write(host_if->arg, AC97_REG_POWER, AC97_POWER_MIXER);
1290 1.74 scw ac97_read(as, AC97_REG_POWER, &val);
1291 1.74 scw if ((val & AC97_POWER_MIXER) == 0) {
1292 1.74 scw /* Codec doesn't support analogue mixer power-down */
1293 1.74 scw as->power_all &= ~AC97_POWER_ANL;
1294 1.74 scw }
1295 1.80 jmcneill host_if->write(host_if->arg, AC97_REG_POWER, POWER_EAMP_ON(as));
1296 1.1 augustss
1297 1.72 jmcneill for (i = 500000; i >= 0; i--) {
1298 1.72 jmcneill ac97_read(as, AC97_REG_POWER, &val);
1299 1.74 scw if ((val & as->power_all) == as->power_all)
1300 1.72 jmcneill break;
1301 1.72 jmcneill DELAY(1);
1302 1.72 jmcneill }
1303 1.80 jmcneill
1304 1.80 jmcneill /* save AC97_REG_POWER so that we can restore it later */
1305 1.80 jmcneill ac97_read(as, AC97_REG_POWER, &as->power_reg);
1306 1.72 jmcneill } else if (as->type == AC97_CODEC_TYPE_MODEM) {
1307 1.72 jmcneill host_if->write(host_if->arg, AC97_REG_EXT_MODEM_ID, 0);
1308 1.59 kent }
1309 1.59 kent
1310 1.14 thorpej ac97_setup_defaults(as);
1311 1.72 jmcneill if (as->type == AC97_CODEC_TYPE_AUDIO)
1312 1.72 jmcneill ac97_read(as, AC97_REG_RESET, &as->caps);
1313 1.15 thorpej ac97_read(as, AC97_REG_VENDOR_ID1, &id1);
1314 1.15 thorpej ac97_read(as, AC97_REG_VENDOR_ID2, &id2);
1315 1.1 augustss
1316 1.92 jmcneill mutex_exit(as->lock);
1317 1.92 jmcneill
1318 1.1 augustss id = (id1 << 16) | id2;
1319 1.87 cegger aprint_normal_dev(sc_dev, "ac97: ");
1320 1.2 soren
1321 1.2 soren for (i = 0; ; i++) {
1322 1.2 soren if (ac97codecid[i].id == 0) {
1323 1.4 augustss char pnp[4];
1324 1.93 mbalmer
1325 1.7 thorpej AC97_GET_CODEC_ID(id, pnp);
1326 1.4 augustss #define ISASCII(c) ((c) >= ' ' && (c) < 0x7f)
1327 1.4 augustss if (ISASCII(pnp[0]) && ISASCII(pnp[1]) &&
1328 1.4 augustss ISASCII(pnp[2]))
1329 1.40 thorpej aprint_normal("%c%c%c%d",
1330 1.40 thorpej pnp[0], pnp[1], pnp[2], pnp[3]);
1331 1.4 augustss else
1332 1.40 thorpej aprint_normal("unknown (0x%08x)", id);
1333 1.11 soren break;
1334 1.11 soren }
1335 1.31 kent if (ac97codecid[i].id == (id & ac97codecid[i].mask)) {
1336 1.40 thorpej aprint_normal("%s", ac97codecid[i].name);
1337 1.33 kent if (ac97codecid[i].mask == AC97_VENDOR_ID_MASK) {
1338 1.40 thorpej aprint_normal(" (0x%08x)", id);
1339 1.33 kent }
1340 1.33 kent initfunc = ac97codecid[i].init;
1341 1.2 soren break;
1342 1.2 soren }
1343 1.1 augustss }
1344 1.40 thorpej aprint_normal(" codec; ");
1345 1.1 augustss for (i = j = 0; i < 10; i++) {
1346 1.28 kent if (as->caps & (1 << i)) {
1347 1.50 kent aprint_normal("%s%s", j ? ", " : "", ac97feature[i]);
1348 1.1 augustss j++;
1349 1.1 augustss }
1350 1.1 augustss }
1351 1.40 thorpej aprint_normal("%s%s\n", j ? ", " : "",
1352 1.33 kent ac97enhancement[AC97_CAPS_ENHANCEMENT(as->caps)]);
1353 1.1 augustss
1354 1.28 kent as->ac97_clock = AC97_STANDARD_CLOCK;
1355 1.69 jmcneill
1356 1.92 jmcneill mutex_enter(as->lock);
1357 1.92 jmcneill
1358 1.72 jmcneill if (as->type == AC97_CODEC_TYPE_AUDIO) {
1359 1.72 jmcneill ac97_read(as, AC97_REG_EXT_AUDIO_ID, &as->ext_id);
1360 1.72 jmcneill if (as->ext_id != 0) {
1361 1.92 jmcneill mutex_exit(as->lock);
1362 1.92 jmcneill
1363 1.72 jmcneill /* Print capabilities */
1364 1.89 christos snprintb(flagbuf, sizeof(flagbuf),
1365 1.89 christos "\20\20SECONDARY10\17SECONDARY01"
1366 1.89 christos "\14AC97_23\13AC97_22\12AMAP\11LDAC\10SDAC"
1367 1.89 christos "\7CDAC\4VRM\3SPDIF\2DRA\1VRA", as->ext_id);
1368 1.87 cegger aprint_normal_dev(sc_dev, "ac97: ext id %s\n",
1369 1.72 jmcneill flagbuf);
1370 1.44 kent
1371 1.72 jmcneill /* Print unusual settings */
1372 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_DSA_MASK) {
1373 1.87 cegger aprint_normal_dev(sc_dev, "ac97: Slot assignment: ");
1374 1.72 jmcneill switch (as->ext_id & AC97_EXT_AUDIO_DSA_MASK) {
1375 1.72 jmcneill case AC97_EXT_AUDIO_DSA01:
1376 1.72 jmcneill aprint_normal("7&8, 6&9, 10&11.\n");
1377 1.72 jmcneill break;
1378 1.72 jmcneill case AC97_EXT_AUDIO_DSA10:
1379 1.72 jmcneill aprint_normal("6&9, 10&11, 3&4.\n");
1380 1.72 jmcneill break;
1381 1.72 jmcneill case AC97_EXT_AUDIO_DSA11:
1382 1.72 jmcneill aprint_normal("10&11, 3&4, 7&8.\n");
1383 1.72 jmcneill break;
1384 1.72 jmcneill }
1385 1.44 kent }
1386 1.80 jmcneill if (as->host_flags & AC97_HOST_INVERTED_EAMP) {
1387 1.87 cegger aprint_normal_dev(sc_dev, "ac97: using inverted "
1388 1.87 cegger "AC97_POWER_EAMP bit\n");
1389 1.80 jmcneill }
1390 1.27 kent
1391 1.92 jmcneill mutex_enter(as->lock);
1392 1.92 jmcneill
1393 1.72 jmcneill /* Enable and disable features */
1394 1.72 jmcneill ac97_read(as, AC97_REG_EXT_AUDIO_CTRL, &extstat);
1395 1.72 jmcneill extstat &= ~AC97_EXT_AUDIO_DRA;
1396 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_LDAC)
1397 1.72 jmcneill extstat |= AC97_EXT_AUDIO_LDAC;
1398 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_SDAC)
1399 1.72 jmcneill extstat |= AC97_EXT_AUDIO_SDAC;
1400 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_CDAC)
1401 1.72 jmcneill extstat |= AC97_EXT_AUDIO_CDAC;
1402 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_VRM)
1403 1.72 jmcneill extstat |= AC97_EXT_AUDIO_VRM;
1404 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_SPDIF) {
1405 1.72 jmcneill /* Output the same data as DAC to SPDIF output */
1406 1.72 jmcneill extstat &= ~AC97_EXT_AUDIO_SPSA_MASK;
1407 1.72 jmcneill extstat |= AC97_EXT_AUDIO_SPSA34;
1408 1.82 kent ac97_read(as, AC97_REG_SPDIF_CTRL, &val);
1409 1.82 kent val = (val & ~AC97_SPDIF_SPSR_MASK)
1410 1.82 kent | AC97_SPDIF_SPSR_48K;
1411 1.82 kent ac97_write(as, AC97_REG_SPDIF_CTRL, val);
1412 1.72 jmcneill }
1413 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_VRA)
1414 1.72 jmcneill extstat |= AC97_EXT_AUDIO_VRA;
1415 1.72 jmcneill ac97_write(as, AC97_REG_EXT_AUDIO_CTRL, extstat);
1416 1.72 jmcneill if (as->ext_id & AC97_EXT_AUDIO_VRA) {
1417 1.72 jmcneill /* VRA should be enabled. */
1418 1.72 jmcneill /* so it claims to do variable rate, let's make sure */
1419 1.72 jmcneill ac97_write(as, AC97_REG_PCM_FRONT_DAC_RATE,
1420 1.72 jmcneill 44100);
1421 1.72 jmcneill ac97_read(as, AC97_REG_PCM_FRONT_DAC_RATE,
1422 1.72 jmcneill &rate);
1423 1.72 jmcneill if (rate != 44100) {
1424 1.72 jmcneill /* We can't believe ext_id */
1425 1.72 jmcneill as->ext_id = 0;
1426 1.93 mbalmer aprint_normal_dev(sc_dev,
1427 1.87 cegger "Ignore these capabilities.\n");
1428 1.72 jmcneill }
1429 1.72 jmcneill /* restore the default value */
1430 1.72 jmcneill ac97_write(as, AC97_REG_PCM_FRONT_DAC_RATE,
1431 1.72 jmcneill AC97_SINGLE_RATE);
1432 1.28 kent }
1433 1.28 kent }
1434 1.72 jmcneill } else if (as->type == AC97_CODEC_TYPE_MODEM) {
1435 1.76 atatat const struct sysctlnode *node;
1436 1.76 atatat const struct sysctlnode *node_line1;
1437 1.76 atatat const struct sysctlnode *node_line2;
1438 1.75 christos uint16_t xrate = 8000;
1439 1.75 christos uint16_t xval, reg;
1440 1.68 jmcneill int err;
1441 1.67 jmcneill
1442 1.72 jmcneill ac97_read(as, AC97_REG_EXT_MODEM_ID, &as->ext_mid);
1443 1.92 jmcneill mutex_exit(as->lock);
1444 1.92 jmcneill
1445 1.72 jmcneill if (as->ext_mid == 0 || as->ext_mid == 0xffff) {
1446 1.87 cegger aprint_normal_dev(sc_dev, "no modem codec found\n");
1447 1.72 jmcneill return ENXIO;
1448 1.72 jmcneill }
1449 1.71 jmcneill as->type = AC97_CODEC_TYPE_MODEM;
1450 1.69 jmcneill
1451 1.67 jmcneill /* Print capabilities */
1452 1.89 christos snprintb(flagbuf, sizeof(flagbuf),
1453 1.89 christos "\20\5CID2\4CID1\3HANDSET\2LINE2\1LINE1", as->ext_mid);
1454 1.87 cegger aprint_normal_dev(sc_dev, "ac97: ext mid %s",
1455 1.67 jmcneill flagbuf);
1456 1.67 jmcneill aprint_normal(", %s codec\n",
1457 1.67 jmcneill (as->ext_mid & 0xc000) == 0 ?
1458 1.67 jmcneill "primary" : "secondary");
1459 1.67 jmcneill
1460 1.68 jmcneill /* Setup modem and sysctls */
1461 1.68 jmcneill err = sysctl_createv(&as->log, 0, NULL, NULL, 0, CTLTYPE_NODE,
1462 1.68 jmcneill "hw", NULL, NULL, 0, NULL, 0, CTL_HW,
1463 1.68 jmcneill CTL_EOL);
1464 1.68 jmcneill if (err != 0)
1465 1.72 jmcneill goto setup_modem;
1466 1.68 jmcneill err = sysctl_createv(&as->log, 0, NULL, &node, 0,
1467 1.87 cegger CTLTYPE_NODE, device_xname(sc_dev), NULL,
1468 1.68 jmcneill NULL, 0, NULL, 0, CTL_HW, CTL_CREATE,
1469 1.68 jmcneill CTL_EOL);
1470 1.68 jmcneill if (err != 0)
1471 1.72 jmcneill goto setup_modem;
1472 1.72 jmcneill setup_modem:
1473 1.92 jmcneill mutex_enter(as->lock);
1474 1.92 jmcneill
1475 1.72 jmcneill /* reset */
1476 1.72 jmcneill ac97_write(as, AC97_REG_EXT_MODEM_ID, 1);
1477 1.72 jmcneill
1478 1.72 jmcneill /* program rates */
1479 1.75 christos xval = 0xff00 & ~AC97_EXT_MODEM_CTRL_PRA;
1480 1.67 jmcneill if (as->ext_mid & AC97_EXT_MODEM_LINE1) {
1481 1.75 christos ac97_write(as, AC97_REG_LINE1_RATE, xrate);
1482 1.75 christos xval &= ~(AC97_EXT_MODEM_CTRL_PRC |
1483 1.72 jmcneill AC97_EXT_MODEM_CTRL_PRD);
1484 1.67 jmcneill }
1485 1.67 jmcneill if (as->ext_mid & AC97_EXT_MODEM_LINE2) {
1486 1.75 christos ac97_write(as, AC97_REG_LINE2_RATE, xrate);
1487 1.75 christos xval &= ~(AC97_EXT_MODEM_CTRL_PRE |
1488 1.72 jmcneill AC97_EXT_MODEM_CTRL_PRF);
1489 1.67 jmcneill }
1490 1.67 jmcneill if (as->ext_mid & AC97_EXT_MODEM_HANDSET) {
1491 1.75 christos ac97_write(as, AC97_REG_HANDSET_RATE, xrate);
1492 1.75 christos xval &= ~(AC97_EXT_MODEM_CTRL_PRG |
1493 1.72 jmcneill AC97_EXT_MODEM_CTRL_PRH);
1494 1.67 jmcneill }
1495 1.72 jmcneill
1496 1.72 jmcneill /* power-up everything */
1497 1.72 jmcneill ac97_write(as, AC97_REG_EXT_MODEM_CTRL, 0);
1498 1.73 jmcneill for (i = 5000; i >= 0; i--) {
1499 1.68 jmcneill ac97_read(as, AC97_REG_EXT_MODEM_CTRL, ®);
1500 1.72 jmcneill if ((reg & /*XXXval*/0xf) == /*XXXval*/0xf)
1501 1.72 jmcneill break;
1502 1.72 jmcneill DELAY(1);
1503 1.72 jmcneill }
1504 1.73 jmcneill if (i <= 0) {
1505 1.92 jmcneill mutex_exit(as->lock);
1506 1.73 jmcneill printf("%s: codec not responding, status=0x%x\n",
1507 1.87 cegger device_xname(sc_dev), reg);
1508 1.73 jmcneill return ENXIO;
1509 1.73 jmcneill }
1510 1.67 jmcneill
1511 1.68 jmcneill /* setup sysctls */
1512 1.68 jmcneill if (as->ext_mid & AC97_EXT_MODEM_LINE1) {
1513 1.68 jmcneill ac97_read(as, AC97_REG_GPIO_CFG, ®);
1514 1.68 jmcneill reg &= ~AC97_GPIO_LINE1_OH;
1515 1.68 jmcneill ac97_write(as, AC97_REG_GPIO_CFG, reg);
1516 1.68 jmcneill ac97_read(as, AC97_REG_GPIO_POLARITY, ®);
1517 1.68 jmcneill reg &= ~AC97_GPIO_LINE1_OH;
1518 1.68 jmcneill ac97_write(as, AC97_REG_GPIO_POLARITY, reg);
1519 1.68 jmcneill
1520 1.92 jmcneill mutex_exit(as->lock);
1521 1.68 jmcneill err = sysctl_createv(&as->log, 0, NULL, &node_line1,
1522 1.68 jmcneill CTLFLAG_READWRITE, CTLTYPE_INT,
1523 1.68 jmcneill "line1",
1524 1.68 jmcneill SYSCTL_DESCR("off-hook line1"),
1525 1.94 dsl ac97_sysctl_verify, 0, (void *)as, 0,
1526 1.68 jmcneill CTL_HW, node->sysctl_num,
1527 1.68 jmcneill CTL_CREATE, CTL_EOL);
1528 1.92 jmcneill mutex_enter(as->lock);
1529 1.92 jmcneill
1530 1.68 jmcneill if (err != 0)
1531 1.68 jmcneill goto sysctl_err;
1532 1.68 jmcneill as->offhook_line1_mib = node_line1->sysctl_num;
1533 1.68 jmcneill }
1534 1.68 jmcneill if (as->ext_mid & AC97_EXT_MODEM_LINE2) {
1535 1.68 jmcneill ac97_read(as, AC97_REG_GPIO_CFG, ®);
1536 1.68 jmcneill reg &= ~AC97_GPIO_LINE2_OH;
1537 1.68 jmcneill ac97_write(as, AC97_REG_GPIO_CFG, reg);
1538 1.68 jmcneill ac97_read(as, AC97_REG_GPIO_POLARITY, ®);
1539 1.68 jmcneill reg &= ~AC97_GPIO_LINE2_OH;
1540 1.68 jmcneill ac97_write(as, AC97_REG_GPIO_POLARITY, reg);
1541 1.68 jmcneill
1542 1.92 jmcneill mutex_exit(as->lock);
1543 1.68 jmcneill err = sysctl_createv(&as->log, 0, NULL, &node_line2,
1544 1.68 jmcneill CTLFLAG_READWRITE, CTLTYPE_INT,
1545 1.68 jmcneill "line2",
1546 1.68 jmcneill SYSCTL_DESCR("off-hook line2"),
1547 1.94 dsl ac97_sysctl_verify, 0, (void *)as, 0,
1548 1.68 jmcneill CTL_HW, node->sysctl_num,
1549 1.68 jmcneill CTL_CREATE, CTL_EOL);
1550 1.92 jmcneill mutex_enter(as->lock);
1551 1.92 jmcneill
1552 1.68 jmcneill if (err != 0)
1553 1.68 jmcneill goto sysctl_err;
1554 1.68 jmcneill as->offhook_line2_mib = node_line2->sysctl_num;
1555 1.68 jmcneill }
1556 1.72 jmcneill sysctl_err:
1557 1.68 jmcneill
1558 1.67 jmcneill ac97_write(as, AC97_REG_GPIO_STICKY, 0xffff);
1559 1.67 jmcneill ac97_write(as, AC97_REG_GPIO_WAKEUP, 0x0);
1560 1.67 jmcneill ac97_write(as, AC97_REG_MISC_AFE, 0x0);
1561 1.67 jmcneill }
1562 1.67 jmcneill
1563 1.71 jmcneill as->source_info = (as->type == AC97_CODEC_TYPE_MODEM ?
1564 1.69 jmcneill as->modem_source_info : as->audio_source_info);
1565 1.1 augustss ac97_setup_source_info(as);
1566 1.8 augustss
1567 1.8 augustss memset(&ctl, 0, sizeof(ctl));
1568 1.33 kent /* disable mutes */
1569 1.33 kent for (i = 0; i < 11; i++) {
1570 1.33 kent static struct {
1571 1.75 christos const char *class, *device;
1572 1.33 kent } d[11] = {
1573 1.33 kent { AudioCoutputs, AudioNmaster},
1574 1.33 kent { AudioCoutputs, AudioNheadphone},
1575 1.33 kent { AudioCoutputs, AudioNsurround},
1576 1.33 kent { AudioCoutputs, AudioNcenter},
1577 1.33 kent { AudioCoutputs, AudioNlfe},
1578 1.33 kent { AudioCinputs, AudioNdac},
1579 1.33 kent { AudioCinputs, AudioNcd},
1580 1.33 kent { AudioCinputs, AudioNline},
1581 1.33 kent { AudioCinputs, AudioNaux},
1582 1.33 kent { AudioCinputs, AudioNvideo},
1583 1.33 kent { AudioCrecord, AudioNvolume},
1584 1.33 kent };
1585 1.33 kent
1586 1.33 kent ctl.type = AUDIO_MIXER_ENUM;
1587 1.33 kent ctl.un.ord = 0;
1588 1.33 kent
1589 1.33 kent ctl.dev = ac97_get_portnum_by_name(&as->codec_if,
1590 1.33 kent d[i].class, d[i].device, AudioNmute);
1591 1.33 kent ac97_mixer_set_port(&as->codec_if, &ctl);
1592 1.33 kent }
1593 1.8 augustss ctl.type = AUDIO_MIXER_ENUM;
1594 1.33 kent ctl.un.ord = 0;
1595 1.33 kent ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCrecord,
1596 1.33 kent AudioNsource, NULL);
1597 1.33 kent ac97_mixer_set_port(&as->codec_if, &ctl);
1598 1.33 kent
1599 1.33 kent /* set a reasonable default volume */
1600 1.33 kent ctl.type = AUDIO_MIXER_VALUE;
1601 1.33 kent ctl.un.value.num_channels = 2;
1602 1.33 kent ctl.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = \
1603 1.33 kent ctl.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 127;
1604 1.14 thorpej ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
1605 1.33 kent AudioNmaster, NULL);
1606 1.14 thorpej ac97_mixer_set_port(&as->codec_if, &ctl);
1607 1.33 kent ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
1608 1.33 kent AudioNsurround, NULL);
1609 1.14 thorpej ac97_mixer_set_port(&as->codec_if, &ctl);
1610 1.33 kent ctl.un.value.num_channels = 1;
1611 1.33 kent ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
1612 1.33 kent AudioNcenter, NULL);
1613 1.14 thorpej ac97_mixer_set_port(&as->codec_if, &ctl);
1614 1.33 kent ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
1615 1.33 kent AudioNlfe, NULL);
1616 1.14 thorpej ac97_mixer_set_port(&as->codec_if, &ctl);
1617 1.1 augustss
1618 1.33 kent if (initfunc != NULL)
1619 1.33 kent initfunc(as);
1620 1.80 jmcneill
1621 1.80 jmcneill /* restore AC97_REG_POWER */
1622 1.80 jmcneill if (as->type == AC97_CODEC_TYPE_AUDIO)
1623 1.80 jmcneill ac97_write(as, AC97_REG_POWER, as->power_reg);
1624 1.80 jmcneill
1625 1.92 jmcneill mutex_exit(as->lock);
1626 1.92 jmcneill
1627 1.50 kent return 0;
1628 1.1 augustss }
1629 1.1 augustss
1630 1.65 kent static void
1631 1.65 kent ac97_detach(struct ac97_codec_if *codec_if)
1632 1.65 kent {
1633 1.65 kent struct ac97_softc *as;
1634 1.65 kent
1635 1.65 kent as = (struct ac97_softc *)codec_if;
1636 1.92 jmcneill
1637 1.92 jmcneill mutex_enter(as->lock);
1638 1.65 kent ac97_write(as, AC97_REG_POWER, AC97_POWER_IN | AC97_POWER_OUT
1639 1.65 kent | AC97_POWER_MIXER | AC97_POWER_MIXER_VREF
1640 1.65 kent | AC97_POWER_ACLINK | AC97_POWER_CLK | AC97_POWER_AUX
1641 1.80 jmcneill | POWER_EAMP_OFF(as));
1642 1.92 jmcneill mutex_exit(as->lock);
1643 1.92 jmcneill
1644 1.65 kent free(as, M_DEVBUF);
1645 1.65 kent }
1646 1.1 augustss
1647 1.82 kent static void
1648 1.82 kent ac97_lock(struct ac97_codec_if *codec_if)
1649 1.82 kent {
1650 1.82 kent struct ac97_softc *as;
1651 1.82 kent
1652 1.82 kent as = (struct ac97_softc *)codec_if;
1653 1.92 jmcneill
1654 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1655 1.92 jmcneill
1656 1.82 kent as->lock_counter++;
1657 1.82 kent }
1658 1.82 kent
1659 1.82 kent static void
1660 1.82 kent ac97_unlock(struct ac97_codec_if *codec_if)
1661 1.82 kent {
1662 1.82 kent struct ac97_softc *as;
1663 1.82 kent
1664 1.82 kent as = (struct ac97_softc *)codec_if;
1665 1.92 jmcneill
1666 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1667 1.92 jmcneill
1668 1.82 kent as->lock_counter--;
1669 1.82 kent }
1670 1.82 kent
1671 1.60 thorpej static int
1672 1.50 kent ac97_query_devinfo(struct ac97_codec_if *codec_if, mixer_devinfo_t *dip)
1673 1.1 augustss {
1674 1.50 kent struct ac97_softc *as;
1675 1.50 kent struct ac97_source_info *si;
1676 1.50 kent const char *name;
1677 1.1 augustss
1678 1.50 kent as = (struct ac97_softc *)codec_if;
1679 1.1 augustss if (dip->index < as->num_source_info) {
1680 1.50 kent si = &as->source_info[dip->index];
1681 1.1 augustss dip->type = si->type;
1682 1.1 augustss dip->mixer_class = si->mixer_class;
1683 1.1 augustss dip->prev = si->prev;
1684 1.1 augustss dip->next = si->next;
1685 1.36 kent
1686 1.1 augustss if (si->qualifier)
1687 1.1 augustss name = si->qualifier;
1688 1.1 augustss else if (si->device)
1689 1.1 augustss name = si->device;
1690 1.1 augustss else if (si->class)
1691 1.1 augustss name = si->class;
1692 1.6 augustss else
1693 1.6 augustss name = 0;
1694 1.36 kent
1695 1.1 augustss if (name)
1696 1.1 augustss strcpy(dip->label.name, name);
1697 1.1 augustss
1698 1.20 thorpej memcpy(&dip->un, si->info, si->info_size);
1699 1.19 erh
1700 1.19 erh /* Set the delta for volume sources */
1701 1.19 erh if (dip->type == AUDIO_MIXER_VALUE)
1702 1.19 erh dip->un.v.delta = 1 << (8 - si->bits);
1703 1.19 erh
1704 1.50 kent return 0;
1705 1.1 augustss }
1706 1.1 augustss
1707 1.50 kent return ENXIO;
1708 1.1 augustss }
1709 1.1 augustss
1710 1.60 thorpej static int
1711 1.50 kent ac97_mixer_set_port(struct ac97_codec_if *codec_if, mixer_ctrl_t *cp)
1712 1.1 augustss {
1713 1.50 kent struct ac97_softc *as;
1714 1.50 kent struct ac97_source_info *si;
1715 1.66 kent uint16_t mask;
1716 1.66 kent uint16_t val, newval;
1717 1.1 augustss int error;
1718 1.86 thorpej bool spdif;
1719 1.1 augustss
1720 1.50 kent as = (struct ac97_softc *)codec_if;
1721 1.92 jmcneill
1722 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1723 1.92 jmcneill
1724 1.1 augustss if (cp->dev < 0 || cp->dev >= as->num_source_info)
1725 1.50 kent return EINVAL;
1726 1.82 kent si = &as->source_info[cp->dev];
1727 1.1 augustss
1728 1.82 kent if (cp->type == AUDIO_MIXER_CLASS || cp->type != si->type)
1729 1.50 kent return EINVAL;
1730 1.82 kent spdif = si->req_feature == CHECK_SPDIF && si->reg == AC97_REG_EXT_AUDIO_CTRL;
1731 1.82 kent if (spdif && as->lock_counter >= 0) {
1732 1.82 kent /* When the value of lock_counter is the default 0,
1733 1.82 kent * it is not allowed to change the SPDIF mode. */
1734 1.82 kent return EBUSY;
1735 1.82 kent }
1736 1.1 augustss
1737 1.15 thorpej ac97_read(as, si->reg, &val);
1738 1.1 augustss
1739 1.1 augustss DPRINTFN(5, ("read(%x) = %x\n", si->reg, val));
1740 1.1 augustss
1741 1.1 augustss mask = (1 << si->bits) - 1;
1742 1.1 augustss
1743 1.1 augustss switch (cp->type) {
1744 1.1 augustss case AUDIO_MIXER_ENUM:
1745 1.1 augustss if (cp->un.ord > mask || cp->un.ord < 0)
1746 1.50 kent return EINVAL;
1747 1.1 augustss
1748 1.1 augustss newval = (cp->un.ord << si->ofs);
1749 1.1 augustss if (si->reg == AC97_REG_RECORD_SELECT) {
1750 1.1 augustss newval |= (newval << (8 + si->ofs));
1751 1.1 augustss mask |= (mask << 8);
1752 1.33 kent mask = mask << si->ofs;
1753 1.33 kent } else if (si->reg == AC97_REG_SURR_MASTER) {
1754 1.33 kent newval = cp->un.ord ? 0x8080 : 0x0000;
1755 1.33 kent mask = 0x8080;
1756 1.33 kent } else
1757 1.33 kent mask = mask << si->ofs;
1758 1.1 augustss break;
1759 1.1 augustss case AUDIO_MIXER_VALUE:
1760 1.1 augustss {
1761 1.18 jdolecek const struct audio_mixer_value *value = si->info;
1762 1.66 kent uint16_t l, r, ol, or;
1763 1.49 cube int deltal, deltar;
1764 1.1 augustss
1765 1.1 augustss if ((cp->un.value.num_channels <= 0) ||
1766 1.36 kent (cp->un.value.num_channels > value->num_channels))
1767 1.50 kent return EINVAL;
1768 1.1 augustss
1769 1.1 augustss if (cp->un.value.num_channels == 1) {
1770 1.1 augustss l = r = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
1771 1.1 augustss } else {
1772 1.17 rh if (!(as->host_flags & AC97_HOST_SWAPPED_CHANNELS)) {
1773 1.17 rh l = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
1774 1.17 rh r = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
1775 1.17 rh } else { /* left/right is reversed here */
1776 1.17 rh r = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
1777 1.17 rh l = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
1778 1.17 rh }
1779 1.17 rh
1780 1.1 augustss }
1781 1.1 augustss
1782 1.1 augustss if (!si->polarity) {
1783 1.1 augustss l = 255 - l;
1784 1.1 augustss r = 255 - r;
1785 1.1 augustss }
1786 1.36 kent
1787 1.49 cube ol = (val >> (8+si->ofs)) & mask;
1788 1.49 cube or = (val >> si->ofs) & mask;
1789 1.49 cube
1790 1.49 cube deltal = (ol << (8 - si->bits)) - l;
1791 1.49 cube deltar = (or << (8 - si->bits)) - r;
1792 1.49 cube
1793 1.1 augustss l = l >> (8 - si->bits);
1794 1.1 augustss r = r >> (8 - si->bits);
1795 1.1 augustss
1796 1.49 cube if (deltal && ol == l)
1797 1.49 cube l += (deltal > 0) ? (l ? -1 : 0) : (l < mask ? 1 : 0);
1798 1.49 cube if (deltar && or == r)
1799 1.49 cube r += (deltar > 0) ? (r ? -1 : 0) : (r < mask ? 1 : 0);
1800 1.49 cube
1801 1.49 cube newval = ((r & mask) << si->ofs);
1802 1.1 augustss if (value->num_channels == 2) {
1803 1.49 cube newval = newval | ((l & mask) << (si->ofs+8));
1804 1.1 augustss mask |= (mask << 8);
1805 1.1 augustss }
1806 1.33 kent mask = mask << si->ofs;
1807 1.1 augustss break;
1808 1.1 augustss }
1809 1.1 augustss default:
1810 1.50 kent return EINVAL;
1811 1.1 augustss }
1812 1.1 augustss
1813 1.15 thorpej error = ac97_write(as, si->reg, (val & ~mask) | newval);
1814 1.1 augustss if (error)
1815 1.50 kent return error;
1816 1.1 augustss
1817 1.82 kent if (spdif && as->host_if->spdif_event != NULL) {
1818 1.82 kent DPRINTF(("%s: call spdif_event(%d)\n", __func__, cp->un.ord));
1819 1.82 kent as->host_if->spdif_event(as->host_if->arg, cp->un.ord);
1820 1.82 kent }
1821 1.50 kent return 0;
1822 1.1 augustss }
1823 1.1 augustss
1824 1.60 thorpej static int
1825 1.50 kent ac97_get_portnum_by_name(struct ac97_codec_if *codec_if, const char *class,
1826 1.50 kent const char *device, const char *qualifier)
1827 1.1 augustss {
1828 1.50 kent struct ac97_softc *as;
1829 1.1 augustss int idx;
1830 1.1 augustss
1831 1.50 kent as = (struct ac97_softc *)codec_if;
1832 1.92 jmcneill
1833 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1834 1.92 jmcneill
1835 1.1 augustss for (idx = 0; idx < as->num_source_info; idx++) {
1836 1.1 augustss struct ac97_source_info *si = &as->source_info[idx];
1837 1.1 augustss if (ac97_str_equal(class, si->class) &&
1838 1.1 augustss ac97_str_equal(device, si->device) &&
1839 1.1 augustss ac97_str_equal(qualifier, si->qualifier))
1840 1.50 kent return idx;
1841 1.1 augustss }
1842 1.1 augustss
1843 1.50 kent return -1;
1844 1.1 augustss }
1845 1.1 augustss
1846 1.60 thorpej static int
1847 1.50 kent ac97_mixer_get_port(struct ac97_codec_if *codec_if, mixer_ctrl_t *cp)
1848 1.1 augustss {
1849 1.50 kent struct ac97_softc *as;
1850 1.50 kent struct ac97_source_info *si;
1851 1.66 kent uint16_t mask;
1852 1.66 kent uint16_t val;
1853 1.1 augustss
1854 1.50 kent as = (struct ac97_softc *)codec_if;
1855 1.92 jmcneill
1856 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1857 1.92 jmcneill
1858 1.50 kent si = &as->source_info[cp->dev];
1859 1.1 augustss if (cp->dev < 0 || cp->dev >= as->num_source_info)
1860 1.50 kent return EINVAL;
1861 1.1 augustss
1862 1.1 augustss if (cp->type != si->type)
1863 1.50 kent return EINVAL;
1864 1.1 augustss
1865 1.15 thorpej ac97_read(as, si->reg, &val);
1866 1.1 augustss
1867 1.1 augustss DPRINTFN(5, ("read(%x) = %x\n", si->reg, val));
1868 1.1 augustss
1869 1.1 augustss mask = (1 << si->bits) - 1;
1870 1.1 augustss
1871 1.1 augustss switch (cp->type) {
1872 1.1 augustss case AUDIO_MIXER_ENUM:
1873 1.1 augustss cp->un.ord = (val >> si->ofs) & mask;
1874 1.36 kent DPRINTFN(4, ("AUDIO_MIXER_ENUM: %x %d %x %d\n",
1875 1.36 kent val, si->ofs, mask, cp->un.ord));
1876 1.1 augustss break;
1877 1.1 augustss case AUDIO_MIXER_VALUE:
1878 1.1 augustss {
1879 1.18 jdolecek const struct audio_mixer_value *value = si->info;
1880 1.66 kent uint16_t l, r;
1881 1.1 augustss
1882 1.1 augustss if ((cp->un.value.num_channels <= 0) ||
1883 1.36 kent (cp->un.value.num_channels > value->num_channels))
1884 1.50 kent return EINVAL;
1885 1.1 augustss
1886 1.1 augustss if (value->num_channels == 1) {
1887 1.1 augustss l = r = (val >> si->ofs) & mask;
1888 1.1 augustss } else {
1889 1.17 rh if (!(as->host_flags & AC97_HOST_SWAPPED_CHANNELS)) {
1890 1.37 kent l = (val >> (si->ofs + 8)) & mask;
1891 1.37 kent r = (val >> si->ofs) & mask;
1892 1.37 kent } else { /* host has reversed channels */
1893 1.37 kent r = (val >> (si->ofs + 8)) & mask;
1894 1.17 rh l = (val >> si->ofs) & mask;
1895 1.17 rh }
1896 1.1 augustss }
1897 1.1 augustss
1898 1.1 augustss l = (l << (8 - si->bits));
1899 1.1 augustss r = (r << (8 - si->bits));
1900 1.1 augustss if (!si->polarity) {
1901 1.1 augustss l = 255 - l;
1902 1.1 augustss r = 255 - r;
1903 1.1 augustss }
1904 1.1 augustss
1905 1.1 augustss /* The EAP driver averages l and r for stereo
1906 1.1 augustss channels that are requested in MONO mode. Does this
1907 1.1 augustss make sense? */
1908 1.1 augustss if (cp->un.value.num_channels == 1) {
1909 1.1 augustss cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = l;
1910 1.1 augustss } else if (cp->un.value.num_channels == 2) {
1911 1.1 augustss cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
1912 1.1 augustss cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
1913 1.1 augustss }
1914 1.1 augustss
1915 1.1 augustss break;
1916 1.1 augustss }
1917 1.1 augustss default:
1918 1.50 kent return EINVAL;
1919 1.1 augustss }
1920 1.1 augustss
1921 1.50 kent return 0;
1922 1.1 augustss }
1923 1.1 augustss
1924 1.28 kent
1925 1.60 thorpej static int
1926 1.66 kent ac97_set_rate(struct ac97_codec_if *codec_if, int target, u_int *rate)
1927 1.28 kent {
1928 1.28 kent struct ac97_softc *as;
1929 1.66 kent u_int value;
1930 1.66 kent uint16_t ext_stat;
1931 1.66 kent uint16_t actual;
1932 1.66 kent uint16_t power;
1933 1.66 kent uint16_t power_bit;
1934 1.28 kent
1935 1.28 kent as = (struct ac97_softc *)codec_if;
1936 1.92 jmcneill
1937 1.92 jmcneill KASSERT(mutex_owned(as->lock));
1938 1.92 jmcneill
1939 1.29 kent if (target == AC97_REG_PCM_MIC_ADC_RATE) {
1940 1.29 kent if (!(as->ext_id & AC97_EXT_AUDIO_VRM)) {
1941 1.29 kent *rate = AC97_SINGLE_RATE;
1942 1.29 kent return 0;
1943 1.29 kent }
1944 1.29 kent } else {
1945 1.29 kent if (!(as->ext_id & AC97_EXT_AUDIO_VRA)) {
1946 1.29 kent *rate = AC97_SINGLE_RATE;
1947 1.29 kent return 0;
1948 1.29 kent }
1949 1.29 kent }
1950 1.28 kent value = *rate * AC97_STANDARD_CLOCK / as->ac97_clock;
1951 1.28 kent ext_stat = 0;
1952 1.28 kent /*
1953 1.28 kent * PCM_FRONT_DAC_RATE/PCM_SURR_DAC_RATE/PCM_LFE_DAC_RATE
1954 1.28 kent * Check VRA, DRA
1955 1.28 kent * PCM_LR_ADC_RATE
1956 1.28 kent * Check VRA
1957 1.28 kent * PCM_MIC_ADC_RATE
1958 1.28 kent * Check VRM
1959 1.28 kent */
1960 1.28 kent switch (target) {
1961 1.28 kent case AC97_REG_PCM_FRONT_DAC_RATE:
1962 1.28 kent case AC97_REG_PCM_SURR_DAC_RATE:
1963 1.28 kent case AC97_REG_PCM_LFE_DAC_RATE:
1964 1.28 kent power_bit = AC97_POWER_OUT;
1965 1.28 kent if (!(as->ext_id & AC97_EXT_AUDIO_VRA)) {
1966 1.28 kent *rate = AC97_SINGLE_RATE;
1967 1.28 kent return 0;
1968 1.28 kent }
1969 1.28 kent if (as->ext_id & AC97_EXT_AUDIO_DRA) {
1970 1.28 kent ac97_read(as, AC97_REG_EXT_AUDIO_CTRL, &ext_stat);
1971 1.28 kent if (value > 0x1ffff) {
1972 1.28 kent return EINVAL;
1973 1.28 kent } else if (value > 0xffff) {
1974 1.28 kent /* Enable DRA */
1975 1.28 kent ext_stat |= AC97_EXT_AUDIO_DRA;
1976 1.28 kent ac97_write(as, AC97_REG_EXT_AUDIO_CTRL, ext_stat);
1977 1.28 kent value /= 2;
1978 1.28 kent } else {
1979 1.28 kent /* Disable DRA */
1980 1.28 kent ext_stat &= ~AC97_EXT_AUDIO_DRA;
1981 1.28 kent ac97_write(as, AC97_REG_EXT_AUDIO_CTRL, ext_stat);
1982 1.28 kent }
1983 1.28 kent } else {
1984 1.28 kent if (value > 0xffff)
1985 1.28 kent return EINVAL;
1986 1.28 kent }
1987 1.28 kent break;
1988 1.28 kent case AC97_REG_PCM_LR_ADC_RATE:
1989 1.28 kent power_bit = AC97_POWER_IN;
1990 1.28 kent if (!(as->ext_id & AC97_EXT_AUDIO_VRA)) {
1991 1.28 kent *rate = AC97_SINGLE_RATE;
1992 1.28 kent return 0;
1993 1.28 kent }
1994 1.28 kent if (value > 0xffff)
1995 1.28 kent return EINVAL;
1996 1.28 kent break;
1997 1.28 kent case AC97_REG_PCM_MIC_ADC_RATE:
1998 1.28 kent power_bit = AC97_POWER_IN;
1999 1.28 kent if (!(as->ext_id & AC97_EXT_AUDIO_VRM)) {
2000 1.28 kent *rate = AC97_SINGLE_RATE;
2001 1.28 kent return 0;
2002 1.28 kent }
2003 1.28 kent if (value > 0xffff)
2004 1.28 kent return EINVAL;
2005 1.28 kent break;
2006 1.28 kent default:
2007 1.28 kent printf("%s: Unknown register: 0x%x\n", __func__, target);
2008 1.28 kent return EINVAL;
2009 1.28 kent }
2010 1.28 kent
2011 1.28 kent ac97_read(as, AC97_REG_POWER, &power);
2012 1.28 kent ac97_write(as, AC97_REG_POWER, power | power_bit);
2013 1.28 kent
2014 1.66 kent ac97_write(as, target, (uint16_t)value);
2015 1.28 kent ac97_read(as, target, &actual);
2016 1.66 kent actual = (uint32_t)actual * as->ac97_clock / AC97_STANDARD_CLOCK;
2017 1.28 kent
2018 1.28 kent ac97_write(as, AC97_REG_POWER, power);
2019 1.28 kent if (ext_stat & AC97_EXT_AUDIO_DRA) {
2020 1.28 kent *rate = actual * 2;
2021 1.28 kent } else {
2022 1.28 kent *rate = actual;
2023 1.28 kent }
2024 1.28 kent return 0;
2025 1.28 kent }
2026 1.28 kent
2027 1.60 thorpej static void
2028 1.28 kent ac97_set_clock(struct ac97_codec_if *codec_if, unsigned int clock)
2029 1.28 kent {
2030 1.28 kent struct ac97_softc *as;
2031 1.28 kent
2032 1.28 kent as = (struct ac97_softc *)codec_if;
2033 1.92 jmcneill
2034 1.92 jmcneill KASSERT(mutex_owned(as->lock));
2035 1.92 jmcneill
2036 1.28 kent as->ac97_clock = clock;
2037 1.28 kent }
2038 1.28 kent
2039 1.66 kent static uint16_t
2040 1.28 kent ac97_get_extcaps(struct ac97_codec_if *codec_if)
2041 1.28 kent {
2042 1.28 kent struct ac97_softc *as;
2043 1.28 kent
2044 1.28 kent as = (struct ac97_softc *)codec_if;
2045 1.92 jmcneill
2046 1.92 jmcneill KASSERT(mutex_owned(as->lock));
2047 1.92 jmcneill
2048 1.28 kent return as->ext_id;
2049 1.33 kent }
2050 1.33 kent
2051 1.60 thorpej static int
2052 1.33 kent ac97_add_port(struct ac97_softc *as, const struct ac97_source_info *src)
2053 1.33 kent {
2054 1.33 kent struct ac97_source_info *si;
2055 1.33 kent int ouridx, idx;
2056 1.33 kent
2057 1.92 jmcneill KASSERT(mutex_owned(as->lock));
2058 1.92 jmcneill
2059 1.71 jmcneill if ((as->type == AC97_CODEC_TYPE_AUDIO &&
2060 1.69 jmcneill as->num_source_info >= AUDIO_MAX_SOURCES) ||
2061 1.71 jmcneill (as->type == AC97_CODEC_TYPE_MODEM &&
2062 1.69 jmcneill as->num_source_info >= MODEM_MAX_SOURCES)) {
2063 1.33 kent printf("%s: internal error: increase MAX_SOURCES in %s\n",
2064 1.33 kent __func__, __FILE__);
2065 1.33 kent return -1;
2066 1.33 kent }
2067 1.33 kent if (!ac97_check_capability(as, src->req_feature))
2068 1.33 kent return -1;
2069 1.33 kent ouridx = as->num_source_info;
2070 1.33 kent si = &as->source_info[ouridx];
2071 1.33 kent memcpy(si, src, sizeof(*si));
2072 1.33 kent
2073 1.33 kent switch (si->type) {
2074 1.33 kent case AUDIO_MIXER_CLASS:
2075 1.33 kent case AUDIO_MIXER_VALUE:
2076 1.33 kent printf("%s: adding class/value is not supported yet.\n",
2077 1.33 kent __func__);
2078 1.33 kent return -1;
2079 1.33 kent case AUDIO_MIXER_ENUM:
2080 1.33 kent break;
2081 1.33 kent default:
2082 1.33 kent printf("%s: unknown type: %d\n", __func__, si->type);
2083 1.33 kent return -1;
2084 1.33 kent }
2085 1.33 kent as->num_source_info++;
2086 1.33 kent
2087 1.33 kent si->mixer_class = ac97_get_portnum_by_name(&as->codec_if, si->class,
2088 1.33 kent NULL, NULL);
2089 1.33 kent /* Find the root of the device */
2090 1.33 kent idx = ac97_get_portnum_by_name(&as->codec_if, si->class,
2091 1.33 kent si->device, NULL);
2092 1.33 kent /* Find the last item */
2093 1.33 kent while (as->source_info[idx].next != AUDIO_MIXER_LAST)
2094 1.33 kent idx = as->source_info[idx].next;
2095 1.33 kent /* Append */
2096 1.33 kent as->source_info[idx].next = ouridx;
2097 1.33 kent si->prev = idx;
2098 1.33 kent si->next = AUDIO_MIXER_LAST;
2099 1.33 kent
2100 1.33 kent return 0;
2101 1.43 kent }
2102 1.43 kent
2103 1.43 kent /**
2104 1.43 kent * Codec-dependent initialization
2105 1.43 kent */
2106 1.43 kent
2107 1.46 kent #define AD1980_REG_MISC 0x76
2108 1.55 kent #define AD1980_MISC_MBG0 0x0001 /* 0 1888/1980/1981 /1985 */
2109 1.55 kent #define AD1980_MISC_MBG1 0x0002 /* 1 1888/1980/1981 /1985 */
2110 1.55 kent #define AD1980_MISC_VREFD 0x0004 /* 2 1888/1980/1981 /1985 */
2111 1.55 kent #define AD1980_MISC_VREFH 0x0008 /* 3 1888/1980/1981 /1985 */
2112 1.55 kent #define AD1980_MISC_SRU 0x0010 /* 4 1888/1980 /1985 */
2113 1.55 kent #define AD1980_MISC_LOSEL 0x0020 /* 5 1888/1980/1981 /1985 */
2114 1.55 kent #define AD1980_MISC_2CMIC 0x0040 /* 6 1980/1981B/1985 */
2115 1.55 kent #define AD1980_MISC_SPRD 0x0080 /* 7 1888/1980 /1985 */
2116 1.55 kent #define AD1980_MISC_DMIX0 0x0100 /* 8 1888/1980 /1985 */
2117 1.55 kent #define AD1980_MISC_DMIX1 0x0200 /* 9 1888/1980 /1985 */
2118 1.55 kent #define AD1980_MISC_HPSEL 0x0400 /*10 1888/1980 /1985 */
2119 1.55 kent #define AD1980_MISC_CLDIS 0x0800 /*11 1888/1980 /1985 */
2120 1.55 kent #define AD1980_MISC_LODIS 0x1000 /*12 1888/1980/1981 /1985 */
2121 1.55 kent #define AD1980_MISC_MSPLT 0x2000 /*13 1888/1980/1981 /1985 */
2122 1.55 kent #define AD1980_MISC_AC97NC 0x4000 /*14 1888/1980 /1985 */
2123 1.55 kent #define AD1980_MISC_DACZ 0x8000 /*15 1888/1980/1981 /1985 */
2124 1.46 kent #define AD1981_REG_MISC 0x76
2125 1.55 kent #define AD1981_MISC_MADST 0x0010 /* 4 */
2126 1.55 kent #define AD1981A_MISC_MADPD 0x0040 /* 6 */
2127 1.55 kent #define AD1981B_MISC_MADPD 0x0080 /* 7 */
2128 1.55 kent #define AD1981_MISC_FMXE 0x0200 /* 9 */
2129 1.55 kent #define AD1981_MISC_DAM 0x0800 /*11 */
2130 1.43 kent static void
2131 1.51 kent ac97_ad198x_init(struct ac97_softc *as)
2132 1.43 kent {
2133 1.47 jmmv int i;
2134 1.55 kent uint16_t misc;
2135 1.43 kent
2136 1.92 jmcneill KASSERT(mutex_owned(as->lock));
2137 1.92 jmcneill
2138 1.46 kent ac97_read(as, AD1980_REG_MISC, &misc);
2139 1.46 kent ac97_write(as, AD1980_REG_MISC,
2140 1.46 kent misc | AD1980_MISC_LOSEL | AD1980_MISC_HPSEL);
2141 1.47 jmmv
2142 1.47 jmmv for (i = 0; i < as->num_source_info; i++) {
2143 1.47 jmmv if (as->source_info[i].type != AUDIO_MIXER_VALUE)
2144 1.47 jmmv continue;
2145 1.47 jmmv
2146 1.47 jmmv if (as->source_info[i].reg == AC97_REG_MASTER_VOLUME)
2147 1.47 jmmv as->source_info[i].reg = AC97_REG_SURR_MASTER;
2148 1.47 jmmv else if (as->source_info[i].reg == AC97_REG_SURR_MASTER)
2149 1.47 jmmv as->source_info[i].reg = AC97_REG_MASTER_VOLUME;
2150 1.47 jmmv }
2151 1.33 kent }
2152 1.33 kent
2153 1.33 kent #define ALC650_REG_MULTI_CHANNEL_CONTROL 0x6a
2154 1.33 kent #define ALC650_MCC_SLOT_MODIFY_MASK 0xc000
2155 1.35 kent #define ALC650_MCC_FRONTDAC_FROM_SPDIFIN 0x2000 /* 13 */
2156 1.35 kent #define ALC650_MCC_SPDIFOUT_FROM_ADC 0x1000 /* 12 */
2157 1.35 kent #define ALC650_MCC_PCM_FROM_SPDIFIN 0x0800 /* 11 */
2158 1.35 kent #define ALC650_MCC_MIC_OR_CENTERLFE 0x0400 /* 10 */
2159 1.35 kent #define ALC650_MCC_LINEIN_OR_SURROUND 0x0200 /* 9 */
2160 1.35 kent #define ALC650_MCC_INDEPENDENT_MASTER_L 0x0080 /* 7 */
2161 1.35 kent #define ALC650_MCC_INDEPENDENT_MASTER_R 0x0040 /* 6 */
2162 1.35 kent #define ALC650_MCC_ANALOG_TO_CENTERLFE 0x0020 /* 5 */
2163 1.35 kent #define ALC650_MCC_ANALOG_TO_SURROUND 0x0010 /* 4 */
2164 1.35 kent #define ALC650_MCC_EXCHANGE_CENTERLFE 0x0008 /* 3 */
2165 1.35 kent #define ALC650_MCC_CENTERLFE_DOWNMIX 0x0004 /* 2 */
2166 1.35 kent #define ALC650_MCC_SURROUND_DOWNMIX 0x0002 /* 1 */
2167 1.35 kent #define ALC650_MCC_LINEOUT_TO_SURROUND 0x0001 /* 0 */
2168 1.33 kent static void
2169 1.33 kent ac97_alc650_init(struct ac97_softc *as)
2170 1.33 kent {
2171 1.35 kent static const struct ac97_source_info sources[6] = {
2172 1.33 kent { AudioCoutputs, AudioNsurround, "lineinjack",
2173 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2174 1.33 kent ALC650_REG_MULTI_CHANNEL_CONTROL,
2175 1.84 christos 0x0000, 1, 9, 0, 0, 0, CHECK_SURROUND, 0, 0, 0, },
2176 1.35 kent { AudioCoutputs, AudioNsurround, "mixtofront",
2177 1.35 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2178 1.35 kent ALC650_REG_MULTI_CHANNEL_CONTROL,
2179 1.84 christos 0x0000, 1, 1, 0, 0, 0, CHECK_SURROUND, 0, 0, 0, },
2180 1.33 kent { AudioCoutputs, AudioNcenter, "micjack",
2181 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2182 1.33 kent ALC650_REG_MULTI_CHANNEL_CONTROL,
2183 1.84 christos 0x0000, 1, 10, 0, 0, 0, CHECK_CENTER, 0, 0, 0, },
2184 1.33 kent { AudioCoutputs, AudioNlfe, "micjack",
2185 1.33 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2186 1.33 kent ALC650_REG_MULTI_CHANNEL_CONTROL,
2187 1.84 christos 0x0000, 1, 10, 0, 0, 0, CHECK_LFE, 0, 0, 0, },
2188 1.35 kent { AudioCoutputs, AudioNcenter, "mixtofront",
2189 1.35 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2190 1.35 kent ALC650_REG_MULTI_CHANNEL_CONTROL,
2191 1.84 christos 0x0000, 1, 2, 0, 0, 0, CHECK_CENTER, 0, 0, 0, },
2192 1.35 kent { AudioCoutputs, AudioNlfe, "mixtofront",
2193 1.35 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2194 1.35 kent ALC650_REG_MULTI_CHANNEL_CONTROL,
2195 1.84 christos 0x0000, 1, 2, 0, 0, 0, CHECK_LFE, 0, 0, 0, },
2196 1.35 kent };
2197 1.35 kent
2198 1.35 kent ac97_add_port(as, &sources[0]);
2199 1.35 kent ac97_add_port(as, &sources[1]);
2200 1.35 kent ac97_add_port(as, &sources[2]);
2201 1.35 kent ac97_add_port(as, &sources[3]);
2202 1.35 kent ac97_add_port(as, &sources[4]);
2203 1.35 kent ac97_add_port(as, &sources[5]);
2204 1.35 kent }
2205 1.35 kent
2206 1.91 kiyohara #define UCB1400_REG_FEATURE_CSR1 0x6a
2207 1.91 kiyohara #define UCB1400_BB(bb) (((bb) & 0xf) << 11)
2208 1.91 kiyohara #define UCB1400_TR(tr) (((tr) & 0x3) << 9)
2209 1.91 kiyohara #define UCB1400_M_MAXIMUM (3 << 7)
2210 1.91 kiyohara #define UCB1400_M_MINIMUM (1 << 7)
2211 1.91 kiyohara #define UCB1400_M_FLAT (0 << 7)
2212 1.91 kiyohara #define UCB1400_HPEN (1 << 6)
2213 1.91 kiyohara #define UCB1400_DE (1 << 5)
2214 1.91 kiyohara #define UCB1400_DC (1 << 4)
2215 1.91 kiyohara #define UCB1400_HIPS (1 << 3)
2216 1.91 kiyohara #define UCB1400_GIEN (1 << 2)
2217 1.91 kiyohara #define UCB1400_OVFL (1 << 0)
2218 1.91 kiyohara #define UCB1400_REG_FEATURE_CSR2 0x6c
2219 1.91 kiyohara #define UCB1400_SMT (1 << 15) /* Must be 0 */
2220 1.91 kiyohara #define UCB1400_SUEV1 (1 << 14) /* Must be 0 */
2221 1.91 kiyohara #define UCB1400_SUEV0 (1 << 13) /* Must be 0 */
2222 1.91 kiyohara #define UCB1400_AVE (1 << 12)
2223 1.91 kiyohara #define UCB1400_AVEN1 (1 << 11) /* Must be 0 */
2224 1.91 kiyohara #define UCB1400_AVEN0 (1 << 10) /* Must be 0 */
2225 1.91 kiyohara #define UCB1400_SLP_ON \
2226 1.91 kiyohara (UCB1400_SLP_PLL | UCB1400_SLP_CODEC)
2227 1.91 kiyohara #define UCB1400_SLP_PLL (2 << 4)
2228 1.91 kiyohara #define UCB1400_SLP_CODEC (1 << 4)
2229 1.91 kiyohara #define UCB1400_SLP_NO (0 << 4)
2230 1.91 kiyohara #define UCB1400_EV2 (1 << 2) /* Must be 0 */
2231 1.91 kiyohara #define UCB1400_EV1 (1 << 1) /* Must be 0 */
2232 1.91 kiyohara #define UCB1400_EV0 (1 << 0) /* Must be 0 */
2233 1.91 kiyohara static void
2234 1.91 kiyohara ac97_ucb1400_init(struct ac97_softc *as)
2235 1.91 kiyohara {
2236 1.91 kiyohara
2237 1.91 kiyohara ac97_write(as, UCB1400_REG_FEATURE_CSR1,
2238 1.91 kiyohara UCB1400_HPEN | UCB1400_DC | UCB1400_HIPS | UCB1400_OVFL);
2239 1.91 kiyohara ac97_write(as, UCB1400_REG_FEATURE_CSR2, UCB1400_AVE | UCB1400_SLP_ON);
2240 1.91 kiyohara }
2241 1.91 kiyohara
2242 1.35 kent #define VT1616_REG_IO_CONTROL 0x5a
2243 1.35 kent #define VT1616_IC_LVL (1 << 15)
2244 1.35 kent #define VT1616_IC_LFECENTER_TO_FRONT (1 << 12)
2245 1.35 kent #define VT1616_IC_SURROUND_TO_FRONT (1 << 11)
2246 1.35 kent #define VT1616_IC_BPDC (1 << 10)
2247 1.35 kent #define VT1616_IC_DC (1 << 9)
2248 1.35 kent #define VT1616_IC_IB_MASK 0x000c
2249 1.35 kent static void
2250 1.35 kent ac97_vt1616_init(struct ac97_softc *as)
2251 1.35 kent {
2252 1.35 kent static const struct ac97_source_info sources[3] = {
2253 1.35 kent { AudioCoutputs, AudioNsurround, "mixtofront",
2254 1.35 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2255 1.35 kent VT1616_REG_IO_CONTROL,
2256 1.84 christos 0x0000, 1, 11, 0, 0, 0, CHECK_SURROUND, 0, 0, 0, },
2257 1.35 kent { AudioCoutputs, AudioNcenter, "mixtofront",
2258 1.35 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2259 1.35 kent VT1616_REG_IO_CONTROL,
2260 1.84 christos 0x0000, 1, 12, 0, 0, 0, CHECK_CENTER, 0, 0, 0, },
2261 1.35 kent { AudioCoutputs, AudioNlfe, "mixtofront",
2262 1.35 kent AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
2263 1.35 kent VT1616_REG_IO_CONTROL,
2264 1.84 christos 0x0000, 1, 12, 0, 0, 0, CHECK_LFE, 0, 0, 0, },
2265 1.35 kent };
2266 1.33 kent
2267 1.92 jmcneill KASSERT(mutex_owned(as->lock));
2268 1.92 jmcneill
2269 1.33 kent ac97_add_port(as, &sources[0]);
2270 1.33 kent ac97_add_port(as, &sources[1]);
2271 1.33 kent ac97_add_port(as, &sources[2]);
2272 1.28 kent }
2273 1.68 jmcneill
2274 1.68 jmcneill static int
2275 1.68 jmcneill ac97_modem_offhook_set(struct ac97_softc *as, int line, int newval)
2276 1.68 jmcneill {
2277 1.69 jmcneill uint16_t val;
2278 1.68 jmcneill
2279 1.92 jmcneill KASSERT(mutex_owned(as->lock));
2280 1.92 jmcneill
2281 1.69 jmcneill val = as->shadow_reg[AC97_REG_GPIO_STATUS >> 1];
2282 1.68 jmcneill switch (newval) {
2283 1.68 jmcneill case 0:
2284 1.68 jmcneill val &= ~line;
2285 1.68 jmcneill break;
2286 1.68 jmcneill case 1:
2287 1.68 jmcneill val |= line;
2288 1.68 jmcneill break;
2289 1.68 jmcneill }
2290 1.68 jmcneill ac97_write(as, AC97_REG_GPIO_STATUS, val);
2291 1.68 jmcneill
2292 1.68 jmcneill return 0;
2293 1.68 jmcneill }
2294 1.68 jmcneill
2295 1.68 jmcneill static int
2296 1.68 jmcneill ac97_sysctl_verify(SYSCTLFN_ARGS)
2297 1.68 jmcneill {
2298 1.68 jmcneill int error, tmp;
2299 1.68 jmcneill struct sysctlnode node;
2300 1.68 jmcneill struct ac97_softc *as;
2301 1.68 jmcneill
2302 1.68 jmcneill node = *rnode;
2303 1.68 jmcneill as = rnode->sysctl_data;
2304 1.68 jmcneill if (node.sysctl_num == as->offhook_line1_mib) {
2305 1.68 jmcneill tmp = as->offhook_line1;
2306 1.68 jmcneill node.sysctl_data = &tmp;
2307 1.68 jmcneill error = sysctl_lookup(SYSCTLFN_CALL(&node));
2308 1.68 jmcneill if (error || newp == NULL)
2309 1.68 jmcneill return error;
2310 1.68 jmcneill
2311 1.68 jmcneill if (tmp < 0 || tmp > 1)
2312 1.68 jmcneill return EINVAL;
2313 1.68 jmcneill
2314 1.68 jmcneill as->offhook_line1 = tmp;
2315 1.92 jmcneill mutex_enter(as->lock);
2316 1.68 jmcneill ac97_modem_offhook_set(as, AC97_GPIO_LINE1_OH, tmp);
2317 1.92 jmcneill mutex_exit(as->lock);
2318 1.68 jmcneill } else if (node.sysctl_num == as->offhook_line2_mib) {
2319 1.68 jmcneill tmp = as->offhook_line2;
2320 1.68 jmcneill node.sysctl_data = &tmp;
2321 1.68 jmcneill error = sysctl_lookup(SYSCTLFN_CALL(&node));
2322 1.68 jmcneill if (error || newp == NULL)
2323 1.68 jmcneill return error;
2324 1.68 jmcneill
2325 1.68 jmcneill if (tmp < 0 || tmp > 1)
2326 1.68 jmcneill return EINVAL;
2327 1.68 jmcneill
2328 1.68 jmcneill as->offhook_line2 = tmp;
2329 1.92 jmcneill mutex_enter(as->lock);
2330 1.68 jmcneill ac97_modem_offhook_set(as, AC97_GPIO_LINE2_OH, tmp);
2331 1.92 jmcneill mutex_exit(as->lock);
2332 1.68 jmcneill }
2333 1.68 jmcneill
2334 1.68 jmcneill return 0;
2335 1.68 jmcneill }
2336