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)
465 *pinctl |= AC_PINCTL_VREF_GRD;
468 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
472 if ((location & 0x0f) == AC_JACK_LOC_FRONT)
475 case AC_JACK_SPDIF_IN:
477 case AC_JACK_DIG_OTHER_IN:
484 * parse the nodes recursively until reach to the input PIN
486 * returns 0 if not found, 1 if found, or a negative error code.
488 static int parse_adc_sub_nodes(struct hda_codec *codec, struct hda_gspec *spec,
489 struct hda_gnode *node)
500 if (node->type != AC_WID_PIN) {
501 for (i = 0; i < node->nconns; i++) {
502 struct hda_gnode *child;
503 child = hda_get_node(spec, node->conn_list[i]);
506 err = parse_adc_sub_nodes(codec, spec, child);
511 * select the path, unmute both input and output
513 if (node->nconns > 1)
514 select_input_connection(codec, node, i);
515 unmute_input(codec, node, i);
516 unmute_output(codec, node);
524 if (! (node->pin_caps & AC_PINCAP_IN))
527 if (defcfg_port_conn(node) == AC_JACK_PORT_NONE)
528 return 0; /* unconnected */
530 if (node->wid_caps & AC_WCAP_DIGITAL)
531 return 0; /* skip SPDIF */
533 if (spec->input_mux.num_items >= HDA_MAX_NUM_INPUTS) {
534 snd_printk(KERN_ERR "hda_generic: Too many items for capture\n");
538 pinctl = AC_PINCTL_IN_EN;
539 /* create a proper capture source label */
540 type = get_input_type(node, &pinctl);
542 /* input as default? */
543 if (! (node->pin_ctl & AC_PINCTL_IN_EN))
547 label = spec->cap_labels[spec->input_mux.num_items];
549 spec->input_mux.items[spec->input_mux.num_items].label = label;
551 /* unmute the PIN external input */
552 unmute_input(codec, node, 0); /* index = 0? */
553 /* set PIN-In enable */
554 snd_hda_codec_write(codec, node->nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
556 return 1; /* found */
562 static int parse_input_path(struct hda_codec *codec, struct hda_gnode *adc_node)
564 struct hda_gspec *spec = codec->spec;
565 struct hda_gnode *node;
568 snd_printdd("AUD_IN = %x\n", adc_node->nid);
569 clear_check_flags(spec);
571 // awk added - fixed no recording due to muted widget
572 unmute_input(codec, adc_node, 0);
575 * check each connection of the ADC
576 * if it reaches to a proper input PIN, add the path as the
579 for (i = 0; i < adc_node->nconns; i++) {
580 node = hda_get_node(spec, adc_node->conn_list[i]);
583 err = parse_adc_sub_nodes(codec, spec, node);
587 struct hda_input_mux_item *csrc = &spec->input_mux.items[spec->input_mux.num_items];
588 char *buf = spec->cap_labels[spec->input_mux.num_items];
590 for (ocap = 0; ocap < spec->input_mux.num_items; ocap++) {
591 if (! strcmp(buf, spec->cap_labels[ocap])) {
592 /* same label already exists,
593 * put the index number to be unique
595 sprintf(buf, "%s %d", spec->cap_labels[ocap],
596 spec->input_mux.num_items);
600 spec->input_mux.num_items++;
604 if (! spec->input_mux.num_items)
605 return 0; /* no input path found... */
607 snd_printdd("[Capture Source] NID=0x%x, #SRC=%d\n", adc_node->nid, spec->input_mux.num_items);
608 for (i = 0; i < spec->input_mux.num_items; i++)
609 snd_printdd(" [%s] IDX=0x%x\n", spec->input_mux.items[i].label,
610 spec->input_mux.items[i].index);
612 spec->adc_node = adc_node;
619 static int parse_input(struct hda_codec *codec)
621 struct hda_gspec *spec = codec->spec;
623 struct hda_gnode *node;
627 * At first we look for an audio input widget.
628 * If it reaches to certain input PINs, we take it as the
631 list_for_each(p, &spec->nid_list) {
632 node = list_entry(p, struct hda_gnode, list);
633 if (node->wid_caps & AC_WCAP_DIGITAL)
634 continue; /* skip SPDIF */
635 if (node->type == AC_WID_AUD_IN) {
636 err = parse_input_path(codec, node);
643 snd_printd("hda_generic: no proper input path found\n");
648 * create mixer controls if possible
653 static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
654 unsigned int index, const char *type, const char *dir_sfx)
659 struct snd_kcontrol_new knew;
662 sprintf(name, "%s %s Switch", type, dir_sfx);
664 sprintf(name, "%s Switch", dir_sfx);
665 if ((node->wid_caps & AC_WCAP_IN_AMP) &&
666 (node->amp_in_caps & AC_AMPCAP_MUTE)) {
667 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT);
668 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
669 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
672 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
673 (node->amp_out_caps & AC_AMPCAP_MUTE)) {
674 knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT);
675 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
676 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
682 sprintf(name, "%s %s Volume", type, dir_sfx);
684 sprintf(name, "%s Volume", dir_sfx);
685 if ((node->wid_caps & AC_WCAP_IN_AMP) &&
686 (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
687 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
688 snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
689 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
692 } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
693 (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
694 knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
695 snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
696 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
705 * check whether the controls with the given name and direction suffix already exist
707 static int check_existing_control(struct hda_codec *codec, const char *type, const char *dir)
709 struct snd_ctl_elem_id id;
710 memset(&id, 0, sizeof(id));
711 sprintf(id.name, "%s %s Volume", type, dir);
712 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
713 if (snd_ctl_find_id(codec->bus->card, &id))
715 sprintf(id.name, "%s %s Switch", type, dir);
716 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
717 if (snd_ctl_find_id(codec->bus->card, &id))
723 * build output mixer controls
725 static int build_output_controls(struct hda_codec *codec)
727 struct hda_gspec *spec = codec->spec;
728 static const char *types[2] = { "Master", "Headphone" };
731 for (i = 0; i < 2 && spec->pcm_vol_node[i]; i++) {
732 err = create_mixer(codec, spec->pcm_vol_node[i],
733 spec->pcm_vol_index[i],
734 types[i], "Playback");
741 /* create capture volume/switch */
742 static int build_input_controls(struct hda_codec *codec)
744 struct hda_gspec *spec = codec->spec;
745 struct hda_gnode *adc_node = spec->adc_node;
749 return 0; /* not found */
751 /* create capture volume and switch controls if the ADC has an amp */
752 err = create_mixer(codec, adc_node, 0, NULL, "Capture");
754 /* create input MUX if multiple sources are available */
755 if (spec->input_mux.num_items > 1) {
756 static struct snd_kcontrol_new cap_sel = {
757 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
758 .name = "Capture Source",
759 .info = capture_source_info,
760 .get = capture_source_get,
761 .put = capture_source_put,
763 if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&cap_sel, codec))) < 0)
765 spec->cur_cap_src = 0;
766 select_input_connection(codec, adc_node, spec->input_mux.items[0].index);
773 * parse the nodes recursively until reach to the output PIN.
775 * returns 0 - if not found,
776 * 1 - if found, but no mixer is created
777 * 2 - if found and mixer was already created, (just skip)
778 * a negative error code
780 static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec,
781 struct hda_gnode *node, struct hda_gnode *dest_node,
790 if (node == dest_node) {
791 /* loopback connection found */
795 for (i = 0; i < node->nconns; i++) {
796 struct hda_gnode *child = hda_get_node(spec, node->conn_list[i]);
799 err = parse_loopback_path(codec, spec, child, dest_node, type);
804 err = create_mixer(codec, node, i, type, "Playback");
808 return 2; /* ok, created */
809 /* not created, maybe in the lower path */
812 /* connect and unmute */
813 if (node->nconns > 1)
814 select_input_connection(codec, node, i);
815 unmute_input(codec, node, i);
816 unmute_output(codec, node);
824 * parse the tree and build the loopback controls
826 static int build_loopback_controls(struct hda_codec *codec)
828 struct hda_gspec *spec = codec->spec;
830 struct hda_gnode *node;
834 if (! spec->out_pin_node[0])
837 list_for_each(p, &spec->nid_list) {
838 node = list_entry(p, struct hda_gnode, list);
839 if (node->type != AC_WID_PIN)
842 if (! (node->pin_caps & AC_PINCAP_IN))
844 type = get_input_type(node, NULL);
846 if (check_existing_control(codec, type, "Playback"))
848 clear_check_flags(spec);
849 err = parse_loopback_path(codec, spec,
850 spec->out_pin_node[0],
862 * build mixer controls
864 static int build_generic_controls(struct hda_codec *codec)
868 if ((err = build_input_controls(codec)) < 0 ||
869 (err = build_output_controls(codec)) < 0 ||
870 (err = build_loopback_controls(codec)) < 0)
879 static struct hda_pcm_stream generic_pcm_playback = {
885 static int generic_pcm2_prepare(struct hda_pcm_stream *hinfo,
886 struct hda_codec *codec,
887 unsigned int stream_tag,
889 struct snd_pcm_substream *substream)
891 struct hda_gspec *spec = codec->spec;
893 snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format);
894 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid,
895 stream_tag, 0, format);
899 static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
900 struct hda_codec *codec,
901 struct snd_pcm_substream *substream)
903 struct hda_gspec *spec = codec->spec;
905 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0);
906 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0);
910 static int build_generic_pcms(struct hda_codec *codec)
912 struct hda_gspec *spec = codec->spec;
913 struct hda_pcm *info = &spec->pcm_rec;
915 if (! spec->dac_node[0] && ! spec->adc_node) {
916 snd_printd("hda_generic: no PCM found\n");
921 codec->pcm_info = info;
923 info->name = "HDA Generic";
924 if (spec->dac_node[0]) {
925 info->stream[0] = generic_pcm_playback;
926 info->stream[0].nid = spec->dac_node[0]->nid;
927 if (spec->dac_node[1]) {
928 info->stream[0].ops.prepare = generic_pcm2_prepare;
929 info->stream[0].ops.cleanup = generic_pcm2_cleanup;
932 if (spec->adc_node) {
933 info->stream[1] = generic_pcm_playback;
934 info->stream[1].nid = spec->adc_node->nid;
943 static struct hda_codec_ops generic_patch_ops = {
944 .build_controls = build_generic_controls,
945 .build_pcms = build_generic_pcms,
946 .free = snd_hda_generic_free,
952 int snd_hda_parse_generic_codec(struct hda_codec *codec)
954 struct hda_gspec *spec;
960 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
962 printk(KERN_ERR "hda_generic: can't allocate spec\n");
966 INIT_LIST_HEAD(&spec->nid_list);
968 if ((err = build_afg_tree(codec)) < 0)
971 if ((err = parse_input(codec)) < 0 ||
972 (err = parse_output(codec)) < 0)
975 codec->patch_ops = generic_patch_ops;
980 snd_hda_generic_free(codec);