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