Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 2 | * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984, |
| 3 | * AD1986A, AD1988 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Takashi Iwai | 2bac647 | 2007-05-18 18:21:41 +0200 | [diff] [blame] | 5 | * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This driver is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This driver is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include "hda_codec.h" |
| 28 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 29 | #include "hda_auto_parser.h" |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 30 | #include "hda_beep.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 31 | #include "hda_jack.h" |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 32 | #include "hda_generic.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 34 | |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 35 | struct ad198x_spec { |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 36 | struct hda_gen_spec gen; |
| 37 | |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 38 | /* for auto parser */ |
| 39 | int smux_paths[4]; |
| 40 | unsigned int cur_smux; |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 41 | hda_nid_t eapd_nid; |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 42 | |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 43 | unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
Takashi Iwai | 2134ea4 | 2008-01-10 16:53:55 +0100 | [diff] [blame] | 46 | |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 47 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 48 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | 498f5b1 | 2011-05-02 11:33:15 +0200 | [diff] [blame] | 49 | static const struct snd_kcontrol_new ad_beep_mixer[] = { |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 50 | HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT), |
Jaroslav Kysela | 123c07a | 2009-10-21 14:48:23 +0200 | [diff] [blame] | 51 | HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT), |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 52 | { } /* end */ |
| 53 | }; |
| 54 | |
| 55 | #define set_beep_amp(spec, nid, idx, dir) \ |
| 56 | ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */ |
Takashi Iwai | 67d634c | 2009-11-16 15:35:59 +0100 | [diff] [blame] | 57 | #else |
| 58 | #define set_beep_amp(spec, nid, idx, dir) /* NOP */ |
| 59 | #endif |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 60 | |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 61 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
| 62 | static int create_beep_ctls(struct hda_codec *codec) |
| 63 | { |
| 64 | struct ad198x_spec *spec = codec->spec; |
| 65 | const struct snd_kcontrol_new *knew; |
| 66 | |
| 67 | if (!spec->beep_amp) |
| 68 | return 0; |
| 69 | |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 70 | for (knew = ad_beep_mixer ; knew->name; knew++) { |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 71 | int err; |
| 72 | struct snd_kcontrol *kctl; |
| 73 | kctl = snd_ctl_new1(knew, codec); |
| 74 | if (!kctl) |
| 75 | return -ENOMEM; |
| 76 | kctl->private_value = spec->beep_amp; |
| 77 | err = snd_hda_ctl_add(codec, 0, kctl); |
| 78 | if (err < 0) |
| 79 | return err; |
| 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | #else |
| 84 | #define create_beep_ctls(codec) 0 |
| 85 | #endif |
| 86 | |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 87 | |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 88 | static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front, |
| 89 | hda_nid_t hp) |
| 90 | { |
Raymond Yau | a01ef05 | 2011-06-01 15:09:48 +0800 | [diff] [blame] | 91 | if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD) |
| 92 | snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE, |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 93 | !codec->inv_eapd ? 0x00 : 0x02); |
Raymond Yau | a01ef05 | 2011-06-01 15:09:48 +0800 | [diff] [blame] | 94 | if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD) |
| 95 | snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE, |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 96 | !codec->inv_eapd ? 0x00 : 0x02); |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void ad198x_power_eapd(struct hda_codec *codec) |
| 100 | { |
| 101 | /* We currently only handle front, HP */ |
| 102 | switch (codec->vendor_id) { |
| 103 | case 0x11d41882: |
| 104 | case 0x11d4882a: |
| 105 | case 0x11d41884: |
| 106 | case 0x11d41984: |
| 107 | case 0x11d41883: |
| 108 | case 0x11d4184a: |
| 109 | case 0x11d4194a: |
| 110 | case 0x11d4194b: |
Takashi Iwai | 4dffbe0 | 2011-06-03 10:05:02 +0200 | [diff] [blame] | 111 | case 0x11d41988: |
| 112 | case 0x11d4198b: |
| 113 | case 0x11d4989a: |
| 114 | case 0x11d4989b: |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 115 | ad198x_power_eapd_write(codec, 0x12, 0x11); |
| 116 | break; |
| 117 | case 0x11d41981: |
| 118 | case 0x11d41983: |
| 119 | ad198x_power_eapd_write(codec, 0x05, 0x06); |
| 120 | break; |
| 121 | case 0x11d41986: |
| 122 | ad198x_power_eapd_write(codec, 0x1b, 0x1a); |
| 123 | break; |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
Takashi Iwai | 0da2692 | 2011-04-26 15:18:33 +0200 | [diff] [blame] | 127 | static void ad198x_shutup(struct hda_codec *codec) |
| 128 | { |
| 129 | snd_hda_shutup_pins(codec); |
| 130 | ad198x_power_eapd(codec); |
| 131 | } |
| 132 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 133 | #ifdef CONFIG_PM |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 134 | static int ad198x_suspend(struct hda_codec *codec) |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 135 | { |
| 136 | ad198x_shutup(codec); |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 137 | return 0; |
| 138 | } |
Daniel T Chen | ea52bf2 | 2009-12-27 18:48:29 -0500 | [diff] [blame] | 139 | #endif |
| 140 | |
Takashi Iwai | f710a9f | 2013-11-13 09:42:56 +0100 | [diff] [blame] | 141 | /* follow EAPD via vmaster hook */ |
| 142 | static void ad_vmaster_eapd_hook(void *private_data, int enabled) |
| 143 | { |
| 144 | struct hda_codec *codec = private_data; |
| 145 | struct ad198x_spec *spec = codec->spec; |
| 146 | |
| 147 | if (!spec->eapd_nid) |
| 148 | return; |
Takashi Iwai | ce8e0fd | 2013-12-02 15:01:35 +0100 | [diff] [blame] | 149 | if (codec->inv_eapd) |
| 150 | enabled = !enabled; |
Takashi Iwai | f710a9f | 2013-11-13 09:42:56 +0100 | [diff] [blame] | 151 | snd_hda_codec_update_cache(codec, spec->eapd_nid, 0, |
| 152 | AC_VERB_SET_EAPD_BTLENABLE, |
| 153 | enabled ? 0x02 : 0x00); |
| 154 | } |
Takashi Iwai | 9230d21 | 2006-03-13 13:49:49 +0100 | [diff] [blame] | 155 | |
Takashi Iwai | 18a815d | 2006-03-01 19:54:39 +0100 | [diff] [blame] | 156 | /* |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 157 | * Automatic parse of I/O pins from the BIOS configuration |
| 158 | */ |
| 159 | |
| 160 | static int ad198x_auto_build_controls(struct hda_codec *codec) |
| 161 | { |
| 162 | int err; |
| 163 | |
| 164 | err = snd_hda_gen_build_controls(codec); |
| 165 | if (err < 0) |
| 166 | return err; |
| 167 | err = create_beep_ctls(codec); |
| 168 | if (err < 0) |
| 169 | return err; |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static const struct hda_codec_ops ad198x_auto_patch_ops = { |
| 174 | .build_controls = ad198x_auto_build_controls, |
| 175 | .build_pcms = snd_hda_gen_build_pcms, |
| 176 | .init = snd_hda_gen_init, |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 177 | .free = snd_hda_gen_free, |
Takashi Iwai | 8a6c21a | 2013-01-18 07:51:17 +0100 | [diff] [blame] | 178 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 179 | #ifdef CONFIG_PM |
| 180 | .check_power_status = snd_hda_gen_check_power_status, |
| 181 | .suspend = ad198x_suspend, |
| 182 | #endif |
| 183 | .reboot_notify = ad198x_shutup, |
| 184 | }; |
| 185 | |
| 186 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 187 | static int ad198x_parse_auto_config(struct hda_codec *codec, bool indep_hp) |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 188 | { |
| 189 | struct ad198x_spec *spec = codec->spec; |
| 190 | struct auto_pin_cfg *cfg = &spec->gen.autocfg; |
| 191 | int err; |
| 192 | |
| 193 | codec->spdif_status_reset = 1; |
| 194 | codec->no_trigger_sense = 1; |
| 195 | codec->no_sticky_stream = 1; |
| 196 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 197 | spec->gen.indep_hp = indep_hp; |
Takashi Iwai | 74f14b3 | 2014-12-15 13:43:59 +0100 | [diff] [blame] | 198 | if (!spec->gen.add_stereo_mix_input) |
| 199 | spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 200 | |
| 201 | err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); |
| 202 | if (err < 0) |
| 203 | return err; |
| 204 | err = snd_hda_gen_parse_auto_config(codec, cfg); |
| 205 | if (err < 0) |
| 206 | return err; |
| 207 | |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 208 | codec->patch_ops = ad198x_auto_patch_ops; |
| 209 | |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | /* |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 214 | * AD1986A specific |
| 215 | */ |
| 216 | |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 217 | static int alloc_ad_spec(struct hda_codec *codec) |
| 218 | { |
| 219 | struct ad198x_spec *spec; |
| 220 | |
| 221 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 222 | if (!spec) |
| 223 | return -ENOMEM; |
| 224 | codec->spec = spec; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 225 | snd_hda_gen_spec_init(&spec->gen); |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 229 | /* |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 230 | * AD1986A fixup codes |
| 231 | */ |
| 232 | |
| 233 | /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */ |
| 234 | static void ad_fixup_inv_jack_detect(struct hda_codec *codec, |
| 235 | const struct hda_fixup *fix, int action) |
| 236 | { |
Takashi Iwai | 7a3e610 | 2013-11-13 09:39:08 +0100 | [diff] [blame] | 237 | struct ad198x_spec *spec = codec->spec; |
| 238 | |
| 239 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 240 | codec->inv_jack_detect = 1; |
Takashi Iwai | 7a3e610 | 2013-11-13 09:39:08 +0100 | [diff] [blame] | 241 | spec->gen.keep_eapd_on = 1; |
Takashi Iwai | f710a9f | 2013-11-13 09:42:56 +0100 | [diff] [blame] | 242 | spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; |
| 243 | spec->eapd_nid = 0x1b; |
Takashi Iwai | 7a3e610 | 2013-11-13 09:39:08 +0100 | [diff] [blame] | 244 | } |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Takashi Iwai | 4528eb1 | 2014-02-04 07:39:06 +0100 | [diff] [blame] | 247 | /* Toshiba Satellite L40 implements EAPD in a standard way unlike others */ |
| 248 | static void ad1986a_fixup_eapd(struct hda_codec *codec, |
| 249 | const struct hda_fixup *fix, int action) |
| 250 | { |
| 251 | struct ad198x_spec *spec = codec->spec; |
| 252 | |
| 253 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 254 | codec->inv_eapd = 0; |
| 255 | spec->gen.keep_eapd_on = 1; |
| 256 | spec->eapd_nid = 0x1b; |
| 257 | } |
| 258 | } |
| 259 | |
Takashi Iwai | 7327643 | 2014-12-15 13:47:25 +0100 | [diff] [blame] | 260 | /* enable stereo-mix input for avoiding regression on KDE (bko#88251) */ |
| 261 | static void ad1986a_fixup_eapd_mix_in(struct hda_codec *codec, |
| 262 | const struct hda_fixup *fix, int action) |
| 263 | { |
| 264 | struct ad198x_spec *spec = codec->spec; |
| 265 | |
| 266 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 267 | ad1986a_fixup_eapd(codec, fix, action); |
| 268 | spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_ENABLE; |
| 269 | } |
| 270 | } |
| 271 | |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 272 | enum { |
| 273 | AD1986A_FIXUP_INV_JACK_DETECT, |
Takashi Iwai | e0b2716 | 2013-07-04 16:50:46 +0200 | [diff] [blame] | 274 | AD1986A_FIXUP_ULTRA, |
Takashi Iwai | f8c0ab1 | 2013-07-04 17:06:04 +0200 | [diff] [blame] | 275 | AD1986A_FIXUP_SAMSUNG, |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 276 | AD1986A_FIXUP_3STACK, |
| 277 | AD1986A_FIXUP_LAPTOP, |
| 278 | AD1986A_FIXUP_LAPTOP_IMIC, |
Takashi Iwai | 4528eb1 | 2014-02-04 07:39:06 +0100 | [diff] [blame] | 279 | AD1986A_FIXUP_EAPD, |
Takashi Iwai | 7327643 | 2014-12-15 13:47:25 +0100 | [diff] [blame] | 280 | AD1986A_FIXUP_EAPD_MIX_IN, |
| 281 | AD1986A_FIXUP_EASYNOTE, |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 282 | }; |
| 283 | |
| 284 | static const struct hda_fixup ad1986a_fixups[] = { |
| 285 | [AD1986A_FIXUP_INV_JACK_DETECT] = { |
| 286 | .type = HDA_FIXUP_FUNC, |
| 287 | .v.func = ad_fixup_inv_jack_detect, |
| 288 | }, |
Takashi Iwai | e0b2716 | 2013-07-04 16:50:46 +0200 | [diff] [blame] | 289 | [AD1986A_FIXUP_ULTRA] = { |
| 290 | .type = HDA_FIXUP_PINS, |
| 291 | .v.pins = (const struct hda_pintbl[]) { |
| 292 | { 0x1b, 0x90170110 }, /* speaker */ |
| 293 | { 0x1d, 0x90a7013e }, /* int mic */ |
| 294 | {} |
| 295 | }, |
| 296 | }, |
Takashi Iwai | f8c0ab1 | 2013-07-04 17:06:04 +0200 | [diff] [blame] | 297 | [AD1986A_FIXUP_SAMSUNG] = { |
| 298 | .type = HDA_FIXUP_PINS, |
| 299 | .v.pins = (const struct hda_pintbl[]) { |
| 300 | { 0x1b, 0x90170110 }, /* speaker */ |
| 301 | { 0x1d, 0x90a7013e }, /* int mic */ |
| 302 | { 0x20, 0x411111f0 }, /* N/A */ |
| 303 | { 0x24, 0x411111f0 }, /* N/A */ |
| 304 | {} |
| 305 | }, |
| 306 | }, |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 307 | [AD1986A_FIXUP_3STACK] = { |
| 308 | .type = HDA_FIXUP_PINS, |
| 309 | .v.pins = (const struct hda_pintbl[]) { |
| 310 | { 0x1a, 0x02214021 }, /* headphone */ |
| 311 | { 0x1b, 0x01014011 }, /* front */ |
Takashi Iwai | ed0e0d0 | 2014-01-07 17:48:11 +0100 | [diff] [blame] | 312 | { 0x1c, 0x01813030 }, /* line-in */ |
| 313 | { 0x1d, 0x01a19020 }, /* rear mic */ |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 314 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 315 | { 0x1f, 0x02a190f0 }, /* mic */ |
Takashi Iwai | ed0e0d0 | 2014-01-07 17:48:11 +0100 | [diff] [blame] | 316 | { 0x20, 0x411111f0 }, /* N/A */ |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 317 | {} |
| 318 | }, |
| 319 | }, |
| 320 | [AD1986A_FIXUP_LAPTOP] = { |
| 321 | .type = HDA_FIXUP_PINS, |
| 322 | .v.pins = (const struct hda_pintbl[]) { |
| 323 | { 0x1a, 0x02214021 }, /* headphone */ |
| 324 | { 0x1b, 0x90170110 }, /* speaker */ |
| 325 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 326 | { 0x1d, 0x411111f0 }, /* N/A */ |
| 327 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 328 | { 0x1f, 0x02a191f0 }, /* mic */ |
| 329 | { 0x20, 0x411111f0 }, /* N/A */ |
| 330 | {} |
| 331 | }, |
| 332 | }, |
| 333 | [AD1986A_FIXUP_LAPTOP_IMIC] = { |
| 334 | .type = HDA_FIXUP_PINS, |
| 335 | .v.pins = (const struct hda_pintbl[]) { |
| 336 | { 0x1d, 0x90a7013e }, /* int mic */ |
| 337 | {} |
| 338 | }, |
| 339 | .chained_before = 1, |
| 340 | .chain_id = AD1986A_FIXUP_LAPTOP, |
| 341 | }, |
Takashi Iwai | 4528eb1 | 2014-02-04 07:39:06 +0100 | [diff] [blame] | 342 | [AD1986A_FIXUP_EAPD] = { |
| 343 | .type = HDA_FIXUP_FUNC, |
| 344 | .v.func = ad1986a_fixup_eapd, |
| 345 | }, |
Takashi Iwai | 7327643 | 2014-12-15 13:47:25 +0100 | [diff] [blame] | 346 | [AD1986A_FIXUP_EAPD_MIX_IN] = { |
| 347 | .type = HDA_FIXUP_FUNC, |
| 348 | .v.func = ad1986a_fixup_eapd_mix_in, |
| 349 | }, |
| 350 | [AD1986A_FIXUP_EASYNOTE] = { |
| 351 | .type = HDA_FIXUP_PINS, |
| 352 | .v.pins = (const struct hda_pintbl[]) { |
| 353 | { 0x1a, 0x0421402f }, /* headphone */ |
| 354 | { 0x1b, 0x90170110 }, /* speaker */ |
| 355 | { 0x1c, 0x411111f0 }, /* N/A */ |
| 356 | { 0x1d, 0x90a70130 }, /* int mic */ |
| 357 | { 0x1e, 0x411111f0 }, /* N/A */ |
| 358 | { 0x1f, 0x04a19040 }, /* mic */ |
| 359 | { 0x20, 0x411111f0 }, /* N/A */ |
| 360 | { 0x21, 0x411111f0 }, /* N/A */ |
| 361 | { 0x22, 0x411111f0 }, /* N/A */ |
| 362 | { 0x23, 0x411111f0 }, /* N/A */ |
| 363 | { 0x24, 0x411111f0 }, /* N/A */ |
| 364 | { 0x25, 0x411111f0 }, /* N/A */ |
| 365 | {} |
| 366 | }, |
| 367 | .chained = true, |
| 368 | .chain_id = AD1986A_FIXUP_EAPD_MIX_IN, |
| 369 | }, |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | static const struct snd_pci_quirk ad1986a_fixup_tbl[] = { |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 373 | SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_FIXUP_LAPTOP_IMIC), |
Takashi Iwai | f62f5ef | 2014-12-09 19:58:53 +0100 | [diff] [blame] | 374 | SND_PCI_QUIRK(0x1043, 0x1443, "ASUS Z99He", AD1986A_FIXUP_EAPD), |
Takashi Iwai | 598e306 | 2014-05-23 09:21:06 +0200 | [diff] [blame] | 375 | SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8JN", AD1986A_FIXUP_EAPD), |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 376 | SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8100, "ASUS P5", AD1986A_FIXUP_3STACK), |
| 377 | SND_PCI_QUIRK_MASK(0x1043, 0xff00, 0x8200, "ASUS M2", AD1986A_FIXUP_3STACK), |
| 378 | SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_FIXUP_3STACK), |
Takashi Iwai | 4528eb1 | 2014-02-04 07:39:06 +0100 | [diff] [blame] | 379 | SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40", AD1986A_FIXUP_EAPD), |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 380 | SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_FIXUP_LAPTOP), |
Takashi Iwai | f8c0ab1 | 2013-07-04 17:06:04 +0200 | [diff] [blame] | 381 | SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_FIXUP_SAMSUNG), |
Takashi Iwai | e0b2716 | 2013-07-04 16:50:46 +0200 | [diff] [blame] | 382 | SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_FIXUP_ULTRA), |
Takashi Iwai | 7327643 | 2014-12-15 13:47:25 +0100 | [diff] [blame] | 383 | SND_PCI_QUIRK(0x1631, 0xc022, "PackardBell EasyNote MX65", AD1986A_FIXUP_EASYNOTE), |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 384 | SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_FIXUP_INV_JACK_DETECT), |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 385 | SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_FIXUP_3STACK), |
| 386 | SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_FIXUP_3STACK), |
| 387 | {} |
| 388 | }; |
| 389 | |
| 390 | static const struct hda_model_fixup ad1986a_fixup_models[] = { |
| 391 | { .id = AD1986A_FIXUP_3STACK, .name = "3stack" }, |
| 392 | { .id = AD1986A_FIXUP_LAPTOP, .name = "laptop" }, |
| 393 | { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-imic" }, |
| 394 | { .id = AD1986A_FIXUP_LAPTOP_IMIC, .name = "laptop-eapd" }, /* alias */ |
Takashi Iwai | 9faa73f | 2014-12-10 13:58:37 +0100 | [diff] [blame] | 395 | { .id = AD1986A_FIXUP_EAPD, .name = "eapd" }, |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 396 | {} |
| 397 | }; |
| 398 | |
| 399 | /* |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 400 | */ |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 401 | static int patch_ad1986a(struct hda_codec *codec) |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 402 | { |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 403 | int err; |
| 404 | struct ad198x_spec *spec; |
Takashi Iwai | 3690739 | 2013-12-10 17:29:26 +0100 | [diff] [blame] | 405 | static hda_nid_t preferred_pairs[] = { |
| 406 | 0x1a, 0x03, |
| 407 | 0x1b, 0x03, |
| 408 | 0x1c, 0x04, |
| 409 | 0x1d, 0x05, |
| 410 | 0x1e, 0x03, |
| 411 | 0 |
| 412 | }; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 413 | |
| 414 | err = alloc_ad_spec(codec); |
| 415 | if (err < 0) |
| 416 | return err; |
| 417 | spec = codec->spec; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 418 | |
| 419 | /* AD1986A has the inverted EAPD implementation */ |
| 420 | codec->inv_eapd = 1; |
| 421 | |
Takashi Iwai | f2f8be4 | 2013-01-21 16:40:16 +0100 | [diff] [blame] | 422 | spec->gen.mixer_nid = 0x07; |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 423 | spec->gen.beep_nid = 0x19; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 424 | set_beep_amp(spec, 0x18, 0, HDA_OUTPUT); |
| 425 | |
| 426 | /* AD1986A has a hardware problem that it can't share a stream |
| 427 | * with multiple output pins. The copy of front to surrounds |
| 428 | * causes noisy or silent outputs at a certain timing, e.g. |
| 429 | * changing the volume. |
| 430 | * So, let's disable the shared stream. |
| 431 | */ |
| 432 | spec->gen.multiout.no_share_stream = 1; |
Takashi Iwai | 3690739 | 2013-12-10 17:29:26 +0100 | [diff] [blame] | 433 | /* give fixed DAC/pin pairs */ |
| 434 | spec->gen.preferred_dacs = preferred_pairs; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 435 | |
Takashi Iwai | b3bd4fc | 2013-12-02 15:04:03 +0100 | [diff] [blame] | 436 | /* AD1986A can't manage the dynamic pin on/off smoothly */ |
| 437 | spec->gen.auto_mute_via_amp = 1; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 438 | |
Takashi Iwai | 632408a | 2013-07-05 14:14:14 +0200 | [diff] [blame] | 439 | snd_hda_pick_fixup(codec, ad1986a_fixup_models, ad1986a_fixup_tbl, |
| 440 | ad1986a_fixups); |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 441 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
| 442 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 443 | err = ad198x_parse_auto_config(codec, false); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 444 | if (err < 0) { |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 445 | snd_hda_gen_free(codec); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 446 | return err; |
| 447 | } |
| 448 | |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 449 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 450 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 451 | return 0; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 452 | } |
| 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | /* |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 456 | * AD1983 specific |
| 457 | */ |
| 458 | |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 459 | /* |
| 460 | * SPDIF mux control for AD1983 auto-parser |
| 461 | */ |
| 462 | static int ad1983_auto_smux_enum_info(struct snd_kcontrol *kcontrol, |
| 463 | struct snd_ctl_elem_info *uinfo) |
| 464 | { |
| 465 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 466 | struct ad198x_spec *spec = codec->spec; |
| 467 | static const char * const texts2[] = { "PCM", "ADC" }; |
| 468 | static const char * const texts3[] = { "PCM", "ADC1", "ADC2" }; |
| 469 | hda_nid_t dig_out = spec->gen.multiout.dig_out_nid; |
| 470 | int num_conns = snd_hda_get_num_conns(codec, dig_out); |
| 471 | |
| 472 | if (num_conns == 2) |
| 473 | return snd_hda_enum_helper_info(kcontrol, uinfo, 2, texts2); |
| 474 | else if (num_conns == 3) |
| 475 | return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3); |
| 476 | else |
| 477 | return -EINVAL; |
| 478 | } |
| 479 | |
| 480 | static int ad1983_auto_smux_enum_get(struct snd_kcontrol *kcontrol, |
| 481 | struct snd_ctl_elem_value *ucontrol) |
| 482 | { |
| 483 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 484 | struct ad198x_spec *spec = codec->spec; |
| 485 | |
| 486 | ucontrol->value.enumerated.item[0] = spec->cur_smux; |
| 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | static int ad1983_auto_smux_enum_put(struct snd_kcontrol *kcontrol, |
| 491 | struct snd_ctl_elem_value *ucontrol) |
| 492 | { |
| 493 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 494 | struct ad198x_spec *spec = codec->spec; |
| 495 | unsigned int val = ucontrol->value.enumerated.item[0]; |
| 496 | hda_nid_t dig_out = spec->gen.multiout.dig_out_nid; |
| 497 | int num_conns = snd_hda_get_num_conns(codec, dig_out); |
| 498 | |
| 499 | if (val >= num_conns) |
| 500 | return -EINVAL; |
| 501 | if (spec->cur_smux == val) |
| 502 | return 0; |
| 503 | spec->cur_smux = val; |
| 504 | snd_hda_codec_write_cache(codec, dig_out, 0, |
| 505 | AC_VERB_SET_CONNECT_SEL, val); |
| 506 | return 1; |
| 507 | } |
| 508 | |
| 509 | static struct snd_kcontrol_new ad1983_auto_smux_mixer = { |
| 510 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 511 | .name = "IEC958 Playback Source", |
| 512 | .info = ad1983_auto_smux_enum_info, |
| 513 | .get = ad1983_auto_smux_enum_get, |
| 514 | .put = ad1983_auto_smux_enum_put, |
| 515 | }; |
| 516 | |
| 517 | static int ad1983_add_spdif_mux_ctl(struct hda_codec *codec) |
| 518 | { |
| 519 | struct ad198x_spec *spec = codec->spec; |
| 520 | hda_nid_t dig_out = spec->gen.multiout.dig_out_nid; |
| 521 | int num_conns; |
| 522 | |
| 523 | if (!dig_out) |
| 524 | return 0; |
| 525 | num_conns = snd_hda_get_num_conns(codec, dig_out); |
| 526 | if (num_conns != 2 && num_conns != 3) |
| 527 | return 0; |
| 528 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1983_auto_smux_mixer)) |
| 529 | return -ENOMEM; |
| 530 | return 0; |
| 531 | } |
| 532 | |
Takashi Iwai | bd450dc | 2013-07-04 15:48:04 +0200 | [diff] [blame] | 533 | static int patch_ad1983(struct hda_codec *codec) |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 534 | { |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 535 | struct ad198x_spec *spec; |
Takashi Iwai | 276ab33 | 2014-02-05 08:49:41 +0100 | [diff] [blame] | 536 | static hda_nid_t conn_0c[] = { 0x08 }; |
| 537 | static hda_nid_t conn_0d[] = { 0x09 }; |
Takashi Iwai | c5a4bcd | 2009-02-06 17:22:05 +0100 | [diff] [blame] | 538 | int err; |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 539 | |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 540 | err = alloc_ad_spec(codec); |
| 541 | if (err < 0) |
| 542 | return err; |
| 543 | spec = codec->spec; |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 544 | |
Takashi Iwai | c7579fe | 2014-02-05 07:28:10 +0100 | [diff] [blame] | 545 | spec->gen.mixer_nid = 0x0e; |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 546 | spec->gen.beep_nid = 0x10; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 547 | set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); |
Takashi Iwai | 276ab33 | 2014-02-05 08:49:41 +0100 | [diff] [blame] | 548 | |
| 549 | /* limit the loopback routes not to confuse the parser */ |
| 550 | snd_hda_override_conn_list(codec, 0x0c, ARRAY_SIZE(conn_0c), conn_0c); |
| 551 | snd_hda_override_conn_list(codec, 0x0d, ARRAY_SIZE(conn_0d), conn_0d); |
| 552 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 553 | err = ad198x_parse_auto_config(codec, false); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 554 | if (err < 0) |
| 555 | goto error; |
| 556 | err = ad1983_add_spdif_mux_ctl(codec); |
| 557 | if (err < 0) |
| 558 | goto error; |
| 559 | return 0; |
| 560 | |
| 561 | error: |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 562 | snd_hda_gen_free(codec); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 563 | return err; |
| 564 | } |
| 565 | |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 566 | |
| 567 | /* |
| 568 | * AD1981 HD specific |
| 569 | */ |
| 570 | |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 571 | static void ad1981_fixup_hp_eapd(struct hda_codec *codec, |
| 572 | const struct hda_fixup *fix, int action) |
| 573 | { |
| 574 | struct ad198x_spec *spec = codec->spec; |
| 575 | |
| 576 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
| 577 | spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; |
| 578 | spec->eapd_nid = 0x05; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | /* set the upper-limit for mixer amp to 0dB for avoiding the possible |
| 583 | * damage by overloading |
| 584 | */ |
| 585 | static void ad1981_fixup_amp_override(struct hda_codec *codec, |
| 586 | const struct hda_fixup *fix, int action) |
| 587 | { |
| 588 | if (action == HDA_FIXUP_ACT_PRE_PROBE) |
| 589 | snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT, |
| 590 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 591 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 592 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 593 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 594 | } |
| 595 | |
| 596 | enum { |
| 597 | AD1981_FIXUP_AMP_OVERRIDE, |
| 598 | AD1981_FIXUP_HP_EAPD, |
| 599 | }; |
| 600 | |
| 601 | static const struct hda_fixup ad1981_fixups[] = { |
| 602 | [AD1981_FIXUP_AMP_OVERRIDE] = { |
| 603 | .type = HDA_FIXUP_FUNC, |
| 604 | .v.func = ad1981_fixup_amp_override, |
| 605 | }, |
| 606 | [AD1981_FIXUP_HP_EAPD] = { |
| 607 | .type = HDA_FIXUP_FUNC, |
| 608 | .v.func = ad1981_fixup_hp_eapd, |
| 609 | .chained = true, |
| 610 | .chain_id = AD1981_FIXUP_AMP_OVERRIDE, |
| 611 | }, |
| 612 | }; |
| 613 | |
| 614 | static const struct snd_pci_quirk ad1981_fixup_tbl[] = { |
| 615 | SND_PCI_QUIRK_VENDOR(0x1014, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE), |
| 616 | SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1981_FIXUP_HP_EAPD), |
| 617 | SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", AD1981_FIXUP_AMP_OVERRIDE), |
| 618 | /* HP nx6320 (reversed SSID, H/W bug) */ |
| 619 | SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_FIXUP_HP_EAPD), |
| 620 | {} |
| 621 | }; |
| 622 | |
Takashi Iwai | bd450dc | 2013-07-04 15:48:04 +0200 | [diff] [blame] | 623 | static int patch_ad1981(struct hda_codec *codec) |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 624 | { |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 625 | struct ad198x_spec *spec; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 626 | int err; |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 627 | |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 628 | err = alloc_ad_spec(codec); |
| 629 | if (err < 0) |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 630 | return -ENOMEM; |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 631 | spec = codec->spec; |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 632 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 633 | spec->gen.mixer_nid = 0x0e; |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 634 | spec->gen.beep_nid = 0x10; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 635 | set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT); |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 636 | |
| 637 | snd_hda_pick_fixup(codec, NULL, ad1981_fixup_tbl, ad1981_fixups); |
| 638 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
| 639 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 640 | err = ad198x_parse_auto_config(codec, false); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 641 | if (err < 0) |
| 642 | goto error; |
| 643 | err = ad1983_add_spdif_mux_ctl(codec); |
| 644 | if (err < 0) |
| 645 | goto error; |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 646 | |
| 647 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 648 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 649 | return 0; |
| 650 | |
| 651 | error: |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 652 | snd_hda_gen_free(codec); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 653 | return err; |
| 654 | } |
| 655 | |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 656 | |
| 657 | /* |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 658 | * AD1988 |
| 659 | * |
| 660 | * Output pins and routes |
| 661 | * |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 662 | * Pin Mix Sel DAC (*) |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 663 | * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06 |
| 664 | * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06 |
| 665 | * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a |
| 666 | * port-D 0x12 (mute/hp) <- 0x29 <- 04 |
| 667 | * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a |
| 668 | * port-F 0x16 (mute) <- 0x2a <- 06 |
| 669 | * port-G 0x24 (mute) <- 0x27 <- 05 |
| 670 | * port-H 0x25 (mute) <- 0x28 <- 0a |
| 671 | * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06 |
| 672 | * |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 673 | * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah |
| 674 | * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug. |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 675 | * |
| 676 | * Input pins and routes |
| 677 | * |
| 678 | * pin boost mix input # / adc input # |
| 679 | * port-A 0x11 -> 0x38 -> mix 2, ADC 0 |
| 680 | * port-B 0x14 -> 0x39 -> mix 0, ADC 1 |
| 681 | * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2 |
| 682 | * port-D 0x12 -> 0x3d -> mix 3, ADC 8 |
| 683 | * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4 |
| 684 | * port-F 0x16 -> 0x3b -> mix 5, ADC 3 |
| 685 | * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6 |
| 686 | * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7 |
| 687 | * |
| 688 | * |
| 689 | * DAC assignment |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 690 | * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03 |
Takashi Iwai | f8c7c7b | 2005-11-24 16:17:20 +0100 | [diff] [blame] | 691 | * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03 |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 692 | * |
| 693 | * Inputs of Analog Mix (0x20) |
| 694 | * 0:Port-B (front mic) |
| 695 | * 1:Port-C/G/H (line-in) |
| 696 | * 2:Port-A |
| 697 | * 3:Port-D (line-in/2) |
| 698 | * 4:Port-E/G/H (mic-in) |
| 699 | * 5:Port-F (mic2-in) |
| 700 | * 6:CD |
| 701 | * 7:Beep |
| 702 | * |
| 703 | * ADC selection |
| 704 | * 0:Port-A |
| 705 | * 1:Port-B (front mic-in) |
| 706 | * 2:Port-C (line-in) |
| 707 | * 3:Port-F (mic2-in) |
| 708 | * 4:Port-E (mic-in) |
| 709 | * 5:CD |
| 710 | * 6:Port-G |
| 711 | * 7:Port-H |
| 712 | * 8:Port-D (line-in/2) |
| 713 | * 9:Mix |
| 714 | * |
| 715 | * Proposed pin assignments by the datasheet |
| 716 | * |
| 717 | * 6-stack |
| 718 | * Port-A front headphone |
| 719 | * B front mic-in |
| 720 | * C rear line-in |
| 721 | * D rear front-out |
| 722 | * E rear mic-in |
| 723 | * F rear surround |
| 724 | * G rear CLFE |
| 725 | * H rear side |
| 726 | * |
| 727 | * 3-stack |
| 728 | * Port-A front headphone |
| 729 | * B front mic |
| 730 | * C rear line-in/surround |
| 731 | * D rear front-out |
| 732 | * E rear mic-in/CLFE |
| 733 | * |
| 734 | * laptop |
| 735 | * Port-A headphone |
| 736 | * B mic-in |
| 737 | * C docking station |
| 738 | * D internal speaker (with EAPD) |
| 739 | * E/F quad mic array |
| 740 | */ |
| 741 | |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 742 | static int ad1988_auto_smux_enum_info(struct snd_kcontrol *kcontrol, |
| 743 | struct snd_ctl_elem_info *uinfo) |
| 744 | { |
| 745 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 746 | static const char * const texts[] = { |
| 747 | "PCM", "ADC1", "ADC2", "ADC3", |
| 748 | }; |
| 749 | int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; |
| 750 | if (num_conns > 4) |
| 751 | num_conns = 4; |
| 752 | return snd_hda_enum_helper_info(kcontrol, uinfo, num_conns, texts); |
| 753 | } |
| 754 | |
| 755 | static int ad1988_auto_smux_enum_get(struct snd_kcontrol *kcontrol, |
| 756 | struct snd_ctl_elem_value *ucontrol) |
| 757 | { |
| 758 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 759 | struct ad198x_spec *spec = codec->spec; |
| 760 | |
| 761 | ucontrol->value.enumerated.item[0] = spec->cur_smux; |
| 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | static int ad1988_auto_smux_enum_put(struct snd_kcontrol *kcontrol, |
| 766 | struct snd_ctl_elem_value *ucontrol) |
| 767 | { |
| 768 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 769 | struct ad198x_spec *spec = codec->spec; |
| 770 | unsigned int val = ucontrol->value.enumerated.item[0]; |
| 771 | struct nid_path *path; |
| 772 | int num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; |
| 773 | |
| 774 | if (val >= num_conns) |
| 775 | return -EINVAL; |
| 776 | if (spec->cur_smux == val) |
| 777 | return 0; |
| 778 | |
| 779 | mutex_lock(&codec->control_mutex); |
| 780 | codec->cached_write = 1; |
| 781 | path = snd_hda_get_path_from_idx(codec, |
| 782 | spec->smux_paths[spec->cur_smux]); |
| 783 | if (path) |
| 784 | snd_hda_activate_path(codec, path, false, true); |
| 785 | path = snd_hda_get_path_from_idx(codec, spec->smux_paths[val]); |
| 786 | if (path) |
| 787 | snd_hda_activate_path(codec, path, true, true); |
| 788 | spec->cur_smux = val; |
| 789 | codec->cached_write = 0; |
| 790 | mutex_unlock(&codec->control_mutex); |
| 791 | snd_hda_codec_flush_cache(codec); /* flush the updates */ |
| 792 | return 1; |
| 793 | } |
| 794 | |
| 795 | static struct snd_kcontrol_new ad1988_auto_smux_mixer = { |
| 796 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 797 | .name = "IEC958 Playback Source", |
| 798 | .info = ad1988_auto_smux_enum_info, |
| 799 | .get = ad1988_auto_smux_enum_get, |
| 800 | .put = ad1988_auto_smux_enum_put, |
| 801 | }; |
| 802 | |
| 803 | static int ad1988_auto_init(struct hda_codec *codec) |
| 804 | { |
| 805 | struct ad198x_spec *spec = codec->spec; |
| 806 | int i, err; |
| 807 | |
| 808 | err = snd_hda_gen_init(codec); |
| 809 | if (err < 0) |
| 810 | return err; |
| 811 | if (!spec->gen.autocfg.dig_outs) |
| 812 | return 0; |
| 813 | |
| 814 | for (i = 0; i < 4; i++) { |
| 815 | struct nid_path *path; |
| 816 | path = snd_hda_get_path_from_idx(codec, spec->smux_paths[i]); |
| 817 | if (path) |
| 818 | snd_hda_activate_path(codec, path, path->active, false); |
| 819 | } |
| 820 | |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | static int ad1988_add_spdif_mux_ctl(struct hda_codec *codec) |
| 825 | { |
| 826 | struct ad198x_spec *spec = codec->spec; |
| 827 | int i, num_conns; |
| 828 | /* we create four static faked paths, since AD codecs have odd |
| 829 | * widget connections regarding the SPDIF out source |
| 830 | */ |
| 831 | static struct nid_path fake_paths[4] = { |
| 832 | { |
| 833 | .depth = 3, |
| 834 | .path = { 0x02, 0x1d, 0x1b }, |
| 835 | .idx = { 0, 0, 0 }, |
| 836 | .multi = { 0, 0, 0 }, |
| 837 | }, |
| 838 | { |
| 839 | .depth = 4, |
| 840 | .path = { 0x08, 0x0b, 0x1d, 0x1b }, |
| 841 | .idx = { 0, 0, 1, 0 }, |
| 842 | .multi = { 0, 1, 0, 0 }, |
| 843 | }, |
| 844 | { |
| 845 | .depth = 4, |
| 846 | .path = { 0x09, 0x0b, 0x1d, 0x1b }, |
| 847 | .idx = { 0, 1, 1, 0 }, |
| 848 | .multi = { 0, 1, 0, 0 }, |
| 849 | }, |
| 850 | { |
| 851 | .depth = 4, |
| 852 | .path = { 0x0f, 0x0b, 0x1d, 0x1b }, |
| 853 | .idx = { 0, 2, 1, 0 }, |
| 854 | .multi = { 0, 1, 0, 0 }, |
| 855 | }, |
| 856 | }; |
| 857 | |
| 858 | /* SPDIF source mux appears to be present only on AD1988A */ |
| 859 | if (!spec->gen.autocfg.dig_outs || |
| 860 | get_wcaps_type(get_wcaps(codec, 0x1d)) != AC_WID_AUD_MIX) |
| 861 | return 0; |
| 862 | |
| 863 | num_conns = snd_hda_get_num_conns(codec, 0x0b) + 1; |
| 864 | if (num_conns != 3 && num_conns != 4) |
| 865 | return 0; |
| 866 | |
| 867 | for (i = 0; i < num_conns; i++) { |
| 868 | struct nid_path *path = snd_array_new(&spec->gen.paths); |
| 869 | if (!path) |
| 870 | return -ENOMEM; |
| 871 | *path = fake_paths[i]; |
| 872 | if (!i) |
| 873 | path->active = 1; |
| 874 | spec->smux_paths[i] = snd_hda_get_path_idx(codec, path); |
| 875 | } |
| 876 | |
| 877 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &ad1988_auto_smux_mixer)) |
| 878 | return -ENOMEM; |
| 879 | |
| 880 | codec->patch_ops.init = ad1988_auto_init; |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 885 | /* |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 886 | */ |
| 887 | |
Takashi Iwai | 36ad453 | 2013-07-04 16:34:20 +0200 | [diff] [blame] | 888 | enum { |
| 889 | AD1988_FIXUP_6STACK_DIG, |
| 890 | }; |
| 891 | |
| 892 | static const struct hda_fixup ad1988_fixups[] = { |
| 893 | [AD1988_FIXUP_6STACK_DIG] = { |
| 894 | .type = HDA_FIXUP_PINS, |
| 895 | .v.pins = (const struct hda_pintbl[]) { |
| 896 | { 0x11, 0x02214130 }, /* front-hp */ |
| 897 | { 0x12, 0x01014010 }, /* line-out */ |
| 898 | { 0x14, 0x02a19122 }, /* front-mic */ |
| 899 | { 0x15, 0x01813021 }, /* line-in */ |
| 900 | { 0x16, 0x01011012 }, /* line-out */ |
| 901 | { 0x17, 0x01a19020 }, /* mic */ |
| 902 | { 0x1b, 0x0145f1f0 }, /* SPDIF */ |
| 903 | { 0x24, 0x01016011 }, /* line-out */ |
| 904 | { 0x25, 0x01012013 }, /* line-out */ |
| 905 | { } |
| 906 | } |
| 907 | }, |
| 908 | }; |
| 909 | |
| 910 | static const struct hda_model_fixup ad1988_fixup_models[] = { |
| 911 | { .id = AD1988_FIXUP_6STACK_DIG, .name = "6stack-dig" }, |
| 912 | {} |
| 913 | }; |
| 914 | |
| 915 | static int patch_ad1988(struct hda_codec *codec) |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 916 | { |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 917 | struct ad198x_spec *spec; |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 918 | int err; |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 919 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 920 | err = alloc_ad_spec(codec); |
| 921 | if (err < 0) |
| 922 | return err; |
| 923 | spec = codec->spec; |
| 924 | |
Takashi Iwai | f2f8be4 | 2013-01-21 16:40:16 +0100 | [diff] [blame] | 925 | spec->gen.mixer_nid = 0x20; |
Takashi Iwai | e4a395e | 2013-01-23 17:00:31 +0100 | [diff] [blame] | 926 | spec->gen.mixer_merge_nid = 0x21; |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 927 | spec->gen.beep_nid = 0x10; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 928 | set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); |
Takashi Iwai | 36ad453 | 2013-07-04 16:34:20 +0200 | [diff] [blame] | 929 | |
| 930 | snd_hda_pick_fixup(codec, ad1988_fixup_models, NULL, ad1988_fixups); |
| 931 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
| 932 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 933 | err = ad198x_parse_auto_config(codec, true); |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 934 | if (err < 0) |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 935 | goto error; |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 936 | err = ad1988_add_spdif_mux_ctl(codec); |
| 937 | if (err < 0) |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 938 | goto error; |
Takashi Iwai | 36ad453 | 2013-07-04 16:34:20 +0200 | [diff] [blame] | 939 | |
| 940 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 941 | |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 942 | return 0; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 943 | |
| 944 | error: |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 945 | snd_hda_gen_free(codec); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 946 | return err; |
Takashi Iwai | d32410b1 | 2005-11-24 16:06:23 +0100 | [diff] [blame] | 947 | } |
| 948 | |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 949 | |
| 950 | /* |
Takashi Iwai | 2bac647 | 2007-05-18 18:21:41 +0200 | [diff] [blame] | 951 | * AD1884 / AD1984 |
| 952 | * |
| 953 | * port-B - front line/mic-in |
| 954 | * port-E - aux in/out |
| 955 | * port-F - aux in/out |
| 956 | * port-C - rear line/mic-in |
| 957 | * port-D - rear line/hp-out |
| 958 | * port-A - front line/hp-out |
| 959 | * |
| 960 | * AD1984 = AD1884 + two digital mic-ins |
| 961 | * |
Takashi Iwai | 5ccc618 | 2013-07-04 15:36:56 +0200 | [diff] [blame] | 962 | * AD1883 / AD1884A / AD1984A / AD1984B |
| 963 | * |
| 964 | * port-B (0x14) - front mic-in |
| 965 | * port-E (0x1c) - rear mic-in |
| 966 | * port-F (0x16) - CD / ext out |
| 967 | * port-C (0x15) - rear line-in |
| 968 | * port-D (0x12) - rear line-out |
| 969 | * port-A (0x11) - front hp-out |
| 970 | * |
| 971 | * AD1984A = AD1884A + digital-mic |
| 972 | * AD1883 = equivalent with AD1984A |
| 973 | * AD1984B = AD1984A + extra SPDIF-out |
Takashi Iwai | 2bac647 | 2007-05-18 18:21:41 +0200 | [diff] [blame] | 974 | */ |
| 975 | |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 976 | /* set the upper-limit for mixer amp to 0dB for avoiding the possible |
| 977 | * damage by overloading |
| 978 | */ |
| 979 | static void ad1884_fixup_amp_override(struct hda_codec *codec, |
| 980 | const struct hda_fixup *fix, int action) |
| 981 | { |
| 982 | if (action == HDA_FIXUP_ACT_PRE_PROBE) |
| 983 | snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT, |
| 984 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 985 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 986 | (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 987 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 988 | } |
| 989 | |
Takashi Iwai | 1a39b5e | 2013-07-04 14:32:16 +0200 | [diff] [blame] | 990 | /* toggle GPIO1 according to the mute state */ |
| 991 | static void ad1884_vmaster_hp_gpio_hook(void *private_data, int enabled) |
| 992 | { |
| 993 | struct hda_codec *codec = private_data; |
| 994 | struct ad198x_spec *spec = codec->spec; |
| 995 | |
| 996 | if (spec->eapd_nid) |
| 997 | ad_vmaster_eapd_hook(private_data, enabled); |
| 998 | snd_hda_codec_update_cache(codec, 0x01, 0, |
| 999 | AC_VERB_SET_GPIO_DATA, |
| 1000 | enabled ? 0x00 : 0x02); |
| 1001 | } |
| 1002 | |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1003 | static void ad1884_fixup_hp_eapd(struct hda_codec *codec, |
| 1004 | const struct hda_fixup *fix, int action) |
| 1005 | { |
| 1006 | struct ad198x_spec *spec = codec->spec; |
Takashi Iwai | 1a39b5e | 2013-07-04 14:32:16 +0200 | [diff] [blame] | 1007 | static const struct hda_verb gpio_init_verbs[] = { |
| 1008 | {0x01, AC_VERB_SET_GPIO_MASK, 0x02}, |
| 1009 | {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02}, |
| 1010 | {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, |
| 1011 | {}, |
| 1012 | }; |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1013 | |
Takashi Iwai | 8f0b3b7 | 2013-07-04 12:54:22 +0200 | [diff] [blame] | 1014 | switch (action) { |
| 1015 | case HDA_FIXUP_ACT_PRE_PROBE: |
Takashi Iwai | 1a39b5e | 2013-07-04 14:32:16 +0200 | [diff] [blame] | 1016 | spec->gen.vmaster_mute.hook = ad1884_vmaster_hp_gpio_hook; |
Takashi Iwai | 1cd9b2f | 2013-12-02 13:19:45 +0100 | [diff] [blame] | 1017 | spec->gen.own_eapd_ctl = 1; |
Takashi Iwai | 1a39b5e | 2013-07-04 14:32:16 +0200 | [diff] [blame] | 1018 | snd_hda_sequence_write_cache(codec, gpio_init_verbs); |
Takashi Iwai | 8f0b3b7 | 2013-07-04 12:54:22 +0200 | [diff] [blame] | 1019 | break; |
| 1020 | case HDA_FIXUP_ACT_PROBE: |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1021 | if (spec->gen.autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) |
| 1022 | spec->eapd_nid = spec->gen.autocfg.line_out_pins[0]; |
| 1023 | else |
| 1024 | spec->eapd_nid = spec->gen.autocfg.speaker_pins[0]; |
Takashi Iwai | 8f0b3b7 | 2013-07-04 12:54:22 +0200 | [diff] [blame] | 1025 | break; |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1026 | } |
| 1027 | } |
| 1028 | |
Takashi Iwai | 1ac3293 | 2013-10-26 00:24:14 +0200 | [diff] [blame] | 1029 | static void ad1884_fixup_thinkpad(struct hda_codec *codec, |
| 1030 | const struct hda_fixup *fix, int action) |
| 1031 | { |
| 1032 | struct ad198x_spec *spec = codec->spec; |
| 1033 | |
Takashi Iwai | afb5a77 | 2013-10-26 00:33:58 +0200 | [diff] [blame] | 1034 | if (action == HDA_FIXUP_ACT_PRE_PROBE) { |
Takashi Iwai | 1ac3293 | 2013-10-26 00:24:14 +0200 | [diff] [blame] | 1035 | spec->gen.keep_eapd_on = 1; |
Takashi Iwai | afb5a77 | 2013-10-26 00:33:58 +0200 | [diff] [blame] | 1036 | spec->gen.vmaster_mute.hook = ad_vmaster_eapd_hook; |
| 1037 | spec->eapd_nid = 0x12; |
Takashi Iwai | f3e9b59 | 2014-03-05 12:00:29 +0100 | [diff] [blame] | 1038 | /* Analog PC Beeper - allow firmware/ACPI beeps */ |
| 1039 | spec->beep_amp = HDA_COMPOSE_AMP_VAL(0x20, 3, 3, HDA_INPUT); |
| 1040 | spec->gen.beep_nid = 0; /* no digital beep */ |
Takashi Iwai | afb5a77 | 2013-10-26 00:33:58 +0200 | [diff] [blame] | 1041 | } |
Takashi Iwai | 1ac3293 | 2013-10-26 00:24:14 +0200 | [diff] [blame] | 1042 | } |
| 1043 | |
Takashi Iwai | 6a699be | 2013-07-04 14:45:37 +0200 | [diff] [blame] | 1044 | /* set magic COEFs for dmic */ |
| 1045 | static const struct hda_verb ad1884_dmic_init_verbs[] = { |
| 1046 | {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7}, |
| 1047 | {0x01, AC_VERB_SET_PROC_COEF, 0x08}, |
| 1048 | {} |
| 1049 | }; |
| 1050 | |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1051 | enum { |
| 1052 | AD1884_FIXUP_AMP_OVERRIDE, |
| 1053 | AD1884_FIXUP_HP_EAPD, |
Takashi Iwai | 6a699be | 2013-07-04 14:45:37 +0200 | [diff] [blame] | 1054 | AD1884_FIXUP_DMIC_COEF, |
Takashi Iwai | 1ac3293 | 2013-10-26 00:24:14 +0200 | [diff] [blame] | 1055 | AD1884_FIXUP_THINKPAD, |
Takashi Iwai | f404627 | 2013-07-04 15:14:17 +0200 | [diff] [blame] | 1056 | AD1884_FIXUP_HP_TOUCHSMART, |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1057 | }; |
| 1058 | |
| 1059 | static const struct hda_fixup ad1884_fixups[] = { |
| 1060 | [AD1884_FIXUP_AMP_OVERRIDE] = { |
| 1061 | .type = HDA_FIXUP_FUNC, |
| 1062 | .v.func = ad1884_fixup_amp_override, |
| 1063 | }, |
| 1064 | [AD1884_FIXUP_HP_EAPD] = { |
| 1065 | .type = HDA_FIXUP_FUNC, |
| 1066 | .v.func = ad1884_fixup_hp_eapd, |
| 1067 | .chained = true, |
| 1068 | .chain_id = AD1884_FIXUP_AMP_OVERRIDE, |
| 1069 | }, |
Takashi Iwai | 6a699be | 2013-07-04 14:45:37 +0200 | [diff] [blame] | 1070 | [AD1884_FIXUP_DMIC_COEF] = { |
| 1071 | .type = HDA_FIXUP_VERBS, |
| 1072 | .v.verbs = ad1884_dmic_init_verbs, |
| 1073 | }, |
Takashi Iwai | 1ac3293 | 2013-10-26 00:24:14 +0200 | [diff] [blame] | 1074 | [AD1884_FIXUP_THINKPAD] = { |
| 1075 | .type = HDA_FIXUP_FUNC, |
| 1076 | .v.func = ad1884_fixup_thinkpad, |
| 1077 | .chained = true, |
| 1078 | .chain_id = AD1884_FIXUP_DMIC_COEF, |
| 1079 | }, |
Takashi Iwai | f404627 | 2013-07-04 15:14:17 +0200 | [diff] [blame] | 1080 | [AD1884_FIXUP_HP_TOUCHSMART] = { |
| 1081 | .type = HDA_FIXUP_VERBS, |
| 1082 | .v.verbs = ad1884_dmic_init_verbs, |
| 1083 | .chained = true, |
| 1084 | .chain_id = AD1884_FIXUP_HP_EAPD, |
| 1085 | }, |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1086 | }; |
| 1087 | |
| 1088 | static const struct snd_pci_quirk ad1884_fixup_tbl[] = { |
Takashi Iwai | f404627 | 2013-07-04 15:14:17 +0200 | [diff] [blame] | 1089 | SND_PCI_QUIRK(0x103c, 0x2a82, "HP Touchsmart", AD1884_FIXUP_HP_TOUCHSMART), |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1090 | SND_PCI_QUIRK_VENDOR(0x103c, "HP", AD1884_FIXUP_HP_EAPD), |
Takashi Iwai | 1ac3293 | 2013-10-26 00:24:14 +0200 | [diff] [blame] | 1091 | SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1884_FIXUP_THINKPAD), |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1092 | {} |
| 1093 | }; |
| 1094 | |
| 1095 | |
Takashi Iwai | 5ccc618 | 2013-07-04 15:36:56 +0200 | [diff] [blame] | 1096 | static int patch_ad1884(struct hda_codec *codec) |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 1097 | { |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1098 | struct ad198x_spec *spec; |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 1099 | int err; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 1100 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1101 | err = alloc_ad_spec(codec); |
| 1102 | if (err < 0) |
| 1103 | return err; |
| 1104 | spec = codec->spec; |
| 1105 | |
Takashi Iwai | f2f8be4 | 2013-01-21 16:40:16 +0100 | [diff] [blame] | 1106 | spec->gen.mixer_nid = 0x20; |
Takashi Iwai | c5eda4c | 2014-03-05 11:52:24 +0100 | [diff] [blame] | 1107 | spec->gen.mixer_merge_nid = 0x21; |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 1108 | spec->gen.beep_nid = 0x10; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 1109 | set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1110 | |
| 1111 | snd_hda_pick_fixup(codec, NULL, ad1884_fixup_tbl, ad1884_fixups); |
| 1112 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
| 1113 | |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 1114 | err = ad198x_parse_auto_config(codec, true); |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 1115 | if (err < 0) |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1116 | goto error; |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 1117 | err = ad1983_add_spdif_mux_ctl(codec); |
| 1118 | if (err < 0) |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1119 | goto error; |
Takashi Iwai | a928bd2 | 2013-01-22 18:18:42 +0100 | [diff] [blame] | 1120 | |
| 1121 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); |
| 1122 | |
Takashi Iwai | 272f3ea | 2013-01-22 15:31:33 +0100 | [diff] [blame] | 1123 | return 0; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1124 | |
| 1125 | error: |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 1126 | snd_hda_gen_free(codec); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1127 | return err; |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 1128 | } |
| 1129 | |
Takashi Iwai | c505925 | 2008-02-16 09:43:56 +0100 | [diff] [blame] | 1130 | /* |
Takashi Iwai | 9e44c6e | 2008-08-18 13:53:07 +0200 | [diff] [blame] | 1131 | * AD1882 / AD1882A |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 1132 | * |
| 1133 | * port-A - front hp-out |
| 1134 | * port-B - front mic-in |
| 1135 | * port-C - rear line-in, shared surr-out (3stack) |
| 1136 | * port-D - rear line-out |
| 1137 | * port-E - rear mic-in, shared clfe-out (3stack) |
| 1138 | * port-F - rear surr-out (6stack) |
| 1139 | * port-G - rear clfe-out (6stack) |
| 1140 | */ |
| 1141 | |
Takashi Iwai | aa95d61 | 2013-07-04 15:16:31 +0200 | [diff] [blame] | 1142 | static int patch_ad1882(struct hda_codec *codec) |
Takashi Iwai | 78bb3cb | 2012-12-21 15:17:06 +0100 | [diff] [blame] | 1143 | { |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 1144 | struct ad198x_spec *spec; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1145 | int err; |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 1146 | |
Takashi Iwai | 361dab3 | 2012-05-09 14:35:27 +0200 | [diff] [blame] | 1147 | err = alloc_ad_spec(codec); |
| 1148 | if (err < 0) |
| 1149 | return err; |
| 1150 | spec = codec->spec; |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 1151 | |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1152 | spec->gen.mixer_nid = 0x20; |
Takashi Iwai | e4a395e | 2013-01-23 17:00:31 +0100 | [diff] [blame] | 1153 | spec->gen.mixer_merge_nid = 0x21; |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 1154 | spec->gen.beep_nid = 0x10; |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1155 | set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); |
Takashi Iwai | cbd209f | 2014-01-13 12:40:07 +0100 | [diff] [blame] | 1156 | err = ad198x_parse_auto_config(codec, true); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1157 | if (err < 0) |
| 1158 | goto error; |
| 1159 | err = ad1988_add_spdif_mux_ctl(codec); |
| 1160 | if (err < 0) |
| 1161 | goto error; |
| 1162 | return 0; |
| 1163 | |
| 1164 | error: |
Takashi Iwai | 7504b6c | 2013-03-18 11:25:51 +0100 | [diff] [blame] | 1165 | snd_hda_gen_free(codec); |
Takashi Iwai | 9ff4bc8 | 2013-01-22 16:45:58 +0100 | [diff] [blame] | 1166 | return err; |
| 1167 | } |
| 1168 | |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 1169 | |
| 1170 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | * patch entries |
| 1172 | */ |
Takashi Iwai | 498f5b1 | 2011-05-02 11:33:15 +0200 | [diff] [blame] | 1173 | static const struct hda_codec_preset snd_hda_preset_analog[] = { |
Takashi Iwai | 5ccc618 | 2013-07-04 15:36:56 +0200 | [diff] [blame] | 1174 | { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884 }, |
Takashi Iwai | 0ac8551 | 2007-06-20 15:46:13 +0200 | [diff] [blame] | 1175 | { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 }, |
Takashi Iwai | 5ccc618 | 2013-07-04 15:36:56 +0200 | [diff] [blame] | 1176 | { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884 }, |
Takashi Iwai | 2bac647 | 2007-05-18 18:21:41 +0200 | [diff] [blame] | 1177 | { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 }, |
Takashi Iwai | 5ccc618 | 2013-07-04 15:36:56 +0200 | [diff] [blame] | 1178 | { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884 }, |
| 1179 | { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884 }, |
Takashi Iwai | 4a3fdf3 | 2005-04-14 13:35:51 +0200 | [diff] [blame] | 1180 | { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 }, |
| 1181 | { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 }, |
Takashi Iwai | 5ccc618 | 2013-07-04 15:36:56 +0200 | [diff] [blame] | 1182 | { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1884 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, |
Takashi Iwai | fd66e0d | 2005-11-17 15:31:34 +0100 | [diff] [blame] | 1184 | { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, |
Takashi Iwai | 71b2ccc | 2006-04-21 16:09:31 +0200 | [diff] [blame] | 1185 | { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 }, |
Takashi Iwai | 9e44c6e | 2008-08-18 13:53:07 +0200 | [diff] [blame] | 1186 | { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 }, |
Takashi Iwai | 3adb8ab | 2008-04-15 18:46:42 +0200 | [diff] [blame] | 1187 | { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 }, |
| 1188 | { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | {} /* terminator */ |
| 1190 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1191 | |
| 1192 | MODULE_ALIAS("snd-hda-codec-id:11d4*"); |
| 1193 | |
| 1194 | MODULE_LICENSE("GPL"); |
| 1195 | MODULE_DESCRIPTION("Analog Devices HD-audio codec"); |
| 1196 | |
| 1197 | static struct hda_codec_preset_list analog_list = { |
| 1198 | .preset = snd_hda_preset_analog, |
| 1199 | .owner = THIS_MODULE, |
| 1200 | }; |
| 1201 | |
| 1202 | static int __init patch_analog_init(void) |
| 1203 | { |
| 1204 | return snd_hda_add_codec_preset(&analog_list); |
| 1205 | } |
| 1206 | |
| 1207 | static void __exit patch_analog_exit(void) |
| 1208 | { |
| 1209 | snd_hda_delete_codec_preset(&analog_list); |
| 1210 | } |
| 1211 | |
| 1212 | module_init(patch_analog_init) |
| 1213 | module_exit(patch_analog_exit) |