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