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