xref: /openbmc/linux/sound/pci/hda/hda_proc.c (revision a09d2831)
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 			if (caps & AC_PINCAP_HBR)
245 				snd_iprintf(buffer, " HBR");
246 			snd_iprintf(buffer, " HDMI");
247 		}
248 	}
249 	if (caps & AC_PINCAP_DP)
250 		snd_iprintf(buffer, " DP");
251 	if (caps & AC_PINCAP_TRIG_REQ)
252 		snd_iprintf(buffer, " Trigger");
253 	if (caps & AC_PINCAP_IMP_SENSE)
254 		snd_iprintf(buffer, " ImpSense");
255 	snd_iprintf(buffer, "\n");
256 	if (caps & AC_PINCAP_VREF) {
257 		unsigned int vref =
258 			(caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
259 		snd_iprintf(buffer, "    Vref caps:");
260 		if (vref & AC_PINCAP_VREF_HIZ)
261 			snd_iprintf(buffer, " HIZ");
262 		if (vref & AC_PINCAP_VREF_50)
263 			snd_iprintf(buffer, " 50");
264 		if (vref & AC_PINCAP_VREF_GRD)
265 			snd_iprintf(buffer, " GRD");
266 		if (vref & AC_PINCAP_VREF_80)
267 			snd_iprintf(buffer, " 80");
268 		if (vref & AC_PINCAP_VREF_100)
269 			snd_iprintf(buffer, " 100");
270 		snd_iprintf(buffer, "\n");
271 		*supports_vref = 1;
272 	} else
273 		*supports_vref = 0;
274 	if (caps & AC_PINCAP_EAPD) {
275 		val = snd_hda_codec_read(codec, nid, 0,
276 					 AC_VERB_GET_EAPD_BTLENABLE, 0);
277 		snd_iprintf(buffer, "  EAPD 0x%x:", val);
278 		if (val & AC_EAPDBTL_BALANCED)
279 			snd_iprintf(buffer, " BALANCED");
280 		if (val & AC_EAPDBTL_EAPD)
281 			snd_iprintf(buffer, " EAPD");
282 		if (val & AC_EAPDBTL_LR_SWAP)
283 			snd_iprintf(buffer, " R/L");
284 		snd_iprintf(buffer, "\n");
285 	}
286 	caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
287 	snd_iprintf(buffer, "  Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
288 		    jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
289 		    snd_hda_get_jack_type(caps),
290 		    snd_hda_get_jack_connectivity(caps),
291 		    snd_hda_get_jack_location(caps));
292 	snd_iprintf(buffer, "    Conn = %s, Color = %s\n",
293 		    get_jack_connection(caps),
294 		    get_jack_color(caps));
295 	/* Default association and sequence values refer to default grouping
296 	 * of pin complexes and their sequence within the group. This is used
297 	 * for priority and resource allocation.
298 	 */
299 	snd_iprintf(buffer, "    DefAssociation = 0x%x, Sequence = 0x%x\n",
300 		    (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
301 		    caps & AC_DEFCFG_SEQUENCE);
302 	if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
303 	    AC_DEFCFG_MISC_NO_PRESENCE) {
304 		/* Miscellaneous bit indicates external hardware does not
305 		 * support presence detection even if the pin complex
306 		 * indicates it is supported.
307 		 */
308 		snd_iprintf(buffer, "    Misc = NO_PRESENCE\n");
309 	}
310 }
311 
312 static void print_pin_ctls(struct snd_info_buffer *buffer,
313 			   struct hda_codec *codec, hda_nid_t nid,
314 			   int supports_vref)
315 {
316 	unsigned int pinctls;
317 
318 	pinctls = snd_hda_codec_read(codec, nid, 0,
319 				     AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
320 	snd_iprintf(buffer, "  Pin-ctls: 0x%02x:", pinctls);
321 	if (pinctls & AC_PINCTL_IN_EN)
322 		snd_iprintf(buffer, " IN");
323 	if (pinctls & AC_PINCTL_OUT_EN)
324 		snd_iprintf(buffer, " OUT");
325 	if (pinctls & AC_PINCTL_HP_EN)
326 		snd_iprintf(buffer, " HP");
327 	if (supports_vref) {
328 		int vref = pinctls & AC_PINCTL_VREFEN;
329 		switch (vref) {
330 		case AC_PINCTL_VREF_HIZ:
331 			snd_iprintf(buffer, " VREF_HIZ");
332 			break;
333 		case AC_PINCTL_VREF_50:
334 			snd_iprintf(buffer, " VREF_50");
335 			break;
336 		case AC_PINCTL_VREF_GRD:
337 			snd_iprintf(buffer, " VREF_GRD");
338 			break;
339 		case AC_PINCTL_VREF_80:
340 			snd_iprintf(buffer, " VREF_80");
341 			break;
342 		case AC_PINCTL_VREF_100:
343 			snd_iprintf(buffer, " VREF_100");
344 			break;
345 		}
346 	}
347 	snd_iprintf(buffer, "\n");
348 }
349 
350 static void print_vol_knob(struct snd_info_buffer *buffer,
351 			   struct hda_codec *codec, hda_nid_t nid)
352 {
353 	unsigned int cap = snd_hda_param_read(codec, nid,
354 					      AC_PAR_VOL_KNB_CAP);
355 	snd_iprintf(buffer, "  Volume-Knob: delta=%d, steps=%d, ",
356 		    (cap >> 7) & 1, cap & 0x7f);
357 	cap = snd_hda_codec_read(codec, nid, 0,
358 				 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
359 	snd_iprintf(buffer, "direct=%d, val=%d\n",
360 		    (cap >> 7) & 1, cap & 0x7f);
361 }
362 
363 static void print_audio_io(struct snd_info_buffer *buffer,
364 			   struct hda_codec *codec, hda_nid_t nid,
365 			   unsigned int wid_type)
366 {
367 	int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
368 	snd_iprintf(buffer,
369 		    "  Converter: stream=%d, channel=%d\n",
370 		    (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
371 		    conv & AC_CONV_CHANNEL);
372 
373 	if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
374 		int sdi = snd_hda_codec_read(codec, nid, 0,
375 					     AC_VERB_GET_SDI_SELECT, 0);
376 		snd_iprintf(buffer, "  SDI-Select: %d\n",
377 			    sdi & AC_SDI_SELECT);
378 	}
379 }
380 
381 static void print_digital_conv(struct snd_info_buffer *buffer,
382 			       struct hda_codec *codec, hda_nid_t nid)
383 {
384 	unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
385 						AC_VERB_GET_DIGI_CONVERT_1, 0);
386 	snd_iprintf(buffer, "  Digital:");
387 	if (digi1 & AC_DIG1_ENABLE)
388 		snd_iprintf(buffer, " Enabled");
389 	if (digi1 & AC_DIG1_V)
390 		snd_iprintf(buffer, " Validity");
391 	if (digi1 & AC_DIG1_VCFG)
392 		snd_iprintf(buffer, " ValidityCfg");
393 	if (digi1 & AC_DIG1_EMPHASIS)
394 		snd_iprintf(buffer, " Preemphasis");
395 	if (digi1 & AC_DIG1_COPYRIGHT)
396 		snd_iprintf(buffer, " Copyright");
397 	if (digi1 & AC_DIG1_NONAUDIO)
398 		snd_iprintf(buffer, " Non-Audio");
399 	if (digi1 & AC_DIG1_PROFESSIONAL)
400 		snd_iprintf(buffer, " Pro");
401 	if (digi1 & AC_DIG1_LEVEL)
402 		snd_iprintf(buffer, " GenLevel");
403 	snd_iprintf(buffer, "\n");
404 	snd_iprintf(buffer, "  Digital category: 0x%x\n",
405 		    (digi1 >> 8) & AC_DIG2_CC);
406 }
407 
408 static const char *get_pwr_state(u32 state)
409 {
410 	static const char *buf[4] = {
411 		"D0", "D1", "D2", "D3"
412 	};
413 	if (state < 4)
414 		return buf[state];
415 	return "UNKNOWN";
416 }
417 
418 static void print_power_state(struct snd_info_buffer *buffer,
419 			      struct hda_codec *codec, hda_nid_t nid)
420 {
421 	static char *names[] = {
422 		[ilog2(AC_PWRST_D0SUP)]		= "D0",
423 		[ilog2(AC_PWRST_D1SUP)]		= "D1",
424 		[ilog2(AC_PWRST_D2SUP)]		= "D2",
425 		[ilog2(AC_PWRST_D3SUP)]		= "D3",
426 		[ilog2(AC_PWRST_D3COLDSUP)]	= "D3cold",
427 		[ilog2(AC_PWRST_S3D3COLDSUP)]	= "S3D3cold",
428 		[ilog2(AC_PWRST_CLKSTOP)]	= "CLKSTOP",
429 		[ilog2(AC_PWRST_EPSS)]		= "EPSS",
430 	};
431 
432 	int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
433 	int pwr = snd_hda_codec_read(codec, nid, 0,
434 				     AC_VERB_GET_POWER_STATE, 0);
435 	if (sup)
436 		snd_iprintf(buffer, "  Power states: %s\n",
437 			    bits_names(sup, names, ARRAY_SIZE(names)));
438 
439 	snd_iprintf(buffer, "  Power: setting=%s, actual=%s\n",
440 		    get_pwr_state(pwr & AC_PWRST_SETTING),
441 		    get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
442 				  AC_PWRST_ACTUAL_SHIFT));
443 }
444 
445 static void print_unsol_cap(struct snd_info_buffer *buffer,
446 			      struct hda_codec *codec, hda_nid_t nid)
447 {
448 	int unsol = snd_hda_codec_read(codec, nid, 0,
449 				       AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
450 	snd_iprintf(buffer,
451 		    "  Unsolicited: tag=%02x, enabled=%d\n",
452 		    unsol & AC_UNSOL_TAG,
453 		    (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
454 }
455 
456 static void print_proc_caps(struct snd_info_buffer *buffer,
457 			    struct hda_codec *codec, hda_nid_t nid)
458 {
459 	unsigned int proc_caps = snd_hda_param_read(codec, nid,
460 						    AC_PAR_PROC_CAP);
461 	snd_iprintf(buffer, "  Processing caps: benign=%d, ncoeff=%d\n",
462 		    proc_caps & AC_PCAP_BENIGN,
463 		    (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT);
464 }
465 
466 static void print_conn_list(struct snd_info_buffer *buffer,
467 			    struct hda_codec *codec, hda_nid_t nid,
468 			    unsigned int wid_type, hda_nid_t *conn,
469 			    int conn_len)
470 {
471 	int c, curr = -1;
472 
473 	if (conn_len > 1 &&
474 	    wid_type != AC_WID_AUD_MIX &&
475 	    wid_type != AC_WID_VOL_KNB &&
476 	    wid_type != AC_WID_POWER)
477 		curr = snd_hda_codec_read(codec, nid, 0,
478 					  AC_VERB_GET_CONNECT_SEL, 0);
479 	snd_iprintf(buffer, "  Connection: %d\n", conn_len);
480 	if (conn_len > 0) {
481 		snd_iprintf(buffer, "    ");
482 		for (c = 0; c < conn_len; c++) {
483 			snd_iprintf(buffer, " 0x%02x", conn[c]);
484 			if (c == curr)
485 				snd_iprintf(buffer, "*");
486 		}
487 		snd_iprintf(buffer, "\n");
488 	}
489 }
490 
491 static void print_gpio(struct snd_info_buffer *buffer,
492 		       struct hda_codec *codec, hda_nid_t nid)
493 {
494 	unsigned int gpio =
495 		snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
496 	unsigned int enable, direction, wake, unsol, sticky, data;
497 	int i, max;
498 	snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
499 		    "unsolicited=%d, wake=%d\n",
500 		    gpio & AC_GPIO_IO_COUNT,
501 		    (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
502 		    (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
503 		    (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
504 		    (gpio & AC_GPIO_WAKE) ? 1 : 0);
505 	max = gpio & AC_GPIO_IO_COUNT;
506 	if (!max || max > 8)
507 		return;
508 	enable = snd_hda_codec_read(codec, nid, 0,
509 				    AC_VERB_GET_GPIO_MASK, 0);
510 	direction = snd_hda_codec_read(codec, nid, 0,
511 				       AC_VERB_GET_GPIO_DIRECTION, 0);
512 	wake = snd_hda_codec_read(codec, nid, 0,
513 				  AC_VERB_GET_GPIO_WAKE_MASK, 0);
514 	unsol  = snd_hda_codec_read(codec, nid, 0,
515 				    AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
516 	sticky = snd_hda_codec_read(codec, nid, 0,
517 				    AC_VERB_GET_GPIO_STICKY_MASK, 0);
518 	data = snd_hda_codec_read(codec, nid, 0,
519 				  AC_VERB_GET_GPIO_DATA, 0);
520 	for (i = 0; i < max; ++i)
521 		snd_iprintf(buffer,
522 			    "  IO[%d]: enable=%d, dir=%d, wake=%d, "
523 			    "sticky=%d, data=%d, unsol=%d\n", i,
524 			    (enable & (1<<i)) ? 1 : 0,
525 			    (direction & (1<<i)) ? 1 : 0,
526 			    (wake & (1<<i)) ? 1 : 0,
527 			    (sticky & (1<<i)) ? 1 : 0,
528 			    (data & (1<<i)) ? 1 : 0,
529 			    (unsol & (1<<i)) ? 1 : 0);
530 	/* FIXME: add GPO and GPI pin information */
531 	print_nid_mixers(buffer, codec, nid);
532 }
533 
534 static void print_codec_info(struct snd_info_entry *entry,
535 			     struct snd_info_buffer *buffer)
536 {
537 	struct hda_codec *codec = entry->private_data;
538 	hda_nid_t nid;
539 	int i, nodes;
540 
541 	snd_iprintf(buffer, "Codec: ");
542 	if (codec->vendor_name && codec->chip_name)
543 		snd_iprintf(buffer, "%s %s\n",
544 			    codec->vendor_name, codec->chip_name);
545 	else
546 		snd_iprintf(buffer, "Not Set\n");
547 	snd_iprintf(buffer, "Address: %d\n", codec->addr);
548 	snd_iprintf(buffer, "Function Id: 0x%x\n", codec->function_id);
549 	snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
550 	snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
551 	snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
552 
553 	if (codec->mfg)
554 		snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
555 	else
556 		snd_iprintf(buffer, "No Modem Function Group found\n");
557 
558 	if (! codec->afg)
559 		return;
560 	snd_hda_power_up(codec);
561 	snd_iprintf(buffer, "Default PCM:\n");
562 	print_pcm_caps(buffer, codec, codec->afg);
563 	snd_iprintf(buffer, "Default Amp-In caps: ");
564 	print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
565 	snd_iprintf(buffer, "Default Amp-Out caps: ");
566 	print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
567 
568 	nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
569 	if (! nid || nodes < 0) {
570 		snd_iprintf(buffer, "Invalid AFG subtree\n");
571 		snd_hda_power_down(codec);
572 		return;
573 	}
574 
575 	print_gpio(buffer, codec, codec->afg);
576 	if (codec->proc_widget_hook)
577 		codec->proc_widget_hook(buffer, codec, codec->afg);
578 
579 	for (i = 0; i < nodes; i++, nid++) {
580 		unsigned int wid_caps =
581 			snd_hda_param_read(codec, nid,
582 					   AC_PAR_AUDIO_WIDGET_CAP);
583 		unsigned int wid_type = get_wcaps_type(wid_caps);
584 		hda_nid_t conn[HDA_MAX_CONNECTIONS];
585 		int conn_len = 0;
586 
587 		snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
588 			    get_wid_type_name(wid_type), wid_caps);
589 		if (wid_caps & AC_WCAP_STEREO) {
590 			unsigned int chans = get_wcaps_channels(wid_caps);
591 			if (chans == 2)
592 				snd_iprintf(buffer, " Stereo");
593 			else
594 				snd_iprintf(buffer, " %d-Channels", chans);
595 		} else
596 			snd_iprintf(buffer, " Mono");
597 		if (wid_caps & AC_WCAP_DIGITAL)
598 			snd_iprintf(buffer, " Digital");
599 		if (wid_caps & AC_WCAP_IN_AMP)
600 			snd_iprintf(buffer, " Amp-In");
601 		if (wid_caps & AC_WCAP_OUT_AMP)
602 			snd_iprintf(buffer, " Amp-Out");
603 		if (wid_caps & AC_WCAP_STRIPE)
604 			snd_iprintf(buffer, " Stripe");
605 		if (wid_caps & AC_WCAP_LR_SWAP)
606 			snd_iprintf(buffer, " R/L");
607 		if (wid_caps & AC_WCAP_CP_CAPS)
608 			snd_iprintf(buffer, " CP");
609 		snd_iprintf(buffer, "\n");
610 
611 		print_nid_mixers(buffer, codec, nid);
612 		print_nid_pcms(buffer, codec, nid);
613 
614 		/* volume knob is a special widget that always have connection
615 		 * list
616 		 */
617 		if (wid_type == AC_WID_VOL_KNB)
618 			wid_caps |= AC_WCAP_CONN_LIST;
619 
620 		if (wid_caps & AC_WCAP_CONN_LIST)
621 			conn_len = snd_hda_get_connections(codec, nid, conn,
622 							   HDA_MAX_CONNECTIONS);
623 
624 		if (wid_caps & AC_WCAP_IN_AMP) {
625 			snd_iprintf(buffer, "  Amp-In caps: ");
626 			print_amp_caps(buffer, codec, nid, HDA_INPUT);
627 			snd_iprintf(buffer, "  Amp-In vals: ");
628 			print_amp_vals(buffer, codec, nid, HDA_INPUT,
629 				       wid_caps & AC_WCAP_STEREO,
630 				       wid_type == AC_WID_PIN ? 1 : conn_len);
631 		}
632 		if (wid_caps & AC_WCAP_OUT_AMP) {
633 			snd_iprintf(buffer, "  Amp-Out caps: ");
634 			print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
635 			snd_iprintf(buffer, "  Amp-Out vals: ");
636 			if (wid_type == AC_WID_PIN &&
637 			    codec->pin_amp_workaround)
638 				print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
639 					       wid_caps & AC_WCAP_STEREO,
640 					       conn_len);
641 			else
642 				print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
643 					       wid_caps & AC_WCAP_STEREO, 1);
644 		}
645 
646 		switch (wid_type) {
647 		case AC_WID_PIN: {
648 			int supports_vref;
649 			print_pin_caps(buffer, codec, nid, &supports_vref);
650 			print_pin_ctls(buffer, codec, nid, supports_vref);
651 			break;
652 		}
653 		case AC_WID_VOL_KNB:
654 			print_vol_knob(buffer, codec, nid);
655 			break;
656 		case AC_WID_AUD_OUT:
657 		case AC_WID_AUD_IN:
658 			print_audio_io(buffer, codec, nid, wid_type);
659 			if (wid_caps & AC_WCAP_DIGITAL)
660 				print_digital_conv(buffer, codec, nid);
661 			if (wid_caps & AC_WCAP_FORMAT_OVRD) {
662 				snd_iprintf(buffer, "  PCM:\n");
663 				print_pcm_caps(buffer, codec, nid);
664 			}
665 			break;
666 		}
667 
668 		if (wid_caps & AC_WCAP_UNSOL_CAP)
669 			print_unsol_cap(buffer, codec, nid);
670 
671 		if (wid_caps & AC_WCAP_POWER)
672 			print_power_state(buffer, codec, nid);
673 
674 		if (wid_caps & AC_WCAP_DELAY)
675 			snd_iprintf(buffer, "  Delay: %d samples\n",
676 				    (wid_caps & AC_WCAP_DELAY) >>
677 				    AC_WCAP_DELAY_SHIFT);
678 
679 		if (wid_caps & AC_WCAP_CONN_LIST)
680 			print_conn_list(buffer, codec, nid, wid_type,
681 					conn, conn_len);
682 
683 		if (wid_caps & AC_WCAP_PROC_WID)
684 			print_proc_caps(buffer, codec, nid);
685 
686 		if (codec->proc_widget_hook)
687 			codec->proc_widget_hook(buffer, codec, nid);
688 	}
689 	snd_hda_power_down(codec);
690 }
691 
692 /*
693  * create a proc read
694  */
695 int snd_hda_codec_proc_new(struct hda_codec *codec)
696 {
697 	char name[32];
698 	struct snd_info_entry *entry;
699 	int err;
700 
701 	snprintf(name, sizeof(name), "codec#%d", codec->addr);
702 	err = snd_card_proc_new(codec->bus->card, name, &entry);
703 	if (err < 0)
704 		return err;
705 
706 	snd_info_set_text_ops(entry, codec, print_codec_info);
707 	return 0;
708 }
709 
710