blob: 7134b3f55fb526658e79d97337335e3b120fb74e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * 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
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"
31#include "ac97_id.h"
32
33/*
34 * proc interface
35 */
36
Takashi Iwaiee423812005-11-17 14:21:36 +010037static void snd_ac97_proc_read_functions(struct snd_ac97 *ac97, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
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",
44 "Aux In", "Mono Out"
45 };
46 static const char *locations[8] = {
47 "Rear I/O Panel", "Front Panel", "Motherboard", "Dock/External",
48 "reserved", "reserved", "reserved", "NC/unused"
49 };
50
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);
54 if (!(info & 0x0001))
55 continue;
56 if (!header) {
57 snd_iprintf(buffer, "\n Gain Inverted Buffer delay Location\n");
58 header = 1;
59 }
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' : '-',
66 (info & 0x03e0) >> 5,
67 locations[sense_info >> 13]);
68 }
69}
70
Takashi Iwaiadf1b3d2005-12-01 10:49:58 +010071static const char *snd_ac97_stereo_enhancements[] =
72{
73 /* 0 */ "No 3D Stereo Enhancement",
74 /* 1 */ "Analog Devices Phat Stereo",
75 /* 2 */ "Creative Stereo Enhancement",
76 /* 3 */ "National Semi 3D Stereo Enhancement",
77 /* 4 */ "YAMAHA Ymersion",
78 /* 5 */ "BBE 3D Stereo Enhancement",
79 /* 6 */ "Crystal Semi 3D Stereo Enhancement",
80 /* 7 */ "Qsound QXpander",
81 /* 8 */ "Spatializer 3D Stereo Enhancement",
82 /* 9 */ "SRS 3D Stereo Enhancement",
83 /* 10 */ "Platform Tech 3D Stereo Enhancement",
84 /* 11 */ "AKM 3D Audio",
85 /* 12 */ "Aureal Stereo Enhancement",
86 /* 13 */ "Aztech 3D Enhancement",
87 /* 14 */ "Binaura 3D Audio Enhancement",
88 /* 15 */ "ESS Technology Stereo Enhancement",
89 /* 16 */ "Harman International VMAx",
90 /* 17 */ "Nvidea/IC Ensemble/KS Waves 3D Stereo Enhancement",
91 /* 18 */ "Philips Incredible Sound",
92 /* 19 */ "Texas Instruments 3D Stereo Enhancement",
93 /* 20 */ "VLSI Technology 3D Stereo Enhancement",
94 /* 21 */ "TriTech 3D Stereo Enhancement",
95 /* 22 */ "Realtek 3D Stereo Enhancement",
96 /* 23 */ "Samsung 3D Stereo Enhancement",
97 /* 24 */ "Wolfson Microelectronics 3D Enhancement",
98 /* 25 */ "Delta Integration 3D Enhancement",
99 /* 26 */ "SigmaTel 3D Enhancement",
100 /* 27 */ "IC Ensemble/KS Waves",
101 /* 28 */ "Rockwell 3D Stereo Enhancement",
102 /* 29 */ "Reserved 29",
103 /* 30 */ "Reserved 30",
104 /* 31 */ "Reserved 31"
105};
106
Takashi Iwaiee423812005-11-17 14:21:36 +0100107static void snd_ac97_proc_read_main(struct snd_ac97 *ac97, struct snd_info_buffer *buffer, int subidx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 char name[64];
110 unsigned short val, tmp, ext, mext;
111 static const char *spdif_slots[4] = { " SPDIF=3/4", " SPDIF=7/8", " SPDIF=6/9", " SPDIF=10/11" };
112 static const char *spdif_rates[4] = { " Rate=44.1kHz", " Rate=res", " Rate=48kHz", " Rate=32kHz" };
113 static const char *spdif_rates_cs4205[4] = { " Rate=48kHz", " Rate=44.1kHz", " Rate=res", " Rate=res" };
114 static const char *double_rate_slots[4] = { "10/11", "7/8", "reserved", "reserved" };
115
116 snd_ac97_get_name(NULL, ac97->id, name, 0);
117 snd_iprintf(buffer, "%d-%d/%d: %s\n\n", ac97->addr, ac97->num, subidx, name);
Jaroslav Kyselab4a621f2005-11-14 08:48:59 +0100118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if ((ac97->scaps & AC97_SCAP_AUDIO) == 0)
120 goto __modem;
121
Jaroslav Kyselab4a621f2005-11-14 08:48:59 +0100122 snd_iprintf(buffer, "PCI Subsys Vendor: 0x%04x\n",
123 ac97->subsystem_vendor);
124 snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n",
125 ac97->subsystem_device);
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
128 val = snd_ac97_read(ac97, AC97_INT_PAGING);
129 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
130 AC97_PAGE_MASK, AC97_PAGE_1);
131 tmp = snd_ac97_read(ac97, AC97_CODEC_CLASS_REV);
132 snd_iprintf(buffer, "Revision : 0x%02x\n", tmp & 0xff);
133 snd_iprintf(buffer, "Compat. Class : 0x%02x\n", (tmp >> 8) & 0x1f);
134 snd_iprintf(buffer, "Subsys. Vendor ID: 0x%04x\n",
135 snd_ac97_read(ac97, AC97_PCI_SVID));
136 snd_iprintf(buffer, "Subsys. ID : 0x%04x\n\n",
137 snd_ac97_read(ac97, AC97_PCI_SID));
138 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
139 AC97_PAGE_MASK, val & AC97_PAGE_MASK);
140 }
141
142 // val = snd_ac97_read(ac97, AC97_RESET);
143 val = ac97->caps;
144 snd_iprintf(buffer, "Capabilities :%s%s%s%s%s%s\n",
145 val & AC97_BC_DEDICATED_MIC ? " -dedicated MIC PCM IN channel-" : "",
146 val & AC97_BC_RESERVED1 ? " -reserved1-" : "",
147 val & AC97_BC_BASS_TREBLE ? " -bass & treble-" : "",
148 val & AC97_BC_SIM_STEREO ? " -simulated stereo-" : "",
149 val & AC97_BC_HEADPHONE ? " -headphone out-" : "",
150 val & AC97_BC_LOUDNESS ? " -loudness-" : "");
151 tmp = ac97->caps & AC97_BC_DAC_MASK;
152 snd_iprintf(buffer, "DAC resolution : %s%s%s%s\n",
153 tmp == AC97_BC_16BIT_DAC ? "16-bit" : "",
154 tmp == AC97_BC_18BIT_DAC ? "18-bit" : "",
155 tmp == AC97_BC_20BIT_DAC ? "20-bit" : "",
156 tmp == AC97_BC_DAC_MASK ? "???" : "");
157 tmp = ac97->caps & AC97_BC_ADC_MASK;
158 snd_iprintf(buffer, "ADC resolution : %s%s%s%s\n",
159 tmp == AC97_BC_16BIT_ADC ? "16-bit" : "",
160 tmp == AC97_BC_18BIT_ADC ? "18-bit" : "",
161 tmp == AC97_BC_20BIT_ADC ? "20-bit" : "",
162 tmp == AC97_BC_ADC_MASK ? "???" : "");
163 snd_iprintf(buffer, "3D enhancement : %s\n",
164 snd_ac97_stereo_enhancements[(val >> 10) & 0x1f]);
165 snd_iprintf(buffer, "\nCurrent setup\n");
166 val = snd_ac97_read(ac97, AC97_MIC);
167 snd_iprintf(buffer, "Mic gain : %s [%s]\n", val & 0x0040 ? "+20dB" : "+0dB", ac97->regs[AC97_MIC] & 0x0040 ? "+20dB" : "+0dB");
168 val = snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
169 snd_iprintf(buffer, "POP path : %s 3D\n"
170 "Sim. stereo : %s\n"
171 "3D enhancement : %s\n"
172 "Loudness : %s\n"
173 "Mono output : %s\n"
174 "Mic select : %s\n"
175 "ADC/DAC loopback : %s\n",
176 val & 0x8000 ? "post" : "pre",
177 val & 0x4000 ? "on" : "off",
178 val & 0x2000 ? "on" : "off",
179 val & 0x1000 ? "on" : "off",
180 val & 0x0200 ? "Mic" : "MIX",
181 val & 0x0100 ? "Mic2" : "Mic1",
182 val & 0x0080 ? "on" : "off");
183 if (ac97->ext_id & AC97_EI_DRA)
184 snd_iprintf(buffer, "Double rate slots: %s\n",
185 double_rate_slots[(val >> 10) & 3]);
186
187 ext = snd_ac97_read(ac97, AC97_EXTENDED_ID);
188 if (ext == 0)
189 goto __modem;
190
191 snd_iprintf(buffer, "Extended ID : codec=%i rev=%i%s%s%s%s DSA=%i%s%s%s%s\n",
192 (ext & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT,
193 (ext & AC97_EI_REV_MASK) >> AC97_EI_REV_SHIFT,
194 ext & AC97_EI_AMAP ? " AMAP" : "",
195 ext & AC97_EI_LDAC ? " LDAC" : "",
196 ext & AC97_EI_SDAC ? " SDAC" : "",
197 ext & AC97_EI_CDAC ? " CDAC" : "",
198 (ext & AC97_EI_DACS_SLOT_MASK) >> AC97_EI_DACS_SLOT_SHIFT,
199 ext & AC97_EI_VRM ? " VRM" : "",
200 ext & AC97_EI_SPDIF ? " SPDIF" : "",
201 ext & AC97_EI_DRA ? " DRA" : "",
202 ext & AC97_EI_VRA ? " VRA" : "");
203 val = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
204 snd_iprintf(buffer, "Extended status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
205 val & AC97_EA_PRL ? " PRL" : "",
206 val & AC97_EA_PRK ? " PRK" : "",
207 val & AC97_EA_PRJ ? " PRJ" : "",
208 val & AC97_EA_PRI ? " PRI" : "",
209 val & AC97_EA_SPCV ? " SPCV" : "",
210 val & AC97_EA_MDAC ? " MADC" : "",
211 val & AC97_EA_LDAC ? " LDAC" : "",
212 val & AC97_EA_SDAC ? " SDAC" : "",
213 val & AC97_EA_CDAC ? " CDAC" : "",
214 ext & AC97_EI_SPDIF ? spdif_slots[(val & AC97_EA_SPSA_SLOT_MASK) >> AC97_EA_SPSA_SLOT_SHIFT] : "",
215 val & AC97_EA_VRM ? " VRM" : "",
216 val & AC97_EA_SPDIF ? " SPDIF" : "",
217 val & AC97_EA_DRA ? " DRA" : "",
218 val & AC97_EA_VRA ? " VRA" : "");
219 if (ext & AC97_EI_VRA) { /* VRA */
220 val = snd_ac97_read(ac97, AC97_PCM_FRONT_DAC_RATE);
221 snd_iprintf(buffer, "PCM front DAC : %iHz\n", val);
222 if (ext & AC97_EI_SDAC) {
223 val = snd_ac97_read(ac97, AC97_PCM_SURR_DAC_RATE);
224 snd_iprintf(buffer, "PCM Surr DAC : %iHz\n", val);
225 }
226 if (ext & AC97_EI_LDAC) {
227 val = snd_ac97_read(ac97, AC97_PCM_LFE_DAC_RATE);
228 snd_iprintf(buffer, "PCM LFE DAC : %iHz\n", val);
229 }
230 val = snd_ac97_read(ac97, AC97_PCM_LR_ADC_RATE);
231 snd_iprintf(buffer, "PCM ADC : %iHz\n", val);
232 }
233 if (ext & AC97_EI_VRM) {
234 val = snd_ac97_read(ac97, AC97_PCM_MIC_ADC_RATE);
235 snd_iprintf(buffer, "PCM MIC ADC : %iHz\n", val);
236 }
237 if ((ext & AC97_EI_SPDIF) || (ac97->flags & AC97_CS_SPDIF)) {
238 if (ac97->flags & AC97_CS_SPDIF)
239 val = snd_ac97_read(ac97, AC97_CSR_SPDIF);
240 else
241 val = snd_ac97_read(ac97, AC97_SPDIF);
242
243 snd_iprintf(buffer, "SPDIF Control :%s%s%s%s Category=0x%x Generation=%i%s%s%s\n",
244 val & AC97_SC_PRO ? " PRO" : " Consumer",
245 val & AC97_SC_NAUDIO ? " Non-audio" : " PCM",
246 val & AC97_SC_COPY ? "" : " Copyright",
247 val & AC97_SC_PRE ? " Preemph50/15" : "",
248 (val & AC97_SC_CC_MASK) >> AC97_SC_CC_SHIFT,
249 (val & AC97_SC_L) >> 11,
250 (ac97->flags & AC97_CS_SPDIF) ?
251 spdif_rates_cs4205[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT] :
252 spdif_rates[(val & AC97_SC_SPSR_MASK) >> AC97_SC_SPSR_SHIFT],
253 (ac97->flags & AC97_CS_SPDIF) ?
254 (val & AC97_SC_DRS ? " Validity" : "") :
255 (val & AC97_SC_DRS ? " DRS" : ""),
256 (ac97->flags & AC97_CS_SPDIF) ?
257 (val & AC97_SC_V ? " Enabled" : "") :
258 (val & AC97_SC_V ? " Validity" : ""));
259 /* ALC650 specific*/
260 if ((ac97->id & 0xfffffff0) == 0x414c4720 &&
261 (snd_ac97_read(ac97, AC97_ALC650_CLOCK) & 0x01)) {
262 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
263 if (val & AC97_ALC650_CLOCK_LOCK) {
264 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS1);
265 snd_iprintf(buffer, "SPDIF In Status :%s%s%s%s Category=0x%x Generation=%i",
266 val & AC97_ALC650_PRO ? " PRO" : " Consumer",
267 val & AC97_ALC650_NAUDIO ? " Non-audio" : " PCM",
268 val & AC97_ALC650_COPY ? "" : " Copyright",
269 val & AC97_ALC650_PRE ? " Preemph50/15" : "",
270 (val & AC97_ALC650_CC_MASK) >> AC97_ALC650_CC_SHIFT,
271 (val & AC97_ALC650_L) >> 15);
272 val = snd_ac97_read(ac97, AC97_ALC650_SPDIF_INPUT_STATUS2);
273 snd_iprintf(buffer, "%s Accuracy=%i%s%s\n",
274 spdif_rates[(val & AC97_ALC650_SPSR_MASK) >> AC97_ALC650_SPSR_SHIFT],
275 (val & AC97_ALC650_CLOCK_ACCURACY) >> AC97_ALC650_CLOCK_SHIFT,
276 (val & AC97_ALC650_CLOCK_LOCK ? " Locked" : " Unlocked"),
277 (val & AC97_ALC650_V ? " Validity?" : ""));
278 } else {
279 snd_iprintf(buffer, "SPDIF In Status : Not Locked\n");
280 }
281 }
282 }
283 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
284 val = snd_ac97_read(ac97, AC97_INT_PAGING);
285 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
286 AC97_PAGE_MASK, AC97_PAGE_1);
287 snd_ac97_proc_read_functions(ac97, buffer);
288 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
289 AC97_PAGE_MASK, val & AC97_PAGE_MASK);
290 }
291
292
293 __modem:
294 mext = snd_ac97_read(ac97, AC97_EXTENDED_MID);
295 if (mext == 0)
296 return;
297
298 snd_iprintf(buffer, "Extended modem ID: codec=%i%s%s%s%s%s\n",
299 (mext & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT,
300 mext & AC97_MEI_CID2 ? " CID2" : "",
301 mext & AC97_MEI_CID1 ? " CID1" : "",
302 mext & AC97_MEI_HANDSET ? " HSET" : "",
303 mext & AC97_MEI_LINE2 ? " LIN2" : "",
304 mext & AC97_MEI_LINE1 ? " LIN1" : "");
305 val = snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS);
306 snd_iprintf(buffer, "Modem status :%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
307 val & AC97_MEA_GPIO ? " GPIO" : "",
308 val & AC97_MEA_MREF ? " MREF" : "",
309 val & AC97_MEA_ADC1 ? " ADC1" : "",
310 val & AC97_MEA_DAC1 ? " DAC1" : "",
311 val & AC97_MEA_ADC2 ? " ADC2" : "",
312 val & AC97_MEA_DAC2 ? " DAC2" : "",
313 val & AC97_MEA_HADC ? " HADC" : "",
314 val & AC97_MEA_HDAC ? " HDAC" : "",
315 val & AC97_MEA_PRA ? " PRA(GPIO)" : "",
316 val & AC97_MEA_PRB ? " PRB(res)" : "",
317 val & AC97_MEA_PRC ? " PRC(ADC1)" : "",
318 val & AC97_MEA_PRD ? " PRD(DAC1)" : "",
319 val & AC97_MEA_PRE ? " PRE(ADC2)" : "",
320 val & AC97_MEA_PRF ? " PRF(DAC2)" : "",
321 val & AC97_MEA_PRG ? " PRG(HADC)" : "",
322 val & AC97_MEA_PRH ? " PRH(HDAC)" : "");
323 if (mext & AC97_MEI_LINE1) {
324 val = snd_ac97_read(ac97, AC97_LINE1_RATE);
325 snd_iprintf(buffer, "Line1 rate : %iHz\n", val);
326 }
327 if (mext & AC97_MEI_LINE2) {
328 val = snd_ac97_read(ac97, AC97_LINE2_RATE);
329 snd_iprintf(buffer, "Line2 rate : %iHz\n", val);
330 }
331 if (mext & AC97_MEI_HANDSET) {
332 val = snd_ac97_read(ac97, AC97_HANDSET_RATE);
333 snd_iprintf(buffer, "Headset rate : %iHz\n", val);
334 }
335}
336
Takashi Iwaiee423812005-11-17 14:21:36 +0100337static void snd_ac97_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Takashi Iwaiee423812005-11-17 14:21:36 +0100339 struct snd_ac97 *ac97 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 down(&ac97->page_mutex);
342 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
343 int idx;
344 for (idx = 0; idx < 3; idx++)
345 if (ac97->spec.ad18xx.id[idx]) {
346 /* select single codec */
347 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
348 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
349 snd_ac97_proc_read_main(ac97, buffer, idx);
350 snd_iprintf(buffer, "\n\n");
351 }
352 /* select all codecs */
353 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
354
355 snd_iprintf(buffer, "\nAD18XX configuration\n");
356 snd_iprintf(buffer, "Unchained : 0x%04x,0x%04x,0x%04x\n",
357 ac97->spec.ad18xx.unchained[0],
358 ac97->spec.ad18xx.unchained[1],
359 ac97->spec.ad18xx.unchained[2]);
360 snd_iprintf(buffer, "Chained : 0x%04x,0x%04x,0x%04x\n",
361 ac97->spec.ad18xx.chained[0],
362 ac97->spec.ad18xx.chained[1],
363 ac97->spec.ad18xx.chained[2]);
364 } else {
365 snd_ac97_proc_read_main(ac97, buffer, 0);
366 }
367 up(&ac97->page_mutex);
368}
369
370#ifdef CONFIG_SND_DEBUG
371/* direct register write for debugging */
Takashi Iwaiee423812005-11-17 14:21:36 +0100372static void snd_ac97_proc_regs_write(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Takashi Iwaiee423812005-11-17 14:21:36 +0100374 struct snd_ac97 *ac97 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 char line[64];
376 unsigned int reg, val;
377 down(&ac97->page_mutex);
378 while (!snd_info_get_line(buffer, line, sizeof(line))) {
379 if (sscanf(line, "%x %x", &reg, &val) != 2)
380 continue;
381 /* register must be even */
382 if (reg < 0x80 && (reg & 1) == 0 && val <= 0xffff)
383 snd_ac97_write_cache(ac97, reg, val);
384 }
385 up(&ac97->page_mutex);
386}
387#endif
388
Takashi Iwaiee423812005-11-17 14:21:36 +0100389static 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 -0700390{
391 int reg, val;
392
393 for (reg = 0; reg < 0x80; reg += 2) {
394 val = snd_ac97_read(ac97, reg);
395 snd_iprintf(buffer, "%i:%02x = %04x\n", subidx, reg, val);
396 }
397}
398
Takashi Iwaiee423812005-11-17 14:21:36 +0100399static void snd_ac97_proc_regs_read(struct snd_info_entry *entry,
400 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Takashi Iwaiee423812005-11-17 14:21:36 +0100402 struct snd_ac97 *ac97 = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 down(&ac97->page_mutex);
405 if ((ac97->id & 0xffffff40) == AC97_ID_AD1881) { // Analog Devices AD1881/85/86
406
407 int idx;
408 for (idx = 0; idx < 3; idx++)
409 if (ac97->spec.ad18xx.id[idx]) {
410 /* select single codec */
411 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000,
412 ac97->spec.ad18xx.unchained[idx] | ac97->spec.ad18xx.chained[idx]);
413 snd_ac97_proc_regs_read_main(ac97, buffer, idx);
414 }
415 /* select all codecs */
416 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 0x7000, 0x7000);
417 } else {
418 snd_ac97_proc_regs_read_main(ac97, buffer, 0);
419 }
420 up(&ac97->page_mutex);
421}
422
Takashi Iwaiee423812005-11-17 14:21:36 +0100423void snd_ac97_proc_init(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Takashi Iwaiee423812005-11-17 14:21:36 +0100425 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 char name[32];
427 const char *prefix;
428
429 if (ac97->bus->proc == NULL)
430 return;
431 prefix = ac97_is_audio(ac97) ? "ac97" : "mc97";
432 sprintf(name, "%s#%d-%d", prefix, ac97->addr, ac97->num);
433 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
434 snd_info_set_text_ops(entry, ac97, 1024, snd_ac97_proc_read);
435 if (snd_info_register(entry) < 0) {
436 snd_info_free_entry(entry);
437 entry = NULL;
438 }
439 }
440 ac97->proc = entry;
441 sprintf(name, "%s#%d-%d+regs", prefix, ac97->addr, ac97->num);
442 if ((entry = snd_info_create_card_entry(ac97->bus->card, name, ac97->bus->proc)) != NULL) {
443 snd_info_set_text_ops(entry, ac97, 1024, snd_ac97_proc_regs_read);
444#ifdef CONFIG_SND_DEBUG
445 entry->mode |= S_IWUSR;
446 entry->c.text.write_size = 1024;
447 entry->c.text.write = snd_ac97_proc_regs_write;
448#endif
449 if (snd_info_register(entry) < 0) {
450 snd_info_free_entry(entry);
451 entry = NULL;
452 }
453 }
454 ac97->proc_regs = entry;
455}
456
Takashi Iwaiee423812005-11-17 14:21:36 +0100457void snd_ac97_proc_done(struct snd_ac97 * ac97)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
459 if (ac97->proc_regs) {
460 snd_info_unregister(ac97->proc_regs);
461 ac97->proc_regs = NULL;
462 }
463 if (ac97->proc) {
464 snd_info_unregister(ac97->proc);
465 ac97->proc = NULL;
466 }
467}
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{
487 if (bus->proc) {
488 snd_info_unregister(bus->proc);
489 bus->proc = NULL;
490 }
491}