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