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