blob: 254ab5204603767c54f44f25b5d94df624bb89d3 [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 };
Takashi Iwai3a902742012-01-10 12:41:22 +010057 if (wid_value == -1)
58 return "UNKNOWN Widget";
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 wid_value &= 0xf;
60 if (names[wid_value])
61 return names[wid_value];
62 else
Takashi Iwai3bc89522006-10-17 20:41:38 +020063 return "UNKNOWN Widget";
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010066static void print_nid_array(struct snd_info_buffer *buffer,
67 struct hda_codec *codec, hda_nid_t nid,
68 struct snd_array *array)
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010069{
70 int i;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010071 struct hda_nid_item *items = array->list, *item;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010072 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010073 for (i = 0; i < array->used; i++) {
74 item = &items[i];
75 if (item->nid == nid) {
76 kctl = item->kctl;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010077 snd_iprintf(buffer,
78 " Control: name=\"%s\", index=%i, device=%i\n",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010079 kctl->id.name, kctl->id.index + item->index,
80 kctl->id.device);
Jaroslav Kysela9e3fd872009-12-08 17:45:25 +010081 if (item->flags & HDA_NID_ITEM_AMP)
82 snd_iprintf(buffer,
83 " ControlAmp: chs=%lu, dir=%s, "
84 "idx=%lu, ofs=%lu\n",
85 get_amp_channels(kctl),
86 get_amp_direction(kctl) ? "Out" : "In",
87 get_amp_index(kctl),
88 get_amp_offset(kctl));
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010089 }
90 }
91}
92
93static void print_nid_pcms(struct snd_info_buffer *buffer,
94 struct hda_codec *codec, hda_nid_t nid)
95{
96 int pcm, type;
97 struct hda_pcm *cpcm;
98 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
99 cpcm = &codec->pcm_info[pcm];
100 for (type = 0; type < 2; type++) {
101 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
102 continue;
103 snd_iprintf(buffer, " Device: name=\"%s\", "
104 "type=\"%s\", device=%i\n",
105 cpcm->name,
106 snd_hda_pcm_type_name[cpcm->pcm_type],
107 cpcm->pcm->device);
108 }
109 }
110}
111
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100112static void print_amp_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct hda_codec *codec, hda_nid_t nid, int dir)
114{
115 unsigned int caps;
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200116 caps = snd_hda_param_read(codec, nid,
117 dir == HDA_OUTPUT ?
118 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 if (caps == -1 || caps == 0) {
120 snd_iprintf(buffer, "N/A\n");
121 return;
122 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200123 snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
124 "mute=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 caps & AC_AMPCAP_OFFSET,
126 (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
127 (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
128 (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
129}
130
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100131static void print_amp_vals(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200133 int dir, int stereo, int indices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 unsigned int val;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200136 int i;
137
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200138 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200139 for (i = 0; i < indices; i++) {
140 snd_iprintf(buffer, " [");
141 if (stereo) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200142 val = snd_hda_codec_read(codec, nid, 0,
143 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200144 AC_AMP_GET_LEFT | dir | i);
145 snd_iprintf(buffer, "0x%02x ", val);
146 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200147 val = snd_hda_codec_read(codec, nid, 0,
148 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200149 AC_AMP_GET_RIGHT | dir | i);
150 snd_iprintf(buffer, "0x%02x]", val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
Takashi Iwai3e289f12005-06-10 19:45:09 +0200152 snd_iprintf(buffer, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
Wu Fengguang33deeca2008-11-18 11:47:51 +0800155static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
156{
Takashi Iwaif71ff0d2011-10-06 08:16:29 +0200157 static unsigned int rates[] = {
158 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
159 96000, 176400, 192000, 384000
160 };
161 int i;
Wu Fengguangd39b4352008-11-19 15:14:02 +0800162
Takashi Iwaib90d7762006-11-07 16:10:06 +0100163 pcm &= AC_SUPPCM_RATES;
164 snd_iprintf(buffer, " rates [0x%x]:", pcm);
Takashi Iwaif71ff0d2011-10-06 08:16:29 +0200165 for (i = 0; i < ARRAY_SIZE(rates); i++)
166 if (pcm & (1 << i))
167 snd_iprintf(buffer, " %d", rates[i]);
168 snd_iprintf(buffer, "\n");
Takashi Iwaib90d7762006-11-07 16:10:06 +0100169}
170
Wu Fengguangd39b4352008-11-19 15:14:02 +0800171static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
172{
173 char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
Takashi Iwaib90d7762006-11-07 16:10:06 +0100174
Takashi Iwaib0e64812008-11-25 16:07:01 +0100175 snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
Wu Fengguangd39b4352008-11-19 15:14:02 +0800176 snd_print_pcm_bits(pcm, buf, sizeof(buf));
177 snd_iprintf(buffer, "%s\n", buf);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100178}
179
180static void print_pcm_formats(struct snd_info_buffer *buffer,
181 unsigned int streams)
182{
183 snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
184 if (streams & AC_SUPFMT_PCM)
185 snd_iprintf(buffer, " PCM");
186 if (streams & AC_SUPFMT_FLOAT32)
187 snd_iprintf(buffer, " FLOAT");
188 if (streams & AC_SUPFMT_AC3)
189 snd_iprintf(buffer, " AC3");
190 snd_iprintf(buffer, "\n");
191}
192
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100193static void print_pcm_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 struct hda_codec *codec, hda_nid_t nid)
195{
196 unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
197 unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
198 if (pcm == -1 || stream == -1) {
199 snd_iprintf(buffer, "N/A\n");
200 return;
201 }
Takashi Iwaib90d7762006-11-07 16:10:06 +0100202 print_pcm_rates(buffer, pcm);
203 print_pcm_bits(buffer, pcm);
204 print_pcm_formats(buffer, stream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207static const char *get_jack_connection(u32 cfg)
208{
209 static char *names[16] = {
210 "Unknown", "1/8", "1/4", "ATAPI",
211 "RCA", "Optical","Digital", "Analog",
212 "DIN", "XLR", "RJ11", "Comb",
213 NULL, NULL, NULL, "Other"
214 };
215 cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
216 if (names[cfg])
217 return names[cfg];
218 else
219 return "UNKNOWN";
220}
221
222static const char *get_jack_color(u32 cfg)
223{
224 static char *names[16] = {
225 "Unknown", "Black", "Grey", "Blue",
226 "Green", "Red", "Orange", "Yellow",
227 "Purple", "Pink", NULL, NULL,
228 NULL, NULL, "White", "Other",
229 };
230 cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
231 if (names[cfg])
232 return names[cfg];
233 else
234 return "UNKNOWN";
235}
236
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100237static void print_pin_caps(struct snd_info_buffer *buffer,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100238 struct hda_codec *codec, hda_nid_t nid,
239 int *supports_vref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200241 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
Takashi Iwaie97a5162007-10-26 14:56:36 +0200242 unsigned int caps, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
Robin H. Johnson0481f452008-09-13 16:54:57 -0700245 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (caps & AC_PINCAP_IN)
247 snd_iprintf(buffer, " IN");
248 if (caps & AC_PINCAP_OUT)
249 snd_iprintf(buffer, " OUT");
250 if (caps & AC_PINCAP_HP_DRV)
251 snd_iprintf(buffer, " HP");
Takashi Iwai58854922006-06-21 19:19:25 +0200252 if (caps & AC_PINCAP_EAPD)
253 snd_iprintf(buffer, " EAPD");
254 if (caps & AC_PINCAP_PRES_DETECT)
255 snd_iprintf(buffer, " Detect");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100256 if (caps & AC_PINCAP_BALANCE)
257 snd_iprintf(buffer, " Balanced");
Takashi Iwaic4920602008-07-30 15:13:29 +0200258 if (caps & AC_PINCAP_HDMI) {
259 /* Realtek uses this bit as a different meaning */
260 if ((codec->vendor_id >> 16) == 0x10ec)
261 snd_iprintf(buffer, " R/L");
Wu Fengguangb9235282009-12-11 12:28:33 +0800262 else {
263 if (caps & AC_PINCAP_HBR)
264 snd_iprintf(buffer, " HBR");
Takashi Iwaic4920602008-07-30 15:13:29 +0200265 snd_iprintf(buffer, " HDMI");
Wu Fengguangb9235282009-12-11 12:28:33 +0800266 }
Takashi Iwaic4920602008-07-30 15:13:29 +0200267 }
Wu Fengguang728765b2009-12-11 12:28:34 +0800268 if (caps & AC_PINCAP_DP)
269 snd_iprintf(buffer, " DP");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100270 if (caps & AC_PINCAP_TRIG_REQ)
271 snd_iprintf(buffer, " Trigger");
272 if (caps & AC_PINCAP_IMP_SENSE)
273 snd_iprintf(buffer, " ImpSense");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 snd_iprintf(buffer, "\n");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100275 if (caps & AC_PINCAP_VREF) {
276 unsigned int vref =
277 (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
278 snd_iprintf(buffer, " Vref caps:");
279 if (vref & AC_PINCAP_VREF_HIZ)
280 snd_iprintf(buffer, " HIZ");
281 if (vref & AC_PINCAP_VREF_50)
282 snd_iprintf(buffer, " 50");
283 if (vref & AC_PINCAP_VREF_GRD)
284 snd_iprintf(buffer, " GRD");
285 if (vref & AC_PINCAP_VREF_80)
286 snd_iprintf(buffer, " 80");
287 if (vref & AC_PINCAP_VREF_100)
288 snd_iprintf(buffer, " 100");
289 snd_iprintf(buffer, "\n");
290 *supports_vref = 1;
291 } else
292 *supports_vref = 0;
293 if (caps & AC_PINCAP_EAPD) {
294 val = snd_hda_codec_read(codec, nid, 0,
295 AC_VERB_GET_EAPD_BTLENABLE, 0);
296 snd_iprintf(buffer, " EAPD 0x%x:", val);
297 if (val & AC_EAPDBTL_BALANCED)
298 snd_iprintf(buffer, " BALANCED");
299 if (val & AC_EAPDBTL_EAPD)
300 snd_iprintf(buffer, " EAPD");
301 if (val & AC_EAPDBTL_LR_SWAP)
302 snd_iprintf(buffer, " R/L");
303 snd_iprintf(buffer, "\n");
304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200306 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
307 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
Matthew Ranostay50a9f792008-10-25 01:05:45 -0400308 snd_hda_get_jack_type(caps),
309 snd_hda_get_jack_connectivity(caps),
310 snd_hda_get_jack_location(caps));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
312 get_jack_connection(caps),
313 get_jack_color(caps));
Andrew Paprocki797760a2008-01-18 12:51:11 +0100314 /* Default association and sequence values refer to default grouping
315 * of pin complexes and their sequence within the group. This is used
316 * for priority and resource allocation.
317 */
318 snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
319 (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
320 caps & AC_DEFCFG_SEQUENCE);
321 if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
322 AC_DEFCFG_MISC_NO_PRESENCE) {
323 /* Miscellaneous bit indicates external hardware does not
324 * support presence detection even if the pin complex
325 * indicates it is supported.
326 */
327 snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
Takashi Iwaie97a5162007-10-26 14:56:36 +0200328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
Andrew Paprocki797760a2008-01-18 12:51:11 +0100331static void print_pin_ctls(struct snd_info_buffer *buffer,
332 struct hda_codec *codec, hda_nid_t nid,
333 int supports_vref)
334{
335 unsigned int pinctls;
336
337 pinctls = snd_hda_codec_read(codec, nid, 0,
338 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
339 snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
340 if (pinctls & AC_PINCTL_IN_EN)
341 snd_iprintf(buffer, " IN");
342 if (pinctls & AC_PINCTL_OUT_EN)
343 snd_iprintf(buffer, " OUT");
344 if (pinctls & AC_PINCTL_HP_EN)
345 snd_iprintf(buffer, " HP");
346 if (supports_vref) {
347 int vref = pinctls & AC_PINCTL_VREFEN;
348 switch (vref) {
349 case AC_PINCTL_VREF_HIZ:
350 snd_iprintf(buffer, " VREF_HIZ");
351 break;
352 case AC_PINCTL_VREF_50:
353 snd_iprintf(buffer, " VREF_50");
354 break;
355 case AC_PINCTL_VREF_GRD:
356 snd_iprintf(buffer, " VREF_GRD");
357 break;
358 case AC_PINCTL_VREF_80:
359 snd_iprintf(buffer, " VREF_80");
360 break;
361 case AC_PINCTL_VREF_100:
362 snd_iprintf(buffer, " VREF_100");
363 break;
364 }
365 }
366 snd_iprintf(buffer, "\n");
367}
368
369static void print_vol_knob(struct snd_info_buffer *buffer,
370 struct hda_codec *codec, hda_nid_t nid)
371{
372 unsigned int cap = snd_hda_param_read(codec, nid,
373 AC_PAR_VOL_KNB_CAP);
374 snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
375 (cap >> 7) & 1, cap & 0x7f);
376 cap = snd_hda_codec_read(codec, nid, 0,
377 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
378 snd_iprintf(buffer, "direct=%d, val=%d\n",
379 (cap >> 7) & 1, cap & 0x7f);
380}
381
382static void print_audio_io(struct snd_info_buffer *buffer,
383 struct hda_codec *codec, hda_nid_t nid,
384 unsigned int wid_type)
385{
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100386 int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100387 snd_iprintf(buffer,
388 " Converter: stream=%d, channel=%d\n",
389 (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
390 conv & AC_CONV_CHANNEL);
391
392 if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
393 int sdi = snd_hda_codec_read(codec, nid, 0,
394 AC_VERB_GET_SDI_SELECT, 0);
395 snd_iprintf(buffer, " SDI-Select: %d\n",
396 sdi & AC_SDI_SELECT);
397 }
398}
399
400static void print_digital_conv(struct snd_info_buffer *buffer,
401 struct hda_codec *codec, hda_nid_t nid)
402{
403 unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
404 AC_VERB_GET_DIGI_CONVERT_1, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100405 snd_iprintf(buffer, " Digital:");
406 if (digi1 & AC_DIG1_ENABLE)
407 snd_iprintf(buffer, " Enabled");
408 if (digi1 & AC_DIG1_V)
409 snd_iprintf(buffer, " Validity");
410 if (digi1 & AC_DIG1_VCFG)
411 snd_iprintf(buffer, " ValidityCfg");
412 if (digi1 & AC_DIG1_EMPHASIS)
413 snd_iprintf(buffer, " Preemphasis");
414 if (digi1 & AC_DIG1_COPYRIGHT)
415 snd_iprintf(buffer, " Copyright");
416 if (digi1 & AC_DIG1_NONAUDIO)
417 snd_iprintf(buffer, " Non-Audio");
418 if (digi1 & AC_DIG1_PROFESSIONAL)
419 snd_iprintf(buffer, " Pro");
420 if (digi1 & AC_DIG1_LEVEL)
421 snd_iprintf(buffer, " GenLevel");
422 snd_iprintf(buffer, "\n");
Takashi Iwaia1855d82008-06-19 15:41:37 +0200423 snd_iprintf(buffer, " Digital category: 0x%x\n",
424 (digi1 >> 8) & AC_DIG2_CC);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100425}
426
427static const char *get_pwr_state(u32 state)
428{
Takashi Iwaiea734962011-01-17 11:29:34 +0100429 static const char * const buf[4] = {
Andrew Paprocki797760a2008-01-18 12:51:11 +0100430 "D0", "D1", "D2", "D3"
431 };
432 if (state < 4)
433 return buf[state];
434 return "UNKNOWN";
435}
436
437static void print_power_state(struct snd_info_buffer *buffer,
438 struct hda_codec *codec, hda_nid_t nid)
439{
Wu Fengguang83d605f2009-11-18 12:38:08 +0800440 static char *names[] = {
441 [ilog2(AC_PWRST_D0SUP)] = "D0",
442 [ilog2(AC_PWRST_D1SUP)] = "D1",
443 [ilog2(AC_PWRST_D2SUP)] = "D2",
444 [ilog2(AC_PWRST_D3SUP)] = "D3",
445 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
446 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
447 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
448 [ilog2(AC_PWRST_EPSS)] = "EPSS",
449 };
450
451 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100452 int pwr = snd_hda_codec_read(codec, nid, 0,
453 AC_VERB_GET_POWER_STATE, 0);
Wu Fengguang83d605f2009-11-18 12:38:08 +0800454 if (sup)
455 snd_iprintf(buffer, " Power states: %s\n",
456 bits_names(sup, names, ARRAY_SIZE(names)));
457
Andrew Paprocki797760a2008-01-18 12:51:11 +0100458 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n",
459 get_pwr_state(pwr & AC_PWRST_SETTING),
460 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
461 AC_PWRST_ACTUAL_SHIFT));
462}
463
464static void print_unsol_cap(struct snd_info_buffer *buffer,
465 struct hda_codec *codec, hda_nid_t nid)
466{
467 int unsol = snd_hda_codec_read(codec, nid, 0,
468 AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
469 snd_iprintf(buffer,
470 " Unsolicited: tag=%02x, enabled=%d\n",
471 unsol & AC_UNSOL_TAG,
472 (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
473}
474
475static void print_proc_caps(struct snd_info_buffer *buffer,
476 struct hda_codec *codec, hda_nid_t nid)
477{
478 unsigned int proc_caps = snd_hda_param_read(codec, nid,
479 AC_PAR_PROC_CAP);
480 snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
481 proc_caps & AC_PCAP_BENIGN,
482 (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT);
483}
484
485static void print_conn_list(struct snd_info_buffer *buffer,
486 struct hda_codec *codec, hda_nid_t nid,
487 unsigned int wid_type, hda_nid_t *conn,
488 int conn_len)
489{
490 int c, curr = -1;
491
Takashi Iwai07a1e812009-03-19 17:08:19 +0100492 if (conn_len > 1 &&
493 wid_type != AC_WID_AUD_MIX &&
494 wid_type != AC_WID_VOL_KNB &&
495 wid_type != AC_WID_POWER)
Andrew Paprocki797760a2008-01-18 12:51:11 +0100496 curr = snd_hda_codec_read(codec, nid, 0,
497 AC_VERB_GET_CONNECT_SEL, 0);
498 snd_iprintf(buffer, " Connection: %d\n", conn_len);
499 if (conn_len > 0) {
500 snd_iprintf(buffer, " ");
501 for (c = 0; c < conn_len; c++) {
502 snd_iprintf(buffer, " 0x%02x", conn[c]);
503 if (c == curr)
504 snd_iprintf(buffer, "*");
505 }
506 snd_iprintf(buffer, "\n");
507 }
508}
509
Andrew Paprocki797760a2008-01-18 12:51:11 +0100510static void print_gpio(struct snd_info_buffer *buffer,
511 struct hda_codec *codec, hda_nid_t nid)
512{
513 unsigned int gpio =
514 snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
515 unsigned int enable, direction, wake, unsol, sticky, data;
516 int i, max;
517 snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
518 "unsolicited=%d, wake=%d\n",
519 gpio & AC_GPIO_IO_COUNT,
520 (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
521 (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
522 (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
523 (gpio & AC_GPIO_WAKE) ? 1 : 0);
524 max = gpio & AC_GPIO_IO_COUNT;
Takashi Iwaic4dc5072008-11-04 13:30:57 +0100525 if (!max || max > 8)
526 return;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100527 enable = snd_hda_codec_read(codec, nid, 0,
528 AC_VERB_GET_GPIO_MASK, 0);
529 direction = snd_hda_codec_read(codec, nid, 0,
530 AC_VERB_GET_GPIO_DIRECTION, 0);
531 wake = snd_hda_codec_read(codec, nid, 0,
532 AC_VERB_GET_GPIO_WAKE_MASK, 0);
533 unsol = snd_hda_codec_read(codec, nid, 0,
534 AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
535 sticky = snd_hda_codec_read(codec, nid, 0,
536 AC_VERB_GET_GPIO_STICKY_MASK, 0);
537 data = snd_hda_codec_read(codec, nid, 0,
538 AC_VERB_GET_GPIO_DATA, 0);
539 for (i = 0; i < max; ++i)
540 snd_iprintf(buffer,
541 " IO[%d]: enable=%d, dir=%d, wake=%d, "
Takashi Iwai85639642008-11-19 14:14:50 +0100542 "sticky=%d, data=%d, unsol=%d\n", i,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100543 (enable & (1<<i)) ? 1 : 0,
544 (direction & (1<<i)) ? 1 : 0,
545 (wake & (1<<i)) ? 1 : 0,
546 (sticky & (1<<i)) ? 1 : 0,
Takashi Iwai85639642008-11-19 14:14:50 +0100547 (data & (1<<i)) ? 1 : 0,
548 (unsol & (1<<i)) ? 1 : 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100549 /* FIXME: add GPO and GPI pin information */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100550 print_nid_array(buffer, codec, nid, &codec->mixers);
551 print_nid_array(buffer, codec, nid, &codec->nids);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100552}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Takashi Iwaid01ce992007-07-27 16:52:19 +0200554static void print_codec_info(struct snd_info_entry *entry,
555 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 struct hda_codec *codec = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 hda_nid_t nid;
559 int i, nodes;
560
Takashi Iwai812a2cc2009-05-16 10:00:49 +0200561 snd_iprintf(buffer, "Codec: ");
562 if (codec->vendor_name && codec->chip_name)
563 snd_iprintf(buffer, "%s %s\n",
564 codec->vendor_name, codec->chip_name);
565 else
566 snd_iprintf(buffer, "Not Set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 snd_iprintf(buffer, "Address: %d\n", codec->addr);
Jaroslav Kysela79c944a2010-07-19 15:52:39 +0200568 if (codec->afg)
569 snd_iprintf(buffer, "AFG Function Id: 0x%x (unsol %u)\n",
570 codec->afg_function_id, codec->afg_unsol);
571 if (codec->mfg)
572 snd_iprintf(buffer, "MFG Function Id: 0x%x (unsol %u)\n",
573 codec->mfg_function_id, codec->mfg_unsol);
Pascal de Bruijn234b4342009-03-23 11:15:59 +0100574 snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
575 snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
Jonathan Phenixe25c05f2007-06-19 18:31:28 +0200577
578 if (codec->mfg)
579 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
580 else
581 snd_iprintf(buffer, "No Modem Function Group found\n");
582
Takashi Iwaiec9e1c52005-09-07 13:29:22 +0200583 if (! codec->afg)
584 return;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200585 snd_hda_power_up(codec);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100586 snd_iprintf(buffer, "Default PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 print_pcm_caps(buffer, codec, codec->afg);
588 snd_iprintf(buffer, "Default Amp-In caps: ");
589 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
590 snd_iprintf(buffer, "Default Amp-Out caps: ");
591 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
592
593 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
594 if (! nid || nodes < 0) {
595 snd_iprintf(buffer, "Invalid AFG subtree\n");
Takashi Iwaicb53c622007-08-10 17:21:45 +0200596 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 return;
598 }
Andrew Paprocki797760a2008-01-18 12:51:11 +0100599
600 print_gpio(buffer, codec, codec->afg);
Takashi Iwai2d34e1b2008-11-28 14:35:16 +0100601 if (codec->proc_widget_hook)
602 codec->proc_widget_hook(buffer, codec, codec->afg);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 for (i = 0; i < nodes; i++, nid++) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200605 unsigned int wid_caps =
606 snd_hda_param_read(codec, nid,
607 AC_PAR_AUDIO_WIDGET_CAP);
Takashi Iwaia22d5432009-07-27 12:54:26 +0200608 unsigned int wid_type = get_wcaps_type(wid_caps);
Takashi Iwai3e289f12005-06-10 19:45:09 +0200609 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Andrew Paprocki797760a2008-01-18 12:51:11 +0100610 int conn_len = 0;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
613 get_wid_type_name(wid_type), wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200614 if (wid_caps & AC_WCAP_STEREO) {
Wu Fengguangfd72d002009-08-24 09:50:46 +0800615 unsigned int chans = get_wcaps_channels(wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200616 if (chans == 2)
617 snd_iprintf(buffer, " Stereo");
618 else
619 snd_iprintf(buffer, " %d-Channels", chans);
620 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 snd_iprintf(buffer, " Mono");
622 if (wid_caps & AC_WCAP_DIGITAL)
623 snd_iprintf(buffer, " Digital");
624 if (wid_caps & AC_WCAP_IN_AMP)
625 snd_iprintf(buffer, " Amp-In");
626 if (wid_caps & AC_WCAP_OUT_AMP)
627 snd_iprintf(buffer, " Amp-Out");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100628 if (wid_caps & AC_WCAP_STRIPE)
629 snd_iprintf(buffer, " Stripe");
630 if (wid_caps & AC_WCAP_LR_SWAP)
631 snd_iprintf(buffer, " R/L");
Takashi Iwaic4920602008-07-30 15:13:29 +0200632 if (wid_caps & AC_WCAP_CP_CAPS)
633 snd_iprintf(buffer, " CP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 snd_iprintf(buffer, "\n");
635
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100636 print_nid_array(buffer, codec, nid, &codec->mixers);
637 print_nid_array(buffer, codec, nid, &codec->nids);
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100638 print_nid_pcms(buffer, codec, nid);
639
Takashi Iwaie1716132007-11-16 17:52:39 +0100640 /* volume knob is a special widget that always have connection
641 * list
642 */
643 if (wid_type == AC_WID_VOL_KNB)
644 wid_caps |= AC_WCAP_CONN_LIST;
645
Takashi Iwai3e289f12005-06-10 19:45:09 +0200646 if (wid_caps & AC_WCAP_CONN_LIST)
Takashi Iwai9e7717c2011-07-11 15:42:52 +0200647 conn_len = snd_hda_get_raw_connections(codec, nid, conn,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200648 HDA_MAX_CONNECTIONS);
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 if (wid_caps & AC_WCAP_IN_AMP) {
651 snd_iprintf(buffer, " Amp-In caps: ");
652 print_amp_caps(buffer, codec, nid, HDA_INPUT);
653 snd_iprintf(buffer, " Amp-In vals: ");
654 print_amp_vals(buffer, codec, nid, HDA_INPUT,
Takashi Iwai9e03ad72008-02-22 18:46:00 +0100655 wid_caps & AC_WCAP_STEREO,
656 wid_type == AC_WID_PIN ? 1 : conn_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
658 if (wid_caps & AC_WCAP_OUT_AMP) {
659 snd_iprintf(buffer, " Amp-Out caps: ");
660 print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
661 snd_iprintf(buffer, " Amp-Out vals: ");
Takashi Iwai9421f952009-03-12 17:06:07 +0100662 if (wid_type == AC_WID_PIN &&
663 codec->pin_amp_workaround)
664 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
665 wid_caps & AC_WCAP_STEREO,
666 conn_len);
667 else
668 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
669 wid_caps & AC_WCAP_STEREO, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671
Takashi Iwaie97a5162007-10-26 14:56:36 +0200672 switch (wid_type) {
Andrew Paprocki797760a2008-01-18 12:51:11 +0100673 case AC_WID_PIN: {
674 int supports_vref;
675 print_pin_caps(buffer, codec, nid, &supports_vref);
676 print_pin_ctls(buffer, codec, nid, supports_vref);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200677 break;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100678 }
Takashi Iwaie97a5162007-10-26 14:56:36 +0200679 case AC_WID_VOL_KNB:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100680 print_vol_knob(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200681 break;
682 case AC_WID_AUD_OUT:
683 case AC_WID_AUD_IN:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100684 print_audio_io(buffer, codec, nid, wid_type);
685 if (wid_caps & AC_WCAP_DIGITAL)
686 print_digital_conv(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200687 if (wid_caps & AC_WCAP_FORMAT_OVRD) {
688 snd_iprintf(buffer, " PCM:\n");
689 print_pcm_caps(buffer, codec, nid);
690 }
691 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 }
693
Andrew Paprocki797760a2008-01-18 12:51:11 +0100694 if (wid_caps & AC_WCAP_UNSOL_CAP)
695 print_unsol_cap(buffer, codec, nid);
Takashi Iwaib7027cc2005-11-02 18:13:41 +0100696
Andrew Paprocki797760a2008-01-18 12:51:11 +0100697 if (wid_caps & AC_WCAP_POWER)
698 print_power_state(buffer, codec, nid);
699
700 if (wid_caps & AC_WCAP_DELAY)
701 snd_iprintf(buffer, " Delay: %d samples\n",
702 (wid_caps & AC_WCAP_DELAY) >>
703 AC_WCAP_DELAY_SHIFT);
704
705 if (wid_caps & AC_WCAP_CONN_LIST)
706 print_conn_list(buffer, codec, nid, wid_type,
707 conn, conn_len);
708
709 if (wid_caps & AC_WCAP_PROC_WID)
710 print_proc_caps(buffer, codec, nid);
711
Takashi Iwaidaead532008-11-28 12:55:36 +0100712 if (codec->proc_widget_hook)
713 codec->proc_widget_hook(buffer, codec, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
Takashi Iwaicb53c622007-08-10 17:21:45 +0200715 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718/*
719 * create a proc read
720 */
721int snd_hda_codec_proc_new(struct hda_codec *codec)
722{
723 char name[32];
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100724 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 int err;
726
727 snprintf(name, sizeof(name), "codec#%d", codec->addr);
728 err = snd_card_proc_new(codec->bus->card, name, &entry);
729 if (err < 0)
730 return err;
731
Takashi Iwaibf850202006-04-28 15:13:41 +0200732 snd_info_set_text_ops(entry, codec, print_codec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 return 0;
734}
735