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 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 110 | struct via_spec { |
| 111 | /* codec parameterization */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 112 | const struct snd_kcontrol_new *mixers[6]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 113 | unsigned int num_mixers; |
| 114 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 115 | const struct hda_verb *init_verbs[5]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 116 | unsigned int num_iverbs; |
| 117 | |
| 118 | char *stream_name_analog; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 119 | const struct hda_pcm_stream *stream_analog_playback; |
| 120 | const struct hda_pcm_stream *stream_analog_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 121 | |
| 122 | char *stream_name_digital; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 123 | const struct hda_pcm_stream *stream_digital_playback; |
| 124 | const struct hda_pcm_stream *stream_digital_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 125 | |
| 126 | /* playback */ |
| 127 | struct hda_multi_out multiout; |
| 128 | hda_nid_t slave_dig_outs[2]; |
| 129 | |
| 130 | /* capture */ |
| 131 | unsigned int num_adc_nids; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 132 | hda_nid_t adc_nids[3]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 133 | hda_nid_t mux_nids[3]; |
| 134 | hda_nid_t dig_in_nid; |
| 135 | hda_nid_t dig_in_pin; |
| 136 | |
| 137 | /* capture source */ |
| 138 | const struct hda_input_mux *input_mux; |
| 139 | unsigned int cur_mux[3]; |
| 140 | |
| 141 | /* PCM information */ |
| 142 | struct hda_pcm pcm_rec[3]; |
| 143 | |
| 144 | /* dynamic controls, init_verbs and input_mux */ |
| 145 | struct auto_pin_cfg autocfg; |
| 146 | struct snd_array kctls; |
| 147 | struct hda_input_mux private_imux[2]; |
| 148 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
| 149 | |
| 150 | /* HP mode source */ |
| 151 | const struct hda_input_mux *hp_mux; |
| 152 | unsigned int hp_independent_mode; |
| 153 | unsigned int hp_independent_mode_index; |
| 154 | unsigned int smart51_enabled; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 155 | unsigned int dmic_enabled; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 156 | unsigned int no_pin_power_ctl; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 157 | enum VIA_HDA_CODEC codec_type; |
| 158 | |
| 159 | /* work to check hp jack state */ |
| 160 | struct hda_codec *codec; |
| 161 | struct delayed_work vt1708_hp_work; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 162 | int vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 163 | int vt1708_hp_present; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 164 | |
| 165 | void (*set_widgets_power_state)(struct hda_codec *codec); |
| 166 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 167 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 168 | struct hda_loopback_check loopback; |
| 169 | #endif |
| 170 | }; |
| 171 | |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 172 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 173 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
| 174 | { |
| 175 | struct via_spec *spec; |
| 176 | |
| 177 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 178 | if (spec == NULL) |
| 179 | return NULL; |
| 180 | |
| 181 | codec->spec = spec; |
| 182 | spec->codec = codec; |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 183 | spec->codec_type = get_codec_type(codec); |
| 184 | /* VT1708BCE & VT1708S are almost same */ |
| 185 | if (spec->codec_type == VT1708BCE) |
| 186 | spec->codec_type = VT1708S; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 187 | return spec; |
| 188 | } |
| 189 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 190 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 191 | { |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 192 | u32 vendor_id = codec->vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 193 | u16 ven_id = vendor_id >> 16; |
| 194 | u16 dev_id = vendor_id & 0xffff; |
| 195 | enum VIA_HDA_CODEC codec_type; |
| 196 | |
| 197 | /* get codec type */ |
| 198 | if (ven_id != 0x1106) |
| 199 | codec_type = UNKNOWN; |
| 200 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 201 | codec_type = VT1708; |
| 202 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 203 | codec_type = VT1709_10CH; |
| 204 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 205 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 206 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 207 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 208 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 209 | codec_type = VT1708BCE; |
| 210 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 211 | codec_type = VT1708B_4CH; |
| 212 | else if ((dev_id & 0xfff) == 0x397 |
| 213 | && (dev_id >> 12) < 8) |
| 214 | codec_type = VT1708S; |
| 215 | else if ((dev_id & 0xfff) == 0x398 |
| 216 | && (dev_id >> 12) < 8) |
| 217 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 218 | else if ((dev_id & 0xfff) == 0x428 |
| 219 | && (dev_id >> 12) < 8) |
| 220 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 221 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 222 | codec_type = VT1716S; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 223 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 224 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 225 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 226 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 227 | else if (dev_id == 0x0448) |
| 228 | codec_type = VT1812; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 229 | else if (dev_id == 0x0440) |
| 230 | codec_type = VT1708S; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 231 | else if ((dev_id & 0xfff) == 0x446) |
| 232 | codec_type = VT1802; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 233 | else |
| 234 | codec_type = UNKNOWN; |
| 235 | return codec_type; |
| 236 | }; |
| 237 | |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 238 | #define VIA_JACK_EVENT 0x20 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 239 | #define VIA_HP_EVENT 0x01 |
| 240 | #define VIA_GPIO_EVENT 0x02 |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 241 | #define VIA_MONO_EVENT 0x03 |
| 242 | #define VIA_SPEAKER_EVENT 0x04 |
| 243 | #define VIA_BIND_HP_EVENT 0x05 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 244 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 245 | enum { |
| 246 | VIA_CTL_WIDGET_VOL, |
| 247 | VIA_CTL_WIDGET_MUTE, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 248 | VIA_CTL_WIDGET_ANALOG_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 249 | VIA_CTL_WIDGET_BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | enum { |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 253 | AUTO_SEQ_FRONT = 0, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 254 | AUTO_SEQ_SURROUND, |
| 255 | AUTO_SEQ_CENLFE, |
| 256 | AUTO_SEQ_SIDE |
| 257 | }; |
| 258 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 259 | 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] | 260 | static int is_aa_path_mute(struct hda_codec *codec); |
| 261 | |
| 262 | static void vt1708_start_hp_work(struct via_spec *spec) |
| 263 | { |
| 264 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 265 | return; |
| 266 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 267 | !spec->vt1708_jack_detect); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 268 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
| 269 | schedule_delayed_work(&spec->vt1708_hp_work, |
| 270 | msecs_to_jiffies(100)); |
| 271 | } |
| 272 | |
| 273 | static void vt1708_stop_hp_work(struct via_spec *spec) |
| 274 | { |
| 275 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 276 | return; |
| 277 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 |
| 278 | && !is_aa_path_mute(spec->codec)) |
| 279 | return; |
| 280 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 281 | !spec->vt1708_jack_detect); |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 282 | cancel_delayed_work_sync(&spec->vt1708_hp_work); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 283 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 284 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 285 | static void set_widgets_power_state(struct hda_codec *codec) |
| 286 | { |
| 287 | struct via_spec *spec = codec->spec; |
| 288 | if (spec->set_widgets_power_state) |
| 289 | spec->set_widgets_power_state(codec); |
| 290 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 291 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 292 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
| 293 | struct snd_ctl_elem_value *ucontrol) |
| 294 | { |
| 295 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 296 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 297 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 298 | set_widgets_power_state(codec); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 299 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 300 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
| 301 | if (is_aa_path_mute(codec)) |
| 302 | vt1708_start_hp_work(codec->spec); |
| 303 | else |
| 304 | vt1708_stop_hp_work(codec->spec); |
| 305 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 306 | return change; |
| 307 | } |
| 308 | |
| 309 | /* modify .put = snd_hda_mixer_amp_switch_put */ |
| 310 | #define ANALOG_INPUT_MUTE \ |
| 311 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 312 | .name = NULL, \ |
| 313 | .index = 0, \ |
| 314 | .info = snd_hda_mixer_amp_switch_info, \ |
| 315 | .get = snd_hda_mixer_amp_switch_get, \ |
| 316 | .put = analog_input_switch_put, \ |
| 317 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 318 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 319 | static void via_hp_bind_automute(struct hda_codec *codec); |
| 320 | |
| 321 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, |
| 322 | struct snd_ctl_elem_value *ucontrol) |
| 323 | { |
| 324 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 325 | struct via_spec *spec = codec->spec; |
| 326 | int i; |
| 327 | int change = 0; |
| 328 | |
| 329 | long *valp = ucontrol->value.integer.value; |
| 330 | int lmute, rmute; |
| 331 | if (strstr(kcontrol->id.name, "Switch") == NULL) { |
| 332 | snd_printd("Invalid control!\n"); |
| 333 | return change; |
| 334 | } |
| 335 | change = snd_hda_mixer_amp_switch_put(kcontrol, |
| 336 | ucontrol); |
| 337 | /* Get mute value */ |
| 338 | lmute = *valp ? 0 : HDA_AMP_MUTE; |
| 339 | valp++; |
| 340 | rmute = *valp ? 0 : HDA_AMP_MUTE; |
| 341 | |
| 342 | /* Set hp pins */ |
| 343 | if (!spec->hp_independent_mode) { |
| 344 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 345 | snd_hda_codec_amp_update( |
| 346 | codec, spec->autocfg.hp_pins[i], |
| 347 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 348 | lmute); |
| 349 | snd_hda_codec_amp_update( |
| 350 | codec, spec->autocfg.hp_pins[i], |
| 351 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 352 | rmute); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if (!lmute && !rmute) { |
| 357 | /* Line Outs */ |
| 358 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 359 | snd_hda_codec_amp_stereo( |
| 360 | codec, spec->autocfg.line_out_pins[i], |
| 361 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 362 | /* Speakers */ |
| 363 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 364 | snd_hda_codec_amp_stereo( |
| 365 | codec, spec->autocfg.speaker_pins[i], |
| 366 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 367 | /* unmute */ |
| 368 | via_hp_bind_automute(codec); |
| 369 | |
| 370 | } else { |
| 371 | if (lmute) { |
| 372 | /* Mute all left channels */ |
| 373 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 374 | snd_hda_codec_amp_update( |
| 375 | codec, |
| 376 | spec->autocfg.line_out_pins[i], |
| 377 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 378 | lmute); |
| 379 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 380 | snd_hda_codec_amp_update( |
| 381 | codec, |
| 382 | spec->autocfg.speaker_pins[i], |
| 383 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 384 | lmute); |
| 385 | } |
| 386 | if (rmute) { |
| 387 | /* mute all right channels */ |
| 388 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 389 | snd_hda_codec_amp_update( |
| 390 | codec, |
| 391 | spec->autocfg.line_out_pins[i], |
| 392 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 393 | rmute); |
| 394 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 395 | snd_hda_codec_amp_update( |
| 396 | codec, |
| 397 | spec->autocfg.speaker_pins[i], |
| 398 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 399 | rmute); |
| 400 | } |
| 401 | } |
| 402 | return change; |
| 403 | } |
| 404 | |
| 405 | #define BIND_PIN_MUTE \ |
| 406 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 407 | .name = NULL, \ |
| 408 | .index = 0, \ |
| 409 | .info = snd_hda_mixer_amp_switch_info, \ |
| 410 | .get = snd_hda_mixer_amp_switch_get, \ |
| 411 | .put = bind_pin_switch_put, \ |
| 412 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 413 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 414 | static const struct snd_kcontrol_new via_control_templates[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 415 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 416 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 417 | ANALOG_INPUT_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 418 | BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 419 | }; |
| 420 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 421 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 422 | /* add dynamic controls */ |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame^] | 423 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
| 424 | const struct snd_kcontrol_new *tmpl, |
| 425 | const char *name) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 426 | { |
| 427 | struct snd_kcontrol_new *knew; |
| 428 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 429 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
| 430 | knew = snd_array_new(&spec->kctls); |
| 431 | if (!knew) |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame^] | 432 | return NULL; |
| 433 | *knew = *tmpl; |
| 434 | if (!name) |
| 435 | name = tmpl->name; |
| 436 | if (name) { |
| 437 | knew->name = kstrdup(name, GFP_KERNEL); |
| 438 | if (!knew->name) |
| 439 | return NULL; |
| 440 | } |
| 441 | return knew; |
| 442 | } |
| 443 | |
| 444 | static int __via_add_control(struct via_spec *spec, int type, const char *name, |
| 445 | int idx, unsigned long val) |
| 446 | { |
| 447 | struct snd_kcontrol_new *knew; |
| 448 | |
| 449 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); |
| 450 | if (!knew) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 451 | return -ENOMEM; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 452 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 453 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 454 | knew->private_value = val; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 458 | #define via_add_control(spec, type, name, val) \ |
| 459 | __via_add_control(spec, type, name, 0, val) |
| 460 | |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame^] | 461 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 462 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 463 | static void via_free_kctls(struct hda_codec *codec) |
| 464 | { |
| 465 | struct via_spec *spec = codec->spec; |
| 466 | |
| 467 | if (spec->kctls.list) { |
| 468 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 469 | int i; |
| 470 | for (i = 0; i < spec->kctls.used; i++) |
| 471 | kfree(kctl[i].name); |
| 472 | } |
| 473 | snd_array_free(&spec->kctls); |
| 474 | } |
| 475 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 476 | /* create input playback/capture controls for the given pin */ |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 477 | 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] | 478 | int type_idx, int idx, int mix_nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 479 | { |
| 480 | char name[32]; |
| 481 | int err; |
| 482 | |
| 483 | sprintf(name, "%s Playback Volume", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 484 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 485 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 486 | if (err < 0) |
| 487 | return err; |
| 488 | sprintf(name, "%s Playback Switch", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 489 | 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] | 490 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 491 | if (err < 0) |
| 492 | return err; |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static void via_auto_set_output_and_unmute(struct hda_codec *codec, |
| 497 | hda_nid_t nid, int pin_type, |
| 498 | int dac_idx) |
| 499 | { |
| 500 | /* set as output */ |
| 501 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 502 | pin_type); |
| 503 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 504 | AMP_OUT_UNMUTE); |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 505 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 506 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 507 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | |
| 511 | static void via_auto_init_multi_out(struct hda_codec *codec) |
| 512 | { |
| 513 | struct via_spec *spec = codec->spec; |
| 514 | int i; |
| 515 | |
| 516 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 517 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 518 | if (nid) |
| 519 | via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | static void via_auto_init_hp_out(struct hda_codec *codec) |
| 524 | { |
| 525 | struct via_spec *spec = codec->spec; |
| 526 | hda_nid_t pin; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 527 | int i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 528 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 529 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 530 | pin = spec->autocfg.hp_pins[i]; |
| 531 | if (pin) /* connect to front */ |
| 532 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); |
| 533 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 534 | } |
| 535 | |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 536 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin); |
| 537 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 538 | static void via_auto_init_analog_input(struct hda_codec *codec) |
| 539 | { |
| 540 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 541 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 542 | unsigned int ctl; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 543 | int i; |
| 544 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 545 | for (i = 0; i < cfg->num_inputs; i++) { |
| 546 | hda_nid_t nid = cfg->inputs[i].pin; |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 547 | if (spec->smart51_enabled && is_smart51_pins(spec, nid)) |
| 548 | ctl = PIN_OUT; |
David Henningsson | 3064967 | 2011-02-21 10:23:18 +0100 | [diff] [blame] | 549 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 550 | ctl = PIN_VREF50; |
| 551 | else |
| 552 | ctl = PIN_IN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 553 | snd_hda_codec_write(codec, nid, 0, |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 554 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 555 | } |
| 556 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 557 | |
| 558 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 559 | unsigned int *affected_parm) |
| 560 | { |
| 561 | unsigned parm; |
| 562 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 563 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) |
| 564 | >> AC_DEFCFG_MISC_SHIFT |
| 565 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 566 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 567 | unsigned present = 0; |
| 568 | |
| 569 | no_presence |= spec->no_pin_power_ctl; |
| 570 | if (!no_presence) |
| 571 | present = snd_hda_jack_detect(codec, nid); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 572 | if ((spec->smart51_enabled && is_smart51_pins(spec, nid)) |
| 573 | || ((no_presence || present) |
| 574 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 575 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
| 576 | parm = AC_PWRST_D0; |
| 577 | } else |
| 578 | parm = AC_PWRST_D3; |
| 579 | |
| 580 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 581 | } |
| 582 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 583 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
| 584 | struct snd_ctl_elem_info *uinfo) |
| 585 | { |
| 586 | static const char * const texts[] = { |
| 587 | "Disabled", "Enabled" |
| 588 | }; |
| 589 | |
| 590 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 591 | uinfo->count = 1; |
| 592 | uinfo->value.enumerated.items = 2; |
| 593 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 594 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 595 | strcpy(uinfo->value.enumerated.name, |
| 596 | texts[uinfo->value.enumerated.item]); |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, |
| 601 | struct snd_ctl_elem_value *ucontrol) |
| 602 | { |
| 603 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 604 | struct via_spec *spec = codec->spec; |
| 605 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, |
| 610 | struct snd_ctl_elem_value *ucontrol) |
| 611 | { |
| 612 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 613 | struct via_spec *spec = codec->spec; |
| 614 | unsigned int val = !ucontrol->value.enumerated.item[0]; |
| 615 | |
| 616 | if (val == spec->no_pin_power_ctl) |
| 617 | return 0; |
| 618 | spec->no_pin_power_ctl = val; |
| 619 | set_widgets_power_state(codec); |
| 620 | return 1; |
| 621 | } |
| 622 | |
| 623 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { |
| 624 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 625 | .name = "Dynamic Power-Control", |
| 626 | .info = via_pin_power_ctl_info, |
| 627 | .get = via_pin_power_ctl_get, |
| 628 | .put = via_pin_power_ctl_put, |
| 629 | }; |
| 630 | |
| 631 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 632 | /* |
| 633 | * input MUX handling |
| 634 | */ |
| 635 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 636 | struct snd_ctl_elem_info *uinfo) |
| 637 | { |
| 638 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 639 | struct via_spec *spec = codec->spec; |
| 640 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
| 641 | } |
| 642 | |
| 643 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 644 | struct snd_ctl_elem_value *ucontrol) |
| 645 | { |
| 646 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 647 | struct via_spec *spec = codec->spec; |
| 648 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 649 | |
| 650 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 655 | struct snd_ctl_elem_value *ucontrol) |
| 656 | { |
| 657 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 658 | struct via_spec *spec = codec->spec; |
| 659 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 660 | int ret; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 661 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 662 | if (!spec->mux_nids[adc_idx]) |
| 663 | return -EINVAL; |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 664 | /* switch to D0 beofre change index */ |
| 665 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, |
| 666 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) |
| 667 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, |
| 668 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 669 | |
| 670 | ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
| 671 | spec->mux_nids[adc_idx], |
| 672 | &spec->cur_mux[adc_idx]); |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 673 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 674 | set_widgets_power_state(codec); |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 675 | |
Lydia Wang | bff5fbf | 2011-03-22 16:21:38 +0800 | [diff] [blame] | 676 | return ret; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 679 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
| 680 | struct snd_ctl_elem_info *uinfo) |
| 681 | { |
| 682 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 683 | struct via_spec *spec = codec->spec; |
| 684 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); |
| 685 | } |
| 686 | |
| 687 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, |
| 688 | struct snd_ctl_elem_value *ucontrol) |
| 689 | { |
| 690 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 691 | hda_nid_t nid = kcontrol->private_value; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 692 | unsigned int pinsel; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 693 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 694 | /* use !! to translate conn sel 2 for VT1718S */ |
| 695 | pinsel = !!snd_hda_codec_read(codec, nid, 0, |
| 696 | AC_VERB_GET_CONNECT_SEL, |
| 697 | 0x00); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 698 | ucontrol->value.enumerated.item[0] = pinsel; |
| 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 703 | static void activate_ctl(struct hda_codec *codec, const char *name, int active) |
| 704 | { |
| 705 | struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); |
| 706 | if (ctl) { |
| 707 | ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 708 | ctl->vd[0].access |= active |
| 709 | ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 710 | snd_ctl_notify(codec->bus->card, |
| 711 | SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); |
| 712 | } |
| 713 | } |
| 714 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 715 | static hda_nid_t side_mute_channel(struct via_spec *spec) |
| 716 | { |
| 717 | switch (spec->codec_type) { |
| 718 | case VT1708: return 0x1b; |
| 719 | case VT1709_10CH: return 0x29; |
| 720 | case VT1708B_8CH: /* fall thru */ |
| 721 | case VT1708S: return 0x27; |
Lydia Wang | e87885f | 2011-03-24 12:39:05 +0800 | [diff] [blame] | 722 | case VT2002P: return 0x19; |
| 723 | case VT1802: return 0x15; |
| 724 | case VT1812: return 0x15; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 725 | default: return 0; |
| 726 | } |
| 727 | } |
| 728 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 729 | static int update_side_mute_status(struct hda_codec *codec) |
| 730 | { |
| 731 | /* mute side channel */ |
| 732 | struct via_spec *spec = codec->spec; |
Lydia Wang | e87885f | 2011-03-24 12:39:05 +0800 | [diff] [blame] | 733 | unsigned int parm; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 734 | hda_nid_t sw3 = side_mute_channel(spec); |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 735 | |
Lydia Wang | e87885f | 2011-03-24 12:39:05 +0800 | [diff] [blame] | 736 | if (sw3) { |
| 737 | if (VT2002P_COMPATIBLE(spec)) |
| 738 | parm = spec->hp_independent_mode ? |
| 739 | AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1); |
| 740 | else |
| 741 | parm = spec->hp_independent_mode ? |
| 742 | AMP_OUT_MUTE : AMP_OUT_UNMUTE; |
| 743 | snd_hda_codec_write(codec, sw3, 0, |
| 744 | AC_VERB_SET_AMP_GAIN_MUTE, parm); |
| 745 | if (spec->codec_type == VT1812) |
| 746 | snd_hda_codec_write(codec, 0x1d, 0, |
| 747 | AC_VERB_SET_AMP_GAIN_MUTE, parm); |
| 748 | } |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 752 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
| 753 | struct snd_ctl_elem_value *ucontrol) |
| 754 | { |
| 755 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 756 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 757 | hda_nid_t nid = kcontrol->private_value; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 758 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 759 | /* Get Independent Mode index of headphone pin widget */ |
| 760 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel |
| 761 | ? 1 : 0; |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 762 | if (spec->codec_type == VT1718S) |
| 763 | snd_hda_codec_write(codec, nid, 0, |
| 764 | AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0); |
| 765 | else |
| 766 | snd_hda_codec_write(codec, nid, 0, |
| 767 | AC_VERB_SET_CONNECT_SEL, pinsel); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 768 | |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 769 | if (spec->codec_type == VT1812) |
| 770 | snd_hda_codec_write(codec, 0x35, 0, |
| 771 | AC_VERB_SET_CONNECT_SEL, pinsel); |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 772 | if (spec->multiout.hp_nid && spec->multiout.hp_nid |
| 773 | != spec->multiout.dac_nids[HDA_FRONT]) |
| 774 | snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, |
| 775 | 0, 0, 0); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 776 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 777 | update_side_mute_status(codec); |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 778 | /* update HP volume/swtich active state */ |
| 779 | if (spec->codec_type == VT1708S |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 780 | || spec->codec_type == VT1702 |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 781 | || spec->codec_type == VT1718S |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 782 | || spec->codec_type == VT1716S |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 783 | || VT2002P_COMPATIBLE(spec)) { |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 784 | activate_ctl(codec, "Headphone Playback Volume", |
| 785 | spec->hp_independent_mode); |
| 786 | activate_ctl(codec, "Headphone Playback Switch", |
| 787 | spec->hp_independent_mode); |
| 788 | } |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 789 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 790 | set_widgets_power_state(codec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 791 | return 0; |
| 792 | } |
| 793 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 794 | static const struct snd_kcontrol_new via_hp_mixer[2] = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 795 | { |
| 796 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 797 | .name = "Independent HP", |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 798 | .info = via_independent_hp_info, |
| 799 | .get = via_independent_hp_get, |
| 800 | .put = via_independent_hp_put, |
| 801 | }, |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 802 | { |
| 803 | .iface = NID_MAPPING, |
| 804 | .name = "Independent HP", |
| 805 | }, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 806 | }; |
| 807 | |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 808 | static int via_hp_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 809 | { |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 810 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 811 | struct snd_kcontrol_new *knew; |
| 812 | hda_nid_t nid; |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 813 | int nums; |
| 814 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 815 | |
| 816 | switch (spec->codec_type) { |
| 817 | case VT1718S: |
| 818 | nid = 0x34; |
| 819 | break; |
| 820 | case VT2002P: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 821 | case VT1802: |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 822 | nid = 0x35; |
| 823 | break; |
| 824 | case VT1812: |
| 825 | nid = 0x3d; |
| 826 | break; |
| 827 | default: |
| 828 | nid = spec->autocfg.hp_pins[0]; |
| 829 | break; |
| 830 | } |
| 831 | |
Lydia Wang | ee3c35c | 2011-03-22 16:26:36 +0800 | [diff] [blame] | 832 | if (spec->codec_type != VT1708) { |
| 833 | nums = snd_hda_get_connections(codec, nid, |
| 834 | conn, HDA_MAX_CONNECTIONS); |
| 835 | if (nums <= 1) |
| 836 | return 0; |
| 837 | } |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 838 | |
| 839 | knew = via_clone_control(spec, &via_hp_mixer[0]); |
| 840 | if (knew == NULL) |
| 841 | return -ENOMEM; |
| 842 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 843 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
| 844 | knew->private_value = nid; |
| 845 | |
| 846 | knew = via_clone_control(spec, &via_hp_mixer[1]); |
| 847 | if (knew == NULL) |
| 848 | return -ENOMEM; |
| 849 | knew->subdevice = side_mute_channel(spec); |
| 850 | |
| 851 | return 0; |
| 852 | } |
| 853 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 854 | static void notify_aa_path_ctls(struct hda_codec *codec) |
| 855 | { |
| 856 | int i; |
| 857 | struct snd_ctl_elem_id id; |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 858 | const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"}; |
| 859 | struct snd_kcontrol *ctl; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 860 | |
| 861 | memset(&id, 0, sizeof(id)); |
| 862 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 863 | for (i = 0; i < ARRAY_SIZE(labels); i++) { |
| 864 | sprintf(id.name, "%s Playback Volume", labels[i]); |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 865 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
| 866 | if (ctl) |
| 867 | snd_ctl_notify(codec->bus->card, |
| 868 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 869 | &ctl->id); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | |
| 873 | static void mute_aa_path(struct hda_codec *codec, int mute) |
| 874 | { |
| 875 | struct via_spec *spec = codec->spec; |
| 876 | hda_nid_t nid_mixer; |
| 877 | int start_idx; |
| 878 | int end_idx; |
| 879 | int i; |
| 880 | /* get nid of MW0 and start & end index */ |
| 881 | switch (spec->codec_type) { |
| 882 | case VT1708: |
| 883 | nid_mixer = 0x17; |
| 884 | start_idx = 2; |
| 885 | end_idx = 4; |
| 886 | break; |
| 887 | case VT1709_10CH: |
| 888 | case VT1709_6CH: |
| 889 | nid_mixer = 0x18; |
| 890 | start_idx = 2; |
| 891 | end_idx = 4; |
| 892 | break; |
| 893 | case VT1708B_8CH: |
| 894 | case VT1708B_4CH: |
| 895 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 896 | case VT1716S: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 897 | nid_mixer = 0x16; |
| 898 | start_idx = 2; |
| 899 | end_idx = 4; |
| 900 | break; |
Lydia Wang | ab657e0 | 2011-03-22 16:23:23 +0800 | [diff] [blame] | 901 | case VT1718S: |
| 902 | nid_mixer = 0x21; |
| 903 | start_idx = 1; |
| 904 | end_idx = 3; |
| 905 | break; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 906 | default: |
| 907 | return; |
| 908 | } |
| 909 | /* check AA path's mute status */ |
| 910 | for (i = start_idx; i <= end_idx; i++) { |
| 911 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; |
| 912 | snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i, |
| 913 | HDA_AMP_MUTE, val); |
| 914 | } |
| 915 | } |
| 916 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin) |
| 917 | { |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 918 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 919 | int i; |
| 920 | |
| 921 | for (i = 0; i < cfg->num_inputs; i++) { |
| 922 | if (pin == cfg->inputs[i].pin) |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 923 | return cfg->inputs[i].type <= AUTO_PIN_LINE_IN; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 924 | } |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 925 | return 0; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static int via_smart51_info(struct snd_kcontrol *kcontrol, |
| 929 | struct snd_ctl_elem_info *uinfo) |
| 930 | { |
| 931 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 932 | uinfo->count = 1; |
| 933 | uinfo->value.integer.min = 0; |
| 934 | uinfo->value.integer.max = 1; |
| 935 | return 0; |
| 936 | } |
| 937 | |
| 938 | static int via_smart51_get(struct snd_kcontrol *kcontrol, |
| 939 | struct snd_ctl_elem_value *ucontrol) |
| 940 | { |
| 941 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 942 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 943 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 944 | int on = 1; |
| 945 | int i; |
| 946 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 947 | for (i = 0; i < cfg->num_inputs; i++) { |
| 948 | hda_nid_t nid = cfg->inputs[i].pin; |
| 949 | int ctl = snd_hda_codec_read(codec, nid, 0, |
| 950 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 951 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 952 | continue; |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 953 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 954 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
| 955 | continue; /* ignore FMic for independent HP */ |
| 956 | if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) |
| 957 | on = 0; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 958 | } |
| 959 | *ucontrol->value.integer.value = on; |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static int via_smart51_put(struct snd_kcontrol *kcontrol, |
| 964 | struct snd_ctl_elem_value *ucontrol) |
| 965 | { |
| 966 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 967 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 968 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 969 | int out_in = *ucontrol->value.integer.value |
| 970 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 971 | int i; |
| 972 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 973 | for (i = 0; i < cfg->num_inputs; i++) { |
| 974 | hda_nid_t nid = cfg->inputs[i].pin; |
| 975 | unsigned int parm; |
| 976 | |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 977 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 978 | continue; |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 979 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 980 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 981 | continue; /* don't retask FMic for independent HP */ |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 982 | |
| 983 | parm = snd_hda_codec_read(codec, nid, 0, |
| 984 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 985 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); |
| 986 | parm |= out_in; |
| 987 | snd_hda_codec_write(codec, nid, 0, |
| 988 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 989 | parm); |
| 990 | if (out_in == AC_PINCTL_OUT_EN) { |
| 991 | mute_aa_path(codec, 1); |
| 992 | notify_aa_path_ctls(codec); |
| 993 | } |
| 994 | if (spec->codec_type == VT1718S) { |
| 995 | snd_hda_codec_amp_stereo( |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 996 | codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 997 | HDA_AMP_UNMUTE); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 998 | } |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 999 | if (cfg->inputs[i].type == AUTO_PIN_MIC) { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1000 | if (spec->codec_type == VT1708S |
| 1001 | || spec->codec_type == VT1716S) { |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1002 | /* input = index 1 (AOW3) */ |
| 1003 | snd_hda_codec_write( |
| 1004 | codec, nid, 0, |
| 1005 | AC_VERB_SET_CONNECT_SEL, 1); |
| 1006 | snd_hda_codec_amp_stereo( |
| 1007 | codec, nid, HDA_OUTPUT, |
| 1008 | 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE); |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | spec->smart51_enabled = *ucontrol->value.integer.value; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1013 | set_widgets_power_state(codec); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1014 | return 1; |
| 1015 | } |
| 1016 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1017 | static const struct snd_kcontrol_new via_smart51_mixer = { |
| 1018 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1019 | .name = "Smart 5.1", |
| 1020 | .count = 1, |
| 1021 | .info = via_smart51_info, |
| 1022 | .get = via_smart51_get, |
| 1023 | .put = via_smart51_put, |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1024 | }; |
| 1025 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1026 | static int via_smart51_build(struct via_spec *spec) |
| 1027 | { |
| 1028 | struct snd_kcontrol_new *knew; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1029 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1030 | hda_nid_t nid; |
| 1031 | int i; |
| 1032 | |
Lydia Wang | cb34c20 | 2011-04-27 17:44:16 +0800 | [diff] [blame] | 1033 | if (!cfg) |
| 1034 | return 0; |
| 1035 | if (cfg->line_outs > 2) |
| 1036 | return 0; |
| 1037 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1038 | knew = via_clone_control(spec, &via_smart51_mixer); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1039 | if (knew == NULL) |
| 1040 | return -ENOMEM; |
| 1041 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1042 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1043 | nid = cfg->inputs[i].pin; |
Takashi Iwai | 86e2959 | 2010-09-09 14:50:17 +0200 | [diff] [blame] | 1044 | if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) { |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 1045 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 1046 | break; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1053 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1054 | static const struct snd_kcontrol_new vt1708_capture_mixer[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1055 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), |
| 1056 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT), |
| 1057 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT), |
| 1058 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT), |
| 1059 | { |
| 1060 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1061 | /* The multiple "Capture Source" controls confuse alsamixer |
| 1062 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1063 | */ |
| 1064 | /* .name = "Capture Source", */ |
| 1065 | .name = "Input Source", |
| 1066 | .count = 1, |
| 1067 | .info = via_mux_enum_info, |
| 1068 | .get = via_mux_enum_get, |
| 1069 | .put = via_mux_enum_put, |
| 1070 | }, |
| 1071 | { } /* end */ |
| 1072 | }; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1073 | |
| 1074 | /* check AA path's mute statue */ |
| 1075 | static int is_aa_path_mute(struct hda_codec *codec) |
| 1076 | { |
| 1077 | int mute = 1; |
| 1078 | hda_nid_t nid_mixer; |
| 1079 | int start_idx; |
| 1080 | int end_idx; |
| 1081 | int i; |
| 1082 | struct via_spec *spec = codec->spec; |
| 1083 | /* get nid of MW0 and start & end index */ |
| 1084 | switch (spec->codec_type) { |
| 1085 | case VT1708B_8CH: |
| 1086 | case VT1708B_4CH: |
| 1087 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1088 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1089 | nid_mixer = 0x16; |
| 1090 | start_idx = 2; |
| 1091 | end_idx = 4; |
| 1092 | break; |
| 1093 | case VT1702: |
| 1094 | nid_mixer = 0x1a; |
| 1095 | start_idx = 1; |
| 1096 | end_idx = 3; |
| 1097 | break; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1098 | case VT1718S: |
| 1099 | nid_mixer = 0x21; |
| 1100 | start_idx = 1; |
| 1101 | end_idx = 3; |
| 1102 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1103 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1104 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1105 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1106 | nid_mixer = 0x21; |
| 1107 | start_idx = 0; |
| 1108 | end_idx = 2; |
| 1109 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1110 | default: |
| 1111 | return 0; |
| 1112 | } |
| 1113 | /* check AA path's mute status */ |
| 1114 | for (i = start_idx; i <= end_idx; i++) { |
| 1115 | unsigned int con_list = snd_hda_codec_read( |
| 1116 | codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); |
| 1117 | int shift = 8 * (i % 4); |
| 1118 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; |
| 1119 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); |
| 1120 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { |
| 1121 | /* check mute status while the pin is connected */ |
| 1122 | int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0, |
| 1123 | HDA_INPUT, i) >> 7; |
| 1124 | int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1, |
| 1125 | HDA_INPUT, i) >> 7; |
| 1126 | if (!mute_l || !mute_r) { |
| 1127 | mute = 0; |
| 1128 | break; |
| 1129 | } |
| 1130 | } |
| 1131 | } |
| 1132 | return mute; |
| 1133 | } |
| 1134 | |
| 1135 | /* enter/exit analog low-current mode */ |
| 1136 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) |
| 1137 | { |
| 1138 | struct via_spec *spec = codec->spec; |
| 1139 | static int saved_stream_idle = 1; /* saved stream idle status */ |
| 1140 | int enable = is_aa_path_mute(codec); |
| 1141 | unsigned int verb = 0; |
| 1142 | unsigned int parm = 0; |
| 1143 | |
| 1144 | if (stream_idle == -1) /* stream status did not change */ |
| 1145 | enable = enable && saved_stream_idle; |
| 1146 | else { |
| 1147 | enable = enable && stream_idle; |
| 1148 | saved_stream_idle = stream_idle; |
| 1149 | } |
| 1150 | |
| 1151 | /* decide low current mode's verb & parameter */ |
| 1152 | switch (spec->codec_type) { |
| 1153 | case VT1708B_8CH: |
| 1154 | case VT1708B_4CH: |
| 1155 | verb = 0xf70; |
| 1156 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 1157 | break; |
| 1158 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1159 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1160 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1161 | verb = 0xf73; |
| 1162 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 1163 | break; |
| 1164 | case VT1702: |
| 1165 | verb = 0xf73; |
| 1166 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 1167 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1168 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1169 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1170 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1171 | verb = 0xf93; |
| 1172 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 1173 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1174 | default: |
| 1175 | return; /* other codecs are not supported */ |
| 1176 | } |
| 1177 | /* send verb */ |
| 1178 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); |
| 1179 | } |
| 1180 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1181 | /* |
| 1182 | * generic initialization of ADC, input mixers and output mixers |
| 1183 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1184 | static const struct hda_verb vt1708_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1185 | /* |
| 1186 | * Unmute ADC0-1 and set the default input to mic-in |
| 1187 | */ |
| 1188 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1189 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1190 | |
| 1191 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1192 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1193 | * mixer widget |
| 1194 | */ |
| 1195 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1196 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1197 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 1198 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 1199 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 1200 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1201 | |
| 1202 | /* |
| 1203 | * Set up output mixers (0x19 - 0x1b) |
| 1204 | */ |
| 1205 | /* set vol=0 to output mixers */ |
| 1206 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 1207 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 1208 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1209 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 1210 | /* Setup default input MW0 to PW4 */ |
| 1211 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1212 | /* PW9 Output enable */ |
| 1213 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Lydia Wang | aa266fc | 2011-03-24 12:41:01 +0800 | [diff] [blame] | 1214 | /* power down jack detect function */ |
| 1215 | {0x1, 0xf81, 0x1}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1216 | { } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1220 | struct hda_codec *codec, |
| 1221 | struct snd_pcm_substream *substream) |
| 1222 | { |
| 1223 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1224 | int idle = substream->pstr->substream_opened == 1 |
| 1225 | && substream->ref_count == 0; |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1226 | analog_low_current_mode(codec, idle); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1227 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 1228 | hinfo); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1229 | } |
| 1230 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1231 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, |
| 1232 | unsigned int stream_tag, |
| 1233 | unsigned int format, |
| 1234 | struct snd_pcm_substream *substream) |
| 1235 | { |
| 1236 | struct via_spec *spec = codec->spec; |
| 1237 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1238 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1239 | int chs = substream->runtime->channels; |
| 1240 | int i; |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1241 | struct hda_spdif_out *spdif = |
| 1242 | snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1243 | |
| 1244 | mutex_lock(&codec->spdif_mutex); |
| 1245 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
| 1246 | if (chs == 2 && |
| 1247 | snd_hda_is_supported_format(codec, mout->dig_out_nid, |
| 1248 | format) && |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1249 | !(spdif->status & IEC958_AES0_NONAUDIO)) { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1250 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
| 1251 | /* turn off SPDIF once; otherwise the IEC958 bits won't |
| 1252 | * be updated */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1253 | if (spdif->ctls & AC_DIG1_ENABLE) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1254 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1255 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1256 | spdif->ctls & |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1257 | ~AC_DIG1_ENABLE & 0xff); |
| 1258 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1259 | stream_tag, 0, format); |
| 1260 | /* turn on again (if needed) */ |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1261 | if (spdif->ctls & AC_DIG1_ENABLE) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1262 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1263 | AC_VERB_SET_DIGI_CONVERT_1, |
Stephen Warren | 7c93597 | 2011-06-01 11:14:17 -0600 | [diff] [blame] | 1264 | spdif->ctls & 0xff); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1265 | } else { |
| 1266 | mout->dig_out_used = 0; |
| 1267 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1268 | 0, 0, 0); |
| 1269 | } |
| 1270 | } |
| 1271 | mutex_unlock(&codec->spdif_mutex); |
| 1272 | |
| 1273 | /* front */ |
| 1274 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
| 1275 | 0, format); |
| 1276 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1277 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
| 1278 | && !spec->hp_independent_mode) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1279 | /* headphone out will just decode front left/right (stereo) */ |
| 1280 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
| 1281 | 0, format); |
| 1282 | |
| 1283 | /* extra outputs copied from front */ |
| 1284 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1285 | if (mout->extra_out_nid[i]) |
| 1286 | snd_hda_codec_setup_stream(codec, |
| 1287 | mout->extra_out_nid[i], |
| 1288 | stream_tag, 0, format); |
| 1289 | |
| 1290 | /* surrounds */ |
| 1291 | for (i = 1; i < mout->num_dacs; i++) { |
| 1292 | if (chs >= (i + 1) * 2) /* independent out */ |
| 1293 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1294 | i * 2, format); |
| 1295 | else /* copy front */ |
| 1296 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1297 | 0, format); |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1302 | struct hda_codec *codec, |
| 1303 | unsigned int stream_tag, |
| 1304 | unsigned int format, |
| 1305 | struct snd_pcm_substream *substream) |
| 1306 | { |
| 1307 | struct via_spec *spec = codec->spec; |
| 1308 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1309 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1310 | |
| 1311 | if (substream->number == 0) |
| 1312 | playback_multi_pcm_prep_0(codec, stream_tag, format, |
| 1313 | substream); |
| 1314 | else { |
| 1315 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1316 | spec->hp_independent_mode) |
| 1317 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1318 | stream_tag, 0, format); |
| 1319 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1320 | vt1708_start_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1325 | struct hda_codec *codec, |
| 1326 | struct snd_pcm_substream *substream) |
| 1327 | { |
| 1328 | struct via_spec *spec = codec->spec; |
| 1329 | struct hda_multi_out *mout = &spec->multiout; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1330 | const hda_nid_t *nids = mout->dac_nids; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1331 | int i; |
| 1332 | |
| 1333 | if (substream->number == 0) { |
| 1334 | for (i = 0; i < mout->num_dacs; i++) |
| 1335 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); |
| 1336 | |
| 1337 | if (mout->hp_nid && !spec->hp_independent_mode) |
| 1338 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1339 | 0, 0, 0); |
| 1340 | |
| 1341 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1342 | if (mout->extra_out_nid[i]) |
| 1343 | snd_hda_codec_setup_stream(codec, |
| 1344 | mout->extra_out_nid[i], |
| 1345 | 0, 0, 0); |
| 1346 | mutex_lock(&codec->spdif_mutex); |
| 1347 | if (mout->dig_out_nid && |
| 1348 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { |
| 1349 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1350 | 0, 0, 0); |
| 1351 | mout->dig_out_used = 0; |
| 1352 | } |
| 1353 | mutex_unlock(&codec->spdif_mutex); |
| 1354 | } else { |
| 1355 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1356 | spec->hp_independent_mode) |
| 1357 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1358 | 0, 0, 0); |
| 1359 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1360 | vt1708_stop_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1361 | return 0; |
| 1362 | } |
| 1363 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1364 | /* |
| 1365 | * Digital out |
| 1366 | */ |
| 1367 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1368 | struct hda_codec *codec, |
| 1369 | struct snd_pcm_substream *substream) |
| 1370 | { |
| 1371 | struct via_spec *spec = codec->spec; |
| 1372 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 1373 | } |
| 1374 | |
| 1375 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1376 | struct hda_codec *codec, |
| 1377 | struct snd_pcm_substream *substream) |
| 1378 | { |
| 1379 | struct via_spec *spec = codec->spec; |
| 1380 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 1381 | } |
| 1382 | |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1383 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1384 | struct hda_codec *codec, |
| 1385 | unsigned int stream_tag, |
| 1386 | unsigned int format, |
| 1387 | struct snd_pcm_substream *substream) |
| 1388 | { |
| 1389 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1390 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 1391 | stream_tag, format, substream); |
| 1392 | } |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1393 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1394 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1395 | struct hda_codec *codec, |
| 1396 | struct snd_pcm_substream *substream) |
| 1397 | { |
| 1398 | struct via_spec *spec = codec->spec; |
| 1399 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1400 | return 0; |
| 1401 | } |
| 1402 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1403 | /* |
| 1404 | * Analog capture |
| 1405 | */ |
| 1406 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1407 | struct hda_codec *codec, |
| 1408 | unsigned int stream_tag, |
| 1409 | unsigned int format, |
| 1410 | struct snd_pcm_substream *substream) |
| 1411 | { |
| 1412 | struct via_spec *spec = codec->spec; |
| 1413 | |
| 1414 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 1415 | stream_tag, 0, format); |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
| 1419 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1420 | struct hda_codec *codec, |
| 1421 | struct snd_pcm_substream *substream) |
| 1422 | { |
| 1423 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1424 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1425 | return 0; |
| 1426 | } |
| 1427 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1428 | static const struct hda_pcm_stream vt1708_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1429 | .substreams = 2, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1430 | .channels_min = 2, |
| 1431 | .channels_max = 8, |
| 1432 | .nid = 0x10, /* NID to query formats and rates */ |
| 1433 | .ops = { |
| 1434 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1435 | .prepare = via_playback_multi_pcm_prepare, |
| 1436 | .cleanup = via_playback_multi_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1437 | }, |
| 1438 | }; |
| 1439 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1440 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1441 | .substreams = 2, |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1442 | .channels_min = 2, |
| 1443 | .channels_max = 8, |
| 1444 | .nid = 0x10, /* NID to query formats and rates */ |
| 1445 | /* We got noisy outputs on the right channel on VT1708 when |
| 1446 | * 24bit samples are used. Until any workaround is found, |
| 1447 | * disable the 24bit format, so far. |
| 1448 | */ |
| 1449 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1450 | .ops = { |
| 1451 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1452 | .prepare = via_playback_multi_pcm_prepare, |
| 1453 | .cleanup = via_playback_multi_pcm_cleanup |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1454 | }, |
| 1455 | }; |
| 1456 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1457 | static const struct hda_pcm_stream vt1708_pcm_analog_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1458 | .substreams = 2, |
| 1459 | .channels_min = 2, |
| 1460 | .channels_max = 2, |
| 1461 | .nid = 0x15, /* NID to query formats and rates */ |
| 1462 | .ops = { |
| 1463 | .prepare = via_capture_pcm_prepare, |
| 1464 | .cleanup = via_capture_pcm_cleanup |
| 1465 | }, |
| 1466 | }; |
| 1467 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1468 | static const struct hda_pcm_stream vt1708_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1469 | .substreams = 1, |
| 1470 | .channels_min = 2, |
| 1471 | .channels_max = 2, |
| 1472 | /* NID is set in via_build_pcms */ |
| 1473 | .ops = { |
| 1474 | .open = via_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 1475 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1476 | .prepare = via_dig_playback_pcm_prepare, |
| 1477 | .cleanup = via_dig_playback_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1478 | }, |
| 1479 | }; |
| 1480 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1481 | static const struct hda_pcm_stream vt1708_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1482 | .substreams = 1, |
| 1483 | .channels_min = 2, |
| 1484 | .channels_max = 2, |
| 1485 | }; |
| 1486 | |
| 1487 | static int via_build_controls(struct hda_codec *codec) |
| 1488 | { |
| 1489 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1490 | struct snd_kcontrol *kctl; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1491 | const struct snd_kcontrol_new *knew; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1492 | int err, i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1493 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 1494 | if (spec->set_widgets_power_state) |
| 1495 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) |
| 1496 | return -ENOMEM; |
| 1497 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1498 | for (i = 0; i < spec->num_mixers; i++) { |
| 1499 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1500 | if (err < 0) |
| 1501 | return err; |
| 1502 | } |
| 1503 | |
| 1504 | if (spec->multiout.dig_out_nid) { |
| 1505 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1506 | spec->multiout.dig_out_nid, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1507 | spec->multiout.dig_out_nid); |
| 1508 | if (err < 0) |
| 1509 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1510 | err = snd_hda_create_spdif_share_sw(codec, |
| 1511 | &spec->multiout); |
| 1512 | if (err < 0) |
| 1513 | return err; |
| 1514 | spec->multiout.share_spdif = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1515 | } |
| 1516 | if (spec->dig_in_nid) { |
| 1517 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1518 | if (err < 0) |
| 1519 | return err; |
| 1520 | } |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1521 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1522 | /* assign Capture Source enums to NID */ |
| 1523 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1524 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 1525 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1526 | if (err < 0) |
| 1527 | return err; |
| 1528 | } |
| 1529 | |
| 1530 | /* other nid->control mapping */ |
| 1531 | for (i = 0; i < spec->num_mixers; i++) { |
| 1532 | for (knew = spec->mixers[i]; knew->name; knew++) { |
| 1533 | if (knew->iface != NID_MAPPING) |
| 1534 | continue; |
| 1535 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); |
| 1536 | if (kctl == NULL) |
| 1537 | continue; |
| 1538 | err = snd_hda_add_nid(codec, kctl, 0, |
| 1539 | knew->subdevice); |
| 1540 | } |
| 1541 | } |
| 1542 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1543 | /* init power states */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1544 | set_widgets_power_state(codec); |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1545 | analog_low_current_mode(codec, 1); |
| 1546 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1547 | via_free_kctls(codec); /* no longer needed */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1548 | return 0; |
| 1549 | } |
| 1550 | |
| 1551 | static int via_build_pcms(struct hda_codec *codec) |
| 1552 | { |
| 1553 | struct via_spec *spec = codec->spec; |
| 1554 | struct hda_pcm *info = spec->pcm_rec; |
| 1555 | |
| 1556 | codec->num_pcms = 1; |
| 1557 | codec->pcm_info = info; |
| 1558 | |
| 1559 | info->name = spec->stream_name_analog; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1560 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 1561 | *(spec->stream_analog_playback); |
| 1562 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1563 | spec->multiout.dac_nids[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1564 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); |
| 1565 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 1566 | |
| 1567 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 1568 | spec->multiout.max_channels; |
| 1569 | |
| 1570 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 1571 | codec->num_pcms++; |
| 1572 | info++; |
| 1573 | info->name = spec->stream_name_digital; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 1574 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1575 | if (spec->multiout.dig_out_nid) { |
| 1576 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 1577 | *(spec->stream_digital_playback); |
| 1578 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1579 | spec->multiout.dig_out_nid; |
| 1580 | } |
| 1581 | if (spec->dig_in_nid) { |
| 1582 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 1583 | *(spec->stream_digital_capture); |
| 1584 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 1585 | spec->dig_in_nid; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
| 1592 | static void via_free(struct hda_codec *codec) |
| 1593 | { |
| 1594 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1595 | |
| 1596 | if (!spec) |
| 1597 | return; |
| 1598 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1599 | via_free_kctls(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1600 | vt1708_stop_hp_work(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1601 | kfree(codec->spec); |
| 1602 | } |
| 1603 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1604 | /* mute internal speaker if HP is plugged */ |
| 1605 | static void via_hp_automute(struct hda_codec *codec) |
| 1606 | { |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1607 | unsigned int present = 0; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1608 | struct via_spec *spec = codec->spec; |
| 1609 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1610 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1611 | |
| 1612 | if (!spec->hp_independent_mode) { |
| 1613 | struct snd_ctl_elem_id id; |
| 1614 | /* auto mute */ |
| 1615 | snd_hda_codec_amp_stereo( |
| 1616 | codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0, |
| 1617 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); |
| 1618 | /* notify change */ |
| 1619 | memset(&id, 0, sizeof(id)); |
| 1620 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1621 | strcpy(id.name, "Front Playback Switch"); |
| 1622 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 1623 | &id); |
| 1624 | } |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1625 | } |
| 1626 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1627 | /* mute mono out if HP or Line out is plugged */ |
| 1628 | static void via_mono_automute(struct hda_codec *codec) |
| 1629 | { |
| 1630 | unsigned int hp_present, lineout_present; |
| 1631 | struct via_spec *spec = codec->spec; |
| 1632 | |
| 1633 | if (spec->codec_type != VT1716S) |
| 1634 | return; |
| 1635 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1636 | lineout_present = snd_hda_jack_detect(codec, |
| 1637 | spec->autocfg.line_out_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1638 | |
| 1639 | /* Mute Mono Out if Line Out is plugged */ |
| 1640 | if (lineout_present) { |
| 1641 | snd_hda_codec_amp_stereo( |
| 1642 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 1643 | return; |
| 1644 | } |
| 1645 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1646 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1647 | |
| 1648 | if (!spec->hp_independent_mode) |
| 1649 | snd_hda_codec_amp_stereo( |
| 1650 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 1651 | hp_present ? HDA_AMP_MUTE : 0); |
| 1652 | } |
| 1653 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1654 | static void via_gpio_control(struct hda_codec *codec) |
| 1655 | { |
| 1656 | unsigned int gpio_data; |
| 1657 | unsigned int vol_counter; |
| 1658 | unsigned int vol; |
| 1659 | unsigned int master_vol; |
| 1660 | |
| 1661 | struct via_spec *spec = codec->spec; |
| 1662 | |
| 1663 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, |
| 1664 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; |
| 1665 | |
| 1666 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, |
| 1667 | 0xF84, 0) & 0x3F0000) >> 16; |
| 1668 | |
| 1669 | vol = vol_counter & 0x1F; |
| 1670 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, |
| 1671 | AC_VERB_GET_AMP_GAIN_MUTE, |
| 1672 | AC_AMP_GET_INPUT); |
| 1673 | |
| 1674 | if (gpio_data == 0x02) { |
| 1675 | /* unmute line out */ |
| 1676 | snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], |
| 1677 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 1678 | |
| 1679 | if (vol_counter & 0x20) { |
| 1680 | /* decrease volume */ |
| 1681 | if (vol > master_vol) |
| 1682 | vol = master_vol; |
| 1683 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, |
| 1684 | 0, HDA_AMP_VOLMASK, |
| 1685 | master_vol-vol); |
| 1686 | } else { |
| 1687 | /* increase volume */ |
| 1688 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, |
| 1689 | HDA_AMP_VOLMASK, |
| 1690 | ((master_vol+vol) > 0x2A) ? 0x2A : |
| 1691 | (master_vol+vol)); |
| 1692 | } |
| 1693 | } else if (!(gpio_data & 0x02)) { |
| 1694 | /* mute line out */ |
| 1695 | snd_hda_codec_amp_stereo(codec, |
| 1696 | spec->autocfg.line_out_pins[0], |
| 1697 | HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 1698 | HDA_AMP_MUTE); |
| 1699 | } |
| 1700 | } |
| 1701 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1702 | /* mute Internal-Speaker if HP is plugged */ |
| 1703 | static void via_speaker_automute(struct hda_codec *codec) |
| 1704 | { |
| 1705 | unsigned int hp_present; |
| 1706 | struct via_spec *spec = codec->spec; |
| 1707 | |
Lydia Wang | 27439ce | 2011-03-24 12:40:10 +0800 | [diff] [blame] | 1708 | if (!VT2002P_COMPATIBLE(spec)) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1709 | return; |
| 1710 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1711 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1712 | |
| 1713 | if (!spec->hp_independent_mode) { |
| 1714 | struct snd_ctl_elem_id id; |
| 1715 | snd_hda_codec_amp_stereo( |
| 1716 | codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0, |
| 1717 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); |
| 1718 | /* notify change */ |
| 1719 | memset(&id, 0, sizeof(id)); |
| 1720 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1721 | strcpy(id.name, "Speaker Playback Switch"); |
| 1722 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 1723 | &id); |
| 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | /* mute line-out and internal speaker if HP is plugged */ |
| 1728 | static void via_hp_bind_automute(struct hda_codec *codec) |
| 1729 | { |
akpm@linux-foundation.org | 01a1796 | 2009-11-13 16:47:10 -0800 | [diff] [blame] | 1730 | /* use long instead of int below just to avoid an internal compiler |
| 1731 | * error with gcc 4.0.x |
| 1732 | */ |
| 1733 | unsigned long hp_present, present = 0; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1734 | struct via_spec *spec = codec->spec; |
| 1735 | int i; |
| 1736 | |
| 1737 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) |
| 1738 | return; |
| 1739 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1740 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1741 | |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 1742 | present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1743 | |
| 1744 | if (!spec->hp_independent_mode) { |
| 1745 | /* Mute Line-Outs */ |
| 1746 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 1747 | snd_hda_codec_amp_stereo( |
| 1748 | codec, spec->autocfg.line_out_pins[i], |
| 1749 | HDA_OUTPUT, 0, |
| 1750 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); |
| 1751 | if (hp_present) |
| 1752 | present = hp_present; |
| 1753 | } |
| 1754 | /* Speakers */ |
| 1755 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 1756 | snd_hda_codec_amp_stereo( |
| 1757 | codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0, |
| 1758 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); |
| 1759 | } |
| 1760 | |
| 1761 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1762 | /* unsolicited event for jack sensing */ |
| 1763 | static void via_unsol_event(struct hda_codec *codec, |
| 1764 | unsigned int res) |
| 1765 | { |
| 1766 | res >>= 26; |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1767 | |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 1768 | if (res & VIA_JACK_EVENT) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1769 | set_widgets_power_state(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1770 | |
| 1771 | res &= ~VIA_JACK_EVENT; |
| 1772 | |
| 1773 | if (res == VIA_HP_EVENT) |
| 1774 | via_hp_automute(codec); |
| 1775 | else if (res == VIA_GPIO_EVENT) |
| 1776 | via_gpio_control(codec); |
| 1777 | else if (res == VIA_MONO_EVENT) |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1778 | via_mono_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1779 | else if (res == VIA_SPEAKER_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1780 | via_speaker_automute(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1781 | else if (res == VIA_BIND_HP_EVENT) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1782 | via_hp_bind_automute(codec); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1783 | } |
| 1784 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1785 | static int via_init(struct hda_codec *codec) |
| 1786 | { |
| 1787 | struct via_spec *spec = codec->spec; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1788 | int i; |
| 1789 | for (i = 0; i < spec->num_iverbs; i++) |
| 1790 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 1791 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1792 | /* Lydia Add for EAPD enable */ |
| 1793 | if (!spec->dig_in_nid) { /* No Digital In connection */ |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 1794 | if (spec->dig_in_pin) { |
| 1795 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1796 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 1797 | PIN_OUT); |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 1798 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1799 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
| 1800 | } |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 1801 | } else /* enable SPDIF-input pin */ |
| 1802 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, |
| 1803 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1804 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1805 | /* assign slave outs */ |
| 1806 | if (spec->slave_dig_outs[0]) |
| 1807 | codec->slave_dig_outs = spec->slave_dig_outs; |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1808 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1809 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1810 | } |
| 1811 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1812 | #ifdef SND_HDA_NEEDS_RESUME |
| 1813 | static int via_suspend(struct hda_codec *codec, pm_message_t state) |
| 1814 | { |
| 1815 | struct via_spec *spec = codec->spec; |
| 1816 | vt1708_stop_hp_work(spec); |
| 1817 | return 0; |
| 1818 | } |
| 1819 | #endif |
| 1820 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1821 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1822 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 1823 | { |
| 1824 | struct via_spec *spec = codec->spec; |
| 1825 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 1826 | } |
| 1827 | #endif |
| 1828 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1829 | /* |
| 1830 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1831 | static const struct hda_codec_ops via_patch_ops = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1832 | .build_controls = via_build_controls, |
| 1833 | .build_pcms = via_build_pcms, |
| 1834 | .init = via_init, |
| 1835 | .free = via_free, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1836 | #ifdef SND_HDA_NEEDS_RESUME |
| 1837 | .suspend = via_suspend, |
| 1838 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1839 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1840 | .check_power_status = via_check_power_status, |
| 1841 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1842 | }; |
| 1843 | |
| 1844 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 1845 | static int vt1708_auto_fill_dac_nids(struct via_spec *spec, |
| 1846 | const struct auto_pin_cfg *cfg) |
| 1847 | { |
| 1848 | int i; |
| 1849 | hda_nid_t nid; |
| 1850 | |
| 1851 | spec->multiout.num_dacs = cfg->line_outs; |
| 1852 | |
| 1853 | spec->multiout.dac_nids = spec->private_dac_nids; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1854 | |
| 1855 | for (i = 0; i < 4; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1856 | nid = cfg->line_out_pins[i]; |
| 1857 | if (nid) { |
| 1858 | /* config dac list */ |
| 1859 | switch (i) { |
| 1860 | case AUTO_SEQ_FRONT: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1861 | spec->private_dac_nids[i] = 0x10; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1862 | break; |
| 1863 | case AUTO_SEQ_CENLFE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1864 | spec->private_dac_nids[i] = 0x12; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1865 | break; |
| 1866 | case AUTO_SEQ_SURROUND: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1867 | spec->private_dac_nids[i] = 0x11; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1868 | break; |
| 1869 | case AUTO_SEQ_SIDE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 1870 | spec->private_dac_nids[i] = 0x13; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1871 | break; |
| 1872 | } |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | return 0; |
| 1877 | } |
| 1878 | |
| 1879 | /* add playback controls from the parsed DAC table */ |
| 1880 | static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, |
| 1881 | const struct auto_pin_cfg *cfg) |
| 1882 | { |
| 1883 | char name[32]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1884 | static const char * const chname[4] = { |
| 1885 | "Front", "Surround", "C/LFE", "Side" |
| 1886 | }; |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 1887 | hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b}; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1888 | int i, err; |
| 1889 | |
| 1890 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 1891 | nid = cfg->line_out_pins[i]; |
| 1892 | |
| 1893 | if (!nid) |
| 1894 | continue; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1895 | |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 1896 | nid_vol = nid_vols[i]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1897 | |
| 1898 | if (i == AUTO_SEQ_CENLFE) { |
| 1899 | /* Center/LFE */ |
| 1900 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1901 | "Center Playback Volume", |
| 1902 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 1903 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1904 | if (err < 0) |
| 1905 | return err; |
| 1906 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 1907 | "LFE Playback Volume", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1908 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 1909 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1910 | if (err < 0) |
| 1911 | return err; |
| 1912 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 1913 | "Center Playback Switch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1914 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 1915 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1916 | if (err < 0) |
| 1917 | return err; |
| 1918 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 1919 | "LFE Playback Switch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1920 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 1921 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1922 | if (err < 0) |
| 1923 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1924 | } else if (i == AUTO_SEQ_FRONT) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1925 | /* add control to mixer index 0 */ |
| 1926 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 1927 | "Master Front Playback Volume", |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 1928 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1929 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1930 | if (err < 0) |
| 1931 | return err; |
| 1932 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 1933 | "Master Front Playback Switch", |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 1934 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1935 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1936 | if (err < 0) |
| 1937 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1938 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1939 | /* add control to PW3 */ |
| 1940 | sprintf(name, "%s Playback Volume", chname[i]); |
| 1941 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1942 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 1943 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1944 | if (err < 0) |
| 1945 | return err; |
| 1946 | sprintf(name, "%s Playback Switch", chname[i]); |
| 1947 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1948 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 1949 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1950 | if (err < 0) |
| 1951 | return err; |
| 1952 | } else { |
| 1953 | sprintf(name, "%s Playback Volume", chname[i]); |
| 1954 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1955 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 1956 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1957 | if (err < 0) |
| 1958 | return err; |
| 1959 | sprintf(name, "%s Playback Switch", chname[i]); |
| 1960 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1961 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 1962 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1963 | if (err < 0) |
| 1964 | return err; |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1971 | static void create_hp_imux(struct via_spec *spec) |
| 1972 | { |
| 1973 | int i; |
| 1974 | struct hda_input_mux *imux = &spec->private_imux[1]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1975 | static const char * const texts[] = { "OFF", "ON", NULL}; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1976 | |
| 1977 | /* for hp mode select */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 1978 | for (i = 0; texts[i]; i++) |
| 1979 | snd_hda_add_imux_item(imux, texts[i], i, NULL); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1980 | |
| 1981 | spec->hp_mux = &spec->private_imux[1]; |
| 1982 | } |
| 1983 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1984 | static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 1985 | { |
| 1986 | int err; |
| 1987 | |
| 1988 | if (!pin) |
| 1989 | return 0; |
| 1990 | |
| 1991 | spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 1992 | spec->hp_independent_mode_index = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1993 | |
| 1994 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 1995 | "Headphone Playback Volume", |
| 1996 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 1997 | if (err < 0) |
| 1998 | return err; |
| 1999 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2000 | "Headphone Playback Switch", |
| 2001 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2002 | if (err < 0) |
| 2003 | return err; |
| 2004 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2005 | create_hp_imux(spec); |
| 2006 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2007 | return 0; |
| 2008 | } |
| 2009 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2010 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
| 2011 | hda_nid_t nid) |
| 2012 | { |
| 2013 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; |
| 2014 | int i, nums; |
| 2015 | |
| 2016 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); |
| 2017 | for (i = 0; i < nums; i++) |
| 2018 | if (conn[i] == nid) |
| 2019 | return i; |
| 2020 | return -1; |
| 2021 | } |
| 2022 | |
| 2023 | /* look for ADCs */ |
| 2024 | static int via_fill_adcs(struct hda_codec *codec) |
| 2025 | { |
| 2026 | struct via_spec *spec = codec->spec; |
| 2027 | hda_nid_t nid = codec->start_nid; |
| 2028 | int i; |
| 2029 | |
| 2030 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2031 | unsigned int wcaps = get_wcaps(codec, nid); |
| 2032 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 2033 | continue; |
| 2034 | if (wcaps & AC_WCAP_DIGITAL) |
| 2035 | continue; |
| 2036 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 2037 | continue; |
| 2038 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) |
| 2039 | return -ENOMEM; |
| 2040 | spec->adc_nids[spec->num_adc_nids++] = nid; |
| 2041 | } |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | static int get_mux_nids(struct hda_codec *codec); |
| 2046 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2047 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2048 | static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2049 | const struct auto_pin_cfg *cfg, |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2050 | hda_nid_t mix_nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2051 | { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2052 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2053 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2054 | int i, err, idx, idx2, type, type_idx = 0; |
| 2055 | hda_nid_t cap_nid; |
| 2056 | hda_nid_t pin_idxs[8]; |
| 2057 | int num_idxs; |
| 2058 | |
| 2059 | err = via_fill_adcs(codec); |
| 2060 | if (err < 0) |
| 2061 | return err; |
| 2062 | err = get_mux_nids(codec); |
| 2063 | if (err < 0) |
| 2064 | return err; |
| 2065 | cap_nid = spec->mux_nids[0]; |
| 2066 | |
| 2067 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, |
| 2068 | ARRAY_SIZE(pin_idxs)); |
| 2069 | if (num_idxs <= 0) |
| 2070 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2071 | |
| 2072 | /* for internal loopback recording select */ |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2073 | for (idx = 0; idx < num_idxs; idx++) { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2074 | if (pin_idxs[idx] == mix_nid) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2075 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2076 | break; |
| 2077 | } |
| 2078 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2079 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2080 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2081 | const char *label; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2082 | type = cfg->inputs[i].type; |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2083 | for (idx = 0; idx < num_idxs; idx++) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2084 | if (pin_idxs[idx] == cfg->inputs[i].pin) |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2085 | break; |
| 2086 | if (idx >= num_idxs) |
| 2087 | continue; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2088 | if (i > 0 && type == cfg->inputs[i - 1].type) |
| 2089 | type_idx++; |
| 2090 | else |
| 2091 | type_idx = 0; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2092 | label = hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2093 | idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]); |
| 2094 | if (idx2 >= 0) |
Lydia Wang | 1692228 | 2011-03-22 16:24:10 +0800 | [diff] [blame] | 2095 | err = via_new_analog_input(spec, label, type_idx, |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2096 | idx2, mix_nid); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2097 | if (err < 0) |
| 2098 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2099 | snd_hda_add_imux_item(imux, label, idx, NULL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2100 | } |
| 2101 | return 0; |
| 2102 | } |
| 2103 | |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2104 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2105 | static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec, |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2106 | const struct auto_pin_cfg *cfg) |
| 2107 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2108 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x17); |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2111 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2112 | static const struct hda_amp_list vt1708_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2113 | { 0x17, HDA_INPUT, 1 }, |
| 2114 | { 0x17, HDA_INPUT, 2 }, |
| 2115 | { 0x17, HDA_INPUT, 3 }, |
| 2116 | { 0x17, HDA_INPUT, 4 }, |
| 2117 | { } /* end */ |
| 2118 | }; |
| 2119 | #endif |
| 2120 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2121 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 2122 | { |
| 2123 | unsigned int def_conf; |
| 2124 | unsigned char seqassoc; |
| 2125 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 2126 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2127 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 2128 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 2129 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 2130 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 2131 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 2132 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | return; |
| 2136 | } |
| 2137 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2138 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2139 | struct snd_ctl_elem_value *ucontrol) |
| 2140 | { |
| 2141 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2142 | struct via_spec *spec = codec->spec; |
| 2143 | |
| 2144 | if (spec->codec_type != VT1708) |
| 2145 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2146 | spec->vt1708_jack_detect = |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2147 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2148 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2149 | return 0; |
| 2150 | } |
| 2151 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2152 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2153 | struct snd_ctl_elem_value *ucontrol) |
| 2154 | { |
| 2155 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2156 | struct via_spec *spec = codec->spec; |
| 2157 | int change; |
| 2158 | |
| 2159 | if (spec->codec_type != VT1708) |
| 2160 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2161 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2162 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2163 | == !spec->vt1708_jack_detect; |
| 2164 | if (spec->vt1708_jack_detect) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2165 | mute_aa_path(codec, 1); |
| 2166 | notify_aa_path_ctls(codec); |
| 2167 | } |
| 2168 | return change; |
| 2169 | } |
| 2170 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2171 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
| 2172 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2173 | .name = "Jack Detect", |
| 2174 | .count = 1, |
| 2175 | .info = snd_ctl_boolean_mono_info, |
| 2176 | .get = vt1708_jack_detect_get, |
| 2177 | .put = vt1708_jack_detect_put, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2178 | }; |
| 2179 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2180 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
| 2181 | { |
| 2182 | struct via_spec *spec = codec->spec; |
| 2183 | int err; |
| 2184 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2185 | /* Add HP and CD pin config connect bit re-config action */ |
| 2186 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 2187 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 2188 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2189 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2190 | if (err < 0) |
| 2191 | return err; |
| 2192 | err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg); |
| 2193 | if (err < 0) |
| 2194 | return err; |
| 2195 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2196 | return 0; /* can't find valid BIOS pin config */ |
| 2197 | |
| 2198 | err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 2199 | if (err < 0) |
| 2200 | return err; |
| 2201 | err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 2202 | if (err < 0) |
| 2203 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2204 | err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2205 | if (err < 0) |
| 2206 | return err; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2207 | /* add jack detect on/off control */ |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2208 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
| 2209 | return -ENOMEM; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2210 | |
| 2211 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2212 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2213 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2214 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2215 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2216 | if (spec->autocfg.dig_in_pin) |
| 2217 | spec->dig_in_nid = VT1708_DIGIN_NID; |
| 2218 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2219 | if (spec->kctls.list) |
| 2220 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2221 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2222 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2223 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2224 | spec->input_mux = &spec->private_imux[0]; |
| 2225 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2226 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2227 | via_hp_build(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2228 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2229 | via_smart51_build(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2230 | return 1; |
| 2231 | } |
| 2232 | |
| 2233 | /* init callback for auto-configuration model -- overriding the default init */ |
| 2234 | static int via_auto_init(struct hda_codec *codec) |
| 2235 | { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2236 | struct via_spec *spec = codec->spec; |
| 2237 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2238 | via_init(codec); |
| 2239 | via_auto_init_multi_out(codec); |
| 2240 | via_auto_init_hp_out(codec); |
| 2241 | via_auto_init_analog_input(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 2242 | |
| 2243 | if (VT2002P_COMPATIBLE(spec)) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2244 | via_hp_bind_automute(codec); |
| 2245 | } else { |
| 2246 | via_hp_automute(codec); |
| 2247 | via_speaker_automute(codec); |
| 2248 | } |
| 2249 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2250 | return 0; |
| 2251 | } |
| 2252 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2253 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
| 2254 | { |
| 2255 | struct via_spec *spec = container_of(work, struct via_spec, |
| 2256 | vt1708_hp_work.work); |
| 2257 | if (spec->codec_type != VT1708) |
| 2258 | return; |
| 2259 | /* if jack state toggled */ |
| 2260 | if (spec->vt1708_hp_present |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2261 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2262 | spec->vt1708_hp_present ^= 1; |
| 2263 | via_hp_automute(spec->codec); |
| 2264 | } |
| 2265 | vt1708_start_hp_work(spec); |
| 2266 | } |
| 2267 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2268 | static int get_mux_nids(struct hda_codec *codec) |
| 2269 | { |
| 2270 | struct via_spec *spec = codec->spec; |
| 2271 | hda_nid_t nid, conn[8]; |
| 2272 | unsigned int type; |
| 2273 | int i, n; |
| 2274 | |
| 2275 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2276 | nid = spec->adc_nids[i]; |
| 2277 | while (nid) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2278 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2279 | if (type == AC_WID_PIN) |
| 2280 | break; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2281 | n = snd_hda_get_connections(codec, nid, conn, |
| 2282 | ARRAY_SIZE(conn)); |
| 2283 | if (n <= 0) |
| 2284 | break; |
| 2285 | if (n > 1) { |
| 2286 | spec->mux_nids[i] = nid; |
| 2287 | break; |
| 2288 | } |
| 2289 | nid = conn[0]; |
| 2290 | } |
| 2291 | } |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2292 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2293 | } |
| 2294 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2295 | static int patch_vt1708(struct hda_codec *codec) |
| 2296 | { |
| 2297 | struct via_spec *spec; |
| 2298 | int err; |
| 2299 | |
| 2300 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2301 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2302 | if (spec == NULL) |
| 2303 | return -ENOMEM; |
| 2304 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2305 | /* automatic parse from the BIOS config */ |
| 2306 | err = vt1708_parse_auto_config(codec); |
| 2307 | if (err < 0) { |
| 2308 | via_free(codec); |
| 2309 | return err; |
| 2310 | } else if (!err) { |
| 2311 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 2312 | "from BIOS. Using genenic mode...\n"); |
| 2313 | } |
| 2314 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2315 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2316 | spec->stream_name_analog = "VT1708 Analog"; |
| 2317 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 2318 | /* disable 32bit format on VT1708 */ |
| 2319 | if (codec->vendor_id == 0x11061708) |
| 2320 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2321 | spec->stream_analog_capture = &vt1708_pcm_analog_capture; |
| 2322 | |
| 2323 | spec->stream_name_digital = "VT1708 Digital"; |
| 2324 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; |
| 2325 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; |
| 2326 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2327 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2328 | spec->mixers[spec->num_mixers] = vt1708_capture_mixer; |
| 2329 | spec->num_mixers++; |
| 2330 | } |
| 2331 | |
| 2332 | codec->patch_ops = via_patch_ops; |
| 2333 | |
| 2334 | codec->patch_ops.init = via_auto_init; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2335 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2336 | spec->loopback.amplist = vt1708_loopbacks; |
| 2337 | #endif |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2338 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2339 | return 0; |
| 2340 | } |
| 2341 | |
| 2342 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2343 | static const struct snd_kcontrol_new vt1709_capture_mixer[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2344 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), |
| 2345 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), |
| 2346 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), |
| 2347 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), |
| 2348 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), |
| 2349 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), |
| 2350 | { |
| 2351 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2352 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2353 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2354 | */ |
| 2355 | /* .name = "Capture Source", */ |
| 2356 | .name = "Input Source", |
| 2357 | .count = 1, |
| 2358 | .info = via_mux_enum_info, |
| 2359 | .get = via_mux_enum_get, |
| 2360 | .put = via_mux_enum_put, |
| 2361 | }, |
| 2362 | { } /* end */ |
| 2363 | }; |
| 2364 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2365 | static const struct hda_verb vt1709_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2366 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2367 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2368 | { } |
| 2369 | }; |
| 2370 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2371 | /* |
| 2372 | * generic initialization of ADC, input mixers and output mixers |
| 2373 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2374 | static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2375 | /* |
| 2376 | * Unmute ADC0-2 and set the default input to mic-in |
| 2377 | */ |
| 2378 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2379 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2380 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2381 | |
| 2382 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2383 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2384 | * mixer widget |
| 2385 | */ |
| 2386 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2387 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2388 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2389 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2390 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2391 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2392 | |
| 2393 | /* |
| 2394 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2395 | */ |
| 2396 | /* set vol=0 to output mixers */ |
| 2397 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2398 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2399 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2400 | |
| 2401 | /* |
| 2402 | * Unmute PW3 and PW4 |
| 2403 | */ |
| 2404 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2405 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2406 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2407 | /* Set input of PW4 as MW0 */ |
| 2408 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2409 | /* PW9 Output enable */ |
| 2410 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2411 | { } |
| 2412 | }; |
| 2413 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2414 | static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2415 | .substreams = 1, |
| 2416 | .channels_min = 2, |
| 2417 | .channels_max = 10, |
| 2418 | .nid = 0x10, /* NID to query formats and rates */ |
| 2419 | .ops = { |
| 2420 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 2421 | .prepare = via_playback_multi_pcm_prepare, |
| 2422 | .cleanup = via_playback_multi_pcm_cleanup, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2423 | }, |
| 2424 | }; |
| 2425 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2426 | static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2427 | .substreams = 1, |
| 2428 | .channels_min = 2, |
| 2429 | .channels_max = 6, |
| 2430 | .nid = 0x10, /* NID to query formats and rates */ |
| 2431 | .ops = { |
| 2432 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 2433 | .prepare = via_playback_multi_pcm_prepare, |
| 2434 | .cleanup = via_playback_multi_pcm_cleanup, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2435 | }, |
| 2436 | }; |
| 2437 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2438 | static const struct hda_pcm_stream vt1709_pcm_analog_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2439 | .substreams = 2, |
| 2440 | .channels_min = 2, |
| 2441 | .channels_max = 2, |
| 2442 | .nid = 0x14, /* NID to query formats and rates */ |
| 2443 | .ops = { |
| 2444 | .prepare = via_capture_pcm_prepare, |
| 2445 | .cleanup = via_capture_pcm_cleanup |
| 2446 | }, |
| 2447 | }; |
| 2448 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2449 | static const struct hda_pcm_stream vt1709_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2450 | .substreams = 1, |
| 2451 | .channels_min = 2, |
| 2452 | .channels_max = 2, |
| 2453 | /* NID is set in via_build_pcms */ |
| 2454 | .ops = { |
| 2455 | .open = via_dig_playback_pcm_open, |
| 2456 | .close = via_dig_playback_pcm_close |
| 2457 | }, |
| 2458 | }; |
| 2459 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2460 | static const struct hda_pcm_stream vt1709_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2461 | .substreams = 1, |
| 2462 | .channels_min = 2, |
| 2463 | .channels_max = 2, |
| 2464 | }; |
| 2465 | |
| 2466 | static int vt1709_auto_fill_dac_nids(struct via_spec *spec, |
| 2467 | const struct auto_pin_cfg *cfg) |
| 2468 | { |
| 2469 | int i; |
| 2470 | hda_nid_t nid; |
| 2471 | |
| 2472 | if (cfg->line_outs == 4) /* 10 channels */ |
| 2473 | spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */ |
| 2474 | else if (cfg->line_outs == 3) /* 6 channels */ |
| 2475 | spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */ |
| 2476 | |
| 2477 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 2478 | |
| 2479 | if (cfg->line_outs == 4) { /* 10 channels */ |
| 2480 | for (i = 0; i < cfg->line_outs; i++) { |
| 2481 | nid = cfg->line_out_pins[i]; |
| 2482 | if (nid) { |
| 2483 | /* config dac list */ |
| 2484 | switch (i) { |
| 2485 | case AUTO_SEQ_FRONT: |
| 2486 | /* AOW0 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2487 | spec->private_dac_nids[i] = 0x10; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2488 | break; |
| 2489 | case AUTO_SEQ_CENLFE: |
| 2490 | /* AOW2 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2491 | spec->private_dac_nids[i] = 0x12; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2492 | break; |
| 2493 | case AUTO_SEQ_SURROUND: |
| 2494 | /* AOW3 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2495 | spec->private_dac_nids[i] = 0x11; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2496 | break; |
| 2497 | case AUTO_SEQ_SIDE: |
| 2498 | /* AOW1 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2499 | spec->private_dac_nids[i] = 0x27; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2500 | break; |
| 2501 | default: |
| 2502 | break; |
| 2503 | } |
| 2504 | } |
| 2505 | } |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2506 | spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2507 | |
| 2508 | } else if (cfg->line_outs == 3) { /* 6 channels */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2509 | for (i = 0; i < cfg->line_outs; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2510 | nid = cfg->line_out_pins[i]; |
| 2511 | if (nid) { |
| 2512 | /* config dac list */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2513 | switch (i) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2514 | case AUTO_SEQ_FRONT: |
| 2515 | /* AOW0 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2516 | spec->private_dac_nids[i] = 0x10; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2517 | break; |
| 2518 | case AUTO_SEQ_CENLFE: |
| 2519 | /* AOW2 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2520 | spec->private_dac_nids[i] = 0x12; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2521 | break; |
| 2522 | case AUTO_SEQ_SURROUND: |
| 2523 | /* AOW1 */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 2524 | spec->private_dac_nids[i] = 0x11; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2525 | break; |
| 2526 | default: |
| 2527 | break; |
| 2528 | } |
| 2529 | } |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
| 2536 | /* add playback controls from the parsed DAC table */ |
| 2537 | static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, |
| 2538 | const struct auto_pin_cfg *cfg) |
| 2539 | { |
| 2540 | char name[32]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 2541 | static const char * const chname[4] = { |
| 2542 | "Front", "Surround", "C/LFE", "Side" |
| 2543 | }; |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2544 | hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29}; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2545 | int i, err; |
| 2546 | |
| 2547 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 2548 | nid = cfg->line_out_pins[i]; |
| 2549 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2550 | if (!nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2551 | continue; |
| 2552 | |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2553 | nid_vol = nid_vols[i]; |
| 2554 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2555 | if (i == AUTO_SEQ_CENLFE) { |
| 2556 | /* Center/LFE */ |
| 2557 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2558 | "Center Playback Volume", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2559 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2560 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2561 | if (err < 0) |
| 2562 | return err; |
| 2563 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2564 | "LFE Playback Volume", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2565 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2566 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2567 | if (err < 0) |
| 2568 | return err; |
| 2569 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2570 | "Center Playback Switch", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2571 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2572 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2573 | if (err < 0) |
| 2574 | return err; |
| 2575 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2576 | "LFE Playback Switch", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2577 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2578 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2579 | if (err < 0) |
| 2580 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2581 | } else if (i == AUTO_SEQ_FRONT) { |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2582 | /* ADD control to mixer index 0 */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2583 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2584 | "Master Front Playback Volume", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2585 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2586 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2587 | if (err < 0) |
| 2588 | return err; |
| 2589 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2590 | "Master Front Playback Switch", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2591 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2592 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2593 | if (err < 0) |
| 2594 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2595 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2596 | /* add control to PW3 */ |
| 2597 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2598 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2599 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 2600 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2601 | if (err < 0) |
| 2602 | return err; |
| 2603 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2604 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2605 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 2606 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2607 | if (err < 0) |
| 2608 | return err; |
| 2609 | } else if (i == AUTO_SEQ_SURROUND) { |
| 2610 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2611 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2612 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2613 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2614 | if (err < 0) |
| 2615 | return err; |
| 2616 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2617 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2618 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2619 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2620 | if (err < 0) |
| 2621 | return err; |
| 2622 | } else if (i == AUTO_SEQ_SIDE) { |
| 2623 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2624 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2625 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2626 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2627 | if (err < 0) |
| 2628 | return err; |
| 2629 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2630 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2631 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2632 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2633 | if (err < 0) |
| 2634 | return err; |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | return 0; |
| 2639 | } |
| 2640 | |
| 2641 | static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 2642 | { |
| 2643 | int err; |
| 2644 | |
| 2645 | if (!pin) |
| 2646 | return 0; |
| 2647 | |
| 2648 | if (spec->multiout.num_dacs == 5) /* 10 channels */ |
| 2649 | spec->multiout.hp_nid = VT1709_HP_DAC_NID; |
| 2650 | else if (spec->multiout.num_dacs == 3) /* 6 channels */ |
| 2651 | spec->multiout.hp_nid = 0; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 2652 | spec->hp_independent_mode_index = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2653 | |
| 2654 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2655 | "Headphone Playback Volume", |
| 2656 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2657 | if (err < 0) |
| 2658 | return err; |
| 2659 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2660 | "Headphone Playback Switch", |
| 2661 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2662 | if (err < 0) |
| 2663 | return err; |
| 2664 | |
| 2665 | return 0; |
| 2666 | } |
| 2667 | |
| 2668 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2669 | static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2670 | const struct auto_pin_cfg *cfg) |
| 2671 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2672 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x18); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | static int vt1709_parse_auto_config(struct hda_codec *codec) |
| 2676 | { |
| 2677 | struct via_spec *spec = codec->spec; |
| 2678 | int err; |
| 2679 | |
| 2680 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2681 | if (err < 0) |
| 2682 | return err; |
| 2683 | err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg); |
| 2684 | if (err < 0) |
| 2685 | return err; |
| 2686 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2687 | return 0; /* can't find valid BIOS pin config */ |
| 2688 | |
| 2689 | err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 2690 | if (err < 0) |
| 2691 | return err; |
| 2692 | err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 2693 | if (err < 0) |
| 2694 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2695 | err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2696 | if (err < 0) |
| 2697 | return err; |
| 2698 | |
| 2699 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2700 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2701 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2702 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2703 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2704 | if (spec->autocfg.dig_in_pin) |
| 2705 | spec->dig_in_nid = VT1709_DIGIN_NID; |
| 2706 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2707 | if (spec->kctls.list) |
| 2708 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2709 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2710 | spec->input_mux = &spec->private_imux[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2711 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2712 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 2713 | via_hp_build(codec); |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2714 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2715 | via_smart51_build(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2716 | return 1; |
| 2717 | } |
| 2718 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2719 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2720 | static const struct hda_amp_list vt1709_loopbacks[] = { |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2721 | { 0x18, HDA_INPUT, 1 }, |
| 2722 | { 0x18, HDA_INPUT, 2 }, |
| 2723 | { 0x18, HDA_INPUT, 3 }, |
| 2724 | { 0x18, HDA_INPUT, 4 }, |
| 2725 | { } /* end */ |
| 2726 | }; |
| 2727 | #endif |
| 2728 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2729 | static int patch_vt1709_10ch(struct hda_codec *codec) |
| 2730 | { |
| 2731 | struct via_spec *spec; |
| 2732 | int err; |
| 2733 | |
| 2734 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2735 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2736 | if (spec == NULL) |
| 2737 | return -ENOMEM; |
| 2738 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2739 | err = vt1709_parse_auto_config(codec); |
| 2740 | if (err < 0) { |
| 2741 | via_free(codec); |
| 2742 | return err; |
| 2743 | } else if (!err) { |
| 2744 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 2745 | "Using genenic mode...\n"); |
| 2746 | } |
| 2747 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2748 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
| 2749 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2750 | |
| 2751 | spec->stream_name_analog = "VT1709 Analog"; |
| 2752 | spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; |
| 2753 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; |
| 2754 | |
| 2755 | spec->stream_name_digital = "VT1709 Digital"; |
| 2756 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
| 2757 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
| 2758 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2759 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2760 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 2761 | spec->num_mixers++; |
| 2762 | } |
| 2763 | |
| 2764 | codec->patch_ops = via_patch_ops; |
| 2765 | |
| 2766 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2767 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2768 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2769 | spec->loopback.amplist = vt1709_loopbacks; |
| 2770 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2771 | |
| 2772 | return 0; |
| 2773 | } |
| 2774 | /* |
| 2775 | * generic initialization of ADC, input mixers and output mixers |
| 2776 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2777 | static const struct hda_verb vt1709_6ch_volume_init_verbs[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2778 | /* |
| 2779 | * Unmute ADC0-2 and set the default input to mic-in |
| 2780 | */ |
| 2781 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2782 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2783 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2784 | |
| 2785 | |
| 2786 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2787 | * mixer widget |
| 2788 | */ |
| 2789 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2790 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2791 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2792 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2793 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2794 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2795 | |
| 2796 | /* |
| 2797 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2798 | */ |
| 2799 | /* set vol=0 to output mixers */ |
| 2800 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2801 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2802 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2803 | |
| 2804 | /* |
| 2805 | * Unmute PW3 and PW4 |
| 2806 | */ |
| 2807 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2808 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2809 | |
| 2810 | /* Set input of PW4 as MW0 */ |
| 2811 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2812 | /* PW9 Output enable */ |
| 2813 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2814 | { } |
| 2815 | }; |
| 2816 | |
| 2817 | static int patch_vt1709_6ch(struct hda_codec *codec) |
| 2818 | { |
| 2819 | struct via_spec *spec; |
| 2820 | int err; |
| 2821 | |
| 2822 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2823 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2824 | if (spec == NULL) |
| 2825 | return -ENOMEM; |
| 2826 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2827 | err = vt1709_parse_auto_config(codec); |
| 2828 | if (err < 0) { |
| 2829 | via_free(codec); |
| 2830 | return err; |
| 2831 | } else if (!err) { |
| 2832 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 2833 | "Using genenic mode...\n"); |
| 2834 | } |
| 2835 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2836 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
| 2837 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2838 | |
| 2839 | spec->stream_name_analog = "VT1709 Analog"; |
| 2840 | spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; |
| 2841 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; |
| 2842 | |
| 2843 | spec->stream_name_digital = "VT1709 Digital"; |
| 2844 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
| 2845 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
| 2846 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2847 | if (spec->adc_nids && spec->input_mux) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2848 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 2849 | spec->num_mixers++; |
| 2850 | } |
| 2851 | |
| 2852 | codec->patch_ops = via_patch_ops; |
| 2853 | |
| 2854 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2855 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2856 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2857 | spec->loopback.amplist = vt1709_loopbacks; |
| 2858 | #endif |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2859 | return 0; |
| 2860 | } |
| 2861 | |
| 2862 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2863 | static const struct snd_kcontrol_new vt1708B_capture_mixer[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2864 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 2865 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 2866 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 2867 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 2868 | { |
| 2869 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2870 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2871 | * So call somewhat different.. |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2872 | */ |
| 2873 | /* .name = "Capture Source", */ |
| 2874 | .name = "Input Source", |
| 2875 | .count = 1, |
| 2876 | .info = via_mux_enum_info, |
| 2877 | .get = via_mux_enum_get, |
| 2878 | .put = via_mux_enum_put, |
| 2879 | }, |
| 2880 | { } /* end */ |
| 2881 | }; |
| 2882 | /* |
| 2883 | * generic initialization of ADC, input mixers and output mixers |
| 2884 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2885 | static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2886 | /* |
| 2887 | * Unmute ADC0-1 and set the default input to mic-in |
| 2888 | */ |
| 2889 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2890 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2891 | |
| 2892 | |
| 2893 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2894 | * mixer widget |
| 2895 | */ |
| 2896 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2897 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2898 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2899 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2900 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2901 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2902 | |
| 2903 | /* |
| 2904 | * Set up output mixers |
| 2905 | */ |
| 2906 | /* set vol=0 to output mixers */ |
| 2907 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2908 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2909 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2910 | |
| 2911 | /* Setup default input to PW4 */ |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2912 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2913 | /* PW9 Output enable */ |
| 2914 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2915 | /* PW10 Input enable */ |
| 2916 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 2917 | { } |
| 2918 | }; |
| 2919 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2920 | static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2921 | /* |
| 2922 | * Unmute ADC0-1 and set the default input to mic-in |
| 2923 | */ |
| 2924 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2925 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2926 | |
| 2927 | |
| 2928 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 2929 | * mixer widget |
| 2930 | */ |
| 2931 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 2932 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2933 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2934 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2935 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2936 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 2937 | |
| 2938 | /* |
| 2939 | * Set up output mixers |
| 2940 | */ |
| 2941 | /* set vol=0 to output mixers */ |
| 2942 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2943 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2944 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2945 | |
| 2946 | /* Setup default input of PW4 to MW0 */ |
| 2947 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 2948 | /* PW9 Output enable */ |
| 2949 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2950 | /* PW10 Input enable */ |
| 2951 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 2952 | { } |
| 2953 | }; |
| 2954 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2955 | static const struct hda_verb vt1708B_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2956 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2957 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 2958 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2959 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2960 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2961 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2962 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2963 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 2964 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2965 | { } |
| 2966 | }; |
| 2967 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 2968 | static int via_pcm_open_close(struct hda_pcm_stream *hinfo, |
| 2969 | struct hda_codec *codec, |
| 2970 | struct snd_pcm_substream *substream) |
| 2971 | { |
| 2972 | int idle = substream->pstr->substream_opened == 1 |
| 2973 | && substream->ref_count == 0; |
| 2974 | |
| 2975 | analog_low_current_mode(codec, idle); |
| 2976 | return 0; |
| 2977 | } |
| 2978 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2979 | static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2980 | .substreams = 2, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2981 | .channels_min = 2, |
| 2982 | .channels_max = 8, |
| 2983 | .nid = 0x10, /* NID to query formats and rates */ |
| 2984 | .ops = { |
| 2985 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2986 | .prepare = via_playback_multi_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 2987 | .cleanup = via_playback_multi_pcm_cleanup, |
| 2988 | .close = via_pcm_open_close |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2989 | }, |
| 2990 | }; |
| 2991 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 2992 | static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2993 | .substreams = 2, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2994 | .channels_min = 2, |
| 2995 | .channels_max = 4, |
| 2996 | .nid = 0x10, /* NID to query formats and rates */ |
| 2997 | .ops = { |
| 2998 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2999 | .prepare = via_playback_multi_pcm_prepare, |
| 3000 | .cleanup = via_playback_multi_pcm_cleanup |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3001 | }, |
| 3002 | }; |
| 3003 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3004 | static const struct hda_pcm_stream vt1708B_pcm_analog_capture = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3005 | .substreams = 2, |
| 3006 | .channels_min = 2, |
| 3007 | .channels_max = 2, |
| 3008 | .nid = 0x13, /* NID to query formats and rates */ |
| 3009 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3010 | .open = via_pcm_open_close, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3011 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3012 | .cleanup = via_capture_pcm_cleanup, |
| 3013 | .close = via_pcm_open_close |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3014 | }, |
| 3015 | }; |
| 3016 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3017 | static const struct hda_pcm_stream vt1708B_pcm_digital_playback = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3018 | .substreams = 1, |
| 3019 | .channels_min = 2, |
| 3020 | .channels_max = 2, |
| 3021 | /* NID is set in via_build_pcms */ |
| 3022 | .ops = { |
| 3023 | .open = via_dig_playback_pcm_open, |
| 3024 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3025 | .prepare = via_dig_playback_pcm_prepare, |
| 3026 | .cleanup = via_dig_playback_pcm_cleanup |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3027 | }, |
| 3028 | }; |
| 3029 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3030 | static const struct hda_pcm_stream vt1708B_pcm_digital_capture = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3031 | .substreams = 1, |
| 3032 | .channels_min = 2, |
| 3033 | .channels_max = 2, |
| 3034 | }; |
| 3035 | |
| 3036 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 3037 | static int vt1708B_auto_fill_dac_nids(struct via_spec *spec, |
| 3038 | const struct auto_pin_cfg *cfg) |
| 3039 | { |
| 3040 | int i; |
| 3041 | hda_nid_t nid; |
| 3042 | |
| 3043 | spec->multiout.num_dacs = cfg->line_outs; |
| 3044 | |
| 3045 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 3046 | |
| 3047 | for (i = 0; i < 4; i++) { |
| 3048 | nid = cfg->line_out_pins[i]; |
| 3049 | if (nid) { |
| 3050 | /* config dac list */ |
| 3051 | switch (i) { |
| 3052 | case AUTO_SEQ_FRONT: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3053 | spec->private_dac_nids[i] = 0x10; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3054 | break; |
| 3055 | case AUTO_SEQ_CENLFE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3056 | spec->private_dac_nids[i] = 0x24; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3057 | break; |
| 3058 | case AUTO_SEQ_SURROUND: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3059 | spec->private_dac_nids[i] = 0x11; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3060 | break; |
| 3061 | case AUTO_SEQ_SIDE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3062 | spec->private_dac_nids[i] = 0x25; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3063 | break; |
| 3064 | } |
| 3065 | } |
| 3066 | } |
| 3067 | |
| 3068 | return 0; |
| 3069 | } |
| 3070 | |
| 3071 | /* add playback controls from the parsed DAC table */ |
| 3072 | static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec, |
| 3073 | const struct auto_pin_cfg *cfg) |
| 3074 | { |
| 3075 | char name[32]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 3076 | static const char * const chname[4] = { |
| 3077 | "Front", "Surround", "C/LFE", "Side" |
| 3078 | }; |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 3079 | hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27}; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3080 | hda_nid_t nid, nid_vol = 0; |
| 3081 | int i, err; |
| 3082 | |
| 3083 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 3084 | nid = cfg->line_out_pins[i]; |
| 3085 | |
| 3086 | if (!nid) |
| 3087 | continue; |
| 3088 | |
| 3089 | nid_vol = nid_vols[i]; |
| 3090 | |
| 3091 | if (i == AUTO_SEQ_CENLFE) { |
| 3092 | /* Center/LFE */ |
| 3093 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3094 | "Center Playback Volume", |
| 3095 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 3096 | HDA_OUTPUT)); |
| 3097 | if (err < 0) |
| 3098 | return err; |
| 3099 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3100 | "LFE Playback Volume", |
| 3101 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 3102 | HDA_OUTPUT)); |
| 3103 | if (err < 0) |
| 3104 | return err; |
| 3105 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3106 | "Center Playback Switch", |
| 3107 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 3108 | HDA_OUTPUT)); |
| 3109 | if (err < 0) |
| 3110 | return err; |
| 3111 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3112 | "LFE Playback Switch", |
| 3113 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 3114 | HDA_OUTPUT)); |
| 3115 | if (err < 0) |
| 3116 | return err; |
| 3117 | } else if (i == AUTO_SEQ_FRONT) { |
| 3118 | /* add control to mixer index 0 */ |
| 3119 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3120 | "Master Front Playback Volume", |
| 3121 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3122 | HDA_INPUT)); |
| 3123 | if (err < 0) |
| 3124 | return err; |
| 3125 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3126 | "Master Front Playback Switch", |
| 3127 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3128 | HDA_INPUT)); |
| 3129 | if (err < 0) |
| 3130 | return err; |
| 3131 | |
| 3132 | /* add control to PW3 */ |
| 3133 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3134 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3135 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 3136 | HDA_OUTPUT)); |
| 3137 | if (err < 0) |
| 3138 | return err; |
| 3139 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3140 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3141 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 3142 | HDA_OUTPUT)); |
| 3143 | if (err < 0) |
| 3144 | return err; |
| 3145 | } else { |
| 3146 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3147 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3148 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3149 | HDA_OUTPUT)); |
| 3150 | if (err < 0) |
| 3151 | return err; |
| 3152 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3153 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3154 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3155 | HDA_OUTPUT)); |
| 3156 | if (err < 0) |
| 3157 | return err; |
| 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | return 0; |
| 3162 | } |
| 3163 | |
| 3164 | static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 3165 | { |
| 3166 | int err; |
| 3167 | |
| 3168 | if (!pin) |
| 3169 | return 0; |
| 3170 | |
| 3171 | spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 3172 | spec->hp_independent_mode_index = 1; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3173 | |
| 3174 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3175 | "Headphone Playback Volume", |
| 3176 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3177 | if (err < 0) |
| 3178 | return err; |
| 3179 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3180 | "Headphone Playback Switch", |
| 3181 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3182 | if (err < 0) |
| 3183 | return err; |
| 3184 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3185 | create_hp_imux(spec); |
| 3186 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3187 | return 0; |
| 3188 | } |
| 3189 | |
| 3190 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 3191 | static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3192 | const struct auto_pin_cfg *cfg) |
| 3193 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3194 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | static int vt1708B_parse_auto_config(struct hda_codec *codec) |
| 3198 | { |
| 3199 | struct via_spec *spec = codec->spec; |
| 3200 | int err; |
| 3201 | |
| 3202 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 3203 | if (err < 0) |
| 3204 | return err; |
| 3205 | err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg); |
| 3206 | if (err < 0) |
| 3207 | return err; |
| 3208 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3209 | return 0; /* can't find valid BIOS pin config */ |
| 3210 | |
| 3211 | err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 3212 | if (err < 0) |
| 3213 | return err; |
| 3214 | err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 3215 | if (err < 0) |
| 3216 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 3217 | err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3218 | if (err < 0) |
| 3219 | return err; |
| 3220 | |
| 3221 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3222 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 3223 | if (spec->autocfg.dig_outs) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3224 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 3225 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3226 | if (spec->autocfg.dig_in_pin) |
| 3227 | spec->dig_in_nid = VT1708B_DIGIN_NID; |
| 3228 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3229 | if (spec->kctls.list) |
| 3230 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3231 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3232 | spec->input_mux = &spec->private_imux[0]; |
| 3233 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3234 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3235 | via_hp_build(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3236 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3237 | via_smart51_build(spec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3238 | return 1; |
| 3239 | } |
| 3240 | |
| 3241 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3242 | static const struct hda_amp_list vt1708B_loopbacks[] = { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3243 | { 0x16, HDA_INPUT, 1 }, |
| 3244 | { 0x16, HDA_INPUT, 2 }, |
| 3245 | { 0x16, HDA_INPUT, 3 }, |
| 3246 | { 0x16, HDA_INPUT, 4 }, |
| 3247 | { } /* end */ |
| 3248 | }; |
| 3249 | #endif |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3250 | |
| 3251 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
| 3252 | { |
| 3253 | struct via_spec *spec = codec->spec; |
| 3254 | int imux_is_smixer; |
| 3255 | unsigned int parm; |
| 3256 | int is_8ch = 0; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3257 | if ((spec->codec_type != VT1708B_4CH) && |
| 3258 | (codec->vendor_id != 0x11064397)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3259 | is_8ch = 1; |
| 3260 | |
| 3261 | /* SW0 (17h) = stereo mixer */ |
| 3262 | imux_is_smixer = |
| 3263 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 3264 | == ((spec->codec_type == VT1708S) ? 5 : 0)); |
| 3265 | /* inputs */ |
| 3266 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 3267 | parm = AC_PWRST_D3; |
| 3268 | set_pin_power_state(codec, 0x1a, &parm); |
| 3269 | set_pin_power_state(codec, 0x1b, &parm); |
| 3270 | set_pin_power_state(codec, 0x1e, &parm); |
| 3271 | if (imux_is_smixer) |
| 3272 | parm = AC_PWRST_D0; |
| 3273 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
| 3274 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3275 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3276 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3277 | |
| 3278 | /* outputs */ |
| 3279 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 3280 | parm = AC_PWRST_D3; |
| 3281 | set_pin_power_state(codec, 0x19, &parm); |
| 3282 | if (spec->smart51_enabled) |
| 3283 | set_pin_power_state(codec, 0x1b, &parm); |
| 3284 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3285 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3286 | |
| 3287 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 3288 | if (is_8ch) { |
| 3289 | parm = AC_PWRST_D3; |
| 3290 | set_pin_power_state(codec, 0x22, &parm); |
| 3291 | if (spec->smart51_enabled) |
| 3292 | set_pin_power_state(codec, 0x1a, &parm); |
| 3293 | snd_hda_codec_write(codec, 0x26, 0, |
| 3294 | AC_VERB_SET_POWER_STATE, parm); |
| 3295 | snd_hda_codec_write(codec, 0x24, 0, |
| 3296 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3297 | } else if (codec->vendor_id == 0x11064397) { |
| 3298 | /* PW7(23h), SW2(27h), AOW2(25h) */ |
| 3299 | parm = AC_PWRST_D3; |
| 3300 | set_pin_power_state(codec, 0x23, &parm); |
| 3301 | if (spec->smart51_enabled) |
| 3302 | set_pin_power_state(codec, 0x1a, &parm); |
| 3303 | snd_hda_codec_write(codec, 0x27, 0, |
| 3304 | AC_VERB_SET_POWER_STATE, parm); |
| 3305 | snd_hda_codec_write(codec, 0x25, 0, |
| 3306 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 3310 | parm = AC_PWRST_D3; |
| 3311 | /* force to D0 for internal Speaker */ |
| 3312 | set_pin_power_state(codec, 0x1c, &parm); |
| 3313 | set_pin_power_state(codec, 0x1d, &parm); |
| 3314 | if (is_8ch) |
| 3315 | set_pin_power_state(codec, 0x23, &parm); |
| 3316 | |
| 3317 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
| 3318 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 3319 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3320 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3321 | if (is_8ch) { |
| 3322 | snd_hda_codec_write(codec, 0x25, 0, |
| 3323 | AC_VERB_SET_POWER_STATE, parm); |
| 3324 | snd_hda_codec_write(codec, 0x27, 0, |
| 3325 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3326 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
| 3327 | snd_hda_codec_write(codec, 0x25, 0, |
| 3328 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3329 | } |
| 3330 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3331 | static int patch_vt1708S(struct hda_codec *codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3332 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
| 3333 | { |
| 3334 | struct via_spec *spec; |
| 3335 | int err; |
| 3336 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3337 | if (get_codec_type(codec) == VT1708BCE) |
| 3338 | return patch_vt1708S(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3339 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3340 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3341 | if (spec == NULL) |
| 3342 | return -ENOMEM; |
| 3343 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3344 | /* automatic parse from the BIOS config */ |
| 3345 | err = vt1708B_parse_auto_config(codec); |
| 3346 | if (err < 0) { |
| 3347 | via_free(codec); |
| 3348 | return err; |
| 3349 | } else if (!err) { |
| 3350 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3351 | "from BIOS. Using genenic mode...\n"); |
| 3352 | } |
| 3353 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3354 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
| 3355 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3356 | |
| 3357 | spec->stream_name_analog = "VT1708B Analog"; |
| 3358 | spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; |
| 3359 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; |
| 3360 | |
| 3361 | spec->stream_name_digital = "VT1708B Digital"; |
| 3362 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; |
| 3363 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; |
| 3364 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3365 | if (spec->adc_nids && spec->input_mux) { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3366 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 3367 | spec->num_mixers++; |
| 3368 | } |
| 3369 | |
| 3370 | codec->patch_ops = via_patch_ops; |
| 3371 | |
| 3372 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3373 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3374 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3375 | spec->loopback.amplist = vt1708B_loopbacks; |
| 3376 | #endif |
| 3377 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3378 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 3379 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3380 | return 0; |
| 3381 | } |
| 3382 | |
| 3383 | static int patch_vt1708B_4ch(struct hda_codec *codec) |
| 3384 | { |
| 3385 | struct via_spec *spec; |
| 3386 | int err; |
| 3387 | |
| 3388 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3389 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3390 | if (spec == NULL) |
| 3391 | return -ENOMEM; |
| 3392 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3393 | /* automatic parse from the BIOS config */ |
| 3394 | err = vt1708B_parse_auto_config(codec); |
| 3395 | if (err < 0) { |
| 3396 | via_free(codec); |
| 3397 | return err; |
| 3398 | } else if (!err) { |
| 3399 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3400 | "from BIOS. Using genenic mode...\n"); |
| 3401 | } |
| 3402 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3403 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
| 3404 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3405 | |
| 3406 | spec->stream_name_analog = "VT1708B Analog"; |
| 3407 | spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; |
| 3408 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; |
| 3409 | |
| 3410 | spec->stream_name_digital = "VT1708B Digital"; |
| 3411 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; |
| 3412 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; |
| 3413 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3414 | if (spec->adc_nids && spec->input_mux) { |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3415 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 3416 | spec->num_mixers++; |
| 3417 | } |
| 3418 | |
| 3419 | codec->patch_ops = via_patch_ops; |
| 3420 | |
| 3421 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3422 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3423 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3424 | spec->loopback.amplist = vt1708B_loopbacks; |
| 3425 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3426 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3427 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 3428 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3429 | return 0; |
| 3430 | } |
| 3431 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3432 | /* Patch for VT1708S */ |
| 3433 | |
| 3434 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3435 | static const struct snd_kcontrol_new vt1708S_capture_mixer[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3436 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 3437 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 3438 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 3439 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3440 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 3441 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 3442 | HDA_INPUT), |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3443 | { |
| 3444 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3445 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3446 | * So call somewhat different.. |
| 3447 | */ |
| 3448 | /* .name = "Capture Source", */ |
| 3449 | .name = "Input Source", |
| 3450 | .count = 1, |
| 3451 | .info = via_mux_enum_info, |
| 3452 | .get = via_mux_enum_get, |
| 3453 | .put = via_mux_enum_put, |
| 3454 | }, |
| 3455 | { } /* end */ |
| 3456 | }; |
| 3457 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3458 | static const struct hda_verb vt1708S_volume_init_verbs[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3459 | /* Unmute ADC0-1 and set the default input to mic-in */ |
| 3460 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3461 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3462 | |
| 3463 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the |
| 3464 | * analog-loopback mixer widget */ |
| 3465 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3466 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3467 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3468 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3469 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3470 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3471 | |
| 3472 | /* Setup default input of PW4 to MW0 */ |
| 3473 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3474 | /* PW9, PW10 Output enable */ |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3475 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3476 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 3477 | /* Enable Mic Boost Volume backdoor */ |
| 3478 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3479 | /* don't bybass mixer */ |
| 3480 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3481 | { } |
| 3482 | }; |
| 3483 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3484 | static const struct hda_verb vt1708S_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3485 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3486 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3487 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3488 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3489 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3490 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3491 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3492 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3493 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3494 | { } |
| 3495 | }; |
| 3496 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3497 | static const struct hda_verb vt1705_uniwill_init_verbs[] = { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3498 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3499 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3500 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3501 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3502 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3503 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3504 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3505 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3506 | { } |
| 3507 | }; |
| 3508 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3509 | static const struct hda_pcm_stream vt1708S_pcm_analog_playback = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3510 | .substreams = 2, |
| 3511 | .channels_min = 2, |
| 3512 | .channels_max = 8, |
| 3513 | .nid = 0x10, /* NID to query formats and rates */ |
| 3514 | .ops = { |
| 3515 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 3516 | .prepare = via_playback_multi_pcm_prepare, |
| 3517 | .cleanup = via_playback_multi_pcm_cleanup, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3518 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3519 | }, |
| 3520 | }; |
| 3521 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3522 | static const struct hda_pcm_stream vt1705_pcm_analog_playback = { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3523 | .substreams = 2, |
| 3524 | .channels_min = 2, |
| 3525 | .channels_max = 6, |
| 3526 | .nid = 0x10, /* NID to query formats and rates */ |
| 3527 | .ops = { |
| 3528 | .open = via_playback_pcm_open, |
| 3529 | .prepare = via_playback_multi_pcm_prepare, |
| 3530 | .cleanup = via_playback_multi_pcm_cleanup, |
| 3531 | .close = via_pcm_open_close |
| 3532 | }, |
| 3533 | }; |
| 3534 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3535 | static const struct hda_pcm_stream vt1708S_pcm_analog_capture = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3536 | .substreams = 2, |
| 3537 | .channels_min = 2, |
| 3538 | .channels_max = 2, |
| 3539 | .nid = 0x13, /* NID to query formats and rates */ |
| 3540 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3541 | .open = via_pcm_open_close, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3542 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3543 | .cleanup = via_capture_pcm_cleanup, |
| 3544 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3545 | }, |
| 3546 | }; |
| 3547 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3548 | static const struct hda_pcm_stream vt1708S_pcm_digital_playback = { |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3549 | .substreams = 1, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3550 | .channels_min = 2, |
| 3551 | .channels_max = 2, |
| 3552 | /* NID is set in via_build_pcms */ |
| 3553 | .ops = { |
| 3554 | .open = via_dig_playback_pcm_open, |
| 3555 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3556 | .prepare = via_dig_playback_pcm_prepare, |
| 3557 | .cleanup = via_dig_playback_pcm_cleanup |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3558 | }, |
| 3559 | }; |
| 3560 | |
| 3561 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 3562 | static int vt1708S_auto_fill_dac_nids(struct via_spec *spec, |
| 3563 | const struct auto_pin_cfg *cfg) |
| 3564 | { |
| 3565 | int i; |
| 3566 | hda_nid_t nid; |
| 3567 | |
| 3568 | spec->multiout.num_dacs = cfg->line_outs; |
| 3569 | |
| 3570 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 3571 | |
| 3572 | for (i = 0; i < 4; i++) { |
| 3573 | nid = cfg->line_out_pins[i]; |
| 3574 | if (nid) { |
| 3575 | /* config dac list */ |
| 3576 | switch (i) { |
| 3577 | case AUTO_SEQ_FRONT: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3578 | spec->private_dac_nids[i] = 0x10; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3579 | break; |
| 3580 | case AUTO_SEQ_CENLFE: |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3581 | if (spec->codec->vendor_id == 0x11064397) |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3582 | spec->private_dac_nids[i] = 0x25; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3583 | else |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3584 | spec->private_dac_nids[i] = 0x24; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3585 | break; |
| 3586 | case AUTO_SEQ_SURROUND: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3587 | spec->private_dac_nids[i] = 0x11; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3588 | break; |
| 3589 | case AUTO_SEQ_SIDE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3590 | spec->private_dac_nids[i] = 0x25; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3591 | break; |
| 3592 | } |
| 3593 | } |
| 3594 | } |
| 3595 | |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 3596 | /* for Smart 5.1, line/mic inputs double as output pins */ |
| 3597 | if (cfg->line_outs == 1) { |
| 3598 | spec->multiout.num_dacs = 3; |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3599 | spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3600 | if (spec->codec->vendor_id == 0x11064397) |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3601 | spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3602 | else |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 3603 | spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24; |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 3604 | } |
| 3605 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3606 | return 0; |
| 3607 | } |
| 3608 | |
| 3609 | /* add playback controls from the parsed DAC table */ |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3610 | static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3611 | const struct auto_pin_cfg *cfg) |
| 3612 | { |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3613 | struct via_spec *spec = codec->spec; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3614 | char name[32]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 3615 | static const char * const chname[4] = { |
| 3616 | "Front", "Surround", "C/LFE", "Side" |
| 3617 | }; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3618 | hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25}, |
| 3619 | {0x10, 0x11, 0x25, 0} }; |
| 3620 | hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27}, |
| 3621 | {0x1C, 0x18, 0x27, 0} }; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3622 | hda_nid_t nid, nid_vol, nid_mute; |
| 3623 | int i, err; |
| 3624 | |
| 3625 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 3626 | nid = cfg->line_out_pins[i]; |
| 3627 | |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 3628 | /* for Smart 5.1, there are always at least six channels */ |
| 3629 | if (!nid && i > AUTO_SEQ_CENLFE) |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3630 | continue; |
| 3631 | |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3632 | if (codec->vendor_id == 0x11064397) { |
| 3633 | nid_vol = nid_vols[1][i]; |
| 3634 | nid_mute = nid_mutes[1][i]; |
| 3635 | } else { |
| 3636 | nid_vol = nid_vols[0][i]; |
| 3637 | nid_mute = nid_mutes[0][i]; |
| 3638 | } |
| 3639 | if (!nid_vol && !nid_mute) |
| 3640 | continue; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3641 | |
| 3642 | if (i == AUTO_SEQ_CENLFE) { |
| 3643 | /* Center/LFE */ |
| 3644 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3645 | "Center Playback Volume", |
| 3646 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 3647 | HDA_OUTPUT)); |
| 3648 | if (err < 0) |
| 3649 | return err; |
| 3650 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3651 | "LFE Playback Volume", |
| 3652 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 3653 | HDA_OUTPUT)); |
| 3654 | if (err < 0) |
| 3655 | return err; |
| 3656 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3657 | "Center Playback Switch", |
| 3658 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3659 | 1, 0, |
| 3660 | HDA_OUTPUT)); |
| 3661 | if (err < 0) |
| 3662 | return err; |
| 3663 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3664 | "LFE Playback Switch", |
| 3665 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3666 | 2, 0, |
| 3667 | HDA_OUTPUT)); |
| 3668 | if (err < 0) |
| 3669 | return err; |
| 3670 | } else if (i == AUTO_SEQ_FRONT) { |
| 3671 | /* add control to mixer index 0 */ |
| 3672 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3673 | "Master Front Playback Volume", |
| 3674 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, |
| 3675 | HDA_INPUT)); |
| 3676 | if (err < 0) |
| 3677 | return err; |
| 3678 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3679 | "Master Front Playback Switch", |
| 3680 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, |
| 3681 | HDA_INPUT)); |
| 3682 | if (err < 0) |
| 3683 | return err; |
| 3684 | |
| 3685 | /* Front */ |
| 3686 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3687 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3688 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3689 | HDA_OUTPUT)); |
| 3690 | if (err < 0) |
| 3691 | return err; |
| 3692 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3693 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3694 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3695 | 3, 0, |
| 3696 | HDA_OUTPUT)); |
| 3697 | if (err < 0) |
| 3698 | return err; |
| 3699 | } else { |
| 3700 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3701 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3702 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3703 | HDA_OUTPUT)); |
| 3704 | if (err < 0) |
| 3705 | return err; |
| 3706 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3707 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3708 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3709 | 3, 0, |
| 3710 | HDA_OUTPUT)); |
| 3711 | if (err < 0) |
| 3712 | return err; |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | return 0; |
| 3717 | } |
| 3718 | |
| 3719 | static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 3720 | { |
| 3721 | int err; |
| 3722 | |
| 3723 | if (!pin) |
| 3724 | return 0; |
| 3725 | |
| 3726 | spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 3727 | spec->hp_independent_mode_index = 1; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3728 | |
| 3729 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3730 | "Headphone Playback Volume", |
| 3731 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); |
| 3732 | if (err < 0) |
| 3733 | return err; |
| 3734 | |
| 3735 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3736 | "Headphone Playback Switch", |
| 3737 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3738 | if (err < 0) |
| 3739 | return err; |
| 3740 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3741 | create_hp_imux(spec); |
| 3742 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3743 | return 0; |
| 3744 | } |
| 3745 | |
| 3746 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 3747 | static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3748 | const struct auto_pin_cfg *cfg) |
| 3749 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3750 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3751 | } |
| 3752 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3753 | /* fill out digital output widgets; one for master and one for slave outputs */ |
| 3754 | static void fill_dig_outs(struct hda_codec *codec) |
| 3755 | { |
| 3756 | struct via_spec *spec = codec->spec; |
| 3757 | int i; |
| 3758 | |
| 3759 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 3760 | hda_nid_t nid; |
| 3761 | int conn; |
| 3762 | |
| 3763 | nid = spec->autocfg.dig_out_pins[i]; |
| 3764 | if (!nid) |
| 3765 | continue; |
| 3766 | conn = snd_hda_get_connections(codec, nid, &nid, 1); |
| 3767 | if (conn < 1) |
| 3768 | continue; |
| 3769 | if (!spec->multiout.dig_out_nid) |
| 3770 | spec->multiout.dig_out_nid = nid; |
| 3771 | else { |
| 3772 | spec->slave_dig_outs[0] = nid; |
| 3773 | break; /* at most two dig outs */ |
| 3774 | } |
| 3775 | } |
| 3776 | } |
| 3777 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3778 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
| 3779 | { |
| 3780 | struct via_spec *spec = codec->spec; |
| 3781 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3782 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3783 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3784 | if (err < 0) |
| 3785 | return err; |
| 3786 | err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg); |
| 3787 | if (err < 0) |
| 3788 | return err; |
| 3789 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3790 | return 0; /* can't find valid BIOS pin config */ |
| 3791 | |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3792 | err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3793 | if (err < 0) |
| 3794 | return err; |
| 3795 | err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 3796 | if (err < 0) |
| 3797 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 3798 | err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3799 | if (err < 0) |
| 3800 | return err; |
| 3801 | |
| 3802 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3803 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3804 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 3805 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3806 | if (spec->kctls.list) |
| 3807 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3808 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3809 | spec->input_mux = &spec->private_imux[0]; |
| 3810 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3811 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 3812 | via_hp_build(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3813 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3814 | via_smart51_build(spec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3815 | return 1; |
| 3816 | } |
| 3817 | |
| 3818 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3819 | static const struct hda_amp_list vt1708S_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3820 | { 0x16, HDA_INPUT, 1 }, |
| 3821 | { 0x16, HDA_INPUT, 2 }, |
| 3822 | { 0x16, HDA_INPUT, 3 }, |
| 3823 | { 0x16, HDA_INPUT, 4 }, |
| 3824 | { } /* end */ |
| 3825 | }; |
| 3826 | #endif |
| 3827 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3828 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 3829 | int offset, int num_steps, int step_size) |
| 3830 | { |
| 3831 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 3832 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 3833 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3834 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3835 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 3836 | } |
| 3837 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3838 | static int patch_vt1708S(struct hda_codec *codec) |
| 3839 | { |
| 3840 | struct via_spec *spec; |
| 3841 | int err; |
| 3842 | |
| 3843 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3844 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3845 | if (spec == NULL) |
| 3846 | return -ENOMEM; |
| 3847 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3848 | /* automatic parse from the BIOS config */ |
| 3849 | err = vt1708S_parse_auto_config(codec); |
| 3850 | if (err < 0) { |
| 3851 | via_free(codec); |
| 3852 | return err; |
| 3853 | } else if (!err) { |
| 3854 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3855 | "from BIOS. Using genenic mode...\n"); |
| 3856 | } |
| 3857 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3858 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3859 | if (codec->vendor_id == 0x11064397) |
| 3860 | spec->init_verbs[spec->num_iverbs++] = |
| 3861 | vt1705_uniwill_init_verbs; |
| 3862 | else |
| 3863 | spec->init_verbs[spec->num_iverbs++] = |
| 3864 | vt1708S_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3865 | |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 3866 | if (codec->vendor_id == 0x11060440) |
| 3867 | spec->stream_name_analog = "VT1818S Analog"; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3868 | else if (codec->vendor_id == 0x11064397) |
| 3869 | spec->stream_name_analog = "VT1705 Analog"; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 3870 | else |
| 3871 | spec->stream_name_analog = "VT1708S Analog"; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3872 | if (codec->vendor_id == 0x11064397) |
| 3873 | spec->stream_analog_playback = &vt1705_pcm_analog_playback; |
| 3874 | else |
| 3875 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3876 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; |
| 3877 | |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 3878 | if (codec->vendor_id == 0x11060440) |
| 3879 | spec->stream_name_digital = "VT1818S Digital"; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3880 | else if (codec->vendor_id == 0x11064397) |
| 3881 | spec->stream_name_digital = "VT1705 Digital"; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 3882 | else |
| 3883 | spec->stream_name_digital = "VT1708S Digital"; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3884 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; |
| 3885 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 3886 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3887 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3888 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3889 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; |
| 3890 | spec->num_mixers++; |
| 3891 | } |
| 3892 | |
| 3893 | codec->patch_ops = via_patch_ops; |
| 3894 | |
| 3895 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3896 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3897 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3898 | spec->loopback.amplist = vt1708S_loopbacks; |
| 3899 | #endif |
| 3900 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3901 | /* correct names for VT1708BCE */ |
| 3902 | if (get_codec_type(codec) == VT1708BCE) { |
| 3903 | kfree(codec->chip_name); |
| 3904 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 3905 | snprintf(codec->bus->card->mixername, |
| 3906 | sizeof(codec->bus->card->mixername), |
| 3907 | "%s %s", codec->vendor_name, codec->chip_name); |
| 3908 | spec->stream_name_analog = "VT1708BCE Analog"; |
| 3909 | spec->stream_name_digital = "VT1708BCE Digital"; |
| 3910 | } |
Lydia Wang | 970f630f | 2011-03-22 16:25:56 +0800 | [diff] [blame] | 3911 | /* correct names for VT1818S */ |
| 3912 | if (codec->vendor_id == 0x11060440) { |
| 3913 | spec->stream_name_analog = "VT1818S Analog"; |
| 3914 | spec->stream_name_digital = "VT1818S Digital"; |
| 3915 | } |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3916 | /* correct names for VT1705 */ |
| 3917 | if (codec->vendor_id == 0x11064397) { |
| 3918 | kfree(codec->chip_name); |
| 3919 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); |
| 3920 | snprintf(codec->bus->card->mixername, |
| 3921 | sizeof(codec->bus->card->mixername), |
| 3922 | "%s %s", codec->vendor_name, codec->chip_name); |
| 3923 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3924 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3925 | return 0; |
| 3926 | } |
| 3927 | |
| 3928 | /* Patch for VT1702 */ |
| 3929 | |
| 3930 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3931 | static const struct snd_kcontrol_new vt1702_capture_mixer[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3932 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), |
| 3933 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), |
| 3934 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), |
| 3935 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), |
| 3936 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), |
| 3937 | HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), |
| 3938 | HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, |
| 3939 | HDA_INPUT), |
| 3940 | { |
| 3941 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3942 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3943 | * So call somewhat different.. |
| 3944 | */ |
| 3945 | /* .name = "Capture Source", */ |
| 3946 | .name = "Input Source", |
| 3947 | .count = 1, |
| 3948 | .info = via_mux_enum_info, |
| 3949 | .get = via_mux_enum_get, |
| 3950 | .put = via_mux_enum_put, |
| 3951 | }, |
| 3952 | { } /* end */ |
| 3953 | }; |
| 3954 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3955 | static const struct hda_verb vt1702_volume_init_verbs[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3956 | /* |
| 3957 | * Unmute ADC0-1 and set the default input to mic-in |
| 3958 | */ |
| 3959 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3960 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3961 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3962 | |
| 3963 | |
| 3964 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3965 | * mixer widget |
| 3966 | */ |
| 3967 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ |
| 3968 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3969 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3970 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3971 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3972 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 3973 | |
| 3974 | /* Setup default input of PW4 to MW0 */ |
| 3975 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 3976 | /* PW6 PW7 Output enable */ |
| 3977 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3978 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3979 | /* mixer enable */ |
| 3980 | {0x1, 0xF88, 0x3}, |
| 3981 | /* GPIO 0~2 */ |
| 3982 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3983 | { } |
| 3984 | }; |
| 3985 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3986 | static const struct hda_verb vt1702_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3987 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3988 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3989 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3990 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3991 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3992 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3993 | { } |
| 3994 | }; |
| 3995 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3996 | static const struct hda_pcm_stream vt1702_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3997 | .substreams = 2, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3998 | .channels_min = 2, |
| 3999 | .channels_max = 2, |
| 4000 | .nid = 0x10, /* NID to query formats and rates */ |
| 4001 | .ops = { |
| 4002 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4003 | .prepare = via_playback_multi_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 4004 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4005 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4006 | }, |
| 4007 | }; |
| 4008 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4009 | static const struct hda_pcm_stream vt1702_pcm_analog_capture = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4010 | .substreams = 3, |
| 4011 | .channels_min = 2, |
| 4012 | .channels_max = 2, |
| 4013 | .nid = 0x12, /* NID to query formats and rates */ |
| 4014 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 4015 | .open = via_pcm_open_close, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4016 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 4017 | .cleanup = via_capture_pcm_cleanup, |
| 4018 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4019 | }, |
| 4020 | }; |
| 4021 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4022 | static const struct hda_pcm_stream vt1702_pcm_digital_playback = { |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 4023 | .substreams = 2, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4024 | .channels_min = 2, |
| 4025 | .channels_max = 2, |
| 4026 | /* NID is set in via_build_pcms */ |
| 4027 | .ops = { |
| 4028 | .open = via_dig_playback_pcm_open, |
| 4029 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4030 | .prepare = via_dig_playback_pcm_prepare, |
| 4031 | .cleanup = via_dig_playback_pcm_cleanup |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4032 | }, |
| 4033 | }; |
| 4034 | |
| 4035 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 4036 | static int vt1702_auto_fill_dac_nids(struct via_spec *spec, |
| 4037 | const struct auto_pin_cfg *cfg) |
| 4038 | { |
| 4039 | spec->multiout.num_dacs = 1; |
| 4040 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 4041 | |
| 4042 | if (cfg->line_out_pins[0]) { |
| 4043 | /* config dac list */ |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4044 | spec->private_dac_nids[0] = 0x10; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | return 0; |
| 4048 | } |
| 4049 | |
| 4050 | /* add playback controls from the parsed DAC table */ |
| 4051 | static int vt1702_auto_create_line_out_ctls(struct via_spec *spec, |
| 4052 | const struct auto_pin_cfg *cfg) |
| 4053 | { |
| 4054 | int err; |
| 4055 | |
| 4056 | if (!cfg->line_out_pins[0]) |
| 4057 | return -1; |
| 4058 | |
| 4059 | /* add control to mixer index 0 */ |
| 4060 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4061 | "Master Front Playback Volume", |
| 4062 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); |
| 4063 | if (err < 0) |
| 4064 | return err; |
| 4065 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4066 | "Master Front Playback Switch", |
| 4067 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); |
| 4068 | if (err < 0) |
| 4069 | return err; |
| 4070 | |
| 4071 | /* Front */ |
| 4072 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4073 | "Front Playback Volume", |
| 4074 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT)); |
| 4075 | if (err < 0) |
| 4076 | return err; |
| 4077 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4078 | "Front Playback Switch", |
| 4079 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT)); |
| 4080 | if (err < 0) |
| 4081 | return err; |
| 4082 | |
| 4083 | return 0; |
| 4084 | } |
| 4085 | |
| 4086 | static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 4087 | { |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4088 | int err, i; |
| 4089 | struct hda_input_mux *imux; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 4090 | static const char * const texts[] = { "ON", "OFF", NULL}; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4091 | if (!pin) |
| 4092 | return 0; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4093 | spec->multiout.hp_nid = 0x1D; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 4094 | spec->hp_independent_mode_index = 0; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4095 | |
| 4096 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4097 | "Headphone Playback Volume", |
| 4098 | HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT)); |
| 4099 | if (err < 0) |
| 4100 | return err; |
| 4101 | |
| 4102 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4103 | "Headphone Playback Switch", |
| 4104 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 4105 | if (err < 0) |
| 4106 | return err; |
| 4107 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4108 | imux = &spec->private_imux[1]; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4109 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4110 | /* for hp mode select */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 4111 | for (i = 0; texts[i]; i++) |
| 4112 | snd_hda_add_imux_item(imux, texts[i], i, NULL); |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4113 | |
| 4114 | spec->hp_mux = &spec->private_imux[1]; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4115 | return 0; |
| 4116 | } |
| 4117 | |
| 4118 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 4119 | static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4120 | const struct auto_pin_cfg *cfg) |
| 4121 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4122 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | static int vt1702_parse_auto_config(struct hda_codec *codec) |
| 4126 | { |
| 4127 | struct via_spec *spec = codec->spec; |
| 4128 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4129 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4130 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4131 | if (err < 0) |
| 4132 | return err; |
| 4133 | err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg); |
| 4134 | if (err < 0) |
| 4135 | return err; |
| 4136 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4137 | return 0; /* can't find valid BIOS pin config */ |
| 4138 | |
| 4139 | err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg); |
| 4140 | if (err < 0) |
| 4141 | return err; |
| 4142 | err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 4143 | if (err < 0) |
| 4144 | return err; |
Lydia Wang | c2c02ea | 2009-10-10 19:07:32 +0800 | [diff] [blame] | 4145 | /* limit AA path volume to 0 dB */ |
| 4146 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 4147 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 4148 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4149 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4150 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 4151 | err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4152 | if (err < 0) |
| 4153 | return err; |
| 4154 | |
| 4155 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4156 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4157 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 4158 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4159 | if (spec->kctls.list) |
| 4160 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4161 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4162 | spec->input_mux = &spec->private_imux[0]; |
| 4163 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 4164 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4165 | via_hp_build(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4166 | |
| 4167 | return 1; |
| 4168 | } |
| 4169 | |
| 4170 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4171 | static const struct hda_amp_list vt1702_loopbacks[] = { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4172 | { 0x1A, HDA_INPUT, 1 }, |
| 4173 | { 0x1A, HDA_INPUT, 2 }, |
| 4174 | { 0x1A, HDA_INPUT, 3 }, |
| 4175 | { 0x1A, HDA_INPUT, 4 }, |
| 4176 | { } /* end */ |
| 4177 | }; |
| 4178 | #endif |
| 4179 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4180 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
| 4181 | { |
| 4182 | int imux_is_smixer = |
| 4183 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 4184 | unsigned int parm; |
| 4185 | /* inputs */ |
| 4186 | /* PW 1/2/5 (14h/15h/18h) */ |
| 4187 | parm = AC_PWRST_D3; |
| 4188 | set_pin_power_state(codec, 0x14, &parm); |
| 4189 | set_pin_power_state(codec, 0x15, &parm); |
| 4190 | set_pin_power_state(codec, 0x18, &parm); |
| 4191 | if (imux_is_smixer) |
| 4192 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ |
| 4193 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
| 4194 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4195 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4196 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4197 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4198 | |
| 4199 | /* outputs */ |
| 4200 | /* PW 3/4 (16h/17h) */ |
| 4201 | parm = AC_PWRST_D3; |
| 4202 | set_pin_power_state(codec, 0x17, &parm); |
| 4203 | set_pin_power_state(codec, 0x16, &parm); |
| 4204 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
| 4205 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 4206 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 4207 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4208 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4209 | } |
| 4210 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4211 | static int patch_vt1702(struct hda_codec *codec) |
| 4212 | { |
| 4213 | struct via_spec *spec; |
| 4214 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4215 | |
| 4216 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4217 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4218 | if (spec == NULL) |
| 4219 | return -ENOMEM; |
| 4220 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4221 | /* automatic parse from the BIOS config */ |
| 4222 | err = vt1702_parse_auto_config(codec); |
| 4223 | if (err < 0) { |
| 4224 | via_free(codec); |
| 4225 | return err; |
| 4226 | } else if (!err) { |
| 4227 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4228 | "from BIOS. Using genenic mode...\n"); |
| 4229 | } |
| 4230 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4231 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
| 4232 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4233 | |
| 4234 | spec->stream_name_analog = "VT1702 Analog"; |
| 4235 | spec->stream_analog_playback = &vt1702_pcm_analog_playback; |
| 4236 | spec->stream_analog_capture = &vt1702_pcm_analog_capture; |
| 4237 | |
| 4238 | spec->stream_name_digital = "VT1702 Digital"; |
| 4239 | spec->stream_digital_playback = &vt1702_pcm_digital_playback; |
| 4240 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4241 | if (spec->adc_nids && spec->input_mux) { |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4242 | spec->mixers[spec->num_mixers] = vt1702_capture_mixer; |
| 4243 | spec->num_mixers++; |
| 4244 | } |
| 4245 | |
| 4246 | codec->patch_ops = via_patch_ops; |
| 4247 | |
| 4248 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4249 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4250 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4251 | spec->loopback.amplist = vt1702_loopbacks; |
| 4252 | #endif |
| 4253 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4254 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4255 | return 0; |
| 4256 | } |
| 4257 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4258 | /* Patch for VT1718S */ |
| 4259 | |
| 4260 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4261 | static const struct snd_kcontrol_new vt1718S_capture_mixer[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4262 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 4263 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 4264 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 4265 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 4266 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 4267 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 4268 | HDA_INPUT), |
| 4269 | { |
| 4270 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4271 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4272 | * So call somewhat different.. |
| 4273 | */ |
| 4274 | .name = "Input Source", |
| 4275 | .count = 2, |
| 4276 | .info = via_mux_enum_info, |
| 4277 | .get = via_mux_enum_get, |
| 4278 | .put = via_mux_enum_put, |
| 4279 | }, |
| 4280 | { } /* end */ |
| 4281 | }; |
| 4282 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4283 | static const struct hda_verb vt1718S_volume_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4284 | /* |
| 4285 | * Unmute ADC0-1 and set the default input to mic-in |
| 4286 | */ |
| 4287 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4288 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4289 | |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 4290 | /* Enable MW0 adjust Gain 5 */ |
| 4291 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4292 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4293 | * mixer widget |
| 4294 | */ |
| 4295 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4296 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4297 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4298 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4299 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 4300 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4301 | |
| 4302 | /* Setup default input of Front HP to MW9 */ |
| 4303 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4304 | /* PW9 PW10 Output enable */ |
| 4305 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4306 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4307 | /* PW11 Input enable */ |
| 4308 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, |
| 4309 | /* Enable Boost Volume backdoor */ |
| 4310 | {0x1, 0xf88, 0x8}, |
| 4311 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ |
| 4312 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4313 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4314 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4315 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4316 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4317 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4318 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4319 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4320 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4321 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4322 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ |
| 4323 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, |
| 4324 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4325 | /* Unmute MW4's index 0 */ |
| 4326 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4327 | { } |
| 4328 | }; |
| 4329 | |
| 4330 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4331 | static const struct hda_verb vt1718S_uniwill_init_verbs[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4332 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4333 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 4334 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4335 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4336 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4337 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4338 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4339 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4340 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4341 | { } |
| 4342 | }; |
| 4343 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4344 | static const struct hda_pcm_stream vt1718S_pcm_analog_playback = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4345 | .substreams = 2, |
| 4346 | .channels_min = 2, |
| 4347 | .channels_max = 10, |
| 4348 | .nid = 0x8, /* NID to query formats and rates */ |
| 4349 | .ops = { |
| 4350 | .open = via_playback_pcm_open, |
| 4351 | .prepare = via_playback_multi_pcm_prepare, |
| 4352 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4353 | .close = via_pcm_open_close, |
| 4354 | }, |
| 4355 | }; |
| 4356 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4357 | static const struct hda_pcm_stream vt1718S_pcm_analog_capture = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4358 | .substreams = 2, |
| 4359 | .channels_min = 2, |
| 4360 | .channels_max = 2, |
| 4361 | .nid = 0x10, /* NID to query formats and rates */ |
| 4362 | .ops = { |
| 4363 | .open = via_pcm_open_close, |
| 4364 | .prepare = via_capture_pcm_prepare, |
| 4365 | .cleanup = via_capture_pcm_cleanup, |
| 4366 | .close = via_pcm_open_close, |
| 4367 | }, |
| 4368 | }; |
| 4369 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4370 | static const struct hda_pcm_stream vt1718S_pcm_digital_playback = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4371 | .substreams = 2, |
| 4372 | .channels_min = 2, |
| 4373 | .channels_max = 2, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4374 | /* NID is set in via_build_pcms */ |
| 4375 | .ops = { |
| 4376 | .open = via_dig_playback_pcm_open, |
| 4377 | .close = via_dig_playback_pcm_close, |
| 4378 | .prepare = via_dig_playback_pcm_prepare, |
| 4379 | .cleanup = via_dig_playback_pcm_cleanup |
| 4380 | }, |
| 4381 | }; |
| 4382 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4383 | static const struct hda_pcm_stream vt1718S_pcm_digital_capture = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4384 | .substreams = 1, |
| 4385 | .channels_min = 2, |
| 4386 | .channels_max = 2, |
| 4387 | }; |
| 4388 | |
| 4389 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 4390 | static int vt1718S_auto_fill_dac_nids(struct via_spec *spec, |
| 4391 | const struct auto_pin_cfg *cfg) |
| 4392 | { |
| 4393 | int i; |
| 4394 | hda_nid_t nid; |
| 4395 | |
| 4396 | spec->multiout.num_dacs = cfg->line_outs; |
| 4397 | |
| 4398 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 4399 | |
| 4400 | for (i = 0; i < 4; i++) { |
| 4401 | nid = cfg->line_out_pins[i]; |
| 4402 | if (nid) { |
| 4403 | /* config dac list */ |
| 4404 | switch (i) { |
| 4405 | case AUTO_SEQ_FRONT: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4406 | spec->private_dac_nids[i] = 0x8; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4407 | break; |
| 4408 | case AUTO_SEQ_CENLFE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4409 | spec->private_dac_nids[i] = 0xa; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4410 | break; |
| 4411 | case AUTO_SEQ_SURROUND: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4412 | spec->private_dac_nids[i] = 0x9; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4413 | break; |
| 4414 | case AUTO_SEQ_SIDE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4415 | spec->private_dac_nids[i] = 0xb; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4416 | break; |
| 4417 | } |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | return 0; |
| 4422 | } |
| 4423 | |
| 4424 | /* add playback controls from the parsed DAC table */ |
| 4425 | static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec, |
| 4426 | const struct auto_pin_cfg *cfg) |
| 4427 | { |
| 4428 | char name[32]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 4429 | static const char * const chname[4] = { |
| 4430 | "Front", "Surround", "C/LFE", "Side" |
| 4431 | }; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4432 | hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb}; |
| 4433 | hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27}; |
| 4434 | hda_nid_t nid, nid_vol, nid_mute = 0; |
| 4435 | int i, err; |
| 4436 | |
| 4437 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 4438 | nid = cfg->line_out_pins[i]; |
| 4439 | |
| 4440 | if (!nid) |
| 4441 | continue; |
| 4442 | nid_vol = nid_vols[i]; |
| 4443 | nid_mute = nid_mutes[i]; |
| 4444 | |
| 4445 | if (i == AUTO_SEQ_CENLFE) { |
| 4446 | /* Center/LFE */ |
| 4447 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4448 | "Center Playback Volume", |
| 4449 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 4450 | HDA_OUTPUT)); |
| 4451 | if (err < 0) |
| 4452 | return err; |
| 4453 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4454 | "LFE Playback Volume", |
| 4455 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 4456 | HDA_OUTPUT)); |
| 4457 | if (err < 0) |
| 4458 | return err; |
| 4459 | err = via_add_control( |
| 4460 | spec, VIA_CTL_WIDGET_MUTE, |
| 4461 | "Center Playback Switch", |
| 4462 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, |
| 4463 | HDA_OUTPUT)); |
| 4464 | if (err < 0) |
| 4465 | return err; |
| 4466 | err = via_add_control( |
| 4467 | spec, VIA_CTL_WIDGET_MUTE, |
| 4468 | "LFE Playback Switch", |
| 4469 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, |
| 4470 | HDA_OUTPUT)); |
| 4471 | if (err < 0) |
| 4472 | return err; |
| 4473 | } else if (i == AUTO_SEQ_FRONT) { |
| 4474 | /* Front */ |
| 4475 | sprintf(name, "%s Playback Volume", chname[i]); |
| 4476 | err = via_add_control( |
| 4477 | spec, VIA_CTL_WIDGET_VOL, name, |
| 4478 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 4479 | if (err < 0) |
| 4480 | return err; |
| 4481 | sprintf(name, "%s Playback Switch", chname[i]); |
| 4482 | err = via_add_control( |
| 4483 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 4484 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 4485 | HDA_OUTPUT)); |
| 4486 | if (err < 0) |
| 4487 | return err; |
| 4488 | } else { |
| 4489 | sprintf(name, "%s Playback Volume", chname[i]); |
| 4490 | err = via_add_control( |
| 4491 | spec, VIA_CTL_WIDGET_VOL, name, |
| 4492 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 4493 | if (err < 0) |
| 4494 | return err; |
| 4495 | sprintf(name, "%s Playback Switch", chname[i]); |
| 4496 | err = via_add_control( |
| 4497 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 4498 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 4499 | HDA_OUTPUT)); |
| 4500 | if (err < 0) |
| 4501 | return err; |
| 4502 | } |
| 4503 | } |
| 4504 | return 0; |
| 4505 | } |
| 4506 | |
| 4507 | static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 4508 | { |
| 4509 | int err; |
| 4510 | |
| 4511 | if (!pin) |
| 4512 | return 0; |
| 4513 | |
| 4514 | spec->multiout.hp_nid = 0xc; /* AOW4 */ |
| 4515 | spec->hp_independent_mode_index = 1; |
| 4516 | |
| 4517 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4518 | "Headphone Playback Volume", |
| 4519 | HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT)); |
| 4520 | if (err < 0) |
| 4521 | return err; |
| 4522 | |
| 4523 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4524 | "Headphone Playback Switch", |
| 4525 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 4526 | if (err < 0) |
| 4527 | return err; |
| 4528 | |
| 4529 | create_hp_imux(spec); |
| 4530 | return 0; |
| 4531 | } |
| 4532 | |
| 4533 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 4534 | static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4535 | const struct auto_pin_cfg *cfg) |
| 4536 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4537 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | static int vt1718S_parse_auto_config(struct hda_codec *codec) |
| 4541 | { |
| 4542 | struct via_spec *spec = codec->spec; |
| 4543 | int err; |
| 4544 | |
| 4545 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4546 | |
| 4547 | if (err < 0) |
| 4548 | return err; |
| 4549 | err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg); |
| 4550 | if (err < 0) |
| 4551 | return err; |
| 4552 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4553 | return 0; /* can't find valid BIOS pin config */ |
| 4554 | |
| 4555 | err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 4556 | if (err < 0) |
| 4557 | return err; |
| 4558 | err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 4559 | if (err < 0) |
| 4560 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 4561 | err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4562 | if (err < 0) |
| 4563 | return err; |
| 4564 | |
| 4565 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4566 | |
| 4567 | fill_dig_outs(codec); |
| 4568 | |
| 4569 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) |
| 4570 | spec->dig_in_nid = 0x13; |
| 4571 | |
| 4572 | if (spec->kctls.list) |
| 4573 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4574 | |
| 4575 | spec->input_mux = &spec->private_imux[0]; |
| 4576 | |
| 4577 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 4578 | via_hp_build(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4579 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4580 | via_smart51_build(spec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4581 | |
| 4582 | return 1; |
| 4583 | } |
| 4584 | |
| 4585 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4586 | static const struct hda_amp_list vt1718S_loopbacks[] = { |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4587 | { 0x21, HDA_INPUT, 1 }, |
| 4588 | { 0x21, HDA_INPUT, 2 }, |
| 4589 | { 0x21, HDA_INPUT, 3 }, |
| 4590 | { 0x21, HDA_INPUT, 4 }, |
| 4591 | { } /* end */ |
| 4592 | }; |
| 4593 | #endif |
| 4594 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4595 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
| 4596 | { |
| 4597 | struct via_spec *spec = codec->spec; |
| 4598 | int imux_is_smixer; |
| 4599 | unsigned int parm; |
| 4600 | /* MUX6 (1eh) = stereo mixer */ |
| 4601 | imux_is_smixer = |
| 4602 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 4603 | /* inputs */ |
| 4604 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 4605 | parm = AC_PWRST_D3; |
| 4606 | set_pin_power_state(codec, 0x29, &parm); |
| 4607 | set_pin_power_state(codec, 0x2a, &parm); |
| 4608 | set_pin_power_state(codec, 0x2b, &parm); |
| 4609 | if (imux_is_smixer) |
| 4610 | parm = AC_PWRST_D0; |
| 4611 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 4612 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4613 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4614 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4615 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4616 | |
| 4617 | /* outputs */ |
| 4618 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 4619 | parm = AC_PWRST_D3; |
| 4620 | set_pin_power_state(codec, 0x27, &parm); |
| 4621 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4622 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4623 | |
| 4624 | /* PW2 (26h), AOW2 (ah) */ |
| 4625 | parm = AC_PWRST_D3; |
| 4626 | set_pin_power_state(codec, 0x26, &parm); |
| 4627 | if (spec->smart51_enabled) |
| 4628 | set_pin_power_state(codec, 0x2b, &parm); |
| 4629 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4630 | |
| 4631 | /* PW0 (24h), AOW0 (8h) */ |
| 4632 | parm = AC_PWRST_D3; |
| 4633 | set_pin_power_state(codec, 0x24, &parm); |
| 4634 | if (!spec->hp_independent_mode) /* check for redirected HP */ |
| 4635 | set_pin_power_state(codec, 0x28, &parm); |
| 4636 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4637 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 4638 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, |
| 4639 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 4640 | |
| 4641 | /* PW1 (25h), AOW1 (9h) */ |
| 4642 | parm = AC_PWRST_D3; |
| 4643 | set_pin_power_state(codec, 0x25, &parm); |
| 4644 | if (spec->smart51_enabled) |
| 4645 | set_pin_power_state(codec, 0x2a, &parm); |
| 4646 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); |
| 4647 | |
| 4648 | if (spec->hp_independent_mode) { |
| 4649 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 4650 | parm = AC_PWRST_D3; |
| 4651 | set_pin_power_state(codec, 0x28, &parm); |
| 4652 | snd_hda_codec_write(codec, 0x1b, 0, |
| 4653 | AC_VERB_SET_POWER_STATE, parm); |
| 4654 | snd_hda_codec_write(codec, 0x34, 0, |
| 4655 | AC_VERB_SET_POWER_STATE, parm); |
| 4656 | snd_hda_codec_write(codec, 0xc, 0, |
| 4657 | AC_VERB_SET_POWER_STATE, parm); |
| 4658 | } |
| 4659 | } |
| 4660 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4661 | static int patch_vt1718S(struct hda_codec *codec) |
| 4662 | { |
| 4663 | struct via_spec *spec; |
| 4664 | int err; |
| 4665 | |
| 4666 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4667 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4668 | if (spec == NULL) |
| 4669 | return -ENOMEM; |
| 4670 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4671 | /* automatic parse from the BIOS config */ |
| 4672 | err = vt1718S_parse_auto_config(codec); |
| 4673 | if (err < 0) { |
| 4674 | via_free(codec); |
| 4675 | return err; |
| 4676 | } else if (!err) { |
| 4677 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4678 | "from BIOS. Using genenic mode...\n"); |
| 4679 | } |
| 4680 | |
| 4681 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; |
| 4682 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; |
| 4683 | |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4684 | if (codec->vendor_id == 0x11060441) |
| 4685 | spec->stream_name_analog = "VT2020 Analog"; |
| 4686 | else if (codec->vendor_id == 0x11064441) |
| 4687 | spec->stream_name_analog = "VT1828S Analog"; |
| 4688 | else |
| 4689 | spec->stream_name_analog = "VT1718S Analog"; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4690 | spec->stream_analog_playback = &vt1718S_pcm_analog_playback; |
| 4691 | spec->stream_analog_capture = &vt1718S_pcm_analog_capture; |
| 4692 | |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4693 | if (codec->vendor_id == 0x11060441) |
| 4694 | spec->stream_name_digital = "VT2020 Digital"; |
| 4695 | else if (codec->vendor_id == 0x11064441) |
| 4696 | spec->stream_name_digital = "VT1828S Digital"; |
| 4697 | else |
| 4698 | spec->stream_name_digital = "VT1718S Digital"; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4699 | spec->stream_digital_playback = &vt1718S_pcm_digital_playback; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4700 | if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4701 | spec->stream_digital_capture = &vt1718S_pcm_digital_capture; |
| 4702 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 4703 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4704 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 4705 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4706 | spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; |
| 4707 | spec->num_mixers++; |
| 4708 | } |
| 4709 | |
| 4710 | codec->patch_ops = via_patch_ops; |
| 4711 | |
| 4712 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 4713 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4714 | |
| 4715 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4716 | spec->loopback.amplist = vt1718S_loopbacks; |
| 4717 | #endif |
| 4718 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4719 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
| 4720 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4721 | return 0; |
| 4722 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4723 | |
| 4724 | /* Patch for VT1716S */ |
| 4725 | |
| 4726 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 4727 | struct snd_ctl_elem_info *uinfo) |
| 4728 | { |
| 4729 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 4730 | uinfo->count = 1; |
| 4731 | uinfo->value.integer.min = 0; |
| 4732 | uinfo->value.integer.max = 1; |
| 4733 | return 0; |
| 4734 | } |
| 4735 | |
| 4736 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 4737 | struct snd_ctl_elem_value *ucontrol) |
| 4738 | { |
| 4739 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 4740 | int index = 0; |
| 4741 | |
| 4742 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 4743 | AC_VERB_GET_CONNECT_SEL, 0); |
| 4744 | if (index != -1) |
| 4745 | *ucontrol->value.integer.value = index; |
| 4746 | |
| 4747 | return 0; |
| 4748 | } |
| 4749 | |
| 4750 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 4751 | struct snd_ctl_elem_value *ucontrol) |
| 4752 | { |
| 4753 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 4754 | struct via_spec *spec = codec->spec; |
| 4755 | int index = *ucontrol->value.integer.value; |
| 4756 | |
| 4757 | snd_hda_codec_write(codec, 0x26, 0, |
| 4758 | AC_VERB_SET_CONNECT_SEL, index); |
| 4759 | spec->dmic_enabled = index; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 4760 | set_widgets_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4761 | return 1; |
| 4762 | } |
| 4763 | |
| 4764 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4765 | static const struct snd_kcontrol_new vt1716S_capture_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4766 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 4767 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 4768 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 4769 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 4770 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 4771 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 4772 | HDA_INPUT), |
| 4773 | { |
| 4774 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4775 | .name = "Input Source", |
| 4776 | .count = 1, |
| 4777 | .info = via_mux_enum_info, |
| 4778 | .get = via_mux_enum_get, |
| 4779 | .put = via_mux_enum_put, |
| 4780 | }, |
| 4781 | { } /* end */ |
| 4782 | }; |
| 4783 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4784 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4785 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 4786 | { |
| 4787 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4788 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 4789 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4790 | .count = 1, |
| 4791 | .info = vt1716s_dmic_info, |
| 4792 | .get = vt1716s_dmic_get, |
| 4793 | .put = vt1716s_dmic_put, |
| 4794 | }, |
| 4795 | {} /* end */ |
| 4796 | }; |
| 4797 | |
| 4798 | |
| 4799 | /* mono-out mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4800 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4801 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 4802 | { } /* end */ |
| 4803 | }; |
| 4804 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4805 | static const struct hda_verb vt1716S_volume_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4806 | /* |
| 4807 | * Unmute ADC0-1 and set the default input to mic-in |
| 4808 | */ |
| 4809 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4810 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4811 | |
| 4812 | |
| 4813 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4814 | * mixer widget |
| 4815 | */ |
| 4816 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4817 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4818 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4819 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4820 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4821 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4822 | |
| 4823 | /* MUX Indices: Stereo Mixer = 5 */ |
| 4824 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, |
| 4825 | |
| 4826 | /* Setup default input of PW4 to MW0 */ |
| 4827 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 4828 | |
| 4829 | /* Setup default input of SW1 as MW0 */ |
| 4830 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4831 | |
| 4832 | /* Setup default input of SW4 as AOW0 */ |
| 4833 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4834 | |
| 4835 | /* PW9 PW10 Output enable */ |
| 4836 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4837 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4838 | |
| 4839 | /* Unmute SW1, PW12 */ |
| 4840 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4841 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 4842 | /* PW12 Output enable */ |
| 4843 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4844 | /* Enable Boost Volume backdoor */ |
| 4845 | {0x1, 0xf8a, 0x80}, |
| 4846 | /* don't bybass mixer */ |
| 4847 | {0x1, 0xf88, 0xc0}, |
| 4848 | /* Enable mono output */ |
| 4849 | {0x1, 0xf90, 0x08}, |
| 4850 | { } |
| 4851 | }; |
| 4852 | |
| 4853 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4854 | static const struct hda_verb vt1716S_uniwill_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4855 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4856 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 4857 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4858 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4859 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4860 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4861 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, |
| 4862 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4863 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4864 | { } |
| 4865 | }; |
| 4866 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4867 | static const struct hda_pcm_stream vt1716S_pcm_analog_playback = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4868 | .substreams = 2, |
| 4869 | .channels_min = 2, |
| 4870 | .channels_max = 6, |
| 4871 | .nid = 0x10, /* NID to query formats and rates */ |
| 4872 | .ops = { |
| 4873 | .open = via_playback_pcm_open, |
| 4874 | .prepare = via_playback_multi_pcm_prepare, |
| 4875 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4876 | .close = via_pcm_open_close, |
| 4877 | }, |
| 4878 | }; |
| 4879 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4880 | static const struct hda_pcm_stream vt1716S_pcm_analog_capture = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4881 | .substreams = 2, |
| 4882 | .channels_min = 2, |
| 4883 | .channels_max = 2, |
| 4884 | .nid = 0x13, /* NID to query formats and rates */ |
| 4885 | .ops = { |
| 4886 | .open = via_pcm_open_close, |
| 4887 | .prepare = via_capture_pcm_prepare, |
| 4888 | .cleanup = via_capture_pcm_cleanup, |
| 4889 | .close = via_pcm_open_close, |
| 4890 | }, |
| 4891 | }; |
| 4892 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 4893 | static const struct hda_pcm_stream vt1716S_pcm_digital_playback = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4894 | .substreams = 2, |
| 4895 | .channels_min = 2, |
| 4896 | .channels_max = 2, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4897 | /* NID is set in via_build_pcms */ |
| 4898 | .ops = { |
| 4899 | .open = via_dig_playback_pcm_open, |
| 4900 | .close = via_dig_playback_pcm_close, |
| 4901 | .prepare = via_dig_playback_pcm_prepare, |
| 4902 | .cleanup = via_dig_playback_pcm_cleanup |
| 4903 | }, |
| 4904 | }; |
| 4905 | |
| 4906 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 4907 | static int vt1716S_auto_fill_dac_nids(struct via_spec *spec, |
| 4908 | const struct auto_pin_cfg *cfg) |
| 4909 | { int i; |
| 4910 | hda_nid_t nid; |
| 4911 | |
| 4912 | spec->multiout.num_dacs = cfg->line_outs; |
| 4913 | |
| 4914 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 4915 | |
| 4916 | for (i = 0; i < 3; i++) { |
| 4917 | nid = cfg->line_out_pins[i]; |
| 4918 | if (nid) { |
| 4919 | /* config dac list */ |
| 4920 | switch (i) { |
| 4921 | case AUTO_SEQ_FRONT: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4922 | spec->private_dac_nids[i] = 0x10; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4923 | break; |
| 4924 | case AUTO_SEQ_CENLFE: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4925 | spec->private_dac_nids[i] = 0x25; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4926 | break; |
| 4927 | case AUTO_SEQ_SURROUND: |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 4928 | spec->private_dac_nids[i] = 0x11; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4929 | break; |
| 4930 | } |
| 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | return 0; |
| 4935 | } |
| 4936 | |
| 4937 | /* add playback controls from the parsed DAC table */ |
| 4938 | static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec, |
| 4939 | const struct auto_pin_cfg *cfg) |
| 4940 | { |
| 4941 | char name[32]; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 4942 | static const char * const chname[3] = { |
| 4943 | "Front", "Surround", "C/LFE" |
| 4944 | }; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4945 | hda_nid_t nid_vols[] = {0x10, 0x11, 0x25}; |
| 4946 | hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27}; |
| 4947 | hda_nid_t nid, nid_vol, nid_mute; |
| 4948 | int i, err; |
| 4949 | |
| 4950 | for (i = 0; i <= AUTO_SEQ_CENLFE; i++) { |
| 4951 | nid = cfg->line_out_pins[i]; |
| 4952 | |
| 4953 | if (!nid) |
| 4954 | continue; |
| 4955 | |
| 4956 | nid_vol = nid_vols[i]; |
| 4957 | nid_mute = nid_mutes[i]; |
| 4958 | |
| 4959 | if (i == AUTO_SEQ_CENLFE) { |
| 4960 | err = via_add_control( |
| 4961 | spec, VIA_CTL_WIDGET_VOL, |
| 4962 | "Center Playback Volume", |
| 4963 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT)); |
| 4964 | if (err < 0) |
| 4965 | return err; |
| 4966 | err = via_add_control( |
| 4967 | spec, VIA_CTL_WIDGET_VOL, |
| 4968 | "LFE Playback Volume", |
| 4969 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT)); |
| 4970 | if (err < 0) |
| 4971 | return err; |
| 4972 | err = via_add_control( |
| 4973 | spec, VIA_CTL_WIDGET_MUTE, |
| 4974 | "Center Playback Switch", |
| 4975 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, |
| 4976 | HDA_OUTPUT)); |
| 4977 | if (err < 0) |
| 4978 | return err; |
| 4979 | err = via_add_control( |
| 4980 | spec, VIA_CTL_WIDGET_MUTE, |
| 4981 | "LFE Playback Switch", |
| 4982 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, |
| 4983 | HDA_OUTPUT)); |
| 4984 | if (err < 0) |
| 4985 | return err; |
| 4986 | } else if (i == AUTO_SEQ_FRONT) { |
| 4987 | |
| 4988 | err = via_add_control( |
| 4989 | spec, VIA_CTL_WIDGET_VOL, |
| 4990 | "Master Front Playback Volume", |
| 4991 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); |
| 4992 | if (err < 0) |
| 4993 | return err; |
| 4994 | err = via_add_control( |
| 4995 | spec, VIA_CTL_WIDGET_MUTE, |
| 4996 | "Master Front Playback Switch", |
| 4997 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); |
| 4998 | if (err < 0) |
| 4999 | return err; |
| 5000 | |
| 5001 | sprintf(name, "%s Playback Volume", chname[i]); |
| 5002 | err = via_add_control( |
| 5003 | spec, VIA_CTL_WIDGET_VOL, name, |
| 5004 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 5005 | if (err < 0) |
| 5006 | return err; |
| 5007 | sprintf(name, "%s Playback Switch", chname[i]); |
| 5008 | err = via_add_control( |
| 5009 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 5010 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 5011 | HDA_OUTPUT)); |
| 5012 | if (err < 0) |
| 5013 | return err; |
| 5014 | } else { |
| 5015 | sprintf(name, "%s Playback Volume", chname[i]); |
| 5016 | err = via_add_control( |
| 5017 | spec, VIA_CTL_WIDGET_VOL, name, |
| 5018 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 5019 | if (err < 0) |
| 5020 | return err; |
| 5021 | sprintf(name, "%s Playback Switch", chname[i]); |
| 5022 | err = via_add_control( |
| 5023 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 5024 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 5025 | HDA_OUTPUT)); |
| 5026 | if (err < 0) |
| 5027 | return err; |
| 5028 | } |
| 5029 | } |
| 5030 | return 0; |
| 5031 | } |
| 5032 | |
| 5033 | static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 5034 | { |
| 5035 | int err; |
| 5036 | |
| 5037 | if (!pin) |
| 5038 | return 0; |
| 5039 | |
| 5040 | spec->multiout.hp_nid = 0x25; /* AOW3 */ |
| 5041 | spec->hp_independent_mode_index = 1; |
| 5042 | |
| 5043 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5044 | "Headphone Playback Volume", |
| 5045 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); |
| 5046 | if (err < 0) |
| 5047 | return err; |
| 5048 | |
| 5049 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 5050 | "Headphone Playback Switch", |
| 5051 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 5052 | if (err < 0) |
| 5053 | return err; |
| 5054 | |
| 5055 | create_hp_imux(spec); |
| 5056 | return 0; |
| 5057 | } |
| 5058 | |
| 5059 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5060 | static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5061 | const struct auto_pin_cfg *cfg) |
| 5062 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 5063 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | static int vt1716S_parse_auto_config(struct hda_codec *codec) |
| 5067 | { |
| 5068 | struct via_spec *spec = codec->spec; |
| 5069 | int err; |
| 5070 | |
| 5071 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 5072 | if (err < 0) |
| 5073 | return err; |
| 5074 | err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg); |
| 5075 | if (err < 0) |
| 5076 | return err; |
| 5077 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 5078 | return 0; /* can't find valid BIOS pin config */ |
| 5079 | |
| 5080 | err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 5081 | if (err < 0) |
| 5082 | return err; |
| 5083 | err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 5084 | if (err < 0) |
| 5085 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5086 | err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5087 | if (err < 0) |
| 5088 | return err; |
| 5089 | |
| 5090 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 5091 | |
| 5092 | fill_dig_outs(codec); |
| 5093 | |
| 5094 | if (spec->kctls.list) |
| 5095 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 5096 | |
| 5097 | spec->input_mux = &spec->private_imux[0]; |
| 5098 | |
| 5099 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 5100 | via_hp_build(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5101 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 5102 | via_smart51_build(spec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5103 | |
| 5104 | return 1; |
| 5105 | } |
| 5106 | |
| 5107 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5108 | static const struct hda_amp_list vt1716S_loopbacks[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5109 | { 0x16, HDA_INPUT, 1 }, |
| 5110 | { 0x16, HDA_INPUT, 2 }, |
| 5111 | { 0x16, HDA_INPUT, 3 }, |
| 5112 | { 0x16, HDA_INPUT, 4 }, |
| 5113 | { } /* end */ |
| 5114 | }; |
| 5115 | #endif |
| 5116 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5117 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
| 5118 | { |
| 5119 | struct via_spec *spec = codec->spec; |
| 5120 | int imux_is_smixer; |
| 5121 | unsigned int parm; |
| 5122 | unsigned int mono_out, present; |
| 5123 | /* SW0 (17h) = stereo mixer */ |
| 5124 | imux_is_smixer = |
| 5125 | (snd_hda_codec_read(codec, 0x17, 0, |
| 5126 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); |
| 5127 | /* inputs */ |
| 5128 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 5129 | parm = AC_PWRST_D3; |
| 5130 | set_pin_power_state(codec, 0x1a, &parm); |
| 5131 | set_pin_power_state(codec, 0x1b, &parm); |
| 5132 | set_pin_power_state(codec, 0x1e, &parm); |
| 5133 | if (imux_is_smixer) |
| 5134 | parm = AC_PWRST_D0; |
| 5135 | /* SW0 (17h), AIW0(13h) */ |
| 5136 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5137 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5138 | |
| 5139 | parm = AC_PWRST_D3; |
| 5140 | set_pin_power_state(codec, 0x1e, &parm); |
| 5141 | /* PW11 (22h) */ |
| 5142 | if (spec->dmic_enabled) |
| 5143 | set_pin_power_state(codec, 0x22, &parm); |
| 5144 | else |
| 5145 | snd_hda_codec_write(codec, 0x22, 0, |
| 5146 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 5147 | |
| 5148 | /* SW2(26h), AIW1(14h) */ |
| 5149 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5150 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5151 | |
| 5152 | /* outputs */ |
| 5153 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 5154 | parm = AC_PWRST_D3; |
| 5155 | set_pin_power_state(codec, 0x19, &parm); |
| 5156 | /* Smart 5.1 PW2(1bh) */ |
| 5157 | if (spec->smart51_enabled) |
| 5158 | set_pin_power_state(codec, 0x1b, &parm); |
| 5159 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5160 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5161 | |
| 5162 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 5163 | parm = AC_PWRST_D3; |
| 5164 | set_pin_power_state(codec, 0x23, &parm); |
| 5165 | /* Smart 5.1 PW1(1ah) */ |
| 5166 | if (spec->smart51_enabled) |
| 5167 | set_pin_power_state(codec, 0x1a, &parm); |
| 5168 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5169 | |
| 5170 | /* Smart 5.1 PW5(1eh) */ |
| 5171 | if (spec->smart51_enabled) |
| 5172 | set_pin_power_state(codec, 0x1e, &parm); |
| 5173 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5174 | |
| 5175 | /* Mono out */ |
| 5176 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 5177 | present = snd_hda_jack_detect(codec, 0x1c); |
| 5178 | |
| 5179 | if (present) |
| 5180 | mono_out = 0; |
| 5181 | else { |
| 5182 | present = snd_hda_jack_detect(codec, 0x1d); |
| 5183 | if (!spec->hp_independent_mode && present) |
| 5184 | mono_out = 0; |
| 5185 | else |
| 5186 | mono_out = 1; |
| 5187 | } |
| 5188 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
| 5189 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5190 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5191 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5192 | |
| 5193 | /* PW 3/4 (1ch/1dh) */ |
| 5194 | parm = AC_PWRST_D3; |
| 5195 | set_pin_power_state(codec, 0x1c, &parm); |
| 5196 | set_pin_power_state(codec, 0x1d, &parm); |
| 5197 | /* HP Independent Mode, power on AOW3 */ |
| 5198 | if (spec->hp_independent_mode) |
| 5199 | snd_hda_codec_write(codec, 0x25, 0, |
| 5200 | AC_VERB_SET_POWER_STATE, parm); |
| 5201 | |
| 5202 | /* force to D0 for internal Speaker */ |
| 5203 | /* MW0 (16h), AOW0 (10h) */ |
| 5204 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 5205 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 5206 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 5207 | mono_out ? AC_PWRST_D0 : parm); |
| 5208 | } |
| 5209 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5210 | static int patch_vt1716S(struct hda_codec *codec) |
| 5211 | { |
| 5212 | struct via_spec *spec; |
| 5213 | int err; |
| 5214 | |
| 5215 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 5216 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5217 | if (spec == NULL) |
| 5218 | return -ENOMEM; |
| 5219 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5220 | /* automatic parse from the BIOS config */ |
| 5221 | err = vt1716S_parse_auto_config(codec); |
| 5222 | if (err < 0) { |
| 5223 | via_free(codec); |
| 5224 | return err; |
| 5225 | } else if (!err) { |
| 5226 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 5227 | "from BIOS. Using genenic mode...\n"); |
| 5228 | } |
| 5229 | |
| 5230 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; |
| 5231 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; |
| 5232 | |
| 5233 | spec->stream_name_analog = "VT1716S Analog"; |
| 5234 | spec->stream_analog_playback = &vt1716S_pcm_analog_playback; |
| 5235 | spec->stream_analog_capture = &vt1716S_pcm_analog_capture; |
| 5236 | |
| 5237 | spec->stream_name_digital = "VT1716S Digital"; |
| 5238 | spec->stream_digital_playback = &vt1716S_pcm_digital_playback; |
| 5239 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 5240 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5241 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 5242 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
| 5243 | spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; |
| 5244 | spec->num_mixers++; |
| 5245 | } |
| 5246 | |
| 5247 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
| 5248 | spec->num_mixers++; |
| 5249 | |
| 5250 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 5251 | |
| 5252 | codec->patch_ops = via_patch_ops; |
| 5253 | |
| 5254 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 5255 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5256 | |
| 5257 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5258 | spec->loopback.amplist = vt1716S_loopbacks; |
| 5259 | #endif |
| 5260 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5261 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5262 | return 0; |
| 5263 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5264 | |
| 5265 | /* for vt2002P */ |
| 5266 | |
| 5267 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5268 | static const struct snd_kcontrol_new vt2002P_capture_mixer[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5269 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 5270 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 5271 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 5272 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 5273 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 5274 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 5275 | HDA_INPUT), |
| 5276 | { |
| 5277 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 5278 | /* The multiple "Capture Source" controls confuse alsamixer |
| 5279 | * So call somewhat different.. |
| 5280 | */ |
| 5281 | /* .name = "Capture Source", */ |
| 5282 | .name = "Input Source", |
| 5283 | .count = 2, |
| 5284 | .info = via_mux_enum_info, |
| 5285 | .get = via_mux_enum_get, |
| 5286 | .put = via_mux_enum_put, |
| 5287 | }, |
| 5288 | { } /* end */ |
| 5289 | }; |
| 5290 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5291 | static const struct hda_verb vt2002P_volume_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 5292 | /* Class-D speaker related verbs */ |
| 5293 | {0x1, 0xfe0, 0x4}, |
| 5294 | {0x1, 0xfe9, 0x80}, |
| 5295 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5296 | /* |
| 5297 | * Unmute ADC0-1 and set the default input to mic-in |
| 5298 | */ |
| 5299 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5300 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5301 | |
| 5302 | |
| 5303 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 5304 | * mixer widget |
| 5305 | */ |
| 5306 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 5307 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 5308 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5309 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 5310 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 5311 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 5312 | |
| 5313 | /* MUX Indices: Mic = 0 */ |
| 5314 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5315 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5316 | |
| 5317 | /* PW9 Output enable */ |
| 5318 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 5319 | |
| 5320 | /* Enable Boost Volume backdoor */ |
| 5321 | {0x1, 0xfb9, 0x24}, |
| 5322 | |
| 5323 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 5324 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5325 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5326 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5327 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5328 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5329 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5330 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5331 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5332 | |
| 5333 | /* set MUX0/1/4/8 = 0 (AOW0) */ |
| 5334 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5335 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5336 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5337 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5338 | |
| 5339 | /* set PW0 index=0 (MW0) */ |
| 5340 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5341 | |
| 5342 | /* Enable AOW0 to MW9 */ |
| 5343 | {0x1, 0xfb8, 0x88}, |
| 5344 | { } |
| 5345 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5346 | static const struct hda_verb vt1802_volume_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5347 | /* |
| 5348 | * Unmute ADC0-1 and set the default input to mic-in |
| 5349 | */ |
| 5350 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5351 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5352 | |
| 5353 | |
| 5354 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 5355 | * mixer widget |
| 5356 | */ |
| 5357 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 5358 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 5359 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5360 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 5361 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 5362 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 5363 | |
| 5364 | /* MUX Indices: Mic = 0 */ |
| 5365 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5366 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5367 | |
| 5368 | /* PW9 Output enable */ |
| 5369 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 5370 | |
| 5371 | /* Enable Boost Volume backdoor */ |
| 5372 | {0x1, 0xfb9, 0x24}, |
| 5373 | |
| 5374 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 5375 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5376 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5377 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5378 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5379 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5380 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5381 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5382 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5383 | |
| 5384 | /* set MUX0/1/4/8 = 0 (AOW0) */ |
| 5385 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5386 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5387 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5388 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5389 | |
| 5390 | /* set PW0 index=0 (MW0) */ |
| 5391 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5392 | |
| 5393 | /* Enable AOW0 to MW9 */ |
| 5394 | {0x1, 0xfb8, 0x88}, |
| 5395 | { } |
| 5396 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5397 | |
| 5398 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5399 | static const struct hda_verb vt2002P_uniwill_init_verbs[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5400 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5401 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5402 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5403 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5404 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5405 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5406 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5407 | { } |
| 5408 | }; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5409 | static const struct hda_verb vt1802_uniwill_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5410 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5411 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5412 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5413 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5414 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5415 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5416 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5417 | { } |
| 5418 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5419 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5420 | static const struct hda_pcm_stream vt2002P_pcm_analog_playback = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5421 | .substreams = 2, |
| 5422 | .channels_min = 2, |
| 5423 | .channels_max = 2, |
| 5424 | .nid = 0x8, /* NID to query formats and rates */ |
| 5425 | .ops = { |
| 5426 | .open = via_playback_pcm_open, |
| 5427 | .prepare = via_playback_multi_pcm_prepare, |
| 5428 | .cleanup = via_playback_multi_pcm_cleanup, |
| 5429 | .close = via_pcm_open_close, |
| 5430 | }, |
| 5431 | }; |
| 5432 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5433 | static const struct hda_pcm_stream vt2002P_pcm_analog_capture = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5434 | .substreams = 2, |
| 5435 | .channels_min = 2, |
| 5436 | .channels_max = 2, |
| 5437 | .nid = 0x10, /* NID to query formats and rates */ |
| 5438 | .ops = { |
| 5439 | .open = via_pcm_open_close, |
| 5440 | .prepare = via_capture_pcm_prepare, |
| 5441 | .cleanup = via_capture_pcm_cleanup, |
| 5442 | .close = via_pcm_open_close, |
| 5443 | }, |
| 5444 | }; |
| 5445 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5446 | static const struct hda_pcm_stream vt2002P_pcm_digital_playback = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5447 | .substreams = 1, |
| 5448 | .channels_min = 2, |
| 5449 | .channels_max = 2, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5450 | /* NID is set in via_build_pcms */ |
| 5451 | .ops = { |
| 5452 | .open = via_dig_playback_pcm_open, |
| 5453 | .close = via_dig_playback_pcm_close, |
| 5454 | .prepare = via_dig_playback_pcm_prepare, |
| 5455 | .cleanup = via_dig_playback_pcm_cleanup |
| 5456 | }, |
| 5457 | }; |
| 5458 | |
| 5459 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 5460 | static int vt2002P_auto_fill_dac_nids(struct via_spec *spec, |
| 5461 | const struct auto_pin_cfg *cfg) |
| 5462 | { |
| 5463 | spec->multiout.num_dacs = 1; |
| 5464 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 5465 | if (cfg->line_out_pins[0]) |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 5466 | spec->private_dac_nids[0] = 0x8; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5467 | return 0; |
| 5468 | } |
| 5469 | |
| 5470 | /* add playback controls from the parsed DAC table */ |
| 5471 | static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec, |
| 5472 | const struct auto_pin_cfg *cfg) |
| 5473 | { |
| 5474 | int err; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5475 | hda_nid_t sw_nid; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5476 | |
| 5477 | if (!cfg->line_out_pins[0]) |
| 5478 | return -1; |
| 5479 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5480 | if (spec->codec_type == VT1802) |
| 5481 | sw_nid = 0x28; |
| 5482 | else |
| 5483 | sw_nid = 0x26; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5484 | |
| 5485 | /* Line-Out: PortE */ |
| 5486 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5487 | "Master Front Playback Volume", |
| 5488 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); |
| 5489 | if (err < 0) |
| 5490 | return err; |
| 5491 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, |
| 5492 | "Master Front Playback Switch", |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5493 | HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT)); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5494 | if (err < 0) |
| 5495 | return err; |
| 5496 | |
| 5497 | return 0; |
| 5498 | } |
| 5499 | |
| 5500 | static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 5501 | { |
| 5502 | int err; |
| 5503 | |
| 5504 | if (!pin) |
| 5505 | return 0; |
| 5506 | |
| 5507 | spec->multiout.hp_nid = 0x9; |
| 5508 | spec->hp_independent_mode_index = 1; |
| 5509 | |
| 5510 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5511 | "Headphone Playback Volume", |
| 5512 | HDA_COMPOSE_AMP_VAL( |
| 5513 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); |
| 5514 | if (err < 0) |
| 5515 | return err; |
| 5516 | |
| 5517 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 5518 | "Headphone Playback Switch", |
| 5519 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); |
| 5520 | if (err < 0) |
| 5521 | return err; |
| 5522 | |
| 5523 | create_hp_imux(spec); |
| 5524 | return 0; |
| 5525 | } |
| 5526 | |
| 5527 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5528 | static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5529 | const struct auto_pin_cfg *cfg) |
| 5530 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 5531 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | static int vt2002P_parse_auto_config(struct hda_codec *codec) |
| 5535 | { |
| 5536 | struct via_spec *spec = codec->spec; |
| 5537 | int err; |
| 5538 | |
| 5539 | |
| 5540 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 5541 | if (err < 0) |
| 5542 | return err; |
| 5543 | |
| 5544 | err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg); |
| 5545 | if (err < 0) |
| 5546 | return err; |
| 5547 | |
| 5548 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 5549 | return 0; /* can't find valid BIOS pin config */ |
| 5550 | |
| 5551 | err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 5552 | if (err < 0) |
| 5553 | return err; |
| 5554 | err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 5555 | if (err < 0) |
| 5556 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5557 | err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5558 | if (err < 0) |
| 5559 | return err; |
| 5560 | |
| 5561 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 5562 | |
| 5563 | fill_dig_outs(codec); |
| 5564 | |
| 5565 | if (spec->kctls.list) |
| 5566 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 5567 | |
| 5568 | spec->input_mux = &spec->private_imux[0]; |
| 5569 | |
| 5570 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 5571 | via_hp_build(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5572 | |
| 5573 | return 1; |
| 5574 | } |
| 5575 | |
| 5576 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5577 | static const struct hda_amp_list vt2002P_loopbacks[] = { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5578 | { 0x21, HDA_INPUT, 0 }, |
| 5579 | { 0x21, HDA_INPUT, 1 }, |
| 5580 | { 0x21, HDA_INPUT, 2 }, |
| 5581 | { } /* end */ |
| 5582 | }; |
| 5583 | #endif |
| 5584 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5585 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
| 5586 | { |
| 5587 | struct via_spec *spec = codec->spec; |
| 5588 | int imux_is_smixer; |
| 5589 | unsigned int parm; |
| 5590 | unsigned int present; |
| 5591 | /* MUX9 (1eh) = stereo mixer */ |
| 5592 | imux_is_smixer = |
| 5593 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 5594 | /* inputs */ |
| 5595 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 5596 | parm = AC_PWRST_D3; |
| 5597 | set_pin_power_state(codec, 0x29, &parm); |
| 5598 | set_pin_power_state(codec, 0x2a, &parm); |
| 5599 | set_pin_power_state(codec, 0x2b, &parm); |
| 5600 | parm = AC_PWRST_D0; |
| 5601 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 5602 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5603 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5604 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5605 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5606 | |
| 5607 | /* outputs */ |
| 5608 | /* AOW0 (8h)*/ |
| 5609 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5610 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5611 | if (spec->codec_type == VT1802) { |
| 5612 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 5613 | parm = AC_PWRST_D3; |
| 5614 | set_pin_power_state(codec, 0x28, &parm); |
| 5615 | snd_hda_codec_write(codec, 0x18, 0, |
| 5616 | AC_VERB_SET_POWER_STATE, parm); |
| 5617 | snd_hda_codec_write(codec, 0x38, 0, |
| 5618 | AC_VERB_SET_POWER_STATE, parm); |
| 5619 | } else { |
| 5620 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 5621 | parm = AC_PWRST_D3; |
| 5622 | set_pin_power_state(codec, 0x26, &parm); |
| 5623 | snd_hda_codec_write(codec, 0x1c, 0, |
| 5624 | AC_VERB_SET_POWER_STATE, parm); |
| 5625 | snd_hda_codec_write(codec, 0x37, 0, |
| 5626 | AC_VERB_SET_POWER_STATE, parm); |
| 5627 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5628 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5629 | if (spec->codec_type == VT1802) { |
| 5630 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 5631 | parm = AC_PWRST_D3; |
| 5632 | set_pin_power_state(codec, 0x25, &parm); |
| 5633 | snd_hda_codec_write(codec, 0x15, 0, |
| 5634 | AC_VERB_SET_POWER_STATE, parm); |
| 5635 | snd_hda_codec_write(codec, 0x35, 0, |
| 5636 | AC_VERB_SET_POWER_STATE, parm); |
| 5637 | } else { |
| 5638 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 5639 | parm = AC_PWRST_D3; |
| 5640 | set_pin_power_state(codec, 0x25, &parm); |
| 5641 | snd_hda_codec_write(codec, 0x19, 0, |
| 5642 | AC_VERB_SET_POWER_STATE, parm); |
| 5643 | snd_hda_codec_write(codec, 0x35, 0, |
| 5644 | AC_VERB_SET_POWER_STATE, parm); |
| 5645 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5646 | |
| 5647 | if (spec->hp_independent_mode) |
| 5648 | snd_hda_codec_write(codec, 0x9, 0, |
| 5649 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 5650 | |
| 5651 | /* Class-D */ |
| 5652 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ |
| 5653 | present = snd_hda_jack_detect(codec, 0x25); |
| 5654 | |
| 5655 | parm = AC_PWRST_D3; |
| 5656 | set_pin_power_state(codec, 0x24, &parm); |
| 5657 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5658 | if (spec->codec_type == VT1802) |
| 5659 | snd_hda_codec_write(codec, 0x14, 0, |
| 5660 | AC_VERB_SET_POWER_STATE, parm); |
| 5661 | else |
| 5662 | snd_hda_codec_write(codec, 0x18, 0, |
| 5663 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5664 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
| 5665 | |
| 5666 | /* Mono Out */ |
| 5667 | present = snd_hda_jack_detect(codec, 0x26); |
| 5668 | |
| 5669 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5670 | if (spec->codec_type == VT1802) { |
| 5671 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ |
| 5672 | snd_hda_codec_write(codec, 0x33, 0, |
| 5673 | AC_VERB_SET_POWER_STATE, parm); |
| 5674 | snd_hda_codec_write(codec, 0x1c, 0, |
| 5675 | AC_VERB_SET_POWER_STATE, parm); |
| 5676 | snd_hda_codec_write(codec, 0x3c, 0, |
| 5677 | AC_VERB_SET_POWER_STATE, parm); |
| 5678 | } else { |
| 5679 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
| 5680 | snd_hda_codec_write(codec, 0x31, 0, |
| 5681 | AC_VERB_SET_POWER_STATE, parm); |
| 5682 | snd_hda_codec_write(codec, 0x17, 0, |
| 5683 | AC_VERB_SET_POWER_STATE, parm); |
| 5684 | snd_hda_codec_write(codec, 0x3b, 0, |
| 5685 | AC_VERB_SET_POWER_STATE, parm); |
| 5686 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5687 | /* MW9 (21h) */ |
| 5688 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 5689 | snd_hda_codec_write(codec, 0x21, 0, |
| 5690 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 5691 | else |
| 5692 | snd_hda_codec_write(codec, 0x21, 0, |
| 5693 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 5694 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5695 | |
| 5696 | /* patch for vt2002P */ |
| 5697 | static int patch_vt2002P(struct hda_codec *codec) |
| 5698 | { |
| 5699 | struct via_spec *spec; |
| 5700 | int err; |
| 5701 | |
| 5702 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 5703 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5704 | if (spec == NULL) |
| 5705 | return -ENOMEM; |
| 5706 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5707 | /* automatic parse from the BIOS config */ |
| 5708 | err = vt2002P_parse_auto_config(codec); |
| 5709 | if (err < 0) { |
| 5710 | via_free(codec); |
| 5711 | return err; |
| 5712 | } else if (!err) { |
| 5713 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 5714 | "from BIOS. Using genenic mode...\n"); |
| 5715 | } |
| 5716 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5717 | if (spec->codec_type == VT1802) |
| 5718 | spec->init_verbs[spec->num_iverbs++] = |
| 5719 | vt1802_volume_init_verbs; |
| 5720 | else |
| 5721 | spec->init_verbs[spec->num_iverbs++] = |
| 5722 | vt2002P_volume_init_verbs; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5723 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5724 | if (spec->codec_type == VT1802) |
| 5725 | spec->init_verbs[spec->num_iverbs++] = |
| 5726 | vt1802_uniwill_init_verbs; |
| 5727 | else |
| 5728 | spec->init_verbs[spec->num_iverbs++] = |
| 5729 | vt2002P_uniwill_init_verbs; |
| 5730 | |
| 5731 | if (spec->codec_type == VT1802) |
| 5732 | spec->stream_name_analog = "VT1802 Analog"; |
| 5733 | else |
| 5734 | spec->stream_name_analog = "VT2002P Analog"; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5735 | spec->stream_analog_playback = &vt2002P_pcm_analog_playback; |
| 5736 | spec->stream_analog_capture = &vt2002P_pcm_analog_capture; |
| 5737 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 5738 | if (spec->codec_type == VT1802) |
| 5739 | spec->stream_name_digital = "VT1802 Digital"; |
| 5740 | else |
| 5741 | spec->stream_name_digital = "VT2002P Digital"; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5742 | spec->stream_digital_playback = &vt2002P_pcm_digital_playback; |
| 5743 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 5744 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5745 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 5746 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 5747 | spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; |
| 5748 | spec->num_mixers++; |
| 5749 | } |
| 5750 | |
| 5751 | codec->patch_ops = via_patch_ops; |
| 5752 | |
| 5753 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 5754 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5755 | |
| 5756 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5757 | spec->loopback.amplist = vt2002P_loopbacks; |
| 5758 | #endif |
| 5759 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 5760 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5761 | return 0; |
| 5762 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5763 | |
| 5764 | /* for vt1812 */ |
| 5765 | |
| 5766 | /* capture mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5767 | static const struct snd_kcontrol_new vt1812_capture_mixer[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5768 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 5769 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 5770 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 5771 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 5772 | HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 5773 | HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 5774 | HDA_INPUT), |
| 5775 | { |
| 5776 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 5777 | /* The multiple "Capture Source" controls confuse alsamixer |
| 5778 | * So call somewhat different.. |
| 5779 | */ |
| 5780 | .name = "Input Source", |
| 5781 | .count = 2, |
| 5782 | .info = via_mux_enum_info, |
| 5783 | .get = via_mux_enum_get, |
| 5784 | .put = via_mux_enum_put, |
| 5785 | }, |
| 5786 | { } /* end */ |
| 5787 | }; |
| 5788 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5789 | static const struct hda_verb vt1812_volume_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5790 | /* |
| 5791 | * Unmute ADC0-1 and set the default input to mic-in |
| 5792 | */ |
| 5793 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5794 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5795 | |
| 5796 | |
| 5797 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 5798 | * mixer widget |
| 5799 | */ |
| 5800 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 5801 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 5802 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5803 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 5804 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 5805 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 5806 | |
| 5807 | /* MUX Indices: Mic = 0 */ |
| 5808 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5809 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5810 | |
| 5811 | /* PW9 Output enable */ |
| 5812 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 5813 | |
| 5814 | /* Enable Boost Volume backdoor */ |
| 5815 | {0x1, 0xfb9, 0x24}, |
| 5816 | |
| 5817 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 5818 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5819 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5820 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5821 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5822 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5823 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5824 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5825 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5826 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5827 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5828 | |
| 5829 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ |
| 5830 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5831 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5832 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5833 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5834 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5835 | |
| 5836 | /* Enable AOW0 to MW9 */ |
| 5837 | {0x1, 0xfb8, 0xa8}, |
| 5838 | { } |
| 5839 | }; |
| 5840 | |
| 5841 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5842 | static const struct hda_verb vt1812_uniwill_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5843 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5844 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5845 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, |
| 5846 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5847 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5848 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5849 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5850 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5851 | { } |
| 5852 | }; |
| 5853 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5854 | static const struct hda_pcm_stream vt1812_pcm_analog_playback = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5855 | .substreams = 2, |
| 5856 | .channels_min = 2, |
| 5857 | .channels_max = 2, |
| 5858 | .nid = 0x8, /* NID to query formats and rates */ |
| 5859 | .ops = { |
| 5860 | .open = via_playback_pcm_open, |
| 5861 | .prepare = via_playback_multi_pcm_prepare, |
| 5862 | .cleanup = via_playback_multi_pcm_cleanup, |
| 5863 | .close = via_pcm_open_close, |
| 5864 | }, |
| 5865 | }; |
| 5866 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5867 | static const struct hda_pcm_stream vt1812_pcm_analog_capture = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5868 | .substreams = 2, |
| 5869 | .channels_min = 2, |
| 5870 | .channels_max = 2, |
| 5871 | .nid = 0x10, /* NID to query formats and rates */ |
| 5872 | .ops = { |
| 5873 | .open = via_pcm_open_close, |
| 5874 | .prepare = via_capture_pcm_prepare, |
| 5875 | .cleanup = via_capture_pcm_cleanup, |
| 5876 | .close = via_pcm_open_close, |
| 5877 | }, |
| 5878 | }; |
| 5879 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 5880 | static const struct hda_pcm_stream vt1812_pcm_digital_playback = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5881 | .substreams = 1, |
| 5882 | .channels_min = 2, |
| 5883 | .channels_max = 2, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5884 | /* NID is set in via_build_pcms */ |
| 5885 | .ops = { |
| 5886 | .open = via_dig_playback_pcm_open, |
| 5887 | .close = via_dig_playback_pcm_close, |
| 5888 | .prepare = via_dig_playback_pcm_prepare, |
| 5889 | .cleanup = via_dig_playback_pcm_cleanup |
| 5890 | }, |
| 5891 | }; |
| 5892 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 5893 | static int vt1812_auto_fill_dac_nids(struct via_spec *spec, |
| 5894 | const struct auto_pin_cfg *cfg) |
| 5895 | { |
| 5896 | spec->multiout.num_dacs = 1; |
| 5897 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 5898 | if (cfg->line_out_pins[0]) |
Takashi Iwai | dda1441 | 2011-05-02 11:29:30 +0200 | [diff] [blame] | 5899 | spec->private_dac_nids[0] = 0x8; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5900 | return 0; |
| 5901 | } |
| 5902 | |
| 5903 | |
| 5904 | /* add playback controls from the parsed DAC table */ |
| 5905 | static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec, |
| 5906 | const struct auto_pin_cfg *cfg) |
| 5907 | { |
| 5908 | int err; |
| 5909 | |
| 5910 | if (!cfg->line_out_pins[0]) |
| 5911 | return -1; |
| 5912 | |
| 5913 | /* Line-Out: PortE */ |
| 5914 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 5915 | "Front Playback Volume", |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5916 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); |
| 5917 | if (err < 0) |
| 5918 | return err; |
| 5919 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 5920 | "Front Playback Switch", |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5921 | HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT)); |
| 5922 | if (err < 0) |
| 5923 | return err; |
| 5924 | |
| 5925 | return 0; |
| 5926 | } |
| 5927 | |
| 5928 | static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 5929 | { |
| 5930 | int err; |
| 5931 | |
| 5932 | if (!pin) |
| 5933 | return 0; |
| 5934 | |
| 5935 | spec->multiout.hp_nid = 0x9; |
| 5936 | spec->hp_independent_mode_index = 1; |
| 5937 | |
| 5938 | |
| 5939 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5940 | "Headphone Playback Volume", |
| 5941 | HDA_COMPOSE_AMP_VAL( |
| 5942 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); |
| 5943 | if (err < 0) |
| 5944 | return err; |
| 5945 | |
| 5946 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 5947 | "Headphone Playback Switch", |
| 5948 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 5949 | if (err < 0) |
| 5950 | return err; |
| 5951 | |
| 5952 | create_hp_imux(spec); |
| 5953 | return 0; |
| 5954 | } |
| 5955 | |
| 5956 | /* create playback/capture controls for input pins */ |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5957 | static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5958 | const struct auto_pin_cfg *cfg) |
| 5959 | { |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 5960 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | static int vt1812_parse_auto_config(struct hda_codec *codec) |
| 5964 | { |
| 5965 | struct via_spec *spec = codec->spec; |
| 5966 | int err; |
| 5967 | |
| 5968 | |
| 5969 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 5970 | if (err < 0) |
| 5971 | return err; |
| 5972 | fill_dig_outs(codec); |
| 5973 | err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg); |
| 5974 | if (err < 0) |
| 5975 | return err; |
| 5976 | |
| 5977 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) |
| 5978 | return 0; /* can't find valid BIOS pin config */ |
| 5979 | |
| 5980 | err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 5981 | if (err < 0) |
| 5982 | return err; |
| 5983 | err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 5984 | if (err < 0) |
| 5985 | return err; |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 5986 | err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5987 | if (err < 0) |
| 5988 | return err; |
| 5989 | |
| 5990 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 5991 | |
| 5992 | fill_dig_outs(codec); |
| 5993 | |
| 5994 | if (spec->kctls.list) |
| 5995 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 5996 | |
| 5997 | spec->input_mux = &spec->private_imux[0]; |
| 5998 | |
| 5999 | if (spec->hp_mux) |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 6000 | via_hp_build(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6001 | |
| 6002 | return 1; |
| 6003 | } |
| 6004 | |
| 6005 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 6006 | static const struct hda_amp_list vt1812_loopbacks[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6007 | { 0x21, HDA_INPUT, 0 }, |
| 6008 | { 0x21, HDA_INPUT, 1 }, |
| 6009 | { 0x21, HDA_INPUT, 2 }, |
| 6010 | { } /* end */ |
| 6011 | }; |
| 6012 | #endif |
| 6013 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 6014 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
| 6015 | { |
| 6016 | struct via_spec *spec = codec->spec; |
| 6017 | int imux_is_smixer = |
| 6018 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 6019 | unsigned int parm; |
| 6020 | unsigned int present; |
| 6021 | /* MUX10 (1eh) = stereo mixer */ |
| 6022 | imux_is_smixer = |
| 6023 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 6024 | /* inputs */ |
| 6025 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 6026 | parm = AC_PWRST_D3; |
| 6027 | set_pin_power_state(codec, 0x29, &parm); |
| 6028 | set_pin_power_state(codec, 0x2a, &parm); |
| 6029 | set_pin_power_state(codec, 0x2b, &parm); |
| 6030 | parm = AC_PWRST_D0; |
| 6031 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 6032 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6033 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6034 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6035 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6036 | |
| 6037 | /* outputs */ |
| 6038 | /* AOW0 (8h)*/ |
| 6039 | snd_hda_codec_write(codec, 0x8, 0, |
| 6040 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6041 | |
| 6042 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 6043 | parm = AC_PWRST_D3; |
| 6044 | set_pin_power_state(codec, 0x28, &parm); |
| 6045 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6046 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6047 | |
| 6048 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 6049 | parm = AC_PWRST_D3; |
| 6050 | set_pin_power_state(codec, 0x25, &parm); |
| 6051 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6052 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6053 | if (spec->hp_independent_mode) |
| 6054 | snd_hda_codec_write(codec, 0x9, 0, |
| 6055 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6056 | |
| 6057 | /* Internal Speaker */ |
| 6058 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 6059 | present = snd_hda_jack_detect(codec, 0x25); |
| 6060 | |
| 6061 | parm = AC_PWRST_D3; |
| 6062 | set_pin_power_state(codec, 0x24, &parm); |
| 6063 | if (present) { |
| 6064 | snd_hda_codec_write(codec, 0x14, 0, |
| 6065 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 6066 | snd_hda_codec_write(codec, 0x34, 0, |
| 6067 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 6068 | } else { |
| 6069 | snd_hda_codec_write(codec, 0x14, 0, |
| 6070 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6071 | snd_hda_codec_write(codec, 0x34, 0, |
| 6072 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6073 | } |
| 6074 | |
| 6075 | |
| 6076 | /* Mono Out */ |
| 6077 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 6078 | present = snd_hda_jack_detect(codec, 0x28); |
| 6079 | |
| 6080 | parm = AC_PWRST_D3; |
| 6081 | set_pin_power_state(codec, 0x31, &parm); |
| 6082 | if (present) { |
| 6083 | snd_hda_codec_write(codec, 0x1c, 0, |
| 6084 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 6085 | snd_hda_codec_write(codec, 0x3c, 0, |
| 6086 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 6087 | snd_hda_codec_write(codec, 0x3e, 0, |
| 6088 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 6089 | } else { |
| 6090 | snd_hda_codec_write(codec, 0x1c, 0, |
| 6091 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6092 | snd_hda_codec_write(codec, 0x3c, 0, |
| 6093 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6094 | snd_hda_codec_write(codec, 0x3e, 0, |
| 6095 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 6096 | } |
| 6097 | |
| 6098 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 6099 | parm = AC_PWRST_D3; |
| 6100 | set_pin_power_state(codec, 0x33, &parm); |
| 6101 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6102 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 6103 | |
| 6104 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6105 | |
| 6106 | /* patch for vt1812 */ |
| 6107 | static int patch_vt1812(struct hda_codec *codec) |
| 6108 | { |
| 6109 | struct via_spec *spec; |
| 6110 | int err; |
| 6111 | |
| 6112 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 6113 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6114 | if (spec == NULL) |
| 6115 | return -ENOMEM; |
| 6116 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6117 | /* automatic parse from the BIOS config */ |
| 6118 | err = vt1812_parse_auto_config(codec); |
| 6119 | if (err < 0) { |
| 6120 | via_free(codec); |
| 6121 | return err; |
| 6122 | } else if (!err) { |
| 6123 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 6124 | "from BIOS. Using genenic mode...\n"); |
| 6125 | } |
| 6126 | |
| 6127 | |
| 6128 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; |
| 6129 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; |
| 6130 | |
| 6131 | spec->stream_name_analog = "VT1812 Analog"; |
| 6132 | spec->stream_analog_playback = &vt1812_pcm_analog_playback; |
| 6133 | spec->stream_analog_capture = &vt1812_pcm_analog_capture; |
| 6134 | |
| 6135 | spec->stream_name_digital = "VT1812 Digital"; |
| 6136 | spec->stream_digital_playback = &vt1812_pcm_digital_playback; |
| 6137 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 6138 | if (spec->adc_nids && spec->input_mux) { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6139 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 6140 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 6141 | spec->mixers[spec->num_mixers] = vt1812_capture_mixer; |
| 6142 | spec->num_mixers++; |
| 6143 | } |
| 6144 | |
| 6145 | codec->patch_ops = via_patch_ops; |
| 6146 | |
| 6147 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame] | 6148 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6149 | |
| 6150 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6151 | spec->loopback.amplist = vt1812_loopbacks; |
| 6152 | #endif |
| 6153 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 6154 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6155 | return 0; |
| 6156 | } |
| 6157 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 6158 | /* |
| 6159 | * patch entries |
| 6160 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 6161 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6162 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 6163 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 6164 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 6165 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 6166 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6167 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6168 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6169 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6170 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6171 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6172 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6173 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6174 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6175 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6176 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6177 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6178 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6179 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6180 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6181 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6182 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6183 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6184 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6185 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6186 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6187 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6188 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6189 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6190 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6191 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6192 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6193 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6194 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6195 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6196 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6197 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6198 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6199 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6200 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6201 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6202 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6203 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6204 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6205 | .patch = patch_vt1708S}, |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 6206 | { .id = 0x11064397, .name = "VT1705", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6207 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6208 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6209 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6210 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6211 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6212 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6213 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6214 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6215 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6216 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6217 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6218 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6219 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6220 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6221 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6222 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6223 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6224 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6225 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6226 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6227 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6228 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6229 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 6230 | { .id = 0x11060428, .name = "VT1718S", |
| 6231 | .patch = patch_vt1718S}, |
| 6232 | { .id = 0x11064428, .name = "VT1718S", |
| 6233 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 6234 | { .id = 0x11060441, .name = "VT2020", |
| 6235 | .patch = patch_vt1718S}, |
| 6236 | { .id = 0x11064441, .name = "VT1828S", |
| 6237 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 6238 | { .id = 0x11060433, .name = "VT1716S", |
| 6239 | .patch = patch_vt1716S}, |
| 6240 | { .id = 0x1106a721, .name = "VT1716S", |
| 6241 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 6242 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 6243 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6244 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 6245 | { .id = 0x11060440, .name = "VT1818S", |
| 6246 | .patch = patch_vt1708S}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 6247 | { .id = 0x11060446, .name = "VT1802", |
| 6248 | .patch = patch_vt2002P}, |
| 6249 | { .id = 0x11068446, .name = "VT1802", |
| 6250 | .patch = patch_vt2002P}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 6251 | {} /* terminator */ |
| 6252 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 6253 | |
| 6254 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 6255 | |
| 6256 | static struct hda_codec_preset_list via_list = { |
| 6257 | .preset = snd_hda_preset_via, |
| 6258 | .owner = THIS_MODULE, |
| 6259 | }; |
| 6260 | |
| 6261 | MODULE_LICENSE("GPL"); |
| 6262 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 6263 | |
| 6264 | static int __init patch_via_init(void) |
| 6265 | { |
| 6266 | return snd_hda_add_codec_preset(&via_list); |
| 6267 | } |
| 6268 | |
| 6269 | static void __exit patch_via_exit(void) |
| 6270 | { |
| 6271 | snd_hda_delete_codec_preset(&via_list); |
| 6272 | } |
| 6273 | |
| 6274 | module_init(patch_via_init) |
| 6275 | module_exit(patch_via_exit) |