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> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 52 | #include <sound/core.h> |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 53 | #include <sound/asoundef.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 54 | #include "hda_codec.h" |
| 55 | #include "hda_local.h" |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 56 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 57 | #define NID_MAPPING (-1) |
| 58 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 59 | /* amp values */ |
| 60 | #define AMP_VAL_IDX_SHIFT 19 |
| 61 | #define AMP_VAL_IDX_MASK (0x0f<<19) |
| 62 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 63 | /* Pin Widget NID */ |
| 64 | #define VT1708_HP_NID 0x13 |
| 65 | #define VT1708_DIGOUT_NID 0x14 |
| 66 | #define VT1708_DIGIN_NID 0x16 |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 67 | #define VT1708_DIGIN_PIN 0x26 |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 68 | #define VT1708_HP_PIN_NID 0x20 |
| 69 | #define VT1708_CD_PIN_NID 0x24 |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 70 | |
| 71 | #define VT1709_HP_DAC_NID 0x28 |
| 72 | #define VT1709_DIGOUT_NID 0x13 |
| 73 | #define VT1709_DIGIN_NID 0x17 |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 74 | #define VT1709_DIGIN_PIN 0x25 |
| 75 | |
| 76 | #define VT1708B_HP_NID 0x25 |
| 77 | #define VT1708B_DIGOUT_NID 0x12 |
| 78 | #define VT1708B_DIGIN_NID 0x15 |
| 79 | #define VT1708B_DIGIN_PIN 0x21 |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 80 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 81 | #define VT1708S_HP_NID 0x25 |
| 82 | #define VT1708S_DIGOUT_NID 0x12 |
| 83 | |
| 84 | #define VT1702_HP_NID 0x17 |
| 85 | #define VT1702_DIGOUT_NID 0x11 |
| 86 | |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 87 | enum VIA_HDA_CODEC { |
| 88 | UNKNOWN = -1, |
| 89 | VT1708, |
| 90 | VT1709_10CH, |
| 91 | VT1709_6CH, |
| 92 | VT1708B_8CH, |
| 93 | VT1708B_4CH, |
| 94 | VT1708S, |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 95 | VT1708BCE, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 96 | VT1702, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 97 | VT1718S, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 98 | VT1716S, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 99 | VT2002P, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 100 | VT1812, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 101 | VT1802, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 102 | CODEC_TYPES, |
| 103 | }; |
| 104 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 105 | #define VT2002P_COMPATIBLE(spec) \ |
| 106 | ((spec)->codec_type == VT2002P ||\ |
| 107 | (spec)->codec_type == VT1812 ||\ |
| 108 | (spec)->codec_type == VT1802) |
| 109 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 110 | struct nid_path { |
| 111 | int depth; |
| 112 | hda_nid_t path[5]; |
| 113 | short idx[5]; |
| 114 | }; |
| 115 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 116 | struct via_spec { |
| 117 | /* codec parameterization */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 118 | const struct snd_kcontrol_new *mixers[6]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 119 | unsigned int num_mixers; |
| 120 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 121 | const struct hda_verb *init_verbs[5]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 122 | unsigned int num_iverbs; |
| 123 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 124 | char stream_name_analog[32]; |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 125 | char stream_name_hp[32]; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 126 | const struct hda_pcm_stream *stream_analog_playback; |
| 127 | const struct hda_pcm_stream *stream_analog_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 128 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 129 | char stream_name_digital[32]; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 130 | const struct hda_pcm_stream *stream_digital_playback; |
| 131 | const struct hda_pcm_stream *stream_digital_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 132 | |
| 133 | /* playback */ |
| 134 | struct hda_multi_out multiout; |
| 135 | hda_nid_t slave_dig_outs[2]; |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 136 | hda_nid_t hp_dac_nid; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 137 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 138 | struct nid_path out_path[4]; |
| 139 | struct nid_path hp_path; |
| 140 | struct nid_path hp_dep_path; |
| 141 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 142 | /* capture */ |
| 143 | unsigned int num_adc_nids; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 144 | hda_nid_t adc_nids[3]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 145 | hda_nid_t mux_nids[3]; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 146 | hda_nid_t aa_mix_nid; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 147 | hda_nid_t dig_in_nid; |
| 148 | hda_nid_t dig_in_pin; |
| 149 | |
| 150 | /* capture source */ |
| 151 | const struct hda_input_mux *input_mux; |
| 152 | unsigned int cur_mux[3]; |
| 153 | |
| 154 | /* PCM information */ |
| 155 | struct hda_pcm pcm_rec[3]; |
| 156 | |
| 157 | /* dynamic controls, init_verbs and input_mux */ |
| 158 | struct auto_pin_cfg autocfg; |
| 159 | struct snd_array kctls; |
| 160 | struct hda_input_mux private_imux[2]; |
| 161 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
| 162 | |
| 163 | /* HP mode source */ |
| 164 | const struct hda_input_mux *hp_mux; |
| 165 | unsigned int hp_independent_mode; |
| 166 | unsigned int hp_independent_mode_index; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 167 | unsigned int can_smart51; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 168 | unsigned int smart51_enabled; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 169 | unsigned int dmic_enabled; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 170 | unsigned int no_pin_power_ctl; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 171 | enum VIA_HDA_CODEC codec_type; |
| 172 | |
| 173 | /* work to check hp jack state */ |
| 174 | struct hda_codec *codec; |
| 175 | struct delayed_work vt1708_hp_work; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 176 | int vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 177 | int vt1708_hp_present; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 178 | |
| 179 | void (*set_widgets_power_state)(struct hda_codec *codec); |
| 180 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 181 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 182 | struct hda_loopback_check loopback; |
| 183 | #endif |
| 184 | }; |
| 185 | |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 186 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 187 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
| 188 | { |
| 189 | struct via_spec *spec; |
| 190 | |
| 191 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 192 | if (spec == NULL) |
| 193 | return NULL; |
| 194 | |
| 195 | codec->spec = spec; |
| 196 | spec->codec = codec; |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 197 | spec->codec_type = get_codec_type(codec); |
| 198 | /* VT1708BCE & VT1708S are almost same */ |
| 199 | if (spec->codec_type == VT1708BCE) |
| 200 | spec->codec_type = VT1708S; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 201 | return spec; |
| 202 | } |
| 203 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 204 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 205 | { |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 206 | u32 vendor_id = codec->vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 207 | u16 ven_id = vendor_id >> 16; |
| 208 | u16 dev_id = vendor_id & 0xffff; |
| 209 | enum VIA_HDA_CODEC codec_type; |
| 210 | |
| 211 | /* get codec type */ |
| 212 | if (ven_id != 0x1106) |
| 213 | codec_type = UNKNOWN; |
| 214 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 215 | codec_type = VT1708; |
| 216 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 217 | codec_type = VT1709_10CH; |
| 218 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 219 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 220 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 221 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 222 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 223 | codec_type = VT1708BCE; |
| 224 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 225 | codec_type = VT1708B_4CH; |
| 226 | else if ((dev_id & 0xfff) == 0x397 |
| 227 | && (dev_id >> 12) < 8) |
| 228 | codec_type = VT1708S; |
| 229 | else if ((dev_id & 0xfff) == 0x398 |
| 230 | && (dev_id >> 12) < 8) |
| 231 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 232 | else if ((dev_id & 0xfff) == 0x428 |
| 233 | && (dev_id >> 12) < 8) |
| 234 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 235 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 236 | codec_type = VT1716S; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 237 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 238 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 239 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 240 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 241 | else if (dev_id == 0x0448) |
| 242 | codec_type = VT1812; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 243 | else if (dev_id == 0x0440) |
| 244 | codec_type = VT1708S; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 245 | else if ((dev_id & 0xfff) == 0x446) |
| 246 | codec_type = VT1802; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 247 | else |
| 248 | codec_type = UNKNOWN; |
| 249 | return codec_type; |
| 250 | }; |
| 251 | |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 252 | #define VIA_JACK_EVENT 0x20 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 253 | #define VIA_HP_EVENT 0x01 |
| 254 | #define VIA_GPIO_EVENT 0x02 |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 255 | #define VIA_MONO_EVENT 0x03 |
| 256 | #define VIA_SPEAKER_EVENT 0x04 |
| 257 | #define VIA_BIND_HP_EVENT 0x05 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 258 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 259 | enum { |
| 260 | VIA_CTL_WIDGET_VOL, |
| 261 | VIA_CTL_WIDGET_MUTE, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 262 | VIA_CTL_WIDGET_ANALOG_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 263 | VIA_CTL_WIDGET_BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 264 | }; |
| 265 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 266 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 267 | static int is_aa_path_mute(struct hda_codec *codec); |
| 268 | |
| 269 | static void vt1708_start_hp_work(struct via_spec *spec) |
| 270 | { |
| 271 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 272 | return; |
| 273 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 274 | !spec->vt1708_jack_detect); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 275 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
| 276 | schedule_delayed_work(&spec->vt1708_hp_work, |
| 277 | msecs_to_jiffies(100)); |
| 278 | } |
| 279 | |
| 280 | static void vt1708_stop_hp_work(struct via_spec *spec) |
| 281 | { |
| 282 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 283 | return; |
| 284 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 |
| 285 | && !is_aa_path_mute(spec->codec)) |
| 286 | return; |
| 287 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 288 | !spec->vt1708_jack_detect); |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 289 | cancel_delayed_work_sync(&spec->vt1708_hp_work); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 290 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 291 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 292 | static void set_widgets_power_state(struct hda_codec *codec) |
| 293 | { |
| 294 | struct via_spec *spec = codec->spec; |
| 295 | if (spec->set_widgets_power_state) |
| 296 | spec->set_widgets_power_state(codec); |
| 297 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 298 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 299 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
| 300 | struct snd_ctl_elem_value *ucontrol) |
| 301 | { |
| 302 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 303 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 304 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 305 | set_widgets_power_state(codec); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 306 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 307 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
| 308 | if (is_aa_path_mute(codec)) |
| 309 | vt1708_start_hp_work(codec->spec); |
| 310 | else |
| 311 | vt1708_stop_hp_work(codec->spec); |
| 312 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 313 | return change; |
| 314 | } |
| 315 | |
| 316 | /* modify .put = snd_hda_mixer_amp_switch_put */ |
| 317 | #define ANALOG_INPUT_MUTE \ |
| 318 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 319 | .name = NULL, \ |
| 320 | .index = 0, \ |
| 321 | .info = snd_hda_mixer_amp_switch_info, \ |
| 322 | .get = snd_hda_mixer_amp_switch_get, \ |
| 323 | .put = analog_input_switch_put, \ |
| 324 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 325 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 326 | static void via_hp_bind_automute(struct hda_codec *codec); |
| 327 | |
| 328 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, |
| 329 | struct snd_ctl_elem_value *ucontrol) |
| 330 | { |
| 331 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 332 | struct via_spec *spec = codec->spec; |
| 333 | int i; |
| 334 | int change = 0; |
| 335 | |
| 336 | long *valp = ucontrol->value.integer.value; |
| 337 | int lmute, rmute; |
| 338 | if (strstr(kcontrol->id.name, "Switch") == NULL) { |
| 339 | snd_printd("Invalid control!\n"); |
| 340 | return change; |
| 341 | } |
| 342 | change = snd_hda_mixer_amp_switch_put(kcontrol, |
| 343 | ucontrol); |
| 344 | /* Get mute value */ |
| 345 | lmute = *valp ? 0 : HDA_AMP_MUTE; |
| 346 | valp++; |
| 347 | rmute = *valp ? 0 : HDA_AMP_MUTE; |
| 348 | |
| 349 | /* Set hp pins */ |
| 350 | if (!spec->hp_independent_mode) { |
| 351 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 352 | snd_hda_codec_amp_update( |
| 353 | codec, spec->autocfg.hp_pins[i], |
| 354 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 355 | lmute); |
| 356 | snd_hda_codec_amp_update( |
| 357 | codec, spec->autocfg.hp_pins[i], |
| 358 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 359 | rmute); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (!lmute && !rmute) { |
| 364 | /* Line Outs */ |
| 365 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 366 | snd_hda_codec_amp_stereo( |
| 367 | codec, spec->autocfg.line_out_pins[i], |
| 368 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 369 | /* Speakers */ |
| 370 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 371 | snd_hda_codec_amp_stereo( |
| 372 | codec, spec->autocfg.speaker_pins[i], |
| 373 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 374 | /* unmute */ |
| 375 | via_hp_bind_automute(codec); |
| 376 | |
| 377 | } else { |
| 378 | if (lmute) { |
| 379 | /* Mute all left channels */ |
| 380 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 381 | snd_hda_codec_amp_update( |
| 382 | codec, |
| 383 | spec->autocfg.line_out_pins[i], |
| 384 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 385 | lmute); |
| 386 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 387 | snd_hda_codec_amp_update( |
| 388 | codec, |
| 389 | spec->autocfg.speaker_pins[i], |
| 390 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 391 | lmute); |
| 392 | } |
| 393 | if (rmute) { |
| 394 | /* mute all right channels */ |
| 395 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 396 | snd_hda_codec_amp_update( |
| 397 | codec, |
| 398 | spec->autocfg.line_out_pins[i], |
| 399 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 400 | rmute); |
| 401 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 402 | snd_hda_codec_amp_update( |
| 403 | codec, |
| 404 | spec->autocfg.speaker_pins[i], |
| 405 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 406 | rmute); |
| 407 | } |
| 408 | } |
| 409 | return change; |
| 410 | } |
| 411 | |
| 412 | #define BIND_PIN_MUTE \ |
| 413 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 414 | .name = NULL, \ |
| 415 | .index = 0, \ |
| 416 | .info = snd_hda_mixer_amp_switch_info, \ |
| 417 | .get = snd_hda_mixer_amp_switch_get, \ |
| 418 | .put = bind_pin_switch_put, \ |
| 419 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 420 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 421 | static const struct snd_kcontrol_new via_control_templates[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 422 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 423 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 424 | ANALOG_INPUT_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 425 | BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 426 | }; |
| 427 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 428 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 429 | /* add dynamic controls */ |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 430 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
| 431 | const struct snd_kcontrol_new *tmpl, |
| 432 | const char *name) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 433 | { |
| 434 | struct snd_kcontrol_new *knew; |
| 435 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 436 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
| 437 | knew = snd_array_new(&spec->kctls); |
| 438 | if (!knew) |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 439 | return NULL; |
| 440 | *knew = *tmpl; |
| 441 | if (!name) |
| 442 | name = tmpl->name; |
| 443 | if (name) { |
| 444 | knew->name = kstrdup(name, GFP_KERNEL); |
| 445 | if (!knew->name) |
| 446 | return NULL; |
| 447 | } |
| 448 | return knew; |
| 449 | } |
| 450 | |
| 451 | static int __via_add_control(struct via_spec *spec, int type, const char *name, |
| 452 | int idx, unsigned long val) |
| 453 | { |
| 454 | struct snd_kcontrol_new *knew; |
| 455 | |
| 456 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); |
| 457 | if (!knew) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 458 | return -ENOMEM; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 459 | knew->index = idx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 460 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 461 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 462 | knew->private_value = val; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 466 | #define via_add_control(spec, type, name, val) \ |
| 467 | __via_add_control(spec, type, name, 0, val) |
| 468 | |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 469 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 470 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 471 | static void via_free_kctls(struct hda_codec *codec) |
| 472 | { |
| 473 | struct via_spec *spec = codec->spec; |
| 474 | |
| 475 | if (spec->kctls.list) { |
| 476 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 477 | int i; |
| 478 | for (i = 0; i < spec->kctls.used; i++) |
| 479 | kfree(kctl[i].name); |
| 480 | } |
| 481 | snd_array_free(&spec->kctls); |
| 482 | } |
| 483 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 484 | /* create input playback/capture controls for the given pin */ |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 485 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 486 | int type_idx, int idx, int mix_nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 487 | { |
| 488 | char name[32]; |
| 489 | int err; |
| 490 | |
| 491 | sprintf(name, "%s Playback Volume", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 492 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 493 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 494 | if (err < 0) |
| 495 | return err; |
| 496 | sprintf(name, "%s Playback Switch", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 497 | err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 498 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 499 | if (err < 0) |
| 500 | return err; |
| 501 | return 0; |
| 502 | } |
| 503 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 504 | /* return the index of the given widget nid as the source of mux; |
| 505 | * return -1 if not found; |
| 506 | * if num_conns is non-NULL, set the total number of connections |
| 507 | */ |
| 508 | static int __get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
| 509 | hda_nid_t nid, int *num_conns) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 510 | { |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 511 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; |
| 512 | int i, nums; |
| 513 | |
| 514 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); |
| 515 | if (num_conns) |
| 516 | *num_conns = nums; |
| 517 | for (i = 0; i < nums; i++) |
| 518 | if (conn[i] == nid) |
| 519 | return i; |
| 520 | return -1; |
| 521 | } |
| 522 | |
| 523 | #define get_connection_index(codec, mux, nid) \ |
| 524 | __get_connection_index(codec, mux, nid, NULL) |
| 525 | |
| 526 | /* unmute input amp and select the specificed source */ |
| 527 | static void unmute_and_select(struct hda_codec *codec, hda_nid_t nid, |
| 528 | hda_nid_t src, hda_nid_t mix) |
| 529 | { |
| 530 | int idx, num_conns; |
| 531 | |
| 532 | idx = __get_connection_index(codec, nid, src, &num_conns); |
| 533 | if (idx < 0) |
| 534 | return; |
| 535 | |
| 536 | /* select the route explicitly when multiple connections exist */ |
| 537 | if (num_conns > 1) |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 538 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 539 | AC_VERB_SET_CONNECT_SEL, idx); |
| 540 | /* unmute if the input amp is present */ |
| 541 | if (!(query_amp_caps(codec, nid, HDA_INPUT) & |
| 542 | (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE))) |
| 543 | return; |
| 544 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 545 | AMP_IN_UNMUTE(idx)); |
| 546 | |
| 547 | /* unmute AA-path if present */ |
| 548 | if (!mix) |
| 549 | return; |
| 550 | idx = __get_connection_index(codec, nid, mix, NULL); |
| 551 | if (idx >= 0) |
| 552 | snd_hda_codec_write(codec, nid, 0, |
| 553 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 554 | AMP_IN_UNMUTE(idx)); |
| 555 | } |
| 556 | |
| 557 | /* set the given pin as output */ |
| 558 | static void init_output_pin(struct hda_codec *codec, hda_nid_t pin, |
| 559 | int pin_type) |
| 560 | { |
| 561 | if (!pin) |
| 562 | return; |
| 563 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 564 | pin_type); |
| 565 | if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) |
| 566 | snd_hda_codec_write(codec, pin, 0, |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 567 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 570 | static void via_auto_init_output(struct hda_codec *codec, hda_nid_t pin, |
| 571 | int pin_type, struct nid_path *path) |
| 572 | { |
| 573 | struct via_spec *spec = codec->spec; |
| 574 | unsigned int caps; |
| 575 | hda_nid_t nid; |
| 576 | int i; |
| 577 | |
| 578 | if (!pin) |
| 579 | return; |
| 580 | |
| 581 | init_output_pin(codec, pin, pin_type); |
| 582 | caps = query_amp_caps(codec, pin, HDA_OUTPUT); |
| 583 | if (caps & AC_AMPCAP_MUTE) { |
| 584 | unsigned int val; |
| 585 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; |
| 586 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 587 | AMP_OUT_MUTE | val); |
| 588 | } |
| 589 | |
| 590 | /* initialize the output path */ |
| 591 | nid = pin; |
| 592 | for (i = 0; i < path->depth; i++) { |
| 593 | unmute_and_select(codec, nid, path->idx[i], spec->aa_mix_nid); |
| 594 | nid = path->path[i]; |
| 595 | if (query_amp_caps(codec, nid, HDA_OUTPUT) & |
| 596 | (AC_AMPCAP_NUM_STEPS | AC_AMPCAP_MUTE)) |
| 597 | snd_hda_codec_write(codec, nid, 0, |
| 598 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 599 | AMP_OUT_UNMUTE); |
| 600 | } |
| 601 | } |
| 602 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 603 | |
| 604 | static void via_auto_init_multi_out(struct hda_codec *codec) |
| 605 | { |
| 606 | struct via_spec *spec = codec->spec; |
| 607 | int i; |
| 608 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 609 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 610 | via_auto_init_output(codec, spec->autocfg.line_out_pins[i], |
| 611 | PIN_OUT, &spec->out_path[i]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static void via_auto_init_hp_out(struct hda_codec *codec) |
| 615 | { |
| 616 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 617 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 618 | if (spec->hp_dac_nid) |
| 619 | via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP, |
| 620 | &spec->hp_path); |
| 621 | else |
| 622 | via_auto_init_output(codec, spec->autocfg.hp_pins[0], PIN_HP, |
| 623 | &spec->hp_dep_path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 626 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 627 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 628 | static void via_auto_init_analog_input(struct hda_codec *codec) |
| 629 | { |
| 630 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 631 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 632 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 633 | unsigned int ctl; |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 634 | int i, num_conns; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 635 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 636 | /* init ADCs */ |
| 637 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 638 | snd_hda_codec_write(codec, spec->adc_nids[i], 0, |
| 639 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 640 | AMP_IN_UNMUTE(0)); |
| 641 | } |
| 642 | |
| 643 | /* init pins */ |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 644 | for (i = 0; i < cfg->num_inputs; i++) { |
| 645 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 646 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 647 | ctl = PIN_OUT; |
David Henningsson | 3064967 | 2011-02-21 10:23:18 +0100 | [diff] [blame] | 648 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 649 | ctl = PIN_VREF50; |
| 650 | else |
| 651 | ctl = PIN_IN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 652 | snd_hda_codec_write(codec, nid, 0, |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 653 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 654 | } |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 655 | |
| 656 | /* init input-src */ |
| 657 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 658 | const struct hda_input_mux *imux = spec->input_mux; |
| 659 | if (!imux || !spec->mux_nids[i]) |
| 660 | continue; |
| 661 | snd_hda_codec_write(codec, spec->mux_nids[i], 0, |
| 662 | AC_VERB_SET_CONNECT_SEL, |
| 663 | imux->items[spec->cur_mux[i]].index); |
| 664 | } |
| 665 | |
| 666 | /* init aa-mixer */ |
| 667 | if (!spec->aa_mix_nid) |
| 668 | return; |
| 669 | num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, |
| 670 | ARRAY_SIZE(conn)); |
| 671 | for (i = 0; i < num_conns; i++) { |
| 672 | unsigned int caps = get_wcaps(codec, conn[i]); |
| 673 | if (get_wcaps_type(caps) == AC_WID_PIN) |
| 674 | snd_hda_codec_write(codec, spec->aa_mix_nid, 0, |
| 675 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 676 | AMP_IN_MUTE(i)); |
| 677 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 678 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 679 | |
| 680 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 681 | unsigned int *affected_parm) |
| 682 | { |
| 683 | unsigned parm; |
| 684 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 685 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) |
| 686 | >> AC_DEFCFG_MISC_SHIFT |
| 687 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 688 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 689 | unsigned present = 0; |
| 690 | |
| 691 | no_presence |= spec->no_pin_power_ctl; |
| 692 | if (!no_presence) |
| 693 | present = snd_hda_jack_detect(codec, nid); |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 694 | if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 695 | || ((no_presence || present) |
| 696 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 697 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
| 698 | parm = AC_PWRST_D0; |
| 699 | } else |
| 700 | parm = AC_PWRST_D3; |
| 701 | |
| 702 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 703 | } |
| 704 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 705 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
| 706 | struct snd_ctl_elem_info *uinfo) |
| 707 | { |
| 708 | static const char * const texts[] = { |
| 709 | "Disabled", "Enabled" |
| 710 | }; |
| 711 | |
| 712 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 713 | uinfo->count = 1; |
| 714 | uinfo->value.enumerated.items = 2; |
| 715 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 716 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 717 | strcpy(uinfo->value.enumerated.name, |
| 718 | texts[uinfo->value.enumerated.item]); |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, |
| 723 | struct snd_ctl_elem_value *ucontrol) |
| 724 | { |
| 725 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 726 | struct via_spec *spec = codec->spec; |
| 727 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, |
| 732 | struct snd_ctl_elem_value *ucontrol) |
| 733 | { |
| 734 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 735 | struct via_spec *spec = codec->spec; |
| 736 | unsigned int val = !ucontrol->value.enumerated.item[0]; |
| 737 | |
| 738 | if (val == spec->no_pin_power_ctl) |
| 739 | return 0; |
| 740 | spec->no_pin_power_ctl = val; |
| 741 | set_widgets_power_state(codec); |
| 742 | return 1; |
| 743 | } |
| 744 | |
| 745 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { |
| 746 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 747 | .name = "Dynamic Power-Control", |
| 748 | .info = via_pin_power_ctl_info, |
| 749 | .get = via_pin_power_ctl_get, |
| 750 | .put = via_pin_power_ctl_put, |
| 751 | }; |
| 752 | |
| 753 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 754 | /* |
| 755 | * input MUX handling |
| 756 | */ |
| 757 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 758 | struct snd_ctl_elem_info *uinfo) |
| 759 | { |
| 760 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 761 | struct via_spec *spec = codec->spec; |
| 762 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
| 763 | } |
| 764 | |
| 765 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 766 | struct snd_ctl_elem_value *ucontrol) |
| 767 | { |
| 768 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 769 | struct via_spec *spec = codec->spec; |
| 770 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 771 | |
| 772 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 777 | struct snd_ctl_elem_value *ucontrol) |
| 778 | { |
| 779 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 780 | struct via_spec *spec = codec->spec; |
| 781 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 782 | int ret; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 783 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 784 | if (!spec->mux_nids[adc_idx]) |
| 785 | return -EINVAL; |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 786 | /* switch to D0 beofre change index */ |
| 787 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, |
| 788 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) |
| 789 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, |
| 790 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 791 | |
| 792 | ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
| 793 | spec->mux_nids[adc_idx], |
| 794 | &spec->cur_mux[adc_idx]); |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 795 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 796 | set_widgets_power_state(codec); |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 797 | |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 798 | return ret; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 799 | } |
| 800 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 801 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
| 802 | struct snd_ctl_elem_info *uinfo) |
| 803 | { |
| 804 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 805 | struct via_spec *spec = codec->spec; |
| 806 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); |
| 807 | } |
| 808 | |
| 809 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, |
| 810 | struct snd_ctl_elem_value *ucontrol) |
| 811 | { |
| 812 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 813 | struct via_spec *spec = codec->spec; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 814 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 815 | ucontrol->value.enumerated.item[0] = spec->hp_independent_mode; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 816 | return 0; |
| 817 | } |
| 818 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 819 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
| 820 | struct snd_ctl_elem_value *ucontrol) |
| 821 | { |
| 822 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 823 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 824 | hda_nid_t nid = kcontrol->private_value; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 825 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 826 | /* Get Independent Mode index of headphone pin widget */ |
| 827 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel |
| 828 | ? 1 : 0; |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 829 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 830 | |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 831 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 832 | set_widgets_power_state(codec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 836 | static const struct snd_kcontrol_new via_hp_mixer = { |
| 837 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 838 | .name = "Independent HP", |
| 839 | .info = via_independent_hp_info, |
| 840 | .get = via_independent_hp_get, |
| 841 | .put = via_independent_hp_put, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 842 | }; |
| 843 | |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 844 | static int via_hp_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 845 | { |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 846 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 847 | struct snd_kcontrol_new *knew; |
| 848 | hda_nid_t nid; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 849 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 850 | nid = spec->autocfg.hp_pins[0]; |
| 851 | knew = via_clone_control(spec, &via_hp_mixer); |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 852 | if (knew == NULL) |
| 853 | return -ENOMEM; |
| 854 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 855 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
| 856 | knew->private_value = nid; |
| 857 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 858 | return 0; |
| 859 | } |
| 860 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 861 | static void notify_aa_path_ctls(struct hda_codec *codec) |
| 862 | { |
| 863 | int i; |
| 864 | struct snd_ctl_elem_id id; |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 865 | const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"}; |
| 866 | struct snd_kcontrol *ctl; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 867 | |
| 868 | memset(&id, 0, sizeof(id)); |
| 869 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 870 | for (i = 0; i < ARRAY_SIZE(labels); i++) { |
| 871 | sprintf(id.name, "%s Playback Volume", labels[i]); |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 872 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
| 873 | if (ctl) |
| 874 | snd_ctl_notify(codec->bus->card, |
| 875 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 876 | &ctl->id); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | static void mute_aa_path(struct hda_codec *codec, int mute) |
| 881 | { |
| 882 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 883 | int start_idx; |
| 884 | int end_idx; |
| 885 | int i; |
| 886 | /* get nid of MW0 and start & end index */ |
| 887 | switch (spec->codec_type) { |
| 888 | case VT1708: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 889 | start_idx = 2; |
| 890 | end_idx = 4; |
| 891 | break; |
| 892 | case VT1709_10CH: |
| 893 | case VT1709_6CH: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 894 | start_idx = 2; |
| 895 | end_idx = 4; |
| 896 | break; |
| 897 | case VT1708B_8CH: |
| 898 | case VT1708B_4CH: |
| 899 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 900 | case VT1716S: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 901 | start_idx = 2; |
| 902 | end_idx = 4; |
| 903 | break; |
Lydia Wang | ab657e0 | 2011-03-22 16:23:23 +0800 | [diff] [blame] | 904 | case VT1718S: |
Lydia Wang | ab657e0 | 2011-03-22 16:23:23 +0800 | [diff] [blame] | 905 | start_idx = 1; |
| 906 | end_idx = 3; |
| 907 | break; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 908 | default: |
| 909 | return; |
| 910 | } |
| 911 | /* check AA path's mute status */ |
| 912 | for (i = start_idx; i <= end_idx; i++) { |
| 913 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 914 | snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i, |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 915 | HDA_AMP_MUTE, val); |
| 916 | } |
| 917 | } |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 918 | |
| 919 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 920 | { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 921 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 922 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 923 | int i; |
| 924 | |
| 925 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 926 | unsigned int defcfg; |
| 927 | if (pin != cfg->inputs[i].pin) |
| 928 | continue; |
| 929 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 930 | return false; |
| 931 | defcfg = snd_hda_codec_get_pincfg(codec, pin); |
| 932 | if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL) |
| 933 | return false; |
| 934 | return true; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 935 | } |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 936 | return false; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | static int via_smart51_info(struct snd_kcontrol *kcontrol, |
| 940 | struct snd_ctl_elem_info *uinfo) |
| 941 | { |
| 942 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 943 | uinfo->count = 1; |
| 944 | uinfo->value.integer.min = 0; |
| 945 | uinfo->value.integer.max = 1; |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | static int via_smart51_get(struct snd_kcontrol *kcontrol, |
| 950 | struct snd_ctl_elem_value *ucontrol) |
| 951 | { |
| 952 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 953 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 954 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 955 | int on = 1; |
| 956 | int i; |
| 957 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 958 | for (i = 0; i < cfg->num_inputs; i++) { |
| 959 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 960 | unsigned int ctl; |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 961 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 962 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
| 963 | continue; /* ignore FMic for independent HP */ |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 964 | if (!is_smart51_pins(codec, nid)) |
| 965 | continue; |
| 966 | ctl = snd_hda_codec_read(codec, nid, 0, |
| 967 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 968 | if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) |
| 969 | on = 0; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 970 | } |
| 971 | *ucontrol->value.integer.value = on; |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | static int via_smart51_put(struct snd_kcontrol *kcontrol, |
| 976 | struct snd_ctl_elem_value *ucontrol) |
| 977 | { |
| 978 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 979 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 980 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 981 | int out_in = *ucontrol->value.integer.value |
| 982 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 983 | int i; |
| 984 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 985 | for (i = 0; i < cfg->num_inputs; i++) { |
| 986 | hda_nid_t nid = cfg->inputs[i].pin; |
| 987 | unsigned int parm; |
| 988 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 989 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 990 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 991 | continue; /* don't retask FMic for independent HP */ |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 992 | if (!is_smart51_pins(codec, nid)) |
| 993 | continue; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 994 | |
| 995 | parm = snd_hda_codec_read(codec, nid, 0, |
| 996 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 997 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); |
| 998 | parm |= out_in; |
| 999 | snd_hda_codec_write(codec, nid, 0, |
| 1000 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1001 | parm); |
| 1002 | if (out_in == AC_PINCTL_OUT_EN) { |
| 1003 | mute_aa_path(codec, 1); |
| 1004 | notify_aa_path_ctls(codec); |
| 1005 | } |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1006 | } |
| 1007 | spec->smart51_enabled = *ucontrol->value.integer.value; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1008 | set_widgets_power_state(codec); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1009 | return 1; |
| 1010 | } |
| 1011 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1012 | static const struct snd_kcontrol_new via_smart51_mixer = { |
| 1013 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1014 | .name = "Smart 5.1", |
| 1015 | .count = 1, |
| 1016 | .info = via_smart51_info, |
| 1017 | .get = via_smart51_get, |
| 1018 | .put = via_smart51_put, |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1019 | }; |
| 1020 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1021 | static int via_smart51_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1022 | { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1023 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1024 | struct snd_kcontrol_new *knew; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1025 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1026 | hda_nid_t nid; |
| 1027 | int i; |
| 1028 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1029 | if (!spec->can_smart51) |
Lydia Wang | cb34c20 | 2011-04-27 17:44:16 +0800 | [diff] [blame] | 1030 | return 0; |
| 1031 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1032 | knew = via_clone_control(spec, &via_smart51_mixer); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1033 | if (knew == NULL) |
| 1034 | return -ENOMEM; |
| 1035 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1036 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1037 | nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1038 | if (is_smart51_pins(codec, nid)) { |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1039 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1040 | break; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1047 | /* check AA path's mute statue */ |
| 1048 | static int is_aa_path_mute(struct hda_codec *codec) |
| 1049 | { |
| 1050 | int mute = 1; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1051 | int start_idx; |
| 1052 | int end_idx; |
| 1053 | int i; |
| 1054 | struct via_spec *spec = codec->spec; |
| 1055 | /* get nid of MW0 and start & end index */ |
| 1056 | switch (spec->codec_type) { |
| 1057 | case VT1708B_8CH: |
| 1058 | case VT1708B_4CH: |
| 1059 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1060 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1061 | start_idx = 2; |
| 1062 | end_idx = 4; |
| 1063 | break; |
| 1064 | case VT1702: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1065 | start_idx = 1; |
| 1066 | end_idx = 3; |
| 1067 | break; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1068 | case VT1718S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1069 | start_idx = 1; |
| 1070 | end_idx = 3; |
| 1071 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1072 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1073 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1074 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1075 | start_idx = 0; |
| 1076 | end_idx = 2; |
| 1077 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1078 | default: |
| 1079 | return 0; |
| 1080 | } |
| 1081 | /* check AA path's mute status */ |
| 1082 | for (i = start_idx; i <= end_idx; i++) { |
| 1083 | unsigned int con_list = snd_hda_codec_read( |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1084 | codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1085 | int shift = 8 * (i % 4); |
| 1086 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; |
| 1087 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); |
| 1088 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { |
| 1089 | /* check mute status while the pin is connected */ |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1090 | int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1091 | HDA_INPUT, i) >> 7; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1092 | int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1093 | HDA_INPUT, i) >> 7; |
| 1094 | if (!mute_l || !mute_r) { |
| 1095 | mute = 0; |
| 1096 | break; |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | return mute; |
| 1101 | } |
| 1102 | |
| 1103 | /* enter/exit analog low-current mode */ |
| 1104 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) |
| 1105 | { |
| 1106 | struct via_spec *spec = codec->spec; |
| 1107 | static int saved_stream_idle = 1; /* saved stream idle status */ |
| 1108 | int enable = is_aa_path_mute(codec); |
| 1109 | unsigned int verb = 0; |
| 1110 | unsigned int parm = 0; |
| 1111 | |
| 1112 | if (stream_idle == -1) /* stream status did not change */ |
| 1113 | enable = enable && saved_stream_idle; |
| 1114 | else { |
| 1115 | enable = enable && stream_idle; |
| 1116 | saved_stream_idle = stream_idle; |
| 1117 | } |
| 1118 | |
| 1119 | /* decide low current mode's verb & parameter */ |
| 1120 | switch (spec->codec_type) { |
| 1121 | case VT1708B_8CH: |
| 1122 | case VT1708B_4CH: |
| 1123 | verb = 0xf70; |
| 1124 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 1125 | break; |
| 1126 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1127 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1128 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1129 | verb = 0xf73; |
| 1130 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 1131 | break; |
| 1132 | case VT1702: |
| 1133 | verb = 0xf73; |
| 1134 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 1135 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1136 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1137 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1138 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1139 | verb = 0xf93; |
| 1140 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 1141 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1142 | default: |
| 1143 | return; /* other codecs are not supported */ |
| 1144 | } |
| 1145 | /* send verb */ |
| 1146 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); |
| 1147 | } |
| 1148 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1149 | /* |
| 1150 | * generic initialization of ADC, input mixers and output mixers |
| 1151 | */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 1152 | static const struct hda_verb vt1708_init_verbs[] = { |
Lydia Wang | aa266fc | 2011-03-24 12:41:01 +0800 | [diff] [blame] | 1153 | /* power down jack detect function */ |
| 1154 | {0x1, 0xf81, 0x1}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1155 | { } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1156 | }; |
| 1157 | |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1158 | static void substream_set_idle(struct hda_codec *codec, |
| 1159 | struct snd_pcm_substream *substream) |
| 1160 | { |
| 1161 | int idle = substream->pstr->substream_opened == 1 |
| 1162 | && substream->ref_count == 0; |
| 1163 | analog_low_current_mode(codec, idle); |
| 1164 | } |
| 1165 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1166 | static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1167 | struct hda_codec *codec, |
| 1168 | struct snd_pcm_substream *substream) |
| 1169 | { |
| 1170 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1171 | |
| 1172 | if (!spec->hp_independent_mode) |
| 1173 | spec->multiout.hp_nid = spec->hp_dac_nid; |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1174 | substream_set_idle(codec, substream); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1175 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 1176 | hinfo); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1177 | } |
| 1178 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1179 | static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1180 | struct hda_codec *codec, |
| 1181 | struct snd_pcm_substream *substream) |
| 1182 | { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1183 | struct via_spec *spec = codec->spec; |
| 1184 | |
| 1185 | spec->multiout.hp_nid = 0; |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1186 | substream_set_idle(codec, substream); |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1187 | return 0; |
| 1188 | } |
| 1189 | |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1190 | static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, |
| 1191 | struct hda_codec *codec, |
| 1192 | struct snd_pcm_substream *substream) |
| 1193 | { |
| 1194 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1195 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1196 | if (snd_BUG_ON(!spec->hp_dac_nid)) |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1197 | return -EINVAL; |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1198 | if (!spec->hp_independent_mode || spec->multiout.hp_nid) |
| 1199 | return -EBUSY; |
| 1200 | substream_set_idle(codec, substream); |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo, |
| 1205 | struct hda_codec *codec, |
| 1206 | struct snd_pcm_substream *substream) |
| 1207 | { |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1208 | substream_set_idle(codec, substream); |
| 1209 | return 0; |
| 1210 | } |
| 1211 | |
| 1212 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1213 | struct hda_codec *codec, |
| 1214 | unsigned int stream_tag, |
| 1215 | unsigned int format, |
| 1216 | struct snd_pcm_substream *substream) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1217 | { |
| 1218 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1219 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1220 | snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, |
| 1221 | format, substream); |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1222 | vt1708_start_hp_work(spec); |
| 1223 | return 0; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1224 | } |
| 1225 | |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1226 | static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1227 | struct hda_codec *codec, |
| 1228 | unsigned int stream_tag, |
| 1229 | unsigned int format, |
| 1230 | struct snd_pcm_substream *substream) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1231 | { |
| 1232 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1233 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1234 | snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, |
| 1235 | stream_tag, 0, format); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1236 | vt1708_start_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1241 | struct hda_codec *codec, |
| 1242 | struct snd_pcm_substream *substream) |
| 1243 | { |
| 1244 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1245 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1246 | snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1247 | vt1708_stop_hp_work(spec); |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1252 | struct hda_codec *codec, |
| 1253 | struct snd_pcm_substream *substream) |
| 1254 | { |
| 1255 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1256 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1257 | snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1258 | vt1708_stop_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1259 | return 0; |
| 1260 | } |
| 1261 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1262 | /* |
| 1263 | * Digital out |
| 1264 | */ |
| 1265 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1266 | struct hda_codec *codec, |
| 1267 | struct snd_pcm_substream *substream) |
| 1268 | { |
| 1269 | struct via_spec *spec = codec->spec; |
| 1270 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 1271 | } |
| 1272 | |
| 1273 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1274 | struct hda_codec *codec, |
| 1275 | struct snd_pcm_substream *substream) |
| 1276 | { |
| 1277 | struct via_spec *spec = codec->spec; |
| 1278 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 1279 | } |
| 1280 | |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1281 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1282 | struct hda_codec *codec, |
| 1283 | unsigned int stream_tag, |
| 1284 | unsigned int format, |
| 1285 | struct snd_pcm_substream *substream) |
| 1286 | { |
| 1287 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1288 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 1289 | stream_tag, format, substream); |
| 1290 | } |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1291 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1292 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1293 | struct hda_codec *codec, |
| 1294 | struct snd_pcm_substream *substream) |
| 1295 | { |
| 1296 | struct via_spec *spec = codec->spec; |
| 1297 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1298 | return 0; |
| 1299 | } |
| 1300 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1301 | /* |
| 1302 | * Analog capture |
| 1303 | */ |
| 1304 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1305 | struct hda_codec *codec, |
| 1306 | unsigned int stream_tag, |
| 1307 | unsigned int format, |
| 1308 | struct snd_pcm_substream *substream) |
| 1309 | { |
| 1310 | struct via_spec *spec = codec->spec; |
| 1311 | |
| 1312 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 1313 | stream_tag, 0, format); |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1318 | struct hda_codec *codec, |
| 1319 | struct snd_pcm_substream *substream) |
| 1320 | { |
| 1321 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1322 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1323 | return 0; |
| 1324 | } |
| 1325 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1326 | static const struct hda_pcm_stream via_pcm_analog_playback = { |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1327 | .substreams = 1, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1328 | .channels_min = 2, |
| 1329 | .channels_max = 8, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1330 | /* NID is set in via_build_pcms */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1331 | .ops = { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1332 | .open = via_playback_multi_pcm_open, |
| 1333 | .close = via_playback_multi_pcm_close, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1334 | .prepare = via_playback_multi_pcm_prepare, |
| 1335 | .cleanup = via_playback_multi_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1336 | }, |
| 1337 | }; |
| 1338 | |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1339 | static const struct hda_pcm_stream via_pcm_hp_playback = { |
| 1340 | .substreams = 1, |
| 1341 | .channels_min = 2, |
| 1342 | .channels_max = 2, |
| 1343 | /* NID is set in via_build_pcms */ |
| 1344 | .ops = { |
| 1345 | .open = via_playback_hp_pcm_open, |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1346 | .close = via_playback_hp_pcm_close, |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1347 | .prepare = via_playback_hp_pcm_prepare, |
| 1348 | .cleanup = via_playback_hp_pcm_cleanup |
| 1349 | }, |
| 1350 | }; |
| 1351 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1352 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1353 | .substreams = 1, |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1354 | .channels_min = 2, |
| 1355 | .channels_max = 8, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1356 | /* NID is set in via_build_pcms */ |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1357 | /* We got noisy outputs on the right channel on VT1708 when |
| 1358 | * 24bit samples are used. Until any workaround is found, |
| 1359 | * disable the 24bit format, so far. |
| 1360 | */ |
| 1361 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1362 | .ops = { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1363 | .open = via_playback_multi_pcm_open, |
| 1364 | .close = via_playback_multi_pcm_close, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1365 | .prepare = via_playback_multi_pcm_prepare, |
| 1366 | .cleanup = via_playback_multi_pcm_cleanup |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1367 | }, |
| 1368 | }; |
| 1369 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1370 | static const struct hda_pcm_stream via_pcm_analog_capture = { |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1371 | .substreams = 1, /* will be changed in via_build_pcms() */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1372 | .channels_min = 2, |
| 1373 | .channels_max = 2, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1374 | /* NID is set in via_build_pcms */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1375 | .ops = { |
| 1376 | .prepare = via_capture_pcm_prepare, |
| 1377 | .cleanup = via_capture_pcm_cleanup |
| 1378 | }, |
| 1379 | }; |
| 1380 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1381 | static const struct hda_pcm_stream via_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1382 | .substreams = 1, |
| 1383 | .channels_min = 2, |
| 1384 | .channels_max = 2, |
| 1385 | /* NID is set in via_build_pcms */ |
| 1386 | .ops = { |
| 1387 | .open = via_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 1388 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1389 | .prepare = via_dig_playback_pcm_prepare, |
| 1390 | .cleanup = via_dig_playback_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1391 | }, |
| 1392 | }; |
| 1393 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1394 | static const struct hda_pcm_stream via_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1395 | .substreams = 1, |
| 1396 | .channels_min = 2, |
| 1397 | .channels_max = 2, |
| 1398 | }; |
| 1399 | |
| 1400 | static int via_build_controls(struct hda_codec *codec) |
| 1401 | { |
| 1402 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1403 | struct snd_kcontrol *kctl; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1404 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1405 | int err, i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1406 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 1407 | if (spec->set_widgets_power_state) |
| 1408 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) |
| 1409 | return -ENOMEM; |
| 1410 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1411 | for (i = 0; i < spec->num_mixers; i++) { |
| 1412 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1413 | if (err < 0) |
| 1414 | return err; |
| 1415 | } |
| 1416 | |
| 1417 | if (spec->multiout.dig_out_nid) { |
| 1418 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1419 | spec->multiout.dig_out_nid, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1420 | spec->multiout.dig_out_nid); |
| 1421 | if (err < 0) |
| 1422 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1423 | err = snd_hda_create_spdif_share_sw(codec, |
| 1424 | &spec->multiout); |
| 1425 | if (err < 0) |
| 1426 | return err; |
| 1427 | spec->multiout.share_spdif = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1428 | } |
| 1429 | if (spec->dig_in_nid) { |
| 1430 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1431 | if (err < 0) |
| 1432 | return err; |
| 1433 | } |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1434 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1435 | /* assign Capture Source enums to NID */ |
| 1436 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1437 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 1438 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1439 | if (err < 0) |
| 1440 | return err; |
| 1441 | } |
| 1442 | |
| 1443 | /* other nid->control mapping */ |
| 1444 | for (i = 0; i < spec->num_mixers; i++) { |
| 1445 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1446 | if (knew->iface != NID_MAPPING) |
| 1447 | continue; |
| 1448 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1449 | if (kctl == NULL) |
| 1450 | continue; |
| 1451 | err = snd_hda_add_nid(codec, kctl, 0, |
| 1452 | knew->subdevice); |
| 1453 | } |
| 1454 | } |
| 1455 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1456 | /* init power states */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1457 | set_widgets_power_state(codec); |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1458 | analog_low_current_mode(codec, 1); |
| 1459 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1460 | via_free_kctls(codec); /* no longer needed */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | static int via_build_pcms(struct hda_codec *codec) |
| 1465 | { |
| 1466 | struct via_spec *spec = codec->spec; |
| 1467 | struct hda_pcm *info = spec->pcm_rec; |
| 1468 | |
| 1469 | codec->num_pcms = 1; |
| 1470 | codec->pcm_info = info; |
| 1471 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1472 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 1473 | "%s Analog", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1474 | info->name = spec->stream_name_analog; |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1475 | |
| 1476 | if (!spec->stream_analog_playback) |
| 1477 | spec->stream_analog_playback = &via_pcm_analog_playback; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1478 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1479 | *spec->stream_analog_playback; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1480 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1481 | spec->multiout.dac_nids[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1482 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 1483 | spec->multiout.max_channels; |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1484 | |
| 1485 | if (!spec->stream_analog_capture) |
| 1486 | spec->stream_analog_capture = &via_pcm_analog_capture; |
| 1487 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 1488 | *spec->stream_analog_capture; |
| 1489 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 1490 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 1491 | spec->num_adc_nids; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1492 | |
| 1493 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 1494 | codec->num_pcms++; |
| 1495 | info++; |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1496 | snprintf(spec->stream_name_digital, |
| 1497 | sizeof(spec->stream_name_digital), |
| 1498 | "%s Digital", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1499 | info->name = spec->stream_name_digital; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 1500 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1501 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1502 | if (!spec->stream_digital_playback) |
| 1503 | spec->stream_digital_playback = |
| 1504 | &via_pcm_digital_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1505 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1506 | *spec->stream_digital_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1507 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1508 | spec->multiout.dig_out_nid; |
| 1509 | } |
| 1510 | if (spec->dig_in_nid) { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1511 | if (!spec->stream_digital_capture) |
| 1512 | spec->stream_digital_capture = |
| 1513 | &via_pcm_digital_capture; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1514 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1515 | *spec->stream_digital_capture; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1516 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 1517 | spec->dig_in_nid; |
| 1518 | } |
| 1519 | } |
| 1520 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1521 | if (spec->hp_dac_nid) { |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1522 | codec->num_pcms++; |
| 1523 | info++; |
| 1524 | snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), |
| 1525 | "%s HP", codec->chip_name); |
| 1526 | info->name = spec->stream_name_hp; |
| 1527 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; |
| 1528 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1529 | spec->hp_dac_nid; |
Takashi Iwai | 7eb56e84 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1530 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1531 | return 0; |
| 1532 | } |
| 1533 | |
| 1534 | static void via_free(struct hda_codec *codec) |
| 1535 | { |
| 1536 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1537 | |
| 1538 | if (!spec) |
| 1539 | return; |
| 1540 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1541 | via_free_kctls(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1542 | vt1708_stop_hp_work(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1543 | kfree(codec->spec); |
| 1544 | } |
| 1545 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1546 | /* mute/unmute outputs */ |
| 1547 | static void toggle_output_mutes(struct hda_codec *codec, int num_pins, |
| 1548 | hda_nid_t *pins, bool mute) |
| 1549 | { |
| 1550 | int i; |
| 1551 | for (i = 0; i < num_pins; i++) |
| 1552 | snd_hda_codec_write(codec, pins[i], 0, |
| 1553 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1554 | mute ? 0 : PIN_OUT); |
| 1555 | } |
| 1556 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1557 | /* mute internal speaker if HP is plugged */ |
| 1558 | static void via_hp_automute(struct hda_codec *codec) |
| 1559 | { |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1560 | unsigned int present = 0; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1561 | struct via_spec *spec = codec->spec; |
| 1562 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1563 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1564 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1565 | if (!spec->hp_independent_mode) |
| 1566 | toggle_output_mutes(codec, spec->autocfg.line_outs, |
| 1567 | spec->autocfg.line_out_pins, |
| 1568 | present); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1569 | } |
| 1570 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1571 | /* mute mono out if HP or Line out is plugged */ |
| 1572 | static void via_mono_automute(struct hda_codec *codec) |
| 1573 | { |
| 1574 | unsigned int hp_present, lineout_present; |
| 1575 | struct via_spec *spec = codec->spec; |
| 1576 | |
| 1577 | if (spec->codec_type != VT1716S) |
| 1578 | return; |
| 1579 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1580 | lineout_present = snd_hda_jack_detect(codec, |
| 1581 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1582 | |
| 1583 | /* Mute Mono Out if Line Out is plugged */ |
| 1584 | if (lineout_present) { |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1585 | snd_hda_codec_write(codec, 0x2A, 0, |
| 1586 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1587 | lineout_present ? 0 : PIN_OUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1588 | return; |
| 1589 | } |
| 1590 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1591 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1592 | |
| 1593 | if (!spec->hp_independent_mode) |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1594 | snd_hda_codec_write(codec, 0x2A, 0, |
| 1595 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1596 | hp_present ? 0 : PIN_OUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1597 | } |
| 1598 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1599 | static void via_gpio_control(struct hda_codec *codec) |
| 1600 | { |
| 1601 | unsigned int gpio_data; |
| 1602 | unsigned int vol_counter; |
| 1603 | unsigned int vol; |
| 1604 | unsigned int master_vol; |
| 1605 | |
| 1606 | struct via_spec *spec = codec->spec; |
| 1607 | |
| 1608 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, |
| 1609 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; |
| 1610 | |
| 1611 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, |
| 1612 | 0xF84, 0) & 0x3F0000) >> 16; |
| 1613 | |
| 1614 | vol = vol_counter & 0x1F; |
| 1615 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, |
| 1616 | AC_VERB_GET_AMP_GAIN_MUTE, |
| 1617 | AC_AMP_GET_INPUT); |
| 1618 | |
| 1619 | if (gpio_data == 0x02) { |
| 1620 | /* unmute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1621 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1622 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1623 | PIN_OUT); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1624 | if (vol_counter & 0x20) { |
| 1625 | /* decrease volume */ |
| 1626 | if (vol > master_vol) |
| 1627 | vol = master_vol; |
| 1628 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, |
| 1629 | 0, HDA_AMP_VOLMASK, |
| 1630 | master_vol-vol); |
| 1631 | } else { |
| 1632 | /* increase volume */ |
| 1633 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, |
| 1634 | HDA_AMP_VOLMASK, |
| 1635 | ((master_vol+vol) > 0x2A) ? 0x2A : |
| 1636 | (master_vol+vol)); |
| 1637 | } |
| 1638 | } else if (!(gpio_data & 0x02)) { |
| 1639 | /* mute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1640 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1641 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1642 | 0); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1643 | } |
| 1644 | } |
| 1645 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1646 | /* mute Internal-Speaker if HP is plugged */ |
| 1647 | static void via_speaker_automute(struct hda_codec *codec) |
| 1648 | { |
| 1649 | unsigned int hp_present; |
| 1650 | struct via_spec *spec = codec->spec; |
| 1651 | |
Lydia Wang | 27439ce | 2011-03-24 12:40:10 +0800 | [diff] [blame] | 1652 | if (!VT2002P_COMPATIBLE(spec)) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1653 | return; |
| 1654 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1655 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1656 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1657 | if (!spec->hp_independent_mode) |
| 1658 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1659 | spec->autocfg.speaker_pins, |
| 1660 | hp_present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | /* mute line-out and internal speaker if HP is plugged */ |
| 1664 | static void via_hp_bind_automute(struct hda_codec *codec) |
| 1665 | { |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1666 | int present; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1667 | struct via_spec *spec = codec->spec; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1668 | |
| 1669 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) |
| 1670 | return; |
| 1671 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1672 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
| 1673 | if (!spec->hp_independent_mode) |
| 1674 | toggle_output_mutes(codec, spec->autocfg.line_outs, |
| 1675 | spec->autocfg.line_out_pins, |
| 1676 | present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1677 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1678 | if (!present) |
| 1679 | present = snd_hda_jack_detect(codec, |
| 1680 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1681 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1682 | /* Speakers */ |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1683 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1684 | spec->autocfg.speaker_pins, |
| 1685 | present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1689 | /* unsolicited event for jack sensing */ |
| 1690 | static void via_unsol_event(struct hda_codec *codec, |
| 1691 | unsigned int res) |
| 1692 | { |
| 1693 | res >>= 26; |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1694 | |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 1695 | if (res & VIA_JACK_EVENT) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1696 | set_widgets_power_state(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1697 | |
| 1698 | res &= ~VIA_JACK_EVENT; |
| 1699 | |
| 1700 | if (res == VIA_HP_EVENT) |
| 1701 | via_hp_automute(codec); |
| 1702 | else if (res == VIA_GPIO_EVENT) |
| 1703 | via_gpio_control(codec); |
| 1704 | else if (res == VIA_MONO_EVENT) |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1705 | via_mono_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1706 | else if (res == VIA_SPEAKER_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1707 | via_speaker_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1708 | else if (res == VIA_BIND_HP_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1709 | via_hp_bind_automute(codec); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1710 | } |
| 1711 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1712 | #ifdef SND_HDA_NEEDS_RESUME |
| 1713 | static int via_suspend(struct hda_codec *codec, pm_message_t state) |
| 1714 | { |
| 1715 | struct via_spec *spec = codec->spec; |
| 1716 | vt1708_stop_hp_work(spec); |
| 1717 | return 0; |
| 1718 | } |
| 1719 | #endif |
| 1720 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1721 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1722 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 1723 | { |
| 1724 | struct via_spec *spec = codec->spec; |
| 1725 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 1726 | } |
| 1727 | #endif |
| 1728 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1729 | /* |
| 1730 | */ |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 1731 | |
| 1732 | static int via_init(struct hda_codec *codec); |
| 1733 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1734 | static const struct hda_codec_ops via_patch_ops = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1735 | .build_controls = via_build_controls, |
| 1736 | .build_pcms = via_build_pcms, |
| 1737 | .init = via_init, |
| 1738 | .free = via_free, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1739 | #ifdef SND_HDA_NEEDS_RESUME |
| 1740 | .suspend = via_suspend, |
| 1741 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1742 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1743 | .check_power_status = via_check_power_status, |
| 1744 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1745 | }; |
| 1746 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1747 | static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1748 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1749 | struct via_spec *spec = codec->spec; |
| 1750 | int i; |
| 1751 | |
| 1752 | for (i = 0; i < spec->multiout.num_dacs; i++) { |
| 1753 | if (spec->multiout.dac_nids[i] == dac) |
| 1754 | return false; |
| 1755 | } |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1756 | if (spec->hp_dac_nid == dac) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1757 | return false; |
| 1758 | return true; |
| 1759 | } |
| 1760 | |
| 1761 | static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
| 1762 | hda_nid_t target_dac, struct nid_path *path, |
| 1763 | int depth, int wid_type) |
| 1764 | { |
| 1765 | hda_nid_t conn[8]; |
| 1766 | int i, nums; |
| 1767 | |
| 1768 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); |
| 1769 | for (i = 0; i < nums; i++) { |
| 1770 | if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) |
| 1771 | continue; |
| 1772 | if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { |
| 1773 | path->path[depth] = conn[i]; |
| 1774 | path->idx[depth] = i; |
| 1775 | path->depth = ++depth; |
| 1776 | return true; |
| 1777 | } |
| 1778 | } |
| 1779 | if (depth > 4) |
| 1780 | return false; |
| 1781 | for (i = 0; i < nums; i++) { |
| 1782 | unsigned int type; |
| 1783 | type = get_wcaps_type(get_wcaps(codec, conn[i])); |
| 1784 | if (type == AC_WID_AUD_OUT || |
| 1785 | (wid_type != -1 && type != wid_type)) |
| 1786 | continue; |
| 1787 | if (parse_output_path(codec, conn[i], target_dac, |
| 1788 | path, depth + 1, AC_WID_AUD_SEL)) { |
| 1789 | path->path[depth] = conn[i]; |
| 1790 | path->idx[depth] = i; |
| 1791 | return true; |
| 1792 | } |
| 1793 | } |
| 1794 | return false; |
| 1795 | } |
| 1796 | |
| 1797 | static int via_auto_fill_dac_nids(struct hda_codec *codec) |
| 1798 | { |
| 1799 | struct via_spec *spec = codec->spec; |
| 1800 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1801 | int i; |
| 1802 | hda_nid_t nid; |
| 1803 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1804 | spec->multiout.dac_nids = spec->private_dac_nids; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1805 | spec->multiout.num_dacs = cfg->line_outs; |
| 1806 | for (i = 0; i < cfg->line_outs; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1807 | nid = cfg->line_out_pins[i]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1808 | if (!nid) |
| 1809 | continue; |
| 1810 | if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1)) |
| 1811 | spec->private_dac_nids[i] = |
| 1812 | spec->out_path[i].path[spec->out_path[i].depth - 1]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1813 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1817 | static int create_ch_ctls(struct hda_codec *codec, const char *pfx, |
| 1818 | hda_nid_t pin, hda_nid_t dac, int chs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1819 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1820 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1821 | char name[32]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1822 | hda_nid_t nid; |
| 1823 | int err; |
| 1824 | |
| 1825 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
| 1826 | nid = dac; |
| 1827 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
| 1828 | nid = pin; |
| 1829 | else |
| 1830 | nid = 0; |
| 1831 | if (nid) { |
| 1832 | sprintf(name, "%s Playback Volume", pfx); |
| 1833 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 1834 | HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT)); |
| 1835 | if (err < 0) |
| 1836 | return err; |
| 1837 | } |
| 1838 | |
| 1839 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 1840 | nid = dac; |
| 1841 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 1842 | nid = pin; |
| 1843 | else |
| 1844 | nid = 0; |
| 1845 | if (nid) { |
| 1846 | sprintf(name, "%s Playback Switch", pfx); |
| 1847 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 1848 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
| 1849 | if (err < 0) |
| 1850 | return err; |
| 1851 | } |
| 1852 | return 0; |
| 1853 | } |
| 1854 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1855 | static void mangle_smart51(struct hda_codec *codec) |
| 1856 | { |
| 1857 | struct via_spec *spec = codec->spec; |
| 1858 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1859 | int i; |
| 1860 | |
| 1861 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1862 | if (!is_smart51_pins(codec, cfg->inputs[i].pin)) |
| 1863 | continue; |
| 1864 | spec->can_smart51 = 1; |
| 1865 | cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; |
| 1866 | if (cfg->line_outs == 3) |
| 1867 | break; |
| 1868 | } |
| 1869 | } |
| 1870 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1871 | /* add playback controls from the parsed DAC table */ |
| 1872 | static int via_auto_create_multi_out_ctls(struct hda_codec *codec) |
| 1873 | { |
| 1874 | struct via_spec *spec = codec->spec; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1875 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1876 | static const char * const chname[4] = { |
| 1877 | "Front", "Surround", "C/LFE", "Side" |
| 1878 | }; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1879 | int i, idx, err; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1880 | int old_line_outs; |
| 1881 | |
| 1882 | /* check smart51 */ |
| 1883 | old_line_outs = cfg->line_outs; |
| 1884 | if (cfg->line_outs == 1) |
| 1885 | mangle_smart51(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1886 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1887 | for (i = 0; i < cfg->line_outs; i++) { |
| 1888 | hda_nid_t pin, dac; |
| 1889 | pin = cfg->line_out_pins[i]; |
| 1890 | dac = spec->multiout.dac_nids[i]; |
| 1891 | if (!pin || !dac) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1892 | continue; |
Takashi Iwai | 0fe0adf | 2011-06-19 16:27:53 +0200 | [diff] [blame] | 1893 | if (i == HDA_CLFE) { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1894 | err = create_ch_ctls(codec, "Center", pin, dac, 1); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1895 | if (err < 0) |
| 1896 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1897 | err = create_ch_ctls(codec, "LFE", pin, dac, 2); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1898 | if (err < 0) |
| 1899 | return err; |
| 1900 | } else { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1901 | err = create_ch_ctls(codec, chname[i], pin, dac, 3); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1902 | if (err < 0) |
| 1903 | return err; |
| 1904 | } |
| 1905 | } |
| 1906 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1907 | idx = get_connection_index(codec, spec->aa_mix_nid, |
| 1908 | spec->multiout.dac_nids[0]); |
| 1909 | if (idx >= 0) { |
| 1910 | /* add control to mixer */ |
| 1911 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 1912 | "PCM Playback Volume", |
| 1913 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 1914 | idx, HDA_INPUT)); |
| 1915 | if (err < 0) |
| 1916 | return err; |
| 1917 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 1918 | "PCM Playback Switch", |
| 1919 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 1920 | idx, HDA_INPUT)); |
| 1921 | if (err < 0) |
| 1922 | return err; |
| 1923 | } |
| 1924 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1925 | cfg->line_outs = old_line_outs; |
| 1926 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1927 | return 0; |
| 1928 | } |
| 1929 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1930 | static void create_hp_imux(struct via_spec *spec) |
| 1931 | { |
| 1932 | int i; |
| 1933 | struct hda_input_mux *imux = &spec->private_imux[1]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1934 | static const char * const texts[] = { "OFF", "ON", NULL}; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1935 | |
| 1936 | /* for hp mode select */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 1937 | for (i = 0; texts[i]; i++) |
| 1938 | snd_hda_add_imux_item(imux, texts[i], i, NULL); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1939 | |
| 1940 | spec->hp_mux = &spec->private_imux[1]; |
| 1941 | } |
| 1942 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1943 | static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1944 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1945 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1946 | int err; |
| 1947 | |
| 1948 | if (!pin) |
| 1949 | return 0; |
| 1950 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1951 | if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1952 | spec->hp_dac_nid = spec->hp_path.path[spec->hp_path.depth - 1]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1953 | spec->hp_independent_mode_index = |
| 1954 | spec->hp_path.idx[spec->hp_path.depth - 1]; |
| 1955 | create_hp_imux(spec); |
| 1956 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1957 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1958 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
| 1959 | &spec->hp_dep_path, 0, -1) && |
| 1960 | !spec->hp_dac_nid) |
| 1961 | return 0; |
| 1962 | |
| 1963 | |
| 1964 | err = create_ch_ctls(codec, "Headphone", pin, spec->hp_dac_nid, 3); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1965 | if (err < 0) |
| 1966 | return err; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1967 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1968 | return 0; |
| 1969 | } |
| 1970 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 1971 | /* look for ADCs */ |
| 1972 | static int via_fill_adcs(struct hda_codec *codec) |
| 1973 | { |
| 1974 | struct via_spec *spec = codec->spec; |
| 1975 | hda_nid_t nid = codec->start_nid; |
| 1976 | int i; |
| 1977 | |
| 1978 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 1979 | unsigned int wcaps = get_wcaps(codec, nid); |
| 1980 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 1981 | continue; |
| 1982 | if (wcaps & AC_WCAP_DIGITAL) |
| 1983 | continue; |
| 1984 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 1985 | continue; |
| 1986 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) |
| 1987 | return -ENOMEM; |
| 1988 | spec->adc_nids[spec->num_adc_nids++] = nid; |
| 1989 | } |
| 1990 | return 0; |
| 1991 | } |
| 1992 | |
| 1993 | static int get_mux_nids(struct hda_codec *codec); |
| 1994 | |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 1995 | static const struct snd_kcontrol_new via_input_src_ctl = { |
| 1996 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1997 | /* The multiple "Capture Source" controls confuse alsamixer |
| 1998 | * So call somewhat different.. |
| 1999 | */ |
| 2000 | /* .name = "Capture Source", */ |
| 2001 | .name = "Input Source", |
| 2002 | .info = via_mux_enum_info, |
| 2003 | .get = via_mux_enum_get, |
| 2004 | .put = via_mux_enum_put, |
| 2005 | }; |
| 2006 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2007 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2008 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec, |
| 2009 | const struct auto_pin_cfg *cfg) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2010 | { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2011 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2012 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2013 | int i, err, idx, idx2, type, type_idx = 0; |
| 2014 | hda_nid_t cap_nid; |
| 2015 | hda_nid_t pin_idxs[8]; |
| 2016 | int num_idxs; |
| 2017 | |
| 2018 | err = via_fill_adcs(codec); |
| 2019 | if (err < 0) |
| 2020 | return err; |
| 2021 | err = get_mux_nids(codec); |
| 2022 | if (err < 0) |
| 2023 | return err; |
| 2024 | cap_nid = spec->mux_nids[0]; |
| 2025 | |
| 2026 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, |
| 2027 | ARRAY_SIZE(pin_idxs)); |
| 2028 | if (num_idxs <= 0) |
| 2029 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2030 | |
| 2031 | /* for internal loopback recording select */ |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2032 | for (idx = 0; idx < num_idxs; idx++) { |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2033 | if (pin_idxs[idx] == spec->aa_mix_nid) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2034 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2035 | break; |
| 2036 | } |
| 2037 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2038 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2039 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2040 | const char *label; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2041 | type = cfg->inputs[i].type; |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2042 | for (idx = 0; idx < num_idxs; idx++) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2043 | if (pin_idxs[idx] == cfg->inputs[i].pin) |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2044 | break; |
| 2045 | if (idx >= num_idxs) |
| 2046 | continue; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2047 | if (i > 0 && type == cfg->inputs[i - 1].type) |
| 2048 | type_idx++; |
| 2049 | else |
| 2050 | type_idx = 0; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2051 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2052 | idx2 = get_connection_index(codec, spec->aa_mix_nid, |
| 2053 | pin_idxs[idx]); |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2054 | if (idx2 >= 0) |
Lydia Wang | 1692228 | 2011-03-22 16:24:10 +0800 | [diff] [blame] | 2055 | err = via_new_analog_input(spec, label, type_idx, |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2056 | idx2, spec->aa_mix_nid); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2057 | if (err < 0) |
| 2058 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2059 | snd_hda_add_imux_item(imux, label, idx, NULL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2060 | } |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2061 | |
| 2062 | /* create capture mixer elements */ |
| 2063 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2064 | hda_nid_t adc = spec->adc_nids[i]; |
| 2065 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2066 | "Capture Volume", i, |
| 2067 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, |
| 2068 | HDA_INPUT)); |
| 2069 | if (err < 0) |
| 2070 | return err; |
| 2071 | err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2072 | "Capture Switch", i, |
| 2073 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, |
| 2074 | HDA_INPUT)); |
| 2075 | if (err < 0) |
| 2076 | return err; |
| 2077 | } |
| 2078 | |
| 2079 | /* input-source control */ |
| 2080 | for (i = 0; i < spec->num_adc_nids; i++) |
| 2081 | if (!spec->mux_nids[i]) |
| 2082 | break; |
| 2083 | if (i) { |
| 2084 | struct snd_kcontrol_new *knew; |
| 2085 | knew = via_clone_control(spec, &via_input_src_ctl); |
| 2086 | if (!knew) |
| 2087 | return -ENOMEM; |
| 2088 | knew->count = i; |
| 2089 | } |
| 2090 | |
| 2091 | /* mic-boosts */ |
| 2092 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2093 | hda_nid_t pin = cfg->inputs[i].pin; |
| 2094 | unsigned int caps; |
| 2095 | const char *label; |
| 2096 | char name[32]; |
| 2097 | |
| 2098 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 2099 | continue; |
| 2100 | caps = query_amp_caps(codec, pin, HDA_INPUT); |
| 2101 | if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) |
| 2102 | continue; |
| 2103 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 2104 | snprintf(name, sizeof(name), "%s Boost Capture Volume", label); |
| 2105 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 2106 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); |
| 2107 | if (err < 0) |
| 2108 | return err; |
| 2109 | } |
| 2110 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2111 | return 0; |
| 2112 | } |
| 2113 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2114 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2115 | static const struct hda_amp_list vt1708_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2116 | { 0x17, HDA_INPUT, 1 }, |
| 2117 | { 0x17, HDA_INPUT, 2 }, |
| 2118 | { 0x17, HDA_INPUT, 3 }, |
| 2119 | { 0x17, HDA_INPUT, 4 }, |
| 2120 | { } /* end */ |
| 2121 | }; |
| 2122 | #endif |
| 2123 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2124 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 2125 | { |
| 2126 | unsigned int def_conf; |
| 2127 | unsigned char seqassoc; |
| 2128 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 2129 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2130 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 2131 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 2132 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 2133 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 2134 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 2135 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | return; |
| 2139 | } |
| 2140 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2141 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2142 | struct snd_ctl_elem_value *ucontrol) |
| 2143 | { |
| 2144 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2145 | struct via_spec *spec = codec->spec; |
| 2146 | |
| 2147 | if (spec->codec_type != VT1708) |
| 2148 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2149 | spec->vt1708_jack_detect = |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2150 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2151 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2152 | return 0; |
| 2153 | } |
| 2154 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2155 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2156 | struct snd_ctl_elem_value *ucontrol) |
| 2157 | { |
| 2158 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2159 | struct via_spec *spec = codec->spec; |
| 2160 | int change; |
| 2161 | |
| 2162 | if (spec->codec_type != VT1708) |
| 2163 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2164 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2165 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2166 | == !spec->vt1708_jack_detect; |
| 2167 | if (spec->vt1708_jack_detect) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2168 | mute_aa_path(codec, 1); |
| 2169 | notify_aa_path_ctls(codec); |
| 2170 | } |
| 2171 | return change; |
| 2172 | } |
| 2173 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2174 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
| 2175 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2176 | .name = "Jack Detect", |
| 2177 | .count = 1, |
| 2178 | .info = snd_ctl_boolean_mono_info, |
| 2179 | .get = vt1708_jack_detect_get, |
| 2180 | .put = vt1708_jack_detect_put, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2181 | }; |
| 2182 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2183 | static void fill_dig_outs(struct hda_codec *codec); |
| 2184 | static void fill_dig_in(struct hda_codec *codec); |
| 2185 | |
| 2186 | static int via_parse_auto_config(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2187 | { |
| 2188 | struct via_spec *spec = codec->spec; |
| 2189 | int err; |
| 2190 | |
| 2191 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2192 | if (err < 0) |
| 2193 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2194 | err = via_auto_fill_dac_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2195 | if (err < 0) |
| 2196 | return err; |
| 2197 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
Takashi Iwai | 7f0df88 | 2011-06-18 17:33:34 +0200 | [diff] [blame] | 2198 | return -EINVAL; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2199 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2200 | err = via_auto_create_multi_out_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2201 | if (err < 0) |
| 2202 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2203 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2204 | if (err < 0) |
| 2205 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2206 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2207 | if (err < 0) |
| 2208 | return err; |
| 2209 | |
| 2210 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2211 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2212 | fill_dig_outs(codec); |
| 2213 | fill_dig_in(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2214 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2215 | if (spec->kctls.list) |
| 2216 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2217 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 2218 | spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2219 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2220 | spec->input_mux = &spec->private_imux[0]; |
| 2221 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 2222 | if (spec->hp_mux) { |
| 2223 | err = via_hp_build(codec); |
| 2224 | if (err < 0) |
| 2225 | return err; |
| 2226 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2227 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2228 | err = via_smart51_build(codec); |
| 2229 | if (err < 0) |
| 2230 | return err; |
| 2231 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2232 | /* assign slave outs */ |
| 2233 | if (spec->slave_dig_outs[0]) |
| 2234 | codec->slave_dig_outs = spec->slave_dig_outs; |
| 2235 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2236 | return 1; |
| 2237 | } |
| 2238 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2239 | static void via_auto_init_dig_outs(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2240 | { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2241 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2242 | if (spec->multiout.dig_out_nid) |
| 2243 | init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT); |
| 2244 | if (spec->slave_dig_outs[0]) |
| 2245 | init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT); |
| 2246 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2247 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2248 | static void via_auto_init_dig_in(struct hda_codec *codec) |
| 2249 | { |
| 2250 | struct via_spec *spec = codec->spec; |
| 2251 | if (!spec->dig_in_nid) |
| 2252 | return; |
| 2253 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, |
| 2254 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
| 2255 | } |
| 2256 | |
| 2257 | static int via_init(struct hda_codec *codec) |
| 2258 | { |
| 2259 | struct via_spec *spec = codec->spec; |
| 2260 | int i; |
| 2261 | |
| 2262 | for (i = 0; i < spec->num_iverbs; i++) |
| 2263 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 2264 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2265 | via_auto_init_multi_out(codec); |
| 2266 | via_auto_init_hp_out(codec); |
| 2267 | via_auto_init_analog_input(codec); |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2268 | via_auto_init_dig_outs(codec); |
| 2269 | via_auto_init_dig_in(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 2270 | |
| 2271 | if (VT2002P_COMPATIBLE(spec)) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2272 | via_hp_bind_automute(codec); |
| 2273 | } else { |
| 2274 | via_hp_automute(codec); |
| 2275 | via_speaker_automute(codec); |
| 2276 | } |
| 2277 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2278 | return 0; |
| 2279 | } |
| 2280 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2281 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
| 2282 | { |
| 2283 | struct via_spec *spec = container_of(work, struct via_spec, |
| 2284 | vt1708_hp_work.work); |
| 2285 | if (spec->codec_type != VT1708) |
| 2286 | return; |
| 2287 | /* if jack state toggled */ |
| 2288 | if (spec->vt1708_hp_present |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2289 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2290 | spec->vt1708_hp_present ^= 1; |
| 2291 | via_hp_automute(spec->codec); |
| 2292 | } |
| 2293 | vt1708_start_hp_work(spec); |
| 2294 | } |
| 2295 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2296 | static int get_mux_nids(struct hda_codec *codec) |
| 2297 | { |
| 2298 | struct via_spec *spec = codec->spec; |
| 2299 | hda_nid_t nid, conn[8]; |
| 2300 | unsigned int type; |
| 2301 | int i, n; |
| 2302 | |
| 2303 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2304 | nid = spec->adc_nids[i]; |
| 2305 | while (nid) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2306 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2307 | if (type == AC_WID_PIN) |
| 2308 | break; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2309 | n = snd_hda_get_connections(codec, nid, conn, |
| 2310 | ARRAY_SIZE(conn)); |
| 2311 | if (n <= 0) |
| 2312 | break; |
| 2313 | if (n > 1) { |
| 2314 | spec->mux_nids[i] = nid; |
| 2315 | break; |
| 2316 | } |
| 2317 | nid = conn[0]; |
| 2318 | } |
| 2319 | } |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2320 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2321 | } |
| 2322 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2323 | static int patch_vt1708(struct hda_codec *codec) |
| 2324 | { |
| 2325 | struct via_spec *spec; |
| 2326 | int err; |
| 2327 | |
| 2328 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2329 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2330 | if (spec == NULL) |
| 2331 | return -ENOMEM; |
| 2332 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2333 | spec->aa_mix_nid = 0x17; |
| 2334 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2335 | /* Add HP and CD pin config connect bit re-config action */ |
| 2336 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 2337 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 2338 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2339 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2340 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2341 | if (err < 0) { |
| 2342 | via_free(codec); |
| 2343 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2344 | } |
| 2345 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2346 | /* add jack detect on/off control */ |
| 2347 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
| 2348 | return -ENOMEM; |
| 2349 | |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 2350 | /* disable 32bit format on VT1708 */ |
| 2351 | if (codec->vendor_id == 0x11061708) |
| 2352 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2353 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2354 | codec->patch_ops = via_patch_ops; |
| 2355 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2356 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2357 | spec->loopback.amplist = vt1708_loopbacks; |
| 2358 | #endif |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2359 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2360 | return 0; |
| 2361 | } |
| 2362 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2363 | static const struct hda_verb vt1709_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2364 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2365 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2366 | { } |
| 2367 | }; |
| 2368 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2369 | /* |
| 2370 | * generic initialization of ADC, input mixers and output mixers |
| 2371 | */ |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2372 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2373 | static const struct hda_amp_list vt1709_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2374 | { 0x18, HDA_INPUT, 1 }, |
| 2375 | { 0x18, HDA_INPUT, 2 }, |
| 2376 | { 0x18, HDA_INPUT, 3 }, |
| 2377 | { 0x18, HDA_INPUT, 4 }, |
| 2378 | { } /* end */ |
| 2379 | }; |
| 2380 | #endif |
| 2381 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2382 | static int patch_vt1709_10ch(struct hda_codec *codec) |
| 2383 | { |
| 2384 | struct via_spec *spec; |
| 2385 | int err; |
| 2386 | |
| 2387 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2388 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2389 | if (spec == NULL) |
| 2390 | return -ENOMEM; |
| 2391 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2392 | spec->aa_mix_nid = 0x18; |
| 2393 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2394 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2395 | if (err < 0) { |
| 2396 | via_free(codec); |
| 2397 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2398 | } |
| 2399 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2400 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2401 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2402 | codec->patch_ops = via_patch_ops; |
| 2403 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2404 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2405 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2406 | spec->loopback.amplist = vt1709_loopbacks; |
| 2407 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2408 | |
| 2409 | return 0; |
| 2410 | } |
| 2411 | /* |
| 2412 | * generic initialization of ADC, input mixers and output mixers |
| 2413 | */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2414 | static int patch_vt1709_6ch(struct hda_codec *codec) |
| 2415 | { |
| 2416 | struct via_spec *spec; |
| 2417 | int err; |
| 2418 | |
| 2419 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2420 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2421 | if (spec == NULL) |
| 2422 | return -ENOMEM; |
| 2423 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2424 | spec->aa_mix_nid = 0x18; |
| 2425 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2426 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2427 | if (err < 0) { |
| 2428 | via_free(codec); |
| 2429 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2430 | } |
| 2431 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2432 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2433 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2434 | codec->patch_ops = via_patch_ops; |
| 2435 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2436 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2437 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2438 | spec->loopback.amplist = vt1709_loopbacks; |
| 2439 | #endif |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2440 | return 0; |
| 2441 | } |
| 2442 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2443 | /* |
| 2444 | * generic initialization of ADC, input mixers and output mixers |
| 2445 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2446 | static const struct hda_verb vt1708B_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2447 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2448 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2449 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2450 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2451 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2452 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2453 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2454 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2455 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2456 | { } |
| 2457 | }; |
| 2458 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2459 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2460 | static const struct hda_amp_list vt1708B_loopbacks[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2461 | { 0x16, HDA_INPUT, 1 }, |
| 2462 | { 0x16, HDA_INPUT, 2 }, |
| 2463 | { 0x16, HDA_INPUT, 3 }, |
| 2464 | { 0x16, HDA_INPUT, 4 }, |
| 2465 | { } /* end */ |
| 2466 | }; |
| 2467 | #endif |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2468 | |
| 2469 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
| 2470 | { |
| 2471 | struct via_spec *spec = codec->spec; |
| 2472 | int imux_is_smixer; |
| 2473 | unsigned int parm; |
| 2474 | int is_8ch = 0; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2475 | if ((spec->codec_type != VT1708B_4CH) && |
| 2476 | (codec->vendor_id != 0x11064397)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2477 | is_8ch = 1; |
| 2478 | |
| 2479 | /* SW0 (17h) = stereo mixer */ |
| 2480 | imux_is_smixer = |
| 2481 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 2482 | == ((spec->codec_type == VT1708S) ? 5 : 0)); |
| 2483 | /* inputs */ |
| 2484 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 2485 | parm = AC_PWRST_D3; |
| 2486 | set_pin_power_state(codec, 0x1a, &parm); |
| 2487 | set_pin_power_state(codec, 0x1b, &parm); |
| 2488 | set_pin_power_state(codec, 0x1e, &parm); |
| 2489 | if (imux_is_smixer) |
| 2490 | parm = AC_PWRST_D0; |
| 2491 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
| 2492 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2493 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2494 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2495 | |
| 2496 | /* outputs */ |
| 2497 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 2498 | parm = AC_PWRST_D3; |
| 2499 | set_pin_power_state(codec, 0x19, &parm); |
| 2500 | if (spec->smart51_enabled) |
| 2501 | set_pin_power_state(codec, 0x1b, &parm); |
| 2502 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2503 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2504 | |
| 2505 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 2506 | if (is_8ch) { |
| 2507 | parm = AC_PWRST_D3; |
| 2508 | set_pin_power_state(codec, 0x22, &parm); |
| 2509 | if (spec->smart51_enabled) |
| 2510 | set_pin_power_state(codec, 0x1a, &parm); |
| 2511 | snd_hda_codec_write(codec, 0x26, 0, |
| 2512 | AC_VERB_SET_POWER_STATE, parm); |
| 2513 | snd_hda_codec_write(codec, 0x24, 0, |
| 2514 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2515 | } else if (codec->vendor_id == 0x11064397) { |
| 2516 | /* PW7(23h), SW2(27h), AOW2(25h) */ |
| 2517 | parm = AC_PWRST_D3; |
| 2518 | set_pin_power_state(codec, 0x23, &parm); |
| 2519 | if (spec->smart51_enabled) |
| 2520 | set_pin_power_state(codec, 0x1a, &parm); |
| 2521 | snd_hda_codec_write(codec, 0x27, 0, |
| 2522 | AC_VERB_SET_POWER_STATE, parm); |
| 2523 | snd_hda_codec_write(codec, 0x25, 0, |
| 2524 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 2528 | parm = AC_PWRST_D3; |
| 2529 | /* force to D0 for internal Speaker */ |
| 2530 | set_pin_power_state(codec, 0x1c, &parm); |
| 2531 | set_pin_power_state(codec, 0x1d, &parm); |
| 2532 | if (is_8ch) |
| 2533 | set_pin_power_state(codec, 0x23, &parm); |
| 2534 | |
| 2535 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
| 2536 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 2537 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 2538 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2539 | if (is_8ch) { |
| 2540 | snd_hda_codec_write(codec, 0x25, 0, |
| 2541 | AC_VERB_SET_POWER_STATE, parm); |
| 2542 | snd_hda_codec_write(codec, 0x27, 0, |
| 2543 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2544 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
| 2545 | snd_hda_codec_write(codec, 0x25, 0, |
| 2546 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2547 | } |
| 2548 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2549 | static int patch_vt1708S(struct hda_codec *codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2550 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
| 2551 | { |
| 2552 | struct via_spec *spec; |
| 2553 | int err; |
| 2554 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2555 | if (get_codec_type(codec) == VT1708BCE) |
| 2556 | return patch_vt1708S(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2557 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2558 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2559 | if (spec == NULL) |
| 2560 | return -ENOMEM; |
| 2561 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2562 | spec->aa_mix_nid = 0x16; |
| 2563 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2564 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2565 | err = via_parse_auto_config(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2566 | if (err < 0) { |
| 2567 | via_free(codec); |
| 2568 | return err; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2569 | } |
| 2570 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2571 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2572 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2573 | codec->patch_ops = via_patch_ops; |
| 2574 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2575 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2576 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2577 | spec->loopback.amplist = vt1708B_loopbacks; |
| 2578 | #endif |
| 2579 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2580 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 2581 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2582 | return 0; |
| 2583 | } |
| 2584 | |
| 2585 | static int patch_vt1708B_4ch(struct hda_codec *codec) |
| 2586 | { |
| 2587 | struct via_spec *spec; |
| 2588 | int err; |
| 2589 | |
| 2590 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2591 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2592 | if (spec == NULL) |
| 2593 | return -ENOMEM; |
| 2594 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2595 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2596 | err = via_parse_auto_config(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2597 | if (err < 0) { |
| 2598 | via_free(codec); |
| 2599 | return err; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2600 | } |
| 2601 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2602 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2603 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2604 | codec->patch_ops = via_patch_ops; |
| 2605 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2606 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2607 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2608 | spec->loopback.amplist = vt1708B_loopbacks; |
| 2609 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2610 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2611 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 2612 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2613 | return 0; |
| 2614 | } |
| 2615 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2616 | /* Patch for VT1708S */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 2617 | static const struct hda_verb vt1708S_init_verbs[] = { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 2618 | /* Enable Mic Boost Volume backdoor */ |
| 2619 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 2620 | /* don't bybass mixer */ |
| 2621 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2622 | { } |
| 2623 | }; |
| 2624 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2625 | static const struct hda_verb vt1708S_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2626 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2627 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2628 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2629 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2630 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2631 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2632 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2633 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2634 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2635 | { } |
| 2636 | }; |
| 2637 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2638 | static const struct hda_verb vt1705_uniwill_init_verbs[] = { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2639 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2640 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2641 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2642 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2643 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2644 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2645 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2646 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2647 | { } |
| 2648 | }; |
| 2649 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 2650 | /* fill out digital output widgets; one for master and one for slave outputs */ |
| 2651 | static void fill_dig_outs(struct hda_codec *codec) |
| 2652 | { |
| 2653 | struct via_spec *spec = codec->spec; |
| 2654 | int i; |
| 2655 | |
| 2656 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 2657 | hda_nid_t nid; |
| 2658 | int conn; |
| 2659 | |
| 2660 | nid = spec->autocfg.dig_out_pins[i]; |
| 2661 | if (!nid) |
| 2662 | continue; |
| 2663 | conn = snd_hda_get_connections(codec, nid, &nid, 1); |
| 2664 | if (conn < 1) |
| 2665 | continue; |
| 2666 | if (!spec->multiout.dig_out_nid) |
| 2667 | spec->multiout.dig_out_nid = nid; |
| 2668 | else { |
| 2669 | spec->slave_dig_outs[0] = nid; |
| 2670 | break; /* at most two dig outs */ |
| 2671 | } |
| 2672 | } |
| 2673 | } |
| 2674 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2675 | static void fill_dig_in(struct hda_codec *codec) |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2676 | { |
| 2677 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2678 | hda_nid_t dig_nid; |
| 2679 | int i, err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2680 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2681 | if (!spec->autocfg.dig_in_pin) |
| 2682 | return; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2683 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2684 | dig_nid = codec->start_nid; |
| 2685 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 2686 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 2687 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 2688 | continue; |
| 2689 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 2690 | continue; |
| 2691 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 2692 | continue; |
| 2693 | err = get_connection_index(codec, dig_nid, |
| 2694 | spec->autocfg.dig_in_pin); |
| 2695 | if (err >= 0) { |
| 2696 | spec->dig_in_nid = dig_nid; |
| 2697 | break; |
| 2698 | } |
| 2699 | } |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2703 | static const struct hda_amp_list vt1708S_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2704 | { 0x16, HDA_INPUT, 1 }, |
| 2705 | { 0x16, HDA_INPUT, 2 }, |
| 2706 | { 0x16, HDA_INPUT, 3 }, |
| 2707 | { 0x16, HDA_INPUT, 4 }, |
| 2708 | { } /* end */ |
| 2709 | }; |
| 2710 | #endif |
| 2711 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 2712 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 2713 | int offset, int num_steps, int step_size) |
| 2714 | { |
| 2715 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 2716 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 2717 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 2718 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 2719 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 2720 | } |
| 2721 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2722 | static int patch_vt1708S(struct hda_codec *codec) |
| 2723 | { |
| 2724 | struct via_spec *spec; |
| 2725 | int err; |
| 2726 | |
| 2727 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2728 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2729 | if (spec == NULL) |
| 2730 | return -ENOMEM; |
| 2731 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2732 | spec->aa_mix_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2733 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 2734 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2735 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2736 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2737 | err = via_parse_auto_config(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2738 | if (err < 0) { |
| 2739 | via_free(codec); |
| 2740 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2741 | } |
| 2742 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 2743 | spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2744 | if (codec->vendor_id == 0x11064397) |
| 2745 | spec->init_verbs[spec->num_iverbs++] = |
| 2746 | vt1705_uniwill_init_verbs; |
| 2747 | else |
| 2748 | spec->init_verbs[spec->num_iverbs++] = |
| 2749 | vt1708S_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2750 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2751 | codec->patch_ops = via_patch_ops; |
| 2752 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2753 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2754 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2755 | spec->loopback.amplist = vt1708S_loopbacks; |
| 2756 | #endif |
| 2757 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2758 | /* correct names for VT1708BCE */ |
| 2759 | if (get_codec_type(codec) == VT1708BCE) { |
| 2760 | kfree(codec->chip_name); |
| 2761 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 2762 | snprintf(codec->bus->card->mixername, |
| 2763 | sizeof(codec->bus->card->mixername), |
| 2764 | "%s %s", codec->vendor_name, codec->chip_name); |
Lydia Wang | 970f630f | 2011-03-22 16:25:56 +0800 | [diff] [blame] | 2765 | } |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2766 | /* correct names for VT1705 */ |
| 2767 | if (codec->vendor_id == 0x11064397) { |
| 2768 | kfree(codec->chip_name); |
| 2769 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); |
| 2770 | snprintf(codec->bus->card->mixername, |
| 2771 | sizeof(codec->bus->card->mixername), |
| 2772 | "%s %s", codec->vendor_name, codec->chip_name); |
| 2773 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2774 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2775 | return 0; |
| 2776 | } |
| 2777 | |
| 2778 | /* Patch for VT1702 */ |
| 2779 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 2780 | static const struct hda_verb vt1702_init_verbs[] = { |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 2781 | /* mixer enable */ |
| 2782 | {0x1, 0xF88, 0x3}, |
| 2783 | /* GPIO 0~2 */ |
| 2784 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2785 | { } |
| 2786 | }; |
| 2787 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2788 | static const struct hda_verb vt1702_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2789 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2790 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2791 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2792 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2793 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2794 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2795 | { } |
| 2796 | }; |
| 2797 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2798 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2799 | static const struct hda_amp_list vt1702_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2800 | { 0x1A, HDA_INPUT, 1 }, |
| 2801 | { 0x1A, HDA_INPUT, 2 }, |
| 2802 | { 0x1A, HDA_INPUT, 3 }, |
| 2803 | { 0x1A, HDA_INPUT, 4 }, |
| 2804 | { } /* end */ |
| 2805 | }; |
| 2806 | #endif |
| 2807 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2808 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
| 2809 | { |
| 2810 | int imux_is_smixer = |
| 2811 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 2812 | unsigned int parm; |
| 2813 | /* inputs */ |
| 2814 | /* PW 1/2/5 (14h/15h/18h) */ |
| 2815 | parm = AC_PWRST_D3; |
| 2816 | set_pin_power_state(codec, 0x14, &parm); |
| 2817 | set_pin_power_state(codec, 0x15, &parm); |
| 2818 | set_pin_power_state(codec, 0x18, &parm); |
| 2819 | if (imux_is_smixer) |
| 2820 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ |
| 2821 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
| 2822 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2823 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2824 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2825 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2826 | |
| 2827 | /* outputs */ |
| 2828 | /* PW 3/4 (16h/17h) */ |
| 2829 | parm = AC_PWRST_D3; |
| 2830 | set_pin_power_state(codec, 0x17, &parm); |
| 2831 | set_pin_power_state(codec, 0x16, &parm); |
| 2832 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
| 2833 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 2834 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 2835 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2836 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2837 | } |
| 2838 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2839 | static int patch_vt1702(struct hda_codec *codec) |
| 2840 | { |
| 2841 | struct via_spec *spec; |
| 2842 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2843 | |
| 2844 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2845 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2846 | if (spec == NULL) |
| 2847 | return -ENOMEM; |
| 2848 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2849 | spec->aa_mix_nid = 0x1a; |
| 2850 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2851 | /* limit AA path volume to 0 dB */ |
| 2852 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 2853 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 2854 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 2855 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 2856 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 2857 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2858 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2859 | err = via_parse_auto_config(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2860 | if (err < 0) { |
| 2861 | via_free(codec); |
| 2862 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2863 | } |
| 2864 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 2865 | spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2866 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2867 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2868 | codec->patch_ops = via_patch_ops; |
| 2869 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2870 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2871 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2872 | spec->loopback.amplist = vt1702_loopbacks; |
| 2873 | #endif |
| 2874 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2875 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2876 | return 0; |
| 2877 | } |
| 2878 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2879 | /* Patch for VT1718S */ |
| 2880 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 2881 | static const struct hda_verb vt1718S_init_verbs[] = { |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 2882 | /* Enable MW0 adjust Gain 5 */ |
| 2883 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2884 | /* Enable Boost Volume backdoor */ |
| 2885 | {0x1, 0xf88, 0x8}, |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2886 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2887 | { } |
| 2888 | }; |
| 2889 | |
| 2890 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2891 | static const struct hda_verb vt1718S_uniwill_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2892 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2893 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2894 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2895 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2896 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2897 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2898 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2899 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2900 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2901 | { } |
| 2902 | }; |
| 2903 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2904 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2905 | static const struct hda_amp_list vt1718S_loopbacks[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2906 | { 0x21, HDA_INPUT, 1 }, |
| 2907 | { 0x21, HDA_INPUT, 2 }, |
| 2908 | { 0x21, HDA_INPUT, 3 }, |
| 2909 | { 0x21, HDA_INPUT, 4 }, |
| 2910 | { } /* end */ |
| 2911 | }; |
| 2912 | #endif |
| 2913 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2914 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
| 2915 | { |
| 2916 | struct via_spec *spec = codec->spec; |
| 2917 | int imux_is_smixer; |
| 2918 | unsigned int parm; |
| 2919 | /* MUX6 (1eh) = stereo mixer */ |
| 2920 | imux_is_smixer = |
| 2921 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 2922 | /* inputs */ |
| 2923 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 2924 | parm = AC_PWRST_D3; |
| 2925 | set_pin_power_state(codec, 0x29, &parm); |
| 2926 | set_pin_power_state(codec, 0x2a, &parm); |
| 2927 | set_pin_power_state(codec, 0x2b, &parm); |
| 2928 | if (imux_is_smixer) |
| 2929 | parm = AC_PWRST_D0; |
| 2930 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 2931 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2932 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2933 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2934 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2935 | |
| 2936 | /* outputs */ |
| 2937 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 2938 | parm = AC_PWRST_D3; |
| 2939 | set_pin_power_state(codec, 0x27, &parm); |
| 2940 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2941 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2942 | |
| 2943 | /* PW2 (26h), AOW2 (ah) */ |
| 2944 | parm = AC_PWRST_D3; |
| 2945 | set_pin_power_state(codec, 0x26, &parm); |
| 2946 | if (spec->smart51_enabled) |
| 2947 | set_pin_power_state(codec, 0x2b, &parm); |
| 2948 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2949 | |
| 2950 | /* PW0 (24h), AOW0 (8h) */ |
| 2951 | parm = AC_PWRST_D3; |
| 2952 | set_pin_power_state(codec, 0x24, &parm); |
| 2953 | if (!spec->hp_independent_mode) /* check for redirected HP */ |
| 2954 | set_pin_power_state(codec, 0x28, &parm); |
| 2955 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2956 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 2957 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, |
| 2958 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 2959 | |
| 2960 | /* PW1 (25h), AOW1 (9h) */ |
| 2961 | parm = AC_PWRST_D3; |
| 2962 | set_pin_power_state(codec, 0x25, &parm); |
| 2963 | if (spec->smart51_enabled) |
| 2964 | set_pin_power_state(codec, 0x2a, &parm); |
| 2965 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2966 | |
| 2967 | if (spec->hp_independent_mode) { |
| 2968 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 2969 | parm = AC_PWRST_D3; |
| 2970 | set_pin_power_state(codec, 0x28, &parm); |
| 2971 | snd_hda_codec_write(codec, 0x1b, 0, |
| 2972 | AC_VERB_SET_POWER_STATE, parm); |
| 2973 | snd_hda_codec_write(codec, 0x34, 0, |
| 2974 | AC_VERB_SET_POWER_STATE, parm); |
| 2975 | snd_hda_codec_write(codec, 0xc, 0, |
| 2976 | AC_VERB_SET_POWER_STATE, parm); |
| 2977 | } |
| 2978 | } |
| 2979 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2980 | static int patch_vt1718S(struct hda_codec *codec) |
| 2981 | { |
| 2982 | struct via_spec *spec; |
| 2983 | int err; |
| 2984 | |
| 2985 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2986 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2987 | if (spec == NULL) |
| 2988 | return -ENOMEM; |
| 2989 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2990 | spec->aa_mix_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2991 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 2992 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2993 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2994 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2995 | err = via_parse_auto_config(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2996 | if (err < 0) { |
| 2997 | via_free(codec); |
| 2998 | return err; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 2999 | } |
| 3000 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3001 | spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3002 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; |
| 3003 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3004 | codec->patch_ops = via_patch_ops; |
| 3005 | |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3006 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3007 | |
| 3008 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3009 | spec->loopback.amplist = vt1718S_loopbacks; |
| 3010 | #endif |
| 3011 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3012 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
| 3013 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3014 | return 0; |
| 3015 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3016 | |
| 3017 | /* Patch for VT1716S */ |
| 3018 | |
| 3019 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 3020 | struct snd_ctl_elem_info *uinfo) |
| 3021 | { |
| 3022 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3023 | uinfo->count = 1; |
| 3024 | uinfo->value.integer.min = 0; |
| 3025 | uinfo->value.integer.max = 1; |
| 3026 | return 0; |
| 3027 | } |
| 3028 | |
| 3029 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 3030 | struct snd_ctl_elem_value *ucontrol) |
| 3031 | { |
| 3032 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3033 | int index = 0; |
| 3034 | |
| 3035 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 3036 | AC_VERB_GET_CONNECT_SEL, 0); |
| 3037 | if (index != -1) |
| 3038 | *ucontrol->value.integer.value = index; |
| 3039 | |
| 3040 | return 0; |
| 3041 | } |
| 3042 | |
| 3043 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 3044 | struct snd_ctl_elem_value *ucontrol) |
| 3045 | { |
| 3046 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3047 | struct via_spec *spec = codec->spec; |
| 3048 | int index = *ucontrol->value.integer.value; |
| 3049 | |
| 3050 | snd_hda_codec_write(codec, 0x26, 0, |
| 3051 | AC_VERB_SET_CONNECT_SEL, index); |
| 3052 | spec->dmic_enabled = index; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3053 | set_widgets_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3054 | return 1; |
| 3055 | } |
| 3056 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3057 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3058 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 3059 | { |
| 3060 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3061 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3062 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3063 | .count = 1, |
| 3064 | .info = vt1716s_dmic_info, |
| 3065 | .get = vt1716s_dmic_get, |
| 3066 | .put = vt1716s_dmic_put, |
| 3067 | }, |
| 3068 | {} /* end */ |
| 3069 | }; |
| 3070 | |
| 3071 | |
| 3072 | /* mono-out mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3073 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3074 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 3075 | { } /* end */ |
| 3076 | }; |
| 3077 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3078 | static const struct hda_verb vt1716S_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3079 | /* Enable Boost Volume backdoor */ |
| 3080 | {0x1, 0xf8a, 0x80}, |
| 3081 | /* don't bybass mixer */ |
| 3082 | {0x1, 0xf88, 0xc0}, |
| 3083 | /* Enable mono output */ |
| 3084 | {0x1, 0xf90, 0x08}, |
| 3085 | { } |
| 3086 | }; |
| 3087 | |
| 3088 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3089 | static const struct hda_verb vt1716S_uniwill_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3090 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3091 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3092 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3093 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3094 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3095 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3096 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, |
| 3097 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3098 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3099 | { } |
| 3100 | }; |
| 3101 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3102 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3103 | static const struct hda_amp_list vt1716S_loopbacks[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3104 | { 0x16, HDA_INPUT, 1 }, |
| 3105 | { 0x16, HDA_INPUT, 2 }, |
| 3106 | { 0x16, HDA_INPUT, 3 }, |
| 3107 | { 0x16, HDA_INPUT, 4 }, |
| 3108 | { } /* end */ |
| 3109 | }; |
| 3110 | #endif |
| 3111 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3112 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
| 3113 | { |
| 3114 | struct via_spec *spec = codec->spec; |
| 3115 | int imux_is_smixer; |
| 3116 | unsigned int parm; |
| 3117 | unsigned int mono_out, present; |
| 3118 | /* SW0 (17h) = stereo mixer */ |
| 3119 | imux_is_smixer = |
| 3120 | (snd_hda_codec_read(codec, 0x17, 0, |
| 3121 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); |
| 3122 | /* inputs */ |
| 3123 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 3124 | parm = AC_PWRST_D3; |
| 3125 | set_pin_power_state(codec, 0x1a, &parm); |
| 3126 | set_pin_power_state(codec, 0x1b, &parm); |
| 3127 | set_pin_power_state(codec, 0x1e, &parm); |
| 3128 | if (imux_is_smixer) |
| 3129 | parm = AC_PWRST_D0; |
| 3130 | /* SW0 (17h), AIW0(13h) */ |
| 3131 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3132 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3133 | |
| 3134 | parm = AC_PWRST_D3; |
| 3135 | set_pin_power_state(codec, 0x1e, &parm); |
| 3136 | /* PW11 (22h) */ |
| 3137 | if (spec->dmic_enabled) |
| 3138 | set_pin_power_state(codec, 0x22, &parm); |
| 3139 | else |
| 3140 | snd_hda_codec_write(codec, 0x22, 0, |
| 3141 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3142 | |
| 3143 | /* SW2(26h), AIW1(14h) */ |
| 3144 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3145 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3146 | |
| 3147 | /* outputs */ |
| 3148 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 3149 | parm = AC_PWRST_D3; |
| 3150 | set_pin_power_state(codec, 0x19, &parm); |
| 3151 | /* Smart 5.1 PW2(1bh) */ |
| 3152 | if (spec->smart51_enabled) |
| 3153 | set_pin_power_state(codec, 0x1b, &parm); |
| 3154 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3155 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3156 | |
| 3157 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 3158 | parm = AC_PWRST_D3; |
| 3159 | set_pin_power_state(codec, 0x23, &parm); |
| 3160 | /* Smart 5.1 PW1(1ah) */ |
| 3161 | if (spec->smart51_enabled) |
| 3162 | set_pin_power_state(codec, 0x1a, &parm); |
| 3163 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3164 | |
| 3165 | /* Smart 5.1 PW5(1eh) */ |
| 3166 | if (spec->smart51_enabled) |
| 3167 | set_pin_power_state(codec, 0x1e, &parm); |
| 3168 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3169 | |
| 3170 | /* Mono out */ |
| 3171 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 3172 | present = snd_hda_jack_detect(codec, 0x1c); |
| 3173 | |
| 3174 | if (present) |
| 3175 | mono_out = 0; |
| 3176 | else { |
| 3177 | present = snd_hda_jack_detect(codec, 0x1d); |
| 3178 | if (!spec->hp_independent_mode && present) |
| 3179 | mono_out = 0; |
| 3180 | else |
| 3181 | mono_out = 1; |
| 3182 | } |
| 3183 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
| 3184 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3185 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3186 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3187 | |
| 3188 | /* PW 3/4 (1ch/1dh) */ |
| 3189 | parm = AC_PWRST_D3; |
| 3190 | set_pin_power_state(codec, 0x1c, &parm); |
| 3191 | set_pin_power_state(codec, 0x1d, &parm); |
| 3192 | /* HP Independent Mode, power on AOW3 */ |
| 3193 | if (spec->hp_independent_mode) |
| 3194 | snd_hda_codec_write(codec, 0x25, 0, |
| 3195 | AC_VERB_SET_POWER_STATE, parm); |
| 3196 | |
| 3197 | /* force to D0 for internal Speaker */ |
| 3198 | /* MW0 (16h), AOW0 (10h) */ |
| 3199 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 3200 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3201 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 3202 | mono_out ? AC_PWRST_D0 : parm); |
| 3203 | } |
| 3204 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3205 | static int patch_vt1716S(struct hda_codec *codec) |
| 3206 | { |
| 3207 | struct via_spec *spec; |
| 3208 | int err; |
| 3209 | |
| 3210 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3211 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3212 | if (spec == NULL) |
| 3213 | return -ENOMEM; |
| 3214 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3215 | spec->aa_mix_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3216 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3217 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3218 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3219 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3220 | err = via_parse_auto_config(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3221 | if (err < 0) { |
| 3222 | via_free(codec); |
| 3223 | return err; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3224 | } |
| 3225 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3226 | spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3227 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; |
| 3228 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3229 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
| 3230 | spec->num_mixers++; |
| 3231 | |
| 3232 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 3233 | |
| 3234 | codec->patch_ops = via_patch_ops; |
| 3235 | |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3236 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3237 | |
| 3238 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3239 | spec->loopback.amplist = vt1716S_loopbacks; |
| 3240 | #endif |
| 3241 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3242 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3243 | return 0; |
| 3244 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3245 | |
| 3246 | /* for vt2002P */ |
| 3247 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3248 | static const struct hda_verb vt2002P_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 3249 | /* Class-D speaker related verbs */ |
| 3250 | {0x1, 0xfe0, 0x4}, |
| 3251 | {0x1, 0xfe9, 0x80}, |
| 3252 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3253 | /* Enable Boost Volume backdoor */ |
| 3254 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3255 | /* Enable AOW0 to MW9 */ |
| 3256 | {0x1, 0xfb8, 0x88}, |
| 3257 | { } |
| 3258 | }; |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3259 | static const struct hda_verb vt1802_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3260 | /* Enable Boost Volume backdoor */ |
| 3261 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3262 | /* Enable AOW0 to MW9 */ |
| 3263 | {0x1, 0xfb8, 0x88}, |
| 3264 | { } |
| 3265 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3266 | |
| 3267 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3268 | static const struct hda_verb vt2002P_uniwill_init_verbs[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3269 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3270 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 3271 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3272 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 3273 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3274 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3275 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3276 | { } |
| 3277 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3278 | static const struct hda_verb vt1802_uniwill_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3279 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3280 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 3281 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3282 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 3283 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3284 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3285 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3286 | { } |
| 3287 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3288 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3289 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3290 | static const struct hda_amp_list vt2002P_loopbacks[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3291 | { 0x21, HDA_INPUT, 0 }, |
| 3292 | { 0x21, HDA_INPUT, 1 }, |
| 3293 | { 0x21, HDA_INPUT, 2 }, |
| 3294 | { } /* end */ |
| 3295 | }; |
| 3296 | #endif |
| 3297 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3298 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
| 3299 | { |
| 3300 | struct via_spec *spec = codec->spec; |
| 3301 | int imux_is_smixer; |
| 3302 | unsigned int parm; |
| 3303 | unsigned int present; |
| 3304 | /* MUX9 (1eh) = stereo mixer */ |
| 3305 | imux_is_smixer = |
| 3306 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3307 | /* inputs */ |
| 3308 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3309 | parm = AC_PWRST_D3; |
| 3310 | set_pin_power_state(codec, 0x29, &parm); |
| 3311 | set_pin_power_state(codec, 0x2a, &parm); |
| 3312 | set_pin_power_state(codec, 0x2b, &parm); |
| 3313 | parm = AC_PWRST_D0; |
| 3314 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3315 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3316 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3317 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3318 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3319 | |
| 3320 | /* outputs */ |
| 3321 | /* AOW0 (8h)*/ |
| 3322 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3323 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3324 | if (spec->codec_type == VT1802) { |
| 3325 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 3326 | parm = AC_PWRST_D3; |
| 3327 | set_pin_power_state(codec, 0x28, &parm); |
| 3328 | snd_hda_codec_write(codec, 0x18, 0, |
| 3329 | AC_VERB_SET_POWER_STATE, parm); |
| 3330 | snd_hda_codec_write(codec, 0x38, 0, |
| 3331 | AC_VERB_SET_POWER_STATE, parm); |
| 3332 | } else { |
| 3333 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 3334 | parm = AC_PWRST_D3; |
| 3335 | set_pin_power_state(codec, 0x26, &parm); |
| 3336 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3337 | AC_VERB_SET_POWER_STATE, parm); |
| 3338 | snd_hda_codec_write(codec, 0x37, 0, |
| 3339 | AC_VERB_SET_POWER_STATE, parm); |
| 3340 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3341 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3342 | if (spec->codec_type == VT1802) { |
| 3343 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 3344 | parm = AC_PWRST_D3; |
| 3345 | set_pin_power_state(codec, 0x25, &parm); |
| 3346 | snd_hda_codec_write(codec, 0x15, 0, |
| 3347 | AC_VERB_SET_POWER_STATE, parm); |
| 3348 | snd_hda_codec_write(codec, 0x35, 0, |
| 3349 | AC_VERB_SET_POWER_STATE, parm); |
| 3350 | } else { |
| 3351 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 3352 | parm = AC_PWRST_D3; |
| 3353 | set_pin_power_state(codec, 0x25, &parm); |
| 3354 | snd_hda_codec_write(codec, 0x19, 0, |
| 3355 | AC_VERB_SET_POWER_STATE, parm); |
| 3356 | snd_hda_codec_write(codec, 0x35, 0, |
| 3357 | AC_VERB_SET_POWER_STATE, parm); |
| 3358 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3359 | |
| 3360 | if (spec->hp_independent_mode) |
| 3361 | snd_hda_codec_write(codec, 0x9, 0, |
| 3362 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3363 | |
| 3364 | /* Class-D */ |
| 3365 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ |
| 3366 | present = snd_hda_jack_detect(codec, 0x25); |
| 3367 | |
| 3368 | parm = AC_PWRST_D3; |
| 3369 | set_pin_power_state(codec, 0x24, &parm); |
| 3370 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3371 | if (spec->codec_type == VT1802) |
| 3372 | snd_hda_codec_write(codec, 0x14, 0, |
| 3373 | AC_VERB_SET_POWER_STATE, parm); |
| 3374 | else |
| 3375 | snd_hda_codec_write(codec, 0x18, 0, |
| 3376 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3377 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3378 | |
| 3379 | /* Mono Out */ |
| 3380 | present = snd_hda_jack_detect(codec, 0x26); |
| 3381 | |
| 3382 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3383 | if (spec->codec_type == VT1802) { |
| 3384 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ |
| 3385 | snd_hda_codec_write(codec, 0x33, 0, |
| 3386 | AC_VERB_SET_POWER_STATE, parm); |
| 3387 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3388 | AC_VERB_SET_POWER_STATE, parm); |
| 3389 | snd_hda_codec_write(codec, 0x3c, 0, |
| 3390 | AC_VERB_SET_POWER_STATE, parm); |
| 3391 | } else { |
| 3392 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
| 3393 | snd_hda_codec_write(codec, 0x31, 0, |
| 3394 | AC_VERB_SET_POWER_STATE, parm); |
| 3395 | snd_hda_codec_write(codec, 0x17, 0, |
| 3396 | AC_VERB_SET_POWER_STATE, parm); |
| 3397 | snd_hda_codec_write(codec, 0x3b, 0, |
| 3398 | AC_VERB_SET_POWER_STATE, parm); |
| 3399 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3400 | /* MW9 (21h) */ |
| 3401 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 3402 | snd_hda_codec_write(codec, 0x21, 0, |
| 3403 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3404 | else |
| 3405 | snd_hda_codec_write(codec, 0x21, 0, |
| 3406 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3407 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3408 | |
| 3409 | /* patch for vt2002P */ |
| 3410 | static int patch_vt2002P(struct hda_codec *codec) |
| 3411 | { |
| 3412 | struct via_spec *spec; |
| 3413 | int err; |
| 3414 | |
| 3415 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3416 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3417 | if (spec == NULL) |
| 3418 | return -ENOMEM; |
| 3419 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3420 | spec->aa_mix_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3421 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3422 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3423 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3424 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3425 | err = via_parse_auto_config(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3426 | if (err < 0) { |
| 3427 | via_free(codec); |
| 3428 | return err; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3429 | } |
| 3430 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3431 | if (spec->codec_type == VT1802) |
| 3432 | spec->init_verbs[spec->num_iverbs++] = |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3433 | vt1802_init_verbs; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3434 | else |
| 3435 | spec->init_verbs[spec->num_iverbs++] = |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3436 | vt2002P_init_verbs; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3437 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3438 | if (spec->codec_type == VT1802) |
| 3439 | spec->init_verbs[spec->num_iverbs++] = |
| 3440 | vt1802_uniwill_init_verbs; |
| 3441 | else |
| 3442 | spec->init_verbs[spec->num_iverbs++] = |
| 3443 | vt2002P_uniwill_init_verbs; |
| 3444 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3445 | codec->patch_ops = via_patch_ops; |
| 3446 | |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3447 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3448 | |
| 3449 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3450 | spec->loopback.amplist = vt2002P_loopbacks; |
| 3451 | #endif |
| 3452 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3453 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3454 | return 0; |
| 3455 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3456 | |
| 3457 | /* for vt1812 */ |
| 3458 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3459 | static const struct hda_verb vt1812_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3460 | /* Enable Boost Volume backdoor */ |
| 3461 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3462 | /* Enable AOW0 to MW9 */ |
| 3463 | {0x1, 0xfb8, 0xa8}, |
| 3464 | { } |
| 3465 | }; |
| 3466 | |
| 3467 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3468 | static const struct hda_verb vt1812_uniwill_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3469 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3470 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 3471 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, |
| 3472 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3473 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 3474 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3475 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3476 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3477 | { } |
| 3478 | }; |
| 3479 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3480 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3481 | static const struct hda_amp_list vt1812_loopbacks[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3482 | { 0x21, HDA_INPUT, 0 }, |
| 3483 | { 0x21, HDA_INPUT, 1 }, |
| 3484 | { 0x21, HDA_INPUT, 2 }, |
| 3485 | { } /* end */ |
| 3486 | }; |
| 3487 | #endif |
| 3488 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3489 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
| 3490 | { |
| 3491 | struct via_spec *spec = codec->spec; |
| 3492 | int imux_is_smixer = |
| 3493 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3494 | unsigned int parm; |
| 3495 | unsigned int present; |
| 3496 | /* MUX10 (1eh) = stereo mixer */ |
| 3497 | imux_is_smixer = |
| 3498 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 3499 | /* inputs */ |
| 3500 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3501 | parm = AC_PWRST_D3; |
| 3502 | set_pin_power_state(codec, 0x29, &parm); |
| 3503 | set_pin_power_state(codec, 0x2a, &parm); |
| 3504 | set_pin_power_state(codec, 0x2b, &parm); |
| 3505 | parm = AC_PWRST_D0; |
| 3506 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3507 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3508 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3509 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3510 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3511 | |
| 3512 | /* outputs */ |
| 3513 | /* AOW0 (8h)*/ |
| 3514 | snd_hda_codec_write(codec, 0x8, 0, |
| 3515 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3516 | |
| 3517 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 3518 | parm = AC_PWRST_D3; |
| 3519 | set_pin_power_state(codec, 0x28, &parm); |
| 3520 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3521 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3522 | |
| 3523 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 3524 | parm = AC_PWRST_D3; |
| 3525 | set_pin_power_state(codec, 0x25, &parm); |
| 3526 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3527 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3528 | if (spec->hp_independent_mode) |
| 3529 | snd_hda_codec_write(codec, 0x9, 0, |
| 3530 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3531 | |
| 3532 | /* Internal Speaker */ |
| 3533 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 3534 | present = snd_hda_jack_detect(codec, 0x25); |
| 3535 | |
| 3536 | parm = AC_PWRST_D3; |
| 3537 | set_pin_power_state(codec, 0x24, &parm); |
| 3538 | if (present) { |
| 3539 | snd_hda_codec_write(codec, 0x14, 0, |
| 3540 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3541 | snd_hda_codec_write(codec, 0x34, 0, |
| 3542 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3543 | } else { |
| 3544 | snd_hda_codec_write(codec, 0x14, 0, |
| 3545 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3546 | snd_hda_codec_write(codec, 0x34, 0, |
| 3547 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | /* Mono Out */ |
| 3552 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 3553 | present = snd_hda_jack_detect(codec, 0x28); |
| 3554 | |
| 3555 | parm = AC_PWRST_D3; |
| 3556 | set_pin_power_state(codec, 0x31, &parm); |
| 3557 | if (present) { |
| 3558 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3559 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3560 | snd_hda_codec_write(codec, 0x3c, 0, |
| 3561 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3562 | snd_hda_codec_write(codec, 0x3e, 0, |
| 3563 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3564 | } else { |
| 3565 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3566 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3567 | snd_hda_codec_write(codec, 0x3c, 0, |
| 3568 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3569 | snd_hda_codec_write(codec, 0x3e, 0, |
| 3570 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3571 | } |
| 3572 | |
| 3573 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 3574 | parm = AC_PWRST_D3; |
| 3575 | set_pin_power_state(codec, 0x33, &parm); |
| 3576 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3577 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3578 | |
| 3579 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3580 | |
| 3581 | /* patch for vt1812 */ |
| 3582 | static int patch_vt1812(struct hda_codec *codec) |
| 3583 | { |
| 3584 | struct via_spec *spec; |
| 3585 | int err; |
| 3586 | |
| 3587 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3588 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3589 | if (spec == NULL) |
| 3590 | return -ENOMEM; |
| 3591 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3592 | spec->aa_mix_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3593 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3594 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3595 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3596 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3597 | err = via_parse_auto_config(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3598 | if (err < 0) { |
| 3599 | via_free(codec); |
| 3600 | return err; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3601 | } |
| 3602 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame^] | 3603 | spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3604 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; |
| 3605 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3606 | codec->patch_ops = via_patch_ops; |
| 3607 | |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3608 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3609 | |
| 3610 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3611 | spec->loopback.amplist = vt1812_loopbacks; |
| 3612 | #endif |
| 3613 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3614 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3615 | return 0; |
| 3616 | } |
| 3617 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3618 | /* |
| 3619 | * patch entries |
| 3620 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3621 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3622 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 3623 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 3624 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 3625 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 3626 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3627 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3628 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3629 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3630 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3631 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3632 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3633 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3634 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3635 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3636 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3637 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3638 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3639 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3640 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3641 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3642 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3643 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3644 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3645 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3646 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3647 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3648 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3649 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3650 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3651 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3652 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3653 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3654 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3655 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3656 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3657 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3658 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3659 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3660 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3661 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3662 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3663 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3664 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3665 | .patch = patch_vt1708S}, |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3666 | { .id = 0x11064397, .name = "VT1705", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3667 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3668 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3669 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3670 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3671 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3672 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3673 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3674 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3675 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3676 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3677 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3678 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3679 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3680 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3681 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3682 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3683 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3684 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3685 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3686 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3687 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3688 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3689 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3690 | { .id = 0x11060428, .name = "VT1718S", |
| 3691 | .patch = patch_vt1718S}, |
| 3692 | { .id = 0x11064428, .name = "VT1718S", |
| 3693 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 3694 | { .id = 0x11060441, .name = "VT2020", |
| 3695 | .patch = patch_vt1718S}, |
| 3696 | { .id = 0x11064441, .name = "VT1828S", |
| 3697 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3698 | { .id = 0x11060433, .name = "VT1716S", |
| 3699 | .patch = patch_vt1716S}, |
| 3700 | { .id = 0x1106a721, .name = "VT1716S", |
| 3701 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3702 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 3703 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3704 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 3705 | { .id = 0x11060440, .name = "VT1818S", |
| 3706 | .patch = patch_vt1708S}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3707 | { .id = 0x11060446, .name = "VT1802", |
| 3708 | .patch = patch_vt2002P}, |
| 3709 | { .id = 0x11068446, .name = "VT1802", |
| 3710 | .patch = patch_vt2002P}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3711 | {} /* terminator */ |
| 3712 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 3713 | |
| 3714 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 3715 | |
| 3716 | static struct hda_codec_preset_list via_list = { |
| 3717 | .preset = snd_hda_preset_via, |
| 3718 | .owner = THIS_MODULE, |
| 3719 | }; |
| 3720 | |
| 3721 | MODULE_LICENSE("GPL"); |
| 3722 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 3723 | |
| 3724 | static int __init patch_via_init(void) |
| 3725 | { |
| 3726 | return snd_hda_add_codec_preset(&via_list); |
| 3727 | } |
| 3728 | |
| 3729 | static void __exit patch_via_exit(void) |
| 3730 | { |
| 3731 | snd_hda_delete_codec_preset(&via_list); |
| 3732 | } |
| 3733 | |
| 3734 | module_init(patch_via_init) |
| 3735 | module_exit(patch_via_exit) |