blob: 17df4d0fe135b4a13e56a78df4f36c58c296b4a6 [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
24#include <sound/driver.h>
25#include <linux/init.h>
26#include <linux/pci.h>
27#include <sound/core.h>
28#include "hda_codec.h"
Adrian Bunk18612042005-11-23 13:14:50 +010029#include "hda_local.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31static const char *get_wid_type_name(unsigned int wid_value)
32{
33 static char *names[16] = {
34 [AC_WID_AUD_OUT] = "Audio Output",
35 [AC_WID_AUD_IN] = "Audio Input",
36 [AC_WID_AUD_MIX] = "Audio Mixer",
37 [AC_WID_AUD_SEL] = "Audio Selector",
38 [AC_WID_PIN] = "Pin Complex",
39 [AC_WID_POWER] = "Power Widget",
40 [AC_WID_VOL_KNB] = "Volume Knob Widget",
41 [AC_WID_BEEP] = "Beep Generator Widget",
42 [AC_WID_VENDOR] = "Vendor Defined Widget",
43 };
44 wid_value &= 0xf;
45 if (names[wid_value])
46 return names[wid_value];
47 else
Takashi Iwai3bc89522006-10-17 20:41:38 +020048 return "UNKNOWN Widget";
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010051static void print_amp_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct hda_codec *codec, hda_nid_t nid, int dir)
53{
54 unsigned int caps;
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +020055 caps = snd_hda_param_read(codec, nid,
56 dir == HDA_OUTPUT ?
57 AC_PAR_AMP_OUT_CAP : AC_PAR_AMP_IN_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (caps == -1 || caps == 0) {
59 snd_iprintf(buffer, "N/A\n");
60 return;
61 }
62 snd_iprintf(buffer, "ofs=0x%02x, nsteps=0x%02x, stepsize=0x%02x, mute=%x\n",
63 caps & AC_AMPCAP_OFFSET,
64 (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT,
65 (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT,
66 (caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT);
67}
68
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010069static void print_amp_vals(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai3e289f12005-06-10 19:45:09 +020071 int dir, int stereo, int indices)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 unsigned int val;
Takashi Iwai3e289f12005-06-10 19:45:09 +020074 int i;
75
Jaroslav Kysela7f0e2f82006-07-05 17:39:14 +020076 dir = dir == HDA_OUTPUT ? AC_AMP_GET_OUTPUT : AC_AMP_GET_INPUT;
Takashi Iwai3e289f12005-06-10 19:45:09 +020077 for (i = 0; i < indices; i++) {
78 snd_iprintf(buffer, " [");
79 if (stereo) {
80 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_AMP_GAIN_MUTE,
81 AC_AMP_GET_LEFT | dir | i);
82 snd_iprintf(buffer, "0x%02x ", val);
83 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_AMP_GAIN_MUTE,
Takashi Iwai3e289f12005-06-10 19:45:09 +020085 AC_AMP_GET_RIGHT | dir | i);
86 snd_iprintf(buffer, "0x%02x]", val);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
Takashi Iwai3e289f12005-06-10 19:45:09 +020088 snd_iprintf(buffer, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Takashi Iwaib90d7762006-11-07 16:10:06 +010091static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
92{
93 static unsigned int rates[] = {
94 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
95 96000, 176400, 192000, 384000
96 };
97 int i;
98
99 pcm &= AC_SUPPCM_RATES;
100 snd_iprintf(buffer, " rates [0x%x]:", pcm);
101 for (i = 0; i < ARRAY_SIZE(rates); i++)
102 if (pcm & (1 << i))
103 snd_iprintf(buffer, " %d", rates[i]);
104 snd_iprintf(buffer, "\n");
105}
106
107static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
108{
109 static unsigned int bits[] = { 8, 16, 20, 24, 32 };
110 int i;
111
112 pcm = (pcm >> 16) & 0xff;
113 snd_iprintf(buffer, " bits [0x%x]:", pcm);
114 for (i = 0; i < ARRAY_SIZE(bits); i++)
115 if (pcm & (1 << i))
116 snd_iprintf(buffer, " %d", bits[i]);
117 snd_iprintf(buffer, "\n");
118}
119
120static void print_pcm_formats(struct snd_info_buffer *buffer,
121 unsigned int streams)
122{
123 snd_iprintf(buffer, " formats [0x%x]:", streams & 0xf);
124 if (streams & AC_SUPFMT_PCM)
125 snd_iprintf(buffer, " PCM");
126 if (streams & AC_SUPFMT_FLOAT32)
127 snd_iprintf(buffer, " FLOAT");
128 if (streams & AC_SUPFMT_AC3)
129 snd_iprintf(buffer, " AC3");
130 snd_iprintf(buffer, "\n");
131}
132
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100133static void print_pcm_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 struct hda_codec *codec, hda_nid_t nid)
135{
136 unsigned int pcm = snd_hda_param_read(codec, nid, AC_PAR_PCM);
137 unsigned int stream = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
138 if (pcm == -1 || stream == -1) {
139 snd_iprintf(buffer, "N/A\n");
140 return;
141 }
Takashi Iwaib90d7762006-11-07 16:10:06 +0100142 print_pcm_rates(buffer, pcm);
143 print_pcm_bits(buffer, pcm);
144 print_pcm_formats(buffer, stream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
147static const char *get_jack_location(u32 cfg)
148{
149 static char *bases[7] = {
150 "N/A", "Rear", "Front", "Left", "Right", "Top", "Bottom",
151 };
152 static unsigned char specials_idx[] = {
153 0x07, 0x08,
154 0x17, 0x18, 0x19,
155 0x37, 0x38
156 };
157 static char *specials[] = {
158 "Rear Panel", "Drive Bar",
159 "Riser", "HDMI", "ATAPI",
160 "Mobile-In", "Mobile-Out"
161 };
162 int i;
163 cfg = (cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT;
164 if ((cfg & 0x0f) < 7)
165 return bases[cfg & 0x0f];
166 for (i = 0; i < ARRAY_SIZE(specials_idx); i++) {
167 if (cfg == specials_idx[i])
168 return specials[i];
169 }
170 return "UNKNOWN";
171}
172
173static const char *get_jack_connection(u32 cfg)
174{
175 static char *names[16] = {
176 "Unknown", "1/8", "1/4", "ATAPI",
177 "RCA", "Optical","Digital", "Analog",
178 "DIN", "XLR", "RJ11", "Comb",
179 NULL, NULL, NULL, "Other"
180 };
181 cfg = (cfg & AC_DEFCFG_CONN_TYPE) >> AC_DEFCFG_CONN_TYPE_SHIFT;
182 if (names[cfg])
183 return names[cfg];
184 else
185 return "UNKNOWN";
186}
187
188static const char *get_jack_color(u32 cfg)
189{
190 static char *names[16] = {
191 "Unknown", "Black", "Grey", "Blue",
192 "Green", "Red", "Orange", "Yellow",
193 "Purple", "Pink", NULL, NULL,
194 NULL, NULL, "White", "Other",
195 };
196 cfg = (cfg & AC_DEFCFG_COLOR) >> AC_DEFCFG_COLOR_SHIFT;
197 if (names[cfg])
198 return names[cfg];
199 else
200 return "UNKNOWN";
201}
202
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100203static void print_pin_caps(struct snd_info_buffer *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 struct hda_codec *codec, hda_nid_t nid)
205{
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200206 static char *jack_conns[4] = { "Jack", "N/A", "Fixed", "Both" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 static char *jack_types[16] = {
208 "Line Out", "Speaker", "HP Out", "CD",
209 "SPDIF Out", "Digital Out", "Modem Line", "Modem Hand",
210 "Line In", "Aux", "Mic", "Telephony",
211 "SPDIF In", "Digitial In", "Reserved", "Other"
212 };
213 static char *jack_locations[4] = { "Ext", "Int", "Sep", "Oth" };
214 unsigned int caps;
215
216 caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
217 snd_iprintf(buffer, " Pincap 0x08%x:", caps);
218 if (caps & AC_PINCAP_IN)
219 snd_iprintf(buffer, " IN");
220 if (caps & AC_PINCAP_OUT)
221 snd_iprintf(buffer, " OUT");
222 if (caps & AC_PINCAP_HP_DRV)
223 snd_iprintf(buffer, " HP");
Takashi Iwai58854922006-06-21 19:19:25 +0200224 if (caps & AC_PINCAP_EAPD)
225 snd_iprintf(buffer, " EAPD");
226 if (caps & AC_PINCAP_PRES_DETECT)
227 snd_iprintf(buffer, " Detect");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 snd_iprintf(buffer, "\n");
229 caps = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
Takashi Iwaib0c95f52005-04-20 13:44:08 +0200230 snd_iprintf(buffer, " Pin Default 0x%08x: [%s] %s at %s %s\n", caps,
231 jack_conns[(caps & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 jack_types[(caps & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT],
233 jack_locations[(caps >> (AC_DEFCFG_LOCATION_SHIFT + 4)) & 3],
234 get_jack_location(caps));
235 snd_iprintf(buffer, " Conn = %s, Color = %s\n",
236 get_jack_connection(caps),
237 get_jack_color(caps));
238}
239
240
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100241static void print_codec_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
243 struct hda_codec *codec = entry->private_data;
244 char buf[32];
245 hda_nid_t nid;
246 int i, nodes;
247
248 snd_hda_get_codec_name(codec, buf, sizeof(buf));
249 snd_iprintf(buffer, "Codec: %s\n", buf);
250 snd_iprintf(buffer, "Address: %d\n", codec->addr);
251 snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
252 snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);
253 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
Takashi Iwaiec9e1c52005-09-07 13:29:22 +0200254 if (! codec->afg)
255 return;
Takashi Iwaib90d7762006-11-07 16:10:06 +0100256 snd_iprintf(buffer, "Default PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 print_pcm_caps(buffer, codec, codec->afg);
258 snd_iprintf(buffer, "Default Amp-In caps: ");
259 print_amp_caps(buffer, codec, codec->afg, HDA_INPUT);
260 snd_iprintf(buffer, "Default Amp-Out caps: ");
261 print_amp_caps(buffer, codec, codec->afg, HDA_OUTPUT);
262
263 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
264 if (! nid || nodes < 0) {
265 snd_iprintf(buffer, "Invalid AFG subtree\n");
266 return;
267 }
268 for (i = 0; i < nodes; i++, nid++) {
269 unsigned int wid_caps = snd_hda_param_read(codec, nid,
270 AC_PAR_AUDIO_WIDGET_CAP);
271 unsigned int wid_type = (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Takashi Iwai3e289f12005-06-10 19:45:09 +0200272 int conn_len = 0;
273 hda_nid_t conn[HDA_MAX_CONNECTIONS];
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 snd_iprintf(buffer, "Node 0x%02x [%s] wcaps 0x%x:", nid,
276 get_wid_type_name(wid_type), wid_caps);
277 if (wid_caps & AC_WCAP_STEREO)
278 snd_iprintf(buffer, " Stereo");
279 else
280 snd_iprintf(buffer, " Mono");
281 if (wid_caps & AC_WCAP_DIGITAL)
282 snd_iprintf(buffer, " Digital");
283 if (wid_caps & AC_WCAP_IN_AMP)
284 snd_iprintf(buffer, " Amp-In");
285 if (wid_caps & AC_WCAP_OUT_AMP)
286 snd_iprintf(buffer, " Amp-Out");
287 snd_iprintf(buffer, "\n");
288
Takashi Iwai3e289f12005-06-10 19:45:09 +0200289 if (wid_caps & AC_WCAP_CONN_LIST)
290 conn_len = snd_hda_get_connections(codec, nid, conn,
291 HDA_MAX_CONNECTIONS);
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (wid_caps & AC_WCAP_IN_AMP) {
294 snd_iprintf(buffer, " Amp-In caps: ");
295 print_amp_caps(buffer, codec, nid, HDA_INPUT);
296 snd_iprintf(buffer, " Amp-In vals: ");
297 print_amp_vals(buffer, codec, nid, HDA_INPUT,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200298 wid_caps & AC_WCAP_STEREO, conn_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
300 if (wid_caps & AC_WCAP_OUT_AMP) {
301 snd_iprintf(buffer, " Amp-Out caps: ");
302 print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
303 snd_iprintf(buffer, " Amp-Out vals: ");
304 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
Takashi Iwai3e289f12005-06-10 19:45:09 +0200305 wid_caps & AC_WCAP_STEREO, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307
308 if (wid_type == AC_WID_PIN) {
309 unsigned int pinctls;
310 print_pin_caps(buffer, codec, nid);
311 pinctls = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
312 snd_iprintf(buffer, " Pin-ctls: 0x%02x:", pinctls);
313 if (pinctls & AC_PINCTL_IN_EN)
314 snd_iprintf(buffer, " IN");
315 if (pinctls & AC_PINCTL_OUT_EN)
316 snd_iprintf(buffer, " OUT");
317 if (pinctls & AC_PINCTL_HP_EN)
318 snd_iprintf(buffer, " HP");
319 snd_iprintf(buffer, "\n");
320 }
321
322 if ((wid_type == AC_WID_AUD_OUT || wid_type == AC_WID_AUD_IN) &&
323 (wid_caps & AC_WCAP_FORMAT_OVRD)) {
Takashi Iwaib90d7762006-11-07 16:10:06 +0100324 snd_iprintf(buffer, " PCM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 print_pcm_caps(buffer, codec, nid);
326 }
327
Takashi Iwaib7027cc2005-11-02 18:13:41 +0100328 if (wid_caps & AC_WCAP_POWER)
329 snd_iprintf(buffer, " Power: 0x%x\n",
330 snd_hda_codec_read(codec, nid, 0,
331 AC_VERB_GET_POWER_STATE, 0));
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if (wid_caps & AC_WCAP_CONN_LIST) {
Takashi Iwai3e289f12005-06-10 19:45:09 +0200334 int c, curr = -1;
ChenLi Tienc3010982005-03-24 12:02:54 +0100335 if (conn_len > 1 && wid_type != AC_WID_AUD_MIX)
336 curr = snd_hda_codec_read(codec, nid, 0,
337 AC_VERB_GET_CONNECT_SEL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 snd_iprintf(buffer, " Connection: %d\n", conn_len);
339 snd_iprintf(buffer, " ");
ChenLi Tienc3010982005-03-24 12:02:54 +0100340 for (c = 0; c < conn_len; c++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 snd_iprintf(buffer, " 0x%02x", conn[c]);
ChenLi Tienc3010982005-03-24 12:02:54 +0100342 if (c == curr)
343 snd_iprintf(buffer, "*");
344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 snd_iprintf(buffer, "\n");
346 }
347 }
348}
349
350/*
351 * create a proc read
352 */
353int snd_hda_codec_proc_new(struct hda_codec *codec)
354{
355 char name[32];
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100356 struct snd_info_entry *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 int err;
358
359 snprintf(name, sizeof(name), "codec#%d", codec->addr);
360 err = snd_card_proc_new(codec->bus->card, name, &entry);
361 if (err < 0)
362 return err;
363
Takashi Iwaibf850202006-04-28 15:13:41 +0200364 snd_info_set_text_ops(entry, codec, print_codec_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 return 0;
366}
367