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