]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - sound/pci/hda/hda_proc.c
ALSA: introduce snd_print_pcm_rates()
[linux-2.6-omap-h63xx.git] / sound / pci / hda / hda_proc.c
1 /*
2  * Universal Interface for Intel High Definition Audio Codec
3  * 
4  * Generic proc interface
5  *
6  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
7  *
8  *
9  *  This driver 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 driver 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 #include <linux/init.h>
25 #include <sound/core.h>
26 #include "hda_codec.h"
27 #include "hda_local.h"
28
29 static const char *get_wid_type_name(unsigned int wid_value)
30 {
31         static char *names[16] = {
32                 [AC_WID_AUD_OUT] = "Audio Output",
33                 [AC_WID_AUD_IN] = "Audio Input",
34                 [AC_WID_AUD_MIX] = "Audio Mixer",
35                 [AC_WID_AUD_SEL] = "Audio Selector",
36                 [AC_WID_PIN] = "Pin Complex",
37                 [AC_WID_POWER] = "Power Widget",
38                 [AC_WID_VOL_KNB] = "Volume Knob Widget",
39                 [AC_WID_BEEP] = "Beep Generator Widget",
40                 [AC_WID_VENDOR] = "Vendor Defined Widget",
41         };
42         wid_value &= 0xf;
43         if (names[wid_value])
44                 return names[wid_value];
45         else
46                 return "UNKNOWN Widget";
47 }
48
49 static void print_amp_caps(struct snd_info_buffer *buffer,
50                            struct hda_codec *codec, hda_nid_t nid, int dir)
51 {
52         unsigned int caps;
53         caps = snd_hda_param_read(codec, nid,
54                                   dir == HDA_OUTPUT ?
55                                     AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
56         if (caps == -1 || caps == 0) {
57                 snd_iprintf(buffer, "N/A\n");
58                 return;
59         }
60         snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
61                     "mute=%x\n",
62                     caps & AC_AMPCAP_OFFSET,
63                     (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
64                     (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
65                     (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
66 }
67
68 static void print_amp_vals(struct snd_info_buffer *buffer,
69                            struct hda_codec *codec, hda_nid_t nid,
70                            int dir, int stereo, int indices)
71 {
72         unsigned int val;
73         int i;
74
75         dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
76         for (i = 0; i < indices; i++) {
77                 snd_iprintf(buffer, " [");
78                 if (stereo) {
79                         val = snd_hda_codec_read(codec, nid, 0,
80                                                  AC_VERB_GET_AMP_GAIN_MUTE,
81                                                  AC_AMP_GET_LEFT | dir | i);
82                         snd_iprintf(buffer, "0x%02x ", val);
83                 }
84                 val = snd_hda_codec_read(codec, nid, 0,
85                                          AC_VERB_GET_AMP_GAIN_MUTE,
86                                          AC_AMP_GET_RIGHT | dir | i);
87                 snd_iprintf(buffer, "0x%02x]", val);
88         }
89         snd_iprintf(buffer, "\n");
90 }
91
92 void snd_print_pcm_rates(int pcm, char *buf, int buflen)
93 {
94         static unsigned int rates[] = {
95                 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
96                 96000, 176400, 192000, 384000
97         };
98         int i, j;
99
100         for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
101                 if (pcm & (1 << i))
102                         j += snprintf(buf + j, buflen - j,  " %d", rates[i]);
103
104         buf[j] = '\0'; /* necessary when j == 0 */
105 }
106
107 static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
108 {
109         char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
110         pcm &= AC_SUPPCM_RATES;
111         snd_iprintf(buffer, "    rates [0x%x]:", pcm);
112         snd_print_pcm_rates(pcm, buf, sizeof(buf));
113         snd_iprintf(buffer, "%s\n", buf);
114 }
115
116 static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
117 {
118         static unsigned int bits[] = { 8, 16, 20, 24, 32 };
119         int i;
120
121         pcm = (pcm >> 16) & 0xff;
122         snd_iprintf(buffer, "    bits [0x%x]:", pcm);
123         for (i = 0; i < ARRAY_SIZE(bits); i++)
124                 if (pcm & (1 << i))
125                         snd_iprintf(buffer, " %d", bits[i]);
126         snd_iprintf(buffer, "\n");
127 }
128
129 static void print_pcm_formats(struct snd_info_buffer *buffer,
130                               unsigned int streams)
131 {
132         snd_iprintf(buffer, "    formats [0x%x]:", streams & 0xf);
133         if (streams & AC_SUPFMT_PCM)
134                 snd_iprintf(buffer, " PCM");
135         if (streams & AC_SUPFMT_FLOAT32)
136                 snd_iprintf(buffer, " FLOAT");
137         if (streams & AC_SUPFMT_AC3)
138                 snd_iprintf(buffer, " AC3");
139         snd_iprintf(buffer, "\n");
140 }
141
142 static void print_pcm_caps(struct snd_info_buffer *buffer,
143                            struct hda_codec *codec, hda_nid_t nid)
144 {
145         unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
146         unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
147         if (pcm == -1 || stream == -1) {
148                 snd_iprintf(buffer, "N/A\n");
149                 return;
150         }
151         print_pcm_rates(buffer, pcm);
152         print_pcm_bits(buffer, pcm);
153         print_pcm_formats(buffer, stream);
154 }
155
156 static const char *get_jack_connection(u32 cfg)
157 {
158         static char *names[16] = {
159                 "Unknown", "1/8", "1/4", "ATAPI",
160                 "RCA", "Optical","Digital", "Analog",
161                 "DIN", "XLR", "RJ11", "Comb",
162                 NULL, NULL, NULL, "Other"
163         };
164         cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
165         if (names[cfg])
166                 return names[cfg];
167         else
168                 return "UNKNOWN";
169 }
170
171 static const char *get_jack_color(u32 cfg)
172 {
173         static char *names[16] = {
174                 "Unknown", "Black", "Grey", "Blue",
175                 "Green", "Red", "Orange", "Yellow",
176                 "Purple", "Pink", NULL, NULL,
177                 NULL, NULL, "White", "Other",
178         };
179         cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
180         if (names[cfg])
181                 return names[cfg];
182         else
183                 return "UNKNOWN";
184 }
185
186 static void print_pin_caps(struct snd_info_buffer *buffer,
187                            struct hda_codec *codec, hda_nid_t nid,
188                            int *supports_vref)
189 {
190         static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
191         unsigned int caps, val;
192
193         caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
194         snd_iprintf(buffer, "  Pincap 0x%08x:", caps);
195         if (caps & AC_PINCAP_IN)
196                 snd_iprintf(buffer, " IN");
197         if (caps & AC_PINCAP_OUT)
198                 snd_iprintf(buffer, " OUT");
199         if (caps & AC_PINCAP_HP_DRV)
200                 snd_iprintf(buffer, " HP");
201         if (caps & AC_PINCAP_EAPD)
202                 snd_iprintf(buffer, " EAPD");
203         if (caps & AC_PINCAP_PRES_DETECT)
204                 snd_iprintf(buffer, " Detect");
205         if (caps & AC_PINCAP_BALANCE)
206                 snd_iprintf(buffer, " Balanced");
207         if (caps & AC_PINCAP_HDMI) {
208                 /* Realtek uses this bit as a different meaning */
209                 if ((codec->vendor_id >> 16) == 0x10ec)
210                         snd_iprintf(buffer, " R/L");
211                 else
212                         snd_iprintf(buffer, " HDMI");
213         }
214         if (caps & AC_PINCAP_TRIG_REQ)
215                 snd_iprintf(buffer, " Trigger");
216         if (caps & AC_PINCAP_IMP_SENSE)
217                 snd_iprintf(buffer, " ImpSense");
218         snd_iprintf(buffer, "\n");
219         if (caps & AC_PINCAP_VREF) {
220                 unsigned int vref =
221                         (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
222                 snd_iprintf(buffer, "    Vref caps:");
223                 if (vref & AC_PINCAP_VREF_HIZ)
224                         snd_iprintf(buffer, " HIZ");
225                 if (vref & AC_PINCAP_VREF_50)
226                         snd_iprintf(buffer, " 50");
227                 if (vref & AC_PINCAP_VREF_GRD)
228                         snd_iprintf(buffer, " GRD");
229                 if (vref & AC_PINCAP_VREF_80)
230                         snd_iprintf(buffer, " 80");
231                 if (vref & AC_PINCAP_VREF_100)
232                         snd_iprintf(buffer, " 100");
233                 snd_iprintf(buffer, "\n");
234                 *supports_vref = 1;
235         } else
236                 *supports_vref = 0;
237         if (caps & AC_PINCAP_EAPD) {
238                 val = snd_hda_codec_read(codec, nid, 0,
239                                          AC_VERB_GET_EAPD_BTLENABLE, 0);
240                 snd_iprintf(buffer, "  EAPD 0x%x:", val);
241                 if (val & AC_EAPDBTL_BALANCED)
242                         snd_iprintf(buffer, " BALANCED");
243                 if (val & AC_EAPDBTL_EAPD)
244                         snd_iprintf(buffer, " EAPD");
245                 if (val & AC_EAPDBTL_LR_SWAP)
246                         snd_iprintf(buffer, " R/L");
247                 snd_iprintf(buffer, "\n");
248         }
249         caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
250         snd_iprintf(buffer, "  Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
251                     jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
252                     snd_hda_get_jack_type(caps),
253                     snd_hda_get_jack_connectivity(caps),
254                     snd_hda_get_jack_location(caps));
255         snd_iprintf(buffer, "    Conn = %s, Color = %s\n",
256                     get_jack_connection(caps),
257                     get_jack_color(caps));
258         /* Default association and sequence values refer to default grouping
259          * of pin complexes and their sequence within the group. This is used
260          * for priority and resource allocation.
261          */
262         snd_iprintf(buffer, "    DefAssociation = 0x%x, Sequence = 0x%x\n",
263                     (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
264                     caps & AC_DEFCFG_SEQUENCE);
265         if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
266             AC_DEFCFG_MISC_NO_PRESENCE) {
267                 /* Miscellaneous bit indicates external hardware does not
268                  * support presence detection even if the pin complex
269                  * indicates it is supported.
270                  */
271                 snd_iprintf(buffer, "    Misc = NO_PRESENCE\n");
272         }
273 }
274
275 static void print_pin_ctls(struct snd_info_buffer *buffer,
276                            struct hda_codec *codec, hda_nid_t nid,
277                            int supports_vref)
278 {
279         unsigned int pinctls;
280
281         pinctls = snd_hda_codec_read(codec, nid, 0,
282                                      AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
283         snd_iprintf(buffer, "  Pin-ctls: 0x%02x:", pinctls);
284         if (pinctls & AC_PINCTL_IN_EN)
285                 snd_iprintf(buffer, " IN");
286         if (pinctls & AC_PINCTL_OUT_EN)
287                 snd_iprintf(buffer, " OUT");
288         if (pinctls & AC_PINCTL_HP_EN)
289                 snd_iprintf(buffer, " HP");
290         if (supports_vref) {
291                 int vref = pinctls & AC_PINCTL_VREFEN;
292                 switch (vref) {
293                 case AC_PINCTL_VREF_HIZ:
294                         snd_iprintf(buffer, " VREF_HIZ");
295                         break;
296                 case AC_PINCTL_VREF_50:
297                         snd_iprintf(buffer, " VREF_50");
298                         break;
299                 case AC_PINCTL_VREF_GRD:
300                         snd_iprintf(buffer, " VREF_GRD");
301                         break;
302                 case AC_PINCTL_VREF_80:
303                         snd_iprintf(buffer, " VREF_80");
304                         break;
305                 case AC_PINCTL_VREF_100:
306                         snd_iprintf(buffer, " VREF_100");
307                         break;
308                 }
309         }
310         snd_iprintf(buffer, "\n");
311 }
312
313 static void print_vol_knob(struct snd_info_buffer *buffer,
314                            struct hda_codec *codec, hda_nid_t nid)
315 {
316         unsigned int cap = snd_hda_param_read(codec, nid,
317                                               AC_PAR_VOL_KNB_CAP);
318         snd_iprintf(buffer, "  Volume-Knob: delta=%d, steps=%d, ",
319                     (cap >> 7) & 1, cap & 0x7f);
320         cap = snd_hda_codec_read(codec, nid, 0,
321                                  AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
322         snd_iprintf(buffer, "direct=%d, val=%d\n",
323                     (cap >> 7) & 1, cap & 0x7f);
324 }
325
326 static void print_audio_io(struct snd_info_buffer *buffer,
327                            struct hda_codec *codec, hda_nid_t nid,
328                            unsigned int wid_type)
329 {
330         int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
331         snd_iprintf(buffer,
332                     "  Converter: stream=%d, channel=%d\n",
333                     (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
334                     conv & AC_CONV_CHANNEL);
335
336         if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
337                 int sdi = snd_hda_codec_read(codec, nid, 0,
338                                              AC_VERB_GET_SDI_SELECT, 0);
339                 snd_iprintf(buffer, "  SDI-Select: %d\n",
340                             sdi & AC_SDI_SELECT);
341         }
342 }
343
344 static void print_digital_conv(struct snd_info_buffer *buffer,
345                                struct hda_codec *codec, hda_nid_t nid)
346 {
347         unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
348                                                 AC_VERB_GET_DIGI_CONVERT_1, 0);
349         snd_iprintf(buffer, "  Digital:");
350         if (digi1 & AC_DIG1_ENABLE)
351                 snd_iprintf(buffer, " Enabled");
352         if (digi1 & AC_DIG1_V)
353                 snd_iprintf(buffer, " Validity");
354         if (digi1 & AC_DIG1_VCFG)
355                 snd_iprintf(buffer, " ValidityCfg");
356         if (digi1 & AC_DIG1_EMPHASIS)
357                 snd_iprintf(buffer, " Preemphasis");
358         if (digi1 & AC_DIG1_COPYRIGHT)
359                 snd_iprintf(buffer, " Copyright");
360         if (digi1 & AC_DIG1_NONAUDIO)
361                 snd_iprintf(buffer, " Non-Audio");
362         if (digi1 & AC_DIG1_PROFESSIONAL)
363                 snd_iprintf(buffer, " Pro");
364         if (digi1 & AC_DIG1_LEVEL)
365                 snd_iprintf(buffer, " GenLevel");
366         snd_iprintf(buffer, "\n");
367         snd_iprintf(buffer, "  Digital category: 0x%x\n",
368                     (digi1 >> 8) & AC_DIG2_CC);
369 }
370
371 static const char *get_pwr_state(u32 state)
372 {
373         static const char *buf[4] = {
374                 "D0", "D1", "D2", "D3"
375         };
376         if (state < 4)
377                 return buf[state];
378         return "UNKNOWN";
379 }
380
381 static void print_power_state(struct snd_info_buffer *buffer,
382                               struct hda_codec *codec, hda_nid_t nid)
383 {
384         int pwr = snd_hda_codec_read(codec, nid, 0,
385                                      AC_VERB_GET_POWER_STATE, 0);
386         snd_iprintf(buffer, "  Power: setting=%s, actual=%s\n",
387                     get_pwr_state(pwr & AC_PWRST_SETTING),
388                     get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
389                                   AC_PWRST_ACTUAL_SHIFT));
390 }
391
392 static void print_unsol_cap(struct snd_info_buffer *buffer,
393                               struct hda_codec *codec, hda_nid_t nid)
394 {
395         int unsol = snd_hda_codec_read(codec, nid, 0,
396                                        AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
397         snd_iprintf(buffer,
398                     "  Unsolicited: tag=%02x, enabled=%d\n",
399                     unsol & AC_UNSOL_TAG,
400                     (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
401 }
402
403 static void print_proc_caps(struct snd_info_buffer *buffer,
404                             struct hda_codec *codec, hda_nid_t nid)
405 {
406         unsigned int proc_caps = snd_hda_param_read(codec, nid,
407                                                     AC_PAR_PROC_CAP);
408         snd_iprintf(buffer, "  Processing caps: benign=%d, ncoeff=%d\n",
409                     proc_caps & AC_PCAP_BENIGN,
410                     (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT);
411 }
412
413 static void print_conn_list(struct snd_info_buffer *buffer,
414                             struct hda_codec *codec, hda_nid_t nid,
415                             unsigned int wid_type, hda_nid_t *conn,
416                             int conn_len)
417 {
418         int c, curr = -1;
419
420         if (conn_len > 1 && wid_type != AC_WID_AUD_MIX)
421                 curr = snd_hda_codec_read(codec, nid, 0,
422                                           AC_VERB_GET_CONNECT_SEL, 0);
423         snd_iprintf(buffer, "  Connection: %d\n", conn_len);
424         if (conn_len > 0) {
425                 snd_iprintf(buffer, "    ");
426                 for (c = 0; c < conn_len; c++) {
427                         snd_iprintf(buffer, " 0x%02x", conn[c]);
428                         if (c == curr)
429                                 snd_iprintf(buffer, "*");
430                 }
431                 snd_iprintf(buffer, "\n");
432         }
433 }
434
435 static void print_realtek_coef(struct snd_info_buffer *buffer,
436                                struct hda_codec *codec, hda_nid_t nid)
437 {
438         int coeff = snd_hda_codec_read(codec, nid, 0,
439                                        AC_VERB_GET_PROC_COEF, 0);
440         snd_iprintf(buffer, "  Processing Coefficient: 0x%02x\n", coeff);
441         coeff = snd_hda_codec_read(codec, nid, 0,
442                                    AC_VERB_GET_COEF_INDEX, 0);
443         snd_iprintf(buffer, "  Coefficient Index: 0x%02x\n", coeff);
444 }
445
446 static void print_gpio(struct snd_info_buffer *buffer,
447                        struct hda_codec *codec, hda_nid_t nid)
448 {
449         unsigned int gpio =
450                 snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
451         unsigned int enable, direction, wake, unsol, sticky, data;
452         int i, max;
453         snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
454                     "unsolicited=%d, wake=%d\n",
455                     gpio & AC_GPIO_IO_COUNT,
456                     (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
457                     (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
458                     (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
459                     (gpio & AC_GPIO_WAKE) ? 1 : 0);
460         max = gpio & AC_GPIO_IO_COUNT;
461         if (!max || max > 8)
462                 return;
463         enable = snd_hda_codec_read(codec, nid, 0,
464                                     AC_VERB_GET_GPIO_MASK, 0);
465         direction = snd_hda_codec_read(codec, nid, 0,
466                                        AC_VERB_GET_GPIO_DIRECTION, 0);
467         wake = snd_hda_codec_read(codec, nid, 0,
468                                   AC_VERB_GET_GPIO_WAKE_MASK, 0);
469         unsol  = snd_hda_codec_read(codec, nid, 0,
470                                     AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
471         sticky = snd_hda_codec_read(codec, nid, 0,
472                                     AC_VERB_GET_GPIO_STICKY_MASK, 0);
473         data = snd_hda_codec_read(codec, nid, 0,
474                                   AC_VERB_GET_GPIO_DATA, 0);
475         for (i = 0; i < max; ++i)
476                 snd_iprintf(buffer,
477                             "  IO[%d]: enable=%d, dir=%d, wake=%d, "
478                             "sticky=%d, data=%d\n", i,
479                             (enable & (1<<i)) ? 1 : 0,
480                             (direction & (1<<i)) ? 1 : 0,
481                             (wake & (1<<i)) ? 1 : 0,
482                             (sticky & (1<<i)) ? 1 : 0,
483                             (data & (1<<i)) ? 1 : 0);
484         /* FIXME: add GPO and GPI pin information */
485 }
486
487 static void print_codec_info(struct snd_info_entry *entry,
488                              struct snd_info_buffer *buffer)
489 {
490         struct hda_codec *codec = entry->private_data;
491         hda_nid_t nid;
492         int i, nodes;
493
494         snd_iprintf(buffer, "Codec: %s\n",
495                     codec->name ? codec->name : "Not Set");
496         snd_iprintf(buffer, "Address: %d\n", codec->addr);
497         snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
498         snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);
499         snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
500
501         if (codec->mfg)
502                 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
503         else
504                 snd_iprintf(buffer, "No Modem Function Group found\n");
505
506         if (! codec->afg)
507                 return;
508         snd_hda_power_up(codec);
509         snd_iprintf(buffer, "Default PCM:\n");
510         print_pcm_caps(buffer, codec, codec->afg);
511         snd_iprintf(buffer, "Default Amp-In caps: ");
512         print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
513         snd_iprintf(buffer, "Default Amp-Out caps: ");
514         print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
515
516         nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
517         if (! nid || nodes < 0) {
518                 snd_iprintf(buffer, "Invalid AFG subtree\n");
519                 snd_hda_power_down(codec);
520                 return;
521         }
522
523         print_gpio(buffer, codec, codec->afg);
524
525         for (i = 0; i < nodes; i++, nid++) {
526                 unsigned int wid_caps =
527                         snd_hda_param_read(codec, nid,
528                                            AC_PAR_AUDIO_WIDGET_CAP);
529                 unsigned int wid_type =
530                         (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
531                 hda_nid_t conn[HDA_MAX_CONNECTIONS];
532                 int conn_len = 0;
533
534                 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
535                             get_wid_type_name(wid_type), wid_caps);
536                 if (wid_caps & AC_WCAP_STEREO) {
537                         unsigned int chans;
538                         chans = (wid_caps & AC_WCAP_CHAN_CNT_EXT) >> 13;
539                         chans = ((chans << 1) | 1) + 1;
540                         if (chans == 2)
541                                 snd_iprintf(buffer, " Stereo");
542                         else
543                                 snd_iprintf(buffer, " %d-Channels", chans);
544                 } else
545                         snd_iprintf(buffer, " Mono");
546                 if (wid_caps & AC_WCAP_DIGITAL)
547                         snd_iprintf(buffer, " Digital");
548                 if (wid_caps & AC_WCAP_IN_AMP)
549                         snd_iprintf(buffer, " Amp-In");
550                 if (wid_caps & AC_WCAP_OUT_AMP)
551                         snd_iprintf(buffer, " Amp-Out");
552                 if (wid_caps & AC_WCAP_STRIPE)
553                         snd_iprintf(buffer, " Stripe");
554                 if (wid_caps & AC_WCAP_LR_SWAP)
555                         snd_iprintf(buffer, " R/L");
556                 if (wid_caps & AC_WCAP_CP_CAPS)
557                         snd_iprintf(buffer, " CP");
558                 snd_iprintf(buffer, "\n");
559
560                 /* volume knob is a special widget that always have connection
561                  * list
562                  */
563                 if (wid_type == AC_WID_VOL_KNB)
564                         wid_caps |= AC_WCAP_CONN_LIST;
565
566                 if (wid_caps & AC_WCAP_CONN_LIST)
567                         conn_len = snd_hda_get_connections(codec, nid, conn,
568                                                            HDA_MAX_CONNECTIONS);
569
570                 if (wid_caps & AC_WCAP_IN_AMP) {
571                         snd_iprintf(buffer, "  Amp-In caps: ");
572                         print_amp_caps(buffer, codec, nid, HDA_INPUT);
573                         snd_iprintf(buffer, "  Amp-In vals: ");
574                         print_amp_vals(buffer, codec, nid, HDA_INPUT,
575                                        wid_caps & AC_WCAP_STEREO,
576                                        wid_type == AC_WID_PIN ? 1 : conn_len);
577                 }
578                 if (wid_caps & AC_WCAP_OUT_AMP) {
579                         snd_iprintf(buffer, "  Amp-Out caps: ");
580                         print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
581                         snd_iprintf(buffer, "  Amp-Out vals: ");
582                         print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
583                                        wid_caps & AC_WCAP_STEREO, 1);
584                 }
585
586                 switch (wid_type) {
587                 case AC_WID_PIN: {
588                         int supports_vref;
589                         print_pin_caps(buffer, codec, nid, &supports_vref);
590                         print_pin_ctls(buffer, codec, nid, supports_vref);
591                         break;
592                 }
593                 case AC_WID_VOL_KNB:
594                         print_vol_knob(buffer, codec, nid);
595                         break;
596                 case AC_WID_AUD_OUT:
597                 case AC_WID_AUD_IN:
598                         print_audio_io(buffer, codec, nid, wid_type);
599                         if (wid_caps & AC_WCAP_DIGITAL)
600                                 print_digital_conv(buffer, codec, nid);
601                         if (wid_caps & AC_WCAP_FORMAT_OVRD) {
602                                 snd_iprintf(buffer, "  PCM:\n");
603                                 print_pcm_caps(buffer, codec, nid);
604                         }
605                         break;
606                 }
607
608                 if (wid_caps & AC_WCAP_UNSOL_CAP)
609                         print_unsol_cap(buffer, codec, nid);
610
611                 if (wid_caps & AC_WCAP_POWER)
612                         print_power_state(buffer, codec, nid);
613
614                 if (wid_caps & AC_WCAP_DELAY)
615                         snd_iprintf(buffer, "  Delay: %d samples\n",
616                                     (wid_caps & AC_WCAP_DELAY) >>
617                                     AC_WCAP_DELAY_SHIFT);
618
619                 if (wid_caps & AC_WCAP_CONN_LIST)
620                         print_conn_list(buffer, codec, nid, wid_type,
621                                         conn, conn_len);
622
623                 if (wid_caps & AC_WCAP_PROC_WID)
624                         print_proc_caps(buffer, codec, nid);
625
626                 /* NID 0x20 == Realtek Define Registers */
627                 if (codec->vendor_id == 0x10ec && nid == 0x20)
628                         print_realtek_coef(buffer, codec, nid);
629         }
630         snd_hda_power_down(codec);
631 }
632
633 /*
634  * create a proc read
635  */
636 int snd_hda_codec_proc_new(struct hda_codec *codec)
637 {
638         char name[32];
639         struct snd_info_entry *entry;
640         int err;
641
642         snprintf(name, sizeof(name), "codec#%d", codec->addr);
643         err = snd_card_proc_new(codec->bus->card, name, &entry);
644         if (err < 0)
645                 return err;
646
647         snd_info_set_text_ops(entry, codec, print_codec_info);
648         return 0;
649 }
650