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