ALSA: hda - Make some helper functions local
[deliverable/linux.git] / sound / pci / hda / hda_proc.c
CommitLineData
1da177e4
LT
1/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * Generic proc interface
5 *
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
7 *
8 *
9 * This driver is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
1da177e4 24#include <linux/init.h>
4eea3091 25#include <linux/slab.h>
1da177e4 26#include <sound/core.h>
cd262518 27#include <linux/module.h>
1da177e4 28#include "hda_codec.h"
18612048 29#include "hda_local.h"
1da177e4 30
cd262518
DH
31static int dump_coef = -1;
32module_param(dump_coef, int, 0644);
33MODULE_PARM_DESC(dump_coef, "Dump processing coefficients in codec proc file (-1=auto, 0=disable, 1=enable)");
34
9ba17b4d
TI
35/* always use noncached version */
36#define param_read(codec, nid, parm) \
37 snd_hdac_read_parm_uncached(&(codec)->core, nid, parm)
38
83d605fd
WF
39static char *bits_names(unsigned int bits, char *names[], int size)
40{
41 int i, n;
42 static char buf[128];
43
44 for (i = 0, n = 0; i < size; i++) {
45 if (bits & (1U<<i) && names[i])
46 n += snprintf(buf + n, sizeof(buf) - n, " %s",
47 names[i]);
48 }
49 buf[n] = '\0';
50
51 return buf;
52}
53
1da177e4
LT
54static const char *get_wid_type_name(unsigned int wid_value)
55{
56 static char *names[16] = {
57 [AC_WID_AUD_OUT] = "Audio Output",
58 [AC_WID_AUD_IN] = "Audio Input",
59 [AC_WID_AUD_MIX] = "Audio Mixer",
60 [AC_WID_AUD_SEL] = "Audio Selector",
61 [AC_WID_PIN] = "Pin Complex",
62 [AC_WID_POWER] = "Power Widget",
63 [AC_WID_VOL_KNB] = "Volume Knob Widget",
64 [AC_WID_BEEP] = "Beep Generator Widget",
65 [AC_WID_VENDOR] = "Vendor Defined Widget",
66 };
3a90274d
TI
67 if (wid_value == -1)
68 return "UNKNOWN Widget";
1da177e4
LT
69 wid_value &= 0xf;
70 if (names[wid_value])
71 return names[wid_value];
72 else
3bc89529 73 return "UNKNOWN Widget";
1da177e4
LT
74}
75
5b0cb1d8
JK
76static void print_nid_array(struct snd_info_buffer *buffer,
77 struct hda_codec *codec, hda_nid_t nid,
78 struct snd_array *array)
3911a4c1
JK
79{
80 int i;
5b0cb1d8 81 struct hda_nid_item *items = array->list, *item;
3911a4c1 82 struct snd_kcontrol *kctl;
5b0cb1d8
JK
83 for (i = 0; i < array->used; i++) {
84 item = &items[i];
85 if (item->nid == nid) {
86 kctl = item->kctl;
3911a4c1
JK
87 snd_iprintf(buffer,
88 " Control: name=\"%s\", index=%i, device=%i\n",
5b0cb1d8
JK
89 kctl->id.name, kctl->id.index + item->index,
90 kctl->id.device);
9e3fd871
JK
91 if (item->flags & HDA_NID_ITEM_AMP)
92 snd_iprintf(buffer,
93 " ControlAmp: chs=%lu, dir=%s, "
94 "idx=%lu, ofs=%lu\n",
95 get_amp_channels(kctl),
96 get_amp_direction(kctl) ? "Out" : "In",
97 get_amp_index(kctl),
98 get_amp_offset(kctl));
3911a4c1
JK
99 }
100 }
101}
102
103static void print_nid_pcms(struct snd_info_buffer *buffer,
104 struct hda_codec *codec, hda_nid_t nid)
105{
bbbc7e85 106 int type;
3911a4c1 107 struct hda_pcm *cpcm;
bbbc7e85
TI
108
109 list_for_each_entry(cpcm, &codec->pcm_list_head, list) {
3911a4c1
JK
110 for (type = 0; type < 2; type++) {
111 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
112 continue;
113 snd_iprintf(buffer, " Device: name=\"%s\", "
114 "type=\"%s\", device=%i\n",
115 cpcm->name,
116 snd_hda_pcm_type_name[cpcm->pcm_type],
117 cpcm->pcm->device);
118 }
119 }
120}
121
c8b6bf9b 122static void print_amp_caps(struct snd_info_buffer *buffer,
1da177e4
LT
123 struct hda_codec *codec, hda_nid_t nid, int dir)
124{
125 unsigned int caps;
9ba17b4d
TI
126 caps = param_read(codec, nid, dir == HDA_OUTPUT ?
127 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
1da177e4
LT
128 if (caps == -1 || caps == 0) {
129 snd_iprintf(buffer, "N/A\n");
130 return;
131 }
d01ce99f
TI
132 snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
133 "mute=%x\n",
1da177e4
LT
134 caps & AC_AMPCAP_OFFSET,
135 (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
136 (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
137 (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
138}
139
cc261738
TI
140/* is this a stereo widget or a stereo-to-mono mix? */
141static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid,
142 int dir, unsigned int wcaps, int indices)
143{
144 hda_nid_t conn;
145
146 if (wcaps & AC_WCAP_STEREO)
147 return true;
148 /* check for a stereo-to-mono mix; it must be:
149 * only a single connection, only for input, and only a mixer widget
150 */
151 if (indices != 1 || dir != HDA_INPUT ||
152 get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
153 return false;
154
155 if (snd_hda_get_raw_connections(codec, nid, &conn, 1) < 0)
156 return false;
157 /* the connection source is a stereo? */
158 wcaps = snd_hda_param_read(codec, conn, AC_PAR_AUDIO_WIDGET_CAP);
159 return !!(wcaps & AC_WCAP_STEREO);
160}
161
c8b6bf9b 162static void print_amp_vals(struct snd_info_buffer *buffer,
1da177e4 163 struct hda_codec *codec, hda_nid_t nid,
cc261738 164 int dir, unsigned int wcaps, int indices)
1da177e4
LT
165{
166 unsigned int val;
cc261738 167 bool stereo;
3e289f16
TI
168 int i;
169
cc261738
TI
170 stereo = is_stereo_amps(codec, nid, dir, wcaps, indices);
171
7f0e2f8b 172 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
3e289f16
TI
173 for (i = 0; i < indices; i++) {
174 snd_iprintf(buffer, " [");
2f179721
TI
175 val = snd_hda_codec_read(codec, nid, 0,
176 AC_VERB_GET_AMP_GAIN_MUTE,
177 AC_AMP_GET_LEFT | dir | i);
178 snd_iprintf(buffer, "0x%02x", val);
3e289f16 179 if (stereo) {
d01ce99f
TI
180 val = snd_hda_codec_read(codec, nid, 0,
181 AC_VERB_GET_AMP_GAIN_MUTE,
2f179721
TI
182 AC_AMP_GET_RIGHT | dir | i);
183 snd_iprintf(buffer, " 0x%02x", val);
3e289f16 184 }
2f179721 185 snd_iprintf(buffer, "]");
1da177e4 186 }
3e289f16 187 snd_iprintf(buffer, "\n");
1da177e4
LT
188}
189
33deeca3
WF
190static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
191{
f71ff0d7
TI
192 static unsigned int rates[] = {
193 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
194 96000, 176400, 192000, 384000
195 };
196 int i;
d39b4352 197
b90d7760
TI
198 pcm &= AC_SUPPCM_RATES;
199 snd_iprintf(buffer, " rates [0x%x]:", pcm);
f71ff0d7
TI
200 for (i = 0; i < ARRAY_SIZE(rates); i++)
201 if (pcm & (1 << i))
202 snd_iprintf(buffer, " %d", rates[i]);
203 snd_iprintf(buffer, "\n");
b90d7760
TI
204}
205
d39b4352
WF
206static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
207{
208 char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
b90d7760 209
b0e6481a 210 snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
d39b4352
WF
211 snd_print_pcm_bits(pcm, buf, sizeof(buf));
212 snd_iprintf(buffer, "%s\n", buf);
b90d7760
TI
213}
214
215static void print_pcm_formats(struct snd_info_buffer *buffer,
216 unsigned int streams)
217{
218 snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
219 if (streams & AC_SUPFMT_PCM)
220 snd_iprintf(buffer, " PCM");
221 if (streams & AC_SUPFMT_FLOAT32)
222 snd_iprintf(buffer, " FLOAT");
223 if (streams & AC_SUPFMT_AC3)
224 snd_iprintf(buffer, " AC3");
225 snd_iprintf(buffer, "\n");
226}
227
c8b6bf9b 228static void print_pcm_caps(struct snd_info_buffer *buffer,
1da177e4
LT
229 struct hda_codec *codec, hda_nid_t nid)
230{
9ba17b4d
TI
231 unsigned int pcm = param_read(codec, nid, AC_PAR_PCM);
232 unsigned int stream = param_read(codec, nid, AC_PAR_STREAM);
1da177e4
LT
233 if (pcm == -1 || stream == -1) {
234 snd_iprintf(buffer, "N/A\n");
235 return;
236 }
b90d7760
TI
237 print_pcm_rates(buffer, pcm);
238 print_pcm_bits(buffer, pcm);
239 print_pcm_formats(buffer, stream);
1da177e4
LT
240}
241
1da177e4
LT
242static const char *get_jack_connection(u32 cfg)
243{
244 static char *names[16] = {
245 "Unknown", "1/8", "1/4", "ATAPI",
246 "RCA", "Optical","Digital", "Analog",
247 "DIN", "XLR", "RJ11", "Comb",
248 NULL, NULL, NULL, "Other"
249 };
250 cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
251 if (names[cfg])
252 return names[cfg];
253 else
254 return "UNKNOWN";
255}
256
257static const char *get_jack_color(u32 cfg)
258{
259 static char *names[16] = {
260 "Unknown", "Black", "Grey", "Blue",
261 "Green", "Red", "Orange", "Yellow",
262 "Purple", "Pink", NULL, NULL,
263 NULL, NULL, "White", "Other",
264 };
265 cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
266 if (names[cfg])
267 return names[cfg];
268 else
269 return "UNKNOWN";
270}
271
d2c6b63d
TI
272/*
273 * Parse the pin default config value and returns the string of the
274 * jack location, e.g. "Rear", "Front", etc.
275 */
276static const char *get_jack_location(u32 cfg)
277{
278 static char *bases[7] = {
279 "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
280 };
281 static unsigned char specials_idx[] = {
282 0x07, 0x08,
283 0x17, 0x18, 0x19,
284 0x37, 0x38
285 };
286 static char *specials[] = {
287 "Rear Panel", "Drive Bar",
288 "Riser", "HDMI", "ATAPI",
289 "Mobile-In", "Mobile-Out"
290 };
291 int i;
292
293 cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
294 if ((cfg & 0x0f) < 7)
295 return bases[cfg & 0x0f];
296 for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
297 if (cfg == specials_idx[i])
298 return specials[i];
299 }
300 return "UNKNOWN";
301}
302
303/*
304 * Parse the pin default config value and returns the string of the
305 * jack connectivity, i.e. external or internal connection.
306 */
307static const char *get_jack_connectivity(u32 cfg)
308{
309 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
310
311 return jack_locations[(cfg >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3];
312}
313
314/*
315 * Parse the pin default config value and returns the string of the
316 * jack type, i.e. the purpose of the jack, such as Line-Out or CD.
317 */
318static const char *get_jack_type(u32 cfg)
319{
320 static char *jack_types[16] = {
321 "Line Out", "Speaker", "HP Out", "CD",
322 "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
323 "Line In", "Aux", "Mic", "Telephony",
324 "SPDIF In", "Digital In", "Reserved", "Other"
325 };
326
327 return jack_types[(cfg & AC_DEFCFG_DEVICE)
328 >> AC_DEFCFG_DEVICE_SHIFT];
329}
330
c8b6bf9b 331static void print_pin_caps(struct snd_info_buffer *buffer,
797760ab
AP
332 struct hda_codec *codec, hda_nid_t nid,
333 int *supports_vref)
1da177e4 334{
b0c95f51 335 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
e97a5167 336 unsigned int caps, val;
1da177e4 337
9ba17b4d 338 caps = param_read(codec, nid, AC_PAR_PIN_CAP);
0481f453 339 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
1da177e4
LT
340 if (caps & AC_PINCAP_IN)
341 snd_iprintf(buffer, " IN");
342 if (caps & AC_PINCAP_OUT)
343 snd_iprintf(buffer, " OUT");
344 if (caps & AC_PINCAP_HP_DRV)
345 snd_iprintf(buffer, " HP");
5885492a
TI
346 if (caps & AC_PINCAP_EAPD)
347 snd_iprintf(buffer, " EAPD");
348 if (caps & AC_PINCAP_PRES_DETECT)
349 snd_iprintf(buffer, " Detect");
797760ab
AP
350 if (caps & AC_PINCAP_BALANCE)
351 snd_iprintf(buffer, " Balanced");
c4920606
TI
352 if (caps & AC_PINCAP_HDMI) {
353 /* Realtek uses this bit as a different meaning */
7639a06c 354 if ((codec->core.vendor_id >> 16) == 0x10ec)
c4920606 355 snd_iprintf(buffer, " R/L");
b923528e
WF
356 else {
357 if (caps & AC_PINCAP_HBR)
358 snd_iprintf(buffer, " HBR");
c4920606 359 snd_iprintf(buffer, " HDMI");
b923528e 360 }
c4920606 361 }
728765b3
WF
362 if (caps & AC_PINCAP_DP)
363 snd_iprintf(buffer, " DP");
797760ab
AP
364 if (caps & AC_PINCAP_TRIG_REQ)
365 snd_iprintf(buffer, " Trigger");
366 if (caps & AC_PINCAP_IMP_SENSE)
367 snd_iprintf(buffer, " ImpSense");
1da177e4 368 snd_iprintf(buffer, "\n");
797760ab
AP
369 if (caps & AC_PINCAP_VREF) {
370 unsigned int vref =
371 (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
372 snd_iprintf(buffer, " Vref caps:");
373 if (vref & AC_PINCAP_VREF_HIZ)
374 snd_iprintf(buffer, " HIZ");
375 if (vref & AC_PINCAP_VREF_50)
376 snd_iprintf(buffer, " 50");
377 if (vref & AC_PINCAP_VREF_GRD)
378 snd_iprintf(buffer, " GRD");
379 if (vref & AC_PINCAP_VREF_80)
380 snd_iprintf(buffer, " 80");
381 if (vref & AC_PINCAP_VREF_100)
382 snd_iprintf(buffer, " 100");
383 snd_iprintf(buffer, "\n");
384 *supports_vref = 1;
385 } else
386 *supports_vref = 0;
387 if (caps & AC_PINCAP_EAPD) {
388 val = snd_hda_codec_read(codec, nid, 0,
389 AC_VERB_GET_EAPD_BTLENABLE, 0);
390 snd_iprintf(buffer, " EAPD 0x%x:", val);
391 if (val & AC_EAPDBTL_BALANCED)
392 snd_iprintf(buffer, " BALANCED");
393 if (val & AC_EAPDBTL_EAPD)
394 snd_iprintf(buffer, " EAPD");
395 if (val & AC_EAPDBTL_LR_SWAP)
396 snd_iprintf(buffer, " R/L");
397 snd_iprintf(buffer, "\n");
398 }
1da177e4 399 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
b0c95f51
TI
400 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
401 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
d2c6b63d
TI
402 get_jack_type(caps),
403 get_jack_connectivity(caps),
404 get_jack_location(caps));
1da177e4
LT
405 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
406 get_jack_connection(caps),
407 get_jack_color(caps));
797760ab
AP
408 /* Default association and sequence values refer to default grouping
409 * of pin complexes and their sequence within the group. This is used
410 * for priority and resource allocation.
411 */
412 snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
413 (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
414 caps & AC_DEFCFG_SEQUENCE);
415 if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
416 AC_DEFCFG_MISC_NO_PRESENCE) {
417 /* Miscellaneous bit indicates external hardware does not
418 * support presence detection even if the pin complex
419 * indicates it is supported.
420 */
421 snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
e97a5167 422 }
1da177e4
LT
423}
424
797760ab
AP
425static void print_pin_ctls(struct snd_info_buffer *buffer,
426 struct hda_codec *codec, hda_nid_t nid,
427 int supports_vref)
428{
429 unsigned int pinctls;
430
431 pinctls = snd_hda_codec_read(codec, nid, 0,
432 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
433 snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
434 if (pinctls & AC_PINCTL_IN_EN)
435 snd_iprintf(buffer, " IN");
436 if (pinctls & AC_PINCTL_OUT_EN)
437 snd_iprintf(buffer, " OUT");
438 if (pinctls & AC_PINCTL_HP_EN)
439 snd_iprintf(buffer, " HP");
440 if (supports_vref) {
441 int vref = pinctls & AC_PINCTL_VREFEN;
442 switch (vref) {
443 case AC_PINCTL_VREF_HIZ:
444 snd_iprintf(buffer, " VREF_HIZ");
445 break;
446 case AC_PINCTL_VREF_50:
447 snd_iprintf(buffer, " VREF_50");
448 break;
449 case AC_PINCTL_VREF_GRD:
450 snd_iprintf(buffer, " VREF_GRD");
451 break;
452 case AC_PINCTL_VREF_80:
453 snd_iprintf(buffer, " VREF_80");
454 break;
455 case AC_PINCTL_VREF_100:
456 snd_iprintf(buffer, " VREF_100");
457 break;
458 }
459 }
460 snd_iprintf(buffer, "\n");
461}
462
463static void print_vol_knob(struct snd_info_buffer *buffer,
464 struct hda_codec *codec, hda_nid_t nid)
465{
9ba17b4d 466 unsigned int cap = param_read(codec, nid, AC_PAR_VOL_KNB_CAP);
797760ab
AP
467 snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
468 (cap >> 7) & 1, cap & 0x7f);
469 cap = snd_hda_codec_read(codec, nid, 0,
470 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
471 snd_iprintf(buffer, "direct=%d, val=%d\n",
472 (cap >> 7) & 1, cap & 0x7f);
473}
474
475static void print_audio_io(struct snd_info_buffer *buffer,
476 struct hda_codec *codec, hda_nid_t nid,
477 unsigned int wid_type)
478{
3911a4c1 479 int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
797760ab
AP
480 snd_iprintf(buffer,
481 " Converter: stream=%d, channel=%d\n",
482 (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
483 conv & AC_CONV_CHANNEL);
484
485 if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
486 int sdi = snd_hda_codec_read(codec, nid, 0,
487 AC_VERB_GET_SDI_SELECT, 0);
488 snd_iprintf(buffer, " SDI-Select: %d\n",
489 sdi & AC_SDI_SELECT);
490 }
491}
492
493static void print_digital_conv(struct snd_info_buffer *buffer,
494 struct hda_codec *codec, hda_nid_t nid)
495{
496 unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
497 AC_VERB_GET_DIGI_CONVERT_1, 0);
61525979
WX
498 unsigned char digi2 = digi1 >> 8;
499 unsigned char digi3 = digi1 >> 16;
500
797760ab
AP
501 snd_iprintf(buffer, " Digital:");
502 if (digi1 & AC_DIG1_ENABLE)
503 snd_iprintf(buffer, " Enabled");
504 if (digi1 & AC_DIG1_V)
505 snd_iprintf(buffer, " Validity");
506 if (digi1 & AC_DIG1_VCFG)
507 snd_iprintf(buffer, " ValidityCfg");
508 if (digi1 & AC_DIG1_EMPHASIS)
509 snd_iprintf(buffer, " Preemphasis");
510 if (digi1 & AC_DIG1_COPYRIGHT)
088c820b 511 snd_iprintf(buffer, " Non-Copyright");
797760ab
AP
512 if (digi1 & AC_DIG1_NONAUDIO)
513 snd_iprintf(buffer, " Non-Audio");
514 if (digi1 & AC_DIG1_PROFESSIONAL)
515 snd_iprintf(buffer, " Pro");
516 if (digi1 & AC_DIG1_LEVEL)
517 snd_iprintf(buffer, " GenLevel");
61525979
WX
518 if (digi3 & AC_DIG3_KAE)
519 snd_iprintf(buffer, " KAE");
797760ab 520 snd_iprintf(buffer, "\n");
a1855d80 521 snd_iprintf(buffer, " Digital category: 0x%x\n",
61525979
WX
522 digi2 & AC_DIG2_CC);
523 snd_iprintf(buffer, " IEC Coding Type: 0x%x\n",
524 digi3 & AC_DIG3_ICT);
797760ab
AP
525}
526
527static const char *get_pwr_state(u32 state)
528{
167d2d55
TI
529 static const char * const buf[] = {
530 "D0", "D1", "D2", "D3", "D3cold"
797760ab 531 };
167d2d55 532 if (state < ARRAY_SIZE(buf))
797760ab
AP
533 return buf[state];
534 return "UNKNOWN";
535}
536
537static void print_power_state(struct snd_info_buffer *buffer,
538 struct hda_codec *codec, hda_nid_t nid)
539{
83d605fd
WF
540 static char *names[] = {
541 [ilog2(AC_PWRST_D0SUP)] = "D0",
542 [ilog2(AC_PWRST_D1SUP)] = "D1",
543 [ilog2(AC_PWRST_D2SUP)] = "D2",
544 [ilog2(AC_PWRST_D3SUP)] = "D3",
545 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
546 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
547 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
548 [ilog2(AC_PWRST_EPSS)] = "EPSS",
549 };
550
9ba17b4d 551 int sup = param_read(codec, nid, AC_PAR_POWER_STATE);
797760ab
AP
552 int pwr = snd_hda_codec_read(codec, nid, 0,
553 AC_VERB_GET_POWER_STATE, 0);
e076eb5c 554 if (sup != -1)
83d605fd
WF
555 snd_iprintf(buffer, " Power states: %s\n",
556 bits_names(sup, names, ARRAY_SIZE(names)));
557
ce63f3ba 558 snd_iprintf(buffer, " Power: setting=%s, actual=%s",
797760ab
AP
559 get_pwr_state(pwr & AC_PWRST_SETTING),
560 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
561 AC_PWRST_ACTUAL_SHIFT));
ce63f3ba
WX
562 if (pwr & AC_PWRST_ERROR)
563 snd_iprintf(buffer, ", Error");
564 if (pwr & AC_PWRST_CLK_STOP_OK)
565 snd_iprintf(buffer, ", Clock-stop-OK");
566 if (pwr & AC_PWRST_SETTING_RESET)
567 snd_iprintf(buffer, ", Setting-reset");
568 snd_iprintf(buffer, "\n");
797760ab
AP
569}
570
571static void print_unsol_cap(struct snd_info_buffer *buffer,
572 struct hda_codec *codec, hda_nid_t nid)
573{
574 int unsol = snd_hda_codec_read(codec, nid, 0,
575 AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
576 snd_iprintf(buffer,
577 " Unsolicited: tag=%02x, enabled=%d\n",
578 unsol & AC_UNSOL_TAG,
579 (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
580}
581
cd262518
DH
582static inline bool can_dump_coef(struct hda_codec *codec)
583{
584 switch (dump_coef) {
585 case 0: return false;
586 case 1: return true;
587 default: return codec->dump_coef;
588 }
589}
590
797760ab
AP
591static void print_proc_caps(struct snd_info_buffer *buffer,
592 struct hda_codec *codec, hda_nid_t nid)
593{
cd262518 594 unsigned int i, ncoeff, oldindex;
9ba17b4d 595 unsigned int proc_caps = param_read(codec, nid, AC_PAR_PROC_CAP);
cd262518 596 ncoeff = (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT;
797760ab 597 snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
cd262518
DH
598 proc_caps & AC_PCAP_BENIGN, ncoeff);
599
600 if (!can_dump_coef(codec))
601 return;
602
603 /* Note: This is racy - another process could run in parallel and change
604 the coef index too. */
605 oldindex = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_COEF_INDEX, 0);
606 for (i = 0; i < ncoeff; i++) {
607 unsigned int val;
608 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, i);
609 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PROC_COEF,
610 0);
611 snd_iprintf(buffer, " Coeff 0x%02x: 0x%04x\n", i, val);
612 }
613 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_COEF_INDEX, oldindex);
797760ab
AP
614}
615
616static void print_conn_list(struct snd_info_buffer *buffer,
617 struct hda_codec *codec, hda_nid_t nid,
618 unsigned int wid_type, hda_nid_t *conn,
619 int conn_len)
620{
621 int c, curr = -1;
8b2c7a5c
WX
622 const hda_nid_t *list;
623 int cache_len;
797760ab 624
07a1e813
TI
625 if (conn_len > 1 &&
626 wid_type != AC_WID_AUD_MIX &&
627 wid_type != AC_WID_VOL_KNB &&
628 wid_type != AC_WID_POWER)
797760ab
AP
629 curr = snd_hda_codec_read(codec, nid, 0,
630 AC_VERB_GET_CONNECT_SEL, 0);
631 snd_iprintf(buffer, " Connection: %d\n", conn_len);
632 if (conn_len > 0) {
633 snd_iprintf(buffer, " ");
634 for (c = 0; c < conn_len; c++) {
635 snd_iprintf(buffer, " 0x%02x", conn[c]);
636 if (c == curr)
637 snd_iprintf(buffer, "*");
638 }
639 snd_iprintf(buffer, "\n");
640 }
8b2c7a5c
WX
641
642 /* Get Cache connections info */
643 cache_len = snd_hda_get_conn_list(codec, nid, &list);
f4d77031
DC
644 if (cache_len >= 0 && (cache_len != conn_len ||
645 memcmp(list, conn, conn_len) != 0)) {
8b2c7a5c
WX
646 snd_iprintf(buffer, " In-driver Connection: %d\n", cache_len);
647 if (cache_len > 0) {
648 snd_iprintf(buffer, " ");
649 for (c = 0; c < cache_len; c++)
650 snd_iprintf(buffer, " 0x%02x", list[c]);
651 snd_iprintf(buffer, "\n");
652 }
653 }
797760ab
AP
654}
655
797760ab
AP
656static void print_gpio(struct snd_info_buffer *buffer,
657 struct hda_codec *codec, hda_nid_t nid)
658{
659 unsigned int gpio =
9ba17b4d 660 param_read(codec, codec->core.afg, AC_PAR_GPIO_CAP);
797760ab
AP
661 unsigned int enable, direction, wake, unsol, sticky, data;
662 int i, max;
663 snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
664 "unsolicited=%d, wake=%d\n",
665 gpio & AC_GPIO_IO_COUNT,
666 (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
667 (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
668 (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
669 (gpio & AC_GPIO_WAKE) ? 1 : 0);
670 max = gpio & AC_GPIO_IO_COUNT;
c4dc5071
TI
671 if (!max || max > 8)
672 return;
797760ab
AP
673 enable = snd_hda_codec_read(codec, nid, 0,
674 AC_VERB_GET_GPIO_MASK, 0);
675 direction = snd_hda_codec_read(codec, nid, 0,
676 AC_VERB_GET_GPIO_DIRECTION, 0);
677 wake = snd_hda_codec_read(codec, nid, 0,
678 AC_VERB_GET_GPIO_WAKE_MASK, 0);
679 unsol = snd_hda_codec_read(codec, nid, 0,
680 AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
681 sticky = snd_hda_codec_read(codec, nid, 0,
682 AC_VERB_GET_GPIO_STICKY_MASK, 0);
683 data = snd_hda_codec_read(codec, nid, 0,
684 AC_VERB_GET_GPIO_DATA, 0);
685 for (i = 0; i < max; ++i)
686 snd_iprintf(buffer,
687 " IO[%d]: enable=%d, dir=%d, wake=%d, "
85639646 688 "sticky=%d, data=%d, unsol=%d\n", i,
797760ab
AP
689 (enable & (1<<i)) ? 1 : 0,
690 (direction & (1<<i)) ? 1 : 0,
691 (wake & (1<<i)) ? 1 : 0,
692 (sticky & (1<<i)) ? 1 : 0,
85639646
TI
693 (data & (1<<i)) ? 1 : 0,
694 (unsol & (1<<i)) ? 1 : 0);
797760ab 695 /* FIXME: add GPO and GPI pin information */
5b0cb1d8
JK
696 print_nid_array(buffer, codec, nid, &codec->mixers);
697 print_nid_array(buffer, codec, nid, &codec->nids);
797760ab 698}
1da177e4 699
7a624ea5
ML
700static void print_device_list(struct snd_info_buffer *buffer,
701 struct hda_codec *codec, hda_nid_t nid)
702{
703 int i, curr = -1;
704 u8 dev_list[AC_MAX_DEV_LIST_LEN];
705 int devlist_len;
706
707 devlist_len = snd_hda_get_devices(codec, nid, dev_list,
708 AC_MAX_DEV_LIST_LEN);
709 snd_iprintf(buffer, " Devices: %d\n", devlist_len);
710 if (devlist_len <= 0)
711 return;
712
713 curr = snd_hda_codec_read(codec, nid, 0,
714 AC_VERB_GET_DEVICE_SEL, 0);
715
716 for (i = 0; i < devlist_len; i++) {
717 if (i == curr)
718 snd_iprintf(buffer, " *");
719 else
720 snd_iprintf(buffer, " ");
721
722 snd_iprintf(buffer,
723 "Dev %02d: PD = %d, ELDV = %d, IA = %d\n", i,
724 !!(dev_list[i] & AC_DE_PD),
725 !!(dev_list[i] & AC_DE_ELDV),
726 !!(dev_list[i] & AC_DE_IA));
727 }
728}
729
7639a06c
TI
730static void print_codec_core_info(struct hdac_device *codec,
731 struct snd_info_buffer *buffer)
1da177e4 732{
812a2cca
TI
733 snd_iprintf(buffer, "Codec: ");
734 if (codec->vendor_name && codec->chip_name)
735 snd_iprintf(buffer, "%s %s\n",
736 codec->vendor_name, codec->chip_name);
737 else
738 snd_iprintf(buffer, "Not Set\n");
1da177e4 739 snd_iprintf(buffer, "Address: %d\n", codec->addr);
79c944ad
JK
740 if (codec->afg)
741 snd_iprintf(buffer, "AFG Function Id: 0x%x (unsol %u)\n",
742 codec->afg_function_id, codec->afg_unsol);
743 if (codec->mfg)
744 snd_iprintf(buffer, "MFG Function Id: 0x%x (unsol %u)\n",
745 codec->mfg_function_id, codec->mfg_unsol);
234b4346
PB
746 snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
747 snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
1da177e4 748 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
e25c05f1
JP
749
750 if (codec->mfg)
751 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
752 else
753 snd_iprintf(buffer, "No Modem Function Group found\n");
7639a06c
TI
754}
755
756static void print_codec_info(struct snd_info_entry *entry,
757 struct snd_info_buffer *buffer)
758{
759 struct hda_codec *codec = entry->private_data;
760 hda_nid_t nid, fg;
761 int i, nodes;
e25c05f1 762
7639a06c
TI
763 print_codec_core_info(&codec->core, buffer);
764 fg = codec->core.afg;
765 if (!fg)
ec9e1c5c 766 return;
cb53c626 767 snd_hda_power_up(codec);
b90d7760 768 snd_iprintf(buffer, "Default PCM:\n");
7639a06c 769 print_pcm_caps(buffer, codec, fg);
1da177e4 770 snd_iprintf(buffer, "Default Amp-In caps: ");
7639a06c 771 print_amp_caps(buffer, codec, fg, HDA_INPUT);
1da177e4 772 snd_iprintf(buffer, "Default Amp-Out caps: ");
7639a06c
TI
773 print_amp_caps(buffer, codec, fg, HDA_OUTPUT);
774 snd_iprintf(buffer, "State of AFG node 0x%02x:\n", fg);
775 print_power_state(buffer, codec, fg);
1da177e4 776
7639a06c 777 nodes = snd_hda_get_sub_nodes(codec, fg, &nid);
1da177e4
LT
778 if (! nid || nodes < 0) {
779 snd_iprintf(buffer, "Invalid AFG subtree\n");
cb53c626 780 snd_hda_power_down(codec);
1da177e4
LT
781 return;
782 }
797760ab 783
7639a06c 784 print_gpio(buffer, codec, fg);
2d34e1b3 785 if (codec->proc_widget_hook)
7639a06c 786 codec->proc_widget_hook(buffer, codec, fg);
797760ab 787
1da177e4 788 for (i = 0; i < nodes; i++, nid++) {
d01ce99f 789 unsigned int wid_caps =
9ba17b4d 790 param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
a22d543a 791 unsigned int wid_type = get_wcaps_type(wid_caps);
4eea3091 792 hda_nid_t *conn = NULL;
797760ab 793 int conn_len = 0;
3e289f16 794
1da177e4
LT
795 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
796 get_wid_type_name(wid_type), wid_caps);
c4920606 797 if (wid_caps & AC_WCAP_STEREO) {
fd72d008 798 unsigned int chans = get_wcaps_channels(wid_caps);
c4920606
TI
799 if (chans == 2)
800 snd_iprintf(buffer, " Stereo");
801 else
802 snd_iprintf(buffer, " %d-Channels", chans);
803 } else
1da177e4
LT
804 snd_iprintf(buffer, " Mono");
805 if (wid_caps & AC_WCAP_DIGITAL)
806 snd_iprintf(buffer, " Digital");
807 if (wid_caps & AC_WCAP_IN_AMP)
808 snd_iprintf(buffer, " Amp-In");
809 if (wid_caps & AC_WCAP_OUT_AMP)
810 snd_iprintf(buffer, " Amp-Out");
797760ab
AP
811 if (wid_caps & AC_WCAP_STRIPE)
812 snd_iprintf(buffer, " Stripe");
813 if (wid_caps & AC_WCAP_LR_SWAP)
814 snd_iprintf(buffer, " R/L");
c4920606
TI
815 if (wid_caps & AC_WCAP_CP_CAPS)
816 snd_iprintf(buffer, " CP");
1da177e4
LT
817 snd_iprintf(buffer, "\n");
818
5b0cb1d8
JK
819 print_nid_array(buffer, codec, nid, &codec->mixers);
820 print_nid_array(buffer, codec, nid, &codec->nids);
3911a4c1
JK
821 print_nid_pcms(buffer, codec, nid);
822
e1716139
TI
823 /* volume knob is a special widget that always have connection
824 * list
825 */
826 if (wid_type == AC_WID_VOL_KNB)
827 wid_caps |= AC_WCAP_CONN_LIST;
828
4eea3091
TI
829 if (wid_caps & AC_WCAP_CONN_LIST) {
830 conn_len = snd_hda_get_num_raw_conns(codec, nid);
831 if (conn_len > 0) {
832 conn = kmalloc(sizeof(hda_nid_t) * conn_len,
833 GFP_KERNEL);
834 if (!conn)
835 return;
836 if (snd_hda_get_raw_connections(codec, nid, conn,
837 conn_len) < 0)
838 conn_len = 0;
839 }
840 }
3e289f16 841
1da177e4
LT
842 if (wid_caps & AC_WCAP_IN_AMP) {
843 snd_iprintf(buffer, " Amp-In caps: ");
844 print_amp_caps(buffer, codec, nid, HDA_INPUT);
845 snd_iprintf(buffer, " Amp-In vals: ");
4f32456e
MK
846 if (wid_type == AC_WID_PIN ||
847 (codec->single_adc_amp &&
848 wid_type == AC_WID_AUD_IN))
849 print_amp_vals(buffer, codec, nid, HDA_INPUT,
cc261738 850 wid_caps, 1);
4f32456e
MK
851 else
852 print_amp_vals(buffer, codec, nid, HDA_INPUT,
cc261738 853 wid_caps, conn_len);
1da177e4
LT
854 }
855 if (wid_caps & AC_WCAP_OUT_AMP) {
856 snd_iprintf(buffer, " Amp-Out caps: ");
857 print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
858 snd_iprintf(buffer, " Amp-Out vals: ");
9421f954
TI
859 if (wid_type == AC_WID_PIN &&
860 codec->pin_amp_workaround)
861 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
cc261738 862 wid_caps, conn_len);
9421f954
TI
863 else
864 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
cc261738 865 wid_caps, 1);
1da177e4
LT
866 }
867
e97a5167 868 switch (wid_type) {
797760ab
AP
869 case AC_WID_PIN: {
870 int supports_vref;
871 print_pin_caps(buffer, codec, nid, &supports_vref);
872 print_pin_ctls(buffer, codec, nid, supports_vref);
e97a5167 873 break;
797760ab 874 }
e97a5167 875 case AC_WID_VOL_KNB:
797760ab 876 print_vol_knob(buffer, codec, nid);
e97a5167
TI
877 break;
878 case AC_WID_AUD_OUT:
879 case AC_WID_AUD_IN:
797760ab
AP
880 print_audio_io(buffer, codec, nid, wid_type);
881 if (wid_caps & AC_WCAP_DIGITAL)
882 print_digital_conv(buffer, codec, nid);
e97a5167
TI
883 if (wid_caps & AC_WCAP_FORMAT_OVRD) {
884 snd_iprintf(buffer, " PCM:\n");
885 print_pcm_caps(buffer, codec, nid);
886 }
887 break;
1da177e4
LT
888 }
889
797760ab
AP
890 if (wid_caps & AC_WCAP_UNSOL_CAP)
891 print_unsol_cap(buffer, codec, nid);
892
b7027cc2 893 if (wid_caps & AC_WCAP_POWER)
797760ab
AP
894 print_power_state(buffer, codec, nid);
895
896 if (wid_caps & AC_WCAP_DELAY)
897 snd_iprintf(buffer, " Delay: %d samples\n",
898 (wid_caps & AC_WCAP_DELAY) >>
899 AC_WCAP_DELAY_SHIFT);
900
7a624ea5
ML
901 if (wid_type == AC_WID_PIN && codec->dp_mst)
902 print_device_list(buffer, codec, nid);
903
797760ab
AP
904 if (wid_caps & AC_WCAP_CONN_LIST)
905 print_conn_list(buffer, codec, nid, wid_type,
906 conn, conn_len);
907
908 if (wid_caps & AC_WCAP_PROC_WID)
909 print_proc_caps(buffer, codec, nid);
910
daead538
TI
911 if (codec->proc_widget_hook)
912 codec->proc_widget_hook(buffer, codec, nid);
4eea3091
TI
913
914 kfree(conn);
1da177e4 915 }
cb53c626 916 snd_hda_power_down(codec);
1da177e4
LT
917}
918
919/*
920 * create a proc read
921 */
922int snd_hda_codec_proc_new(struct hda_codec *codec)
923{
924 char name[32];
c8b6bf9b 925 struct snd_info_entry *entry;
1da177e4
LT
926 int err;
927
7639a06c 928 snprintf(name, sizeof(name), "codec#%d", codec->core.addr);
6efdd851 929 err = snd_card_proc_new(codec->card, name, &entry);
1da177e4
LT
930 if (err < 0)
931 return err;
932
bf850204 933 snd_info_set_text_ops(entry, codec, print_codec_info);
1da177e4
LT
934 return 0;
935}
936
This page took 0.645258 seconds and 5 git commands to generate.