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