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 | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 125 | const struct hda_pcm_stream *stream_analog_playback; |
| 126 | const struct hda_pcm_stream *stream_analog_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 127 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 128 | char stream_name_digital[32]; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 129 | const struct hda_pcm_stream *stream_digital_playback; |
| 130 | const struct hda_pcm_stream *stream_digital_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 131 | |
| 132 | /* playback */ |
| 133 | struct hda_multi_out multiout; |
| 134 | hda_nid_t slave_dig_outs[2]; |
| 135 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 136 | struct nid_path out_path[4]; |
| 137 | struct nid_path hp_path; |
| 138 | struct nid_path hp_dep_path; |
| 139 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 140 | /* capture */ |
| 141 | unsigned int num_adc_nids; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 142 | hda_nid_t adc_nids[3]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 143 | hda_nid_t mux_nids[3]; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 144 | hda_nid_t aa_mix_nid; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 145 | hda_nid_t dig_in_nid; |
| 146 | hda_nid_t dig_in_pin; |
| 147 | |
| 148 | /* capture source */ |
| 149 | const struct hda_input_mux *input_mux; |
| 150 | unsigned int cur_mux[3]; |
| 151 | |
| 152 | /* PCM information */ |
| 153 | struct hda_pcm pcm_rec[3]; |
| 154 | |
| 155 | /* dynamic controls, init_verbs and input_mux */ |
| 156 | struct auto_pin_cfg autocfg; |
| 157 | struct snd_array kctls; |
| 158 | struct hda_input_mux private_imux[2]; |
| 159 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
| 160 | |
| 161 | /* HP mode source */ |
| 162 | const struct hda_input_mux *hp_mux; |
| 163 | unsigned int hp_independent_mode; |
| 164 | unsigned int hp_independent_mode_index; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 165 | unsigned int can_smart51; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 166 | unsigned int smart51_enabled; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 167 | unsigned int dmic_enabled; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 168 | unsigned int no_pin_power_ctl; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 169 | enum VIA_HDA_CODEC codec_type; |
| 170 | |
| 171 | /* work to check hp jack state */ |
| 172 | struct hda_codec *codec; |
| 173 | struct delayed_work vt1708_hp_work; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 174 | int vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 175 | int vt1708_hp_present; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 176 | |
| 177 | void (*set_widgets_power_state)(struct hda_codec *codec); |
| 178 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 179 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 180 | struct hda_loopback_check loopback; |
| 181 | #endif |
| 182 | }; |
| 183 | |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 184 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 185 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
| 186 | { |
| 187 | struct via_spec *spec; |
| 188 | |
| 189 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 190 | if (spec == NULL) |
| 191 | return NULL; |
| 192 | |
| 193 | codec->spec = spec; |
| 194 | spec->codec = codec; |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 195 | spec->codec_type = get_codec_type(codec); |
| 196 | /* VT1708BCE & VT1708S are almost same */ |
| 197 | if (spec->codec_type == VT1708BCE) |
| 198 | spec->codec_type = VT1708S; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 199 | return spec; |
| 200 | } |
| 201 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 202 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 203 | { |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 204 | u32 vendor_id = codec->vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 205 | u16 ven_id = vendor_id >> 16; |
| 206 | u16 dev_id = vendor_id & 0xffff; |
| 207 | enum VIA_HDA_CODEC codec_type; |
| 208 | |
| 209 | /* get codec type */ |
| 210 | if (ven_id != 0x1106) |
| 211 | codec_type = UNKNOWN; |
| 212 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 213 | codec_type = VT1708; |
| 214 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 215 | codec_type = VT1709_10CH; |
| 216 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 217 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 218 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 219 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 220 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 221 | codec_type = VT1708BCE; |
| 222 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 223 | codec_type = VT1708B_4CH; |
| 224 | else if ((dev_id & 0xfff) == 0x397 |
| 225 | && (dev_id >> 12) < 8) |
| 226 | codec_type = VT1708S; |
| 227 | else if ((dev_id & 0xfff) == 0x398 |
| 228 | && (dev_id >> 12) < 8) |
| 229 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 230 | else if ((dev_id & 0xfff) == 0x428 |
| 231 | && (dev_id >> 12) < 8) |
| 232 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 233 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 234 | codec_type = VT1716S; |
Lydia Wang | bb3c6bf | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 235 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 236 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 237 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 238 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 239 | else if (dev_id == 0x0448) |
| 240 | codec_type = VT1812; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 241 | else if (dev_id == 0x0440) |
| 242 | codec_type = VT1708S; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 243 | else if ((dev_id & 0xfff) == 0x446) |
| 244 | codec_type = VT1802; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 245 | else |
| 246 | codec_type = UNKNOWN; |
| 247 | return codec_type; |
| 248 | }; |
| 249 | |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 250 | #define VIA_JACK_EVENT 0x20 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 251 | #define VIA_HP_EVENT 0x01 |
| 252 | #define VIA_GPIO_EVENT 0x02 |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 253 | #define VIA_MONO_EVENT 0x03 |
| 254 | #define VIA_SPEAKER_EVENT 0x04 |
| 255 | #define VIA_BIND_HP_EVENT 0x05 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 256 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 257 | enum { |
| 258 | VIA_CTL_WIDGET_VOL, |
| 259 | VIA_CTL_WIDGET_MUTE, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 260 | VIA_CTL_WIDGET_ANALOG_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 261 | VIA_CTL_WIDGET_BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | enum { |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 265 | AUTO_SEQ_FRONT = 0, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 266 | AUTO_SEQ_SURROUND, |
| 267 | AUTO_SEQ_CENLFE, |
| 268 | AUTO_SEQ_SIDE |
| 269 | }; |
| 270 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 271 | 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] | 272 | static int is_aa_path_mute(struct hda_codec *codec); |
| 273 | |
| 274 | static void vt1708_start_hp_work(struct via_spec *spec) |
| 275 | { |
| 276 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 277 | return; |
| 278 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 279 | !spec->vt1708_jack_detect); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 280 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
| 281 | schedule_delayed_work(&spec->vt1708_hp_work, |
| 282 | msecs_to_jiffies(100)); |
| 283 | } |
| 284 | |
| 285 | static void vt1708_stop_hp_work(struct via_spec *spec) |
| 286 | { |
| 287 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 288 | return; |
| 289 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 |
| 290 | && !is_aa_path_mute(spec->codec)) |
| 291 | return; |
| 292 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 293 | !spec->vt1708_jack_detect); |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 294 | cancel_delayed_work_sync(&spec->vt1708_hp_work); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 295 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 296 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 297 | static void set_widgets_power_state(struct hda_codec *codec) |
| 298 | { |
| 299 | struct via_spec *spec = codec->spec; |
| 300 | if (spec->set_widgets_power_state) |
| 301 | spec->set_widgets_power_state(codec); |
| 302 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 303 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 304 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
| 305 | struct snd_ctl_elem_value *ucontrol) |
| 306 | { |
| 307 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 308 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 309 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 310 | set_widgets_power_state(codec); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 311 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 312 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
| 313 | if (is_aa_path_mute(codec)) |
| 314 | vt1708_start_hp_work(codec->spec); |
| 315 | else |
| 316 | vt1708_stop_hp_work(codec->spec); |
| 317 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 318 | return change; |
| 319 | } |
| 320 | |
| 321 | /* modify .put = snd_hda_mixer_amp_switch_put */ |
| 322 | #define ANALOG_INPUT_MUTE \ |
| 323 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 324 | .name = NULL, \ |
| 325 | .index = 0, \ |
| 326 | .info = snd_hda_mixer_amp_switch_info, \ |
| 327 | .get = snd_hda_mixer_amp_switch_get, \ |
| 328 | .put = analog_input_switch_put, \ |
| 329 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 330 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 331 | static void via_hp_bind_automute(struct hda_codec *codec); |
| 332 | |
| 333 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, |
| 334 | struct snd_ctl_elem_value *ucontrol) |
| 335 | { |
| 336 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 337 | struct via_spec *spec = codec->spec; |
| 338 | int i; |
| 339 | int change = 0; |
| 340 | |
| 341 | long *valp = ucontrol->value.integer.value; |
| 342 | int lmute, rmute; |
| 343 | if (strstr(kcontrol->id.name, "Switch") == NULL) { |
| 344 | snd_printd("Invalid control!\n"); |
| 345 | return change; |
| 346 | } |
| 347 | change = snd_hda_mixer_amp_switch_put(kcontrol, |
| 348 | ucontrol); |
| 349 | /* Get mute value */ |
| 350 | lmute = *valp ? 0 : HDA_AMP_MUTE; |
| 351 | valp++; |
| 352 | rmute = *valp ? 0 : HDA_AMP_MUTE; |
| 353 | |
| 354 | /* Set hp pins */ |
| 355 | if (!spec->hp_independent_mode) { |
| 356 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 357 | snd_hda_codec_amp_update( |
| 358 | codec, spec->autocfg.hp_pins[i], |
| 359 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 360 | lmute); |
| 361 | snd_hda_codec_amp_update( |
| 362 | codec, spec->autocfg.hp_pins[i], |
| 363 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 364 | rmute); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | if (!lmute && !rmute) { |
| 369 | /* Line Outs */ |
| 370 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 371 | snd_hda_codec_amp_stereo( |
| 372 | codec, spec->autocfg.line_out_pins[i], |
| 373 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 374 | /* Speakers */ |
| 375 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 376 | snd_hda_codec_amp_stereo( |
| 377 | codec, spec->autocfg.speaker_pins[i], |
| 378 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 379 | /* unmute */ |
| 380 | via_hp_bind_automute(codec); |
| 381 | |
| 382 | } else { |
| 383 | if (lmute) { |
| 384 | /* Mute all left channels */ |
| 385 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 386 | snd_hda_codec_amp_update( |
| 387 | codec, |
| 388 | spec->autocfg.line_out_pins[i], |
| 389 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 390 | lmute); |
| 391 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 392 | snd_hda_codec_amp_update( |
| 393 | codec, |
| 394 | spec->autocfg.speaker_pins[i], |
| 395 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 396 | lmute); |
| 397 | } |
| 398 | if (rmute) { |
| 399 | /* mute all right channels */ |
| 400 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 401 | snd_hda_codec_amp_update( |
| 402 | codec, |
| 403 | spec->autocfg.line_out_pins[i], |
| 404 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 405 | rmute); |
| 406 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 407 | snd_hda_codec_amp_update( |
| 408 | codec, |
| 409 | spec->autocfg.speaker_pins[i], |
| 410 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 411 | rmute); |
| 412 | } |
| 413 | } |
| 414 | return change; |
| 415 | } |
| 416 | |
| 417 | #define BIND_PIN_MUTE \ |
| 418 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 419 | .name = NULL, \ |
| 420 | .index = 0, \ |
| 421 | .info = snd_hda_mixer_amp_switch_info, \ |
| 422 | .get = snd_hda_mixer_amp_switch_get, \ |
| 423 | .put = bind_pin_switch_put, \ |
| 424 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 425 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 426 | static const struct snd_kcontrol_new via_control_templates[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 427 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 428 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 429 | ANALOG_INPUT_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 430 | BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 431 | }; |
| 432 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 433 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 434 | /* add dynamic controls */ |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 435 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
| 436 | const struct snd_kcontrol_new *tmpl, |
| 437 | const char *name) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 438 | { |
| 439 | struct snd_kcontrol_new *knew; |
| 440 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 441 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
| 442 | knew = snd_array_new(&spec->kctls); |
| 443 | if (!knew) |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 444 | return NULL; |
| 445 | *knew = *tmpl; |
| 446 | if (!name) |
| 447 | name = tmpl->name; |
| 448 | if (name) { |
| 449 | knew->name = kstrdup(name, GFP_KERNEL); |
| 450 | if (!knew->name) |
| 451 | return NULL; |
| 452 | } |
| 453 | return knew; |
| 454 | } |
| 455 | |
| 456 | static int __via_add_control(struct via_spec *spec, int type, const char *name, |
| 457 | int idx, unsigned long val) |
| 458 | { |
| 459 | struct snd_kcontrol_new *knew; |
| 460 | |
| 461 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); |
| 462 | if (!knew) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 463 | return -ENOMEM; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 464 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 465 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 466 | knew->private_value = val; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 467 | return 0; |
| 468 | } |
| 469 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 470 | #define via_add_control(spec, type, name, val) \ |
| 471 | __via_add_control(spec, type, name, 0, val) |
| 472 | |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 473 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 474 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 475 | static void via_free_kctls(struct hda_codec *codec) |
| 476 | { |
| 477 | struct via_spec *spec = codec->spec; |
| 478 | |
| 479 | if (spec->kctls.list) { |
| 480 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 481 | int i; |
| 482 | for (i = 0; i < spec->kctls.used; i++) |
| 483 | kfree(kctl[i].name); |
| 484 | } |
| 485 | snd_array_free(&spec->kctls); |
| 486 | } |
| 487 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 488 | /* create input playback/capture controls for the given pin */ |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 489 | 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] | 490 | int type_idx, int idx, int mix_nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 491 | { |
| 492 | char name[32]; |
| 493 | int err; |
| 494 | |
| 495 | sprintf(name, "%s Playback Volume", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 496 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 497 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 498 | if (err < 0) |
| 499 | return err; |
| 500 | sprintf(name, "%s Playback Switch", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 501 | 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] | 502 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 503 | if (err < 0) |
| 504 | return err; |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static void via_auto_set_output_and_unmute(struct hda_codec *codec, |
| 509 | hda_nid_t nid, int pin_type, |
| 510 | int dac_idx) |
| 511 | { |
| 512 | /* set as output */ |
| 513 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 514 | pin_type); |
| 515 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 516 | AMP_OUT_UNMUTE); |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 517 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 518 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 519 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
| 523 | static void via_auto_init_multi_out(struct hda_codec *codec) |
| 524 | { |
| 525 | struct via_spec *spec = codec->spec; |
| 526 | int i; |
| 527 | |
| 528 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 529 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 530 | if (nid) |
| 531 | via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static void via_auto_init_hp_out(struct hda_codec *codec) |
| 536 | { |
| 537 | struct via_spec *spec = codec->spec; |
| 538 | hda_nid_t pin; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 539 | int i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 540 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 541 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 542 | pin = spec->autocfg.hp_pins[i]; |
| 543 | if (pin) /* connect to front */ |
| 544 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); |
| 545 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 548 | 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] | 549 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 550 | static void via_auto_init_analog_input(struct hda_codec *codec) |
| 551 | { |
| 552 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 553 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 554 | unsigned int ctl; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 555 | int i; |
| 556 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 557 | for (i = 0; i < cfg->num_inputs; i++) { |
| 558 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 559 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 560 | ctl = PIN_OUT; |
David Henningsson | 3064967 | 2011-02-21 10:23:18 +0100 | [diff] [blame] | 561 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 562 | ctl = PIN_VREF50; |
| 563 | else |
| 564 | ctl = PIN_IN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 565 | snd_hda_codec_write(codec, nid, 0, |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 566 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 567 | } |
| 568 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 569 | |
| 570 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 571 | unsigned int *affected_parm) |
| 572 | { |
| 573 | unsigned parm; |
| 574 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 575 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) |
| 576 | >> AC_DEFCFG_MISC_SHIFT |
| 577 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 578 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 579 | unsigned present = 0; |
| 580 | |
| 581 | no_presence |= spec->no_pin_power_ctl; |
| 582 | if (!no_presence) |
| 583 | present = snd_hda_jack_detect(codec, nid); |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 584 | if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 585 | || ((no_presence || present) |
| 586 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 587 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
| 588 | parm = AC_PWRST_D0; |
| 589 | } else |
| 590 | parm = AC_PWRST_D3; |
| 591 | |
| 592 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 593 | } |
| 594 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 595 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
| 596 | struct snd_ctl_elem_info *uinfo) |
| 597 | { |
| 598 | static const char * const texts[] = { |
| 599 | "Disabled", "Enabled" |
| 600 | }; |
| 601 | |
| 602 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 603 | uinfo->count = 1; |
| 604 | uinfo->value.enumerated.items = 2; |
| 605 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 606 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 607 | strcpy(uinfo->value.enumerated.name, |
| 608 | texts[uinfo->value.enumerated.item]); |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, |
| 613 | struct snd_ctl_elem_value *ucontrol) |
| 614 | { |
| 615 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 616 | struct via_spec *spec = codec->spec; |
| 617 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, |
| 622 | struct snd_ctl_elem_value *ucontrol) |
| 623 | { |
| 624 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 625 | struct via_spec *spec = codec->spec; |
| 626 | unsigned int val = !ucontrol->value.enumerated.item[0]; |
| 627 | |
| 628 | if (val == spec->no_pin_power_ctl) |
| 629 | return 0; |
| 630 | spec->no_pin_power_ctl = val; |
| 631 | set_widgets_power_state(codec); |
| 632 | return 1; |
| 633 | } |
| 634 | |
| 635 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { |
| 636 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 637 | .name = "Dynamic Power-Control", |
| 638 | .info = via_pin_power_ctl_info, |
| 639 | .get = via_pin_power_ctl_get, |
| 640 | .put = via_pin_power_ctl_put, |
| 641 | }; |
| 642 | |
| 643 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 644 | /* |
| 645 | * input MUX handling |
| 646 | */ |
| 647 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 648 | struct snd_ctl_elem_info *uinfo) |
| 649 | { |
| 650 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 651 | struct via_spec *spec = codec->spec; |
| 652 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
| 653 | } |
| 654 | |
| 655 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 656 | struct snd_ctl_elem_value *ucontrol) |
| 657 | { |
| 658 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 659 | struct via_spec *spec = codec->spec; |
| 660 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 661 | |
| 662 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 667 | struct snd_ctl_elem_value *ucontrol) |
| 668 | { |
| 669 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 670 | struct via_spec *spec = codec->spec; |
| 671 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 672 | int ret; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 673 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 674 | if (!spec->mux_nids[adc_idx]) |
| 675 | return -EINVAL; |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 676 | /* switch to D0 beofre change index */ |
| 677 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, |
| 678 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) |
| 679 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, |
| 680 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 681 | |
| 682 | ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
| 683 | spec->mux_nids[adc_idx], |
| 684 | &spec->cur_mux[adc_idx]); |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 685 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 686 | set_widgets_power_state(codec); |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 687 | |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 688 | return ret; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 691 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
| 692 | struct snd_ctl_elem_info *uinfo) |
| 693 | { |
| 694 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 695 | struct via_spec *spec = codec->spec; |
| 696 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); |
| 697 | } |
| 698 | |
| 699 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, |
| 700 | struct snd_ctl_elem_value *ucontrol) |
| 701 | { |
| 702 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 703 | hda_nid_t nid = kcontrol->private_value; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 704 | unsigned int pinsel; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 705 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 706 | /* use !! to translate conn sel 2 for VT1718S */ |
| 707 | pinsel = !!snd_hda_codec_read(codec, nid, 0, |
| 708 | AC_VERB_GET_CONNECT_SEL, |
| 709 | 0x00); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 710 | ucontrol->value.enumerated.item[0] = pinsel; |
| 711 | |
| 712 | return 0; |
| 713 | } |
| 714 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 715 | static void activate_ctl(struct hda_codec *codec, const char *name, int active) |
| 716 | { |
| 717 | struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); |
| 718 | if (ctl) { |
| 719 | ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 720 | ctl->vd[0].access |= active |
| 721 | ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 722 | snd_ctl_notify(codec->bus->card, |
| 723 | SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); |
| 724 | } |
| 725 | } |
| 726 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 727 | static hda_nid_t side_mute_channel(struct via_spec *spec) |
| 728 | { |
| 729 | switch (spec->codec_type) { |
| 730 | case VT1708: return 0x1b; |
| 731 | case VT1709_10CH: return 0x29; |
| 732 | case VT1708B_8CH: /* fall thru */ |
| 733 | case VT1708S: return 0x27; |
Lydia Wang | e87885f | 2011-03-24 12:39:05 +0800 | [diff] [blame] | 734 | case VT2002P: return 0x19; |
| 735 | case VT1802: return 0x15; |
| 736 | case VT1812: return 0x15; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 737 | default: return 0; |
| 738 | } |
| 739 | } |
| 740 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 741 | static int update_side_mute_status(struct hda_codec *codec) |
| 742 | { |
| 743 | /* mute side channel */ |
| 744 | struct via_spec *spec = codec->spec; |
Lydia Wang | e87885f | 2011-03-24 12:39:05 +0800 | [diff] [blame] | 745 | unsigned int parm; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 746 | hda_nid_t sw3 = side_mute_channel(spec); |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 747 | |
Lydia Wang | e87885f | 2011-03-24 12:39:05 +0800 | [diff] [blame] | 748 | if (sw3) { |
| 749 | if (VT2002P_COMPATIBLE(spec)) |
| 750 | parm = spec->hp_independent_mode ? |
| 751 | AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1); |
| 752 | else |
| 753 | parm = spec->hp_independent_mode ? |
| 754 | AMP_OUT_MUTE : AMP_OUT_UNMUTE; |
| 755 | snd_hda_codec_write(codec, sw3, 0, |
| 756 | AC_VERB_SET_AMP_GAIN_MUTE, parm); |
| 757 | if (spec->codec_type == VT1812) |
| 758 | snd_hda_codec_write(codec, 0x1d, 0, |
| 759 | AC_VERB_SET_AMP_GAIN_MUTE, parm); |
| 760 | } |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 764 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
| 765 | struct snd_ctl_elem_value *ucontrol) |
| 766 | { |
| 767 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 768 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 769 | hda_nid_t nid = kcontrol->private_value; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 770 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 771 | /* Get Independent Mode index of headphone pin widget */ |
| 772 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel |
| 773 | ? 1 : 0; |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 774 | if (spec->codec_type == VT1718S) |
| 775 | snd_hda_codec_write(codec, nid, 0, |
| 776 | AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0); |
| 777 | else |
| 778 | snd_hda_codec_write(codec, nid, 0, |
| 779 | AC_VERB_SET_CONNECT_SEL, pinsel); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 780 | |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 781 | if (spec->codec_type == VT1812) |
| 782 | snd_hda_codec_write(codec, 0x35, 0, |
| 783 | AC_VERB_SET_CONNECT_SEL, pinsel); |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 784 | if (spec->multiout.hp_nid && spec->multiout.hp_nid |
| 785 | != spec->multiout.dac_nids[HDA_FRONT]) |
| 786 | snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, |
| 787 | 0, 0, 0); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 788 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 789 | update_side_mute_status(codec); |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 790 | /* update HP volume/swtich active state */ |
| 791 | if (spec->codec_type == VT1708S |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 792 | || spec->codec_type == VT1702 |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 793 | || spec->codec_type == VT1718S |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 794 | || spec->codec_type == VT1716S |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 795 | || VT2002P_COMPATIBLE(spec)) { |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 796 | activate_ctl(codec, "Headphone Playback Volume", |
| 797 | spec->hp_independent_mode); |
| 798 | activate_ctl(codec, "Headphone Playback Switch", |
| 799 | spec->hp_independent_mode); |
| 800 | } |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 801 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 802 | set_widgets_power_state(codec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 803 | return 0; |
| 804 | } |
| 805 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 806 | static const struct snd_kcontrol_new via_hp_mixer[2] = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 807 | { |
| 808 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 809 | .name = "Independent HP", |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 810 | .info = via_independent_hp_info, |
| 811 | .get = via_independent_hp_get, |
| 812 | .put = via_independent_hp_put, |
| 813 | }, |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 814 | { |
| 815 | .iface = NID_MAPPING, |
| 816 | .name = "Independent HP", |
| 817 | }, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 818 | }; |
| 819 | |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 820 | static int via_hp_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 821 | { |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 822 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 823 | struct snd_kcontrol_new *knew; |
| 824 | hda_nid_t nid; |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 825 | int nums; |
| 826 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 827 | |
| 828 | switch (spec->codec_type) { |
| 829 | case VT1718S: |
| 830 | nid = 0x34; |
| 831 | break; |
| 832 | case VT2002P: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 833 | case VT1802: |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 834 | nid = 0x35; |
| 835 | break; |
| 836 | case VT1812: |
| 837 | nid = 0x3d; |
| 838 | break; |
| 839 | default: |
| 840 | nid = spec->autocfg.hp_pins[0]; |
| 841 | break; |
| 842 | } |
| 843 | |
Lydia Wang | ee3c35c | 2011-03-22 16:26:36 +0800 | [diff] [blame] | 844 | if (spec->codec_type != VT1708) { |
| 845 | nums = snd_hda_get_connections(codec, nid, |
| 846 | conn, HDA_MAX_CONNECTIONS); |
| 847 | if (nums <= 1) |
| 848 | return 0; |
| 849 | } |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 850 | |
| 851 | knew = via_clone_control(spec, &via_hp_mixer[0]); |
| 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 | |
| 858 | knew = via_clone_control(spec, &via_hp_mixer[1]); |
| 859 | if (knew == NULL) |
| 860 | return -ENOMEM; |
| 861 | knew->subdevice = side_mute_channel(spec); |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 866 | static void notify_aa_path_ctls(struct hda_codec *codec) |
| 867 | { |
| 868 | int i; |
| 869 | struct snd_ctl_elem_id id; |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 870 | const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"}; |
| 871 | struct snd_kcontrol *ctl; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 872 | |
| 873 | memset(&id, 0, sizeof(id)); |
| 874 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 875 | for (i = 0; i < ARRAY_SIZE(labels); i++) { |
| 876 | sprintf(id.name, "%s Playback Volume", labels[i]); |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 877 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
| 878 | if (ctl) |
| 879 | snd_ctl_notify(codec->bus->card, |
| 880 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 881 | &ctl->id); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | |
| 885 | static void mute_aa_path(struct hda_codec *codec, int mute) |
| 886 | { |
| 887 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 888 | int start_idx; |
| 889 | int end_idx; |
| 890 | int i; |
| 891 | /* get nid of MW0 and start & end index */ |
| 892 | switch (spec->codec_type) { |
| 893 | case VT1708: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 894 | start_idx = 2; |
| 895 | end_idx = 4; |
| 896 | break; |
| 897 | case VT1709_10CH: |
| 898 | case VT1709_6CH: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 899 | start_idx = 2; |
| 900 | end_idx = 4; |
| 901 | break; |
| 902 | case VT1708B_8CH: |
| 903 | case VT1708B_4CH: |
| 904 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 905 | case VT1716S: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 906 | start_idx = 2; |
| 907 | end_idx = 4; |
| 908 | break; |
Lydia Wang | ab657e0 | 2011-03-22 16:23:23 +0800 | [diff] [blame] | 909 | case VT1718S: |
Lydia Wang | ab657e0 | 2011-03-22 16:23:23 +0800 | [diff] [blame] | 910 | start_idx = 1; |
| 911 | end_idx = 3; |
| 912 | break; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 913 | default: |
| 914 | return; |
| 915 | } |
| 916 | /* check AA path's mute status */ |
| 917 | for (i = start_idx; i <= end_idx; i++) { |
| 918 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 919 | 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] | 920 | HDA_AMP_MUTE, val); |
| 921 | } |
| 922 | } |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 923 | |
| 924 | 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] | 925 | { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 926 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 927 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 928 | int i; |
| 929 | |
| 930 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 931 | unsigned int defcfg; |
| 932 | if (pin != cfg->inputs[i].pin) |
| 933 | continue; |
| 934 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
| 935 | return false; |
| 936 | defcfg = snd_hda_codec_get_pincfg(codec, pin); |
| 937 | if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL) |
| 938 | return false; |
| 939 | return true; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 940 | } |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 941 | return false; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static int via_smart51_info(struct snd_kcontrol *kcontrol, |
| 945 | struct snd_ctl_elem_info *uinfo) |
| 946 | { |
| 947 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 948 | uinfo->count = 1; |
| 949 | uinfo->value.integer.min = 0; |
| 950 | uinfo->value.integer.max = 1; |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | static int via_smart51_get(struct snd_kcontrol *kcontrol, |
| 955 | struct snd_ctl_elem_value *ucontrol) |
| 956 | { |
| 957 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 958 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 959 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 960 | int on = 1; |
| 961 | int i; |
| 962 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 963 | for (i = 0; i < cfg->num_inputs; i++) { |
| 964 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 965 | unsigned int ctl; |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 966 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 967 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
| 968 | continue; /* ignore FMic for independent HP */ |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 969 | if (!is_smart51_pins(codec, nid)) |
| 970 | continue; |
| 971 | ctl = snd_hda_codec_read(codec, nid, 0, |
| 972 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 973 | if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) |
| 974 | on = 0; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 975 | } |
| 976 | *ucontrol->value.integer.value = on; |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static int via_smart51_put(struct snd_kcontrol *kcontrol, |
| 981 | struct snd_ctl_elem_value *ucontrol) |
| 982 | { |
| 983 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 984 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 985 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 986 | int out_in = *ucontrol->value.integer.value |
| 987 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 988 | int i; |
| 989 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 990 | for (i = 0; i < cfg->num_inputs; i++) { |
| 991 | hda_nid_t nid = cfg->inputs[i].pin; |
| 992 | unsigned int parm; |
| 993 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 994 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 995 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 996 | continue; /* don't retask FMic for independent HP */ |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 997 | if (!is_smart51_pins(codec, nid)) |
| 998 | continue; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 999 | |
| 1000 | parm = snd_hda_codec_read(codec, nid, 0, |
| 1001 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 1002 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); |
| 1003 | parm |= out_in; |
| 1004 | snd_hda_codec_write(codec, nid, 0, |
| 1005 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1006 | parm); |
| 1007 | if (out_in == AC_PINCTL_OUT_EN) { |
| 1008 | mute_aa_path(codec, 1); |
| 1009 | notify_aa_path_ctls(codec); |
| 1010 | } |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1011 | } |
| 1012 | spec->smart51_enabled = *ucontrol->value.integer.value; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1013 | set_widgets_power_state(codec); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1014 | return 1; |
| 1015 | } |
| 1016 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1017 | static const struct snd_kcontrol_new via_smart51_mixer = { |
| 1018 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1019 | .name = "Smart 5.1", |
| 1020 | .count = 1, |
| 1021 | .info = via_smart51_info, |
| 1022 | .get = via_smart51_get, |
| 1023 | .put = via_smart51_put, |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1024 | }; |
| 1025 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1026 | static int via_smart51_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1027 | { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1028 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1029 | struct snd_kcontrol_new *knew; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1030 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1031 | hda_nid_t nid; |
| 1032 | int i; |
| 1033 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1034 | if (!spec->can_smart51) |
Lydia Wang | cb34c20 | 2011-04-27 17:44:16 +0800 | [diff] [blame] | 1035 | return 0; |
| 1036 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1037 | knew = via_clone_control(spec, &via_smart51_mixer); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1038 | if (knew == NULL) |
| 1039 | return -ENOMEM; |
| 1040 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1041 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1042 | nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1043 | if (is_smart51_pins(codec, nid)) { |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1044 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1045 | break; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1052 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1053 | static const struct snd_kcontrol_new vt1708_capture_mixer[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1054 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), |
| 1055 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT), |
| 1056 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT), |
| 1057 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT), |
| 1058 | { |
| 1059 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1060 | /* The multiple "Capture Source" controls confuse alsamixer |
| 1061 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1062 | */ |
| 1063 | /* .name = "Capture Source", */ |
| 1064 | .name = "Input Source", |
| 1065 | .count = 1, |
| 1066 | .info = via_mux_enum_info, |
| 1067 | .get = via_mux_enum_get, |
| 1068 | .put = via_mux_enum_put, |
| 1069 | }, |
| 1070 | { } /* end */ |
| 1071 | }; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1072 | |
| 1073 | /* check AA path's mute statue */ |
| 1074 | static int is_aa_path_mute(struct hda_codec *codec) |
| 1075 | { |
| 1076 | int mute = 1; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1077 | int start_idx; |
| 1078 | int end_idx; |
| 1079 | int i; |
| 1080 | struct via_spec *spec = codec->spec; |
| 1081 | /* get nid of MW0 and start & end index */ |
| 1082 | switch (spec->codec_type) { |
| 1083 | case VT1708B_8CH: |
| 1084 | case VT1708B_4CH: |
| 1085 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1086 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1087 | start_idx = 2; |
| 1088 | end_idx = 4; |
| 1089 | break; |
| 1090 | case VT1702: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1091 | start_idx = 1; |
| 1092 | end_idx = 3; |
| 1093 | break; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1094 | case VT1718S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1095 | start_idx = 1; |
| 1096 | end_idx = 3; |
| 1097 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1098 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1099 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1100 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1101 | start_idx = 0; |
| 1102 | end_idx = 2; |
| 1103 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1104 | default: |
| 1105 | return 0; |
| 1106 | } |
| 1107 | /* check AA path's mute status */ |
| 1108 | for (i = start_idx; i <= end_idx; i++) { |
| 1109 | unsigned int con_list = snd_hda_codec_read( |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1110 | 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] | 1111 | int shift = 8 * (i % 4); |
| 1112 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; |
| 1113 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); |
| 1114 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { |
| 1115 | /* check mute status while the pin is connected */ |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1116 | 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] | 1117 | HDA_INPUT, i) >> 7; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 1118 | 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] | 1119 | HDA_INPUT, i) >> 7; |
| 1120 | if (!mute_l || !mute_r) { |
| 1121 | mute = 0; |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | return mute; |
| 1127 | } |
| 1128 | |
| 1129 | /* enter/exit analog low-current mode */ |
| 1130 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) |
| 1131 | { |
| 1132 | struct via_spec *spec = codec->spec; |
| 1133 | static int saved_stream_idle = 1; /* saved stream idle status */ |
| 1134 | int enable = is_aa_path_mute(codec); |
| 1135 | unsigned int verb = 0; |
| 1136 | unsigned int parm = 0; |
| 1137 | |
| 1138 | if (stream_idle == -1) /* stream status did not change */ |
| 1139 | enable = enable && saved_stream_idle; |
| 1140 | else { |
| 1141 | enable = enable && stream_idle; |
| 1142 | saved_stream_idle = stream_idle; |
| 1143 | } |
| 1144 | |
| 1145 | /* decide low current mode's verb & parameter */ |
| 1146 | switch (spec->codec_type) { |
| 1147 | case VT1708B_8CH: |
| 1148 | case VT1708B_4CH: |
| 1149 | verb = 0xf70; |
| 1150 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 1151 | break; |
| 1152 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1153 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1154 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1155 | verb = 0xf73; |
| 1156 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 1157 | break; |
| 1158 | case VT1702: |
| 1159 | verb = 0xf73; |
| 1160 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 1161 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1162 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1163 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1164 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1165 | verb = 0xf93; |
| 1166 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 1167 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1168 | default: |
| 1169 | return; /* other codecs are not supported */ |
| 1170 | } |
| 1171 | /* send verb */ |
| 1172 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); |
| 1173 | } |
| 1174 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1175 | /* |
| 1176 | * generic initialization of ADC, input mixers and output mixers |
| 1177 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1178 | static const struct hda_verb vt1708_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1179 | /* |
| 1180 | * Unmute ADC0-1 and set the default input to mic-in |
| 1181 | */ |
| 1182 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1183 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1184 | |
| 1185 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1186 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1187 | * mixer widget |
| 1188 | */ |
| 1189 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1190 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1191 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 1192 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 1193 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 1194 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1195 | |
| 1196 | /* |
| 1197 | * Set up output mixers (0x19 - 0x1b) |
| 1198 | */ |
| 1199 | /* set vol=0 to output mixers */ |
| 1200 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 1201 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 1202 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1203 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 1204 | /* Setup default input MW0 to PW4 */ |
| 1205 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1206 | /* PW9 Output enable */ |
| 1207 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Lydia Wang | aa266fc | 2011-03-24 12:41:01 +0800 | [diff] [blame] | 1208 | /* power down jack detect function */ |
| 1209 | {0x1, 0xf81, 0x1}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1210 | { } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1211 | }; |
| 1212 | |
| 1213 | static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1214 | struct hda_codec *codec, |
| 1215 | struct snd_pcm_substream *substream) |
| 1216 | { |
| 1217 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1218 | int idle = substream->pstr->substream_opened == 1 |
| 1219 | && substream->ref_count == 0; |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1220 | analog_low_current_mode(codec, idle); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1221 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 1222 | hinfo); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1223 | } |
| 1224 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1225 | static int via_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1226 | struct hda_codec *codec, |
| 1227 | struct snd_pcm_substream *substream) |
| 1228 | { |
| 1229 | int idle = substream->pstr->substream_opened == 1 |
| 1230 | && substream->ref_count == 0; |
| 1231 | |
| 1232 | analog_low_current_mode(codec, idle); |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1236 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, |
| 1237 | unsigned int stream_tag, |
| 1238 | unsigned int format, |
| 1239 | struct snd_pcm_substream *substream) |
| 1240 | { |
| 1241 | struct via_spec *spec = codec->spec; |
| 1242 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1243 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1244 | int chs = substream->runtime->channels; |
| 1245 | int i; |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1246 | struct hda_spdif_out *spdif = |
| 1247 | snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1248 | |
| 1249 | mutex_lock(&codec->spdif_mutex); |
| 1250 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
| 1251 | if (chs == 2 && |
| 1252 | snd_hda_is_supported_format(codec, mout->dig_out_nid, |
| 1253 | format) && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1254 | !(spdif->status & IEC958_AES0_NONAUDIO)) { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1255 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
| 1256 | /* turn off SPDIF once; otherwise the IEC958 bits won't |
| 1257 | * be updated */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1258 | if (spdif->ctls & AC_DIG1_ENABLE) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1259 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1260 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1261 | spdif->ctls & |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1262 | ~AC_DIG1_ENABLE & 0xff); |
| 1263 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1264 | stream_tag, 0, format); |
| 1265 | /* turn on again (if needed) */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1266 | if (spdif->ctls & AC_DIG1_ENABLE) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1267 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1268 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1269 | spdif->ctls & 0xff); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1270 | } else { |
| 1271 | mout->dig_out_used = 0; |
| 1272 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1273 | 0, 0, 0); |
| 1274 | } |
| 1275 | } |
| 1276 | mutex_unlock(&codec->spdif_mutex); |
| 1277 | |
| 1278 | /* front */ |
| 1279 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
| 1280 | 0, format); |
| 1281 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1282 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
| 1283 | && !spec->hp_independent_mode) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1284 | /* headphone out will just decode front left/right (stereo) */ |
| 1285 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
| 1286 | 0, format); |
| 1287 | |
| 1288 | /* extra outputs copied from front */ |
| 1289 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1290 | if (mout->extra_out_nid[i]) |
| 1291 | snd_hda_codec_setup_stream(codec, |
| 1292 | mout->extra_out_nid[i], |
| 1293 | stream_tag, 0, format); |
| 1294 | |
| 1295 | /* surrounds */ |
| 1296 | for (i = 1; i < mout->num_dacs; i++) { |
| 1297 | if (chs >= (i + 1) * 2) /* independent out */ |
| 1298 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1299 | i * 2, format); |
| 1300 | else /* copy front */ |
| 1301 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1302 | 0, format); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1307 | struct hda_codec *codec, |
| 1308 | unsigned int stream_tag, |
| 1309 | unsigned int format, |
| 1310 | struct snd_pcm_substream *substream) |
| 1311 | { |
| 1312 | struct via_spec *spec = codec->spec; |
| 1313 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1314 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1315 | |
| 1316 | if (substream->number == 0) |
| 1317 | playback_multi_pcm_prep_0(codec, stream_tag, format, |
| 1318 | substream); |
| 1319 | else { |
| 1320 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1321 | spec->hp_independent_mode) |
| 1322 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1323 | stream_tag, 0, format); |
| 1324 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1325 | vt1708_start_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1330 | struct hda_codec *codec, |
| 1331 | struct snd_pcm_substream *substream) |
| 1332 | { |
| 1333 | struct via_spec *spec = codec->spec; |
| 1334 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1335 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1336 | int i; |
| 1337 | |
| 1338 | if (substream->number == 0) { |
| 1339 | for (i = 0; i < mout->num_dacs; i++) |
| 1340 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); |
| 1341 | |
| 1342 | if (mout->hp_nid && !spec->hp_independent_mode) |
| 1343 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1344 | 0, 0, 0); |
| 1345 | |
| 1346 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1347 | if (mout->extra_out_nid[i]) |
| 1348 | snd_hda_codec_setup_stream(codec, |
| 1349 | mout->extra_out_nid[i], |
| 1350 | 0, 0, 0); |
| 1351 | mutex_lock(&codec->spdif_mutex); |
| 1352 | if (mout->dig_out_nid && |
| 1353 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { |
| 1354 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1355 | 0, 0, 0); |
| 1356 | mout->dig_out_used = 0; |
| 1357 | } |
| 1358 | mutex_unlock(&codec->spdif_mutex); |
| 1359 | } else { |
| 1360 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1361 | spec->hp_independent_mode) |
| 1362 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1363 | 0, 0, 0); |
| 1364 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1365 | vt1708_stop_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1366 | return 0; |
| 1367 | } |
| 1368 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1369 | /* |
| 1370 | * Digital out |
| 1371 | */ |
| 1372 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1373 | struct hda_codec *codec, |
| 1374 | struct snd_pcm_substream *substream) |
| 1375 | { |
| 1376 | struct via_spec *spec = codec->spec; |
| 1377 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 1378 | } |
| 1379 | |
| 1380 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1381 | struct hda_codec *codec, |
| 1382 | struct snd_pcm_substream *substream) |
| 1383 | { |
| 1384 | struct via_spec *spec = codec->spec; |
| 1385 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 1386 | } |
| 1387 | |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1388 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1389 | struct hda_codec *codec, |
| 1390 | unsigned int stream_tag, |
| 1391 | unsigned int format, |
| 1392 | struct snd_pcm_substream *substream) |
| 1393 | { |
| 1394 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1395 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 1396 | stream_tag, format, substream); |
| 1397 | } |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1398 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1399 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1400 | struct hda_codec *codec, |
| 1401 | struct snd_pcm_substream *substream) |
| 1402 | { |
| 1403 | struct via_spec *spec = codec->spec; |
| 1404 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1405 | return 0; |
| 1406 | } |
| 1407 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1408 | /* |
| 1409 | * Analog capture |
| 1410 | */ |
| 1411 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1412 | struct hda_codec *codec, |
| 1413 | unsigned int stream_tag, |
| 1414 | unsigned int format, |
| 1415 | struct snd_pcm_substream *substream) |
| 1416 | { |
| 1417 | struct via_spec *spec = codec->spec; |
| 1418 | |
| 1419 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 1420 | stream_tag, 0, format); |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
| 1424 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1425 | struct hda_codec *codec, |
| 1426 | struct snd_pcm_substream *substream) |
| 1427 | { |
| 1428 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1429 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1430 | return 0; |
| 1431 | } |
| 1432 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1433 | static const struct hda_pcm_stream via_pcm_analog_playback = { |
| 1434 | .substreams = 2, /* will be changed in via_build_pcms() */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1435 | .channels_min = 2, |
| 1436 | .channels_max = 8, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1437 | /* NID is set in via_build_pcms */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1438 | .ops = { |
| 1439 | .open = via_playback_pcm_open, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1440 | .close = via_playback_pcm_close, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1441 | .prepare = via_playback_multi_pcm_prepare, |
| 1442 | .cleanup = via_playback_multi_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1443 | }, |
| 1444 | }; |
| 1445 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1446 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1447 | .substreams = 2, /* will be changed in via_build_pcms() */ |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1448 | .channels_min = 2, |
| 1449 | .channels_max = 8, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1450 | /* NID is set in via_build_pcms */ |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1451 | /* We got noisy outputs on the right channel on VT1708 when |
| 1452 | * 24bit samples are used. Until any workaround is found, |
| 1453 | * disable the 24bit format, so far. |
| 1454 | */ |
| 1455 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1456 | .ops = { |
| 1457 | .open = via_playback_pcm_open, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1458 | .close = via_playback_pcm_close, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1459 | .prepare = via_playback_multi_pcm_prepare, |
| 1460 | .cleanup = via_playback_multi_pcm_cleanup |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1461 | }, |
| 1462 | }; |
| 1463 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1464 | static const struct hda_pcm_stream via_pcm_analog_capture = { |
| 1465 | .substreams = 2, /* will be changed in via_build_pcms() */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1466 | .channels_min = 2, |
| 1467 | .channels_max = 2, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1468 | /* NID is set in via_build_pcms */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1469 | .ops = { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1470 | .open = via_playback_pcm_open, |
| 1471 | .close = via_playback_pcm_close, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1472 | .prepare = via_capture_pcm_prepare, |
| 1473 | .cleanup = via_capture_pcm_cleanup |
| 1474 | }, |
| 1475 | }; |
| 1476 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1477 | static const struct hda_pcm_stream via_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1478 | .substreams = 1, |
| 1479 | .channels_min = 2, |
| 1480 | .channels_max = 2, |
| 1481 | /* NID is set in via_build_pcms */ |
| 1482 | .ops = { |
| 1483 | .open = via_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 1484 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1485 | .prepare = via_dig_playback_pcm_prepare, |
| 1486 | .cleanup = via_dig_playback_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1487 | }, |
| 1488 | }; |
| 1489 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1490 | static const struct hda_pcm_stream via_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1491 | .substreams = 1, |
| 1492 | .channels_min = 2, |
| 1493 | .channels_max = 2, |
| 1494 | }; |
| 1495 | |
| 1496 | static int via_build_controls(struct hda_codec *codec) |
| 1497 | { |
| 1498 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1499 | struct snd_kcontrol *kctl; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1500 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1501 | int err, i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1502 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 1503 | if (spec->set_widgets_power_state) |
| 1504 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) |
| 1505 | return -ENOMEM; |
| 1506 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1507 | for (i = 0; i < spec->num_mixers; i++) { |
| 1508 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1509 | if (err < 0) |
| 1510 | return err; |
| 1511 | } |
| 1512 | |
| 1513 | if (spec->multiout.dig_out_nid) { |
| 1514 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1515 | spec->multiout.dig_out_nid, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1516 | spec->multiout.dig_out_nid); |
| 1517 | if (err < 0) |
| 1518 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1519 | err = snd_hda_create_spdif_share_sw(codec, |
| 1520 | &spec->multiout); |
| 1521 | if (err < 0) |
| 1522 | return err; |
| 1523 | spec->multiout.share_spdif = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1524 | } |
| 1525 | if (spec->dig_in_nid) { |
| 1526 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1527 | if (err < 0) |
| 1528 | return err; |
| 1529 | } |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1530 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1531 | /* assign Capture Source enums to NID */ |
| 1532 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1533 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 1534 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1535 | if (err < 0) |
| 1536 | return err; |
| 1537 | } |
| 1538 | |
| 1539 | /* other nid->control mapping */ |
| 1540 | for (i = 0; i < spec->num_mixers; i++) { |
| 1541 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1542 | if (knew->iface != NID_MAPPING) |
| 1543 | continue; |
| 1544 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1545 | if (kctl == NULL) |
| 1546 | continue; |
| 1547 | err = snd_hda_add_nid(codec, kctl, 0, |
| 1548 | knew->subdevice); |
| 1549 | } |
| 1550 | } |
| 1551 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1552 | /* init power states */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1553 | set_widgets_power_state(codec); |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1554 | analog_low_current_mode(codec, 1); |
| 1555 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1556 | via_free_kctls(codec); /* no longer needed */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1557 | return 0; |
| 1558 | } |
| 1559 | |
| 1560 | static int via_build_pcms(struct hda_codec *codec) |
| 1561 | { |
| 1562 | struct via_spec *spec = codec->spec; |
| 1563 | struct hda_pcm *info = spec->pcm_rec; |
| 1564 | |
| 1565 | codec->num_pcms = 1; |
| 1566 | codec->pcm_info = info; |
| 1567 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1568 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 1569 | "%s Analog", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1570 | info->name = spec->stream_name_analog; |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1571 | |
| 1572 | if (!spec->stream_analog_playback) |
| 1573 | spec->stream_analog_playback = &via_pcm_analog_playback; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1574 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1575 | *spec->stream_analog_playback; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1576 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1577 | spec->multiout.dac_nids[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1578 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 1579 | spec->multiout.max_channels; |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1580 | if (!spec->multiout.hp_nid) |
| 1581 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1; |
| 1582 | |
| 1583 | if (!spec->stream_analog_capture) |
| 1584 | spec->stream_analog_capture = &via_pcm_analog_capture; |
| 1585 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 1586 | *spec->stream_analog_capture; |
| 1587 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 1588 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 1589 | spec->num_adc_nids; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1590 | |
| 1591 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 1592 | codec->num_pcms++; |
| 1593 | info++; |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1594 | snprintf(spec->stream_name_digital, |
| 1595 | sizeof(spec->stream_name_digital), |
| 1596 | "%s Digital", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1597 | info->name = spec->stream_name_digital; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 1598 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1599 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1600 | if (!spec->stream_digital_playback) |
| 1601 | spec->stream_digital_playback = |
| 1602 | &via_pcm_digital_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1603 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1604 | *spec->stream_digital_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1605 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1606 | spec->multiout.dig_out_nid; |
| 1607 | } |
| 1608 | if (spec->dig_in_nid) { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1609 | if (!spec->stream_digital_capture) |
| 1610 | spec->stream_digital_capture = |
| 1611 | &via_pcm_digital_capture; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1612 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame^] | 1613 | *spec->stream_digital_capture; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1614 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 1615 | spec->dig_in_nid; |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | static void via_free(struct hda_codec *codec) |
| 1623 | { |
| 1624 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1625 | |
| 1626 | if (!spec) |
| 1627 | return; |
| 1628 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1629 | via_free_kctls(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1630 | vt1708_stop_hp_work(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1631 | kfree(codec->spec); |
| 1632 | } |
| 1633 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1634 | /* mute/unmute outputs */ |
| 1635 | static void toggle_output_mutes(struct hda_codec *codec, int num_pins, |
| 1636 | hda_nid_t *pins, bool mute) |
| 1637 | { |
| 1638 | int i; |
| 1639 | for (i = 0; i < num_pins; i++) |
| 1640 | snd_hda_codec_write(codec, pins[i], 0, |
| 1641 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1642 | mute ? 0 : PIN_OUT); |
| 1643 | } |
| 1644 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1645 | /* mute internal speaker if HP is plugged */ |
| 1646 | static void via_hp_automute(struct hda_codec *codec) |
| 1647 | { |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1648 | unsigned int present = 0; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1649 | struct via_spec *spec = codec->spec; |
| 1650 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1651 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1652 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1653 | if (!spec->hp_independent_mode) |
| 1654 | toggle_output_mutes(codec, spec->autocfg.line_outs, |
| 1655 | spec->autocfg.line_out_pins, |
| 1656 | present); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1657 | } |
| 1658 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1659 | /* mute mono out if HP or Line out is plugged */ |
| 1660 | static void via_mono_automute(struct hda_codec *codec) |
| 1661 | { |
| 1662 | unsigned int hp_present, lineout_present; |
| 1663 | struct via_spec *spec = codec->spec; |
| 1664 | |
| 1665 | if (spec->codec_type != VT1716S) |
| 1666 | return; |
| 1667 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1668 | lineout_present = snd_hda_jack_detect(codec, |
| 1669 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1670 | |
| 1671 | /* Mute Mono Out if Line Out is plugged */ |
| 1672 | if (lineout_present) { |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1673 | snd_hda_codec_write(codec, 0x2A, 0, |
| 1674 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1675 | lineout_present ? 0 : PIN_OUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1676 | return; |
| 1677 | } |
| 1678 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1679 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1680 | |
| 1681 | if (!spec->hp_independent_mode) |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1682 | snd_hda_codec_write(codec, 0x2A, 0, |
| 1683 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1684 | hp_present ? 0 : PIN_OUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1685 | } |
| 1686 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1687 | static void via_gpio_control(struct hda_codec *codec) |
| 1688 | { |
| 1689 | unsigned int gpio_data; |
| 1690 | unsigned int vol_counter; |
| 1691 | unsigned int vol; |
| 1692 | unsigned int master_vol; |
| 1693 | |
| 1694 | struct via_spec *spec = codec->spec; |
| 1695 | |
| 1696 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, |
| 1697 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; |
| 1698 | |
| 1699 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, |
| 1700 | 0xF84, 0) & 0x3F0000) >> 16; |
| 1701 | |
| 1702 | vol = vol_counter & 0x1F; |
| 1703 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, |
| 1704 | AC_VERB_GET_AMP_GAIN_MUTE, |
| 1705 | AC_AMP_GET_INPUT); |
| 1706 | |
| 1707 | if (gpio_data == 0x02) { |
| 1708 | /* unmute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1709 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1710 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1711 | PIN_OUT); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1712 | if (vol_counter & 0x20) { |
| 1713 | /* decrease volume */ |
| 1714 | if (vol > master_vol) |
| 1715 | vol = master_vol; |
| 1716 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, |
| 1717 | 0, HDA_AMP_VOLMASK, |
| 1718 | master_vol-vol); |
| 1719 | } else { |
| 1720 | /* increase volume */ |
| 1721 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, |
| 1722 | HDA_AMP_VOLMASK, |
| 1723 | ((master_vol+vol) > 0x2A) ? 0x2A : |
| 1724 | (master_vol+vol)); |
| 1725 | } |
| 1726 | } else if (!(gpio_data & 0x02)) { |
| 1727 | /* mute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1728 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1729 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1730 | 0); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1734 | /* mute Internal-Speaker if HP is plugged */ |
| 1735 | static void via_speaker_automute(struct hda_codec *codec) |
| 1736 | { |
| 1737 | unsigned int hp_present; |
| 1738 | struct via_spec *spec = codec->spec; |
| 1739 | |
Lydia Wang | 27439ce | 2011-03-24 12:40:10 +0800 | [diff] [blame] | 1740 | if (!VT2002P_COMPATIBLE(spec)) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1741 | return; |
| 1742 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1743 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1744 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1745 | if (!spec->hp_independent_mode) |
| 1746 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1747 | spec->autocfg.speaker_pins, |
| 1748 | hp_present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | /* mute line-out and internal speaker if HP is plugged */ |
| 1752 | static void via_hp_bind_automute(struct hda_codec *codec) |
| 1753 | { |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1754 | int present; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1755 | struct via_spec *spec = codec->spec; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1756 | |
| 1757 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) |
| 1758 | return; |
| 1759 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1760 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
| 1761 | if (!spec->hp_independent_mode) |
| 1762 | toggle_output_mutes(codec, spec->autocfg.line_outs, |
| 1763 | spec->autocfg.line_out_pins, |
| 1764 | present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1765 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1766 | if (!present) |
| 1767 | present = snd_hda_jack_detect(codec, |
| 1768 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1769 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1770 | /* Speakers */ |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1771 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1772 | spec->autocfg.speaker_pins, |
| 1773 | present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1777 | /* unsolicited event for jack sensing */ |
| 1778 | static void via_unsol_event(struct hda_codec *codec, |
| 1779 | unsigned int res) |
| 1780 | { |
| 1781 | res >>= 26; |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1782 | |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 1783 | if (res & VIA_JACK_EVENT) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1784 | set_widgets_power_state(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1785 | |
| 1786 | res &= ~VIA_JACK_EVENT; |
| 1787 | |
| 1788 | if (res == VIA_HP_EVENT) |
| 1789 | via_hp_automute(codec); |
| 1790 | else if (res == VIA_GPIO_EVENT) |
| 1791 | via_gpio_control(codec); |
| 1792 | else if (res == VIA_MONO_EVENT) |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1793 | via_mono_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1794 | else if (res == VIA_SPEAKER_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1795 | via_speaker_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1796 | else if (res == VIA_BIND_HP_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1797 | via_hp_bind_automute(codec); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1798 | } |
| 1799 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1800 | static int via_init(struct hda_codec *codec) |
| 1801 | { |
| 1802 | struct via_spec *spec = codec->spec; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1803 | int i; |
| 1804 | for (i = 0; i < spec->num_iverbs; i++) |
| 1805 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 1806 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1807 | /* Lydia Add for EAPD enable */ |
| 1808 | if (!spec->dig_in_nid) { /* No Digital In connection */ |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 1809 | if (spec->dig_in_pin) { |
| 1810 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1811 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 1812 | PIN_OUT); |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 1813 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1814 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
| 1815 | } |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 1816 | } else /* enable SPDIF-input pin */ |
| 1817 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, |
| 1818 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1819 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1820 | /* assign slave outs */ |
| 1821 | if (spec->slave_dig_outs[0]) |
| 1822 | codec->slave_dig_outs = spec->slave_dig_outs; |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1823 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1824 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1825 | } |
| 1826 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1827 | #ifdef SND_HDA_NEEDS_RESUME |
| 1828 | static int via_suspend(struct hda_codec *codec, pm_message_t state) |
| 1829 | { |
| 1830 | struct via_spec *spec = codec->spec; |
| 1831 | vt1708_stop_hp_work(spec); |
| 1832 | return 0; |
| 1833 | } |
| 1834 | #endif |
| 1835 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1836 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1837 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 1838 | { |
| 1839 | struct via_spec *spec = codec->spec; |
| 1840 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 1841 | } |
| 1842 | #endif |
| 1843 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1844 | /* |
| 1845 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1846 | static const struct hda_codec_ops via_patch_ops = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1847 | .build_controls = via_build_controls, |
| 1848 | .build_pcms = via_build_pcms, |
| 1849 | .init = via_init, |
| 1850 | .free = via_free, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1851 | #ifdef SND_HDA_NEEDS_RESUME |
| 1852 | .suspend = via_suspend, |
| 1853 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1854 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1855 | .check_power_status = via_check_power_status, |
| 1856 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1857 | }; |
| 1858 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1859 | 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] | 1860 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1861 | struct via_spec *spec = codec->spec; |
| 1862 | int i; |
| 1863 | |
| 1864 | for (i = 0; i < spec->multiout.num_dacs; i++) { |
| 1865 | if (spec->multiout.dac_nids[i] == dac) |
| 1866 | return false; |
| 1867 | } |
| 1868 | if (spec->multiout.hp_nid == dac) |
| 1869 | return false; |
| 1870 | return true; |
| 1871 | } |
| 1872 | |
| 1873 | static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
| 1874 | hda_nid_t target_dac, struct nid_path *path, |
| 1875 | int depth, int wid_type) |
| 1876 | { |
| 1877 | hda_nid_t conn[8]; |
| 1878 | int i, nums; |
| 1879 | |
| 1880 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); |
| 1881 | for (i = 0; i < nums; i++) { |
| 1882 | if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) |
| 1883 | continue; |
| 1884 | if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { |
| 1885 | path->path[depth] = conn[i]; |
| 1886 | path->idx[depth] = i; |
| 1887 | path->depth = ++depth; |
| 1888 | return true; |
| 1889 | } |
| 1890 | } |
| 1891 | if (depth > 4) |
| 1892 | return false; |
| 1893 | for (i = 0; i < nums; i++) { |
| 1894 | unsigned int type; |
| 1895 | type = get_wcaps_type(get_wcaps(codec, conn[i])); |
| 1896 | if (type == AC_WID_AUD_OUT || |
| 1897 | (wid_type != -1 && type != wid_type)) |
| 1898 | continue; |
| 1899 | if (parse_output_path(codec, conn[i], target_dac, |
| 1900 | path, depth + 1, AC_WID_AUD_SEL)) { |
| 1901 | path->path[depth] = conn[i]; |
| 1902 | path->idx[depth] = i; |
| 1903 | return true; |
| 1904 | } |
| 1905 | } |
| 1906 | return false; |
| 1907 | } |
| 1908 | |
| 1909 | static int via_auto_fill_dac_nids(struct hda_codec *codec) |
| 1910 | { |
| 1911 | struct via_spec *spec = codec->spec; |
| 1912 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1913 | int i; |
| 1914 | hda_nid_t nid; |
| 1915 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1916 | spec->multiout.dac_nids = spec->private_dac_nids; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1917 | spec->multiout.num_dacs = cfg->line_outs; |
| 1918 | for (i = 0; i < cfg->line_outs; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1919 | nid = cfg->line_out_pins[i]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1920 | if (!nid) |
| 1921 | continue; |
| 1922 | if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1)) |
| 1923 | spec->private_dac_nids[i] = |
| 1924 | spec->out_path[i].path[spec->out_path[i].depth - 1]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1925 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1926 | return 0; |
| 1927 | } |
| 1928 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1929 | static int create_ch_ctls(struct hda_codec *codec, const char *pfx, |
| 1930 | hda_nid_t pin, hda_nid_t dac, int chs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1931 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1932 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1933 | char name[32]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1934 | hda_nid_t nid; |
| 1935 | int err; |
| 1936 | |
| 1937 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
| 1938 | nid = dac; |
| 1939 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
| 1940 | nid = pin; |
| 1941 | else |
| 1942 | nid = 0; |
| 1943 | if (nid) { |
| 1944 | sprintf(name, "%s Playback Volume", pfx); |
| 1945 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 1946 | HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT)); |
| 1947 | if (err < 0) |
| 1948 | return err; |
| 1949 | } |
| 1950 | |
| 1951 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 1952 | nid = dac; |
| 1953 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 1954 | nid = pin; |
| 1955 | else |
| 1956 | nid = 0; |
| 1957 | if (nid) { |
| 1958 | sprintf(name, "%s Playback Switch", pfx); |
| 1959 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 1960 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
| 1961 | if (err < 0) |
| 1962 | return err; |
| 1963 | } |
| 1964 | return 0; |
| 1965 | } |
| 1966 | |
| 1967 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
| 1968 | hda_nid_t nid); |
| 1969 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1970 | static void mangle_smart51(struct hda_codec *codec) |
| 1971 | { |
| 1972 | struct via_spec *spec = codec->spec; |
| 1973 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1974 | int i; |
| 1975 | |
| 1976 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1977 | if (!is_smart51_pins(codec, cfg->inputs[i].pin)) |
| 1978 | continue; |
| 1979 | spec->can_smart51 = 1; |
| 1980 | cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; |
| 1981 | if (cfg->line_outs == 3) |
| 1982 | break; |
| 1983 | } |
| 1984 | } |
| 1985 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1986 | /* add playback controls from the parsed DAC table */ |
| 1987 | static int via_auto_create_multi_out_ctls(struct hda_codec *codec) |
| 1988 | { |
| 1989 | struct via_spec *spec = codec->spec; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1990 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1991 | static const char * const chname[4] = { |
| 1992 | "Front", "Surround", "C/LFE", "Side" |
| 1993 | }; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1994 | int i, idx, err; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1995 | int old_line_outs; |
| 1996 | |
| 1997 | /* check smart51 */ |
| 1998 | old_line_outs = cfg->line_outs; |
| 1999 | if (cfg->line_outs == 1) |
| 2000 | mangle_smart51(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2001 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2002 | for (i = 0; i < cfg->line_outs; i++) { |
| 2003 | hda_nid_t pin, dac; |
| 2004 | pin = cfg->line_out_pins[i]; |
| 2005 | dac = spec->multiout.dac_nids[i]; |
| 2006 | if (!pin || !dac) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2007 | continue; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2008 | if (i == AUTO_SEQ_CENLFE) { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2009 | err = create_ch_ctls(codec, "Center", pin, dac, 1); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2010 | if (err < 0) |
| 2011 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2012 | err = create_ch_ctls(codec, "LFE", pin, dac, 2); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2013 | if (err < 0) |
| 2014 | return err; |
| 2015 | } else { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2016 | err = create_ch_ctls(codec, chname[i], pin, dac, 3); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2017 | if (err < 0) |
| 2018 | return err; |
| 2019 | } |
| 2020 | } |
| 2021 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2022 | idx = get_connection_index(codec, spec->aa_mix_nid, |
| 2023 | spec->multiout.dac_nids[0]); |
| 2024 | if (idx >= 0) { |
| 2025 | /* add control to mixer */ |
| 2026 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2027 | "PCM Playback Volume", |
| 2028 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 2029 | idx, HDA_INPUT)); |
| 2030 | if (err < 0) |
| 2031 | return err; |
| 2032 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2033 | "PCM Playback Switch", |
| 2034 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 2035 | idx, HDA_INPUT)); |
| 2036 | if (err < 0) |
| 2037 | return err; |
| 2038 | } |
| 2039 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2040 | cfg->line_outs = old_line_outs; |
| 2041 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2042 | return 0; |
| 2043 | } |
| 2044 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2045 | static void create_hp_imux(struct via_spec *spec) |
| 2046 | { |
| 2047 | int i; |
| 2048 | struct hda_input_mux *imux = &spec->private_imux[1]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 2049 | static const char * const texts[] = { "OFF", "ON", NULL}; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2050 | |
| 2051 | /* for hp mode select */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2052 | for (i = 0; texts[i]; i++) |
| 2053 | snd_hda_add_imux_item(imux, texts[i], i, NULL); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2054 | |
| 2055 | spec->hp_mux = &spec->private_imux[1]; |
| 2056 | } |
| 2057 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2058 | 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] | 2059 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2060 | struct via_spec *spec = codec->spec; |
| 2061 | hda_nid_t dac = 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2062 | int err; |
| 2063 | |
| 2064 | if (!pin) |
| 2065 | return 0; |
| 2066 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2067 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
| 2068 | &spec->hp_dep_path, 0, -1)) |
| 2069 | return 0; |
| 2070 | if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { |
| 2071 | dac = spec->hp_path.path[spec->hp_path.depth - 1]; |
| 2072 | spec->multiout.hp_nid = dac; |
| 2073 | spec->hp_independent_mode_index = |
| 2074 | spec->hp_path.idx[spec->hp_path.depth - 1]; |
| 2075 | create_hp_imux(spec); |
| 2076 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2077 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2078 | err = create_ch_ctls(codec, "Headphone", pin, dac, 3); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2079 | if (err < 0) |
| 2080 | return err; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2081 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2082 | return 0; |
| 2083 | } |
| 2084 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2085 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
| 2086 | hda_nid_t nid) |
| 2087 | { |
| 2088 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; |
| 2089 | int i, nums; |
| 2090 | |
| 2091 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); |
| 2092 | for (i = 0; i < nums; i++) |
| 2093 | if (conn[i] == nid) |
| 2094 | return i; |
| 2095 | return -1; |
| 2096 | } |
| 2097 | |
| 2098 | /* look for ADCs */ |
| 2099 | static int via_fill_adcs(struct hda_codec *codec) |
| 2100 | { |
| 2101 | struct via_spec *spec = codec->spec; |
| 2102 | hda_nid_t nid = codec->start_nid; |
| 2103 | int i; |
| 2104 | |
| 2105 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2106 | unsigned int wcaps = get_wcaps(codec, nid); |
| 2107 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 2108 | continue; |
| 2109 | if (wcaps & AC_WCAP_DIGITAL) |
| 2110 | continue; |
| 2111 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 2112 | continue; |
| 2113 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) |
| 2114 | return -ENOMEM; |
| 2115 | spec->adc_nids[spec->num_adc_nids++] = nid; |
| 2116 | } |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static int get_mux_nids(struct hda_codec *codec); |
| 2121 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2122 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2123 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec, |
| 2124 | const struct auto_pin_cfg *cfg) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2125 | { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2126 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2127 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2128 | int i, err, idx, idx2, type, type_idx = 0; |
| 2129 | hda_nid_t cap_nid; |
| 2130 | hda_nid_t pin_idxs[8]; |
| 2131 | int num_idxs; |
| 2132 | |
| 2133 | err = via_fill_adcs(codec); |
| 2134 | if (err < 0) |
| 2135 | return err; |
| 2136 | err = get_mux_nids(codec); |
| 2137 | if (err < 0) |
| 2138 | return err; |
| 2139 | cap_nid = spec->mux_nids[0]; |
| 2140 | |
| 2141 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, |
| 2142 | ARRAY_SIZE(pin_idxs)); |
| 2143 | if (num_idxs <= 0) |
| 2144 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2145 | |
| 2146 | /* for internal loopback recording select */ |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2147 | for (idx = 0; idx < num_idxs; idx++) { |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2148 | if (pin_idxs[idx] == spec->aa_mix_nid) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2149 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2150 | break; |
| 2151 | } |
| 2152 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2153 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2154 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2155 | const char *label; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2156 | type = cfg->inputs[i].type; |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2157 | for (idx = 0; idx < num_idxs; idx++) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2158 | if (pin_idxs[idx] == cfg->inputs[i].pin) |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2159 | break; |
| 2160 | if (idx >= num_idxs) |
| 2161 | continue; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2162 | if (i > 0 && type == cfg->inputs[i - 1].type) |
| 2163 | type_idx++; |
| 2164 | else |
| 2165 | type_idx = 0; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2166 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2167 | idx2 = get_connection_index(codec, spec->aa_mix_nid, |
| 2168 | pin_idxs[idx]); |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2169 | if (idx2 >= 0) |
Lydia Wang | 1692228 | 2011-03-22 16:24:10 +0800 | [diff] [blame] | 2170 | err = via_new_analog_input(spec, label, type_idx, |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2171 | idx2, spec->aa_mix_nid); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2172 | if (err < 0) |
| 2173 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2174 | snd_hda_add_imux_item(imux, label, idx, NULL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2175 | } |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2179 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2180 | static const struct hda_amp_list vt1708_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2181 | { 0x17, HDA_INPUT, 1 }, |
| 2182 | { 0x17, HDA_INPUT, 2 }, |
| 2183 | { 0x17, HDA_INPUT, 3 }, |
| 2184 | { 0x17, HDA_INPUT, 4 }, |
| 2185 | { } /* end */ |
| 2186 | }; |
| 2187 | #endif |
| 2188 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2189 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 2190 | { |
| 2191 | unsigned int def_conf; |
| 2192 | unsigned char seqassoc; |
| 2193 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 2194 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2195 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 2196 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 2197 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 2198 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 2199 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 2200 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | return; |
| 2204 | } |
| 2205 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2206 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2207 | struct snd_ctl_elem_value *ucontrol) |
| 2208 | { |
| 2209 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2210 | struct via_spec *spec = codec->spec; |
| 2211 | |
| 2212 | if (spec->codec_type != VT1708) |
| 2213 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2214 | spec->vt1708_jack_detect = |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2215 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2216 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2217 | return 0; |
| 2218 | } |
| 2219 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2220 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2221 | struct snd_ctl_elem_value *ucontrol) |
| 2222 | { |
| 2223 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2224 | struct via_spec *spec = codec->spec; |
| 2225 | int change; |
| 2226 | |
| 2227 | if (spec->codec_type != VT1708) |
| 2228 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2229 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2230 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2231 | == !spec->vt1708_jack_detect; |
| 2232 | if (spec->vt1708_jack_detect) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2233 | mute_aa_path(codec, 1); |
| 2234 | notify_aa_path_ctls(codec); |
| 2235 | } |
| 2236 | return change; |
| 2237 | } |
| 2238 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2239 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
| 2240 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2241 | .name = "Jack Detect", |
| 2242 | .count = 1, |
| 2243 | .info = snd_ctl_boolean_mono_info, |
| 2244 | .get = vt1708_jack_detect_get, |
| 2245 | .put = vt1708_jack_detect_put, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2246 | }; |
| 2247 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2248 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
| 2249 | { |
| 2250 | struct via_spec *spec = codec->spec; |
| 2251 | int err; |
| 2252 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2253 | /* Add HP and CD pin config connect bit re-config action */ |
| 2254 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 2255 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 2256 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2257 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2258 | if (err < 0) |
| 2259 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2260 | err = via_auto_fill_dac_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2261 | if (err < 0) |
| 2262 | return err; |
| 2263 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2264 | return 0; /* can't find valid BIOS pin config */ |
| 2265 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2266 | err = via_auto_create_multi_out_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2267 | if (err < 0) |
| 2268 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2269 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2270 | if (err < 0) |
| 2271 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2272 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2273 | if (err < 0) |
| 2274 | return err; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2275 | /* add jack detect on/off control */ |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2276 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
| 2277 | return -ENOMEM; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2278 | |
| 2279 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2280 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2281 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2282 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2283 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2284 | if (spec->autocfg.dig_in_pin) |
| 2285 | spec->dig_in_nid = VT1708_DIGIN_NID; |
| 2286 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2287 | if (spec->kctls.list) |
| 2288 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2289 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2290 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2291 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2292 | spec->input_mux = &spec->private_imux[0]; |
| 2293 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2294 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2295 | via_hp_build(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2296 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2297 | err = via_smart51_build(codec); |
| 2298 | if (err < 0) |
| 2299 | return err; |
| 2300 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2301 | return 1; |
| 2302 | } |
| 2303 | |
| 2304 | /* init callback for auto-configuration model -- overriding the default init */ |
| 2305 | static int via_auto_init(struct hda_codec *codec) |
| 2306 | { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2307 | struct via_spec *spec = codec->spec; |
| 2308 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2309 | via_init(codec); |
| 2310 | via_auto_init_multi_out(codec); |
| 2311 | via_auto_init_hp_out(codec); |
| 2312 | via_auto_init_analog_input(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 2313 | |
| 2314 | if (VT2002P_COMPATIBLE(spec)) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2315 | via_hp_bind_automute(codec); |
| 2316 | } else { |
| 2317 | via_hp_automute(codec); |
| 2318 | via_speaker_automute(codec); |
| 2319 | } |
| 2320 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2321 | return 0; |
| 2322 | } |
| 2323 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2324 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
| 2325 | { |
| 2326 | struct via_spec *spec = container_of(work, struct via_spec, |
| 2327 | vt1708_hp_work.work); |
| 2328 | if (spec->codec_type != VT1708) |
| 2329 | return; |
| 2330 | /* if jack state toggled */ |
| 2331 | if (spec->vt1708_hp_present |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2332 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2333 | spec->vt1708_hp_present ^= 1; |
| 2334 | via_hp_automute(spec->codec); |
| 2335 | } |
| 2336 | vt1708_start_hp_work(spec); |
| 2337 | } |
| 2338 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2339 | static int get_mux_nids(struct hda_codec *codec) |
| 2340 | { |
| 2341 | struct via_spec *spec = codec->spec; |
| 2342 | hda_nid_t nid, conn[8]; |
| 2343 | unsigned int type; |
| 2344 | int i, n; |
| 2345 | |
| 2346 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2347 | nid = spec->adc_nids[i]; |
| 2348 | while (nid) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2349 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2350 | if (type == AC_WID_PIN) |
| 2351 | break; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2352 | n = snd_hda_get_connections(codec, nid, conn, |
| 2353 | ARRAY_SIZE(conn)); |
| 2354 | if (n <= 0) |
| 2355 | break; |
| 2356 | if (n > 1) { |
| 2357 | spec->mux_nids[i] = nid; |
| 2358 | break; |
| 2359 | } |
| 2360 | nid = conn[0]; |
| 2361 | } |
| 2362 | } |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2363 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2364 | } |
| 2365 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2366 | static int patch_vt1708(struct hda_codec *codec) |
| 2367 | { |
| 2368 | struct via_spec *spec; |
| 2369 | int err; |
| 2370 | |
| 2371 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2372 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2373 | if (spec == NULL) |
| 2374 | return -ENOMEM; |
| 2375 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2376 | spec->aa_mix_nid = 0x17; |
| 2377 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2378 | /* automatic parse from the BIOS config */ |
| 2379 | err = vt1708_parse_auto_config(codec); |
| 2380 | if (err < 0) { |
| 2381 | via_free(codec); |
| 2382 | return err; |
| 2383 | } else if (!err) { |
| 2384 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 2385 | "from BIOS. Using genenic mode...\n"); |
| 2386 | } |
| 2387 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2388 | |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 2389 | /* disable 32bit format on VT1708 */ |
| 2390 | if (codec->vendor_id == 0x11061708) |
| 2391 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2392 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2393 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2394 | spec->mixers[spec->num_mixers] = vt1708_capture_mixer; |
| 2395 | spec->num_mixers++; |
| 2396 | } |
| 2397 | |
| 2398 | codec->patch_ops = via_patch_ops; |
| 2399 | |
| 2400 | codec->patch_ops.init = via_auto_init; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2401 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2402 | spec->loopback.amplist = vt1708_loopbacks; |
| 2403 | #endif |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2404 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2405 | return 0; |
| 2406 | } |
| 2407 | |
| 2408 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2409 | static const struct snd_kcontrol_new vt1709_capture_mixer[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2410 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), |
| 2411 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), |
| 2412 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), |
| 2413 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), |
| 2414 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), |
| 2415 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), |
| 2416 | { |
| 2417 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2418 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2419 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2420 | */ |
| 2421 | /* .name = "Capture Source", */ |
| 2422 | .name = "Input Source", |
| 2423 | .count = 1, |
| 2424 | .info = via_mux_enum_info, |
| 2425 | .get = via_mux_enum_get, |
| 2426 | .put = via_mux_enum_put, |
| 2427 | }, |
| 2428 | { } /* end */ |
| 2429 | }; |
| 2430 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2431 | static const struct hda_verb vt1709_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2432 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2433 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2434 | { } |
| 2435 | }; |
| 2436 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2437 | /* |
| 2438 | * generic initialization of ADC, input mixers and output mixers |
| 2439 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2440 | static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2441 | /* |
| 2442 | * Unmute ADC0-2 and set the default input to mic-in |
| 2443 | */ |
| 2444 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2445 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2446 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2447 | |
| 2448 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2449 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2450 | * mixer widget |
| 2451 | */ |
| 2452 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2453 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2454 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2455 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2456 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2457 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2458 | |
| 2459 | /* |
| 2460 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2461 | */ |
| 2462 | /* set vol=0 to output mixers */ |
| 2463 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2464 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2465 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2466 | |
| 2467 | /* |
| 2468 | * Unmute PW3 and PW4 |
| 2469 | */ |
| 2470 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2471 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2472 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2473 | /* Set input of PW4 as MW0 */ |
| 2474 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2475 | /* PW9 Output enable */ |
| 2476 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2477 | { } |
| 2478 | }; |
| 2479 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2480 | static int vt1709_parse_auto_config(struct hda_codec *codec) |
| 2481 | { |
| 2482 | struct via_spec *spec = codec->spec; |
| 2483 | int err; |
| 2484 | |
| 2485 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2486 | if (err < 0) |
| 2487 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2488 | err = via_auto_fill_dac_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2489 | if (err < 0) |
| 2490 | return err; |
| 2491 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2492 | return 0; /* can't find valid BIOS pin config */ |
| 2493 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2494 | err = via_auto_create_multi_out_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2495 | if (err < 0) |
| 2496 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2497 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2498 | if (err < 0) |
| 2499 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2500 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2501 | if (err < 0) |
| 2502 | return err; |
| 2503 | |
| 2504 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2505 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2506 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2507 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2508 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2509 | if (spec->autocfg.dig_in_pin) |
| 2510 | spec->dig_in_nid = VT1709_DIGIN_NID; |
| 2511 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2512 | if (spec->kctls.list) |
| 2513 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2514 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2515 | spec->input_mux = &spec->private_imux[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2516 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2517 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2518 | via_hp_build(codec); |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2519 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2520 | err = via_smart51_build(codec); |
| 2521 | if (err < 0) |
| 2522 | return err; |
| 2523 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2524 | return 1; |
| 2525 | } |
| 2526 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2527 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2528 | static const struct hda_amp_list vt1709_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2529 | { 0x18, HDA_INPUT, 1 }, |
| 2530 | { 0x18, HDA_INPUT, 2 }, |
| 2531 | { 0x18, HDA_INPUT, 3 }, |
| 2532 | { 0x18, HDA_INPUT, 4 }, |
| 2533 | { } /* end */ |
| 2534 | }; |
| 2535 | #endif |
| 2536 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2537 | static int patch_vt1709_10ch(struct hda_codec *codec) |
| 2538 | { |
| 2539 | struct via_spec *spec; |
| 2540 | int err; |
| 2541 | |
| 2542 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2543 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2544 | if (spec == NULL) |
| 2545 | return -ENOMEM; |
| 2546 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2547 | spec->aa_mix_nid = 0x18; |
| 2548 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2549 | err = vt1709_parse_auto_config(codec); |
| 2550 | if (err < 0) { |
| 2551 | via_free(codec); |
| 2552 | return err; |
| 2553 | } else if (!err) { |
| 2554 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 2555 | "Using genenic mode...\n"); |
| 2556 | } |
| 2557 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2558 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
| 2559 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2560 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2561 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2562 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 2563 | spec->num_mixers++; |
| 2564 | } |
| 2565 | |
| 2566 | codec->patch_ops = via_patch_ops; |
| 2567 | |
| 2568 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2569 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2570 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2571 | spec->loopback.amplist = vt1709_loopbacks; |
| 2572 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2573 | |
| 2574 | return 0; |
| 2575 | } |
| 2576 | /* |
| 2577 | * generic initialization of ADC, input mixers and output mixers |
| 2578 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2579 | static const struct hda_verb vt1709_6ch_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2580 | /* |
| 2581 | * Unmute ADC0-2 and set the default input to mic-in |
| 2582 | */ |
| 2583 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2584 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2585 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2586 | |
| 2587 | |
| 2588 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2589 | * mixer widget |
| 2590 | */ |
| 2591 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2592 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2593 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2594 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2595 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2596 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2597 | |
| 2598 | /* |
| 2599 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2600 | */ |
| 2601 | /* set vol=0 to output mixers */ |
| 2602 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2603 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2604 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2605 | |
| 2606 | /* |
| 2607 | * Unmute PW3 and PW4 |
| 2608 | */ |
| 2609 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2610 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2611 | |
| 2612 | /* Set input of PW4 as MW0 */ |
| 2613 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2614 | /* PW9 Output enable */ |
| 2615 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2616 | { } |
| 2617 | }; |
| 2618 | |
| 2619 | static int patch_vt1709_6ch(struct hda_codec *codec) |
| 2620 | { |
| 2621 | struct via_spec *spec; |
| 2622 | int err; |
| 2623 | |
| 2624 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2625 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2626 | if (spec == NULL) |
| 2627 | return -ENOMEM; |
| 2628 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2629 | spec->aa_mix_nid = 0x18; |
| 2630 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2631 | err = vt1709_parse_auto_config(codec); |
| 2632 | if (err < 0) { |
| 2633 | via_free(codec); |
| 2634 | return err; |
| 2635 | } else if (!err) { |
| 2636 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 2637 | "Using genenic mode...\n"); |
| 2638 | } |
| 2639 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2640 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
| 2641 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2642 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2643 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2644 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 2645 | spec->num_mixers++; |
| 2646 | } |
| 2647 | |
| 2648 | codec->patch_ops = via_patch_ops; |
| 2649 | |
| 2650 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2651 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2652 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2653 | spec->loopback.amplist = vt1709_loopbacks; |
| 2654 | #endif |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2655 | return 0; |
| 2656 | } |
| 2657 | |
| 2658 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2659 | static const struct snd_kcontrol_new vt1708B_capture_mixer[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2660 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 2661 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 2662 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 2663 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 2664 | { |
| 2665 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2666 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2667 | * So call somewhat different.. |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2668 | */ |
| 2669 | /* .name = "Capture Source", */ |
| 2670 | .name = "Input Source", |
| 2671 | .count = 1, |
| 2672 | .info = via_mux_enum_info, |
| 2673 | .get = via_mux_enum_get, |
| 2674 | .put = via_mux_enum_put, |
| 2675 | }, |
| 2676 | { } /* end */ |
| 2677 | }; |
| 2678 | /* |
| 2679 | * generic initialization of ADC, input mixers and output mixers |
| 2680 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2681 | static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2682 | /* |
| 2683 | * Unmute ADC0-1 and set the default input to mic-in |
| 2684 | */ |
| 2685 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2686 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2687 | |
| 2688 | |
| 2689 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2690 | * mixer widget |
| 2691 | */ |
| 2692 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2693 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2694 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2695 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2696 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2697 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2698 | |
| 2699 | /* |
| 2700 | * Set up output mixers |
| 2701 | */ |
| 2702 | /* set vol=0 to output mixers */ |
| 2703 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2704 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2705 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2706 | |
| 2707 | /* Setup default input to PW4 */ |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2708 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2709 | /* PW9 Output enable */ |
| 2710 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2711 | /* PW10 Input enable */ |
| 2712 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 2713 | { } |
| 2714 | }; |
| 2715 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2716 | static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2717 | /* |
| 2718 | * Unmute ADC0-1 and set the default input to mic-in |
| 2719 | */ |
| 2720 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2721 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2722 | |
| 2723 | |
| 2724 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2725 | * mixer widget |
| 2726 | */ |
| 2727 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2728 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2729 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2730 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2731 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2732 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2733 | |
| 2734 | /* |
| 2735 | * Set up output mixers |
| 2736 | */ |
| 2737 | /* set vol=0 to output mixers */ |
| 2738 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2739 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2740 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2741 | |
| 2742 | /* Setup default input of PW4 to MW0 */ |
| 2743 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2744 | /* PW9 Output enable */ |
| 2745 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2746 | /* PW10 Input enable */ |
| 2747 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 2748 | { } |
| 2749 | }; |
| 2750 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2751 | static const struct hda_verb vt1708B_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2752 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2753 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2754 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2755 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2756 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2757 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2758 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2759 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2760 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2761 | { } |
| 2762 | }; |
| 2763 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2764 | static int vt1708B_parse_auto_config(struct hda_codec *codec) |
| 2765 | { |
| 2766 | struct via_spec *spec = codec->spec; |
| 2767 | int err; |
| 2768 | |
| 2769 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2770 | if (err < 0) |
| 2771 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2772 | err = via_auto_fill_dac_nids(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2773 | if (err < 0) |
| 2774 | return err; |
| 2775 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2776 | return 0; /* can't find valid BIOS pin config */ |
| 2777 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2778 | err = via_auto_create_multi_out_ctls(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2779 | if (err < 0) |
| 2780 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2781 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2782 | if (err < 0) |
| 2783 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2784 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2785 | if (err < 0) |
| 2786 | return err; |
| 2787 | |
| 2788 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2789 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2790 | if (spec->autocfg.dig_outs) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2791 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2792 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2793 | if (spec->autocfg.dig_in_pin) |
| 2794 | spec->dig_in_nid = VT1708B_DIGIN_NID; |
| 2795 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2796 | if (spec->kctls.list) |
| 2797 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2798 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2799 | spec->input_mux = &spec->private_imux[0]; |
| 2800 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2801 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2802 | via_hp_build(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2803 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2804 | err = via_smart51_build(codec); |
| 2805 | if (err < 0) |
| 2806 | return err; |
| 2807 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2808 | return 1; |
| 2809 | } |
| 2810 | |
| 2811 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2812 | static const struct hda_amp_list vt1708B_loopbacks[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2813 | { 0x16, HDA_INPUT, 1 }, |
| 2814 | { 0x16, HDA_INPUT, 2 }, |
| 2815 | { 0x16, HDA_INPUT, 3 }, |
| 2816 | { 0x16, HDA_INPUT, 4 }, |
| 2817 | { } /* end */ |
| 2818 | }; |
| 2819 | #endif |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2820 | |
| 2821 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
| 2822 | { |
| 2823 | struct via_spec *spec = codec->spec; |
| 2824 | int imux_is_smixer; |
| 2825 | unsigned int parm; |
| 2826 | int is_8ch = 0; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2827 | if ((spec->codec_type != VT1708B_4CH) && |
| 2828 | (codec->vendor_id != 0x11064397)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2829 | is_8ch = 1; |
| 2830 | |
| 2831 | /* SW0 (17h) = stereo mixer */ |
| 2832 | imux_is_smixer = |
| 2833 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 2834 | == ((spec->codec_type == VT1708S) ? 5 : 0)); |
| 2835 | /* inputs */ |
| 2836 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 2837 | parm = AC_PWRST_D3; |
| 2838 | set_pin_power_state(codec, 0x1a, &parm); |
| 2839 | set_pin_power_state(codec, 0x1b, &parm); |
| 2840 | set_pin_power_state(codec, 0x1e, &parm); |
| 2841 | if (imux_is_smixer) |
| 2842 | parm = AC_PWRST_D0; |
| 2843 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
| 2844 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2845 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2846 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2847 | |
| 2848 | /* outputs */ |
| 2849 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 2850 | parm = AC_PWRST_D3; |
| 2851 | set_pin_power_state(codec, 0x19, &parm); |
| 2852 | if (spec->smart51_enabled) |
| 2853 | set_pin_power_state(codec, 0x1b, &parm); |
| 2854 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2855 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2856 | |
| 2857 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 2858 | if (is_8ch) { |
| 2859 | parm = AC_PWRST_D3; |
| 2860 | set_pin_power_state(codec, 0x22, &parm); |
| 2861 | if (spec->smart51_enabled) |
| 2862 | set_pin_power_state(codec, 0x1a, &parm); |
| 2863 | snd_hda_codec_write(codec, 0x26, 0, |
| 2864 | AC_VERB_SET_POWER_STATE, parm); |
| 2865 | snd_hda_codec_write(codec, 0x24, 0, |
| 2866 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2867 | } else if (codec->vendor_id == 0x11064397) { |
| 2868 | /* PW7(23h), SW2(27h), AOW2(25h) */ |
| 2869 | parm = AC_PWRST_D3; |
| 2870 | set_pin_power_state(codec, 0x23, &parm); |
| 2871 | if (spec->smart51_enabled) |
| 2872 | set_pin_power_state(codec, 0x1a, &parm); |
| 2873 | snd_hda_codec_write(codec, 0x27, 0, |
| 2874 | AC_VERB_SET_POWER_STATE, parm); |
| 2875 | snd_hda_codec_write(codec, 0x25, 0, |
| 2876 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 2880 | parm = AC_PWRST_D3; |
| 2881 | /* force to D0 for internal Speaker */ |
| 2882 | set_pin_power_state(codec, 0x1c, &parm); |
| 2883 | set_pin_power_state(codec, 0x1d, &parm); |
| 2884 | if (is_8ch) |
| 2885 | set_pin_power_state(codec, 0x23, &parm); |
| 2886 | |
| 2887 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
| 2888 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 2889 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 2890 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2891 | if (is_8ch) { |
| 2892 | snd_hda_codec_write(codec, 0x25, 0, |
| 2893 | AC_VERB_SET_POWER_STATE, parm); |
| 2894 | snd_hda_codec_write(codec, 0x27, 0, |
| 2895 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2896 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
| 2897 | snd_hda_codec_write(codec, 0x25, 0, |
| 2898 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2899 | } |
| 2900 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2901 | static int patch_vt1708S(struct hda_codec *codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2902 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
| 2903 | { |
| 2904 | struct via_spec *spec; |
| 2905 | int err; |
| 2906 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2907 | if (get_codec_type(codec) == VT1708BCE) |
| 2908 | return patch_vt1708S(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2909 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2910 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2911 | if (spec == NULL) |
| 2912 | return -ENOMEM; |
| 2913 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2914 | spec->aa_mix_nid = 0x16; |
| 2915 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2916 | /* automatic parse from the BIOS config */ |
| 2917 | err = vt1708B_parse_auto_config(codec); |
| 2918 | if (err < 0) { |
| 2919 | via_free(codec); |
| 2920 | return err; |
| 2921 | } else if (!err) { |
| 2922 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 2923 | "from BIOS. Using genenic mode...\n"); |
| 2924 | } |
| 2925 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2926 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
| 2927 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2928 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2929 | if (spec->adc_nids && spec->input_mux) { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2930 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 2931 | spec->num_mixers++; |
| 2932 | } |
| 2933 | |
| 2934 | codec->patch_ops = via_patch_ops; |
| 2935 | |
| 2936 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2937 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2938 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2939 | spec->loopback.amplist = vt1708B_loopbacks; |
| 2940 | #endif |
| 2941 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2942 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 2943 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2944 | return 0; |
| 2945 | } |
| 2946 | |
| 2947 | static int patch_vt1708B_4ch(struct hda_codec *codec) |
| 2948 | { |
| 2949 | struct via_spec *spec; |
| 2950 | int err; |
| 2951 | |
| 2952 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2953 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2954 | if (spec == NULL) |
| 2955 | return -ENOMEM; |
| 2956 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2957 | /* automatic parse from the BIOS config */ |
| 2958 | err = vt1708B_parse_auto_config(codec); |
| 2959 | if (err < 0) { |
| 2960 | via_free(codec); |
| 2961 | return err; |
| 2962 | } else if (!err) { |
| 2963 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 2964 | "from BIOS. Using genenic mode...\n"); |
| 2965 | } |
| 2966 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2967 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
| 2968 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2969 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2970 | if (spec->adc_nids && spec->input_mux) { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2971 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 2972 | spec->num_mixers++; |
| 2973 | } |
| 2974 | |
| 2975 | codec->patch_ops = via_patch_ops; |
| 2976 | |
| 2977 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2978 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2979 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2980 | spec->loopback.amplist = vt1708B_loopbacks; |
| 2981 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2982 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2983 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 2984 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2985 | return 0; |
| 2986 | } |
| 2987 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2988 | /* Patch for VT1708S */ |
| 2989 | |
| 2990 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2991 | static const struct snd_kcontrol_new vt1708S_capture_mixer[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2992 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 2993 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 2994 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 2995 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 2996 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 2997 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 2998 | HDA_INPUT), |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2999 | { |
| 3000 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3001 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3002 | * So call somewhat different.. |
| 3003 | */ |
| 3004 | /* .name = "Capture Source", */ |
| 3005 | .name = "Input Source", |
| 3006 | .count = 1, |
| 3007 | .info = via_mux_enum_info, |
| 3008 | .get = via_mux_enum_get, |
| 3009 | .put = via_mux_enum_put, |
| 3010 | }, |
| 3011 | { } /* end */ |
| 3012 | }; |
| 3013 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3014 | static const struct hda_verb vt1708S_volume_init_verbs[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3015 | /* Unmute ADC0-1 and set the default input to mic-in */ |
| 3016 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3017 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3018 | |
| 3019 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the |
| 3020 | * analog-loopback mixer widget */ |
| 3021 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3022 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3023 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3024 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3025 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3026 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3027 | |
| 3028 | /* Setup default input of PW4 to MW0 */ |
| 3029 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3030 | /* PW9, PW10 Output enable */ |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3031 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3032 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 3033 | /* Enable Mic Boost Volume backdoor */ |
| 3034 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3035 | /* don't bybass mixer */ |
| 3036 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3037 | { } |
| 3038 | }; |
| 3039 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3040 | static const struct hda_verb vt1708S_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3041 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3042 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3043 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3044 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3045 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3046 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3047 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3048 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3049 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3050 | { } |
| 3051 | }; |
| 3052 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3053 | static const struct hda_verb vt1705_uniwill_init_verbs[] = { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3054 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3055 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3056 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3057 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3058 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3059 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3060 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3061 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3062 | { } |
| 3063 | }; |
| 3064 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3065 | /* fill out digital output widgets; one for master and one for slave outputs */ |
| 3066 | static void fill_dig_outs(struct hda_codec *codec) |
| 3067 | { |
| 3068 | struct via_spec *spec = codec->spec; |
| 3069 | int i; |
| 3070 | |
| 3071 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 3072 | hda_nid_t nid; |
| 3073 | int conn; |
| 3074 | |
| 3075 | nid = spec->autocfg.dig_out_pins[i]; |
| 3076 | if (!nid) |
| 3077 | continue; |
| 3078 | conn = snd_hda_get_connections(codec, nid, &nid, 1); |
| 3079 | if (conn < 1) |
| 3080 | continue; |
| 3081 | if (!spec->multiout.dig_out_nid) |
| 3082 | spec->multiout.dig_out_nid = nid; |
| 3083 | else { |
| 3084 | spec->slave_dig_outs[0] = nid; |
| 3085 | break; /* at most two dig outs */ |
| 3086 | } |
| 3087 | } |
| 3088 | } |
| 3089 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3090 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
| 3091 | { |
| 3092 | struct via_spec *spec = codec->spec; |
| 3093 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3094 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3095 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3096 | if (err < 0) |
| 3097 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3098 | err = via_auto_fill_dac_nids(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3099 | if (err < 0) |
| 3100 | return err; |
| 3101 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3102 | return 0; /* can't find valid BIOS pin config */ |
| 3103 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3104 | err = via_auto_create_multi_out_ctls(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3105 | if (err < 0) |
| 3106 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3107 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3108 | if (err < 0) |
| 3109 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3110 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3111 | if (err < 0) |
| 3112 | return err; |
| 3113 | |
| 3114 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3115 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3116 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 3117 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3118 | if (spec->kctls.list) |
| 3119 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3120 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3121 | spec->input_mux = &spec->private_imux[0]; |
| 3122 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3123 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3124 | via_hp_build(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3125 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 3126 | err = via_smart51_build(codec); |
| 3127 | if (err < 0) |
| 3128 | return err; |
| 3129 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3130 | return 1; |
| 3131 | } |
| 3132 | |
| 3133 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3134 | static const struct hda_amp_list vt1708S_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3135 | { 0x16, HDA_INPUT, 1 }, |
| 3136 | { 0x16, HDA_INPUT, 2 }, |
| 3137 | { 0x16, HDA_INPUT, 3 }, |
| 3138 | { 0x16, HDA_INPUT, 4 }, |
| 3139 | { } /* end */ |
| 3140 | }; |
| 3141 | #endif |
| 3142 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3143 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 3144 | int offset, int num_steps, int step_size) |
| 3145 | { |
| 3146 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 3147 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 3148 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3149 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3150 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 3151 | } |
| 3152 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3153 | static int patch_vt1708S(struct hda_codec *codec) |
| 3154 | { |
| 3155 | struct via_spec *spec; |
| 3156 | int err; |
| 3157 | |
| 3158 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3159 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3160 | if (spec == NULL) |
| 3161 | return -ENOMEM; |
| 3162 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3163 | spec->aa_mix_nid = 0x16; |
| 3164 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3165 | /* automatic parse from the BIOS config */ |
| 3166 | err = vt1708S_parse_auto_config(codec); |
| 3167 | if (err < 0) { |
| 3168 | via_free(codec); |
| 3169 | return err; |
| 3170 | } else if (!err) { |
| 3171 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3172 | "from BIOS. Using genenic mode...\n"); |
| 3173 | } |
| 3174 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3175 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3176 | if (codec->vendor_id == 0x11064397) |
| 3177 | spec->init_verbs[spec->num_iverbs++] = |
| 3178 | vt1705_uniwill_init_verbs; |
| 3179 | else |
| 3180 | spec->init_verbs[spec->num_iverbs++] = |
| 3181 | vt1708S_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3182 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3183 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3184 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3185 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3186 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; |
| 3187 | spec->num_mixers++; |
| 3188 | } |
| 3189 | |
| 3190 | codec->patch_ops = via_patch_ops; |
| 3191 | |
| 3192 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3193 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3194 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3195 | spec->loopback.amplist = vt1708S_loopbacks; |
| 3196 | #endif |
| 3197 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3198 | /* correct names for VT1708BCE */ |
| 3199 | if (get_codec_type(codec) == VT1708BCE) { |
| 3200 | kfree(codec->chip_name); |
| 3201 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 3202 | snprintf(codec->bus->card->mixername, |
| 3203 | sizeof(codec->bus->card->mixername), |
| 3204 | "%s %s", codec->vendor_name, codec->chip_name); |
Lydia Wang | 970f630 | 2011-03-22 16:25:56 +0800 | [diff] [blame] | 3205 | } |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3206 | /* correct names for VT1705 */ |
| 3207 | if (codec->vendor_id == 0x11064397) { |
| 3208 | kfree(codec->chip_name); |
| 3209 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); |
| 3210 | snprintf(codec->bus->card->mixername, |
| 3211 | sizeof(codec->bus->card->mixername), |
| 3212 | "%s %s", codec->vendor_name, codec->chip_name); |
| 3213 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3214 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3215 | return 0; |
| 3216 | } |
| 3217 | |
| 3218 | /* Patch for VT1702 */ |
| 3219 | |
| 3220 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3221 | static const struct snd_kcontrol_new vt1702_capture_mixer[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3222 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), |
| 3223 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), |
| 3224 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), |
| 3225 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), |
| 3226 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), |
| 3227 | HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), |
| 3228 | HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, |
| 3229 | HDA_INPUT), |
| 3230 | { |
| 3231 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3232 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3233 | * So call somewhat different.. |
| 3234 | */ |
| 3235 | /* .name = "Capture Source", */ |
| 3236 | .name = "Input Source", |
| 3237 | .count = 1, |
| 3238 | .info = via_mux_enum_info, |
| 3239 | .get = via_mux_enum_get, |
| 3240 | .put = via_mux_enum_put, |
| 3241 | }, |
| 3242 | { } /* end */ |
| 3243 | }; |
| 3244 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3245 | static const struct hda_verb vt1702_volume_init_verbs[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3246 | /* |
| 3247 | * Unmute ADC0-1 and set the default input to mic-in |
| 3248 | */ |
| 3249 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3250 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3251 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3252 | |
| 3253 | |
| 3254 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3255 | * mixer widget |
| 3256 | */ |
| 3257 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ |
| 3258 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3259 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3260 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3261 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3262 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 3263 | |
| 3264 | /* Setup default input of PW4 to MW0 */ |
| 3265 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3266 | /* PW6 PW7 Output enable */ |
| 3267 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3268 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3269 | /* mixer enable */ |
| 3270 | {0x1, 0xF88, 0x3}, |
| 3271 | /* GPIO 0~2 */ |
| 3272 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3273 | { } |
| 3274 | }; |
| 3275 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3276 | static const struct hda_verb vt1702_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3277 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3278 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3279 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3280 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3281 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3282 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3283 | { } |
| 3284 | }; |
| 3285 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3286 | static int vt1702_parse_auto_config(struct hda_codec *codec) |
| 3287 | { |
| 3288 | struct via_spec *spec = codec->spec; |
| 3289 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3290 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3291 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3292 | if (err < 0) |
| 3293 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3294 | err = via_auto_fill_dac_nids(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3295 | if (err < 0) |
| 3296 | return err; |
| 3297 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3298 | return 0; /* can't find valid BIOS pin config */ |
| 3299 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3300 | err = via_auto_create_multi_out_ctls(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3301 | if (err < 0) |
| 3302 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3303 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3304 | if (err < 0) |
| 3305 | return err; |
Lydia Wang | c2c02ea | 2009-10-10 19:07:32 +0800 | [diff] [blame] | 3306 | /* limit AA path volume to 0 dB */ |
| 3307 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 3308 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 3309 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3310 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3311 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3312 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3313 | if (err < 0) |
| 3314 | return err; |
| 3315 | |
| 3316 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3317 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3318 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 3319 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3320 | if (spec->kctls.list) |
| 3321 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3322 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3323 | spec->input_mux = &spec->private_imux[0]; |
| 3324 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3325 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3326 | via_hp_build(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3327 | |
| 3328 | return 1; |
| 3329 | } |
| 3330 | |
| 3331 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3332 | static const struct hda_amp_list vt1702_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3333 | { 0x1A, HDA_INPUT, 1 }, |
| 3334 | { 0x1A, HDA_INPUT, 2 }, |
| 3335 | { 0x1A, HDA_INPUT, 3 }, |
| 3336 | { 0x1A, HDA_INPUT, 4 }, |
| 3337 | { } /* end */ |
| 3338 | }; |
| 3339 | #endif |
| 3340 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3341 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
| 3342 | { |
| 3343 | int imux_is_smixer = |
| 3344 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3345 | unsigned int parm; |
| 3346 | /* inputs */ |
| 3347 | /* PW 1/2/5 (14h/15h/18h) */ |
| 3348 | parm = AC_PWRST_D3; |
| 3349 | set_pin_power_state(codec, 0x14, &parm); |
| 3350 | set_pin_power_state(codec, 0x15, &parm); |
| 3351 | set_pin_power_state(codec, 0x18, &parm); |
| 3352 | if (imux_is_smixer) |
| 3353 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ |
| 3354 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
| 3355 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3356 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3357 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3358 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3359 | |
| 3360 | /* outputs */ |
| 3361 | /* PW 3/4 (16h/17h) */ |
| 3362 | parm = AC_PWRST_D3; |
| 3363 | set_pin_power_state(codec, 0x17, &parm); |
| 3364 | set_pin_power_state(codec, 0x16, &parm); |
| 3365 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
| 3366 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 3367 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3368 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3369 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3370 | } |
| 3371 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3372 | static int patch_vt1702(struct hda_codec *codec) |
| 3373 | { |
| 3374 | struct via_spec *spec; |
| 3375 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3376 | |
| 3377 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3378 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3379 | if (spec == NULL) |
| 3380 | return -ENOMEM; |
| 3381 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3382 | spec->aa_mix_nid = 0x1a; |
| 3383 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3384 | /* automatic parse from the BIOS config */ |
| 3385 | err = vt1702_parse_auto_config(codec); |
| 3386 | if (err < 0) { |
| 3387 | via_free(codec); |
| 3388 | return err; |
| 3389 | } else if (!err) { |
| 3390 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3391 | "from BIOS. Using genenic mode...\n"); |
| 3392 | } |
| 3393 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3394 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
| 3395 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3396 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3397 | if (spec->adc_nids && spec->input_mux) { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3398 | spec->mixers[spec->num_mixers] = vt1702_capture_mixer; |
| 3399 | spec->num_mixers++; |
| 3400 | } |
| 3401 | |
| 3402 | codec->patch_ops = via_patch_ops; |
| 3403 | |
| 3404 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3405 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3406 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3407 | spec->loopback.amplist = vt1702_loopbacks; |
| 3408 | #endif |
| 3409 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3410 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3411 | return 0; |
| 3412 | } |
| 3413 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3414 | /* Patch for VT1718S */ |
| 3415 | |
| 3416 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3417 | static const struct snd_kcontrol_new vt1718S_capture_mixer[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3418 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 3419 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 3420 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 3421 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 3422 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 3423 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 3424 | HDA_INPUT), |
| 3425 | { |
| 3426 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3427 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3428 | * So call somewhat different.. |
| 3429 | */ |
| 3430 | .name = "Input Source", |
| 3431 | .count = 2, |
| 3432 | .info = via_mux_enum_info, |
| 3433 | .get = via_mux_enum_get, |
| 3434 | .put = via_mux_enum_put, |
| 3435 | }, |
| 3436 | { } /* end */ |
| 3437 | }; |
| 3438 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3439 | static const struct hda_verb vt1718S_volume_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3440 | /* |
| 3441 | * Unmute ADC0-1 and set the default input to mic-in |
| 3442 | */ |
| 3443 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3444 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3445 | |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 3446 | /* Enable MW0 adjust Gain 5 */ |
| 3447 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3448 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3449 | * mixer widget |
| 3450 | */ |
| 3451 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3452 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 3453 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3454 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 3455 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 3456 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3457 | |
| 3458 | /* Setup default input of Front HP to MW9 */ |
| 3459 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3460 | /* PW9 PW10 Output enable */ |
| 3461 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 3462 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 3463 | /* PW11 Input enable */ |
| 3464 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, |
| 3465 | /* Enable Boost Volume backdoor */ |
| 3466 | {0x1, 0xf88, 0x8}, |
| 3467 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ |
| 3468 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3469 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3470 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3471 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3472 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3473 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3474 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3475 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3476 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3477 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3478 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ |
| 3479 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, |
| 3480 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3481 | /* Unmute MW4's index 0 */ |
| 3482 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3483 | { } |
| 3484 | }; |
| 3485 | |
| 3486 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3487 | static const struct hda_verb vt1718S_uniwill_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3488 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3489 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3490 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3491 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3492 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3493 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3494 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3495 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3496 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3497 | { } |
| 3498 | }; |
| 3499 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3500 | static int vt1718S_parse_auto_config(struct hda_codec *codec) |
| 3501 | { |
| 3502 | struct via_spec *spec = codec->spec; |
| 3503 | int err; |
| 3504 | |
| 3505 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 3506 | |
| 3507 | if (err < 0) |
| 3508 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3509 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3510 | if (err < 0) |
| 3511 | return err; |
| 3512 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3513 | return 0; /* can't find valid BIOS pin config */ |
| 3514 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3515 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3516 | if (err < 0) |
| 3517 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3518 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3519 | if (err < 0) |
| 3520 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3521 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3522 | if (err < 0) |
| 3523 | return err; |
| 3524 | |
| 3525 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3526 | |
| 3527 | fill_dig_outs(codec); |
| 3528 | |
| 3529 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) |
| 3530 | spec->dig_in_nid = 0x13; |
| 3531 | |
| 3532 | if (spec->kctls.list) |
| 3533 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 3534 | |
| 3535 | spec->input_mux = &spec->private_imux[0]; |
| 3536 | |
| 3537 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3538 | via_hp_build(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3539 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 3540 | err = via_smart51_build(codec); |
| 3541 | if (err < 0) |
| 3542 | return err; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3543 | |
| 3544 | return 1; |
| 3545 | } |
| 3546 | |
| 3547 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3548 | static const struct hda_amp_list vt1718S_loopbacks[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3549 | { 0x21, HDA_INPUT, 1 }, |
| 3550 | { 0x21, HDA_INPUT, 2 }, |
| 3551 | { 0x21, HDA_INPUT, 3 }, |
| 3552 | { 0x21, HDA_INPUT, 4 }, |
| 3553 | { } /* end */ |
| 3554 | }; |
| 3555 | #endif |
| 3556 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3557 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
| 3558 | { |
| 3559 | struct via_spec *spec = codec->spec; |
| 3560 | int imux_is_smixer; |
| 3561 | unsigned int parm; |
| 3562 | /* MUX6 (1eh) = stereo mixer */ |
| 3563 | imux_is_smixer = |
| 3564 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 3565 | /* inputs */ |
| 3566 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3567 | parm = AC_PWRST_D3; |
| 3568 | set_pin_power_state(codec, 0x29, &parm); |
| 3569 | set_pin_power_state(codec, 0x2a, &parm); |
| 3570 | set_pin_power_state(codec, 0x2b, &parm); |
| 3571 | if (imux_is_smixer) |
| 3572 | parm = AC_PWRST_D0; |
| 3573 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3574 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3575 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3576 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3577 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3578 | |
| 3579 | /* outputs */ |
| 3580 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 3581 | parm = AC_PWRST_D3; |
| 3582 | set_pin_power_state(codec, 0x27, &parm); |
| 3583 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3584 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3585 | |
| 3586 | /* PW2 (26h), AOW2 (ah) */ |
| 3587 | parm = AC_PWRST_D3; |
| 3588 | set_pin_power_state(codec, 0x26, &parm); |
| 3589 | if (spec->smart51_enabled) |
| 3590 | set_pin_power_state(codec, 0x2b, &parm); |
| 3591 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3592 | |
| 3593 | /* PW0 (24h), AOW0 (8h) */ |
| 3594 | parm = AC_PWRST_D3; |
| 3595 | set_pin_power_state(codec, 0x24, &parm); |
| 3596 | if (!spec->hp_independent_mode) /* check for redirected HP */ |
| 3597 | set_pin_power_state(codec, 0x28, &parm); |
| 3598 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3599 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 3600 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, |
| 3601 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3602 | |
| 3603 | /* PW1 (25h), AOW1 (9h) */ |
| 3604 | parm = AC_PWRST_D3; |
| 3605 | set_pin_power_state(codec, 0x25, &parm); |
| 3606 | if (spec->smart51_enabled) |
| 3607 | set_pin_power_state(codec, 0x2a, &parm); |
| 3608 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3609 | |
| 3610 | if (spec->hp_independent_mode) { |
| 3611 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 3612 | parm = AC_PWRST_D3; |
| 3613 | set_pin_power_state(codec, 0x28, &parm); |
| 3614 | snd_hda_codec_write(codec, 0x1b, 0, |
| 3615 | AC_VERB_SET_POWER_STATE, parm); |
| 3616 | snd_hda_codec_write(codec, 0x34, 0, |
| 3617 | AC_VERB_SET_POWER_STATE, parm); |
| 3618 | snd_hda_codec_write(codec, 0xc, 0, |
| 3619 | AC_VERB_SET_POWER_STATE, parm); |
| 3620 | } |
| 3621 | } |
| 3622 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3623 | static int patch_vt1718S(struct hda_codec *codec) |
| 3624 | { |
| 3625 | struct via_spec *spec; |
| 3626 | int err; |
| 3627 | |
| 3628 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3629 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3630 | if (spec == NULL) |
| 3631 | return -ENOMEM; |
| 3632 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3633 | spec->aa_mix_nid = 0x21; |
| 3634 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3635 | /* automatic parse from the BIOS config */ |
| 3636 | err = vt1718S_parse_auto_config(codec); |
| 3637 | if (err < 0) { |
| 3638 | via_free(codec); |
| 3639 | return err; |
| 3640 | } else if (!err) { |
| 3641 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3642 | "from BIOS. Using genenic mode...\n"); |
| 3643 | } |
| 3644 | |
| 3645 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; |
| 3646 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; |
| 3647 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3648 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | bb3c6bf | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 3649 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3650 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3651 | spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; |
| 3652 | spec->num_mixers++; |
| 3653 | } |
| 3654 | |
| 3655 | codec->patch_ops = via_patch_ops; |
| 3656 | |
| 3657 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3658 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3659 | |
| 3660 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3661 | spec->loopback.amplist = vt1718S_loopbacks; |
| 3662 | #endif |
| 3663 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3664 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
| 3665 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3666 | return 0; |
| 3667 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3668 | |
| 3669 | /* Patch for VT1716S */ |
| 3670 | |
| 3671 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 3672 | struct snd_ctl_elem_info *uinfo) |
| 3673 | { |
| 3674 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3675 | uinfo->count = 1; |
| 3676 | uinfo->value.integer.min = 0; |
| 3677 | uinfo->value.integer.max = 1; |
| 3678 | return 0; |
| 3679 | } |
| 3680 | |
| 3681 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 3682 | struct snd_ctl_elem_value *ucontrol) |
| 3683 | { |
| 3684 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3685 | int index = 0; |
| 3686 | |
| 3687 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 3688 | AC_VERB_GET_CONNECT_SEL, 0); |
| 3689 | if (index != -1) |
| 3690 | *ucontrol->value.integer.value = index; |
| 3691 | |
| 3692 | return 0; |
| 3693 | } |
| 3694 | |
| 3695 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 3696 | struct snd_ctl_elem_value *ucontrol) |
| 3697 | { |
| 3698 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3699 | struct via_spec *spec = codec->spec; |
| 3700 | int index = *ucontrol->value.integer.value; |
| 3701 | |
| 3702 | snd_hda_codec_write(codec, 0x26, 0, |
| 3703 | AC_VERB_SET_CONNECT_SEL, index); |
| 3704 | spec->dmic_enabled = index; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3705 | set_widgets_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3706 | return 1; |
| 3707 | } |
| 3708 | |
| 3709 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3710 | static const struct snd_kcontrol_new vt1716S_capture_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3711 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 3712 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 3713 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 3714 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 3715 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 3716 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 3717 | HDA_INPUT), |
| 3718 | { |
| 3719 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3720 | .name = "Input Source", |
| 3721 | .count = 1, |
| 3722 | .info = via_mux_enum_info, |
| 3723 | .get = via_mux_enum_get, |
| 3724 | .put = via_mux_enum_put, |
| 3725 | }, |
| 3726 | { } /* end */ |
| 3727 | }; |
| 3728 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3729 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3730 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 3731 | { |
| 3732 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3733 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3734 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3735 | .count = 1, |
| 3736 | .info = vt1716s_dmic_info, |
| 3737 | .get = vt1716s_dmic_get, |
| 3738 | .put = vt1716s_dmic_put, |
| 3739 | }, |
| 3740 | {} /* end */ |
| 3741 | }; |
| 3742 | |
| 3743 | |
| 3744 | /* mono-out mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3745 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3746 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 3747 | { } /* end */ |
| 3748 | }; |
| 3749 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3750 | static const struct hda_verb vt1716S_volume_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3751 | /* |
| 3752 | * Unmute ADC0-1 and set the default input to mic-in |
| 3753 | */ |
| 3754 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3755 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3756 | |
| 3757 | |
| 3758 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3759 | * mixer widget |
| 3760 | */ |
| 3761 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3762 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 3763 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3764 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 3765 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 3766 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 3767 | |
| 3768 | /* MUX Indices: Stereo Mixer = 5 */ |
| 3769 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, |
| 3770 | |
| 3771 | /* Setup default input of PW4 to MW0 */ |
| 3772 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 3773 | |
| 3774 | /* Setup default input of SW1 as MW0 */ |
| 3775 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3776 | |
| 3777 | /* Setup default input of SW4 as AOW0 */ |
| 3778 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3779 | |
| 3780 | /* PW9 PW10 Output enable */ |
| 3781 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3782 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3783 | |
| 3784 | /* Unmute SW1, PW12 */ |
| 3785 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3786 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 3787 | /* PW12 Output enable */ |
| 3788 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3789 | /* Enable Boost Volume backdoor */ |
| 3790 | {0x1, 0xf8a, 0x80}, |
| 3791 | /* don't bybass mixer */ |
| 3792 | {0x1, 0xf88, 0xc0}, |
| 3793 | /* Enable mono output */ |
| 3794 | {0x1, 0xf90, 0x08}, |
| 3795 | { } |
| 3796 | }; |
| 3797 | |
| 3798 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3799 | static const struct hda_verb vt1716S_uniwill_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3800 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3801 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3802 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3803 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3804 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3805 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3806 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, |
| 3807 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3808 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3809 | { } |
| 3810 | }; |
| 3811 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3812 | static int vt1716S_parse_auto_config(struct hda_codec *codec) |
| 3813 | { |
| 3814 | struct via_spec *spec = codec->spec; |
| 3815 | int err; |
| 3816 | |
| 3817 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 3818 | if (err < 0) |
| 3819 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3820 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3821 | if (err < 0) |
| 3822 | return err; |
| 3823 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3824 | return 0; /* can't find valid BIOS pin config */ |
| 3825 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3826 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3827 | if (err < 0) |
| 3828 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3829 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3830 | if (err < 0) |
| 3831 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3832 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3833 | if (err < 0) |
| 3834 | return err; |
| 3835 | |
| 3836 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3837 | |
| 3838 | fill_dig_outs(codec); |
| 3839 | |
| 3840 | if (spec->kctls.list) |
| 3841 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 3842 | |
| 3843 | spec->input_mux = &spec->private_imux[0]; |
| 3844 | |
| 3845 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3846 | via_hp_build(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3847 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 3848 | err = via_smart51_build(codec); |
| 3849 | if (err < 0) |
| 3850 | return err; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3851 | |
| 3852 | return 1; |
| 3853 | } |
| 3854 | |
| 3855 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3856 | static const struct hda_amp_list vt1716S_loopbacks[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3857 | { 0x16, HDA_INPUT, 1 }, |
| 3858 | { 0x16, HDA_INPUT, 2 }, |
| 3859 | { 0x16, HDA_INPUT, 3 }, |
| 3860 | { 0x16, HDA_INPUT, 4 }, |
| 3861 | { } /* end */ |
| 3862 | }; |
| 3863 | #endif |
| 3864 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3865 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
| 3866 | { |
| 3867 | struct via_spec *spec = codec->spec; |
| 3868 | int imux_is_smixer; |
| 3869 | unsigned int parm; |
| 3870 | unsigned int mono_out, present; |
| 3871 | /* SW0 (17h) = stereo mixer */ |
| 3872 | imux_is_smixer = |
| 3873 | (snd_hda_codec_read(codec, 0x17, 0, |
| 3874 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); |
| 3875 | /* inputs */ |
| 3876 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 3877 | parm = AC_PWRST_D3; |
| 3878 | set_pin_power_state(codec, 0x1a, &parm); |
| 3879 | set_pin_power_state(codec, 0x1b, &parm); |
| 3880 | set_pin_power_state(codec, 0x1e, &parm); |
| 3881 | if (imux_is_smixer) |
| 3882 | parm = AC_PWRST_D0; |
| 3883 | /* SW0 (17h), AIW0(13h) */ |
| 3884 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3885 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3886 | |
| 3887 | parm = AC_PWRST_D3; |
| 3888 | set_pin_power_state(codec, 0x1e, &parm); |
| 3889 | /* PW11 (22h) */ |
| 3890 | if (spec->dmic_enabled) |
| 3891 | set_pin_power_state(codec, 0x22, &parm); |
| 3892 | else |
| 3893 | snd_hda_codec_write(codec, 0x22, 0, |
| 3894 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3895 | |
| 3896 | /* SW2(26h), AIW1(14h) */ |
| 3897 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3898 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3899 | |
| 3900 | /* outputs */ |
| 3901 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 3902 | parm = AC_PWRST_D3; |
| 3903 | set_pin_power_state(codec, 0x19, &parm); |
| 3904 | /* Smart 5.1 PW2(1bh) */ |
| 3905 | if (spec->smart51_enabled) |
| 3906 | set_pin_power_state(codec, 0x1b, &parm); |
| 3907 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3908 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3909 | |
| 3910 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 3911 | parm = AC_PWRST_D3; |
| 3912 | set_pin_power_state(codec, 0x23, &parm); |
| 3913 | /* Smart 5.1 PW1(1ah) */ |
| 3914 | if (spec->smart51_enabled) |
| 3915 | set_pin_power_state(codec, 0x1a, &parm); |
| 3916 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3917 | |
| 3918 | /* Smart 5.1 PW5(1eh) */ |
| 3919 | if (spec->smart51_enabled) |
| 3920 | set_pin_power_state(codec, 0x1e, &parm); |
| 3921 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3922 | |
| 3923 | /* Mono out */ |
| 3924 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 3925 | present = snd_hda_jack_detect(codec, 0x1c); |
| 3926 | |
| 3927 | if (present) |
| 3928 | mono_out = 0; |
| 3929 | else { |
| 3930 | present = snd_hda_jack_detect(codec, 0x1d); |
| 3931 | if (!spec->hp_independent_mode && present) |
| 3932 | mono_out = 0; |
| 3933 | else |
| 3934 | mono_out = 1; |
| 3935 | } |
| 3936 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
| 3937 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3938 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3939 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3940 | |
| 3941 | /* PW 3/4 (1ch/1dh) */ |
| 3942 | parm = AC_PWRST_D3; |
| 3943 | set_pin_power_state(codec, 0x1c, &parm); |
| 3944 | set_pin_power_state(codec, 0x1d, &parm); |
| 3945 | /* HP Independent Mode, power on AOW3 */ |
| 3946 | if (spec->hp_independent_mode) |
| 3947 | snd_hda_codec_write(codec, 0x25, 0, |
| 3948 | AC_VERB_SET_POWER_STATE, parm); |
| 3949 | |
| 3950 | /* force to D0 for internal Speaker */ |
| 3951 | /* MW0 (16h), AOW0 (10h) */ |
| 3952 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 3953 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3954 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 3955 | mono_out ? AC_PWRST_D0 : parm); |
| 3956 | } |
| 3957 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3958 | static int patch_vt1716S(struct hda_codec *codec) |
| 3959 | { |
| 3960 | struct via_spec *spec; |
| 3961 | int err; |
| 3962 | |
| 3963 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3964 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3965 | if (spec == NULL) |
| 3966 | return -ENOMEM; |
| 3967 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3968 | spec->aa_mix_nid = 0x16; |
| 3969 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3970 | /* automatic parse from the BIOS config */ |
| 3971 | err = vt1716S_parse_auto_config(codec); |
| 3972 | if (err < 0) { |
| 3973 | via_free(codec); |
| 3974 | return err; |
| 3975 | } else if (!err) { |
| 3976 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3977 | "from BIOS. Using genenic mode...\n"); |
| 3978 | } |
| 3979 | |
| 3980 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; |
| 3981 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; |
| 3982 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3983 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3984 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3985 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
| 3986 | spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; |
| 3987 | spec->num_mixers++; |
| 3988 | } |
| 3989 | |
| 3990 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
| 3991 | spec->num_mixers++; |
| 3992 | |
| 3993 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 3994 | |
| 3995 | codec->patch_ops = via_patch_ops; |
| 3996 | |
| 3997 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3998 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3999 | |
| 4000 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4001 | spec->loopback.amplist = vt1716S_loopbacks; |
| 4002 | #endif |
| 4003 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4004 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4005 | return 0; |
| 4006 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4007 | |
| 4008 | /* for vt2002P */ |
| 4009 | |
| 4010 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4011 | static const struct snd_kcontrol_new vt2002P_capture_mixer[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4012 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 4013 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 4014 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 4015 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 4016 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 4017 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 4018 | HDA_INPUT), |
| 4019 | { |
| 4020 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4021 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4022 | * So call somewhat different.. |
| 4023 | */ |
| 4024 | /* .name = "Capture Source", */ |
| 4025 | .name = "Input Source", |
| 4026 | .count = 2, |
| 4027 | .info = via_mux_enum_info, |
| 4028 | .get = via_mux_enum_get, |
| 4029 | .put = via_mux_enum_put, |
| 4030 | }, |
| 4031 | { } /* end */ |
| 4032 | }; |
| 4033 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4034 | static const struct hda_verb vt2002P_volume_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 4035 | /* Class-D speaker related verbs */ |
| 4036 | {0x1, 0xfe0, 0x4}, |
| 4037 | {0x1, 0xfe9, 0x80}, |
| 4038 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4039 | /* |
| 4040 | * Unmute ADC0-1 and set the default input to mic-in |
| 4041 | */ |
| 4042 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4043 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4044 | |
| 4045 | |
| 4046 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4047 | * mixer widget |
| 4048 | */ |
| 4049 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4050 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4051 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4052 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4053 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4054 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4055 | |
| 4056 | /* MUX Indices: Mic = 0 */ |
| 4057 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4058 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4059 | |
| 4060 | /* PW9 Output enable */ |
| 4061 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4062 | |
| 4063 | /* Enable Boost Volume backdoor */ |
| 4064 | {0x1, 0xfb9, 0x24}, |
| 4065 | |
| 4066 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 4067 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4068 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4069 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4070 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4071 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4072 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4073 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4074 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4075 | |
| 4076 | /* set MUX0/1/4/8 = 0 (AOW0) */ |
| 4077 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4078 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4079 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4080 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4081 | |
| 4082 | /* set PW0 index=0 (MW0) */ |
| 4083 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4084 | |
| 4085 | /* Enable AOW0 to MW9 */ |
| 4086 | {0x1, 0xfb8, 0x88}, |
| 4087 | { } |
| 4088 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4089 | static const struct hda_verb vt1802_volume_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4090 | /* |
| 4091 | * Unmute ADC0-1 and set the default input to mic-in |
| 4092 | */ |
| 4093 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4094 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4095 | |
| 4096 | |
| 4097 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4098 | * mixer widget |
| 4099 | */ |
| 4100 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4101 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4102 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4103 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4104 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4105 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4106 | |
| 4107 | /* MUX Indices: Mic = 0 */ |
| 4108 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4109 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4110 | |
| 4111 | /* PW9 Output enable */ |
| 4112 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4113 | |
| 4114 | /* Enable Boost Volume backdoor */ |
| 4115 | {0x1, 0xfb9, 0x24}, |
| 4116 | |
| 4117 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 4118 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4119 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4120 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4121 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4122 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4123 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4124 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4125 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4126 | |
| 4127 | /* set MUX0/1/4/8 = 0 (AOW0) */ |
| 4128 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4129 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4130 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4131 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4132 | |
| 4133 | /* set PW0 index=0 (MW0) */ |
| 4134 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4135 | |
| 4136 | /* Enable AOW0 to MW9 */ |
| 4137 | {0x1, 0xfb8, 0x88}, |
| 4138 | { } |
| 4139 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4140 | |
| 4141 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4142 | static const struct hda_verb vt2002P_uniwill_init_verbs[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4143 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4144 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4145 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4146 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4147 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4148 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4149 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4150 | { } |
| 4151 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4152 | static const struct hda_verb vt1802_uniwill_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4153 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4154 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4155 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4156 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4157 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4158 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4159 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4160 | { } |
| 4161 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4162 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4163 | static int vt2002P_parse_auto_config(struct hda_codec *codec) |
| 4164 | { |
| 4165 | struct via_spec *spec = codec->spec; |
| 4166 | int err; |
| 4167 | |
| 4168 | |
| 4169 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4170 | if (err < 0) |
| 4171 | return err; |
| 4172 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4173 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4174 | if (err < 0) |
| 4175 | return err; |
| 4176 | |
| 4177 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4178 | return 0; /* can't find valid BIOS pin config */ |
| 4179 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4180 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4181 | if (err < 0) |
| 4182 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4183 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4184 | if (err < 0) |
| 4185 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4186 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4187 | if (err < 0) |
| 4188 | return err; |
| 4189 | |
| 4190 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4191 | |
| 4192 | fill_dig_outs(codec); |
| 4193 | |
| 4194 | if (spec->kctls.list) |
| 4195 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4196 | |
| 4197 | spec->input_mux = &spec->private_imux[0]; |
| 4198 | |
| 4199 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4200 | via_hp_build(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4201 | |
| 4202 | return 1; |
| 4203 | } |
| 4204 | |
| 4205 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4206 | static const struct hda_amp_list vt2002P_loopbacks[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4207 | { 0x21, HDA_INPUT, 0 }, |
| 4208 | { 0x21, HDA_INPUT, 1 }, |
| 4209 | { 0x21, HDA_INPUT, 2 }, |
| 4210 | { } /* end */ |
| 4211 | }; |
| 4212 | #endif |
| 4213 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4214 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
| 4215 | { |
| 4216 | struct via_spec *spec = codec->spec; |
| 4217 | int imux_is_smixer; |
| 4218 | unsigned int parm; |
| 4219 | unsigned int present; |
| 4220 | /* MUX9 (1eh) = stereo mixer */ |
| 4221 | imux_is_smixer = |
| 4222 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 4223 | /* inputs */ |
| 4224 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 4225 | parm = AC_PWRST_D3; |
| 4226 | set_pin_power_state(codec, 0x29, &parm); |
| 4227 | set_pin_power_state(codec, 0x2a, &parm); |
| 4228 | set_pin_power_state(codec, 0x2b, &parm); |
| 4229 | parm = AC_PWRST_D0; |
| 4230 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 4231 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4232 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4233 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4234 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4235 | |
| 4236 | /* outputs */ |
| 4237 | /* AOW0 (8h)*/ |
| 4238 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4239 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4240 | if (spec->codec_type == VT1802) { |
| 4241 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 4242 | parm = AC_PWRST_D3; |
| 4243 | set_pin_power_state(codec, 0x28, &parm); |
| 4244 | snd_hda_codec_write(codec, 0x18, 0, |
| 4245 | AC_VERB_SET_POWER_STATE, parm); |
| 4246 | snd_hda_codec_write(codec, 0x38, 0, |
| 4247 | AC_VERB_SET_POWER_STATE, parm); |
| 4248 | } else { |
| 4249 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 4250 | parm = AC_PWRST_D3; |
| 4251 | set_pin_power_state(codec, 0x26, &parm); |
| 4252 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4253 | AC_VERB_SET_POWER_STATE, parm); |
| 4254 | snd_hda_codec_write(codec, 0x37, 0, |
| 4255 | AC_VERB_SET_POWER_STATE, parm); |
| 4256 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4257 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4258 | if (spec->codec_type == VT1802) { |
| 4259 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 4260 | parm = AC_PWRST_D3; |
| 4261 | set_pin_power_state(codec, 0x25, &parm); |
| 4262 | snd_hda_codec_write(codec, 0x15, 0, |
| 4263 | AC_VERB_SET_POWER_STATE, parm); |
| 4264 | snd_hda_codec_write(codec, 0x35, 0, |
| 4265 | AC_VERB_SET_POWER_STATE, parm); |
| 4266 | } else { |
| 4267 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 4268 | parm = AC_PWRST_D3; |
| 4269 | set_pin_power_state(codec, 0x25, &parm); |
| 4270 | snd_hda_codec_write(codec, 0x19, 0, |
| 4271 | AC_VERB_SET_POWER_STATE, parm); |
| 4272 | snd_hda_codec_write(codec, 0x35, 0, |
| 4273 | AC_VERB_SET_POWER_STATE, parm); |
| 4274 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4275 | |
| 4276 | if (spec->hp_independent_mode) |
| 4277 | snd_hda_codec_write(codec, 0x9, 0, |
| 4278 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4279 | |
| 4280 | /* Class-D */ |
| 4281 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ |
| 4282 | present = snd_hda_jack_detect(codec, 0x25); |
| 4283 | |
| 4284 | parm = AC_PWRST_D3; |
| 4285 | set_pin_power_state(codec, 0x24, &parm); |
| 4286 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4287 | if (spec->codec_type == VT1802) |
| 4288 | snd_hda_codec_write(codec, 0x14, 0, |
| 4289 | AC_VERB_SET_POWER_STATE, parm); |
| 4290 | else |
| 4291 | snd_hda_codec_write(codec, 0x18, 0, |
| 4292 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4293 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4294 | |
| 4295 | /* Mono Out */ |
| 4296 | present = snd_hda_jack_detect(codec, 0x26); |
| 4297 | |
| 4298 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4299 | if (spec->codec_type == VT1802) { |
| 4300 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ |
| 4301 | snd_hda_codec_write(codec, 0x33, 0, |
| 4302 | AC_VERB_SET_POWER_STATE, parm); |
| 4303 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4304 | AC_VERB_SET_POWER_STATE, parm); |
| 4305 | snd_hda_codec_write(codec, 0x3c, 0, |
| 4306 | AC_VERB_SET_POWER_STATE, parm); |
| 4307 | } else { |
| 4308 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
| 4309 | snd_hda_codec_write(codec, 0x31, 0, |
| 4310 | AC_VERB_SET_POWER_STATE, parm); |
| 4311 | snd_hda_codec_write(codec, 0x17, 0, |
| 4312 | AC_VERB_SET_POWER_STATE, parm); |
| 4313 | snd_hda_codec_write(codec, 0x3b, 0, |
| 4314 | AC_VERB_SET_POWER_STATE, parm); |
| 4315 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4316 | /* MW9 (21h) */ |
| 4317 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 4318 | snd_hda_codec_write(codec, 0x21, 0, |
| 4319 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4320 | else |
| 4321 | snd_hda_codec_write(codec, 0x21, 0, |
| 4322 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4323 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4324 | |
| 4325 | /* patch for vt2002P */ |
| 4326 | static int patch_vt2002P(struct hda_codec *codec) |
| 4327 | { |
| 4328 | struct via_spec *spec; |
| 4329 | int err; |
| 4330 | |
| 4331 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4332 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4333 | if (spec == NULL) |
| 4334 | return -ENOMEM; |
| 4335 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4336 | spec->aa_mix_nid = 0x21; |
| 4337 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4338 | /* automatic parse from the BIOS config */ |
| 4339 | err = vt2002P_parse_auto_config(codec); |
| 4340 | if (err < 0) { |
| 4341 | via_free(codec); |
| 4342 | return err; |
| 4343 | } else if (!err) { |
| 4344 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4345 | "from BIOS. Using genenic mode...\n"); |
| 4346 | } |
| 4347 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4348 | if (spec->codec_type == VT1802) |
| 4349 | spec->init_verbs[spec->num_iverbs++] = |
| 4350 | vt1802_volume_init_verbs; |
| 4351 | else |
| 4352 | spec->init_verbs[spec->num_iverbs++] = |
| 4353 | vt2002P_volume_init_verbs; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4354 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4355 | if (spec->codec_type == VT1802) |
| 4356 | spec->init_verbs[spec->num_iverbs++] = |
| 4357 | vt1802_uniwill_init_verbs; |
| 4358 | else |
| 4359 | spec->init_verbs[spec->num_iverbs++] = |
| 4360 | vt2002P_uniwill_init_verbs; |
| 4361 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4362 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4363 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 4364 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 4365 | spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; |
| 4366 | spec->num_mixers++; |
| 4367 | } |
| 4368 | |
| 4369 | codec->patch_ops = via_patch_ops; |
| 4370 | |
| 4371 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 4372 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4373 | |
| 4374 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4375 | spec->loopback.amplist = vt2002P_loopbacks; |
| 4376 | #endif |
| 4377 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4378 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4379 | return 0; |
| 4380 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4381 | |
| 4382 | /* for vt1812 */ |
| 4383 | |
| 4384 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4385 | static const struct snd_kcontrol_new vt1812_capture_mixer[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4386 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 4387 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 4388 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 4389 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 4390 | HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 4391 | HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 4392 | HDA_INPUT), |
| 4393 | { |
| 4394 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4395 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4396 | * So call somewhat different.. |
| 4397 | */ |
| 4398 | .name = "Input Source", |
| 4399 | .count = 2, |
| 4400 | .info = via_mux_enum_info, |
| 4401 | .get = via_mux_enum_get, |
| 4402 | .put = via_mux_enum_put, |
| 4403 | }, |
| 4404 | { } /* end */ |
| 4405 | }; |
| 4406 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4407 | static const struct hda_verb vt1812_volume_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4408 | /* |
| 4409 | * Unmute ADC0-1 and set the default input to mic-in |
| 4410 | */ |
| 4411 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4412 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4413 | |
| 4414 | |
| 4415 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4416 | * mixer widget |
| 4417 | */ |
| 4418 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4419 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4420 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4421 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4422 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4423 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4424 | |
| 4425 | /* MUX Indices: Mic = 0 */ |
| 4426 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4427 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4428 | |
| 4429 | /* PW9 Output enable */ |
| 4430 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4431 | |
| 4432 | /* Enable Boost Volume backdoor */ |
| 4433 | {0x1, 0xfb9, 0x24}, |
| 4434 | |
| 4435 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 4436 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4437 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4438 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4439 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4440 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4441 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4442 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4443 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4444 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4445 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4446 | |
| 4447 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ |
| 4448 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4449 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4450 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4451 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4452 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4453 | |
| 4454 | /* Enable AOW0 to MW9 */ |
| 4455 | {0x1, 0xfb8, 0xa8}, |
| 4456 | { } |
| 4457 | }; |
| 4458 | |
| 4459 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4460 | static const struct hda_verb vt1812_uniwill_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4461 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4462 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4463 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, |
| 4464 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4465 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4466 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4467 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4468 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4469 | { } |
| 4470 | }; |
| 4471 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4472 | static int vt1812_parse_auto_config(struct hda_codec *codec) |
| 4473 | { |
| 4474 | struct via_spec *spec = codec->spec; |
| 4475 | int err; |
| 4476 | |
| 4477 | |
| 4478 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4479 | if (err < 0) |
| 4480 | return err; |
| 4481 | fill_dig_outs(codec); |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4482 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4483 | if (err < 0) |
| 4484 | return err; |
| 4485 | |
| 4486 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) |
| 4487 | return 0; /* can't find valid BIOS pin config */ |
| 4488 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4489 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4490 | if (err < 0) |
| 4491 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4492 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4493 | if (err < 0) |
| 4494 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4495 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4496 | if (err < 0) |
| 4497 | return err; |
| 4498 | |
| 4499 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4500 | |
| 4501 | fill_dig_outs(codec); |
| 4502 | |
| 4503 | if (spec->kctls.list) |
| 4504 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4505 | |
| 4506 | spec->input_mux = &spec->private_imux[0]; |
| 4507 | |
| 4508 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4509 | via_hp_build(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4510 | |
| 4511 | return 1; |
| 4512 | } |
| 4513 | |
| 4514 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4515 | static const struct hda_amp_list vt1812_loopbacks[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4516 | { 0x21, HDA_INPUT, 0 }, |
| 4517 | { 0x21, HDA_INPUT, 1 }, |
| 4518 | { 0x21, HDA_INPUT, 2 }, |
| 4519 | { } /* end */ |
| 4520 | }; |
| 4521 | #endif |
| 4522 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4523 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
| 4524 | { |
| 4525 | struct via_spec *spec = codec->spec; |
| 4526 | int imux_is_smixer = |
| 4527 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 4528 | unsigned int parm; |
| 4529 | unsigned int present; |
| 4530 | /* MUX10 (1eh) = stereo mixer */ |
| 4531 | imux_is_smixer = |
| 4532 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 4533 | /* inputs */ |
| 4534 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 4535 | parm = AC_PWRST_D3; |
| 4536 | set_pin_power_state(codec, 0x29, &parm); |
| 4537 | set_pin_power_state(codec, 0x2a, &parm); |
| 4538 | set_pin_power_state(codec, 0x2b, &parm); |
| 4539 | parm = AC_PWRST_D0; |
| 4540 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 4541 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4542 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4543 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4544 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4545 | |
| 4546 | /* outputs */ |
| 4547 | /* AOW0 (8h)*/ |
| 4548 | snd_hda_codec_write(codec, 0x8, 0, |
| 4549 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4550 | |
| 4551 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 4552 | parm = AC_PWRST_D3; |
| 4553 | set_pin_power_state(codec, 0x28, &parm); |
| 4554 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4555 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4556 | |
| 4557 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 4558 | parm = AC_PWRST_D3; |
| 4559 | set_pin_power_state(codec, 0x25, &parm); |
| 4560 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4561 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4562 | if (spec->hp_independent_mode) |
| 4563 | snd_hda_codec_write(codec, 0x9, 0, |
| 4564 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4565 | |
| 4566 | /* Internal Speaker */ |
| 4567 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 4568 | present = snd_hda_jack_detect(codec, 0x25); |
| 4569 | |
| 4570 | parm = AC_PWRST_D3; |
| 4571 | set_pin_power_state(codec, 0x24, &parm); |
| 4572 | if (present) { |
| 4573 | snd_hda_codec_write(codec, 0x14, 0, |
| 4574 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4575 | snd_hda_codec_write(codec, 0x34, 0, |
| 4576 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4577 | } else { |
| 4578 | snd_hda_codec_write(codec, 0x14, 0, |
| 4579 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4580 | snd_hda_codec_write(codec, 0x34, 0, |
| 4581 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4582 | } |
| 4583 | |
| 4584 | |
| 4585 | /* Mono Out */ |
| 4586 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 4587 | present = snd_hda_jack_detect(codec, 0x28); |
| 4588 | |
| 4589 | parm = AC_PWRST_D3; |
| 4590 | set_pin_power_state(codec, 0x31, &parm); |
| 4591 | if (present) { |
| 4592 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4593 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4594 | snd_hda_codec_write(codec, 0x3c, 0, |
| 4595 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4596 | snd_hda_codec_write(codec, 0x3e, 0, |
| 4597 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4598 | } else { |
| 4599 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4600 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4601 | snd_hda_codec_write(codec, 0x3c, 0, |
| 4602 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4603 | snd_hda_codec_write(codec, 0x3e, 0, |
| 4604 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4605 | } |
| 4606 | |
| 4607 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 4608 | parm = AC_PWRST_D3; |
| 4609 | set_pin_power_state(codec, 0x33, &parm); |
| 4610 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4611 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4612 | |
| 4613 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4614 | |
| 4615 | /* patch for vt1812 */ |
| 4616 | static int patch_vt1812(struct hda_codec *codec) |
| 4617 | { |
| 4618 | struct via_spec *spec; |
| 4619 | int err; |
| 4620 | |
| 4621 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4622 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4623 | if (spec == NULL) |
| 4624 | return -ENOMEM; |
| 4625 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4626 | spec->aa_mix_nid = 0x21; |
| 4627 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4628 | /* automatic parse from the BIOS config */ |
| 4629 | err = vt1812_parse_auto_config(codec); |
| 4630 | if (err < 0) { |
| 4631 | via_free(codec); |
| 4632 | return err; |
| 4633 | } else if (!err) { |
| 4634 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4635 | "from BIOS. Using genenic mode...\n"); |
| 4636 | } |
| 4637 | |
| 4638 | |
| 4639 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; |
| 4640 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; |
| 4641 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4642 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4643 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 4644 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 4645 | spec->mixers[spec->num_mixers] = vt1812_capture_mixer; |
| 4646 | spec->num_mixers++; |
| 4647 | } |
| 4648 | |
| 4649 | codec->patch_ops = via_patch_ops; |
| 4650 | |
| 4651 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 4652 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4653 | |
| 4654 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4655 | spec->loopback.amplist = vt1812_loopbacks; |
| 4656 | #endif |
| 4657 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4658 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4659 | return 0; |
| 4660 | } |
| 4661 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 4662 | /* |
| 4663 | * patch entries |
| 4664 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4665 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4666 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 4667 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 4668 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 4669 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 4670 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4671 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4672 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4673 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4674 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4675 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4676 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4677 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4678 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4679 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4680 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4681 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4682 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4683 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4684 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4685 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4686 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4687 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4688 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4689 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4690 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4691 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4692 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4693 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4694 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4695 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4696 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4697 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4698 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4699 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4700 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 4701 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4702 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4703 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4704 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4705 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4706 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4707 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4708 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4709 | .patch = patch_vt1708S}, |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 4710 | { .id = 0x11064397, .name = "VT1705", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4711 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4712 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4713 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4714 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4715 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4716 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4717 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4718 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4719 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4720 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4721 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4722 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4723 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4724 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4725 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4726 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4727 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4728 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4729 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4730 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4731 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 4732 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4733 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4734 | { .id = 0x11060428, .name = "VT1718S", |
| 4735 | .patch = patch_vt1718S}, |
| 4736 | { .id = 0x11064428, .name = "VT1718S", |
| 4737 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bf | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4738 | { .id = 0x11060441, .name = "VT2020", |
| 4739 | .patch = patch_vt1718S}, |
| 4740 | { .id = 0x11064441, .name = "VT1828S", |
| 4741 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4742 | { .id = 0x11060433, .name = "VT1716S", |
| 4743 | .patch = patch_vt1716S}, |
| 4744 | { .id = 0x1106a721, .name = "VT1716S", |
| 4745 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4746 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 4747 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4748 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 4749 | { .id = 0x11060440, .name = "VT1818S", |
| 4750 | .patch = patch_vt1708S}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4751 | { .id = 0x11060446, .name = "VT1802", |
| 4752 | .patch = patch_vt2002P}, |
| 4753 | { .id = 0x11068446, .name = "VT1802", |
| 4754 | .patch = patch_vt2002P}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 4755 | {} /* terminator */ |
| 4756 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 4757 | |
| 4758 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 4759 | |
| 4760 | static struct hda_codec_preset_list via_list = { |
| 4761 | .preset = snd_hda_preset_via, |
| 4762 | .owner = THIS_MODULE, |
| 4763 | }; |
| 4764 | |
| 4765 | MODULE_LICENSE("GPL"); |
| 4766 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 4767 | |
| 4768 | static int __init patch_via_init(void) |
| 4769 | { |
| 4770 | return snd_hda_add_codec_preset(&via_list); |
| 4771 | } |
| 4772 | |
| 4773 | static void __exit patch_via_exit(void) |
| 4774 | { |
| 4775 | snd_hda_delete_codec_preset(&via_list); |
| 4776 | } |
| 4777 | |
| 4778 | module_init(patch_via_init) |
| 4779 | module_exit(patch_via_exit) |