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