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