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