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