| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> | 
|  | 24 | #include <linux/slab.h> | 
| Paul Gortmaker | d81a6d7 | 2011-09-22 09:34:58 -0400 | [diff] [blame] | 25 | #include <linux/export.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <sound/core.h> | 
|  | 27 | #include "hda_codec.h" | 
|  | 28 | #include "hda_local.h" | 
|  | 29 |  | 
|  | 30 | /* widget node for parsing */ | 
|  | 31 | struct hda_gnode { | 
|  | 32 | hda_nid_t nid;		/* NID of this widget */ | 
|  | 33 | unsigned short nconns;	/* number of input connections */ | 
| Takashi Iwai | d256950 | 2005-11-21 16:33:51 +0100 | [diff] [blame] | 34 | hda_nid_t *conn_list; | 
|  | 35 | hda_nid_t slist[2];	/* temporay list */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | unsigned int wid_caps;	/* widget capabilities */ | 
|  | 37 | unsigned char type;	/* widget type */ | 
|  | 38 | unsigned char pin_ctl;	/* pin controls */ | 
|  | 39 | unsigned char checked;	/* the flag indicates that the node is already parsed */ | 
|  | 40 | unsigned int pin_caps;	/* pin widget capabilities */ | 
|  | 41 | unsigned int def_cfg;	/* default configuration */ | 
|  | 42 | unsigned int amp_out_caps;	/* AMP out capabilities */ | 
|  | 43 | unsigned int amp_in_caps;	/* AMP in capabilities */ | 
|  | 44 | struct list_head list; | 
|  | 45 | }; | 
|  | 46 |  | 
| Takashi Iwai | c313292 | 2005-04-20 13:43:00 +0200 | [diff] [blame] | 47 | /* patch-specific record */ | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 48 |  | 
|  | 49 | #define MAX_PCM_VOLS	2 | 
|  | 50 | struct pcm_vol { | 
|  | 51 | struct hda_gnode *node;	/* Node for PCM volume */ | 
|  | 52 | unsigned int index;	/* connection of PCM volume */ | 
|  | 53 | }; | 
|  | 54 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | struct hda_gspec { | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 56 | struct hda_gnode *dac_node[2];	/* DAC node */ | 
|  | 57 | struct hda_gnode *out_pin_node[2];	/* Output pin (Line-Out) node */ | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 58 | struct pcm_vol pcm_vol[MAX_PCM_VOLS];	/* PCM volumes */ | 
|  | 59 | unsigned int pcm_vol_nodes;	/* number of PCM volumes */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  | 
|  | 61 | struct hda_gnode *adc_node;	/* ADC node */ | 
|  | 62 | struct hda_gnode *cap_vol_node;	/* Node for capture volume */ | 
|  | 63 | unsigned int cur_cap_src;	/* current capture source */ | 
|  | 64 | struct hda_input_mux input_mux; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 72 |  | 
|  | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }; | 
|  | 80 |  | 
|  | 81 | /* | 
|  | 82 | * retrieve the default device type from the default config value | 
|  | 83 | */ | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 84 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
|  | 91 | /* | 
|  | 92 | * destructor | 
|  | 93 | */ | 
|  | 94 | static void snd_hda_generic_free(struct hda_codec *codec) | 
|  | 95 | { | 
|  | 96 | struct hda_gspec *spec = codec->spec; | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 97 | struct hda_gnode *node, *n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 |  | 
|  | 99 | if (! spec) | 
|  | 100 | return; | 
|  | 101 | /* free all widgets */ | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 102 | list_for_each_entry_safe(node, n, &spec->nid_list, list) { | 
| Takashi Iwai | d256950 | 2005-11-21 16:33:51 +0100 | [diff] [blame] | 103 | if (node->conn_list != node->slist) | 
|  | 104 | kfree(node->conn_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | kfree(node); | 
|  | 106 | } | 
|  | 107 | kfree(spec); | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 |  | 
|  | 111 | /* | 
|  | 112 | * add a new widget node and read its attributes | 
|  | 113 | */ | 
|  | 114 | static 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 Iwai | d256950 | 2005-11-21 16:33:51 +0100 | [diff] [blame] | 118 | hda_nid_t conn_list[HDA_MAX_CONNECTIONS]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 |  | 
| Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 120 | node = kzalloc(sizeof(*node), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if (node == NULL) | 
|  | 122 | return -ENOMEM; | 
|  | 123 | node->nid = nid; | 
| Jaroslav Kysela | 0529604 | 2009-07-22 14:38:58 +0200 | [diff] [blame] | 124 | node->wid_caps = get_wcaps(codec, nid); | 
| Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 125 | node->type = get_wcaps_type(node->wid_caps); | 
| Jaroslav Kysela | 254da00 | 2009-07-22 15:31:03 +0200 | [diff] [blame] | 126 | if (node->wid_caps & AC_WCAP_CONN_LIST) { | 
| Jaroslav Kysela | 0529604 | 2009-07-22 14:38:58 +0200 | [diff] [blame] | 127 | nconns = snd_hda_get_connections(codec, nid, conn_list, | 
|  | 128 | HDA_MAX_CONNECTIONS); | 
|  | 129 | if (nconns < 0) { | 
|  | 130 | kfree(node); | 
|  | 131 | return nconns; | 
|  | 132 | } | 
|  | 133 | } else { | 
|  | 134 | nconns = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } | 
| Takashi Iwai | d256950 | 2005-11-21 16:33:51 +0100 | [diff] [blame] | 136 | if (nconns <= ARRAY_SIZE(node->slist)) | 
|  | 137 | node->conn_list = node->slist; | 
|  | 138 | else { | 
|  | 139 | node->conn_list = kmalloc(sizeof(hda_nid_t) * nconns, | 
|  | 140 | GFP_KERNEL); | 
|  | 141 | if (! node->conn_list) { | 
|  | 142 | snd_printk(KERN_ERR "hda-generic: cannot malloc\n"); | 
|  | 143 | kfree(node); | 
|  | 144 | return -ENOMEM; | 
|  | 145 | } | 
|  | 146 | } | 
| Takashi Iwai | 0bbed75 | 2007-05-08 15:17:15 +0200 | [diff] [blame] | 147 | memcpy(node->conn_list, conn_list, nconns * sizeof(hda_nid_t)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | node->nconns = nconns; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 |  | 
|  | 150 | if (node->type == AC_WID_PIN) { | 
| Takashi Iwai | 1327a32 | 2009-03-23 13:07:47 +0100 | [diff] [blame] | 151 | node->pin_caps = snd_hda_query_pin_caps(codec, node->nid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | node->pin_ctl = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | 
| Takashi Iwai | c17a1ab | 2009-02-23 09:28:12 +0100 | [diff] [blame] | 153 | node->def_cfg = snd_hda_codec_get_pincfg(codec, node->nid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } | 
|  | 155 |  | 
|  | 156 | if (node->wid_caps & AC_WCAP_OUT_AMP) { | 
|  | 157 | if (node->wid_caps & AC_WCAP_AMP_OVRD) | 
|  | 158 | node->amp_out_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_OUT_CAP); | 
|  | 159 | if (! node->amp_out_caps) | 
|  | 160 | node->amp_out_caps = spec->def_amp_out_caps; | 
|  | 161 | } | 
|  | 162 | if (node->wid_caps & AC_WCAP_IN_AMP) { | 
|  | 163 | if (node->wid_caps & AC_WCAP_AMP_OVRD) | 
|  | 164 | node->amp_in_caps = snd_hda_param_read(codec, node->nid, AC_PAR_AMP_IN_CAP); | 
|  | 165 | if (! node->amp_in_caps) | 
|  | 166 | node->amp_in_caps = spec->def_amp_in_caps; | 
|  | 167 | } | 
|  | 168 | list_add_tail(&node->list, &spec->nid_list); | 
|  | 169 | return 0; | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | /* | 
|  | 173 | * build the AFG subtree | 
|  | 174 | */ | 
|  | 175 | static int build_afg_tree(struct hda_codec *codec) | 
|  | 176 | { | 
|  | 177 | struct hda_gspec *spec = codec->spec; | 
|  | 178 | int i, nodes, err; | 
|  | 179 | hda_nid_t nid; | 
|  | 180 |  | 
| Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 181 | if (snd_BUG_ON(!spec)) | 
|  | 182 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 |  | 
|  | 184 | spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP); | 
|  | 185 | spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP); | 
|  | 186 |  | 
|  | 187 | nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid); | 
|  | 188 | if (! nid || nodes < 0) { | 
|  | 189 | printk(KERN_ERR "Invalid AFG subtree\n"); | 
|  | 190 | return -EINVAL; | 
|  | 191 | } | 
|  | 192 |  | 
|  | 193 | /* parse all nodes belonging to the AFG */ | 
|  | 194 | for (i = 0; i < nodes; i++, nid++) { | 
|  | 195 | if ((err = add_new_node(codec, spec, nid)) < 0) | 
|  | 196 | return err; | 
|  | 197 | } | 
|  | 198 |  | 
|  | 199 | return 0; | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 |  | 
|  | 203 | /* | 
|  | 204 | * look for the node record for the given NID | 
|  | 205 | */ | 
|  | 206 | /* FIXME: should avoid the braindead linear search */ | 
|  | 207 | static struct hda_gnode *hda_get_node(struct hda_gspec *spec, hda_nid_t nid) | 
|  | 208 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | struct hda_gnode *node; | 
|  | 210 |  | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 211 | list_for_each_entry(node, &spec->nid_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | if (node->nid == nid) | 
|  | 213 | return node; | 
|  | 214 | } | 
|  | 215 | return NULL; | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | /* | 
|  | 219 | * unmute (and set max vol) the output amplifier | 
|  | 220 | */ | 
|  | 221 | static int unmute_output(struct hda_codec *codec, struct hda_gnode *node) | 
|  | 222 | { | 
|  | 223 | unsigned int val, ofs; | 
|  | 224 | snd_printdd("UNMUTE OUT: NID=0x%x\n", node->nid); | 
|  | 225 | val = (node->amp_out_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; | 
|  | 226 | ofs = (node->amp_out_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; | 
|  | 227 | if (val >= ofs) | 
|  | 228 | val -= ofs; | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 229 | snd_hda_codec_amp_stereo(codec, node->nid, HDA_OUTPUT, 0, 0xff, val); | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 230 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } | 
|  | 232 |  | 
|  | 233 | /* | 
|  | 234 | * unmute (and set max vol) the input amplifier | 
|  | 235 | */ | 
|  | 236 | static int unmute_input(struct hda_codec *codec, struct hda_gnode *node, unsigned int index) | 
|  | 237 | { | 
|  | 238 | unsigned int val, ofs; | 
|  | 239 | snd_printdd("UNMUTE IN: NID=0x%x IDX=0x%x\n", node->nid, index); | 
|  | 240 | val = (node->amp_in_caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT; | 
|  | 241 | ofs = (node->amp_in_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; | 
|  | 242 | if (val >= ofs) | 
|  | 243 | val -= ofs; | 
| Takashi Iwai | 47fd830 | 2007-08-10 17:11:07 +0200 | [diff] [blame] | 244 | snd_hda_codec_amp_stereo(codec, node->nid, HDA_INPUT, index, 0xff, val); | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 245 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
|  | 248 | /* | 
|  | 249 | * select the input connection of the given node. | 
|  | 250 | */ | 
|  | 251 | static int select_input_connection(struct hda_codec *codec, struct hda_gnode *node, | 
|  | 252 | unsigned int index) | 
|  | 253 | { | 
|  | 254 | snd_printdd("CONNECT: NID=0x%x IDX=0x%x\n", node->nid, index); | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 255 | return snd_hda_codec_write_cache(codec, node->nid, 0, | 
|  | 256 | AC_VERB_SET_CONNECT_SEL, index); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } | 
|  | 258 |  | 
|  | 259 | /* | 
|  | 260 | * clear checked flag of each node in the node list | 
|  | 261 | */ | 
|  | 262 | static void clear_check_flags(struct hda_gspec *spec) | 
|  | 263 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | struct hda_gnode *node; | 
|  | 265 |  | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 266 | list_for_each_entry(node, &spec->nid_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | node->checked = 0; | 
|  | 268 | } | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | /* | 
|  | 272 | * parse the output path recursively until reach to an audio output widget | 
|  | 273 | * | 
|  | 274 | * returns 0 if not found, 1 if found, or a negative error code. | 
|  | 275 | */ | 
|  | 276 | static int parse_output_path(struct hda_codec *codec, struct hda_gspec *spec, | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 277 | struct hda_gnode *node, int dac_idx) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { | 
|  | 279 | int i, err; | 
|  | 280 | struct hda_gnode *child; | 
|  | 281 |  | 
|  | 282 | if (node->checked) | 
|  | 283 | return 0; | 
|  | 284 |  | 
|  | 285 | node->checked = 1; | 
|  | 286 | if (node->type == AC_WID_AUD_OUT) { | 
|  | 287 | if (node->wid_caps & AC_WCAP_DIGITAL) { | 
|  | 288 | snd_printdd("Skip Digital OUT node %x\n", node->nid); | 
|  | 289 | return 0; | 
|  | 290 | } | 
|  | 291 | snd_printdd("AUD_OUT found %x\n", node->nid); | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 292 | if (spec->dac_node[dac_idx]) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | /* already DAC node is assigned, just unmute & connect */ | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 294 | return node == spec->dac_node[dac_idx]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 296 | spec->dac_node[dac_idx] = node; | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 297 | if ((node->wid_caps & AC_WCAP_OUT_AMP) && | 
|  | 298 | spec->pcm_vol_nodes < MAX_PCM_VOLS) { | 
|  | 299 | spec->pcm_vol[spec->pcm_vol_nodes].node = node; | 
|  | 300 | spec->pcm_vol[spec->pcm_vol_nodes].index = 0; | 
|  | 301 | spec->pcm_vol_nodes++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } | 
|  | 303 | return 1; /* found */ | 
|  | 304 | } | 
|  | 305 |  | 
|  | 306 | for (i = 0; i < node->nconns; i++) { | 
|  | 307 | child = hda_get_node(spec, node->conn_list[i]); | 
|  | 308 | if (! child) | 
|  | 309 | continue; | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 310 | err = parse_output_path(codec, spec, child, dac_idx); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (err < 0) | 
|  | 312 | return err; | 
|  | 313 | else if (err > 0) { | 
|  | 314 | /* found one, | 
|  | 315 | * select the path, unmute both input and output | 
|  | 316 | */ | 
|  | 317 | if (node->nconns > 1) | 
|  | 318 | select_input_connection(codec, node, i); | 
|  | 319 | unmute_input(codec, node, i); | 
|  | 320 | unmute_output(codec, node); | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 321 | if (spec->dac_node[dac_idx] && | 
|  | 322 | spec->pcm_vol_nodes < MAX_PCM_VOLS && | 
|  | 323 | !(spec->dac_node[dac_idx]->wid_caps & | 
|  | 324 | AC_WCAP_OUT_AMP)) { | 
|  | 325 | if ((node->wid_caps & AC_WCAP_IN_AMP) || | 
|  | 326 | (node->wid_caps & AC_WCAP_OUT_AMP)) { | 
|  | 327 | int n = spec->pcm_vol_nodes; | 
|  | 328 | spec->pcm_vol[n].node = node; | 
|  | 329 | spec->pcm_vol[n].index = i; | 
|  | 330 | spec->pcm_vol_nodes++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } | 
|  | 332 | } | 
|  | 333 | return 1; | 
|  | 334 | } | 
|  | 335 | } | 
|  | 336 | return 0; | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | /* | 
|  | 340 | * Look for the output PIN widget with the given jack type | 
|  | 341 | * and parse the output path to that PIN. | 
|  | 342 | * | 
|  | 343 | * Returns the PIN node when the path to DAC is established. | 
|  | 344 | */ | 
|  | 345 | static struct hda_gnode *parse_output_jack(struct hda_codec *codec, | 
|  | 346 | struct hda_gspec *spec, | 
|  | 347 | int jack_type) | 
|  | 348 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | struct hda_gnode *node; | 
|  | 350 | int err; | 
|  | 351 |  | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 352 | list_for_each_entry(node, &spec->nid_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (node->type != AC_WID_PIN) | 
|  | 354 | continue; | 
|  | 355 | /* output capable? */ | 
|  | 356 | if (! (node->pin_caps & AC_PINCAP_OUT)) | 
|  | 357 | continue; | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 358 | if (defcfg_port_conn(node) == AC_JACK_PORT_NONE) | 
|  | 359 | continue; /* unconnected */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | if (jack_type >= 0) { | 
| Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 361 | if (jack_type != defcfg_type(node)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | continue; | 
|  | 363 | if (node->wid_caps & AC_WCAP_DIGITAL) | 
|  | 364 | continue; /* skip SPDIF */ | 
|  | 365 | } else { | 
|  | 366 | /* output as default? */ | 
|  | 367 | if (! (node->pin_ctl & AC_PINCTL_OUT_EN)) | 
|  | 368 | continue; | 
|  | 369 | } | 
|  | 370 | clear_check_flags(spec); | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 371 | err = parse_output_path(codec, spec, node, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | if (err < 0) | 
|  | 373 | return NULL; | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 374 | if (! err && spec->out_pin_node[0]) { | 
|  | 375 | err = parse_output_path(codec, spec, node, 1); | 
|  | 376 | if (err < 0) | 
|  | 377 | return NULL; | 
|  | 378 | } | 
|  | 379 | if (err > 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /* unmute the PIN output */ | 
|  | 381 | unmute_output(codec, node); | 
|  | 382 | /* set PIN-Out enable */ | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 383 | snd_hda_codec_write_cache(codec, node->nid, 0, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | AC_VERB_SET_PIN_WIDGET_CONTROL, | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 385 | AC_PINCTL_OUT_EN | | 
|  | 386 | ((node->pin_caps & AC_PINCAP_HP_DRV) ? | 
|  | 387 | AC_PINCTL_HP_EN : 0)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return node; | 
|  | 389 | } | 
|  | 390 | } | 
|  | 391 | return NULL; | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 |  | 
|  | 395 | /* | 
|  | 396 | * parse outputs | 
|  | 397 | */ | 
|  | 398 | static int parse_output(struct hda_codec *codec) | 
|  | 399 | { | 
|  | 400 | struct hda_gspec *spec = codec->spec; | 
|  | 401 | struct hda_gnode *node; | 
|  | 402 |  | 
|  | 403 | /* | 
|  | 404 | * Look for the output PIN widget | 
|  | 405 | */ | 
|  | 406 | /* first, look for the line-out pin */ | 
|  | 407 | node = parse_output_jack(codec, spec, AC_JACK_LINE_OUT); | 
|  | 408 | if (node) /* found, remember the PIN node */ | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 409 | spec->out_pin_node[0] = node; | 
|  | 410 | else { | 
|  | 411 | /* if no line-out is found, try speaker out */ | 
|  | 412 | node = parse_output_jack(codec, spec, AC_JACK_SPEAKER); | 
|  | 413 | if (node) | 
|  | 414 | spec->out_pin_node[0] = node; | 
|  | 415 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | /* look for the HP-out pin */ | 
|  | 417 | node = parse_output_jack(codec, spec, AC_JACK_HP_OUT); | 
|  | 418 | if (node) { | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 419 | if (! spec->out_pin_node[0]) | 
|  | 420 | spec->out_pin_node[0] = node; | 
|  | 421 | else | 
|  | 422 | spec->out_pin_node[1] = node; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } | 
|  | 424 |  | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 425 | if (! spec->out_pin_node[0]) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* no line-out or HP pins found, | 
|  | 427 | * then choose for the first output pin | 
|  | 428 | */ | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 429 | spec->out_pin_node[0] = parse_output_jack(codec, spec, -1); | 
|  | 430 | if (! spec->out_pin_node[0]) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | snd_printd("hda_generic: no proper output path found\n"); | 
|  | 432 | } | 
|  | 433 |  | 
|  | 434 | return 0; | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | /* | 
|  | 438 | * input MUX | 
|  | 439 | */ | 
|  | 440 |  | 
|  | 441 | /* control callbacks */ | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 442 | static int capture_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { | 
|  | 444 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
|  | 445 | struct hda_gspec *spec = codec->spec; | 
|  | 446 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); | 
|  | 447 | } | 
|  | 448 |  | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 449 | static int capture_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | { | 
|  | 451 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
|  | 452 | struct hda_gspec *spec = codec->spec; | 
|  | 453 |  | 
|  | 454 | ucontrol->value.enumerated.item[0] = spec->cur_cap_src; | 
|  | 455 | return 0; | 
|  | 456 | } | 
|  | 457 |  | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 458 | static int capture_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { | 
|  | 460 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 
|  | 461 | struct hda_gspec *spec = codec->spec; | 
|  | 462 | return snd_hda_input_mux_put(codec, &spec->input_mux, ucontrol, | 
|  | 463 | spec->adc_node->nid, &spec->cur_cap_src); | 
|  | 464 | } | 
|  | 465 |  | 
|  | 466 | /* | 
|  | 467 | * return the string name of the given input PIN widget | 
|  | 468 | */ | 
|  | 469 | static const char *get_input_type(struct hda_gnode *node, unsigned int *pinctl) | 
|  | 470 | { | 
| Takashi Iwai | e9edcee | 2005-06-13 14:16:38 +0200 | [diff] [blame] | 471 | unsigned int location = defcfg_location(node); | 
|  | 472 | switch (defcfg_type(node)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | case AC_JACK_LINE_IN: | 
|  | 474 | if ((location & 0x0f) == AC_JACK_LOC_FRONT) | 
|  | 475 | return "Front Line"; | 
|  | 476 | return "Line"; | 
|  | 477 | case AC_JACK_CD: | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 478 | #if 0 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | if (pinctl) | 
| Matt | 1a12de1e | 2005-04-13 14:37:50 +0200 | [diff] [blame] | 480 | *pinctl |= AC_PINCTL_VREF_GRD; | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 481 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return "CD"; | 
|  | 483 | case AC_JACK_AUX: | 
|  | 484 | if ((location & 0x0f) == AC_JACK_LOC_FRONT) | 
|  | 485 | return "Front Aux"; | 
|  | 486 | return "Aux"; | 
|  | 487 | case AC_JACK_MIC_IN: | 
| Takashi Iwai | 6afeb11 | 2006-12-18 16:16:04 +0100 | [diff] [blame] | 488 | if (pinctl && | 
|  | 489 | (node->pin_caps & | 
|  | 490 | (AC_PINCAP_VREF_80 << AC_PINCAP_VREF_SHIFT))) | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 491 | *pinctl |= AC_PINCTL_VREF_80; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | if ((location & 0x0f) == AC_JACK_LOC_FRONT) | 
|  | 493 | return "Front Mic"; | 
|  | 494 | return "Mic"; | 
|  | 495 | case AC_JACK_SPDIF_IN: | 
|  | 496 | return "SPDIF"; | 
|  | 497 | case AC_JACK_DIG_OTHER_IN: | 
|  | 498 | return "Digital"; | 
|  | 499 | } | 
|  | 500 | return NULL; | 
|  | 501 | } | 
|  | 502 |  | 
|  | 503 | /* | 
|  | 504 | * parse the nodes recursively until reach to the input PIN | 
|  | 505 | * | 
|  | 506 | * returns 0 if not found, 1 if found, or a negative error code. | 
|  | 507 | */ | 
|  | 508 | static int parse_adc_sub_nodes(struct hda_codec *codec, struct hda_gspec *spec, | 
| Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 509 | struct hda_gnode *node, int idx) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { | 
|  | 511 | int i, err; | 
|  | 512 | unsigned int pinctl; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | const char *type; | 
|  | 514 |  | 
|  | 515 | if (node->checked) | 
|  | 516 | return 0; | 
|  | 517 |  | 
|  | 518 | node->checked = 1; | 
|  | 519 | if (node->type != AC_WID_PIN) { | 
|  | 520 | for (i = 0; i < node->nconns; i++) { | 
|  | 521 | struct hda_gnode *child; | 
|  | 522 | child = hda_get_node(spec, node->conn_list[i]); | 
|  | 523 | if (! child) | 
|  | 524 | continue; | 
| Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 525 | err = parse_adc_sub_nodes(codec, spec, child, idx); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | if (err < 0) | 
|  | 527 | return err; | 
|  | 528 | if (err > 0) { | 
|  | 529 | /* found one, | 
|  | 530 | * select the path, unmute both input and output | 
|  | 531 | */ | 
|  | 532 | if (node->nconns > 1) | 
|  | 533 | select_input_connection(codec, node, i); | 
|  | 534 | unmute_input(codec, node, i); | 
|  | 535 | unmute_output(codec, node); | 
|  | 536 | return err; | 
|  | 537 | } | 
|  | 538 | } | 
|  | 539 | return 0; | 
|  | 540 | } | 
|  | 541 |  | 
|  | 542 | /* input capable? */ | 
|  | 543 | if (! (node->pin_caps & AC_PINCAP_IN)) | 
|  | 544 | return 0; | 
|  | 545 |  | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 546 | if (defcfg_port_conn(node) == AC_JACK_PORT_NONE) | 
|  | 547 | return 0; /* unconnected */ | 
|  | 548 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (node->wid_caps & AC_WCAP_DIGITAL) | 
|  | 550 | return 0; /* skip SPDIF */ | 
|  | 551 |  | 
|  | 552 | if (spec->input_mux.num_items >= HDA_MAX_NUM_INPUTS) { | 
|  | 553 | snd_printk(KERN_ERR "hda_generic: Too many items for capture\n"); | 
|  | 554 | return -EINVAL; | 
|  | 555 | } | 
|  | 556 |  | 
|  | 557 | pinctl = AC_PINCTL_IN_EN; | 
|  | 558 | /* create a proper capture source label */ | 
|  | 559 | type = get_input_type(node, &pinctl); | 
|  | 560 | if (! type) { | 
|  | 561 | /* input as default? */ | 
|  | 562 | if (! (node->pin_ctl & AC_PINCTL_IN_EN)) | 
|  | 563 | return 0; | 
|  | 564 | type = "Input"; | 
|  | 565 | } | 
| Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 566 | snd_hda_add_imux_item(&spec->input_mux, type, idx, NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 |  | 
|  | 568 | /* unmute the PIN external input */ | 
|  | 569 | unmute_input(codec, node, 0); /* index = 0? */ | 
|  | 570 | /* set PIN-In enable */ | 
| Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 571 | snd_hda_codec_write_cache(codec, node->nid, 0, | 
|  | 572 | AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 |  | 
|  | 574 | return 1; /* found */ | 
|  | 575 | } | 
|  | 576 |  | 
|  | 577 | /* | 
|  | 578 | * parse input | 
|  | 579 | */ | 
|  | 580 | static int parse_input_path(struct hda_codec *codec, struct hda_gnode *adc_node) | 
|  | 581 | { | 
|  | 582 | struct hda_gspec *spec = codec->spec; | 
|  | 583 | struct hda_gnode *node; | 
|  | 584 | int i, err; | 
|  | 585 |  | 
|  | 586 | snd_printdd("AUD_IN = %x\n", adc_node->nid); | 
|  | 587 | clear_check_flags(spec); | 
|  | 588 |  | 
|  | 589 | // awk added - fixed no recording due to muted widget | 
|  | 590 | unmute_input(codec, adc_node, 0); | 
|  | 591 |  | 
|  | 592 | /* | 
|  | 593 | * check each connection of the ADC | 
|  | 594 | * if it reaches to a proper input PIN, add the path as the | 
|  | 595 | * input path. | 
|  | 596 | */ | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 597 | /* first, check the direct connections to PIN widgets */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | for (i = 0; i < adc_node->nconns; i++) { | 
|  | 599 | node = hda_get_node(spec, adc_node->conn_list[i]); | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 600 | if (node && node->type == AC_WID_PIN) { | 
| Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 601 | err = parse_adc_sub_nodes(codec, spec, node, i); | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 602 | if (err < 0) | 
|  | 603 | return err; | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 604 | } | 
|  | 605 | } | 
|  | 606 | /* ... then check the rests, more complicated connections */ | 
|  | 607 | for (i = 0; i < adc_node->nconns; i++) { | 
|  | 608 | node = hda_get_node(spec, adc_node->conn_list[i]); | 
|  | 609 | if (node && node->type != AC_WID_PIN) { | 
| Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 610 | err = parse_adc_sub_nodes(codec, spec, node, i); | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 611 | if (err < 0) | 
|  | 612 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } | 
|  | 614 | } | 
|  | 615 |  | 
|  | 616 | if (! spec->input_mux.num_items) | 
|  | 617 | return 0; /* no input path found... */ | 
|  | 618 |  | 
|  | 619 | snd_printdd("[Capture Source] NID=0x%x, #SRC=%d\n", adc_node->nid, spec->input_mux.num_items); | 
|  | 620 | for (i = 0; i < spec->input_mux.num_items; i++) | 
|  | 621 | snd_printdd("  [%s] IDX=0x%x\n", spec->input_mux.items[i].label, | 
|  | 622 | spec->input_mux.items[i].index); | 
|  | 623 |  | 
|  | 624 | spec->adc_node = adc_node; | 
|  | 625 | return 1; | 
|  | 626 | } | 
|  | 627 |  | 
|  | 628 | /* | 
|  | 629 | * parse input | 
|  | 630 | */ | 
|  | 631 | static int parse_input(struct hda_codec *codec) | 
|  | 632 | { | 
|  | 633 | struct hda_gspec *spec = codec->spec; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | struct hda_gnode *node; | 
|  | 635 | int err; | 
|  | 636 |  | 
|  | 637 | /* | 
|  | 638 | * At first we look for an audio input widget. | 
|  | 639 | * If it reaches to certain input PINs, we take it as the | 
|  | 640 | * input path. | 
|  | 641 | */ | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 642 | list_for_each_entry(node, &spec->nid_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | if (node->wid_caps & AC_WCAP_DIGITAL) | 
|  | 644 | continue; /* skip SPDIF */ | 
|  | 645 | if (node->type == AC_WID_AUD_IN) { | 
|  | 646 | err = parse_input_path(codec, node); | 
|  | 647 | if (err < 0) | 
|  | 648 | return err; | 
|  | 649 | else if (err > 0) | 
|  | 650 | return 0; | 
|  | 651 | } | 
|  | 652 | } | 
|  | 653 | snd_printd("hda_generic: no proper input path found\n"); | 
|  | 654 | return 0; | 
|  | 655 | } | 
|  | 656 |  | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 657 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 
|  | 658 | static void add_input_loopback(struct hda_codec *codec, hda_nid_t nid, | 
|  | 659 | int dir, int idx) | 
|  | 660 | { | 
|  | 661 | struct hda_gspec *spec = codec->spec; | 
|  | 662 | struct hda_amp_list *p; | 
|  | 663 |  | 
|  | 664 | if (spec->num_loopbacks >= MAX_LOOPBACK_AMPS) { | 
|  | 665 | snd_printk(KERN_ERR "hda_generic: Too many loopback ctls\n"); | 
|  | 666 | return; | 
|  | 667 | } | 
|  | 668 | p = &spec->loopback_list[spec->num_loopbacks++]; | 
|  | 669 | p->nid = nid; | 
|  | 670 | p->dir = dir; | 
|  | 671 | p->idx = idx; | 
|  | 672 | spec->loopback.amplist = spec->loopback_list; | 
|  | 673 | } | 
|  | 674 | #else | 
|  | 675 | #define add_input_loopback(codec,nid,dir,idx) | 
|  | 676 | #endif | 
|  | 677 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* | 
|  | 679 | * create mixer controls if possible | 
|  | 680 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | static int create_mixer(struct hda_codec *codec, struct hda_gnode *node, | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 682 | unsigned int index, const char *type, | 
|  | 683 | const char *dir_sfx, int is_loopback) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { | 
|  | 685 | char name[32]; | 
|  | 686 | int err; | 
|  | 687 | int created = 0; | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 688 | struct snd_kcontrol_new knew; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 |  | 
|  | 690 | if (type) | 
|  | 691 | sprintf(name, "%s %s Switch", type, dir_sfx); | 
|  | 692 | else | 
|  | 693 | sprintf(name, "%s Switch", dir_sfx); | 
|  | 694 | if ((node->wid_caps & AC_WCAP_IN_AMP) && | 
|  | 695 | (node->amp_in_caps & AC_AMPCAP_MUTE)) { | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 696 | knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT); | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 697 | if (is_loopback) | 
|  | 698 | add_input_loopback(codec, node->nid, HDA_INPUT, index); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); | 
| Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 700 | err = snd_hda_ctl_add(codec, node->nid, | 
|  | 701 | snd_ctl_new1(&knew, codec)); | 
| Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 702 | if (err < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return err; | 
|  | 704 | created = 1; | 
|  | 705 | } else if ((node->wid_caps & AC_WCAP_OUT_AMP) && | 
|  | 706 | (node->amp_out_caps & AC_AMPCAP_MUTE)) { | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 707 | knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT); | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 708 | if (is_loopback) | 
|  | 709 | add_input_loopback(codec, node->nid, HDA_OUTPUT, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); | 
| Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 711 | err = snd_hda_ctl_add(codec, node->nid, | 
|  | 712 | snd_ctl_new1(&knew, codec)); | 
| Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 713 | if (err < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | return err; | 
|  | 715 | created = 1; | 
|  | 716 | } | 
|  | 717 |  | 
|  | 718 | if (type) | 
|  | 719 | sprintf(name, "%s %s Volume", type, dir_sfx); | 
|  | 720 | else | 
|  | 721 | sprintf(name, "%s Volume", dir_sfx); | 
|  | 722 | if ((node->wid_caps & AC_WCAP_IN_AMP) && | 
|  | 723 | (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) { | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 724 | knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index); | 
| Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 726 | err = snd_hda_ctl_add(codec, node->nid, | 
|  | 727 | snd_ctl_new1(&knew, codec)); | 
| Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 728 | if (err < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | return err; | 
|  | 730 | created = 1; | 
|  | 731 | } else if ((node->wid_caps & AC_WCAP_OUT_AMP) && | 
|  | 732 | (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) { | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 733 | knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid); | 
| Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 735 | err = snd_hda_ctl_add(codec, node->nid, | 
|  | 736 | snd_ctl_new1(&knew, codec)); | 
| Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 737 | if (err < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return err; | 
|  | 739 | created = 1; | 
|  | 740 | } | 
|  | 741 |  | 
|  | 742 | return created; | 
|  | 743 | } | 
|  | 744 |  | 
|  | 745 | /* | 
|  | 746 | * check whether the controls with the given name and direction suffix already exist | 
|  | 747 | */ | 
|  | 748 | static int check_existing_control(struct hda_codec *codec, const char *type, const char *dir) | 
|  | 749 | { | 
| Takashi Iwai | c8b6bf9 | 2005-11-17 14:57:47 +0100 | [diff] [blame] | 750 | struct snd_ctl_elem_id id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | memset(&id, 0, sizeof(id)); | 
|  | 752 | sprintf(id.name, "%s %s Volume", type, dir); | 
|  | 753 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | 
|  | 754 | if (snd_ctl_find_id(codec->bus->card, &id)) | 
|  | 755 | return 1; | 
|  | 756 | sprintf(id.name, "%s %s Switch", type, dir); | 
|  | 757 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | 
|  | 758 | if (snd_ctl_find_id(codec->bus->card, &id)) | 
|  | 759 | return 1; | 
|  | 760 | return 0; | 
|  | 761 | } | 
|  | 762 |  | 
|  | 763 | /* | 
|  | 764 | * build output mixer controls | 
|  | 765 | */ | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 766 | static int create_output_mixers(struct hda_codec *codec, | 
|  | 767 | const char * const *names) | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 768 | { | 
|  | 769 | struct hda_gspec *spec = codec->spec; | 
|  | 770 | int i, err; | 
|  | 771 |  | 
|  | 772 | for (i = 0; i < spec->pcm_vol_nodes; i++) { | 
|  | 773 | err = create_mixer(codec, spec->pcm_vol[i].node, | 
|  | 774 | spec->pcm_vol[i].index, | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 775 | names[i], "Playback", 0); | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 776 | if (err < 0) | 
|  | 777 | return err; | 
|  | 778 | } | 
|  | 779 | return 0; | 
|  | 780 | } | 
|  | 781 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | static int build_output_controls(struct hda_codec *codec) | 
|  | 783 | { | 
|  | 784 | struct hda_gspec *spec = codec->spec; | 
| Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 785 | static const char * const types_speaker[] = { "Speaker", "Headphone" }; | 
|  | 786 | static const char * const types_line[] = { "Front", "Headphone" }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 |  | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 788 | switch (spec->pcm_vol_nodes) { | 
|  | 789 | case 1: | 
|  | 790 | return create_mixer(codec, spec->pcm_vol[0].node, | 
|  | 791 | spec->pcm_vol[0].index, | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 792 | "Master", "Playback", 0); | 
| Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 793 | case 2: | 
|  | 794 | if (defcfg_type(spec->out_pin_node[0]) == AC_JACK_SPEAKER) | 
|  | 795 | return create_output_mixers(codec, types_speaker); | 
|  | 796 | else | 
|  | 797 | return create_output_mixers(codec, types_line); | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 798 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | return 0; | 
|  | 800 | } | 
|  | 801 |  | 
|  | 802 | /* create capture volume/switch */ | 
|  | 803 | static int build_input_controls(struct hda_codec *codec) | 
|  | 804 | { | 
|  | 805 | struct hda_gspec *spec = codec->spec; | 
|  | 806 | struct hda_gnode *adc_node = spec->adc_node; | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 807 | int i, err; | 
|  | 808 | static struct snd_kcontrol_new cap_sel = { | 
|  | 809 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 
|  | 810 | .name = "Capture Source", | 
|  | 811 | .info = capture_source_info, | 
|  | 812 | .get = capture_source_get, | 
|  | 813 | .put = capture_source_put, | 
|  | 814 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 |  | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 816 | if (! adc_node || ! spec->input_mux.num_items) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return 0; /* not found */ | 
|  | 818 |  | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 819 | spec->cur_cap_src = 0; | 
|  | 820 | select_input_connection(codec, adc_node, | 
|  | 821 | spec->input_mux.items[0].index); | 
|  | 822 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | /* create capture volume and switch controls if the ADC has an amp */ | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 824 | /* do we have only a single item? */ | 
|  | 825 | if (spec->input_mux.num_items == 1) { | 
|  | 826 | err = create_mixer(codec, adc_node, | 
|  | 827 | spec->input_mux.items[0].index, | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 828 | NULL, "Capture", 0); | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 829 | if (err < 0) | 
|  | 830 | return err; | 
|  | 831 | return 0; | 
|  | 832 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 |  | 
|  | 834 | /* create input MUX if multiple sources are available */ | 
| Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 835 | err = snd_hda_ctl_add(codec, spec->adc_node->nid, | 
|  | 836 | snd_ctl_new1(&cap_sel, codec)); | 
| Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 837 | if (err < 0) | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 838 | return err; | 
|  | 839 |  | 
|  | 840 | /* no volume control? */ | 
|  | 841 | if (! (adc_node->wid_caps & AC_WCAP_IN_AMP) || | 
|  | 842 | ! (adc_node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) | 
|  | 843 | return 0; | 
|  | 844 |  | 
|  | 845 | for (i = 0; i < spec->input_mux.num_items; i++) { | 
|  | 846 | struct snd_kcontrol_new knew; | 
|  | 847 | char name[32]; | 
|  | 848 | sprintf(name, "%s Capture Volume", | 
|  | 849 | spec->input_mux.items[i].label); | 
|  | 850 | knew = (struct snd_kcontrol_new) | 
|  | 851 | HDA_CODEC_VOLUME(name, adc_node->nid, | 
|  | 852 | spec->input_mux.items[i].index, | 
|  | 853 | HDA_INPUT); | 
| Jaroslav Kysela | 3911a4c | 2009-11-11 13:43:01 +0100 | [diff] [blame] | 854 | err = snd_hda_ctl_add(codec, adc_node->nid, | 
|  | 855 | snd_ctl_new1(&knew, codec)); | 
| Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 856 | if (err < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } | 
| Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 859 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | return 0; | 
|  | 861 | } | 
|  | 862 |  | 
|  | 863 |  | 
|  | 864 | /* | 
|  | 865 | * parse the nodes recursively until reach to the output PIN. | 
|  | 866 | * | 
|  | 867 | * returns 0 - if not found, | 
|  | 868 | *         1 - if found, but no mixer is created | 
|  | 869 | *         2 - if found and mixer was already created, (just skip) | 
|  | 870 | *         a negative error code | 
|  | 871 | */ | 
|  | 872 | static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec, | 
|  | 873 | struct hda_gnode *node, struct hda_gnode *dest_node, | 
|  | 874 | const char *type) | 
|  | 875 | { | 
|  | 876 | int i, err; | 
|  | 877 |  | 
|  | 878 | if (node->checked) | 
|  | 879 | return 0; | 
|  | 880 |  | 
|  | 881 | node->checked = 1; | 
|  | 882 | if (node == dest_node) { | 
|  | 883 | /* loopback connection found */ | 
|  | 884 | return 1; | 
|  | 885 | } | 
|  | 886 |  | 
|  | 887 | for (i = 0; i < node->nconns; i++) { | 
|  | 888 | struct hda_gnode *child = hda_get_node(spec, node->conn_list[i]); | 
|  | 889 | if (! child) | 
|  | 890 | continue; | 
|  | 891 | err = parse_loopback_path(codec, spec, child, dest_node, type); | 
|  | 892 | if (err < 0) | 
|  | 893 | return err; | 
|  | 894 | else if (err >= 1) { | 
|  | 895 | if (err == 1) { | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 896 | err = create_mixer(codec, node, i, type, | 
|  | 897 | "Playback", 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | if (err < 0) | 
|  | 899 | return err; | 
|  | 900 | if (err > 0) | 
|  | 901 | return 2; /* ok, created */ | 
|  | 902 | /* not created, maybe in the lower path */ | 
|  | 903 | err = 1; | 
|  | 904 | } | 
|  | 905 | /* connect and unmute */ | 
|  | 906 | if (node->nconns > 1) | 
|  | 907 | select_input_connection(codec, node, i); | 
|  | 908 | unmute_input(codec, node, i); | 
|  | 909 | unmute_output(codec, node); | 
|  | 910 | return err; | 
|  | 911 | } | 
|  | 912 | } | 
|  | 913 | return 0; | 
|  | 914 | } | 
|  | 915 |  | 
|  | 916 | /* | 
|  | 917 | * parse the tree and build the loopback controls | 
|  | 918 | */ | 
|  | 919 | static int build_loopback_controls(struct hda_codec *codec) | 
|  | 920 | { | 
|  | 921 | struct hda_gspec *spec = codec->spec; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | struct hda_gnode *node; | 
|  | 923 | int err; | 
|  | 924 | const char *type; | 
|  | 925 |  | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 926 | if (! spec->out_pin_node[0]) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | return 0; | 
|  | 928 |  | 
| Matthias Kaehlcke | 33206e8 | 2007-09-17 14:40:04 +0200 | [diff] [blame] | 929 | list_for_each_entry(node, &spec->nid_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | if (node->type != AC_WID_PIN) | 
|  | 931 | continue; | 
|  | 932 | /* input capable? */ | 
|  | 933 | if (! (node->pin_caps & AC_PINCAP_IN)) | 
|  | 934 | return 0; | 
|  | 935 | type = get_input_type(node, NULL); | 
|  | 936 | if (type) { | 
|  | 937 | if (check_existing_control(codec, type, "Playback")) | 
|  | 938 | continue; | 
|  | 939 | clear_check_flags(spec); | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 940 | err = parse_loopback_path(codec, spec, | 
|  | 941 | spec->out_pin_node[0], | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | node, type); | 
|  | 943 | if (err < 0) | 
|  | 944 | return err; | 
|  | 945 | if (! err) | 
|  | 946 | continue; | 
|  | 947 | } | 
|  | 948 | } | 
|  | 949 | return 0; | 
|  | 950 | } | 
|  | 951 |  | 
|  | 952 | /* | 
|  | 953 | * build mixer controls | 
|  | 954 | */ | 
|  | 955 | static int build_generic_controls(struct hda_codec *codec) | 
|  | 956 | { | 
|  | 957 | int err; | 
|  | 958 |  | 
|  | 959 | if ((err = build_input_controls(codec)) < 0 || | 
|  | 960 | (err = build_output_controls(codec)) < 0 || | 
|  | 961 | (err = build_loopback_controls(codec)) < 0) | 
|  | 962 | return err; | 
|  | 963 |  | 
|  | 964 | return 0; | 
|  | 965 | } | 
|  | 966 |  | 
|  | 967 | /* | 
|  | 968 | * PCM | 
|  | 969 | */ | 
|  | 970 | static struct hda_pcm_stream generic_pcm_playback = { | 
|  | 971 | .substreams = 1, | 
|  | 972 | .channels_min = 2, | 
|  | 973 | .channels_max = 2, | 
|  | 974 | }; | 
|  | 975 |  | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 976 | static int generic_pcm2_prepare(struct hda_pcm_stream *hinfo, | 
|  | 977 | struct hda_codec *codec, | 
|  | 978 | unsigned int stream_tag, | 
|  | 979 | unsigned int format, | 
|  | 980 | struct snd_pcm_substream *substream) | 
|  | 981 | { | 
|  | 982 | struct hda_gspec *spec = codec->spec; | 
|  | 983 |  | 
|  | 984 | snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); | 
|  | 985 | snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, | 
|  | 986 | stream_tag, 0, format); | 
|  | 987 | return 0; | 
|  | 988 | } | 
|  | 989 |  | 
|  | 990 | static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo, | 
|  | 991 | struct hda_codec *codec, | 
|  | 992 | struct snd_pcm_substream *substream) | 
|  | 993 | { | 
|  | 994 | struct hda_gspec *spec = codec->spec; | 
|  | 995 |  | 
| Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 996 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); | 
|  | 997 | snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid); | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 998 | return 0; | 
|  | 999 | } | 
|  | 1000 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | static int build_generic_pcms(struct hda_codec *codec) | 
|  | 1002 | { | 
|  | 1003 | struct hda_gspec *spec = codec->spec; | 
|  | 1004 | struct hda_pcm *info = &spec->pcm_rec; | 
|  | 1005 |  | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 1006 | if (! spec->dac_node[0] && ! spec->adc_node) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | snd_printd("hda_generic: no PCM found\n"); | 
|  | 1008 | return 0; | 
|  | 1009 | } | 
|  | 1010 |  | 
|  | 1011 | codec->num_pcms = 1; | 
|  | 1012 | codec->pcm_info = info; | 
|  | 1013 |  | 
|  | 1014 | info->name = "HDA Generic"; | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 1015 | if (spec->dac_node[0]) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | info->stream[0] = generic_pcm_playback; | 
| Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 1017 | info->stream[0].nid = spec->dac_node[0]->nid; | 
|  | 1018 | if (spec->dac_node[1]) { | 
|  | 1019 | info->stream[0].ops.prepare = generic_pcm2_prepare; | 
|  | 1020 | info->stream[0].ops.cleanup = generic_pcm2_cleanup; | 
|  | 1021 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | } | 
|  | 1023 | if (spec->adc_node) { | 
|  | 1024 | info->stream[1] = generic_pcm_playback; | 
|  | 1025 | info->stream[1].nid = spec->adc_node->nid; | 
|  | 1026 | } | 
|  | 1027 |  | 
|  | 1028 | return 0; | 
|  | 1029 | } | 
|  | 1030 |  | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1031 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 
|  | 1032 | static int generic_check_power_status(struct hda_codec *codec, hda_nid_t nid) | 
|  | 1033 | { | 
|  | 1034 | struct hda_gspec *spec = codec->spec; | 
|  | 1035 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | 
|  | 1036 | } | 
|  | 1037 | #endif | 
|  | 1038 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 |  | 
|  | 1040 | /* | 
|  | 1041 | */ | 
|  | 1042 | static struct hda_codec_ops generic_patch_ops = { | 
|  | 1043 | .build_controls = build_generic_controls, | 
|  | 1044 | .build_pcms = build_generic_pcms, | 
|  | 1045 | .free = snd_hda_generic_free, | 
| Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1046 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 
|  | 1047 | .check_power_status = generic_check_power_status, | 
|  | 1048 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | }; | 
|  | 1050 |  | 
|  | 1051 | /* | 
|  | 1052 | * the generic parser | 
|  | 1053 | */ | 
|  | 1054 | int snd_hda_parse_generic_codec(struct hda_codec *codec) | 
|  | 1055 | { | 
|  | 1056 | struct hda_gspec *spec; | 
|  | 1057 | int err; | 
|  | 1058 |  | 
| Sasha Khapyorsky | 84802f0 | 2005-09-13 11:25:54 +0200 | [diff] [blame] | 1059 | if(!codec->afg) | 
|  | 1060 | return 0; | 
| Sasha Khapyorsky | 673b683 | 2005-08-11 11:00:16 +0200 | [diff] [blame] | 1061 |  | 
| Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 1062 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | if (spec == NULL) { | 
|  | 1064 | printk(KERN_ERR "hda_generic: can't allocate spec\n"); | 
|  | 1065 | return -ENOMEM; | 
|  | 1066 | } | 
|  | 1067 | codec->spec = spec; | 
|  | 1068 | INIT_LIST_HEAD(&spec->nid_list); | 
|  | 1069 |  | 
|  | 1070 | if ((err = build_afg_tree(codec)) < 0) | 
|  | 1071 | goto error; | 
|  | 1072 |  | 
|  | 1073 | if ((err = parse_input(codec)) < 0 || | 
|  | 1074 | (err = parse_output(codec)) < 0) | 
|  | 1075 | goto error; | 
|  | 1076 |  | 
|  | 1077 | codec->patch_ops = generic_patch_ops; | 
|  | 1078 |  | 
|  | 1079 | return 0; | 
|  | 1080 |  | 
|  | 1081 | error: | 
|  | 1082 | snd_hda_generic_free(codec); | 
|  | 1083 | return err; | 
|  | 1084 | } | 
| Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1085 | EXPORT_SYMBOL(snd_hda_parse_generic_codec); |