blob: 65745e96dc701d91cb5bcbf31b883e80f53791e9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * Generic widget tree parser
5 *
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
7 *
8 * This driver is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This driver is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
24#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <sound/core.h>
26#include "hda_codec.h"
27#include "hda_local.h"
28
29/* widget node for parsing */
30struct hda_gnode {
31 hda_nid_t nid; /* NID of this widget */
32 unsigned short nconns; /* number of input connections */
Takashi Iwaid2569502005-11-21 16:33:51 +010033 hda_nid_t *conn_list;
34 hda_nid_t slist[2]; /* temporay list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 unsigned int wid_caps; /* widget capabilities */
36 unsigned char type; /* widget type */
37 unsigned char pin_ctl; /* pin controls */
38 unsigned char checked; /* the flag indicates that the node is already parsed */
39 unsigned int pin_caps; /* pin widget capabilities */
40 unsigned int def_cfg; /* default configuration */
41 unsigned int amp_out_caps; /* AMP out capabilities */
42 unsigned int amp_in_caps; /* AMP in capabilities */
43 struct list_head list;
44};
45
Takashi Iwaic3132922005-04-20 13:43:00 +020046/* patch-specific record */
Takashi Iwaia7da6ce2006-09-06 14:03:14 +020047
48#define MAX_PCM_VOLS 2
49struct pcm_vol {
50 struct hda_gnode *node; /* Node for PCM volume */
51 unsigned int index; /* connection of PCM volume */
52};
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054struct hda_gspec {
Takashi Iwai97ec5582006-03-21 11:29:07 +010055 struct hda_gnode *dac_node[2]; /* DAC node */
56 struct hda_gnode *out_pin_node[2]; /* Output pin (Line-Out) node */
Takashi Iwaia7da6ce2006-09-06 14:03:14 +020057 struct pcm_vol pcm_vol[MAX_PCM_VOLS]; /* PCM volumes */
58 unsigned int pcm_vol_nodes; /* number of PCM volumes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 struct hda_gnode *adc_node; /* ADC node */
61 struct hda_gnode *cap_vol_node; /* Node for capture volume */
62 unsigned int cur_cap_src; /* current capture source */
63 struct hda_input_mux input_mux;
64 char cap_labels[HDA_MAX_NUM_INPUTS][16];
65
66 unsigned int def_amp_in_caps;
67 unsigned int def_amp_out_caps;
68
69 struct hda_pcm pcm_rec; /* PCM information */
70
71 struct list_head nid_list; /* list of widgets */
Takashi Iwaicb53c622007-08-10 17:21:45 +020072
73#ifdef CONFIG_SND_HDA_POWER_SAVE
74#define MAX_LOOPBACK_AMPS 7
75 struct hda_loopback_check loopback;
76 int num_loopbacks;
77 struct hda_amp_list loopback_list[MAX_LOOPBACK_AMPS + 1];
78#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070079};
80
81/*
82 * retrieve the default device type from the default config value
83 */
Takashi Iwai97ec5582006-03-21 11:29:07 +010084#define defcfg_type(node) (((node)->def_cfg & AC_DEFCFG_DEVICE) >> \
85 AC_DEFCFG_DEVICE_SHIFT)
86#define defcfg_location(node) (((node)->def_cfg & AC_DEFCFG_LOCATION) >> \
87 AC_DEFCFG_LOCATION_SHIFT)
88#define defcfg_port_conn(node) (((node)->def_cfg & AC_DEFCFG_PORT_CONN) >> \
89 AC_DEFCFG_PORT_CONN_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/*
92 * destructor
93 */
94static void snd_hda_generic_free(struct hda_codec *codec)
95{
96 struct hda_gspec *spec = codec->spec;
Matthias Kaehlcke33206e82007-09-17 14:40:04 +020097 struct hda_gnode *node, *n;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 if (! spec)
100 return;
101 /* free all widgets */
Matthias Kaehlcke33206e82007-09-17 14:40:04 +0200102 list_for_each_entry_safe(node, n, &spec->nid_list, list) {
Takashi Iwaid2569502005-11-21 16:33:51 +0100103 if (node->conn_list != node->slist)
104 kfree(node->conn_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 kfree(node);
106 }
107 kfree(spec);
108}
109
110
111/*
112 * add a new widget node and read its attributes
113 */
114static int add_new_node(struct hda_codec *codec, struct hda_gspec *spec, hda_nid_t nid)
115{
116 struct hda_gnode *node;
117 int nconns;
Takashi Iwaid2569502005-11-21 16:33:51 +0100118 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200120 node = kzalloc(sizeof(*node), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (node == NULL)
122 return -ENOMEM;
123 node->nid = nid;
Takashi Iwaid2569502005-11-21 16:33:51 +0100124 nconns = snd_hda_get_connections(codec, nid, conn_list,
125 HDA_MAX_CONNECTIONS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 if (nconns < 0) {
127 kfree(node);
128 return nconns;
129 }
Takashi Iwaid2569502005-11-21 16:33:51 +0100130 if (nconns <= ARRAY_SIZE(node->slist))
131 node->conn_list = node->slist;
132 else {
133 node->conn_list = kmalloc(sizeof(hda_nid_t) * nconns,
134 GFP_KERNEL);
135 if (! node->conn_list) {
136 snd_printk(KERN_ERR "hda-generic: cannot malloc\n");
137 kfree(node);
138 return -ENOMEM;
139 }
140 }
Takashi Iwai0bbed752007-05-08 15:17:15 +0200141 memcpy(node->conn_list, conn_list, nconns * sizeof(hda_nid_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 node->nconns = nconns;
Takashi Iwaid2569502005-11-21 16:33:51 +0100143 node->wid_caps = get_wcaps(codec, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 node->type = (node->wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
145
146 if (node->type == AC_WID_PIN) {
147 node->pin_caps = snd_hda_param_read(codec, node->nid, AC_PAR_PIN_CAP);
148 node->pin_ctl = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
149 node->def_cfg = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
150 }
151
152 if (node->wid_caps & AC_WCAP_OUT_AMP) {
153 if (node->wid_caps & AC_WCAP_AMP_OVRD)
154 node->amp_out_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_OUT_CAP);
155 if (! node->amp_out_caps)
156 node->amp_out_caps = spec->def_amp_out_caps;
157 }
158 if (node->wid_caps & AC_WCAP_IN_AMP) {
159 if (node->wid_caps & AC_WCAP_AMP_OVRD)
160 node->amp_in_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_IN_CAP);
161 if (! node->amp_in_caps)
162 node->amp_in_caps = spec->def_amp_in_caps;
163 }
164 list_add_tail(&node->list, &spec->nid_list);
165 return 0;
166}
167
168/*
169 * build the AFG subtree
170 */
171static int build_afg_tree(struct hda_codec *codec)
172{
173 struct hda_gspec *spec = codec->spec;
174 int i, nodes, err;
175 hda_nid_t nid;
176
Takashi Iwaida3cec32008-08-08 17:12:14 +0200177 if (snd_BUG_ON(!spec))
178 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP);
181 spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP);
182
183 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
184 if (! nid || nodes < 0) {
185 printk(KERN_ERR "Invalid AFG subtree\n");
186 return -EINVAL;
187 }
188
189 /* parse all nodes belonging to the AFG */
190 for (i = 0; i < nodes; i++, nid++) {
191 if ((err = add_new_node(codec, spec, nid)) < 0)
192 return err;
193 }
194
195 return 0;
196}
197
198
199/*
200 * look for the node record for the given NID
201 */
202/* FIXME: should avoid the braindead linear search */
203static struct hda_gnode *hda_get_node(struct hda_gspec *spec, hda_nid_t nid)
204{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 struct hda_gnode *node;
206
Matthias Kaehlcke33206e82007-09-17 14:40:04 +0200207 list_for_each_entry(node, &spec->nid_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 if (node->nid == nid)
209 return node;
210 }
211 return NULL;
212}
213
214/*
215 * unmute (and set max vol) the output amplifier
216 */
217static int unmute_output(struct hda_codec *codec, struct hda_gnode *node)
218{
219 unsigned int val, ofs;
220 snd_printdd("UNMUTE OUT: NID=0x%x\n", node->nid);
221 val = (node->amp_out_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
222 ofs = (node->amp_out_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
223 if (val >= ofs)
224 val -= ofs;
Takashi Iwai47fd8302007-08-10 17:11:07 +0200225 snd_hda_codec_amp_stereo(codec, node->nid, HDA_OUTPUT, 0, 0xff, val);
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229/*
230 * unmute (and set max vol) the input amplifier
231 */
232static int unmute_input(struct hda_codec *codec, struct hda_gnode *node, unsigned int index)
233{
234 unsigned int val, ofs;
235 snd_printdd("UNMUTE IN: NID=0x%x IDX=0x%x\n", node->nid, index);
236 val = (node->amp_in_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
237 ofs = (node->amp_in_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
238 if (val >= ofs)
239 val -= ofs;
Takashi Iwai47fd8302007-08-10 17:11:07 +0200240 snd_hda_codec_amp_stereo(codec, node->nid, HDA_INPUT, index, 0xff, val);
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200241 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
244/*
245 * select the input connection of the given node.
246 */
247static int select_input_connection(struct hda_codec *codec, struct hda_gnode *node,
248 unsigned int index)
249{
250 snd_printdd("CONNECT: NID=0x%x IDX=0x%x\n", node->nid, index);
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200251 return snd_hda_codec_write_cache(codec, node->nid, 0,
252 AC_VERB_SET_CONNECT_SEL, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255/*
256 * clear checked flag of each node in the node list
257 */
258static void clear_check_flags(struct hda_gspec *spec)
259{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 struct hda_gnode *node;
261
Matthias Kaehlcke33206e82007-09-17 14:40:04 +0200262 list_for_each_entry(node, &spec->nid_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 node->checked = 0;
264 }
265}
266
267/*
268 * parse the output path recursively until reach to an audio output widget
269 *
270 * returns 0 if not found, 1 if found, or a negative error code.
271 */
272static int parse_output_path(struct hda_codec *codec, struct hda_gspec *spec,
Takashi Iwai97ec5582006-03-21 11:29:07 +0100273 struct hda_gnode *node, int dac_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 int i, err;
276 struct hda_gnode *child;
277
278 if (node->checked)
279 return 0;
280
281 node->checked = 1;
282 if (node->type == AC_WID_AUD_OUT) {
283 if (node->wid_caps & AC_WCAP_DIGITAL) {
284 snd_printdd("Skip Digital OUT node %x\n", node->nid);
285 return 0;
286 }
287 snd_printdd("AUD_OUT found %x\n", node->nid);
Takashi Iwai97ec5582006-03-21 11:29:07 +0100288 if (spec->dac_node[dac_idx]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* already DAC node is assigned, just unmute & connect */
Takashi Iwai97ec5582006-03-21 11:29:07 +0100290 return node == spec->dac_node[dac_idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
Takashi Iwai97ec5582006-03-21 11:29:07 +0100292 spec->dac_node[dac_idx] = node;
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200293 if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
294 spec->pcm_vol_nodes < MAX_PCM_VOLS) {
295 spec->pcm_vol[spec->pcm_vol_nodes].node = node;
296 spec->pcm_vol[spec->pcm_vol_nodes].index = 0;
297 spec->pcm_vol_nodes++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299 return 1; /* found */
300 }
301
302 for (i = 0; i < node->nconns; i++) {
303 child = hda_get_node(spec, node->conn_list[i]);
304 if (! child)
305 continue;
Takashi Iwai97ec5582006-03-21 11:29:07 +0100306 err = parse_output_path(codec, spec, child, dac_idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (err < 0)
308 return err;
309 else if (err > 0) {
310 /* found one,
311 * select the path, unmute both input and output
312 */
313 if (node->nconns > 1)
314 select_input_connection(codec, node, i);
315 unmute_input(codec, node, i);
316 unmute_output(codec, node);
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200317 if (spec->dac_node[dac_idx] &&
318 spec->pcm_vol_nodes < MAX_PCM_VOLS &&
319 !(spec->dac_node[dac_idx]->wid_caps &
320 AC_WCAP_OUT_AMP)) {
321 if ((node->wid_caps & AC_WCAP_IN_AMP) ||
322 (node->wid_caps & AC_WCAP_OUT_AMP)) {
323 int n = spec->pcm_vol_nodes;
324 spec->pcm_vol[n].node = node;
325 spec->pcm_vol[n].index = i;
326 spec->pcm_vol_nodes++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
328 }
329 return 1;
330 }
331 }
332 return 0;
333}
334
335/*
336 * Look for the output PIN widget with the given jack type
337 * and parse the output path to that PIN.
338 *
339 * Returns the PIN node when the path to DAC is established.
340 */
341static struct hda_gnode *parse_output_jack(struct hda_codec *codec,
342 struct hda_gspec *spec,
343 int jack_type)
344{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 struct hda_gnode *node;
346 int err;
347
Matthias Kaehlcke33206e82007-09-17 14:40:04 +0200348 list_for_each_entry(node, &spec->nid_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (node->type != AC_WID_PIN)
350 continue;
351 /* output capable? */
352 if (! (node->pin_caps & AC_PINCAP_OUT))
353 continue;
Takashi Iwai97ec5582006-03-21 11:29:07 +0100354 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
355 continue; /* unconnected */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 if (jack_type >= 0) {
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200357 if (jack_type != defcfg_type(node))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 continue;
359 if (node->wid_caps & AC_WCAP_DIGITAL)
360 continue; /* skip SPDIF */
361 } else {
362 /* output as default? */
363 if (! (node->pin_ctl & AC_PINCTL_OUT_EN))
364 continue;
365 }
366 clear_check_flags(spec);
Takashi Iwai97ec5582006-03-21 11:29:07 +0100367 err = parse_output_path(codec, spec, node, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if (err < 0)
369 return NULL;
Takashi Iwai97ec5582006-03-21 11:29:07 +0100370 if (! err && spec->out_pin_node[0]) {
371 err = parse_output_path(codec, spec, node, 1);
372 if (err < 0)
373 return NULL;
374 }
375 if (err > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /* unmute the PIN output */
377 unmute_output(codec, node);
378 /* set PIN-Out enable */
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200379 snd_hda_codec_write_cache(codec, node->nid, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200381 AC_PINCTL_OUT_EN |
382 ((node->pin_caps & AC_PINCAP_HP_DRV) ?
383 AC_PINCTL_HP_EN : 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return node;
385 }
386 }
387 return NULL;
388}
389
390
391/*
392 * parse outputs
393 */
394static int parse_output(struct hda_codec *codec)
395{
396 struct hda_gspec *spec = codec->spec;
397 struct hda_gnode *node;
398
399 /*
400 * Look for the output PIN widget
401 */
402 /* first, look for the line-out pin */
403 node = parse_output_jack(codec, spec, AC_JACK_LINE_OUT);
404 if (node) /* found, remember the PIN node */
Takashi Iwai97ec5582006-03-21 11:29:07 +0100405 spec->out_pin_node[0] = node;
406 else {
407 /* if no line-out is found, try speaker out */
408 node = parse_output_jack(codec, spec, AC_JACK_SPEAKER);
409 if (node)
410 spec->out_pin_node[0] = node;
411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* look for the HP-out pin */
413 node = parse_output_jack(codec, spec, AC_JACK_HP_OUT);
414 if (node) {
Takashi Iwai97ec5582006-03-21 11:29:07 +0100415 if (! spec->out_pin_node[0])
416 spec->out_pin_node[0] = node;
417 else
418 spec->out_pin_node[1] = node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420
Takashi Iwai97ec5582006-03-21 11:29:07 +0100421 if (! spec->out_pin_node[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /* no line-out or HP pins found,
423 * then choose for the first output pin
424 */
Takashi Iwai97ec5582006-03-21 11:29:07 +0100425 spec->out_pin_node[0] = parse_output_jack(codec, spec, -1);
426 if (! spec->out_pin_node[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 snd_printd("hda_generic: no proper output path found\n");
428 }
429
430 return 0;
431}
432
433/*
434 * input MUX
435 */
436
437/* control callbacks */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100438static int capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
441 struct hda_gspec *spec = codec->spec;
442 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
443}
444
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100445static int capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
447 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
448 struct hda_gspec *spec = codec->spec;
449
450 ucontrol->value.enumerated.item[0] = spec->cur_cap_src;
451 return 0;
452}
453
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100454static int capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
457 struct hda_gspec *spec = codec->spec;
458 return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol,
459 spec->adc_node->nid, &spec->cur_cap_src);
460}
461
462/*
463 * return the string name of the given input PIN widget
464 */
465static const char *get_input_type(struct hda_gnode *node, unsigned int *pinctl)
466{
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200467 unsigned int location = defcfg_location(node);
468 switch (defcfg_type(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 case AC_JACK_LINE_IN:
470 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
471 return "Front Line";
472 return "Line";
473 case AC_JACK_CD:
Takashi Iwai071c73a2006-08-23 18:34:06 +0200474#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 if (pinctl)
Matt1a12de1e2005-04-13 14:37:50 +0200476 *pinctl |= AC_PINCTL_VREF_GRD;
Takashi Iwai071c73a2006-08-23 18:34:06 +0200477#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 return "CD";
479 case AC_JACK_AUX:
480 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
481 return "Front Aux";
482 return "Aux";
483 case AC_JACK_MIC_IN:
Takashi Iwai6afeb112006-12-18 16:16:04 +0100484 if (pinctl &&
485 (node->pin_caps &
486 (AC_PINCAP_VREF_80 << AC_PINCAP_VREF_SHIFT)))
Takashi Iwai071c73a2006-08-23 18:34:06 +0200487 *pinctl |= AC_PINCTL_VREF_80;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
489 return "Front Mic";
490 return "Mic";
491 case AC_JACK_SPDIF_IN:
492 return "SPDIF";
493 case AC_JACK_DIG_OTHER_IN:
494 return "Digital";
495 }
496 return NULL;
497}
498
499/*
500 * parse the nodes recursively until reach to the input PIN
501 *
502 * returns 0 if not found, 1 if found, or a negative error code.
503 */
504static int parse_adc_sub_nodes(struct hda_codec *codec, struct hda_gspec *spec,
505 struct hda_gnode *node)
506{
507 int i, err;
508 unsigned int pinctl;
509 char *label;
510 const char *type;
511
512 if (node->checked)
513 return 0;
514
515 node->checked = 1;
516 if (node->type != AC_WID_PIN) {
517 for (i = 0; i < node->nconns; i++) {
518 struct hda_gnode *child;
519 child = hda_get_node(spec, node->conn_list[i]);
520 if (! child)
521 continue;
522 err = parse_adc_sub_nodes(codec, spec, child);
523 if (err < 0)
524 return err;
525 if (err > 0) {
526 /* found one,
527 * select the path, unmute both input and output
528 */
529 if (node->nconns > 1)
530 select_input_connection(codec, node, i);
531 unmute_input(codec, node, i);
532 unmute_output(codec, node);
533 return err;
534 }
535 }
536 return 0;
537 }
538
539 /* input capable? */
540 if (! (node->pin_caps & AC_PINCAP_IN))
541 return 0;
542
Takashi Iwai97ec5582006-03-21 11:29:07 +0100543 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
544 return 0; /* unconnected */
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 if (node->wid_caps & AC_WCAP_DIGITAL)
547 return 0; /* skip SPDIF */
548
549 if (spec->input_mux.num_items >= HDA_MAX_NUM_INPUTS) {
550 snd_printk(KERN_ERR "hda_generic: Too many items for capture\n");
551 return -EINVAL;
552 }
553
554 pinctl = AC_PINCTL_IN_EN;
555 /* create a proper capture source label */
556 type = get_input_type(node, &pinctl);
557 if (! type) {
558 /* input as default? */
559 if (! (node->pin_ctl & AC_PINCTL_IN_EN))
560 return 0;
561 type = "Input";
562 }
563 label = spec->cap_labels[spec->input_mux.num_items];
564 strcpy(label, type);
565 spec->input_mux.items[spec->input_mux.num_items].label = label;
566
567 /* unmute the PIN external input */
568 unmute_input(codec, node, 0); /* index = 0? */
569 /* set PIN-In enable */
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200570 snd_hda_codec_write_cache(codec, node->nid, 0,
571 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 return 1; /* found */
574}
575
Takashi Iwai071c73a2006-08-23 18:34:06 +0200576/* add a capture source element */
577static void add_cap_src(struct hda_gspec *spec, int idx)
578{
579 struct hda_input_mux_item *csrc;
580 char *buf;
581 int num, ocap;
582
583 num = spec->input_mux.num_items;
584 csrc = &spec->input_mux.items[num];
585 buf = spec->cap_labels[num];
586 for (ocap = 0; ocap < num; ocap++) {
587 if (! strcmp(buf, spec->cap_labels[ocap])) {
588 /* same label already exists,
589 * put the index number to be unique
590 */
591 sprintf(buf, "%s %d", spec->cap_labels[ocap], num);
592 break;
593 }
594 }
595 csrc->index = idx;
596 spec->input_mux.num_items++;
597}
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599/*
600 * parse input
601 */
602static int parse_input_path(struct hda_codec *codec, struct hda_gnode *adc_node)
603{
604 struct hda_gspec *spec = codec->spec;
605 struct hda_gnode *node;
606 int i, err;
607
608 snd_printdd("AUD_IN = %x\n", adc_node->nid);
609 clear_check_flags(spec);
610
611 // awk added - fixed no recording due to muted widget
612 unmute_input(codec, adc_node, 0);
613
614 /*
615 * check each connection of the ADC
616 * if it reaches to a proper input PIN, add the path as the
617 * input path.
618 */
Takashi Iwai071c73a2006-08-23 18:34:06 +0200619 /* first, check the direct connections to PIN widgets */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 for (i = 0; i < adc_node->nconns; i++) {
621 node = hda_get_node(spec, adc_node->conn_list[i]);
Takashi Iwai071c73a2006-08-23 18:34:06 +0200622 if (node && node->type == AC_WID_PIN) {
623 err = parse_adc_sub_nodes(codec, spec, node);
624 if (err < 0)
625 return err;
626 else if (err > 0)
627 add_cap_src(spec, i);
628 }
629 }
630 /* ... then check the rests, more complicated connections */
631 for (i = 0; i < adc_node->nconns; i++) {
632 node = hda_get_node(spec, adc_node->conn_list[i]);
633 if (node && node->type != AC_WID_PIN) {
634 err = parse_adc_sub_nodes(codec, spec, node);
635 if (err < 0)
636 return err;
637 else if (err > 0)
638 add_cap_src(spec, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640 }
641
642 if (! spec->input_mux.num_items)
643 return 0; /* no input path found... */
644
645 snd_printdd("[Capture Source] NID=0x%x, #SRC=%d\n", adc_node->nid, spec->input_mux.num_items);
646 for (i = 0; i < spec->input_mux.num_items; i++)
647 snd_printdd(" [%s] IDX=0x%x\n", spec->input_mux.items[i].label,
648 spec->input_mux.items[i].index);
649
650 spec->adc_node = adc_node;
651 return 1;
652}
653
654/*
655 * parse input
656 */
657static int parse_input(struct hda_codec *codec)
658{
659 struct hda_gspec *spec = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 struct hda_gnode *node;
661 int err;
662
663 /*
664 * At first we look for an audio input widget.
665 * If it reaches to certain input PINs, we take it as the
666 * input path.
667 */
Matthias Kaehlcke33206e82007-09-17 14:40:04 +0200668 list_for_each_entry(node, &spec->nid_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (node->wid_caps & AC_WCAP_DIGITAL)
670 continue; /* skip SPDIF */
671 if (node->type == AC_WID_AUD_IN) {
672 err = parse_input_path(codec, node);
673 if (err < 0)
674 return err;
675 else if (err > 0)
676 return 0;
677 }
678 }
679 snd_printd("hda_generic: no proper input path found\n");
680 return 0;
681}
682
Takashi Iwaicb53c622007-08-10 17:21:45 +0200683#ifdef CONFIG_SND_HDA_POWER_SAVE
684static void add_input_loopback(struct hda_codec *codec, hda_nid_t nid,
685 int dir, int idx)
686{
687 struct hda_gspec *spec = codec->spec;
688 struct hda_amp_list *p;
689
690 if (spec->num_loopbacks >= MAX_LOOPBACK_AMPS) {
691 snd_printk(KERN_ERR "hda_generic: Too many loopback ctls\n");
692 return;
693 }
694 p = &spec->loopback_list[spec->num_loopbacks++];
695 p->nid = nid;
696 p->dir = dir;
697 p->idx = idx;
698 spec->loopback.amplist = spec->loopback_list;
699}
700#else
701#define add_input_loopback(codec,nid,dir,idx)
702#endif
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704/*
705 * create mixer controls if possible
706 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200708 unsigned int index, const char *type,
709 const char *dir_sfx, int is_loopback)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
711 char name[32];
712 int err;
713 int created = 0;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100714 struct snd_kcontrol_new knew;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 if (type)
717 sprintf(name, "%s %s Switch", type, dir_sfx);
718 else
719 sprintf(name, "%s Switch", dir_sfx);
720 if ((node->wid_caps & AC_WCAP_IN_AMP) &&
721 (node->amp_in_caps & AC_AMPCAP_MUTE)) {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100722 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT);
Takashi Iwaicb53c622007-08-10 17:21:45 +0200723 if (is_loopback)
724 add_input_loopback(codec, node->nid, HDA_INPUT, index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
Takashi Iwaid13bd412008-07-30 15:01:45 +0200726 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
727 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 return err;
729 created = 1;
730 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
731 (node->amp_out_caps & AC_AMPCAP_MUTE)) {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100732 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT);
Takashi Iwaicb53c622007-08-10 17:21:45 +0200733 if (is_loopback)
734 add_input_loopback(codec, node->nid, HDA_OUTPUT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
Takashi Iwaid13bd412008-07-30 15:01:45 +0200736 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
737 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 return err;
739 created = 1;
740 }
741
742 if (type)
743 sprintf(name, "%s %s Volume", type, dir_sfx);
744 else
745 sprintf(name, "%s Volume", dir_sfx);
746 if ((node->wid_caps & AC_WCAP_IN_AMP) &&
747 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100748 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
Takashi Iwaid13bd412008-07-30 15:01:45 +0200750 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
751 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 return err;
753 created = 1;
754 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
755 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100756 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
Takashi Iwaid13bd412008-07-30 15:01:45 +0200758 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
759 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 return err;
761 created = 1;
762 }
763
764 return created;
765}
766
767/*
768 * check whether the controls with the given name and direction suffix already exist
769 */
770static int check_existing_control(struct hda_codec *codec, const char *type, const char *dir)
771{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100772 struct snd_ctl_elem_id id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 memset(&id, 0, sizeof(id));
774 sprintf(id.name, "%s %s Volume", type, dir);
775 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
776 if (snd_ctl_find_id(codec->bus->card, &id))
777 return 1;
778 sprintf(id.name, "%s %s Switch", type, dir);
779 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
780 if (snd_ctl_find_id(codec->bus->card, &id))
781 return 1;
782 return 0;
783}
784
785/*
786 * build output mixer controls
787 */
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200788static int create_output_mixers(struct hda_codec *codec, const char **names)
789{
790 struct hda_gspec *spec = codec->spec;
791 int i, err;
792
793 for (i = 0; i < spec->pcm_vol_nodes; i++) {
794 err = create_mixer(codec, spec->pcm_vol[i].node,
795 spec->pcm_vol[i].index,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200796 names[i], "Playback", 0);
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200797 if (err < 0)
798 return err;
799 }
800 return 0;
801}
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803static int build_output_controls(struct hda_codec *codec)
804{
805 struct hda_gspec *spec = codec->spec;
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200806 static const char *types_speaker[] = { "Speaker", "Headphone" };
807 static const char *types_line[] = { "Front", "Headphone" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200809 switch (spec->pcm_vol_nodes) {
810 case 1:
811 return create_mixer(codec, spec->pcm_vol[0].node,
812 spec->pcm_vol[0].index,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200813 "Master", "Playback", 0);
Takashi Iwaia7da6ce2006-09-06 14:03:14 +0200814 case 2:
815 if (defcfg_type(spec->out_pin_node[0]) == AC_JACK_SPEAKER)
816 return create_output_mixers(codec, types_speaker);
817 else
818 return create_output_mixers(codec, types_line);
Takashi Iwai97ec5582006-03-21 11:29:07 +0100819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return 0;
821}
822
823/* create capture volume/switch */
824static int build_input_controls(struct hda_codec *codec)
825{
826 struct hda_gspec *spec = codec->spec;
827 struct hda_gnode *adc_node = spec->adc_node;
Takashi Iwai071c73a2006-08-23 18:34:06 +0200828 int i, err;
829 static struct snd_kcontrol_new cap_sel = {
830 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
831 .name = "Capture Source",
832 .info = capture_source_info,
833 .get = capture_source_get,
834 .put = capture_source_put,
835 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Takashi Iwai071c73a2006-08-23 18:34:06 +0200837 if (! adc_node || ! spec->input_mux.num_items)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 return 0; /* not found */
839
Takashi Iwai071c73a2006-08-23 18:34:06 +0200840 spec->cur_cap_src = 0;
841 select_input_connection(codec, adc_node,
842 spec->input_mux.items[0].index);
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /* create capture volume and switch controls if the ADC has an amp */
Takashi Iwai071c73a2006-08-23 18:34:06 +0200845 /* do we have only a single item? */
846 if (spec->input_mux.num_items == 1) {
847 err = create_mixer(codec, adc_node,
848 spec->input_mux.items[0].index,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200849 NULL, "Capture", 0);
Takashi Iwai071c73a2006-08-23 18:34:06 +0200850 if (err < 0)
851 return err;
852 return 0;
853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
855 /* create input MUX if multiple sources are available */
Takashi Iwaid13bd412008-07-30 15:01:45 +0200856 err = snd_hda_ctl_add(codec, snd_ctl_new1(&cap_sel, codec));
857 if (err < 0)
Takashi Iwai071c73a2006-08-23 18:34:06 +0200858 return err;
859
860 /* no volume control? */
861 if (! (adc_node->wid_caps & AC_WCAP_IN_AMP) ||
862 ! (adc_node->amp_in_caps & AC_AMPCAP_NUM_STEPS))
863 return 0;
864
865 for (i = 0; i < spec->input_mux.num_items; i++) {
866 struct snd_kcontrol_new knew;
867 char name[32];
868 sprintf(name, "%s Capture Volume",
869 spec->input_mux.items[i].label);
870 knew = (struct snd_kcontrol_new)
871 HDA_CODEC_VOLUME(name, adc_node->nid,
872 spec->input_mux.items[i].index,
873 HDA_INPUT);
Takashi Iwaid13bd412008-07-30 15:01:45 +0200874 err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
875 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
Takashi Iwai071c73a2006-08-23 18:34:06 +0200878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 return 0;
880}
881
882
883/*
884 * parse the nodes recursively until reach to the output PIN.
885 *
886 * returns 0 - if not found,
887 * 1 - if found, but no mixer is created
888 * 2 - if found and mixer was already created, (just skip)
889 * a negative error code
890 */
891static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec,
892 struct hda_gnode *node, struct hda_gnode *dest_node,
893 const char *type)
894{
895 int i, err;
896
897 if (node->checked)
898 return 0;
899
900 node->checked = 1;
901 if (node == dest_node) {
902 /* loopback connection found */
903 return 1;
904 }
905
906 for (i = 0; i < node->nconns; i++) {
907 struct hda_gnode *child = hda_get_node(spec, node->conn_list[i]);
908 if (! child)
909 continue;
910 err = parse_loopback_path(codec, spec, child, dest_node, type);
911 if (err < 0)
912 return err;
913 else if (err >= 1) {
914 if (err == 1) {
Takashi Iwaicb53c622007-08-10 17:21:45 +0200915 err = create_mixer(codec, node, i, type,
916 "Playback", 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (err < 0)
918 return err;
919 if (err > 0)
920 return 2; /* ok, created */
921 /* not created, maybe in the lower path */
922 err = 1;
923 }
924 /* connect and unmute */
925 if (node->nconns > 1)
926 select_input_connection(codec, node, i);
927 unmute_input(codec, node, i);
928 unmute_output(codec, node);
929 return err;
930 }
931 }
932 return 0;
933}
934
935/*
936 * parse the tree and build the loopback controls
937 */
938static int build_loopback_controls(struct hda_codec *codec)
939{
940 struct hda_gspec *spec = codec->spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 struct hda_gnode *node;
942 int err;
943 const char *type;
944
Takashi Iwai97ec5582006-03-21 11:29:07 +0100945 if (! spec->out_pin_node[0])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 return 0;
947
Matthias Kaehlcke33206e82007-09-17 14:40:04 +0200948 list_for_each_entry(node, &spec->nid_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (node->type != AC_WID_PIN)
950 continue;
951 /* input capable? */
952 if (! (node->pin_caps & AC_PINCAP_IN))
953 return 0;
954 type = get_input_type(node, NULL);
955 if (type) {
956 if (check_existing_control(codec, type, "Playback"))
957 continue;
958 clear_check_flags(spec);
Takashi Iwai97ec5582006-03-21 11:29:07 +0100959 err = parse_loopback_path(codec, spec,
960 spec->out_pin_node[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 node, type);
962 if (err < 0)
963 return err;
964 if (! err)
965 continue;
966 }
967 }
968 return 0;
969}
970
971/*
972 * build mixer controls
973 */
974static int build_generic_controls(struct hda_codec *codec)
975{
976 int err;
977
978 if ((err = build_input_controls(codec)) < 0 ||
979 (err = build_output_controls(codec)) < 0 ||
980 (err = build_loopback_controls(codec)) < 0)
981 return err;
982
983 return 0;
984}
985
986/*
987 * PCM
988 */
989static struct hda_pcm_stream generic_pcm_playback = {
990 .substreams = 1,
991 .channels_min = 2,
992 .channels_max = 2,
993};
994
Takashi Iwai97ec5582006-03-21 11:29:07 +0100995static int generic_pcm2_prepare(struct hda_pcm_stream *hinfo,
996 struct hda_codec *codec,
997 unsigned int stream_tag,
998 unsigned int format,
999 struct snd_pcm_substream *substream)
1000{
1001 struct hda_gspec *spec = codec->spec;
1002
1003 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
1004 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid,
1005 stream_tag, 0, format);
1006 return 0;
1007}
1008
1009static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
1010 struct hda_codec *codec,
1011 struct snd_pcm_substream *substream)
1012{
1013 struct hda_gspec *spec = codec->spec;
1014
Takashi Iwai888afa12008-03-18 09:57:50 +01001015 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1016 snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid);
Takashi Iwai97ec5582006-03-21 11:29:07 +01001017 return 0;
1018}
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020static int build_generic_pcms(struct hda_codec *codec)
1021{
1022 struct hda_gspec *spec = codec->spec;
1023 struct hda_pcm *info = &spec->pcm_rec;
1024
Takashi Iwai97ec5582006-03-21 11:29:07 +01001025 if (! spec->dac_node[0] && ! spec->adc_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 snd_printd("hda_generic: no PCM found\n");
1027 return 0;
1028 }
1029
1030 codec->num_pcms = 1;
1031 codec->pcm_info = info;
1032
1033 info->name = "HDA Generic";
Takashi Iwai97ec5582006-03-21 11:29:07 +01001034 if (spec->dac_node[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 info->stream[0] = generic_pcm_playback;
Takashi Iwai97ec5582006-03-21 11:29:07 +01001036 info->stream[0].nid = spec->dac_node[0]->nid;
1037 if (spec->dac_node[1]) {
1038 info->stream[0].ops.prepare = generic_pcm2_prepare;
1039 info->stream[0].ops.cleanup = generic_pcm2_cleanup;
1040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 }
1042 if (spec->adc_node) {
1043 info->stream[1] = generic_pcm_playback;
1044 info->stream[1].nid = spec->adc_node->nid;
1045 }
1046
1047 return 0;
1048}
1049
Takashi Iwaicb53c622007-08-10 17:21:45 +02001050#ifdef CONFIG_SND_HDA_POWER_SAVE
1051static int generic_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1052{
1053 struct hda_gspec *spec = codec->spec;
1054 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1055}
1056#endif
1057
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059/*
1060 */
1061static struct hda_codec_ops generic_patch_ops = {
1062 .build_controls = build_generic_controls,
1063 .build_pcms = build_generic_pcms,
1064 .free = snd_hda_generic_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02001065#ifdef CONFIG_SND_HDA_POWER_SAVE
1066 .check_power_status = generic_check_power_status,
1067#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068};
1069
1070/*
1071 * the generic parser
1072 */
1073int snd_hda_parse_generic_codec(struct hda_codec *codec)
1074{
1075 struct hda_gspec *spec;
1076 int err;
1077
Sasha Khapyorsky84802f02005-09-13 11:25:54 +02001078 if(!codec->afg)
1079 return 0;
Sasha Khapyorsky673b6832005-08-11 11:00:16 +02001080
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001081 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 if (spec == NULL) {
1083 printk(KERN_ERR "hda_generic: can't allocate spec\n");
1084 return -ENOMEM;
1085 }
1086 codec->spec = spec;
1087 INIT_LIST_HEAD(&spec->nid_list);
1088
1089 if ((err = build_afg_tree(codec)) < 0)
1090 goto error;
1091
1092 if ((err = parse_input(codec)) < 0 ||
1093 (err = parse_output(codec)) < 0)
1094 goto error;
1095
1096 codec->patch_ops = generic_patch_ops;
1097
1098 return 0;
1099
1100 error:
1101 snd_hda_generic_free(codec);
1102 return err;
1103}
Takashi Iwai1289e9e2008-11-27 15:47:11 +01001104EXPORT_SYMBOL(snd_hda_parse_generic_codec);