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> |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 26 | #include <linux/sort.h> |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 27 | #include <linux/delay.h> |
Takashi Iwai | f873e53 | 2012-12-20 16:58:39 +0100 | [diff] [blame] | 28 | #include <linux/ctype.h> |
| 29 | #include <linux/string.h> |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 30 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <sound/core.h> |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 32 | #include <sound/jack.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "hda_codec.h" |
| 34 | #include "hda_local.h" |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 35 | #include "hda_auto_parser.h" |
| 36 | #include "hda_jack.h" |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 37 | #include "hda_beep.h" |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 38 | #include "hda_generic.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 41 | /* initialize hda_gen_spec struct */ |
| 42 | int snd_hda_gen_spec_init(struct hda_gen_spec *spec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 44 | snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 45 | snd_array_init(&spec->paths, sizeof(struct nid_path), 8); |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 46 | snd_array_init(&spec->loopback_list, sizeof(struct hda_amp_list), 8); |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 47 | mutex_init(&spec->pcm_mutex); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | EXPORT_SYMBOL_HDA(snd_hda_gen_spec_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 52 | struct snd_kcontrol_new * |
| 53 | snd_hda_gen_add_kctl(struct hda_gen_spec *spec, const char *name, |
| 54 | const struct snd_kcontrol_new *temp) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 55 | { |
| 56 | struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls); |
| 57 | if (!knew) |
| 58 | return NULL; |
| 59 | *knew = *temp; |
| 60 | if (name) |
| 61 | knew->name = kstrdup(name, GFP_KERNEL); |
| 62 | else if (knew->name) |
| 63 | knew->name = kstrdup(knew->name, GFP_KERNEL); |
| 64 | if (!knew->name) |
| 65 | return NULL; |
| 66 | return knew; |
| 67 | } |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 68 | EXPORT_SYMBOL_HDA(snd_hda_gen_add_kctl); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 69 | |
| 70 | static void free_kctls(struct hda_gen_spec *spec) |
| 71 | { |
| 72 | if (spec->kctls.list) { |
| 73 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 74 | int i; |
| 75 | for (i = 0; i < spec->kctls.used; i++) |
| 76 | kfree(kctl[i].name); |
| 77 | } |
| 78 | snd_array_free(&spec->kctls); |
| 79 | } |
| 80 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 81 | void snd_hda_gen_spec_free(struct hda_gen_spec *spec) |
| 82 | { |
| 83 | if (!spec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | return; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 85 | free_kctls(spec); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 86 | snd_array_free(&spec->paths); |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 87 | snd_array_free(&spec->loopback_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 89 | EXPORT_SYMBOL_HDA(snd_hda_gen_spec_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
Takashi Iwai | 1c70a58 | 2013-01-11 17:48:22 +0100 | [diff] [blame] | 92 | * store user hints |
| 93 | */ |
| 94 | static void parse_user_hints(struct hda_codec *codec) |
| 95 | { |
| 96 | struct hda_gen_spec *spec = codec->spec; |
| 97 | int val; |
| 98 | |
| 99 | val = snd_hda_get_bool_hint(codec, "jack_detect"); |
| 100 | if (val >= 0) |
| 101 | codec->no_jack_detect = !val; |
| 102 | val = snd_hda_get_bool_hint(codec, "inv_jack_detect"); |
| 103 | if (val >= 0) |
| 104 | codec->inv_jack_detect = !!val; |
| 105 | val = snd_hda_get_bool_hint(codec, "trigger_sense"); |
| 106 | if (val >= 0) |
| 107 | codec->no_trigger_sense = !val; |
| 108 | val = snd_hda_get_bool_hint(codec, "inv_eapd"); |
| 109 | if (val >= 0) |
| 110 | codec->inv_eapd = !!val; |
| 111 | val = snd_hda_get_bool_hint(codec, "pcm_format_first"); |
| 112 | if (val >= 0) |
| 113 | codec->pcm_format_first = !!val; |
| 114 | val = snd_hda_get_bool_hint(codec, "sticky_stream"); |
| 115 | if (val >= 0) |
| 116 | codec->no_sticky_stream = !val; |
| 117 | val = snd_hda_get_bool_hint(codec, "spdif_status_reset"); |
| 118 | if (val >= 0) |
| 119 | codec->spdif_status_reset = !!val; |
| 120 | val = snd_hda_get_bool_hint(codec, "pin_amp_workaround"); |
| 121 | if (val >= 0) |
| 122 | codec->pin_amp_workaround = !!val; |
| 123 | val = snd_hda_get_bool_hint(codec, "single_adc_amp"); |
| 124 | if (val >= 0) |
| 125 | codec->single_adc_amp = !!val; |
| 126 | |
Takashi Iwai | f72706b | 2013-01-16 18:20:07 +0100 | [diff] [blame] | 127 | val = snd_hda_get_bool_hint(codec, "auto_mute"); |
| 128 | if (val >= 0) |
| 129 | spec->suppress_auto_mute = !val; |
Takashi Iwai | 1c70a58 | 2013-01-11 17:48:22 +0100 | [diff] [blame] | 130 | val = snd_hda_get_bool_hint(codec, "auto_mic"); |
| 131 | if (val >= 0) |
| 132 | spec->suppress_auto_mic = !val; |
| 133 | val = snd_hda_get_bool_hint(codec, "line_in_auto_switch"); |
| 134 | if (val >= 0) |
| 135 | spec->line_in_auto_switch = !!val; |
| 136 | val = snd_hda_get_bool_hint(codec, "need_dac_fix"); |
| 137 | if (val >= 0) |
| 138 | spec->need_dac_fix = !!val; |
| 139 | val = snd_hda_get_bool_hint(codec, "primary_hp"); |
| 140 | if (val >= 0) |
| 141 | spec->no_primary_hp = !val; |
| 142 | val = snd_hda_get_bool_hint(codec, "multi_cap_vol"); |
| 143 | if (val >= 0) |
| 144 | spec->multi_cap_vol = !!val; |
| 145 | val = snd_hda_get_bool_hint(codec, "inv_dmic_split"); |
| 146 | if (val >= 0) |
| 147 | spec->inv_dmic_split = !!val; |
| 148 | val = snd_hda_get_bool_hint(codec, "indep_hp"); |
| 149 | if (val >= 0) |
| 150 | spec->indep_hp = !!val; |
| 151 | val = snd_hda_get_bool_hint(codec, "add_stereo_mix_input"); |
| 152 | if (val >= 0) |
| 153 | spec->add_stereo_mix_input = !!val; |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 154 | /* the following two are just for compatibility */ |
Takashi Iwai | 1c70a58 | 2013-01-11 17:48:22 +0100 | [diff] [blame] | 155 | val = snd_hda_get_bool_hint(codec, "add_out_jack_modes"); |
| 156 | if (val >= 0) |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 157 | spec->add_jack_modes = !!val; |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 158 | val = snd_hda_get_bool_hint(codec, "add_in_jack_modes"); |
| 159 | if (val >= 0) |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 160 | spec->add_jack_modes = !!val; |
| 161 | val = snd_hda_get_bool_hint(codec, "add_jack_modes"); |
| 162 | if (val >= 0) |
| 163 | spec->add_jack_modes = !!val; |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 164 | val = snd_hda_get_bool_hint(codec, "power_down_unused"); |
| 165 | if (val >= 0) |
| 166 | spec->power_down_unused = !!val; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 167 | val = snd_hda_get_bool_hint(codec, "add_hp_mic"); |
| 168 | if (val >= 0) |
| 169 | spec->hp_mic = !!val; |
| 170 | val = snd_hda_get_bool_hint(codec, "hp_mic_detect"); |
| 171 | if (val >= 0) |
| 172 | spec->suppress_hp_mic_detect = !val; |
Takashi Iwai | 1c70a58 | 2013-01-11 17:48:22 +0100 | [diff] [blame] | 173 | |
| 174 | if (!snd_hda_get_int_hint(codec, "mixer_nid", &val)) |
| 175 | spec->mixer_nid = val; |
| 176 | } |
| 177 | |
| 178 | /* |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 179 | * pin control value accesses |
| 180 | */ |
| 181 | |
| 182 | #define update_pin_ctl(codec, pin, val) \ |
| 183 | snd_hda_codec_update_cache(codec, pin, 0, \ |
| 184 | AC_VERB_SET_PIN_WIDGET_CONTROL, val) |
| 185 | |
| 186 | /* restore the pinctl based on the cached value */ |
| 187 | static inline void restore_pin_ctl(struct hda_codec *codec, hda_nid_t pin) |
| 188 | { |
| 189 | update_pin_ctl(codec, pin, snd_hda_codec_get_pin_target(codec, pin)); |
| 190 | } |
| 191 | |
| 192 | /* set the pinctl target value and write it if requested */ |
| 193 | static void set_pin_target(struct hda_codec *codec, hda_nid_t pin, |
| 194 | unsigned int val, bool do_write) |
| 195 | { |
| 196 | if (!pin) |
| 197 | return; |
| 198 | val = snd_hda_correct_pin_ctl(codec, pin, val); |
| 199 | snd_hda_codec_set_pin_target(codec, pin, val); |
| 200 | if (do_write) |
| 201 | update_pin_ctl(codec, pin, val); |
| 202 | } |
| 203 | |
| 204 | /* set pinctl target values for all given pins */ |
| 205 | static void set_pin_targets(struct hda_codec *codec, int num_pins, |
| 206 | hda_nid_t *pins, unsigned int val) |
| 207 | { |
| 208 | int i; |
| 209 | for (i = 0; i < num_pins; i++) |
| 210 | set_pin_target(codec, pins[i], val, false); |
| 211 | } |
| 212 | |
| 213 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 214 | * parsing paths |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 217 | /* return the position of NID in the list, or -1 if not found */ |
| 218 | static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) |
| 219 | { |
| 220 | int i; |
| 221 | for (i = 0; i < nums; i++) |
| 222 | if (list[i] == nid) |
| 223 | return i; |
| 224 | return -1; |
| 225 | } |
| 226 | |
| 227 | /* return true if the given NID is contained in the path */ |
| 228 | static bool is_nid_contained(struct nid_path *path, hda_nid_t nid) |
| 229 | { |
| 230 | return find_idx_in_nid_list(nid, path->path, path->depth) >= 0; |
| 231 | } |
| 232 | |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 233 | static struct nid_path *get_nid_path(struct hda_codec *codec, |
| 234 | hda_nid_t from_nid, hda_nid_t to_nid, |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 235 | int anchor_nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 237 | struct hda_gen_spec *spec = codec->spec; |
| 238 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 240 | for (i = 0; i < spec->paths.used; i++) { |
| 241 | struct nid_path *path = snd_array_elem(&spec->paths, i); |
| 242 | if (path->depth <= 0) |
| 243 | continue; |
| 244 | if ((!from_nid || path->path[0] == from_nid) && |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 245 | (!to_nid || path->path[path->depth - 1] == to_nid)) { |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 246 | if (!anchor_nid || |
| 247 | (anchor_nid > 0 && is_nid_contained(path, anchor_nid)) || |
| 248 | (anchor_nid < 0 && !is_nid_contained(path, anchor_nid))) |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 249 | return path; |
| 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | return NULL; |
| 253 | } |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 254 | |
| 255 | /* get the path between the given NIDs; |
| 256 | * passing 0 to either @pin or @dac behaves as a wildcard |
| 257 | */ |
| 258 | struct nid_path *snd_hda_get_nid_path(struct hda_codec *codec, |
| 259 | hda_nid_t from_nid, hda_nid_t to_nid) |
| 260 | { |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 261 | return get_nid_path(codec, from_nid, to_nid, 0); |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 262 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 263 | EXPORT_SYMBOL_HDA(snd_hda_get_nid_path); |
| 264 | |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 265 | /* get the index number corresponding to the path instance; |
| 266 | * the index starts from 1, for easier checking the invalid value |
| 267 | */ |
| 268 | int snd_hda_get_path_idx(struct hda_codec *codec, struct nid_path *path) |
| 269 | { |
| 270 | struct hda_gen_spec *spec = codec->spec; |
| 271 | struct nid_path *array = spec->paths.list; |
| 272 | ssize_t idx; |
| 273 | |
| 274 | if (!spec->paths.used) |
| 275 | return 0; |
| 276 | idx = path - array; |
| 277 | if (idx < 0 || idx >= spec->paths.used) |
| 278 | return 0; |
| 279 | return idx + 1; |
| 280 | } |
Takashi Iwai | 4bd01e9 | 2013-01-22 15:17:20 +0100 | [diff] [blame] | 281 | EXPORT_SYMBOL_HDA(snd_hda_get_path_idx); |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 282 | |
| 283 | /* get the path instance corresponding to the given index number */ |
| 284 | struct nid_path *snd_hda_get_path_from_idx(struct hda_codec *codec, int idx) |
| 285 | { |
| 286 | struct hda_gen_spec *spec = codec->spec; |
| 287 | |
| 288 | if (idx <= 0 || idx > spec->paths.used) |
| 289 | return NULL; |
| 290 | return snd_array_elem(&spec->paths, idx - 1); |
| 291 | } |
Takashi Iwai | 4bd01e9 | 2013-01-22 15:17:20 +0100 | [diff] [blame] | 292 | EXPORT_SYMBOL_HDA(snd_hda_get_path_from_idx); |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 293 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 294 | /* check whether the given DAC is already found in any existing paths */ |
| 295 | static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) |
| 296 | { |
| 297 | struct hda_gen_spec *spec = codec->spec; |
| 298 | int i; |
| 299 | |
| 300 | for (i = 0; i < spec->paths.used; i++) { |
| 301 | struct nid_path *path = snd_array_elem(&spec->paths, i); |
| 302 | if (path->path[0] == nid) |
| 303 | return true; |
| 304 | } |
| 305 | return false; |
| 306 | } |
| 307 | |
| 308 | /* check whether the given two widgets can be connected */ |
| 309 | static bool is_reachable_path(struct hda_codec *codec, |
| 310 | hda_nid_t from_nid, hda_nid_t to_nid) |
| 311 | { |
| 312 | if (!from_nid || !to_nid) |
| 313 | return false; |
| 314 | return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0; |
| 315 | } |
| 316 | |
| 317 | /* nid, dir and idx */ |
| 318 | #define AMP_VAL_COMPARE_MASK (0xffff | (1U << 18) | (0x0f << 19)) |
| 319 | |
| 320 | /* check whether the given ctl is already assigned in any path elements */ |
| 321 | static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type) |
| 322 | { |
| 323 | struct hda_gen_spec *spec = codec->spec; |
| 324 | int i; |
| 325 | |
| 326 | val &= AMP_VAL_COMPARE_MASK; |
| 327 | for (i = 0; i < spec->paths.used; i++) { |
| 328 | struct nid_path *path = snd_array_elem(&spec->paths, i); |
| 329 | if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val) |
| 330 | return true; |
| 331 | } |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | /* check whether a control with the given (nid, dir, idx) was assigned */ |
| 336 | static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 337 | int dir, int idx, int type) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 338 | { |
| 339 | unsigned int val = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir); |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 340 | return is_ctl_used(codec, val, type); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 343 | static void print_nid_path(const char *pfx, struct nid_path *path) |
| 344 | { |
| 345 | char buf[40]; |
| 346 | int i; |
| 347 | |
| 348 | |
| 349 | buf[0] = 0; |
| 350 | for (i = 0; i < path->depth; i++) { |
| 351 | char tmp[4]; |
| 352 | sprintf(tmp, ":%02x", path->path[i]); |
| 353 | strlcat(buf, tmp, sizeof(buf)); |
| 354 | } |
| 355 | snd_printdd("%s path: depth=%d %s\n", pfx, path->depth, buf); |
| 356 | } |
| 357 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 358 | /* called recursively */ |
| 359 | static bool __parse_nid_path(struct hda_codec *codec, |
| 360 | hda_nid_t from_nid, hda_nid_t to_nid, |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 361 | int anchor_nid, struct nid_path *path, |
| 362 | int depth) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 363 | { |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 364 | const hda_nid_t *conn; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 365 | int i, nums; |
| 366 | |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 367 | if (to_nid == anchor_nid) |
| 368 | anchor_nid = 0; /* anchor passed */ |
| 369 | else if (to_nid == (hda_nid_t)(-anchor_nid)) |
| 370 | return false; /* hit the exclusive nid */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 371 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 372 | nums = snd_hda_get_conn_list(codec, to_nid, &conn); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 373 | for (i = 0; i < nums; i++) { |
| 374 | if (conn[i] != from_nid) { |
| 375 | /* special case: when from_nid is 0, |
| 376 | * try to find an empty DAC |
| 377 | */ |
| 378 | if (from_nid || |
| 379 | get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT || |
| 380 | is_dac_already_used(codec, conn[i])) |
| 381 | continue; |
| 382 | } |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 383 | /* anchor is not requested or already passed? */ |
| 384 | if (anchor_nid <= 0) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 385 | goto found; |
| 386 | } |
| 387 | if (depth >= MAX_NID_PATH_DEPTH) |
| 388 | return false; |
| 389 | for (i = 0; i < nums; i++) { |
| 390 | unsigned int type; |
| 391 | type = get_wcaps_type(get_wcaps(codec, conn[i])); |
| 392 | if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN || |
| 393 | type == AC_WID_PIN) |
| 394 | continue; |
| 395 | if (__parse_nid_path(codec, from_nid, conn[i], |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 396 | anchor_nid, path, depth + 1)) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 397 | goto found; |
| 398 | } |
| 399 | return false; |
| 400 | |
| 401 | found: |
| 402 | path->path[path->depth] = conn[i]; |
| 403 | path->idx[path->depth + 1] = i; |
| 404 | if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX) |
| 405 | path->multi[path->depth + 1] = 1; |
| 406 | path->depth++; |
| 407 | return true; |
| 408 | } |
| 409 | |
| 410 | /* parse the widget path from the given nid to the target nid; |
| 411 | * when @from_nid is 0, try to find an empty DAC; |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 412 | * when @anchor_nid is set to a positive value, only paths through the widget |
| 413 | * with the given value are evaluated. |
| 414 | * when @anchor_nid is set to a negative value, paths through the widget |
| 415 | * with the negative of given value are excluded, only other paths are chosen. |
| 416 | * when @anchor_nid is zero, no special handling about path selection. |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 417 | */ |
| 418 | bool snd_hda_parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid, |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 419 | hda_nid_t to_nid, int anchor_nid, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 420 | struct nid_path *path) |
| 421 | { |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 422 | if (__parse_nid_path(codec, from_nid, to_nid, anchor_nid, path, 1)) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 423 | path->path[path->depth] = to_nid; |
| 424 | path->depth++; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 425 | return true; |
| 426 | } |
| 427 | return false; |
| 428 | } |
| 429 | EXPORT_SYMBOL_HDA(snd_hda_parse_nid_path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 432 | * parse the path between the given NIDs and add to the path list. |
| 433 | * if no valid path is found, return NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 435 | struct nid_path * |
| 436 | snd_hda_add_new_path(struct hda_codec *codec, hda_nid_t from_nid, |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 437 | hda_nid_t to_nid, int anchor_nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 439 | struct hda_gen_spec *spec = codec->spec; |
| 440 | struct nid_path *path; |
| 441 | |
| 442 | if (from_nid && to_nid && !is_reachable_path(codec, from_nid, to_nid)) |
| 443 | return NULL; |
| 444 | |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 445 | /* check whether the path has been already added */ |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 446 | path = get_nid_path(codec, from_nid, to_nid, anchor_nid); |
Takashi Iwai | f5172a7 | 2013-01-04 13:19:55 +0100 | [diff] [blame] | 447 | if (path) |
| 448 | return path; |
| 449 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 450 | path = snd_array_new(&spec->paths); |
| 451 | if (!path) |
| 452 | return NULL; |
| 453 | memset(path, 0, sizeof(*path)); |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 454 | if (snd_hda_parse_nid_path(codec, from_nid, to_nid, anchor_nid, path)) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 455 | return path; |
| 456 | /* push back */ |
| 457 | spec->paths.used--; |
| 458 | return NULL; |
| 459 | } |
| 460 | EXPORT_SYMBOL_HDA(snd_hda_add_new_path); |
| 461 | |
Takashi Iwai | 980428c | 2013-01-09 09:28:20 +0100 | [diff] [blame] | 462 | /* clear the given path as invalid so that it won't be picked up later */ |
| 463 | static void invalidate_nid_path(struct hda_codec *codec, int idx) |
| 464 | { |
| 465 | struct nid_path *path = snd_hda_get_path_from_idx(codec, idx); |
| 466 | if (!path) |
| 467 | return; |
| 468 | memset(path, 0, sizeof(*path)); |
| 469 | } |
| 470 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 471 | /* look for an empty DAC slot */ |
| 472 | static hda_nid_t look_for_dac(struct hda_codec *codec, hda_nid_t pin, |
| 473 | bool is_digital) |
| 474 | { |
| 475 | struct hda_gen_spec *spec = codec->spec; |
| 476 | bool cap_digital; |
| 477 | int i; |
| 478 | |
| 479 | for (i = 0; i < spec->num_all_dacs; i++) { |
| 480 | hda_nid_t nid = spec->all_dacs[i]; |
| 481 | if (!nid || is_dac_already_used(codec, nid)) |
| 482 | continue; |
| 483 | cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL); |
| 484 | if (is_digital != cap_digital) |
| 485 | continue; |
| 486 | if (is_reachable_path(codec, nid, pin)) |
| 487 | return nid; |
| 488 | } |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | /* replace the channels in the composed amp value with the given number */ |
| 493 | static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs) |
| 494 | { |
| 495 | val &= ~(0x3U << 16); |
| 496 | val |= chs << 16; |
| 497 | return val; |
| 498 | } |
| 499 | |
| 500 | /* check whether the widget has the given amp capability for the direction */ |
| 501 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, |
| 502 | int dir, unsigned int bits) |
| 503 | { |
| 504 | if (!nid) |
| 505 | return false; |
| 506 | if (get_wcaps(codec, nid) & (1 << (dir + 1))) |
| 507 | if (query_amp_caps(codec, nid, dir) & bits) |
| 508 | return true; |
| 509 | return false; |
| 510 | } |
| 511 | |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 512 | static bool same_amp_caps(struct hda_codec *codec, hda_nid_t nid1, |
| 513 | hda_nid_t nid2, int dir) |
| 514 | { |
| 515 | if (!(get_wcaps(codec, nid1) & (1 << (dir + 1)))) |
| 516 | return !(get_wcaps(codec, nid2) & (1 << (dir + 1))); |
| 517 | return (query_amp_caps(codec, nid1, dir) == |
| 518 | query_amp_caps(codec, nid2, dir)); |
| 519 | } |
| 520 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 521 | #define nid_has_mute(codec, nid, dir) \ |
| 522 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
| 523 | #define nid_has_volume(codec, nid, dir) \ |
| 524 | check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS) |
| 525 | |
| 526 | /* look for a widget suitable for assigning a mute switch in the path */ |
| 527 | static hda_nid_t look_for_out_mute_nid(struct hda_codec *codec, |
| 528 | struct nid_path *path) |
| 529 | { |
| 530 | int i; |
| 531 | |
| 532 | for (i = path->depth - 1; i >= 0; i--) { |
| 533 | if (nid_has_mute(codec, path->path[i], HDA_OUTPUT)) |
| 534 | return path->path[i]; |
| 535 | if (i != path->depth - 1 && i != 0 && |
| 536 | nid_has_mute(codec, path->path[i], HDA_INPUT)) |
| 537 | return path->path[i]; |
| 538 | } |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /* look for a widget suitable for assigning a volume ctl in the path */ |
| 543 | static hda_nid_t look_for_out_vol_nid(struct hda_codec *codec, |
| 544 | struct nid_path *path) |
| 545 | { |
| 546 | int i; |
| 547 | |
| 548 | for (i = path->depth - 1; i >= 0; i--) { |
| 549 | if (nid_has_volume(codec, path->path[i], HDA_OUTPUT)) |
| 550 | return path->path[i]; |
| 551 | } |
Takashi Iwai | 82beb8f | 2007-08-10 17:09:26 +0200 | [diff] [blame] | 552 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 556 | * path activation / deactivation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 558 | |
| 559 | /* can have the amp-in capability? */ |
| 560 | static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 562 | hda_nid_t nid = path->path[idx]; |
| 563 | unsigned int caps = get_wcaps(codec, nid); |
| 564 | unsigned int type = get_wcaps_type(caps); |
| 565 | |
| 566 | if (!(caps & AC_WCAP_IN_AMP)) |
| 567 | return false; |
| 568 | if (type == AC_WID_PIN && idx > 0) /* only for input pins */ |
| 569 | return false; |
| 570 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 573 | /* can have the amp-out capability? */ |
| 574 | static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 576 | hda_nid_t nid = path->path[idx]; |
| 577 | unsigned int caps = get_wcaps(codec, nid); |
| 578 | unsigned int type = get_wcaps_type(caps); |
| 579 | |
| 580 | if (!(caps & AC_WCAP_OUT_AMP)) |
| 581 | return false; |
| 582 | if (type == AC_WID_PIN && !idx) /* only for output pins */ |
| 583 | return false; |
| 584 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 587 | /* check whether the given (nid,dir,idx) is active */ |
| 588 | static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 7dddf2ae | 2013-01-24 16:31:35 +0100 | [diff] [blame] | 589 | unsigned int dir, unsigned int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 591 | struct hda_gen_spec *spec = codec->spec; |
| 592 | int i, n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 594 | for (n = 0; n < spec->paths.used; n++) { |
| 595 | struct nid_path *path = snd_array_elem(&spec->paths, n); |
| 596 | if (!path->active) |
| 597 | continue; |
| 598 | for (i = 0; i < path->depth; i++) { |
| 599 | if (path->path[i] == nid) { |
| 600 | if (dir == HDA_OUTPUT || path->idx[i] == idx) |
| 601 | return true; |
| 602 | break; |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | return false; |
| 607 | } |
| 608 | |
| 609 | /* get the default amp value for the target state */ |
| 610 | static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 611 | int dir, unsigned int caps, bool enable) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 612 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 613 | unsigned int val = 0; |
| 614 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 615 | if (caps & AC_AMPCAP_NUM_STEPS) { |
| 616 | /* set to 0dB */ |
| 617 | if (enable) |
| 618 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; |
| 619 | } |
| 620 | if (caps & AC_AMPCAP_MUTE) { |
| 621 | if (!enable) |
| 622 | val |= HDA_AMP_MUTE; |
| 623 | } |
| 624 | return val; |
| 625 | } |
| 626 | |
| 627 | /* initialize the amp value (only at the first time) */ |
| 628 | static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx) |
| 629 | { |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 630 | unsigned int caps = query_amp_caps(codec, nid, dir); |
| 631 | int val = get_amp_val_to_activate(codec, nid, dir, caps, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 632 | snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val); |
| 633 | } |
| 634 | |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 635 | /* calculate amp value mask we can modify; |
| 636 | * if the given amp is controlled by mixers, don't touch it |
| 637 | */ |
| 638 | static unsigned int get_amp_mask_to_modify(struct hda_codec *codec, |
| 639 | hda_nid_t nid, int dir, int idx, |
| 640 | unsigned int caps) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 641 | { |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 642 | unsigned int mask = 0xff; |
| 643 | |
| 644 | if (caps & AC_AMPCAP_MUTE) { |
| 645 | if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_MUTE_CTL)) |
| 646 | mask &= ~0x80; |
| 647 | } |
| 648 | if (caps & AC_AMPCAP_NUM_STEPS) { |
| 649 | if (is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) || |
| 650 | is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL)) |
| 651 | mask &= ~0x7f; |
| 652 | } |
| 653 | return mask; |
| 654 | } |
| 655 | |
| 656 | static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 657 | int idx, int idx_to_check, bool enable) |
| 658 | { |
| 659 | unsigned int caps; |
| 660 | unsigned int mask, val; |
| 661 | |
Takashi Iwai | 7dddf2ae | 2013-01-24 16:31:35 +0100 | [diff] [blame] | 662 | if (!enable && is_active_nid(codec, nid, dir, idx_to_check)) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 663 | return; |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 664 | |
| 665 | caps = query_amp_caps(codec, nid, dir); |
| 666 | val = get_amp_val_to_activate(codec, nid, dir, caps, enable); |
| 667 | mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps); |
| 668 | if (!mask) |
| 669 | return; |
| 670 | |
| 671 | val &= mask; |
| 672 | snd_hda_codec_amp_stereo(codec, nid, dir, idx, mask, val); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static void activate_amp_out(struct hda_codec *codec, struct nid_path *path, |
| 676 | int i, bool enable) |
| 677 | { |
| 678 | hda_nid_t nid = path->path[i]; |
| 679 | init_amp(codec, nid, HDA_OUTPUT, 0); |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 680 | activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static void activate_amp_in(struct hda_codec *codec, struct nid_path *path, |
| 684 | int i, bool enable, bool add_aamix) |
| 685 | { |
| 686 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 687 | const hda_nid_t *conn; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 688 | int n, nums, idx; |
| 689 | int type; |
| 690 | hda_nid_t nid = path->path[i]; |
| 691 | |
Takashi Iwai | ee8e765 | 2013-01-03 15:25:11 +0100 | [diff] [blame] | 692 | nums = snd_hda_get_conn_list(codec, nid, &conn); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 693 | type = get_wcaps_type(get_wcaps(codec, nid)); |
| 694 | if (type == AC_WID_PIN || |
| 695 | (type == AC_WID_AUD_IN && codec->single_adc_amp)) { |
| 696 | nums = 1; |
| 697 | idx = 0; |
| 698 | } else |
| 699 | idx = path->idx[i]; |
| 700 | |
| 701 | for (n = 0; n < nums; n++) |
| 702 | init_amp(codec, nid, HDA_INPUT, n); |
| 703 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 704 | /* here is a little bit tricky in comparison with activate_amp_out(); |
| 705 | * when aa-mixer is available, we need to enable the path as well |
| 706 | */ |
| 707 | for (n = 0; n < nums; n++) { |
Takashi Iwai | e4a395e | 2013-01-23 17:00:31 +0100 | [diff] [blame] | 708 | if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid)) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 709 | continue; |
Takashi Iwai | 8999bf0 | 2013-01-18 11:01:33 +0100 | [diff] [blame] | 710 | activate_amp(codec, nid, HDA_INPUT, n, idx, enable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 714 | /* activate or deactivate the given path |
| 715 | * if @add_aamix is set, enable the input from aa-mix NID as well (if any) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 717 | void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path, |
| 718 | bool enable, bool add_aamix) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 720 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 721 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 723 | if (!enable) |
| 724 | path->active = false; |
| 725 | |
| 726 | for (i = path->depth - 1; i >= 0; i--) { |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 727 | hda_nid_t nid = path->path[i]; |
| 728 | if (enable && spec->power_down_unused) { |
| 729 | /* make sure the widget is powered up */ |
| 730 | if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) |
| 731 | snd_hda_codec_write(codec, nid, 0, |
| 732 | AC_VERB_SET_POWER_STATE, |
| 733 | AC_PWRST_D0); |
| 734 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 735 | if (enable && path->multi[i]) |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 736 | snd_hda_codec_write_cache(codec, nid, 0, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 737 | AC_VERB_SET_CONNECT_SEL, |
| 738 | path->idx[i]); |
| 739 | if (has_amp_in(codec, path, i)) |
| 740 | activate_amp_in(codec, path, i, enable, add_aamix); |
| 741 | if (has_amp_out(codec, path, i)) |
| 742 | activate_amp_out(codec, path, i, enable); |
| 743 | } |
| 744 | |
| 745 | if (enable) |
| 746 | path->active = true; |
| 747 | } |
| 748 | EXPORT_SYMBOL_HDA(snd_hda_activate_path); |
| 749 | |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 750 | /* if the given path is inactive, put widgets into D3 (only if suitable) */ |
| 751 | static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) |
| 752 | { |
| 753 | struct hda_gen_spec *spec = codec->spec; |
| 754 | bool changed; |
| 755 | int i; |
| 756 | |
| 757 | if (!spec->power_down_unused || path->active) |
| 758 | return; |
| 759 | |
| 760 | for (i = 0; i < path->depth; i++) { |
| 761 | hda_nid_t nid = path->path[i]; |
| 762 | if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3)) { |
| 763 | snd_hda_codec_write(codec, nid, 0, |
| 764 | AC_VERB_SET_POWER_STATE, |
| 765 | AC_PWRST_D3); |
| 766 | changed = true; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | if (changed) { |
| 771 | msleep(10); |
| 772 | snd_hda_codec_read(codec, path->path[0], 0, |
| 773 | AC_VERB_GET_POWER_STATE, 0); |
| 774 | } |
| 775 | } |
| 776 | |
Takashi Iwai | d5a9f1b | 2012-12-20 15:36:30 +0100 | [diff] [blame] | 777 | /* turn on/off EAPD on the given pin */ |
| 778 | static void set_pin_eapd(struct hda_codec *codec, hda_nid_t pin, bool enable) |
| 779 | { |
| 780 | struct hda_gen_spec *spec = codec->spec; |
| 781 | if (spec->own_eapd_ctl || |
| 782 | !(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)) |
| 783 | return; |
Takashi Iwai | ecac3ed | 2012-12-21 15:23:01 +0100 | [diff] [blame] | 784 | if (codec->inv_eapd) |
| 785 | enable = !enable; |
Takashi Iwai | d5a9f1b | 2012-12-20 15:36:30 +0100 | [diff] [blame] | 786 | snd_hda_codec_update_cache(codec, pin, 0, |
| 787 | AC_VERB_SET_EAPD_BTLENABLE, |
| 788 | enable ? 0x02 : 0x00); |
| 789 | } |
| 790 | |
Takashi Iwai | 3e367f1 | 2013-01-23 17:07:23 +0100 | [diff] [blame] | 791 | /* re-initialize the path specified by the given path index */ |
| 792 | static void resume_path_from_idx(struct hda_codec *codec, int path_idx) |
| 793 | { |
| 794 | struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx); |
| 795 | if (path) |
| 796 | snd_hda_activate_path(codec, path, path->active, false); |
| 797 | } |
| 798 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 799 | |
| 800 | /* |
| 801 | * Helper functions for creating mixer ctl elements |
| 802 | */ |
| 803 | |
| 804 | enum { |
| 805 | HDA_CTL_WIDGET_VOL, |
| 806 | HDA_CTL_WIDGET_MUTE, |
| 807 | HDA_CTL_BIND_MUTE, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 808 | }; |
| 809 | static const struct snd_kcontrol_new control_templates[] = { |
| 810 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 811 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
| 812 | HDA_BIND_MUTE(NULL, 0, 0, 0), |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 813 | }; |
| 814 | |
| 815 | /* add dynamic controls from template */ |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 816 | static struct snd_kcontrol_new * |
| 817 | add_control(struct hda_gen_spec *spec, int type, const char *name, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 818 | int cidx, unsigned long val) |
| 819 | { |
| 820 | struct snd_kcontrol_new *knew; |
| 821 | |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 822 | knew = snd_hda_gen_add_kctl(spec, name, &control_templates[type]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 823 | if (!knew) |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 824 | return NULL; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 825 | knew->index = cidx; |
| 826 | if (get_amp_nid_(val)) |
| 827 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
| 828 | knew->private_value = val; |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 829 | return knew; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | static int add_control_with_pfx(struct hda_gen_spec *spec, int type, |
| 833 | const char *pfx, const char *dir, |
| 834 | const char *sfx, int cidx, unsigned long val) |
| 835 | { |
| 836 | char name[32]; |
| 837 | snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx); |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 838 | if (!add_control(spec, type, name, cidx, val)) |
| 839 | return -ENOMEM; |
| 840 | return 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | #define add_pb_vol_ctrl(spec, type, pfx, val) \ |
| 844 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val) |
| 845 | #define add_pb_sw_ctrl(spec, type, pfx, val) \ |
| 846 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val) |
| 847 | #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \ |
| 848 | add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val) |
| 849 | #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ |
| 850 | add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) |
| 851 | |
| 852 | static int add_vol_ctl(struct hda_codec *codec, const char *pfx, int cidx, |
| 853 | unsigned int chs, struct nid_path *path) |
| 854 | { |
| 855 | unsigned int val; |
| 856 | if (!path) |
| 857 | return 0; |
| 858 | val = path->ctls[NID_PATH_VOL_CTL]; |
| 859 | if (!val) |
| 860 | return 0; |
| 861 | val = amp_val_replace_channels(val, chs); |
| 862 | return __add_pb_vol_ctrl(codec->spec, HDA_CTL_WIDGET_VOL, pfx, cidx, val); |
| 863 | } |
| 864 | |
| 865 | /* return the channel bits suitable for the given path->ctls[] */ |
| 866 | static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path, |
| 867 | int type) |
| 868 | { |
| 869 | int chs = 1; /* mono (left only) */ |
| 870 | if (path) { |
| 871 | hda_nid_t nid = get_amp_nid_(path->ctls[type]); |
| 872 | if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO)) |
| 873 | chs = 3; /* stereo */ |
| 874 | } |
| 875 | return chs; |
| 876 | } |
| 877 | |
| 878 | static int add_stereo_vol(struct hda_codec *codec, const char *pfx, int cidx, |
| 879 | struct nid_path *path) |
| 880 | { |
| 881 | int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL); |
| 882 | return add_vol_ctl(codec, pfx, cidx, chs, path); |
| 883 | } |
| 884 | |
| 885 | /* create a mute-switch for the given mixer widget; |
| 886 | * if it has multiple sources (e.g. DAC and loopback), create a bind-mute |
| 887 | */ |
| 888 | static int add_sw_ctl(struct hda_codec *codec, const char *pfx, int cidx, |
| 889 | unsigned int chs, struct nid_path *path) |
| 890 | { |
| 891 | unsigned int val; |
| 892 | int type = HDA_CTL_WIDGET_MUTE; |
| 893 | |
| 894 | if (!path) |
| 895 | return 0; |
| 896 | val = path->ctls[NID_PATH_MUTE_CTL]; |
| 897 | if (!val) |
| 898 | return 0; |
| 899 | val = amp_val_replace_channels(val, chs); |
| 900 | if (get_amp_direction_(val) == HDA_INPUT) { |
| 901 | hda_nid_t nid = get_amp_nid_(val); |
| 902 | int nums = snd_hda_get_num_conns(codec, nid); |
| 903 | if (nums > 1) { |
| 904 | type = HDA_CTL_BIND_MUTE; |
| 905 | val |= nums << 19; |
| 906 | } |
| 907 | } |
| 908 | return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); |
| 909 | } |
| 910 | |
| 911 | static int add_stereo_sw(struct hda_codec *codec, const char *pfx, |
| 912 | int cidx, struct nid_path *path) |
| 913 | { |
| 914 | int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL); |
| 915 | return add_sw_ctl(codec, pfx, cidx, chs, path); |
| 916 | } |
| 917 | |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 918 | /* any ctl assigned to the path with the given index? */ |
| 919 | static bool path_has_mixer(struct hda_codec *codec, int path_idx, int ctl_type) |
| 920 | { |
| 921 | struct nid_path *path = snd_hda_get_path_from_idx(codec, path_idx); |
| 922 | return path && path->ctls[ctl_type]; |
| 923 | } |
| 924 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 925 | static const char * const channel_name[4] = { |
| 926 | "Front", "Surround", "CLFE", "Side" |
| 927 | }; |
| 928 | |
| 929 | /* give some appropriate ctl name prefix for the given line out channel */ |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 930 | static const char *get_line_out_pfx(struct hda_codec *codec, int ch, |
| 931 | int *index, int ctl_type) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 932 | { |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 933 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 934 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 935 | |
| 936 | *index = 0; |
| 937 | if (cfg->line_outs == 1 && !spec->multi_ios && |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 938 | !cfg->hp_outs && !cfg->speaker_outs) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 939 | return spec->vmaster_mute.hook ? "PCM" : "Master"; |
| 940 | |
| 941 | /* if there is really a single DAC used in the whole output paths, |
| 942 | * use it master (or "PCM" if a vmaster hook is present) |
| 943 | */ |
| 944 | if (spec->multiout.num_dacs == 1 && !spec->mixer_nid && |
| 945 | !spec->multiout.hp_out_nid[0] && !spec->multiout.extra_out_nid[0]) |
| 946 | return spec->vmaster_mute.hook ? "PCM" : "Master"; |
| 947 | |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 948 | /* multi-io channels */ |
| 949 | if (ch >= cfg->line_outs) |
| 950 | return channel_name[ch]; |
| 951 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 952 | switch (cfg->line_out_type) { |
| 953 | case AUTO_PIN_SPEAKER_OUT: |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 954 | /* if the primary channel vol/mute is shared with HP volume, |
| 955 | * don't name it as Speaker |
| 956 | */ |
| 957 | if (!ch && cfg->hp_outs && |
| 958 | !path_has_mixer(codec, spec->hp_paths[0], ctl_type)) |
| 959 | break; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 960 | if (cfg->line_outs == 1) |
| 961 | return "Speaker"; |
| 962 | if (cfg->line_outs == 2) |
| 963 | return ch ? "Bass Speaker" : "Speaker"; |
| 964 | break; |
| 965 | case AUTO_PIN_HP_OUT: |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 966 | /* if the primary channel vol/mute is shared with spk volume, |
| 967 | * don't name it as Headphone |
| 968 | */ |
| 969 | if (!ch && cfg->speaker_outs && |
| 970 | !path_has_mixer(codec, spec->speaker_paths[0], ctl_type)) |
| 971 | break; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 972 | /* for multi-io case, only the primary out */ |
| 973 | if (ch && spec->multi_ios) |
| 974 | break; |
| 975 | *index = ch; |
| 976 | return "Headphone"; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 977 | } |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 978 | |
| 979 | /* for a single channel output, we don't have to name the channel */ |
| 980 | if (cfg->line_outs == 1 && !spec->multi_ios) |
| 981 | return "PCM"; |
| 982 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 983 | if (ch >= ARRAY_SIZE(channel_name)) { |
| 984 | snd_BUG(); |
| 985 | return "PCM"; |
| 986 | } |
| 987 | |
| 988 | return channel_name[ch]; |
| 989 | } |
| 990 | |
| 991 | /* |
| 992 | * Parse output paths |
| 993 | */ |
| 994 | |
| 995 | /* badness definition */ |
| 996 | enum { |
| 997 | /* No primary DAC is found for the main output */ |
| 998 | BAD_NO_PRIMARY_DAC = 0x10000, |
| 999 | /* No DAC is found for the extra output */ |
| 1000 | BAD_NO_DAC = 0x4000, |
| 1001 | /* No possible multi-ios */ |
Takashi Iwai | 1d73906 | 2013-02-13 14:17:32 +0100 | [diff] [blame] | 1002 | BAD_MULTI_IO = 0x120, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1003 | /* No individual DAC for extra output */ |
| 1004 | BAD_NO_EXTRA_DAC = 0x102, |
| 1005 | /* No individual DAC for extra surrounds */ |
| 1006 | BAD_NO_EXTRA_SURR_DAC = 0x101, |
| 1007 | /* Primary DAC shared with main surrounds */ |
| 1008 | BAD_SHARED_SURROUND = 0x100, |
Takashi Iwai | 55a63d4 | 2013-03-21 17:20:12 +0100 | [diff] [blame] | 1009 | /* No independent HP possible */ |
| 1010 | BAD_NO_INDEP_HP = 0x40, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1011 | /* Primary DAC shared with main CLFE */ |
| 1012 | BAD_SHARED_CLFE = 0x10, |
| 1013 | /* Primary DAC shared with extra surrounds */ |
| 1014 | BAD_SHARED_EXTRA_SURROUND = 0x10, |
| 1015 | /* Volume widget is shared */ |
| 1016 | BAD_SHARED_VOL = 0x10, |
| 1017 | }; |
| 1018 | |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1019 | /* look for widgets in the given path which are appropriate for |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1020 | * volume and mute controls, and assign the values to ctls[]. |
| 1021 | * |
| 1022 | * When no appropriate widget is found in the path, the badness value |
| 1023 | * is incremented depending on the situation. The function returns the |
| 1024 | * total badness for both volume and mute controls. |
| 1025 | */ |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1026 | static int assign_out_path_ctls(struct hda_codec *codec, struct nid_path *path) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1027 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1028 | hda_nid_t nid; |
| 1029 | unsigned int val; |
| 1030 | int badness = 0; |
| 1031 | |
| 1032 | if (!path) |
| 1033 | return BAD_SHARED_VOL * 2; |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1034 | |
| 1035 | if (path->ctls[NID_PATH_VOL_CTL] || |
| 1036 | path->ctls[NID_PATH_MUTE_CTL]) |
| 1037 | return 0; /* already evaluated */ |
| 1038 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1039 | nid = look_for_out_vol_nid(codec, path); |
| 1040 | if (nid) { |
| 1041 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 1042 | if (is_ctl_used(codec, val, NID_PATH_VOL_CTL)) |
| 1043 | badness += BAD_SHARED_VOL; |
| 1044 | else |
| 1045 | path->ctls[NID_PATH_VOL_CTL] = val; |
| 1046 | } else |
| 1047 | badness += BAD_SHARED_VOL; |
| 1048 | nid = look_for_out_mute_nid(codec, path); |
| 1049 | if (nid) { |
| 1050 | unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid)); |
| 1051 | if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT || |
| 1052 | nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 1053 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 1054 | else |
| 1055 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT); |
| 1056 | if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL)) |
| 1057 | badness += BAD_SHARED_VOL; |
| 1058 | else |
| 1059 | path->ctls[NID_PATH_MUTE_CTL] = val; |
| 1060 | } else |
| 1061 | badness += BAD_SHARED_VOL; |
| 1062 | return badness; |
| 1063 | } |
| 1064 | |
| 1065 | struct badness_table { |
| 1066 | int no_primary_dac; /* no primary DAC */ |
| 1067 | int no_dac; /* no secondary DACs */ |
| 1068 | int shared_primary; /* primary DAC is shared with main output */ |
| 1069 | int shared_surr; /* secondary DAC shared with main or primary */ |
| 1070 | int shared_clfe; /* third DAC shared with main or primary */ |
| 1071 | int shared_surr_main; /* secondary DAC sahred with main/DAC0 */ |
| 1072 | }; |
| 1073 | |
| 1074 | static struct badness_table main_out_badness = { |
| 1075 | .no_primary_dac = BAD_NO_PRIMARY_DAC, |
| 1076 | .no_dac = BAD_NO_DAC, |
| 1077 | .shared_primary = BAD_NO_PRIMARY_DAC, |
| 1078 | .shared_surr = BAD_SHARED_SURROUND, |
| 1079 | .shared_clfe = BAD_SHARED_CLFE, |
| 1080 | .shared_surr_main = BAD_SHARED_SURROUND, |
| 1081 | }; |
| 1082 | |
| 1083 | static struct badness_table extra_out_badness = { |
| 1084 | .no_primary_dac = BAD_NO_DAC, |
| 1085 | .no_dac = BAD_NO_DAC, |
| 1086 | .shared_primary = BAD_NO_EXTRA_DAC, |
| 1087 | .shared_surr = BAD_SHARED_EXTRA_SURROUND, |
| 1088 | .shared_clfe = BAD_SHARED_EXTRA_SURROUND, |
| 1089 | .shared_surr_main = BAD_NO_EXTRA_SURR_DAC, |
| 1090 | }; |
| 1091 | |
Takashi Iwai | 7385df6 | 2013-01-07 09:50:52 +0100 | [diff] [blame] | 1092 | /* get the DAC of the primary output corresponding to the given array index */ |
| 1093 | static hda_nid_t get_primary_out(struct hda_codec *codec, int idx) |
| 1094 | { |
| 1095 | struct hda_gen_spec *spec = codec->spec; |
| 1096 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1097 | |
| 1098 | if (cfg->line_outs > idx) |
| 1099 | return spec->private_dac_nids[idx]; |
| 1100 | idx -= cfg->line_outs; |
| 1101 | if (spec->multi_ios > idx) |
| 1102 | return spec->multi_io[idx].dac; |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | /* return the DAC if it's reachable, otherwise zero */ |
| 1107 | static inline hda_nid_t try_dac(struct hda_codec *codec, |
| 1108 | hda_nid_t dac, hda_nid_t pin) |
| 1109 | { |
| 1110 | return is_reachable_path(codec, dac, pin) ? dac : 0; |
| 1111 | } |
| 1112 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1113 | /* try to assign DACs to pins and return the resultant badness */ |
| 1114 | static int try_assign_dacs(struct hda_codec *codec, int num_outs, |
| 1115 | const hda_nid_t *pins, hda_nid_t *dacs, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1116 | int *path_idx, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1117 | const struct badness_table *bad) |
| 1118 | { |
| 1119 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1120 | int i, j; |
| 1121 | int badness = 0; |
| 1122 | hda_nid_t dac; |
| 1123 | |
| 1124 | if (!num_outs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | return 0; |
| 1126 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1127 | for (i = 0; i < num_outs; i++) { |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 1128 | struct nid_path *path; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1129 | hda_nid_t pin = pins[i]; |
Takashi Iwai | 1e0b528 | 2013-01-04 12:56:52 +0100 | [diff] [blame] | 1130 | |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1131 | path = snd_hda_get_path_from_idx(codec, path_idx[i]); |
| 1132 | if (path) { |
| 1133 | badness += assign_out_path_ctls(codec, path); |
Takashi Iwai | 1e0b528 | 2013-01-04 12:56:52 +0100 | [diff] [blame] | 1134 | continue; |
| 1135 | } |
| 1136 | |
| 1137 | dacs[i] = look_for_dac(codec, pin, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1138 | if (!dacs[i] && !i) { |
Takashi Iwai | 980428c | 2013-01-09 09:28:20 +0100 | [diff] [blame] | 1139 | /* try to steal the DAC of surrounds for the front */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1140 | for (j = 1; j < num_outs; j++) { |
| 1141 | if (is_reachable_path(codec, dacs[j], pin)) { |
| 1142 | dacs[0] = dacs[j]; |
| 1143 | dacs[j] = 0; |
Takashi Iwai | 980428c | 2013-01-09 09:28:20 +0100 | [diff] [blame] | 1144 | invalidate_nid_path(codec, path_idx[j]); |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1145 | path_idx[j] = 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1146 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } |
| 1148 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1149 | } |
| 1150 | dac = dacs[i]; |
| 1151 | if (!dac) { |
Takashi Iwai | 7385df6 | 2013-01-07 09:50:52 +0100 | [diff] [blame] | 1152 | if (num_outs > 2) |
| 1153 | dac = try_dac(codec, get_primary_out(codec, i), pin); |
| 1154 | if (!dac) |
| 1155 | dac = try_dac(codec, dacs[0], pin); |
| 1156 | if (!dac) |
| 1157 | dac = try_dac(codec, get_primary_out(codec, i), pin); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1158 | if (dac) { |
| 1159 | if (!i) |
| 1160 | badness += bad->shared_primary; |
| 1161 | else if (i == 1) |
| 1162 | badness += bad->shared_surr; |
| 1163 | else |
| 1164 | badness += bad->shared_clfe; |
| 1165 | } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) { |
| 1166 | dac = spec->private_dac_nids[0]; |
| 1167 | badness += bad->shared_surr_main; |
| 1168 | } else if (!i) |
| 1169 | badness += bad->no_primary_dac; |
| 1170 | else |
| 1171 | badness += bad->no_dac; |
| 1172 | } |
Takashi Iwai | 1fa335b | 2013-01-21 11:43:19 +0100 | [diff] [blame] | 1173 | if (!dac) |
| 1174 | continue; |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1175 | path = snd_hda_add_new_path(codec, dac, pin, -spec->mixer_nid); |
Takashi Iwai | 117688a | 2013-01-04 15:41:41 +0100 | [diff] [blame] | 1176 | if (!path && !i && spec->mixer_nid) { |
Takashi Iwai | b3a8c74 | 2012-12-20 18:29:16 +0100 | [diff] [blame] | 1177 | /* try with aamix */ |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1178 | path = snd_hda_add_new_path(codec, dac, pin, 0); |
Takashi Iwai | b3a8c74 | 2012-12-20 18:29:16 +0100 | [diff] [blame] | 1179 | } |
Takashi Iwai | 1fa335b | 2013-01-21 11:43:19 +0100 | [diff] [blame] | 1180 | if (!path) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1181 | dac = dacs[i] = 0; |
Takashi Iwai | 1fa335b | 2013-01-21 11:43:19 +0100 | [diff] [blame] | 1182 | badness += bad->no_dac; |
| 1183 | } else { |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1184 | /* print_nid_path("output", path); */ |
Takashi Iwai | e1284af | 2013-01-03 16:33:02 +0100 | [diff] [blame] | 1185 | path->active = true; |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1186 | path_idx[i] = snd_hda_get_path_idx(codec, path); |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1187 | badness += assign_out_path_ctls(codec, path); |
Takashi Iwai | e1284af | 2013-01-03 16:33:02 +0100 | [diff] [blame] | 1188 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | return badness; |
| 1192 | } |
| 1193 | |
| 1194 | /* return NID if the given pin has only a single connection to a certain DAC */ |
| 1195 | static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin) |
| 1196 | { |
| 1197 | struct hda_gen_spec *spec = codec->spec; |
| 1198 | int i; |
| 1199 | hda_nid_t nid_found = 0; |
| 1200 | |
| 1201 | for (i = 0; i < spec->num_all_dacs; i++) { |
| 1202 | hda_nid_t nid = spec->all_dacs[i]; |
| 1203 | if (!nid || is_dac_already_used(codec, nid)) |
| 1204 | continue; |
| 1205 | if (is_reachable_path(codec, nid, pin)) { |
| 1206 | if (nid_found) |
| 1207 | return 0; |
| 1208 | nid_found = nid; |
| 1209 | } |
| 1210 | } |
| 1211 | return nid_found; |
| 1212 | } |
| 1213 | |
| 1214 | /* check whether the given pin can be a multi-io pin */ |
| 1215 | static bool can_be_multiio_pin(struct hda_codec *codec, |
| 1216 | unsigned int location, hda_nid_t nid) |
| 1217 | { |
| 1218 | unsigned int defcfg, caps; |
| 1219 | |
| 1220 | defcfg = snd_hda_codec_get_pincfg(codec, nid); |
| 1221 | if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX) |
| 1222 | return false; |
| 1223 | if (location && get_defcfg_location(defcfg) != location) |
| 1224 | return false; |
| 1225 | caps = snd_hda_query_pin_caps(codec, nid); |
| 1226 | if (!(caps & AC_PINCAP_OUT)) |
| 1227 | return false; |
| 1228 | return true; |
| 1229 | } |
| 1230 | |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1231 | /* count the number of input pins that are capable to be multi-io */ |
| 1232 | static int count_multiio_pins(struct hda_codec *codec, hda_nid_t reference_pin) |
| 1233 | { |
| 1234 | struct hda_gen_spec *spec = codec->spec; |
| 1235 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1236 | unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin); |
| 1237 | unsigned int location = get_defcfg_location(defcfg); |
| 1238 | int type, i; |
| 1239 | int num_pins = 0; |
| 1240 | |
| 1241 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 1242 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1243 | if (cfg->inputs[i].type != type) |
| 1244 | continue; |
| 1245 | if (can_be_multiio_pin(codec, location, |
| 1246 | cfg->inputs[i].pin)) |
| 1247 | num_pins++; |
| 1248 | } |
| 1249 | } |
| 1250 | return num_pins; |
| 1251 | } |
| 1252 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1253 | /* |
| 1254 | * multi-io helper |
| 1255 | * |
| 1256 | * When hardwired is set, try to fill ony hardwired pins, and returns |
| 1257 | * zero if any pins are filled, non-zero if nothing found. |
| 1258 | * When hardwired is off, try to fill possible input pins, and returns |
| 1259 | * the badness value. |
| 1260 | */ |
| 1261 | static int fill_multi_ios(struct hda_codec *codec, |
| 1262 | hda_nid_t reference_pin, |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1263 | bool hardwired) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1264 | { |
| 1265 | struct hda_gen_spec *spec = codec->spec; |
| 1266 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1267 | int type, i, j, num_pins, old_pins; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1268 | unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin); |
| 1269 | unsigned int location = get_defcfg_location(defcfg); |
| 1270 | int badness = 0; |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1271 | struct nid_path *path; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1272 | |
| 1273 | old_pins = spec->multi_ios; |
| 1274 | if (old_pins >= 2) |
| 1275 | goto end_fill; |
| 1276 | |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1277 | num_pins = count_multiio_pins(codec, reference_pin); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1278 | if (num_pins < 2) |
| 1279 | goto end_fill; |
| 1280 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1281 | for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { |
| 1282 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1283 | hda_nid_t nid = cfg->inputs[i].pin; |
| 1284 | hda_nid_t dac = 0; |
| 1285 | |
| 1286 | if (cfg->inputs[i].type != type) |
| 1287 | continue; |
| 1288 | if (!can_be_multiio_pin(codec, location, nid)) |
| 1289 | continue; |
| 1290 | for (j = 0; j < spec->multi_ios; j++) { |
| 1291 | if (nid == spec->multi_io[j].pin) |
| 1292 | break; |
| 1293 | } |
| 1294 | if (j < spec->multi_ios) |
| 1295 | continue; |
| 1296 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1297 | if (hardwired) |
| 1298 | dac = get_dac_if_single(codec, nid); |
| 1299 | else if (!dac) |
| 1300 | dac = look_for_dac(codec, nid, false); |
| 1301 | if (!dac) { |
| 1302 | badness++; |
| 1303 | continue; |
| 1304 | } |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1305 | path = snd_hda_add_new_path(codec, dac, nid, |
| 1306 | -spec->mixer_nid); |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 1307 | if (!path) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1308 | badness++; |
| 1309 | continue; |
| 1310 | } |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1311 | /* print_nid_path("multiio", path); */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1312 | spec->multi_io[spec->multi_ios].pin = nid; |
| 1313 | spec->multi_io[spec->multi_ios].dac = dac; |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1314 | spec->out_paths[cfg->line_outs + spec->multi_ios] = |
| 1315 | snd_hda_get_path_idx(codec, path); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1316 | spec->multi_ios++; |
| 1317 | if (spec->multi_ios >= 2) |
| 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | end_fill: |
| 1322 | if (badness) |
| 1323 | badness = BAD_MULTI_IO; |
| 1324 | if (old_pins == spec->multi_ios) { |
| 1325 | if (hardwired) |
| 1326 | return 1; /* nothing found */ |
| 1327 | else |
| 1328 | return badness; /* no badness if nothing found */ |
| 1329 | } |
| 1330 | if (!hardwired && spec->multi_ios < 2) { |
| 1331 | /* cancel newly assigned paths */ |
| 1332 | spec->paths.used -= spec->multi_ios - old_pins; |
| 1333 | spec->multi_ios = old_pins; |
| 1334 | return badness; |
| 1335 | } |
| 1336 | |
| 1337 | /* assign volume and mute controls */ |
Takashi Iwai | 0e614dd | 2013-01-07 15:11:44 +0100 | [diff] [blame] | 1338 | for (i = old_pins; i < spec->multi_ios; i++) { |
| 1339 | path = snd_hda_get_path_from_idx(codec, spec->out_paths[cfg->line_outs + i]); |
| 1340 | badness += assign_out_path_ctls(codec, path); |
| 1341 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1342 | |
| 1343 | return badness; |
| 1344 | } |
| 1345 | |
| 1346 | /* map DACs for all pins in the list if they are single connections */ |
| 1347 | static bool map_singles(struct hda_codec *codec, int outs, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1348 | const hda_nid_t *pins, hda_nid_t *dacs, int *path_idx) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1349 | { |
Takashi Iwai | b3a8c74 | 2012-12-20 18:29:16 +0100 | [diff] [blame] | 1350 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1351 | int i; |
| 1352 | bool found = false; |
| 1353 | for (i = 0; i < outs; i++) { |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 1354 | struct nid_path *path; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1355 | hda_nid_t dac; |
| 1356 | if (dacs[i]) |
| 1357 | continue; |
| 1358 | dac = get_dac_if_single(codec, pins[i]); |
| 1359 | if (!dac) |
| 1360 | continue; |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1361 | path = snd_hda_add_new_path(codec, dac, pins[i], |
| 1362 | -spec->mixer_nid); |
Takashi Iwai | 117688a | 2013-01-04 15:41:41 +0100 | [diff] [blame] | 1363 | if (!path && !i && spec->mixer_nid) |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1364 | path = snd_hda_add_new_path(codec, dac, pins[i], 0); |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 1365 | if (path) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1366 | dacs[i] = dac; |
| 1367 | found = true; |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1368 | /* print_nid_path("output", path); */ |
Takashi Iwai | e1284af | 2013-01-03 16:33:02 +0100 | [diff] [blame] | 1369 | path->active = true; |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1370 | path_idx[i] = snd_hda_get_path_idx(codec, path); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1371 | } |
| 1372 | } |
| 1373 | return found; |
| 1374 | } |
| 1375 | |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1376 | /* create a new path including aamix if available, and return its index */ |
| 1377 | static int check_aamix_out_path(struct hda_codec *codec, int path_idx) |
| 1378 | { |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1379 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1380 | struct nid_path *path; |
Takashi Iwai | f87498b | 2013-01-21 14:24:31 +0100 | [diff] [blame] | 1381 | hda_nid_t dac, pin; |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1382 | |
| 1383 | path = snd_hda_get_path_from_idx(codec, path_idx); |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 1384 | if (!path || !path->depth || |
| 1385 | is_nid_contained(path, spec->mixer_nid)) |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1386 | return 0; |
Takashi Iwai | f87498b | 2013-01-21 14:24:31 +0100 | [diff] [blame] | 1387 | dac = path->path[0]; |
| 1388 | pin = path->path[path->depth - 1]; |
| 1389 | path = snd_hda_add_new_path(codec, dac, pin, spec->mixer_nid); |
| 1390 | if (!path) { |
| 1391 | if (dac != spec->multiout.dac_nids[0]) |
| 1392 | dac = spec->multiout.dac_nids[0]; |
| 1393 | else if (spec->multiout.hp_out_nid[0]) |
| 1394 | dac = spec->multiout.hp_out_nid[0]; |
| 1395 | else if (spec->multiout.extra_out_nid[0]) |
| 1396 | dac = spec->multiout.extra_out_nid[0]; |
| 1397 | if (dac) |
| 1398 | path = snd_hda_add_new_path(codec, dac, pin, |
| 1399 | spec->mixer_nid); |
| 1400 | } |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1401 | if (!path) |
| 1402 | return 0; |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1403 | /* print_nid_path("output-aamix", path); */ |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1404 | path->active = false; /* unused as default */ |
| 1405 | return snd_hda_get_path_idx(codec, path); |
| 1406 | } |
| 1407 | |
Takashi Iwai | 55a63d4 | 2013-03-21 17:20:12 +0100 | [diff] [blame] | 1408 | /* check whether the independent HP is available with the current config */ |
| 1409 | static bool indep_hp_possible(struct hda_codec *codec) |
| 1410 | { |
| 1411 | struct hda_gen_spec *spec = codec->spec; |
| 1412 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1413 | struct nid_path *path; |
| 1414 | int i, idx; |
| 1415 | |
| 1416 | if (cfg->line_out_type == AUTO_PIN_HP_OUT) |
| 1417 | idx = spec->out_paths[0]; |
| 1418 | else |
| 1419 | idx = spec->hp_paths[0]; |
| 1420 | path = snd_hda_get_path_from_idx(codec, idx); |
| 1421 | if (!path) |
| 1422 | return false; |
| 1423 | |
| 1424 | /* assume no path conflicts unless aamix is involved */ |
| 1425 | if (!spec->mixer_nid || !is_nid_contained(path, spec->mixer_nid)) |
| 1426 | return true; |
| 1427 | |
| 1428 | /* check whether output paths contain aamix */ |
| 1429 | for (i = 0; i < cfg->line_outs; i++) { |
| 1430 | if (spec->out_paths[i] == idx) |
| 1431 | break; |
| 1432 | path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]); |
| 1433 | if (path && is_nid_contained(path, spec->mixer_nid)) |
| 1434 | return false; |
| 1435 | } |
| 1436 | for (i = 0; i < cfg->speaker_outs; i++) { |
| 1437 | path = snd_hda_get_path_from_idx(codec, spec->speaker_paths[i]); |
| 1438 | if (path && is_nid_contained(path, spec->mixer_nid)) |
| 1439 | return false; |
| 1440 | } |
| 1441 | |
| 1442 | return true; |
| 1443 | } |
| 1444 | |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 1445 | /* fill the empty entries in the dac array for speaker/hp with the |
| 1446 | * shared dac pointed by the paths |
| 1447 | */ |
| 1448 | static void refill_shared_dacs(struct hda_codec *codec, int num_outs, |
| 1449 | hda_nid_t *dacs, int *path_idx) |
| 1450 | { |
| 1451 | struct nid_path *path; |
| 1452 | int i; |
| 1453 | |
| 1454 | for (i = 0; i < num_outs; i++) { |
| 1455 | if (dacs[i]) |
| 1456 | continue; |
| 1457 | path = snd_hda_get_path_from_idx(codec, path_idx[i]); |
| 1458 | if (!path) |
| 1459 | continue; |
| 1460 | dacs[i] = path->path[0]; |
| 1461 | } |
| 1462 | } |
| 1463 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1464 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 1465 | static int fill_and_eval_dacs(struct hda_codec *codec, |
| 1466 | bool fill_hardwired, |
| 1467 | bool fill_mio_first) |
| 1468 | { |
| 1469 | struct hda_gen_spec *spec = codec->spec; |
| 1470 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1471 | int i, err, badness; |
| 1472 | |
| 1473 | /* set num_dacs once to full for look_for_dac() */ |
| 1474 | spec->multiout.num_dacs = cfg->line_outs; |
| 1475 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 1476 | memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); |
| 1477 | memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid)); |
| 1478 | memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid)); |
| 1479 | spec->multi_ios = 0; |
| 1480 | snd_array_free(&spec->paths); |
Takashi Iwai | cd5be3f | 2013-01-07 15:07:00 +0100 | [diff] [blame] | 1481 | |
| 1482 | /* clear path indices */ |
| 1483 | memset(spec->out_paths, 0, sizeof(spec->out_paths)); |
| 1484 | memset(spec->hp_paths, 0, sizeof(spec->hp_paths)); |
| 1485 | memset(spec->speaker_paths, 0, sizeof(spec->speaker_paths)); |
| 1486 | memset(spec->aamix_out_paths, 0, sizeof(spec->aamix_out_paths)); |
| 1487 | memset(spec->digout_paths, 0, sizeof(spec->digout_paths)); |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 1488 | memset(spec->input_paths, 0, sizeof(spec->input_paths)); |
Takashi Iwai | cd5be3f | 2013-01-07 15:07:00 +0100 | [diff] [blame] | 1489 | memset(spec->loopback_paths, 0, sizeof(spec->loopback_paths)); |
| 1490 | memset(&spec->digin_path, 0, sizeof(spec->digin_path)); |
| 1491 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1492 | badness = 0; |
| 1493 | |
| 1494 | /* fill hard-wired DACs first */ |
| 1495 | if (fill_hardwired) { |
| 1496 | bool mapped; |
| 1497 | do { |
| 1498 | mapped = map_singles(codec, cfg->line_outs, |
| 1499 | cfg->line_out_pins, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1500 | spec->private_dac_nids, |
| 1501 | spec->out_paths); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1502 | mapped |= map_singles(codec, cfg->hp_outs, |
| 1503 | cfg->hp_pins, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1504 | spec->multiout.hp_out_nid, |
| 1505 | spec->hp_paths); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1506 | mapped |= map_singles(codec, cfg->speaker_outs, |
| 1507 | cfg->speaker_pins, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1508 | spec->multiout.extra_out_nid, |
| 1509 | spec->speaker_paths); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1510 | if (fill_mio_first && cfg->line_outs == 1 && |
| 1511 | cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1512 | err = fill_multi_ios(codec, cfg->line_out_pins[0], true); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1513 | if (!err) |
| 1514 | mapped = true; |
| 1515 | } |
| 1516 | } while (mapped); |
| 1517 | } |
| 1518 | |
| 1519 | badness += try_assign_dacs(codec, cfg->line_outs, cfg->line_out_pins, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1520 | spec->private_dac_nids, spec->out_paths, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1521 | &main_out_badness); |
| 1522 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1523 | if (fill_mio_first && |
| 1524 | cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 1525 | /* try to fill multi-io first */ |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1526 | err = fill_multi_ios(codec, cfg->line_out_pins[0], false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1527 | if (err < 0) |
| 1528 | return err; |
| 1529 | /* we don't count badness at this stage yet */ |
| 1530 | } |
| 1531 | |
| 1532 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { |
| 1533 | err = try_assign_dacs(codec, cfg->hp_outs, cfg->hp_pins, |
| 1534 | spec->multiout.hp_out_nid, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1535 | spec->hp_paths, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1536 | &extra_out_badness); |
| 1537 | if (err < 0) |
| 1538 | return err; |
| 1539 | badness += err; |
| 1540 | } |
| 1541 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 1542 | err = try_assign_dacs(codec, cfg->speaker_outs, |
| 1543 | cfg->speaker_pins, |
| 1544 | spec->multiout.extra_out_nid, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1545 | spec->speaker_paths, |
| 1546 | &extra_out_badness); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1547 | if (err < 0) |
| 1548 | return err; |
| 1549 | badness += err; |
| 1550 | } |
| 1551 | if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1552 | err = fill_multi_ios(codec, cfg->line_out_pins[0], false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1553 | if (err < 0) |
| 1554 | return err; |
| 1555 | badness += err; |
| 1556 | } |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1557 | |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 1558 | if (spec->mixer_nid) { |
| 1559 | spec->aamix_out_paths[0] = |
| 1560 | check_aamix_out_path(codec, spec->out_paths[0]); |
| 1561 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 1562 | spec->aamix_out_paths[1] = |
| 1563 | check_aamix_out_path(codec, spec->hp_paths[0]); |
| 1564 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 1565 | spec->aamix_out_paths[2] = |
| 1566 | check_aamix_out_path(codec, spec->speaker_paths[0]); |
| 1567 | } |
| 1568 | |
Takashi Iwai | e22aab7 | 2013-01-04 14:50:04 +0100 | [diff] [blame] | 1569 | if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 1570 | if (count_multiio_pins(codec, cfg->hp_pins[0]) >= 2) |
| 1571 | spec->multi_ios = 1; /* give badness */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1572 | |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 1573 | /* re-count num_dacs and squash invalid entries */ |
| 1574 | spec->multiout.num_dacs = 0; |
| 1575 | for (i = 0; i < cfg->line_outs; i++) { |
| 1576 | if (spec->private_dac_nids[i]) |
| 1577 | spec->multiout.num_dacs++; |
| 1578 | else { |
| 1579 | memmove(spec->private_dac_nids + i, |
| 1580 | spec->private_dac_nids + i + 1, |
| 1581 | sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); |
| 1582 | spec->private_dac_nids[cfg->line_outs - 1] = 0; |
| 1583 | } |
| 1584 | } |
| 1585 | |
| 1586 | spec->ext_channel_count = spec->min_channel_count = |
David Henningsson | c0f3b21 | 2013-01-16 11:45:37 +0100 | [diff] [blame] | 1587 | spec->multiout.num_dacs * 2; |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 1588 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1589 | if (spec->multi_ios == 2) { |
| 1590 | for (i = 0; i < 2; i++) |
| 1591 | spec->private_dac_nids[spec->multiout.num_dacs++] = |
| 1592 | spec->multi_io[i].dac; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1593 | } else if (spec->multi_ios) { |
| 1594 | spec->multi_ios = 0; |
| 1595 | badness += BAD_MULTI_IO; |
| 1596 | } |
| 1597 | |
Takashi Iwai | 55a63d4 | 2013-03-21 17:20:12 +0100 | [diff] [blame] | 1598 | if (spec->indep_hp && !indep_hp_possible(codec)) |
| 1599 | badness += BAD_NO_INDEP_HP; |
| 1600 | |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 1601 | /* re-fill the shared DAC for speaker / headphone */ |
| 1602 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 1603 | refill_shared_dacs(codec, cfg->hp_outs, |
| 1604 | spec->multiout.hp_out_nid, |
| 1605 | spec->hp_paths); |
| 1606 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 1607 | refill_shared_dacs(codec, cfg->speaker_outs, |
| 1608 | spec->multiout.extra_out_nid, |
| 1609 | spec->speaker_paths); |
| 1610 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1611 | return badness; |
| 1612 | } |
| 1613 | |
| 1614 | #define DEBUG_BADNESS |
| 1615 | |
| 1616 | #ifdef DEBUG_BADNESS |
| 1617 | #define debug_badness snd_printdd |
| 1618 | #else |
| 1619 | #define debug_badness(...) |
| 1620 | #endif |
| 1621 | |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1622 | #ifdef DEBUG_BADNESS |
| 1623 | static inline void print_nid_path_idx(struct hda_codec *codec, |
| 1624 | const char *pfx, int idx) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1625 | { |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1626 | struct nid_path *path; |
| 1627 | |
| 1628 | path = snd_hda_get_path_from_idx(codec, idx); |
| 1629 | if (path) |
| 1630 | print_nid_path(pfx, path); |
| 1631 | } |
| 1632 | |
| 1633 | static void debug_show_configs(struct hda_codec *codec, |
| 1634 | struct auto_pin_cfg *cfg) |
| 1635 | { |
| 1636 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1637 | static const char * const lo_type[3] = { "LO", "SP", "HP" }; |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1638 | int i; |
| 1639 | |
| 1640 | debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x (type %s)\n", |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1641 | cfg->line_out_pins[0], cfg->line_out_pins[1], |
Takashi Iwai | 708122e | 2012-12-20 17:56:57 +0100 | [diff] [blame] | 1642 | cfg->line_out_pins[2], cfg->line_out_pins[3], |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1643 | spec->multiout.dac_nids[0], |
| 1644 | spec->multiout.dac_nids[1], |
| 1645 | spec->multiout.dac_nids[2], |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1646 | spec->multiout.dac_nids[3], |
| 1647 | lo_type[cfg->line_out_type]); |
| 1648 | for (i = 0; i < cfg->line_outs; i++) |
| 1649 | print_nid_path_idx(codec, " out", spec->out_paths[i]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1650 | if (spec->multi_ios > 0) |
| 1651 | debug_badness("multi_ios(%d) = %x/%x : %x/%x\n", |
| 1652 | spec->multi_ios, |
| 1653 | spec->multi_io[0].pin, spec->multi_io[1].pin, |
| 1654 | spec->multi_io[0].dac, spec->multi_io[1].dac); |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1655 | for (i = 0; i < spec->multi_ios; i++) |
| 1656 | print_nid_path_idx(codec, " mio", |
| 1657 | spec->out_paths[cfg->line_outs + i]); |
| 1658 | if (cfg->hp_outs) |
| 1659 | debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1660 | cfg->hp_pins[0], cfg->hp_pins[1], |
Takashi Iwai | 708122e | 2012-12-20 17:56:57 +0100 | [diff] [blame] | 1661 | cfg->hp_pins[2], cfg->hp_pins[3], |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1662 | spec->multiout.hp_out_nid[0], |
| 1663 | spec->multiout.hp_out_nid[1], |
| 1664 | spec->multiout.hp_out_nid[2], |
| 1665 | spec->multiout.hp_out_nid[3]); |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1666 | for (i = 0; i < cfg->hp_outs; i++) |
| 1667 | print_nid_path_idx(codec, " hp ", spec->hp_paths[i]); |
| 1668 | if (cfg->speaker_outs) |
| 1669 | debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n", |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1670 | cfg->speaker_pins[0], cfg->speaker_pins[1], |
| 1671 | cfg->speaker_pins[2], cfg->speaker_pins[3], |
| 1672 | spec->multiout.extra_out_nid[0], |
| 1673 | spec->multiout.extra_out_nid[1], |
| 1674 | spec->multiout.extra_out_nid[2], |
| 1675 | spec->multiout.extra_out_nid[3]); |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1676 | for (i = 0; i < cfg->speaker_outs; i++) |
| 1677 | print_nid_path_idx(codec, " spk", spec->speaker_paths[i]); |
| 1678 | for (i = 0; i < 3; i++) |
| 1679 | print_nid_path_idx(codec, " mix", spec->aamix_out_paths[i]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1680 | } |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1681 | #else |
| 1682 | #define debug_show_configs(codec, cfg) /* NOP */ |
| 1683 | #endif |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1684 | |
| 1685 | /* find all available DACs of the codec */ |
| 1686 | static void fill_all_dac_nids(struct hda_codec *codec) |
| 1687 | { |
| 1688 | struct hda_gen_spec *spec = codec->spec; |
| 1689 | int i; |
| 1690 | hda_nid_t nid = codec->start_nid; |
| 1691 | |
| 1692 | spec->num_all_dacs = 0; |
| 1693 | memset(spec->all_dacs, 0, sizeof(spec->all_dacs)); |
| 1694 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 1695 | if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT) |
| 1696 | continue; |
| 1697 | if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) { |
| 1698 | snd_printk(KERN_ERR "hda: Too many DACs!\n"); |
| 1699 | break; |
| 1700 | } |
| 1701 | spec->all_dacs[spec->num_all_dacs++] = nid; |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | static int parse_output_paths(struct hda_codec *codec) |
| 1706 | { |
| 1707 | struct hda_gen_spec *spec = codec->spec; |
| 1708 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1709 | struct auto_pin_cfg *best_cfg; |
Takashi Iwai | 9314a58 | 2013-01-21 10:49:05 +0100 | [diff] [blame] | 1710 | unsigned int val; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1711 | int best_badness = INT_MAX; |
| 1712 | int badness; |
| 1713 | bool fill_hardwired = true, fill_mio_first = true; |
| 1714 | bool best_wired = true, best_mio = true; |
| 1715 | bool hp_spk_swapped = false; |
| 1716 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1717 | best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL); |
| 1718 | if (!best_cfg) |
| 1719 | return -ENOMEM; |
| 1720 | *best_cfg = *cfg; |
| 1721 | |
| 1722 | for (;;) { |
| 1723 | badness = fill_and_eval_dacs(codec, fill_hardwired, |
| 1724 | fill_mio_first); |
| 1725 | if (badness < 0) { |
| 1726 | kfree(best_cfg); |
| 1727 | return badness; |
| 1728 | } |
| 1729 | debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n", |
| 1730 | cfg->line_out_type, fill_hardwired, fill_mio_first, |
| 1731 | badness); |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1732 | debug_show_configs(codec, cfg); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1733 | if (badness < best_badness) { |
| 1734 | best_badness = badness; |
| 1735 | *best_cfg = *cfg; |
| 1736 | best_wired = fill_hardwired; |
| 1737 | best_mio = fill_mio_first; |
| 1738 | } |
| 1739 | if (!badness) |
| 1740 | break; |
| 1741 | fill_mio_first = !fill_mio_first; |
| 1742 | if (!fill_mio_first) |
| 1743 | continue; |
| 1744 | fill_hardwired = !fill_hardwired; |
| 1745 | if (!fill_hardwired) |
| 1746 | continue; |
| 1747 | if (hp_spk_swapped) |
| 1748 | break; |
| 1749 | hp_spk_swapped = true; |
| 1750 | if (cfg->speaker_outs > 0 && |
| 1751 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
| 1752 | cfg->hp_outs = cfg->line_outs; |
| 1753 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 1754 | sizeof(cfg->hp_pins)); |
| 1755 | cfg->line_outs = cfg->speaker_outs; |
| 1756 | memcpy(cfg->line_out_pins, cfg->speaker_pins, |
| 1757 | sizeof(cfg->speaker_pins)); |
| 1758 | cfg->speaker_outs = 0; |
| 1759 | memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins)); |
| 1760 | cfg->line_out_type = AUTO_PIN_SPEAKER_OUT; |
| 1761 | fill_hardwired = true; |
| 1762 | continue; |
| 1763 | } |
| 1764 | if (cfg->hp_outs > 0 && |
| 1765 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 1766 | cfg->speaker_outs = cfg->line_outs; |
| 1767 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 1768 | sizeof(cfg->speaker_pins)); |
| 1769 | cfg->line_outs = cfg->hp_outs; |
| 1770 | memcpy(cfg->line_out_pins, cfg->hp_pins, |
| 1771 | sizeof(cfg->hp_pins)); |
| 1772 | cfg->hp_outs = 0; |
| 1773 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 1774 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 1775 | fill_hardwired = true; |
| 1776 | continue; |
| 1777 | } |
| 1778 | break; |
| 1779 | } |
| 1780 | |
| 1781 | if (badness) { |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 1782 | debug_badness("==> restoring best_cfg\n"); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1783 | *cfg = *best_cfg; |
| 1784 | fill_and_eval_dacs(codec, best_wired, best_mio); |
| 1785 | } |
| 1786 | debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n", |
| 1787 | cfg->line_out_type, best_wired, best_mio); |
Takashi Iwai | a769409 | 2013-01-21 10:43:18 +0100 | [diff] [blame] | 1788 | debug_show_configs(codec, cfg); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1789 | |
| 1790 | if (cfg->line_out_pins[0]) { |
| 1791 | struct nid_path *path; |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1792 | path = snd_hda_get_path_from_idx(codec, spec->out_paths[0]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1793 | if (path) |
| 1794 | spec->vmaster_nid = look_for_out_vol_nid(codec, path); |
Takashi Iwai | 7a71bbf | 2013-01-17 10:25:15 +0100 | [diff] [blame] | 1795 | if (spec->vmaster_nid) |
| 1796 | snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, |
| 1797 | HDA_OUTPUT, spec->vmaster_tlv); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1798 | } |
| 1799 | |
Takashi Iwai | 9314a58 | 2013-01-21 10:49:05 +0100 | [diff] [blame] | 1800 | /* set initial pinctl targets */ |
| 1801 | if (spec->prefer_hp_amp || cfg->line_out_type == AUTO_PIN_HP_OUT) |
| 1802 | val = PIN_HP; |
| 1803 | else |
| 1804 | val = PIN_OUT; |
| 1805 | set_pin_targets(codec, cfg->line_outs, cfg->line_out_pins, val); |
| 1806 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 1807 | set_pin_targets(codec, cfg->hp_outs, cfg->hp_pins, PIN_HP); |
| 1808 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 1809 | val = spec->prefer_hp_amp ? PIN_HP : PIN_OUT; |
| 1810 | set_pin_targets(codec, cfg->speaker_outs, |
| 1811 | cfg->speaker_pins, val); |
| 1812 | } |
| 1813 | |
Takashi Iwai | 55a63d4 | 2013-03-21 17:20:12 +0100 | [diff] [blame] | 1814 | /* clear indep_hp flag if not available */ |
| 1815 | if (spec->indep_hp && !indep_hp_possible(codec)) |
| 1816 | spec->indep_hp = 0; |
| 1817 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1818 | kfree(best_cfg); |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | /* add playback controls from the parsed DAC table */ |
| 1823 | static int create_multi_out_ctls(struct hda_codec *codec, |
| 1824 | const struct auto_pin_cfg *cfg) |
| 1825 | { |
| 1826 | struct hda_gen_spec *spec = codec->spec; |
| 1827 | int i, err, noutputs; |
| 1828 | |
| 1829 | noutputs = cfg->line_outs; |
| 1830 | if (spec->multi_ios > 0 && cfg->line_outs < 3) |
| 1831 | noutputs += spec->multi_ios; |
| 1832 | |
| 1833 | for (i = 0; i < noutputs; i++) { |
| 1834 | const char *name; |
| 1835 | int index; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1836 | struct nid_path *path; |
| 1837 | |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1838 | path = snd_hda_get_path_from_idx(codec, spec->out_paths[i]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1839 | if (!path) |
| 1840 | continue; |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 1841 | |
| 1842 | name = get_line_out_pfx(codec, i, &index, NID_PATH_VOL_CTL); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1843 | if (!name || !strcmp(name, "CLFE")) { |
| 1844 | /* Center/LFE */ |
| 1845 | err = add_vol_ctl(codec, "Center", 0, 1, path); |
| 1846 | if (err < 0) |
| 1847 | return err; |
| 1848 | err = add_vol_ctl(codec, "LFE", 0, 2, path); |
| 1849 | if (err < 0) |
| 1850 | return err; |
Takashi Iwai | 247d85e | 2013-01-17 16:18:11 +0100 | [diff] [blame] | 1851 | } else { |
| 1852 | err = add_stereo_vol(codec, name, index, path); |
| 1853 | if (err < 0) |
| 1854 | return err; |
| 1855 | } |
| 1856 | |
| 1857 | name = get_line_out_pfx(codec, i, &index, NID_PATH_MUTE_CTL); |
| 1858 | if (!name || !strcmp(name, "CLFE")) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1859 | err = add_sw_ctl(codec, "Center", 0, 1, path); |
| 1860 | if (err < 0) |
| 1861 | return err; |
| 1862 | err = add_sw_ctl(codec, "LFE", 0, 2, path); |
| 1863 | if (err < 0) |
| 1864 | return err; |
| 1865 | } else { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1866 | err = add_stereo_sw(codec, name, index, path); |
| 1867 | if (err < 0) |
| 1868 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | return 0; |
| 1872 | } |
| 1873 | |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1874 | static int create_extra_out(struct hda_codec *codec, int path_idx, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1875 | const char *pfx, int cidx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1877 | struct nid_path *path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | int err; |
| 1879 | |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1880 | path = snd_hda_get_path_from_idx(codec, path_idx); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1881 | if (!path) |
| 1882 | return 0; |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1883 | err = add_stereo_vol(codec, pfx, cidx, path); |
| 1884 | if (err < 0) |
| 1885 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1886 | err = add_stereo_sw(codec, pfx, cidx, path); |
| 1887 | if (err < 0) |
| 1888 | return err; |
| 1889 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1892 | /* add playback controls for speaker and HP outputs */ |
| 1893 | static int create_extra_outs(struct hda_codec *codec, int num_pins, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1894 | const int *paths, const char *pfx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | { |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1896 | int i; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1897 | |
| 1898 | for (i = 0; i < num_pins; i++) { |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1899 | const char *name; |
| 1900 | char tmp[44]; |
| 1901 | int err, idx = 0; |
| 1902 | |
| 1903 | if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) |
| 1904 | name = "Bass Speaker"; |
| 1905 | else if (num_pins >= 3) { |
| 1906 | snprintf(tmp, sizeof(tmp), "%s %s", |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1907 | pfx, channel_name[i]); |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1908 | name = tmp; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1909 | } else { |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1910 | name = pfx; |
| 1911 | idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
Takashi Iwai | c2c8038 | 2013-01-07 10:33:57 +0100 | [diff] [blame] | 1913 | err = create_extra_out(codec, paths[i], name, idx); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1914 | if (err < 0) |
| 1915 | return err; |
| 1916 | } |
| 1917 | return 0; |
| 1918 | } |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 1919 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1920 | static int create_hp_out_ctls(struct hda_codec *codec) |
| 1921 | { |
| 1922 | struct hda_gen_spec *spec = codec->spec; |
| 1923 | return create_extra_outs(codec, spec->autocfg.hp_outs, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1924 | spec->hp_paths, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1925 | "Headphone"); |
| 1926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1928 | static int create_speaker_out_ctls(struct hda_codec *codec) |
| 1929 | { |
| 1930 | struct hda_gen_spec *spec = codec->spec; |
| 1931 | return create_extra_outs(codec, spec->autocfg.speaker_outs, |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 1932 | spec->speaker_paths, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 1933 | "Speaker"); |
| 1934 | } |
| 1935 | |
| 1936 | /* |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 1937 | * independent HP controls |
| 1938 | */ |
| 1939 | |
Takashi Iwai | 8ba955c | 2013-03-07 18:40:58 +0100 | [diff] [blame] | 1940 | /* update HP auto-mute state too */ |
| 1941 | static void update_hp_automute_hook(struct hda_codec *codec) |
| 1942 | { |
| 1943 | struct hda_gen_spec *spec = codec->spec; |
| 1944 | |
| 1945 | if (spec->hp_automute_hook) |
| 1946 | spec->hp_automute_hook(codec, NULL); |
| 1947 | else |
| 1948 | snd_hda_gen_hp_automute(codec, NULL); |
| 1949 | } |
| 1950 | |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 1951 | static int indep_hp_info(struct snd_kcontrol *kcontrol, |
| 1952 | struct snd_ctl_elem_info *uinfo) |
| 1953 | { |
| 1954 | return snd_hda_enum_bool_helper_info(kcontrol, uinfo); |
| 1955 | } |
| 1956 | |
| 1957 | static int indep_hp_get(struct snd_kcontrol *kcontrol, |
| 1958 | struct snd_ctl_elem_value *ucontrol) |
| 1959 | { |
| 1960 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1961 | struct hda_gen_spec *spec = codec->spec; |
| 1962 | ucontrol->value.enumerated.item[0] = spec->indep_hp_enabled; |
| 1963 | return 0; |
| 1964 | } |
| 1965 | |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 1966 | static void update_aamix_paths(struct hda_codec *codec, bool do_mix, |
| 1967 | int nomix_path_idx, int mix_path_idx, |
| 1968 | int out_type); |
| 1969 | |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 1970 | static int indep_hp_put(struct snd_kcontrol *kcontrol, |
| 1971 | struct snd_ctl_elem_value *ucontrol) |
| 1972 | { |
| 1973 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1974 | struct hda_gen_spec *spec = codec->spec; |
| 1975 | unsigned int select = ucontrol->value.enumerated.item[0]; |
| 1976 | int ret = 0; |
| 1977 | |
| 1978 | mutex_lock(&spec->pcm_mutex); |
| 1979 | if (spec->active_streams) { |
| 1980 | ret = -EBUSY; |
| 1981 | goto unlock; |
| 1982 | } |
| 1983 | |
| 1984 | if (spec->indep_hp_enabled != select) { |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 1985 | hda_nid_t *dacp; |
| 1986 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 1987 | dacp = &spec->private_dac_nids[0]; |
| 1988 | else |
| 1989 | dacp = &spec->multiout.hp_out_nid[0]; |
| 1990 | |
| 1991 | /* update HP aamix paths in case it conflicts with indep HP */ |
| 1992 | if (spec->have_aamix_ctl) { |
| 1993 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 1994 | update_aamix_paths(codec, spec->aamix_mode, |
| 1995 | spec->out_paths[0], |
| 1996 | spec->aamix_out_paths[0], |
| 1997 | spec->autocfg.line_out_type); |
| 1998 | else |
| 1999 | update_aamix_paths(codec, spec->aamix_mode, |
| 2000 | spec->hp_paths[0], |
| 2001 | spec->aamix_out_paths[1], |
| 2002 | AUTO_PIN_HP_OUT); |
| 2003 | } |
| 2004 | |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 2005 | spec->indep_hp_enabled = select; |
| 2006 | if (spec->indep_hp_enabled) |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2007 | *dacp = 0; |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 2008 | else |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2009 | *dacp = spec->alt_dac_nid; |
Takashi Iwai | 92603c5 | 2013-01-22 07:46:31 +0100 | [diff] [blame] | 2010 | |
Takashi Iwai | 8ba955c | 2013-03-07 18:40:58 +0100 | [diff] [blame] | 2011 | update_hp_automute_hook(codec); |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 2012 | ret = 1; |
| 2013 | } |
| 2014 | unlock: |
| 2015 | mutex_unlock(&spec->pcm_mutex); |
| 2016 | return ret; |
| 2017 | } |
| 2018 | |
| 2019 | static const struct snd_kcontrol_new indep_hp_ctl = { |
| 2020 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2021 | .name = "Independent HP", |
| 2022 | .info = indep_hp_info, |
| 2023 | .get = indep_hp_get, |
| 2024 | .put = indep_hp_put, |
| 2025 | }; |
| 2026 | |
| 2027 | |
| 2028 | static int create_indep_hp_ctls(struct hda_codec *codec) |
| 2029 | { |
| 2030 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2031 | hda_nid_t dac; |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 2032 | |
| 2033 | if (!spec->indep_hp) |
| 2034 | return 0; |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2035 | if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT) |
| 2036 | dac = spec->multiout.dac_nids[0]; |
| 2037 | else |
| 2038 | dac = spec->multiout.hp_out_nid[0]; |
| 2039 | if (!dac) { |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 2040 | spec->indep_hp = 0; |
| 2041 | return 0; |
| 2042 | } |
| 2043 | |
| 2044 | spec->indep_hp_enabled = false; |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2045 | spec->alt_dac_nid = dac; |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 2046 | if (!snd_hda_gen_add_kctl(spec, NULL, &indep_hp_ctl)) |
| 2047 | return -ENOMEM; |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
| 2051 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2052 | * channel mode enum control |
| 2053 | */ |
| 2054 | |
| 2055 | static int ch_mode_info(struct snd_kcontrol *kcontrol, |
| 2056 | struct snd_ctl_elem_info *uinfo) |
| 2057 | { |
| 2058 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2059 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 2060 | int chs; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2061 | |
| 2062 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2063 | uinfo->count = 1; |
| 2064 | uinfo->value.enumerated.items = spec->multi_ios + 1; |
| 2065 | if (uinfo->value.enumerated.item > spec->multi_ios) |
| 2066 | uinfo->value.enumerated.item = spec->multi_ios; |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 2067 | chs = uinfo->value.enumerated.item * 2 + spec->min_channel_count; |
| 2068 | sprintf(uinfo->value.enumerated.name, "%dch", chs); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | static int ch_mode_get(struct snd_kcontrol *kcontrol, |
| 2073 | struct snd_ctl_elem_value *ucontrol) |
| 2074 | { |
| 2075 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2076 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 2077 | ucontrol->value.enumerated.item[0] = |
| 2078 | (spec->ext_channel_count - spec->min_channel_count) / 2; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2079 | return 0; |
| 2080 | } |
| 2081 | |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 2082 | static inline struct nid_path * |
| 2083 | get_multiio_path(struct hda_codec *codec, int idx) |
| 2084 | { |
| 2085 | struct hda_gen_spec *spec = codec->spec; |
| 2086 | return snd_hda_get_path_from_idx(codec, |
| 2087 | spec->out_paths[spec->autocfg.line_outs + idx]); |
| 2088 | } |
| 2089 | |
Takashi Iwai | a5cc250 | 2013-01-16 18:08:55 +0100 | [diff] [blame] | 2090 | static void update_automute_all(struct hda_codec *codec); |
| 2091 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2092 | static int set_multi_io(struct hda_codec *codec, int idx, bool output) |
| 2093 | { |
| 2094 | struct hda_gen_spec *spec = codec->spec; |
| 2095 | hda_nid_t nid = spec->multi_io[idx].pin; |
| 2096 | struct nid_path *path; |
| 2097 | |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 2098 | path = get_multiio_path(codec, idx); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2099 | if (!path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | return -EINVAL; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2101 | |
| 2102 | if (path->active == output) |
| 2103 | return 0; |
| 2104 | |
| 2105 | if (output) { |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 2106 | set_pin_target(codec, nid, PIN_OUT, true); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2107 | snd_hda_activate_path(codec, path, true, true); |
Takashi Iwai | d5a9f1b | 2012-12-20 15:36:30 +0100 | [diff] [blame] | 2108 | set_pin_eapd(codec, nid, true); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2109 | } else { |
Takashi Iwai | d5a9f1b | 2012-12-20 15:36:30 +0100 | [diff] [blame] | 2110 | set_pin_eapd(codec, nid, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2111 | snd_hda_activate_path(codec, path, false, true); |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 2112 | set_pin_target(codec, nid, spec->multi_io[idx].ctl_in, true); |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 2113 | path_power_down_sync(codec, path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | } |
Takashi Iwai | a365fed | 2013-01-10 16:10:06 +0100 | [diff] [blame] | 2115 | |
| 2116 | /* update jack retasking in case it modifies any of them */ |
Takashi Iwai | a5cc250 | 2013-01-16 18:08:55 +0100 | [diff] [blame] | 2117 | update_automute_all(codec); |
Takashi Iwai | a365fed | 2013-01-10 16:10:06 +0100 | [diff] [blame] | 2118 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2119 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2122 | static int ch_mode_put(struct snd_kcontrol *kcontrol, |
| 2123 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2125 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2126 | struct hda_gen_spec *spec = codec->spec; |
| 2127 | int i, ch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2129 | ch = ucontrol->value.enumerated.item[0]; |
| 2130 | if (ch < 0 || ch > spec->multi_ios) |
| 2131 | return -EINVAL; |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 2132 | if (ch == (spec->ext_channel_count - spec->min_channel_count) / 2) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2133 | return 0; |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 2134 | spec->ext_channel_count = ch * 2 + spec->min_channel_count; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2135 | for (i = 0; i < spec->multi_ios; i++) |
| 2136 | set_multi_io(codec, i, i < ch); |
| 2137 | spec->multiout.max_channels = max(spec->ext_channel_count, |
| 2138 | spec->const_channel_count); |
| 2139 | if (spec->need_dac_fix) |
| 2140 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | return 1; |
| 2142 | } |
| 2143 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2144 | static const struct snd_kcontrol_new channel_mode_enum = { |
| 2145 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2146 | .name = "Channel Mode", |
| 2147 | .info = ch_mode_info, |
| 2148 | .get = ch_mode_get, |
| 2149 | .put = ch_mode_put, |
| 2150 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2152 | static int create_multi_channel_mode(struct hda_codec *codec) |
| 2153 | { |
| 2154 | struct hda_gen_spec *spec = codec->spec; |
| 2155 | |
| 2156 | if (spec->multi_ios > 0) { |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 2157 | if (!snd_hda_gen_add_kctl(spec, NULL, &channel_mode_enum)) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2158 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | return 0; |
| 2161 | } |
| 2162 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2163 | /* |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2164 | * aamix loopback enable/disable switch |
| 2165 | */ |
| 2166 | |
| 2167 | #define loopback_mixing_info indep_hp_info |
| 2168 | |
| 2169 | static int loopback_mixing_get(struct snd_kcontrol *kcontrol, |
| 2170 | struct snd_ctl_elem_value *ucontrol) |
| 2171 | { |
| 2172 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2173 | struct hda_gen_spec *spec = codec->spec; |
| 2174 | ucontrol->value.enumerated.item[0] = spec->aamix_mode; |
| 2175 | return 0; |
| 2176 | } |
| 2177 | |
| 2178 | static void update_aamix_paths(struct hda_codec *codec, bool do_mix, |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2179 | int nomix_path_idx, int mix_path_idx, |
| 2180 | int out_type) |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2181 | { |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2182 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2183 | struct nid_path *nomix_path, *mix_path; |
| 2184 | |
| 2185 | nomix_path = snd_hda_get_path_from_idx(codec, nomix_path_idx); |
| 2186 | mix_path = snd_hda_get_path_from_idx(codec, mix_path_idx); |
| 2187 | if (!nomix_path || !mix_path) |
| 2188 | return; |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2189 | |
| 2190 | /* if HP aamix path is driven from a different DAC and the |
| 2191 | * independent HP mode is ON, can't turn on aamix path |
| 2192 | */ |
| 2193 | if (out_type == AUTO_PIN_HP_OUT && spec->indep_hp_enabled && |
| 2194 | mix_path->path[0] != spec->alt_dac_nid) |
| 2195 | do_mix = false; |
| 2196 | |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2197 | if (do_mix) { |
| 2198 | snd_hda_activate_path(codec, nomix_path, false, true); |
| 2199 | snd_hda_activate_path(codec, mix_path, true, true); |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 2200 | path_power_down_sync(codec, nomix_path); |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2201 | } else { |
| 2202 | snd_hda_activate_path(codec, mix_path, false, true); |
| 2203 | snd_hda_activate_path(codec, nomix_path, true, true); |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 2204 | path_power_down_sync(codec, mix_path); |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | static int loopback_mixing_put(struct snd_kcontrol *kcontrol, |
| 2209 | struct snd_ctl_elem_value *ucontrol) |
| 2210 | { |
| 2211 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2212 | struct hda_gen_spec *spec = codec->spec; |
| 2213 | unsigned int val = ucontrol->value.enumerated.item[0]; |
| 2214 | |
| 2215 | if (val == spec->aamix_mode) |
| 2216 | return 0; |
| 2217 | spec->aamix_mode = val; |
| 2218 | update_aamix_paths(codec, val, spec->out_paths[0], |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2219 | spec->aamix_out_paths[0], |
| 2220 | spec->autocfg.line_out_type); |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2221 | update_aamix_paths(codec, val, spec->hp_paths[0], |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2222 | spec->aamix_out_paths[1], |
| 2223 | AUTO_PIN_HP_OUT); |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2224 | update_aamix_paths(codec, val, spec->speaker_paths[0], |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2225 | spec->aamix_out_paths[2], |
| 2226 | AUTO_PIN_SPEAKER_OUT); |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2227 | return 1; |
| 2228 | } |
| 2229 | |
| 2230 | static const struct snd_kcontrol_new loopback_mixing_enum = { |
| 2231 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2232 | .name = "Loopback Mixing", |
| 2233 | .info = loopback_mixing_info, |
| 2234 | .get = loopback_mixing_get, |
| 2235 | .put = loopback_mixing_put, |
| 2236 | }; |
| 2237 | |
| 2238 | static int create_loopback_mixing_ctl(struct hda_codec *codec) |
| 2239 | { |
| 2240 | struct hda_gen_spec *spec = codec->spec; |
| 2241 | |
| 2242 | if (!spec->mixer_nid) |
| 2243 | return 0; |
| 2244 | if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] || |
| 2245 | spec->aamix_out_paths[2])) |
| 2246 | return 0; |
| 2247 | if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum)) |
| 2248 | return -ENOMEM; |
Takashi Iwai | a1e908e | 2013-01-21 15:11:25 +0100 | [diff] [blame] | 2249 | spec->have_aamix_ctl = 1; |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2254 | * shared headphone/mic handling |
| 2255 | */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2256 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2257 | static void call_update_outputs(struct hda_codec *codec); |
| 2258 | |
| 2259 | /* for shared I/O, change the pin-control accordingly */ |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2260 | static void update_hp_mic(struct hda_codec *codec, int adc_mux, bool force) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2261 | { |
| 2262 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2263 | bool as_mic; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2264 | unsigned int val; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2265 | hda_nid_t pin; |
| 2266 | |
| 2267 | pin = spec->hp_mic_pin; |
| 2268 | as_mic = spec->cur_mux[adc_mux] == spec->hp_mic_mux_idx; |
| 2269 | |
| 2270 | if (!force) { |
| 2271 | val = snd_hda_codec_get_pin_target(codec, pin); |
| 2272 | if (as_mic) { |
| 2273 | if (val & PIN_IN) |
| 2274 | return; |
| 2275 | } else { |
| 2276 | if (val & PIN_OUT) |
| 2277 | return; |
| 2278 | } |
| 2279 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2280 | |
| 2281 | val = snd_hda_get_default_vref(codec, pin); |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2282 | /* if the HP pin doesn't support VREF and the codec driver gives an |
| 2283 | * alternative pin, set up the VREF on that pin instead |
| 2284 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2285 | if (val == AC_PINCTL_VREF_HIZ && spec->shared_mic_vref_pin) { |
| 2286 | const hda_nid_t vref_pin = spec->shared_mic_vref_pin; |
| 2287 | unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin); |
| 2288 | if (vref_val != AC_PINCTL_VREF_HIZ) |
Takashi Iwai | 7594aa3 | 2012-12-20 15:38:40 +0100 | [diff] [blame] | 2289 | snd_hda_set_pin_ctl_cache(codec, vref_pin, |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2290 | PIN_IN | (as_mic ? vref_val : 0)); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2291 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2292 | |
Takashi Iwai | 8ba955c | 2013-03-07 18:40:58 +0100 | [diff] [blame] | 2293 | if (!spec->hp_mic_jack_modes) { |
| 2294 | if (as_mic) |
| 2295 | val |= PIN_IN; |
| 2296 | else |
| 2297 | val = PIN_HP; |
| 2298 | set_pin_target(codec, pin, val, true); |
| 2299 | update_hp_automute_hook(codec); |
| 2300 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | /* create a shared input with the headphone out */ |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2304 | static int create_hp_mic(struct hda_codec *codec) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2305 | { |
| 2306 | struct hda_gen_spec *spec = codec->spec; |
| 2307 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2308 | unsigned int defcfg; |
| 2309 | hda_nid_t nid; |
| 2310 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2311 | if (!spec->hp_mic) { |
| 2312 | if (spec->suppress_hp_mic_detect) |
| 2313 | return 0; |
| 2314 | /* automatic detection: only if no input or a single internal |
| 2315 | * input pin is found, try to detect the shared hp/mic |
| 2316 | */ |
| 2317 | if (cfg->num_inputs > 1) |
| 2318 | return 0; |
| 2319 | else if (cfg->num_inputs == 1) { |
| 2320 | defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin); |
| 2321 | if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT) |
| 2322 | return 0; |
| 2323 | } |
| 2324 | } |
| 2325 | |
| 2326 | spec->hp_mic = 0; /* clear once */ |
| 2327 | if (cfg->num_inputs >= AUTO_CFG_MAX_INS) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2328 | return 0; |
| 2329 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2330 | nid = 0; |
| 2331 | if (cfg->line_out_type == AUTO_PIN_HP_OUT && cfg->line_outs > 0) |
| 2332 | nid = cfg->line_out_pins[0]; |
| 2333 | else if (cfg->hp_outs > 0) |
| 2334 | nid = cfg->hp_pins[0]; |
| 2335 | if (!nid) |
| 2336 | return 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2337 | |
| 2338 | if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN)) |
| 2339 | return 0; /* no input */ |
| 2340 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2341 | cfg->inputs[cfg->num_inputs].pin = nid; |
| 2342 | cfg->inputs[cfg->num_inputs].type = AUTO_PIN_MIC; |
| 2343 | cfg->num_inputs++; |
| 2344 | spec->hp_mic = 1; |
| 2345 | spec->hp_mic_pin = nid; |
| 2346 | /* we can't handle auto-mic together with HP-mic */ |
| 2347 | spec->suppress_auto_mic = 1; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2348 | snd_printdd("hda-codec: Enable shared I/O jack on NID 0x%x\n", nid); |
| 2349 | return 0; |
| 2350 | } |
| 2351 | |
Takashi Iwai | 978e77e | 2013-01-10 16:57:58 +0100 | [diff] [blame] | 2352 | /* |
| 2353 | * output jack mode |
| 2354 | */ |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2355 | |
| 2356 | static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin); |
| 2357 | |
| 2358 | static const char * const out_jack_texts[] = { |
| 2359 | "Line Out", "Headphone Out", |
| 2360 | }; |
| 2361 | |
Takashi Iwai | 978e77e | 2013-01-10 16:57:58 +0100 | [diff] [blame] | 2362 | static int out_jack_mode_info(struct snd_kcontrol *kcontrol, |
| 2363 | struct snd_ctl_elem_info *uinfo) |
| 2364 | { |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2365 | return snd_hda_enum_helper_info(kcontrol, uinfo, 2, out_jack_texts); |
Takashi Iwai | 978e77e | 2013-01-10 16:57:58 +0100 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | static int out_jack_mode_get(struct snd_kcontrol *kcontrol, |
| 2369 | struct snd_ctl_elem_value *ucontrol) |
| 2370 | { |
| 2371 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2372 | hda_nid_t nid = kcontrol->private_value; |
| 2373 | if (snd_hda_codec_get_pin_target(codec, nid) == PIN_HP) |
| 2374 | ucontrol->value.enumerated.item[0] = 1; |
| 2375 | else |
| 2376 | ucontrol->value.enumerated.item[0] = 0; |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
| 2380 | static int out_jack_mode_put(struct snd_kcontrol *kcontrol, |
| 2381 | struct snd_ctl_elem_value *ucontrol) |
| 2382 | { |
| 2383 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2384 | hda_nid_t nid = kcontrol->private_value; |
| 2385 | unsigned int val; |
| 2386 | |
| 2387 | val = ucontrol->value.enumerated.item[0] ? PIN_HP : PIN_OUT; |
| 2388 | if (snd_hda_codec_get_pin_target(codec, nid) == val) |
| 2389 | return 0; |
| 2390 | snd_hda_set_pin_ctl_cache(codec, nid, val); |
| 2391 | return 1; |
| 2392 | } |
| 2393 | |
| 2394 | static const struct snd_kcontrol_new out_jack_mode_enum = { |
| 2395 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2396 | .info = out_jack_mode_info, |
| 2397 | .get = out_jack_mode_get, |
| 2398 | .put = out_jack_mode_put, |
| 2399 | }; |
| 2400 | |
| 2401 | static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx) |
| 2402 | { |
| 2403 | struct hda_gen_spec *spec = codec->spec; |
| 2404 | int i; |
| 2405 | |
| 2406 | for (i = 0; i < spec->kctls.used; i++) { |
| 2407 | struct snd_kcontrol_new *kctl = snd_array_elem(&spec->kctls, i); |
| 2408 | if (!strcmp(kctl->name, name) && kctl->index == idx) |
| 2409 | return true; |
| 2410 | } |
| 2411 | return false; |
| 2412 | } |
| 2413 | |
| 2414 | static void get_jack_mode_name(struct hda_codec *codec, hda_nid_t pin, |
| 2415 | char *name, size_t name_len) |
| 2416 | { |
| 2417 | struct hda_gen_spec *spec = codec->spec; |
| 2418 | int idx = 0; |
| 2419 | |
| 2420 | snd_hda_get_pin_label(codec, pin, &spec->autocfg, name, name_len, &idx); |
| 2421 | strlcat(name, " Jack Mode", name_len); |
| 2422 | |
| 2423 | for (; find_kctl_name(codec, name, idx); idx++) |
| 2424 | ; |
| 2425 | } |
| 2426 | |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2427 | static int get_out_jack_num_items(struct hda_codec *codec, hda_nid_t pin) |
| 2428 | { |
| 2429 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 2430 | if (spec->add_jack_modes) { |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2431 | unsigned int pincap = snd_hda_query_pin_caps(codec, pin); |
| 2432 | if ((pincap & AC_PINCAP_OUT) && (pincap & AC_PINCAP_HP_DRV)) |
| 2433 | return 2; |
| 2434 | } |
| 2435 | return 1; |
| 2436 | } |
| 2437 | |
Takashi Iwai | 978e77e | 2013-01-10 16:57:58 +0100 | [diff] [blame] | 2438 | static int create_out_jack_modes(struct hda_codec *codec, int num_pins, |
| 2439 | hda_nid_t *pins) |
| 2440 | { |
| 2441 | struct hda_gen_spec *spec = codec->spec; |
| 2442 | int i; |
| 2443 | |
| 2444 | for (i = 0; i < num_pins; i++) { |
| 2445 | hda_nid_t pin = pins[i]; |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2446 | if (pin == spec->hp_mic_pin) { |
| 2447 | int ret = create_hp_mic_jack_mode(codec, pin); |
| 2448 | if (ret < 0) |
| 2449 | return ret; |
| 2450 | continue; |
| 2451 | } |
| 2452 | if (get_out_jack_num_items(codec, pin) > 1) { |
Takashi Iwai | 978e77e | 2013-01-10 16:57:58 +0100 | [diff] [blame] | 2453 | struct snd_kcontrol_new *knew; |
| 2454 | char name[44]; |
| 2455 | get_jack_mode_name(codec, pin, name, sizeof(name)); |
| 2456 | knew = snd_hda_gen_add_kctl(spec, name, |
| 2457 | &out_jack_mode_enum); |
| 2458 | if (!knew) |
| 2459 | return -ENOMEM; |
| 2460 | knew->private_value = pin; |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | return 0; |
| 2465 | } |
| 2466 | |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 2467 | /* |
| 2468 | * input jack mode |
| 2469 | */ |
| 2470 | |
| 2471 | /* from AC_PINCTL_VREF_HIZ to AC_PINCTL_VREF_100 */ |
| 2472 | #define NUM_VREFS 6 |
| 2473 | |
| 2474 | static const char * const vref_texts[NUM_VREFS] = { |
| 2475 | "Line In", "Mic 50pc Bias", "Mic 0V Bias", |
| 2476 | "", "Mic 80pc Bias", "Mic 100pc Bias" |
| 2477 | }; |
| 2478 | |
| 2479 | static unsigned int get_vref_caps(struct hda_codec *codec, hda_nid_t pin) |
| 2480 | { |
| 2481 | unsigned int pincap; |
| 2482 | |
| 2483 | pincap = snd_hda_query_pin_caps(codec, pin); |
| 2484 | pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; |
| 2485 | /* filter out unusual vrefs */ |
| 2486 | pincap &= ~(AC_PINCAP_VREF_GRD | AC_PINCAP_VREF_100); |
| 2487 | return pincap; |
| 2488 | } |
| 2489 | |
| 2490 | /* convert from the enum item index to the vref ctl index (0=HIZ, 1=50%...) */ |
| 2491 | static int get_vref_idx(unsigned int vref_caps, unsigned int item_idx) |
| 2492 | { |
| 2493 | unsigned int i, n = 0; |
| 2494 | |
| 2495 | for (i = 0; i < NUM_VREFS; i++) { |
| 2496 | if (vref_caps & (1 << i)) { |
| 2497 | if (n == item_idx) |
| 2498 | return i; |
| 2499 | n++; |
| 2500 | } |
| 2501 | } |
| 2502 | return 0; |
| 2503 | } |
| 2504 | |
| 2505 | /* convert back from the vref ctl index to the enum item index */ |
| 2506 | static int cvt_from_vref_idx(unsigned int vref_caps, unsigned int idx) |
| 2507 | { |
| 2508 | unsigned int i, n = 0; |
| 2509 | |
| 2510 | for (i = 0; i < NUM_VREFS; i++) { |
| 2511 | if (i == idx) |
| 2512 | return n; |
| 2513 | if (vref_caps & (1 << i)) |
| 2514 | n++; |
| 2515 | } |
| 2516 | return 0; |
| 2517 | } |
| 2518 | |
| 2519 | static int in_jack_mode_info(struct snd_kcontrol *kcontrol, |
| 2520 | struct snd_ctl_elem_info *uinfo) |
| 2521 | { |
| 2522 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2523 | hda_nid_t nid = kcontrol->private_value; |
| 2524 | unsigned int vref_caps = get_vref_caps(codec, nid); |
| 2525 | |
| 2526 | snd_hda_enum_helper_info(kcontrol, uinfo, hweight32(vref_caps), |
| 2527 | vref_texts); |
| 2528 | /* set the right text */ |
| 2529 | strcpy(uinfo->value.enumerated.name, |
| 2530 | vref_texts[get_vref_idx(vref_caps, uinfo->value.enumerated.item)]); |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
| 2534 | static int in_jack_mode_get(struct snd_kcontrol *kcontrol, |
| 2535 | struct snd_ctl_elem_value *ucontrol) |
| 2536 | { |
| 2537 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2538 | hda_nid_t nid = kcontrol->private_value; |
| 2539 | unsigned int vref_caps = get_vref_caps(codec, nid); |
| 2540 | unsigned int idx; |
| 2541 | |
| 2542 | idx = snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_VREFEN; |
| 2543 | ucontrol->value.enumerated.item[0] = cvt_from_vref_idx(vref_caps, idx); |
| 2544 | return 0; |
| 2545 | } |
| 2546 | |
| 2547 | static int in_jack_mode_put(struct snd_kcontrol *kcontrol, |
| 2548 | struct snd_ctl_elem_value *ucontrol) |
| 2549 | { |
| 2550 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2551 | hda_nid_t nid = kcontrol->private_value; |
| 2552 | unsigned int vref_caps = get_vref_caps(codec, nid); |
| 2553 | unsigned int val, idx; |
| 2554 | |
| 2555 | val = snd_hda_codec_get_pin_target(codec, nid); |
| 2556 | idx = cvt_from_vref_idx(vref_caps, val & AC_PINCTL_VREFEN); |
| 2557 | if (idx == ucontrol->value.enumerated.item[0]) |
| 2558 | return 0; |
| 2559 | |
| 2560 | val &= ~AC_PINCTL_VREFEN; |
| 2561 | val |= get_vref_idx(vref_caps, ucontrol->value.enumerated.item[0]); |
| 2562 | snd_hda_set_pin_ctl_cache(codec, nid, val); |
| 2563 | return 1; |
| 2564 | } |
| 2565 | |
| 2566 | static const struct snd_kcontrol_new in_jack_mode_enum = { |
| 2567 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2568 | .info = in_jack_mode_info, |
| 2569 | .get = in_jack_mode_get, |
| 2570 | .put = in_jack_mode_put, |
| 2571 | }; |
| 2572 | |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2573 | static int get_in_jack_num_items(struct hda_codec *codec, hda_nid_t pin) |
| 2574 | { |
| 2575 | struct hda_gen_spec *spec = codec->spec; |
| 2576 | int nitems = 0; |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 2577 | if (spec->add_jack_modes) |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2578 | nitems = hweight32(get_vref_caps(codec, pin)); |
| 2579 | return nitems ? nitems : 1; |
| 2580 | } |
| 2581 | |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 2582 | static int create_in_jack_mode(struct hda_codec *codec, hda_nid_t pin) |
| 2583 | { |
| 2584 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 2585 | struct snd_kcontrol_new *knew; |
| 2586 | char name[44]; |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2587 | unsigned int defcfg; |
| 2588 | |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 2589 | if (pin == spec->hp_mic_pin) |
| 2590 | return 0; /* already done in create_out_jack_mode() */ |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 2591 | |
| 2592 | /* no jack mode for fixed pins */ |
| 2593 | defcfg = snd_hda_codec_get_pincfg(codec, pin); |
| 2594 | if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT) |
| 2595 | return 0; |
| 2596 | |
| 2597 | /* no multiple vref caps? */ |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2598 | if (get_in_jack_num_items(codec, pin) <= 1) |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 2599 | return 0; |
| 2600 | |
| 2601 | get_jack_mode_name(codec, pin, name, sizeof(name)); |
| 2602 | knew = snd_hda_gen_add_kctl(spec, name, &in_jack_mode_enum); |
| 2603 | if (!knew) |
| 2604 | return -ENOMEM; |
| 2605 | knew->private_value = pin; |
| 2606 | return 0; |
| 2607 | } |
| 2608 | |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2609 | /* |
| 2610 | * HP/mic shared jack mode |
| 2611 | */ |
| 2612 | static int hp_mic_jack_mode_info(struct snd_kcontrol *kcontrol, |
| 2613 | struct snd_ctl_elem_info *uinfo) |
| 2614 | { |
| 2615 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2616 | hda_nid_t nid = kcontrol->private_value; |
| 2617 | int out_jacks = get_out_jack_num_items(codec, nid); |
| 2618 | int in_jacks = get_in_jack_num_items(codec, nid); |
| 2619 | const char *text = NULL; |
| 2620 | int idx; |
| 2621 | |
| 2622 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2623 | uinfo->count = 1; |
| 2624 | uinfo->value.enumerated.items = out_jacks + in_jacks; |
| 2625 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2626 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 2627 | idx = uinfo->value.enumerated.item; |
| 2628 | if (idx < out_jacks) { |
| 2629 | if (out_jacks > 1) |
| 2630 | text = out_jack_texts[idx]; |
| 2631 | else |
| 2632 | text = "Headphone Out"; |
| 2633 | } else { |
| 2634 | idx -= out_jacks; |
| 2635 | if (in_jacks > 1) { |
| 2636 | unsigned int vref_caps = get_vref_caps(codec, nid); |
| 2637 | text = vref_texts[get_vref_idx(vref_caps, idx)]; |
| 2638 | } else |
| 2639 | text = "Mic In"; |
| 2640 | } |
| 2641 | |
| 2642 | strcpy(uinfo->value.enumerated.name, text); |
| 2643 | return 0; |
| 2644 | } |
| 2645 | |
| 2646 | static int get_cur_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t nid) |
| 2647 | { |
| 2648 | int out_jacks = get_out_jack_num_items(codec, nid); |
| 2649 | int in_jacks = get_in_jack_num_items(codec, nid); |
| 2650 | unsigned int val = snd_hda_codec_get_pin_target(codec, nid); |
| 2651 | int idx = 0; |
| 2652 | |
| 2653 | if (val & PIN_OUT) { |
| 2654 | if (out_jacks > 1 && val == PIN_HP) |
| 2655 | idx = 1; |
| 2656 | } else if (val & PIN_IN) { |
| 2657 | idx = out_jacks; |
| 2658 | if (in_jacks > 1) { |
| 2659 | unsigned int vref_caps = get_vref_caps(codec, nid); |
| 2660 | val &= AC_PINCTL_VREFEN; |
| 2661 | idx += cvt_from_vref_idx(vref_caps, val); |
| 2662 | } |
| 2663 | } |
| 2664 | return idx; |
| 2665 | } |
| 2666 | |
| 2667 | static int hp_mic_jack_mode_get(struct snd_kcontrol *kcontrol, |
| 2668 | struct snd_ctl_elem_value *ucontrol) |
| 2669 | { |
| 2670 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2671 | hda_nid_t nid = kcontrol->private_value; |
| 2672 | ucontrol->value.enumerated.item[0] = |
| 2673 | get_cur_hp_mic_jack_mode(codec, nid); |
| 2674 | return 0; |
| 2675 | } |
| 2676 | |
| 2677 | static int hp_mic_jack_mode_put(struct snd_kcontrol *kcontrol, |
| 2678 | struct snd_ctl_elem_value *ucontrol) |
| 2679 | { |
| 2680 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2681 | hda_nid_t nid = kcontrol->private_value; |
| 2682 | int out_jacks = get_out_jack_num_items(codec, nid); |
| 2683 | int in_jacks = get_in_jack_num_items(codec, nid); |
| 2684 | unsigned int val, oldval, idx; |
| 2685 | |
| 2686 | oldval = get_cur_hp_mic_jack_mode(codec, nid); |
| 2687 | idx = ucontrol->value.enumerated.item[0]; |
| 2688 | if (oldval == idx) |
| 2689 | return 0; |
| 2690 | |
| 2691 | if (idx < out_jacks) { |
| 2692 | if (out_jacks > 1) |
| 2693 | val = idx ? PIN_HP : PIN_OUT; |
| 2694 | else |
| 2695 | val = PIN_HP; |
| 2696 | } else { |
| 2697 | idx -= out_jacks; |
| 2698 | if (in_jacks > 1) { |
| 2699 | unsigned int vref_caps = get_vref_caps(codec, nid); |
| 2700 | val = snd_hda_codec_get_pin_target(codec, nid); |
Takashi Iwai | 3f550e3 | 2013-03-07 18:30:27 +0100 | [diff] [blame] | 2701 | val &= ~(AC_PINCTL_VREFEN | PIN_HP); |
| 2702 | val |= get_vref_idx(vref_caps, idx) | PIN_IN; |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2703 | } else |
| 2704 | val = snd_hda_get_default_vref(codec, nid); |
| 2705 | } |
| 2706 | snd_hda_set_pin_ctl_cache(codec, nid, val); |
Takashi Iwai | 8ba955c | 2013-03-07 18:40:58 +0100 | [diff] [blame] | 2707 | update_hp_automute_hook(codec); |
| 2708 | |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2709 | return 1; |
| 2710 | } |
| 2711 | |
| 2712 | static const struct snd_kcontrol_new hp_mic_jack_mode_enum = { |
| 2713 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2714 | .info = hp_mic_jack_mode_info, |
| 2715 | .get = hp_mic_jack_mode_get, |
| 2716 | .put = hp_mic_jack_mode_put, |
| 2717 | }; |
| 2718 | |
| 2719 | static int create_hp_mic_jack_mode(struct hda_codec *codec, hda_nid_t pin) |
| 2720 | { |
| 2721 | struct hda_gen_spec *spec = codec->spec; |
| 2722 | struct snd_kcontrol_new *knew; |
| 2723 | |
| 2724 | if (get_out_jack_num_items(codec, pin) <= 1 && |
| 2725 | get_in_jack_num_items(codec, pin) <= 1) |
| 2726 | return 0; /* no need */ |
| 2727 | knew = snd_hda_gen_add_kctl(spec, "Headphone Mic Jack Mode", |
| 2728 | &hp_mic_jack_mode_enum); |
| 2729 | if (!knew) |
| 2730 | return -ENOMEM; |
| 2731 | knew->private_value = pin; |
Takashi Iwai | 8ba955c | 2013-03-07 18:40:58 +0100 | [diff] [blame] | 2732 | spec->hp_mic_jack_modes = 1; |
Takashi Iwai | 5f171ba | 2013-02-19 18:14:54 +0100 | [diff] [blame] | 2733 | return 0; |
| 2734 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2735 | |
| 2736 | /* |
| 2737 | * Parse input paths |
| 2738 | */ |
| 2739 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2740 | /* add the powersave loopback-list entry */ |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 2741 | static int add_loopback_list(struct hda_gen_spec *spec, hda_nid_t mix, int idx) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2742 | { |
| 2743 | struct hda_amp_list *list; |
| 2744 | |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 2745 | list = snd_array_new(&spec->loopback_list); |
| 2746 | if (!list) |
| 2747 | return -ENOMEM; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2748 | list->nid = mix; |
| 2749 | list->dir = HDA_INPUT; |
| 2750 | list->idx = idx; |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 2751 | spec->loopback.amplist = spec->loopback_list.list; |
| 2752 | return 0; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2753 | } |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2754 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2755 | /* create input playback/capture controls for the given pin */ |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 2756 | static int new_analog_input(struct hda_codec *codec, int input_idx, |
| 2757 | hda_nid_t pin, const char *ctlname, int ctlidx, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2758 | hda_nid_t mix_nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2760 | struct hda_gen_spec *spec = codec->spec; |
| 2761 | struct nid_path *path; |
| 2762 | unsigned int val; |
| 2763 | int err, idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2765 | if (!nid_has_volume(codec, mix_nid, HDA_INPUT) && |
| 2766 | !nid_has_mute(codec, mix_nid, HDA_INPUT)) |
| 2767 | return 0; /* no need for analog loopback */ |
| 2768 | |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 2769 | path = snd_hda_add_new_path(codec, pin, mix_nid, 0); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2770 | if (!path) |
| 2771 | return -EINVAL; |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 2772 | print_nid_path("loopback", path); |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 2773 | spec->loopback_paths[input_idx] = snd_hda_get_path_idx(codec, path); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2774 | |
| 2775 | idx = path->idx[path->depth - 1]; |
| 2776 | if (nid_has_volume(codec, mix_nid, HDA_INPUT)) { |
| 2777 | val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT); |
| 2778 | err = __add_pb_vol_ctrl(spec, HDA_CTL_WIDGET_VOL, ctlname, ctlidx, val); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2779 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2781 | path->ctls[NID_PATH_VOL_CTL] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2784 | if (nid_has_mute(codec, mix_nid, HDA_INPUT)) { |
| 2785 | val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT); |
| 2786 | err = __add_pb_sw_ctrl(spec, HDA_CTL_WIDGET_MUTE, ctlname, ctlidx, val); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 2787 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2789 | path->ctls[NID_PATH_MUTE_CTL] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2792 | path->active = true; |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 2793 | err = add_loopback_list(spec, mix_nid, idx); |
| 2794 | if (err < 0) |
| 2795 | return err; |
Takashi Iwai | e4a395e | 2013-01-23 17:00:31 +0100 | [diff] [blame] | 2796 | |
| 2797 | if (spec->mixer_nid != spec->mixer_merge_nid && |
| 2798 | !spec->loopback_merge_path) { |
| 2799 | path = snd_hda_add_new_path(codec, spec->mixer_nid, |
| 2800 | spec->mixer_merge_nid, 0); |
| 2801 | if (path) { |
| 2802 | print_nid_path("loopback-merge", path); |
| 2803 | path->active = true; |
| 2804 | spec->loopback_merge_path = |
| 2805 | snd_hda_get_path_idx(codec, path); |
| 2806 | } |
| 2807 | } |
| 2808 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2809 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | } |
| 2811 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2812 | static int is_input_pin(struct hda_codec *codec, hda_nid_t nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2814 | unsigned int pincap = snd_hda_query_pin_caps(codec, nid); |
| 2815 | return (pincap & AC_PINCAP_IN) != 0; |
| 2816 | } |
| 2817 | |
| 2818 | /* Parse the codec tree and retrieve ADCs */ |
| 2819 | static int fill_adc_nids(struct hda_codec *codec) |
| 2820 | { |
| 2821 | struct hda_gen_spec *spec = codec->spec; |
| 2822 | hda_nid_t nid; |
| 2823 | hda_nid_t *adc_nids = spec->adc_nids; |
| 2824 | int max_nums = ARRAY_SIZE(spec->adc_nids); |
| 2825 | int i, nums = 0; |
| 2826 | |
| 2827 | nid = codec->start_nid; |
| 2828 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2829 | unsigned int caps = get_wcaps(codec, nid); |
| 2830 | int type = get_wcaps_type(caps); |
| 2831 | |
| 2832 | if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL)) |
| 2833 | continue; |
| 2834 | adc_nids[nums] = nid; |
| 2835 | if (++nums >= max_nums) |
| 2836 | break; |
| 2837 | } |
| 2838 | spec->num_adc_nids = nums; |
Takashi Iwai | 0ffd534 | 2013-01-17 15:53:29 +0100 | [diff] [blame] | 2839 | |
| 2840 | /* copy the detected ADCs to all_adcs[] */ |
| 2841 | spec->num_all_adcs = nums; |
| 2842 | memcpy(spec->all_adcs, spec->adc_nids, nums * sizeof(hda_nid_t)); |
| 2843 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2844 | return nums; |
| 2845 | } |
| 2846 | |
| 2847 | /* filter out invalid adc_nids that don't give all active input pins; |
| 2848 | * if needed, check whether dynamic ADC-switching is available |
| 2849 | */ |
| 2850 | static int check_dyn_adc_switch(struct hda_codec *codec) |
| 2851 | { |
| 2852 | struct hda_gen_spec *spec = codec->spec; |
| 2853 | struct hda_input_mux *imux = &spec->input_mux; |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2854 | unsigned int ok_bits; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2855 | int i, n, nums; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2856 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2857 | nums = 0; |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2858 | ok_bits = 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2859 | for (n = 0; n < spec->num_adc_nids; n++) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2860 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2861 | if (!spec->input_paths[i][n]) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2862 | break; |
| 2863 | } |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2864 | if (i >= imux->num_items) { |
| 2865 | ok_bits |= (1 << n); |
| 2866 | nums++; |
| 2867 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2868 | } |
| 2869 | |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2870 | if (!ok_bits) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2871 | /* check whether ADC-switch is possible */ |
| 2872 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2873 | for (n = 0; n < spec->num_adc_nids; n++) { |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2874 | if (spec->input_paths[i][n]) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2875 | spec->dyn_adc_idx[i] = n; |
| 2876 | break; |
| 2877 | } |
| 2878 | } |
| 2879 | } |
| 2880 | |
| 2881 | snd_printdd("hda-codec: enabling ADC switching\n"); |
| 2882 | spec->dyn_adc_switch = 1; |
| 2883 | } else if (nums != spec->num_adc_nids) { |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2884 | /* shrink the invalid adcs and input paths */ |
| 2885 | nums = 0; |
| 2886 | for (n = 0; n < spec->num_adc_nids; n++) { |
| 2887 | if (!(ok_bits & (1 << n))) |
| 2888 | continue; |
| 2889 | if (n != nums) { |
| 2890 | spec->adc_nids[nums] = spec->adc_nids[n]; |
Takashi Iwai | 980428c | 2013-01-09 09:28:20 +0100 | [diff] [blame] | 2891 | for (i = 0; i < imux->num_items; i++) { |
| 2892 | invalidate_nid_path(codec, |
| 2893 | spec->input_paths[i][nums]); |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2894 | spec->input_paths[i][nums] = |
| 2895 | spec->input_paths[i][n]; |
Takashi Iwai | 980428c | 2013-01-09 09:28:20 +0100 | [diff] [blame] | 2896 | } |
Takashi Iwai | 3a65bcd | 2013-01-09 09:06:18 +0100 | [diff] [blame] | 2897 | } |
| 2898 | nums++; |
| 2899 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2900 | spec->num_adc_nids = nums; |
| 2901 | } |
| 2902 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2903 | if (imux->num_items == 1 || |
| 2904 | (imux->num_items == 2 && spec->hp_mic)) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2905 | snd_printdd("hda-codec: reducing to a single ADC\n"); |
| 2906 | spec->num_adc_nids = 1; /* reduce to a single ADC */ |
| 2907 | } |
| 2908 | |
| 2909 | /* single index for individual volumes ctls */ |
| 2910 | if (!spec->dyn_adc_switch && spec->multi_cap_vol) |
| 2911 | spec->num_adc_nids = 1; |
| 2912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | return 0; |
| 2914 | } |
| 2915 | |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 2916 | /* parse capture source paths from the given pin and create imux items */ |
| 2917 | static int parse_capture_source(struct hda_codec *codec, hda_nid_t pin, |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 2918 | int cfg_idx, int num_adcs, |
| 2919 | const char *label, int anchor) |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 2920 | { |
| 2921 | struct hda_gen_spec *spec = codec->spec; |
| 2922 | struct hda_input_mux *imux = &spec->input_mux; |
| 2923 | int imux_idx = imux->num_items; |
| 2924 | bool imux_added = false; |
| 2925 | int c; |
| 2926 | |
| 2927 | for (c = 0; c < num_adcs; c++) { |
| 2928 | struct nid_path *path; |
| 2929 | hda_nid_t adc = spec->adc_nids[c]; |
| 2930 | |
| 2931 | if (!is_reachable_path(codec, pin, adc)) |
| 2932 | continue; |
| 2933 | path = snd_hda_add_new_path(codec, pin, adc, anchor); |
| 2934 | if (!path) |
| 2935 | continue; |
| 2936 | print_nid_path("input", path); |
| 2937 | spec->input_paths[imux_idx][c] = |
| 2938 | snd_hda_get_path_idx(codec, path); |
| 2939 | |
| 2940 | if (!imux_added) { |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 2941 | if (spec->hp_mic_pin == pin) |
| 2942 | spec->hp_mic_mux_idx = imux->num_items; |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 2943 | spec->imux_pins[imux->num_items] = pin; |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 2944 | snd_hda_add_imux_item(imux, label, cfg_idx, NULL); |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 2945 | imux_added = true; |
| 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | return 0; |
| 2950 | } |
| 2951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2952 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2953 | * create playback/capture controls for input pins |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2954 | */ |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 2955 | |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 2956 | /* fill the label for each input at first */ |
| 2957 | static int fill_input_pin_labels(struct hda_codec *codec) |
| 2958 | { |
| 2959 | struct hda_gen_spec *spec = codec->spec; |
| 2960 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2961 | int i; |
| 2962 | |
| 2963 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2964 | hda_nid_t pin = cfg->inputs[i].pin; |
| 2965 | const char *label; |
| 2966 | int j, idx; |
| 2967 | |
| 2968 | if (!is_input_pin(codec, pin)) |
| 2969 | continue; |
| 2970 | |
| 2971 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 2972 | idx = 0; |
David Henningsson | 8e8db7f | 2013-01-18 15:43:02 +0100 | [diff] [blame] | 2973 | for (j = i - 1; j >= 0; j--) { |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 2974 | if (spec->input_labels[j] && |
| 2975 | !strcmp(spec->input_labels[j], label)) { |
| 2976 | idx = spec->input_label_idxs[j] + 1; |
| 2977 | break; |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | spec->input_labels[i] = label; |
| 2982 | spec->input_label_idxs[i] = idx; |
| 2983 | } |
| 2984 | |
| 2985 | return 0; |
| 2986 | } |
| 2987 | |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 2988 | #define CFG_IDX_MIX 99 /* a dummy cfg->input idx for stereo mix */ |
| 2989 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2990 | static int create_input_ctls(struct hda_codec *codec) |
Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 2991 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2992 | struct hda_gen_spec *spec = codec->spec; |
| 2993 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2994 | hda_nid_t mixer = spec->mixer_nid; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2995 | int num_adcs; |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 2996 | int i, err; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 2997 | unsigned int val; |
Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 2998 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 2999 | num_adcs = fill_adc_nids(codec); |
| 3000 | if (num_adcs < 0) |
| 3001 | return 0; |
Takashi Iwai | a7da6ce | 2006-09-06 14:03:14 +0200 | [diff] [blame] | 3002 | |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3003 | err = fill_input_pin_labels(codec); |
| 3004 | if (err < 0) |
| 3005 | return err; |
| 3006 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3007 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3008 | hda_nid_t pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3010 | pin = cfg->inputs[i].pin; |
| 3011 | if (!is_input_pin(codec, pin)) |
| 3012 | continue; |
| 3013 | |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3014 | val = PIN_IN; |
| 3015 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
| 3016 | val |= snd_hda_get_default_vref(codec, pin); |
Takashi Iwai | 93c9d8a | 2013-03-11 09:48:43 +0100 | [diff] [blame] | 3017 | if (pin != spec->hp_mic_pin) |
| 3018 | set_pin_target(codec, pin, val, false); |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3019 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3020 | if (mixer) { |
| 3021 | if (is_reachable_path(codec, pin, mixer)) { |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 3022 | err = new_analog_input(codec, i, pin, |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3023 | spec->input_labels[i], |
| 3024 | spec->input_label_idxs[i], |
| 3025 | mixer); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3026 | if (err < 0) |
| 3027 | return err; |
| 3028 | } |
| 3029 | } |
| 3030 | |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3031 | err = parse_capture_source(codec, pin, i, num_adcs, |
| 3032 | spec->input_labels[i], -mixer); |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 3033 | if (err < 0) |
| 3034 | return err; |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 3035 | |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 3036 | if (spec->add_jack_modes) { |
Takashi Iwai | 29476558 | 2013-01-17 09:52:11 +0100 | [diff] [blame] | 3037 | err = create_in_jack_mode(codec, pin); |
| 3038 | if (err < 0) |
| 3039 | return err; |
| 3040 | } |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 3041 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3042 | |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 3043 | if (mixer && spec->add_stereo_mix_input) { |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 3044 | err = parse_capture_source(codec, mixer, CFG_IDX_MIX, num_adcs, |
Takashi Iwai | f3fc0b0 | 2013-01-09 09:14:23 +0100 | [diff] [blame] | 3045 | "Stereo Mix", 0); |
| 3046 | if (err < 0) |
| 3047 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | return 0; |
| 3051 | } |
| 3052 | |
| 3053 | |
| 3054 | /* |
| 3055 | * input source mux |
| 3056 | */ |
| 3057 | |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3058 | /* get the input path specified by the given adc and imux indices */ |
| 3059 | static struct nid_path *get_input_path(struct hda_codec *codec, int adc_idx, int imux_idx) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3060 | { |
| 3061 | struct hda_gen_spec *spec = codec->spec; |
David Henningsson | b56fa1e | 2013-01-16 11:45:35 +0100 | [diff] [blame] | 3062 | if (imux_idx < 0 || imux_idx >= HDA_MAX_NUM_INPUTS) { |
| 3063 | snd_BUG(); |
| 3064 | return NULL; |
| 3065 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3066 | if (spec->dyn_adc_switch) |
| 3067 | adc_idx = spec->dyn_adc_idx[imux_idx]; |
David Henningsson | d3d982f | 2013-01-18 15:43:01 +0100 | [diff] [blame] | 3068 | if (adc_idx < 0 || adc_idx >= AUTO_CFG_MAX_INS) { |
David Henningsson | b56fa1e | 2013-01-16 11:45:35 +0100 | [diff] [blame] | 3069 | snd_BUG(); |
| 3070 | return NULL; |
| 3071 | } |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3072 | return snd_hda_get_path_from_idx(codec, spec->input_paths[imux_idx][adc_idx]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | static int mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 3076 | unsigned int idx); |
| 3077 | |
| 3078 | static int mux_enum_info(struct snd_kcontrol *kcontrol, |
| 3079 | struct snd_ctl_elem_info *uinfo) |
| 3080 | { |
| 3081 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3082 | struct hda_gen_spec *spec = codec->spec; |
| 3083 | return snd_hda_input_mux_info(&spec->input_mux, uinfo); |
| 3084 | } |
| 3085 | |
| 3086 | static int mux_enum_get(struct snd_kcontrol *kcontrol, |
| 3087 | struct snd_ctl_elem_value *ucontrol) |
| 3088 | { |
| 3089 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3090 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 2a8d539 | 2013-01-18 16:23:25 +0100 | [diff] [blame] | 3091 | /* the ctls are created at once with multiple counts */ |
| 3092 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3093 | |
| 3094 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 3095 | return 0; |
| 3096 | } |
| 3097 | |
| 3098 | static int mux_enum_put(struct snd_kcontrol *kcontrol, |
| 3099 | struct snd_ctl_elem_value *ucontrol) |
| 3100 | { |
| 3101 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 2a8d539 | 2013-01-18 16:23:25 +0100 | [diff] [blame] | 3102 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3103 | return mux_select(codec, adc_idx, |
| 3104 | ucontrol->value.enumerated.item[0]); |
| 3105 | } |
| 3106 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3107 | static const struct snd_kcontrol_new cap_src_temp = { |
| 3108 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3109 | .name = "Input Source", |
| 3110 | .info = mux_enum_info, |
| 3111 | .get = mux_enum_get, |
| 3112 | .put = mux_enum_put, |
| 3113 | }; |
| 3114 | |
Takashi Iwai | 47d46ab | 2012-12-20 11:48:54 +0100 | [diff] [blame] | 3115 | /* |
| 3116 | * capture volume and capture switch ctls |
| 3117 | */ |
| 3118 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3119 | typedef int (*put_call_t)(struct snd_kcontrol *kcontrol, |
| 3120 | struct snd_ctl_elem_value *ucontrol); |
| 3121 | |
Takashi Iwai | 47d46ab | 2012-12-20 11:48:54 +0100 | [diff] [blame] | 3122 | /* call the given amp update function for all amps in the imux list at once */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3123 | static int cap_put_caller(struct snd_kcontrol *kcontrol, |
| 3124 | struct snd_ctl_elem_value *ucontrol, |
| 3125 | put_call_t func, int type) |
| 3126 | { |
| 3127 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3128 | struct hda_gen_spec *spec = codec->spec; |
| 3129 | const struct hda_input_mux *imux; |
| 3130 | struct nid_path *path; |
| 3131 | int i, adc_idx, err = 0; |
| 3132 | |
| 3133 | imux = &spec->input_mux; |
David Henningsson | a053d1e | 2013-01-16 11:45:36 +0100 | [diff] [blame] | 3134 | adc_idx = kcontrol->id.index; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3135 | mutex_lock(&codec->control_mutex); |
Takashi Iwai | 47d46ab | 2012-12-20 11:48:54 +0100 | [diff] [blame] | 3136 | /* we use the cache-only update at first since multiple input paths |
| 3137 | * may shared the same amp; by updating only caches, the redundant |
| 3138 | * writes to hardware can be reduced. |
| 3139 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3140 | codec->cached_write = 1; |
| 3141 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3142 | path = get_input_path(codec, adc_idx, i); |
| 3143 | if (!path || !path->ctls[type]) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3144 | continue; |
| 3145 | kcontrol->private_value = path->ctls[type]; |
| 3146 | err = func(kcontrol, ucontrol); |
| 3147 | if (err < 0) |
| 3148 | goto error; |
| 3149 | } |
| 3150 | error: |
| 3151 | codec->cached_write = 0; |
| 3152 | mutex_unlock(&codec->control_mutex); |
Takashi Iwai | dc870f3 | 2013-01-22 15:24:30 +0100 | [diff] [blame] | 3153 | snd_hda_codec_flush_cache(codec); /* flush the updates */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3154 | if (err >= 0 && spec->cap_sync_hook) |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3155 | spec->cap_sync_hook(codec, ucontrol); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3156 | return err; |
| 3157 | } |
| 3158 | |
| 3159 | /* capture volume ctl callbacks */ |
| 3160 | #define cap_vol_info snd_hda_mixer_amp_volume_info |
| 3161 | #define cap_vol_get snd_hda_mixer_amp_volume_get |
| 3162 | #define cap_vol_tlv snd_hda_mixer_amp_tlv |
| 3163 | |
| 3164 | static int cap_vol_put(struct snd_kcontrol *kcontrol, |
| 3165 | struct snd_ctl_elem_value *ucontrol) |
| 3166 | { |
| 3167 | return cap_put_caller(kcontrol, ucontrol, |
| 3168 | snd_hda_mixer_amp_volume_put, |
| 3169 | NID_PATH_VOL_CTL); |
| 3170 | } |
| 3171 | |
| 3172 | static const struct snd_kcontrol_new cap_vol_temp = { |
| 3173 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3174 | .name = "Capture Volume", |
| 3175 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 3176 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 3177 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), |
| 3178 | .info = cap_vol_info, |
| 3179 | .get = cap_vol_get, |
| 3180 | .put = cap_vol_put, |
| 3181 | .tlv = { .c = cap_vol_tlv }, |
| 3182 | }; |
| 3183 | |
| 3184 | /* capture switch ctl callbacks */ |
| 3185 | #define cap_sw_info snd_ctl_boolean_stereo_info |
| 3186 | #define cap_sw_get snd_hda_mixer_amp_switch_get |
| 3187 | |
| 3188 | static int cap_sw_put(struct snd_kcontrol *kcontrol, |
| 3189 | struct snd_ctl_elem_value *ucontrol) |
| 3190 | { |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3191 | return cap_put_caller(kcontrol, ucontrol, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3192 | snd_hda_mixer_amp_switch_put, |
| 3193 | NID_PATH_MUTE_CTL); |
| 3194 | } |
| 3195 | |
| 3196 | static const struct snd_kcontrol_new cap_sw_temp = { |
| 3197 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3198 | .name = "Capture Switch", |
| 3199 | .info = cap_sw_info, |
| 3200 | .get = cap_sw_get, |
| 3201 | .put = cap_sw_put, |
| 3202 | }; |
| 3203 | |
| 3204 | static int parse_capvol_in_path(struct hda_codec *codec, struct nid_path *path) |
| 3205 | { |
| 3206 | hda_nid_t nid; |
| 3207 | int i, depth; |
| 3208 | |
| 3209 | path->ctls[NID_PATH_VOL_CTL] = path->ctls[NID_PATH_MUTE_CTL] = 0; |
| 3210 | for (depth = 0; depth < 3; depth++) { |
| 3211 | if (depth >= path->depth) |
| 3212 | return -EINVAL; |
| 3213 | i = path->depth - depth - 1; |
| 3214 | nid = path->path[i]; |
| 3215 | if (!path->ctls[NID_PATH_VOL_CTL]) { |
| 3216 | if (nid_has_volume(codec, nid, HDA_OUTPUT)) |
| 3217 | path->ctls[NID_PATH_VOL_CTL] = |
| 3218 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3219 | else if (nid_has_volume(codec, nid, HDA_INPUT)) { |
| 3220 | int idx = path->idx[i]; |
| 3221 | if (!depth && codec->single_adc_amp) |
| 3222 | idx = 0; |
| 3223 | path->ctls[NID_PATH_VOL_CTL] = |
| 3224 | HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT); |
| 3225 | } |
| 3226 | } |
| 3227 | if (!path->ctls[NID_PATH_MUTE_CTL]) { |
| 3228 | if (nid_has_mute(codec, nid, HDA_OUTPUT)) |
| 3229 | path->ctls[NID_PATH_MUTE_CTL] = |
| 3230 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3231 | else if (nid_has_mute(codec, nid, HDA_INPUT)) { |
| 3232 | int idx = path->idx[i]; |
| 3233 | if (!depth && codec->single_adc_amp) |
| 3234 | idx = 0; |
| 3235 | path->ctls[NID_PATH_MUTE_CTL] = |
| 3236 | HDA_COMPOSE_AMP_VAL(nid, 3, idx, HDA_INPUT); |
| 3237 | } |
| 3238 | } |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 3239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | return 0; |
| 3241 | } |
| 3242 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3243 | static bool is_inv_dmic_pin(struct hda_codec *codec, hda_nid_t nid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3245 | struct hda_gen_spec *spec = codec->spec; |
| 3246 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3247 | unsigned int val; |
| 3248 | int i; |
| 3249 | |
| 3250 | if (!spec->inv_dmic_split) |
| 3251 | return false; |
| 3252 | for (i = 0; i < cfg->num_inputs; i++) { |
| 3253 | if (cfg->inputs[i].pin != nid) |
| 3254 | continue; |
| 3255 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 3256 | return false; |
| 3257 | val = snd_hda_codec_get_pincfg(codec, nid); |
| 3258 | return snd_hda_get_input_pin_attr(val) == INPUT_PIN_ATTR_INT; |
| 3259 | } |
| 3260 | return false; |
| 3261 | } |
| 3262 | |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3263 | /* capture switch put callback for a single control with hook call */ |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3264 | static int cap_single_sw_put(struct snd_kcontrol *kcontrol, |
| 3265 | struct snd_ctl_elem_value *ucontrol) |
| 3266 | { |
| 3267 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3268 | struct hda_gen_spec *spec = codec->spec; |
| 3269 | int ret; |
| 3270 | |
| 3271 | ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 3272 | if (ret < 0) |
| 3273 | return ret; |
| 3274 | |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3275 | if (spec->cap_sync_hook) |
| 3276 | spec->cap_sync_hook(codec, ucontrol); |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3277 | |
| 3278 | return ret; |
| 3279 | } |
| 3280 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3281 | static int add_single_cap_ctl(struct hda_codec *codec, const char *label, |
| 3282 | int idx, bool is_switch, unsigned int ctl, |
| 3283 | bool inv_dmic) |
| 3284 | { |
| 3285 | struct hda_gen_spec *spec = codec->spec; |
| 3286 | char tmpname[44]; |
| 3287 | int type = is_switch ? HDA_CTL_WIDGET_MUTE : HDA_CTL_WIDGET_VOL; |
| 3288 | const char *sfx = is_switch ? "Switch" : "Volume"; |
| 3289 | unsigned int chs = inv_dmic ? 1 : 3; |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3290 | struct snd_kcontrol_new *knew; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3291 | |
| 3292 | if (!ctl) |
| 3293 | return 0; |
| 3294 | |
| 3295 | if (label) |
| 3296 | snprintf(tmpname, sizeof(tmpname), |
| 3297 | "%s Capture %s", label, sfx); |
| 3298 | else |
| 3299 | snprintf(tmpname, sizeof(tmpname), |
| 3300 | "Capture %s", sfx); |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3301 | knew = add_control(spec, type, tmpname, idx, |
| 3302 | amp_val_replace_channels(ctl, chs)); |
| 3303 | if (!knew) |
| 3304 | return -ENOMEM; |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3305 | if (is_switch) |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3306 | knew->put = cap_single_sw_put; |
| 3307 | if (!inv_dmic) |
| 3308 | return 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3309 | |
| 3310 | /* Make independent right kcontrol */ |
| 3311 | if (label) |
| 3312 | snprintf(tmpname, sizeof(tmpname), |
| 3313 | "Inverted %s Capture %s", label, sfx); |
| 3314 | else |
| 3315 | snprintf(tmpname, sizeof(tmpname), |
| 3316 | "Inverted Capture %s", sfx); |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3317 | knew = add_control(spec, type, tmpname, idx, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3318 | amp_val_replace_channels(ctl, 2)); |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3319 | if (!knew) |
| 3320 | return -ENOMEM; |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3321 | if (is_switch) |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3322 | knew->put = cap_single_sw_put; |
| 3323 | return 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | /* create single (and simple) capture volume and switch controls */ |
| 3327 | static int create_single_cap_vol_ctl(struct hda_codec *codec, int idx, |
| 3328 | unsigned int vol_ctl, unsigned int sw_ctl, |
| 3329 | bool inv_dmic) |
| 3330 | { |
| 3331 | int err; |
| 3332 | err = add_single_cap_ctl(codec, NULL, idx, false, vol_ctl, inv_dmic); |
| 3333 | if (err < 0) |
| 3334 | return err; |
| 3335 | err = add_single_cap_ctl(codec, NULL, idx, true, sw_ctl, inv_dmic); |
| 3336 | if (err < 0) |
| 3337 | return err; |
| 3338 | return 0; |
| 3339 | } |
| 3340 | |
| 3341 | /* create bound capture volume and switch controls */ |
| 3342 | static int create_bind_cap_vol_ctl(struct hda_codec *codec, int idx, |
| 3343 | unsigned int vol_ctl, unsigned int sw_ctl) |
| 3344 | { |
| 3345 | struct hda_gen_spec *spec = codec->spec; |
| 3346 | struct snd_kcontrol_new *knew; |
| 3347 | |
| 3348 | if (vol_ctl) { |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 3349 | knew = snd_hda_gen_add_kctl(spec, NULL, &cap_vol_temp); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3350 | if (!knew) |
| 3351 | return -ENOMEM; |
| 3352 | knew->index = idx; |
| 3353 | knew->private_value = vol_ctl; |
| 3354 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
| 3355 | } |
| 3356 | if (sw_ctl) { |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 3357 | knew = snd_hda_gen_add_kctl(spec, NULL, &cap_sw_temp); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3358 | if (!knew) |
| 3359 | return -ENOMEM; |
| 3360 | knew->index = idx; |
| 3361 | knew->private_value = sw_ctl; |
| 3362 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
| 3363 | } |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | /* return the vol ctl when used first in the imux list */ |
| 3368 | static unsigned int get_first_cap_ctl(struct hda_codec *codec, int idx, int type) |
| 3369 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3370 | struct nid_path *path; |
| 3371 | unsigned int ctl; |
| 3372 | int i; |
| 3373 | |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3374 | path = get_input_path(codec, 0, idx); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3375 | if (!path) |
| 3376 | return 0; |
| 3377 | ctl = path->ctls[type]; |
| 3378 | if (!ctl) |
| 3379 | return 0; |
| 3380 | for (i = 0; i < idx - 1; i++) { |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3381 | path = get_input_path(codec, 0, i); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3382 | if (path && path->ctls[type] == ctl) |
| 3383 | return 0; |
| 3384 | } |
| 3385 | return ctl; |
| 3386 | } |
| 3387 | |
| 3388 | /* create individual capture volume and switch controls per input */ |
| 3389 | static int create_multi_cap_vol_ctl(struct hda_codec *codec) |
| 3390 | { |
| 3391 | struct hda_gen_spec *spec = codec->spec; |
| 3392 | struct hda_input_mux *imux = &spec->input_mux; |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3393 | int i, err, type; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3394 | |
| 3395 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3396 | bool inv_dmic; |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3397 | int idx; |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 3398 | |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3399 | idx = imux->items[i].index; |
| 3400 | if (idx >= spec->autocfg.num_inputs) |
Takashi Iwai | 9dba205 | 2013-01-18 10:01:15 +0100 | [diff] [blame] | 3401 | continue; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3402 | inv_dmic = is_inv_dmic_pin(codec, spec->imux_pins[i]); |
| 3403 | |
| 3404 | for (type = 0; type < 2; type++) { |
Takashi Iwai | c970042 | 2013-01-18 10:17:30 +0100 | [diff] [blame] | 3405 | err = add_single_cap_ctl(codec, |
| 3406 | spec->input_labels[idx], |
| 3407 | spec->input_label_idxs[idx], |
| 3408 | type, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3409 | get_first_cap_ctl(codec, i, type), |
| 3410 | inv_dmic); |
| 3411 | if (err < 0) |
| 3412 | return err; |
| 3413 | } |
| 3414 | } |
| 3415 | return 0; |
| 3416 | } |
| 3417 | |
| 3418 | static int create_capture_mixers(struct hda_codec *codec) |
| 3419 | { |
| 3420 | struct hda_gen_spec *spec = codec->spec; |
| 3421 | struct hda_input_mux *imux = &spec->input_mux; |
| 3422 | int i, n, nums, err; |
| 3423 | |
| 3424 | if (spec->dyn_adc_switch) |
| 3425 | nums = 1; |
| 3426 | else |
| 3427 | nums = spec->num_adc_nids; |
| 3428 | |
| 3429 | if (!spec->auto_mic && imux->num_items > 1) { |
| 3430 | struct snd_kcontrol_new *knew; |
Takashi Iwai | 624d914 | 2012-12-19 17:41:52 +0100 | [diff] [blame] | 3431 | const char *name; |
| 3432 | name = nums > 1 ? "Input Source" : "Capture Source"; |
| 3433 | knew = snd_hda_gen_add_kctl(spec, name, &cap_src_temp); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3434 | if (!knew) |
| 3435 | return -ENOMEM; |
| 3436 | knew->count = nums; |
| 3437 | } |
| 3438 | |
| 3439 | for (n = 0; n < nums; n++) { |
| 3440 | bool multi = false; |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 3441 | bool multi_cap_vol = spec->multi_cap_vol; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3442 | bool inv_dmic = false; |
| 3443 | int vol, sw; |
| 3444 | |
| 3445 | vol = sw = 0; |
| 3446 | for (i = 0; i < imux->num_items; i++) { |
| 3447 | struct nid_path *path; |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3448 | path = get_input_path(codec, n, i); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3449 | if (!path) |
| 3450 | continue; |
| 3451 | parse_capvol_in_path(codec, path); |
| 3452 | if (!vol) |
| 3453 | vol = path->ctls[NID_PATH_VOL_CTL]; |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 3454 | else if (vol != path->ctls[NID_PATH_VOL_CTL]) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3455 | multi = true; |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 3456 | if (!same_amp_caps(codec, vol, |
| 3457 | path->ctls[NID_PATH_VOL_CTL], HDA_INPUT)) |
| 3458 | multi_cap_vol = true; |
| 3459 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3460 | if (!sw) |
| 3461 | sw = path->ctls[NID_PATH_MUTE_CTL]; |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 3462 | else if (sw != path->ctls[NID_PATH_MUTE_CTL]) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3463 | multi = true; |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 3464 | if (!same_amp_caps(codec, sw, |
| 3465 | path->ctls[NID_PATH_MUTE_CTL], HDA_INPUT)) |
| 3466 | multi_cap_vol = true; |
| 3467 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3468 | if (is_inv_dmic_pin(codec, spec->imux_pins[i])) |
| 3469 | inv_dmic = true; |
| 3470 | } |
| 3471 | |
| 3472 | if (!multi) |
| 3473 | err = create_single_cap_vol_ctl(codec, n, vol, sw, |
| 3474 | inv_dmic); |
David Henningsson | 99a5592 | 2013-01-16 15:58:44 +0100 | [diff] [blame] | 3475 | else if (!multi_cap_vol) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3476 | err = create_bind_cap_vol_ctl(codec, n, vol, sw); |
| 3477 | else |
| 3478 | err = create_multi_cap_vol_ctl(codec); |
| 3479 | if (err < 0) |
| 3480 | return err; |
| 3481 | } |
| 3482 | |
| 3483 | return 0; |
| 3484 | } |
| 3485 | |
| 3486 | /* |
| 3487 | * add mic boosts if needed |
| 3488 | */ |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3489 | |
| 3490 | /* check whether the given amp is feasible as a boost volume */ |
| 3491 | static bool check_boost_vol(struct hda_codec *codec, hda_nid_t nid, |
| 3492 | int dir, int idx) |
| 3493 | { |
| 3494 | unsigned int step; |
| 3495 | |
| 3496 | if (!nid_has_volume(codec, nid, dir) || |
| 3497 | is_ctl_associated(codec, nid, dir, idx, NID_PATH_VOL_CTL) || |
| 3498 | is_ctl_associated(codec, nid, dir, idx, NID_PATH_BOOST_CTL)) |
| 3499 | return false; |
| 3500 | |
| 3501 | step = (query_amp_caps(codec, nid, dir) & AC_AMPCAP_STEP_SIZE) |
| 3502 | >> AC_AMPCAP_STEP_SIZE_SHIFT; |
| 3503 | if (step < 0x20) |
| 3504 | return false; |
| 3505 | return true; |
| 3506 | } |
| 3507 | |
| 3508 | /* look for a boost amp in a widget close to the pin */ |
| 3509 | static unsigned int look_for_boost_amp(struct hda_codec *codec, |
| 3510 | struct nid_path *path) |
| 3511 | { |
| 3512 | unsigned int val = 0; |
| 3513 | hda_nid_t nid; |
| 3514 | int depth; |
| 3515 | |
| 3516 | for (depth = 0; depth < 3; depth++) { |
| 3517 | if (depth >= path->depth - 1) |
| 3518 | break; |
| 3519 | nid = path->path[depth]; |
| 3520 | if (depth && check_boost_vol(codec, nid, HDA_OUTPUT, 0)) { |
| 3521 | val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT); |
| 3522 | break; |
| 3523 | } else if (check_boost_vol(codec, nid, HDA_INPUT, |
| 3524 | path->idx[depth])) { |
| 3525 | val = HDA_COMPOSE_AMP_VAL(nid, 3, path->idx[depth], |
| 3526 | HDA_INPUT); |
| 3527 | break; |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | return val; |
| 3532 | } |
| 3533 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3534 | static int parse_mic_boost(struct hda_codec *codec) |
| 3535 | { |
| 3536 | struct hda_gen_spec *spec = codec->spec; |
| 3537 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3538 | struct hda_input_mux *imux = &spec->input_mux; |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3539 | int i; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3540 | |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3541 | if (!spec->num_adc_nids) |
| 3542 | return 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3543 | |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3544 | for (i = 0; i < imux->num_items; i++) { |
| 3545 | struct nid_path *path; |
| 3546 | unsigned int val; |
| 3547 | int idx; |
| 3548 | char boost_label[44]; |
David Henningsson | 02aba55 | 2013-01-16 15:58:43 +0100 | [diff] [blame] | 3549 | |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3550 | idx = imux->items[i].index; |
| 3551 | if (idx >= imux->num_items) |
| 3552 | continue; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3553 | |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3554 | /* check only line-in and mic pins */ |
Takashi Iwai | 1799cdd5 | 2013-01-18 14:37:16 +0100 | [diff] [blame] | 3555 | if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN) |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3556 | continue; |
| 3557 | |
| 3558 | path = get_input_path(codec, 0, i); |
| 3559 | if (!path) |
| 3560 | continue; |
| 3561 | |
| 3562 | val = look_for_boost_amp(codec, path); |
| 3563 | if (!val) |
| 3564 | continue; |
| 3565 | |
| 3566 | /* create a boost control */ |
| 3567 | snprintf(boost_label, sizeof(boost_label), |
| 3568 | "%s Boost Volume", spec->input_labels[idx]); |
Takashi Iwai | a35bd1e | 2013-01-18 14:01:14 +0100 | [diff] [blame] | 3569 | if (!add_control(spec, HDA_CTL_WIDGET_VOL, boost_label, |
| 3570 | spec->input_label_idxs[idx], val)) |
| 3571 | return -ENOMEM; |
Takashi Iwai | 6f7c83a | 2013-01-18 11:07:15 +0100 | [diff] [blame] | 3572 | |
| 3573 | path->ctls[NID_PATH_BOOST_CTL] = val; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3574 | } |
| 3575 | return 0; |
| 3576 | } |
| 3577 | |
| 3578 | /* |
| 3579 | * parse digital I/Os and set up NIDs in BIOS auto-parse mode |
| 3580 | */ |
| 3581 | static void parse_digital(struct hda_codec *codec) |
| 3582 | { |
| 3583 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 3584 | struct nid_path *path; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3585 | int i, nums; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3586 | hda_nid_t dig_nid, pin; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3587 | |
| 3588 | /* support multiple SPDIFs; the secondary is set up as a slave */ |
| 3589 | nums = 0; |
| 3590 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3591 | pin = spec->autocfg.dig_out_pins[i]; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3592 | dig_nid = look_for_dac(codec, pin, true); |
| 3593 | if (!dig_nid) |
| 3594 | continue; |
Takashi Iwai | 3ca529d | 2013-01-07 17:25:08 +0100 | [diff] [blame] | 3595 | path = snd_hda_add_new_path(codec, dig_nid, pin, 0); |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 3596 | if (!path) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3597 | continue; |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 3598 | print_nid_path("digout", path); |
Takashi Iwai | e1284af | 2013-01-03 16:33:02 +0100 | [diff] [blame] | 3599 | path->active = true; |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 3600 | spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3601 | set_pin_target(codec, pin, PIN_OUT, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3602 | if (!nums) { |
| 3603 | spec->multiout.dig_out_nid = dig_nid; |
| 3604 | spec->dig_out_type = spec->autocfg.dig_out_type[0]; |
| 3605 | } else { |
| 3606 | spec->multiout.slave_dig_outs = spec->slave_dig_outs; |
| 3607 | if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1) |
| 3608 | break; |
| 3609 | spec->slave_dig_outs[nums - 1] = dig_nid; |
| 3610 | } |
| 3611 | nums++; |
| 3612 | } |
| 3613 | |
| 3614 | if (spec->autocfg.dig_in_pin) { |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3615 | pin = spec->autocfg.dig_in_pin; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3616 | dig_nid = codec->start_nid; |
| 3617 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3618 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 3619 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 3620 | continue; |
| 3621 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 3622 | continue; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3623 | path = snd_hda_add_new_path(codec, pin, dig_nid, 0); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3624 | if (path) { |
Takashi Iwai | 0c8c0f5 | 2012-12-20 17:54:22 +0100 | [diff] [blame] | 3625 | print_nid_path("digin", path); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3626 | path->active = true; |
| 3627 | spec->dig_in_nid = dig_nid; |
Takashi Iwai | 2430d7b | 2013-01-04 15:09:42 +0100 | [diff] [blame] | 3628 | spec->digin_path = snd_hda_get_path_idx(codec, path); |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3629 | set_pin_target(codec, pin, PIN_IN, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3630 | break; |
| 3631 | } |
| 3632 | } |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | |
| 3637 | /* |
| 3638 | * input MUX handling |
| 3639 | */ |
| 3640 | |
| 3641 | static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur); |
| 3642 | |
| 3643 | /* select the given imux item; either unmute exclusively or select the route */ |
| 3644 | static int mux_select(struct hda_codec *codec, unsigned int adc_idx, |
| 3645 | unsigned int idx) |
| 3646 | { |
| 3647 | struct hda_gen_spec *spec = codec->spec; |
| 3648 | const struct hda_input_mux *imux; |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 3649 | struct nid_path *old_path, *path; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3650 | |
| 3651 | imux = &spec->input_mux; |
| 3652 | if (!imux->num_items) |
| 3653 | return 0; |
| 3654 | |
| 3655 | if (idx >= imux->num_items) |
| 3656 | idx = imux->num_items - 1; |
| 3657 | if (spec->cur_mux[adc_idx] == idx) |
| 3658 | return 0; |
| 3659 | |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 3660 | old_path = get_input_path(codec, adc_idx, spec->cur_mux[adc_idx]); |
| 3661 | if (!old_path) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3662 | return 0; |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 3663 | if (old_path->active) |
| 3664 | snd_hda_activate_path(codec, old_path, false, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3665 | |
| 3666 | spec->cur_mux[adc_idx] = idx; |
| 3667 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 3668 | if (spec->hp_mic) |
| 3669 | update_hp_mic(codec, adc_idx, false); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3670 | |
| 3671 | if (spec->dyn_adc_switch) |
| 3672 | dyn_adc_pcm_resetup(codec, idx); |
| 3673 | |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 3674 | path = get_input_path(codec, adc_idx, idx); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3675 | if (!path) |
| 3676 | return 0; |
| 3677 | if (path->active) |
| 3678 | return 0; |
| 3679 | snd_hda_activate_path(codec, path, true, false); |
| 3680 | if (spec->cap_sync_hook) |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 3681 | spec->cap_sync_hook(codec, NULL); |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 3682 | path_power_down_sync(codec, old_path); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3683 | return 1; |
| 3684 | } |
| 3685 | |
| 3686 | |
| 3687 | /* |
| 3688 | * Jack detections for HP auto-mute and mic-switch |
| 3689 | */ |
| 3690 | |
| 3691 | /* check each pin in the given array; returns true if any of them is plugged */ |
| 3692 | static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) |
| 3693 | { |
| 3694 | int i, present = 0; |
| 3695 | |
| 3696 | for (i = 0; i < num_pins; i++) { |
| 3697 | hda_nid_t nid = pins[i]; |
| 3698 | if (!nid) |
| 3699 | break; |
Takashi Iwai | 0b4df93 | 2013-01-10 09:45:13 +0100 | [diff] [blame] | 3700 | /* don't detect pins retasked as inputs */ |
| 3701 | if (snd_hda_codec_get_pin_target(codec, nid) & AC_PINCTL_IN_EN) |
| 3702 | continue; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3703 | present |= snd_hda_jack_detect(codec, nid); |
| 3704 | } |
| 3705 | return present; |
| 3706 | } |
| 3707 | |
| 3708 | /* standard HP/line-out auto-mute helper */ |
| 3709 | static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins, |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3710 | bool mute) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3711 | { |
| 3712 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3713 | int i; |
| 3714 | |
| 3715 | for (i = 0; i < num_pins; i++) { |
| 3716 | hda_nid_t nid = pins[i]; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 3717 | unsigned int val, oldval; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3718 | if (!nid) |
| 3719 | break; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 3720 | oldval = snd_hda_codec_get_pin_target(codec, nid); |
| 3721 | if (oldval & PIN_IN) |
| 3722 | continue; /* no mute for inputs */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3723 | /* don't reset VREF value in case it's controlling |
| 3724 | * the amp (see alc861_fixup_asus_amp_vref_0f()) |
| 3725 | */ |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3726 | if (spec->keep_vref_in_automute) |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 3727 | val = oldval & ~PIN_HP; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3728 | else |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3729 | val = 0; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3730 | if (!mute) |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 3731 | val |= oldval; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3732 | /* here we call update_pin_ctl() so that the pinctl is changed |
| 3733 | * without changing the pinctl target value; |
| 3734 | * the original target value will be still referred at the |
| 3735 | * init / resume again |
| 3736 | */ |
| 3737 | update_pin_ctl(codec, nid, val); |
Takashi Iwai | d5a9f1b | 2012-12-20 15:36:30 +0100 | [diff] [blame] | 3738 | set_pin_eapd(codec, nid, !mute); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3739 | } |
| 3740 | } |
| 3741 | |
| 3742 | /* Toggle outputs muting */ |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3743 | void snd_hda_gen_update_outputs(struct hda_codec *codec) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3744 | { |
| 3745 | struct hda_gen_spec *spec = codec->spec; |
| 3746 | int on; |
| 3747 | |
| 3748 | /* Control HP pins/amps depending on master_mute state; |
| 3749 | * in general, HP pins/amps control should be enabled in all cases, |
| 3750 | * but currently set only for master_mute, just to be safe |
| 3751 | */ |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 3752 | do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3753 | spec->autocfg.hp_pins, spec->master_mute); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3754 | |
| 3755 | if (!spec->automute_speaker) |
| 3756 | on = 0; |
| 3757 | else |
| 3758 | on = spec->hp_jack_present | spec->line_jack_present; |
| 3759 | on |= spec->master_mute; |
Takashi Iwai | 47b9ddb | 2013-01-16 18:18:00 +0100 | [diff] [blame] | 3760 | spec->speaker_muted = on; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3761 | do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3762 | spec->autocfg.speaker_pins, on); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3763 | |
| 3764 | /* toggle line-out mutes if needed, too */ |
| 3765 | /* if LO is a copy of either HP or Speaker, don't need to handle it */ |
| 3766 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || |
| 3767 | spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) |
| 3768 | return; |
| 3769 | if (!spec->automute_lo) |
| 3770 | on = 0; |
| 3771 | else |
| 3772 | on = spec->hp_jack_present; |
| 3773 | on |= spec->master_mute; |
Takashi Iwai | 47b9ddb | 2013-01-16 18:18:00 +0100 | [diff] [blame] | 3774 | spec->line_out_muted = on; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3775 | do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 3776 | spec->autocfg.line_out_pins, on); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3777 | } |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3778 | EXPORT_SYMBOL_HDA(snd_hda_gen_update_outputs); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3779 | |
| 3780 | static void call_update_outputs(struct hda_codec *codec) |
| 3781 | { |
| 3782 | struct hda_gen_spec *spec = codec->spec; |
| 3783 | if (spec->automute_hook) |
| 3784 | spec->automute_hook(codec); |
| 3785 | else |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3786 | snd_hda_gen_update_outputs(codec); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | /* standard HP-automute helper */ |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3790 | void snd_hda_gen_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3791 | { |
| 3792 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 92603c5 | 2013-01-22 07:46:31 +0100 | [diff] [blame] | 3793 | hda_nid_t *pins = spec->autocfg.hp_pins; |
| 3794 | int num_pins = ARRAY_SIZE(spec->autocfg.hp_pins); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3795 | |
Takashi Iwai | 92603c5 | 2013-01-22 07:46:31 +0100 | [diff] [blame] | 3796 | /* No detection for the first HP jack during indep-HP mode */ |
| 3797 | if (spec->indep_hp_enabled) { |
| 3798 | pins++; |
| 3799 | num_pins--; |
| 3800 | } |
| 3801 | |
| 3802 | spec->hp_jack_present = detect_jacks(codec, num_pins, pins); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3803 | if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo)) |
| 3804 | return; |
| 3805 | call_update_outputs(codec); |
| 3806 | } |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3807 | EXPORT_SYMBOL_HDA(snd_hda_gen_hp_automute); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3808 | |
| 3809 | /* standard line-out-automute helper */ |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3810 | void snd_hda_gen_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3811 | { |
| 3812 | struct hda_gen_spec *spec = codec->spec; |
| 3813 | |
| 3814 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 3815 | return; |
| 3816 | /* check LO jack only when it's different from HP */ |
| 3817 | if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0]) |
| 3818 | return; |
| 3819 | |
| 3820 | spec->line_jack_present = |
| 3821 | detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), |
| 3822 | spec->autocfg.line_out_pins); |
| 3823 | if (!spec->automute_speaker || !spec->detect_lo) |
| 3824 | return; |
| 3825 | call_update_outputs(codec); |
| 3826 | } |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3827 | EXPORT_SYMBOL_HDA(snd_hda_gen_line_automute); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3828 | |
| 3829 | /* standard mic auto-switch helper */ |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3830 | void snd_hda_gen_mic_autoswitch(struct hda_codec *codec, struct hda_jack_tbl *jack) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3831 | { |
| 3832 | struct hda_gen_spec *spec = codec->spec; |
| 3833 | int i; |
| 3834 | |
| 3835 | if (!spec->auto_mic) |
| 3836 | return; |
| 3837 | |
| 3838 | for (i = spec->am_num_entries - 1; i > 0; i--) { |
Takashi Iwai | 0b4df93 | 2013-01-10 09:45:13 +0100 | [diff] [blame] | 3839 | hda_nid_t pin = spec->am_entry[i].pin; |
| 3840 | /* don't detect pins retasked as outputs */ |
| 3841 | if (snd_hda_codec_get_pin_target(codec, pin) & AC_PINCTL_OUT_EN) |
| 3842 | continue; |
| 3843 | if (snd_hda_jack_detect(codec, pin)) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3844 | mux_select(codec, 0, spec->am_entry[i].idx); |
| 3845 | return; |
| 3846 | } |
| 3847 | } |
| 3848 | mux_select(codec, 0, spec->am_entry[0].idx); |
| 3849 | } |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 3850 | EXPORT_SYMBOL_HDA(snd_hda_gen_mic_autoswitch); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3851 | |
Takashi Iwai | a5cc250 | 2013-01-16 18:08:55 +0100 | [diff] [blame] | 3852 | /* update jack retasking */ |
| 3853 | static void update_automute_all(struct hda_codec *codec) |
| 3854 | { |
| 3855 | struct hda_gen_spec *spec = codec->spec; |
| 3856 | |
Takashi Iwai | 8ba955c | 2013-03-07 18:40:58 +0100 | [diff] [blame] | 3857 | update_hp_automute_hook(codec); |
Takashi Iwai | a5cc250 | 2013-01-16 18:08:55 +0100 | [diff] [blame] | 3858 | if (spec->line_automute_hook) |
| 3859 | spec->line_automute_hook(codec, NULL); |
| 3860 | else |
| 3861 | snd_hda_gen_line_automute(codec, NULL); |
| 3862 | if (spec->mic_autoswitch_hook) |
| 3863 | spec->mic_autoswitch_hook(codec, NULL); |
| 3864 | else |
| 3865 | snd_hda_gen_mic_autoswitch(codec, NULL); |
| 3866 | } |
| 3867 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3868 | /* |
| 3869 | * Auto-Mute mode mixer enum support |
| 3870 | */ |
| 3871 | static int automute_mode_info(struct snd_kcontrol *kcontrol, |
| 3872 | struct snd_ctl_elem_info *uinfo) |
| 3873 | { |
| 3874 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3875 | struct hda_gen_spec *spec = codec->spec; |
| 3876 | static const char * const texts3[] = { |
| 3877 | "Disabled", "Speaker Only", "Line Out+Speaker" |
Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 3878 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3879 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3880 | if (spec->automute_speaker_possible && spec->automute_lo_possible) |
| 3881 | return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3); |
| 3882 | return snd_hda_enum_bool_helper_info(kcontrol, uinfo); |
| 3883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3884 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3885 | static int automute_mode_get(struct snd_kcontrol *kcontrol, |
| 3886 | struct snd_ctl_elem_value *ucontrol) |
| 3887 | { |
| 3888 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3889 | struct hda_gen_spec *spec = codec->spec; |
| 3890 | unsigned int val = 0; |
| 3891 | if (spec->automute_speaker) |
| 3892 | val++; |
| 3893 | if (spec->automute_lo) |
| 3894 | val++; |
Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 3895 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3896 | ucontrol->value.enumerated.item[0] = val; |
| 3897 | return 0; |
| 3898 | } |
| 3899 | |
| 3900 | static int automute_mode_put(struct snd_kcontrol *kcontrol, |
| 3901 | struct snd_ctl_elem_value *ucontrol) |
| 3902 | { |
| 3903 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3904 | struct hda_gen_spec *spec = codec->spec; |
| 3905 | |
| 3906 | switch (ucontrol->value.enumerated.item[0]) { |
| 3907 | case 0: |
| 3908 | if (!spec->automute_speaker && !spec->automute_lo) |
| 3909 | return 0; |
| 3910 | spec->automute_speaker = 0; |
| 3911 | spec->automute_lo = 0; |
| 3912 | break; |
| 3913 | case 1: |
| 3914 | if (spec->automute_speaker_possible) { |
| 3915 | if (!spec->automute_lo && spec->automute_speaker) |
| 3916 | return 0; |
| 3917 | spec->automute_speaker = 1; |
| 3918 | spec->automute_lo = 0; |
| 3919 | } else if (spec->automute_lo_possible) { |
| 3920 | if (spec->automute_lo) |
| 3921 | return 0; |
| 3922 | spec->automute_lo = 1; |
| 3923 | } else |
| 3924 | return -EINVAL; |
| 3925 | break; |
| 3926 | case 2: |
| 3927 | if (!spec->automute_lo_possible || !spec->automute_speaker_possible) |
| 3928 | return -EINVAL; |
| 3929 | if (spec->automute_speaker && spec->automute_lo) |
| 3930 | return 0; |
| 3931 | spec->automute_speaker = 1; |
| 3932 | spec->automute_lo = 1; |
| 3933 | break; |
| 3934 | default: |
| 3935 | return -EINVAL; |
| 3936 | } |
| 3937 | call_update_outputs(codec); |
| 3938 | return 1; |
| 3939 | } |
| 3940 | |
| 3941 | static const struct snd_kcontrol_new automute_mode_enum = { |
| 3942 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3943 | .name = "Auto-Mute Mode", |
| 3944 | .info = automute_mode_info, |
| 3945 | .get = automute_mode_get, |
| 3946 | .put = automute_mode_put, |
| 3947 | }; |
| 3948 | |
| 3949 | static int add_automute_mode_enum(struct hda_codec *codec) |
| 3950 | { |
| 3951 | struct hda_gen_spec *spec = codec->spec; |
| 3952 | |
Takashi Iwai | 12c93df | 2012-12-19 14:38:33 +0100 | [diff] [blame] | 3953 | if (!snd_hda_gen_add_kctl(spec, NULL, &automute_mode_enum)) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3954 | return -ENOMEM; |
| 3955 | return 0; |
| 3956 | } |
| 3957 | |
| 3958 | /* |
| 3959 | * Check the availability of HP/line-out auto-mute; |
| 3960 | * Set up appropriately if really supported |
| 3961 | */ |
| 3962 | static int check_auto_mute_availability(struct hda_codec *codec) |
| 3963 | { |
| 3964 | struct hda_gen_spec *spec = codec->spec; |
| 3965 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 3966 | int present = 0; |
| 3967 | int i, err; |
| 3968 | |
Takashi Iwai | f72706b | 2013-01-16 18:20:07 +0100 | [diff] [blame] | 3969 | if (spec->suppress_auto_mute) |
| 3970 | return 0; |
| 3971 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3972 | if (cfg->hp_pins[0]) |
| 3973 | present++; |
| 3974 | if (cfg->line_out_pins[0]) |
| 3975 | present++; |
| 3976 | if (cfg->speaker_pins[0]) |
| 3977 | present++; |
| 3978 | if (present < 2) /* need two different output types */ |
Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 3979 | return 0; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3980 | |
| 3981 | if (!cfg->speaker_pins[0] && |
| 3982 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { |
| 3983 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 3984 | sizeof(cfg->speaker_pins)); |
| 3985 | cfg->speaker_outs = cfg->line_outs; |
Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 3986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 3988 | if (!cfg->hp_pins[0] && |
| 3989 | cfg->line_out_type == AUTO_PIN_HP_OUT) { |
| 3990 | memcpy(cfg->hp_pins, cfg->line_out_pins, |
| 3991 | sizeof(cfg->hp_pins)); |
| 3992 | cfg->hp_outs = cfg->line_outs; |
| 3993 | } |
| 3994 | |
| 3995 | for (i = 0; i < cfg->hp_outs; i++) { |
| 3996 | hda_nid_t nid = cfg->hp_pins[i]; |
| 3997 | if (!is_jack_detectable(codec, nid)) |
| 3998 | continue; |
| 3999 | snd_printdd("hda-codec: Enable HP auto-muting on NID 0x%x\n", |
| 4000 | nid); |
| 4001 | snd_hda_jack_detect_enable_callback(codec, nid, HDA_GEN_HP_EVENT, |
Takashi Iwai | 2e03e95 | 2013-01-03 15:55:06 +0100 | [diff] [blame] | 4002 | spec->hp_automute_hook ? |
| 4003 | spec->hp_automute_hook : |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 4004 | snd_hda_gen_hp_automute); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4005 | spec->detect_hp = 1; |
| 4006 | } |
| 4007 | |
| 4008 | if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) { |
| 4009 | if (cfg->speaker_outs) |
| 4010 | for (i = 0; i < cfg->line_outs; i++) { |
| 4011 | hda_nid_t nid = cfg->line_out_pins[i]; |
| 4012 | if (!is_jack_detectable(codec, nid)) |
| 4013 | continue; |
| 4014 | snd_printdd("hda-codec: Enable Line-Out auto-muting on NID 0x%x\n", nid); |
| 4015 | snd_hda_jack_detect_enable_callback(codec, nid, |
| 4016 | HDA_GEN_FRONT_EVENT, |
Takashi Iwai | 2e03e95 | 2013-01-03 15:55:06 +0100 | [diff] [blame] | 4017 | spec->line_automute_hook ? |
| 4018 | spec->line_automute_hook : |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 4019 | snd_hda_gen_line_automute); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4020 | spec->detect_lo = 1; |
| 4021 | } |
| 4022 | spec->automute_lo_possible = spec->detect_hp; |
| 4023 | } |
| 4024 | |
| 4025 | spec->automute_speaker_possible = cfg->speaker_outs && |
| 4026 | (spec->detect_hp || spec->detect_lo); |
| 4027 | |
| 4028 | spec->automute_lo = spec->automute_lo_possible; |
| 4029 | spec->automute_speaker = spec->automute_speaker_possible; |
| 4030 | |
| 4031 | if (spec->automute_speaker_possible || spec->automute_lo_possible) { |
| 4032 | /* create a control for automute mode */ |
| 4033 | err = add_automute_mode_enum(codec); |
| 4034 | if (err < 0) |
| 4035 | return err; |
| 4036 | } |
| 4037 | return 0; |
| 4038 | } |
| 4039 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4040 | /* check whether all auto-mic pins are valid; setup indices if OK */ |
| 4041 | static bool auto_mic_check_imux(struct hda_codec *codec) |
| 4042 | { |
| 4043 | struct hda_gen_spec *spec = codec->spec; |
| 4044 | const struct hda_input_mux *imux; |
| 4045 | int i; |
| 4046 | |
| 4047 | imux = &spec->input_mux; |
| 4048 | for (i = 0; i < spec->am_num_entries; i++) { |
| 4049 | spec->am_entry[i].idx = |
| 4050 | find_idx_in_nid_list(spec->am_entry[i].pin, |
| 4051 | spec->imux_pins, imux->num_items); |
| 4052 | if (spec->am_entry[i].idx < 0) |
| 4053 | return false; /* no corresponding imux */ |
| 4054 | } |
| 4055 | |
| 4056 | /* we don't need the jack detection for the first pin */ |
| 4057 | for (i = 1; i < spec->am_num_entries; i++) |
| 4058 | snd_hda_jack_detect_enable_callback(codec, |
| 4059 | spec->am_entry[i].pin, |
| 4060 | HDA_GEN_MIC_EVENT, |
Takashi Iwai | 2e03e95 | 2013-01-03 15:55:06 +0100 | [diff] [blame] | 4061 | spec->mic_autoswitch_hook ? |
| 4062 | spec->mic_autoswitch_hook : |
Takashi Iwai | 5d550e1 | 2012-12-19 15:16:44 +0100 | [diff] [blame] | 4063 | snd_hda_gen_mic_autoswitch); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4064 | return true; |
| 4065 | } |
| 4066 | |
| 4067 | static int compare_attr(const void *ap, const void *bp) |
| 4068 | { |
| 4069 | const struct automic_entry *a = ap; |
| 4070 | const struct automic_entry *b = bp; |
| 4071 | return (int)(a->attr - b->attr); |
| 4072 | } |
| 4073 | |
| 4074 | /* |
| 4075 | * Check the availability of auto-mic switch; |
| 4076 | * Set up if really supported |
| 4077 | */ |
| 4078 | static int check_auto_mic_availability(struct hda_codec *codec) |
| 4079 | { |
| 4080 | struct hda_gen_spec *spec = codec->spec; |
| 4081 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 4082 | unsigned int types; |
| 4083 | int i, num_pins; |
| 4084 | |
Takashi Iwai | d12daf6 | 2013-01-07 16:32:11 +0100 | [diff] [blame] | 4085 | if (spec->suppress_auto_mic) |
| 4086 | return 0; |
| 4087 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4088 | types = 0; |
| 4089 | num_pins = 0; |
| 4090 | for (i = 0; i < cfg->num_inputs; i++) { |
| 4091 | hda_nid_t nid = cfg->inputs[i].pin; |
| 4092 | unsigned int attr; |
| 4093 | attr = snd_hda_codec_get_pincfg(codec, nid); |
| 4094 | attr = snd_hda_get_input_pin_attr(attr); |
| 4095 | if (types & (1 << attr)) |
| 4096 | return 0; /* already occupied */ |
| 4097 | switch (attr) { |
| 4098 | case INPUT_PIN_ATTR_INT: |
| 4099 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 4100 | return 0; /* invalid type */ |
| 4101 | break; |
| 4102 | case INPUT_PIN_ATTR_UNUSED: |
| 4103 | return 0; /* invalid entry */ |
| 4104 | default: |
| 4105 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 4106 | return 0; /* invalid type */ |
| 4107 | if (!spec->line_in_auto_switch && |
| 4108 | cfg->inputs[i].type != AUTO_PIN_MIC) |
| 4109 | return 0; /* only mic is allowed */ |
| 4110 | if (!is_jack_detectable(codec, nid)) |
| 4111 | return 0; /* no unsol support */ |
| 4112 | break; |
| 4113 | } |
| 4114 | if (num_pins >= MAX_AUTO_MIC_PINS) |
| 4115 | return 0; |
| 4116 | types |= (1 << attr); |
| 4117 | spec->am_entry[num_pins].pin = nid; |
| 4118 | spec->am_entry[num_pins].attr = attr; |
| 4119 | num_pins++; |
| 4120 | } |
| 4121 | |
| 4122 | if (num_pins < 2) |
| 4123 | return 0; |
| 4124 | |
| 4125 | spec->am_num_entries = num_pins; |
| 4126 | /* sort the am_entry in the order of attr so that the pin with a |
| 4127 | * higher attr will be selected when the jack is plugged. |
| 4128 | */ |
| 4129 | sort(spec->am_entry, num_pins, sizeof(spec->am_entry[0]), |
| 4130 | compare_attr, NULL); |
| 4131 | |
| 4132 | if (!auto_mic_check_imux(codec)) |
| 4133 | return 0; |
| 4134 | |
| 4135 | spec->auto_mic = 1; |
| 4136 | spec->num_adc_nids = 1; |
| 4137 | spec->cur_mux[0] = spec->am_entry[0].idx; |
| 4138 | snd_printdd("hda-codec: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n", |
| 4139 | spec->am_entry[0].pin, |
| 4140 | spec->am_entry[1].pin, |
| 4141 | spec->am_entry[2].pin); |
| 4142 | |
| 4143 | return 0; |
| 4144 | } |
| 4145 | |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 4146 | /* power_filter hook; make inactive widgets into power down */ |
| 4147 | static unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, |
| 4148 | hda_nid_t nid, |
| 4149 | unsigned int power_state) |
| 4150 | { |
| 4151 | if (power_state != AC_PWRST_D0) |
| 4152 | return power_state; |
| 4153 | if (get_wcaps_type(get_wcaps(codec, nid)) >= AC_WID_POWER) |
| 4154 | return power_state; |
| 4155 | if (is_active_nid(codec, nid, HDA_OUTPUT, 0)) |
| 4156 | return power_state; |
| 4157 | return AC_PWRST_D3; |
| 4158 | } |
| 4159 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4160 | |
Takashi Iwai | 9eb413e | 2012-12-19 14:41:21 +0100 | [diff] [blame] | 4161 | /* |
| 4162 | * Parse the given BIOS configuration and set up the hda_gen_spec |
| 4163 | * |
| 4164 | * return 1 if successful, 0 if the proper config is not found, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4165 | * or a negative error code |
| 4166 | */ |
| 4167 | int snd_hda_gen_parse_auto_config(struct hda_codec *codec, |
Takashi Iwai | 9eb413e | 2012-12-19 14:41:21 +0100 | [diff] [blame] | 4168 | struct auto_pin_cfg *cfg) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4169 | { |
| 4170 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4171 | int err; |
| 4172 | |
Takashi Iwai | 1c70a58 | 2013-01-11 17:48:22 +0100 | [diff] [blame] | 4173 | parse_user_hints(codec); |
| 4174 | |
Takashi Iwai | e4a395e | 2013-01-23 17:00:31 +0100 | [diff] [blame] | 4175 | if (spec->mixer_nid && !spec->mixer_merge_nid) |
| 4176 | spec->mixer_merge_nid = spec->mixer_nid; |
| 4177 | |
Takashi Iwai | 9eb413e | 2012-12-19 14:41:21 +0100 | [diff] [blame] | 4178 | if (cfg != &spec->autocfg) { |
| 4179 | spec->autocfg = *cfg; |
| 4180 | cfg = &spec->autocfg; |
| 4181 | } |
| 4182 | |
David Henningsson | 6fc4cb9 | 2013-01-16 15:58:45 +0100 | [diff] [blame] | 4183 | fill_all_dac_nids(codec); |
| 4184 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4185 | if (!cfg->line_outs) { |
| 4186 | if (cfg->dig_outs || cfg->dig_in_pin) { |
| 4187 | spec->multiout.max_channels = 2; |
| 4188 | spec->no_analog = 1; |
| 4189 | goto dig_only; |
| 4190 | } |
| 4191 | return 0; /* can't find valid BIOS pin config */ |
| 4192 | } |
| 4193 | |
| 4194 | if (!spec->no_primary_hp && |
| 4195 | cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 4196 | cfg->line_outs <= cfg->hp_outs) { |
| 4197 | /* use HP as primary out */ |
| 4198 | cfg->speaker_outs = cfg->line_outs; |
| 4199 | memcpy(cfg->speaker_pins, cfg->line_out_pins, |
| 4200 | sizeof(cfg->speaker_pins)); |
| 4201 | cfg->line_outs = cfg->hp_outs; |
| 4202 | memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins)); |
| 4203 | cfg->hp_outs = 0; |
| 4204 | memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins)); |
| 4205 | cfg->line_out_type = AUTO_PIN_HP_OUT; |
| 4206 | } |
| 4207 | |
| 4208 | err = parse_output_paths(codec); |
| 4209 | if (err < 0) |
| 4210 | return err; |
| 4211 | err = create_multi_channel_mode(codec); |
| 4212 | if (err < 0) |
| 4213 | return err; |
| 4214 | err = create_multi_out_ctls(codec, cfg); |
| 4215 | if (err < 0) |
| 4216 | return err; |
| 4217 | err = create_hp_out_ctls(codec); |
| 4218 | if (err < 0) |
| 4219 | return err; |
| 4220 | err = create_speaker_out_ctls(codec); |
| 4221 | if (err < 0) |
| 4222 | return err; |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4223 | err = create_indep_hp_ctls(codec); |
| 4224 | if (err < 0) |
| 4225 | return err; |
Takashi Iwai | c30aa7b | 2013-01-04 16:42:48 +0100 | [diff] [blame] | 4226 | err = create_loopback_mixing_ctl(codec); |
| 4227 | if (err < 0) |
| 4228 | return err; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 4229 | err = create_hp_mic(codec); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4230 | if (err < 0) |
| 4231 | return err; |
| 4232 | err = create_input_ctls(codec); |
Takashi Iwai | d13bd41 | 2008-07-30 15:01:45 +0200 | [diff] [blame] | 4233 | if (err < 0) |
Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 4234 | return err; |
| 4235 | |
Takashi Iwai | a07a949 | 2013-01-07 16:44:06 +0100 | [diff] [blame] | 4236 | spec->const_channel_count = spec->ext_channel_count; |
| 4237 | /* check the multiple speaker and headphone pins */ |
| 4238 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 4239 | spec->const_channel_count = max(spec->const_channel_count, |
| 4240 | cfg->speaker_outs * 2); |
| 4241 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) |
| 4242 | spec->const_channel_count = max(spec->const_channel_count, |
| 4243 | cfg->hp_outs * 2); |
| 4244 | spec->multiout.max_channels = max(spec->ext_channel_count, |
| 4245 | spec->const_channel_count); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4246 | |
| 4247 | err = check_auto_mute_availability(codec); |
| 4248 | if (err < 0) |
| 4249 | return err; |
| 4250 | |
| 4251 | err = check_dyn_adc_switch(codec); |
| 4252 | if (err < 0) |
| 4253 | return err; |
| 4254 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 4255 | err = check_auto_mic_availability(codec); |
| 4256 | if (err < 0) |
| 4257 | return err; |
Takashi Iwai | 071c73a | 2006-08-23 18:34:06 +0200 | [diff] [blame] | 4258 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4259 | err = create_capture_mixers(codec); |
| 4260 | if (err < 0) |
| 4261 | return err; |
| 4262 | |
| 4263 | err = parse_mic_boost(codec); |
| 4264 | if (err < 0) |
| 4265 | return err; |
| 4266 | |
Takashi Iwai | f811c3c | 2013-03-07 18:32:59 +0100 | [diff] [blame] | 4267 | if (spec->add_jack_modes) { |
Takashi Iwai | 978e77e | 2013-01-10 16:57:58 +0100 | [diff] [blame] | 4268 | if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) { |
| 4269 | err = create_out_jack_modes(codec, cfg->line_outs, |
| 4270 | cfg->line_out_pins); |
| 4271 | if (err < 0) |
| 4272 | return err; |
| 4273 | } |
| 4274 | if (cfg->line_out_type != AUTO_PIN_HP_OUT) { |
| 4275 | err = create_out_jack_modes(codec, cfg->hp_outs, |
| 4276 | cfg->hp_pins); |
| 4277 | if (err < 0) |
| 4278 | return err; |
| 4279 | } |
| 4280 | } |
| 4281 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4282 | dig_only: |
| 4283 | parse_digital(codec); |
| 4284 | |
Takashi Iwai | 55196ff | 2013-01-24 17:32:56 +0100 | [diff] [blame] | 4285 | if (spec->power_down_unused) |
| 4286 | codec->power_filter = snd_hda_gen_path_power_filter; |
| 4287 | |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 4288 | if (!spec->no_analog && spec->beep_nid) { |
| 4289 | err = snd_hda_attach_beep_device(codec, spec->beep_nid); |
| 4290 | if (err < 0) |
| 4291 | return err; |
| 4292 | } |
| 4293 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4294 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4296 | EXPORT_SYMBOL_HDA(snd_hda_gen_parse_auto_config); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4297 | |
| 4298 | |
| 4299 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4300 | * Build control elements |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4302 | |
| 4303 | /* slave controls for virtual master */ |
| 4304 | static const char * const slave_pfxs[] = { |
| 4305 | "Front", "Surround", "Center", "LFE", "Side", |
| 4306 | "Headphone", "Speaker", "Mono", "Line Out", |
| 4307 | "CLFE", "Bass Speaker", "PCM", |
Takashi Iwai | ee79c69 | 2013-01-07 09:57:42 +0100 | [diff] [blame] | 4308 | "Speaker Front", "Speaker Surround", "Speaker CLFE", "Speaker Side", |
| 4309 | "Headphone Front", "Headphone Surround", "Headphone CLFE", |
| 4310 | "Headphone Side", |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4311 | NULL, |
| 4312 | }; |
| 4313 | |
| 4314 | int snd_hda_gen_build_controls(struct hda_codec *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4316 | struct hda_gen_spec *spec = codec->spec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4317 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | |
Takashi Iwai | 36502d0 | 2012-12-19 15:15:10 +0100 | [diff] [blame] | 4319 | if (spec->kctls.used) { |
| 4320 | err = snd_hda_add_new_ctls(codec, spec->kctls.list); |
| 4321 | if (err < 0) |
| 4322 | return err; |
| 4323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4325 | if (spec->multiout.dig_out_nid) { |
| 4326 | err = snd_hda_create_dig_out_ctls(codec, |
| 4327 | spec->multiout.dig_out_nid, |
| 4328 | spec->multiout.dig_out_nid, |
| 4329 | spec->pcm_rec[1].pcm_type); |
| 4330 | if (err < 0) |
| 4331 | return err; |
| 4332 | if (!spec->no_analog) { |
| 4333 | err = snd_hda_create_spdif_share_sw(codec, |
| 4334 | &spec->multiout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4335 | if (err < 0) |
| 4336 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4337 | spec->multiout.share_spdif = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | } |
| 4339 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4340 | if (spec->dig_in_nid) { |
| 4341 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 4342 | if (err < 0) |
| 4343 | return err; |
| 4344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4345 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4346 | /* if we have no master control, let's create it */ |
| 4347 | if (!spec->no_analog && |
| 4348 | !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4349 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
Takashi Iwai | 7a71bbf | 2013-01-17 10:25:15 +0100 | [diff] [blame] | 4350 | spec->vmaster_tlv, slave_pfxs, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4351 | "Playback Volume"); |
| 4352 | if (err < 0) |
| 4353 | return err; |
| 4354 | } |
| 4355 | if (!spec->no_analog && |
| 4356 | !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
| 4357 | err = __snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 4358 | NULL, slave_pfxs, |
| 4359 | "Playback Switch", |
| 4360 | true, &spec->vmaster_mute.sw_kctl); |
| 4361 | if (err < 0) |
| 4362 | return err; |
| 4363 | if (spec->vmaster_mute.hook) |
Takashi Iwai | fd25a97 | 2012-12-20 14:57:18 +0100 | [diff] [blame] | 4364 | snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, |
| 4365 | spec->vmaster_mute_enum); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4368 | free_kctls(spec); /* no longer needed */ |
| 4369 | |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 4370 | if (spec->hp_mic_pin) { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4371 | int err; |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 4372 | int nid = spec->hp_mic_pin; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4373 | err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0); |
| 4374 | if (err < 0) |
| 4375 | return err; |
| 4376 | err = snd_hda_jack_detect_enable(codec, nid, 0); |
| 4377 | if (err < 0) |
| 4378 | return err; |
| 4379 | } |
| 4380 | |
| 4381 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); |
| 4382 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | return err; |
| 4384 | |
| 4385 | return 0; |
| 4386 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4387 | EXPORT_SYMBOL_HDA(snd_hda_gen_build_controls); |
| 4388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | |
| 4390 | /* |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4391 | * PCM definitions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4394 | static void call_pcm_playback_hook(struct hda_pcm_stream *hinfo, |
| 4395 | struct hda_codec *codec, |
| 4396 | struct snd_pcm_substream *substream, |
| 4397 | int action) |
| 4398 | { |
| 4399 | struct hda_gen_spec *spec = codec->spec; |
| 4400 | if (spec->pcm_playback_hook) |
| 4401 | spec->pcm_playback_hook(hinfo, codec, substream, action); |
| 4402 | } |
| 4403 | |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4404 | static void call_pcm_capture_hook(struct hda_pcm_stream *hinfo, |
| 4405 | struct hda_codec *codec, |
| 4406 | struct snd_pcm_substream *substream, |
| 4407 | int action) |
| 4408 | { |
| 4409 | struct hda_gen_spec *spec = codec->spec; |
| 4410 | if (spec->pcm_capture_hook) |
| 4411 | spec->pcm_capture_hook(hinfo, codec, substream, action); |
| 4412 | } |
| 4413 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4414 | /* |
| 4415 | * Analog playback callbacks |
| 4416 | */ |
| 4417 | static int playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 4418 | struct hda_codec *codec, |
| 4419 | struct snd_pcm_substream *substream) |
| 4420 | { |
| 4421 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4422 | int err; |
| 4423 | |
| 4424 | mutex_lock(&spec->pcm_mutex); |
| 4425 | err = snd_hda_multi_out_analog_open(codec, |
| 4426 | &spec->multiout, substream, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4427 | hinfo); |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4428 | if (!err) { |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4429 | spec->active_streams |= 1 << STREAM_MULTI_OUT; |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4430 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4431 | HDA_GEN_PCM_ACT_OPEN); |
| 4432 | } |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4433 | mutex_unlock(&spec->pcm_mutex); |
| 4434 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | static int playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4438 | struct hda_codec *codec, |
| 4439 | unsigned int stream_tag, |
| 4440 | unsigned int format, |
| 4441 | struct snd_pcm_substream *substream) |
| 4442 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4443 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4444 | int err; |
| 4445 | |
| 4446 | err = snd_hda_multi_out_analog_prepare(codec, &spec->multiout, |
| 4447 | stream_tag, format, substream); |
| 4448 | if (!err) |
| 4449 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4450 | HDA_GEN_PCM_ACT_PREPARE); |
| 4451 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4452 | } |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4453 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4454 | static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 4455 | struct hda_codec *codec, |
| 4456 | struct snd_pcm_substream *substream) |
| 4457 | { |
| 4458 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4459 | int err; |
| 4460 | |
| 4461 | err = snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
| 4462 | if (!err) |
| 4463 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4464 | HDA_GEN_PCM_ACT_CLEANUP); |
| 4465 | return err; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4466 | } |
| 4467 | |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4468 | static int playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 4469 | struct hda_codec *codec, |
| 4470 | struct snd_pcm_substream *substream) |
| 4471 | { |
| 4472 | struct hda_gen_spec *spec = codec->spec; |
| 4473 | mutex_lock(&spec->pcm_mutex); |
| 4474 | spec->active_streams &= ~(1 << STREAM_MULTI_OUT); |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4475 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4476 | HDA_GEN_PCM_ACT_CLOSE); |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4477 | mutex_unlock(&spec->pcm_mutex); |
| 4478 | return 0; |
| 4479 | } |
| 4480 | |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4481 | static int capture_pcm_open(struct hda_pcm_stream *hinfo, |
| 4482 | struct hda_codec *codec, |
| 4483 | struct snd_pcm_substream *substream) |
| 4484 | { |
| 4485 | call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_OPEN); |
| 4486 | return 0; |
| 4487 | } |
| 4488 | |
| 4489 | static int capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 4490 | struct hda_codec *codec, |
| 4491 | unsigned int stream_tag, |
| 4492 | unsigned int format, |
| 4493 | struct snd_pcm_substream *substream) |
| 4494 | { |
| 4495 | snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); |
| 4496 | call_pcm_capture_hook(hinfo, codec, substream, |
| 4497 | HDA_GEN_PCM_ACT_PREPARE); |
| 4498 | return 0; |
| 4499 | } |
| 4500 | |
| 4501 | static int capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 4502 | struct hda_codec *codec, |
| 4503 | struct snd_pcm_substream *substream) |
| 4504 | { |
| 4505 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); |
| 4506 | call_pcm_capture_hook(hinfo, codec, substream, |
| 4507 | HDA_GEN_PCM_ACT_CLEANUP); |
| 4508 | return 0; |
| 4509 | } |
| 4510 | |
| 4511 | static int capture_pcm_close(struct hda_pcm_stream *hinfo, |
| 4512 | struct hda_codec *codec, |
| 4513 | struct snd_pcm_substream *substream) |
| 4514 | { |
| 4515 | call_pcm_capture_hook(hinfo, codec, substream, HDA_GEN_PCM_ACT_CLOSE); |
| 4516 | return 0; |
| 4517 | } |
| 4518 | |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4519 | static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 4520 | struct hda_codec *codec, |
| 4521 | struct snd_pcm_substream *substream) |
| 4522 | { |
| 4523 | struct hda_gen_spec *spec = codec->spec; |
| 4524 | int err = 0; |
| 4525 | |
| 4526 | mutex_lock(&spec->pcm_mutex); |
| 4527 | if (!spec->indep_hp_enabled) |
| 4528 | err = -EBUSY; |
| 4529 | else |
| 4530 | spec->active_streams |= 1 << STREAM_INDEP_HP; |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4531 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4532 | HDA_GEN_PCM_ACT_OPEN); |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4533 | mutex_unlock(&spec->pcm_mutex); |
| 4534 | return err; |
| 4535 | } |
| 4536 | |
| 4537 | static int alt_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 4538 | struct hda_codec *codec, |
| 4539 | struct snd_pcm_substream *substream) |
| 4540 | { |
| 4541 | struct hda_gen_spec *spec = codec->spec; |
| 4542 | mutex_lock(&spec->pcm_mutex); |
| 4543 | spec->active_streams &= ~(1 << STREAM_INDEP_HP); |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4544 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4545 | HDA_GEN_PCM_ACT_CLOSE); |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4546 | mutex_unlock(&spec->pcm_mutex); |
| 4547 | return 0; |
| 4548 | } |
| 4549 | |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4550 | static int alt_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 4551 | struct hda_codec *codec, |
| 4552 | unsigned int stream_tag, |
| 4553 | unsigned int format, |
| 4554 | struct snd_pcm_substream *substream) |
| 4555 | { |
| 4556 | snd_hda_codec_setup_stream(codec, hinfo->nid, stream_tag, 0, format); |
| 4557 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4558 | HDA_GEN_PCM_ACT_PREPARE); |
| 4559 | return 0; |
| 4560 | } |
| 4561 | |
| 4562 | static int alt_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 4563 | struct hda_codec *codec, |
| 4564 | struct snd_pcm_substream *substream) |
| 4565 | { |
| 4566 | snd_hda_codec_cleanup_stream(codec, hinfo->nid); |
| 4567 | call_pcm_playback_hook(hinfo, codec, substream, |
| 4568 | HDA_GEN_PCM_ACT_CLEANUP); |
| 4569 | return 0; |
| 4570 | } |
| 4571 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4572 | /* |
| 4573 | * Digital out |
| 4574 | */ |
| 4575 | static int dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 4576 | struct hda_codec *codec, |
| 4577 | struct snd_pcm_substream *substream) |
| 4578 | { |
| 4579 | struct hda_gen_spec *spec = codec->spec; |
| 4580 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 4581 | } |
| 4582 | |
| 4583 | static int dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 4584 | struct hda_codec *codec, |
| 4585 | unsigned int stream_tag, |
| 4586 | unsigned int format, |
| 4587 | struct snd_pcm_substream *substream) |
| 4588 | { |
| 4589 | struct hda_gen_spec *spec = codec->spec; |
| 4590 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 4591 | stream_tag, format, substream); |
| 4592 | } |
| 4593 | |
| 4594 | static int dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 4595 | struct hda_codec *codec, |
| 4596 | struct snd_pcm_substream *substream) |
| 4597 | { |
| 4598 | struct hda_gen_spec *spec = codec->spec; |
| 4599 | return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
| 4600 | } |
| 4601 | |
| 4602 | static int dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 4603 | struct hda_codec *codec, |
| 4604 | struct snd_pcm_substream *substream) |
| 4605 | { |
| 4606 | struct hda_gen_spec *spec = codec->spec; |
| 4607 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 4608 | } |
| 4609 | |
| 4610 | /* |
| 4611 | * Analog capture |
| 4612 | */ |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4613 | #define alt_capture_pcm_open capture_pcm_open |
| 4614 | #define alt_capture_pcm_close capture_pcm_close |
| 4615 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4616 | static int alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 4617 | struct hda_codec *codec, |
| 4618 | unsigned int stream_tag, |
| 4619 | unsigned int format, |
| 4620 | struct snd_pcm_substream *substream) |
| 4621 | { |
| 4622 | struct hda_gen_spec *spec = codec->spec; |
| 4623 | |
| 4624 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4625 | stream_tag, 0, format); |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4626 | call_pcm_capture_hook(hinfo, codec, substream, |
| 4627 | HDA_GEN_PCM_ACT_PREPARE); |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4628 | return 0; |
| 4629 | } |
| 4630 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4631 | static int alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 4632 | struct hda_codec *codec, |
| 4633 | struct snd_pcm_substream *substream) |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4634 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4635 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4636 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4637 | snd_hda_codec_cleanup_stream(codec, |
| 4638 | spec->adc_nids[substream->number + 1]); |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4639 | call_pcm_capture_hook(hinfo, codec, substream, |
| 4640 | HDA_GEN_PCM_ACT_CLEANUP); |
Takashi Iwai | 97ec558 | 2006-03-21 11:29:07 +0100 | [diff] [blame] | 4641 | return 0; |
| 4642 | } |
| 4643 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4644 | /* |
| 4645 | */ |
| 4646 | static const struct hda_pcm_stream pcm_analog_playback = { |
| 4647 | .substreams = 1, |
| 4648 | .channels_min = 2, |
| 4649 | .channels_max = 8, |
| 4650 | /* NID is set in build_pcms */ |
| 4651 | .ops = { |
| 4652 | .open = playback_pcm_open, |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4653 | .close = playback_pcm_close, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4654 | .prepare = playback_pcm_prepare, |
| 4655 | .cleanup = playback_pcm_cleanup |
| 4656 | }, |
| 4657 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4659 | static const struct hda_pcm_stream pcm_analog_capture = { |
| 4660 | .substreams = 1, |
| 4661 | .channels_min = 2, |
| 4662 | .channels_max = 2, |
| 4663 | /* NID is set in build_pcms */ |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4664 | .ops = { |
| 4665 | .open = capture_pcm_open, |
| 4666 | .close = capture_pcm_close, |
| 4667 | .prepare = capture_pcm_prepare, |
| 4668 | .cleanup = capture_pcm_cleanup |
| 4669 | }, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4670 | }; |
| 4671 | |
| 4672 | static const struct hda_pcm_stream pcm_analog_alt_playback = { |
| 4673 | .substreams = 1, |
| 4674 | .channels_min = 2, |
| 4675 | .channels_max = 2, |
| 4676 | /* NID is set in build_pcms */ |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4677 | .ops = { |
| 4678 | .open = alt_playback_pcm_open, |
Takashi Iwai | e6b85f3 | 2013-01-07 11:54:34 +0100 | [diff] [blame] | 4679 | .close = alt_playback_pcm_close, |
| 4680 | .prepare = alt_playback_pcm_prepare, |
| 4681 | .cleanup = alt_playback_pcm_cleanup |
Takashi Iwai | 38cf6f1 | 2012-12-21 14:09:42 +0100 | [diff] [blame] | 4682 | }, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4683 | }; |
| 4684 | |
| 4685 | static const struct hda_pcm_stream pcm_analog_alt_capture = { |
| 4686 | .substreams = 2, /* can be overridden */ |
| 4687 | .channels_min = 2, |
| 4688 | .channels_max = 2, |
| 4689 | /* NID is set in build_pcms */ |
| 4690 | .ops = { |
Takashi Iwai | ac2e873 | 2013-01-17 15:57:10 +0100 | [diff] [blame] | 4691 | .open = alt_capture_pcm_open, |
| 4692 | .close = alt_capture_pcm_close, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4693 | .prepare = alt_capture_pcm_prepare, |
| 4694 | .cleanup = alt_capture_pcm_cleanup |
| 4695 | }, |
| 4696 | }; |
| 4697 | |
| 4698 | static const struct hda_pcm_stream pcm_digital_playback = { |
| 4699 | .substreams = 1, |
| 4700 | .channels_min = 2, |
| 4701 | .channels_max = 2, |
| 4702 | /* NID is set in build_pcms */ |
| 4703 | .ops = { |
| 4704 | .open = dig_playback_pcm_open, |
| 4705 | .close = dig_playback_pcm_close, |
| 4706 | .prepare = dig_playback_pcm_prepare, |
| 4707 | .cleanup = dig_playback_pcm_cleanup |
| 4708 | }, |
| 4709 | }; |
| 4710 | |
| 4711 | static const struct hda_pcm_stream pcm_digital_capture = { |
| 4712 | .substreams = 1, |
| 4713 | .channels_min = 2, |
| 4714 | .channels_max = 2, |
| 4715 | /* NID is set in build_pcms */ |
| 4716 | }; |
| 4717 | |
| 4718 | /* Used by build_pcms to flag that a PCM has no playback stream */ |
| 4719 | static const struct hda_pcm_stream pcm_null_stream = { |
| 4720 | .substreams = 0, |
| 4721 | .channels_min = 0, |
| 4722 | .channels_max = 0, |
| 4723 | }; |
| 4724 | |
| 4725 | /* |
| 4726 | * dynamic changing ADC PCM streams |
| 4727 | */ |
| 4728 | static bool dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) |
| 4729 | { |
| 4730 | struct hda_gen_spec *spec = codec->spec; |
| 4731 | hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]]; |
| 4732 | |
| 4733 | if (spec->cur_adc && spec->cur_adc != new_adc) { |
| 4734 | /* stream is running, let's swap the current ADC */ |
| 4735 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 4736 | spec->cur_adc = new_adc; |
| 4737 | snd_hda_codec_setup_stream(codec, new_adc, |
| 4738 | spec->cur_adc_stream_tag, 0, |
| 4739 | spec->cur_adc_format); |
| 4740 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4741 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4742 | return false; |
| 4743 | } |
| 4744 | |
| 4745 | /* analog capture with dynamic dual-adc changes */ |
| 4746 | static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 4747 | struct hda_codec *codec, |
| 4748 | unsigned int stream_tag, |
| 4749 | unsigned int format, |
| 4750 | struct snd_pcm_substream *substream) |
| 4751 | { |
| 4752 | struct hda_gen_spec *spec = codec->spec; |
| 4753 | spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]]; |
| 4754 | spec->cur_adc_stream_tag = stream_tag; |
| 4755 | spec->cur_adc_format = format; |
| 4756 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
| 4757 | return 0; |
| 4758 | } |
| 4759 | |
| 4760 | static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 4761 | struct hda_codec *codec, |
| 4762 | struct snd_pcm_substream *substream) |
| 4763 | { |
| 4764 | struct hda_gen_spec *spec = codec->spec; |
| 4765 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 4766 | spec->cur_adc = 0; |
| 4767 | return 0; |
| 4768 | } |
| 4769 | |
| 4770 | static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = { |
| 4771 | .substreams = 1, |
| 4772 | .channels_min = 2, |
| 4773 | .channels_max = 2, |
| 4774 | .nid = 0, /* fill later */ |
| 4775 | .ops = { |
| 4776 | .prepare = dyn_adc_capture_pcm_prepare, |
| 4777 | .cleanup = dyn_adc_capture_pcm_cleanup |
| 4778 | }, |
| 4779 | }; |
| 4780 | |
Takashi Iwai | f873e53 | 2012-12-20 16:58:39 +0100 | [diff] [blame] | 4781 | static void fill_pcm_stream_name(char *str, size_t len, const char *sfx, |
| 4782 | const char *chip_name) |
| 4783 | { |
| 4784 | char *p; |
| 4785 | |
| 4786 | if (*str) |
| 4787 | return; |
| 4788 | strlcpy(str, chip_name, len); |
| 4789 | |
| 4790 | /* drop non-alnum chars after a space */ |
| 4791 | for (p = strchr(str, ' '); p; p = strchr(p + 1, ' ')) { |
| 4792 | if (!isalnum(p[1])) { |
| 4793 | *p = 0; |
| 4794 | break; |
| 4795 | } |
| 4796 | } |
| 4797 | strlcat(str, sfx, len); |
| 4798 | } |
| 4799 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4800 | /* build PCM streams based on the parsed results */ |
| 4801 | int snd_hda_gen_build_pcms(struct hda_codec *codec) |
| 4802 | { |
| 4803 | struct hda_gen_spec *spec = codec->spec; |
| 4804 | struct hda_pcm *info = spec->pcm_rec; |
| 4805 | const struct hda_pcm_stream *p; |
| 4806 | bool have_multi_adcs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | |
| 4808 | codec->num_pcms = 1; |
| 4809 | codec->pcm_info = info; |
| 4810 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4811 | if (spec->no_analog) |
| 4812 | goto skip_analog; |
| 4813 | |
Takashi Iwai | f873e53 | 2012-12-20 16:58:39 +0100 | [diff] [blame] | 4814 | fill_pcm_stream_name(spec->stream_name_analog, |
| 4815 | sizeof(spec->stream_name_analog), |
| 4816 | " Analog", codec->chip_name); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4817 | info->name = spec->stream_name_analog; |
| 4818 | |
| 4819 | if (spec->multiout.num_dacs > 0) { |
| 4820 | p = spec->stream_analog_playback; |
| 4821 | if (!p) |
| 4822 | p = &pcm_analog_playback; |
| 4823 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
| 4824 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; |
| 4825 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 4826 | spec->multiout.max_channels; |
| 4827 | if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 4828 | spec->autocfg.line_outs == 2) |
| 4829 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap = |
| 4830 | snd_pcm_2_1_chmaps; |
| 4831 | } |
| 4832 | if (spec->num_adc_nids) { |
| 4833 | p = spec->stream_analog_capture; |
| 4834 | if (!p) { |
| 4835 | if (spec->dyn_adc_switch) |
| 4836 | p = &dyn_adc_pcm_analog_capture; |
| 4837 | else |
| 4838 | p = &pcm_analog_capture; |
| 4839 | } |
| 4840 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
| 4841 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 4842 | } |
| 4843 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4844 | skip_analog: |
| 4845 | /* SPDIF for stream index #1 */ |
| 4846 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
Takashi Iwai | f873e53 | 2012-12-20 16:58:39 +0100 | [diff] [blame] | 4847 | fill_pcm_stream_name(spec->stream_name_digital, |
| 4848 | sizeof(spec->stream_name_digital), |
| 4849 | " Digital", codec->chip_name); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4850 | codec->num_pcms = 2; |
| 4851 | codec->slave_dig_outs = spec->multiout.slave_dig_outs; |
| 4852 | info = spec->pcm_rec + 1; |
| 4853 | info->name = spec->stream_name_digital; |
| 4854 | if (spec->dig_out_type) |
| 4855 | info->pcm_type = spec->dig_out_type; |
| 4856 | else |
| 4857 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
| 4858 | if (spec->multiout.dig_out_nid) { |
| 4859 | p = spec->stream_digital_playback; |
| 4860 | if (!p) |
| 4861 | p = &pcm_digital_playback; |
| 4862 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
| 4863 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; |
| 4864 | } |
| 4865 | if (spec->dig_in_nid) { |
| 4866 | p = spec->stream_digital_capture; |
| 4867 | if (!p) |
| 4868 | p = &pcm_digital_capture; |
| 4869 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
| 4870 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; |
| 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | if (spec->no_analog) |
| 4875 | return 0; |
| 4876 | |
| 4877 | /* If the use of more than one ADC is requested for the current |
| 4878 | * model, configure a second analog capture-only PCM. |
| 4879 | */ |
| 4880 | have_multi_adcs = (spec->num_adc_nids > 1) && |
| 4881 | !spec->dyn_adc_switch && !spec->auto_mic; |
| 4882 | /* Additional Analaog capture for index #2 */ |
| 4883 | if (spec->alt_dac_nid || have_multi_adcs) { |
Takashi Iwai | a607148 | 2013-01-21 16:50:09 +0100 | [diff] [blame] | 4884 | fill_pcm_stream_name(spec->stream_name_alt_analog, |
| 4885 | sizeof(spec->stream_name_alt_analog), |
| 4886 | " Alt Analog", codec->chip_name); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4887 | codec->num_pcms = 3; |
| 4888 | info = spec->pcm_rec + 2; |
Takashi Iwai | a607148 | 2013-01-21 16:50:09 +0100 | [diff] [blame] | 4889 | info->name = spec->stream_name_alt_analog; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4890 | if (spec->alt_dac_nid) { |
| 4891 | p = spec->stream_analog_alt_playback; |
| 4892 | if (!p) |
| 4893 | p = &pcm_analog_alt_playback; |
| 4894 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; |
| 4895 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 4896 | spec->alt_dac_nid; |
| 4897 | } else { |
| 4898 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 4899 | pcm_null_stream; |
| 4900 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; |
| 4901 | } |
| 4902 | if (have_multi_adcs) { |
| 4903 | p = spec->stream_analog_alt_capture; |
| 4904 | if (!p) |
| 4905 | p = &pcm_analog_alt_capture; |
| 4906 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; |
| 4907 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 4908 | spec->adc_nids[1]; |
| 4909 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 4910 | spec->num_adc_nids - 1; |
| 4911 | } else { |
| 4912 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 4913 | pcm_null_stream; |
| 4914 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0; |
| 4915 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
| 4918 | return 0; |
| 4919 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4920 | EXPORT_SYMBOL_HDA(snd_hda_gen_build_pcms); |
| 4921 | |
| 4922 | |
| 4923 | /* |
| 4924 | * Standard auto-parser initializations |
| 4925 | */ |
| 4926 | |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 4927 | /* configure the given path as a proper output */ |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4928 | static void set_output_and_unmute(struct hda_codec *codec, int path_idx) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4929 | { |
| 4930 | struct nid_path *path; |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 4931 | hda_nid_t pin; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4932 | |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 4933 | path = snd_hda_get_path_from_idx(codec, path_idx); |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 4934 | if (!path || !path->depth) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4935 | return; |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 4936 | pin = path->path[path->depth - 1]; |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4937 | restore_pin_ctl(codec, pin); |
Takashi Iwai | e1284af | 2013-01-03 16:33:02 +0100 | [diff] [blame] | 4938 | snd_hda_activate_path(codec, path, path->active, true); |
| 4939 | set_pin_eapd(codec, pin, path->active); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | /* initialize primary output paths */ |
| 4943 | static void init_multi_out(struct hda_codec *codec) |
| 4944 | { |
| 4945 | struct hda_gen_spec *spec = codec->spec; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4946 | int i; |
| 4947 | |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 4948 | for (i = 0; i < spec->autocfg.line_outs; i++) |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4949 | set_output_and_unmute(codec, spec->out_paths[i]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4950 | } |
| 4951 | |
Takashi Iwai | db23fd1 | 2012-12-20 15:27:24 +0100 | [diff] [blame] | 4952 | |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4953 | static void __init_extra_out(struct hda_codec *codec, int num_outs, int *paths) |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4954 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4955 | int i; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4956 | |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 4957 | for (i = 0; i < num_outs; i++) |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4958 | set_output_and_unmute(codec, paths[i]); |
Takashi Iwai | db23fd1 | 2012-12-20 15:27:24 +0100 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | /* initialize hp and speaker paths */ |
| 4962 | static void init_extra_out(struct hda_codec *codec) |
| 4963 | { |
| 4964 | struct hda_gen_spec *spec = codec->spec; |
| 4965 | |
| 4966 | if (spec->autocfg.line_out_type != AUTO_PIN_HP_OUT) |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4967 | __init_extra_out(codec, spec->autocfg.hp_outs, spec->hp_paths); |
Takashi Iwai | db23fd1 | 2012-12-20 15:27:24 +0100 | [diff] [blame] | 4968 | if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT) |
| 4969 | __init_extra_out(codec, spec->autocfg.speaker_outs, |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4970 | spec->speaker_paths); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | /* initialize multi-io paths */ |
| 4974 | static void init_multi_io(struct hda_codec *codec) |
| 4975 | { |
| 4976 | struct hda_gen_spec *spec = codec->spec; |
| 4977 | int i; |
| 4978 | |
| 4979 | for (i = 0; i < spec->multi_ios; i++) { |
| 4980 | hda_nid_t pin = spec->multi_io[i].pin; |
| 4981 | struct nid_path *path; |
Takashi Iwai | 196c1766 | 2013-01-04 15:01:40 +0100 | [diff] [blame] | 4982 | path = get_multiio_path(codec, i); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4983 | if (!path) |
| 4984 | continue; |
| 4985 | if (!spec->multi_io[i].ctl_in) |
| 4986 | spec->multi_io[i].ctl_in = |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 4987 | snd_hda_codec_get_pin_target(codec, pin); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4988 | snd_hda_activate_path(codec, path, path->active, true); |
| 4989 | } |
| 4990 | } |
| 4991 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 4992 | /* set up input pins and loopback paths */ |
| 4993 | static void init_analog_input(struct hda_codec *codec) |
| 4994 | { |
| 4995 | struct hda_gen_spec *spec = codec->spec; |
| 4996 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 4997 | int i; |
| 4998 | |
| 4999 | for (i = 0; i < cfg->num_inputs; i++) { |
| 5000 | hda_nid_t nid = cfg->inputs[i].pin; |
| 5001 | if (is_input_pin(codec, nid)) |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 5002 | restore_pin_ctl(codec, nid); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5003 | |
| 5004 | /* init loopback inputs */ |
| 5005 | if (spec->mixer_nid) { |
Takashi Iwai | 3e367f1 | 2013-01-23 17:07:23 +0100 | [diff] [blame] | 5006 | resume_path_from_idx(codec, spec->loopback_paths[i]); |
| 5007 | resume_path_from_idx(codec, spec->loopback_merge_path); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5008 | } |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | /* initialize ADC paths */ |
| 5013 | static void init_input_src(struct hda_codec *codec) |
| 5014 | { |
| 5015 | struct hda_gen_spec *spec = codec->spec; |
| 5016 | struct hda_input_mux *imux = &spec->input_mux; |
| 5017 | struct nid_path *path; |
| 5018 | int i, c, nums; |
| 5019 | |
| 5020 | if (spec->dyn_adc_switch) |
| 5021 | nums = 1; |
| 5022 | else |
| 5023 | nums = spec->num_adc_nids; |
| 5024 | |
| 5025 | for (c = 0; c < nums; c++) { |
| 5026 | for (i = 0; i < imux->num_items; i++) { |
Takashi Iwai | c697b71 | 2013-01-07 17:09:26 +0100 | [diff] [blame] | 5027 | path = get_input_path(codec, c, i); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5028 | if (path) { |
| 5029 | bool active = path->active; |
| 5030 | if (i == spec->cur_mux[c]) |
| 5031 | active = true; |
| 5032 | snd_hda_activate_path(codec, path, active, false); |
| 5033 | } |
| 5034 | } |
Takashi Iwai | 967303d | 2013-02-19 17:12:42 +0100 | [diff] [blame] | 5035 | if (spec->hp_mic) |
| 5036 | update_hp_mic(codec, c, true); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5037 | } |
| 5038 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5039 | if (spec->cap_sync_hook) |
Takashi Iwai | a90229e | 2013-01-18 14:10:00 +0100 | [diff] [blame] | 5040 | spec->cap_sync_hook(codec, NULL); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5041 | } |
| 5042 | |
| 5043 | /* set right pin controls for digital I/O */ |
| 5044 | static void init_digital(struct hda_codec *codec) |
| 5045 | { |
| 5046 | struct hda_gen_spec *spec = codec->spec; |
| 5047 | int i; |
| 5048 | hda_nid_t pin; |
| 5049 | |
Takashi Iwai | d415693 | 2013-01-07 10:08:02 +0100 | [diff] [blame] | 5050 | for (i = 0; i < spec->autocfg.dig_outs; i++) |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 5051 | set_output_and_unmute(codec, spec->digout_paths[i]); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5052 | pin = spec->autocfg.dig_in_pin; |
Takashi Iwai | 2430d7b | 2013-01-04 15:09:42 +0100 | [diff] [blame] | 5053 | if (pin) { |
Takashi Iwai | 2c12c30 | 2013-01-10 09:33:29 +0100 | [diff] [blame] | 5054 | restore_pin_ctl(codec, pin); |
Takashi Iwai | 3e367f1 | 2013-01-23 17:07:23 +0100 | [diff] [blame] | 5055 | resume_path_from_idx(codec, spec->digin_path); |
Takashi Iwai | 2430d7b | 2013-01-04 15:09:42 +0100 | [diff] [blame] | 5056 | } |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5057 | } |
| 5058 | |
Takashi Iwai | 973e497 | 2012-12-20 15:16:09 +0100 | [diff] [blame] | 5059 | /* clear unsol-event tags on unused pins; Conexant codecs seem to leave |
| 5060 | * invalid unsol tags by some reason |
| 5061 | */ |
| 5062 | static void clear_unsol_on_unused_pins(struct hda_codec *codec) |
| 5063 | { |
| 5064 | int i; |
| 5065 | |
| 5066 | for (i = 0; i < codec->init_pins.used; i++) { |
| 5067 | struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); |
| 5068 | hda_nid_t nid = pin->nid; |
| 5069 | if (is_jack_detectable(codec, nid) && |
| 5070 | !snd_hda_jack_tbl_get(codec, nid)) |
| 5071 | snd_hda_codec_update_cache(codec, nid, 0, |
| 5072 | AC_VERB_SET_UNSOLICITED_ENABLE, 0); |
| 5073 | } |
| 5074 | } |
| 5075 | |
Takashi Iwai | 5187ac1 | 2013-01-07 12:52:16 +0100 | [diff] [blame] | 5076 | /* |
| 5077 | * initialize the generic spec; |
| 5078 | * this can be put as patch_ops.init function |
| 5079 | */ |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5080 | int snd_hda_gen_init(struct hda_codec *codec) |
| 5081 | { |
| 5082 | struct hda_gen_spec *spec = codec->spec; |
| 5083 | |
| 5084 | if (spec->init_hook) |
| 5085 | spec->init_hook(codec); |
| 5086 | |
| 5087 | snd_hda_apply_verbs(codec); |
| 5088 | |
Takashi Iwai | 3bbcd27 | 2012-12-20 11:50:58 +0100 | [diff] [blame] | 5089 | codec->cached_write = 1; |
| 5090 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5091 | init_multi_out(codec); |
| 5092 | init_extra_out(codec); |
| 5093 | init_multi_io(codec); |
| 5094 | init_analog_input(codec); |
| 5095 | init_input_src(codec); |
| 5096 | init_digital(codec); |
| 5097 | |
Takashi Iwai | 973e497 | 2012-12-20 15:16:09 +0100 | [diff] [blame] | 5098 | clear_unsol_on_unused_pins(codec); |
| 5099 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5100 | /* call init functions of standard auto-mute helpers */ |
Takashi Iwai | a5cc250 | 2013-01-16 18:08:55 +0100 | [diff] [blame] | 5101 | update_automute_all(codec); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5102 | |
Takashi Iwai | dc870f3 | 2013-01-22 15:24:30 +0100 | [diff] [blame] | 5103 | snd_hda_codec_flush_cache(codec); |
Takashi Iwai | 3bbcd27 | 2012-12-20 11:50:58 +0100 | [diff] [blame] | 5104 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5105 | if (spec->vmaster_mute.sw_kctl && spec->vmaster_mute.hook) |
| 5106 | snd_hda_sync_vmaster_hook(&spec->vmaster_mute); |
| 5107 | |
| 5108 | hda_call_check_power_status(codec, 0x01); |
| 5109 | return 0; |
| 5110 | } |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5111 | EXPORT_SYMBOL_HDA(snd_hda_gen_init); |
| 5112 | |
Takashi Iwai | 5187ac1 | 2013-01-07 12:52:16 +0100 | [diff] [blame] | 5113 | /* |
| 5114 | * free the generic spec; |
| 5115 | * this can be put as patch_ops.free function |
| 5116 | */ |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5117 | void snd_hda_gen_free(struct hda_codec *codec) |
| 5118 | { |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 5119 | snd_hda_detach_beep_device(codec); |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5120 | snd_hda_gen_spec_free(codec->spec); |
| 5121 | kfree(codec->spec); |
| 5122 | codec->spec = NULL; |
| 5123 | } |
| 5124 | EXPORT_SYMBOL_HDA(snd_hda_gen_free); |
| 5125 | |
| 5126 | #ifdef CONFIG_PM |
Takashi Iwai | 5187ac1 | 2013-01-07 12:52:16 +0100 | [diff] [blame] | 5127 | /* |
| 5128 | * check the loopback power save state; |
| 5129 | * this can be put as patch_ops.check_power_status function |
| 5130 | */ |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5131 | int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 5132 | { |
| 5133 | struct hda_gen_spec *spec = codec->spec; |
| 5134 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 5135 | } |
| 5136 | EXPORT_SYMBOL_HDA(snd_hda_gen_check_power_status); |
| 5137 | #endif |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5138 | |
| 5139 | |
| 5140 | /* |
| 5141 | * the generic codec support |
| 5142 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5144 | static const struct hda_codec_ops generic_patch_ops = { |
| 5145 | .build_controls = snd_hda_gen_build_controls, |
| 5146 | .build_pcms = snd_hda_gen_build_pcms, |
| 5147 | .init = snd_hda_gen_init, |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5148 | .free = snd_hda_gen_free, |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5149 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 5150 | #ifdef CONFIG_PM |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5151 | .check_power_status = snd_hda_gen_check_power_status, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 5152 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5153 | }; |
| 5154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | int snd_hda_parse_generic_codec(struct hda_codec *codec) |
| 5156 | { |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5157 | struct hda_gen_spec *spec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | int err; |
| 5159 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 5160 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5161 | if (!spec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | return -ENOMEM; |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5163 | snd_hda_gen_spec_init(spec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | codec->spec = spec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | |
Takashi Iwai | 9eb413e | 2012-12-19 14:41:21 +0100 | [diff] [blame] | 5166 | err = snd_hda_parse_pin_defcfg(codec, &spec->autocfg, NULL, 0); |
| 5167 | if (err < 0) |
| 5168 | return err; |
| 5169 | |
| 5170 | err = snd_hda_gen_parse_auto_config(codec, &spec->autocfg); |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5171 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | goto error; |
| 5173 | |
| 5174 | codec->patch_ops = generic_patch_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | return 0; |
| 5176 | |
Takashi Iwai | 352f7f9 | 2012-12-19 12:52:06 +0100 | [diff] [blame] | 5177 | error: |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5178 | snd_hda_gen_free(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | return err; |
| 5180 | } |
Takashi Iwai | fce52a3 | 2013-01-07 12:42:48 +0100 | [diff] [blame] | 5181 | EXPORT_SYMBOL_HDA(snd_hda_parse_generic_codec); |