2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Universal interface for Audio Codec '97
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com).
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sound/driver.h>
26 #include <linux/slab.h>
27 #include <sound/core.h>
28 #include <sound/ac97_codec.h>
29 #include <sound/asoundef.h>
30 #include "ac97_local.h"
37 static void snd_ac97_proc_read_functions(ac97_t
*ac97
, snd_info_buffer_t
*buffer
)
39 int header
= 0, function
;
40 unsigned short info
, sense_info
;
41 static const char *function_names
[12] = {
42 "Master Out", "AUX Out", "Center/LFE Out", "SPDIF Out",
43 "Phone In", "Mic 1", "Mic 2", "Line In", "CD In", "Video In",
46 static const char *locations
[8] = {
47 "Rear I/O Panel", "Front Panel", "Motherboard", "Dock/External",
48 "reserved", "reserved", "reserved", "NC/unused"
51 for (function
= 0; function
< 12; ++function
) {
52 snd_ac97_write(ac97
, AC97_FUNC_SELECT
, function
<< 1);
53 info
= snd_ac97_read(ac97
, AC97_FUNC_INFO
);
57 snd_iprintf(buffer
, "\n Gain Inverted Buffer delay Location\n");
60 sense_info
= snd_ac97_read(ac97
, AC97_SENSE_INFO
);
61 snd_iprintf(buffer
, "%-17s: %3d.%d dBV %c %2d/fs %s\n",
62 function_names
[function
],
63 (info
& 0x8000 ? -1 : 1) * ((info
& 0x7000) >> 12) * 3 / 2,
64 ((info
& 0x0800) >> 11) * 5,
65 info
& 0x0400 ? 'X' : '-',
67 locations
[sense_info
>> 13]);
71 static void snd_ac97_proc_read_main(ac97_t
*ac97
, snd_info_buffer_t
* buffer
, int subidx
)
74 unsigned short val
, tmp
, ext
, mext
;
75 static const char *spdif_slots
[4] = { " SPDIF=3/4", " SPDIF=7/8", " SPDIF=6/9", " SPDIF=10/11" };
76 static const char *spdif_rates
[4] = { " Rate=44.1kHz", " Rate=res", " Rate=48kHz", " Rate=32kHz" };
77 static const char *spdif_rates_cs4205
[4] = { " Rate=48kHz", " Rate=44.1kHz", " Rate=res", " Rate=res" };
78 static const char *double_rate_slots
[4] = { "10/11", "7/8", "reserved", "reserved" };
80 snd_ac97_get_name(NULL
, ac97
->id
, name
, 0);
81 snd_iprintf(buffer
, "%d-%d/%d: %s\n\n", ac97
->addr
, ac97
->num
, subidx
, name
);
82 if ((ac97
->scaps
& AC97_SCAP_AUDIO
) == 0)
85 if ((ac97
->ext_id
& AC97_EI_REV_MASK
) >= AC97_EI_REV_23
) {
86 val
= snd_ac97_read(ac97
, AC97_INT_PAGING
);
87 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
,
88 AC97_PAGE_MASK
, AC97_PAGE_1
);
89 tmp
= snd_ac97_read(ac97
, AC97_CODEC_CLASS_REV
);
90 snd_iprintf(buffer
, "Revision : 0x%02x\n", tmp
& 0xff);
91 snd_iprintf(buffer
, "Compat. Class : 0x%02x\n", (tmp
>> 8) & 0x1f);
92 snd_iprintf(buffer
, "Subsys. Vendor ID: 0x%04x\n",
93 snd_ac97_read(ac97
, AC97_PCI_SVID
));
94 snd_iprintf(buffer
, "Subsys. ID : 0x%04x\n\n",
95 snd_ac97_read(ac97
, AC97_PCI_SID
));
96 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
,
97 AC97_PAGE_MASK
, val
& AC97_PAGE_MASK
);
100 // val = snd_ac97_read(ac97, AC97_RESET);
102 snd_iprintf(buffer
, "Capabilities :%s%s%s%s%s%s\n",
103 val
& AC97_BC_DEDICATED_MIC
? " -dedicated MIC PCM IN channel-" : "",
104 val
& AC97_BC_RESERVED1
? " -reserved1-" : "",
105 val
& AC97_BC_BASS_TREBLE
? " -bass & treble-" : "",
106 val
& AC97_BC_SIM_STEREO
? " -simulated stereo-" : "",
107 val
& AC97_BC_HEADPHONE
? " -headphone out-" : "",
108 val
& AC97_BC_LOUDNESS
? " -loudness-" : "");
109 tmp
= ac97
->caps
& AC97_BC_DAC_MASK
;
110 snd_iprintf(buffer
, "DAC resolution : %s%s%s%s\n",
111 tmp
== AC97_BC_16BIT_DAC
? "16-bit" : "",
112 tmp
== AC97_BC_18BIT_DAC
? "18-bit" : "",
113 tmp
== AC97_BC_20BIT_DAC
? "20-bit" : "",
114 tmp
== AC97_BC_DAC_MASK
? "???" : "");
115 tmp
= ac97
->caps
& AC97_BC_ADC_MASK
;
116 snd_iprintf(buffer
, "ADC resolution : %s%s%s%s\n",
117 tmp
== AC97_BC_16BIT_ADC
? "16-bit" : "",
118 tmp
== AC97_BC_18BIT_ADC
? "18-bit" : "",
119 tmp
== AC97_BC_20BIT_ADC
? "20-bit" : "",
120 tmp
== AC97_BC_ADC_MASK
? "???" : "");
121 snd_iprintf(buffer
, "3D enhancement : %s\n",
122 snd_ac97_stereo_enhancements
[(val
>> 10) & 0x1f]);
123 snd_iprintf(buffer
, "\nCurrent setup\n");
124 val
= snd_ac97_read(ac97
, AC97_MIC
);
125 snd_iprintf(buffer
, "Mic gain : %s [%s]\n", val
& 0x0040 ? "+20dB" : "+0dB", ac97
->regs
[AC97_MIC
] & 0x0040 ? "+20dB" : "+0dB");
126 val
= snd_ac97_read(ac97
, AC97_GENERAL_PURPOSE
);
127 snd_iprintf(buffer
, "POP path : %s 3D\n"
129 "3D enhancement : %s\n"
133 "ADC/DAC loopback : %s\n",
134 val
& 0x8000 ? "post" : "pre",
135 val
& 0x4000 ? "on" : "off",
136 val
& 0x2000 ? "on" : "off",
137 val
& 0x1000 ? "on" : "off",
138 val
& 0x0200 ? "Mic" : "MIX",
139 val
& 0x0100 ? "Mic2" : "Mic1",
140 val
& 0x0080 ? "on" : "off");
141 if (ac97
->ext_id
& AC97_EI_DRA
)
142 snd_iprintf(buffer
, "Double rate slots: %s\n",
143 double_rate_slots
[(val
>> 10) & 3]);
145 ext
= snd_ac97_read(ac97
, AC97_EXTENDED_ID
);
149 snd_iprintf(buffer
, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n",
150 (ext
& AC97_EI_ADDR_MASK
) >> AC97_EI_ADDR_SHIFT
,
151 (ext
& AC97_EI_REV_MASK
) >> AC97_EI_REV_SHIFT
,
152 ext
& AC97_EI_AMAP
? " AMAP" : "",
153 ext
& AC97_EI_LDAC
? " LDAC" : "",
154 ext
& AC97_EI_SDAC
? " SDAC" : "",
155 ext
& AC97_EI_CDAC
? " CDAC" : "",
156 (ext
& AC97_EI_DACS_SLOT_MASK
) >> AC97_EI_DACS_SLOT_SHIFT
,
157 ext
& AC97_EI_VRM
? " VRM" : "",
158 ext
& AC97_EI_SPDIF
? " SPDIF" : "",
159 ext
& AC97_EI_DRA
? " DRA" : "",
160 ext
& AC97_EI_VRA
? " VRA" : "");
161 val
= snd_ac97_read(ac97
, AC97_EXTENDED_STATUS
);
162 snd_iprintf(buffer
, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
163 val
& AC97_EA_PRL
? " PRL" : "",
164 val
& AC97_EA_PRK
? " PRK" : "",
165 val
& AC97_EA_PRJ
? " PRJ" : "",
166 val
& AC97_EA_PRI
? " PRI" : "",
167 val
& AC97_EA_SPCV
? " SPCV" : "",
168 val
& AC97_EA_MDAC
? " MADC" : "",
169 val
& AC97_EA_LDAC
? " LDAC" : "",
170 val
& AC97_EA_SDAC
? " SDAC" : "",
171 val
& AC97_EA_CDAC
? " CDAC" : "",
172 ext
& AC97_EI_SPDIF
? spdif_slots
[(val
& AC97_EA_SPSA_SLOT_MASK
) >> AC97_EA_SPSA_SLOT_SHIFT
] : "",
173 val
& AC97_EA_VRM
? " VRM" : "",
174 val
& AC97_EA_SPDIF
? " SPDIF" : "",
175 val
& AC97_EA_DRA
? " DRA" : "",
176 val
& AC97_EA_VRA
? " VRA" : "");
177 if (ext
& AC97_EI_VRA
) { /* VRA */
178 val
= snd_ac97_read(ac97
, AC97_PCM_FRONT_DAC_RATE
);
179 snd_iprintf(buffer
, "PCM front DAC : %iHz\n", val
);
180 if (ext
& AC97_EI_SDAC
) {
181 val
= snd_ac97_read(ac97
, AC97_PCM_SURR_DAC_RATE
);
182 snd_iprintf(buffer
, "PCM Surr DAC : %iHz\n", val
);
184 if (ext
& AC97_EI_LDAC
) {
185 val
= snd_ac97_read(ac97
, AC97_PCM_LFE_DAC_RATE
);
186 snd_iprintf(buffer
, "PCM LFE DAC : %iHz\n", val
);
188 val
= snd_ac97_read(ac97
, AC97_PCM_LR_ADC_RATE
);
189 snd_iprintf(buffer
, "PCM ADC : %iHz\n", val
);
191 if (ext
& AC97_EI_VRM
) {
192 val
= snd_ac97_read(ac97
, AC97_PCM_MIC_ADC_RATE
);
193 snd_iprintf(buffer
, "PCM MIC ADC : %iHz\n", val
);
195 if ((ext
& AC97_EI_SPDIF
) || (ac97
->flags
& AC97_CS_SPDIF
)) {
196 if (ac97
->flags
& AC97_CS_SPDIF
)
197 val
= snd_ac97_read(ac97
, AC97_CSR_SPDIF
);
199 val
= snd_ac97_read(ac97
, AC97_SPDIF
);
201 snd_iprintf(buffer
, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n",
202 val
& AC97_SC_PRO
? " PRO" : " Consumer",
203 val
& AC97_SC_NAUDIO
? " Non-audio" : " PCM",
204 val
& AC97_SC_COPY
? "" : " Copyright",
205 val
& AC97_SC_PRE
? " Preemph50/15" : "",
206 (val
& AC97_SC_CC_MASK
) >> AC97_SC_CC_SHIFT
,
207 (val
& AC97_SC_L
) >> 11,
208 (ac97
->flags
& AC97_CS_SPDIF
) ?
209 spdif_rates_cs4205
[(val
& AC97_SC_SPSR_MASK
) >> AC97_SC_SPSR_SHIFT
] :
210 spdif_rates
[(val
& AC97_SC_SPSR_MASK
) >> AC97_SC_SPSR_SHIFT
],
211 (ac97
->flags
& AC97_CS_SPDIF
) ?
212 (val
& AC97_SC_DRS
? " Validity" : "") :
213 (val
& AC97_SC_DRS
? " DRS" : ""),
214 (ac97
->flags
& AC97_CS_SPDIF
) ?
215 (val
& AC97_SC_V
? " Enabled" : "") :
216 (val
& AC97_SC_V
? " Validity" : ""));
218 if ((ac97
->id
& 0xfffffff0) == 0x414c4720 &&
219 (snd_ac97_read(ac97
, AC97_ALC650_CLOCK
) & 0x01)) {
220 val
= snd_ac97_read(ac97
, AC97_ALC650_SPDIF_INPUT_STATUS2
);
221 if (val
& AC97_ALC650_CLOCK_LOCK
) {
222 val
= snd_ac97_read(ac97
, AC97_ALC650_SPDIF_INPUT_STATUS1
);
223 snd_iprintf(buffer
, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i",
224 val
& AC97_ALC650_PRO
? " PRO" : " Consumer",
225 val
& AC97_ALC650_NAUDIO
? " Non-audio" : " PCM",
226 val
& AC97_ALC650_COPY
? "" : " Copyright",
227 val
& AC97_ALC650_PRE
? " Preemph50/15" : "",
228 (val
& AC97_ALC650_CC_MASK
) >> AC97_ALC650_CC_SHIFT
,
229 (val
& AC97_ALC650_L
) >> 15);
230 val
= snd_ac97_read(ac97
, AC97_ALC650_SPDIF_INPUT_STATUS2
);
231 snd_iprintf(buffer
, "%s Accuracy=%i%s%s\n",
232 spdif_rates
[(val
& AC97_ALC650_SPSR_MASK
) >> AC97_ALC650_SPSR_SHIFT
],
233 (val
& AC97_ALC650_CLOCK_ACCURACY
) >> AC97_ALC650_CLOCK_SHIFT
,
234 (val
& AC97_ALC650_CLOCK_LOCK
? " Locked" : " Unlocked"),
235 (val
& AC97_ALC650_V
? " Validity?" : ""));
237 snd_iprintf(buffer
, "SPDIF In Status : Not Locked\n");
241 if ((ac97
->ext_id
& AC97_EI_REV_MASK
) >= AC97_EI_REV_23
) {
242 val
= snd_ac97_read(ac97
, AC97_INT_PAGING
);
243 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
,
244 AC97_PAGE_MASK
, AC97_PAGE_1
);
245 snd_ac97_proc_read_functions(ac97
, buffer
);
246 snd_ac97_update_bits(ac97
, AC97_INT_PAGING
,
247 AC97_PAGE_MASK
, val
& AC97_PAGE_MASK
);
252 mext
= snd_ac97_read(ac97
, AC97_EXTENDED_MID
);
256 snd_iprintf(buffer
, "Extended modem ID: codec=%i%s%s%s%s%s\n",
257 (mext
& AC97_MEI_ADDR_MASK
) >> AC97_MEI_ADDR_SHIFT
,
258 mext
& AC97_MEI_CID2
? " CID2" : "",
259 mext
& AC97_MEI_CID1
? " CID1" : "",
260 mext
& AC97_MEI_HANDSET
? " HSET" : "",
261 mext
& AC97_MEI_LINE2
? " LIN2" : "",
262 mext
& AC97_MEI_LINE1
? " LIN1" : "");
263 val
= snd_ac97_read(ac97
, AC97_EXTENDED_MSTATUS
);
264 snd_iprintf(buffer
, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
265 val
& AC97_MEA_GPIO
? " GPIO" : "",
266 val
& AC97_MEA_MREF
? " MREF" : "",
267 val
& AC97_MEA_ADC1
? " ADC1" : "",
268 val
& AC97_MEA_DAC1
? " DAC1" : "",
269 val
& AC97_MEA_ADC2
? " ADC2" : "",
270 val
& AC97_MEA_DAC2
? " DAC2" : "",
271 val
& AC97_MEA_HADC
? " HADC" : "",
272 val
& AC97_MEA_HDAC
? " HDAC" : "",
273 val
& AC97_MEA_PRA
? " PRA(GPIO)" : "",
274 val
& AC97_MEA_PRB
? " PRB(res)" : "",
275 val
& AC97_MEA_PRC
? " PRC(ADC1)" : "",
276 val
& AC97_MEA_PRD
? " PRD(DAC1)" : "",
277 val
& AC97_MEA_PRE
? " PRE(ADC2)" : "",
278 val
& AC97_MEA_PRF
? " PRF(DAC2)" : "",
279 val
& AC97_MEA_PRG
? " PRG(HADC)" : "",
280 val
& AC97_MEA_PRH
? " PRH(HDAC)" : "");
281 if (mext
& AC97_MEI_LINE1
) {
282 val
= snd_ac97_read(ac97
, AC97_LINE1_RATE
);
283 snd_iprintf(buffer
, "Line1 rate : %iHz\n", val
);
285 if (mext
& AC97_MEI_LINE2
) {
286 val
= snd_ac97_read(ac97
, AC97_LINE2_RATE
);
287 snd_iprintf(buffer
, "Line2 rate : %iHz\n", val
);
289 if (mext
& AC97_MEI_HANDSET
) {
290 val
= snd_ac97_read(ac97
, AC97_HANDSET_RATE
);
291 snd_iprintf(buffer
, "Headset rate : %iHz\n", val
);
295 static void snd_ac97_proc_read(snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
297 ac97_t
*ac97
= entry
->private_data
;
299 down(&ac97
->page_mutex
);
300 if ((ac97
->id
& 0xffffff40) == AC97_ID_AD1881
) { // Analog Devices AD1881/85/86
302 for (idx
= 0; idx
< 3; idx
++)
303 if (ac97
->spec
.ad18xx
.id
[idx
]) {
304 /* select single codec */
305 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
306 ac97
->spec
.ad18xx
.unchained
[idx
] | ac97
->spec
.ad18xx
.chained
[idx
]);
307 snd_ac97_proc_read_main(ac97
, buffer
, idx
);
308 snd_iprintf(buffer
, "\n\n");
310 /* select all codecs */
311 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
313 snd_iprintf(buffer
, "\nAD18XX configuration\n");
314 snd_iprintf(buffer
, "Unchained : 0x%04x,0x%04x,0x%04x\n",
315 ac97
->spec
.ad18xx
.unchained
[0],
316 ac97
->spec
.ad18xx
.unchained
[1],
317 ac97
->spec
.ad18xx
.unchained
[2]);
318 snd_iprintf(buffer
, "Chained : 0x%04x,0x%04x,0x%04x\n",
319 ac97
->spec
.ad18xx
.chained
[0],
320 ac97
->spec
.ad18xx
.chained
[1],
321 ac97
->spec
.ad18xx
.chained
[2]);
323 snd_ac97_proc_read_main(ac97
, buffer
, 0);
325 up(&ac97
->page_mutex
);
328 #ifdef CONFIG_SND_DEBUG
329 /* direct register write for debugging */
330 static void snd_ac97_proc_regs_write(snd_info_entry_t
*entry
, snd_info_buffer_t
*buffer
)
332 ac97_t
*ac97
= entry
->private_data
;
334 unsigned int reg
, val
;
335 down(&ac97
->page_mutex
);
336 while (!snd_info_get_line(buffer
, line
, sizeof(line
))) {
337 if (sscanf(line
, "%x %x", ®
, &val
) != 2)
339 /* register must be even */
340 if (reg
< 0x80 && (reg
& 1) == 0 && val
<= 0xffff)
341 snd_ac97_write_cache(ac97
, reg
, val
);
343 up(&ac97
->page_mutex
);
347 static void snd_ac97_proc_regs_read_main(ac97_t
*ac97
, snd_info_buffer_t
* buffer
, int subidx
)
351 for (reg
= 0; reg
< 0x80; reg
+= 2) {
352 val
= snd_ac97_read(ac97
, reg
);
353 snd_iprintf(buffer
, "%i:%02x = %04x\n", subidx
, reg
, val
);
357 static void snd_ac97_proc_regs_read(snd_info_entry_t
*entry
,
358 snd_info_buffer_t
* buffer
)
360 ac97_t
*ac97
= entry
->private_data
;
362 down(&ac97
->page_mutex
);
363 if ((ac97
->id
& 0xffffff40) == AC97_ID_AD1881
) { // Analog Devices AD1881/85/86
366 for (idx
= 0; idx
< 3; idx
++)
367 if (ac97
->spec
.ad18xx
.id
[idx
]) {
368 /* select single codec */
369 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000,
370 ac97
->spec
.ad18xx
.unchained
[idx
] | ac97
->spec
.ad18xx
.chained
[idx
]);
371 snd_ac97_proc_regs_read_main(ac97
, buffer
, idx
);
373 /* select all codecs */
374 snd_ac97_update_bits(ac97
, AC97_AD_SERIAL_CFG
, 0x7000, 0x7000);
376 snd_ac97_proc_regs_read_main(ac97
, buffer
, 0);
378 up(&ac97
->page_mutex
);
381 void snd_ac97_proc_init(ac97_t
* ac97
)
383 snd_info_entry_t
*entry
;
387 if (ac97
->bus
->proc
== NULL
)
389 prefix
= ac97_is_audio(ac97
) ? "ac97" : "mc97";
390 sprintf(name
, "%s#%d-%d", prefix
, ac97
->addr
, ac97
->num
);
391 if ((entry
= snd_info_create_card_entry(ac97
->bus
->card
, name
, ac97
->bus
->proc
)) != NULL
) {
392 snd_info_set_text_ops(entry
, ac97
, 1024, snd_ac97_proc_read
);
393 if (snd_info_register(entry
) < 0) {
394 snd_info_free_entry(entry
);
399 sprintf(name
, "%s#%d-%d+regs", prefix
, ac97
->addr
, ac97
->num
);
400 if ((entry
= snd_info_create_card_entry(ac97
->bus
->card
, name
, ac97
->bus
->proc
)) != NULL
) {
401 snd_info_set_text_ops(entry
, ac97
, 1024, snd_ac97_proc_regs_read
);
402 #ifdef CONFIG_SND_DEBUG
403 entry
->mode
|= S_IWUSR
;
404 entry
->c
.text
.write_size
= 1024;
405 entry
->c
.text
.write
= snd_ac97_proc_regs_write
;
407 if (snd_info_register(entry
) < 0) {
408 snd_info_free_entry(entry
);
412 ac97
->proc_regs
= entry
;
415 void snd_ac97_proc_done(ac97_t
* ac97
)
417 if (ac97
->proc_regs
) {
418 snd_info_unregister(ac97
->proc_regs
);
419 ac97
->proc_regs
= NULL
;
422 snd_info_unregister(ac97
->proc
);
427 void snd_ac97_bus_proc_init(ac97_bus_t
* bus
)
429 snd_info_entry_t
*entry
;
432 sprintf(name
, "codec97#%d", bus
->num
);
433 if ((entry
= snd_info_create_card_entry(bus
->card
, name
, bus
->card
->proc_root
)) != NULL
) {
434 entry
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
435 if (snd_info_register(entry
) < 0) {
436 snd_info_free_entry(entry
);
443 void snd_ac97_bus_proc_done(ac97_bus_t
* bus
)
446 snd_info_unregister(bus
->proc
);