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