blob: 060ea59d5f02f02e74c06b28c68a5c37fb0a7446 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Universal interface for Audio Codec '97
4 *
5 * For more details look to AC '97 component specification revision 2.2
6 * by Intel Corporation (http://developer.intel.com).
7 *
8 *
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.
13 *
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.
18 *
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
22 *
23 */
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/slab.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026#include <linux/mutex.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include <sound/ac97_codec.h>
30#include <sound/asoundef.h>
31#include "ac97_local.h"
32#include "ac97_id.h"
33
34/*
35 * proc interface
36 */
37
Takashi Iwaiee423812005-11-17 14:21:36 +010038static void snd_ac97_proc_read_functions(struct snd_ac97 *ac97, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 int header = 0, function;
41 unsigned short info, sense_info;
42 static const char *function_names[12] = {
43 "Master Out", "AUX Out", "Center/LFE Out", "SPDIF Out",
44 "Phone In", "Mic 1", "Mic 2", "Line In", "CD In", "Video In",
45 "Aux In", "Mono Out"
46 };
47 static const char *locations[8] = {
48 "Rear I/O Panel", "Front Panel", "Motherboard", "Dock/External",
49 "reserved", "reserved", "reserved", "NC/unused"
50 };
51
52 for (function = 0; function < 12; ++function) {
53 snd_ac97_write(ac97, AC97_FUNC_SELECT, function << 1);
54 info = snd_ac97_read(ac97, AC97_FUNC_INFO);
55 if (!(info & 0x0001))
56 continue;
57 if (!header) {
58 snd_iprintf(buffer, "\n Gain Inverted Buffer delay Location\n");
59 header = 1;
60 }
61 sense_info = snd_ac97_read(ac97, AC97_SENSE_INFO);
62 snd_iprintf(buffer, "%-17s: %3d.%d dBV %c %2d/fs %s\n",
63 function_names[function],
64 (info & 0x8000 ? -1 : 1) * ((info & 0x7000) >> 12) * 3 / 2,
65 ((info & 0x0800) >> 11) * 5,
66 info & 0x0400 ? 'X' : '-',
67 (info & 0x03e0) >> 5,
68 locations[sense_info >> 13]);
69 }
70}
71
Takashi Iwaiadf1b3d2005-12-01 10:49:58 +010072static const char *snd_ac97_stereo_enhancements[] =
73{
74 /* 0 */ "No 3D Stereo Enhancement",
75 /* 1 */ "Analog Devices Phat Stereo",
76 /* 2 */ "Creative Stereo Enhancement",
77 /* 3 */ "National Semi 3D Stereo Enhancement",
78 /* 4 */ "YAMAHA Ymersion",
79 /* 5 */ "BBE 3D Stereo Enhancement",
80 /* 6 */ "Crystal Semi 3D Stereo Enhancement",
81 /* 7 */ "Qsound QXpander",
82 /* 8 */ "Spatializer 3D Stereo Enhancement",
83 /* 9 */ "SRS 3D Stereo Enhancement",
84 /* 10 */ "Platform Tech 3D Stereo Enhancement",
85 /* 11 */ "AKM 3D Audio",
86 /* 12 */ "Aureal Stereo Enhancement",
87 /* 13 */ "Aztech 3D Enhancement",
88 /* 14 */ "Binaura 3D Audio Enhancement",
89 /* 15 */ "ESS Technology Stereo Enhancement",
90 /* 16 */ "Harman International VMAx",
91 /* 17 */ "Nvidea/IC Ensemble/KS Waves 3D Stereo Enhancement",
92 /* 18 */ "Philips Incredible Sound",
93 /* 19 */ "Texas Instruments 3D Stereo Enhancement",
94 /* 20 */ "VLSI Technology 3D Stereo Enhancement",
95 /* 21 */ "TriTech 3D Stereo Enhancement",
96 /* 22 */ "Realtek 3D Stereo Enhancement",
97 /* 23 */ "Samsung 3D Stereo Enhancement",
98 /* 24 */ "Wolfson Microelectronics 3D Enhancement",
99 /* 25 */ "Delta Integration 3D Enhancement",
100 /* 26 */ "SigmaTel 3D Enhancement",
101 /* 27 */ "IC Ensemble/KS Waves",
102 /* 28 */ "Rockwell 3D Stereo Enhancement",
103 /* 29 */ "Reserved 29",
104 /* 30 */ "Reserved 30",
105 /* 31 */ "Reserved 31"
106};
107
Takashi Iwaiee423812005-11-17 14:21:36 +0100108static void snd_ac97_proc_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 char name[64];
111 unsigned short val, tmp, ext, mext;
112 static const char *spdif_slots[4] = { " SPDIF=3/4", " SPDIF=7/8", " SPDIF=6/9", " SPDIF=10/11" };
113 static const char *spdif_rates[4] = { " Rate=44.1kHz", " Rate=res", " Rate=48kHz", " Rate=32kHz" };
114 static const char *spdif_rates_cs4205[4] = { " Rate=48kHz", " Rate=44.1kHz", " Rate=res", " Rate=res" };
115 static const char *double_rate_slots[4] = { "10/11", "7/8", "reserved", "reserved" };
116
117 snd_ac97_get_name(NULL, ac97->id, name, 0);
118 snd_iprintf(buffer, "%d-%d/%d: %s\n\n", ac97->addr, ac97->num, subidx, name);
Jaroslav Kyselab4a621f2005-11-14 08:48:59 +0100119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if ((ac97->scaps & AC97_SCAP_AUDIO) == 0)
121 goto __modem;
122
Jaroslav Kyselab4a621f2005-11-14 08:48:59 +0100123 snd_iprintf(buffer, "PCI Subsys Vendor: 0x%04x\n",
124 ac97->subsystem_vendor);
125 snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n",
126 ac97->subsystem_device);
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
129 val = snd_ac97_read(ac97, AC97_INT_PAGING);
130 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
131 AC97_PAGE_MASK, AC97_PAGE_1);
132 tmp = snd_ac97_read(ac97, AC97_CODEC_CLASS_REV);
133 snd_iprintf(buffer, "Revision : 0x%02x\n", tmp & 0xff);
134 snd_iprintf(buffer, "Compat. Class : 0x%02x\n", (tmp >> 8) & 0x1f);
135 snd_iprintf(buffer, "Subsys. Vendor ID: 0x%04x\n",
136 snd_ac97_read(ac97, AC97_PCI_SVID));
137 snd_iprintf(buffer, "Subsys. ID : 0x%04x\n\n",
138 snd_ac97_read(ac97, AC97_PCI_SID));
139 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
140 AC97_PAGE_MASK, val & AC97_PAGE_MASK);
141 }
142
143 // val = snd_ac97_read(ac97, AC97_RESET);
144 val = ac97->caps;
145 snd_iprintf(buffer, "Capabilities :%s%s%s%s%s%s\n",
146 val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "",
147 val & AC97_BC_RESERVED1 ? " -reserved1-" : "",
148 val & AC97_BC_BASS_TREBLE ? " -bass & treble-" : "",
149 val & AC97_BC_SIM_STEREO ? " -simulated stereo-" : "",
150 val & AC97_BC_HEADPHONE ? " -headphone out-" : "",
151 val & AC97_BC_LOUDNESS ? " -loudness-" : "");
152 tmp = ac97->caps & AC97_BC_DAC_MASK;
153 snd_iprintf(buffer, "DAC resolution : %s%s%s%s\n",
154 tmp == AC97_BC_16BIT_DAC ? "16-bit" : "",
155 tmp == AC97_BC_18BIT_DAC ? "18-bit" : "",
156 tmp == AC97_BC_20BIT_DAC ? "20-bit" : "",
157 tmp == AC97_BC_DAC_MASK ? "???" : "");
158 tmp = ac97->caps & AC97_BC_ADC_MASK;
159 snd_iprintf(buffer, "ADC resolution : %s%s%s%s\n",
160 tmp == AC97_BC_16BIT_ADC ? "16-bit" : "",
161 tmp == AC97_BC_18BIT_ADC ? "18-bit" : "",
162 tmp == AC97_BC_20BIT_ADC ? "20-bit" : "",
163 tmp == AC97_BC_ADC_MASK ? "???" : "");
164 snd_iprintf(buffer, "3D enhancement : %s\n",
165 snd_ac97_stereo_enhancements[(val >> 10) & 0x1f]);
166 snd_iprintf(buffer, "\nCurrent setup\n");
167 val = snd_ac97_read(ac97, AC97_MIC);
168 snd_iprintf(buffer, "Mic gain : %s [%s]\n", val & 0x0040 ? "+20dB" : "+0dB", ac97->regs[AC97_MIC] & 0x0040 ? "+20dB" : "+0dB");
169 val = snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
170 snd_iprintf(buffer, "POP path : %s 3D\n"
171 "Sim. stereo : %s\n"
172 "3D enhancement : %s\n"
173 "Loudness : %s\n"
174 "Mono output : %s\n"
175 "Mic select : %s\n"
176 "ADC/DAC loopback : %s\n",
177 val & 0x8000 ? "post" : "pre",
178 val & 0x4000 ? "on" : "off",
179 val & 0x2000 ? "on" : "off",
180 val & 0x1000 ? "on" : "off",
181 val & 0x0200 ? "Mic" : "MIX",
182 val & 0x0100 ? "Mic2" : "Mic1",
183 val & 0x0080 ? "on" : "off");
184 if (ac97->ext_id & AC97_EI_DRA)
185 snd_iprintf(buffer, "Double rate slots: %s\n",
186 double_rate_slots[(val >> 10) & 3]);
187
188 ext = snd_ac97_read(ac97, AC97_EXTENDED_ID);
189 if (ext == 0)
190 goto __modem;
191
192 snd_iprintf(buffer, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n",
193 (ext & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT,
194 (ext & AC97_EI_REV_MASK) >> AC97_EI_REV_SHIFT,
195 ext & AC97_EI_AMAP ? " AMAP" : "",
196 ext & AC97_EI_LDAC ? " LDAC" : "",
197 ext & AC97_EI_SDAC ? " SDAC" : "",
198 ext & AC97_EI_CDAC ? " CDAC" : "",
199 (ext & AC97_EI_DACS_SLOT_MASK) >> AC97_EI_DACS_SLOT_SHIFT,
200 ext & AC97_EI_VRM ? " VRM" : "",
201 ext & AC97_EI_SPDIF ? " SPDIF" : "",
202 ext & AC97_EI_DRA ? " DRA" : "",
203 ext & AC97_EI_VRA ? " VRA" : "");
204 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
205 snd_iprintf(buffer, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
206 val & AC97_EA_PRL ? " PRL" : "",
207 val & AC97_EA_PRK ? " PRK" : "",
208 val & AC97_EA_PRJ ? " PRJ" : "",
209 val & AC97_EA_PRI ? " PRI" : "",
210 val & AC97_EA_SPCV ? " SPCV" : "",
211 val & AC97_EA_MDAC ? " MADC" : "",
212 val & AC97_EA_LDAC ? " LDAC" : "",
213 val & AC97_EA_SDAC ? " SDAC" : "",
214 val & AC97_EA_CDAC ? " CDAC" : "",
215 ext & AC97_EI_SPDIF ? spdif_slots[(val & AC97_EA_SPSA_SLOT_MASK) >> AC97_EA_SPSA_SLOT_SHIFT] : "",
216 val & AC97_EA_VRM ? " VRM" : "",
217 val & AC97_EA_SPDIF ? " SPDIF" : "",
218 val & AC97_EA_DRA ? " DRA" : "",
219 val & AC97_EA_VRA ? " VRA" : "");
220 if (ext & AC97_EI_VRA) { /* VRA */
221 val = snd_ac97_read(ac97, AC97_PCM_FRONT_DAC_RATE);
222 snd_iprintf(buffer, "PCM front DAC : %iHz\n", val);
223 if (ext & AC97_EI_SDAC) {
224 val = snd_ac97_read(ac97, AC97_PCM_SURR_DAC_RATE);
225 snd_iprintf(buffer, "PCM Surr DAC : %iHz\n", val);
226 }
227 if (ext & AC97_EI_LDAC) {
228 val = snd_ac97_read(ac97, AC97_PCM_LFE_DAC_RATE);
229 snd_iprintf(buffer, "PCM LFE DAC : %iHz\n", val);
230 }
231 val = snd_ac97_read(ac97, AC97_PCM_LR_ADC_RATE);
232 snd_iprintf(buffer, "PCM ADC : %iHz\n", val);
233 }
234 if (ext & AC97_EI_VRM) {
235 val = snd_ac97_read(ac97, AC97_PCM_MIC_ADC_RATE);
236 snd_iprintf(buffer, "PCM MIC ADC : %iHz\n", val);
237 }
Keita Maehara43115f52007-09-19 14:29:37 +0200238 if ((ext & AC97_EI_SPDIF) || (ac97->flags & AC97_CS_SPDIF) ||
239 (ac97->id == AC97_ID_YMF743)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (ac97->flags & AC97_CS_SPDIF)
241 val = snd_ac97_read(ac97, AC97_CSR_SPDIF);
Keita Maehara43115f52007-09-19 14:29:37 +0200242 else if (ac97->id == AC97_ID_YMF743) {
243 val = snd_ac97_read(ac97, AC97_YMF7X3_DIT_CTRL);
244 val = 0x2000 | (val & 0xff00) >> 4 | (val & 0x38) >> 2;
245 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 val = snd_ac97_read(ac97, AC97_SPDIF);
247
248 snd_iprintf(buffer, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n",
249 val & AC97_SC_PRO ? " PRO" : " Consumer",
250 val & AC97_SC_NAUDIO ? " Non-audio" : " PCM",
251 val & AC97_SC_COPY ? "" : " Copyright",
252 val & AC97_SC_PRE ? " Preemph50/15" : "",
253 (val & AC97_SC_CC_MASK) >> AC97_SC_CC_SHIFT,
254 (val & AC97_SC_L) >> 11,
255 (ac97->flags & AC97_CS_SPDIF) ?
256 spdif_rates_cs4205[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT] :
257 spdif_rates[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT],
258 (ac97->flags & AC97_CS_SPDIF) ?
259 (val & AC97_SC_DRS ? " Validity" : "") :
260 (val & AC97_SC_DRS ? " DRS" : ""),
261 (ac97->flags & AC97_CS_SPDIF) ?
262 (val & AC97_SC_V ? " Enabled" : "") :
263 (val & AC97_SC_V ? " Validity" : ""));
264 /* ALC650 specific*/
265 if ((ac97->id & 0xfffffff0) == 0x414c4720 &&
266 (snd_ac97_read(ac97, AC97_ALC650_CLOCK) & 0x01)) {
267 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
268 if (val & AC97_ALC650_CLOCK_LOCK) {
269 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS1);
270 snd_iprintf(buffer, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i",
271 val & AC97_ALC650_PRO ? " PRO" : " Consumer",
272 val & AC97_ALC650_NAUDIO ? " Non-audio" : " PCM",
273 val & AC97_ALC650_COPY ? "" : " Copyright",
274 val & AC97_ALC650_PRE ? " Preemph50/15" : "",
275 (val & AC97_ALC650_CC_MASK) >> AC97_ALC650_CC_SHIFT,
276 (val & AC97_ALC650_L) >> 15);
277 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
278 snd_iprintf(buffer, "%s Accuracy=%i%s%s\n",
279 spdif_rates[(val & AC97_ALC650_SPSR_MASK) >> AC97_ALC650_SPSR_SHIFT],
280 (val & AC97_ALC650_CLOCK_ACCURACY) >> AC97_ALC650_CLOCK_SHIFT,
281 (val & AC97_ALC650_CLOCK_LOCK ? " Locked" : " Unlocked"),
282 (val & AC97_ALC650_V ? " Validity?" : ""));
283 } else {
284 snd_iprintf(buffer, "SPDIF In Status : Not Locked\n");
285 }
286 }
287 }
288 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
289 val = snd_ac97_read(ac97, AC97_INT_PAGING);
290 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
291 AC97_PAGE_MASK, AC97_PAGE_1);
292 snd_ac97_proc_read_functions(ac97, buffer);
293 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
294 AC97_PAGE_MASK, val & AC97_PAGE_MASK);
295 }
296
297
298 __modem:
299 mext = snd_ac97_read(ac97, AC97_EXTENDED_MID);
300 if (mext == 0)
301 return;
302
303 snd_iprintf(buffer, "Extended modem ID: codec=%i%s%s%s%s%s\n",
304 (mext & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT,
305 mext & AC97_MEI_CID2 ? " CID2" : "",
306 mext & AC97_MEI_CID1 ? " CID1" : "",
307 mext & AC97_MEI_HANDSET ? " HSET" : "",
308 mext & AC97_MEI_LINE2 ? " LIN2" : "",
309 mext & AC97_MEI_LINE1 ? " LIN1" : "");
310 val = snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS);
311 snd_iprintf(buffer, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
312 val & AC97_MEA_GPIO ? " GPIO" : "",
313 val & AC97_MEA_MREF ? " MREF" : "",
314 val & AC97_MEA_ADC1 ? " ADC1" : "",
315 val & AC97_MEA_DAC1 ? " DAC1" : "",
316 val & AC97_MEA_ADC2 ? " ADC2" : "",
317 val & AC97_MEA_DAC2 ? " DAC2" : "",
318 val & AC97_MEA_HADC ? " HADC" : "",
319 val & AC97_MEA_HDAC ? " HDAC" : "",
320 val & AC97_MEA_PRA ? " PRA(GPIO)" : "",
321 val & AC97_MEA_PRB ? " PRB(res)" : "",
322 val & AC97_MEA_PRC ? " PRC(ADC1)" : "",
323 val & AC97_MEA_PRD ? " PRD(DAC1)" : "",
324 val & AC97_MEA_PRE ? " PRE(ADC2)" : "",
325 val & AC97_MEA_PRF ? " PRF(DAC2)" : "",
326 val & AC97_MEA_PRG ? " PRG(HADC)" : "",
327 val & AC97_MEA_PRH ? " PRH(HDAC)" : "");
328 if (mext & AC97_MEI_LINE1) {
329 val = snd_ac97_read(ac97, AC97_LINE1_RATE);
330 snd_iprintf(buffer, "Line1 rate : %iHz\n", val);
331 }
332 if (mext & AC97_MEI_LINE2) {
333 val = snd_ac97_read(ac97, AC97_LINE2_RATE);
334 snd_iprintf(buffer, "Line2 rate : %iHz\n", val);
335 }
336 if (mext & AC97_MEI_HANDSET) {
337 val = snd_ac97_read(ac97, AC97_HANDSET_RATE);
338 snd_iprintf(buffer, "Headset rate : %iHz\n", val);
339 }
340}
341
Takashi Iwaiee423812005-11-17 14:21:36 +0100342static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Takashi Iwaiee423812005-11-17 14:21:36 +0100344 struct snd_ac97 *ac97 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Ingo Molnar62932df2006-01-16 16:34:20 +0100346 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
348 int idx;
349 for (idx = 0; idx < 3; idx++)
350 if (ac97->spec.ad18xx.id[idx]) {
351 /* select single codec */
352 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
353 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
354 snd_ac97_proc_read_main(ac97, buffer, idx);
355 snd_iprintf(buffer, "\n\n");
356 }
357 /* select all codecs */
358 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
359
360 snd_iprintf(buffer, "\nAD18XX configuration\n");
361 snd_iprintf(buffer, "Unchained : 0x%04x,0x%04x,0x%04x\n",
362 ac97->spec.ad18xx.unchained[0],
363 ac97->spec.ad18xx.unchained[1],
364 ac97->spec.ad18xx.unchained[2]);
365 snd_iprintf(buffer, "Chained : 0x%04x,0x%04x,0x%04x\n",
366 ac97->spec.ad18xx.chained[0],
367 ac97->spec.ad18xx.chained[1],
368 ac97->spec.ad18xx.chained[2]);
369 } else {
370 snd_ac97_proc_read_main(ac97, buffer, 0);
371 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100372 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
375#ifdef CONFIG_SND_DEBUG
376/* direct register write for debugging */
Takashi Iwaiee423812005-11-17 14:21:36 +0100377static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Takashi Iwaiee423812005-11-17 14:21:36 +0100379 struct snd_ac97 *ac97 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 char line[64];
381 unsigned int reg, val;
Ingo Molnar62932df2006-01-16 16:34:20 +0100382 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 while (!snd_info_get_line(buffer, line, sizeof(line))) {
384 if (sscanf(line, "%x %x", &reg, &val) != 2)
385 continue;
386 /* register must be even */
387 if (reg < 0x80 && (reg & 1) == 0 && val <= 0xffff)
388 snd_ac97_write_cache(ac97, reg, val);
389 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100390 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391}
392#endif
393
Takashi Iwaiee423812005-11-17 14:21:36 +0100394static void snd_ac97_proc_regs_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 int reg, val;
397
398 for (reg = 0; reg < 0x80; reg += 2) {
399 val = snd_ac97_read(ac97, reg);
400 snd_iprintf(buffer, "%i:%02x = %04x\n", subidx, reg, val);
401 }
402}
403
Takashi Iwaiee423812005-11-17 14:21:36 +0100404static void snd_ac97_proc_regs_read(struct snd_info_entry *entry,
405 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
Takashi Iwaiee423812005-11-17 14:21:36 +0100407 struct snd_ac97 *ac97 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Ingo Molnar62932df2006-01-16 16:34:20 +0100409 mutex_lock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
411
412 int idx;
413 for (idx = 0; idx < 3; idx++)
414 if (ac97->spec.ad18xx.id[idx]) {
415 /* select single codec */
416 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
417 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
418 snd_ac97_proc_regs_read_main(ac97, buffer, idx);
419 }
420 /* select all codecs */
421 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
422 } else {
423 snd_ac97_proc_regs_read_main(ac97, buffer, 0);
424 }
Ingo Molnar62932df2006-01-16 16:34:20 +0100425 mutex_unlock(&ac97->page_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Takashi Iwaiee423812005-11-17 14:21:36 +0100428void snd_ac97_proc_init(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Takashi Iwaiee423812005-11-17 14:21:36 +0100430 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 char name[32];
432 const char *prefix;
433
434 if (ac97->bus->proc == NULL)
435 return;
436 prefix = ac97_is_audio(ac97) ? "ac97" : "mc97";
437 sprintf(name, "%s#%d-%d", prefix, ac97->addr, ac97->num);
438 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
Takashi Iwaibf850202006-04-28 15:13:41 +0200439 snd_info_set_text_ops(entry, ac97, snd_ac97_proc_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 if (snd_info_register(entry) < 0) {
441 snd_info_free_entry(entry);
442 entry = NULL;
443 }
444 }
445 ac97->proc = entry;
446 sprintf(name, "%s#%d-%d+regs", prefix, ac97->addr, ac97->num);
447 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
Takashi Iwaibf850202006-04-28 15:13:41 +0200448 snd_info_set_text_ops(entry, ac97, snd_ac97_proc_regs_read);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#ifdef CONFIG_SND_DEBUG
450 entry->mode |= S_IWUSR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 entry->c.text.write = snd_ac97_proc_regs_write;
452#endif
453 if (snd_info_register(entry) < 0) {
454 snd_info_free_entry(entry);
455 entry = NULL;
456 }
457 }
458 ac97->proc_regs = entry;
459}
460
Takashi Iwaiee423812005-11-17 14:21:36 +0100461void snd_ac97_proc_done(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
Takashi Iwai746d4a02006-06-23 14:37:59 +0200463 snd_info_free_entry(ac97->proc_regs);
464 ac97->proc_regs = NULL;
465 snd_info_free_entry(ac97->proc);
466 ac97->proc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
Takashi Iwaiee423812005-11-17 14:21:36 +0100469void snd_ac97_bus_proc_init(struct snd_ac97_bus * bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Takashi Iwaiee423812005-11-17 14:21:36 +0100471 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 char name[32];
473
474 sprintf(name, "codec97#%d", bus->num);
475 if ((entry = snd_info_create_card_entry(bus->card, name, bus->card->proc_root)) != NULL) {
476 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
477 if (snd_info_register(entry) < 0) {
478 snd_info_free_entry(entry);
479 entry = NULL;
480 }
481 }
482 bus->proc = entry;
483}
484
Takashi Iwaiee423812005-11-17 14:21:36 +0100485void snd_ac97_bus_proc_done(struct snd_ac97_bus * bus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Takashi Iwai746d4a02006-06-23 14:37:59 +0200487 snd_info_free_entry(bus->proc);
488 bus->proc = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}