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