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