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 | bb3c6bfc | 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 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1225 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, |
| 1226 | unsigned int stream_tag, |
| 1227 | unsigned int format, |
| 1228 | struct snd_pcm_substream *substream) |
| 1229 | { |
| 1230 | struct via_spec *spec = codec->spec; |
| 1231 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1232 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1233 | int chs = substream->runtime->channels; |
| 1234 | int i; |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1235 | struct hda_spdif_out *spdif = |
| 1236 | snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1237 | |
| 1238 | mutex_lock(&codec->spdif_mutex); |
| 1239 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
| 1240 | if (chs == 2 && |
| 1241 | snd_hda_is_supported_format(codec, mout->dig_out_nid, |
| 1242 | format) && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1243 | !(spdif->status & IEC958_AES0_NONAUDIO)) { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1244 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
| 1245 | /* turn off SPDIF once; otherwise the IEC958 bits won't |
| 1246 | * be updated */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1247 | if (spdif->ctls & AC_DIG1_ENABLE) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1248 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1249 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1250 | spdif->ctls & |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1251 | ~AC_DIG1_ENABLE & 0xff); |
| 1252 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1253 | stream_tag, 0, format); |
| 1254 | /* turn on again (if needed) */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1255 | if (spdif->ctls & AC_DIG1_ENABLE) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1256 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1257 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1258 | spdif->ctls & 0xff); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1259 | } else { |
| 1260 | mout->dig_out_used = 0; |
| 1261 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1262 | 0, 0, 0); |
| 1263 | } |
| 1264 | } |
| 1265 | mutex_unlock(&codec->spdif_mutex); |
| 1266 | |
| 1267 | /* front */ |
| 1268 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
| 1269 | 0, format); |
| 1270 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1271 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
| 1272 | && !spec->hp_independent_mode) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1273 | /* headphone out will just decode front left/right (stereo) */ |
| 1274 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
| 1275 | 0, format); |
| 1276 | |
| 1277 | /* extra outputs copied from front */ |
| 1278 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1279 | if (mout->extra_out_nid[i]) |
| 1280 | snd_hda_codec_setup_stream(codec, |
| 1281 | mout->extra_out_nid[i], |
| 1282 | stream_tag, 0, format); |
| 1283 | |
| 1284 | /* surrounds */ |
| 1285 | for (i = 1; i < mout->num_dacs; i++) { |
| 1286 | if (chs >= (i + 1) * 2) /* independent out */ |
| 1287 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1288 | i * 2, format); |
| 1289 | else /* copy front */ |
| 1290 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1291 | 0, format); |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1296 | struct hda_codec *codec, |
| 1297 | unsigned int stream_tag, |
| 1298 | unsigned int format, |
| 1299 | struct snd_pcm_substream *substream) |
| 1300 | { |
| 1301 | struct via_spec *spec = codec->spec; |
| 1302 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1303 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1304 | |
| 1305 | if (substream->number == 0) |
| 1306 | playback_multi_pcm_prep_0(codec, stream_tag, format, |
| 1307 | substream); |
| 1308 | else { |
| 1309 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1310 | spec->hp_independent_mode) |
| 1311 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1312 | stream_tag, 0, format); |
| 1313 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1314 | vt1708_start_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1319 | struct hda_codec *codec, |
| 1320 | struct snd_pcm_substream *substream) |
| 1321 | { |
| 1322 | struct via_spec *spec = codec->spec; |
| 1323 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1324 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1325 | int i; |
| 1326 | |
| 1327 | if (substream->number == 0) { |
| 1328 | for (i = 0; i < mout->num_dacs; i++) |
| 1329 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); |
| 1330 | |
| 1331 | if (mout->hp_nid && !spec->hp_independent_mode) |
| 1332 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1333 | 0, 0, 0); |
| 1334 | |
| 1335 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1336 | if (mout->extra_out_nid[i]) |
| 1337 | snd_hda_codec_setup_stream(codec, |
| 1338 | mout->extra_out_nid[i], |
| 1339 | 0, 0, 0); |
| 1340 | mutex_lock(&codec->spdif_mutex); |
| 1341 | if (mout->dig_out_nid && |
| 1342 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { |
| 1343 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1344 | 0, 0, 0); |
| 1345 | mout->dig_out_used = 0; |
| 1346 | } |
| 1347 | mutex_unlock(&codec->spdif_mutex); |
| 1348 | } else { |
| 1349 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1350 | spec->hp_independent_mode) |
| 1351 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1352 | 0, 0, 0); |
| 1353 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1354 | vt1708_stop_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1355 | return 0; |
| 1356 | } |
| 1357 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1358 | /* |
| 1359 | * Digital out |
| 1360 | */ |
| 1361 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1362 | struct hda_codec *codec, |
| 1363 | struct snd_pcm_substream *substream) |
| 1364 | { |
| 1365 | struct via_spec *spec = codec->spec; |
| 1366 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 1367 | } |
| 1368 | |
| 1369 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1370 | struct hda_codec *codec, |
| 1371 | struct snd_pcm_substream *substream) |
| 1372 | { |
| 1373 | struct via_spec *spec = codec->spec; |
| 1374 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 1375 | } |
| 1376 | |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1377 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1378 | struct hda_codec *codec, |
| 1379 | unsigned int stream_tag, |
| 1380 | unsigned int format, |
| 1381 | struct snd_pcm_substream *substream) |
| 1382 | { |
| 1383 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1384 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 1385 | stream_tag, format, substream); |
| 1386 | } |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1387 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1388 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1389 | struct hda_codec *codec, |
| 1390 | struct snd_pcm_substream *substream) |
| 1391 | { |
| 1392 | struct via_spec *spec = codec->spec; |
| 1393 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1394 | return 0; |
| 1395 | } |
| 1396 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1397 | /* |
| 1398 | * Analog capture |
| 1399 | */ |
| 1400 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1401 | struct hda_codec *codec, |
| 1402 | unsigned int stream_tag, |
| 1403 | unsigned int format, |
| 1404 | struct snd_pcm_substream *substream) |
| 1405 | { |
| 1406 | struct via_spec *spec = codec->spec; |
| 1407 | |
| 1408 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 1409 | stream_tag, 0, format); |
| 1410 | return 0; |
| 1411 | } |
| 1412 | |
| 1413 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1414 | struct hda_codec *codec, |
| 1415 | struct snd_pcm_substream *substream) |
| 1416 | { |
| 1417 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1418 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1419 | return 0; |
| 1420 | } |
| 1421 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1422 | static const struct hda_pcm_stream vt1708_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1423 | .substreams = 2, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1424 | .channels_min = 2, |
| 1425 | .channels_max = 8, |
| 1426 | .nid = 0x10, /* NID to query formats and rates */ |
| 1427 | .ops = { |
| 1428 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1429 | .prepare = via_playback_multi_pcm_prepare, |
| 1430 | .cleanup = via_playback_multi_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1431 | }, |
| 1432 | }; |
| 1433 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1434 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1435 | .substreams = 2, |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1436 | .channels_min = 2, |
| 1437 | .channels_max = 8, |
| 1438 | .nid = 0x10, /* NID to query formats and rates */ |
| 1439 | /* We got noisy outputs on the right channel on VT1708 when |
| 1440 | * 24bit samples are used. Until any workaround is found, |
| 1441 | * disable the 24bit format, so far. |
| 1442 | */ |
| 1443 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1444 | .ops = { |
| 1445 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1446 | .prepare = via_playback_multi_pcm_prepare, |
| 1447 | .cleanup = via_playback_multi_pcm_cleanup |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1448 | }, |
| 1449 | }; |
| 1450 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1451 | static const struct hda_pcm_stream vt1708_pcm_analog_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1452 | .substreams = 2, |
| 1453 | .channels_min = 2, |
| 1454 | .channels_max = 2, |
| 1455 | .nid = 0x15, /* NID to query formats and rates */ |
| 1456 | .ops = { |
| 1457 | .prepare = via_capture_pcm_prepare, |
| 1458 | .cleanup = via_capture_pcm_cleanup |
| 1459 | }, |
| 1460 | }; |
| 1461 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1462 | static const struct hda_pcm_stream vt1708_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1463 | .substreams = 1, |
| 1464 | .channels_min = 2, |
| 1465 | .channels_max = 2, |
| 1466 | /* NID is set in via_build_pcms */ |
| 1467 | .ops = { |
| 1468 | .open = via_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 1469 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1470 | .prepare = via_dig_playback_pcm_prepare, |
| 1471 | .cleanup = via_dig_playback_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1472 | }, |
| 1473 | }; |
| 1474 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1475 | static const struct hda_pcm_stream vt1708_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1476 | .substreams = 1, |
| 1477 | .channels_min = 2, |
| 1478 | .channels_max = 2, |
| 1479 | }; |
| 1480 | |
| 1481 | static int via_build_controls(struct hda_codec *codec) |
| 1482 | { |
| 1483 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1484 | struct snd_kcontrol *kctl; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1485 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1486 | int err, i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1487 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 1488 | if (spec->set_widgets_power_state) |
| 1489 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) |
| 1490 | return -ENOMEM; |
| 1491 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1492 | for (i = 0; i < spec->num_mixers; i++) { |
| 1493 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1494 | if (err < 0) |
| 1495 | return err; |
| 1496 | } |
| 1497 | |
| 1498 | if (spec->multiout.dig_out_nid) { |
| 1499 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1500 | spec->multiout.dig_out_nid, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1501 | spec->multiout.dig_out_nid); |
| 1502 | if (err < 0) |
| 1503 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1504 | err = snd_hda_create_spdif_share_sw(codec, |
| 1505 | &spec->multiout); |
| 1506 | if (err < 0) |
| 1507 | return err; |
| 1508 | spec->multiout.share_spdif = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1509 | } |
| 1510 | if (spec->dig_in_nid) { |
| 1511 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1512 | if (err < 0) |
| 1513 | return err; |
| 1514 | } |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1515 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1516 | /* assign Capture Source enums to NID */ |
| 1517 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1518 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 1519 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1520 | if (err < 0) |
| 1521 | return err; |
| 1522 | } |
| 1523 | |
| 1524 | /* other nid->control mapping */ |
| 1525 | for (i = 0; i < spec->num_mixers; i++) { |
| 1526 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1527 | if (knew->iface != NID_MAPPING) |
| 1528 | continue; |
| 1529 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1530 | if (kctl == NULL) |
| 1531 | continue; |
| 1532 | err = snd_hda_add_nid(codec, kctl, 0, |
| 1533 | knew->subdevice); |
| 1534 | } |
| 1535 | } |
| 1536 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1537 | /* init power states */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1538 | set_widgets_power_state(codec); |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1539 | analog_low_current_mode(codec, 1); |
| 1540 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1541 | via_free_kctls(codec); /* no longer needed */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | static int via_build_pcms(struct hda_codec *codec) |
| 1546 | { |
| 1547 | struct via_spec *spec = codec->spec; |
| 1548 | struct hda_pcm *info = spec->pcm_rec; |
| 1549 | |
| 1550 | codec->num_pcms = 1; |
| 1551 | codec->pcm_info = info; |
| 1552 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1553 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 1554 | "%s Analog", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1555 | info->name = spec->stream_name_analog; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1556 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 1557 | *(spec->stream_analog_playback); |
| 1558 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1559 | spec->multiout.dac_nids[0]; |
Takashi Iwai | 57307bf | 2011-06-18 10:58:49 +0200 | [diff] [blame^] | 1560 | if (!spec->multiout.hp_nid) |
| 1561 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1562 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); |
| 1563 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 1564 | |
| 1565 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 1566 | spec->multiout.max_channels; |
| 1567 | |
| 1568 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 1569 | codec->num_pcms++; |
| 1570 | info++; |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1571 | snprintf(spec->stream_name_digital, |
| 1572 | sizeof(spec->stream_name_digital), |
| 1573 | "%s Digital", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1574 | info->name = spec->stream_name_digital; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 1575 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1576 | if (spec->multiout.dig_out_nid) { |
| 1577 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 1578 | *(spec->stream_digital_playback); |
| 1579 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1580 | spec->multiout.dig_out_nid; |
| 1581 | } |
| 1582 | if (spec->dig_in_nid) { |
| 1583 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 1584 | *(spec->stream_digital_capture); |
| 1585 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 1586 | spec->dig_in_nid; |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | return 0; |
| 1591 | } |
| 1592 | |
| 1593 | static void via_free(struct hda_codec *codec) |
| 1594 | { |
| 1595 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1596 | |
| 1597 | if (!spec) |
| 1598 | return; |
| 1599 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1600 | via_free_kctls(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1601 | vt1708_stop_hp_work(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1602 | kfree(codec->spec); |
| 1603 | } |
| 1604 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1605 | /* mute/unmute outputs */ |
| 1606 | static void toggle_output_mutes(struct hda_codec *codec, int num_pins, |
| 1607 | hda_nid_t *pins, bool mute) |
| 1608 | { |
| 1609 | int i; |
| 1610 | for (i = 0; i < num_pins; i++) |
| 1611 | snd_hda_codec_write(codec, pins[i], 0, |
| 1612 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1613 | mute ? 0 : PIN_OUT); |
| 1614 | } |
| 1615 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1616 | /* mute internal speaker if HP is plugged */ |
| 1617 | static void via_hp_automute(struct hda_codec *codec) |
| 1618 | { |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1619 | unsigned int present = 0; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1620 | struct via_spec *spec = codec->spec; |
| 1621 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1622 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1623 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1624 | if (!spec->hp_independent_mode) |
| 1625 | toggle_output_mutes(codec, spec->autocfg.line_outs, |
| 1626 | spec->autocfg.line_out_pins, |
| 1627 | present); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1630 | /* mute mono out if HP or Line out is plugged */ |
| 1631 | static void via_mono_automute(struct hda_codec *codec) |
| 1632 | { |
| 1633 | unsigned int hp_present, lineout_present; |
| 1634 | struct via_spec *spec = codec->spec; |
| 1635 | |
| 1636 | if (spec->codec_type != VT1716S) |
| 1637 | return; |
| 1638 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1639 | lineout_present = snd_hda_jack_detect(codec, |
| 1640 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1641 | |
| 1642 | /* Mute Mono Out if Line Out is plugged */ |
| 1643 | if (lineout_present) { |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1644 | snd_hda_codec_write(codec, 0x2A, 0, |
| 1645 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1646 | lineout_present ? 0 : PIN_OUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1647 | return; |
| 1648 | } |
| 1649 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1650 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1651 | |
| 1652 | if (!spec->hp_independent_mode) |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1653 | snd_hda_codec_write(codec, 0x2A, 0, |
| 1654 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1655 | hp_present ? 0 : PIN_OUT); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1656 | } |
| 1657 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1658 | static void via_gpio_control(struct hda_codec *codec) |
| 1659 | { |
| 1660 | unsigned int gpio_data; |
| 1661 | unsigned int vol_counter; |
| 1662 | unsigned int vol; |
| 1663 | unsigned int master_vol; |
| 1664 | |
| 1665 | struct via_spec *spec = codec->spec; |
| 1666 | |
| 1667 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, |
| 1668 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; |
| 1669 | |
| 1670 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, |
| 1671 | 0xF84, 0) & 0x3F0000) >> 16; |
| 1672 | |
| 1673 | vol = vol_counter & 0x1F; |
| 1674 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, |
| 1675 | AC_VERB_GET_AMP_GAIN_MUTE, |
| 1676 | AC_AMP_GET_INPUT); |
| 1677 | |
| 1678 | if (gpio_data == 0x02) { |
| 1679 | /* unmute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1680 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1681 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1682 | PIN_OUT); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1683 | if (vol_counter & 0x20) { |
| 1684 | /* decrease volume */ |
| 1685 | if (vol > master_vol) |
| 1686 | vol = master_vol; |
| 1687 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, |
| 1688 | 0, HDA_AMP_VOLMASK, |
| 1689 | master_vol-vol); |
| 1690 | } else { |
| 1691 | /* increase volume */ |
| 1692 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, |
| 1693 | HDA_AMP_VOLMASK, |
| 1694 | ((master_vol+vol) > 0x2A) ? 0x2A : |
| 1695 | (master_vol+vol)); |
| 1696 | } |
| 1697 | } else if (!(gpio_data & 0x02)) { |
| 1698 | /* mute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1699 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1700 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1701 | 0); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1705 | /* mute Internal-Speaker if HP is plugged */ |
| 1706 | static void via_speaker_automute(struct hda_codec *codec) |
| 1707 | { |
| 1708 | unsigned int hp_present; |
| 1709 | struct via_spec *spec = codec->spec; |
| 1710 | |
Lydia Wang | 27439ce | 2011-03-24 12:40:10 +0800 | [diff] [blame] | 1711 | if (!VT2002P_COMPATIBLE(spec)) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1712 | return; |
| 1713 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1714 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1715 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1716 | if (!spec->hp_independent_mode) |
| 1717 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1718 | spec->autocfg.speaker_pins, |
| 1719 | hp_present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | /* mute line-out and internal speaker if HP is plugged */ |
| 1723 | static void via_hp_bind_automute(struct hda_codec *codec) |
| 1724 | { |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1725 | int present; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1726 | struct via_spec *spec = codec->spec; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1727 | |
| 1728 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) |
| 1729 | return; |
| 1730 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1731 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
| 1732 | if (!spec->hp_independent_mode) |
| 1733 | toggle_output_mutes(codec, spec->autocfg.line_outs, |
| 1734 | spec->autocfg.line_out_pins, |
| 1735 | present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1736 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1737 | if (!present) |
| 1738 | present = snd_hda_jack_detect(codec, |
| 1739 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1740 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1741 | /* Speakers */ |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1742 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1743 | spec->autocfg.speaker_pins, |
| 1744 | present); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1748 | /* unsolicited event for jack sensing */ |
| 1749 | static void via_unsol_event(struct hda_codec *codec, |
| 1750 | unsigned int res) |
| 1751 | { |
| 1752 | res >>= 26; |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1753 | |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 1754 | if (res & VIA_JACK_EVENT) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1755 | set_widgets_power_state(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1756 | |
| 1757 | res &= ~VIA_JACK_EVENT; |
| 1758 | |
| 1759 | if (res == VIA_HP_EVENT) |
| 1760 | via_hp_automute(codec); |
| 1761 | else if (res == VIA_GPIO_EVENT) |
| 1762 | via_gpio_control(codec); |
| 1763 | else if (res == VIA_MONO_EVENT) |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1764 | via_mono_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1765 | else if (res == VIA_SPEAKER_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1766 | via_speaker_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1767 | else if (res == VIA_BIND_HP_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1768 | via_hp_bind_automute(codec); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1769 | } |
| 1770 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1771 | static int via_init(struct hda_codec *codec) |
| 1772 | { |
| 1773 | struct via_spec *spec = codec->spec; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1774 | int i; |
| 1775 | for (i = 0; i < spec->num_iverbs; i++) |
| 1776 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 1777 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1778 | /* Lydia Add for EAPD enable */ |
| 1779 | if (!spec->dig_in_nid) { /* No Digital In connection */ |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 1780 | if (spec->dig_in_pin) { |
| 1781 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1782 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 1783 | PIN_OUT); |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 1784 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1785 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
| 1786 | } |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 1787 | } else /* enable SPDIF-input pin */ |
| 1788 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, |
| 1789 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1790 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1791 | /* assign slave outs */ |
| 1792 | if (spec->slave_dig_outs[0]) |
| 1793 | codec->slave_dig_outs = spec->slave_dig_outs; |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1794 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1795 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1798 | #ifdef SND_HDA_NEEDS_RESUME |
| 1799 | static int via_suspend(struct hda_codec *codec, pm_message_t state) |
| 1800 | { |
| 1801 | struct via_spec *spec = codec->spec; |
| 1802 | vt1708_stop_hp_work(spec); |
| 1803 | return 0; |
| 1804 | } |
| 1805 | #endif |
| 1806 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1807 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1808 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 1809 | { |
| 1810 | struct via_spec *spec = codec->spec; |
| 1811 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 1812 | } |
| 1813 | #endif |
| 1814 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1815 | /* |
| 1816 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1817 | static const struct hda_codec_ops via_patch_ops = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1818 | .build_controls = via_build_controls, |
| 1819 | .build_pcms = via_build_pcms, |
| 1820 | .init = via_init, |
| 1821 | .free = via_free, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1822 | #ifdef SND_HDA_NEEDS_RESUME |
| 1823 | .suspend = via_suspend, |
| 1824 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1825 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1826 | .check_power_status = via_check_power_status, |
| 1827 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1828 | }; |
| 1829 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1830 | 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] | 1831 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1832 | struct via_spec *spec = codec->spec; |
| 1833 | int i; |
| 1834 | |
| 1835 | for (i = 0; i < spec->multiout.num_dacs; i++) { |
| 1836 | if (spec->multiout.dac_nids[i] == dac) |
| 1837 | return false; |
| 1838 | } |
| 1839 | if (spec->multiout.hp_nid == dac) |
| 1840 | return false; |
| 1841 | return true; |
| 1842 | } |
| 1843 | |
| 1844 | static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
| 1845 | hda_nid_t target_dac, struct nid_path *path, |
| 1846 | int depth, int wid_type) |
| 1847 | { |
| 1848 | hda_nid_t conn[8]; |
| 1849 | int i, nums; |
| 1850 | |
| 1851 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); |
| 1852 | for (i = 0; i < nums; i++) { |
| 1853 | if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) |
| 1854 | continue; |
| 1855 | if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { |
| 1856 | path->path[depth] = conn[i]; |
| 1857 | path->idx[depth] = i; |
| 1858 | path->depth = ++depth; |
| 1859 | return true; |
| 1860 | } |
| 1861 | } |
| 1862 | if (depth > 4) |
| 1863 | return false; |
| 1864 | for (i = 0; i < nums; i++) { |
| 1865 | unsigned int type; |
| 1866 | type = get_wcaps_type(get_wcaps(codec, conn[i])); |
| 1867 | if (type == AC_WID_AUD_OUT || |
| 1868 | (wid_type != -1 && type != wid_type)) |
| 1869 | continue; |
| 1870 | if (parse_output_path(codec, conn[i], target_dac, |
| 1871 | path, depth + 1, AC_WID_AUD_SEL)) { |
| 1872 | path->path[depth] = conn[i]; |
| 1873 | path->idx[depth] = i; |
| 1874 | return true; |
| 1875 | } |
| 1876 | } |
| 1877 | return false; |
| 1878 | } |
| 1879 | |
| 1880 | static int via_auto_fill_dac_nids(struct hda_codec *codec) |
| 1881 | { |
| 1882 | struct via_spec *spec = codec->spec; |
| 1883 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1884 | int i; |
| 1885 | hda_nid_t nid; |
| 1886 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1887 | spec->multiout.dac_nids = spec->private_dac_nids; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1888 | spec->multiout.num_dacs = cfg->line_outs; |
| 1889 | for (i = 0; i < cfg->line_outs; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1890 | nid = cfg->line_out_pins[i]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1891 | if (!nid) |
| 1892 | continue; |
| 1893 | if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1)) |
| 1894 | spec->private_dac_nids[i] = |
| 1895 | spec->out_path[i].path[spec->out_path[i].depth - 1]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1896 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1897 | return 0; |
| 1898 | } |
| 1899 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1900 | static int create_ch_ctls(struct hda_codec *codec, const char *pfx, |
| 1901 | hda_nid_t pin, hda_nid_t dac, int chs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1902 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1903 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1904 | char name[32]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1905 | hda_nid_t nid; |
| 1906 | int err; |
| 1907 | |
| 1908 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
| 1909 | nid = dac; |
| 1910 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
| 1911 | nid = pin; |
| 1912 | else |
| 1913 | nid = 0; |
| 1914 | if (nid) { |
| 1915 | sprintf(name, "%s Playback Volume", pfx); |
| 1916 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 1917 | HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT)); |
| 1918 | if (err < 0) |
| 1919 | return err; |
| 1920 | } |
| 1921 | |
| 1922 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 1923 | nid = dac; |
| 1924 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
| 1925 | nid = pin; |
| 1926 | else |
| 1927 | nid = 0; |
| 1928 | if (nid) { |
| 1929 | sprintf(name, "%s Playback Switch", pfx); |
| 1930 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 1931 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
| 1932 | if (err < 0) |
| 1933 | return err; |
| 1934 | } |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
| 1939 | hda_nid_t nid); |
| 1940 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1941 | static void mangle_smart51(struct hda_codec *codec) |
| 1942 | { |
| 1943 | struct via_spec *spec = codec->spec; |
| 1944 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 1945 | int i; |
| 1946 | |
| 1947 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1948 | if (!is_smart51_pins(codec, cfg->inputs[i].pin)) |
| 1949 | continue; |
| 1950 | spec->can_smart51 = 1; |
| 1951 | cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; |
| 1952 | if (cfg->line_outs == 3) |
| 1953 | break; |
| 1954 | } |
| 1955 | } |
| 1956 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1957 | /* add playback controls from the parsed DAC table */ |
| 1958 | static int via_auto_create_multi_out_ctls(struct hda_codec *codec) |
| 1959 | { |
| 1960 | struct via_spec *spec = codec->spec; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1961 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1962 | static const char * const chname[4] = { |
| 1963 | "Front", "Surround", "C/LFE", "Side" |
| 1964 | }; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1965 | int i, idx, err; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1966 | int old_line_outs; |
| 1967 | |
| 1968 | /* check smart51 */ |
| 1969 | old_line_outs = cfg->line_outs; |
| 1970 | if (cfg->line_outs == 1) |
| 1971 | mangle_smart51(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1972 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1973 | for (i = 0; i < cfg->line_outs; i++) { |
| 1974 | hda_nid_t pin, dac; |
| 1975 | pin = cfg->line_out_pins[i]; |
| 1976 | dac = spec->multiout.dac_nids[i]; |
| 1977 | if (!pin || !dac) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1978 | continue; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1979 | if (i == AUTO_SEQ_CENLFE) { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1980 | err = create_ch_ctls(codec, "Center", pin, dac, 1); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1981 | if (err < 0) |
| 1982 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1983 | err = create_ch_ctls(codec, "LFE", pin, dac, 2); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1984 | if (err < 0) |
| 1985 | return err; |
| 1986 | } else { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1987 | err = create_ch_ctls(codec, chname[i], pin, dac, 3); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1988 | if (err < 0) |
| 1989 | return err; |
| 1990 | } |
| 1991 | } |
| 1992 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1993 | idx = get_connection_index(codec, spec->aa_mix_nid, |
| 1994 | spec->multiout.dac_nids[0]); |
| 1995 | if (idx >= 0) { |
| 1996 | /* add control to mixer */ |
| 1997 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 1998 | "PCM Playback Volume", |
| 1999 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 2000 | idx, HDA_INPUT)); |
| 2001 | if (err < 0) |
| 2002 | return err; |
| 2003 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2004 | "PCM Playback Switch", |
| 2005 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 2006 | idx, HDA_INPUT)); |
| 2007 | if (err < 0) |
| 2008 | return err; |
| 2009 | } |
| 2010 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2011 | cfg->line_outs = old_line_outs; |
| 2012 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2013 | return 0; |
| 2014 | } |
| 2015 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2016 | static void create_hp_imux(struct via_spec *spec) |
| 2017 | { |
| 2018 | int i; |
| 2019 | struct hda_input_mux *imux = &spec->private_imux[1]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 2020 | static const char * const texts[] = { "OFF", "ON", NULL}; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2021 | |
| 2022 | /* for hp mode select */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2023 | for (i = 0; texts[i]; i++) |
| 2024 | snd_hda_add_imux_item(imux, texts[i], i, NULL); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2025 | |
| 2026 | spec->hp_mux = &spec->private_imux[1]; |
| 2027 | } |
| 2028 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2029 | 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] | 2030 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2031 | struct via_spec *spec = codec->spec; |
| 2032 | hda_nid_t dac = 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2033 | int err; |
| 2034 | |
| 2035 | if (!pin) |
| 2036 | return 0; |
| 2037 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2038 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
| 2039 | &spec->hp_dep_path, 0, -1)) |
| 2040 | return 0; |
| 2041 | if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { |
| 2042 | dac = spec->hp_path.path[spec->hp_path.depth - 1]; |
| 2043 | spec->multiout.hp_nid = dac; |
| 2044 | spec->hp_independent_mode_index = |
| 2045 | spec->hp_path.idx[spec->hp_path.depth - 1]; |
| 2046 | create_hp_imux(spec); |
| 2047 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2048 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2049 | err = create_ch_ctls(codec, "Headphone", pin, dac, 3); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2050 | if (err < 0) |
| 2051 | return err; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2052 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2053 | return 0; |
| 2054 | } |
| 2055 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2056 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
| 2057 | hda_nid_t nid) |
| 2058 | { |
| 2059 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; |
| 2060 | int i, nums; |
| 2061 | |
| 2062 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); |
| 2063 | for (i = 0; i < nums; i++) |
| 2064 | if (conn[i] == nid) |
| 2065 | return i; |
| 2066 | return -1; |
| 2067 | } |
| 2068 | |
| 2069 | /* look for ADCs */ |
| 2070 | static int via_fill_adcs(struct hda_codec *codec) |
| 2071 | { |
| 2072 | struct via_spec *spec = codec->spec; |
| 2073 | hda_nid_t nid = codec->start_nid; |
| 2074 | int i; |
| 2075 | |
| 2076 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2077 | unsigned int wcaps = get_wcaps(codec, nid); |
| 2078 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 2079 | continue; |
| 2080 | if (wcaps & AC_WCAP_DIGITAL) |
| 2081 | continue; |
| 2082 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 2083 | continue; |
| 2084 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) |
| 2085 | return -ENOMEM; |
| 2086 | spec->adc_nids[spec->num_adc_nids++] = nid; |
| 2087 | } |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | static int get_mux_nids(struct hda_codec *codec); |
| 2092 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2093 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2094 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec, |
| 2095 | const struct auto_pin_cfg *cfg) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2096 | { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2097 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2098 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2099 | int i, err, idx, idx2, type, type_idx = 0; |
| 2100 | hda_nid_t cap_nid; |
| 2101 | hda_nid_t pin_idxs[8]; |
| 2102 | int num_idxs; |
| 2103 | |
| 2104 | err = via_fill_adcs(codec); |
| 2105 | if (err < 0) |
| 2106 | return err; |
| 2107 | err = get_mux_nids(codec); |
| 2108 | if (err < 0) |
| 2109 | return err; |
| 2110 | cap_nid = spec->mux_nids[0]; |
| 2111 | |
| 2112 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, |
| 2113 | ARRAY_SIZE(pin_idxs)); |
| 2114 | if (num_idxs <= 0) |
| 2115 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2116 | |
| 2117 | /* for internal loopback recording select */ |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2118 | for (idx = 0; idx < num_idxs; idx++) { |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2119 | if (pin_idxs[idx] == spec->aa_mix_nid) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2120 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2121 | break; |
| 2122 | } |
| 2123 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2124 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2125 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2126 | const char *label; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2127 | type = cfg->inputs[i].type; |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2128 | for (idx = 0; idx < num_idxs; idx++) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2129 | if (pin_idxs[idx] == cfg->inputs[i].pin) |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2130 | break; |
| 2131 | if (idx >= num_idxs) |
| 2132 | continue; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2133 | if (i > 0 && type == cfg->inputs[i - 1].type) |
| 2134 | type_idx++; |
| 2135 | else |
| 2136 | type_idx = 0; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2137 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2138 | idx2 = get_connection_index(codec, spec->aa_mix_nid, |
| 2139 | pin_idxs[idx]); |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2140 | if (idx2 >= 0) |
Lydia Wang | 1692228 | 2011-03-22 16:24:10 +0800 | [diff] [blame] | 2141 | err = via_new_analog_input(spec, label, type_idx, |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2142 | idx2, spec->aa_mix_nid); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2143 | if (err < 0) |
| 2144 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2145 | snd_hda_add_imux_item(imux, label, idx, NULL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2146 | } |
| 2147 | return 0; |
| 2148 | } |
| 2149 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2150 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2151 | static const struct hda_amp_list vt1708_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2152 | { 0x17, HDA_INPUT, 1 }, |
| 2153 | { 0x17, HDA_INPUT, 2 }, |
| 2154 | { 0x17, HDA_INPUT, 3 }, |
| 2155 | { 0x17, HDA_INPUT, 4 }, |
| 2156 | { } /* end */ |
| 2157 | }; |
| 2158 | #endif |
| 2159 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2160 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 2161 | { |
| 2162 | unsigned int def_conf; |
| 2163 | unsigned char seqassoc; |
| 2164 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 2165 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2166 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 2167 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 2168 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 2169 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 2170 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 2171 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | return; |
| 2175 | } |
| 2176 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2177 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2178 | struct snd_ctl_elem_value *ucontrol) |
| 2179 | { |
| 2180 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2181 | struct via_spec *spec = codec->spec; |
| 2182 | |
| 2183 | if (spec->codec_type != VT1708) |
| 2184 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2185 | spec->vt1708_jack_detect = |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2186 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2187 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2188 | return 0; |
| 2189 | } |
| 2190 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2191 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2192 | struct snd_ctl_elem_value *ucontrol) |
| 2193 | { |
| 2194 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2195 | struct via_spec *spec = codec->spec; |
| 2196 | int change; |
| 2197 | |
| 2198 | if (spec->codec_type != VT1708) |
| 2199 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2200 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2201 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2202 | == !spec->vt1708_jack_detect; |
| 2203 | if (spec->vt1708_jack_detect) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2204 | mute_aa_path(codec, 1); |
| 2205 | notify_aa_path_ctls(codec); |
| 2206 | } |
| 2207 | return change; |
| 2208 | } |
| 2209 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2210 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
| 2211 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2212 | .name = "Jack Detect", |
| 2213 | .count = 1, |
| 2214 | .info = snd_ctl_boolean_mono_info, |
| 2215 | .get = vt1708_jack_detect_get, |
| 2216 | .put = vt1708_jack_detect_put, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2217 | }; |
| 2218 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2219 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
| 2220 | { |
| 2221 | struct via_spec *spec = codec->spec; |
| 2222 | int err; |
| 2223 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2224 | /* Add HP and CD pin config connect bit re-config action */ |
| 2225 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 2226 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 2227 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2228 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2229 | if (err < 0) |
| 2230 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2231 | err = via_auto_fill_dac_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2232 | if (err < 0) |
| 2233 | return err; |
| 2234 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2235 | return 0; /* can't find valid BIOS pin config */ |
| 2236 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2237 | err = via_auto_create_multi_out_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2238 | if (err < 0) |
| 2239 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2240 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2241 | if (err < 0) |
| 2242 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2243 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2244 | if (err < 0) |
| 2245 | return err; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2246 | /* add jack detect on/off control */ |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2247 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
| 2248 | return -ENOMEM; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2249 | |
| 2250 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2251 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2252 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2253 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2254 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2255 | if (spec->autocfg.dig_in_pin) |
| 2256 | spec->dig_in_nid = VT1708_DIGIN_NID; |
| 2257 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2258 | if (spec->kctls.list) |
| 2259 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2260 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2261 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2262 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2263 | spec->input_mux = &spec->private_imux[0]; |
| 2264 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2265 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2266 | via_hp_build(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2267 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2268 | err = via_smart51_build(codec); |
| 2269 | if (err < 0) |
| 2270 | return err; |
| 2271 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2272 | return 1; |
| 2273 | } |
| 2274 | |
| 2275 | /* init callback for auto-configuration model -- overriding the default init */ |
| 2276 | static int via_auto_init(struct hda_codec *codec) |
| 2277 | { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2278 | struct via_spec *spec = codec->spec; |
| 2279 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2280 | via_init(codec); |
| 2281 | via_auto_init_multi_out(codec); |
| 2282 | via_auto_init_hp_out(codec); |
| 2283 | via_auto_init_analog_input(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 2284 | |
| 2285 | if (VT2002P_COMPATIBLE(spec)) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2286 | via_hp_bind_automute(codec); |
| 2287 | } else { |
| 2288 | via_hp_automute(codec); |
| 2289 | via_speaker_automute(codec); |
| 2290 | } |
| 2291 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2292 | return 0; |
| 2293 | } |
| 2294 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2295 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
| 2296 | { |
| 2297 | struct via_spec *spec = container_of(work, struct via_spec, |
| 2298 | vt1708_hp_work.work); |
| 2299 | if (spec->codec_type != VT1708) |
| 2300 | return; |
| 2301 | /* if jack state toggled */ |
| 2302 | if (spec->vt1708_hp_present |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2303 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2304 | spec->vt1708_hp_present ^= 1; |
| 2305 | via_hp_automute(spec->codec); |
| 2306 | } |
| 2307 | vt1708_start_hp_work(spec); |
| 2308 | } |
| 2309 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2310 | static int get_mux_nids(struct hda_codec *codec) |
| 2311 | { |
| 2312 | struct via_spec *spec = codec->spec; |
| 2313 | hda_nid_t nid, conn[8]; |
| 2314 | unsigned int type; |
| 2315 | int i, n; |
| 2316 | |
| 2317 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2318 | nid = spec->adc_nids[i]; |
| 2319 | while (nid) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2320 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2321 | if (type == AC_WID_PIN) |
| 2322 | break; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2323 | n = snd_hda_get_connections(codec, nid, conn, |
| 2324 | ARRAY_SIZE(conn)); |
| 2325 | if (n <= 0) |
| 2326 | break; |
| 2327 | if (n > 1) { |
| 2328 | spec->mux_nids[i] = nid; |
| 2329 | break; |
| 2330 | } |
| 2331 | nid = conn[0]; |
| 2332 | } |
| 2333 | } |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2334 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2335 | } |
| 2336 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2337 | static int patch_vt1708(struct hda_codec *codec) |
| 2338 | { |
| 2339 | struct via_spec *spec; |
| 2340 | int err; |
| 2341 | |
| 2342 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2343 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2344 | if (spec == NULL) |
| 2345 | return -ENOMEM; |
| 2346 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2347 | spec->aa_mix_nid = 0x17; |
| 2348 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2349 | /* automatic parse from the BIOS config */ |
| 2350 | err = vt1708_parse_auto_config(codec); |
| 2351 | if (err < 0) { |
| 2352 | via_free(codec); |
| 2353 | return err; |
| 2354 | } else if (!err) { |
| 2355 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 2356 | "from BIOS. Using genenic mode...\n"); |
| 2357 | } |
| 2358 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2359 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2360 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 2361 | /* disable 32bit format on VT1708 */ |
| 2362 | if (codec->vendor_id == 0x11061708) |
| 2363 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2364 | spec->stream_analog_capture = &vt1708_pcm_analog_capture; |
| 2365 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2366 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; |
| 2367 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; |
| 2368 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2369 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2370 | spec->mixers[spec->num_mixers] = vt1708_capture_mixer; |
| 2371 | spec->num_mixers++; |
| 2372 | } |
| 2373 | |
| 2374 | codec->patch_ops = via_patch_ops; |
| 2375 | |
| 2376 | codec->patch_ops.init = via_auto_init; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2377 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2378 | spec->loopback.amplist = vt1708_loopbacks; |
| 2379 | #endif |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2380 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2381 | return 0; |
| 2382 | } |
| 2383 | |
| 2384 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2385 | static const struct snd_kcontrol_new vt1709_capture_mixer[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2386 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), |
| 2387 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), |
| 2388 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), |
| 2389 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), |
| 2390 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), |
| 2391 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), |
| 2392 | { |
| 2393 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2394 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2395 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2396 | */ |
| 2397 | /* .name = "Capture Source", */ |
| 2398 | .name = "Input Source", |
| 2399 | .count = 1, |
| 2400 | .info = via_mux_enum_info, |
| 2401 | .get = via_mux_enum_get, |
| 2402 | .put = via_mux_enum_put, |
| 2403 | }, |
| 2404 | { } /* end */ |
| 2405 | }; |
| 2406 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2407 | static const struct hda_verb vt1709_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2408 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2409 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2410 | { } |
| 2411 | }; |
| 2412 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2413 | /* |
| 2414 | * generic initialization of ADC, input mixers and output mixers |
| 2415 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2416 | static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2417 | /* |
| 2418 | * Unmute ADC0-2 and set the default input to mic-in |
| 2419 | */ |
| 2420 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2421 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2422 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2423 | |
| 2424 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2425 | /* 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] | 2426 | * mixer widget |
| 2427 | */ |
| 2428 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2429 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2430 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2431 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2432 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2433 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2434 | |
| 2435 | /* |
| 2436 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2437 | */ |
| 2438 | /* set vol=0 to output mixers */ |
| 2439 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2440 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2441 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2442 | |
| 2443 | /* |
| 2444 | * Unmute PW3 and PW4 |
| 2445 | */ |
| 2446 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2447 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2448 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2449 | /* Set input of PW4 as MW0 */ |
| 2450 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2451 | /* PW9 Output enable */ |
| 2452 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2453 | { } |
| 2454 | }; |
| 2455 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2456 | static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2457 | .substreams = 1, |
| 2458 | .channels_min = 2, |
| 2459 | .channels_max = 10, |
| 2460 | .nid = 0x10, /* NID to query formats and rates */ |
| 2461 | .ops = { |
| 2462 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 2463 | .prepare = via_playback_multi_pcm_prepare, |
| 2464 | .cleanup = via_playback_multi_pcm_cleanup, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2465 | }, |
| 2466 | }; |
| 2467 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2468 | static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2469 | .substreams = 1, |
| 2470 | .channels_min = 2, |
| 2471 | .channels_max = 6, |
| 2472 | .nid = 0x10, /* NID to query formats and rates */ |
| 2473 | .ops = { |
| 2474 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 2475 | .prepare = via_playback_multi_pcm_prepare, |
| 2476 | .cleanup = via_playback_multi_pcm_cleanup, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2477 | }, |
| 2478 | }; |
| 2479 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2480 | static const struct hda_pcm_stream vt1709_pcm_analog_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2481 | .substreams = 2, |
| 2482 | .channels_min = 2, |
| 2483 | .channels_max = 2, |
| 2484 | .nid = 0x14, /* NID to query formats and rates */ |
| 2485 | .ops = { |
| 2486 | .prepare = via_capture_pcm_prepare, |
| 2487 | .cleanup = via_capture_pcm_cleanup |
| 2488 | }, |
| 2489 | }; |
| 2490 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2491 | static const struct hda_pcm_stream vt1709_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2492 | .substreams = 1, |
| 2493 | .channels_min = 2, |
| 2494 | .channels_max = 2, |
| 2495 | /* NID is set in via_build_pcms */ |
| 2496 | .ops = { |
| 2497 | .open = via_dig_playback_pcm_open, |
| 2498 | .close = via_dig_playback_pcm_close |
| 2499 | }, |
| 2500 | }; |
| 2501 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2502 | static const struct hda_pcm_stream vt1709_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2503 | .substreams = 1, |
| 2504 | .channels_min = 2, |
| 2505 | .channels_max = 2, |
| 2506 | }; |
| 2507 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2508 | static int vt1709_parse_auto_config(struct hda_codec *codec) |
| 2509 | { |
| 2510 | struct via_spec *spec = codec->spec; |
| 2511 | int err; |
| 2512 | |
| 2513 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2514 | if (err < 0) |
| 2515 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2516 | err = via_auto_fill_dac_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2517 | if (err < 0) |
| 2518 | return err; |
| 2519 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2520 | return 0; /* can't find valid BIOS pin config */ |
| 2521 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2522 | err = via_auto_create_multi_out_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2523 | if (err < 0) |
| 2524 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2525 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2526 | if (err < 0) |
| 2527 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2528 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2529 | if (err < 0) |
| 2530 | return err; |
| 2531 | |
| 2532 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2533 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2534 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2535 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2536 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2537 | if (spec->autocfg.dig_in_pin) |
| 2538 | spec->dig_in_nid = VT1709_DIGIN_NID; |
| 2539 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2540 | if (spec->kctls.list) |
| 2541 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2542 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2543 | spec->input_mux = &spec->private_imux[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2544 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2545 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2546 | via_hp_build(codec); |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2547 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2548 | err = via_smart51_build(codec); |
| 2549 | if (err < 0) |
| 2550 | return err; |
| 2551 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2552 | return 1; |
| 2553 | } |
| 2554 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2555 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2556 | static const struct hda_amp_list vt1709_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2557 | { 0x18, HDA_INPUT, 1 }, |
| 2558 | { 0x18, HDA_INPUT, 2 }, |
| 2559 | { 0x18, HDA_INPUT, 3 }, |
| 2560 | { 0x18, HDA_INPUT, 4 }, |
| 2561 | { } /* end */ |
| 2562 | }; |
| 2563 | #endif |
| 2564 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2565 | static int patch_vt1709_10ch(struct hda_codec *codec) |
| 2566 | { |
| 2567 | struct via_spec *spec; |
| 2568 | int err; |
| 2569 | |
| 2570 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2571 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2572 | if (spec == NULL) |
| 2573 | return -ENOMEM; |
| 2574 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2575 | spec->aa_mix_nid = 0x18; |
| 2576 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2577 | err = vt1709_parse_auto_config(codec); |
| 2578 | if (err < 0) { |
| 2579 | via_free(codec); |
| 2580 | return err; |
| 2581 | } else if (!err) { |
| 2582 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 2583 | "Using genenic mode...\n"); |
| 2584 | } |
| 2585 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2586 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
| 2587 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2588 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2589 | spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; |
| 2590 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; |
| 2591 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2592 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
| 2593 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
| 2594 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2595 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2596 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 2597 | spec->num_mixers++; |
| 2598 | } |
| 2599 | |
| 2600 | codec->patch_ops = via_patch_ops; |
| 2601 | |
| 2602 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2603 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2604 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2605 | spec->loopback.amplist = vt1709_loopbacks; |
| 2606 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2607 | |
| 2608 | return 0; |
| 2609 | } |
| 2610 | /* |
| 2611 | * generic initialization of ADC, input mixers and output mixers |
| 2612 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2613 | static const struct hda_verb vt1709_6ch_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2614 | /* |
| 2615 | * Unmute ADC0-2 and set the default input to mic-in |
| 2616 | */ |
| 2617 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2618 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2619 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2620 | |
| 2621 | |
| 2622 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2623 | * mixer widget |
| 2624 | */ |
| 2625 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2626 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2627 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2628 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2629 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2630 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2631 | |
| 2632 | /* |
| 2633 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2634 | */ |
| 2635 | /* set vol=0 to output mixers */ |
| 2636 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2637 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2638 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2639 | |
| 2640 | /* |
| 2641 | * Unmute PW3 and PW4 |
| 2642 | */ |
| 2643 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2644 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2645 | |
| 2646 | /* Set input of PW4 as MW0 */ |
| 2647 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2648 | /* PW9 Output enable */ |
| 2649 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2650 | { } |
| 2651 | }; |
| 2652 | |
| 2653 | static int patch_vt1709_6ch(struct hda_codec *codec) |
| 2654 | { |
| 2655 | struct via_spec *spec; |
| 2656 | int err; |
| 2657 | |
| 2658 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2659 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2660 | if (spec == NULL) |
| 2661 | return -ENOMEM; |
| 2662 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2663 | spec->aa_mix_nid = 0x18; |
| 2664 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2665 | err = vt1709_parse_auto_config(codec); |
| 2666 | if (err < 0) { |
| 2667 | via_free(codec); |
| 2668 | return err; |
| 2669 | } else if (!err) { |
| 2670 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 2671 | "Using genenic mode...\n"); |
| 2672 | } |
| 2673 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2674 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
| 2675 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2676 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2677 | spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; |
| 2678 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; |
| 2679 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2680 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
| 2681 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
| 2682 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2683 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2684 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 2685 | spec->num_mixers++; |
| 2686 | } |
| 2687 | |
| 2688 | codec->patch_ops = via_patch_ops; |
| 2689 | |
| 2690 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2691 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2692 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2693 | spec->loopback.amplist = vt1709_loopbacks; |
| 2694 | #endif |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2695 | return 0; |
| 2696 | } |
| 2697 | |
| 2698 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2699 | static const struct snd_kcontrol_new vt1708B_capture_mixer[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2700 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 2701 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 2702 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 2703 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 2704 | { |
| 2705 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2706 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2707 | * So call somewhat different.. |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2708 | */ |
| 2709 | /* .name = "Capture Source", */ |
| 2710 | .name = "Input Source", |
| 2711 | .count = 1, |
| 2712 | .info = via_mux_enum_info, |
| 2713 | .get = via_mux_enum_get, |
| 2714 | .put = via_mux_enum_put, |
| 2715 | }, |
| 2716 | { } /* end */ |
| 2717 | }; |
| 2718 | /* |
| 2719 | * generic initialization of ADC, input mixers and output mixers |
| 2720 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2721 | static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2722 | /* |
| 2723 | * Unmute ADC0-1 and set the default input to mic-in |
| 2724 | */ |
| 2725 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2726 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2727 | |
| 2728 | |
| 2729 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2730 | * mixer widget |
| 2731 | */ |
| 2732 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2733 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2734 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2735 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2736 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2737 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2738 | |
| 2739 | /* |
| 2740 | * Set up output mixers |
| 2741 | */ |
| 2742 | /* set vol=0 to output mixers */ |
| 2743 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2744 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2745 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2746 | |
| 2747 | /* Setup default input to PW4 */ |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2748 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2749 | /* PW9 Output enable */ |
| 2750 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2751 | /* PW10 Input enable */ |
| 2752 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 2753 | { } |
| 2754 | }; |
| 2755 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2756 | static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2757 | /* |
| 2758 | * Unmute ADC0-1 and set the default input to mic-in |
| 2759 | */ |
| 2760 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2761 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2762 | |
| 2763 | |
| 2764 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2765 | * mixer widget |
| 2766 | */ |
| 2767 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2768 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2769 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2770 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2771 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2772 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2773 | |
| 2774 | /* |
| 2775 | * Set up output mixers |
| 2776 | */ |
| 2777 | /* set vol=0 to output mixers */ |
| 2778 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2779 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2780 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2781 | |
| 2782 | /* Setup default input of PW4 to MW0 */ |
| 2783 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2784 | /* PW9 Output enable */ |
| 2785 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2786 | /* PW10 Input enable */ |
| 2787 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 2788 | { } |
| 2789 | }; |
| 2790 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2791 | static const struct hda_verb vt1708B_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2792 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2793 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2794 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2795 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2796 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2797 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2798 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2799 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2800 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2801 | { } |
| 2802 | }; |
| 2803 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 2804 | static int via_pcm_open_close(struct hda_pcm_stream *hinfo, |
| 2805 | struct hda_codec *codec, |
| 2806 | struct snd_pcm_substream *substream) |
| 2807 | { |
| 2808 | int idle = substream->pstr->substream_opened == 1 |
| 2809 | && substream->ref_count == 0; |
| 2810 | |
| 2811 | analog_low_current_mode(codec, idle); |
| 2812 | return 0; |
| 2813 | } |
| 2814 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2815 | static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2816 | .substreams = 2, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2817 | .channels_min = 2, |
| 2818 | .channels_max = 8, |
| 2819 | .nid = 0x10, /* NID to query formats and rates */ |
| 2820 | .ops = { |
| 2821 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2822 | .prepare = via_playback_multi_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 2823 | .cleanup = via_playback_multi_pcm_cleanup, |
| 2824 | .close = via_pcm_open_close |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2825 | }, |
| 2826 | }; |
| 2827 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2828 | static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2829 | .substreams = 2, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2830 | .channels_min = 2, |
| 2831 | .channels_max = 4, |
| 2832 | .nid = 0x10, /* NID to query formats and rates */ |
| 2833 | .ops = { |
| 2834 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2835 | .prepare = via_playback_multi_pcm_prepare, |
| 2836 | .cleanup = via_playback_multi_pcm_cleanup |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2837 | }, |
| 2838 | }; |
| 2839 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2840 | static const struct hda_pcm_stream vt1708B_pcm_analog_capture = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2841 | .substreams = 2, |
| 2842 | .channels_min = 2, |
| 2843 | .channels_max = 2, |
| 2844 | .nid = 0x13, /* NID to query formats and rates */ |
| 2845 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 2846 | .open = via_pcm_open_close, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2847 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 2848 | .cleanup = via_capture_pcm_cleanup, |
| 2849 | .close = via_pcm_open_close |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2850 | }, |
| 2851 | }; |
| 2852 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2853 | static const struct hda_pcm_stream vt1708B_pcm_digital_playback = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2854 | .substreams = 1, |
| 2855 | .channels_min = 2, |
| 2856 | .channels_max = 2, |
| 2857 | /* NID is set in via_build_pcms */ |
| 2858 | .ops = { |
| 2859 | .open = via_dig_playback_pcm_open, |
| 2860 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 2861 | .prepare = via_dig_playback_pcm_prepare, |
| 2862 | .cleanup = via_dig_playback_pcm_cleanup |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2863 | }, |
| 2864 | }; |
| 2865 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2866 | static const struct hda_pcm_stream vt1708B_pcm_digital_capture = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2867 | .substreams = 1, |
| 2868 | .channels_min = 2, |
| 2869 | .channels_max = 2, |
| 2870 | }; |
| 2871 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2872 | static int vt1708B_parse_auto_config(struct hda_codec *codec) |
| 2873 | { |
| 2874 | struct via_spec *spec = codec->spec; |
| 2875 | int err; |
| 2876 | |
| 2877 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2878 | if (err < 0) |
| 2879 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2880 | err = via_auto_fill_dac_nids(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2881 | if (err < 0) |
| 2882 | return err; |
| 2883 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2884 | return 0; /* can't find valid BIOS pin config */ |
| 2885 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2886 | err = via_auto_create_multi_out_ctls(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2887 | if (err < 0) |
| 2888 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2889 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2890 | if (err < 0) |
| 2891 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2892 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2893 | if (err < 0) |
| 2894 | return err; |
| 2895 | |
| 2896 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2897 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2898 | if (spec->autocfg.dig_outs) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2899 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2900 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2901 | if (spec->autocfg.dig_in_pin) |
| 2902 | spec->dig_in_nid = VT1708B_DIGIN_NID; |
| 2903 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2904 | if (spec->kctls.list) |
| 2905 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2906 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2907 | spec->input_mux = &spec->private_imux[0]; |
| 2908 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2909 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2910 | via_hp_build(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2911 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2912 | err = via_smart51_build(codec); |
| 2913 | if (err < 0) |
| 2914 | return err; |
| 2915 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2916 | return 1; |
| 2917 | } |
| 2918 | |
| 2919 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2920 | static const struct hda_amp_list vt1708B_loopbacks[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2921 | { 0x16, HDA_INPUT, 1 }, |
| 2922 | { 0x16, HDA_INPUT, 2 }, |
| 2923 | { 0x16, HDA_INPUT, 3 }, |
| 2924 | { 0x16, HDA_INPUT, 4 }, |
| 2925 | { } /* end */ |
| 2926 | }; |
| 2927 | #endif |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2928 | |
| 2929 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
| 2930 | { |
| 2931 | struct via_spec *spec = codec->spec; |
| 2932 | int imux_is_smixer; |
| 2933 | unsigned int parm; |
| 2934 | int is_8ch = 0; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2935 | if ((spec->codec_type != VT1708B_4CH) && |
| 2936 | (codec->vendor_id != 0x11064397)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2937 | is_8ch = 1; |
| 2938 | |
| 2939 | /* SW0 (17h) = stereo mixer */ |
| 2940 | imux_is_smixer = |
| 2941 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 2942 | == ((spec->codec_type == VT1708S) ? 5 : 0)); |
| 2943 | /* inputs */ |
| 2944 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 2945 | parm = AC_PWRST_D3; |
| 2946 | set_pin_power_state(codec, 0x1a, &parm); |
| 2947 | set_pin_power_state(codec, 0x1b, &parm); |
| 2948 | set_pin_power_state(codec, 0x1e, &parm); |
| 2949 | if (imux_is_smixer) |
| 2950 | parm = AC_PWRST_D0; |
| 2951 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
| 2952 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2953 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2954 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2955 | |
| 2956 | /* outputs */ |
| 2957 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 2958 | parm = AC_PWRST_D3; |
| 2959 | set_pin_power_state(codec, 0x19, &parm); |
| 2960 | if (spec->smart51_enabled) |
| 2961 | set_pin_power_state(codec, 0x1b, &parm); |
| 2962 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2963 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2964 | |
| 2965 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 2966 | if (is_8ch) { |
| 2967 | parm = AC_PWRST_D3; |
| 2968 | set_pin_power_state(codec, 0x22, &parm); |
| 2969 | if (spec->smart51_enabled) |
| 2970 | set_pin_power_state(codec, 0x1a, &parm); |
| 2971 | snd_hda_codec_write(codec, 0x26, 0, |
| 2972 | AC_VERB_SET_POWER_STATE, parm); |
| 2973 | snd_hda_codec_write(codec, 0x24, 0, |
| 2974 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2975 | } else if (codec->vendor_id == 0x11064397) { |
| 2976 | /* PW7(23h), SW2(27h), AOW2(25h) */ |
| 2977 | parm = AC_PWRST_D3; |
| 2978 | set_pin_power_state(codec, 0x23, &parm); |
| 2979 | if (spec->smart51_enabled) |
| 2980 | set_pin_power_state(codec, 0x1a, &parm); |
| 2981 | snd_hda_codec_write(codec, 0x27, 0, |
| 2982 | AC_VERB_SET_POWER_STATE, parm); |
| 2983 | snd_hda_codec_write(codec, 0x25, 0, |
| 2984 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 2988 | parm = AC_PWRST_D3; |
| 2989 | /* force to D0 for internal Speaker */ |
| 2990 | set_pin_power_state(codec, 0x1c, &parm); |
| 2991 | set_pin_power_state(codec, 0x1d, &parm); |
| 2992 | if (is_8ch) |
| 2993 | set_pin_power_state(codec, 0x23, &parm); |
| 2994 | |
| 2995 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
| 2996 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 2997 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 2998 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2999 | if (is_8ch) { |
| 3000 | snd_hda_codec_write(codec, 0x25, 0, |
| 3001 | AC_VERB_SET_POWER_STATE, parm); |
| 3002 | snd_hda_codec_write(codec, 0x27, 0, |
| 3003 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3004 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
| 3005 | snd_hda_codec_write(codec, 0x25, 0, |
| 3006 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3007 | } |
| 3008 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3009 | static int patch_vt1708S(struct hda_codec *codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3010 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
| 3011 | { |
| 3012 | struct via_spec *spec; |
| 3013 | int err; |
| 3014 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3015 | if (get_codec_type(codec) == VT1708BCE) |
| 3016 | return patch_vt1708S(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3017 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3018 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3019 | if (spec == NULL) |
| 3020 | return -ENOMEM; |
| 3021 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3022 | spec->aa_mix_nid = 0x16; |
| 3023 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3024 | /* automatic parse from the BIOS config */ |
| 3025 | err = vt1708B_parse_auto_config(codec); |
| 3026 | if (err < 0) { |
| 3027 | via_free(codec); |
| 3028 | return err; |
| 3029 | } else if (!err) { |
| 3030 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3031 | "from BIOS. Using genenic mode...\n"); |
| 3032 | } |
| 3033 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3034 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
| 3035 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3036 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3037 | spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; |
| 3038 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; |
| 3039 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3040 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; |
| 3041 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; |
| 3042 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3043 | if (spec->adc_nids && spec->input_mux) { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3044 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 3045 | spec->num_mixers++; |
| 3046 | } |
| 3047 | |
| 3048 | codec->patch_ops = via_patch_ops; |
| 3049 | |
| 3050 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3051 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3052 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3053 | spec->loopback.amplist = vt1708B_loopbacks; |
| 3054 | #endif |
| 3055 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3056 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 3057 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3058 | return 0; |
| 3059 | } |
| 3060 | |
| 3061 | static int patch_vt1708B_4ch(struct hda_codec *codec) |
| 3062 | { |
| 3063 | struct via_spec *spec; |
| 3064 | int err; |
| 3065 | |
| 3066 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3067 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3068 | if (spec == NULL) |
| 3069 | return -ENOMEM; |
| 3070 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3071 | /* automatic parse from the BIOS config */ |
| 3072 | err = vt1708B_parse_auto_config(codec); |
| 3073 | if (err < 0) { |
| 3074 | via_free(codec); |
| 3075 | return err; |
| 3076 | } else if (!err) { |
| 3077 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3078 | "from BIOS. Using genenic mode...\n"); |
| 3079 | } |
| 3080 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3081 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
| 3082 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3083 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3084 | spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; |
| 3085 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; |
| 3086 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3087 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; |
| 3088 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; |
| 3089 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3090 | if (spec->adc_nids && spec->input_mux) { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3091 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 3092 | spec->num_mixers++; |
| 3093 | } |
| 3094 | |
| 3095 | codec->patch_ops = via_patch_ops; |
| 3096 | |
| 3097 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3098 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3099 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3100 | spec->loopback.amplist = vt1708B_loopbacks; |
| 3101 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3102 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3103 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 3104 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3105 | return 0; |
| 3106 | } |
| 3107 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3108 | /* Patch for VT1708S */ |
| 3109 | |
| 3110 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3111 | static const struct snd_kcontrol_new vt1708S_capture_mixer[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3112 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 3113 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 3114 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 3115 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3116 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 3117 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 3118 | HDA_INPUT), |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3119 | { |
| 3120 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3121 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3122 | * So call somewhat different.. |
| 3123 | */ |
| 3124 | /* .name = "Capture Source", */ |
| 3125 | .name = "Input Source", |
| 3126 | .count = 1, |
| 3127 | .info = via_mux_enum_info, |
| 3128 | .get = via_mux_enum_get, |
| 3129 | .put = via_mux_enum_put, |
| 3130 | }, |
| 3131 | { } /* end */ |
| 3132 | }; |
| 3133 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3134 | static const struct hda_verb vt1708S_volume_init_verbs[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3135 | /* Unmute ADC0-1 and set the default input to mic-in */ |
| 3136 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3137 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3138 | |
| 3139 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the |
| 3140 | * analog-loopback mixer widget */ |
| 3141 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3142 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3143 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3144 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3145 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3146 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3147 | |
| 3148 | /* Setup default input of PW4 to MW0 */ |
| 3149 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3150 | /* PW9, PW10 Output enable */ |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3151 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3152 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 3153 | /* Enable Mic Boost Volume backdoor */ |
| 3154 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3155 | /* don't bybass mixer */ |
| 3156 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3157 | { } |
| 3158 | }; |
| 3159 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3160 | static const struct hda_verb vt1708S_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3161 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3162 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3163 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3164 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3165 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3166 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3167 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3168 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3169 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3170 | { } |
| 3171 | }; |
| 3172 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3173 | static const struct hda_verb vt1705_uniwill_init_verbs[] = { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3174 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3175 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3176 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3177 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3178 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3179 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3180 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3181 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3182 | { } |
| 3183 | }; |
| 3184 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3185 | static const struct hda_pcm_stream vt1708S_pcm_analog_playback = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3186 | .substreams = 2, |
| 3187 | .channels_min = 2, |
| 3188 | .channels_max = 8, |
| 3189 | .nid = 0x10, /* NID to query formats and rates */ |
| 3190 | .ops = { |
| 3191 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 3192 | .prepare = via_playback_multi_pcm_prepare, |
| 3193 | .cleanup = via_playback_multi_pcm_cleanup, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3194 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3195 | }, |
| 3196 | }; |
| 3197 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3198 | static const struct hda_pcm_stream vt1705_pcm_analog_playback = { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3199 | .substreams = 2, |
| 3200 | .channels_min = 2, |
| 3201 | .channels_max = 6, |
| 3202 | .nid = 0x10, /* NID to query formats and rates */ |
| 3203 | .ops = { |
| 3204 | .open = via_playback_pcm_open, |
| 3205 | .prepare = via_playback_multi_pcm_prepare, |
| 3206 | .cleanup = via_playback_multi_pcm_cleanup, |
| 3207 | .close = via_pcm_open_close |
| 3208 | }, |
| 3209 | }; |
| 3210 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3211 | static const struct hda_pcm_stream vt1708S_pcm_analog_capture = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3212 | .substreams = 2, |
| 3213 | .channels_min = 2, |
| 3214 | .channels_max = 2, |
| 3215 | .nid = 0x13, /* NID to query formats and rates */ |
| 3216 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3217 | .open = via_pcm_open_close, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3218 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3219 | .cleanup = via_capture_pcm_cleanup, |
| 3220 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3221 | }, |
| 3222 | }; |
| 3223 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3224 | static const struct hda_pcm_stream vt1708S_pcm_digital_playback = { |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3225 | .substreams = 1, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3226 | .channels_min = 2, |
| 3227 | .channels_max = 2, |
| 3228 | /* NID is set in via_build_pcms */ |
| 3229 | .ops = { |
| 3230 | .open = via_dig_playback_pcm_open, |
| 3231 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3232 | .prepare = via_dig_playback_pcm_prepare, |
| 3233 | .cleanup = via_dig_playback_pcm_cleanup |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3234 | }, |
| 3235 | }; |
| 3236 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3237 | /* fill out digital output widgets; one for master and one for slave outputs */ |
| 3238 | static void fill_dig_outs(struct hda_codec *codec) |
| 3239 | { |
| 3240 | struct via_spec *spec = codec->spec; |
| 3241 | int i; |
| 3242 | |
| 3243 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 3244 | hda_nid_t nid; |
| 3245 | int conn; |
| 3246 | |
| 3247 | nid = spec->autocfg.dig_out_pins[i]; |
| 3248 | if (!nid) |
| 3249 | continue; |
| 3250 | conn = snd_hda_get_connections(codec, nid, &nid, 1); |
| 3251 | if (conn < 1) |
| 3252 | continue; |
| 3253 | if (!spec->multiout.dig_out_nid) |
| 3254 | spec->multiout.dig_out_nid = nid; |
| 3255 | else { |
| 3256 | spec->slave_dig_outs[0] = nid; |
| 3257 | break; /* at most two dig outs */ |
| 3258 | } |
| 3259 | } |
| 3260 | } |
| 3261 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3262 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
| 3263 | { |
| 3264 | struct via_spec *spec = codec->spec; |
| 3265 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3266 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3267 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3268 | if (err < 0) |
| 3269 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3270 | err = via_auto_fill_dac_nids(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3271 | if (err < 0) |
| 3272 | return err; |
| 3273 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3274 | return 0; /* can't find valid BIOS pin config */ |
| 3275 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3276 | err = via_auto_create_multi_out_ctls(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3277 | if (err < 0) |
| 3278 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3279 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3280 | if (err < 0) |
| 3281 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3282 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3283 | if (err < 0) |
| 3284 | return err; |
| 3285 | |
| 3286 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3287 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3288 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 3289 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3290 | if (spec->kctls.list) |
| 3291 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3292 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3293 | spec->input_mux = &spec->private_imux[0]; |
| 3294 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3295 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3296 | via_hp_build(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3297 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 3298 | err = via_smart51_build(codec); |
| 3299 | if (err < 0) |
| 3300 | return err; |
| 3301 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3302 | return 1; |
| 3303 | } |
| 3304 | |
| 3305 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3306 | static const struct hda_amp_list vt1708S_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3307 | { 0x16, HDA_INPUT, 1 }, |
| 3308 | { 0x16, HDA_INPUT, 2 }, |
| 3309 | { 0x16, HDA_INPUT, 3 }, |
| 3310 | { 0x16, HDA_INPUT, 4 }, |
| 3311 | { } /* end */ |
| 3312 | }; |
| 3313 | #endif |
| 3314 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3315 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 3316 | int offset, int num_steps, int step_size) |
| 3317 | { |
| 3318 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 3319 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 3320 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3321 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3322 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 3323 | } |
| 3324 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3325 | static int patch_vt1708S(struct hda_codec *codec) |
| 3326 | { |
| 3327 | struct via_spec *spec; |
| 3328 | int err; |
| 3329 | |
| 3330 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3331 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3332 | if (spec == NULL) |
| 3333 | return -ENOMEM; |
| 3334 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3335 | spec->aa_mix_nid = 0x16; |
| 3336 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3337 | /* automatic parse from the BIOS config */ |
| 3338 | err = vt1708S_parse_auto_config(codec); |
| 3339 | if (err < 0) { |
| 3340 | via_free(codec); |
| 3341 | return err; |
| 3342 | } else if (!err) { |
| 3343 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3344 | "from BIOS. Using genenic mode...\n"); |
| 3345 | } |
| 3346 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3347 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3348 | if (codec->vendor_id == 0x11064397) |
| 3349 | spec->init_verbs[spec->num_iverbs++] = |
| 3350 | vt1705_uniwill_init_verbs; |
| 3351 | else |
| 3352 | spec->init_verbs[spec->num_iverbs++] = |
| 3353 | vt1708S_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3354 | |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3355 | if (codec->vendor_id == 0x11064397) |
| 3356 | spec->stream_analog_playback = &vt1705_pcm_analog_playback; |
| 3357 | else |
| 3358 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3359 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; |
| 3360 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3361 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; |
| 3362 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3363 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3364 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3365 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3366 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; |
| 3367 | spec->num_mixers++; |
| 3368 | } |
| 3369 | |
| 3370 | codec->patch_ops = via_patch_ops; |
| 3371 | |
| 3372 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3373 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3374 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3375 | spec->loopback.amplist = vt1708S_loopbacks; |
| 3376 | #endif |
| 3377 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3378 | /* correct names for VT1708BCE */ |
| 3379 | if (get_codec_type(codec) == VT1708BCE) { |
| 3380 | kfree(codec->chip_name); |
| 3381 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 3382 | snprintf(codec->bus->card->mixername, |
| 3383 | sizeof(codec->bus->card->mixername), |
| 3384 | "%s %s", codec->vendor_name, codec->chip_name); |
Lydia Wang | 970f630f | 2011-03-22 16:25:56 +0800 | [diff] [blame] | 3385 | } |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3386 | /* correct names for VT1705 */ |
| 3387 | if (codec->vendor_id == 0x11064397) { |
| 3388 | kfree(codec->chip_name); |
| 3389 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); |
| 3390 | snprintf(codec->bus->card->mixername, |
| 3391 | sizeof(codec->bus->card->mixername), |
| 3392 | "%s %s", codec->vendor_name, codec->chip_name); |
| 3393 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3394 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3395 | return 0; |
| 3396 | } |
| 3397 | |
| 3398 | /* Patch for VT1702 */ |
| 3399 | |
| 3400 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3401 | static const struct snd_kcontrol_new vt1702_capture_mixer[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3402 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), |
| 3403 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), |
| 3404 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), |
| 3405 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), |
| 3406 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), |
| 3407 | HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), |
| 3408 | HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, |
| 3409 | HDA_INPUT), |
| 3410 | { |
| 3411 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3412 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3413 | * So call somewhat different.. |
| 3414 | */ |
| 3415 | /* .name = "Capture Source", */ |
| 3416 | .name = "Input Source", |
| 3417 | .count = 1, |
| 3418 | .info = via_mux_enum_info, |
| 3419 | .get = via_mux_enum_get, |
| 3420 | .put = via_mux_enum_put, |
| 3421 | }, |
| 3422 | { } /* end */ |
| 3423 | }; |
| 3424 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3425 | static const struct hda_verb vt1702_volume_init_verbs[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3426 | /* |
| 3427 | * Unmute ADC0-1 and set the default input to mic-in |
| 3428 | */ |
| 3429 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3430 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3431 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3432 | |
| 3433 | |
| 3434 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3435 | * mixer widget |
| 3436 | */ |
| 3437 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ |
| 3438 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3439 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3440 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3441 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3442 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 3443 | |
| 3444 | /* Setup default input of PW4 to MW0 */ |
| 3445 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3446 | /* PW6 PW7 Output enable */ |
| 3447 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3448 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3449 | /* mixer enable */ |
| 3450 | {0x1, 0xF88, 0x3}, |
| 3451 | /* GPIO 0~2 */ |
| 3452 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3453 | { } |
| 3454 | }; |
| 3455 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3456 | static const struct hda_verb vt1702_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3457 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3458 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3459 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3460 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3461 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3462 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3463 | { } |
| 3464 | }; |
| 3465 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3466 | static const struct hda_pcm_stream vt1702_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3467 | .substreams = 2, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3468 | .channels_min = 2, |
| 3469 | .channels_max = 2, |
| 3470 | .nid = 0x10, /* NID to query formats and rates */ |
| 3471 | .ops = { |
| 3472 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3473 | .prepare = via_playback_multi_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3474 | .cleanup = via_playback_multi_pcm_cleanup, |
| 3475 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3476 | }, |
| 3477 | }; |
| 3478 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3479 | static const struct hda_pcm_stream vt1702_pcm_analog_capture = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3480 | .substreams = 3, |
| 3481 | .channels_min = 2, |
| 3482 | .channels_max = 2, |
| 3483 | .nid = 0x12, /* NID to query formats and rates */ |
| 3484 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3485 | .open = via_pcm_open_close, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3486 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3487 | .cleanup = via_capture_pcm_cleanup, |
| 3488 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3489 | }, |
| 3490 | }; |
| 3491 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3492 | static const struct hda_pcm_stream vt1702_pcm_digital_playback = { |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3493 | .substreams = 2, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3494 | .channels_min = 2, |
| 3495 | .channels_max = 2, |
| 3496 | /* NID is set in via_build_pcms */ |
| 3497 | .ops = { |
| 3498 | .open = via_dig_playback_pcm_open, |
| 3499 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3500 | .prepare = via_dig_playback_pcm_prepare, |
| 3501 | .cleanup = via_dig_playback_pcm_cleanup |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3502 | }, |
| 3503 | }; |
| 3504 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3505 | static int vt1702_parse_auto_config(struct hda_codec *codec) |
| 3506 | { |
| 3507 | struct via_spec *spec = codec->spec; |
| 3508 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3509 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3510 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3511 | if (err < 0) |
| 3512 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3513 | err = via_auto_fill_dac_nids(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3514 | if (err < 0) |
| 3515 | return err; |
| 3516 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3517 | return 0; /* can't find valid BIOS pin config */ |
| 3518 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3519 | err = via_auto_create_multi_out_ctls(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3520 | if (err < 0) |
| 3521 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3522 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3523 | if (err < 0) |
| 3524 | return err; |
Lydia Wang | c2c02ea | 2009-10-10 19:07:32 +0800 | [diff] [blame] | 3525 | /* limit AA path volume to 0 dB */ |
| 3526 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 3527 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 3528 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3529 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3530 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3531 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3532 | if (err < 0) |
| 3533 | return err; |
| 3534 | |
| 3535 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3536 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3537 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 3538 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3539 | if (spec->kctls.list) |
| 3540 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3541 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3542 | spec->input_mux = &spec->private_imux[0]; |
| 3543 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3544 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3545 | via_hp_build(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3546 | |
| 3547 | return 1; |
| 3548 | } |
| 3549 | |
| 3550 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3551 | static const struct hda_amp_list vt1702_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3552 | { 0x1A, HDA_INPUT, 1 }, |
| 3553 | { 0x1A, HDA_INPUT, 2 }, |
| 3554 | { 0x1A, HDA_INPUT, 3 }, |
| 3555 | { 0x1A, HDA_INPUT, 4 }, |
| 3556 | { } /* end */ |
| 3557 | }; |
| 3558 | #endif |
| 3559 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3560 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
| 3561 | { |
| 3562 | int imux_is_smixer = |
| 3563 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3564 | unsigned int parm; |
| 3565 | /* inputs */ |
| 3566 | /* PW 1/2/5 (14h/15h/18h) */ |
| 3567 | parm = AC_PWRST_D3; |
| 3568 | set_pin_power_state(codec, 0x14, &parm); |
| 3569 | set_pin_power_state(codec, 0x15, &parm); |
| 3570 | set_pin_power_state(codec, 0x18, &parm); |
| 3571 | if (imux_is_smixer) |
| 3572 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ |
| 3573 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
| 3574 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3575 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3576 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3577 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3578 | |
| 3579 | /* outputs */ |
| 3580 | /* PW 3/4 (16h/17h) */ |
| 3581 | parm = AC_PWRST_D3; |
| 3582 | set_pin_power_state(codec, 0x17, &parm); |
| 3583 | set_pin_power_state(codec, 0x16, &parm); |
| 3584 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
| 3585 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 3586 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3587 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3588 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3589 | } |
| 3590 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3591 | static int patch_vt1702(struct hda_codec *codec) |
| 3592 | { |
| 3593 | struct via_spec *spec; |
| 3594 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3595 | |
| 3596 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3597 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3598 | if (spec == NULL) |
| 3599 | return -ENOMEM; |
| 3600 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3601 | spec->aa_mix_nid = 0x1a; |
| 3602 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3603 | /* automatic parse from the BIOS config */ |
| 3604 | err = vt1702_parse_auto_config(codec); |
| 3605 | if (err < 0) { |
| 3606 | via_free(codec); |
| 3607 | return err; |
| 3608 | } else if (!err) { |
| 3609 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3610 | "from BIOS. Using genenic mode...\n"); |
| 3611 | } |
| 3612 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3613 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
| 3614 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3615 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3616 | spec->stream_analog_playback = &vt1702_pcm_analog_playback; |
| 3617 | spec->stream_analog_capture = &vt1702_pcm_analog_capture; |
| 3618 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3619 | spec->stream_digital_playback = &vt1702_pcm_digital_playback; |
| 3620 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3621 | if (spec->adc_nids && spec->input_mux) { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3622 | spec->mixers[spec->num_mixers] = vt1702_capture_mixer; |
| 3623 | spec->num_mixers++; |
| 3624 | } |
| 3625 | |
| 3626 | codec->patch_ops = via_patch_ops; |
| 3627 | |
| 3628 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3629 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3630 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3631 | spec->loopback.amplist = vt1702_loopbacks; |
| 3632 | #endif |
| 3633 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3634 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3635 | return 0; |
| 3636 | } |
| 3637 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3638 | /* Patch for VT1718S */ |
| 3639 | |
| 3640 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3641 | static const struct snd_kcontrol_new vt1718S_capture_mixer[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3642 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 3643 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 3644 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 3645 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 3646 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 3647 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 3648 | HDA_INPUT), |
| 3649 | { |
| 3650 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3651 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3652 | * So call somewhat different.. |
| 3653 | */ |
| 3654 | .name = "Input Source", |
| 3655 | .count = 2, |
| 3656 | .info = via_mux_enum_info, |
| 3657 | .get = via_mux_enum_get, |
| 3658 | .put = via_mux_enum_put, |
| 3659 | }, |
| 3660 | { } /* end */ |
| 3661 | }; |
| 3662 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3663 | static const struct hda_verb vt1718S_volume_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3664 | /* |
| 3665 | * Unmute ADC0-1 and set the default input to mic-in |
| 3666 | */ |
| 3667 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3668 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3669 | |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 3670 | /* Enable MW0 adjust Gain 5 */ |
| 3671 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3672 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3673 | * mixer widget |
| 3674 | */ |
| 3675 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3676 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 3677 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3678 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 3679 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 3680 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3681 | |
| 3682 | /* Setup default input of Front HP to MW9 */ |
| 3683 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3684 | /* PW9 PW10 Output enable */ |
| 3685 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 3686 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 3687 | /* PW11 Input enable */ |
| 3688 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, |
| 3689 | /* Enable Boost Volume backdoor */ |
| 3690 | {0x1, 0xf88, 0x8}, |
| 3691 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ |
| 3692 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3693 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3694 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3695 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3696 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3697 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3698 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3699 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3700 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3701 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 3702 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ |
| 3703 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, |
| 3704 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3705 | /* Unmute MW4's index 0 */ |
| 3706 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3707 | { } |
| 3708 | }; |
| 3709 | |
| 3710 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3711 | static const struct hda_verb vt1718S_uniwill_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3712 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3713 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3714 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3715 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3716 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3717 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3718 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3719 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3720 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3721 | { } |
| 3722 | }; |
| 3723 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3724 | static const struct hda_pcm_stream vt1718S_pcm_analog_playback = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3725 | .substreams = 2, |
| 3726 | .channels_min = 2, |
| 3727 | .channels_max = 10, |
| 3728 | .nid = 0x8, /* NID to query formats and rates */ |
| 3729 | .ops = { |
| 3730 | .open = via_playback_pcm_open, |
| 3731 | .prepare = via_playback_multi_pcm_prepare, |
| 3732 | .cleanup = via_playback_multi_pcm_cleanup, |
| 3733 | .close = via_pcm_open_close, |
| 3734 | }, |
| 3735 | }; |
| 3736 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3737 | static const struct hda_pcm_stream vt1718S_pcm_analog_capture = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3738 | .substreams = 2, |
| 3739 | .channels_min = 2, |
| 3740 | .channels_max = 2, |
| 3741 | .nid = 0x10, /* NID to query formats and rates */ |
| 3742 | .ops = { |
| 3743 | .open = via_pcm_open_close, |
| 3744 | .prepare = via_capture_pcm_prepare, |
| 3745 | .cleanup = via_capture_pcm_cleanup, |
| 3746 | .close = via_pcm_open_close, |
| 3747 | }, |
| 3748 | }; |
| 3749 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3750 | static const struct hda_pcm_stream vt1718S_pcm_digital_playback = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3751 | .substreams = 2, |
| 3752 | .channels_min = 2, |
| 3753 | .channels_max = 2, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3754 | /* NID is set in via_build_pcms */ |
| 3755 | .ops = { |
| 3756 | .open = via_dig_playback_pcm_open, |
| 3757 | .close = via_dig_playback_pcm_close, |
| 3758 | .prepare = via_dig_playback_pcm_prepare, |
| 3759 | .cleanup = via_dig_playback_pcm_cleanup |
| 3760 | }, |
| 3761 | }; |
| 3762 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3763 | static const struct hda_pcm_stream vt1718S_pcm_digital_capture = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3764 | .substreams = 1, |
| 3765 | .channels_min = 2, |
| 3766 | .channels_max = 2, |
| 3767 | }; |
| 3768 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3769 | static int vt1718S_parse_auto_config(struct hda_codec *codec) |
| 3770 | { |
| 3771 | struct via_spec *spec = codec->spec; |
| 3772 | int err; |
| 3773 | |
| 3774 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 3775 | |
| 3776 | if (err < 0) |
| 3777 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3778 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3779 | if (err < 0) |
| 3780 | return err; |
| 3781 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3782 | return 0; /* can't find valid BIOS pin config */ |
| 3783 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3784 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3785 | if (err < 0) |
| 3786 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 3787 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3788 | if (err < 0) |
| 3789 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3790 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3791 | if (err < 0) |
| 3792 | return err; |
| 3793 | |
| 3794 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3795 | |
| 3796 | fill_dig_outs(codec); |
| 3797 | |
| 3798 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) |
| 3799 | spec->dig_in_nid = 0x13; |
| 3800 | |
| 3801 | if (spec->kctls.list) |
| 3802 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 3803 | |
| 3804 | spec->input_mux = &spec->private_imux[0]; |
| 3805 | |
| 3806 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3807 | via_hp_build(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3808 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 3809 | err = via_smart51_build(codec); |
| 3810 | if (err < 0) |
| 3811 | return err; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3812 | |
| 3813 | return 1; |
| 3814 | } |
| 3815 | |
| 3816 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3817 | static const struct hda_amp_list vt1718S_loopbacks[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3818 | { 0x21, HDA_INPUT, 1 }, |
| 3819 | { 0x21, HDA_INPUT, 2 }, |
| 3820 | { 0x21, HDA_INPUT, 3 }, |
| 3821 | { 0x21, HDA_INPUT, 4 }, |
| 3822 | { } /* end */ |
| 3823 | }; |
| 3824 | #endif |
| 3825 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3826 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
| 3827 | { |
| 3828 | struct via_spec *spec = codec->spec; |
| 3829 | int imux_is_smixer; |
| 3830 | unsigned int parm; |
| 3831 | /* MUX6 (1eh) = stereo mixer */ |
| 3832 | imux_is_smixer = |
| 3833 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 3834 | /* inputs */ |
| 3835 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3836 | parm = AC_PWRST_D3; |
| 3837 | set_pin_power_state(codec, 0x29, &parm); |
| 3838 | set_pin_power_state(codec, 0x2a, &parm); |
| 3839 | set_pin_power_state(codec, 0x2b, &parm); |
| 3840 | if (imux_is_smixer) |
| 3841 | parm = AC_PWRST_D0; |
| 3842 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3843 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3844 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3845 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3846 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3847 | |
| 3848 | /* outputs */ |
| 3849 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 3850 | parm = AC_PWRST_D3; |
| 3851 | set_pin_power_state(codec, 0x27, &parm); |
| 3852 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3853 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3854 | |
| 3855 | /* PW2 (26h), AOW2 (ah) */ |
| 3856 | parm = AC_PWRST_D3; |
| 3857 | set_pin_power_state(codec, 0x26, &parm); |
| 3858 | if (spec->smart51_enabled) |
| 3859 | set_pin_power_state(codec, 0x2b, &parm); |
| 3860 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3861 | |
| 3862 | /* PW0 (24h), AOW0 (8h) */ |
| 3863 | parm = AC_PWRST_D3; |
| 3864 | set_pin_power_state(codec, 0x24, &parm); |
| 3865 | if (!spec->hp_independent_mode) /* check for redirected HP */ |
| 3866 | set_pin_power_state(codec, 0x28, &parm); |
| 3867 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3868 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 3869 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, |
| 3870 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3871 | |
| 3872 | /* PW1 (25h), AOW1 (9h) */ |
| 3873 | parm = AC_PWRST_D3; |
| 3874 | set_pin_power_state(codec, 0x25, &parm); |
| 3875 | if (spec->smart51_enabled) |
| 3876 | set_pin_power_state(codec, 0x2a, &parm); |
| 3877 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3878 | |
| 3879 | if (spec->hp_independent_mode) { |
| 3880 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 3881 | parm = AC_PWRST_D3; |
| 3882 | set_pin_power_state(codec, 0x28, &parm); |
| 3883 | snd_hda_codec_write(codec, 0x1b, 0, |
| 3884 | AC_VERB_SET_POWER_STATE, parm); |
| 3885 | snd_hda_codec_write(codec, 0x34, 0, |
| 3886 | AC_VERB_SET_POWER_STATE, parm); |
| 3887 | snd_hda_codec_write(codec, 0xc, 0, |
| 3888 | AC_VERB_SET_POWER_STATE, parm); |
| 3889 | } |
| 3890 | } |
| 3891 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3892 | static int patch_vt1718S(struct hda_codec *codec) |
| 3893 | { |
| 3894 | struct via_spec *spec; |
| 3895 | int err; |
| 3896 | |
| 3897 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3898 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3899 | if (spec == NULL) |
| 3900 | return -ENOMEM; |
| 3901 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3902 | spec->aa_mix_nid = 0x21; |
| 3903 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3904 | /* automatic parse from the BIOS config */ |
| 3905 | err = vt1718S_parse_auto_config(codec); |
| 3906 | if (err < 0) { |
| 3907 | via_free(codec); |
| 3908 | return err; |
| 3909 | } else if (!err) { |
| 3910 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3911 | "from BIOS. Using genenic mode...\n"); |
| 3912 | } |
| 3913 | |
| 3914 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; |
| 3915 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; |
| 3916 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3917 | spec->stream_analog_playback = &vt1718S_pcm_analog_playback; |
| 3918 | spec->stream_analog_capture = &vt1718S_pcm_analog_capture; |
| 3919 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3920 | spec->stream_digital_playback = &vt1718S_pcm_digital_playback; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 3921 | if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3922 | spec->stream_digital_capture = &vt1718S_pcm_digital_capture; |
| 3923 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3924 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 3925 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3926 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3927 | spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; |
| 3928 | spec->num_mixers++; |
| 3929 | } |
| 3930 | |
| 3931 | codec->patch_ops = via_patch_ops; |
| 3932 | |
| 3933 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 3934 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3935 | |
| 3936 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3937 | spec->loopback.amplist = vt1718S_loopbacks; |
| 3938 | #endif |
| 3939 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3940 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
| 3941 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3942 | return 0; |
| 3943 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3944 | |
| 3945 | /* Patch for VT1716S */ |
| 3946 | |
| 3947 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 3948 | struct snd_ctl_elem_info *uinfo) |
| 3949 | { |
| 3950 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3951 | uinfo->count = 1; |
| 3952 | uinfo->value.integer.min = 0; |
| 3953 | uinfo->value.integer.max = 1; |
| 3954 | return 0; |
| 3955 | } |
| 3956 | |
| 3957 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 3958 | struct snd_ctl_elem_value *ucontrol) |
| 3959 | { |
| 3960 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3961 | int index = 0; |
| 3962 | |
| 3963 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 3964 | AC_VERB_GET_CONNECT_SEL, 0); |
| 3965 | if (index != -1) |
| 3966 | *ucontrol->value.integer.value = index; |
| 3967 | |
| 3968 | return 0; |
| 3969 | } |
| 3970 | |
| 3971 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 3972 | struct snd_ctl_elem_value *ucontrol) |
| 3973 | { |
| 3974 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3975 | struct via_spec *spec = codec->spec; |
| 3976 | int index = *ucontrol->value.integer.value; |
| 3977 | |
| 3978 | snd_hda_codec_write(codec, 0x26, 0, |
| 3979 | AC_VERB_SET_CONNECT_SEL, index); |
| 3980 | spec->dmic_enabled = index; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3981 | set_widgets_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3982 | return 1; |
| 3983 | } |
| 3984 | |
| 3985 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3986 | static const struct snd_kcontrol_new vt1716S_capture_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3987 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 3988 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 3989 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 3990 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 3991 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 3992 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 3993 | HDA_INPUT), |
| 3994 | { |
| 3995 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3996 | .name = "Input Source", |
| 3997 | .count = 1, |
| 3998 | .info = via_mux_enum_info, |
| 3999 | .get = via_mux_enum_get, |
| 4000 | .put = via_mux_enum_put, |
| 4001 | }, |
| 4002 | { } /* end */ |
| 4003 | }; |
| 4004 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4005 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4006 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 4007 | { |
| 4008 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4009 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4010 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4011 | .count = 1, |
| 4012 | .info = vt1716s_dmic_info, |
| 4013 | .get = vt1716s_dmic_get, |
| 4014 | .put = vt1716s_dmic_put, |
| 4015 | }, |
| 4016 | {} /* end */ |
| 4017 | }; |
| 4018 | |
| 4019 | |
| 4020 | /* mono-out mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4021 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4022 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 4023 | { } /* end */ |
| 4024 | }; |
| 4025 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4026 | static const struct hda_verb vt1716S_volume_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4027 | /* |
| 4028 | * Unmute ADC0-1 and set the default input to mic-in |
| 4029 | */ |
| 4030 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4031 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4032 | |
| 4033 | |
| 4034 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4035 | * mixer widget |
| 4036 | */ |
| 4037 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4038 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4039 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4040 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4041 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4042 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4043 | |
| 4044 | /* MUX Indices: Stereo Mixer = 5 */ |
| 4045 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, |
| 4046 | |
| 4047 | /* Setup default input of PW4 to MW0 */ |
| 4048 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 4049 | |
| 4050 | /* Setup default input of SW1 as MW0 */ |
| 4051 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4052 | |
| 4053 | /* Setup default input of SW4 as AOW0 */ |
| 4054 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4055 | |
| 4056 | /* PW9 PW10 Output enable */ |
| 4057 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4058 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4059 | |
| 4060 | /* Unmute SW1, PW12 */ |
| 4061 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4062 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 4063 | /* PW12 Output enable */ |
| 4064 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4065 | /* Enable Boost Volume backdoor */ |
| 4066 | {0x1, 0xf8a, 0x80}, |
| 4067 | /* don't bybass mixer */ |
| 4068 | {0x1, 0xf88, 0xc0}, |
| 4069 | /* Enable mono output */ |
| 4070 | {0x1, 0xf90, 0x08}, |
| 4071 | { } |
| 4072 | }; |
| 4073 | |
| 4074 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4075 | static const struct hda_verb vt1716S_uniwill_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4076 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4077 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 4078 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4079 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4080 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4081 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4082 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, |
| 4083 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4084 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4085 | { } |
| 4086 | }; |
| 4087 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4088 | static const struct hda_pcm_stream vt1716S_pcm_analog_playback = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4089 | .substreams = 2, |
| 4090 | .channels_min = 2, |
| 4091 | .channels_max = 6, |
| 4092 | .nid = 0x10, /* NID to query formats and rates */ |
| 4093 | .ops = { |
| 4094 | .open = via_playback_pcm_open, |
| 4095 | .prepare = via_playback_multi_pcm_prepare, |
| 4096 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4097 | .close = via_pcm_open_close, |
| 4098 | }, |
| 4099 | }; |
| 4100 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4101 | static const struct hda_pcm_stream vt1716S_pcm_analog_capture = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4102 | .substreams = 2, |
| 4103 | .channels_min = 2, |
| 4104 | .channels_max = 2, |
| 4105 | .nid = 0x13, /* NID to query formats and rates */ |
| 4106 | .ops = { |
| 4107 | .open = via_pcm_open_close, |
| 4108 | .prepare = via_capture_pcm_prepare, |
| 4109 | .cleanup = via_capture_pcm_cleanup, |
| 4110 | .close = via_pcm_open_close, |
| 4111 | }, |
| 4112 | }; |
| 4113 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4114 | static const struct hda_pcm_stream vt1716S_pcm_digital_playback = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4115 | .substreams = 2, |
| 4116 | .channels_min = 2, |
| 4117 | .channels_max = 2, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4118 | /* NID is set in via_build_pcms */ |
| 4119 | .ops = { |
| 4120 | .open = via_dig_playback_pcm_open, |
| 4121 | .close = via_dig_playback_pcm_close, |
| 4122 | .prepare = via_dig_playback_pcm_prepare, |
| 4123 | .cleanup = via_dig_playback_pcm_cleanup |
| 4124 | }, |
| 4125 | }; |
| 4126 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4127 | static int vt1716S_parse_auto_config(struct hda_codec *codec) |
| 4128 | { |
| 4129 | struct via_spec *spec = codec->spec; |
| 4130 | int err; |
| 4131 | |
| 4132 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4133 | if (err < 0) |
| 4134 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4135 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4136 | if (err < 0) |
| 4137 | return err; |
| 4138 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4139 | return 0; /* can't find valid BIOS pin config */ |
| 4140 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4141 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4142 | if (err < 0) |
| 4143 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4144 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4145 | if (err < 0) |
| 4146 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4147 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4148 | if (err < 0) |
| 4149 | return err; |
| 4150 | |
| 4151 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4152 | |
| 4153 | fill_dig_outs(codec); |
| 4154 | |
| 4155 | if (spec->kctls.list) |
| 4156 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4157 | |
| 4158 | spec->input_mux = &spec->private_imux[0]; |
| 4159 | |
| 4160 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4161 | via_hp_build(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4162 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 4163 | err = via_smart51_build(codec); |
| 4164 | if (err < 0) |
| 4165 | return err; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4166 | |
| 4167 | return 1; |
| 4168 | } |
| 4169 | |
| 4170 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4171 | static const struct hda_amp_list vt1716S_loopbacks[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4172 | { 0x16, HDA_INPUT, 1 }, |
| 4173 | { 0x16, HDA_INPUT, 2 }, |
| 4174 | { 0x16, HDA_INPUT, 3 }, |
| 4175 | { 0x16, HDA_INPUT, 4 }, |
| 4176 | { } /* end */ |
| 4177 | }; |
| 4178 | #endif |
| 4179 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4180 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
| 4181 | { |
| 4182 | struct via_spec *spec = codec->spec; |
| 4183 | int imux_is_smixer; |
| 4184 | unsigned int parm; |
| 4185 | unsigned int mono_out, present; |
| 4186 | /* SW0 (17h) = stereo mixer */ |
| 4187 | imux_is_smixer = |
| 4188 | (snd_hda_codec_read(codec, 0x17, 0, |
| 4189 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); |
| 4190 | /* inputs */ |
| 4191 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 4192 | parm = AC_PWRST_D3; |
| 4193 | set_pin_power_state(codec, 0x1a, &parm); |
| 4194 | set_pin_power_state(codec, 0x1b, &parm); |
| 4195 | set_pin_power_state(codec, 0x1e, &parm); |
| 4196 | if (imux_is_smixer) |
| 4197 | parm = AC_PWRST_D0; |
| 4198 | /* SW0 (17h), AIW0(13h) */ |
| 4199 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4200 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4201 | |
| 4202 | parm = AC_PWRST_D3; |
| 4203 | set_pin_power_state(codec, 0x1e, &parm); |
| 4204 | /* PW11 (22h) */ |
| 4205 | if (spec->dmic_enabled) |
| 4206 | set_pin_power_state(codec, 0x22, &parm); |
| 4207 | else |
| 4208 | snd_hda_codec_write(codec, 0x22, 0, |
| 4209 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4210 | |
| 4211 | /* SW2(26h), AIW1(14h) */ |
| 4212 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4213 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4214 | |
| 4215 | /* outputs */ |
| 4216 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 4217 | parm = AC_PWRST_D3; |
| 4218 | set_pin_power_state(codec, 0x19, &parm); |
| 4219 | /* Smart 5.1 PW2(1bh) */ |
| 4220 | if (spec->smart51_enabled) |
| 4221 | set_pin_power_state(codec, 0x1b, &parm); |
| 4222 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4223 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4224 | |
| 4225 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 4226 | parm = AC_PWRST_D3; |
| 4227 | set_pin_power_state(codec, 0x23, &parm); |
| 4228 | /* Smart 5.1 PW1(1ah) */ |
| 4229 | if (spec->smart51_enabled) |
| 4230 | set_pin_power_state(codec, 0x1a, &parm); |
| 4231 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4232 | |
| 4233 | /* Smart 5.1 PW5(1eh) */ |
| 4234 | if (spec->smart51_enabled) |
| 4235 | set_pin_power_state(codec, 0x1e, &parm); |
| 4236 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4237 | |
| 4238 | /* Mono out */ |
| 4239 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 4240 | present = snd_hda_jack_detect(codec, 0x1c); |
| 4241 | |
| 4242 | if (present) |
| 4243 | mono_out = 0; |
| 4244 | else { |
| 4245 | present = snd_hda_jack_detect(codec, 0x1d); |
| 4246 | if (!spec->hp_independent_mode && present) |
| 4247 | mono_out = 0; |
| 4248 | else |
| 4249 | mono_out = 1; |
| 4250 | } |
| 4251 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
| 4252 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4253 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4254 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4255 | |
| 4256 | /* PW 3/4 (1ch/1dh) */ |
| 4257 | parm = AC_PWRST_D3; |
| 4258 | set_pin_power_state(codec, 0x1c, &parm); |
| 4259 | set_pin_power_state(codec, 0x1d, &parm); |
| 4260 | /* HP Independent Mode, power on AOW3 */ |
| 4261 | if (spec->hp_independent_mode) |
| 4262 | snd_hda_codec_write(codec, 0x25, 0, |
| 4263 | AC_VERB_SET_POWER_STATE, parm); |
| 4264 | |
| 4265 | /* force to D0 for internal Speaker */ |
| 4266 | /* MW0 (16h), AOW0 (10h) */ |
| 4267 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 4268 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 4269 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 4270 | mono_out ? AC_PWRST_D0 : parm); |
| 4271 | } |
| 4272 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4273 | static int patch_vt1716S(struct hda_codec *codec) |
| 4274 | { |
| 4275 | struct via_spec *spec; |
| 4276 | int err; |
| 4277 | |
| 4278 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4279 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4280 | if (spec == NULL) |
| 4281 | return -ENOMEM; |
| 4282 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4283 | spec->aa_mix_nid = 0x16; |
| 4284 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4285 | /* automatic parse from the BIOS config */ |
| 4286 | err = vt1716S_parse_auto_config(codec); |
| 4287 | if (err < 0) { |
| 4288 | via_free(codec); |
| 4289 | return err; |
| 4290 | } else if (!err) { |
| 4291 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4292 | "from BIOS. Using genenic mode...\n"); |
| 4293 | } |
| 4294 | |
| 4295 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; |
| 4296 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; |
| 4297 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4298 | spec->stream_analog_playback = &vt1716S_pcm_analog_playback; |
| 4299 | spec->stream_analog_capture = &vt1716S_pcm_analog_capture; |
| 4300 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4301 | spec->stream_digital_playback = &vt1716S_pcm_digital_playback; |
| 4302 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4303 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4304 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 4305 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
| 4306 | spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; |
| 4307 | spec->num_mixers++; |
| 4308 | } |
| 4309 | |
| 4310 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
| 4311 | spec->num_mixers++; |
| 4312 | |
| 4313 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 4314 | |
| 4315 | codec->patch_ops = via_patch_ops; |
| 4316 | |
| 4317 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 4318 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4319 | |
| 4320 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4321 | spec->loopback.amplist = vt1716S_loopbacks; |
| 4322 | #endif |
| 4323 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4324 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4325 | return 0; |
| 4326 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4327 | |
| 4328 | /* for vt2002P */ |
| 4329 | |
| 4330 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4331 | static const struct snd_kcontrol_new vt2002P_capture_mixer[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4332 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 4333 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 4334 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 4335 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 4336 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 4337 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 4338 | HDA_INPUT), |
| 4339 | { |
| 4340 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4341 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4342 | * So call somewhat different.. |
| 4343 | */ |
| 4344 | /* .name = "Capture Source", */ |
| 4345 | .name = "Input Source", |
| 4346 | .count = 2, |
| 4347 | .info = via_mux_enum_info, |
| 4348 | .get = via_mux_enum_get, |
| 4349 | .put = via_mux_enum_put, |
| 4350 | }, |
| 4351 | { } /* end */ |
| 4352 | }; |
| 4353 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4354 | static const struct hda_verb vt2002P_volume_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 4355 | /* Class-D speaker related verbs */ |
| 4356 | {0x1, 0xfe0, 0x4}, |
| 4357 | {0x1, 0xfe9, 0x80}, |
| 4358 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4359 | /* |
| 4360 | * Unmute ADC0-1 and set the default input to mic-in |
| 4361 | */ |
| 4362 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4363 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4364 | |
| 4365 | |
| 4366 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4367 | * mixer widget |
| 4368 | */ |
| 4369 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4370 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4371 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4372 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4373 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4374 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4375 | |
| 4376 | /* MUX Indices: Mic = 0 */ |
| 4377 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4378 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4379 | |
| 4380 | /* PW9 Output enable */ |
| 4381 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4382 | |
| 4383 | /* Enable Boost Volume backdoor */ |
| 4384 | {0x1, 0xfb9, 0x24}, |
| 4385 | |
| 4386 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 4387 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4388 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4389 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4390 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4391 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4392 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4393 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4394 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4395 | |
| 4396 | /* set MUX0/1/4/8 = 0 (AOW0) */ |
| 4397 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4398 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4399 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4400 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4401 | |
| 4402 | /* set PW0 index=0 (MW0) */ |
| 4403 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4404 | |
| 4405 | /* Enable AOW0 to MW9 */ |
| 4406 | {0x1, 0xfb8, 0x88}, |
| 4407 | { } |
| 4408 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4409 | static const struct hda_verb vt1802_volume_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4410 | /* |
| 4411 | * Unmute ADC0-1 and set the default input to mic-in |
| 4412 | */ |
| 4413 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4414 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4415 | |
| 4416 | |
| 4417 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4418 | * mixer widget |
| 4419 | */ |
| 4420 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4421 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4422 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4423 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4424 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4425 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4426 | |
| 4427 | /* MUX Indices: Mic = 0 */ |
| 4428 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4429 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4430 | |
| 4431 | /* PW9 Output enable */ |
| 4432 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4433 | |
| 4434 | /* Enable Boost Volume backdoor */ |
| 4435 | {0x1, 0xfb9, 0x24}, |
| 4436 | |
| 4437 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 4438 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4439 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4440 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4441 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4442 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4443 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4444 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4445 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4446 | |
| 4447 | /* set MUX0/1/4/8 = 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 | |
| 4453 | /* set PW0 index=0 (MW0) */ |
| 4454 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4455 | |
| 4456 | /* Enable AOW0 to MW9 */ |
| 4457 | {0x1, 0xfb8, 0x88}, |
| 4458 | { } |
| 4459 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4460 | |
| 4461 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4462 | static const struct hda_verb vt2002P_uniwill_init_verbs[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4463 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4464 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4465 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4466 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4467 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4468 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4469 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4470 | { } |
| 4471 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4472 | static const struct hda_verb vt1802_uniwill_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4473 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4474 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4475 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4476 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4477 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4478 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4479 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4480 | { } |
| 4481 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4482 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4483 | static const struct hda_pcm_stream vt2002P_pcm_analog_playback = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4484 | .substreams = 2, |
| 4485 | .channels_min = 2, |
| 4486 | .channels_max = 2, |
| 4487 | .nid = 0x8, /* NID to query formats and rates */ |
| 4488 | .ops = { |
| 4489 | .open = via_playback_pcm_open, |
| 4490 | .prepare = via_playback_multi_pcm_prepare, |
| 4491 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4492 | .close = via_pcm_open_close, |
| 4493 | }, |
| 4494 | }; |
| 4495 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4496 | static const struct hda_pcm_stream vt2002P_pcm_analog_capture = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4497 | .substreams = 2, |
| 4498 | .channels_min = 2, |
| 4499 | .channels_max = 2, |
| 4500 | .nid = 0x10, /* NID to query formats and rates */ |
| 4501 | .ops = { |
| 4502 | .open = via_pcm_open_close, |
| 4503 | .prepare = via_capture_pcm_prepare, |
| 4504 | .cleanup = via_capture_pcm_cleanup, |
| 4505 | .close = via_pcm_open_close, |
| 4506 | }, |
| 4507 | }; |
| 4508 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4509 | static const struct hda_pcm_stream vt2002P_pcm_digital_playback = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4510 | .substreams = 1, |
| 4511 | .channels_min = 2, |
| 4512 | .channels_max = 2, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4513 | /* NID is set in via_build_pcms */ |
| 4514 | .ops = { |
| 4515 | .open = via_dig_playback_pcm_open, |
| 4516 | .close = via_dig_playback_pcm_close, |
| 4517 | .prepare = via_dig_playback_pcm_prepare, |
| 4518 | .cleanup = via_dig_playback_pcm_cleanup |
| 4519 | }, |
| 4520 | }; |
| 4521 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4522 | static int vt2002P_parse_auto_config(struct hda_codec *codec) |
| 4523 | { |
| 4524 | struct via_spec *spec = codec->spec; |
| 4525 | int err; |
| 4526 | |
| 4527 | |
| 4528 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4529 | if (err < 0) |
| 4530 | return err; |
| 4531 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4532 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4533 | if (err < 0) |
| 4534 | return err; |
| 4535 | |
| 4536 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4537 | return 0; /* can't find valid BIOS pin config */ |
| 4538 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4539 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4540 | if (err < 0) |
| 4541 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4542 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4543 | if (err < 0) |
| 4544 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4545 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4546 | if (err < 0) |
| 4547 | return err; |
| 4548 | |
| 4549 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4550 | |
| 4551 | fill_dig_outs(codec); |
| 4552 | |
| 4553 | if (spec->kctls.list) |
| 4554 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4555 | |
| 4556 | spec->input_mux = &spec->private_imux[0]; |
| 4557 | |
| 4558 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4559 | via_hp_build(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4560 | |
| 4561 | return 1; |
| 4562 | } |
| 4563 | |
| 4564 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4565 | static const struct hda_amp_list vt2002P_loopbacks[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4566 | { 0x21, HDA_INPUT, 0 }, |
| 4567 | { 0x21, HDA_INPUT, 1 }, |
| 4568 | { 0x21, HDA_INPUT, 2 }, |
| 4569 | { } /* end */ |
| 4570 | }; |
| 4571 | #endif |
| 4572 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4573 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
| 4574 | { |
| 4575 | struct via_spec *spec = codec->spec; |
| 4576 | int imux_is_smixer; |
| 4577 | unsigned int parm; |
| 4578 | unsigned int present; |
| 4579 | /* MUX9 (1eh) = stereo mixer */ |
| 4580 | imux_is_smixer = |
| 4581 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 4582 | /* inputs */ |
| 4583 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 4584 | parm = AC_PWRST_D3; |
| 4585 | set_pin_power_state(codec, 0x29, &parm); |
| 4586 | set_pin_power_state(codec, 0x2a, &parm); |
| 4587 | set_pin_power_state(codec, 0x2b, &parm); |
| 4588 | parm = AC_PWRST_D0; |
| 4589 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 4590 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4591 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4592 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4593 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4594 | |
| 4595 | /* outputs */ |
| 4596 | /* AOW0 (8h)*/ |
| 4597 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4598 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4599 | if (spec->codec_type == VT1802) { |
| 4600 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 4601 | parm = AC_PWRST_D3; |
| 4602 | set_pin_power_state(codec, 0x28, &parm); |
| 4603 | snd_hda_codec_write(codec, 0x18, 0, |
| 4604 | AC_VERB_SET_POWER_STATE, parm); |
| 4605 | snd_hda_codec_write(codec, 0x38, 0, |
| 4606 | AC_VERB_SET_POWER_STATE, parm); |
| 4607 | } else { |
| 4608 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 4609 | parm = AC_PWRST_D3; |
| 4610 | set_pin_power_state(codec, 0x26, &parm); |
| 4611 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4612 | AC_VERB_SET_POWER_STATE, parm); |
| 4613 | snd_hda_codec_write(codec, 0x37, 0, |
| 4614 | AC_VERB_SET_POWER_STATE, parm); |
| 4615 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4616 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4617 | if (spec->codec_type == VT1802) { |
| 4618 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 4619 | parm = AC_PWRST_D3; |
| 4620 | set_pin_power_state(codec, 0x25, &parm); |
| 4621 | snd_hda_codec_write(codec, 0x15, 0, |
| 4622 | AC_VERB_SET_POWER_STATE, parm); |
| 4623 | snd_hda_codec_write(codec, 0x35, 0, |
| 4624 | AC_VERB_SET_POWER_STATE, parm); |
| 4625 | } else { |
| 4626 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 4627 | parm = AC_PWRST_D3; |
| 4628 | set_pin_power_state(codec, 0x25, &parm); |
| 4629 | snd_hda_codec_write(codec, 0x19, 0, |
| 4630 | AC_VERB_SET_POWER_STATE, parm); |
| 4631 | snd_hda_codec_write(codec, 0x35, 0, |
| 4632 | AC_VERB_SET_POWER_STATE, parm); |
| 4633 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4634 | |
| 4635 | if (spec->hp_independent_mode) |
| 4636 | snd_hda_codec_write(codec, 0x9, 0, |
| 4637 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4638 | |
| 4639 | /* Class-D */ |
| 4640 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ |
| 4641 | present = snd_hda_jack_detect(codec, 0x25); |
| 4642 | |
| 4643 | parm = AC_PWRST_D3; |
| 4644 | set_pin_power_state(codec, 0x24, &parm); |
| 4645 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4646 | if (spec->codec_type == VT1802) |
| 4647 | snd_hda_codec_write(codec, 0x14, 0, |
| 4648 | AC_VERB_SET_POWER_STATE, parm); |
| 4649 | else |
| 4650 | snd_hda_codec_write(codec, 0x18, 0, |
| 4651 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4652 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4653 | |
| 4654 | /* Mono Out */ |
| 4655 | present = snd_hda_jack_detect(codec, 0x26); |
| 4656 | |
| 4657 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4658 | if (spec->codec_type == VT1802) { |
| 4659 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ |
| 4660 | snd_hda_codec_write(codec, 0x33, 0, |
| 4661 | AC_VERB_SET_POWER_STATE, parm); |
| 4662 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4663 | AC_VERB_SET_POWER_STATE, parm); |
| 4664 | snd_hda_codec_write(codec, 0x3c, 0, |
| 4665 | AC_VERB_SET_POWER_STATE, parm); |
| 4666 | } else { |
| 4667 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
| 4668 | snd_hda_codec_write(codec, 0x31, 0, |
| 4669 | AC_VERB_SET_POWER_STATE, parm); |
| 4670 | snd_hda_codec_write(codec, 0x17, 0, |
| 4671 | AC_VERB_SET_POWER_STATE, parm); |
| 4672 | snd_hda_codec_write(codec, 0x3b, 0, |
| 4673 | AC_VERB_SET_POWER_STATE, parm); |
| 4674 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4675 | /* MW9 (21h) */ |
| 4676 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 4677 | snd_hda_codec_write(codec, 0x21, 0, |
| 4678 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4679 | else |
| 4680 | snd_hda_codec_write(codec, 0x21, 0, |
| 4681 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4682 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4683 | |
| 4684 | /* patch for vt2002P */ |
| 4685 | static int patch_vt2002P(struct hda_codec *codec) |
| 4686 | { |
| 4687 | struct via_spec *spec; |
| 4688 | int err; |
| 4689 | |
| 4690 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4691 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4692 | if (spec == NULL) |
| 4693 | return -ENOMEM; |
| 4694 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4695 | spec->aa_mix_nid = 0x21; |
| 4696 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4697 | /* automatic parse from the BIOS config */ |
| 4698 | err = vt2002P_parse_auto_config(codec); |
| 4699 | if (err < 0) { |
| 4700 | via_free(codec); |
| 4701 | return err; |
| 4702 | } else if (!err) { |
| 4703 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4704 | "from BIOS. Using genenic mode...\n"); |
| 4705 | } |
| 4706 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4707 | if (spec->codec_type == VT1802) |
| 4708 | spec->init_verbs[spec->num_iverbs++] = |
| 4709 | vt1802_volume_init_verbs; |
| 4710 | else |
| 4711 | spec->init_verbs[spec->num_iverbs++] = |
| 4712 | vt2002P_volume_init_verbs; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4713 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 4714 | if (spec->codec_type == VT1802) |
| 4715 | spec->init_verbs[spec->num_iverbs++] = |
| 4716 | vt1802_uniwill_init_verbs; |
| 4717 | else |
| 4718 | spec->init_verbs[spec->num_iverbs++] = |
| 4719 | vt2002P_uniwill_init_verbs; |
| 4720 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4721 | spec->stream_analog_playback = &vt2002P_pcm_analog_playback; |
| 4722 | spec->stream_analog_capture = &vt2002P_pcm_analog_capture; |
| 4723 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4724 | spec->stream_digital_playback = &vt2002P_pcm_digital_playback; |
| 4725 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4726 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4727 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 4728 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 4729 | spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; |
| 4730 | spec->num_mixers++; |
| 4731 | } |
| 4732 | |
| 4733 | codec->patch_ops = via_patch_ops; |
| 4734 | |
| 4735 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 4736 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4737 | |
| 4738 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4739 | spec->loopback.amplist = vt2002P_loopbacks; |
| 4740 | #endif |
| 4741 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4742 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 4743 | return 0; |
| 4744 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4745 | |
| 4746 | /* for vt1812 */ |
| 4747 | |
| 4748 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4749 | static const struct snd_kcontrol_new vt1812_capture_mixer[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4750 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 4751 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 4752 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 4753 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 4754 | HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 4755 | HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 4756 | HDA_INPUT), |
| 4757 | { |
| 4758 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4759 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4760 | * So call somewhat different.. |
| 4761 | */ |
| 4762 | .name = "Input Source", |
| 4763 | .count = 2, |
| 4764 | .info = via_mux_enum_info, |
| 4765 | .get = via_mux_enum_get, |
| 4766 | .put = via_mux_enum_put, |
| 4767 | }, |
| 4768 | { } /* end */ |
| 4769 | }; |
| 4770 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4771 | static const struct hda_verb vt1812_volume_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4772 | /* |
| 4773 | * Unmute ADC0-1 and set the default input to mic-in |
| 4774 | */ |
| 4775 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4776 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4777 | |
| 4778 | |
| 4779 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4780 | * mixer widget |
| 4781 | */ |
| 4782 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4783 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4784 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4785 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4786 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4787 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4788 | |
| 4789 | /* MUX Indices: Mic = 0 */ |
| 4790 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4791 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4792 | |
| 4793 | /* PW9 Output enable */ |
| 4794 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4795 | |
| 4796 | /* Enable Boost Volume backdoor */ |
| 4797 | {0x1, 0xfb9, 0x24}, |
| 4798 | |
| 4799 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 4800 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4801 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4802 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4803 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4804 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4805 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4806 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4807 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4808 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4809 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4810 | |
| 4811 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ |
| 4812 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4813 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4814 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4815 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4816 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, |
| 4817 | |
| 4818 | /* Enable AOW0 to MW9 */ |
| 4819 | {0x1, 0xfb8, 0xa8}, |
| 4820 | { } |
| 4821 | }; |
| 4822 | |
| 4823 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4824 | static const struct hda_verb vt1812_uniwill_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4825 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4826 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4827 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, |
| 4828 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4829 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 4830 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4831 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4832 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4833 | { } |
| 4834 | }; |
| 4835 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4836 | static const struct hda_pcm_stream vt1812_pcm_analog_playback = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4837 | .substreams = 2, |
| 4838 | .channels_min = 2, |
| 4839 | .channels_max = 2, |
| 4840 | .nid = 0x8, /* NID to query formats and rates */ |
| 4841 | .ops = { |
| 4842 | .open = via_playback_pcm_open, |
| 4843 | .prepare = via_playback_multi_pcm_prepare, |
| 4844 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4845 | .close = via_pcm_open_close, |
| 4846 | }, |
| 4847 | }; |
| 4848 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4849 | static const struct hda_pcm_stream vt1812_pcm_analog_capture = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4850 | .substreams = 2, |
| 4851 | .channels_min = 2, |
| 4852 | .channels_max = 2, |
| 4853 | .nid = 0x10, /* NID to query formats and rates */ |
| 4854 | .ops = { |
| 4855 | .open = via_pcm_open_close, |
| 4856 | .prepare = via_capture_pcm_prepare, |
| 4857 | .cleanup = via_capture_pcm_cleanup, |
| 4858 | .close = via_pcm_open_close, |
| 4859 | }, |
| 4860 | }; |
| 4861 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4862 | static const struct hda_pcm_stream vt1812_pcm_digital_playback = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4863 | .substreams = 1, |
| 4864 | .channels_min = 2, |
| 4865 | .channels_max = 2, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4866 | /* NID is set in via_build_pcms */ |
| 4867 | .ops = { |
| 4868 | .open = via_dig_playback_pcm_open, |
| 4869 | .close = via_dig_playback_pcm_close, |
| 4870 | .prepare = via_dig_playback_pcm_prepare, |
| 4871 | .cleanup = via_dig_playback_pcm_cleanup |
| 4872 | }, |
| 4873 | }; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4874 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4875 | static int vt1812_parse_auto_config(struct hda_codec *codec) |
| 4876 | { |
| 4877 | struct via_spec *spec = codec->spec; |
| 4878 | int err; |
| 4879 | |
| 4880 | |
| 4881 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4882 | if (err < 0) |
| 4883 | return err; |
| 4884 | fill_dig_outs(codec); |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4885 | err = via_auto_fill_dac_nids(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4886 | if (err < 0) |
| 4887 | return err; |
| 4888 | |
| 4889 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) |
| 4890 | return 0; /* can't find valid BIOS pin config */ |
| 4891 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4892 | err = via_auto_create_multi_out_ctls(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4893 | if (err < 0) |
| 4894 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 4895 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4896 | if (err < 0) |
| 4897 | return err; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 4898 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4899 | if (err < 0) |
| 4900 | return err; |
| 4901 | |
| 4902 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4903 | |
| 4904 | fill_dig_outs(codec); |
| 4905 | |
| 4906 | if (spec->kctls.list) |
| 4907 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4908 | |
| 4909 | spec->input_mux = &spec->private_imux[0]; |
| 4910 | |
| 4911 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4912 | via_hp_build(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4913 | |
| 4914 | return 1; |
| 4915 | } |
| 4916 | |
| 4917 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4918 | static const struct hda_amp_list vt1812_loopbacks[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 4919 | { 0x21, HDA_INPUT, 0 }, |
| 4920 | { 0x21, HDA_INPUT, 1 }, |
| 4921 | { 0x21, HDA_INPUT, 2 }, |
| 4922 | { } /* end */ |
| 4923 | }; |
| 4924 | #endif |
| 4925 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4926 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
| 4927 | { |
| 4928 | struct via_spec *spec = codec->spec; |
| 4929 | int imux_is_smixer = |
| 4930 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 4931 | unsigned int parm; |
| 4932 | unsigned int present; |
| 4933 | /* MUX10 (1eh) = stereo mixer */ |
| 4934 | imux_is_smixer = |
| 4935 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 4936 | /* inputs */ |
| 4937 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 4938 | parm = AC_PWRST_D3; |
| 4939 | set_pin_power_state(codec, 0x29, &parm); |
| 4940 | set_pin_power_state(codec, 0x2a, &parm); |
| 4941 | set_pin_power_state(codec, 0x2b, &parm); |
| 4942 | parm = AC_PWRST_D0; |
| 4943 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 4944 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4945 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4946 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4947 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4948 | |
| 4949 | /* outputs */ |
| 4950 | /* AOW0 (8h)*/ |
| 4951 | snd_hda_codec_write(codec, 0x8, 0, |
| 4952 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4953 | |
| 4954 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 4955 | parm = AC_PWRST_D3; |
| 4956 | set_pin_power_state(codec, 0x28, &parm); |
| 4957 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4958 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4959 | |
| 4960 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 4961 | parm = AC_PWRST_D3; |
| 4962 | set_pin_power_state(codec, 0x25, &parm); |
| 4963 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4964 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4965 | if (spec->hp_independent_mode) |
| 4966 | snd_hda_codec_write(codec, 0x9, 0, |
| 4967 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4968 | |
| 4969 | /* Internal Speaker */ |
| 4970 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 4971 | present = snd_hda_jack_detect(codec, 0x25); |
| 4972 | |
| 4973 | parm = AC_PWRST_D3; |
| 4974 | set_pin_power_state(codec, 0x24, &parm); |
| 4975 | if (present) { |
| 4976 | snd_hda_codec_write(codec, 0x14, 0, |
| 4977 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4978 | snd_hda_codec_write(codec, 0x34, 0, |
| 4979 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4980 | } else { |
| 4981 | snd_hda_codec_write(codec, 0x14, 0, |
| 4982 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4983 | snd_hda_codec_write(codec, 0x34, 0, |
| 4984 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 4985 | } |
| 4986 | |
| 4987 | |
| 4988 | /* Mono Out */ |
| 4989 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 4990 | present = snd_hda_jack_detect(codec, 0x28); |
| 4991 | |
| 4992 | parm = AC_PWRST_D3; |
| 4993 | set_pin_power_state(codec, 0x31, &parm); |
| 4994 | if (present) { |
| 4995 | snd_hda_codec_write(codec, 0x1c, 0, |
| 4996 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4997 | snd_hda_codec_write(codec, 0x3c, 0, |
| 4998 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 4999 | snd_hda_codec_write(codec, 0x3e, 0, |
| 5000 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 5001 | } else { |
| 5002 | snd_hda_codec_write(codec, 0x1c, 0, |
| 5003 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 5004 | snd_hda_codec_write(codec, 0x3c, 0, |
| 5005 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 5006 | snd_hda_codec_write(codec, 0x3e, 0, |
| 5007 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 5008 | } |
| 5009 | |
| 5010 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 5011 | parm = AC_PWRST_D3; |
| 5012 | set_pin_power_state(codec, 0x33, &parm); |
| 5013 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5014 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5015 | |
| 5016 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5017 | |
| 5018 | /* patch for vt1812 */ |
| 5019 | static int patch_vt1812(struct hda_codec *codec) |
| 5020 | { |
| 5021 | struct via_spec *spec; |
| 5022 | int err; |
| 5023 | |
| 5024 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 5025 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5026 | if (spec == NULL) |
| 5027 | return -ENOMEM; |
| 5028 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 5029 | spec->aa_mix_nid = 0x21; |
| 5030 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5031 | /* automatic parse from the BIOS config */ |
| 5032 | err = vt1812_parse_auto_config(codec); |
| 5033 | if (err < 0) { |
| 5034 | via_free(codec); |
| 5035 | return err; |
| 5036 | } else if (!err) { |
| 5037 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 5038 | "from BIOS. Using genenic mode...\n"); |
| 5039 | } |
| 5040 | |
| 5041 | |
| 5042 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; |
| 5043 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; |
| 5044 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5045 | spec->stream_analog_playback = &vt1812_pcm_analog_playback; |
| 5046 | spec->stream_analog_capture = &vt1812_pcm_analog_capture; |
| 5047 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5048 | spec->stream_digital_playback = &vt1812_pcm_digital_playback; |
| 5049 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 5050 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5051 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 5052 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 5053 | spec->mixers[spec->num_mixers] = vt1812_capture_mixer; |
| 5054 | spec->num_mixers++; |
| 5055 | } |
| 5056 | |
| 5057 | codec->patch_ops = via_patch_ops; |
| 5058 | |
| 5059 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 5060 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5061 | |
| 5062 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5063 | spec->loopback.amplist = vt1812_loopbacks; |
| 5064 | #endif |
| 5065 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5066 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5067 | return 0; |
| 5068 | } |
| 5069 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 5070 | /* |
| 5071 | * patch entries |
| 5072 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5073 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5074 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 5075 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 5076 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 5077 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 5078 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5079 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5080 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5081 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5082 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5083 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5084 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5085 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5086 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5087 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5088 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5089 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5090 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5091 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5092 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5093 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5094 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5095 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5096 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5097 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5098 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5099 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5100 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5101 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5102 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5103 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5104 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5105 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5106 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5107 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5108 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 5109 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5110 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5111 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5112 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5113 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5114 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5115 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5116 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5117 | .patch = patch_vt1708S}, |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 5118 | { .id = 0x11064397, .name = "VT1705", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5119 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5120 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5121 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5122 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5123 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5124 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5125 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5126 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5127 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5128 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5129 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5130 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5131 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5132 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5133 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5134 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5135 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5136 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5137 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5138 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5139 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 5140 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 5141 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 5142 | { .id = 0x11060428, .name = "VT1718S", |
| 5143 | .patch = patch_vt1718S}, |
| 5144 | { .id = 0x11064428, .name = "VT1718S", |
| 5145 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 5146 | { .id = 0x11060441, .name = "VT2020", |
| 5147 | .patch = patch_vt1718S}, |
| 5148 | { .id = 0x11064441, .name = "VT1828S", |
| 5149 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5150 | { .id = 0x11060433, .name = "VT1716S", |
| 5151 | .patch = patch_vt1716S}, |
| 5152 | { .id = 0x1106a721, .name = "VT1716S", |
| 5153 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5154 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 5155 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5156 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 5157 | { .id = 0x11060440, .name = "VT1818S", |
| 5158 | .patch = patch_vt1708S}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5159 | { .id = 0x11060446, .name = "VT1802", |
| 5160 | .patch = patch_vt2002P}, |
| 5161 | { .id = 0x11068446, .name = "VT1802", |
| 5162 | .patch = patch_vt2002P}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 5163 | {} /* terminator */ |
| 5164 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 5165 | |
| 5166 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 5167 | |
| 5168 | static struct hda_codec_preset_list via_list = { |
| 5169 | .preset = snd_hda_preset_via, |
| 5170 | .owner = THIS_MODULE, |
| 5171 | }; |
| 5172 | |
| 5173 | MODULE_LICENSE("GPL"); |
| 5174 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 5175 | |
| 5176 | static int __init patch_via_init(void) |
| 5177 | { |
| 5178 | return snd_hda_add_codec_preset(&via_list); |
| 5179 | } |
| 5180 | |
| 5181 | static void __exit patch_via_exit(void) |
| 5182 | { |
| 5183 | snd_hda_delete_codec_preset(&via_list); |
| 5184 | } |
| 5185 | |
| 5186 | module_init(patch_via_init) |
| 5187 | module_exit(patch_via_exit) |