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