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; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 102 | unsigned int no_pin_power_ctl; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 103 | enum VIA_HDA_CODEC codec_type; |
| 104 | |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 105 | /* analog low-power control */ |
| 106 | bool alc_mode; |
| 107 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 108 | /* work to check hp jack state */ |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 109 | int hp_work_active; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 110 | int vt1708_jack_detect; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 111 | |
| 112 | void (*set_widgets_power_state)(struct hda_codec *codec); |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 113 | unsigned int dac_stream_tag[4]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 114 | }; |
| 115 | |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 116 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 117 | static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo, |
| 118 | struct hda_codec *codec, |
| 119 | struct snd_pcm_substream *substream, |
| 120 | int action); |
| 121 | static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl); |
| 122 | |
| 123 | static struct via_spec *via_new_spec(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 124 | { |
| 125 | struct via_spec *spec; |
| 126 | |
| 127 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 128 | if (spec == NULL) |
| 129 | return NULL; |
| 130 | |
| 131 | codec->spec = spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 132 | snd_hda_gen_spec_init(&spec->gen); |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 133 | spec->codec_type = get_codec_type(codec); |
| 134 | /* VT1708BCE & VT1708S are almost same */ |
| 135 | if (spec->codec_type == VT1708BCE) |
| 136 | spec->codec_type = VT1708S; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 137 | spec->no_pin_power_ctl = 1; |
Takashi Iwai | 1396117 | 2013-01-21 15:15:55 +0100 | [diff] [blame] | 138 | spec->gen.indep_hp = 1; |
Takashi Iwai | 05909d5c | 2013-05-31 19:55:54 +0200 | [diff] [blame] | 139 | spec->gen.keep_eapd_on = 1; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 140 | spec->gen.pcm_playback_hook = via_playback_pcm_hook; |
Takashi Iwai | f1e762d | 2013-12-09 16:02:24 +0100 | [diff] [blame] | 141 | spec->gen.add_stereo_mix_input = 1; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 142 | return spec; |
| 143 | } |
| 144 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 145 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 146 | { |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 147 | u32 vendor_id = codec->vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 148 | u16 ven_id = vendor_id >> 16; |
| 149 | u16 dev_id = vendor_id & 0xffff; |
| 150 | enum VIA_HDA_CODEC codec_type; |
| 151 | |
| 152 | /* get codec type */ |
| 153 | if (ven_id != 0x1106) |
| 154 | codec_type = UNKNOWN; |
| 155 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 156 | codec_type = VT1708; |
| 157 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 158 | codec_type = VT1709_10CH; |
| 159 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 160 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 161 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 162 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 163 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 164 | codec_type = VT1708BCE; |
| 165 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 166 | codec_type = VT1708B_4CH; |
| 167 | else if ((dev_id & 0xfff) == 0x397 |
| 168 | && (dev_id >> 12) < 8) |
| 169 | codec_type = VT1708S; |
| 170 | else if ((dev_id & 0xfff) == 0x398 |
| 171 | && (dev_id >> 12) < 8) |
| 172 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 173 | else if ((dev_id & 0xfff) == 0x428 |
| 174 | && (dev_id >> 12) < 8) |
| 175 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 176 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 177 | codec_type = VT1716S; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 178 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 179 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 180 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 181 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 182 | else if (dev_id == 0x0448) |
| 183 | codec_type = VT1812; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 184 | else if (dev_id == 0x0440) |
| 185 | codec_type = VT1708S; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 186 | else if ((dev_id & 0xfff) == 0x446) |
| 187 | codec_type = VT1802; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 188 | else if (dev_id == 0x4760) |
| 189 | codec_type = VT1705CF; |
Lydia Wang | 6121b84 | 2012-12-10 19:03:26 +0800 | [diff] [blame] | 190 | else if (dev_id == 0x4761 || dev_id == 0x4762) |
| 191 | codec_type = VT1808; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 192 | else |
| 193 | codec_type = UNKNOWN; |
| 194 | return codec_type; |
| 195 | }; |
| 196 | |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 197 | static void analog_low_current_mode(struct hda_codec *codec); |
| 198 | static bool is_aa_path_mute(struct hda_codec *codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 199 | |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 200 | #define hp_detect_with_aa(codec) \ |
| 201 | (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \ |
| 202 | !is_aa_path_mute(codec)) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 203 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 204 | static void vt1708_stop_hp_work(struct hda_codec *codec) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 205 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 206 | struct via_spec *spec = codec->spec; |
| 207 | if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 208 | return; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 209 | if (spec->hp_work_active) { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 210 | snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1); |
Wang Xingchao | 7eaa916 | 2013-07-25 23:34:44 -0400 | [diff] [blame] | 211 | codec->jackpoll_interval = 0; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 212 | cancel_delayed_work_sync(&codec->jackpoll_work); |
| 213 | spec->hp_work_active = false; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 217 | static void vt1708_update_hp_work(struct hda_codec *codec) |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 218 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 219 | struct via_spec *spec = codec->spec; |
| 220 | if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 221 | return; |
David Henningsson | 05dc0fc | 2013-02-05 12:06:03 +0100 | [diff] [blame] | 222 | if (spec->vt1708_jack_detect) { |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 223 | if (!spec->hp_work_active) { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 224 | codec->jackpoll_interval = msecs_to_jiffies(100); |
| 225 | snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); |
| 226 | queue_delayed_work(codec->bus->workq, |
| 227 | &codec->jackpoll_work, 0); |
| 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 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 234 | static void set_widgets_power_state(struct hda_codec *codec) |
| 235 | { |
Takashi Iwai | 087c2e3 | 2013-05-31 13:54:10 +0200 | [diff] [blame] | 236 | #if 0 /* FIXME: the assumed connections don't match always with the |
| 237 | * actual routes by the generic parser, so better to disable |
| 238 | * the control for safety. |
| 239 | */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 240 | struct via_spec *spec = codec->spec; |
| 241 | if (spec->set_widgets_power_state) |
| 242 | spec->set_widgets_power_state(codec); |
Takashi Iwai | 087c2e3 | 2013-05-31 13:54:10 +0200 | [diff] [blame] | 243 | #endif |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 244 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 245 | |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 246 | static void update_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 247 | unsigned int parm) |
| 248 | { |
Takashi Iwai | 9040d10 | 2013-01-24 17:47:17 +0100 | [diff] [blame] | 249 | if (snd_hda_check_power_state(codec, nid, parm)) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 250 | return; |
| 251 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 252 | } |
| 253 | |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 254 | static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 255 | unsigned int parm, unsigned int index) |
| 256 | { |
| 257 | struct via_spec *spec = codec->spec; |
| 258 | unsigned int format; |
Takashi Iwai | 9040d10 | 2013-01-24 17:47:17 +0100 | [diff] [blame] | 259 | |
| 260 | if (snd_hda_check_power_state(codec, nid, parm)) |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 261 | return; |
| 262 | format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); |
| 263 | if (format && (spec->dac_stream_tag[index] != format)) |
| 264 | spec->dac_stream_tag[index] = format; |
| 265 | |
| 266 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 267 | if (parm == AC_PWRST_D0) { |
| 268 | format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0); |
| 269 | if (!format && (spec->dac_stream_tag[index] != format)) |
| 270 | snd_hda_codec_write(codec, nid, 0, |
| 271 | AC_VERB_SET_CHANNEL_STREAMID, |
| 272 | spec->dac_stream_tag[index]); |
| 273 | } |
| 274 | } |
| 275 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 276 | static bool smart51_enabled(struct hda_codec *codec) |
| 277 | { |
| 278 | struct via_spec *spec = codec->spec; |
| 279 | return spec->gen.ext_channel_count > 2; |
| 280 | } |
| 281 | |
| 282 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) |
| 283 | { |
| 284 | struct via_spec *spec = codec->spec; |
| 285 | int i; |
| 286 | |
| 287 | for (i = 0; i < spec->gen.multi_ios; i++) |
| 288 | if (spec->gen.multi_io[i].pin == pin) |
| 289 | return true; |
| 290 | return false; |
| 291 | } |
| 292 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 293 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 294 | unsigned int *affected_parm) |
| 295 | { |
| 296 | unsigned parm; |
| 297 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 298 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) |
| 299 | >> AC_DEFCFG_MISC_SHIFT |
| 300 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 301 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 302 | unsigned present = 0; |
| 303 | |
| 304 | no_presence |= spec->no_pin_power_ctl; |
| 305 | if (!no_presence) |
| 306 | present = snd_hda_jack_detect(codec, nid); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 307 | if ((smart51_enabled(codec) && is_smart51_pins(codec, nid)) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 308 | || ((no_presence || present) |
| 309 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 310 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
| 311 | parm = AC_PWRST_D0; |
| 312 | } else |
| 313 | parm = AC_PWRST_D3; |
| 314 | |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 315 | update_power_state(codec, nid, parm); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 316 | } |
| 317 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 318 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
| 319 | struct snd_ctl_elem_info *uinfo) |
| 320 | { |
Takashi Iwai | dda415d | 2012-11-30 18:34:38 +0100 | [diff] [blame] | 321 | return snd_hda_enum_bool_helper_info(kcontrol, uinfo); |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, |
| 325 | struct snd_ctl_elem_value *ucontrol) |
| 326 | { |
| 327 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 328 | struct via_spec *spec = codec->spec; |
| 329 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, |
| 334 | struct snd_ctl_elem_value *ucontrol) |
| 335 | { |
| 336 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 337 | struct via_spec *spec = codec->spec; |
| 338 | unsigned int val = !ucontrol->value.enumerated.item[0]; |
| 339 | |
| 340 | if (val == spec->no_pin_power_ctl) |
| 341 | return 0; |
| 342 | spec->no_pin_power_ctl = val; |
| 343 | set_widgets_power_state(codec); |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 344 | analog_low_current_mode(codec); |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 345 | return 1; |
| 346 | } |
| 347 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 348 | static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = { |
| 349 | { |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 350 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 351 | .name = "Dynamic Power-Control", |
| 352 | .info = via_pin_power_ctl_info, |
| 353 | .get = via_pin_power_ctl_get, |
| 354 | .put = via_pin_power_ctl_put, |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 355 | }, |
| 356 | {} /* terminator */ |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 360 | /* check AA path's mute status */ |
| 361 | static bool is_aa_path_mute(struct hda_codec *codec) |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 362 | { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 363 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 364 | const struct hda_amp_list *p; |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 365 | int ch, v; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 366 | |
Takashi Iwai | 0186f4f | 2013-02-07 10:45:11 +0100 | [diff] [blame] | 367 | p = spec->gen.loopback.amplist; |
| 368 | if (!p) |
| 369 | return true; |
| 370 | for (; p->nid; p++) { |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 371 | for (ch = 0; ch < 2; ch++) { |
| 372 | v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, |
| 373 | p->idx); |
| 374 | if (!(v & HDA_AMP_MUTE) && v > 0) |
| 375 | return false; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 376 | } |
| 377 | } |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 378 | return true; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /* enter/exit analog low-current mode */ |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 382 | static void __analog_low_current_mode(struct hda_codec *codec, bool force) |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 383 | { |
| 384 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 385 | bool enable; |
| 386 | unsigned int verb, parm; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 387 | |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 388 | if (spec->no_pin_power_ctl) |
| 389 | enable = false; |
| 390 | else |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 391 | enable = is_aa_path_mute(codec) && !spec->gen.active_streams; |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 392 | if (enable == spec->alc_mode && !force) |
| 393 | return; |
| 394 | spec->alc_mode = enable; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 395 | |
| 396 | /* decide low current mode's verb & parameter */ |
| 397 | switch (spec->codec_type) { |
| 398 | case VT1708B_8CH: |
| 399 | case VT1708B_4CH: |
| 400 | verb = 0xf70; |
| 401 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 402 | break; |
| 403 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 404 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 405 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 406 | verb = 0xf73; |
| 407 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 408 | break; |
| 409 | case VT1702: |
| 410 | verb = 0xf73; |
| 411 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 412 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 413 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 414 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 415 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 416 | verb = 0xf93; |
| 417 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 418 | break; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 419 | case VT1705CF: |
Lydia Wang | 6121b84 | 2012-12-10 19:03:26 +0800 | [diff] [blame] | 420 | case VT1808: |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 421 | verb = 0xf82; |
| 422 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 423 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 424 | default: |
| 425 | return; /* other codecs are not supported */ |
| 426 | } |
| 427 | /* send verb */ |
| 428 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); |
| 429 | } |
| 430 | |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 431 | static void analog_low_current_mode(struct hda_codec *codec) |
| 432 | { |
| 433 | return __analog_low_current_mode(codec, false); |
| 434 | } |
| 435 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 436 | static int via_build_controls(struct hda_codec *codec) |
| 437 | { |
| 438 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 439 | int err, i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 440 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 441 | err = snd_hda_gen_build_controls(codec); |
| 442 | if (err < 0) |
| 443 | return err; |
| 444 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 445 | if (spec->set_widgets_power_state) |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 446 | spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 447 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 448 | for (i = 0; i < spec->num_mixers; i++) { |
| 449 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 450 | if (err < 0) |
| 451 | return err; |
| 452 | } |
| 453 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 457 | static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo, |
| 458 | struct hda_codec *codec, |
| 459 | struct snd_pcm_substream *substream, |
| 460 | int action) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 461 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 462 | analog_low_current_mode(codec); |
| 463 | vt1708_update_hp_work(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void via_free(struct hda_codec *codec) |
| 467 | { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 468 | vt1708_stop_hp_work(codec); |
Takashi Iwai | a8dca46 | 2014-02-10 18:23:57 +0100 | [diff] [blame^] | 469 | snd_hda_gen_free(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 470 | } |
| 471 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 472 | #ifdef CONFIG_PM |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 473 | static int via_suspend(struct hda_codec *codec) |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 474 | { |
| 475 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 476 | vt1708_stop_hp_work(codec); |
David Henningsson | 94c142a | 2012-08-09 10:56:12 +0200 | [diff] [blame] | 477 | |
Takashi Iwai | 2c38d99 | 2013-06-05 15:25:18 +0200 | [diff] [blame] | 478 | /* Fix pop noise on headphones */ |
| 479 | if (spec->codec_type == VT1802) |
| 480 | snd_hda_shutup_pins(codec); |
David Henningsson | 94c142a | 2012-08-09 10:56:12 +0200 | [diff] [blame] | 481 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | #endif |
| 485 | |
Takashi Iwai | 83012a7 | 2012-08-24 18:38:08 +0200 | [diff] [blame] | 486 | #ifdef CONFIG_PM |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 487 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 488 | { |
| 489 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 490 | set_widgets_power_state(codec); |
| 491 | analog_low_current_mode(codec); |
| 492 | vt1708_update_hp_work(codec); |
| 493 | return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 494 | } |
| 495 | #endif |
| 496 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 497 | /* |
| 498 | */ |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 499 | |
| 500 | static int via_init(struct hda_codec *codec); |
| 501 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 502 | static const struct hda_codec_ops via_patch_ops = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 503 | .build_controls = via_build_controls, |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 504 | .build_pcms = snd_hda_gen_build_pcms, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 505 | .init = via_init, |
| 506 | .free = via_free, |
David Henningsson | 4e2d16d | 2012-10-08 15:44:14 +0200 | [diff] [blame] | 507 | .unsol_event = snd_hda_jack_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 508 | #ifdef CONFIG_PM |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 509 | .suspend = via_suspend, |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 510 | .check_power_status = via_check_power_status, |
| 511 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 512 | }; |
| 513 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 514 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 515 | static const struct hda_verb vt1708_init_verbs[] = { |
| 516 | /* power down jack detect function */ |
| 517 | {0x1, 0xf81, 0x1}, |
| 518 | { } |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 519 | }; |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 520 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 521 | { |
| 522 | unsigned int def_conf; |
| 523 | unsigned char seqassoc; |
| 524 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 525 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 526 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 527 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 528 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 529 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 530 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 531 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | return; |
| 535 | } |
| 536 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 537 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 538 | struct snd_ctl_elem_value *ucontrol) |
| 539 | { |
| 540 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 541 | struct via_spec *spec = codec->spec; |
| 542 | |
| 543 | if (spec->codec_type != VT1708) |
| 544 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 545 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 549 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 550 | struct snd_ctl_elem_value *ucontrol) |
| 551 | { |
| 552 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 553 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 554 | int val; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 555 | |
| 556 | if (spec->codec_type != VT1708) |
| 557 | return 0; |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 558 | val = !!ucontrol->value.integer.value[0]; |
| 559 | if (spec->vt1708_jack_detect == val) |
| 560 | return 0; |
| 561 | spec->vt1708_jack_detect = val; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 562 | vt1708_update_hp_work(codec); |
Takashi Iwai | 187d333 | 2011-11-24 16:33:09 +0100 | [diff] [blame] | 563 | return 1; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 564 | } |
| 565 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 566 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = { |
| 567 | { |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 568 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 569 | .name = "Jack Detect", |
| 570 | .count = 1, |
| 571 | .info = snd_ctl_boolean_mono_info, |
| 572 | .get = vt1708_jack_detect_get, |
| 573 | .put = vt1708_jack_detect_put, |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 574 | }, |
| 575 | {} /* terminator */ |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 576 | }; |
| 577 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 578 | static void via_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl) |
David Henningsson | 4e2d16d | 2012-10-08 15:44:14 +0200 | [diff] [blame] | 579 | { |
| 580 | set_widgets_power_state(codec); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 581 | snd_hda_gen_hp_automute(codec, tbl); |
| 582 | } |
| 583 | |
| 584 | static void via_line_automute(struct hda_codec *codec, struct hda_jack_tbl *tbl) |
| 585 | { |
| 586 | set_widgets_power_state(codec); |
| 587 | snd_hda_gen_line_automute(codec, tbl); |
David Henningsson | 4e2d16d | 2012-10-08 15:44:14 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl) |
| 591 | { |
| 592 | set_widgets_power_state(codec); |
| 593 | } |
| 594 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 595 | #define VIA_JACK_EVENT (HDA_GEN_LAST_EVENT + 1) |
| 596 | |
| 597 | static void via_set_jack_unsol_events(struct hda_codec *codec) |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 598 | { |
| 599 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 600 | struct auto_pin_cfg *cfg = &spec->gen.autocfg; |
| 601 | hda_nid_t pin; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 602 | int i; |
| 603 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 604 | spec->gen.hp_automute_hook = via_hp_automute; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 605 | if (cfg->speaker_pins[0]) |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 606 | spec->gen.line_automute_hook = via_line_automute; |
David Henningsson | 4e2d16d | 2012-10-08 15:44:14 +0200 | [diff] [blame] | 607 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 608 | for (i = 0; i < cfg->line_outs; i++) { |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 609 | pin = cfg->line_out_pins[i]; |
| 610 | if (pin && !snd_hda_jack_tbl_get(codec, pin) && |
| 611 | is_jack_detectable(codec, pin)) |
| 612 | snd_hda_jack_detect_enable_callback(codec, pin, |
David Henningsson | 4e2d16d | 2012-10-08 15:44:14 +0200 | [diff] [blame] | 613 | VIA_JACK_EVENT, |
| 614 | via_jack_powerstate_event); |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 615 | } |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 616 | |
| 617 | for (i = 0; i < cfg->num_inputs; i++) { |
| 618 | pin = cfg->line_out_pins[i]; |
| 619 | if (pin && !snd_hda_jack_tbl_get(codec, pin) && |
| 620 | is_jack_detectable(codec, pin)) |
| 621 | snd_hda_jack_detect_enable_callback(codec, pin, |
| 622 | VIA_JACK_EVENT, |
| 623 | via_jack_powerstate_event); |
| 624 | } |
| 625 | } |
| 626 | |
Takashi Iwai | 4abdbd1 | 2013-03-22 15:11:07 +0100 | [diff] [blame] | 627 | static const struct badness_table via_main_out_badness = { |
| 628 | .no_primary_dac = 0x10000, |
| 629 | .no_dac = 0x4000, |
| 630 | .shared_primary = 0x10000, |
| 631 | .shared_surr = 0x20, |
| 632 | .shared_clfe = 0x20, |
| 633 | .shared_surr_main = 0x20, |
| 634 | }; |
| 635 | static const struct badness_table via_extra_out_badness = { |
| 636 | .no_primary_dac = 0x4000, |
| 637 | .no_dac = 0x4000, |
| 638 | .shared_primary = 0x12, |
| 639 | .shared_surr = 0x20, |
| 640 | .shared_clfe = 0x20, |
| 641 | .shared_surr_main = 0x10, |
| 642 | }; |
| 643 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 644 | static int via_parse_auto_config(struct hda_codec *codec) |
| 645 | { |
| 646 | struct via_spec *spec = codec->spec; |
| 647 | int err; |
| 648 | |
Takashi Iwai | 4abdbd1 | 2013-03-22 15:11:07 +0100 | [diff] [blame] | 649 | spec->gen.main_out_badness = &via_main_out_badness; |
| 650 | spec->gen.extra_out_badness = &via_extra_out_badness; |
| 651 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 652 | err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0); |
| 653 | if (err < 0) |
| 654 | return err; |
| 655 | |
| 656 | err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg); |
| 657 | if (err < 0) |
| 658 | return err; |
| 659 | |
| 660 | via_set_jack_unsol_events(codec); |
| 661 | return 0; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 662 | } |
| 663 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 664 | static int via_init(struct hda_codec *codec) |
| 665 | { |
| 666 | struct via_spec *spec = codec->spec; |
| 667 | int i; |
| 668 | |
| 669 | for (i = 0; i < spec->num_iverbs; i++) |
| 670 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 671 | |
Takashi Iwai | e9d010c | 2012-02-01 10:33:23 +0100 | [diff] [blame] | 672 | /* init power states */ |
| 673 | set_widgets_power_state(codec); |
| 674 | __analog_low_current_mode(codec, true); |
| 675 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 676 | snd_hda_gen_init(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 677 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 678 | vt1708_update_hp_work(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 679 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 680 | return 0; |
| 681 | } |
| 682 | |
David Henningsson | f672f65 | 2013-02-05 12:06:02 +0100 | [diff] [blame] | 683 | static int vt1708_build_controls(struct hda_codec *codec) |
| 684 | { |
| 685 | /* In order not to create "Phantom Jack" controls, |
| 686 | temporary enable jackpoll */ |
| 687 | int err; |
| 688 | int old_interval = codec->jackpoll_interval; |
| 689 | codec->jackpoll_interval = msecs_to_jiffies(100); |
| 690 | err = via_build_controls(codec); |
| 691 | codec->jackpoll_interval = old_interval; |
| 692 | return err; |
| 693 | } |
| 694 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 695 | static int vt1708_build_pcms(struct hda_codec *codec) |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 696 | { |
| 697 | struct via_spec *spec = codec->spec; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 698 | int i, err; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 699 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 700 | err = snd_hda_gen_build_pcms(codec); |
| 701 | if (err < 0 || codec->vendor_id != 0x11061708) |
| 702 | return err; |
| 703 | |
| 704 | /* We got noisy outputs on the right channel on VT1708 when |
| 705 | * 24bit samples are used. Until any workaround is found, |
| 706 | * disable the 24bit format, so far. |
| 707 | */ |
| 708 | for (i = 0; i < codec->num_pcms; i++) { |
| 709 | struct hda_pcm *info = &spec->gen.pcm_rec[i]; |
| 710 | if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || |
| 711 | info->pcm_type != HDA_PCM_TYPE_AUDIO) |
| 712 | continue; |
| 713 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats = |
| 714 | SNDRV_PCM_FMTBIT_S16_LE; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 715 | } |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 716 | |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 717 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 718 | } |
| 719 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 720 | static int patch_vt1708(struct hda_codec *codec) |
| 721 | { |
| 722 | struct via_spec *spec; |
| 723 | int err; |
| 724 | |
| 725 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 726 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 727 | if (spec == NULL) |
| 728 | return -ENOMEM; |
| 729 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 730 | spec->gen.mixer_nid = 0x17; |
| 731 | |
| 732 | /* set jackpoll_interval while parsing the codec */ |
| 733 | codec->jackpoll_interval = msecs_to_jiffies(100); |
| 734 | spec->vt1708_jack_detect = 1; |
| 735 | |
| 736 | /* don't support the input jack switching due to lack of unsol event */ |
| 737 | /* (it may work with polling, though, but it needs testing) */ |
| 738 | spec->gen.suppress_auto_mic = 1; |
Takashi Iwai | eb33ccf | 2013-06-24 16:18:10 +0200 | [diff] [blame] | 739 | /* Some machines show the broken speaker mute */ |
| 740 | spec->gen.auto_mute_via_amp = 1; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 741 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 742 | /* Add HP and CD pin config connect bit re-config action */ |
| 743 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 744 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 745 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 746 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 747 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 748 | if (err < 0) { |
| 749 | via_free(codec); |
| 750 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 751 | } |
| 752 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 753 | /* add jack detect on/off control */ |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 754 | spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 755 | |
Lydia Wang | e322a36 | 2011-06-29 13:52:02 +0800 | [diff] [blame] | 756 | spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; |
| 757 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 758 | codec->patch_ops = via_patch_ops; |
David Henningsson | f672f65 | 2013-02-05 12:06:02 +0100 | [diff] [blame] | 759 | codec->patch_ops.build_controls = vt1708_build_controls; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 760 | codec->patch_ops.build_pcms = vt1708_build_pcms; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 761 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 762 | /* clear jackpoll_interval again; it's set dynamically */ |
| 763 | codec->jackpoll_interval = 0; |
| 764 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 768 | static int patch_vt1709(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 769 | { |
| 770 | struct via_spec *spec; |
| 771 | int err; |
| 772 | |
| 773 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 774 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 775 | if (spec == NULL) |
| 776 | return -ENOMEM; |
| 777 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 778 | spec->gen.mixer_nid = 0x18; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 779 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 780 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 781 | if (err < 0) { |
| 782 | via_free(codec); |
| 783 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 784 | } |
| 785 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 786 | codec->patch_ops = via_patch_ops; |
| 787 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 788 | return 0; |
| 789 | } |
| 790 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 791 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
| 792 | { |
| 793 | struct via_spec *spec = codec->spec; |
| 794 | int imux_is_smixer; |
| 795 | unsigned int parm; |
| 796 | int is_8ch = 0; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 797 | if ((spec->codec_type != VT1708B_4CH) && |
| 798 | (codec->vendor_id != 0x11064397)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 799 | is_8ch = 1; |
| 800 | |
| 801 | /* SW0 (17h) = stereo mixer */ |
| 802 | imux_is_smixer = |
| 803 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 804 | == ((spec->codec_type == VT1708S) ? 5 : 0)); |
| 805 | /* inputs */ |
| 806 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 807 | parm = AC_PWRST_D3; |
| 808 | set_pin_power_state(codec, 0x1a, &parm); |
| 809 | set_pin_power_state(codec, 0x1b, &parm); |
| 810 | set_pin_power_state(codec, 0x1e, &parm); |
| 811 | if (imux_is_smixer) |
| 812 | parm = AC_PWRST_D0; |
| 813 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 814 | update_power_state(codec, 0x17, parm); |
| 815 | update_power_state(codec, 0x13, parm); |
| 816 | update_power_state(codec, 0x14, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 817 | |
| 818 | /* outputs */ |
| 819 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 820 | parm = AC_PWRST_D3; |
| 821 | set_pin_power_state(codec, 0x19, &parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 822 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 823 | set_pin_power_state(codec, 0x1b, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 824 | update_power_state(codec, 0x18, parm); |
| 825 | update_power_state(codec, 0x11, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 826 | |
| 827 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 828 | if (is_8ch) { |
| 829 | parm = AC_PWRST_D3; |
| 830 | set_pin_power_state(codec, 0x22, &parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 831 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 832 | set_pin_power_state(codec, 0x1a, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 833 | update_power_state(codec, 0x26, parm); |
| 834 | update_power_state(codec, 0x24, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 835 | } else if (codec->vendor_id == 0x11064397) { |
| 836 | /* PW7(23h), SW2(27h), AOW2(25h) */ |
| 837 | parm = AC_PWRST_D3; |
| 838 | set_pin_power_state(codec, 0x23, &parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 839 | if (smart51_enabled(codec)) |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 840 | set_pin_power_state(codec, 0x1a, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 841 | update_power_state(codec, 0x27, parm); |
| 842 | update_power_state(codec, 0x25, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 846 | parm = AC_PWRST_D3; |
| 847 | /* force to D0 for internal Speaker */ |
| 848 | set_pin_power_state(codec, 0x1c, &parm); |
| 849 | set_pin_power_state(codec, 0x1d, &parm); |
| 850 | if (is_8ch) |
| 851 | set_pin_power_state(codec, 0x23, &parm); |
| 852 | |
| 853 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 854 | update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm); |
| 855 | update_power_state(codec, 0x10, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 856 | if (is_8ch) { |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 857 | update_power_state(codec, 0x25, parm); |
| 858 | update_power_state(codec, 0x27, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 859 | } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 860 | update_power_state(codec, 0x25, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 861 | } |
| 862 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 863 | static int patch_vt1708S(struct hda_codec *codec); |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 864 | static int patch_vt1708B(struct hda_codec *codec) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 865 | { |
| 866 | struct via_spec *spec; |
| 867 | int err; |
| 868 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 869 | if (get_codec_type(codec) == VT1708BCE) |
| 870 | return patch_vt1708S(codec); |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 871 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 872 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 873 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 874 | if (spec == NULL) |
| 875 | return -ENOMEM; |
| 876 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 877 | spec->gen.mixer_nid = 0x16; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 878 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 879 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 880 | err = via_parse_auto_config(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 881 | if (err < 0) { |
| 882 | via_free(codec); |
| 883 | return err; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 884 | } |
| 885 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 886 | codec->patch_ops = via_patch_ops; |
| 887 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 888 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 889 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 890 | return 0; |
| 891 | } |
| 892 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 893 | /* Patch for VT1708S */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 894 | static const struct hda_verb vt1708S_init_verbs[] = { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 895 | /* Enable Mic Boost Volume backdoor */ |
| 896 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 897 | /* don't bybass mixer */ |
| 898 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 899 | { } |
| 900 | }; |
| 901 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 902 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 903 | int offset, int num_steps, int step_size) |
| 904 | { |
Takashi Iwai | d045c5d | 2013-06-19 07:54:09 +0200 | [diff] [blame] | 905 | snd_hda_override_wcaps(codec, pin, |
| 906 | get_wcaps(codec, pin) | AC_WCAP_IN_AMP); |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 907 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 908 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 909 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 910 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 911 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 912 | } |
| 913 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 914 | static int patch_vt1708S(struct hda_codec *codec) |
| 915 | { |
| 916 | struct via_spec *spec; |
| 917 | int err; |
| 918 | |
| 919 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 920 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 921 | if (spec == NULL) |
| 922 | return -ENOMEM; |
| 923 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 924 | spec->gen.mixer_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 925 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 926 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 927 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 928 | /* correct names for VT1708BCE */ |
| 929 | if (get_codec_type(codec) == VT1708BCE) { |
| 930 | kfree(codec->chip_name); |
| 931 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 932 | snprintf(codec->bus->card->mixername, |
| 933 | sizeof(codec->bus->card->mixername), |
| 934 | "%s %s", codec->vendor_name, codec->chip_name); |
Lydia Wang | 970f630f | 2011-03-22 16:25:56 +0800 | [diff] [blame] | 935 | } |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 936 | /* correct names for VT1705 */ |
| 937 | if (codec->vendor_id == 0x11064397) { |
| 938 | kfree(codec->chip_name); |
| 939 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); |
| 940 | snprintf(codec->bus->card->mixername, |
| 941 | sizeof(codec->bus->card->mixername), |
| 942 | "%s %s", codec->vendor_name, codec->chip_name); |
| 943 | } |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 944 | |
| 945 | /* automatic parse from the BIOS config */ |
| 946 | err = via_parse_auto_config(codec); |
| 947 | if (err < 0) { |
| 948 | via_free(codec); |
| 949 | return err; |
| 950 | } |
| 951 | |
| 952 | spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; |
| 953 | |
| 954 | codec->patch_ops = via_patch_ops; |
| 955 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 956 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | /* Patch for VT1702 */ |
| 961 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 962 | static const struct hda_verb vt1702_init_verbs[] = { |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 963 | /* mixer enable */ |
| 964 | {0x1, 0xF88, 0x3}, |
| 965 | /* GPIO 0~2 */ |
| 966 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 967 | { } |
| 968 | }; |
| 969 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 970 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
| 971 | { |
| 972 | int imux_is_smixer = |
| 973 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 974 | unsigned int parm; |
| 975 | /* inputs */ |
| 976 | /* PW 1/2/5 (14h/15h/18h) */ |
| 977 | parm = AC_PWRST_D3; |
| 978 | set_pin_power_state(codec, 0x14, &parm); |
| 979 | set_pin_power_state(codec, 0x15, &parm); |
| 980 | set_pin_power_state(codec, 0x18, &parm); |
| 981 | if (imux_is_smixer) |
| 982 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ |
| 983 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 984 | update_power_state(codec, 0x13, parm); |
| 985 | update_power_state(codec, 0x12, parm); |
| 986 | update_power_state(codec, 0x1f, parm); |
| 987 | update_power_state(codec, 0x20, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 988 | |
| 989 | /* outputs */ |
| 990 | /* PW 3/4 (16h/17h) */ |
| 991 | parm = AC_PWRST_D3; |
| 992 | set_pin_power_state(codec, 0x17, &parm); |
| 993 | set_pin_power_state(codec, 0x16, &parm); |
| 994 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 995 | update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm); |
| 996 | update_power_state(codec, 0x10, parm); |
| 997 | update_power_state(codec, 0x1d, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 998 | } |
| 999 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1000 | static int patch_vt1702(struct hda_codec *codec) |
| 1001 | { |
| 1002 | struct via_spec *spec; |
| 1003 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1004 | |
| 1005 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1006 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1007 | if (spec == NULL) |
| 1008 | return -ENOMEM; |
| 1009 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1010 | spec->gen.mixer_nid = 0x1a; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1011 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1012 | /* limit AA path volume to 0 dB */ |
| 1013 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 1014 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 1015 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 1016 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 1017 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 1018 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1019 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1020 | err = via_parse_auto_config(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1021 | if (err < 0) { |
| 1022 | via_free(codec); |
| 1023 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1024 | } |
| 1025 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1026 | spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1027 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1028 | codec->patch_ops = via_patch_ops; |
| 1029 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1030 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1031 | return 0; |
| 1032 | } |
| 1033 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1034 | /* Patch for VT1718S */ |
| 1035 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1036 | static const struct hda_verb vt1718S_init_verbs[] = { |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 1037 | /* Enable MW0 adjust Gain 5 */ |
| 1038 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1039 | /* Enable Boost Volume backdoor */ |
| 1040 | {0x1, 0xf88, 0x8}, |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 1041 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1042 | { } |
| 1043 | }; |
| 1044 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1045 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
| 1046 | { |
| 1047 | struct via_spec *spec = codec->spec; |
| 1048 | int imux_is_smixer; |
Takashi Iwai | 6162552 | 2012-07-25 13:54:55 +0200 | [diff] [blame] | 1049 | unsigned int parm, parm2; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1050 | /* MUX6 (1eh) = stereo mixer */ |
| 1051 | imux_is_smixer = |
| 1052 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 1053 | /* inputs */ |
| 1054 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 1055 | parm = AC_PWRST_D3; |
| 1056 | set_pin_power_state(codec, 0x29, &parm); |
| 1057 | set_pin_power_state(codec, 0x2a, &parm); |
| 1058 | set_pin_power_state(codec, 0x2b, &parm); |
| 1059 | if (imux_is_smixer) |
| 1060 | parm = AC_PWRST_D0; |
| 1061 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1062 | update_power_state(codec, 0x1e, parm); |
| 1063 | update_power_state(codec, 0x1f, parm); |
| 1064 | update_power_state(codec, 0x10, parm); |
| 1065 | update_power_state(codec, 0x11, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1066 | |
| 1067 | /* outputs */ |
| 1068 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 1069 | parm = AC_PWRST_D3; |
| 1070 | set_pin_power_state(codec, 0x27, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1071 | update_power_state(codec, 0x1a, parm); |
Takashi Iwai | 6162552 | 2012-07-25 13:54:55 +0200 | [diff] [blame] | 1072 | parm2 = parm; /* for pin 0x0b */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1073 | |
| 1074 | /* PW2 (26h), AOW2 (ah) */ |
| 1075 | parm = AC_PWRST_D3; |
| 1076 | set_pin_power_state(codec, 0x26, &parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1077 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1078 | set_pin_power_state(codec, 0x2b, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1079 | update_power_state(codec, 0xa, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1080 | |
| 1081 | /* PW0 (24h), AOW0 (8h) */ |
| 1082 | parm = AC_PWRST_D3; |
| 1083 | set_pin_power_state(codec, 0x24, &parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1084 | if (!spec->gen.indep_hp_enabled) /* check for redirected HP */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1085 | set_pin_power_state(codec, 0x28, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1086 | update_power_state(codec, 0x8, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1087 | if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3) |
Takashi Iwai | 6162552 | 2012-07-25 13:54:55 +0200 | [diff] [blame] | 1088 | parm = parm2; |
| 1089 | update_power_state(codec, 0xb, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1090 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1091 | update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1092 | |
| 1093 | /* PW1 (25h), AOW1 (9h) */ |
| 1094 | parm = AC_PWRST_D3; |
| 1095 | set_pin_power_state(codec, 0x25, &parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1096 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1097 | set_pin_power_state(codec, 0x2a, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1098 | update_power_state(codec, 0x9, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1099 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1100 | if (spec->gen.indep_hp_enabled) { |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1101 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 1102 | parm = AC_PWRST_D3; |
| 1103 | set_pin_power_state(codec, 0x28, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1104 | update_power_state(codec, 0x1b, parm); |
| 1105 | update_power_state(codec, 0x34, parm); |
| 1106 | update_power_state(codec, 0xc, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1110 | /* Add a connection to the primary DAC from AA-mixer for some codecs |
| 1111 | * This isn't listed from the raw info, but the chip has a secret connection. |
| 1112 | */ |
| 1113 | static int add_secret_dac_path(struct hda_codec *codec) |
| 1114 | { |
| 1115 | struct via_spec *spec = codec->spec; |
| 1116 | int i, nums; |
| 1117 | hda_nid_t conn[8]; |
| 1118 | hda_nid_t nid; |
| 1119 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1120 | if (!spec->gen.mixer_nid) |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1121 | return 0; |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1122 | nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn, |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1123 | ARRAY_SIZE(conn) - 1); |
| 1124 | for (i = 0; i < nums; i++) { |
| 1125 | if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT) |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | /* find the primary DAC and add to the connection list */ |
| 1130 | nid = codec->start_nid; |
| 1131 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 1132 | unsigned int caps = get_wcaps(codec, nid); |
| 1133 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT && |
| 1134 | !(caps & AC_WCAP_DIGITAL)) { |
| 1135 | conn[nums++] = nid; |
| 1136 | return snd_hda_override_conn_list(codec, |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1137 | spec->gen.mixer_nid, |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1138 | nums, conn); |
| 1139 | } |
| 1140 | } |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1145 | static int patch_vt1718S(struct hda_codec *codec) |
| 1146 | { |
| 1147 | struct via_spec *spec; |
| 1148 | int err; |
| 1149 | |
| 1150 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1151 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1152 | if (spec == NULL) |
| 1153 | return -ENOMEM; |
| 1154 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1155 | spec->gen.mixer_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1156 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 1157 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1158 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1159 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1160 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1161 | err = via_parse_auto_config(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1162 | if (err < 0) { |
| 1163 | via_free(codec); |
| 1164 | return err; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1165 | } |
| 1166 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1167 | spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1168 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1169 | codec->patch_ops = via_patch_ops; |
| 1170 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1171 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
| 1172 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1175 | |
| 1176 | /* Patch for VT1716S */ |
| 1177 | |
| 1178 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 1179 | struct snd_ctl_elem_info *uinfo) |
| 1180 | { |
| 1181 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1182 | uinfo->count = 1; |
| 1183 | uinfo->value.integer.min = 0; |
| 1184 | uinfo->value.integer.max = 1; |
| 1185 | return 0; |
| 1186 | } |
| 1187 | |
| 1188 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 1189 | struct snd_ctl_elem_value *ucontrol) |
| 1190 | { |
| 1191 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1192 | int index = 0; |
| 1193 | |
| 1194 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 1195 | AC_VERB_GET_CONNECT_SEL, 0); |
| 1196 | if (index != -1) |
| 1197 | *ucontrol->value.integer.value = index; |
| 1198 | |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 1203 | struct snd_ctl_elem_value *ucontrol) |
| 1204 | { |
| 1205 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1206 | struct via_spec *spec = codec->spec; |
| 1207 | int index = *ucontrol->value.integer.value; |
| 1208 | |
| 1209 | snd_hda_codec_write(codec, 0x26, 0, |
| 1210 | AC_VERB_SET_CONNECT_SEL, index); |
| 1211 | spec->dmic_enabled = index; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1212 | set_widgets_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1213 | return 1; |
| 1214 | } |
| 1215 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1216 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1217 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 1218 | { |
| 1219 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1220 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1221 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1222 | .count = 1, |
| 1223 | .info = vt1716s_dmic_info, |
| 1224 | .get = vt1716s_dmic_get, |
| 1225 | .put = vt1716s_dmic_put, |
| 1226 | }, |
| 1227 | {} /* end */ |
| 1228 | }; |
| 1229 | |
| 1230 | |
| 1231 | /* mono-out mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1232 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1233 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 1234 | { } /* end */ |
| 1235 | }; |
| 1236 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1237 | static const struct hda_verb vt1716S_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1238 | /* Enable Boost Volume backdoor */ |
| 1239 | {0x1, 0xf8a, 0x80}, |
| 1240 | /* don't bybass mixer */ |
| 1241 | {0x1, 0xf88, 0xc0}, |
| 1242 | /* Enable mono output */ |
| 1243 | {0x1, 0xf90, 0x08}, |
| 1244 | { } |
| 1245 | }; |
| 1246 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1247 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
| 1248 | { |
| 1249 | struct via_spec *spec = codec->spec; |
| 1250 | int imux_is_smixer; |
| 1251 | unsigned int parm; |
| 1252 | unsigned int mono_out, present; |
| 1253 | /* SW0 (17h) = stereo mixer */ |
| 1254 | imux_is_smixer = |
| 1255 | (snd_hda_codec_read(codec, 0x17, 0, |
| 1256 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); |
| 1257 | /* inputs */ |
| 1258 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 1259 | parm = AC_PWRST_D3; |
| 1260 | set_pin_power_state(codec, 0x1a, &parm); |
| 1261 | set_pin_power_state(codec, 0x1b, &parm); |
| 1262 | set_pin_power_state(codec, 0x1e, &parm); |
| 1263 | if (imux_is_smixer) |
| 1264 | parm = AC_PWRST_D0; |
| 1265 | /* SW0 (17h), AIW0(13h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1266 | update_power_state(codec, 0x17, parm); |
| 1267 | update_power_state(codec, 0x13, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1268 | |
| 1269 | parm = AC_PWRST_D3; |
| 1270 | set_pin_power_state(codec, 0x1e, &parm); |
| 1271 | /* PW11 (22h) */ |
| 1272 | if (spec->dmic_enabled) |
| 1273 | set_pin_power_state(codec, 0x22, &parm); |
| 1274 | else |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1275 | update_power_state(codec, 0x22, AC_PWRST_D3); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1276 | |
| 1277 | /* SW2(26h), AIW1(14h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1278 | update_power_state(codec, 0x26, parm); |
| 1279 | update_power_state(codec, 0x14, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1280 | |
| 1281 | /* outputs */ |
| 1282 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 1283 | parm = AC_PWRST_D3; |
| 1284 | set_pin_power_state(codec, 0x19, &parm); |
| 1285 | /* Smart 5.1 PW2(1bh) */ |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1286 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1287 | set_pin_power_state(codec, 0x1b, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1288 | update_power_state(codec, 0x18, parm); |
| 1289 | update_power_state(codec, 0x11, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1290 | |
| 1291 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 1292 | parm = AC_PWRST_D3; |
| 1293 | set_pin_power_state(codec, 0x23, &parm); |
| 1294 | /* Smart 5.1 PW1(1ah) */ |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1295 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1296 | set_pin_power_state(codec, 0x1a, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1297 | update_power_state(codec, 0x27, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1298 | |
| 1299 | /* Smart 5.1 PW5(1eh) */ |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1300 | if (smart51_enabled(codec)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1301 | set_pin_power_state(codec, 0x1e, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1302 | update_power_state(codec, 0x25, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1303 | |
| 1304 | /* Mono out */ |
| 1305 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 1306 | present = snd_hda_jack_detect(codec, 0x1c); |
| 1307 | |
| 1308 | if (present) |
| 1309 | mono_out = 0; |
| 1310 | else { |
| 1311 | present = snd_hda_jack_detect(codec, 0x1d); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1312 | if (!spec->gen.indep_hp_enabled && present) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1313 | mono_out = 0; |
| 1314 | else |
| 1315 | mono_out = 1; |
| 1316 | } |
| 1317 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1318 | update_power_state(codec, 0x28, parm); |
| 1319 | update_power_state(codec, 0x29, parm); |
| 1320 | update_power_state(codec, 0x2a, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1321 | |
| 1322 | /* PW 3/4 (1ch/1dh) */ |
| 1323 | parm = AC_PWRST_D3; |
| 1324 | set_pin_power_state(codec, 0x1c, &parm); |
| 1325 | set_pin_power_state(codec, 0x1d, &parm); |
| 1326 | /* HP Independent Mode, power on AOW3 */ |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1327 | if (spec->gen.indep_hp_enabled) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1328 | update_power_state(codec, 0x25, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1329 | |
| 1330 | /* force to D0 for internal Speaker */ |
| 1331 | /* MW0 (16h), AOW0 (10h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1332 | update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm); |
| 1333 | update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1334 | } |
| 1335 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1336 | static int patch_vt1716S(struct hda_codec *codec) |
| 1337 | { |
| 1338 | struct via_spec *spec; |
| 1339 | int err; |
| 1340 | |
| 1341 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1342 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1343 | if (spec == NULL) |
| 1344 | return -ENOMEM; |
| 1345 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1346 | spec->gen.mixer_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1347 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 1348 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1349 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1350 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1351 | err = via_parse_auto_config(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1352 | if (err < 0) { |
| 1353 | via_free(codec); |
| 1354 | return err; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1355 | } |
| 1356 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1357 | spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1358 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1359 | spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1360 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 1361 | |
| 1362 | codec->patch_ops = via_patch_ops; |
| 1363 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1364 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1365 | return 0; |
| 1366 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1367 | |
| 1368 | /* for vt2002P */ |
| 1369 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1370 | static const struct hda_verb vt2002P_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 1371 | /* Class-D speaker related verbs */ |
| 1372 | {0x1, 0xfe0, 0x4}, |
| 1373 | {0x1, 0xfe9, 0x80}, |
| 1374 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1375 | /* Enable Boost Volume backdoor */ |
| 1376 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1377 | /* Enable AOW0 to MW9 */ |
| 1378 | {0x1, 0xfb8, 0x88}, |
| 1379 | { } |
| 1380 | }; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1381 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1382 | static const struct hda_verb vt1802_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1383 | /* Enable Boost Volume backdoor */ |
| 1384 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1385 | /* Enable AOW0 to MW9 */ |
| 1386 | {0x1, 0xfb8, 0x88}, |
| 1387 | { } |
| 1388 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1389 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1390 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
| 1391 | { |
| 1392 | struct via_spec *spec = codec->spec; |
| 1393 | int imux_is_smixer; |
| 1394 | unsigned int parm; |
| 1395 | unsigned int present; |
| 1396 | /* MUX9 (1eh) = stereo mixer */ |
| 1397 | imux_is_smixer = |
| 1398 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 1399 | /* inputs */ |
| 1400 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 1401 | parm = AC_PWRST_D3; |
| 1402 | set_pin_power_state(codec, 0x29, &parm); |
| 1403 | set_pin_power_state(codec, 0x2a, &parm); |
| 1404 | set_pin_power_state(codec, 0x2b, &parm); |
| 1405 | parm = AC_PWRST_D0; |
| 1406 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1407 | update_power_state(codec, 0x1e, parm); |
| 1408 | update_power_state(codec, 0x1f, parm); |
| 1409 | update_power_state(codec, 0x10, parm); |
| 1410 | update_power_state(codec, 0x11, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1411 | |
| 1412 | /* outputs */ |
| 1413 | /* AOW0 (8h)*/ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1414 | update_power_state(codec, 0x8, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1415 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1416 | if (spec->codec_type == VT1802) { |
| 1417 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 1418 | parm = AC_PWRST_D3; |
| 1419 | set_pin_power_state(codec, 0x28, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1420 | update_power_state(codec, 0x18, parm); |
| 1421 | update_power_state(codec, 0x38, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1422 | } else { |
| 1423 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 1424 | parm = AC_PWRST_D3; |
| 1425 | set_pin_power_state(codec, 0x26, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1426 | update_power_state(codec, 0x1c, parm); |
| 1427 | update_power_state(codec, 0x37, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1428 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1429 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1430 | if (spec->codec_type == VT1802) { |
| 1431 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 1432 | parm = AC_PWRST_D3; |
| 1433 | set_pin_power_state(codec, 0x25, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1434 | update_power_state(codec, 0x15, parm); |
| 1435 | update_power_state(codec, 0x35, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1436 | } else { |
| 1437 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 1438 | parm = AC_PWRST_D3; |
| 1439 | set_pin_power_state(codec, 0x25, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1440 | update_power_state(codec, 0x19, parm); |
| 1441 | update_power_state(codec, 0x35, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1442 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1443 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1444 | if (spec->gen.indep_hp_enabled) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1445 | update_power_state(codec, 0x9, AC_PWRST_D0); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1446 | |
| 1447 | /* Class-D */ |
| 1448 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ |
| 1449 | present = snd_hda_jack_detect(codec, 0x25); |
| 1450 | |
| 1451 | parm = AC_PWRST_D3; |
| 1452 | set_pin_power_state(codec, 0x24, &parm); |
| 1453 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1454 | if (spec->codec_type == VT1802) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1455 | update_power_state(codec, 0x14, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1456 | else |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1457 | update_power_state(codec, 0x18, parm); |
| 1458 | update_power_state(codec, 0x34, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1459 | |
| 1460 | /* Mono Out */ |
| 1461 | present = snd_hda_jack_detect(codec, 0x26); |
| 1462 | |
| 1463 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1464 | if (spec->codec_type == VT1802) { |
| 1465 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1466 | update_power_state(codec, 0x33, parm); |
| 1467 | update_power_state(codec, 0x1c, parm); |
| 1468 | update_power_state(codec, 0x3c, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1469 | } else { |
| 1470 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1471 | update_power_state(codec, 0x31, parm); |
| 1472 | update_power_state(codec, 0x17, parm); |
| 1473 | update_power_state(codec, 0x3b, parm); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1474 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1475 | /* MW9 (21h) */ |
| 1476 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1477 | update_power_state(codec, 0x21, AC_PWRST_D0); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1478 | else |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1479 | update_power_state(codec, 0x21, AC_PWRST_D3); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1480 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1481 | |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1482 | /* |
| 1483 | * pin fix-up |
| 1484 | */ |
| 1485 | enum { |
| 1486 | VIA_FIXUP_INTMIC_BOOST, |
Takashi Iwai | d526612 | 2012-11-07 10:40:36 +0100 | [diff] [blame] | 1487 | VIA_FIXUP_ASUS_G75, |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1488 | }; |
| 1489 | |
| 1490 | static void via_fixup_intmic_boost(struct hda_codec *codec, |
| 1491 | const struct hda_fixup *fix, int action) |
| 1492 | { |
| 1493 | if (action == HDA_FIXUP_ACT_PRE_PROBE) |
| 1494 | override_mic_boost(codec, 0x30, 0, 2, 40); |
| 1495 | } |
| 1496 | |
| 1497 | static const struct hda_fixup via_fixups[] = { |
| 1498 | [VIA_FIXUP_INTMIC_BOOST] = { |
| 1499 | .type = HDA_FIXUP_FUNC, |
| 1500 | .v.func = via_fixup_intmic_boost, |
| 1501 | }, |
Takashi Iwai | d526612 | 2012-11-07 10:40:36 +0100 | [diff] [blame] | 1502 | [VIA_FIXUP_ASUS_G75] = { |
| 1503 | .type = HDA_FIXUP_PINS, |
| 1504 | .v.pins = (const struct hda_pintbl[]) { |
| 1505 | /* set 0x24 and 0x33 as speakers */ |
| 1506 | { 0x24, 0x991301f0 }, |
| 1507 | { 0x33, 0x991301f1 }, /* subwoofer */ |
| 1508 | { } |
| 1509 | } |
| 1510 | }, |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1511 | }; |
| 1512 | |
| 1513 | static const struct snd_pci_quirk vt2002p_fixups[] = { |
Takashi Iwai | d526612 | 2012-11-07 10:40:36 +0100 | [diff] [blame] | 1514 | SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75), |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1515 | SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST), |
| 1516 | {} |
| 1517 | }; |
| 1518 | |
Takashi Iwai | ef4da45 | 2012-11-07 10:37:48 +0100 | [diff] [blame] | 1519 | /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e |
| 1520 | * Replace this with mixer NID 0x1c |
| 1521 | */ |
| 1522 | static void fix_vt1802_connections(struct hda_codec *codec) |
| 1523 | { |
| 1524 | static hda_nid_t conn_24[] = { 0x14, 0x1c }; |
| 1525 | static hda_nid_t conn_33[] = { 0x1c }; |
| 1526 | |
| 1527 | snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24); |
| 1528 | snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33); |
| 1529 | } |
| 1530 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1531 | /* patch for vt2002P */ |
| 1532 | static int patch_vt2002P(struct hda_codec *codec) |
| 1533 | { |
| 1534 | struct via_spec *spec; |
| 1535 | int err; |
| 1536 | |
| 1537 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1538 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1539 | if (spec == NULL) |
| 1540 | return -ENOMEM; |
| 1541 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1542 | spec->gen.mixer_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1543 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 1544 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | ef4da45 | 2012-11-07 10:37:48 +0100 | [diff] [blame] | 1545 | if (spec->codec_type == VT1802) |
| 1546 | fix_vt1802_connections(codec); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1547 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1548 | |
David Henningsson | 4b527b6 | 2012-09-18 14:26:59 +0200 | [diff] [blame] | 1549 | snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups); |
| 1550 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); |
| 1551 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1552 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1553 | err = via_parse_auto_config(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1554 | if (err < 0) { |
| 1555 | via_free(codec); |
| 1556 | return err; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1557 | } |
| 1558 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1559 | if (spec->codec_type == VT1802) |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1560 | spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1561 | else |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1562 | spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1563 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1564 | codec->patch_ops = via_patch_ops; |
| 1565 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1566 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1567 | return 0; |
| 1568 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1569 | |
| 1570 | /* for vt1812 */ |
| 1571 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1572 | static const struct hda_verb vt1812_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1573 | /* Enable Boost Volume backdoor */ |
| 1574 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1575 | /* Enable AOW0 to MW9 */ |
| 1576 | {0x1, 0xfb8, 0xa8}, |
| 1577 | { } |
| 1578 | }; |
| 1579 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1580 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
| 1581 | { |
| 1582 | struct via_spec *spec = codec->spec; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1583 | unsigned int parm; |
| 1584 | unsigned int present; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1585 | /* inputs */ |
| 1586 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 1587 | parm = AC_PWRST_D3; |
| 1588 | set_pin_power_state(codec, 0x29, &parm); |
| 1589 | set_pin_power_state(codec, 0x2a, &parm); |
| 1590 | set_pin_power_state(codec, 0x2b, &parm); |
| 1591 | parm = AC_PWRST_D0; |
| 1592 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1593 | update_power_state(codec, 0x1e, parm); |
| 1594 | update_power_state(codec, 0x1f, parm); |
| 1595 | update_power_state(codec, 0x10, parm); |
| 1596 | update_power_state(codec, 0x11, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1597 | |
| 1598 | /* outputs */ |
| 1599 | /* AOW0 (8h)*/ |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1600 | update_power_state(codec, 0x8, AC_PWRST_D0); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1601 | |
| 1602 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 1603 | parm = AC_PWRST_D3; |
| 1604 | set_pin_power_state(codec, 0x28, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1605 | update_power_state(codec, 0x18, parm); |
| 1606 | update_power_state(codec, 0x38, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1607 | |
| 1608 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 1609 | parm = AC_PWRST_D3; |
| 1610 | set_pin_power_state(codec, 0x25, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1611 | update_power_state(codec, 0x15, parm); |
| 1612 | update_power_state(codec, 0x35, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1613 | if (spec->gen.indep_hp_enabled) |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1614 | update_power_state(codec, 0x9, AC_PWRST_D0); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1615 | |
| 1616 | /* Internal Speaker */ |
| 1617 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 1618 | present = snd_hda_jack_detect(codec, 0x25); |
| 1619 | |
| 1620 | parm = AC_PWRST_D3; |
| 1621 | set_pin_power_state(codec, 0x24, &parm); |
| 1622 | if (present) { |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1623 | update_power_state(codec, 0x14, AC_PWRST_D3); |
| 1624 | update_power_state(codec, 0x34, AC_PWRST_D3); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1625 | } else { |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1626 | update_power_state(codec, 0x14, AC_PWRST_D0); |
| 1627 | update_power_state(codec, 0x34, AC_PWRST_D0); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | |
| 1631 | /* Mono Out */ |
| 1632 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 1633 | present = snd_hda_jack_detect(codec, 0x28); |
| 1634 | |
| 1635 | parm = AC_PWRST_D3; |
| 1636 | set_pin_power_state(codec, 0x31, &parm); |
| 1637 | if (present) { |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1638 | update_power_state(codec, 0x1c, AC_PWRST_D3); |
| 1639 | update_power_state(codec, 0x3c, AC_PWRST_D3); |
| 1640 | update_power_state(codec, 0x3e, AC_PWRST_D3); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1641 | } else { |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1642 | update_power_state(codec, 0x1c, AC_PWRST_D0); |
| 1643 | update_power_state(codec, 0x3c, AC_PWRST_D0); |
| 1644 | update_power_state(codec, 0x3e, AC_PWRST_D0); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 1648 | parm = AC_PWRST_D3; |
| 1649 | set_pin_power_state(codec, 0x33, &parm); |
Takashi Iwai | 054d867 | 2012-01-24 12:25:50 +0100 | [diff] [blame] | 1650 | update_power_state(codec, 0x1d, parm); |
| 1651 | update_power_state(codec, 0x3d, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1652 | |
| 1653 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1654 | |
| 1655 | /* patch for vt1812 */ |
| 1656 | static int patch_vt1812(struct hda_codec *codec) |
| 1657 | { |
| 1658 | struct via_spec *spec; |
| 1659 | int err; |
| 1660 | |
| 1661 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1662 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1663 | if (spec == NULL) |
| 1664 | return -ENOMEM; |
| 1665 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1666 | spec->gen.mixer_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1667 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 1668 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 1669 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1670 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1671 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 1672 | err = via_parse_auto_config(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1673 | if (err < 0) { |
| 1674 | via_free(codec); |
| 1675 | return err; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1676 | } |
| 1677 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1678 | spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1679 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1680 | codec->patch_ops = via_patch_ops; |
| 1681 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1682 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1683 | return 0; |
| 1684 | } |
| 1685 | |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1686 | /* patch for vt3476 */ |
| 1687 | |
| 1688 | static const struct hda_verb vt3476_init_verbs[] = { |
| 1689 | /* Enable DMic 8/16/32K */ |
| 1690 | {0x1, 0xF7B, 0x30}, |
| 1691 | /* Enable Boost Volume backdoor */ |
| 1692 | {0x1, 0xFB9, 0x20}, |
| 1693 | /* Enable AOW-MW9 path */ |
| 1694 | {0x1, 0xFB8, 0x10}, |
| 1695 | { } |
| 1696 | }; |
| 1697 | |
| 1698 | static void set_widgets_power_state_vt3476(struct hda_codec *codec) |
| 1699 | { |
| 1700 | struct via_spec *spec = codec->spec; |
| 1701 | int imux_is_smixer; |
| 1702 | unsigned int parm, parm2; |
| 1703 | /* MUX10 (1eh) = stereo mixer */ |
| 1704 | imux_is_smixer = |
| 1705 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4; |
| 1706 | /* inputs */ |
| 1707 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 1708 | parm = AC_PWRST_D3; |
| 1709 | set_pin_power_state(codec, 0x29, &parm); |
| 1710 | set_pin_power_state(codec, 0x2a, &parm); |
| 1711 | set_pin_power_state(codec, 0x2b, &parm); |
| 1712 | if (imux_is_smixer) |
| 1713 | parm = AC_PWRST_D0; |
| 1714 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 1715 | update_power_state(codec, 0x1e, parm); |
| 1716 | update_power_state(codec, 0x1f, parm); |
| 1717 | update_power_state(codec, 0x10, parm); |
| 1718 | update_power_state(codec, 0x11, parm); |
| 1719 | |
| 1720 | /* outputs */ |
| 1721 | /* PW3 (27h), MW3(37h), AOW3 (bh) */ |
| 1722 | if (spec->codec_type == VT1705CF) { |
| 1723 | parm = AC_PWRST_D3; |
| 1724 | update_power_state(codec, 0x27, parm); |
| 1725 | update_power_state(codec, 0x37, parm); |
| 1726 | } else { |
| 1727 | parm = AC_PWRST_D3; |
| 1728 | set_pin_power_state(codec, 0x27, &parm); |
| 1729 | update_power_state(codec, 0x37, parm); |
| 1730 | } |
| 1731 | |
| 1732 | /* PW2 (26h), MW2(36h), AOW2 (ah) */ |
| 1733 | parm = AC_PWRST_D3; |
| 1734 | set_pin_power_state(codec, 0x26, &parm); |
| 1735 | update_power_state(codec, 0x36, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1736 | if (smart51_enabled(codec)) { |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1737 | /* PW7(2bh), MW7(3bh), MUX7(1Bh) */ |
| 1738 | set_pin_power_state(codec, 0x2b, &parm); |
| 1739 | update_power_state(codec, 0x3b, parm); |
| 1740 | update_power_state(codec, 0x1b, parm); |
| 1741 | } |
| 1742 | update_conv_power_state(codec, 0xa, parm, 2); |
| 1743 | |
| 1744 | /* PW1 (25h), MW1(35h), AOW1 (9h) */ |
| 1745 | parm = AC_PWRST_D3; |
| 1746 | set_pin_power_state(codec, 0x25, &parm); |
| 1747 | update_power_state(codec, 0x35, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1748 | if (smart51_enabled(codec)) { |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1749 | /* PW6(2ah), MW6(3ah), MUX6(1ah) */ |
| 1750 | set_pin_power_state(codec, 0x2a, &parm); |
| 1751 | update_power_state(codec, 0x3a, parm); |
| 1752 | update_power_state(codec, 0x1a, parm); |
| 1753 | } |
| 1754 | update_conv_power_state(codec, 0x9, parm, 1); |
| 1755 | |
| 1756 | /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */ |
| 1757 | parm = AC_PWRST_D3; |
| 1758 | set_pin_power_state(codec, 0x28, &parm); |
| 1759 | update_power_state(codec, 0x38, parm); |
| 1760 | update_power_state(codec, 0x18, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1761 | if (spec->gen.indep_hp_enabled) |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1762 | update_conv_power_state(codec, 0xb, parm, 3); |
| 1763 | parm2 = parm; /* for pin 0x0b */ |
| 1764 | |
| 1765 | /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */ |
| 1766 | parm = AC_PWRST_D3; |
| 1767 | set_pin_power_state(codec, 0x24, &parm); |
| 1768 | update_power_state(codec, 0x34, parm); |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1769 | if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3) |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1770 | parm = parm2; |
| 1771 | update_conv_power_state(codec, 0x8, parm, 0); |
| 1772 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 1773 | update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm); |
| 1774 | } |
| 1775 | |
| 1776 | static int patch_vt3476(struct hda_codec *codec) |
| 1777 | { |
| 1778 | struct via_spec *spec; |
| 1779 | int err; |
| 1780 | |
| 1781 | /* create a codec specific record */ |
| 1782 | spec = via_new_spec(codec); |
| 1783 | if (spec == NULL) |
| 1784 | return -ENOMEM; |
| 1785 | |
Takashi Iwai | b3f6008 | 2013-01-07 12:27:36 +0100 | [diff] [blame] | 1786 | spec->gen.mixer_nid = 0x3f; |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1787 | add_secret_dac_path(codec); |
| 1788 | |
| 1789 | /* automatic parse from the BIOS config */ |
| 1790 | err = via_parse_auto_config(codec); |
| 1791 | if (err < 0) { |
| 1792 | via_free(codec); |
| 1793 | return err; |
| 1794 | } |
| 1795 | |
| 1796 | spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; |
| 1797 | |
| 1798 | codec->patch_ops = via_patch_ops; |
| 1799 | |
| 1800 | spec->set_widgets_power_state = set_widgets_power_state_vt3476; |
| 1801 | |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1805 | /* |
| 1806 | * patch entries |
| 1807 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1808 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1809 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 1810 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 1811 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 1812 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 1813 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1814 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1815 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1816 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1817 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1818 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1819 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1820 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1821 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1822 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1823 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1824 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1825 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1826 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1827 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1828 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1829 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1830 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1831 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1832 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1833 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1834 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1835 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1836 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1837 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1838 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1839 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1840 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1841 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1842 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1843 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 1844 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1845 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1846 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1847 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1848 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1849 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1850 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1851 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1852 | .patch = patch_vt1708S}, |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 1853 | { .id = 0x11064397, .name = "VT1705", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1854 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1855 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1856 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1857 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1858 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1859 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1860 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1861 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1862 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1863 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1864 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1865 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1866 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1867 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1868 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1869 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1870 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1871 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1872 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1873 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1874 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 1875 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 1876 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1877 | { .id = 0x11060428, .name = "VT1718S", |
| 1878 | .patch = patch_vt1718S}, |
| 1879 | { .id = 0x11064428, .name = "VT1718S", |
| 1880 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 1881 | { .id = 0x11060441, .name = "VT2020", |
| 1882 | .patch = patch_vt1718S}, |
| 1883 | { .id = 0x11064441, .name = "VT1828S", |
| 1884 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1885 | { .id = 0x11060433, .name = "VT1716S", |
| 1886 | .patch = patch_vt1716S}, |
| 1887 | { .id = 0x1106a721, .name = "VT1716S", |
| 1888 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1889 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 1890 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1891 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 1892 | { .id = 0x11060440, .name = "VT1818S", |
| 1893 | .patch = patch_vt1708S}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1894 | { .id = 0x11060446, .name = "VT1802", |
| 1895 | .patch = patch_vt2002P}, |
| 1896 | { .id = 0x11068446, .name = "VT1802", |
| 1897 | .patch = patch_vt2002P}, |
Lydia Wang | 43737e0 | 2012-12-10 18:28:11 +0800 | [diff] [blame] | 1898 | { .id = 0x11064760, .name = "VT1705CF", |
| 1899 | .patch = patch_vt3476}, |
Lydia Wang | 6121b84 | 2012-12-10 19:03:26 +0800 | [diff] [blame] | 1900 | { .id = 0x11064761, .name = "VT1708SCE", |
| 1901 | .patch = patch_vt3476}, |
| 1902 | { .id = 0x11064762, .name = "VT1808", |
| 1903 | .patch = patch_vt3476}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1904 | {} /* terminator */ |
| 1905 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 1906 | |
| 1907 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 1908 | |
| 1909 | static struct hda_codec_preset_list via_list = { |
| 1910 | .preset = snd_hda_preset_via, |
| 1911 | .owner = THIS_MODULE, |
| 1912 | }; |
| 1913 | |
| 1914 | MODULE_LICENSE("GPL"); |
| 1915 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 1916 | |
| 1917 | static int __init patch_via_init(void) |
| 1918 | { |
| 1919 | return snd_hda_add_codec_preset(&via_list); |
| 1920 | } |
| 1921 | |
| 1922 | static void __exit patch_via_exit(void) |
| 1923 | { |
| 1924 | snd_hda_delete_codec_preset(&via_list); |
| 1925 | } |
| 1926 | |
| 1927 | module_init(patch_via_init) |
| 1928 | module_exit(patch_via_exit) |