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