2 * Universal Interface for Intel High Definition Audio Codec
4 * Generic widget tree parser
6 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
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.
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.
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
23 #include <sound/driver.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <sound/core.h>
28 #include "hda_codec.h"
29 #include "hda_local.h"
31 /* widget node for parsing */
33 hda_nid_t nid; /* NID of this widget */
34 unsigned short nconns; /* number of input connections */
36 hda_nid_t slist[2]; /* temporay list */
37 unsigned int wid_caps; /* widget capabilities */
38 unsigned char type; /* widget type */
39 unsigned char pin_ctl; /* pin controls */
40 unsigned char checked; /* the flag indicates that the node is already parsed */
41 unsigned int pin_caps; /* pin widget capabilities */
42 unsigned int def_cfg; /* default configuration */
43 unsigned int amp_out_caps; /* AMP out capabilities */
44 unsigned int amp_in_caps; /* AMP in capabilities */
45 struct list_head list;
48 /* patch-specific record */
50 struct hda_gnode *dac_node[2]; /* DAC node */
51 struct hda_gnode *out_pin_node[2]; /* Output pin (Line-Out) node */
52 struct hda_gnode *pcm_vol_node[2]; /* Node for PCM volume */
53 unsigned int pcm_vol_index[2]; /* connection of PCM volume */
55 struct hda_gnode *adc_node; /* ADC node */
56 struct hda_gnode *cap_vol_node; /* Node for capture volume */
57 unsigned int cur_cap_src; /* current capture source */
58 struct hda_input_mux input_mux;
59 char cap_labels[HDA_MAX_NUM_INPUTS][16];
61 unsigned int def_amp_in_caps;
62 unsigned int def_amp_out_caps;
64 struct hda_pcm pcm_rec; /* PCM information */
66 struct list_head nid_list; /* list of widgets */
70 * retrieve the default device type from the default config value
72 #define defcfg_type(node) (((node)->def_cfg & AC_DEFCFG_DEVICE) >> \
73 AC_DEFCFG_DEVICE_SHIFT)
74 #define defcfg_location(node) (((node)->def_cfg & AC_DEFCFG_LOCATION) >> \
75 AC_DEFCFG_LOCATION_SHIFT)
76 #define defcfg_port_conn(node) (((node)->def_cfg & AC_DEFCFG_PORT_CONN) >> \
77 AC_DEFCFG_PORT_CONN_SHIFT)
82 static void snd_hda_generic_free(struct hda_codec *codec)
84 struct hda_gspec *spec = codec->spec;
85 struct list_head *p, *n;
89 /* free all widgets */
90 list_for_each_safe(p, n, &spec->nid_list) {
91 struct hda_gnode *node = list_entry(p, struct hda_gnode, list);
92 if (node->conn_list != node->slist)
93 kfree(node->conn_list);
101 * add a new widget node and read its attributes
103 static int add_new_node(struct hda_codec *codec, struct hda_gspec *spec, hda_nid_t nid)
105 struct hda_gnode *node;
107 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
109 node = kzalloc(sizeof(*node), GFP_KERNEL);
113 nconns = snd_hda_get_connections(codec, nid, conn_list,
114 HDA_MAX_CONNECTIONS);
119 if (nconns <= ARRAY_SIZE(node->slist))
120 node->conn_list = node->slist;
122 node->conn_list = kmalloc(sizeof(hda_nid_t) * nconns,
124 if (! node->conn_list) {
125 snd_printk(KERN_ERR "hda-generic: cannot malloc\n");
130 memcpy(node->conn_list, conn_list, nconns);
131 node->nconns = nconns;
132 node->wid_caps = get_wcaps(codec, nid);
133 node->type = (node->wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
135 if (node->type == AC_WID_PIN) {
136 node->pin_caps = snd_hda_param_read(codec, node->nid, AC_PAR_PIN_CAP);
137 node->pin_ctl = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
138 node->def_cfg = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
141 if (node->wid_caps & AC_WCAP_OUT_AMP) {
142 if (node->wid_caps & AC_WCAP_AMP_OVRD)
143 node->amp_out_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_OUT_CAP);
144 if (! node->amp_out_caps)
145 node->amp_out_caps = spec->def_amp_out_caps;
147 if (node->wid_caps & AC_WCAP_IN_AMP) {
148 if (node->wid_caps & AC_WCAP_AMP_OVRD)
149 node->amp_in_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_IN_CAP);
150 if (! node->amp_in_caps)
151 node->amp_in_caps = spec->def_amp_in_caps;
153 list_add_tail(&node->list, &spec->nid_list);
158 * build the AFG subtree
160 static int build_afg_tree(struct hda_codec *codec)
162 struct hda_gspec *spec = codec->spec;
166 snd_assert(spec, return -EINVAL);
168 spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP);
169 spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP);
171 nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
172 if (! nid || nodes < 0) {
173 printk(KERN_ERR "Invalid AFG subtree\n");
177 /* parse all nodes belonging to the AFG */
178 for (i = 0; i < nodes; i++, nid++) {
179 if ((err = add_new_node(codec, spec, nid)) < 0)
188 * look for the node record for the given NID
190 /* FIXME: should avoid the braindead linear search */
191 static struct hda_gnode *hda_get_node(struct hda_gspec *spec, hda_nid_t nid)
194 struct hda_gnode *node;
196 list_for_each(p, &spec->nid_list) {
197 node = list_entry(p, struct hda_gnode, list);
198 if (node->nid == nid)
205 * unmute (and set max vol) the output amplifier
207 static int unmute_output(struct hda_codec *codec, struct hda_gnode *node)
209 unsigned int val, ofs;
210 snd_printdd("UNMUTE OUT: NID=0x%x\n", node->nid);
211 val = (node->amp_out_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
212 ofs = (node->amp_out_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
215 val |= AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT;
216 val |= AC_AMP_SET_OUTPUT;
217 return snd_hda_codec_write(codec, node->nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, val);
221 * unmute (and set max vol) the input amplifier
223 static int unmute_input(struct hda_codec *codec, struct hda_gnode *node, unsigned int index)
225 unsigned int val, ofs;
226 snd_printdd("UNMUTE IN: NID=0x%x IDX=0x%x\n", node->nid, index);
227 val = (node->amp_in_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
228 ofs = (node->amp_in_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
231 val |= AC_AMP_SET_LEFT | AC_AMP_SET_RIGHT;
232 val |= AC_AMP_SET_INPUT;
233 // awk added - fixed to allow unmuting of indexed amps
234 val |= index << AC_AMP_SET_INDEX_SHIFT;
235 return snd_hda_codec_write(codec, node->nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, val);
239 * select the input connection of the given node.
241 static int select_input_connection(struct hda_codec *codec, struct hda_gnode *node,
244 snd_printdd("CONNECT: NID=0x%x IDX=0x%x\n", node->nid, index);
245 return snd_hda_codec_write(codec, node->nid, 0, AC_VERB_SET_CONNECT_SEL, index);
249 * clear checked flag of each node in the node list
251 static void clear_check_flags(struct hda_gspec *spec)
254 struct hda_gnode *node;
256 list_for_each(p, &spec->nid_list) {
257 node = list_entry(p, struct hda_gnode, list);
263 * parse the output path recursively until reach to an audio output widget
265 * returns 0 if not found, 1 if found, or a negative error code.
267 static int parse_output_path(struct hda_codec *codec, struct hda_gspec *spec,
268 struct hda_gnode *node, int dac_idx)
271 struct hda_gnode *child;
277 if (node->type == AC_WID_AUD_OUT) {
278 if (node->wid_caps & AC_WCAP_DIGITAL) {
279 snd_printdd("Skip Digital OUT node %x\n", node->nid);
282 snd_printdd("AUD_OUT found %x\n", node->nid);
283 if (spec->dac_node[dac_idx]) {
284 /* already DAC node is assigned, just unmute & connect */
285 return node == spec->dac_node[dac_idx];
287 spec->dac_node[dac_idx] = node;
288 if (node->wid_caps & AC_WCAP_OUT_AMP) {
289 spec->pcm_vol_node[dac_idx] = node;
290 spec->pcm_vol_index[dac_idx] = 0;
292 return 1; /* found */
295 for (i = 0; i < node->nconns; i++) {
296 child = hda_get_node(spec, node->conn_list[i]);
299 err = parse_output_path(codec, spec, child, dac_idx);
304 * select the path, unmute both input and output
306 if (node->nconns > 1)
307 select_input_connection(codec, node, i);
308 unmute_input(codec, node, i);
309 unmute_output(codec, node);
310 if (! spec->pcm_vol_node[dac_idx]) {
311 if (node->wid_caps & AC_WCAP_IN_AMP) {
312 spec->pcm_vol_node[dac_idx] = node;
313 spec->pcm_vol_index[dac_idx] = i;
314 } else if (node->wid_caps & AC_WCAP_OUT_AMP) {
315 spec->pcm_vol_node[dac_idx] = node;
316 spec->pcm_vol_index[dac_idx] = 0;
326 * Look for the output PIN widget with the given jack type
327 * and parse the output path to that PIN.
329 * Returns the PIN node when the path to DAC is established.
331 static struct hda_gnode *parse_output_jack(struct hda_codec *codec,
332 struct hda_gspec *spec,
336 struct hda_gnode *node;
339 list_for_each(p, &spec->nid_list) {
340 node = list_entry(p, struct hda_gnode, list);
341 if (node->type != AC_WID_PIN)
343 /* output capable? */
344 if (! (node->pin_caps & AC_PINCAP_OUT))
346 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
347 continue; /* unconnected */
348 if (jack_type >= 0) {
349 if (jack_type != defcfg_type(node))
351 if (node->wid_caps & AC_WCAP_DIGITAL)
352 continue; /* skip SPDIF */
354 /* output as default? */
355 if (! (node->pin_ctl & AC_PINCTL_OUT_EN))
358 clear_check_flags(spec);
359 err = parse_output_path(codec, spec, node, 0);
362 if (! err && spec->out_pin_node[0]) {
363 err = parse_output_path(codec, spec, node, 1);
368 /* unmute the PIN output */
369 unmute_output(codec, node);
370 /* set PIN-Out enable */
371 snd_hda_codec_write(codec, node->nid, 0,
372 AC_VERB_SET_PIN_WIDGET_CONTROL,
373 AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
384 static int parse_output(struct hda_codec *codec)
386 struct hda_gspec *spec = codec->spec;
387 struct hda_gnode *node;
390 * Look for the output PIN widget
392 /* first, look for the line-out pin */
393 node = parse_output_jack(codec, spec, AC_JACK_LINE_OUT);
394 if (node) /* found, remember the PIN node */
395 spec->out_pin_node[0] = node;
397 /* if no line-out is found, try speaker out */
398 node = parse_output_jack(codec, spec, AC_JACK_SPEAKER);
400 spec->out_pin_node[0] = node;
402 /* look for the HP-out pin */
403 node = parse_output_jack(codec, spec, AC_JACK_HP_OUT);
405 if (! spec->out_pin_node[0])
406 spec->out_pin_node[0] = node;
408 spec->out_pin_node[1] = node;
411 if (! spec->out_pin_node[0]) {
412 /* no line-out or HP pins found,
413 * then choose for the first output pin
415 spec->out_pin_node[0] = parse_output_jack(codec, spec, -1);
416 if (! spec->out_pin_node[0])
417 snd_printd("hda_generic: no proper output path found\n");
427 /* control callbacks */
428 static int capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
430 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
431 struct hda_gspec *spec = codec->spec;
432 return snd_hda_input_mux_info(&spec->input_mux, uinfo);
435 static int capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
437 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
438 struct hda_gspec *spec = codec->spec;
440 ucontrol->value.enumerated.item[0] = spec->cur_cap_src;
444 static int capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
446 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
447 struct hda_gspec *spec = codec->spec;
448 return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol,
449 spec->adc_node->nid, &spec->cur_cap_src);
453 * return the string name of the given input PIN widget
455 static const char *get_input_type(struct hda_gnode *node, unsigned int *pinctl)
457 unsigned int location = defcfg_location(node);
458 switch (defcfg_type(node)) {
459 case AC_JACK_LINE_IN:
460 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
466 *pinctl |= AC_PINCTL_VREF_GRD;
470 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
475 (AC_PINCAP_VREF_80 << AC_PINCAP_VREF_SHIFT))
476 *pinctl |= AC_PINCTL_VREF_80;
477 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
480 case AC_JACK_SPDIF_IN:
482 case AC_JACK_DIG_OTHER_IN:
489 * parse the nodes recursively until reach to the input PIN
491 * returns 0 if not found, 1 if found, or a negative error code.
493 static int parse_adc_sub_nodes(struct hda_codec *codec, struct hda_gspec *spec,
494 struct hda_gnode *node)
505 if (node->type != AC_WID_PIN) {
506 for (i = 0; i < node->nconns; i++) {
507 struct hda_gnode *child;
508 child = hda_get_node(spec, node->conn_list[i]);
511 err = parse_adc_sub_nodes(codec, spec, child);
516 * select the path, unmute both input and output
518 if (node->nconns > 1)
519 select_input_connection(codec, node, i);
520 unmute_input(codec, node, i);
521 unmute_output(codec, node);
529 if (! (node->pin_caps & AC_PINCAP_IN))
532 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
533 return 0; /* unconnected */
535 if (node->wid_caps & AC_WCAP_DIGITAL)
536 return 0; /* skip SPDIF */
538 if (spec->input_mux.num_items >= HDA_MAX_NUM_INPUTS) {
539 snd_printk(KERN_ERR "hda_generic: Too many items for capture\n");
543 pinctl = AC_PINCTL_IN_EN;
544 /* create a proper capture source label */
545 type = get_input_type(node, &pinctl);
547 /* input as default? */
548 if (! (node->pin_ctl & AC_PINCTL_IN_EN))
552 label = spec->cap_labels[spec->input_mux.num_items];
554 spec->input_mux.items[spec->input_mux.num_items].label = label;
556 /* unmute the PIN external input */
557 unmute_input(codec, node, 0); /* index = 0? */
558 /* set PIN-In enable */
559 snd_hda_codec_write(codec, node->nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
561 return 1; /* found */
564 /* add a capture source element */
565 static void add_cap_src(struct hda_gspec *spec, int idx)
567 struct hda_input_mux_item *csrc;
571 num = spec->input_mux.num_items;
572 csrc = &spec->input_mux.items[num];
573 buf = spec->cap_labels[num];
574 for (ocap = 0; ocap < num; ocap++) {
575 if (! strcmp(buf, spec->cap_labels[ocap])) {
576 /* same label already exists,
577 * put the index number to be unique
579 sprintf(buf, "%s %d", spec->cap_labels[ocap], num);
584 spec->input_mux.num_items++;
590 static int parse_input_path(struct hda_codec *codec, struct hda_gnode *adc_node)
592 struct hda_gspec *spec = codec->spec;
593 struct hda_gnode *node;
596 snd_printdd("AUD_IN = %x\n", adc_node->nid);
597 clear_check_flags(spec);
599 // awk added - fixed no recording due to muted widget
600 unmute_input(codec, adc_node, 0);
603 * check each connection of the ADC
604 * if it reaches to a proper input PIN, add the path as the
607 /* first, check the direct connections to PIN widgets */
608 for (i = 0; i < adc_node->nconns; i++) {
609 node = hda_get_node(spec, adc_node->conn_list[i]);
610 if (node && node->type == AC_WID_PIN) {
611 err = parse_adc_sub_nodes(codec, spec, node);
615 add_cap_src(spec, i);
618 /* ... then check the rests, more complicated connections */
619 for (i = 0; i < adc_node->nconns; i++) {
620 node = hda_get_node(spec, adc_node->conn_list[i]);
621 if (node && node->type != AC_WID_PIN) {
622 err = parse_adc_sub_nodes(codec, spec, node);
626 add_cap_src(spec, i);
630 if (! spec->input_mux.num_items)
631 return 0; /* no input path found... */
633 snd_printdd("[Capture Source] NID=0x%x, #SRC=%d\n", adc_node->nid, spec->input_mux.num_items);
634 for (i = 0; i < spec->input_mux.num_items; i++)
635 snd_printdd(" [%s] IDX=0x%x\n", spec->input_mux.items[i].label,
636 spec->input_mux.items[i].index);
638 spec->adc_node = adc_node;
645 static int parse_input(struct hda_codec *codec)
647 struct hda_gspec *spec = codec->spec;
649 struct hda_gnode *node;
653 * At first we look for an audio input widget.
654 * If it reaches to certain input PINs, we take it as the
657 list_for_each(p, &spec->nid_list) {
658 node = list_entry(p, struct hda_gnode, list);
659 if (node->wid_caps & AC_WCAP_DIGITAL)
660 continue; /* skip SPDIF */
661 if (node->type == AC_WID_AUD_IN) {
662 err = parse_input_path(codec, node);
669 snd_printd("hda_generic: no proper input path found\n");
674 * create mixer controls if possible
676 static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
677 unsigned int index, const char *type, const char *dir_sfx)
682 struct snd_kcontrol_new knew;
685 sprintf(name, "%s %s Switch", type, dir_sfx);
687 sprintf(name, "%s Switch", dir_sfx);
688 if ((node->wid_caps & AC_WCAP_IN_AMP) &&
689 (node->amp_in_caps & AC_AMPCAP_MUTE)) {
690 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT);
691 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
692 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
695 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
696 (node->amp_out_caps & AC_AMPCAP_MUTE)) {
697 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT);
698 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
699 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
705 sprintf(name, "%s %s Volume", type, dir_sfx);
707 sprintf(name, "%s Volume", dir_sfx);
708 if ((node->wid_caps & AC_WCAP_IN_AMP) &&
709 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
710 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
711 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
712 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
715 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
716 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
717 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
718 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
719 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
728 * check whether the controls with the given name and direction suffix already exist
730 static int check_existing_control(struct hda_codec *codec, const char *type, const char *dir)
732 struct snd_ctl_elem_id id;
733 memset(&id, 0, sizeof(id));
734 sprintf(id.name, "%s %s Volume", type, dir);
735 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
736 if (snd_ctl_find_id(codec->bus->card, &id))
738 sprintf(id.name, "%s %s Switch", type, dir);
739 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
740 if (snd_ctl_find_id(codec->bus->card, &id))
746 * build output mixer controls
748 static int build_output_controls(struct hda_codec *codec)
750 struct hda_gspec *spec = codec->spec;
751 static const char *types[2] = { "Master", "Headphone" };
754 for (i = 0; i < 2 && spec->pcm_vol_node[i]; i++) {
755 err = create_mixer(codec, spec->pcm_vol_node[i],
756 spec->pcm_vol_index[i],
757 types[i], "Playback");
764 /* create capture volume/switch */
765 static int build_input_controls(struct hda_codec *codec)
767 struct hda_gspec *spec = codec->spec;
768 struct hda_gnode *adc_node = spec->adc_node;
770 static struct snd_kcontrol_new cap_sel = {
771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
772 .name = "Capture Source",
773 .info = capture_source_info,
774 .get = capture_source_get,
775 .put = capture_source_put,
778 if (! adc_node || ! spec->input_mux.num_items)
779 return 0; /* not found */
781 spec->cur_cap_src = 0;
782 select_input_connection(codec, adc_node,
783 spec->input_mux.items[0].index);
785 /* create capture volume and switch controls if the ADC has an amp */
786 /* do we have only a single item? */
787 if (spec->input_mux.num_items == 1) {
788 err = create_mixer(codec, adc_node,
789 spec->input_mux.items[0].index,
796 /* create input MUX if multiple sources are available */
797 if ((err = snd_ctl_add(codec->bus->card,
798 snd_ctl_new1(&cap_sel, codec))) < 0)
801 /* no volume control? */
802 if (! (adc_node->wid_caps & AC_WCAP_IN_AMP) ||
803 ! (adc_node->amp_in_caps & AC_AMPCAP_NUM_STEPS))
806 for (i = 0; i < spec->input_mux.num_items; i++) {
807 struct snd_kcontrol_new knew;
809 sprintf(name, "%s Capture Volume",
810 spec->input_mux.items[i].label);
811 knew = (struct snd_kcontrol_new)
812 HDA_CODEC_VOLUME(name, adc_node->nid,
813 spec->input_mux.items[i].index,
815 if ((err = snd_ctl_add(codec->bus->card,
816 snd_ctl_new1(&knew, codec))) < 0)
825 * parse the nodes recursively until reach to the output PIN.
827 * returns 0 - if not found,
828 * 1 - if found, but no mixer is created
829 * 2 - if found and mixer was already created, (just skip)
830 * a negative error code
832 static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec,
833 struct hda_gnode *node, struct hda_gnode *dest_node,
842 if (node == dest_node) {
843 /* loopback connection found */
847 for (i = 0; i < node->nconns; i++) {
848 struct hda_gnode *child = hda_get_node(spec, node->conn_list[i]);
851 err = parse_loopback_path(codec, spec, child, dest_node, type);
856 err = create_mixer(codec, node, i, type, "Playback");
860 return 2; /* ok, created */
861 /* not created, maybe in the lower path */
864 /* connect and unmute */
865 if (node->nconns > 1)
866 select_input_connection(codec, node, i);
867 unmute_input(codec, node, i);
868 unmute_output(codec, node);
876 * parse the tree and build the loopback controls
878 static int build_loopback_controls(struct hda_codec *codec)
880 struct hda_gspec *spec = codec->spec;
882 struct hda_gnode *node;
886 if (! spec->out_pin_node[0])
889 list_for_each(p, &spec->nid_list) {
890 node = list_entry(p, struct hda_gnode, list);
891 if (node->type != AC_WID_PIN)
894 if (! (node->pin_caps & AC_PINCAP_IN))
896 type = get_input_type(node, NULL);
898 if (check_existing_control(codec, type, "Playback"))
900 clear_check_flags(spec);
901 err = parse_loopback_path(codec, spec,
902 spec->out_pin_node[0],
914 * build mixer controls
916 static int build_generic_controls(struct hda_codec *codec)
920 if ((err = build_input_controls(codec)) < 0 ||
921 (err = build_output_controls(codec)) < 0 ||
922 (err = build_loopback_controls(codec)) < 0)
931 static struct hda_pcm_stream generic_pcm_playback = {
937 static int generic_pcm2_prepare(struct hda_pcm_stream *hinfo,
938 struct hda_codec *codec,
939 unsigned int stream_tag,
941 struct snd_pcm_substream *substream)
943 struct hda_gspec *spec = codec->spec;
945 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
946 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid,
947 stream_tag, 0, format);
951 static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
952 struct hda_codec *codec,
953 struct snd_pcm_substream *substream)
955 struct hda_gspec *spec = codec->spec;
957 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0);
958 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0);
962 static int build_generic_pcms(struct hda_codec *codec)
964 struct hda_gspec *spec = codec->spec;
965 struct hda_pcm *info = &spec->pcm_rec;
967 if (! spec->dac_node[0] && ! spec->adc_node) {
968 snd_printd("hda_generic: no PCM found\n");
973 codec->pcm_info = info;
975 info->name = "HDA Generic";
976 if (spec->dac_node[0]) {
977 info->stream[0] = generic_pcm_playback;
978 info->stream[0].nid = spec->dac_node[0]->nid;
979 if (spec->dac_node[1]) {
980 info->stream[0].ops.prepare = generic_pcm2_prepare;
981 info->stream[0].ops.cleanup = generic_pcm2_cleanup;
984 if (spec->adc_node) {
985 info->stream[1] = generic_pcm_playback;
986 info->stream[1].nid = spec->adc_node->nid;
995 static struct hda_codec_ops generic_patch_ops = {
996 .build_controls = build_generic_controls,
997 .build_pcms = build_generic_pcms,
998 .free = snd_hda_generic_free,
1002 * the generic parser
1004 int snd_hda_parse_generic_codec(struct hda_codec *codec)
1006 struct hda_gspec *spec;
1012 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1014 printk(KERN_ERR "hda_generic: can't allocate spec\n");
1018 INIT_LIST_HEAD(&spec->nid_list);
1020 if ((err = build_afg_tree(codec)) < 0)
1023 if ((err = parse_input(codec)) < 0 ||
1024 (err = parse_output(codec)) < 0)
1027 codec->patch_ops = generic_patch_ops;
1032 snd_hda_generic_free(codec);