blob: 09476fc1ab64980c78ca170ca00fa7cbb3bb6ab2 [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");
243 else
244 snd_iprintf(buffer, " HDMI");
245 }
Andrew Paprocki797760a2008-01-18 12:51:11 +0100246 if (caps & AC_PINCAP_TRIG_REQ)
247 snd_iprintf(buffer, " Trigger");
248 if (caps & AC_PINCAP_IMP_SENSE)
249 snd_iprintf(buffer, " ImpSense");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 snd_iprintf(buffer, "\n");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100251 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200282 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],
Matthew Ranostay50a9f792008-10-25 01:05:45 -0400284 snd_hda_get_jack_type(caps),
285 snd_hda_get_jack_connectivity(caps),
286 snd_hda_get_jack_location(caps));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
288 get_jack_connection(caps),
289 get_jack_color(caps));
Andrew Paprocki797760a2008-01-18 12:51:11 +0100290 /* 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");
Takashi Iwaie97a5162007-10-26 14:56:36 +0200304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305}
306
Andrew Paprocki797760a2008-01-18 12:51:11 +0100307static 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
345static 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
358static void print_audio_io(struct snd_info_buffer *buffer,
359 struct hda_codec *codec, hda_nid_t nid,
360 unsigned int wid_type)
361{
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100362 int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100363 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
376static 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);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100381 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");
Takashi Iwaia1855d82008-06-19 15:41:37 +0200399 snd_iprintf(buffer, " Digital category: 0x%x\n",
400 (digi1 >> 8) & AC_DIG2_CC);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100401}
402
403static 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
413static void print_power_state(struct snd_info_buffer *buffer,
414 struct hda_codec *codec, hda_nid_t nid)
415{
Wu Fengguang83d605f2009-11-18 12:38:08 +0800416 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);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100428 int pwr = snd_hda_codec_read(codec, nid, 0,
429 AC_VERB_GET_POWER_STATE, 0);
Wu Fengguang83d605f2009-11-18 12:38:08 +0800430 if (sup)
431 snd_iprintf(buffer, " Power states: %s\n",
432 bits_names(sup, names, ARRAY_SIZE(names)));
433
Andrew Paprocki797760a2008-01-18 12:51:11 +0100434 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
440static 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
451static 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
461static 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
Takashi Iwai07a1e812009-03-19 17:08:19 +0100468 if (conn_len > 1 &&
469 wid_type != AC_WID_AUD_MIX &&
470 wid_type != AC_WID_VOL_KNB &&
471 wid_type != AC_WID_POWER)
Andrew Paprocki797760a2008-01-18 12:51:11 +0100472 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
Andrew Paprocki797760a2008-01-18 12:51:11 +0100486static 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;
Takashi Iwaic4dc5072008-11-04 13:30:57 +0100501 if (!max || max > 8)
502 return;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100503 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, "
Takashi Iwai85639642008-11-19 14:14:50 +0100518 "sticky=%d, data=%d, unsol=%d\n", i,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100519 (enable & (1<<i)) ? 1 : 0,
520 (direction & (1<<i)) ? 1 : 0,
521 (wake & (1<<i)) ? 1 : 0,
522 (sticky & (1<<i)) ? 1 : 0,
Takashi Iwai85639642008-11-19 14:14:50 +0100523 (data & (1<<i)) ? 1 : 0,
524 (unsol & (1<<i)) ? 1 : 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100525 /* FIXME: add GPO and GPI pin information */
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100526 print_nid_mixers(buffer, codec, nid);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100527}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Takashi Iwaid01ce992007-07-27 16:52:19 +0200529static void print_codec_info(struct snd_info_entry *entry,
530 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
532 struct hda_codec *codec = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 hda_nid_t nid;
534 int i, nodes;
535
Takashi Iwai812a2cc2009-05-16 10:00:49 +0200536 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 snd_iprintf(buffer, "Address: %d\n", codec->addr);
Pascal de Bruijn234b4342009-03-23 11:15:59 +0100543 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
Jonathan Phenixe25c05f2007-06-19 18:31:28 +0200547
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
Takashi Iwaiec9e1c52005-09-07 13:29:22 +0200553 if (! codec->afg)
554 return;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200555 snd_hda_power_up(codec);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100556 snd_iprintf(buffer, "Default PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 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");
Takashi Iwaicb53c622007-08-10 17:21:45 +0200566 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return;
568 }
Andrew Paprocki797760a2008-01-18 12:51:11 +0100569
570 print_gpio(buffer, codec, codec->afg);
Takashi Iwai2d34e1b2008-11-28 14:35:16 +0100571 if (codec->proc_widget_hook)
572 codec->proc_widget_hook(buffer, codec, codec->afg);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 for (i = 0; i < nodes; i++, nid++) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200575 unsigned int wid_caps =
576 snd_hda_param_read(codec, nid,
577 AC_PAR_AUDIO_WIDGET_CAP);
Takashi Iwaia22d5432009-07-27 12:54:26 +0200578 unsigned int wid_type = get_wcaps_type(wid_caps);
Takashi Iwai3e289f12005-06-10 19:45:09 +0200579 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Andrew Paprocki797760a2008-01-18 12:51:11 +0100580 int conn_len = 0;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
583 get_wid_type_name(wid_type), wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200584 if (wid_caps & AC_WCAP_STEREO) {
Wu Fengguangfd72d002009-08-24 09:50:46 +0800585 unsigned int chans = get_wcaps_channels(wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200586 if (chans == 2)
587 snd_iprintf(buffer, " Stereo");
588 else
589 snd_iprintf(buffer, " %d-Channels", chans);
590 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 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");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100598 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");
Takashi Iwaic4920602008-07-30 15:13:29 +0200602 if (wid_caps & AC_WCAP_CP_CAPS)
603 snd_iprintf(buffer, " CP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 snd_iprintf(buffer, "\n");
605
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100606 print_nid_mixers(buffer, codec, nid);
607 print_nid_pcms(buffer, codec, nid);
608
Takashi Iwaie1716132007-11-16 17:52:39 +0100609 /* 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
Takashi Iwai3e289f12005-06-10 19:45:09 +0200615 if (wid_caps & AC_WCAP_CONN_LIST)
616 conn_len = snd_hda_get_connections(codec, nid, conn,
617 HDA_MAX_CONNECTIONS);
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 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,
Takashi Iwai9e03ad72008-02-22 18:46:00 +0100624 wid_caps & AC_WCAP_STEREO,
625 wid_type == AC_WID_PIN ? 1 : conn_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 }
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: ");
Takashi Iwai9421f952009-03-12 17:06:07 +0100631 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640
Takashi Iwaie97a5162007-10-26 14:56:36 +0200641 switch (wid_type) {
Andrew Paprocki797760a2008-01-18 12:51:11 +0100642 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);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200646 break;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100647 }
Takashi Iwaie97a5162007-10-26 14:56:36 +0200648 case AC_WID_VOL_KNB:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100649 print_vol_knob(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200650 break;
651 case AC_WID_AUD_OUT:
652 case AC_WID_AUD_IN:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100653 print_audio_io(buffer, codec, nid, wid_type);
654 if (wid_caps & AC_WCAP_DIGITAL)
655 print_digital_conv(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200656 if (wid_caps & AC_WCAP_FORMAT_OVRD) {
657 snd_iprintf(buffer, " PCM:\n");
658 print_pcm_caps(buffer, codec, nid);
659 }
660 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
Andrew Paprocki797760a2008-01-18 12:51:11 +0100663 if (wid_caps & AC_WCAP_UNSOL_CAP)
664 print_unsol_cap(buffer, codec, nid);
Takashi Iwaib7027cc2005-11-02 18:13:41 +0100665
Andrew Paprocki797760a2008-01-18 12:51:11 +0100666 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
Takashi Iwaidaead532008-11-28 12:55:36 +0100681 if (codec->proc_widget_hook)
682 codec->proc_widget_hook(buffer, codec, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
Takashi Iwaicb53c622007-08-10 17:21:45 +0200684 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
687/*
688 * create a proc read
689 */
690int snd_hda_codec_proc_new(struct hda_codec *codec)
691{
692 char name[32];
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100693 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 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
Takashi Iwaibf850202006-04-28 15:13:41 +0200701 snd_info_set_text_ops(entry, codec, print_codec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 return 0;
703}
704