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