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