blob: c9afc04adac8d126c302b7c11bcdc183b355766a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <sound/core.h>
26#include "hda_codec.h"
Adrian Bunk18612042005-11-23 13:14:50 +010027#include "hda_local.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Wu Fengguang83d605f2009-11-18 12:38:08 +080029static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static 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
Takashi Iwai3bc89522006-10-17 20:41:38 +020061 return "UNKNOWN Widget";
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010064static 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
80static 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
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010099static void print_amp_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 struct hda_codec *codec, hda_nid_t nid, int dir)
101{
102 unsigned int caps;
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200103 caps = snd_hda_param_read(codec, nid,
104 dir == HDA_OUTPUT ?
105 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if (caps == -1 || caps == 0) {
107 snd_iprintf(buffer, "N/A\n");
108 return;
109 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200110 snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
111 "mute=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 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
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100118static void print_amp_vals(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200120 int dir, int stereo, int indices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 unsigned int val;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200123 int i;
124
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200125 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200126 for (i = 0; i < indices; i++) {
127 snd_iprintf(buffer, " [");
128 if (stereo) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200129 val = snd_hda_codec_read(codec, nid, 0,
130 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200131 AC_AMP_GET_LEFT | dir | i);
132 snd_iprintf(buffer, "0x%02x ", val);
133 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200134 val = snd_hda_codec_read(codec, nid, 0,
135 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200136 AC_AMP_GET_RIGHT | dir | i);
137 snd_iprintf(buffer, "0x%02x]", val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
Takashi Iwai3e289f12005-06-10 19:45:09 +0200139 snd_iprintf(buffer, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Wu Fengguang33deeca2008-11-18 11:47:51 +0800142static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
143{
144 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
Wu Fengguangd39b4352008-11-19 15:14:02 +0800145
Takashi Iwaib90d7762006-11-07 16:10:06 +0100146 pcm &= AC_SUPPCM_RATES;
147 snd_iprintf(buffer, " rates [0x%x]:", pcm);
Wu Fengguang33deeca2008-11-18 11:47:51 +0800148 snd_print_pcm_rates(pcm, buf, sizeof(buf));
149 snd_iprintf(buffer, "%s\n", buf);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100150}
151
Wu Fengguangd39b4352008-11-19 15:14:02 +0800152static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
153{
154 char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
Takashi Iwaib90d7762006-11-07 16:10:06 +0100155
Takashi Iwaib0e64812008-11-25 16:07:01 +0100156 snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
Wu Fengguangd39b4352008-11-19 15:14:02 +0800157 snd_print_pcm_bits(pcm, buf, sizeof(buf));
158 snd_iprintf(buffer, "%s\n", buf);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100159}
160
161static 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
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100174static void print_pcm_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 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 }
Takashi Iwaib90d7762006-11-07 16:10:06 +0100183 print_pcm_rates(buffer, pcm);
184 print_pcm_bits(buffer, pcm);
185 print_pcm_formats(buffer, stream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static 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
203static 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
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100218static void print_pin_caps(struct snd_info_buffer *buffer,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100219 struct hda_codec *codec, hda_nid_t nid,
220 int *supports_vref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200222 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
Takashi Iwaie97a5162007-10-26 14:56:36 +0200223 unsigned int caps, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
Robin H. Johnson0481f452008-09-13 16:54:57 -0700226 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 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");
Takashi Iwai58854922006-06-21 19:19:25 +0200233 if (caps & AC_PINCAP_EAPD)
234 snd_iprintf(buffer, " EAPD");
235 if (caps & AC_PINCAP_PRES_DETECT)
236 snd_iprintf(buffer, " Detect");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100237 if (caps & AC_PINCAP_BALANCE)
238 snd_iprintf(buffer, " Balanced");
Takashi Iwaic4920602008-07-30 15:13:29 +0200239 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");
Wu Fengguangb9235282009-12-11 12:28:33 +0800243 else {
244 if (caps & AC_PINCAP_HBR)
245 snd_iprintf(buffer, " HBR");
Takashi Iwaic4920602008-07-30 15:13:29 +0200246 snd_iprintf(buffer, " HDMI");
Wu Fengguangb9235282009-12-11 12:28:33 +0800247 }
Takashi Iwaic4920602008-07-30 15:13:29 +0200248 }
Wu Fengguang728765b2009-12-11 12:28:34 +0800249 if (caps & AC_PINCAP_DP)
250 snd_iprintf(buffer, " DP");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100251 if (caps & AC_PINCAP_TRIG_REQ)
252 snd_iprintf(buffer, " Trigger");
253 if (caps & AC_PINCAP_IMP_SENSE)
254 snd_iprintf(buffer, " ImpSense");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 snd_iprintf(buffer, "\n");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100256 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200287 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],
Matthew Ranostay50a9f792008-10-25 01:05:45 -0400289 snd_hda_get_jack_type(caps),
290 snd_hda_get_jack_connectivity(caps),
291 snd_hda_get_jack_location(caps));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
293 get_jack_connection(caps),
294 get_jack_color(caps));
Andrew Paprocki797760a2008-01-18 12:51:11 +0100295 /* 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");
Takashi Iwaie97a5162007-10-26 14:56:36 +0200309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
Andrew Paprocki797760a2008-01-18 12:51:11 +0100312static 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
350static 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
363static void print_audio_io(struct snd_info_buffer *buffer,
364 struct hda_codec *codec, hda_nid_t nid,
365 unsigned int wid_type)
366{
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100367 int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100368 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
381static 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);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100386 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");
Takashi Iwaia1855d82008-06-19 15:41:37 +0200404 snd_iprintf(buffer, " Digital category: 0x%x\n",
405 (digi1 >> 8) & AC_DIG2_CC);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100406}
407
408static 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
418static void print_power_state(struct snd_info_buffer *buffer,
419 struct hda_codec *codec, hda_nid_t nid)
420{
Wu Fengguang83d605f2009-11-18 12:38:08 +0800421 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);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100433 int pwr = snd_hda_codec_read(codec, nid, 0,
434 AC_VERB_GET_POWER_STATE, 0);
Wu Fengguang83d605f2009-11-18 12:38:08 +0800435 if (sup)
436 snd_iprintf(buffer, " Power states: %s\n",
437 bits_names(sup, names, ARRAY_SIZE(names)));
438
Andrew Paprocki797760a2008-01-18 12:51:11 +0100439 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
445static 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
456static 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
466static 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
Takashi Iwai07a1e812009-03-19 17:08:19 +0100473 if (conn_len > 1 &&
474 wid_type != AC_WID_AUD_MIX &&
475 wid_type != AC_WID_VOL_KNB &&
476 wid_type != AC_WID_POWER)
Andrew Paprocki797760a2008-01-18 12:51:11 +0100477 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
Andrew Paprocki797760a2008-01-18 12:51:11 +0100491static 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;
Takashi Iwaic4dc5072008-11-04 13:30:57 +0100506 if (!max || max > 8)
507 return;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100508 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, "
Takashi Iwai85639642008-11-19 14:14:50 +0100523 "sticky=%d, data=%d, unsol=%d\n", i,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100524 (enable & (1<<i)) ? 1 : 0,
525 (direction & (1<<i)) ? 1 : 0,
526 (wake & (1<<i)) ? 1 : 0,
527 (sticky & (1<<i)) ? 1 : 0,
Takashi Iwai85639642008-11-19 14:14:50 +0100528 (data & (1<<i)) ? 1 : 0,
529 (unsol & (1<<i)) ? 1 : 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100530 /* FIXME: add GPO and GPI pin information */
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100531 print_nid_mixers(buffer, codec, nid);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100532}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Takashi Iwaid01ce992007-07-27 16:52:19 +0200534static void print_codec_info(struct snd_info_entry *entry,
535 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
537 struct hda_codec *codec = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 hda_nid_t nid;
539 int i, nodes;
540
Takashi Iwai812a2cc2009-05-16 10:00:49 +0200541 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 snd_iprintf(buffer, "Address: %d\n", codec->addr);
Pascal de Bruijn234b4342009-03-23 11:15:59 +0100548 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
Jonathan Phenixe25c05f2007-06-19 18:31:28 +0200552
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
Takashi Iwaiec9e1c52005-09-07 13:29:22 +0200558 if (! codec->afg)
559 return;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200560 snd_hda_power_up(codec);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100561 snd_iprintf(buffer, "Default PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 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");
Takashi Iwaicb53c622007-08-10 17:21:45 +0200571 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return;
573 }
Andrew Paprocki797760a2008-01-18 12:51:11 +0100574
575 print_gpio(buffer, codec, codec->afg);
Takashi Iwai2d34e1b2008-11-28 14:35:16 +0100576 if (codec->proc_widget_hook)
577 codec->proc_widget_hook(buffer, codec, codec->afg);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 for (i = 0; i < nodes; i++, nid++) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200580 unsigned int wid_caps =
581 snd_hda_param_read(codec, nid,
582 AC_PAR_AUDIO_WIDGET_CAP);
Takashi Iwaia22d5432009-07-27 12:54:26 +0200583 unsigned int wid_type = get_wcaps_type(wid_caps);
Takashi Iwai3e289f12005-06-10 19:45:09 +0200584 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Andrew Paprocki797760a2008-01-18 12:51:11 +0100585 int conn_len = 0;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
588 get_wid_type_name(wid_type), wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200589 if (wid_caps & AC_WCAP_STEREO) {
Wu Fengguangfd72d002009-08-24 09:50:46 +0800590 unsigned int chans = get_wcaps_channels(wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200591 if (chans == 2)
592 snd_iprintf(buffer, " Stereo");
593 else
594 snd_iprintf(buffer, " %d-Channels", chans);
595 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 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");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100603 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");
Takashi Iwaic4920602008-07-30 15:13:29 +0200607 if (wid_caps & AC_WCAP_CP_CAPS)
608 snd_iprintf(buffer, " CP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 snd_iprintf(buffer, "\n");
610
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100611 print_nid_mixers(buffer, codec, nid);
612 print_nid_pcms(buffer, codec, nid);
613
Takashi Iwaie1716132007-11-16 17:52:39 +0100614 /* 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
Takashi Iwai3e289f12005-06-10 19:45:09 +0200620 if (wid_caps & AC_WCAP_CONN_LIST)
621 conn_len = snd_hda_get_connections(codec, nid, conn,
622 HDA_MAX_CONNECTIONS);
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 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,
Takashi Iwai9e03ad72008-02-22 18:46:00 +0100629 wid_caps & AC_WCAP_STEREO,
630 wid_type == AC_WID_PIN ? 1 : conn_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
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: ");
Takashi Iwai9421f952009-03-12 17:06:07 +0100636 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645
Takashi Iwaie97a5162007-10-26 14:56:36 +0200646 switch (wid_type) {
Andrew Paprocki797760a2008-01-18 12:51:11 +0100647 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);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200651 break;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100652 }
Takashi Iwaie97a5162007-10-26 14:56:36 +0200653 case AC_WID_VOL_KNB:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100654 print_vol_knob(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200655 break;
656 case AC_WID_AUD_OUT:
657 case AC_WID_AUD_IN:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100658 print_audio_io(buffer, codec, nid, wid_type);
659 if (wid_caps & AC_WCAP_DIGITAL)
660 print_digital_conv(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200661 if (wid_caps & AC_WCAP_FORMAT_OVRD) {
662 snd_iprintf(buffer, " PCM:\n");
663 print_pcm_caps(buffer, codec, nid);
664 }
665 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667
Andrew Paprocki797760a2008-01-18 12:51:11 +0100668 if (wid_caps & AC_WCAP_UNSOL_CAP)
669 print_unsol_cap(buffer, codec, nid);
Takashi Iwaib7027cc2005-11-02 18:13:41 +0100670
Andrew Paprocki797760a2008-01-18 12:51:11 +0100671 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
Takashi Iwaidaead532008-11-28 12:55:36 +0100686 if (codec->proc_widget_hook)
687 codec->proc_widget_hook(buffer, codec, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
Takashi Iwaicb53c622007-08-10 17:21:45 +0200689 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
692/*
693 * create a proc read
694 */
695int snd_hda_codec_proc_new(struct hda_codec *codec)
696{
697 char name[32];
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100698 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 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
Takashi Iwaibf850202006-04-28 15:13:41 +0200706 snd_info_set_text_ops(entry, codec, print_codec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 return 0;
708}
709