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(struct snd_ac97 *ac97, struct snd_info_buffer *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(struct snd_ac97 *ac97, struct snd_info_buffer *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);
83 if ((ac97->scaps & AC97_SCAP_AUDIO) == 0)
86 snd_iprintf(buffer, "PCI Subsys Vendor: 0x%04x\n",
87 ac97->subsystem_vendor);
88 snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n",
89 ac97->subsystem_device);
91 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
92 val = snd_ac97_read(ac97, AC97_INT_PAGING);
93 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
94 AC97_PAGE_MASK, AC97_PAGE_1);
95 tmp = snd_ac97_read(ac97, AC97_CODEC_CLASS_REV);
96 snd_iprintf(buffer, "Revision : 0x%02x\n", tmp & 0xff);
97 snd_iprintf(buffer, "Compat. Class : 0x%02x\n", (tmp >> 8) & 0x1f);
98 snd_iprintf(buffer, "Subsys. Vendor ID: 0x%04x\n",
99 snd_ac97_read(ac97, AC97_PCI_SVID));
100 snd_iprintf(buffer, "Subsys. ID : 0x%04x\n\n",
101 snd_ac97_read(ac97, AC97_PCI_SID));
102 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
103 AC97_PAGE_MASK, val & AC97_PAGE_MASK);
106 // val = snd_ac97_read(ac97, AC97_RESET);
108 snd_iprintf(buffer, "Capabilities :%s%s%s%s%s%s\n",
109 val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "",
110 val & AC97_BC_RESERVED1 ? " -reserved1-" : "",
111 val & AC97_BC_BASS_TREBLE ? " -bass & treble-" : "",
112 val & AC97_BC_SIM_STEREO ? " -simulated stereo-" : "",
113 val & AC97_BC_HEADPHONE ? " -headphone out-" : "",
114 val & AC97_BC_LOUDNESS ? " -loudness-" : "");
115 tmp = ac97->caps & AC97_BC_DAC_MASK;
116 snd_iprintf(buffer, "DAC resolution : %s%s%s%s\n",
117 tmp == AC97_BC_16BIT_DAC ? "16-bit" : "",
118 tmp == AC97_BC_18BIT_DAC ? "18-bit" : "",
119 tmp == AC97_BC_20BIT_DAC ? "20-bit" : "",
120 tmp == AC97_BC_DAC_MASK ? "???" : "");
121 tmp = ac97->caps & AC97_BC_ADC_MASK;
122 snd_iprintf(buffer, "ADC resolution : %s%s%s%s\n",
123 tmp == AC97_BC_16BIT_ADC ? "16-bit" : "",
124 tmp == AC97_BC_18BIT_ADC ? "18-bit" : "",
125 tmp == AC97_BC_20BIT_ADC ? "20-bit" : "",
126 tmp == AC97_BC_ADC_MASK ? "???" : "");
127 snd_iprintf(buffer, "3D enhancement : %s\n",
128 snd_ac97_stereo_enhancements[(val >> 10) & 0x1f]);
129 snd_iprintf(buffer, "\nCurrent setup\n");
130 val = snd_ac97_read(ac97, AC97_MIC);
131 snd_iprintf(buffer, "Mic gain : %s [%s]\n", val & 0x0040 ? "+20dB" : "+0dB", ac97->regs[AC97_MIC] & 0x0040 ? "+20dB" : "+0dB");
132 val = snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
133 snd_iprintf(buffer, "POP path : %s 3D\n"
135 "3D enhancement : %s\n"
139 "ADC/DAC loopback : %s\n",
140 val & 0x8000 ? "post" : "pre",
141 val & 0x4000 ? "on" : "off",
142 val & 0x2000 ? "on" : "off",
143 val & 0x1000 ? "on" : "off",
144 val & 0x0200 ? "Mic" : "MIX",
145 val & 0x0100 ? "Mic2" : "Mic1",
146 val & 0x0080 ? "on" : "off");
147 if (ac97->ext_id & AC97_EI_DRA)
148 snd_iprintf(buffer, "Double rate slots: %s\n",
149 double_rate_slots[(val >> 10) & 3]);
151 ext = snd_ac97_read(ac97, AC97_EXTENDED_ID);
155 snd_iprintf(buffer, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n",
156 (ext & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT,
157 (ext & AC97_EI_REV_MASK) >> AC97_EI_REV_SHIFT,
158 ext & AC97_EI_AMAP ? " AMAP" : "",
159 ext & AC97_EI_LDAC ? " LDAC" : "",
160 ext & AC97_EI_SDAC ? " SDAC" : "",
161 ext & AC97_EI_CDAC ? " CDAC" : "",
162 (ext & AC97_EI_DACS_SLOT_MASK) >> AC97_EI_DACS_SLOT_SHIFT,
163 ext & AC97_EI_VRM ? " VRM" : "",
164 ext & AC97_EI_SPDIF ? " SPDIF" : "",
165 ext & AC97_EI_DRA ? " DRA" : "",
166 ext & AC97_EI_VRA ? " VRA" : "");
167 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
168 snd_iprintf(buffer, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
169 val & AC97_EA_PRL ? " PRL" : "",
170 val & AC97_EA_PRK ? " PRK" : "",
171 val & AC97_EA_PRJ ? " PRJ" : "",
172 val & AC97_EA_PRI ? " PRI" : "",
173 val & AC97_EA_SPCV ? " SPCV" : "",
174 val & AC97_EA_MDAC ? " MADC" : "",
175 val & AC97_EA_LDAC ? " LDAC" : "",
176 val & AC97_EA_SDAC ? " SDAC" : "",
177 val & AC97_EA_CDAC ? " CDAC" : "",
178 ext & AC97_EI_SPDIF ? spdif_slots[(val & AC97_EA_SPSA_SLOT_MASK) >> AC97_EA_SPSA_SLOT_SHIFT] : "",
179 val & AC97_EA_VRM ? " VRM" : "",
180 val & AC97_EA_SPDIF ? " SPDIF" : "",
181 val & AC97_EA_DRA ? " DRA" : "",
182 val & AC97_EA_VRA ? " VRA" : "");
183 if (ext & AC97_EI_VRA) { /* VRA */
184 val = snd_ac97_read(ac97, AC97_PCM_FRONT_DAC_RATE);
185 snd_iprintf(buffer, "PCM front DAC : %iHz\n", val);
186 if (ext & AC97_EI_SDAC) {
187 val = snd_ac97_read(ac97, AC97_PCM_SURR_DAC_RATE);
188 snd_iprintf(buffer, "PCM Surr DAC : %iHz\n", val);
190 if (ext & AC97_EI_LDAC) {
191 val = snd_ac97_read(ac97, AC97_PCM_LFE_DAC_RATE);
192 snd_iprintf(buffer, "PCM LFE DAC : %iHz\n", val);
194 val = snd_ac97_read(ac97, AC97_PCM_LR_ADC_RATE);
195 snd_iprintf(buffer, "PCM ADC : %iHz\n", val);
197 if (ext & AC97_EI_VRM) {
198 val = snd_ac97_read(ac97, AC97_PCM_MIC_ADC_RATE);
199 snd_iprintf(buffer, "PCM MIC ADC : %iHz\n", val);
201 if ((ext & AC97_EI_SPDIF) || (ac97->flags & AC97_CS_SPDIF)) {
202 if (ac97->flags & AC97_CS_SPDIF)
203 val = snd_ac97_read(ac97, AC97_CSR_SPDIF);
205 val = snd_ac97_read(ac97, AC97_SPDIF);
207 snd_iprintf(buffer, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n",
208 val & AC97_SC_PRO ? " PRO" : " Consumer",
209 val & AC97_SC_NAUDIO ? " Non-audio" : " PCM",
210 val & AC97_SC_COPY ? "" : " Copyright",
211 val & AC97_SC_PRE ? " Preemph50/15" : "",
212 (val & AC97_SC_CC_MASK) >> AC97_SC_CC_SHIFT,
213 (val & AC97_SC_L) >> 11,
214 (ac97->flags & AC97_CS_SPDIF) ?
215 spdif_rates_cs4205[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT] :
216 spdif_rates[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT],
217 (ac97->flags & AC97_CS_SPDIF) ?
218 (val & AC97_SC_DRS ? " Validity" : "") :
219 (val & AC97_SC_DRS ? " DRS" : ""),
220 (ac97->flags & AC97_CS_SPDIF) ?
221 (val & AC97_SC_V ? " Enabled" : "") :
222 (val & AC97_SC_V ? " Validity" : ""));
224 if ((ac97->id & 0xfffffff0) == 0x414c4720 &&
225 (snd_ac97_read(ac97, AC97_ALC650_CLOCK) & 0x01)) {
226 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
227 if (val & AC97_ALC650_CLOCK_LOCK) {
228 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS1);
229 snd_iprintf(buffer, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i",
230 val & AC97_ALC650_PRO ? " PRO" : " Consumer",
231 val & AC97_ALC650_NAUDIO ? " Non-audio" : " PCM",
232 val & AC97_ALC650_COPY ? "" : " Copyright",
233 val & AC97_ALC650_PRE ? " Preemph50/15" : "",
234 (val & AC97_ALC650_CC_MASK) >> AC97_ALC650_CC_SHIFT,
235 (val & AC97_ALC650_L) >> 15);
236 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
237 snd_iprintf(buffer, "%s Accuracy=%i%s%s\n",
238 spdif_rates[(val & AC97_ALC650_SPSR_MASK) >> AC97_ALC650_SPSR_SHIFT],
239 (val & AC97_ALC650_CLOCK_ACCURACY) >> AC97_ALC650_CLOCK_SHIFT,
240 (val & AC97_ALC650_CLOCK_LOCK ? " Locked" : " Unlocked"),
241 (val & AC97_ALC650_V ? " Validity?" : ""));
243 snd_iprintf(buffer, "SPDIF In Status : Not Locked\n");
247 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
248 val = snd_ac97_read(ac97, AC97_INT_PAGING);
249 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
250 AC97_PAGE_MASK, AC97_PAGE_1);
251 snd_ac97_proc_read_functions(ac97, buffer);
252 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
253 AC97_PAGE_MASK, val & AC97_PAGE_MASK);
258 mext = snd_ac97_read(ac97, AC97_EXTENDED_MID);
262 snd_iprintf(buffer, "Extended modem ID: codec=%i%s%s%s%s%s\n",
263 (mext & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT,
264 mext & AC97_MEI_CID2 ? " CID2" : "",
265 mext & AC97_MEI_CID1 ? " CID1" : "",
266 mext & AC97_MEI_HANDSET ? " HSET" : "",
267 mext & AC97_MEI_LINE2 ? " LIN2" : "",
268 mext & AC97_MEI_LINE1 ? " LIN1" : "");
269 val = snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS);
270 snd_iprintf(buffer, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
271 val & AC97_MEA_GPIO ? " GPIO" : "",
272 val & AC97_MEA_MREF ? " MREF" : "",
273 val & AC97_MEA_ADC1 ? " ADC1" : "",
274 val & AC97_MEA_DAC1 ? " DAC1" : "",
275 val & AC97_MEA_ADC2 ? " ADC2" : "",
276 val & AC97_MEA_DAC2 ? " DAC2" : "",
277 val & AC97_MEA_HADC ? " HADC" : "",
278 val & AC97_MEA_HDAC ? " HDAC" : "",
279 val & AC97_MEA_PRA ? " PRA(GPIO)" : "",
280 val & AC97_MEA_PRB ? " PRB(res)" : "",
281 val & AC97_MEA_PRC ? " PRC(ADC1)" : "",
282 val & AC97_MEA_PRD ? " PRD(DAC1)" : "",
283 val & AC97_MEA_PRE ? " PRE(ADC2)" : "",
284 val & AC97_MEA_PRF ? " PRF(DAC2)" : "",
285 val & AC97_MEA_PRG ? " PRG(HADC)" : "",
286 val & AC97_MEA_PRH ? " PRH(HDAC)" : "");
287 if (mext & AC97_MEI_LINE1) {
288 val = snd_ac97_read(ac97, AC97_LINE1_RATE);
289 snd_iprintf(buffer, "Line1 rate : %iHz\n", val);
291 if (mext & AC97_MEI_LINE2) {
292 val = snd_ac97_read(ac97, AC97_LINE2_RATE);
293 snd_iprintf(buffer, "Line2 rate : %iHz\n", val);
295 if (mext & AC97_MEI_HANDSET) {
296 val = snd_ac97_read(ac97, AC97_HANDSET_RATE);
297 snd_iprintf(buffer, "Headset rate : %iHz\n", val);
301 static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
303 struct snd_ac97 *ac97 = entry->private_data;
305 down(&ac97->page_mutex);
306 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
308 for (idx = 0; idx < 3; idx++)
309 if (ac97->spec.ad18xx.id[idx]) {
310 /* select single codec */
311 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
312 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
313 snd_ac97_proc_read_main(ac97, buffer, idx);
314 snd_iprintf(buffer, "\n\n");
316 /* select all codecs */
317 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
319 snd_iprintf(buffer, "\nAD18XX configuration\n");
320 snd_iprintf(buffer, "Unchained : 0x%04x,0x%04x,0x%04x\n",
321 ac97->spec.ad18xx.unchained[0],
322 ac97->spec.ad18xx.unchained[1],
323 ac97->spec.ad18xx.unchained[2]);
324 snd_iprintf(buffer, "Chained : 0x%04x,0x%04x,0x%04x\n",
325 ac97->spec.ad18xx.chained[0],
326 ac97->spec.ad18xx.chained[1],
327 ac97->spec.ad18xx.chained[2]);
329 snd_ac97_proc_read_main(ac97, buffer, 0);
331 up(&ac97->page_mutex);
334 #ifdef CONFIG_SND_DEBUG
335 /* direct register write for debugging */
336 static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
338 struct snd_ac97 *ac97 = entry->private_data;
340 unsigned int reg, val;
341 down(&ac97->page_mutex);
342 while (!snd_info_get_line(buffer, line, sizeof(line))) {
343 if (sscanf(line, "%x %x", ®, &val) != 2)
345 /* register must be even */
346 if (reg < 0x80 && (reg & 1) == 0 && val <= 0xffff)
347 snd_ac97_write_cache(ac97, reg, val);
349 up(&ac97->page_mutex);
353 static void snd_ac97_proc_regs_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx)
357 for (reg = 0; reg < 0x80; reg += 2) {
358 val = snd_ac97_read(ac97, reg);
359 snd_iprintf(buffer, "%i:%02x = %04x\n", subidx, reg, val);
363 static void snd_ac97_proc_regs_read(struct snd_info_entry *entry,
364 struct snd_info_buffer *buffer)
366 struct snd_ac97 *ac97 = entry->private_data;
368 down(&ac97->page_mutex);
369 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
372 for (idx = 0; idx < 3; idx++)
373 if (ac97->spec.ad18xx.id[idx]) {
374 /* select single codec */
375 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
376 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
377 snd_ac97_proc_regs_read_main(ac97, buffer, idx);
379 /* select all codecs */
380 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
382 snd_ac97_proc_regs_read_main(ac97, buffer, 0);
384 up(&ac97->page_mutex);
387 void snd_ac97_proc_init(struct snd_ac97 * ac97)
389 struct snd_info_entry *entry;
393 if (ac97->bus->proc == NULL)
395 prefix = ac97_is_audio(ac97) ? "ac97" : "mc97";
396 sprintf(name, "%s#%d-%d", prefix, ac97->addr, ac97->num);
397 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
398 snd_info_set_text_ops(entry, ac97, 1024, snd_ac97_proc_read);
399 if (snd_info_register(entry) < 0) {
400 snd_info_free_entry(entry);
405 sprintf(name, "%s#%d-%d+regs", prefix, ac97->addr, ac97->num);
406 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
407 snd_info_set_text_ops(entry, ac97, 1024, snd_ac97_proc_regs_read);
408 #ifdef CONFIG_SND_DEBUG
409 entry->mode |= S_IWUSR;
410 entry->c.text.write_size = 1024;
411 entry->c.text.write = snd_ac97_proc_regs_write;
413 if (snd_info_register(entry) < 0) {
414 snd_info_free_entry(entry);
418 ac97->proc_regs = entry;
421 void snd_ac97_proc_done(struct snd_ac97 * ac97)
423 if (ac97->proc_regs) {
424 snd_info_unregister(ac97->proc_regs);
425 ac97->proc_regs = NULL;
428 snd_info_unregister(ac97->proc);
433 void snd_ac97_bus_proc_init(struct snd_ac97_bus * bus)
435 struct snd_info_entry *entry;
438 sprintf(name, "codec97#%d", bus->num);
439 if ((entry = snd_info_create_card_entry(bus->card, name, bus->card->proc_root)) != NULL) {
440 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
441 if (snd_info_register(entry) < 0) {
442 snd_info_free_entry(entry);
449 void snd_ac97_bus_proc_done(struct snd_ac97_bus * bus)
452 snd_info_unregister(bus->proc);