Thomas Gleixner | d0fa117 | 2019-05-20 19:07:57 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Universal Interface for Intel High Definition Audio Codec |
| 4 | * |
Lydia Wang | 8e86597 | 2009-10-10 19:08:52 +0800 | [diff] [blame] | 5 | * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 6 | * |
Lydia Wang | 8e86597 | 2009-10-10 19:08:52 +0800 | [diff] [blame] | 7 | * (C) 2006-2009 VIA Technology, Inc. |
| 8 | * (C) 2006-2008 Takashi Iwai <tiwai@suse.de> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 12 | /* */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 13 | /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 14 | /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */ |
| 15 | /* 2006-08-02 Lydia Wang Add support to VT1709 codec */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 16 | /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 17 | /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ |
| 18 | /* 2007-09-17 Lydia Wang Add VT1708B codec support */ |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 19 | /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 20 | /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 21 | /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ |
| 22 | /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ |
| 23 | /* 2008-04-09 Lydia Wang Add Independent HP feature */ |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 24 | /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 25 | /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ |
Lydia Wang | 8e86597 | 2009-10-10 19:08:52 +0800 | [diff] [blame] | 26 | /* 2009-02-16 Logan Li Add support for VT1718S */ |
| 27 | /* 2009-03-13 Logan Li Add support for VT1716S */ |
| 28 | /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */ |
| 29 | /* 2009-07-08 Lydia Wang Add support for VT2002P */ |
| 30 | /* 2009-07-21 Lydia Wang Add support for VT1812 */ |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 31 | /* 2009-09-19 Lydia Wang Add support for VT1818S */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 32 | /* */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 33 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 34 | |
| 35 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 36 | #include <linux/init.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/slab.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 39 | #include <linux/module.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 40 | #include <sound/core.h> |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 41 | #include <sound/asoundef.h> |
Pierre-Louis Bossart | be57bff | 2018-08-22 15:24:57 -0500 | [diff] [blame] | 42 | #include <sound/hda_codec.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 43 | #include "hda_local.h" |
Takashi Iwai | 128bc4b | 2012-05-07 17:42:31 +0200 | [diff] [blame] | 44 | #include "hda_auto_parser.h" |
Takashi Iwai | 1835a0f | 2011-10-27 22:12:46 +0200 | [diff] [blame] | 45 | #include "hda_jack.h" |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 46 | #include "hda_generic.h" |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 47 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 48 | /* Pin Widget NID */ |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 49 | #define VT1708_HP_PIN_NID 0x20 |
| 50 | #define VT1708_CD_PIN_NID 0x24 |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 51 | |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 52 | enum VIA_HDA_CODEC { |
| 53 | UNKNOWN = -1, |
| 54 | VT1708, |
| 55 | VT1709_10CH, |
| 56 | VT1709_6CH, |
| 57 | VT1708B_8CH, |
| 58 | VT1708B_4CH, |
| 59 | VT1708S, |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 60 | VT1708BCE, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 61 | VT1702, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 62 | VT1718S, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 63 | VT1716S, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 64 | VT2002P, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 65 | VT1812, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 66 | VT1802, |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 67 | VT1705CF, |
Lydia Wang | 6121b84 | 2012-12-10 19:03:26 +0800 | [diff] [blame] | 68 | VT1808, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 69 | CODEC_TYPES, |
| 70 | }; |
| 71 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 72 | #define VT2002P_COMPATIBLE(spec) \ |
| 73 | ((spec)->codec_type == VT2002P ||\ |
| 74 | (spec)->codec_type == VT1812 ||\ |
| 75 | (spec)->codec_type == VT1802) |
| 76 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 77 | struct via_spec { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 78 | struct hda_gen_spec gen; |
| 79 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 80 | /* HP mode source */ |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 81 | unsigned int dmic_enabled; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 82 | enum VIA_HDA_CODEC codec_type; |
| 83 | |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 84 | /* analog low-power control */ |
| 85 | bool alc_mode; |
| 86 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 87 | /* work to check hp jack state */ |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 88 | int hp_work_active; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 89 | int vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 90 | }; |
| 91 | |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 92 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 93 | static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo, |
| 94 | struct hda_codec *codec, |
| 95 | struct snd_pcm_substream *substream, |
| 96 | int action); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 97 | |
Takashi Iwai | 225068a | 2015-05-29 10:42:14 +0200 | [diff] [blame] | 98 | static const struct hda_codec_ops via_patch_ops; /* defined below */ |
| 99 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 100 | static struct via_spec *via_new_spec(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 101 | { |
| 102 | struct via_spec *spec; |
| 103 | |
| 104 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 105 | if (spec == NULL) |
| 106 | return NULL; |
| 107 | |
| 108 | codec->spec = spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 109 | snd_hda_gen_spec_init(&spec->gen); |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 110 | spec->codec_type = get_codec_type(codec); |
| 111 | /* VT1708BCE & VT1708S are almost same */ |
| 112 | if (spec->codec_type == VT1708BCE) |
| 113 | spec->codec_type = VT1708S; |
Takashi Iwai | 1396117 | 2013-01-21 15:15:55 +0100 | [diff] [blame] | 114 | spec->gen.indep_hp = 1; |
Takashi Iwai | 05909d5c | 2013-05-31 19:55:54 +0200 | [diff] [blame] | 115 | spec->gen.keep_eapd_on = 1; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 116 | spec->gen.pcm_playback_hook = via_playback_pcm_hook; |
Takashi Iwai | 74f14b3 | 2014-12-15 13:43:59 +0100 | [diff] [blame] | 117 | spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; |
Takashi Iwai | 967b130 | 2015-03-20 18:21:03 +0100 | [diff] [blame] | 118 | codec->power_save_node = 1; |
Takashi Iwai | 688b12c | 2015-03-17 15:56:05 +0100 | [diff] [blame] | 119 | spec->gen.power_down_unused = 1; |
Takashi Iwai | 225068a | 2015-05-29 10:42:14 +0200 | [diff] [blame] | 120 | codec->patch_ops = via_patch_ops; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 121 | return spec; |
| 122 | } |
| 123 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 124 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 125 | { |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 126 | u32 vendor_id = codec->core.vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 127 | u16 ven_id = vendor_id >> 16; |
| 128 | u16 dev_id = vendor_id & 0xffff; |
| 129 | enum VIA_HDA_CODEC codec_type; |
| 130 | |
| 131 | /* get codec type */ |
| 132 | if (ven_id != 0x1106) |
| 133 | codec_type = UNKNOWN; |
| 134 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 135 | codec_type = VT1708; |
| 136 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 137 | codec_type = VT1709_10CH; |
| 138 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 139 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 140 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 141 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 142 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 143 | codec_type = VT1708BCE; |
| 144 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 145 | codec_type = VT1708B_4CH; |
| 146 | else if ((dev_id & 0xfff) == 0x397 |
| 147 | && (dev_id >> 12) < 8) |
| 148 | codec_type = VT1708S; |
| 149 | else if ((dev_id & 0xfff) == 0x398 |
| 150 | && (dev_id >> 12) < 8) |
| 151 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 152 | else if ((dev_id & 0xfff) == 0x428 |
| 153 | && (dev_id >> 12) < 8) |
| 154 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 155 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 156 | codec_type = VT1716S; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 157 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 158 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 159 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 160 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 161 | else if (dev_id == 0x0448) |
| 162 | codec_type = VT1812; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 163 | else if (dev_id == 0x0440) |
| 164 | codec_type = VT1708S; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 165 | else if ((dev_id & 0xfff) == 0x446) |
| 166 | codec_type = VT1802; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 167 | else if (dev_id == 0x4760) |
| 168 | codec_type = VT1705CF; |
Lydia Wang | 6121b84 | 2012-12-10 19:03:26 +0800 | [diff] [blame] | 169 | else if (dev_id == 0x4761 || dev_id == 0x4762) |
| 170 | codec_type = VT1808; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 171 | else |
| 172 | codec_type = UNKNOWN; |
| 173 | return codec_type; |
| 174 | }; |
| 175 | |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 176 | static void analog_low_current_mode(struct hda_codec *codec); |
| 177 | static bool is_aa_path_mute(struct hda_codec *codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 178 | |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 179 | #define hp_detect_with_aa(codec) \ |
| 180 | (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \ |
| 181 | !is_aa_path_mute(codec)) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 182 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 183 | static void vt1708_stop_hp_work(struct hda_codec *codec) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 184 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 185 | struct via_spec *spec = codec->spec; |
| 186 | if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 187 | return; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 188 | if (spec->hp_work_active) { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 189 | snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1); |
Wang Xingchao | 7eaa916 | 2013-07-25 23:34:44 -0400 | [diff] [blame] | 190 | codec->jackpoll_interval = 0; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 191 | cancel_delayed_work_sync(&codec->jackpoll_work); |
| 192 | spec->hp_work_active = false; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 196 | static void vt1708_update_hp_work(struct hda_codec *codec) |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 197 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 198 | struct via_spec *spec = codec->spec; |
| 199 | if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 200 | return; |
David Henningsson | 05dc0fc | 2013-02-05 12:06:03 +0100 | [diff] [blame] | 201 | if (spec->vt1708_jack_detect) { |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 202 | if (!spec->hp_work_active) { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 203 | codec->jackpoll_interval = msecs_to_jiffies(100); |
| 204 | snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); |
Takashi Iwai | 2f35c63 | 2015-02-27 22:43:26 +0100 | [diff] [blame] | 205 | schedule_delayed_work(&codec->jackpoll_work, 0); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 206 | spec->hp_work_active = true; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 207 | } |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 208 | } else if (!hp_detect_with_aa(codec)) |
| 209 | vt1708_stop_hp_work(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 210 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 211 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 212 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
| 213 | struct snd_ctl_elem_info *uinfo) |
| 214 | { |
Takashi Iwai | dda415d | 2012-11-30 18:34:38 +0100 | [diff] [blame] | 215 | return snd_hda_enum_bool_helper_info(kcontrol, uinfo); |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, |
| 219 | struct snd_ctl_elem_value *ucontrol) |
| 220 | { |
| 221 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 735c75c | 2015-06-25 08:48:54 +0200 | [diff] [blame] | 222 | struct via_spec *spec = codec->spec; |
| 223 | |
| 224 | ucontrol->value.enumerated.item[0] = spec->gen.power_down_unused; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, |
| 229 | struct snd_ctl_elem_value *ucontrol) |
| 230 | { |
| 231 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 232 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 688b12c | 2015-03-17 15:56:05 +0100 | [diff] [blame] | 233 | bool val = !!ucontrol->value.enumerated.item[0]; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 234 | |
Takashi Iwai | 735c75c | 2015-06-25 08:48:54 +0200 | [diff] [blame] | 235 | if (val == spec->gen.power_down_unused) |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 236 | return 0; |
Takashi Iwai | 735c75c | 2015-06-25 08:48:54 +0200 | [diff] [blame] | 237 | /* codec->power_save_node = val; */ /* widget PM seems yet broken */ |
Takashi Iwai | 688b12c | 2015-03-17 15:56:05 +0100 | [diff] [blame] | 238 | spec->gen.power_down_unused = val; |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 239 | analog_low_current_mode(codec); |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 240 | return 1; |
| 241 | } |
| 242 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 243 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 244 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 245 | .name = "Dynamic Power-Control", |
| 246 | .info = via_pin_power_ctl_info, |
| 247 | .get = via_pin_power_ctl_get, |
| 248 | .put = via_pin_power_ctl_put, |
| 249 | }; |
| 250 | |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 251 | #ifdef CONFIG_SND_HDA_INPUT_BEEP |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 252 | /* additional beep mixers; the actual parameters are overwritten at build */ |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 253 | static const struct snd_kcontrol_new via_beep_mixer[] = { |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 254 | HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT), |
| 255 | HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT), |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 258 | static int set_beep_amp(struct via_spec *spec, hda_nid_t nid, |
| 259 | int idx, int dir) |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 260 | { |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 261 | struct snd_kcontrol_new *knew; |
| 262 | unsigned int beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir); |
| 263 | int i; |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 264 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 265 | spec->gen.beep_nid = nid; |
| 266 | for (i = 0; i < ARRAY_SIZE(via_beep_mixer); i++) { |
| 267 | knew = snd_hda_gen_add_kctl(&spec->gen, NULL, |
| 268 | &via_beep_mixer[i]); |
| 269 | if (!knew) |
| 270 | return -ENOMEM; |
| 271 | knew->private_value = beep_amp; |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 272 | } |
| 273 | return 0; |
| 274 | } |
| 275 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 276 | static int auto_parse_beep(struct hda_codec *codec) |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 277 | { |
| 278 | struct via_spec *spec = codec->spec; |
| 279 | hda_nid_t nid; |
| 280 | |
| 281 | for_each_hda_codec_node(nid, codec) |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 282 | if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) |
| 283 | return set_beep_amp(spec, nid, 0, HDA_OUTPUT); |
| 284 | return 0; |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 285 | } |
| 286 | #else |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 287 | #define auto_parse_beep(codec) 0 |
W. Trevor King | 4738465 | 2015-03-25 00:43:42 -0700 | [diff] [blame] | 288 | #endif |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 289 | |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 290 | /* check AA path's mute status */ |
| 291 | static bool is_aa_path_mute(struct hda_codec *codec) |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 292 | { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 293 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 294 | const struct hda_amp_list *p; |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 295 | int ch, v; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 296 | |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 297 | p = spec->gen.loopback.amplist; |
| 298 | if (!p) |
| 299 | return true; |
| 300 | for (; p->nid; p++) { |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 301 | for (ch = 0; ch < 2; ch++) { |
| 302 | v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, |
| 303 | p->idx); |
| 304 | if (!(v & HDA_AMP_MUTE) && v > 0) |
| 305 | return false; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 306 | } |
| 307 | } |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 308 | return true; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /* enter/exit analog low-current mode */ |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 312 | static void __analog_low_current_mode(struct hda_codec *codec, bool force) |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 313 | { |
| 314 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 315 | bool enable; |
| 316 | unsigned int verb, parm; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 317 | |
Takashi Iwai | 967b130 | 2015-03-20 18:21:03 +0100 | [diff] [blame] | 318 | if (!codec->power_save_node) |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 319 | enable = false; |
| 320 | else |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 321 | enable = is_aa_path_mute(codec) && !spec->gen.active_streams; |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 322 | if (enable == spec->alc_mode && !force) |
| 323 | return; |
| 324 | spec->alc_mode = enable; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 325 | |
| 326 | /* decide low current mode's verb & parameter */ |
| 327 | switch (spec->codec_type) { |
| 328 | case VT1708B_8CH: |
| 329 | case VT1708B_4CH: |
| 330 | verb = 0xf70; |
| 331 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 332 | break; |
| 333 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 334 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 335 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 336 | verb = 0xf73; |
| 337 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 338 | break; |
| 339 | case VT1702: |
| 340 | verb = 0xf73; |
| 341 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 342 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 343 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 344 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 345 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 346 | verb = 0xf93; |
| 347 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 348 | break; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 349 | case VT1705CF: |
Lydia Wang | 6121b84 | 2012-12-10 19:03:26 +0800 | [diff] [blame] | 350 | case VT1808: |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 351 | verb = 0xf82; |
| 352 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 353 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 354 | default: |
| 355 | return; /* other codecs are not supported */ |
| 356 | } |
| 357 | /* send verb */ |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 358 | snd_hda_codec_write(codec, codec->core.afg, 0, verb, parm); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 359 | } |
| 360 | |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 361 | static void analog_low_current_mode(struct hda_codec *codec) |
| 362 | { |
| 363 | return __analog_low_current_mode(codec, false); |
| 364 | } |
| 365 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 366 | static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo, |
| 367 | struct hda_codec *codec, |
| 368 | struct snd_pcm_substream *substream, |
| 369 | int action) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 370 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 371 | analog_low_current_mode(codec); |
| 372 | vt1708_update_hp_work(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static void via_free(struct hda_codec *codec) |
| 376 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 377 | vt1708_stop_hp_work(codec); |
Takashi Iwai | a8dca46 | 2014-02-10 18:23:57 +0100 | [diff] [blame] | 378 | snd_hda_gen_free(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 379 | } |
| 380 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 381 | #ifdef CONFIG_PM |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 382 | static int via_suspend(struct hda_codec *codec) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 383 | { |
| 384 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 385 | vt1708_stop_hp_work(codec); |
David Henningsson | 94c142a | 2012-08-09 10:56:12 +0200 | [diff] [blame] | 386 | |
Takashi Iwai | 2c38d99 | 2013-06-05 15:25:18 +0200 | [diff] [blame] | 387 | /* Fix pop noise on headphones */ |
| 388 | if (spec->codec_type == VT1802) |
| 389 | snd_hda_shutup_pins(codec); |
David Henningsson | 94c142a | 2012-08-09 10:56:12 +0200 | [diff] [blame] | 390 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 391 | return 0; |
| 392 | } |
Takashi Iwai | 6b6d000 | 2015-05-31 09:27:29 +0200 | [diff] [blame] | 393 | |
| 394 | static int via_resume(struct hda_codec *codec) |
| 395 | { |
| 396 | /* some delay here to make jack detection working (bko#98921) */ |
| 397 | msleep(10); |
| 398 | codec->patch_ops.init(codec); |
| 399 | regcache_sync(codec->core.regmap); |
| 400 | return 0; |
| 401 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 402 | #endif |
| 403 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 404 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 405 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 406 | { |
| 407 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 408 | analog_low_current_mode(codec); |
| 409 | vt1708_update_hp_work(codec); |
| 410 | return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 411 | } |
| 412 | #endif |
| 413 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 414 | /* |
| 415 | */ |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 416 | |
| 417 | static int via_init(struct hda_codec *codec); |
| 418 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 419 | static const struct hda_codec_ops via_patch_ops = { |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 420 | .build_controls = snd_hda_gen_build_controls, |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 421 | .build_pcms = snd_hda_gen_build_pcms, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 422 | .init = via_init, |
| 423 | .free = via_free, |
David Henningsson | 4e2d16d | 2012-10-08 15:44:14 +0200 | [diff] [blame] | 424 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 425 | #ifdef CONFIG_PM |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 426 | .suspend = via_suspend, |
Takashi Iwai | 6b6d000 | 2015-05-31 09:27:29 +0200 | [diff] [blame] | 427 | .resume = via_resume, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 428 | .check_power_status = via_check_power_status, |
| 429 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 430 | }; |
| 431 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 432 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 433 | static const struct hda_verb vt1708_init_verbs[] = { |
| 434 | /* power down jack detect function */ |
| 435 | {0x1, 0xf81, 0x1}, |
| 436 | { } |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 437 | }; |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 438 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 439 | { |
| 440 | unsigned int def_conf; |
| 441 | unsigned char seqassoc; |
| 442 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 443 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 444 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 445 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 446 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 447 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 448 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 449 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | return; |
| 453 | } |
| 454 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 455 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 456 | struct snd_ctl_elem_value *ucontrol) |
| 457 | { |
| 458 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 459 | struct via_spec *spec = codec->spec; |
| 460 | |
| 461 | if (spec->codec_type != VT1708) |
| 462 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 463 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 464 | return 0; |
| 465 | } |
| 466 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 467 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 468 | struct snd_ctl_elem_value *ucontrol) |
| 469 | { |
| 470 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 471 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 472 | int val; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 473 | |
| 474 | if (spec->codec_type != VT1708) |
| 475 | return 0; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 476 | val = !!ucontrol->value.integer.value[0]; |
| 477 | if (spec->vt1708_jack_detect == val) |
| 478 | return 0; |
| 479 | spec->vt1708_jack_detect = val; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 480 | vt1708_update_hp_work(codec); |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 481 | return 1; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 482 | } |
| 483 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 484 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 485 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 486 | .name = "Jack Detect", |
| 487 | .count = 1, |
| 488 | .info = snd_ctl_boolean_mono_info, |
| 489 | .get = vt1708_jack_detect_get, |
| 490 | .put = vt1708_jack_detect_put, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 491 | }; |
| 492 | |
Takashi Iwai | 4abdbd1 | 2013-03-22 15:11:07 +0100 | [diff] [blame] | 493 | static const struct badness_table via_main_out_badness = { |
| 494 | .no_primary_dac = 0x10000, |
| 495 | .no_dac = 0x4000, |
| 496 | .shared_primary = 0x10000, |
| 497 | .shared_surr = 0x20, |
| 498 | .shared_clfe = 0x20, |
| 499 | .shared_surr_main = 0x20, |
| 500 | }; |
| 501 | static const struct badness_table via_extra_out_badness = { |
| 502 | .no_primary_dac = 0x4000, |
| 503 | .no_dac = 0x4000, |
| 504 | .shared_primary = 0x12, |
| 505 | .shared_surr = 0x20, |
| 506 | .shared_clfe = 0x20, |
| 507 | .shared_surr_main = 0x10, |
| 508 | }; |
| 509 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 510 | static int via_parse_auto_config(struct hda_codec *codec) |
| 511 | { |
| 512 | struct via_spec *spec = codec->spec; |
| 513 | int err; |
| 514 | |
Takashi Iwai | 4abdbd1 | 2013-03-22 15:11:07 +0100 | [diff] [blame] | 515 | spec->gen.main_out_badness = &via_main_out_badness; |
| 516 | spec->gen.extra_out_badness = &via_extra_out_badness; |
| 517 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 518 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
| 519 | if (err < 0) |
| 520 | return err; |
| 521 | |
| 522 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
| 523 | if (err < 0) |
| 524 | return err; |
| 525 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 526 | err = auto_parse_beep(codec); |
| 527 | if (err < 0) |
| 528 | return err; |
| 529 | |
| 530 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &via_pin_power_ctl_enum)) |
| 531 | return -ENOMEM; |
| 532 | |
Takashi Iwai | 688b12c | 2015-03-17 15:56:05 +0100 | [diff] [blame] | 533 | /* disable widget PM at start for compatibility */ |
Takashi Iwai | 967b130 | 2015-03-20 18:21:03 +0100 | [diff] [blame] | 534 | codec->power_save_node = 0; |
Takashi Iwai | 688b12c | 2015-03-17 15:56:05 +0100 | [diff] [blame] | 535 | spec->gen.power_down_unused = 0; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 536 | return 0; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 537 | } |
| 538 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 539 | static int via_init(struct hda_codec *codec) |
| 540 | { |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 541 | /* init power states */ |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 542 | __analog_low_current_mode(codec, true); |
| 543 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 544 | snd_hda_gen_init(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 545 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 546 | vt1708_update_hp_work(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 547 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
David Henningsson | f672f65 | 2013-02-05 12:06:02 +0100 | [diff] [blame] | 551 | static int vt1708_build_controls(struct hda_codec *codec) |
| 552 | { |
| 553 | /* In order not to create "Phantom Jack" controls, |
| 554 | temporary enable jackpoll */ |
| 555 | int err; |
| 556 | int old_interval = codec->jackpoll_interval; |
| 557 | codec->jackpoll_interval = msecs_to_jiffies(100); |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 558 | err = snd_hda_gen_build_controls(codec); |
David Henningsson | f672f65 | 2013-02-05 12:06:02 +0100 | [diff] [blame] | 559 | codec->jackpoll_interval = old_interval; |
| 560 | return err; |
| 561 | } |
| 562 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 563 | static int vt1708_build_pcms(struct hda_codec *codec) |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 564 | { |
| 565 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 566 | int i, err; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 567 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 568 | err = snd_hda_gen_build_pcms(codec); |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 569 | if (err < 0 || codec->core.vendor_id != 0x11061708) |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 570 | return err; |
| 571 | |
| 572 | /* We got noisy outputs on the right channel on VT1708 when |
| 573 | * 24bit samples are used. Until any workaround is found, |
| 574 | * disable the 24bit format, so far. |
| 575 | */ |
Takashi Iwai | bbbc7e8 | 2015-02-27 17:43:19 +0100 | [diff] [blame] | 576 | for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) { |
| 577 | struct hda_pcm *info = spec->gen.pcm_rec[i]; |
| 578 | if (!info) |
| 579 | continue; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 580 | if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || |
| 581 | info->pcm_type != HDA_PCM_TYPE_AUDIO) |
| 582 | continue; |
| 583 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats = |
| 584 | SNDRV_PCM_FMTBIT_S16_LE; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 585 | } |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 586 | |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 587 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 590 | static int patch_vt1708(struct hda_codec *codec) |
| 591 | { |
| 592 | struct via_spec *spec; |
| 593 | int err; |
| 594 | |
| 595 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 596 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 597 | if (spec == NULL) |
| 598 | return -ENOMEM; |
| 599 | |
Takashi Iwai | 225068a | 2015-05-29 10:42:14 +0200 | [diff] [blame] | 600 | /* override some patch_ops */ |
| 601 | codec->patch_ops.build_controls = vt1708_build_controls; |
| 602 | codec->patch_ops.build_pcms = vt1708_build_pcms; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 603 | spec->gen.mixer_nid = 0x17; |
| 604 | |
| 605 | /* set jackpoll_interval while parsing the codec */ |
| 606 | codec->jackpoll_interval = msecs_to_jiffies(100); |
| 607 | spec->vt1708_jack_detect = 1; |
| 608 | |
| 609 | /* don't support the input jack switching due to lack of unsol event */ |
| 610 | /* (it may work with polling, though, but it needs testing) */ |
| 611 | spec->gen.suppress_auto_mic = 1; |
Takashi Iwai | eb33ccf | 2013-06-24 16:18:10 +0200 | [diff] [blame] | 612 | /* Some machines show the broken speaker mute */ |
| 613 | spec->gen.auto_mute_via_amp = 1; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 614 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 615 | /* Add HP and CD pin config connect bit re-config action */ |
| 616 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 617 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 618 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 619 | err = snd_hda_add_verbs(codec, vt1708_init_verbs); |
| 620 | if (err < 0) |
| 621 | goto error; |
| 622 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 623 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 624 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 625 | if (err < 0) |
| 626 | goto error; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 627 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 628 | /* add jack detect on/off control */ |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 629 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1708_jack_detect_ctl)) { |
| 630 | err = -ENOMEM; |
| 631 | goto error; |
| 632 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 633 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 634 | /* clear jackpoll_interval again; it's set dynamically */ |
| 635 | codec->jackpoll_interval = 0; |
| 636 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 637 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 638 | |
| 639 | error: |
| 640 | via_free(codec); |
| 641 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 642 | } |
| 643 | |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 644 | static int patch_vt1709(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 645 | { |
| 646 | struct via_spec *spec; |
| 647 | int err; |
| 648 | |
| 649 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 650 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 651 | if (spec == NULL) |
| 652 | return -ENOMEM; |
| 653 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 654 | spec->gen.mixer_nid = 0x18; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 655 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 656 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 657 | if (err < 0) |
| 658 | goto error; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 659 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 660 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 661 | |
| 662 | error: |
| 663 | via_free(codec); |
| 664 | return err; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 667 | static int patch_vt1708S(struct hda_codec *codec); |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 668 | static int patch_vt1708B(struct hda_codec *codec) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 669 | { |
| 670 | struct via_spec *spec; |
| 671 | int err; |
| 672 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 673 | if (get_codec_type(codec) == VT1708BCE) |
| 674 | return patch_vt1708S(codec); |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 675 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 676 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 677 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 678 | if (spec == NULL) |
| 679 | return -ENOMEM; |
| 680 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 681 | spec->gen.mixer_nid = 0x16; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 682 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 683 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 684 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 685 | if (err < 0) |
| 686 | goto error; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 687 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 688 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 689 | |
| 690 | error: |
| 691 | via_free(codec); |
| 692 | return err; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 693 | } |
| 694 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 695 | /* Patch for VT1708S */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 696 | static const struct hda_verb vt1708S_init_verbs[] = { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 697 | /* Enable Mic Boost Volume backdoor */ |
| 698 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 699 | /* don't bybass mixer */ |
| 700 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 701 | { } |
| 702 | }; |
| 703 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 704 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 705 | int offset, int num_steps, int step_size) |
| 706 | { |
Takashi Iwai | d045c5d | 2013-06-19 07:54:09 +0200 | [diff] [blame] | 707 | snd_hda_override_wcaps(codec, pin, |
| 708 | get_wcaps(codec, pin) | AC_WCAP_IN_AMP); |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 709 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 710 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 711 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 712 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 713 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 714 | } |
| 715 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 716 | static int patch_vt1708S(struct hda_codec *codec) |
| 717 | { |
| 718 | struct via_spec *spec; |
| 719 | int err; |
| 720 | |
| 721 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 722 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 723 | if (spec == NULL) |
| 724 | return -ENOMEM; |
| 725 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 726 | spec->gen.mixer_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 727 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 728 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 729 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 730 | /* correct names for VT1708BCE */ |
Takashi Iwai | ded255b | 2015-10-01 17:59:43 +0200 | [diff] [blame] | 731 | if (get_codec_type(codec) == VT1708BCE) |
| 732 | snd_hda_codec_set_name(codec, "VT1708BCE"); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 733 | /* correct names for VT1705 */ |
Takashi Iwai | ded255b | 2015-10-01 17:59:43 +0200 | [diff] [blame] | 734 | if (codec->core.vendor_id == 0x11064397) |
| 735 | snd_hda_codec_set_name(codec, "VT1705"); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 736 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 737 | err = snd_hda_add_verbs(codec, vt1708S_init_verbs); |
| 738 | if (err < 0) |
| 739 | goto error; |
| 740 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 741 | /* automatic parse from the BIOS config */ |
| 742 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 743 | if (err < 0) |
| 744 | goto error; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 745 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 746 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 747 | |
| 748 | error: |
| 749 | via_free(codec); |
| 750 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /* Patch for VT1702 */ |
| 754 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 755 | static const struct hda_verb vt1702_init_verbs[] = { |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 756 | /* mixer enable */ |
| 757 | {0x1, 0xF88, 0x3}, |
| 758 | /* GPIO 0~2 */ |
| 759 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 760 | { } |
| 761 | }; |
| 762 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 763 | static int patch_vt1702(struct hda_codec *codec) |
| 764 | { |
| 765 | struct via_spec *spec; |
| 766 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 767 | |
| 768 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 769 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 770 | if (spec == NULL) |
| 771 | return -ENOMEM; |
| 772 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 773 | spec->gen.mixer_nid = 0x1a; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 774 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 775 | /* limit AA path volume to 0 dB */ |
| 776 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 777 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 778 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 779 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 780 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 781 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 782 | err = snd_hda_add_verbs(codec, vt1702_init_verbs); |
| 783 | if (err < 0) |
| 784 | goto error; |
| 785 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 786 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 787 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 788 | if (err < 0) |
| 789 | goto error; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 790 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 791 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 792 | |
| 793 | error: |
| 794 | via_free(codec); |
| 795 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 796 | } |
| 797 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 798 | /* Patch for VT1718S */ |
| 799 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 800 | static const struct hda_verb vt1718S_init_verbs[] = { |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 801 | /* Enable MW0 adjust Gain 5 */ |
| 802 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 803 | /* Enable Boost Volume backdoor */ |
| 804 | {0x1, 0xf88, 0x8}, |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 805 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 806 | { } |
| 807 | }; |
| 808 | |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 809 | /* Add a connection to the primary DAC from AA-mixer for some codecs |
| 810 | * This isn't listed from the raw info, but the chip has a secret connection. |
| 811 | */ |
| 812 | static int add_secret_dac_path(struct hda_codec *codec) |
| 813 | { |
| 814 | struct via_spec *spec = codec->spec; |
| 815 | int i, nums; |
| 816 | hda_nid_t conn[8]; |
| 817 | hda_nid_t nid; |
| 818 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 819 | if (!spec->gen.mixer_nid) |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 820 | return 0; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 821 | nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn, |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 822 | ARRAY_SIZE(conn) - 1); |
| 823 | for (i = 0; i < nums; i++) { |
| 824 | if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT) |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | /* find the primary DAC and add to the connection list */ |
Takashi Iwai | 7639a06 | 2015-03-03 10:07:24 +0100 | [diff] [blame] | 829 | for_each_hda_codec_node(nid, codec) { |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 830 | unsigned int caps = get_wcaps(codec, nid); |
| 831 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT && |
| 832 | !(caps & AC_WCAP_DIGITAL)) { |
| 833 | conn[nums++] = nid; |
| 834 | return snd_hda_override_conn_list(codec, |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 835 | spec->gen.mixer_nid, |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 836 | nums, conn); |
| 837 | } |
| 838 | } |
| 839 | return 0; |
| 840 | } |
| 841 | |
| 842 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 843 | static int patch_vt1718S(struct hda_codec *codec) |
| 844 | { |
| 845 | struct via_spec *spec; |
| 846 | int err; |
| 847 | |
| 848 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 849 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 850 | if (spec == NULL) |
| 851 | return -ENOMEM; |
| 852 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 853 | spec->gen.mixer_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 854 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 855 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 856 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 857 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 858 | err = snd_hda_add_verbs(codec, vt1718S_init_verbs); |
| 859 | if (err < 0) |
| 860 | goto error; |
| 861 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 862 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 863 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 864 | if (err < 0) |
| 865 | goto error; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 866 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 867 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 868 | |
| 869 | error: |
| 870 | via_free(codec); |
| 871 | return err; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 872 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 873 | |
| 874 | /* Patch for VT1716S */ |
| 875 | |
| 876 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 877 | struct snd_ctl_elem_info *uinfo) |
| 878 | { |
| 879 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 880 | uinfo->count = 1; |
| 881 | uinfo->value.integer.min = 0; |
| 882 | uinfo->value.integer.max = 1; |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 887 | struct snd_ctl_elem_value *ucontrol) |
| 888 | { |
| 889 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 890 | int index = 0; |
| 891 | |
| 892 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 893 | AC_VERB_GET_CONNECT_SEL, 0); |
| 894 | if (index != -1) |
| 895 | *ucontrol->value.integer.value = index; |
| 896 | |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 901 | struct snd_ctl_elem_value *ucontrol) |
| 902 | { |
| 903 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 904 | struct via_spec *spec = codec->spec; |
| 905 | int index = *ucontrol->value.integer.value; |
| 906 | |
| 907 | snd_hda_codec_write(codec, 0x26, 0, |
| 908 | AC_VERB_SET_CONNECT_SEL, index); |
| 909 | spec->dmic_enabled = index; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 910 | return 1; |
| 911 | } |
| 912 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 913 | static const struct snd_kcontrol_new vt1716s_dmic_mixer_vol = |
| 914 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT); |
| 915 | static const struct snd_kcontrol_new vt1716s_dmic_mixer_sw = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 916 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 917 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 918 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 919 | .count = 1, |
| 920 | .info = vt1716s_dmic_info, |
| 921 | .get = vt1716s_dmic_get, |
| 922 | .put = vt1716s_dmic_put, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 923 | }; |
| 924 | |
| 925 | |
| 926 | /* mono-out mixer elements */ |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 927 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer = |
| 928 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 929 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 930 | static const struct hda_verb vt1716S_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 931 | /* Enable Boost Volume backdoor */ |
| 932 | {0x1, 0xf8a, 0x80}, |
| 933 | /* don't bybass mixer */ |
| 934 | {0x1, 0xf88, 0xc0}, |
| 935 | /* Enable mono output */ |
| 936 | {0x1, 0xf90, 0x08}, |
| 937 | { } |
| 938 | }; |
| 939 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 940 | static int patch_vt1716S(struct hda_codec *codec) |
| 941 | { |
| 942 | struct via_spec *spec; |
| 943 | int err; |
| 944 | |
| 945 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 946 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 947 | if (spec == NULL) |
| 948 | return -ENOMEM; |
| 949 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 950 | spec->gen.mixer_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 951 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 952 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 953 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 954 | err = snd_hda_add_verbs(codec, vt1716S_init_verbs); |
| 955 | if (err < 0) |
| 956 | goto error; |
| 957 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 958 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 959 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 960 | if (err < 0) |
| 961 | goto error; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 962 | |
Takashi Iwai | 0e8f986 | 2018-06-20 17:20:42 +0200 | [diff] [blame] | 963 | if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716s_dmic_mixer_vol) || |
| 964 | !snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716s_dmic_mixer_sw) || |
| 965 | !snd_hda_gen_add_kctl(&spec->gen, NULL, &vt1716S_mono_out_mixer)) { |
| 966 | err = -ENOMEM; |
| 967 | goto error; |
| 968 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 969 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 970 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 971 | |
| 972 | error: |
| 973 | via_free(codec); |
| 974 | return err; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 975 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 976 | |
| 977 | /* for vt2002P */ |
| 978 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 979 | static const struct hda_verb vt2002P_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 980 | /* Class-D speaker related verbs */ |
| 981 | {0x1, 0xfe0, 0x4}, |
| 982 | {0x1, 0xfe9, 0x80}, |
| 983 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 984 | /* Enable Boost Volume backdoor */ |
| 985 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 986 | /* Enable AOW0 to MW9 */ |
| 987 | {0x1, 0xfb8, 0x88}, |
| 988 | { } |
| 989 | }; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 990 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 991 | static const struct hda_verb vt1802_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 992 | /* Enable Boost Volume backdoor */ |
| 993 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 994 | /* Enable AOW0 to MW9 */ |
| 995 | {0x1, 0xfb8, 0x88}, |
| 996 | { } |
| 997 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 998 | |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 999 | /* |
| 1000 | * pin fix-up |
| 1001 | */ |
| 1002 | enum { |
| 1003 | VIA_FIXUP_INTMIC_BOOST, |
Takashi Iwai | d526612 | 2012-11-07 10:40:36 +0100 | [diff] [blame] | 1004 | VIA_FIXUP_ASUS_G75, |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1005 | }; |
| 1006 | |
| 1007 | static void via_fixup_intmic_boost(struct hda_codec *codec, |
| 1008 | const struct hda_fixup *fix, int action) |
| 1009 | { |
| 1010 | if (action == HDA_FIXUP_ACT_PRE_PROBE) |
| 1011 | override_mic_boost(codec, 0x30, 0, 2, 40); |
| 1012 | } |
| 1013 | |
| 1014 | static const struct hda_fixup via_fixups[] = { |
| 1015 | [VIA_FIXUP_INTMIC_BOOST] = { |
| 1016 | .type = HDA_FIXUP_FUNC, |
| 1017 | .v.func = via_fixup_intmic_boost, |
| 1018 | }, |
Takashi Iwai | d526612 | 2012-11-07 10:40:36 +0100 | [diff] [blame] | 1019 | [VIA_FIXUP_ASUS_G75] = { |
| 1020 | .type = HDA_FIXUP_PINS, |
| 1021 | .v.pins = (const struct hda_pintbl[]) { |
| 1022 | /* set 0x24 and 0x33 as speakers */ |
| 1023 | { 0x24, 0x991301f0 }, |
| 1024 | { 0x33, 0x991301f1 }, /* subwoofer */ |
| 1025 | { } |
| 1026 | } |
| 1027 | }, |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1028 | }; |
| 1029 | |
| 1030 | static const struct snd_pci_quirk vt2002p_fixups[] = { |
Takashi Iwai | d526612 | 2012-11-07 10:40:36 +0100 | [diff] [blame] | 1031 | SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75), |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1032 | SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST), |
| 1033 | {} |
| 1034 | }; |
| 1035 | |
Takashi Iwai | ef4da45 | 2012-11-07 10:37:48 +0100 | [diff] [blame] | 1036 | /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e |
| 1037 | * Replace this with mixer NID 0x1c |
| 1038 | */ |
| 1039 | static void fix_vt1802_connections(struct hda_codec *codec) |
| 1040 | { |
| 1041 | static hda_nid_t conn_24[] = { 0x14, 0x1c }; |
| 1042 | static hda_nid_t conn_33[] = { 0x1c }; |
| 1043 | |
| 1044 | snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24); |
| 1045 | snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33); |
| 1046 | } |
| 1047 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1048 | /* patch for vt2002P */ |
| 1049 | static int patch_vt2002P(struct hda_codec *codec) |
| 1050 | { |
| 1051 | struct via_spec *spec; |
| 1052 | int err; |
| 1053 | |
| 1054 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1055 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1056 | if (spec == NULL) |
| 1057 | return -ENOMEM; |
| 1058 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1059 | spec->gen.mixer_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1060 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 1061 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | ef4da45 | 2012-11-07 10:37:48 +0100 | [diff] [blame] | 1062 | if (spec->codec_type == VT1802) |
| 1063 | fix_vt1802_connections(codec); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1064 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1065 | |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1066 | snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups); |
| 1067 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
| 1068 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 1069 | if (spec->codec_type == VT1802) |
| 1070 | err = snd_hda_add_verbs(codec, vt1802_init_verbs); |
| 1071 | else |
| 1072 | err = snd_hda_add_verbs(codec, vt2002P_init_verbs); |
| 1073 | if (err < 0) |
| 1074 | goto error; |
| 1075 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1076 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1077 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 1078 | if (err < 0) |
| 1079 | goto error; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1080 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1081 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 1082 | |
| 1083 | error: |
| 1084 | via_free(codec); |
| 1085 | return err; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1086 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1087 | |
| 1088 | /* for vt1812 */ |
| 1089 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1090 | static const struct hda_verb vt1812_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1091 | /* Enable Boost Volume backdoor */ |
| 1092 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1093 | /* Enable AOW0 to MW9 */ |
| 1094 | {0x1, 0xfb8, 0xa8}, |
| 1095 | { } |
| 1096 | }; |
| 1097 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1098 | /* patch for vt1812 */ |
| 1099 | static int patch_vt1812(struct hda_codec *codec) |
| 1100 | { |
| 1101 | struct via_spec *spec; |
| 1102 | int err; |
| 1103 | |
| 1104 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1105 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1106 | if (spec == NULL) |
| 1107 | return -ENOMEM; |
| 1108 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1109 | spec->gen.mixer_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1110 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 1111 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1112 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1113 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 1114 | err = snd_hda_add_verbs(codec, vt1812_init_verbs); |
| 1115 | if (err < 0) |
| 1116 | goto error; |
| 1117 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1118 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1119 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 1120 | if (err < 0) |
| 1121 | goto error; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1122 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1123 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 1124 | |
| 1125 | error: |
| 1126 | via_free(codec); |
| 1127 | return err; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1128 | } |
| 1129 | |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1130 | /* patch for vt3476 */ |
| 1131 | |
| 1132 | static const struct hda_verb vt3476_init_verbs[] = { |
| 1133 | /* Enable DMic 8/16/32K */ |
| 1134 | {0x1, 0xF7B, 0x30}, |
| 1135 | /* Enable Boost Volume backdoor */ |
| 1136 | {0x1, 0xFB9, 0x20}, |
| 1137 | /* Enable AOW-MW9 path */ |
| 1138 | {0x1, 0xFB8, 0x10}, |
| 1139 | { } |
| 1140 | }; |
| 1141 | |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1142 | static int patch_vt3476(struct hda_codec *codec) |
| 1143 | { |
| 1144 | struct via_spec *spec; |
| 1145 | int err; |
| 1146 | |
| 1147 | /* create a codec specific record */ |
| 1148 | spec = via_new_spec(codec); |
| 1149 | if (spec == NULL) |
| 1150 | return -ENOMEM; |
| 1151 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1152 | spec->gen.mixer_nid = 0x3f; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1153 | add_secret_dac_path(codec); |
| 1154 | |
Takashi Iwai | f8bfc62 | 2018-06-20 17:27:50 +0200 | [diff] [blame] | 1155 | err = snd_hda_add_verbs(codec, vt3476_init_verbs); |
| 1156 | if (err < 0) |
| 1157 | goto error; |
| 1158 | |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1159 | /* automatic parse from the BIOS config */ |
| 1160 | err = via_parse_auto_config(codec); |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 1161 | if (err < 0) |
| 1162 | goto error; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1163 | |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1164 | return 0; |
Takashi Iwai | fcbdcc1 | 2018-06-20 22:36:17 +0200 | [diff] [blame] | 1165 | |
| 1166 | error: |
| 1167 | via_free(codec); |
| 1168 | return err; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1171 | /* |
| 1172 | * patch entries |
| 1173 | */ |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 1174 | static const struct hda_device_id snd_hda_id_via[] = { |
| 1175 | HDA_CODEC_ENTRY(0x11061708, "VT1708", patch_vt1708), |
| 1176 | HDA_CODEC_ENTRY(0x11061709, "VT1708", patch_vt1708), |
| 1177 | HDA_CODEC_ENTRY(0x1106170a, "VT1708", patch_vt1708), |
| 1178 | HDA_CODEC_ENTRY(0x1106170b, "VT1708", patch_vt1708), |
| 1179 | HDA_CODEC_ENTRY(0x1106e710, "VT1709 10-Ch", patch_vt1709), |
| 1180 | HDA_CODEC_ENTRY(0x1106e711, "VT1709 10-Ch", patch_vt1709), |
| 1181 | HDA_CODEC_ENTRY(0x1106e712, "VT1709 10-Ch", patch_vt1709), |
| 1182 | HDA_CODEC_ENTRY(0x1106e713, "VT1709 10-Ch", patch_vt1709), |
| 1183 | HDA_CODEC_ENTRY(0x1106e714, "VT1709 6-Ch", patch_vt1709), |
| 1184 | HDA_CODEC_ENTRY(0x1106e715, "VT1709 6-Ch", patch_vt1709), |
| 1185 | HDA_CODEC_ENTRY(0x1106e716, "VT1709 6-Ch", patch_vt1709), |
| 1186 | HDA_CODEC_ENTRY(0x1106e717, "VT1709 6-Ch", patch_vt1709), |
| 1187 | HDA_CODEC_ENTRY(0x1106e720, "VT1708B 8-Ch", patch_vt1708B), |
| 1188 | HDA_CODEC_ENTRY(0x1106e721, "VT1708B 8-Ch", patch_vt1708B), |
| 1189 | HDA_CODEC_ENTRY(0x1106e722, "VT1708B 8-Ch", patch_vt1708B), |
| 1190 | HDA_CODEC_ENTRY(0x1106e723, "VT1708B 8-Ch", patch_vt1708B), |
| 1191 | HDA_CODEC_ENTRY(0x1106e724, "VT1708B 4-Ch", patch_vt1708B), |
| 1192 | HDA_CODEC_ENTRY(0x1106e725, "VT1708B 4-Ch", patch_vt1708B), |
| 1193 | HDA_CODEC_ENTRY(0x1106e726, "VT1708B 4-Ch", patch_vt1708B), |
| 1194 | HDA_CODEC_ENTRY(0x1106e727, "VT1708B 4-Ch", patch_vt1708B), |
| 1195 | HDA_CODEC_ENTRY(0x11060397, "VT1708S", patch_vt1708S), |
| 1196 | HDA_CODEC_ENTRY(0x11061397, "VT1708S", patch_vt1708S), |
| 1197 | HDA_CODEC_ENTRY(0x11062397, "VT1708S", patch_vt1708S), |
| 1198 | HDA_CODEC_ENTRY(0x11063397, "VT1708S", patch_vt1708S), |
| 1199 | HDA_CODEC_ENTRY(0x11064397, "VT1705", patch_vt1708S), |
| 1200 | HDA_CODEC_ENTRY(0x11065397, "VT1708S", patch_vt1708S), |
| 1201 | HDA_CODEC_ENTRY(0x11066397, "VT1708S", patch_vt1708S), |
| 1202 | HDA_CODEC_ENTRY(0x11067397, "VT1708S", patch_vt1708S), |
| 1203 | HDA_CODEC_ENTRY(0x11060398, "VT1702", patch_vt1702), |
| 1204 | HDA_CODEC_ENTRY(0x11061398, "VT1702", patch_vt1702), |
| 1205 | HDA_CODEC_ENTRY(0x11062398, "VT1702", patch_vt1702), |
| 1206 | HDA_CODEC_ENTRY(0x11063398, "VT1702", patch_vt1702), |
| 1207 | HDA_CODEC_ENTRY(0x11064398, "VT1702", patch_vt1702), |
| 1208 | HDA_CODEC_ENTRY(0x11065398, "VT1702", patch_vt1702), |
| 1209 | HDA_CODEC_ENTRY(0x11066398, "VT1702", patch_vt1702), |
| 1210 | HDA_CODEC_ENTRY(0x11067398, "VT1702", patch_vt1702), |
| 1211 | HDA_CODEC_ENTRY(0x11060428, "VT1718S", patch_vt1718S), |
| 1212 | HDA_CODEC_ENTRY(0x11064428, "VT1718S", patch_vt1718S), |
| 1213 | HDA_CODEC_ENTRY(0x11060441, "VT2020", patch_vt1718S), |
| 1214 | HDA_CODEC_ENTRY(0x11064441, "VT1828S", patch_vt1718S), |
| 1215 | HDA_CODEC_ENTRY(0x11060433, "VT1716S", patch_vt1716S), |
| 1216 | HDA_CODEC_ENTRY(0x1106a721, "VT1716S", patch_vt1716S), |
| 1217 | HDA_CODEC_ENTRY(0x11060438, "VT2002P", patch_vt2002P), |
| 1218 | HDA_CODEC_ENTRY(0x11064438, "VT2002P", patch_vt2002P), |
| 1219 | HDA_CODEC_ENTRY(0x11060448, "VT1812", patch_vt1812), |
| 1220 | HDA_CODEC_ENTRY(0x11060440, "VT1818S", patch_vt1708S), |
| 1221 | HDA_CODEC_ENTRY(0x11060446, "VT1802", patch_vt2002P), |
| 1222 | HDA_CODEC_ENTRY(0x11068446, "VT1802", patch_vt2002P), |
| 1223 | HDA_CODEC_ENTRY(0x11064760, "VT1705CF", patch_vt3476), |
| 1224 | HDA_CODEC_ENTRY(0x11064761, "VT1708SCE", patch_vt3476), |
| 1225 | HDA_CODEC_ENTRY(0x11064762, "VT1808", patch_vt3476), |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1226 | {} /* terminator */ |
| 1227 | }; |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 1228 | MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_via); |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1229 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1230 | static struct hda_codec_driver via_driver = { |
Takashi Iwai | b9a94a9 | 2015-10-01 16:20:04 +0200 | [diff] [blame] | 1231 | .id = snd_hda_id_via, |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1232 | }; |
| 1233 | |
| 1234 | MODULE_LICENSE("GPL"); |
| 1235 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 1236 | |
Takashi Iwai | d8a766a | 2015-02-17 15:25:37 +0100 | [diff] [blame] | 1237 | module_hda_codec_driver(via_driver); |