blob: eb94e495c7546cf6c6409427c676a27345bec1e1 [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>
Takashi Iwai4eea3092013-02-07 18:18:19 +010025#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <sound/core.h>
27#include "hda_codec.h"
Adrian Bunk18612042005-11-23 13:14:50 +010028#include "hda_local.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Wu Fengguang83d605f2009-11-18 12:38:08 +080030static char *bits_names(unsigned int bits, char *names[], int size)
31{
32 int i, n;
33 static char buf[128];
34
35 for (i = 0, n = 0; i < size; i++) {
36 if (bits & (1U<<i) && names[i])
37 n += snprintf(buf + n, sizeof(buf) - n, " %s",
38 names[i]);
39 }
40 buf[n] = '\0';
41
42 return buf;
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static const char *get_wid_type_name(unsigned int wid_value)
46{
47 static char *names[16] = {
48 [AC_WID_AUD_OUT] = "Audio Output",
49 [AC_WID_AUD_IN] = "Audio Input",
50 [AC_WID_AUD_MIX] = "Audio Mixer",
51 [AC_WID_AUD_SEL] = "Audio Selector",
52 [AC_WID_PIN] = "Pin Complex",
53 [AC_WID_POWER] = "Power Widget",
54 [AC_WID_VOL_KNB] = "Volume Knob Widget",
55 [AC_WID_BEEP] = "Beep Generator Widget",
56 [AC_WID_VENDOR] = "Vendor Defined Widget",
57 };
Takashi Iwai3a902742012-01-10 12:41:22 +010058 if (wid_value == -1)
59 return "UNKNOWN Widget";
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 wid_value &= 0xf;
61 if (names[wid_value])
62 return names[wid_value];
63 else
Takashi Iwai3bc89522006-10-17 20:41:38 +020064 return "UNKNOWN Widget";
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010067static void print_nid_array(struct snd_info_buffer *buffer,
68 struct hda_codec *codec, hda_nid_t nid,
69 struct snd_array *array)
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010070{
71 int i;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010072 struct hda_nid_item *items = array->list, *item;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010073 struct snd_kcontrol *kctl;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010074 for (i = 0; i < array->used; i++) {
75 item = &items[i];
76 if (item->nid == nid) {
77 kctl = item->kctl;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010078 snd_iprintf(buffer,
79 " Control: name=\"%s\", index=%i, device=%i\n",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +010080 kctl->id.name, kctl->id.index + item->index,
81 kctl->id.device);
Jaroslav Kysela9e3fd872009-12-08 17:45:25 +010082 if (item->flags & HDA_NID_ITEM_AMP)
83 snd_iprintf(buffer,
84 " ControlAmp: chs=%lu, dir=%s, "
85 "idx=%lu, ofs=%lu\n",
86 get_amp_channels(kctl),
87 get_amp_direction(kctl) ? "Out" : "In",
88 get_amp_index(kctl),
89 get_amp_offset(kctl));
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +010090 }
91 }
92}
93
94static void print_nid_pcms(struct snd_info_buffer *buffer,
95 struct hda_codec *codec, hda_nid_t nid)
96{
97 int pcm, type;
98 struct hda_pcm *cpcm;
99 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
100 cpcm = &codec->pcm_info[pcm];
101 for (type = 0; type < 2; type++) {
102 if (cpcm->stream[type].nid != nid || cpcm->pcm == NULL)
103 continue;
104 snd_iprintf(buffer, " Device: name=\"%s\", "
105 "type=\"%s\", device=%i\n",
106 cpcm->name,
107 snd_hda_pcm_type_name[cpcm->pcm_type],
108 cpcm->pcm->device);
109 }
110 }
111}
112
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100113static void print_amp_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 struct hda_codec *codec, hda_nid_t nid, int dir)
115{
116 unsigned int caps;
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200117 caps = snd_hda_param_read(codec, nid,
118 dir == HDA_OUTPUT ?
119 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 if (caps == -1 || caps == 0) {
121 snd_iprintf(buffer, "N/A\n");
122 return;
123 }
Takashi Iwaid01ce992007-07-27 16:52:19 +0200124 snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, "
125 "mute=%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 caps & AC_AMPCAP_OFFSET,
127 (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
128 (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
129 (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
130}
131
Takashi Iwaia708f072015-03-16 10:18:08 +0100132/* is this a stereo widget or a stereo-to-mono mix? */
133static bool is_stereo_amps(struct hda_codec *codec, hda_nid_t nid,
134 int dir, unsigned int wcaps, int indices)
135{
136 hda_nid_t conn;
137
138 if (wcaps & AC_WCAP_STEREO)
139 return true;
140 /* check for a stereo-to-mono mix; it must be:
141 * only a single connection, only for input, and only a mixer widget
142 */
143 if (indices != 1 || dir != HDA_INPUT ||
144 get_wcaps_type(wcaps) != AC_WID_AUD_MIX)
145 return false;
146
147 if (snd_hda_get_raw_connections(codec, nid, &conn, 1) < 0)
148 return false;
149 /* the connection source is a stereo? */
150 wcaps = snd_hda_param_read(codec, conn, AC_PAR_AUDIO_WIDGET_CAP);
151 return !!(wcaps & AC_WCAP_STEREO);
152}
153
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100154static void print_amp_vals(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaia708f072015-03-16 10:18:08 +0100156 int dir, unsigned int wcaps, int indices)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 unsigned int val;
Takashi Iwaia708f072015-03-16 10:18:08 +0100159 bool stereo;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200160 int i;
161
Takashi Iwaia708f072015-03-16 10:18:08 +0100162 stereo = is_stereo_amps(codec, nid, dir, wcaps, indices);
163
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +0200164 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200165 for (i = 0; i < indices; i++) {
166 snd_iprintf(buffer, " [");
Takashi Iwai2f179722012-12-10 15:58:34 +0100167 val = snd_hda_codec_read(codec, nid, 0,
168 AC_VERB_GET_AMP_GAIN_MUTE,
169 AC_AMP_GET_LEFT | dir | i);
170 snd_iprintf(buffer, "0x%02x", val);
Takashi Iwai3e289f12005-06-10 19:45:09 +0200171 if (stereo) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200172 val = snd_hda_codec_read(codec, nid, 0,
173 AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai2f179722012-12-10 15:58:34 +0100174 AC_AMP_GET_RIGHT | dir | i);
175 snd_iprintf(buffer, " 0x%02x", val);
Takashi Iwai3e289f12005-06-10 19:45:09 +0200176 }
Takashi Iwai2f179722012-12-10 15:58:34 +0100177 snd_iprintf(buffer, "]");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
Takashi Iwai3e289f12005-06-10 19:45:09 +0200179 snd_iprintf(buffer, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180}
181
Wu Fengguang33deeca2008-11-18 11:47:51 +0800182static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
183{
Takashi Iwaif71ff0d2011-10-06 08:16:29 +0200184 static unsigned int rates[] = {
185 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
186 96000, 176400, 192000, 384000
187 };
188 int i;
Wu Fengguangd39b4352008-11-19 15:14:02 +0800189
Takashi Iwaib90d7762006-11-07 16:10:06 +0100190 pcm &= AC_SUPPCM_RATES;
191 snd_iprintf(buffer, " rates [0x%x]:", pcm);
Takashi Iwaif71ff0d2011-10-06 08:16:29 +0200192 for (i = 0; i < ARRAY_SIZE(rates); i++)
193 if (pcm & (1 << i))
194 snd_iprintf(buffer, " %d", rates[i]);
195 snd_iprintf(buffer, "\n");
Takashi Iwaib90d7762006-11-07 16:10:06 +0100196}
197
Wu Fengguangd39b4352008-11-19 15:14:02 +0800198static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
199{
200 char buf[SND_PRINT_BITS_ADVISED_BUFSIZE];
Takashi Iwaib90d7762006-11-07 16:10:06 +0100201
Takashi Iwaib0e64812008-11-25 16:07:01 +0100202 snd_iprintf(buffer, " bits [0x%x]:", (pcm >> 16) & 0xff);
Wu Fengguangd39b4352008-11-19 15:14:02 +0800203 snd_print_pcm_bits(pcm, buf, sizeof(buf));
204 snd_iprintf(buffer, "%s\n", buf);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100205}
206
207static void print_pcm_formats(struct snd_info_buffer *buffer,
208 unsigned int streams)
209{
210 snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
211 if (streams & AC_SUPFMT_PCM)
212 snd_iprintf(buffer, " PCM");
213 if (streams & AC_SUPFMT_FLOAT32)
214 snd_iprintf(buffer, " FLOAT");
215 if (streams & AC_SUPFMT_AC3)
216 snd_iprintf(buffer, " AC3");
217 snd_iprintf(buffer, "\n");
218}
219
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100220static void print_pcm_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 struct hda_codec *codec, hda_nid_t nid)
222{
223 unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
224 unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
225 if (pcm == -1 || stream == -1) {
226 snd_iprintf(buffer, "N/A\n");
227 return;
228 }
Takashi Iwaib90d7762006-11-07 16:10:06 +0100229 print_pcm_rates(buffer, pcm);
230 print_pcm_bits(buffer, pcm);
231 print_pcm_formats(buffer, stream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234static const char *get_jack_connection(u32 cfg)
235{
236 static char *names[16] = {
237 "Unknown", "1/8", "1/4", "ATAPI",
238 "RCA", "Optical","Digital", "Analog",
239 "DIN", "XLR", "RJ11", "Comb",
240 NULL, NULL, NULL, "Other"
241 };
242 cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
243 if (names[cfg])
244 return names[cfg];
245 else
246 return "UNKNOWN";
247}
248
249static const char *get_jack_color(u32 cfg)
250{
251 static char *names[16] = {
252 "Unknown", "Black", "Grey", "Blue",
253 "Green", "Red", "Orange", "Yellow",
254 "Purple", "Pink", NULL, NULL,
255 NULL, NULL, "White", "Other",
256 };
257 cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
258 if (names[cfg])
259 return names[cfg];
260 else
261 return "UNKNOWN";
262}
263
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100264static void print_pin_caps(struct snd_info_buffer *buffer,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100265 struct hda_codec *codec, hda_nid_t nid,
266 int *supports_vref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200268 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
Takashi Iwaie97a5162007-10-26 14:56:36 +0200269 unsigned int caps, val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
Robin H. Johnson0481f452008-09-13 16:54:57 -0700272 snd_iprintf(buffer, " Pincap 0x%08x:", caps);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (caps & AC_PINCAP_IN)
274 snd_iprintf(buffer, " IN");
275 if (caps & AC_PINCAP_OUT)
276 snd_iprintf(buffer, " OUT");
277 if (caps & AC_PINCAP_HP_DRV)
278 snd_iprintf(buffer, " HP");
Takashi Iwai58854922006-06-21 19:19:25 +0200279 if (caps & AC_PINCAP_EAPD)
280 snd_iprintf(buffer, " EAPD");
281 if (caps & AC_PINCAP_PRES_DETECT)
282 snd_iprintf(buffer, " Detect");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100283 if (caps & AC_PINCAP_BALANCE)
284 snd_iprintf(buffer, " Balanced");
Takashi Iwaic4920602008-07-30 15:13:29 +0200285 if (caps & AC_PINCAP_HDMI) {
286 /* Realtek uses this bit as a different meaning */
287 if ((codec->vendor_id >> 16) == 0x10ec)
288 snd_iprintf(buffer, " R/L");
Wu Fengguangb9235282009-12-11 12:28:33 +0800289 else {
290 if (caps & AC_PINCAP_HBR)
291 snd_iprintf(buffer, " HBR");
Takashi Iwaic4920602008-07-30 15:13:29 +0200292 snd_iprintf(buffer, " HDMI");
Wu Fengguangb9235282009-12-11 12:28:33 +0800293 }
Takashi Iwaic4920602008-07-30 15:13:29 +0200294 }
Wu Fengguang728765b2009-12-11 12:28:34 +0800295 if (caps & AC_PINCAP_DP)
296 snd_iprintf(buffer, " DP");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100297 if (caps & AC_PINCAP_TRIG_REQ)
298 snd_iprintf(buffer, " Trigger");
299 if (caps & AC_PINCAP_IMP_SENSE)
300 snd_iprintf(buffer, " ImpSense");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 snd_iprintf(buffer, "\n");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100302 if (caps & AC_PINCAP_VREF) {
303 unsigned int vref =
304 (caps & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
305 snd_iprintf(buffer, " Vref caps:");
306 if (vref & AC_PINCAP_VREF_HIZ)
307 snd_iprintf(buffer, " HIZ");
308 if (vref & AC_PINCAP_VREF_50)
309 snd_iprintf(buffer, " 50");
310 if (vref & AC_PINCAP_VREF_GRD)
311 snd_iprintf(buffer, " GRD");
312 if (vref & AC_PINCAP_VREF_80)
313 snd_iprintf(buffer, " 80");
314 if (vref & AC_PINCAP_VREF_100)
315 snd_iprintf(buffer, " 100");
316 snd_iprintf(buffer, "\n");
317 *supports_vref = 1;
318 } else
319 *supports_vref = 0;
320 if (caps & AC_PINCAP_EAPD) {
321 val = snd_hda_codec_read(codec, nid, 0,
322 AC_VERB_GET_EAPD_BTLENABLE, 0);
323 snd_iprintf(buffer, " EAPD 0x%x:", val);
324 if (val & AC_EAPDBTL_BALANCED)
325 snd_iprintf(buffer, " BALANCED");
326 if (val & AC_EAPDBTL_EAPD)
327 snd_iprintf(buffer, " EAPD");
328 if (val & AC_EAPDBTL_LR_SWAP)
329 snd_iprintf(buffer, " R/L");
330 snd_iprintf(buffer, "\n");
331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200333 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
334 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
Matthew Ranostay50a9f792008-10-25 01:05:45 -0400335 snd_hda_get_jack_type(caps),
336 snd_hda_get_jack_connectivity(caps),
337 snd_hda_get_jack_location(caps));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
339 get_jack_connection(caps),
340 get_jack_color(caps));
Andrew Paprocki797760a2008-01-18 12:51:11 +0100341 /* Default association and sequence values refer to default grouping
342 * of pin complexes and their sequence within the group. This is used
343 * for priority and resource allocation.
344 */
345 snd_iprintf(buffer, " DefAssociation = 0x%x, Sequence = 0x%x\n",
346 (caps & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT,
347 caps & AC_DEFCFG_SEQUENCE);
348 if (((caps & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT) &
349 AC_DEFCFG_MISC_NO_PRESENCE) {
350 /* Miscellaneous bit indicates external hardware does not
351 * support presence detection even if the pin complex
352 * indicates it is supported.
353 */
354 snd_iprintf(buffer, " Misc = NO_PRESENCE\n");
Takashi Iwaie97a5162007-10-26 14:56:36 +0200355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
Andrew Paprocki797760a2008-01-18 12:51:11 +0100358static void print_pin_ctls(struct snd_info_buffer *buffer,
359 struct hda_codec *codec, hda_nid_t nid,
360 int supports_vref)
361{
362 unsigned int pinctls;
363
364 pinctls = snd_hda_codec_read(codec, nid, 0,
365 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
366 snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
367 if (pinctls & AC_PINCTL_IN_EN)
368 snd_iprintf(buffer, " IN");
369 if (pinctls & AC_PINCTL_OUT_EN)
370 snd_iprintf(buffer, " OUT");
371 if (pinctls & AC_PINCTL_HP_EN)
372 snd_iprintf(buffer, " HP");
373 if (supports_vref) {
374 int vref = pinctls & AC_PINCTL_VREFEN;
375 switch (vref) {
376 case AC_PINCTL_VREF_HIZ:
377 snd_iprintf(buffer, " VREF_HIZ");
378 break;
379 case AC_PINCTL_VREF_50:
380 snd_iprintf(buffer, " VREF_50");
381 break;
382 case AC_PINCTL_VREF_GRD:
383 snd_iprintf(buffer, " VREF_GRD");
384 break;
385 case AC_PINCTL_VREF_80:
386 snd_iprintf(buffer, " VREF_80");
387 break;
388 case AC_PINCTL_VREF_100:
389 snd_iprintf(buffer, " VREF_100");
390 break;
391 }
392 }
393 snd_iprintf(buffer, "\n");
394}
395
396static void print_vol_knob(struct snd_info_buffer *buffer,
397 struct hda_codec *codec, hda_nid_t nid)
398{
399 unsigned int cap = snd_hda_param_read(codec, nid,
400 AC_PAR_VOL_KNB_CAP);
401 snd_iprintf(buffer, " Volume-Knob: delta=%d, steps=%d, ",
402 (cap >> 7) & 1, cap & 0x7f);
403 cap = snd_hda_codec_read(codec, nid, 0,
404 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
405 snd_iprintf(buffer, "direct=%d, val=%d\n",
406 (cap >> 7) & 1, cap & 0x7f);
407}
408
409static void print_audio_io(struct snd_info_buffer *buffer,
410 struct hda_codec *codec, hda_nid_t nid,
411 unsigned int wid_type)
412{
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100413 int conv = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100414 snd_iprintf(buffer,
415 " Converter: stream=%d, channel=%d\n",
416 (conv & AC_CONV_STREAM) >> AC_CONV_STREAM_SHIFT,
417 conv & AC_CONV_CHANNEL);
418
419 if (wid_type == AC_WID_AUD_IN && (conv & AC_CONV_CHANNEL) == 0) {
420 int sdi = snd_hda_codec_read(codec, nid, 0,
421 AC_VERB_GET_SDI_SELECT, 0);
422 snd_iprintf(buffer, " SDI-Select: %d\n",
423 sdi & AC_SDI_SELECT);
424 }
425}
426
427static void print_digital_conv(struct snd_info_buffer *buffer,
428 struct hda_codec *codec, hda_nid_t nid)
429{
430 unsigned int digi1 = snd_hda_codec_read(codec, nid, 0,
431 AC_VERB_GET_DIGI_CONVERT_1, 0);
Wang Xingchao61525972012-08-13 15:43:49 +0800432 unsigned char digi2 = digi1 >> 8;
433 unsigned char digi3 = digi1 >> 16;
434
Andrew Paprocki797760a2008-01-18 12:51:11 +0100435 snd_iprintf(buffer, " Digital:");
436 if (digi1 & AC_DIG1_ENABLE)
437 snd_iprintf(buffer, " Enabled");
438 if (digi1 & AC_DIG1_V)
439 snd_iprintf(buffer, " Validity");
440 if (digi1 & AC_DIG1_VCFG)
441 snd_iprintf(buffer, " ValidityCfg");
442 if (digi1 & AC_DIG1_EMPHASIS)
443 snd_iprintf(buffer, " Preemphasis");
444 if (digi1 & AC_DIG1_COPYRIGHT)
Wang Xingchao088c8202012-08-13 14:11:10 +0800445 snd_iprintf(buffer, " Non-Copyright");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100446 if (digi1 & AC_DIG1_NONAUDIO)
447 snd_iprintf(buffer, " Non-Audio");
448 if (digi1 & AC_DIG1_PROFESSIONAL)
449 snd_iprintf(buffer, " Pro");
450 if (digi1 & AC_DIG1_LEVEL)
451 snd_iprintf(buffer, " GenLevel");
Wang Xingchao61525972012-08-13 15:43:49 +0800452 if (digi3 & AC_DIG3_KAE)
453 snd_iprintf(buffer, " KAE");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100454 snd_iprintf(buffer, "\n");
Takashi Iwaia1855d82008-06-19 15:41:37 +0200455 snd_iprintf(buffer, " Digital category: 0x%x\n",
Wang Xingchao61525972012-08-13 15:43:49 +0800456 digi2 & AC_DIG2_CC);
457 snd_iprintf(buffer, " IEC Coding Type: 0x%x\n",
458 digi3 & AC_DIG3_ICT);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100459}
460
461static const char *get_pwr_state(u32 state)
462{
Takashi Iwai167d2d52012-06-06 12:17:20 +0200463 static const char * const buf[] = {
464 "D0", "D1", "D2", "D3", "D3cold"
Andrew Paprocki797760a2008-01-18 12:51:11 +0100465 };
Takashi Iwai167d2d52012-06-06 12:17:20 +0200466 if (state < ARRAY_SIZE(buf))
Andrew Paprocki797760a2008-01-18 12:51:11 +0100467 return buf[state];
468 return "UNKNOWN";
469}
470
471static void print_power_state(struct snd_info_buffer *buffer,
472 struct hda_codec *codec, hda_nid_t nid)
473{
Wu Fengguang83d605f2009-11-18 12:38:08 +0800474 static char *names[] = {
475 [ilog2(AC_PWRST_D0SUP)] = "D0",
476 [ilog2(AC_PWRST_D1SUP)] = "D1",
477 [ilog2(AC_PWRST_D2SUP)] = "D2",
478 [ilog2(AC_PWRST_D3SUP)] = "D3",
479 [ilog2(AC_PWRST_D3COLDSUP)] = "D3cold",
480 [ilog2(AC_PWRST_S3D3COLDSUP)] = "S3D3cold",
481 [ilog2(AC_PWRST_CLKSTOP)] = "CLKSTOP",
482 [ilog2(AC_PWRST_EPSS)] = "EPSS",
483 };
484
485 int sup = snd_hda_param_read(codec, nid, AC_PAR_POWER_STATE);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100486 int pwr = snd_hda_codec_read(codec, nid, 0,
487 AC_VERB_GET_POWER_STATE, 0);
Wang Xingchaoe076eb52012-06-07 16:52:07 +0800488 if (sup != -1)
Wu Fengguang83d605f2009-11-18 12:38:08 +0800489 snd_iprintf(buffer, " Power states: %s\n",
490 bits_names(sup, names, ARRAY_SIZE(names)));
491
Wang Xingchaoce63f3b2012-06-06 13:49:44 +0800492 snd_iprintf(buffer, " Power: setting=%s, actual=%s",
Andrew Paprocki797760a2008-01-18 12:51:11 +0100493 get_pwr_state(pwr & AC_PWRST_SETTING),
494 get_pwr_state((pwr & AC_PWRST_ACTUAL) >>
495 AC_PWRST_ACTUAL_SHIFT));
Wang Xingchaoce63f3b2012-06-06 13:49:44 +0800496 if (pwr & AC_PWRST_ERROR)
497 snd_iprintf(buffer, ", Error");
498 if (pwr & AC_PWRST_CLK_STOP_OK)
499 snd_iprintf(buffer, ", Clock-stop-OK");
500 if (pwr & AC_PWRST_SETTING_RESET)
501 snd_iprintf(buffer, ", Setting-reset");
502 snd_iprintf(buffer, "\n");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100503}
504
505static void print_unsol_cap(struct snd_info_buffer *buffer,
506 struct hda_codec *codec, hda_nid_t nid)
507{
508 int unsol = snd_hda_codec_read(codec, nid, 0,
509 AC_VERB_GET_UNSOLICITED_RESPONSE, 0);
510 snd_iprintf(buffer,
511 " Unsolicited: tag=%02x, enabled=%d\n",
512 unsol & AC_UNSOL_TAG,
513 (unsol & AC_UNSOL_ENABLED) ? 1 : 0);
514}
515
516static void print_proc_caps(struct snd_info_buffer *buffer,
517 struct hda_codec *codec, hda_nid_t nid)
518{
519 unsigned int proc_caps = snd_hda_param_read(codec, nid,
520 AC_PAR_PROC_CAP);
521 snd_iprintf(buffer, " Processing caps: benign=%d, ncoeff=%d\n",
522 proc_caps & AC_PCAP_BENIGN,
523 (proc_caps & AC_PCAP_NUM_COEF) >> AC_PCAP_NUM_COEF_SHIFT);
524}
525
526static void print_conn_list(struct snd_info_buffer *buffer,
527 struct hda_codec *codec, hda_nid_t nid,
528 unsigned int wid_type, hda_nid_t *conn,
529 int conn_len)
530{
531 int c, curr = -1;
532
Takashi Iwai07a1e812009-03-19 17:08:19 +0100533 if (conn_len > 1 &&
534 wid_type != AC_WID_AUD_MIX &&
535 wid_type != AC_WID_VOL_KNB &&
536 wid_type != AC_WID_POWER)
Andrew Paprocki797760a2008-01-18 12:51:11 +0100537 curr = snd_hda_codec_read(codec, nid, 0,
538 AC_VERB_GET_CONNECT_SEL, 0);
539 snd_iprintf(buffer, " Connection: %d\n", conn_len);
540 if (conn_len > 0) {
541 snd_iprintf(buffer, " ");
542 for (c = 0; c < conn_len; c++) {
543 snd_iprintf(buffer, " 0x%02x", conn[c]);
544 if (c == curr)
545 snd_iprintf(buffer, "*");
546 }
547 snd_iprintf(buffer, "\n");
548 }
549}
550
Andrew Paprocki797760a2008-01-18 12:51:11 +0100551static void print_gpio(struct snd_info_buffer *buffer,
552 struct hda_codec *codec, hda_nid_t nid)
553{
554 unsigned int gpio =
555 snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
556 unsigned int enable, direction, wake, unsol, sticky, data;
557 int i, max;
558 snd_iprintf(buffer, "GPIO: io=%d, o=%d, i=%d, "
559 "unsolicited=%d, wake=%d\n",
560 gpio & AC_GPIO_IO_COUNT,
561 (gpio & AC_GPIO_O_COUNT) >> AC_GPIO_O_COUNT_SHIFT,
562 (gpio & AC_GPIO_I_COUNT) >> AC_GPIO_I_COUNT_SHIFT,
563 (gpio & AC_GPIO_UNSOLICITED) ? 1 : 0,
564 (gpio & AC_GPIO_WAKE) ? 1 : 0);
565 max = gpio & AC_GPIO_IO_COUNT;
Takashi Iwaic4dc5072008-11-04 13:30:57 +0100566 if (!max || max > 8)
567 return;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100568 enable = snd_hda_codec_read(codec, nid, 0,
569 AC_VERB_GET_GPIO_MASK, 0);
570 direction = snd_hda_codec_read(codec, nid, 0,
571 AC_VERB_GET_GPIO_DIRECTION, 0);
572 wake = snd_hda_codec_read(codec, nid, 0,
573 AC_VERB_GET_GPIO_WAKE_MASK, 0);
574 unsol = snd_hda_codec_read(codec, nid, 0,
575 AC_VERB_GET_GPIO_UNSOLICITED_RSP_MASK, 0);
576 sticky = snd_hda_codec_read(codec, nid, 0,
577 AC_VERB_GET_GPIO_STICKY_MASK, 0);
578 data = snd_hda_codec_read(codec, nid, 0,
579 AC_VERB_GET_GPIO_DATA, 0);
580 for (i = 0; i < max; ++i)
581 snd_iprintf(buffer,
582 " IO[%d]: enable=%d, dir=%d, wake=%d, "
Takashi Iwai85639642008-11-19 14:14:50 +0100583 "sticky=%d, data=%d, unsol=%d\n", i,
Andrew Paprocki797760a2008-01-18 12:51:11 +0100584 (enable & (1<<i)) ? 1 : 0,
585 (direction & (1<<i)) ? 1 : 0,
586 (wake & (1<<i)) ? 1 : 0,
587 (sticky & (1<<i)) ? 1 : 0,
Takashi Iwai85639642008-11-19 14:14:50 +0100588 (data & (1<<i)) ? 1 : 0,
589 (unsol & (1<<i)) ? 1 : 0);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100590 /* FIXME: add GPO and GPI pin information */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100591 print_nid_array(buffer, codec, nid, &codec->mixers);
592 print_nid_array(buffer, codec, nid, &codec->nids);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100593}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Takashi Iwaid01ce992007-07-27 16:52:19 +0200595static void print_codec_info(struct snd_info_entry *entry,
596 struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
598 struct hda_codec *codec = entry->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 hda_nid_t nid;
600 int i, nodes;
601
Takashi Iwai812a2cc2009-05-16 10:00:49 +0200602 snd_iprintf(buffer, "Codec: ");
603 if (codec->vendor_name && codec->chip_name)
604 snd_iprintf(buffer, "%s %s\n",
605 codec->vendor_name, codec->chip_name);
606 else
607 snd_iprintf(buffer, "Not Set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 snd_iprintf(buffer, "Address: %d\n", codec->addr);
Jaroslav Kysela79c944a2010-07-19 15:52:39 +0200609 if (codec->afg)
610 snd_iprintf(buffer, "AFG Function Id: 0x%x (unsol %u)\n",
611 codec->afg_function_id, codec->afg_unsol);
612 if (codec->mfg)
613 snd_iprintf(buffer, "MFG Function Id: 0x%x (unsol %u)\n",
614 codec->mfg_function_id, codec->mfg_unsol);
Pascal de Bruijn234b4342009-03-23 11:15:59 +0100615 snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
616 snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
Jonathan Phenixe25c05f2007-06-19 18:31:28 +0200618
619 if (codec->mfg)
620 snd_iprintf(buffer, "Modem Function Group: 0x%x\n", codec->mfg);
621 else
622 snd_iprintf(buffer, "No Modem Function Group found\n");
623
Takashi Iwaiec9e1c52005-09-07 13:29:22 +0200624 if (! codec->afg)
625 return;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200626 snd_hda_power_up(codec);
Takashi Iwaib90d7762006-11-07 16:10:06 +0100627 snd_iprintf(buffer, "Default PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 print_pcm_caps(buffer, codec, codec->afg);
629 snd_iprintf(buffer, "Default Amp-In caps: ");
630 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
631 snd_iprintf(buffer, "Default Amp-Out caps: ");
632 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
David Henningssonf4f0a8c2013-01-08 15:01:18 +0100633 snd_iprintf(buffer, "State of AFG node 0x%02x:\n", codec->afg);
634 print_power_state(buffer, codec, codec->afg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
637 if (! nid || nodes < 0) {
638 snd_iprintf(buffer, "Invalid AFG subtree\n");
Takashi Iwaicb53c622007-08-10 17:21:45 +0200639 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 return;
641 }
Andrew Paprocki797760a2008-01-18 12:51:11 +0100642
643 print_gpio(buffer, codec, codec->afg);
Takashi Iwai2d34e1b2008-11-28 14:35:16 +0100644 if (codec->proc_widget_hook)
645 codec->proc_widget_hook(buffer, codec, codec->afg);
Andrew Paprocki797760a2008-01-18 12:51:11 +0100646
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 for (i = 0; i < nodes; i++, nid++) {
Takashi Iwaid01ce992007-07-27 16:52:19 +0200648 unsigned int wid_caps =
649 snd_hda_param_read(codec, nid,
650 AC_PAR_AUDIO_WIDGET_CAP);
Takashi Iwaia22d5432009-07-27 12:54:26 +0200651 unsigned int wid_type = get_wcaps_type(wid_caps);
Takashi Iwai4eea3092013-02-07 18:18:19 +0100652 hda_nid_t *conn = NULL;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100653 int conn_len = 0;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
656 get_wid_type_name(wid_type), wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200657 if (wid_caps & AC_WCAP_STEREO) {
Wu Fengguangfd72d002009-08-24 09:50:46 +0800658 unsigned int chans = get_wcaps_channels(wid_caps);
Takashi Iwaic4920602008-07-30 15:13:29 +0200659 if (chans == 2)
660 snd_iprintf(buffer, " Stereo");
661 else
662 snd_iprintf(buffer, " %d-Channels", chans);
663 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 snd_iprintf(buffer, " Mono");
665 if (wid_caps & AC_WCAP_DIGITAL)
666 snd_iprintf(buffer, " Digital");
667 if (wid_caps & AC_WCAP_IN_AMP)
668 snd_iprintf(buffer, " Amp-In");
669 if (wid_caps & AC_WCAP_OUT_AMP)
670 snd_iprintf(buffer, " Amp-Out");
Andrew Paprocki797760a2008-01-18 12:51:11 +0100671 if (wid_caps & AC_WCAP_STRIPE)
672 snd_iprintf(buffer, " Stripe");
673 if (wid_caps & AC_WCAP_LR_SWAP)
674 snd_iprintf(buffer, " R/L");
Takashi Iwaic4920602008-07-30 15:13:29 +0200675 if (wid_caps & AC_WCAP_CP_CAPS)
676 snd_iprintf(buffer, " CP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 snd_iprintf(buffer, "\n");
678
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100679 print_nid_array(buffer, codec, nid, &codec->mixers);
680 print_nid_array(buffer, codec, nid, &codec->nids);
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +0100681 print_nid_pcms(buffer, codec, nid);
682
Takashi Iwaie1716132007-11-16 17:52:39 +0100683 /* volume knob is a special widget that always have connection
684 * list
685 */
686 if (wid_type == AC_WID_VOL_KNB)
687 wid_caps |= AC_WCAP_CONN_LIST;
688
Takashi Iwai4eea3092013-02-07 18:18:19 +0100689 if (wid_caps & AC_WCAP_CONN_LIST) {
690 conn_len = snd_hda_get_num_raw_conns(codec, nid);
691 if (conn_len > 0) {
692 conn = kmalloc(sizeof(hda_nid_t) * conn_len,
693 GFP_KERNEL);
694 if (!conn)
695 return;
696 if (snd_hda_get_raw_connections(codec, nid, conn,
697 conn_len) < 0)
698 conn_len = 0;
699 }
700 }
Takashi Iwai3e289f12005-06-10 19:45:09 +0200701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 if (wid_caps & AC_WCAP_IN_AMP) {
703 snd_iprintf(buffer, " Amp-In caps: ");
704 print_amp_caps(buffer, codec, nid, HDA_INPUT);
705 snd_iprintf(buffer, " Amp-In vals: ");
Michael Karcher4f324562012-04-06 15:34:15 +0200706 if (wid_type == AC_WID_PIN ||
707 (codec->single_adc_amp &&
708 wid_type == AC_WID_AUD_IN))
709 print_amp_vals(buffer, codec, nid, HDA_INPUT,
Takashi Iwaia708f072015-03-16 10:18:08 +0100710 wid_caps, 1);
Michael Karcher4f324562012-04-06 15:34:15 +0200711 else
712 print_amp_vals(buffer, codec, nid, HDA_INPUT,
Takashi Iwaia708f072015-03-16 10:18:08 +0100713 wid_caps, conn_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715 if (wid_caps & AC_WCAP_OUT_AMP) {
716 snd_iprintf(buffer, " Amp-Out caps: ");
717 print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
718 snd_iprintf(buffer, " Amp-Out vals: ");
Takashi Iwai9421f952009-03-12 17:06:07 +0100719 if (wid_type == AC_WID_PIN &&
720 codec->pin_amp_workaround)
721 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
Takashi Iwaia708f072015-03-16 10:18:08 +0100722 wid_caps, conn_len);
Takashi Iwai9421f952009-03-12 17:06:07 +0100723 else
724 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
Takashi Iwaia708f072015-03-16 10:18:08 +0100725 wid_caps, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 }
727
Takashi Iwaie97a5162007-10-26 14:56:36 +0200728 switch (wid_type) {
Andrew Paprocki797760a2008-01-18 12:51:11 +0100729 case AC_WID_PIN: {
730 int supports_vref;
731 print_pin_caps(buffer, codec, nid, &supports_vref);
732 print_pin_ctls(buffer, codec, nid, supports_vref);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200733 break;
Andrew Paprocki797760a2008-01-18 12:51:11 +0100734 }
Takashi Iwaie97a5162007-10-26 14:56:36 +0200735 case AC_WID_VOL_KNB:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100736 print_vol_knob(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200737 break;
738 case AC_WID_AUD_OUT:
739 case AC_WID_AUD_IN:
Andrew Paprocki797760a2008-01-18 12:51:11 +0100740 print_audio_io(buffer, codec, nid, wid_type);
741 if (wid_caps & AC_WCAP_DIGITAL)
742 print_digital_conv(buffer, codec, nid);
Takashi Iwaie97a5162007-10-26 14:56:36 +0200743 if (wid_caps & AC_WCAP_FORMAT_OVRD) {
744 snd_iprintf(buffer, " PCM:\n");
745 print_pcm_caps(buffer, codec, nid);
746 }
747 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
749
Andrew Paprocki797760a2008-01-18 12:51:11 +0100750 if (wid_caps & AC_WCAP_UNSOL_CAP)
751 print_unsol_cap(buffer, codec, nid);
Takashi Iwaib7027cc2005-11-02 18:13:41 +0100752
Andrew Paprocki797760a2008-01-18 12:51:11 +0100753 if (wid_caps & AC_WCAP_POWER)
754 print_power_state(buffer, codec, nid);
755
756 if (wid_caps & AC_WCAP_DELAY)
757 snd_iprintf(buffer, " Delay: %d samples\n",
758 (wid_caps & AC_WCAP_DELAY) >>
759 AC_WCAP_DELAY_SHIFT);
760
761 if (wid_caps & AC_WCAP_CONN_LIST)
762 print_conn_list(buffer, codec, nid, wid_type,
763 conn, conn_len);
764
765 if (wid_caps & AC_WCAP_PROC_WID)
766 print_proc_caps(buffer, codec, nid);
767
Takashi Iwaidaead532008-11-28 12:55:36 +0100768 if (codec->proc_widget_hook)
769 codec->proc_widget_hook(buffer, codec, nid);
Takashi Iwai4eea3092013-02-07 18:18:19 +0100770
771 kfree(conn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
Takashi Iwaicb53c622007-08-10 17:21:45 +0200773 snd_hda_power_down(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774}
775
776/*
777 * create a proc read
778 */
779int snd_hda_codec_proc_new(struct hda_codec *codec)
780{
781 char name[32];
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100782 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 int err;
784
785 snprintf(name, sizeof(name), "codec#%d", codec->addr);
786 err = snd_card_proc_new(codec->bus->card, name, &entry);
787 if (err < 0)
788 return err;
789
Takashi Iwaibf850202006-04-28 15:13:41 +0200790 snd_info_set_text_ops(entry, codec, print_codec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 return 0;
792}
793