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