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