blob: 2e27d6a8b446ad96ce574385b87b3974b753814b [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 Kysela5b0cb1d2009-12-08 16:13:32 +010064static void print_nid_array(struct snd_info_buffer *buffer,
65 struct hda_codec *codec, hda_nid_t nid,
66 struct snd_array *array)
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010067{
68 int i;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010069 struct hda_nid_item *items = array->list, *item;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010070 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010071 for (i = 0; i < array->used; i++) {
72 item = &items[i];
73 if (item->nid == nid) {
74 kctl = item->kctl;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010075 snd_iprintf(buffer,
76 " Control: name=\"%s\", index=%i, device=%i\n",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010077 kctl->id.name, kctl->id.index + item->index,
78 kctl->id.device);
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010079 }
80 }
81}
82
83static void print_nid_pcms(struct snd_info_buffer *buffer,
84 struct hda_codec *codec, hda_nid_t nid)
85{
86 int pcm, type;
87 struct hda_pcm *cpcm;
88 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
89 cpcm = &codec->pcm_info[pcm];
90 for (type = 0; type < 2; type++) {
91 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
92 continue;
93 snd_iprintf(buffer, " Device: name=\"%s\", "
94 "type=\"%s\", device=%i\n",
95 cpcm->name,
96 snd_hda_pcm_type_name[cpcm->pcm_type],
97 cpcm->pcm->device);
98 }
99 }
100}
101
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100102static void print_amp_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 struct hda_codec *codec, hda_nid_t nid, int dir)
104{
105 unsigned int caps;
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200106 caps = snd_hda_param_read(codec, nid,
107 dir == HDA_OUTPUT ?
108 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (caps == -1 || caps == 0) {
110 snd_iprintf(buffer, "N/A\n");
111 return;
112 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200113 snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
114 "mute=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 caps & AC_AMPCAP_OFFSET,
116 (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
117 (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
118 (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
119}
120
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100121static void print_amp_vals(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200123 int dir, int stereo, int indices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
125 unsigned int val;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200126 int i;
127
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200128 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200129 for (i = 0; i < indices; i++) {
130 snd_iprintf(buffer, " [");
131 if (stereo) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200132 val = snd_hda_codec_read(codec, nid, 0,
133 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200134 AC_AMP_GET_LEFT | dir | i);
135 snd_iprintf(buffer, "0x%02x ", val);
136 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200137 val = snd_hda_codec_read(codec, nid, 0,
138 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200139 AC_AMP_GET_RIGHT | dir | i);
140 snd_iprintf(buffer, "0x%02x]", val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
Takashi Iwai3e289f12005-06-10 19:45:09 +0200142 snd_iprintf(buffer, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
Wu Fengguang33deeca2008-11-18 11:47:51 +0800145static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
146{
147 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
Wu Fengguangd39b4352008-11-19 15:14:02 +0800148
Takashi Iwaib90d7762006-11-07 16:10:06 +0100149 pcm &= AC_SUPPCM_RATES;
150 snd_iprintf(buffer, " rates [0x%x]:", pcm);
Wu Fengguang33deeca2008-11-18 11:47:51 +0800151 snd_print_pcm_rates(pcm, buf, sizeof(buf));
152 snd_iprintf(buffer, "%s\n", buf);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100153}
154
Wu Fengguangd39b4352008-11-19 15:14:02 +0800155static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
156{
157 char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
Takashi Iwaib90d7762006-11-07 16:10:06 +0100158
Takashi Iwaib0e64812008-11-25 16:07:01 +0100159 snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
Wu Fengguangd39b4352008-11-19 15:14:02 +0800160 snd_print_pcm_bits(pcm, buf, sizeof(buf));
161 snd_iprintf(buffer, "%s\n", buf);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100162}
163
164static void print_pcm_formats(struct snd_info_buffer *buffer,
165 unsigned int streams)
166{
167 snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
168 if (streams & AC_SUPFMT_PCM)
169 snd_iprintf(buffer, " PCM");
170 if (streams & AC_SUPFMT_FLOAT32)
171 snd_iprintf(buffer, " FLOAT");
172 if (streams & AC_SUPFMT_AC3)
173 snd_iprintf(buffer, " AC3");
174 snd_iprintf(buffer, "\n");
175}
176
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100177static void print_pcm_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 struct hda_codec *codec, hda_nid_t nid)
179{
180 unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
181 unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
182 if (pcm == -1 || stream == -1) {
183 snd_iprintf(buffer, "N/A\n");
184 return;
185 }
Takashi Iwaib90d7762006-11-07 16:10:06 +0100186 print_pcm_rates(buffer, pcm);
187 print_pcm_bits(buffer, pcm);
188 print_pcm_formats(buffer, stream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static const char *get_jack_connection(u32 cfg)
192{
193 static char *names[16] = {
194 "Unknown", "1/8", "1/4", "ATAPI",
195 "RCA", "Optical","Digital", "Analog",
196 "DIN", "XLR", "RJ11", "Comb",
197 NULL, NULL, NULL, "Other"
198 };
199 cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
200 if (names[cfg])
201 return names[cfg];
202 else
203 return "UNKNOWN";
204}
205
206static const char *get_jack_color(u32 cfg)
207{
208 static char *names[16] = {
209 "Unknown", "Black", "Grey", "Blue",
210 "Green", "Red", "Orange", "Yellow",
211 "Purple", "Pink", NULL, NULL,
212 NULL, NULL, "White", "Other",
213 };
214 cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
215 if (names[cfg])
216 return names[cfg];
217 else
218 return "UNKNOWN";
219}
220
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100221static void print_pin_caps(struct snd_info_buffer *buffer,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100222 struct hda_codec *codec, hda_nid_t nid,
223 int *supports_vref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200225 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
Takashi Iwaie97a5162007-10-26 14:56:36 +0200226 unsigned int caps, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
Robin H. Johnson0481f452008-09-13 16:54:57 -0700229 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (caps & AC_PINCAP_IN)
231 snd_iprintf(buffer, " IN");
232 if (caps & AC_PINCAP_OUT)
233 snd_iprintf(buffer, " OUT");
234 if (caps & AC_PINCAP_HP_DRV)
235 snd_iprintf(buffer, " HP");
Takashi Iwai58854922006-06-21 19:19:25 +0200236 if (caps & AC_PINCAP_EAPD)
237 snd_iprintf(buffer, " EAPD");
238 if (caps & AC_PINCAP_PRES_DETECT)
239 snd_iprintf(buffer, " Detect");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100240 if (caps & AC_PINCAP_BALANCE)
241 snd_iprintf(buffer, " Balanced");
Takashi Iwaic4920602008-07-30 15:13:29 +0200242 if (caps & AC_PINCAP_HDMI) {
243 /* Realtek uses this bit as a different meaning */
244 if ((codec->vendor_id >> 16) == 0x10ec)
245 snd_iprintf(buffer, " R/L");
Wu Fengguangb9235282009-12-11 12:28:33 +0800246 else {
247 if (caps & AC_PINCAP_HBR)
248 snd_iprintf(buffer, " HBR");
Takashi Iwaic4920602008-07-30 15:13:29 +0200249 snd_iprintf(buffer, " HDMI");
Wu Fengguangb9235282009-12-11 12:28:33 +0800250 }
Takashi Iwaic4920602008-07-30 15:13:29 +0200251 }
Wu Fengguang728765b2009-12-11 12:28:34 +0800252 if (caps & AC_PINCAP_DP)
253 snd_iprintf(buffer, " DP");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100254 if (caps & AC_PINCAP_TRIG_REQ)
255 snd_iprintf(buffer, " Trigger");
256 if (caps & AC_PINCAP_IMP_SENSE)
257 snd_iprintf(buffer, " ImpSense");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 snd_iprintf(buffer, "\n");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100259 if (caps & AC_PINCAP_VREF) {
260 unsigned int vref =
261 (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
262 snd_iprintf(buffer, " Vref caps:");
263 if (vref & AC_PINCAP_VREF_HIZ)
264 snd_iprintf(buffer, " HIZ");
265 if (vref & AC_PINCAP_VREF_50)
266 snd_iprintf(buffer, " 50");
267 if (vref & AC_PINCAP_VREF_GRD)
268 snd_iprintf(buffer, " GRD");
269 if (vref & AC_PINCAP_VREF_80)
270 snd_iprintf(buffer, " 80");
271 if (vref & AC_PINCAP_VREF_100)
272 snd_iprintf(buffer, " 100");
273 snd_iprintf(buffer, "\n");
274 *supports_vref = 1;
275 } else
276 *supports_vref = 0;
277 if (caps & AC_PINCAP_EAPD) {
278 val = snd_hda_codec_read(codec, nid, 0,
279 AC_VERB_GET_EAPD_BTLENABLE, 0);
280 snd_iprintf(buffer, " EAPD 0x%x:", val);
281 if (val & AC_EAPDBTL_BALANCED)
282 snd_iprintf(buffer, " BALANCED");
283 if (val & AC_EAPDBTL_EAPD)
284 snd_iprintf(buffer, " EAPD");
285 if (val & AC_EAPDBTL_LR_SWAP)
286 snd_iprintf(buffer, " R/L");
287 snd_iprintf(buffer, "\n");
288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200290 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
291 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
Matthew Ranostay50a9f792008-10-25 01:05:45 -0400292 snd_hda_get_jack_type(caps),
293 snd_hda_get_jack_connectivity(caps),
294 snd_hda_get_jack_location(caps));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
296 get_jack_connection(caps),
297 get_jack_color(caps));
Andrew Paprocki797760a2008-01-18 12:51:11 +0100298 /* Default association and sequence values refer to default grouping
299 * of pin complexes and their sequence within the group. This is used
300 * for priority and resource allocation.
301 */
302 snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
303 (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
304 caps & AC_DEFCFG_SEQUENCE);
305 if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
306 AC_DEFCFG_MISC_NO_PRESENCE) {
307 /* Miscellaneous bit indicates external hardware does not
308 * support presence detection even if the pin complex
309 * indicates it is supported.
310 */
311 snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
Takashi Iwaie97a5162007-10-26 14:56:36 +0200312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
Andrew Paprocki797760a2008-01-18 12:51:11 +0100315static void print_pin_ctls(struct snd_info_buffer *buffer,
316 struct hda_codec *codec, hda_nid_t nid,
317 int supports_vref)
318{
319 unsigned int pinctls;
320
321 pinctls = snd_hda_codec_read(codec, nid, 0,
322 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
323 snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
324 if (pinctls & AC_PINCTL_IN_EN)
325 snd_iprintf(buffer, " IN");
326 if (pinctls & AC_PINCTL_OUT_EN)
327 snd_iprintf(buffer, " OUT");
328 if (pinctls & AC_PINCTL_HP_EN)
329 snd_iprintf(buffer, " HP");
330 if (supports_vref) {
331 int vref = pinctls & AC_PINCTL_VREFEN;
332 switch (vref) {
333 case AC_PINCTL_VREF_HIZ:
334 snd_iprintf(buffer, " VREF_HIZ");
335 break;
336 case AC_PINCTL_VREF_50:
337 snd_iprintf(buffer, " VREF_50");
338 break;
339 case AC_PINCTL_VREF_GRD:
340 snd_iprintf(buffer, " VREF_GRD");
341 break;
342 case AC_PINCTL_VREF_80:
343 snd_iprintf(buffer, " VREF_80");
344 break;
345 case AC_PINCTL_VREF_100:
346 snd_iprintf(buffer, " VREF_100");
347 break;
348 }
349 }
350 snd_iprintf(buffer, "\n");
351}
352
353static void print_vol_knob(struct snd_info_buffer *buffer,
354 struct hda_codec *codec, hda_nid_t nid)
355{
356 unsigned int cap = snd_hda_param_read(codec, nid,
357 AC_PAR_VOL_KNB_CAP);
358 snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
359 (cap >> 7) & 1, cap & 0x7f);
360 cap = snd_hda_codec_read(codec, nid, 0,
361 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
362 snd_iprintf(buffer, "direct=%d, val=%d\n",
363 (cap >> 7) & 1, cap & 0x7f);
364}
365
366static void print_audio_io(struct snd_info_buffer *buffer,
367 struct hda_codec *codec, hda_nid_t nid,
368 unsigned int wid_type)
369{
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100370 int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100371 snd_iprintf(buffer,
372 " Converter: stream=%d, channel=%d\n",
373 (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
374 conv & AC_CONV_CHANNEL);
375
376 if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
377 int sdi = snd_hda_codec_read(codec, nid, 0,
378 AC_VERB_GET_SDI_SELECT, 0);
379 snd_iprintf(buffer, " SDI-Select: %d\n",
380 sdi & AC_SDI_SELECT);
381 }
382}
383
384static void print_digital_conv(struct snd_info_buffer *buffer,
385 struct hda_codec *codec, hda_nid_t nid)
386{
387 unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
388 AC_VERB_GET_DIGI_CONVERT_1, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100389 snd_iprintf(buffer, " Digital:");
390 if (digi1 & AC_DIG1_ENABLE)
391 snd_iprintf(buffer, " Enabled");
392 if (digi1 & AC_DIG1_V)
393 snd_iprintf(buffer, " Validity");
394 if (digi1 & AC_DIG1_VCFG)
395 snd_iprintf(buffer, " ValidityCfg");
396 if (digi1 & AC_DIG1_EMPHASIS)
397 snd_iprintf(buffer, " Preemphasis");
398 if (digi1 & AC_DIG1_COPYRIGHT)
399 snd_iprintf(buffer, " Copyright");
400 if (digi1 & AC_DIG1_NONAUDIO)
401 snd_iprintf(buffer, " Non-Audio");
402 if (digi1 & AC_DIG1_PROFESSIONAL)
403 snd_iprintf(buffer, " Pro");
404 if (digi1 & AC_DIG1_LEVEL)
405 snd_iprintf(buffer, " GenLevel");
406 snd_iprintf(buffer, "\n");
Takashi Iwaia1855d82008-06-19 15:41:37 +0200407 snd_iprintf(buffer, " Digital category: 0x%x\n",
408 (digi1 >> 8) & AC_DIG2_CC);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100409}
410
411static const char *get_pwr_state(u32 state)
412{
413 static const char *buf[4] = {
414 "D0", "D1", "D2", "D3"
415 };
416 if (state < 4)
417 return buf[state];
418 return "UNKNOWN";
419}
420
421static void print_power_state(struct snd_info_buffer *buffer,
422 struct hda_codec *codec, hda_nid_t nid)
423{
Wu Fengguang83d605f2009-11-18 12:38:08 +0800424 static char *names[] = {
425 [ilog2(AC_PWRST_D0SUP)] = "D0",
426 [ilog2(AC_PWRST_D1SUP)] = "D1",
427 [ilog2(AC_PWRST_D2SUP)] = "D2",
428 [ilog2(AC_PWRST_D3SUP)] = "D3",
429 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
430 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
431 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
432 [ilog2(AC_PWRST_EPSS)] = "EPSS",
433 };
434
435 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100436 int pwr = snd_hda_codec_read(codec, nid, 0,
437 AC_VERB_GET_POWER_STATE, 0);
Wu Fengguang83d605f2009-11-18 12:38:08 +0800438 if (sup)
439 snd_iprintf(buffer, " Power states: %s\n",
440 bits_names(sup, names, ARRAY_SIZE(names)));
441
Andrew Paprocki797760a2008-01-18 12:51:11 +0100442 snd_iprintf(buffer, " Power: setting=%s, actual=%s\n",
443 get_pwr_state(pwr & AC_PWRST_SETTING),
444 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
445 AC_PWRST_ACTUAL_SHIFT));
446}
447
448static void print_unsol_cap(struct snd_info_buffer *buffer,
449 struct hda_codec *codec, hda_nid_t nid)
450{
451 int unsol = snd_hda_codec_read(codec, nid, 0,
452 AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
453 snd_iprintf(buffer,
454 " Unsolicited: tag=%02x, enabled=%d\n",
455 unsol & AC_UNSOL_TAG,
456 (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
457}
458
459static void print_proc_caps(struct snd_info_buffer *buffer,
460 struct hda_codec *codec, hda_nid_t nid)
461{
462 unsigned int proc_caps = snd_hda_param_read(codec, nid,
463 AC_PAR_PROC_CAP);
464 snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
465 proc_caps & AC_PCAP_BENIGN,
466 (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT);
467}
468
469static void print_conn_list(struct snd_info_buffer *buffer,
470 struct hda_codec *codec, hda_nid_t nid,
471 unsigned int wid_type, hda_nid_t *conn,
472 int conn_len)
473{
474 int c, curr = -1;
475
Takashi Iwai07a1e812009-03-19 17:08:19 +0100476 if (conn_len > 1 &&
477 wid_type != AC_WID_AUD_MIX &&
478 wid_type != AC_WID_VOL_KNB &&
479 wid_type != AC_WID_POWER)
Andrew Paprocki797760a2008-01-18 12:51:11 +0100480 curr = snd_hda_codec_read(codec, nid, 0,
481 AC_VERB_GET_CONNECT_SEL, 0);
482 snd_iprintf(buffer, " Connection: %d\n", conn_len);
483 if (conn_len > 0) {
484 snd_iprintf(buffer, " ");
485 for (c = 0; c < conn_len; c++) {
486 snd_iprintf(buffer, " 0x%02x", conn[c]);
487 if (c == curr)
488 snd_iprintf(buffer, "*");
489 }
490 snd_iprintf(buffer, "\n");
491 }
492}
493
Andrew Paprocki797760a2008-01-18 12:51:11 +0100494static void print_gpio(struct snd_info_buffer *buffer,
495 struct hda_codec *codec, hda_nid_t nid)
496{
497 unsigned int gpio =
498 snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
499 unsigned int enable, direction, wake, unsol, sticky, data;
500 int i, max;
501 snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
502 "unsolicited=%d, wake=%d\n",
503 gpio & AC_GPIO_IO_COUNT,
504 (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
505 (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
506 (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
507 (gpio & AC_GPIO_WAKE) ? 1 : 0);
508 max = gpio & AC_GPIO_IO_COUNT;
Takashi Iwaic4dc5072008-11-04 13:30:57 +0100509 if (!max || max > 8)
510 return;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100511 enable = snd_hda_codec_read(codec, nid, 0,
512 AC_VERB_GET_GPIO_MASK, 0);
513 direction = snd_hda_codec_read(codec, nid, 0,
514 AC_VERB_GET_GPIO_DIRECTION, 0);
515 wake = snd_hda_codec_read(codec, nid, 0,
516 AC_VERB_GET_GPIO_WAKE_MASK, 0);
517 unsol = snd_hda_codec_read(codec, nid, 0,
518 AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
519 sticky = snd_hda_codec_read(codec, nid, 0,
520 AC_VERB_GET_GPIO_STICKY_MASK, 0);
521 data = snd_hda_codec_read(codec, nid, 0,
522 AC_VERB_GET_GPIO_DATA, 0);
523 for (i = 0; i < max; ++i)
524 snd_iprintf(buffer,
525 " IO[%d]: enable=%d, dir=%d, wake=%d, "
Takashi Iwai85639642008-11-19 14:14:50 +0100526 "sticky=%d, data=%d, unsol=%d\n", i,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100527 (enable & (1<<i)) ? 1 : 0,
528 (direction & (1<<i)) ? 1 : 0,
529 (wake & (1<<i)) ? 1 : 0,
530 (sticky & (1<<i)) ? 1 : 0,
Takashi Iwai85639642008-11-19 14:14:50 +0100531 (data & (1<<i)) ? 1 : 0,
532 (unsol & (1<<i)) ? 1 : 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100533 /* FIXME: add GPO and GPI pin information */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100534 print_nid_array(buffer, codec, nid, &codec->mixers);
535 print_nid_array(buffer, codec, nid, &codec->nids);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100536}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Takashi Iwaid01ce992007-07-27 16:52:19 +0200538static void print_codec_info(struct snd_info_entry *entry,
539 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540{
541 struct hda_codec *codec = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 hda_nid_t nid;
543 int i, nodes;
544
Takashi Iwai812a2cc2009-05-16 10:00:49 +0200545 snd_iprintf(buffer, "Codec: ");
546 if (codec->vendor_name && codec->chip_name)
547 snd_iprintf(buffer, "%s %s\n",
548 codec->vendor_name, codec->chip_name);
549 else
550 snd_iprintf(buffer, "Not Set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 snd_iprintf(buffer, "Address: %d\n", codec->addr);
Pascal de Bruijn234b4342009-03-23 11:15:59 +0100552 snd_iprintf(buffer, "Function Id: 0x%x\n", codec->function_id);
553 snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
554 snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
Jonathan Phenixe25c05f2007-06-19 18:31:28 +0200556
557 if (codec->mfg)
558 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
559 else
560 snd_iprintf(buffer, "No Modem Function Group found\n");
561
Takashi Iwaiec9e1c52005-09-07 13:29:22 +0200562 if (! codec->afg)
563 return;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200564 snd_hda_power_up(codec);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100565 snd_iprintf(buffer, "Default PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 print_pcm_caps(buffer, codec, codec->afg);
567 snd_iprintf(buffer, "Default Amp-In caps: ");
568 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
569 snd_iprintf(buffer, "Default Amp-Out caps: ");
570 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
571
572 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
573 if (! nid || nodes < 0) {
574 snd_iprintf(buffer, "Invalid AFG subtree\n");
Takashi Iwaicb53c622007-08-10 17:21:45 +0200575 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 return;
577 }
Andrew Paprocki797760a2008-01-18 12:51:11 +0100578
579 print_gpio(buffer, codec, codec->afg);
Takashi Iwai2d34e1b2008-11-28 14:35:16 +0100580 if (codec->proc_widget_hook)
581 codec->proc_widget_hook(buffer, codec, codec->afg);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 for (i = 0; i < nodes; i++, nid++) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200584 unsigned int wid_caps =
585 snd_hda_param_read(codec, nid,
586 AC_PAR_AUDIO_WIDGET_CAP);
Takashi Iwaia22d5432009-07-27 12:54:26 +0200587 unsigned int wid_type = get_wcaps_type(wid_caps);
Takashi Iwai3e289f12005-06-10 19:45:09 +0200588 hda_nid_t conn[HDA_MAX_CONNECTIONS];
Andrew Paprocki797760a2008-01-18 12:51:11 +0100589 int conn_len = 0;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
592 get_wid_type_name(wid_type), wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200593 if (wid_caps & AC_WCAP_STEREO) {
Wu Fengguangfd72d002009-08-24 09:50:46 +0800594 unsigned int chans = get_wcaps_channels(wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200595 if (chans == 2)
596 snd_iprintf(buffer, " Stereo");
597 else
598 snd_iprintf(buffer, " %d-Channels", chans);
599 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 snd_iprintf(buffer, " Mono");
601 if (wid_caps & AC_WCAP_DIGITAL)
602 snd_iprintf(buffer, " Digital");
603 if (wid_caps & AC_WCAP_IN_AMP)
604 snd_iprintf(buffer, " Amp-In");
605 if (wid_caps & AC_WCAP_OUT_AMP)
606 snd_iprintf(buffer, " Amp-Out");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100607 if (wid_caps & AC_WCAP_STRIPE)
608 snd_iprintf(buffer, " Stripe");
609 if (wid_caps & AC_WCAP_LR_SWAP)
610 snd_iprintf(buffer, " R/L");
Takashi Iwaic4920602008-07-30 15:13:29 +0200611 if (wid_caps & AC_WCAP_CP_CAPS)
612 snd_iprintf(buffer, " CP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 snd_iprintf(buffer, "\n");
614
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100615 print_nid_array(buffer, codec, nid, &codec->mixers);
616 print_nid_array(buffer, codec, nid, &codec->nids);
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100617 print_nid_pcms(buffer, codec, nid);
618
Takashi Iwaie1716132007-11-16 17:52:39 +0100619 /* volume knob is a special widget that always have connection
620 * list
621 */
622 if (wid_type == AC_WID_VOL_KNB)
623 wid_caps |= AC_WCAP_CONN_LIST;
624
Takashi Iwai3e289f12005-06-10 19:45:09 +0200625 if (wid_caps & AC_WCAP_CONN_LIST)
626 conn_len = snd_hda_get_connections(codec, nid, conn,
627 HDA_MAX_CONNECTIONS);
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 if (wid_caps & AC_WCAP_IN_AMP) {
630 snd_iprintf(buffer, " Amp-In caps: ");
631 print_amp_caps(buffer, codec, nid, HDA_INPUT);
632 snd_iprintf(buffer, " Amp-In vals: ");
633 print_amp_vals(buffer, codec, nid, HDA_INPUT,
Takashi Iwai9e03ad72008-02-22 18:46:00 +0100634 wid_caps & AC_WCAP_STEREO,
635 wid_type == AC_WID_PIN ? 1 : conn_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637 if (wid_caps & AC_WCAP_OUT_AMP) {
638 snd_iprintf(buffer, " Amp-Out caps: ");
639 print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
640 snd_iprintf(buffer, " Amp-Out vals: ");
Takashi Iwai9421f952009-03-12 17:06:07 +0100641 if (wid_type == AC_WID_PIN &&
642 codec->pin_amp_workaround)
643 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
644 wid_caps & AC_WCAP_STEREO,
645 conn_len);
646 else
647 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
648 wid_caps & AC_WCAP_STEREO, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650
Takashi Iwaie97a5162007-10-26 14:56:36 +0200651 switch (wid_type) {
Andrew Paprocki797760a2008-01-18 12:51:11 +0100652 case AC_WID_PIN: {
653 int supports_vref;
654 print_pin_caps(buffer, codec, nid, &supports_vref);
655 print_pin_ctls(buffer, codec, nid, supports_vref);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200656 break;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100657 }
Takashi Iwaie97a5162007-10-26 14:56:36 +0200658 case AC_WID_VOL_KNB:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100659 print_vol_knob(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200660 break;
661 case AC_WID_AUD_OUT:
662 case AC_WID_AUD_IN:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100663 print_audio_io(buffer, codec, nid, wid_type);
664 if (wid_caps & AC_WCAP_DIGITAL)
665 print_digital_conv(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200666 if (wid_caps & AC_WCAP_FORMAT_OVRD) {
667 snd_iprintf(buffer, " PCM:\n");
668 print_pcm_caps(buffer, codec, nid);
669 }
670 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
Andrew Paprocki797760a2008-01-18 12:51:11 +0100673 if (wid_caps & AC_WCAP_UNSOL_CAP)
674 print_unsol_cap(buffer, codec, nid);
Takashi Iwaib7027cc2005-11-02 18:13:41 +0100675
Andrew Paprocki797760a2008-01-18 12:51:11 +0100676 if (wid_caps & AC_WCAP_POWER)
677 print_power_state(buffer, codec, nid);
678
679 if (wid_caps & AC_WCAP_DELAY)
680 snd_iprintf(buffer, " Delay: %d samples\n",
681 (wid_caps & AC_WCAP_DELAY) >>
682 AC_WCAP_DELAY_SHIFT);
683
684 if (wid_caps & AC_WCAP_CONN_LIST)
685 print_conn_list(buffer, codec, nid, wid_type,
686 conn, conn_len);
687
688 if (wid_caps & AC_WCAP_PROC_WID)
689 print_proc_caps(buffer, codec, nid);
690
Takashi Iwaidaead532008-11-28 12:55:36 +0100691 if (codec->proc_widget_hook)
692 codec->proc_widget_hook(buffer, codec, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 }
Takashi Iwaicb53c622007-08-10 17:21:45 +0200694 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695}
696
697/*
698 * create a proc read
699 */
700int snd_hda_codec_proc_new(struct hda_codec *codec)
701{
702 char name[32];
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100703 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 int err;
705
706 snprintf(name, sizeof(name), "codec#%d", codec->addr);
707 err = snd_card_proc_new(codec->bus->card, name, &entry);
708 if (err < 0)
709 return err;
710
Takashi Iwaibf850202006-04-28 15:13:41 +0200711 snd_info_set_text_ops(entry, codec, print_codec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 return 0;
713}
714