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