diff options
Diffstat (limited to 'sound/pci/hda/patch_via.c')
-rw-r--r-- | sound/pci/hda/patch_via.c | 3638 |
1 files changed, 3308 insertions, 330 deletions
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c index ee89db90c9b6..73453814e098 100644 --- a/sound/pci/hda/patch_via.c +++ b/sound/pci/hda/patch_via.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | 2 | * Universal Interface for Intel High Definition Audio Codec |
3 | * | 3 | * |
4 | * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec | 4 | * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec |
5 | * | 5 | * |
6 | * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com> | 6 | * (C) 2006-2009 VIA Technology, Inc. |
7 | * Takashi Iwai <tiwai@suse.de> | 7 | * (C) 2006-2008 Takashi Iwai <tiwai@suse.de> |
8 | * | 8 | * |
9 | * This driver is free software; you can redistribute it and/or modify | 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 | 10 | * it under the terms of the GNU General Public License as published by |
@@ -22,21 +22,27 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ | 24 | /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ |
25 | /* */ | 25 | /* */ |
26 | /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ | 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 */ | 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 */ | 28 | /* 2006-08-02 Lydia Wang Add support to VT1709 codec */ |
29 | /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ | 29 | /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ |
30 | /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ | 30 | /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ |
31 | /* 2007-09-17 Lydia Wang Add VT1708B codec support */ | 31 | /* 2007-09-17 Lydia Wang Add VT1708B codec support */ |
32 | /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ | 32 | /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ |
33 | /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ | 33 | /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ |
34 | /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ | 34 | /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ |
35 | /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ | 35 | /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ |
36 | /* 2008-04-09 Lydia Wang Add Independent HP feature */ | 36 | /* 2008-04-09 Lydia Wang Add Independent HP feature */ |
37 | /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ | 37 | /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ |
38 | /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ | 38 | /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ |
39 | /* */ | 39 | /* 2009-02-16 Logan Li Add support for VT1718S */ |
40 | /* 2009-03-13 Logan Li Add support for VT1716S */ | ||
41 | /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */ | ||
42 | /* 2009-07-08 Lydia Wang Add support for VT2002P */ | ||
43 | /* 2009-07-21 Lydia Wang Add support for VT1812 */ | ||
44 | /* 2009-09-19 Lydia Wang Add support for VT1818S */ | ||
45 | /* */ | ||
40 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 46 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
41 | 47 | ||
42 | 48 | ||
@@ -48,6 +54,8 @@ | |||
48 | #include "hda_codec.h" | 54 | #include "hda_codec.h" |
49 | #include "hda_local.h" | 55 | #include "hda_local.h" |
50 | 56 | ||
57 | #define NID_MAPPING (-1) | ||
58 | |||
51 | /* amp values */ | 59 | /* amp values */ |
52 | #define AMP_VAL_IDX_SHIFT 19 | 60 | #define AMP_VAL_IDX_SHIFT 19 |
53 | #define AMP_VAL_IDX_MASK (0x0f<<19) | 61 | #define AMP_VAL_IDX_MASK (0x0f<<19) |
@@ -76,14 +84,6 @@ | |||
76 | #define VT1702_HP_NID 0x17 | 84 | #define VT1702_HP_NID 0x17 |
77 | #define VT1702_DIGOUT_NID 0x11 | 85 | #define VT1702_DIGOUT_NID 0x11 |
78 | 86 | ||
79 | #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b) | ||
80 | #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713) | ||
81 | #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717) | ||
82 | #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723) | ||
83 | #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727) | ||
84 | #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397) | ||
85 | #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398) | ||
86 | |||
87 | enum VIA_HDA_CODEC { | 87 | enum VIA_HDA_CODEC { |
88 | UNKNOWN = -1, | 88 | UNKNOWN = -1, |
89 | VT1708, | 89 | VT1708, |
@@ -92,12 +92,89 @@ enum VIA_HDA_CODEC { | |||
92 | VT1708B_8CH, | 92 | VT1708B_8CH, |
93 | VT1708B_4CH, | 93 | VT1708B_4CH, |
94 | VT1708S, | 94 | VT1708S, |
95 | VT1708BCE, | ||
95 | VT1702, | 96 | VT1702, |
97 | VT1718S, | ||
98 | VT1716S, | ||
99 | VT2002P, | ||
100 | VT1812, | ||
96 | CODEC_TYPES, | 101 | CODEC_TYPES, |
97 | }; | 102 | }; |
98 | 103 | ||
99 | static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) | 104 | struct via_spec { |
105 | /* codec parameterization */ | ||
106 | struct snd_kcontrol_new *mixers[6]; | ||
107 | unsigned int num_mixers; | ||
108 | |||
109 | struct hda_verb *init_verbs[5]; | ||
110 | unsigned int num_iverbs; | ||
111 | |||
112 | char *stream_name_analog; | ||
113 | struct hda_pcm_stream *stream_analog_playback; | ||
114 | struct hda_pcm_stream *stream_analog_capture; | ||
115 | |||
116 | char *stream_name_digital; | ||
117 | struct hda_pcm_stream *stream_digital_playback; | ||
118 | struct hda_pcm_stream *stream_digital_capture; | ||
119 | |||
120 | /* playback */ | ||
121 | struct hda_multi_out multiout; | ||
122 | hda_nid_t slave_dig_outs[2]; | ||
123 | |||
124 | /* capture */ | ||
125 | unsigned int num_adc_nids; | ||
126 | hda_nid_t *adc_nids; | ||
127 | hda_nid_t mux_nids[3]; | ||
128 | hda_nid_t dig_in_nid; | ||
129 | hda_nid_t dig_in_pin; | ||
130 | |||
131 | /* capture source */ | ||
132 | const struct hda_input_mux *input_mux; | ||
133 | unsigned int cur_mux[3]; | ||
134 | |||
135 | /* PCM information */ | ||
136 | struct hda_pcm pcm_rec[3]; | ||
137 | |||
138 | /* dynamic controls, init_verbs and input_mux */ | ||
139 | struct auto_pin_cfg autocfg; | ||
140 | struct snd_array kctls; | ||
141 | struct hda_input_mux private_imux[2]; | ||
142 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | ||
143 | |||
144 | /* HP mode source */ | ||
145 | const struct hda_input_mux *hp_mux; | ||
146 | unsigned int hp_independent_mode; | ||
147 | unsigned int hp_independent_mode_index; | ||
148 | unsigned int smart51_enabled; | ||
149 | unsigned int dmic_enabled; | ||
150 | enum VIA_HDA_CODEC codec_type; | ||
151 | |||
152 | /* work to check hp jack state */ | ||
153 | struct hda_codec *codec; | ||
154 | struct delayed_work vt1708_hp_work; | ||
155 | int vt1708_jack_detectect; | ||
156 | int vt1708_hp_present; | ||
157 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
158 | struct hda_loopback_check loopback; | ||
159 | #endif | ||
160 | }; | ||
161 | |||
162 | static struct via_spec * via_new_spec(struct hda_codec *codec) | ||
100 | { | 163 | { |
164 | struct via_spec *spec; | ||
165 | |||
166 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
167 | if (spec == NULL) | ||
168 | return NULL; | ||
169 | |||
170 | codec->spec = spec; | ||
171 | spec->codec = codec; | ||
172 | return spec; | ||
173 | } | ||
174 | |||
175 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) | ||
176 | { | ||
177 | u32 vendor_id = codec->vendor_id; | ||
101 | u16 ven_id = vendor_id >> 16; | 178 | u16 ven_id = vendor_id >> 16; |
102 | u16 dev_id = vendor_id & 0xffff; | 179 | u16 dev_id = vendor_id & 0xffff; |
103 | enum VIA_HDA_CODEC codec_type; | 180 | enum VIA_HDA_CODEC codec_type; |
@@ -111,9 +188,11 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) | |||
111 | codec_type = VT1709_10CH; | 188 | codec_type = VT1709_10CH; |
112 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) | 189 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
113 | codec_type = VT1709_6CH; | 190 | codec_type = VT1709_6CH; |
114 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) | 191 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
115 | codec_type = VT1708B_8CH; | 192 | codec_type = VT1708B_8CH; |
116 | else if (dev_id >= 0xe724 && dev_id <= 0xe727) | 193 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
194 | codec_type = VT1708BCE; | ||
195 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) | ||
117 | codec_type = VT1708B_4CH; | 196 | codec_type = VT1708B_4CH; |
118 | else if ((dev_id & 0xfff) == 0x397 | 197 | else if ((dev_id & 0xfff) == 0x397 |
119 | && (dev_id >> 12) < 8) | 198 | && (dev_id >> 12) < 8) |
@@ -121,6 +200,19 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) | |||
121 | else if ((dev_id & 0xfff) == 0x398 | 200 | else if ((dev_id & 0xfff) == 0x398 |
122 | && (dev_id >> 12) < 8) | 201 | && (dev_id >> 12) < 8) |
123 | codec_type = VT1702; | 202 | codec_type = VT1702; |
203 | else if ((dev_id & 0xfff) == 0x428 | ||
204 | && (dev_id >> 12) < 8) | ||
205 | codec_type = VT1718S; | ||
206 | else if (dev_id == 0x0433 || dev_id == 0xa721) | ||
207 | codec_type = VT1716S; | ||
208 | else if (dev_id == 0x0441 || dev_id == 0x4441) | ||
209 | codec_type = VT1718S; | ||
210 | else if (dev_id == 0x0438 || dev_id == 0x4438) | ||
211 | codec_type = VT2002P; | ||
212 | else if (dev_id == 0x0448) | ||
213 | codec_type = VT1812; | ||
214 | else if (dev_id == 0x0440) | ||
215 | codec_type = VT1708S; | ||
124 | else | 216 | else |
125 | codec_type = UNKNOWN; | 217 | codec_type = UNKNOWN; |
126 | return codec_type; | 218 | return codec_type; |
@@ -128,10 +220,16 @@ static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) | |||
128 | 220 | ||
129 | #define VIA_HP_EVENT 0x01 | 221 | #define VIA_HP_EVENT 0x01 |
130 | #define VIA_GPIO_EVENT 0x02 | 222 | #define VIA_GPIO_EVENT 0x02 |
223 | #define VIA_JACK_EVENT 0x04 | ||
224 | #define VIA_MONO_EVENT 0x08 | ||
225 | #define VIA_SPEAKER_EVENT 0x10 | ||
226 | #define VIA_BIND_HP_EVENT 0x20 | ||
131 | 227 | ||
132 | enum { | 228 | enum { |
133 | VIA_CTL_WIDGET_VOL, | 229 | VIA_CTL_WIDGET_VOL, |
134 | VIA_CTL_WIDGET_MUTE, | 230 | VIA_CTL_WIDGET_MUTE, |
231 | VIA_CTL_WIDGET_ANALOG_MUTE, | ||
232 | VIA_CTL_WIDGET_BIND_PIN_MUTE, | ||
135 | }; | 233 | }; |
136 | 234 | ||
137 | enum { | 235 | enum { |
@@ -141,99 +239,162 @@ enum { | |||
141 | AUTO_SEQ_SIDE | 239 | AUTO_SEQ_SIDE |
142 | }; | 240 | }; |
143 | 241 | ||
144 | /* Some VT1708S based boards gets the micboost setting wrong, so we have | 242 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); |
145 | * to apply some brute-force and re-write the TLV's by software. */ | 243 | static void set_jack_power_state(struct hda_codec *codec); |
146 | static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, | 244 | static int is_aa_path_mute(struct hda_codec *codec); |
147 | unsigned int size, unsigned int __user *_tlv) | 245 | |
246 | static void vt1708_start_hp_work(struct via_spec *spec) | ||
148 | { | 247 | { |
149 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 248 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
150 | hda_nid_t nid = get_amp_nid(kcontrol); | 249 | return; |
250 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, | ||
251 | !spec->vt1708_jack_detectect); | ||
252 | if (!delayed_work_pending(&spec->vt1708_hp_work)) | ||
253 | schedule_delayed_work(&spec->vt1708_hp_work, | ||
254 | msecs_to_jiffies(100)); | ||
255 | } | ||
151 | 256 | ||
152 | if (get_codec_type(codec->vendor_id) == VT1708S | 257 | static void vt1708_stop_hp_work(struct via_spec *spec) |
153 | && (nid == 0x1a || nid == 0x1e)) { | 258 | { |
154 | if (size < 4 * sizeof(unsigned int)) | 259 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
155 | return -ENOMEM; | 260 | return; |
156 | if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */ | 261 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 |
157 | return -EFAULT; | 262 | && !is_aa_path_mute(spec->codec)) |
158 | if (put_user(2 * sizeof(unsigned int), _tlv + 1)) | 263 | return; |
159 | return -EFAULT; | 264 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
160 | if (put_user(0, _tlv + 2)) /* offset = 0 */ | 265 | !spec->vt1708_jack_detectect); |
161 | return -EFAULT; | 266 | cancel_delayed_work(&spec->vt1708_hp_work); |
162 | if (put_user(1000, _tlv + 3)) /* step size = 10 dB */ | 267 | flush_scheduled_work(); |
163 | return -EFAULT; | ||
164 | } | ||
165 | return 0; | ||
166 | } | 268 | } |
167 | 269 | ||
168 | static int mic_boost_volume_info(struct snd_kcontrol *kcontrol, | 270 | |
169 | struct snd_ctl_elem_info *uinfo) | 271 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
272 | struct snd_ctl_elem_value *ucontrol) | ||
170 | { | 273 | { |
274 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); | ||
171 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 275 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
172 | hda_nid_t nid = get_amp_nid(kcontrol); | ||
173 | 276 | ||
174 | if (get_codec_type(codec->vendor_id) == VT1708S | 277 | set_jack_power_state(codec); |
175 | && (nid == 0x1a || nid == 0x1e)) { | 278 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
176 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 279 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
177 | uinfo->count = 2; | 280 | if (is_aa_path_mute(codec)) |
178 | uinfo->value.integer.min = 0; | 281 | vt1708_start_hp_work(codec->spec); |
179 | uinfo->value.integer.max = 3; | 282 | else |
283 | vt1708_stop_hp_work(codec->spec); | ||
180 | } | 284 | } |
181 | return 0; | 285 | return change; |
182 | } | 286 | } |
183 | 287 | ||
184 | static struct snd_kcontrol_new vt1708_control_templates[] = { | 288 | /* modify .put = snd_hda_mixer_amp_switch_put */ |
185 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), | 289 | #define ANALOG_INPUT_MUTE \ |
186 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | 290 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
187 | }; | 291 | .name = NULL, \ |
292 | .index = 0, \ | ||
293 | .info = snd_hda_mixer_amp_switch_info, \ | ||
294 | .get = snd_hda_mixer_amp_switch_get, \ | ||
295 | .put = analog_input_switch_put, \ | ||
296 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | ||
188 | 297 | ||
298 | static void via_hp_bind_automute(struct hda_codec *codec); | ||
189 | 299 | ||
190 | struct via_spec { | 300 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, |
191 | /* codec parameterization */ | 301 | struct snd_ctl_elem_value *ucontrol) |
192 | struct snd_kcontrol_new *mixers[3]; | 302 | { |
193 | unsigned int num_mixers; | 303 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
194 | 304 | struct via_spec *spec = codec->spec; | |
195 | struct hda_verb *init_verbs[5]; | 305 | int i; |
196 | unsigned int num_iverbs; | 306 | int change = 0; |
197 | |||
198 | char *stream_name_analog; | ||
199 | struct hda_pcm_stream *stream_analog_playback; | ||
200 | struct hda_pcm_stream *stream_analog_capture; | ||
201 | |||
202 | char *stream_name_digital; | ||
203 | struct hda_pcm_stream *stream_digital_playback; | ||
204 | struct hda_pcm_stream *stream_digital_capture; | ||
205 | |||
206 | /* playback */ | ||
207 | struct hda_multi_out multiout; | ||
208 | hda_nid_t slave_dig_outs[2]; | ||
209 | |||
210 | /* capture */ | ||
211 | unsigned int num_adc_nids; | ||
212 | hda_nid_t *adc_nids; | ||
213 | hda_nid_t mux_nids[3]; | ||
214 | hda_nid_t dig_in_nid; | ||
215 | hda_nid_t dig_in_pin; | ||
216 | 307 | ||
217 | /* capture source */ | 308 | long *valp = ucontrol->value.integer.value; |
218 | const struct hda_input_mux *input_mux; | 309 | int lmute, rmute; |
219 | unsigned int cur_mux[3]; | 310 | if (strstr(kcontrol->id.name, "Switch") == NULL) { |
311 | snd_printd("Invalid control!\n"); | ||
312 | return change; | ||
313 | } | ||
314 | change = snd_hda_mixer_amp_switch_put(kcontrol, | ||
315 | ucontrol); | ||
316 | /* Get mute value */ | ||
317 | lmute = *valp ? 0 : HDA_AMP_MUTE; | ||
318 | valp++; | ||
319 | rmute = *valp ? 0 : HDA_AMP_MUTE; | ||
320 | |||
321 | /* Set hp pins */ | ||
322 | if (!spec->hp_independent_mode) { | ||
323 | for (i = 0; i < spec->autocfg.hp_outs; i++) { | ||
324 | snd_hda_codec_amp_update( | ||
325 | codec, spec->autocfg.hp_pins[i], | ||
326 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
327 | lmute); | ||
328 | snd_hda_codec_amp_update( | ||
329 | codec, spec->autocfg.hp_pins[i], | ||
330 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
331 | rmute); | ||
332 | } | ||
333 | } | ||
220 | 334 | ||
221 | /* PCM information */ | 335 | if (!lmute && !rmute) { |
222 | struct hda_pcm pcm_rec[3]; | 336 | /* Line Outs */ |
337 | for (i = 0; i < spec->autocfg.line_outs; i++) | ||
338 | snd_hda_codec_amp_stereo( | ||
339 | codec, spec->autocfg.line_out_pins[i], | ||
340 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | ||
341 | /* Speakers */ | ||
342 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | ||
343 | snd_hda_codec_amp_stereo( | ||
344 | codec, spec->autocfg.speaker_pins[i], | ||
345 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | ||
346 | /* unmute */ | ||
347 | via_hp_bind_automute(codec); | ||
223 | 348 | ||
224 | /* dynamic controls, init_verbs and input_mux */ | 349 | } else { |
225 | struct auto_pin_cfg autocfg; | 350 | if (lmute) { |
226 | struct snd_array kctls; | 351 | /* Mute all left channels */ |
227 | struct hda_input_mux private_imux[2]; | 352 | for (i = 1; i < spec->autocfg.line_outs; i++) |
228 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | 353 | snd_hda_codec_amp_update( |
354 | codec, | ||
355 | spec->autocfg.line_out_pins[i], | ||
356 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
357 | lmute); | ||
358 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | ||
359 | snd_hda_codec_amp_update( | ||
360 | codec, | ||
361 | spec->autocfg.speaker_pins[i], | ||
362 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
363 | lmute); | ||
364 | } | ||
365 | if (rmute) { | ||
366 | /* mute all right channels */ | ||
367 | for (i = 1; i < spec->autocfg.line_outs; i++) | ||
368 | snd_hda_codec_amp_update( | ||
369 | codec, | ||
370 | spec->autocfg.line_out_pins[i], | ||
371 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
372 | rmute); | ||
373 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | ||
374 | snd_hda_codec_amp_update( | ||
375 | codec, | ||
376 | spec->autocfg.speaker_pins[i], | ||
377 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
378 | rmute); | ||
379 | } | ||
380 | } | ||
381 | return change; | ||
382 | } | ||
229 | 383 | ||
230 | /* HP mode source */ | 384 | #define BIND_PIN_MUTE \ |
231 | const struct hda_input_mux *hp_mux; | 385 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
232 | unsigned int hp_independent_mode; | 386 | .name = NULL, \ |
387 | .index = 0, \ | ||
388 | .info = snd_hda_mixer_amp_switch_info, \ | ||
389 | .get = snd_hda_mixer_amp_switch_get, \ | ||
390 | .put = bind_pin_switch_put, \ | ||
391 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | ||
233 | 392 | ||
234 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 393 | static struct snd_kcontrol_new via_control_templates[] = { |
235 | struct hda_loopback_check loopback; | 394 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
236 | #endif | 395 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
396 | ANALOG_INPUT_MUTE, | ||
397 | BIND_PIN_MUTE, | ||
237 | }; | 398 | }; |
238 | 399 | ||
239 | static hda_nid_t vt1708_adc_nids[2] = { | 400 | static hda_nid_t vt1708_adc_nids[2] = { |
@@ -261,6 +422,27 @@ static hda_nid_t vt1702_adc_nids[3] = { | |||
261 | 0x12, 0x20, 0x1F | 422 | 0x12, 0x20, 0x1F |
262 | }; | 423 | }; |
263 | 424 | ||
425 | static hda_nid_t vt1718S_adc_nids[2] = { | ||
426 | /* ADC1-2 */ | ||
427 | 0x10, 0x11 | ||
428 | }; | ||
429 | |||
430 | static hda_nid_t vt1716S_adc_nids[2] = { | ||
431 | /* ADC1-2 */ | ||
432 | 0x13, 0x14 | ||
433 | }; | ||
434 | |||
435 | static hda_nid_t vt2002P_adc_nids[2] = { | ||
436 | /* ADC1-2 */ | ||
437 | 0x10, 0x11 | ||
438 | }; | ||
439 | |||
440 | static hda_nid_t vt1812_adc_nids[2] = { | ||
441 | /* ADC1-2 */ | ||
442 | 0x10, 0x11 | ||
443 | }; | ||
444 | |||
445 | |||
264 | /* add dynamic controls */ | 446 | /* add dynamic controls */ |
265 | static int via_add_control(struct via_spec *spec, int type, const char *name, | 447 | static int via_add_control(struct via_spec *spec, int type, const char *name, |
266 | unsigned long val) | 448 | unsigned long val) |
@@ -271,14 +453,32 @@ static int via_add_control(struct via_spec *spec, int type, const char *name, | |||
271 | knew = snd_array_new(&spec->kctls); | 453 | knew = snd_array_new(&spec->kctls); |
272 | if (!knew) | 454 | if (!knew) |
273 | return -ENOMEM; | 455 | return -ENOMEM; |
274 | *knew = vt1708_control_templates[type]; | 456 | *knew = via_control_templates[type]; |
275 | knew->name = kstrdup(name, GFP_KERNEL); | 457 | knew->name = kstrdup(name, GFP_KERNEL); |
276 | if (!knew->name) | 458 | if (!knew->name) |
277 | return -ENOMEM; | 459 | return -ENOMEM; |
460 | if (get_amp_nid_(val)) | ||
461 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; | ||
278 | knew->private_value = val; | 462 | knew->private_value = val; |
279 | return 0; | 463 | return 0; |
280 | } | 464 | } |
281 | 465 | ||
466 | static struct snd_kcontrol_new *via_clone_control(struct via_spec *spec, | ||
467 | struct snd_kcontrol_new *tmpl) | ||
468 | { | ||
469 | struct snd_kcontrol_new *knew; | ||
470 | |||
471 | snd_array_init(&spec->kctls, sizeof(*knew), 32); | ||
472 | knew = snd_array_new(&spec->kctls); | ||
473 | if (!knew) | ||
474 | return NULL; | ||
475 | *knew = *tmpl; | ||
476 | knew->name = kstrdup(tmpl->name, GFP_KERNEL); | ||
477 | if (!knew->name) | ||
478 | return NULL; | ||
479 | return knew; | ||
480 | } | ||
481 | |||
282 | static void via_free_kctls(struct hda_codec *codec) | 482 | static void via_free_kctls(struct hda_codec *codec) |
283 | { | 483 | { |
284 | struct via_spec *spec = codec->spec; | 484 | struct via_spec *spec = codec->spec; |
@@ -293,8 +493,8 @@ static void via_free_kctls(struct hda_codec *codec) | |||
293 | } | 493 | } |
294 | 494 | ||
295 | /* create input playback/capture controls for the given pin */ | 495 | /* create input playback/capture controls for the given pin */ |
296 | static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, | 496 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
297 | const char *ctlname, int idx, int mix_nid) | 497 | int idx, int mix_nid) |
298 | { | 498 | { |
299 | char name[32]; | 499 | char name[32]; |
300 | int err; | 500 | int err; |
@@ -305,7 +505,7 @@ static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, | |||
305 | if (err < 0) | 505 | if (err < 0) |
306 | return err; | 506 | return err; |
307 | sprintf(name, "%s Playback Switch", ctlname); | 507 | sprintf(name, "%s Playback Switch", ctlname); |
308 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | 508 | err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, |
309 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); | 509 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
310 | if (err < 0) | 510 | if (err < 0) |
311 | return err; | 511 | return err; |
@@ -322,7 +522,7 @@ static void via_auto_set_output_and_unmute(struct hda_codec *codec, | |||
322 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | 522 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
323 | AMP_OUT_UNMUTE); | 523 | AMP_OUT_UNMUTE); |
324 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) | 524 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
325 | snd_hda_codec_write(codec, nid, 0, | 525 | snd_hda_codec_write(codec, nid, 0, |
326 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); | 526 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
327 | } | 527 | } |
328 | 528 | ||
@@ -343,10 +543,13 @@ static void via_auto_init_hp_out(struct hda_codec *codec) | |||
343 | { | 543 | { |
344 | struct via_spec *spec = codec->spec; | 544 | struct via_spec *spec = codec->spec; |
345 | hda_nid_t pin; | 545 | hda_nid_t pin; |
546 | int i; | ||
346 | 547 | ||
347 | pin = spec->autocfg.hp_pins[0]; | 548 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
348 | if (pin) /* connect to front */ | 549 | pin = spec->autocfg.hp_pins[i]; |
349 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); | 550 | if (pin) /* connect to front */ |
551 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); | ||
552 | } | ||
350 | } | 553 | } |
351 | 554 | ||
352 | static void via_auto_init_analog_input(struct hda_codec *codec) | 555 | static void via_auto_init_analog_input(struct hda_codec *codec) |
@@ -364,6 +567,502 @@ static void via_auto_init_analog_input(struct hda_codec *codec) | |||
364 | 567 | ||
365 | } | 568 | } |
366 | } | 569 | } |
570 | |||
571 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin); | ||
572 | |||
573 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, | ||
574 | unsigned int *affected_parm) | ||
575 | { | ||
576 | unsigned parm; | ||
577 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); | ||
578 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) | ||
579 | >> AC_DEFCFG_MISC_SHIFT | ||
580 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ | ||
581 | unsigned present = snd_hda_jack_detect(codec, nid); | ||
582 | struct via_spec *spec = codec->spec; | ||
583 | if ((spec->smart51_enabled && is_smart51_pins(spec, nid)) | ||
584 | || ((no_presence || present) | ||
585 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { | ||
586 | *affected_parm = AC_PWRST_D0; /* if it's connected */ | ||
587 | parm = AC_PWRST_D0; | ||
588 | } else | ||
589 | parm = AC_PWRST_D3; | ||
590 | |||
591 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); | ||
592 | } | ||
593 | |||
594 | static void set_jack_power_state(struct hda_codec *codec) | ||
595 | { | ||
596 | struct via_spec *spec = codec->spec; | ||
597 | int imux_is_smixer; | ||
598 | unsigned int parm; | ||
599 | |||
600 | if (spec->codec_type == VT1702) { | ||
601 | imux_is_smixer = snd_hda_codec_read( | ||
602 | codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | ||
603 | /* inputs */ | ||
604 | /* PW 1/2/5 (14h/15h/18h) */ | ||
605 | parm = AC_PWRST_D3; | ||
606 | set_pin_power_state(codec, 0x14, &parm); | ||
607 | set_pin_power_state(codec, 0x15, &parm); | ||
608 | set_pin_power_state(codec, 0x18, &parm); | ||
609 | if (imux_is_smixer) | ||
610 | parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */ | ||
611 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ | ||
612 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, | ||
613 | parm); | ||
614 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, | ||
615 | parm); | ||
616 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, | ||
617 | parm); | ||
618 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, | ||
619 | parm); | ||
620 | |||
621 | /* outputs */ | ||
622 | /* PW 3/4 (16h/17h) */ | ||
623 | parm = AC_PWRST_D3; | ||
624 | set_pin_power_state(codec, 0x16, &parm); | ||
625 | set_pin_power_state(codec, 0x17, &parm); | ||
626 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ | ||
627 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, | ||
628 | imux_is_smixer ? AC_PWRST_D0 : parm); | ||
629 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, | ||
630 | parm); | ||
631 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, | ||
632 | parm); | ||
633 | } else if (spec->codec_type == VT1708B_8CH | ||
634 | || spec->codec_type == VT1708B_4CH | ||
635 | || spec->codec_type == VT1708S) { | ||
636 | /* SW0 (17h) = stereo mixer */ | ||
637 | int is_8ch = spec->codec_type != VT1708B_4CH; | ||
638 | imux_is_smixer = snd_hda_codec_read( | ||
639 | codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) | ||
640 | == ((spec->codec_type == VT1708S) ? 5 : 0); | ||
641 | /* inputs */ | ||
642 | /* PW 1/2/5 (1ah/1bh/1eh) */ | ||
643 | parm = AC_PWRST_D3; | ||
644 | set_pin_power_state(codec, 0x1a, &parm); | ||
645 | set_pin_power_state(codec, 0x1b, &parm); | ||
646 | set_pin_power_state(codec, 0x1e, &parm); | ||
647 | if (imux_is_smixer) | ||
648 | parm = AC_PWRST_D0; | ||
649 | /* SW0 (17h), AIW 0/1 (13h/14h) */ | ||
650 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, | ||
651 | parm); | ||
652 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, | ||
653 | parm); | ||
654 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, | ||
655 | parm); | ||
656 | |||
657 | /* outputs */ | ||
658 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | ||
659 | parm = AC_PWRST_D3; | ||
660 | set_pin_power_state(codec, 0x19, &parm); | ||
661 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, | ||
662 | parm); | ||
663 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, | ||
664 | parm); | ||
665 | |||
666 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ | ||
667 | if (is_8ch) { | ||
668 | parm = AC_PWRST_D3; | ||
669 | set_pin_power_state(codec, 0x22, &parm); | ||
670 | snd_hda_codec_write(codec, 0x26, 0, | ||
671 | AC_VERB_SET_POWER_STATE, parm); | ||
672 | snd_hda_codec_write(codec, 0x24, 0, | ||
673 | AC_VERB_SET_POWER_STATE, parm); | ||
674 | } | ||
675 | |||
676 | /* PW 3/4/7 (1ch/1dh/23h) */ | ||
677 | parm = AC_PWRST_D3; | ||
678 | /* force to D0 for internal Speaker */ | ||
679 | set_pin_power_state(codec, 0x1c, &parm); | ||
680 | set_pin_power_state(codec, 0x1d, &parm); | ||
681 | if (is_8ch) | ||
682 | set_pin_power_state(codec, 0x23, &parm); | ||
683 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ | ||
684 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, | ||
685 | imux_is_smixer ? AC_PWRST_D0 : parm); | ||
686 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, | ||
687 | parm); | ||
688 | if (is_8ch) { | ||
689 | snd_hda_codec_write(codec, 0x25, 0, | ||
690 | AC_VERB_SET_POWER_STATE, parm); | ||
691 | snd_hda_codec_write(codec, 0x27, 0, | ||
692 | AC_VERB_SET_POWER_STATE, parm); | ||
693 | } | ||
694 | } else if (spec->codec_type == VT1718S) { | ||
695 | /* MUX6 (1eh) = stereo mixer */ | ||
696 | imux_is_smixer = snd_hda_codec_read( | ||
697 | codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | ||
698 | /* inputs */ | ||
699 | /* PW 5/6/7 (29h/2ah/2bh) */ | ||
700 | parm = AC_PWRST_D3; | ||
701 | set_pin_power_state(codec, 0x29, &parm); | ||
702 | set_pin_power_state(codec, 0x2a, &parm); | ||
703 | set_pin_power_state(codec, 0x2b, &parm); | ||
704 | if (imux_is_smixer) | ||
705 | parm = AC_PWRST_D0; | ||
706 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ | ||
707 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, | ||
708 | parm); | ||
709 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, | ||
710 | parm); | ||
711 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, | ||
712 | parm); | ||
713 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, | ||
714 | parm); | ||
715 | |||
716 | /* outputs */ | ||
717 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ | ||
718 | parm = AC_PWRST_D3; | ||
719 | set_pin_power_state(codec, 0x27, &parm); | ||
720 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, | ||
721 | parm); | ||
722 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, | ||
723 | parm); | ||
724 | |||
725 | /* PW2 (26h), AOW2 (ah) */ | ||
726 | parm = AC_PWRST_D3; | ||
727 | set_pin_power_state(codec, 0x26, &parm); | ||
728 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, | ||
729 | parm); | ||
730 | |||
731 | /* PW0/1 (24h/25h) */ | ||
732 | parm = AC_PWRST_D3; | ||
733 | set_pin_power_state(codec, 0x24, &parm); | ||
734 | set_pin_power_state(codec, 0x25, &parm); | ||
735 | if (!spec->hp_independent_mode) /* check for redirected HP */ | ||
736 | set_pin_power_state(codec, 0x28, &parm); | ||
737 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, | ||
738 | parm); | ||
739 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, | ||
740 | parm); | ||
741 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ | ||
742 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, | ||
743 | imux_is_smixer ? AC_PWRST_D0 : parm); | ||
744 | if (spec->hp_independent_mode) { | ||
745 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ | ||
746 | parm = AC_PWRST_D3; | ||
747 | set_pin_power_state(codec, 0x28, &parm); | ||
748 | snd_hda_codec_write(codec, 0x1b, 0, | ||
749 | AC_VERB_SET_POWER_STATE, parm); | ||
750 | snd_hda_codec_write(codec, 0x34, 0, | ||
751 | AC_VERB_SET_POWER_STATE, parm); | ||
752 | snd_hda_codec_write(codec, 0xc, 0, | ||
753 | AC_VERB_SET_POWER_STATE, parm); | ||
754 | } | ||
755 | } else if (spec->codec_type == VT1716S) { | ||
756 | unsigned int mono_out, present; | ||
757 | /* SW0 (17h) = stereo mixer */ | ||
758 | imux_is_smixer = snd_hda_codec_read( | ||
759 | codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | ||
760 | /* inputs */ | ||
761 | /* PW 1/2/5 (1ah/1bh/1eh) */ | ||
762 | parm = AC_PWRST_D3; | ||
763 | set_pin_power_state(codec, 0x1a, &parm); | ||
764 | set_pin_power_state(codec, 0x1b, &parm); | ||
765 | set_pin_power_state(codec, 0x1e, &parm); | ||
766 | if (imux_is_smixer) | ||
767 | parm = AC_PWRST_D0; | ||
768 | /* SW0 (17h), AIW0(13h) */ | ||
769 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, | ||
770 | parm); | ||
771 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, | ||
772 | parm); | ||
773 | |||
774 | parm = AC_PWRST_D3; | ||
775 | set_pin_power_state(codec, 0x1e, &parm); | ||
776 | /* PW11 (22h) */ | ||
777 | if (spec->dmic_enabled) | ||
778 | set_pin_power_state(codec, 0x22, &parm); | ||
779 | else | ||
780 | snd_hda_codec_write( | ||
781 | codec, 0x22, 0, | ||
782 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
783 | |||
784 | /* SW2(26h), AIW1(14h) */ | ||
785 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, | ||
786 | parm); | ||
787 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, | ||
788 | parm); | ||
789 | |||
790 | /* outputs */ | ||
791 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | ||
792 | parm = AC_PWRST_D3; | ||
793 | set_pin_power_state(codec, 0x19, &parm); | ||
794 | /* Smart 5.1 PW2(1bh) */ | ||
795 | if (spec->smart51_enabled) | ||
796 | set_pin_power_state(codec, 0x1b, &parm); | ||
797 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, | ||
798 | parm); | ||
799 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, | ||
800 | parm); | ||
801 | |||
802 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ | ||
803 | parm = AC_PWRST_D3; | ||
804 | set_pin_power_state(codec, 0x23, &parm); | ||
805 | /* Smart 5.1 PW1(1ah) */ | ||
806 | if (spec->smart51_enabled) | ||
807 | set_pin_power_state(codec, 0x1a, &parm); | ||
808 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, | ||
809 | parm); | ||
810 | |||
811 | /* Smart 5.1 PW5(1eh) */ | ||
812 | if (spec->smart51_enabled) | ||
813 | set_pin_power_state(codec, 0x1e, &parm); | ||
814 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, | ||
815 | parm); | ||
816 | |||
817 | /* Mono out */ | ||
818 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ | ||
819 | present = snd_hda_jack_detect(codec, 0x1c); | ||
820 | if (present) | ||
821 | mono_out = 0; | ||
822 | else { | ||
823 | present = snd_hda_jack_detect(codec, 0x1d); | ||
824 | if (!spec->hp_independent_mode && present) | ||
825 | mono_out = 0; | ||
826 | else | ||
827 | mono_out = 1; | ||
828 | } | ||
829 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; | ||
830 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, | ||
831 | parm); | ||
832 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, | ||
833 | parm); | ||
834 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, | ||
835 | parm); | ||
836 | |||
837 | /* PW 3/4 (1ch/1dh) */ | ||
838 | parm = AC_PWRST_D3; | ||
839 | set_pin_power_state(codec, 0x1c, &parm); | ||
840 | set_pin_power_state(codec, 0x1d, &parm); | ||
841 | /* HP Independent Mode, power on AOW3 */ | ||
842 | if (spec->hp_independent_mode) | ||
843 | snd_hda_codec_write(codec, 0x25, 0, | ||
844 | AC_VERB_SET_POWER_STATE, parm); | ||
845 | |||
846 | /* force to D0 for internal Speaker */ | ||
847 | /* MW0 (16h), AOW0 (10h) */ | ||
848 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, | ||
849 | imux_is_smixer ? AC_PWRST_D0 : parm); | ||
850 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, | ||
851 | mono_out ? AC_PWRST_D0 : parm); | ||
852 | } else if (spec->codec_type == VT2002P) { | ||
853 | unsigned int present; | ||
854 | /* MUX9 (1eh) = stereo mixer */ | ||
855 | imux_is_smixer = snd_hda_codec_read( | ||
856 | codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | ||
857 | /* inputs */ | ||
858 | /* PW 5/6/7 (29h/2ah/2bh) */ | ||
859 | parm = AC_PWRST_D3; | ||
860 | set_pin_power_state(codec, 0x29, &parm); | ||
861 | set_pin_power_state(codec, 0x2a, &parm); | ||
862 | set_pin_power_state(codec, 0x2b, &parm); | ||
863 | if (imux_is_smixer) | ||
864 | parm = AC_PWRST_D0; | ||
865 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ | ||
866 | snd_hda_codec_write(codec, 0x1e, 0, | ||
867 | AC_VERB_SET_POWER_STATE, parm); | ||
868 | snd_hda_codec_write(codec, 0x1f, 0, | ||
869 | AC_VERB_SET_POWER_STATE, parm); | ||
870 | snd_hda_codec_write(codec, 0x10, 0, | ||
871 | AC_VERB_SET_POWER_STATE, parm); | ||
872 | snd_hda_codec_write(codec, 0x11, 0, | ||
873 | AC_VERB_SET_POWER_STATE, parm); | ||
874 | |||
875 | /* outputs */ | ||
876 | /* AOW0 (8h)*/ | ||
877 | snd_hda_codec_write(codec, 0x8, 0, | ||
878 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
879 | |||
880 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ | ||
881 | parm = AC_PWRST_D3; | ||
882 | set_pin_power_state(codec, 0x26, &parm); | ||
883 | snd_hda_codec_write(codec, 0x1c, 0, | ||
884 | AC_VERB_SET_POWER_STATE, parm); | ||
885 | snd_hda_codec_write(codec, 0x37, | ||
886 | 0, AC_VERB_SET_POWER_STATE, parm); | ||
887 | |||
888 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ | ||
889 | parm = AC_PWRST_D3; | ||
890 | set_pin_power_state(codec, 0x25, &parm); | ||
891 | snd_hda_codec_write(codec, 0x19, 0, | ||
892 | AC_VERB_SET_POWER_STATE, parm); | ||
893 | snd_hda_codec_write(codec, 0x35, 0, | ||
894 | AC_VERB_SET_POWER_STATE, parm); | ||
895 | if (spec->hp_independent_mode) { | ||
896 | snd_hda_codec_write(codec, 0x9, 0, | ||
897 | AC_VERB_SET_POWER_STATE, parm); | ||
898 | } | ||
899 | |||
900 | /* Class-D */ | ||
901 | /* PW0 (24h), MW0(18h), MUX0(34h) */ | ||
902 | present = snd_hda_jack_detect(codec, 0x25); | ||
903 | parm = AC_PWRST_D3; | ||
904 | set_pin_power_state(codec, 0x24, &parm); | ||
905 | if (present) { | ||
906 | snd_hda_codec_write( | ||
907 | codec, 0x18, 0, | ||
908 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
909 | snd_hda_codec_write( | ||
910 | codec, 0x34, 0, | ||
911 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
912 | } else { | ||
913 | snd_hda_codec_write( | ||
914 | codec, 0x18, 0, | ||
915 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
916 | snd_hda_codec_write( | ||
917 | codec, 0x34, 0, | ||
918 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
919 | } | ||
920 | |||
921 | /* Mono Out */ | ||
922 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ | ||
923 | present = snd_hda_jack_detect(codec, 0x26); | ||
924 | parm = AC_PWRST_D3; | ||
925 | set_pin_power_state(codec, 0x31, &parm); | ||
926 | if (present) { | ||
927 | snd_hda_codec_write( | ||
928 | codec, 0x17, 0, | ||
929 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
930 | snd_hda_codec_write( | ||
931 | codec, 0x3b, 0, | ||
932 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
933 | } else { | ||
934 | snd_hda_codec_write( | ||
935 | codec, 0x17, 0, | ||
936 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
937 | snd_hda_codec_write( | ||
938 | codec, 0x3b, 0, | ||
939 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
940 | } | ||
941 | |||
942 | /* MW9 (21h) */ | ||
943 | if (imux_is_smixer || !is_aa_path_mute(codec)) | ||
944 | snd_hda_codec_write( | ||
945 | codec, 0x21, 0, | ||
946 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
947 | else | ||
948 | snd_hda_codec_write( | ||
949 | codec, 0x21, 0, | ||
950 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
951 | } else if (spec->codec_type == VT1812) { | ||
952 | unsigned int present; | ||
953 | /* MUX10 (1eh) = stereo mixer */ | ||
954 | imux_is_smixer = snd_hda_codec_read( | ||
955 | codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | ||
956 | /* inputs */ | ||
957 | /* PW 5/6/7 (29h/2ah/2bh) */ | ||
958 | parm = AC_PWRST_D3; | ||
959 | set_pin_power_state(codec, 0x29, &parm); | ||
960 | set_pin_power_state(codec, 0x2a, &parm); | ||
961 | set_pin_power_state(codec, 0x2b, &parm); | ||
962 | if (imux_is_smixer) | ||
963 | parm = AC_PWRST_D0; | ||
964 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ | ||
965 | snd_hda_codec_write(codec, 0x1e, 0, | ||
966 | AC_VERB_SET_POWER_STATE, parm); | ||
967 | snd_hda_codec_write(codec, 0x1f, 0, | ||
968 | AC_VERB_SET_POWER_STATE, parm); | ||
969 | snd_hda_codec_write(codec, 0x10, 0, | ||
970 | AC_VERB_SET_POWER_STATE, parm); | ||
971 | snd_hda_codec_write(codec, 0x11, 0, | ||
972 | AC_VERB_SET_POWER_STATE, parm); | ||
973 | |||
974 | /* outputs */ | ||
975 | /* AOW0 (8h)*/ | ||
976 | snd_hda_codec_write(codec, 0x8, 0, | ||
977 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
978 | |||
979 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | ||
980 | parm = AC_PWRST_D3; | ||
981 | set_pin_power_state(codec, 0x28, &parm); | ||
982 | snd_hda_codec_write(codec, 0x18, 0, | ||
983 | AC_VERB_SET_POWER_STATE, parm); | ||
984 | snd_hda_codec_write(codec, 0x38, 0, | ||
985 | AC_VERB_SET_POWER_STATE, parm); | ||
986 | |||
987 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | ||
988 | parm = AC_PWRST_D3; | ||
989 | set_pin_power_state(codec, 0x25, &parm); | ||
990 | snd_hda_codec_write(codec, 0x15, 0, | ||
991 | AC_VERB_SET_POWER_STATE, parm); | ||
992 | snd_hda_codec_write(codec, 0x35, 0, | ||
993 | AC_VERB_SET_POWER_STATE, parm); | ||
994 | if (spec->hp_independent_mode) { | ||
995 | snd_hda_codec_write(codec, 0x9, 0, | ||
996 | AC_VERB_SET_POWER_STATE, parm); | ||
997 | } | ||
998 | |||
999 | /* Internal Speaker */ | ||
1000 | /* PW0 (24h), MW0(14h), MUX0(34h) */ | ||
1001 | present = snd_hda_jack_detect(codec, 0x25); | ||
1002 | parm = AC_PWRST_D3; | ||
1003 | set_pin_power_state(codec, 0x24, &parm); | ||
1004 | if (present) { | ||
1005 | snd_hda_codec_write(codec, 0x14, 0, | ||
1006 | AC_VERB_SET_POWER_STATE, | ||
1007 | AC_PWRST_D3); | ||
1008 | snd_hda_codec_write(codec, 0x34, 0, | ||
1009 | AC_VERB_SET_POWER_STATE, | ||
1010 | AC_PWRST_D3); | ||
1011 | } else { | ||
1012 | snd_hda_codec_write(codec, 0x14, 0, | ||
1013 | AC_VERB_SET_POWER_STATE, | ||
1014 | AC_PWRST_D0); | ||
1015 | snd_hda_codec_write(codec, 0x34, 0, | ||
1016 | AC_VERB_SET_POWER_STATE, | ||
1017 | AC_PWRST_D0); | ||
1018 | } | ||
1019 | /* Mono Out */ | ||
1020 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ | ||
1021 | present = snd_hda_jack_detect(codec, 0x28); | ||
1022 | parm = AC_PWRST_D3; | ||
1023 | set_pin_power_state(codec, 0x31, &parm); | ||
1024 | if (present) { | ||
1025 | snd_hda_codec_write(codec, 0x1c, 0, | ||
1026 | AC_VERB_SET_POWER_STATE, | ||
1027 | AC_PWRST_D3); | ||
1028 | snd_hda_codec_write(codec, 0x3c, 0, | ||
1029 | AC_VERB_SET_POWER_STATE, | ||
1030 | AC_PWRST_D3); | ||
1031 | snd_hda_codec_write(codec, 0x3e, 0, | ||
1032 | AC_VERB_SET_POWER_STATE, | ||
1033 | AC_PWRST_D3); | ||
1034 | } else { | ||
1035 | snd_hda_codec_write(codec, 0x1c, 0, | ||
1036 | AC_VERB_SET_POWER_STATE, | ||
1037 | AC_PWRST_D0); | ||
1038 | snd_hda_codec_write(codec, 0x3c, 0, | ||
1039 | AC_VERB_SET_POWER_STATE, | ||
1040 | AC_PWRST_D0); | ||
1041 | snd_hda_codec_write(codec, 0x3e, 0, | ||
1042 | AC_VERB_SET_POWER_STATE, | ||
1043 | AC_PWRST_D0); | ||
1044 | } | ||
1045 | |||
1046 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ | ||
1047 | parm = AC_PWRST_D3; | ||
1048 | set_pin_power_state(codec, 0x33, &parm); | ||
1049 | snd_hda_codec_write(codec, 0x1d, 0, | ||
1050 | AC_VERB_SET_POWER_STATE, parm); | ||
1051 | snd_hda_codec_write(codec, 0x3d, 0, | ||
1052 | AC_VERB_SET_POWER_STATE, parm); | ||
1053 | |||
1054 | /* MW9 (21h) */ | ||
1055 | if (imux_is_smixer || !is_aa_path_mute(codec)) | ||
1056 | snd_hda_codec_write( | ||
1057 | codec, 0x21, 0, | ||
1058 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
1059 | else | ||
1060 | snd_hda_codec_write( | ||
1061 | codec, 0x21, 0, | ||
1062 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | ||
1063 | } | ||
1064 | } | ||
1065 | |||
367 | /* | 1066 | /* |
368 | * input MUX handling | 1067 | * input MUX handling |
369 | */ | 1068 | */ |
@@ -395,6 +1094,14 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | |||
395 | 1094 | ||
396 | if (!spec->mux_nids[adc_idx]) | 1095 | if (!spec->mux_nids[adc_idx]) |
397 | return -EINVAL; | 1096 | return -EINVAL; |
1097 | /* switch to D0 beofre change index */ | ||
1098 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, | ||
1099 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) | ||
1100 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, | ||
1101 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | ||
1102 | /* update jack power state */ | ||
1103 | set_jack_power_state(codec); | ||
1104 | |||
398 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | 1105 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
399 | spec->mux_nids[adc_idx], | 1106 | spec->mux_nids[adc_idx], |
400 | &spec->cur_mux[adc_idx]); | 1107 | &spec->cur_mux[adc_idx]); |
@@ -412,80 +1119,340 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol, | |||
412 | struct snd_ctl_elem_value *ucontrol) | 1119 | struct snd_ctl_elem_value *ucontrol) |
413 | { | 1120 | { |
414 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 1121 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
415 | struct via_spec *spec = codec->spec; | 1122 | hda_nid_t nid = kcontrol->private_value; |
416 | hda_nid_t nid = spec->autocfg.hp_pins[0]; | 1123 | unsigned int pinsel; |
417 | unsigned int pinsel = snd_hda_codec_read(codec, nid, 0, | ||
418 | AC_VERB_GET_CONNECT_SEL, | ||
419 | 0x00); | ||
420 | 1124 | ||
1125 | /* use !! to translate conn sel 2 for VT1718S */ | ||
1126 | pinsel = !!snd_hda_codec_read(codec, nid, 0, | ||
1127 | AC_VERB_GET_CONNECT_SEL, | ||
1128 | 0x00); | ||
421 | ucontrol->value.enumerated.item[0] = pinsel; | 1129 | ucontrol->value.enumerated.item[0] = pinsel; |
422 | 1130 | ||
423 | return 0; | 1131 | return 0; |
424 | } | 1132 | } |
425 | 1133 | ||
1134 | static void activate_ctl(struct hda_codec *codec, const char *name, int active) | ||
1135 | { | ||
1136 | struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); | ||
1137 | if (ctl) { | ||
1138 | ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; | ||
1139 | ctl->vd[0].access |= active | ||
1140 | ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; | ||
1141 | snd_ctl_notify(codec->bus->card, | ||
1142 | SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); | ||
1143 | } | ||
1144 | } | ||
1145 | |||
1146 | static hda_nid_t side_mute_channel(struct via_spec *spec) | ||
1147 | { | ||
1148 | switch (spec->codec_type) { | ||
1149 | case VT1708: return 0x1b; | ||
1150 | case VT1709_10CH: return 0x29; | ||
1151 | case VT1708B_8CH: /* fall thru */ | ||
1152 | case VT1708S: return 0x27; | ||
1153 | default: return 0; | ||
1154 | } | ||
1155 | } | ||
1156 | |||
1157 | static int update_side_mute_status(struct hda_codec *codec) | ||
1158 | { | ||
1159 | /* mute side channel */ | ||
1160 | struct via_spec *spec = codec->spec; | ||
1161 | unsigned int parm = spec->hp_independent_mode | ||
1162 | ? AMP_OUT_MUTE : AMP_OUT_UNMUTE; | ||
1163 | hda_nid_t sw3 = side_mute_channel(spec); | ||
1164 | |||
1165 | if (sw3) | ||
1166 | snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE, | ||
1167 | parm); | ||
1168 | return 0; | ||
1169 | } | ||
1170 | |||
426 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, | 1171 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
427 | struct snd_ctl_elem_value *ucontrol) | 1172 | struct snd_ctl_elem_value *ucontrol) |
428 | { | 1173 | { |
429 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | 1174 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
430 | struct via_spec *spec = codec->spec; | 1175 | struct via_spec *spec = codec->spec; |
431 | hda_nid_t nid = spec->autocfg.hp_pins[0]; | 1176 | hda_nid_t nid = kcontrol->private_value; |
432 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; | 1177 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
433 | unsigned int con_nid = snd_hda_codec_read(codec, nid, 0, | 1178 | /* Get Independent Mode index of headphone pin widget */ |
434 | AC_VERB_GET_CONNECT_LIST, 0) & 0xff; | 1179 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel |
435 | 1180 | ? 1 : 0; | |
436 | if (con_nid == spec->multiout.hp_nid) { | 1181 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel); |
437 | if (pinsel == 0) { | 1182 | |
438 | if (!spec->hp_independent_mode) { | 1183 | if (spec->multiout.hp_nid && spec->multiout.hp_nid |
439 | if (spec->multiout.num_dacs > 1) | 1184 | != spec->multiout.dac_nids[HDA_FRONT]) |
440 | spec->multiout.num_dacs -= 1; | 1185 | snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, |
441 | spec->hp_independent_mode = 1; | 1186 | 0, 0, 0); |
442 | } | 1187 | |
443 | } else if (pinsel == 1) { | 1188 | update_side_mute_status(codec); |
444 | if (spec->hp_independent_mode) { | 1189 | /* update HP volume/swtich active state */ |
445 | if (spec->multiout.num_dacs > 1) | 1190 | if (spec->codec_type == VT1708S |
446 | spec->multiout.num_dacs += 1; | 1191 | || spec->codec_type == VT1702 |
447 | spec->hp_independent_mode = 0; | 1192 | || spec->codec_type == VT1718S |
448 | } | 1193 | || spec->codec_type == VT1716S |
449 | } | 1194 | || spec->codec_type == VT2002P |
450 | } else { | 1195 | || spec->codec_type == VT1812) { |
451 | if (pinsel == 0) { | 1196 | activate_ctl(codec, "Headphone Playback Volume", |
452 | if (spec->hp_independent_mode) { | 1197 | spec->hp_independent_mode); |
453 | if (spec->multiout.num_dacs > 1) | 1198 | activate_ctl(codec, "Headphone Playback Switch", |
454 | spec->multiout.num_dacs += 1; | 1199 | spec->hp_independent_mode); |
455 | spec->hp_independent_mode = 0; | ||
456 | } | ||
457 | } else if (pinsel == 1) { | ||
458 | if (!spec->hp_independent_mode) { | ||
459 | if (spec->multiout.num_dacs > 1) | ||
460 | spec->multiout.num_dacs -= 1; | ||
461 | spec->hp_independent_mode = 1; | ||
462 | } | ||
463 | } | ||
464 | } | 1200 | } |
465 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, | ||
466 | pinsel); | ||
467 | |||
468 | if (spec->multiout.hp_nid && | ||
469 | spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT]) | ||
470 | snd_hda_codec_setup_stream(codec, | ||
471 | spec->multiout.hp_nid, | ||
472 | 0, 0, 0); | ||
473 | |||
474 | return 0; | 1201 | return 0; |
475 | } | 1202 | } |
476 | 1203 | ||
477 | static struct snd_kcontrol_new via_hp_mixer[] = { | 1204 | static struct snd_kcontrol_new via_hp_mixer[2] = { |
478 | { | 1205 | { |
479 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 1206 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
480 | .name = "Independent HP", | 1207 | .name = "Independent HP", |
481 | .count = 1, | ||
482 | .info = via_independent_hp_info, | 1208 | .info = via_independent_hp_info, |
483 | .get = via_independent_hp_get, | 1209 | .get = via_independent_hp_get, |
484 | .put = via_independent_hp_put, | 1210 | .put = via_independent_hp_put, |
485 | }, | 1211 | }, |
486 | { } /* end */ | 1212 | { |
1213 | .iface = NID_MAPPING, | ||
1214 | .name = "Independent HP", | ||
1215 | }, | ||
1216 | }; | ||
1217 | |||
1218 | static int via_hp_build(struct hda_codec *codec) | ||
1219 | { | ||
1220 | struct via_spec *spec = codec->spec; | ||
1221 | struct snd_kcontrol_new *knew; | ||
1222 | hda_nid_t nid; | ||
1223 | int nums; | ||
1224 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; | ||
1225 | |||
1226 | switch (spec->codec_type) { | ||
1227 | case VT1718S: | ||
1228 | nid = 0x34; | ||
1229 | break; | ||
1230 | case VT2002P: | ||
1231 | nid = 0x35; | ||
1232 | break; | ||
1233 | case VT1812: | ||
1234 | nid = 0x3d; | ||
1235 | break; | ||
1236 | default: | ||
1237 | nid = spec->autocfg.hp_pins[0]; | ||
1238 | break; | ||
1239 | } | ||
1240 | |||
1241 | nums = snd_hda_get_connections(codec, nid, conn, HDA_MAX_CONNECTIONS); | ||
1242 | if (nums <= 1) | ||
1243 | return 0; | ||
1244 | |||
1245 | knew = via_clone_control(spec, &via_hp_mixer[0]); | ||
1246 | if (knew == NULL) | ||
1247 | return -ENOMEM; | ||
1248 | |||
1249 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; | ||
1250 | knew->private_value = nid; | ||
1251 | |||
1252 | knew = via_clone_control(spec, &via_hp_mixer[1]); | ||
1253 | if (knew == NULL) | ||
1254 | return -ENOMEM; | ||
1255 | knew->subdevice = side_mute_channel(spec); | ||
1256 | |||
1257 | return 0; | ||
1258 | } | ||
1259 | |||
1260 | static void notify_aa_path_ctls(struct hda_codec *codec) | ||
1261 | { | ||
1262 | int i; | ||
1263 | struct snd_ctl_elem_id id; | ||
1264 | const char *labels[] = {"Mic", "Front Mic", "Line"}; | ||
1265 | |||
1266 | memset(&id, 0, sizeof(id)); | ||
1267 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
1268 | for (i = 0; i < ARRAY_SIZE(labels); i++) { | ||
1269 | sprintf(id.name, "%s Playback Volume", labels[i]); | ||
1270 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, | ||
1271 | &id); | ||
1272 | } | ||
1273 | } | ||
1274 | |||
1275 | static void mute_aa_path(struct hda_codec *codec, int mute) | ||
1276 | { | ||
1277 | struct via_spec *spec = codec->spec; | ||
1278 | hda_nid_t nid_mixer; | ||
1279 | int start_idx; | ||
1280 | int end_idx; | ||
1281 | int i; | ||
1282 | /* get nid of MW0 and start & end index */ | ||
1283 | switch (spec->codec_type) { | ||
1284 | case VT1708: | ||
1285 | nid_mixer = 0x17; | ||
1286 | start_idx = 2; | ||
1287 | end_idx = 4; | ||
1288 | break; | ||
1289 | case VT1709_10CH: | ||
1290 | case VT1709_6CH: | ||
1291 | nid_mixer = 0x18; | ||
1292 | start_idx = 2; | ||
1293 | end_idx = 4; | ||
1294 | break; | ||
1295 | case VT1708B_8CH: | ||
1296 | case VT1708B_4CH: | ||
1297 | case VT1708S: | ||
1298 | case VT1716S: | ||
1299 | nid_mixer = 0x16; | ||
1300 | start_idx = 2; | ||
1301 | end_idx = 4; | ||
1302 | break; | ||
1303 | default: | ||
1304 | return; | ||
1305 | } | ||
1306 | /* check AA path's mute status */ | ||
1307 | for (i = start_idx; i <= end_idx; i++) { | ||
1308 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; | ||
1309 | snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i, | ||
1310 | HDA_AMP_MUTE, val); | ||
1311 | } | ||
1312 | } | ||
1313 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin) | ||
1314 | { | ||
1315 | int res = 0; | ||
1316 | int index; | ||
1317 | for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) { | ||
1318 | if (pin == spec->autocfg.input_pins[index]) { | ||
1319 | res = 1; | ||
1320 | break; | ||
1321 | } | ||
1322 | } | ||
1323 | return res; | ||
1324 | } | ||
1325 | |||
1326 | static int via_smart51_info(struct snd_kcontrol *kcontrol, | ||
1327 | struct snd_ctl_elem_info *uinfo) | ||
1328 | { | ||
1329 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | ||
1330 | uinfo->count = 1; | ||
1331 | uinfo->value.integer.min = 0; | ||
1332 | uinfo->value.integer.max = 1; | ||
1333 | return 0; | ||
1334 | } | ||
1335 | |||
1336 | static int via_smart51_get(struct snd_kcontrol *kcontrol, | ||
1337 | struct snd_ctl_elem_value *ucontrol) | ||
1338 | { | ||
1339 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1340 | struct via_spec *spec = codec->spec; | ||
1341 | int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE }; | ||
1342 | int on = 1; | ||
1343 | int i; | ||
1344 | |||
1345 | for (i = 0; i < ARRAY_SIZE(index); i++) { | ||
1346 | hda_nid_t nid = spec->autocfg.input_pins[index[i]]; | ||
1347 | if (nid) { | ||
1348 | int ctl = | ||
1349 | snd_hda_codec_read(codec, nid, 0, | ||
1350 | AC_VERB_GET_PIN_WIDGET_CONTROL, | ||
1351 | 0); | ||
1352 | if (i == AUTO_PIN_FRONT_MIC | ||
1353 | && spec->hp_independent_mode | ||
1354 | && spec->codec_type != VT1718S) | ||
1355 | continue; /* ignore FMic for independent HP */ | ||
1356 | if (ctl & AC_PINCTL_IN_EN | ||
1357 | && !(ctl & AC_PINCTL_OUT_EN)) | ||
1358 | on = 0; | ||
1359 | } | ||
1360 | } | ||
1361 | *ucontrol->value.integer.value = on; | ||
1362 | return 0; | ||
1363 | } | ||
1364 | |||
1365 | static int via_smart51_put(struct snd_kcontrol *kcontrol, | ||
1366 | struct snd_ctl_elem_value *ucontrol) | ||
1367 | { | ||
1368 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
1369 | struct via_spec *spec = codec->spec; | ||
1370 | int out_in = *ucontrol->value.integer.value | ||
1371 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; | ||
1372 | int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE }; | ||
1373 | int i; | ||
1374 | |||
1375 | for (i = 0; i < ARRAY_SIZE(index); i++) { | ||
1376 | hda_nid_t nid = spec->autocfg.input_pins[index[i]]; | ||
1377 | if (i == AUTO_PIN_FRONT_MIC | ||
1378 | && spec->hp_independent_mode | ||
1379 | && spec->codec_type != VT1718S) | ||
1380 | continue; /* don't retask FMic for independent HP */ | ||
1381 | if (nid) { | ||
1382 | unsigned int parm = snd_hda_codec_read( | ||
1383 | codec, nid, 0, | ||
1384 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | ||
1385 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); | ||
1386 | parm |= out_in; | ||
1387 | snd_hda_codec_write(codec, nid, 0, | ||
1388 | AC_VERB_SET_PIN_WIDGET_CONTROL, | ||
1389 | parm); | ||
1390 | if (out_in == AC_PINCTL_OUT_EN) { | ||
1391 | mute_aa_path(codec, 1); | ||
1392 | notify_aa_path_ctls(codec); | ||
1393 | } | ||
1394 | if (spec->codec_type == VT1718S) | ||
1395 | snd_hda_codec_amp_stereo( | ||
1396 | codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
1397 | HDA_AMP_UNMUTE); | ||
1398 | } | ||
1399 | if (i == AUTO_PIN_FRONT_MIC) { | ||
1400 | if (spec->codec_type == VT1708S | ||
1401 | || spec->codec_type == VT1716S) { | ||
1402 | /* input = index 1 (AOW3) */ | ||
1403 | snd_hda_codec_write( | ||
1404 | codec, nid, 0, | ||
1405 | AC_VERB_SET_CONNECT_SEL, 1); | ||
1406 | snd_hda_codec_amp_stereo( | ||
1407 | codec, nid, HDA_OUTPUT, | ||
1408 | 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE); | ||
1409 | } | ||
1410 | } | ||
1411 | } | ||
1412 | spec->smart51_enabled = *ucontrol->value.integer.value; | ||
1413 | set_jack_power_state(codec); | ||
1414 | return 1; | ||
1415 | } | ||
1416 | |||
1417 | static struct snd_kcontrol_new via_smart51_mixer[2] = { | ||
1418 | { | ||
1419 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
1420 | .name = "Smart 5.1", | ||
1421 | .count = 1, | ||
1422 | .info = via_smart51_info, | ||
1423 | .get = via_smart51_get, | ||
1424 | .put = via_smart51_put, | ||
1425 | }, | ||
1426 | { | ||
1427 | .iface = NID_MAPPING, | ||
1428 | .name = "Smart 5.1", | ||
1429 | } | ||
487 | }; | 1430 | }; |
488 | 1431 | ||
1432 | static int via_smart51_build(struct via_spec *spec) | ||
1433 | { | ||
1434 | struct snd_kcontrol_new *knew; | ||
1435 | int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE }; | ||
1436 | hda_nid_t nid; | ||
1437 | int i; | ||
1438 | |||
1439 | knew = via_clone_control(spec, &via_smart51_mixer[0]); | ||
1440 | if (knew == NULL) | ||
1441 | return -ENOMEM; | ||
1442 | |||
1443 | for (i = 0; i < ARRAY_SIZE(index); i++) { | ||
1444 | nid = spec->autocfg.input_pins[index[i]]; | ||
1445 | if (nid) { | ||
1446 | knew = via_clone_control(spec, &via_smart51_mixer[1]); | ||
1447 | if (knew == NULL) | ||
1448 | return -ENOMEM; | ||
1449 | knew->subdevice = nid; | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | return 0; | ||
1454 | } | ||
1455 | |||
489 | /* capture mixer elements */ | 1456 | /* capture mixer elements */ |
490 | static struct snd_kcontrol_new vt1708_capture_mixer[] = { | 1457 | static struct snd_kcontrol_new vt1708_capture_mixer[] = { |
491 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), | 1458 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), |
@@ -506,6 +1473,112 @@ static struct snd_kcontrol_new vt1708_capture_mixer[] = { | |||
506 | }, | 1473 | }, |
507 | { } /* end */ | 1474 | { } /* end */ |
508 | }; | 1475 | }; |
1476 | |||
1477 | /* check AA path's mute statue */ | ||
1478 | static int is_aa_path_mute(struct hda_codec *codec) | ||
1479 | { | ||
1480 | int mute = 1; | ||
1481 | hda_nid_t nid_mixer; | ||
1482 | int start_idx; | ||
1483 | int end_idx; | ||
1484 | int i; | ||
1485 | struct via_spec *spec = codec->spec; | ||
1486 | /* get nid of MW0 and start & end index */ | ||
1487 | switch (spec->codec_type) { | ||
1488 | case VT1708B_8CH: | ||
1489 | case VT1708B_4CH: | ||
1490 | case VT1708S: | ||
1491 | case VT1716S: | ||
1492 | nid_mixer = 0x16; | ||
1493 | start_idx = 2; | ||
1494 | end_idx = 4; | ||
1495 | break; | ||
1496 | case VT1702: | ||
1497 | nid_mixer = 0x1a; | ||
1498 | start_idx = 1; | ||
1499 | end_idx = 3; | ||
1500 | break; | ||
1501 | case VT1718S: | ||
1502 | nid_mixer = 0x21; | ||
1503 | start_idx = 1; | ||
1504 | end_idx = 3; | ||
1505 | break; | ||
1506 | case VT2002P: | ||
1507 | case VT1812: | ||
1508 | nid_mixer = 0x21; | ||
1509 | start_idx = 0; | ||
1510 | end_idx = 2; | ||
1511 | break; | ||
1512 | default: | ||
1513 | return 0; | ||
1514 | } | ||
1515 | /* check AA path's mute status */ | ||
1516 | for (i = start_idx; i <= end_idx; i++) { | ||
1517 | unsigned int con_list = snd_hda_codec_read( | ||
1518 | codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); | ||
1519 | int shift = 8 * (i % 4); | ||
1520 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; | ||
1521 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); | ||
1522 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { | ||
1523 | /* check mute status while the pin is connected */ | ||
1524 | int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0, | ||
1525 | HDA_INPUT, i) >> 7; | ||
1526 | int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1, | ||
1527 | HDA_INPUT, i) >> 7; | ||
1528 | if (!mute_l || !mute_r) { | ||
1529 | mute = 0; | ||
1530 | break; | ||
1531 | } | ||
1532 | } | ||
1533 | } | ||
1534 | return mute; | ||
1535 | } | ||
1536 | |||
1537 | /* enter/exit analog low-current mode */ | ||
1538 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) | ||
1539 | { | ||
1540 | struct via_spec *spec = codec->spec; | ||
1541 | static int saved_stream_idle = 1; /* saved stream idle status */ | ||
1542 | int enable = is_aa_path_mute(codec); | ||
1543 | unsigned int verb = 0; | ||
1544 | unsigned int parm = 0; | ||
1545 | |||
1546 | if (stream_idle == -1) /* stream status did not change */ | ||
1547 | enable = enable && saved_stream_idle; | ||
1548 | else { | ||
1549 | enable = enable && stream_idle; | ||
1550 | saved_stream_idle = stream_idle; | ||
1551 | } | ||
1552 | |||
1553 | /* decide low current mode's verb & parameter */ | ||
1554 | switch (spec->codec_type) { | ||
1555 | case VT1708B_8CH: | ||
1556 | case VT1708B_4CH: | ||
1557 | verb = 0xf70; | ||
1558 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ | ||
1559 | break; | ||
1560 | case VT1708S: | ||
1561 | case VT1718S: | ||
1562 | case VT1716S: | ||
1563 | verb = 0xf73; | ||
1564 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ | ||
1565 | break; | ||
1566 | case VT1702: | ||
1567 | verb = 0xf73; | ||
1568 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ | ||
1569 | break; | ||
1570 | case VT2002P: | ||
1571 | case VT1812: | ||
1572 | verb = 0xf93; | ||
1573 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ | ||
1574 | break; | ||
1575 | default: | ||
1576 | return; /* other codecs are not supported */ | ||
1577 | } | ||
1578 | /* send verb */ | ||
1579 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); | ||
1580 | } | ||
1581 | |||
509 | /* | 1582 | /* |
510 | * generic initialization of ADC, input mixers and output mixers | 1583 | * generic initialization of ADC, input mixers and output mixers |
511 | */ | 1584 | */ |
@@ -534,9 +1607,9 @@ static struct hda_verb vt1708_volume_init_verbs[] = { | |||
534 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | 1607 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
535 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | 1608 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
536 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | 1609 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
537 | 1610 | ||
538 | /* Setup default input to PW4 */ | 1611 | /* Setup default input MW0 to PW4 */ |
539 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, | 1612 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
540 | /* PW9 Output enable */ | 1613 | /* PW9 Output enable */ |
541 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | 1614 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
542 | { } | 1615 | { } |
@@ -547,30 +1620,13 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, | |||
547 | struct snd_pcm_substream *substream) | 1620 | struct snd_pcm_substream *substream) |
548 | { | 1621 | { |
549 | struct via_spec *spec = codec->spec; | 1622 | struct via_spec *spec = codec->spec; |
1623 | int idle = substream->pstr->substream_opened == 1 | ||
1624 | && substream->ref_count == 0; | ||
1625 | analog_low_current_mode(codec, idle); | ||
550 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, | 1626 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
551 | hinfo); | 1627 | hinfo); |
552 | } | 1628 | } |
553 | 1629 | ||
554 | static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | ||
555 | struct hda_codec *codec, | ||
556 | unsigned int stream_tag, | ||
557 | unsigned int format, | ||
558 | struct snd_pcm_substream *substream) | ||
559 | { | ||
560 | struct via_spec *spec = codec->spec; | ||
561 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | ||
562 | stream_tag, format, substream); | ||
563 | } | ||
564 | |||
565 | static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | ||
566 | struct hda_codec *codec, | ||
567 | struct snd_pcm_substream *substream) | ||
568 | { | ||
569 | struct via_spec *spec = codec->spec; | ||
570 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | ||
571 | } | ||
572 | |||
573 | |||
574 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, | 1630 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, |
575 | unsigned int stream_tag, | 1631 | unsigned int stream_tag, |
576 | unsigned int format, | 1632 | unsigned int format, |
@@ -615,8 +1671,8 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec, | |||
615 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, | 1671 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
616 | 0, format); | 1672 | 0, format); |
617 | 1673 | ||
618 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && | 1674 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
619 | !spec->hp_independent_mode) | 1675 | && !spec->hp_independent_mode) |
620 | /* headphone out will just decode front left/right (stereo) */ | 1676 | /* headphone out will just decode front left/right (stereo) */ |
621 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, | 1677 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
622 | 0, format); | 1678 | 0, format); |
@@ -658,7 +1714,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, | |||
658 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | 1714 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
659 | stream_tag, 0, format); | 1715 | stream_tag, 0, format); |
660 | } | 1716 | } |
661 | 1717 | vt1708_start_hp_work(spec); | |
662 | return 0; | 1718 | return 0; |
663 | } | 1719 | } |
664 | 1720 | ||
@@ -698,7 +1754,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, | |||
698 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | 1754 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
699 | 0, 0, 0); | 1755 | 0, 0, 0); |
700 | } | 1756 | } |
701 | 1757 | vt1708_stop_hp_work(spec); | |
702 | return 0; | 1758 | return 0; |
703 | } | 1759 | } |
704 | 1760 | ||
@@ -779,7 +1835,7 @@ static struct hda_pcm_stream vt1708_pcm_analog_playback = { | |||
779 | }; | 1835 | }; |
780 | 1836 | ||
781 | static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { | 1837 | static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
782 | .substreams = 1, | 1838 | .substreams = 2, |
783 | .channels_min = 2, | 1839 | .channels_min = 2, |
784 | .channels_max = 8, | 1840 | .channels_max = 8, |
785 | .nid = 0x10, /* NID to query formats and rates */ | 1841 | .nid = 0x10, /* NID to query formats and rates */ |
@@ -790,8 +1846,8 @@ static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { | |||
790 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | 1846 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
791 | .ops = { | 1847 | .ops = { |
792 | .open = via_playback_pcm_open, | 1848 | .open = via_playback_pcm_open, |
793 | .prepare = via_playback_pcm_prepare, | 1849 | .prepare = via_playback_multi_pcm_prepare, |
794 | .cleanup = via_playback_pcm_cleanup | 1850 | .cleanup = via_playback_multi_pcm_cleanup |
795 | }, | 1851 | }, |
796 | }; | 1852 | }; |
797 | 1853 | ||
@@ -828,8 +1884,9 @@ static struct hda_pcm_stream vt1708_pcm_digital_capture = { | |||
828 | static int via_build_controls(struct hda_codec *codec) | 1884 | static int via_build_controls(struct hda_codec *codec) |
829 | { | 1885 | { |
830 | struct via_spec *spec = codec->spec; | 1886 | struct via_spec *spec = codec->spec; |
831 | int err; | 1887 | struct snd_kcontrol *kctl; |
832 | int i; | 1888 | struct snd_kcontrol_new *knew; |
1889 | int err, i; | ||
833 | 1890 | ||
834 | for (i = 0; i < spec->num_mixers; i++) { | 1891 | for (i = 0; i < spec->num_mixers; i++) { |
835 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | 1892 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
@@ -853,6 +1910,32 @@ static int via_build_controls(struct hda_codec *codec) | |||
853 | if (err < 0) | 1910 | if (err < 0) |
854 | return err; | 1911 | return err; |
855 | } | 1912 | } |
1913 | |||
1914 | /* assign Capture Source enums to NID */ | ||
1915 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); | ||
1916 | for (i = 0; kctl && i < kctl->count; i++) { | ||
1917 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); | ||
1918 | if (err < 0) | ||
1919 | return err; | ||
1920 | } | ||
1921 | |||
1922 | /* other nid->control mapping */ | ||
1923 | for (i = 0; i < spec->num_mixers; i++) { | ||
1924 | for (knew = spec->mixers[i]; knew->name; knew++) { | ||
1925 | if (knew->iface != NID_MAPPING) | ||
1926 | continue; | ||
1927 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); | ||
1928 | if (kctl == NULL) | ||
1929 | continue; | ||
1930 | err = snd_hda_add_nid(codec, kctl, 0, | ||
1931 | knew->subdevice); | ||
1932 | } | ||
1933 | } | ||
1934 | |||
1935 | /* init power states */ | ||
1936 | set_jack_power_state(codec); | ||
1937 | analog_low_current_mode(codec, 1); | ||
1938 | |||
856 | via_free_kctls(codec); /* no longer needed */ | 1939 | via_free_kctls(codec); /* no longer needed */ |
857 | return 0; | 1940 | return 0; |
858 | } | 1941 | } |
@@ -866,8 +1949,10 @@ static int via_build_pcms(struct hda_codec *codec) | |||
866 | codec->pcm_info = info; | 1949 | codec->pcm_info = info; |
867 | 1950 | ||
868 | info->name = spec->stream_name_analog; | 1951 | info->name = spec->stream_name_analog; |
869 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); | 1952 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
870 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; | 1953 | *(spec->stream_analog_playback); |
1954 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | ||
1955 | spec->multiout.dac_nids[0]; | ||
871 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); | 1956 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); |
872 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | 1957 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
873 | 1958 | ||
@@ -904,20 +1989,58 @@ static void via_free(struct hda_codec *codec) | |||
904 | return; | 1989 | return; |
905 | 1990 | ||
906 | via_free_kctls(codec); | 1991 | via_free_kctls(codec); |
1992 | vt1708_stop_hp_work(spec); | ||
907 | kfree(codec->spec); | 1993 | kfree(codec->spec); |
908 | } | 1994 | } |
909 | 1995 | ||
910 | /* mute internal speaker if HP is plugged */ | 1996 | /* mute internal speaker if HP is plugged */ |
911 | static void via_hp_automute(struct hda_codec *codec) | 1997 | static void via_hp_automute(struct hda_codec *codec) |
912 | { | 1998 | { |
913 | unsigned int present; | 1999 | unsigned int present = 0; |
914 | struct via_spec *spec = codec->spec; | 2000 | struct via_spec *spec = codec->spec; |
915 | 2001 | ||
916 | present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, | 2002 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
917 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | 2003 | |
918 | snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], | 2004 | if (!spec->hp_independent_mode) { |
919 | HDA_OUTPUT, 0, HDA_AMP_MUTE, | 2005 | struct snd_ctl_elem_id id; |
920 | present ? HDA_AMP_MUTE : 0); | 2006 | /* auto mute */ |
2007 | snd_hda_codec_amp_stereo( | ||
2008 | codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0, | ||
2009 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); | ||
2010 | /* notify change */ | ||
2011 | memset(&id, 0, sizeof(id)); | ||
2012 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
2013 | strcpy(id.name, "Front Playback Switch"); | ||
2014 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, | ||
2015 | &id); | ||
2016 | } | ||
2017 | } | ||
2018 | |||
2019 | /* mute mono out if HP or Line out is plugged */ | ||
2020 | static void via_mono_automute(struct hda_codec *codec) | ||
2021 | { | ||
2022 | unsigned int hp_present, lineout_present; | ||
2023 | struct via_spec *spec = codec->spec; | ||
2024 | |||
2025 | if (spec->codec_type != VT1716S) | ||
2026 | return; | ||
2027 | |||
2028 | lineout_present = snd_hda_jack_detect(codec, | ||
2029 | spec->autocfg.line_out_pins[0]); | ||
2030 | |||
2031 | /* Mute Mono Out if Line Out is plugged */ | ||
2032 | if (lineout_present) { | ||
2033 | snd_hda_codec_amp_stereo( | ||
2034 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE); | ||
2035 | return; | ||
2036 | } | ||
2037 | |||
2038 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); | ||
2039 | |||
2040 | if (!spec->hp_independent_mode) | ||
2041 | snd_hda_codec_amp_stereo( | ||
2042 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, | ||
2043 | hp_present ? HDA_AMP_MUTE : 0); | ||
921 | } | 2044 | } |
922 | 2045 | ||
923 | static void via_gpio_control(struct hda_codec *codec) | 2046 | static void via_gpio_control(struct hda_codec *codec) |
@@ -968,15 +2091,83 @@ static void via_gpio_control(struct hda_codec *codec) | |||
968 | } | 2091 | } |
969 | } | 2092 | } |
970 | 2093 | ||
2094 | /* mute Internal-Speaker if HP is plugged */ | ||
2095 | static void via_speaker_automute(struct hda_codec *codec) | ||
2096 | { | ||
2097 | unsigned int hp_present; | ||
2098 | struct via_spec *spec = codec->spec; | ||
2099 | |||
2100 | if (spec->codec_type != VT2002P && spec->codec_type != VT1812) | ||
2101 | return; | ||
2102 | |||
2103 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); | ||
2104 | |||
2105 | if (!spec->hp_independent_mode) { | ||
2106 | struct snd_ctl_elem_id id; | ||
2107 | snd_hda_codec_amp_stereo( | ||
2108 | codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0, | ||
2109 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); | ||
2110 | /* notify change */ | ||
2111 | memset(&id, 0, sizeof(id)); | ||
2112 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | ||
2113 | strcpy(id.name, "Speaker Playback Switch"); | ||
2114 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, | ||
2115 | &id); | ||
2116 | } | ||
2117 | } | ||
2118 | |||
2119 | /* mute line-out and internal speaker if HP is plugged */ | ||
2120 | static void via_hp_bind_automute(struct hda_codec *codec) | ||
2121 | { | ||
2122 | /* use long instead of int below just to avoid an internal compiler | ||
2123 | * error with gcc 4.0.x | ||
2124 | */ | ||
2125 | unsigned long hp_present, present = 0; | ||
2126 | struct via_spec *spec = codec->spec; | ||
2127 | int i; | ||
2128 | |||
2129 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) | ||
2130 | return; | ||
2131 | |||
2132 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); | ||
2133 | |||
2134 | present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]); | ||
2135 | |||
2136 | if (!spec->hp_independent_mode) { | ||
2137 | /* Mute Line-Outs */ | ||
2138 | for (i = 0; i < spec->autocfg.line_outs; i++) | ||
2139 | snd_hda_codec_amp_stereo( | ||
2140 | codec, spec->autocfg.line_out_pins[i], | ||
2141 | HDA_OUTPUT, 0, | ||
2142 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); | ||
2143 | if (hp_present) | ||
2144 | present = hp_present; | ||
2145 | } | ||
2146 | /* Speakers */ | ||
2147 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | ||
2148 | snd_hda_codec_amp_stereo( | ||
2149 | codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0, | ||
2150 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); | ||
2151 | } | ||
2152 | |||
2153 | |||
971 | /* unsolicited event for jack sensing */ | 2154 | /* unsolicited event for jack sensing */ |
972 | static void via_unsol_event(struct hda_codec *codec, | 2155 | static void via_unsol_event(struct hda_codec *codec, |
973 | unsigned int res) | 2156 | unsigned int res) |
974 | { | 2157 | { |
975 | res >>= 26; | 2158 | res >>= 26; |
976 | if (res == VIA_HP_EVENT) | 2159 | if (res & VIA_HP_EVENT) |
977 | via_hp_automute(codec); | 2160 | via_hp_automute(codec); |
978 | else if (res == VIA_GPIO_EVENT) | 2161 | if (res & VIA_GPIO_EVENT) |
979 | via_gpio_control(codec); | 2162 | via_gpio_control(codec); |
2163 | if (res & VIA_JACK_EVENT) | ||
2164 | set_jack_power_state(codec); | ||
2165 | if (res & VIA_MONO_EVENT) | ||
2166 | via_mono_automute(codec); | ||
2167 | if (res & VIA_SPEAKER_EVENT) | ||
2168 | via_speaker_automute(codec); | ||
2169 | if (res & VIA_BIND_HP_EVENT) | ||
2170 | via_hp_bind_automute(codec); | ||
980 | } | 2171 | } |
981 | 2172 | ||
982 | static int via_init(struct hda_codec *codec) | 2173 | static int via_init(struct hda_codec *codec) |
@@ -986,6 +2177,10 @@ static int via_init(struct hda_codec *codec) | |||
986 | for (i = 0; i < spec->num_iverbs; i++) | 2177 | for (i = 0; i < spec->num_iverbs; i++) |
987 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | 2178 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
988 | 2179 | ||
2180 | spec->codec_type = get_codec_type(codec); | ||
2181 | if (spec->codec_type == VT1708BCE) | ||
2182 | spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost | ||
2183 | same */ | ||
989 | /* Lydia Add for EAPD enable */ | 2184 | /* Lydia Add for EAPD enable */ |
990 | if (!spec->dig_in_nid) { /* No Digital In connection */ | 2185 | if (!spec->dig_in_nid) { /* No Digital In connection */ |
991 | if (spec->dig_in_pin) { | 2186 | if (spec->dig_in_pin) { |
@@ -1003,9 +2198,18 @@ static int via_init(struct hda_codec *codec) | |||
1003 | if (spec->slave_dig_outs[0]) | 2198 | if (spec->slave_dig_outs[0]) |
1004 | codec->slave_dig_outs = spec->slave_dig_outs; | 2199 | codec->slave_dig_outs = spec->slave_dig_outs; |
1005 | 2200 | ||
1006 | return 0; | 2201 | return 0; |
1007 | } | 2202 | } |
1008 | 2203 | ||
2204 | #ifdef SND_HDA_NEEDS_RESUME | ||
2205 | static int via_suspend(struct hda_codec *codec, pm_message_t state) | ||
2206 | { | ||
2207 | struct via_spec *spec = codec->spec; | ||
2208 | vt1708_stop_hp_work(spec); | ||
2209 | return 0; | ||
2210 | } | ||
2211 | #endif | ||
2212 | |||
1009 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 2213 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1010 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) | 2214 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
1011 | { | 2215 | { |
@@ -1021,6 +2225,9 @@ static struct hda_codec_ops via_patch_ops = { | |||
1021 | .build_pcms = via_build_pcms, | 2225 | .build_pcms = via_build_pcms, |
1022 | .init = via_init, | 2226 | .init = via_init, |
1023 | .free = via_free, | 2227 | .free = via_free, |
2228 | #ifdef SND_HDA_NEEDS_RESUME | ||
2229 | .suspend = via_suspend, | ||
2230 | #endif | ||
1024 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 2231 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1025 | .check_power_status = via_check_power_status, | 2232 | .check_power_status = via_check_power_status, |
1026 | #endif | 2233 | #endif |
@@ -1036,8 +2243,8 @@ static int vt1708_auto_fill_dac_nids(struct via_spec *spec, | |||
1036 | spec->multiout.num_dacs = cfg->line_outs; | 2243 | spec->multiout.num_dacs = cfg->line_outs; |
1037 | 2244 | ||
1038 | spec->multiout.dac_nids = spec->private_dac_nids; | 2245 | spec->multiout.dac_nids = spec->private_dac_nids; |
1039 | 2246 | ||
1040 | for(i = 0; i < 4; i++) { | 2247 | for (i = 0; i < 4; i++) { |
1041 | nid = cfg->line_out_pins[i]; | 2248 | nid = cfg->line_out_pins[i]; |
1042 | if (nid) { | 2249 | if (nid) { |
1043 | /* config dac list */ | 2250 | /* config dac list */ |
@@ -1067,7 +2274,7 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, | |||
1067 | { | 2274 | { |
1068 | char name[32]; | 2275 | char name[32]; |
1069 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | 2276 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
1070 | hda_nid_t nid, nid_vol = 0; | 2277 | hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b}; |
1071 | int i, err; | 2278 | int i, err; |
1072 | 2279 | ||
1073 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | 2280 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
@@ -1075,9 +2282,8 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, | |||
1075 | 2282 | ||
1076 | if (!nid) | 2283 | if (!nid) |
1077 | continue; | 2284 | continue; |
1078 | 2285 | ||
1079 | if (i != AUTO_SEQ_FRONT) | 2286 | nid_vol = nid_vols[i]; |
1080 | nid_vol = 0x18 + i; | ||
1081 | 2287 | ||
1082 | if (i == AUTO_SEQ_CENLFE) { | 2288 | if (i == AUTO_SEQ_CENLFE) { |
1083 | /* Center/LFE */ | 2289 | /* Center/LFE */ |
@@ -1105,21 +2311,21 @@ static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, | |||
1105 | HDA_OUTPUT)); | 2311 | HDA_OUTPUT)); |
1106 | if (err < 0) | 2312 | if (err < 0) |
1107 | return err; | 2313 | return err; |
1108 | } else if (i == AUTO_SEQ_FRONT){ | 2314 | } else if (i == AUTO_SEQ_FRONT) { |
1109 | /* add control to mixer index 0 */ | 2315 | /* add control to mixer index 0 */ |
1110 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 2316 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
1111 | "Master Front Playback Volume", | 2317 | "Master Front Playback Volume", |
1112 | HDA_COMPOSE_AMP_VAL(0x17, 3, 0, | 2318 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1113 | HDA_INPUT)); | 2319 | HDA_INPUT)); |
1114 | if (err < 0) | 2320 | if (err < 0) |
1115 | return err; | 2321 | return err; |
1116 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | 2322 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
1117 | "Master Front Playback Switch", | 2323 | "Master Front Playback Switch", |
1118 | HDA_COMPOSE_AMP_VAL(0x17, 3, 0, | 2324 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1119 | HDA_INPUT)); | 2325 | HDA_INPUT)); |
1120 | if (err < 0) | 2326 | if (err < 0) |
1121 | return err; | 2327 | return err; |
1122 | 2328 | ||
1123 | /* add control to PW3 */ | 2329 | /* add control to PW3 */ |
1124 | sprintf(name, "%s Playback Volume", chname[i]); | 2330 | sprintf(name, "%s Playback Volume", chname[i]); |
1125 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | 2331 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
@@ -1178,6 +2384,7 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |||
1178 | return 0; | 2384 | return 0; |
1179 | 2385 | ||
1180 | spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ | 2386 | spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ |
2387 | spec->hp_independent_mode_index = 1; | ||
1181 | 2388 | ||
1182 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 2389 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
1183 | "Headphone Playback Volume", | 2390 | "Headphone Playback Volume", |
@@ -1218,7 +2425,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec, | |||
1218 | case 0x1d: /* Mic */ | 2425 | case 0x1d: /* Mic */ |
1219 | idx = 2; | 2426 | idx = 2; |
1220 | break; | 2427 | break; |
1221 | 2428 | ||
1222 | case 0x1e: /* Line In */ | 2429 | case 0x1e: /* Line In */ |
1223 | idx = 3; | 2430 | idx = 3; |
1224 | break; | 2431 | break; |
@@ -1231,8 +2438,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec, | |||
1231 | idx = 1; | 2438 | idx = 1; |
1232 | break; | 2439 | break; |
1233 | } | 2440 | } |
1234 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | 2441 | err = via_new_analog_input(spec, labels[i], idx, 0x17); |
1235 | idx, 0x17); | ||
1236 | if (err < 0) | 2442 | if (err < 0) |
1237 | return err; | 2443 | return err; |
1238 | imux->items[imux->num_items].label = labels[i]; | 2444 | imux->items[imux->num_items].label = labels[i]; |
@@ -1260,16 +2466,60 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) | |||
1260 | def_conf = snd_hda_codec_get_pincfg(codec, nid); | 2466 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
1261 | seqassoc = (unsigned char) get_defcfg_association(def_conf); | 2467 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
1262 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); | 2468 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
1263 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { | 2469 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
1264 | if (seqassoc == 0xff) { | 2470 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
1265 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); | 2471 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
1266 | snd_hda_codec_set_pincfg(codec, nid, def_conf); | 2472 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
1267 | } | ||
1268 | } | 2473 | } |
1269 | 2474 | ||
1270 | return; | 2475 | return; |
1271 | } | 2476 | } |
1272 | 2477 | ||
2478 | static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol, | ||
2479 | struct snd_ctl_elem_value *ucontrol) | ||
2480 | { | ||
2481 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2482 | struct via_spec *spec = codec->spec; | ||
2483 | |||
2484 | if (spec->codec_type != VT1708) | ||
2485 | return 0; | ||
2486 | spec->vt1708_jack_detectect = | ||
2487 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); | ||
2488 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect; | ||
2489 | return 0; | ||
2490 | } | ||
2491 | |||
2492 | static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol, | ||
2493 | struct snd_ctl_elem_value *ucontrol) | ||
2494 | { | ||
2495 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
2496 | struct via_spec *spec = codec->spec; | ||
2497 | int change; | ||
2498 | |||
2499 | if (spec->codec_type != VT1708) | ||
2500 | return 0; | ||
2501 | spec->vt1708_jack_detectect = ucontrol->value.integer.value[0]; | ||
2502 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) | ||
2503 | == !spec->vt1708_jack_detectect; | ||
2504 | if (spec->vt1708_jack_detectect) { | ||
2505 | mute_aa_path(codec, 1); | ||
2506 | notify_aa_path_ctls(codec); | ||
2507 | } | ||
2508 | return change; | ||
2509 | } | ||
2510 | |||
2511 | static struct snd_kcontrol_new vt1708_jack_detectect[] = { | ||
2512 | { | ||
2513 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
2514 | .name = "Jack Detect", | ||
2515 | .count = 1, | ||
2516 | .info = snd_ctl_boolean_mono_info, | ||
2517 | .get = vt1708_jack_detectect_get, | ||
2518 | .put = vt1708_jack_detectect_put, | ||
2519 | }, | ||
2520 | {} /* end */ | ||
2521 | }; | ||
2522 | |||
1273 | static int vt1708_parse_auto_config(struct hda_codec *codec) | 2523 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
1274 | { | 2524 | { |
1275 | struct via_spec *spec = codec->spec; | 2525 | struct via_spec *spec = codec->spec; |
@@ -1297,6 +2547,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) | |||
1297 | err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); | 2547 | err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); |
1298 | if (err < 0) | 2548 | if (err < 0) |
1299 | return err; | 2549 | return err; |
2550 | /* add jack detect on/off control */ | ||
2551 | err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect); | ||
2552 | if (err < 0) | ||
2553 | return err; | ||
1300 | 2554 | ||
1301 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | 2555 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
1302 | 2556 | ||
@@ -1314,21 +2568,46 @@ static int vt1708_parse_auto_config(struct hda_codec *codec) | |||
1314 | spec->input_mux = &spec->private_imux[0]; | 2568 | spec->input_mux = &spec->private_imux[0]; |
1315 | 2569 | ||
1316 | if (spec->hp_mux) | 2570 | if (spec->hp_mux) |
1317 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | 2571 | via_hp_build(codec); |
1318 | 2572 | ||
2573 | via_smart51_build(spec); | ||
1319 | return 1; | 2574 | return 1; |
1320 | } | 2575 | } |
1321 | 2576 | ||
1322 | /* init callback for auto-configuration model -- overriding the default init */ | 2577 | /* init callback for auto-configuration model -- overriding the default init */ |
1323 | static int via_auto_init(struct hda_codec *codec) | 2578 | static int via_auto_init(struct hda_codec *codec) |
1324 | { | 2579 | { |
2580 | struct via_spec *spec = codec->spec; | ||
2581 | |||
1325 | via_init(codec); | 2582 | via_init(codec); |
1326 | via_auto_init_multi_out(codec); | 2583 | via_auto_init_multi_out(codec); |
1327 | via_auto_init_hp_out(codec); | 2584 | via_auto_init_hp_out(codec); |
1328 | via_auto_init_analog_input(codec); | 2585 | via_auto_init_analog_input(codec); |
2586 | if (spec->codec_type == VT2002P || spec->codec_type == VT1812) { | ||
2587 | via_hp_bind_automute(codec); | ||
2588 | } else { | ||
2589 | via_hp_automute(codec); | ||
2590 | via_speaker_automute(codec); | ||
2591 | } | ||
2592 | |||
1329 | return 0; | 2593 | return 0; |
1330 | } | 2594 | } |
1331 | 2595 | ||
2596 | static void vt1708_update_hp_jack_state(struct work_struct *work) | ||
2597 | { | ||
2598 | struct via_spec *spec = container_of(work, struct via_spec, | ||
2599 | vt1708_hp_work.work); | ||
2600 | if (spec->codec_type != VT1708) | ||
2601 | return; | ||
2602 | /* if jack state toggled */ | ||
2603 | if (spec->vt1708_hp_present | ||
2604 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { | ||
2605 | spec->vt1708_hp_present ^= 1; | ||
2606 | via_hp_automute(spec->codec); | ||
2607 | } | ||
2608 | vt1708_start_hp_work(spec); | ||
2609 | } | ||
2610 | |||
1332 | static int get_mux_nids(struct hda_codec *codec) | 2611 | static int get_mux_nids(struct hda_codec *codec) |
1333 | { | 2612 | { |
1334 | struct via_spec *spec = codec->spec; | 2613 | struct via_spec *spec = codec->spec; |
@@ -1362,12 +2641,10 @@ static int patch_vt1708(struct hda_codec *codec) | |||
1362 | int err; | 2641 | int err; |
1363 | 2642 | ||
1364 | /* create a codec specific record */ | 2643 | /* create a codec specific record */ |
1365 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 2644 | spec = via_new_spec(codec); |
1366 | if (spec == NULL) | 2645 | if (spec == NULL) |
1367 | return -ENOMEM; | 2646 | return -ENOMEM; |
1368 | 2647 | ||
1369 | codec->spec = spec; | ||
1370 | |||
1371 | /* automatic parse from the BIOS config */ | 2648 | /* automatic parse from the BIOS config */ |
1372 | err = vt1708_parse_auto_config(codec); | 2649 | err = vt1708_parse_auto_config(codec); |
1373 | if (err < 0) { | 2650 | if (err < 0) { |
@@ -1378,7 +2655,7 @@ static int patch_vt1708(struct hda_codec *codec) | |||
1378 | "from BIOS. Using genenic mode...\n"); | 2655 | "from BIOS. Using genenic mode...\n"); |
1379 | } | 2656 | } |
1380 | 2657 | ||
1381 | 2658 | ||
1382 | spec->stream_name_analog = "VT1708 Analog"; | 2659 | spec->stream_name_analog = "VT1708 Analog"; |
1383 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; | 2660 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; |
1384 | /* disable 32bit format on VT1708 */ | 2661 | /* disable 32bit format on VT1708 */ |
@@ -1390,7 +2667,7 @@ static int patch_vt1708(struct hda_codec *codec) | |||
1390 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; | 2667 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; |
1391 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; | 2668 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; |
1392 | 2669 | ||
1393 | 2670 | ||
1394 | if (!spec->adc_nids && spec->input_mux) { | 2671 | if (!spec->adc_nids && spec->input_mux) { |
1395 | spec->adc_nids = vt1708_adc_nids; | 2672 | spec->adc_nids = vt1708_adc_nids; |
1396 | spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); | 2673 | spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); |
@@ -1405,7 +2682,7 @@ static int patch_vt1708(struct hda_codec *codec) | |||
1405 | #ifdef CONFIG_SND_HDA_POWER_SAVE | 2682 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1406 | spec->loopback.amplist = vt1708_loopbacks; | 2683 | spec->loopback.amplist = vt1708_loopbacks; |
1407 | #endif | 2684 | #endif |
1408 | 2685 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); | |
1409 | return 0; | 2686 | return 0; |
1410 | } | 2687 | } |
1411 | 2688 | ||
@@ -1433,7 +2710,8 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = { | |||
1433 | }; | 2710 | }; |
1434 | 2711 | ||
1435 | static struct hda_verb vt1709_uniwill_init_verbs[] = { | 2712 | static struct hda_verb vt1709_uniwill_init_verbs[] = { |
1436 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | 2713 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
2714 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | ||
1437 | { } | 2715 | { } |
1438 | }; | 2716 | }; |
1439 | 2717 | ||
@@ -1473,8 +2751,8 @@ static struct hda_verb vt1709_10ch_volume_init_verbs[] = { | |||
1473 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | 2751 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
1474 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | 2752 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
1475 | 2753 | ||
1476 | /* Set input of PW4 as AOW4 */ | 2754 | /* Set input of PW4 as MW0 */ |
1477 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, | 2755 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
1478 | /* PW9 Output enable */ | 2756 | /* PW9 Output enable */ |
1479 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | 2757 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
1480 | { } | 2758 | { } |
@@ -1487,8 +2765,8 @@ static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { | |||
1487 | .nid = 0x10, /* NID to query formats and rates */ | 2765 | .nid = 0x10, /* NID to query formats and rates */ |
1488 | .ops = { | 2766 | .ops = { |
1489 | .open = via_playback_pcm_open, | 2767 | .open = via_playback_pcm_open, |
1490 | .prepare = via_playback_pcm_prepare, | 2768 | .prepare = via_playback_multi_pcm_prepare, |
1491 | .cleanup = via_playback_pcm_cleanup | 2769 | .cleanup = via_playback_multi_pcm_cleanup, |
1492 | }, | 2770 | }, |
1493 | }; | 2771 | }; |
1494 | 2772 | ||
@@ -1499,8 +2777,8 @@ static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { | |||
1499 | .nid = 0x10, /* NID to query formats and rates */ | 2777 | .nid = 0x10, /* NID to query formats and rates */ |
1500 | .ops = { | 2778 | .ops = { |
1501 | .open = via_playback_pcm_open, | 2779 | .open = via_playback_pcm_open, |
1502 | .prepare = via_playback_pcm_prepare, | 2780 | .prepare = via_playback_multi_pcm_prepare, |
1503 | .cleanup = via_playback_pcm_cleanup | 2781 | .cleanup = via_playback_multi_pcm_cleanup, |
1504 | }, | 2782 | }, |
1505 | }; | 2783 | }; |
1506 | 2784 | ||
@@ -1575,11 +2853,11 @@ static int vt1709_auto_fill_dac_nids(struct via_spec *spec, | |||
1575 | spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ | 2853 | spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ |
1576 | 2854 | ||
1577 | } else if (cfg->line_outs == 3) { /* 6 channels */ | 2855 | } else if (cfg->line_outs == 3) { /* 6 channels */ |
1578 | for(i = 0; i < cfg->line_outs; i++) { | 2856 | for (i = 0; i < cfg->line_outs; i++) { |
1579 | nid = cfg->line_out_pins[i]; | 2857 | nid = cfg->line_out_pins[i]; |
1580 | if (nid) { | 2858 | if (nid) { |
1581 | /* config dac list */ | 2859 | /* config dac list */ |
1582 | switch(i) { | 2860 | switch (i) { |
1583 | case AUTO_SEQ_FRONT: | 2861 | case AUTO_SEQ_FRONT: |
1584 | /* AOW0 */ | 2862 | /* AOW0 */ |
1585 | spec->multiout.dac_nids[i] = 0x10; | 2863 | spec->multiout.dac_nids[i] = 0x10; |
@@ -1608,56 +2886,58 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, | |||
1608 | { | 2886 | { |
1609 | char name[32]; | 2887 | char name[32]; |
1610 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | 2888 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
1611 | hda_nid_t nid = 0; | 2889 | hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29}; |
1612 | int i, err; | 2890 | int i, err; |
1613 | 2891 | ||
1614 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | 2892 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
1615 | nid = cfg->line_out_pins[i]; | 2893 | nid = cfg->line_out_pins[i]; |
1616 | 2894 | ||
1617 | if (!nid) | 2895 | if (!nid) |
1618 | continue; | 2896 | continue; |
1619 | 2897 | ||
2898 | nid_vol = nid_vols[i]; | ||
2899 | |||
1620 | if (i == AUTO_SEQ_CENLFE) { | 2900 | if (i == AUTO_SEQ_CENLFE) { |
1621 | /* Center/LFE */ | 2901 | /* Center/LFE */ |
1622 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 2902 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
1623 | "Center Playback Volume", | 2903 | "Center Playback Volume", |
1624 | HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, | 2904 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
1625 | HDA_OUTPUT)); | 2905 | HDA_OUTPUT)); |
1626 | if (err < 0) | 2906 | if (err < 0) |
1627 | return err; | 2907 | return err; |
1628 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 2908 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
1629 | "LFE Playback Volume", | 2909 | "LFE Playback Volume", |
1630 | HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, | 2910 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
1631 | HDA_OUTPUT)); | 2911 | HDA_OUTPUT)); |
1632 | if (err < 0) | 2912 | if (err < 0) |
1633 | return err; | 2913 | return err; |
1634 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | 2914 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
1635 | "Center Playback Switch", | 2915 | "Center Playback Switch", |
1636 | HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, | 2916 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
1637 | HDA_OUTPUT)); | 2917 | HDA_OUTPUT)); |
1638 | if (err < 0) | 2918 | if (err < 0) |
1639 | return err; | 2919 | return err; |
1640 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | 2920 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
1641 | "LFE Playback Switch", | 2921 | "LFE Playback Switch", |
1642 | HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, | 2922 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
1643 | HDA_OUTPUT)); | 2923 | HDA_OUTPUT)); |
1644 | if (err < 0) | 2924 | if (err < 0) |
1645 | return err; | 2925 | return err; |
1646 | } else if (i == AUTO_SEQ_FRONT){ | 2926 | } else if (i == AUTO_SEQ_FRONT) { |
1647 | /* add control to mixer index 0 */ | 2927 | /* ADD control to mixer index 0 */ |
1648 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 2928 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
1649 | "Master Front Playback Volume", | 2929 | "Master Front Playback Volume", |
1650 | HDA_COMPOSE_AMP_VAL(0x18, 3, 0, | 2930 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1651 | HDA_INPUT)); | 2931 | HDA_INPUT)); |
1652 | if (err < 0) | 2932 | if (err < 0) |
1653 | return err; | 2933 | return err; |
1654 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | 2934 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
1655 | "Master Front Playback Switch", | 2935 | "Master Front Playback Switch", |
1656 | HDA_COMPOSE_AMP_VAL(0x18, 3, 0, | 2936 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1657 | HDA_INPUT)); | 2937 | HDA_INPUT)); |
1658 | if (err < 0) | 2938 | if (err < 0) |
1659 | return err; | 2939 | return err; |
1660 | 2940 | ||
1661 | /* add control to PW3 */ | 2941 | /* add control to PW3 */ |
1662 | sprintf(name, "%s Playback Volume", chname[i]); | 2942 | sprintf(name, "%s Playback Volume", chname[i]); |
1663 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | 2943 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
@@ -1674,26 +2954,26 @@ static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, | |||
1674 | } else if (i == AUTO_SEQ_SURROUND) { | 2954 | } else if (i == AUTO_SEQ_SURROUND) { |
1675 | sprintf(name, "%s Playback Volume", chname[i]); | 2955 | sprintf(name, "%s Playback Volume", chname[i]); |
1676 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | 2956 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
1677 | HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, | 2957 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1678 | HDA_OUTPUT)); | 2958 | HDA_OUTPUT)); |
1679 | if (err < 0) | 2959 | if (err < 0) |
1680 | return err; | 2960 | return err; |
1681 | sprintf(name, "%s Playback Switch", chname[i]); | 2961 | sprintf(name, "%s Playback Switch", chname[i]); |
1682 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | 2962 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
1683 | HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, | 2963 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1684 | HDA_OUTPUT)); | 2964 | HDA_OUTPUT)); |
1685 | if (err < 0) | 2965 | if (err < 0) |
1686 | return err; | 2966 | return err; |
1687 | } else if (i == AUTO_SEQ_SIDE) { | 2967 | } else if (i == AUTO_SEQ_SIDE) { |
1688 | sprintf(name, "%s Playback Volume", chname[i]); | 2968 | sprintf(name, "%s Playback Volume", chname[i]); |
1689 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | 2969 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
1690 | HDA_COMPOSE_AMP_VAL(0x29, 3, 0, | 2970 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1691 | HDA_OUTPUT)); | 2971 | HDA_OUTPUT)); |
1692 | if (err < 0) | 2972 | if (err < 0) |
1693 | return err; | 2973 | return err; |
1694 | sprintf(name, "%s Playback Switch", chname[i]); | 2974 | sprintf(name, "%s Playback Switch", chname[i]); |
1695 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | 2975 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
1696 | HDA_COMPOSE_AMP_VAL(0x29, 3, 0, | 2976 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1697 | HDA_OUTPUT)); | 2977 | HDA_OUTPUT)); |
1698 | if (err < 0) | 2978 | if (err < 0) |
1699 | return err; | 2979 | return err; |
@@ -1714,6 +2994,7 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |||
1714 | spec->multiout.hp_nid = VT1709_HP_DAC_NID; | 2994 | spec->multiout.hp_nid = VT1709_HP_DAC_NID; |
1715 | else if (spec->multiout.num_dacs == 3) /* 6 channels */ | 2995 | else if (spec->multiout.num_dacs == 3) /* 6 channels */ |
1716 | spec->multiout.hp_nid = 0; | 2996 | spec->multiout.hp_nid = 0; |
2997 | spec->hp_independent_mode_index = 1; | ||
1717 | 2998 | ||
1718 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 2999 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
1719 | "Headphone Playback Volume", | 3000 | "Headphone Playback Volume", |
@@ -1752,7 +3033,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec, | |||
1752 | case 0x1d: /* Mic */ | 3033 | case 0x1d: /* Mic */ |
1753 | idx = 2; | 3034 | idx = 2; |
1754 | break; | 3035 | break; |
1755 | 3036 | ||
1756 | case 0x1e: /* Line In */ | 3037 | case 0x1e: /* Line In */ |
1757 | idx = 3; | 3038 | idx = 3; |
1758 | break; | 3039 | break; |
@@ -1765,8 +3046,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec, | |||
1765 | idx = 1; | 3046 | idx = 1; |
1766 | break; | 3047 | break; |
1767 | } | 3048 | } |
1768 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | 3049 | err = via_new_analog_input(spec, labels[i], idx, 0x18); |
1769 | idx, 0x18); | ||
1770 | if (err < 0) | 3050 | if (err < 0) |
1771 | return err; | 3051 | return err; |
1772 | imux->items[imux->num_items].label = labels[i]; | 3052 | imux->items[imux->num_items].label = labels[i]; |
@@ -1814,8 +3094,9 @@ static int vt1709_parse_auto_config(struct hda_codec *codec) | |||
1814 | spec->input_mux = &spec->private_imux[0]; | 3094 | spec->input_mux = &spec->private_imux[0]; |
1815 | 3095 | ||
1816 | if (spec->hp_mux) | 3096 | if (spec->hp_mux) |
1817 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | 3097 | via_hp_build(codec); |
1818 | 3098 | ||
3099 | via_smart51_build(spec); | ||
1819 | return 1; | 3100 | return 1; |
1820 | } | 3101 | } |
1821 | 3102 | ||
@@ -1835,12 +3116,10 @@ static int patch_vt1709_10ch(struct hda_codec *codec) | |||
1835 | int err; | 3116 | int err; |
1836 | 3117 | ||
1837 | /* create a codec specific record */ | 3118 | /* create a codec specific record */ |
1838 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 3119 | spec = via_new_spec(codec); |
1839 | if (spec == NULL) | 3120 | if (spec == NULL) |
1840 | return -ENOMEM; | 3121 | return -ENOMEM; |
1841 | 3122 | ||
1842 | codec->spec = spec; | ||
1843 | |||
1844 | err = vt1709_parse_auto_config(codec); | 3123 | err = vt1709_parse_auto_config(codec); |
1845 | if (err < 0) { | 3124 | if (err < 0) { |
1846 | via_free(codec); | 3125 | via_free(codec); |
@@ -1861,7 +3140,7 @@ static int patch_vt1709_10ch(struct hda_codec *codec) | |||
1861 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; | 3140 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
1862 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; | 3141 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
1863 | 3142 | ||
1864 | 3143 | ||
1865 | if (!spec->adc_nids && spec->input_mux) { | 3144 | if (!spec->adc_nids && spec->input_mux) { |
1866 | spec->adc_nids = vt1709_adc_nids; | 3145 | spec->adc_nids = vt1709_adc_nids; |
1867 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); | 3146 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); |
@@ -1929,12 +3208,10 @@ static int patch_vt1709_6ch(struct hda_codec *codec) | |||
1929 | int err; | 3208 | int err; |
1930 | 3209 | ||
1931 | /* create a codec specific record */ | 3210 | /* create a codec specific record */ |
1932 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 3211 | spec = via_new_spec(codec); |
1933 | if (spec == NULL) | 3212 | if (spec == NULL) |
1934 | return -ENOMEM; | 3213 | return -ENOMEM; |
1935 | 3214 | ||
1936 | codec->spec = spec; | ||
1937 | |||
1938 | err = vt1709_parse_auto_config(codec); | 3215 | err = vt1709_parse_auto_config(codec); |
1939 | if (err < 0) { | 3216 | if (err < 0) { |
1940 | via_free(codec); | 3217 | via_free(codec); |
@@ -1955,7 +3232,7 @@ static int patch_vt1709_6ch(struct hda_codec *codec) | |||
1955 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; | 3232 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
1956 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; | 3233 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
1957 | 3234 | ||
1958 | 3235 | ||
1959 | if (!spec->adc_nids && spec->input_mux) { | 3236 | if (!spec->adc_nids && spec->input_mux) { |
1960 | spec->adc_nids = vt1709_adc_nids; | 3237 | spec->adc_nids = vt1709_adc_nids; |
1961 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); | 3238 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); |
@@ -2024,7 +3301,7 @@ static struct hda_verb vt1708B_8ch_volume_init_verbs[] = { | |||
2024 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | 3301 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
2025 | 3302 | ||
2026 | /* Setup default input to PW4 */ | 3303 | /* Setup default input to PW4 */ |
2027 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, | 3304 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
2028 | /* PW9 Output enable */ | 3305 | /* PW9 Output enable */ |
2029 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | 3306 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
2030 | /* PW10 Input enable */ | 3307 | /* PW10 Input enable */ |
@@ -2068,10 +3345,29 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = { | |||
2068 | }; | 3345 | }; |
2069 | 3346 | ||
2070 | static struct hda_verb vt1708B_uniwill_init_verbs[] = { | 3347 | static struct hda_verb vt1708B_uniwill_init_verbs[] = { |
2071 | {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | 3348 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3349 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | ||
3350 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3351 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3352 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3353 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3354 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3355 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3356 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
2072 | { } | 3357 | { } |
2073 | }; | 3358 | }; |
2074 | 3359 | ||
3360 | static int via_pcm_open_close(struct hda_pcm_stream *hinfo, | ||
3361 | struct hda_codec *codec, | ||
3362 | struct snd_pcm_substream *substream) | ||
3363 | { | ||
3364 | int idle = substream->pstr->substream_opened == 1 | ||
3365 | && substream->ref_count == 0; | ||
3366 | |||
3367 | analog_low_current_mode(codec, idle); | ||
3368 | return 0; | ||
3369 | } | ||
3370 | |||
2075 | static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { | 3371 | static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { |
2076 | .substreams = 2, | 3372 | .substreams = 2, |
2077 | .channels_min = 2, | 3373 | .channels_min = 2, |
@@ -2080,7 +3376,8 @@ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { | |||
2080 | .ops = { | 3376 | .ops = { |
2081 | .open = via_playback_pcm_open, | 3377 | .open = via_playback_pcm_open, |
2082 | .prepare = via_playback_multi_pcm_prepare, | 3378 | .prepare = via_playback_multi_pcm_prepare, |
2083 | .cleanup = via_playback_multi_pcm_cleanup | 3379 | .cleanup = via_playback_multi_pcm_cleanup, |
3380 | .close = via_pcm_open_close | ||
2084 | }, | 3381 | }, |
2085 | }; | 3382 | }; |
2086 | 3383 | ||
@@ -2102,8 +3399,10 @@ static struct hda_pcm_stream vt1708B_pcm_analog_capture = { | |||
2102 | .channels_max = 2, | 3399 | .channels_max = 2, |
2103 | .nid = 0x13, /* NID to query formats and rates */ | 3400 | .nid = 0x13, /* NID to query formats and rates */ |
2104 | .ops = { | 3401 | .ops = { |
3402 | .open = via_pcm_open_close, | ||
2105 | .prepare = via_capture_pcm_prepare, | 3403 | .prepare = via_capture_pcm_prepare, |
2106 | .cleanup = via_capture_pcm_cleanup | 3404 | .cleanup = via_capture_pcm_cleanup, |
3405 | .close = via_pcm_open_close | ||
2107 | }, | 3406 | }, |
2108 | }; | 3407 | }; |
2109 | 3408 | ||
@@ -2260,6 +3559,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |||
2260 | return 0; | 3559 | return 0; |
2261 | 3560 | ||
2262 | spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ | 3561 | spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ |
3562 | spec->hp_independent_mode_index = 1; | ||
2263 | 3563 | ||
2264 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 3564 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
2265 | "Headphone Playback Volume", | 3565 | "Headphone Playback Volume", |
@@ -2313,8 +3613,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec, | |||
2313 | idx = 1; | 3613 | idx = 1; |
2314 | break; | 3614 | break; |
2315 | } | 3615 | } |
2316 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | 3616 | err = via_new_analog_input(spec, labels[i], idx, 0x16); |
2317 | idx, 0x16); | ||
2318 | if (err < 0) | 3617 | if (err < 0) |
2319 | return err; | 3618 | return err; |
2320 | imux->items[imux->num_items].label = labels[i]; | 3619 | imux->items[imux->num_items].label = labels[i]; |
@@ -2362,8 +3661,9 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec) | |||
2362 | spec->input_mux = &spec->private_imux[0]; | 3661 | spec->input_mux = &spec->private_imux[0]; |
2363 | 3662 | ||
2364 | if (spec->hp_mux) | 3663 | if (spec->hp_mux) |
2365 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | 3664 | via_hp_build(codec); |
2366 | 3665 | ||
3666 | via_smart51_build(spec); | ||
2367 | return 1; | 3667 | return 1; |
2368 | } | 3668 | } |
2369 | 3669 | ||
@@ -2376,19 +3676,19 @@ static struct hda_amp_list vt1708B_loopbacks[] = { | |||
2376 | { } /* end */ | 3676 | { } /* end */ |
2377 | }; | 3677 | }; |
2378 | #endif | 3678 | #endif |
2379 | 3679 | static int patch_vt1708S(struct hda_codec *codec); | |
2380 | static int patch_vt1708B_8ch(struct hda_codec *codec) | 3680 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
2381 | { | 3681 | { |
2382 | struct via_spec *spec; | 3682 | struct via_spec *spec; |
2383 | int err; | 3683 | int err; |
2384 | 3684 | ||
3685 | if (get_codec_type(codec) == VT1708BCE) | ||
3686 | return patch_vt1708S(codec); | ||
2385 | /* create a codec specific record */ | 3687 | /* create a codec specific record */ |
2386 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 3688 | spec = via_new_spec(codec); |
2387 | if (spec == NULL) | 3689 | if (spec == NULL) |
2388 | return -ENOMEM; | 3690 | return -ENOMEM; |
2389 | 3691 | ||
2390 | codec->spec = spec; | ||
2391 | |||
2392 | /* automatic parse from the BIOS config */ | 3692 | /* automatic parse from the BIOS config */ |
2393 | err = vt1708B_parse_auto_config(codec); | 3693 | err = vt1708B_parse_auto_config(codec); |
2394 | if (err < 0) { | 3694 | if (err < 0) { |
@@ -2435,12 +3735,10 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) | |||
2435 | int err; | 3735 | int err; |
2436 | 3736 | ||
2437 | /* create a codec specific record */ | 3737 | /* create a codec specific record */ |
2438 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 3738 | spec = via_new_spec(codec); |
2439 | if (spec == NULL) | 3739 | if (spec == NULL) |
2440 | return -ENOMEM; | 3740 | return -ENOMEM; |
2441 | 3741 | ||
2442 | codec->spec = spec; | ||
2443 | |||
2444 | /* automatic parse from the BIOS config */ | 3742 | /* automatic parse from the BIOS config */ |
2445 | err = vt1708B_parse_auto_config(codec); | 3743 | err = vt1708B_parse_auto_config(codec); |
2446 | if (err < 0) { | 3744 | if (err < 0) { |
@@ -2483,29 +3781,15 @@ static int patch_vt1708B_4ch(struct hda_codec *codec) | |||
2483 | 3781 | ||
2484 | /* Patch for VT1708S */ | 3782 | /* Patch for VT1708S */ |
2485 | 3783 | ||
2486 | /* VT1708S software backdoor based override for buggy hardware micboost | ||
2487 | * setting */ | ||
2488 | #define MIC_BOOST_VOLUME(xname, nid) { \ | ||
2489 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | ||
2490 | .name = xname, \ | ||
2491 | .index = 0, \ | ||
2492 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ | ||
2493 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ | ||
2494 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ | ||
2495 | .info = mic_boost_volume_info, \ | ||
2496 | .get = snd_hda_mixer_amp_volume_get, \ | ||
2497 | .put = snd_hda_mixer_amp_volume_put, \ | ||
2498 | .tlv = { .c = mic_boost_tlv }, \ | ||
2499 | .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) } | ||
2500 | |||
2501 | /* capture mixer elements */ | 3784 | /* capture mixer elements */ |
2502 | static struct snd_kcontrol_new vt1708S_capture_mixer[] = { | 3785 | static struct snd_kcontrol_new vt1708S_capture_mixer[] = { |
2503 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), | 3786 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
2504 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | 3787 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
2505 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | 3788 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
2506 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | 3789 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
2507 | MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A), | 3790 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
2508 | MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E), | 3791 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
3792 | HDA_INPUT), | ||
2509 | { | 3793 | { |
2510 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | 3794 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
2511 | /* The multiple "Capture Source" controls confuse alsamixer | 3795 | /* The multiple "Capture Source" controls confuse alsamixer |
@@ -2542,11 +3826,21 @@ static struct hda_verb vt1708S_volume_init_verbs[] = { | |||
2542 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | 3826 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
2543 | /* Enable Mic Boost Volume backdoor */ | 3827 | /* Enable Mic Boost Volume backdoor */ |
2544 | {0x1, 0xf98, 0x1}, | 3828 | {0x1, 0xf98, 0x1}, |
3829 | /* don't bybass mixer */ | ||
3830 | {0x1, 0xf88, 0xc0}, | ||
2545 | { } | 3831 | { } |
2546 | }; | 3832 | }; |
2547 | 3833 | ||
2548 | static struct hda_verb vt1708S_uniwill_init_verbs[] = { | 3834 | static struct hda_verb vt1708S_uniwill_init_verbs[] = { |
2549 | {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | 3835 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3836 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | ||
3837 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3838 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3839 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3840 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3841 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3842 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
3843 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
2550 | { } | 3844 | { } |
2551 | }; | 3845 | }; |
2552 | 3846 | ||
@@ -2557,8 +3851,9 @@ static struct hda_pcm_stream vt1708S_pcm_analog_playback = { | |||
2557 | .nid = 0x10, /* NID to query formats and rates */ | 3851 | .nid = 0x10, /* NID to query formats and rates */ |
2558 | .ops = { | 3852 | .ops = { |
2559 | .open = via_playback_pcm_open, | 3853 | .open = via_playback_pcm_open, |
2560 | .prepare = via_playback_pcm_prepare, | 3854 | .prepare = via_playback_multi_pcm_prepare, |
2561 | .cleanup = via_playback_pcm_cleanup | 3855 | .cleanup = via_playback_multi_pcm_cleanup, |
3856 | .close = via_pcm_open_close | ||
2562 | }, | 3857 | }, |
2563 | }; | 3858 | }; |
2564 | 3859 | ||
@@ -2568,8 +3863,10 @@ static struct hda_pcm_stream vt1708S_pcm_analog_capture = { | |||
2568 | .channels_max = 2, | 3863 | .channels_max = 2, |
2569 | .nid = 0x13, /* NID to query formats and rates */ | 3864 | .nid = 0x13, /* NID to query formats and rates */ |
2570 | .ops = { | 3865 | .ops = { |
3866 | .open = via_pcm_open_close, | ||
2571 | .prepare = via_capture_pcm_prepare, | 3867 | .prepare = via_capture_pcm_prepare, |
2572 | .cleanup = via_capture_pcm_cleanup | 3868 | .cleanup = via_capture_pcm_cleanup, |
3869 | .close = via_pcm_open_close | ||
2573 | }, | 3870 | }, |
2574 | }; | 3871 | }; |
2575 | 3872 | ||
@@ -2726,6 +4023,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |||
2726 | return 0; | 4023 | return 0; |
2727 | 4024 | ||
2728 | spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ | 4025 | spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ |
4026 | spec->hp_independent_mode_index = 1; | ||
2729 | 4027 | ||
2730 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 4028 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
2731 | "Headphone Playback Volume", | 4029 | "Headphone Playback Volume", |
@@ -2780,8 +4078,7 @@ static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec, | |||
2780 | idx = 1; | 4078 | idx = 1; |
2781 | break; | 4079 | break; |
2782 | } | 4080 | } |
2783 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | 4081 | err = via_new_analog_input(spec, labels[i], idx, 0x16); |
2784 | idx, 0x16); | ||
2785 | if (err < 0) | 4082 | if (err < 0) |
2786 | return err; | 4083 | return err; |
2787 | imux->items[imux->num_items].label = labels[i]; | 4084 | imux->items[imux->num_items].label = labels[i]; |
@@ -2850,8 +4147,9 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec) | |||
2850 | spec->input_mux = &spec->private_imux[0]; | 4147 | spec->input_mux = &spec->private_imux[0]; |
2851 | 4148 | ||
2852 | if (spec->hp_mux) | 4149 | if (spec->hp_mux) |
2853 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | 4150 | via_hp_build(codec); |
2854 | 4151 | ||
4152 | via_smart51_build(spec); | ||
2855 | return 1; | 4153 | return 1; |
2856 | } | 4154 | } |
2857 | 4155 | ||
@@ -2865,18 +4163,26 @@ static struct hda_amp_list vt1708S_loopbacks[] = { | |||
2865 | }; | 4163 | }; |
2866 | #endif | 4164 | #endif |
2867 | 4165 | ||
4166 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, | ||
4167 | int offset, int num_steps, int step_size) | ||
4168 | { | ||
4169 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, | ||
4170 | (offset << AC_AMPCAP_OFFSET_SHIFT) | | ||
4171 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | | ||
4172 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | | ||
4173 | (0 << AC_AMPCAP_MUTE_SHIFT)); | ||
4174 | } | ||
4175 | |||
2868 | static int patch_vt1708S(struct hda_codec *codec) | 4176 | static int patch_vt1708S(struct hda_codec *codec) |
2869 | { | 4177 | { |
2870 | struct via_spec *spec; | 4178 | struct via_spec *spec; |
2871 | int err; | 4179 | int err; |
2872 | 4180 | ||
2873 | /* create a codec specific record */ | 4181 | /* create a codec specific record */ |
2874 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 4182 | spec = via_new_spec(codec); |
2875 | if (spec == NULL) | 4183 | if (spec == NULL) |
2876 | return -ENOMEM; | 4184 | return -ENOMEM; |
2877 | 4185 | ||
2878 | codec->spec = spec; | ||
2879 | |||
2880 | /* automatic parse from the BIOS config */ | 4186 | /* automatic parse from the BIOS config */ |
2881 | err = vt1708S_parse_auto_config(codec); | 4187 | err = vt1708S_parse_auto_config(codec); |
2882 | if (err < 0) { | 4188 | if (err < 0) { |
@@ -2890,17 +4196,25 @@ static int patch_vt1708S(struct hda_codec *codec) | |||
2890 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; | 4196 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
2891 | spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; | 4197 | spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; |
2892 | 4198 | ||
2893 | spec->stream_name_analog = "VT1708S Analog"; | 4199 | if (codec->vendor_id == 0x11060440) |
4200 | spec->stream_name_analog = "VT1818S Analog"; | ||
4201 | else | ||
4202 | spec->stream_name_analog = "VT1708S Analog"; | ||
2894 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; | 4203 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; |
2895 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; | 4204 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; |
2896 | 4205 | ||
2897 | spec->stream_name_digital = "VT1708S Digital"; | 4206 | if (codec->vendor_id == 0x11060440) |
4207 | spec->stream_name_digital = "VT1818S Digital"; | ||
4208 | else | ||
4209 | spec->stream_name_digital = "VT1708S Digital"; | ||
2898 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; | 4210 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; |
2899 | 4211 | ||
2900 | if (!spec->adc_nids && spec->input_mux) { | 4212 | if (!spec->adc_nids && spec->input_mux) { |
2901 | spec->adc_nids = vt1708S_adc_nids; | 4213 | spec->adc_nids = vt1708S_adc_nids; |
2902 | spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); | 4214 | spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); |
2903 | get_mux_nids(codec); | 4215 | get_mux_nids(codec); |
4216 | override_mic_boost(codec, 0x1a, 0, 3, 40); | ||
4217 | override_mic_boost(codec, 0x1e, 0, 3, 40); | ||
2904 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; | 4218 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; |
2905 | spec->num_mixers++; | 4219 | spec->num_mixers++; |
2906 | } | 4220 | } |
@@ -2913,6 +4227,16 @@ static int patch_vt1708S(struct hda_codec *codec) | |||
2913 | spec->loopback.amplist = vt1708S_loopbacks; | 4227 | spec->loopback.amplist = vt1708S_loopbacks; |
2914 | #endif | 4228 | #endif |
2915 | 4229 | ||
4230 | /* correct names for VT1708BCE */ | ||
4231 | if (get_codec_type(codec) == VT1708BCE) { | ||
4232 | kfree(codec->chip_name); | ||
4233 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); | ||
4234 | snprintf(codec->bus->card->mixername, | ||
4235 | sizeof(codec->bus->card->mixername), | ||
4236 | "%s %s", codec->vendor_name, codec->chip_name); | ||
4237 | spec->stream_name_analog = "VT1708BCE Analog"; | ||
4238 | spec->stream_name_digital = "VT1708BCE Digital"; | ||
4239 | } | ||
2916 | return 0; | 4240 | return 0; |
2917 | } | 4241 | } |
2918 | 4242 | ||
@@ -2967,12 +4291,20 @@ static struct hda_verb vt1702_volume_init_verbs[] = { | |||
2967 | /* PW6 PW7 Output enable */ | 4291 | /* PW6 PW7 Output enable */ |
2968 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | 4292 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
2969 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | 4293 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
4294 | /* mixer enable */ | ||
4295 | {0x1, 0xF88, 0x3}, | ||
4296 | /* GPIO 0~2 */ | ||
4297 | {0x1, 0xF82, 0x3F}, | ||
2970 | { } | 4298 | { } |
2971 | }; | 4299 | }; |
2972 | 4300 | ||
2973 | static struct hda_verb vt1702_uniwill_init_verbs[] = { | 4301 | static struct hda_verb vt1702_uniwill_init_verbs[] = { |
2974 | {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT}, | 4302 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
2975 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | 4303 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
4304 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4305 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4306 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4307 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
2976 | { } | 4308 | { } |
2977 | }; | 4309 | }; |
2978 | 4310 | ||
@@ -2984,7 +4316,8 @@ static struct hda_pcm_stream vt1702_pcm_analog_playback = { | |||
2984 | .ops = { | 4316 | .ops = { |
2985 | .open = via_playback_pcm_open, | 4317 | .open = via_playback_pcm_open, |
2986 | .prepare = via_playback_multi_pcm_prepare, | 4318 | .prepare = via_playback_multi_pcm_prepare, |
2987 | .cleanup = via_playback_multi_pcm_cleanup | 4319 | .cleanup = via_playback_multi_pcm_cleanup, |
4320 | .close = via_pcm_open_close | ||
2988 | }, | 4321 | }, |
2989 | }; | 4322 | }; |
2990 | 4323 | ||
@@ -2994,8 +4327,10 @@ static struct hda_pcm_stream vt1702_pcm_analog_capture = { | |||
2994 | .channels_max = 2, | 4327 | .channels_max = 2, |
2995 | .nid = 0x12, /* NID to query formats and rates */ | 4328 | .nid = 0x12, /* NID to query formats and rates */ |
2996 | .ops = { | 4329 | .ops = { |
4330 | .open = via_pcm_open_close, | ||
2997 | .prepare = via_capture_pcm_prepare, | 4331 | .prepare = via_capture_pcm_prepare, |
2998 | .cleanup = via_capture_pcm_cleanup | 4332 | .cleanup = via_capture_pcm_cleanup, |
4333 | .close = via_pcm_open_close | ||
2999 | }, | 4334 | }, |
3000 | }; | 4335 | }; |
3001 | 4336 | ||
@@ -3065,12 +4400,13 @@ static int vt1702_auto_create_line_out_ctls(struct via_spec *spec, | |||
3065 | 4400 | ||
3066 | static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | 4401 | static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
3067 | { | 4402 | { |
3068 | int err; | 4403 | int err, i; |
3069 | 4404 | struct hda_input_mux *imux; | |
4405 | static const char *texts[] = { "ON", "OFF", NULL}; | ||
3070 | if (!pin) | 4406 | if (!pin) |
3071 | return 0; | 4407 | return 0; |
3072 | |||
3073 | spec->multiout.hp_nid = 0x1D; | 4408 | spec->multiout.hp_nid = 0x1D; |
4409 | spec->hp_independent_mode_index = 0; | ||
3074 | 4410 | ||
3075 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | 4411 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
3076 | "Headphone Playback Volume", | 4412 | "Headphone Playback Volume", |
@@ -3084,8 +4420,18 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |||
3084 | if (err < 0) | 4420 | if (err < 0) |
3085 | return err; | 4421 | return err; |
3086 | 4422 | ||
3087 | create_hp_imux(spec); | 4423 | imux = &spec->private_imux[1]; |
4424 | |||
4425 | /* for hp mode select */ | ||
4426 | i = 0; | ||
4427 | while (texts[i] != NULL) { | ||
4428 | imux->items[imux->num_items].label = texts[i]; | ||
4429 | imux->items[imux->num_items].index = i; | ||
4430 | imux->num_items++; | ||
4431 | i++; | ||
4432 | } | ||
3088 | 4433 | ||
4434 | spec->hp_mux = &spec->private_imux[1]; | ||
3089 | return 0; | 4435 | return 0; |
3090 | } | 4436 | } |
3091 | 4437 | ||
@@ -3121,8 +4467,7 @@ static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec, | |||
3121 | idx = 3; | 4467 | idx = 3; |
3122 | break; | 4468 | break; |
3123 | } | 4469 | } |
3124 | err = via_new_analog_input(spec, cfg->input_pins[i], | 4470 | err = via_new_analog_input(spec, labels[i], idx, 0x1A); |
3125 | labels[i], idx, 0x1A); | ||
3126 | if (err < 0) | 4471 | if (err < 0) |
3127 | return err; | 4472 | return err; |
3128 | imux->items[imux->num_items].label = labels[i]; | 4473 | imux->items[imux->num_items].label = labels[i]; |
@@ -3152,6 +4497,12 @@ static int vt1702_parse_auto_config(struct hda_codec *codec) | |||
3152 | err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | 4497 | err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
3153 | if (err < 0) | 4498 | if (err < 0) |
3154 | return err; | 4499 | return err; |
4500 | /* limit AA path volume to 0 dB */ | ||
4501 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, | ||
4502 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | | ||
4503 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | | ||
4504 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | | ||
4505 | (1 << AC_AMPCAP_MUTE_SHIFT)); | ||
3155 | err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); | 4506 | err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); |
3156 | if (err < 0) | 4507 | if (err < 0) |
3157 | return err; | 4508 | return err; |
@@ -3166,7 +4517,7 @@ static int vt1702_parse_auto_config(struct hda_codec *codec) | |||
3166 | spec->input_mux = &spec->private_imux[0]; | 4517 | spec->input_mux = &spec->private_imux[0]; |
3167 | 4518 | ||
3168 | if (spec->hp_mux) | 4519 | if (spec->hp_mux) |
3169 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | 4520 | via_hp_build(codec); |
3170 | 4521 | ||
3171 | return 1; | 4522 | return 1; |
3172 | } | 4523 | } |
@@ -3185,16 +4536,12 @@ static int patch_vt1702(struct hda_codec *codec) | |||
3185 | { | 4536 | { |
3186 | struct via_spec *spec; | 4537 | struct via_spec *spec; |
3187 | int err; | 4538 | int err; |
3188 | unsigned int response; | ||
3189 | unsigned char control; | ||
3190 | 4539 | ||
3191 | /* create a codec specific record */ | 4540 | /* create a codec specific record */ |
3192 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 4541 | spec = via_new_spec(codec); |
3193 | if (spec == NULL) | 4542 | if (spec == NULL) |
3194 | return -ENOMEM; | 4543 | return -ENOMEM; |
3195 | 4544 | ||
3196 | codec->spec = spec; | ||
3197 | |||
3198 | /* automatic parse from the BIOS config */ | 4545 | /* automatic parse from the BIOS config */ |
3199 | err = vt1702_parse_auto_config(codec); | 4546 | err = vt1702_parse_auto_config(codec); |
3200 | if (err < 0) { | 4547 | if (err < 0) { |
@@ -3231,17 +4578,1631 @@ static int patch_vt1702(struct hda_codec *codec) | |||
3231 | spec->loopback.amplist = vt1702_loopbacks; | 4578 | spec->loopback.amplist = vt1702_loopbacks; |
3232 | #endif | 4579 | #endif |
3233 | 4580 | ||
3234 | /* Open backdoor */ | 4581 | return 0; |
3235 | response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0); | 4582 | } |
3236 | control = (unsigned char)(response & 0xff); | 4583 | |
3237 | control |= 0x3; | 4584 | /* Patch for VT1718S */ |
3238 | snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control); | 4585 | |
4586 | /* capture mixer elements */ | ||
4587 | static struct snd_kcontrol_new vt1718S_capture_mixer[] = { | ||
4588 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), | ||
4589 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), | ||
4590 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), | ||
4591 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), | ||
4592 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), | ||
4593 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, | ||
4594 | HDA_INPUT), | ||
4595 | { | ||
4596 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
4597 | /* The multiple "Capture Source" controls confuse alsamixer | ||
4598 | * So call somewhat different.. | ||
4599 | */ | ||
4600 | .name = "Input Source", | ||
4601 | .count = 2, | ||
4602 | .info = via_mux_enum_info, | ||
4603 | .get = via_mux_enum_get, | ||
4604 | .put = via_mux_enum_put, | ||
4605 | }, | ||
4606 | { } /* end */ | ||
4607 | }; | ||
4608 | |||
4609 | static struct hda_verb vt1718S_volume_init_verbs[] = { | ||
4610 | /* | ||
4611 | * Unmute ADC0-1 and set the default input to mic-in | ||
4612 | */ | ||
4613 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4614 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4615 | |||
4616 | |||
4617 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | ||
4618 | * mixer widget | ||
4619 | */ | ||
4620 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | ||
4621 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | ||
4622 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
4623 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | ||
4624 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | ||
4625 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, | ||
4626 | |||
4627 | /* Setup default input of Front HP to MW9 */ | ||
4628 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, | ||
4629 | /* PW9 PW10 Output enable */ | ||
4630 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | ||
4631 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | ||
4632 | /* PW11 Input enable */ | ||
4633 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, | ||
4634 | /* Enable Boost Volume backdoor */ | ||
4635 | {0x1, 0xf88, 0x8}, | ||
4636 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ | ||
4637 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4638 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4639 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4640 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4641 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4642 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
4643 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
4644 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
4645 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
4646 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
4647 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ | ||
4648 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, | ||
4649 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, | ||
4650 | /* Unmute MW4's index 0 */ | ||
4651 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
4652 | { } | ||
4653 | }; | ||
4654 | |||
4655 | |||
4656 | static struct hda_verb vt1718S_uniwill_init_verbs[] = { | ||
4657 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
4658 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | ||
4659 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4660 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4661 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4662 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4663 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4664 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4665 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
4666 | { } | ||
4667 | }; | ||
4668 | |||
4669 | static struct hda_pcm_stream vt1718S_pcm_analog_playback = { | ||
4670 | .substreams = 2, | ||
4671 | .channels_min = 2, | ||
4672 | .channels_max = 10, | ||
4673 | .nid = 0x8, /* NID to query formats and rates */ | ||
4674 | .ops = { | ||
4675 | .open = via_playback_pcm_open, | ||
4676 | .prepare = via_playback_multi_pcm_prepare, | ||
4677 | .cleanup = via_playback_multi_pcm_cleanup, | ||
4678 | .close = via_pcm_open_close, | ||
4679 | }, | ||
4680 | }; | ||
4681 | |||
4682 | static struct hda_pcm_stream vt1718S_pcm_analog_capture = { | ||
4683 | .substreams = 2, | ||
4684 | .channels_min = 2, | ||
4685 | .channels_max = 2, | ||
4686 | .nid = 0x10, /* NID to query formats and rates */ | ||
4687 | .ops = { | ||
4688 | .open = via_pcm_open_close, | ||
4689 | .prepare = via_capture_pcm_prepare, | ||
4690 | .cleanup = via_capture_pcm_cleanup, | ||
4691 | .close = via_pcm_open_close, | ||
4692 | }, | ||
4693 | }; | ||
4694 | |||
4695 | static struct hda_pcm_stream vt1718S_pcm_digital_playback = { | ||
4696 | .substreams = 2, | ||
4697 | .channels_min = 2, | ||
4698 | .channels_max = 2, | ||
4699 | /* NID is set in via_build_pcms */ | ||
4700 | .ops = { | ||
4701 | .open = via_dig_playback_pcm_open, | ||
4702 | .close = via_dig_playback_pcm_close, | ||
4703 | .prepare = via_dig_playback_pcm_prepare, | ||
4704 | .cleanup = via_dig_playback_pcm_cleanup | ||
4705 | }, | ||
4706 | }; | ||
4707 | |||
4708 | static struct hda_pcm_stream vt1718S_pcm_digital_capture = { | ||
4709 | .substreams = 1, | ||
4710 | .channels_min = 2, | ||
4711 | .channels_max = 2, | ||
4712 | }; | ||
4713 | |||
4714 | /* fill in the dac_nids table from the parsed pin configuration */ | ||
4715 | static int vt1718S_auto_fill_dac_nids(struct via_spec *spec, | ||
4716 | const struct auto_pin_cfg *cfg) | ||
4717 | { | ||
4718 | int i; | ||
4719 | hda_nid_t nid; | ||
4720 | |||
4721 | spec->multiout.num_dacs = cfg->line_outs; | ||
4722 | |||
4723 | spec->multiout.dac_nids = spec->private_dac_nids; | ||
4724 | |||
4725 | for (i = 0; i < 4; i++) { | ||
4726 | nid = cfg->line_out_pins[i]; | ||
4727 | if (nid) { | ||
4728 | /* config dac list */ | ||
4729 | switch (i) { | ||
4730 | case AUTO_SEQ_FRONT: | ||
4731 | spec->multiout.dac_nids[i] = 0x8; | ||
4732 | break; | ||
4733 | case AUTO_SEQ_CENLFE: | ||
4734 | spec->multiout.dac_nids[i] = 0xa; | ||
4735 | break; | ||
4736 | case AUTO_SEQ_SURROUND: | ||
4737 | spec->multiout.dac_nids[i] = 0x9; | ||
4738 | break; | ||
4739 | case AUTO_SEQ_SIDE: | ||
4740 | spec->multiout.dac_nids[i] = 0xb; | ||
4741 | break; | ||
4742 | } | ||
4743 | } | ||
4744 | } | ||
4745 | |||
4746 | return 0; | ||
4747 | } | ||
4748 | |||
4749 | /* add playback controls from the parsed DAC table */ | ||
4750 | static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec, | ||
4751 | const struct auto_pin_cfg *cfg) | ||
4752 | { | ||
4753 | char name[32]; | ||
4754 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | ||
4755 | hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb}; | ||
4756 | hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27}; | ||
4757 | hda_nid_t nid, nid_vol, nid_mute = 0; | ||
4758 | int i, err; | ||
4759 | |||
4760 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | ||
4761 | nid = cfg->line_out_pins[i]; | ||
4762 | |||
4763 | if (!nid) | ||
4764 | continue; | ||
4765 | nid_vol = nid_vols[i]; | ||
4766 | nid_mute = nid_mutes[i]; | ||
4767 | |||
4768 | if (i == AUTO_SEQ_CENLFE) { | ||
4769 | /* Center/LFE */ | ||
4770 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
4771 | "Center Playback Volume", | ||
4772 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | ||
4773 | HDA_OUTPUT)); | ||
4774 | if (err < 0) | ||
4775 | return err; | ||
4776 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
4777 | "LFE Playback Volume", | ||
4778 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | ||
4779 | HDA_OUTPUT)); | ||
4780 | if (err < 0) | ||
4781 | return err; | ||
4782 | err = via_add_control( | ||
4783 | spec, VIA_CTL_WIDGET_MUTE, | ||
4784 | "Center Playback Switch", | ||
4785 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, | ||
4786 | HDA_OUTPUT)); | ||
4787 | if (err < 0) | ||
4788 | return err; | ||
4789 | err = via_add_control( | ||
4790 | spec, VIA_CTL_WIDGET_MUTE, | ||
4791 | "LFE Playback Switch", | ||
4792 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, | ||
4793 | HDA_OUTPUT)); | ||
4794 | if (err < 0) | ||
4795 | return err; | ||
4796 | } else if (i == AUTO_SEQ_FRONT) { | ||
4797 | /* Front */ | ||
4798 | sprintf(name, "%s Playback Volume", chname[i]); | ||
4799 | err = via_add_control( | ||
4800 | spec, VIA_CTL_WIDGET_VOL, name, | ||
4801 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | ||
4802 | if (err < 0) | ||
4803 | return err; | ||
4804 | sprintf(name, "%s Playback Switch", chname[i]); | ||
4805 | err = via_add_control( | ||
4806 | spec, VIA_CTL_WIDGET_MUTE, name, | ||
4807 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | ||
4808 | HDA_OUTPUT)); | ||
4809 | if (err < 0) | ||
4810 | return err; | ||
4811 | } else { | ||
4812 | sprintf(name, "%s Playback Volume", chname[i]); | ||
4813 | err = via_add_control( | ||
4814 | spec, VIA_CTL_WIDGET_VOL, name, | ||
4815 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | ||
4816 | if (err < 0) | ||
4817 | return err; | ||
4818 | sprintf(name, "%s Playback Switch", chname[i]); | ||
4819 | err = via_add_control( | ||
4820 | spec, VIA_CTL_WIDGET_MUTE, name, | ||
4821 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | ||
4822 | HDA_OUTPUT)); | ||
4823 | if (err < 0) | ||
4824 | return err; | ||
4825 | } | ||
4826 | } | ||
4827 | return 0; | ||
4828 | } | ||
4829 | |||
4830 | static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | ||
4831 | { | ||
4832 | int err; | ||
4833 | |||
4834 | if (!pin) | ||
4835 | return 0; | ||
4836 | |||
4837 | spec->multiout.hp_nid = 0xc; /* AOW4 */ | ||
4838 | spec->hp_independent_mode_index = 1; | ||
4839 | |||
4840 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
4841 | "Headphone Playback Volume", | ||
4842 | HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT)); | ||
4843 | if (err < 0) | ||
4844 | return err; | ||
4845 | |||
4846 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | ||
4847 | "Headphone Playback Switch", | ||
4848 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | ||
4849 | if (err < 0) | ||
4850 | return err; | ||
4851 | |||
4852 | create_hp_imux(spec); | ||
4853 | return 0; | ||
4854 | } | ||
4855 | |||
4856 | /* create playback/capture controls for input pins */ | ||
4857 | static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec, | ||
4858 | const struct auto_pin_cfg *cfg) | ||
4859 | { | ||
4860 | static char *labels[] = { | ||
4861 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | ||
4862 | }; | ||
4863 | struct hda_input_mux *imux = &spec->private_imux[0]; | ||
4864 | int i, err, idx = 0; | ||
4865 | |||
4866 | /* for internal loopback recording select */ | ||
4867 | imux->items[imux->num_items].label = "Stereo Mixer"; | ||
4868 | imux->items[imux->num_items].index = 5; | ||
4869 | imux->num_items++; | ||
4870 | |||
4871 | for (i = 0; i < AUTO_PIN_LAST; i++) { | ||
4872 | if (!cfg->input_pins[i]) | ||
4873 | continue; | ||
4874 | |||
4875 | switch (cfg->input_pins[i]) { | ||
4876 | case 0x2b: /* Mic */ | ||
4877 | idx = 1; | ||
4878 | break; | ||
4879 | |||
4880 | case 0x2a: /* Line In */ | ||
4881 | idx = 2; | ||
4882 | break; | ||
4883 | |||
4884 | case 0x29: /* Front Mic */ | ||
4885 | idx = 3; | ||
4886 | break; | ||
4887 | |||
4888 | case 0x2c: /* CD */ | ||
4889 | idx = 0; | ||
4890 | break; | ||
4891 | } | ||
4892 | err = via_new_analog_input(spec, labels[i], idx, 0x21); | ||
4893 | if (err < 0) | ||
4894 | return err; | ||
4895 | imux->items[imux->num_items].label = labels[i]; | ||
4896 | imux->items[imux->num_items].index = idx; | ||
4897 | imux->num_items++; | ||
4898 | } | ||
4899 | return 0; | ||
4900 | } | ||
4901 | |||
4902 | static int vt1718S_parse_auto_config(struct hda_codec *codec) | ||
4903 | { | ||
4904 | struct via_spec *spec = codec->spec; | ||
4905 | int err; | ||
4906 | |||
4907 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | ||
4908 | |||
4909 | if (err < 0) | ||
4910 | return err; | ||
4911 | err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg); | ||
4912 | if (err < 0) | ||
4913 | return err; | ||
4914 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | ||
4915 | return 0; /* can't find valid BIOS pin config */ | ||
4916 | |||
4917 | err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg); | ||
4918 | if (err < 0) | ||
4919 | return err; | ||
4920 | err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | ||
4921 | if (err < 0) | ||
4922 | return err; | ||
4923 | err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg); | ||
4924 | if (err < 0) | ||
4925 | return err; | ||
4926 | |||
4927 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | ||
4928 | |||
4929 | fill_dig_outs(codec); | ||
4930 | |||
4931 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) | ||
4932 | spec->dig_in_nid = 0x13; | ||
4933 | |||
4934 | if (spec->kctls.list) | ||
4935 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | ||
4936 | |||
4937 | spec->input_mux = &spec->private_imux[0]; | ||
4938 | |||
4939 | if (spec->hp_mux) | ||
4940 | via_hp_build(codec); | ||
4941 | |||
4942 | via_smart51_build(spec); | ||
4943 | |||
4944 | return 1; | ||
4945 | } | ||
4946 | |||
4947 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
4948 | static struct hda_amp_list vt1718S_loopbacks[] = { | ||
4949 | { 0x21, HDA_INPUT, 1 }, | ||
4950 | { 0x21, HDA_INPUT, 2 }, | ||
4951 | { 0x21, HDA_INPUT, 3 }, | ||
4952 | { 0x21, HDA_INPUT, 4 }, | ||
4953 | { } /* end */ | ||
4954 | }; | ||
4955 | #endif | ||
4956 | |||
4957 | static int patch_vt1718S(struct hda_codec *codec) | ||
4958 | { | ||
4959 | struct via_spec *spec; | ||
4960 | int err; | ||
4961 | |||
4962 | /* create a codec specific record */ | ||
4963 | spec = via_new_spec(codec); | ||
4964 | if (spec == NULL) | ||
4965 | return -ENOMEM; | ||
4966 | |||
4967 | /* automatic parse from the BIOS config */ | ||
4968 | err = vt1718S_parse_auto_config(codec); | ||
4969 | if (err < 0) { | ||
4970 | via_free(codec); | ||
4971 | return err; | ||
4972 | } else if (!err) { | ||
4973 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | ||
4974 | "from BIOS. Using genenic mode...\n"); | ||
4975 | } | ||
4976 | |||
4977 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; | ||
4978 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; | ||
4979 | |||
4980 | if (codec->vendor_id == 0x11060441) | ||
4981 | spec->stream_name_analog = "VT2020 Analog"; | ||
4982 | else if (codec->vendor_id == 0x11064441) | ||
4983 | spec->stream_name_analog = "VT1828S Analog"; | ||
4984 | else | ||
4985 | spec->stream_name_analog = "VT1718S Analog"; | ||
4986 | spec->stream_analog_playback = &vt1718S_pcm_analog_playback; | ||
4987 | spec->stream_analog_capture = &vt1718S_pcm_analog_capture; | ||
4988 | |||
4989 | if (codec->vendor_id == 0x11060441) | ||
4990 | spec->stream_name_digital = "VT2020 Digital"; | ||
4991 | else if (codec->vendor_id == 0x11064441) | ||
4992 | spec->stream_name_digital = "VT1828S Digital"; | ||
4993 | else | ||
4994 | spec->stream_name_digital = "VT1718S Digital"; | ||
4995 | spec->stream_digital_playback = &vt1718S_pcm_digital_playback; | ||
4996 | if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) | ||
4997 | spec->stream_digital_capture = &vt1718S_pcm_digital_capture; | ||
4998 | |||
4999 | if (!spec->adc_nids && spec->input_mux) { | ||
5000 | spec->adc_nids = vt1718S_adc_nids; | ||
5001 | spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids); | ||
5002 | get_mux_nids(codec); | ||
5003 | override_mic_boost(codec, 0x2b, 0, 3, 40); | ||
5004 | override_mic_boost(codec, 0x29, 0, 3, 40); | ||
5005 | spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; | ||
5006 | spec->num_mixers++; | ||
5007 | } | ||
5008 | |||
5009 | codec->patch_ops = via_patch_ops; | ||
5010 | |||
5011 | codec->patch_ops.init = via_auto_init; | ||
5012 | codec->patch_ops.unsol_event = via_unsol_event; | ||
5013 | |||
5014 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
5015 | spec->loopback.amplist = vt1718S_loopbacks; | ||
5016 | #endif | ||
5017 | |||
5018 | return 0; | ||
5019 | } | ||
5020 | |||
5021 | /* Patch for VT1716S */ | ||
5022 | |||
5023 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, | ||
5024 | struct snd_ctl_elem_info *uinfo) | ||
5025 | { | ||
5026 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | ||
5027 | uinfo->count = 1; | ||
5028 | uinfo->value.integer.min = 0; | ||
5029 | uinfo->value.integer.max = 1; | ||
5030 | return 0; | ||
5031 | } | ||
5032 | |||
5033 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, | ||
5034 | struct snd_ctl_elem_value *ucontrol) | ||
5035 | { | ||
5036 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
5037 | int index = 0; | ||
5038 | |||
5039 | index = snd_hda_codec_read(codec, 0x26, 0, | ||
5040 | AC_VERB_GET_CONNECT_SEL, 0); | ||
5041 | if (index != -1) | ||
5042 | *ucontrol->value.integer.value = index; | ||
5043 | |||
5044 | return 0; | ||
5045 | } | ||
5046 | |||
5047 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, | ||
5048 | struct snd_ctl_elem_value *ucontrol) | ||
5049 | { | ||
5050 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | ||
5051 | struct via_spec *spec = codec->spec; | ||
5052 | int index = *ucontrol->value.integer.value; | ||
5053 | |||
5054 | snd_hda_codec_write(codec, 0x26, 0, | ||
5055 | AC_VERB_SET_CONNECT_SEL, index); | ||
5056 | spec->dmic_enabled = index; | ||
5057 | set_jack_power_state(codec); | ||
5058 | |||
5059 | return 1; | ||
5060 | } | ||
5061 | |||
5062 | /* capture mixer elements */ | ||
5063 | static struct snd_kcontrol_new vt1716S_capture_mixer[] = { | ||
5064 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), | ||
5065 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | ||
5066 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | ||
5067 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | ||
5068 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), | ||
5069 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, | ||
5070 | HDA_INPUT), | ||
5071 | { | ||
5072 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
5073 | .name = "Input Source", | ||
5074 | .count = 1, | ||
5075 | .info = via_mux_enum_info, | ||
5076 | .get = via_mux_enum_get, | ||
5077 | .put = via_mux_enum_put, | ||
5078 | }, | ||
5079 | { } /* end */ | ||
5080 | }; | ||
5081 | |||
5082 | static struct snd_kcontrol_new vt1716s_dmic_mixer[] = { | ||
5083 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), | ||
5084 | { | ||
5085 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
5086 | .name = "Digital Mic Capture Switch", | ||
5087 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, | ||
5088 | .count = 1, | ||
5089 | .info = vt1716s_dmic_info, | ||
5090 | .get = vt1716s_dmic_get, | ||
5091 | .put = vt1716s_dmic_put, | ||
5092 | }, | ||
5093 | {} /* end */ | ||
5094 | }; | ||
5095 | |||
5096 | |||
5097 | /* mono-out mixer elements */ | ||
5098 | static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { | ||
5099 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), | ||
5100 | { } /* end */ | ||
5101 | }; | ||
5102 | |||
5103 | static struct hda_verb vt1716S_volume_init_verbs[] = { | ||
5104 | /* | ||
5105 | * Unmute ADC0-1 and set the default input to mic-in | ||
5106 | */ | ||
5107 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5108 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5109 | |||
5110 | |||
5111 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | ||
5112 | * mixer widget | ||
5113 | */ | ||
5114 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | ||
5115 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | ||
5116 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
5117 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | ||
5118 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | ||
5119 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | ||
5120 | |||
5121 | /* MUX Indices: Stereo Mixer = 5 */ | ||
5122 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, | ||
5123 | |||
5124 | /* Setup default input of PW4 to MW0 */ | ||
5125 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | ||
5126 | |||
5127 | /* Setup default input of SW1 as MW0 */ | ||
5128 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, | ||
5129 | |||
5130 | /* Setup default input of SW4 as AOW0 */ | ||
5131 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, | ||
5132 | |||
5133 | /* PW9 PW10 Output enable */ | ||
5134 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | ||
5135 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | ||
5136 | |||
5137 | /* Unmute SW1, PW12 */ | ||
5138 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5139 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | ||
5140 | /* PW12 Output enable */ | ||
5141 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | ||
5142 | /* Enable Boost Volume backdoor */ | ||
5143 | {0x1, 0xf8a, 0x80}, | ||
5144 | /* don't bybass mixer */ | ||
5145 | {0x1, 0xf88, 0xc0}, | ||
5146 | /* Enable mono output */ | ||
5147 | {0x1, 0xf90, 0x08}, | ||
5148 | { } | ||
5149 | }; | ||
5150 | |||
5151 | |||
5152 | static struct hda_verb vt1716S_uniwill_init_verbs[] = { | ||
5153 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
5154 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | ||
5155 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5156 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5157 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5158 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
5159 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, | ||
5160 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5161 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5162 | { } | ||
5163 | }; | ||
5164 | |||
5165 | static struct hda_pcm_stream vt1716S_pcm_analog_playback = { | ||
5166 | .substreams = 2, | ||
5167 | .channels_min = 2, | ||
5168 | .channels_max = 6, | ||
5169 | .nid = 0x10, /* NID to query formats and rates */ | ||
5170 | .ops = { | ||
5171 | .open = via_playback_pcm_open, | ||
5172 | .prepare = via_playback_multi_pcm_prepare, | ||
5173 | .cleanup = via_playback_multi_pcm_cleanup, | ||
5174 | .close = via_pcm_open_close, | ||
5175 | }, | ||
5176 | }; | ||
5177 | |||
5178 | static struct hda_pcm_stream vt1716S_pcm_analog_capture = { | ||
5179 | .substreams = 2, | ||
5180 | .channels_min = 2, | ||
5181 | .channels_max = 2, | ||
5182 | .nid = 0x13, /* NID to query formats and rates */ | ||
5183 | .ops = { | ||
5184 | .open = via_pcm_open_close, | ||
5185 | .prepare = via_capture_pcm_prepare, | ||
5186 | .cleanup = via_capture_pcm_cleanup, | ||
5187 | .close = via_pcm_open_close, | ||
5188 | }, | ||
5189 | }; | ||
5190 | |||
5191 | static struct hda_pcm_stream vt1716S_pcm_digital_playback = { | ||
5192 | .substreams = 2, | ||
5193 | .channels_min = 2, | ||
5194 | .channels_max = 2, | ||
5195 | /* NID is set in via_build_pcms */ | ||
5196 | .ops = { | ||
5197 | .open = via_dig_playback_pcm_open, | ||
5198 | .close = via_dig_playback_pcm_close, | ||
5199 | .prepare = via_dig_playback_pcm_prepare, | ||
5200 | .cleanup = via_dig_playback_pcm_cleanup | ||
5201 | }, | ||
5202 | }; | ||
5203 | |||
5204 | /* fill in the dac_nids table from the parsed pin configuration */ | ||
5205 | static int vt1716S_auto_fill_dac_nids(struct via_spec *spec, | ||
5206 | const struct auto_pin_cfg *cfg) | ||
5207 | { int i; | ||
5208 | hda_nid_t nid; | ||
5209 | |||
5210 | spec->multiout.num_dacs = cfg->line_outs; | ||
5211 | |||
5212 | spec->multiout.dac_nids = spec->private_dac_nids; | ||
5213 | |||
5214 | for (i = 0; i < 3; i++) { | ||
5215 | nid = cfg->line_out_pins[i]; | ||
5216 | if (nid) { | ||
5217 | /* config dac list */ | ||
5218 | switch (i) { | ||
5219 | case AUTO_SEQ_FRONT: | ||
5220 | spec->multiout.dac_nids[i] = 0x10; | ||
5221 | break; | ||
5222 | case AUTO_SEQ_CENLFE: | ||
5223 | spec->multiout.dac_nids[i] = 0x25; | ||
5224 | break; | ||
5225 | case AUTO_SEQ_SURROUND: | ||
5226 | spec->multiout.dac_nids[i] = 0x11; | ||
5227 | break; | ||
5228 | } | ||
5229 | } | ||
5230 | } | ||
5231 | |||
5232 | return 0; | ||
5233 | } | ||
5234 | |||
5235 | /* add playback controls from the parsed DAC table */ | ||
5236 | static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec, | ||
5237 | const struct auto_pin_cfg *cfg) | ||
5238 | { | ||
5239 | char name[32]; | ||
5240 | static const char *chname[3] = { "Front", "Surround", "C/LFE" }; | ||
5241 | hda_nid_t nid_vols[] = {0x10, 0x11, 0x25}; | ||
5242 | hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27}; | ||
5243 | hda_nid_t nid, nid_vol, nid_mute; | ||
5244 | int i, err; | ||
5245 | |||
5246 | for (i = 0; i <= AUTO_SEQ_CENLFE; i++) { | ||
5247 | nid = cfg->line_out_pins[i]; | ||
5248 | |||
5249 | if (!nid) | ||
5250 | continue; | ||
5251 | |||
5252 | nid_vol = nid_vols[i]; | ||
5253 | nid_mute = nid_mutes[i]; | ||
5254 | |||
5255 | if (i == AUTO_SEQ_CENLFE) { | ||
5256 | err = via_add_control( | ||
5257 | spec, VIA_CTL_WIDGET_VOL, | ||
5258 | "Center Playback Volume", | ||
5259 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT)); | ||
5260 | if (err < 0) | ||
5261 | return err; | ||
5262 | err = via_add_control( | ||
5263 | spec, VIA_CTL_WIDGET_VOL, | ||
5264 | "LFE Playback Volume", | ||
5265 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT)); | ||
5266 | if (err < 0) | ||
5267 | return err; | ||
5268 | err = via_add_control( | ||
5269 | spec, VIA_CTL_WIDGET_MUTE, | ||
5270 | "Center Playback Switch", | ||
5271 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, | ||
5272 | HDA_OUTPUT)); | ||
5273 | if (err < 0) | ||
5274 | return err; | ||
5275 | err = via_add_control( | ||
5276 | spec, VIA_CTL_WIDGET_MUTE, | ||
5277 | "LFE Playback Switch", | ||
5278 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, | ||
5279 | HDA_OUTPUT)); | ||
5280 | if (err < 0) | ||
5281 | return err; | ||
5282 | } else if (i == AUTO_SEQ_FRONT) { | ||
5283 | |||
5284 | err = via_add_control( | ||
5285 | spec, VIA_CTL_WIDGET_VOL, | ||
5286 | "Master Front Playback Volume", | ||
5287 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); | ||
5288 | if (err < 0) | ||
5289 | return err; | ||
5290 | err = via_add_control( | ||
5291 | spec, VIA_CTL_WIDGET_MUTE, | ||
5292 | "Master Front Playback Switch", | ||
5293 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); | ||
5294 | if (err < 0) | ||
5295 | return err; | ||
5296 | |||
5297 | sprintf(name, "%s Playback Volume", chname[i]); | ||
5298 | err = via_add_control( | ||
5299 | spec, VIA_CTL_WIDGET_VOL, name, | ||
5300 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | ||
5301 | if (err < 0) | ||
5302 | return err; | ||
5303 | sprintf(name, "%s Playback Switch", chname[i]); | ||
5304 | err = via_add_control( | ||
5305 | spec, VIA_CTL_WIDGET_MUTE, name, | ||
5306 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | ||
5307 | HDA_OUTPUT)); | ||
5308 | if (err < 0) | ||
5309 | return err; | ||
5310 | } else { | ||
5311 | sprintf(name, "%s Playback Volume", chname[i]); | ||
5312 | err = via_add_control( | ||
5313 | spec, VIA_CTL_WIDGET_VOL, name, | ||
5314 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | ||
5315 | if (err < 0) | ||
5316 | return err; | ||
5317 | sprintf(name, "%s Playback Switch", chname[i]); | ||
5318 | err = via_add_control( | ||
5319 | spec, VIA_CTL_WIDGET_MUTE, name, | ||
5320 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | ||
5321 | HDA_OUTPUT)); | ||
5322 | if (err < 0) | ||
5323 | return err; | ||
5324 | } | ||
5325 | } | ||
5326 | return 0; | ||
5327 | } | ||
5328 | |||
5329 | static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | ||
5330 | { | ||
5331 | int err; | ||
5332 | |||
5333 | if (!pin) | ||
5334 | return 0; | ||
5335 | |||
5336 | spec->multiout.hp_nid = 0x25; /* AOW3 */ | ||
5337 | spec->hp_independent_mode_index = 1; | ||
5338 | |||
5339 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
5340 | "Headphone Playback Volume", | ||
5341 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); | ||
5342 | if (err < 0) | ||
5343 | return err; | ||
5344 | |||
5345 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | ||
5346 | "Headphone Playback Switch", | ||
5347 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | ||
5348 | if (err < 0) | ||
5349 | return err; | ||
5350 | |||
5351 | create_hp_imux(spec); | ||
5352 | return 0; | ||
5353 | } | ||
5354 | |||
5355 | /* create playback/capture controls for input pins */ | ||
5356 | static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec, | ||
5357 | const struct auto_pin_cfg *cfg) | ||
5358 | { | ||
5359 | static char *labels[] = { | ||
5360 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | ||
5361 | }; | ||
5362 | struct hda_input_mux *imux = &spec->private_imux[0]; | ||
5363 | int i, err, idx = 0; | ||
5364 | |||
5365 | /* for internal loopback recording select */ | ||
5366 | imux->items[imux->num_items].label = "Stereo Mixer"; | ||
5367 | imux->items[imux->num_items].index = 5; | ||
5368 | imux->num_items++; | ||
5369 | |||
5370 | for (i = 0; i < AUTO_PIN_LAST; i++) { | ||
5371 | if (!cfg->input_pins[i]) | ||
5372 | continue; | ||
5373 | |||
5374 | switch (cfg->input_pins[i]) { | ||
5375 | case 0x1a: /* Mic */ | ||
5376 | idx = 2; | ||
5377 | break; | ||
5378 | |||
5379 | case 0x1b: /* Line In */ | ||
5380 | idx = 3; | ||
5381 | break; | ||
5382 | |||
5383 | case 0x1e: /* Front Mic */ | ||
5384 | idx = 4; | ||
5385 | break; | ||
5386 | |||
5387 | case 0x1f: /* CD */ | ||
5388 | idx = 1; | ||
5389 | break; | ||
5390 | } | ||
5391 | err = via_new_analog_input(spec, labels[i], idx, 0x16); | ||
5392 | if (err < 0) | ||
5393 | return err; | ||
5394 | imux->items[imux->num_items].label = labels[i]; | ||
5395 | imux->items[imux->num_items].index = idx-1; | ||
5396 | imux->num_items++; | ||
5397 | } | ||
5398 | return 0; | ||
5399 | } | ||
5400 | |||
5401 | static int vt1716S_parse_auto_config(struct hda_codec *codec) | ||
5402 | { | ||
5403 | struct via_spec *spec = codec->spec; | ||
5404 | int err; | ||
5405 | |||
5406 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | ||
5407 | if (err < 0) | ||
5408 | return err; | ||
5409 | err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg); | ||
5410 | if (err < 0) | ||
5411 | return err; | ||
5412 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | ||
5413 | return 0; /* can't find valid BIOS pin config */ | ||
5414 | |||
5415 | err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg); | ||
5416 | if (err < 0) | ||
5417 | return err; | ||
5418 | err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | ||
5419 | if (err < 0) | ||
5420 | return err; | ||
5421 | err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg); | ||
5422 | if (err < 0) | ||
5423 | return err; | ||
5424 | |||
5425 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | ||
5426 | |||
5427 | fill_dig_outs(codec); | ||
5428 | |||
5429 | if (spec->kctls.list) | ||
5430 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | ||
5431 | |||
5432 | spec->input_mux = &spec->private_imux[0]; | ||
5433 | |||
5434 | if (spec->hp_mux) | ||
5435 | via_hp_build(codec); | ||
5436 | |||
5437 | via_smart51_build(spec); | ||
5438 | |||
5439 | return 1; | ||
5440 | } | ||
5441 | |||
5442 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
5443 | static struct hda_amp_list vt1716S_loopbacks[] = { | ||
5444 | { 0x16, HDA_INPUT, 1 }, | ||
5445 | { 0x16, HDA_INPUT, 2 }, | ||
5446 | { 0x16, HDA_INPUT, 3 }, | ||
5447 | { 0x16, HDA_INPUT, 4 }, | ||
5448 | { } /* end */ | ||
5449 | }; | ||
5450 | #endif | ||
5451 | |||
5452 | static int patch_vt1716S(struct hda_codec *codec) | ||
5453 | { | ||
5454 | struct via_spec *spec; | ||
5455 | int err; | ||
5456 | |||
5457 | /* create a codec specific record */ | ||
5458 | spec = via_new_spec(codec); | ||
5459 | if (spec == NULL) | ||
5460 | return -ENOMEM; | ||
5461 | |||
5462 | /* automatic parse from the BIOS config */ | ||
5463 | err = vt1716S_parse_auto_config(codec); | ||
5464 | if (err < 0) { | ||
5465 | via_free(codec); | ||
5466 | return err; | ||
5467 | } else if (!err) { | ||
5468 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | ||
5469 | "from BIOS. Using genenic mode...\n"); | ||
5470 | } | ||
5471 | |||
5472 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; | ||
5473 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; | ||
5474 | |||
5475 | spec->stream_name_analog = "VT1716S Analog"; | ||
5476 | spec->stream_analog_playback = &vt1716S_pcm_analog_playback; | ||
5477 | spec->stream_analog_capture = &vt1716S_pcm_analog_capture; | ||
5478 | |||
5479 | spec->stream_name_digital = "VT1716S Digital"; | ||
5480 | spec->stream_digital_playback = &vt1716S_pcm_digital_playback; | ||
5481 | |||
5482 | if (!spec->adc_nids && spec->input_mux) { | ||
5483 | spec->adc_nids = vt1716S_adc_nids; | ||
5484 | spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids); | ||
5485 | get_mux_nids(codec); | ||
5486 | override_mic_boost(codec, 0x1a, 0, 3, 40); | ||
5487 | override_mic_boost(codec, 0x1e, 0, 3, 40); | ||
5488 | spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; | ||
5489 | spec->num_mixers++; | ||
5490 | } | ||
5491 | |||
5492 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; | ||
5493 | spec->num_mixers++; | ||
5494 | |||
5495 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; | ||
5496 | |||
5497 | codec->patch_ops = via_patch_ops; | ||
5498 | |||
5499 | codec->patch_ops.init = via_auto_init; | ||
5500 | codec->patch_ops.unsol_event = via_unsol_event; | ||
5501 | |||
5502 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
5503 | spec->loopback.amplist = vt1716S_loopbacks; | ||
5504 | #endif | ||
5505 | |||
5506 | return 0; | ||
5507 | } | ||
5508 | |||
5509 | /* for vt2002P */ | ||
5510 | |||
5511 | /* capture mixer elements */ | ||
5512 | static struct snd_kcontrol_new vt2002P_capture_mixer[] = { | ||
5513 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), | ||
5514 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), | ||
5515 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), | ||
5516 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), | ||
5517 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), | ||
5518 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, | ||
5519 | HDA_INPUT), | ||
5520 | { | ||
5521 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
5522 | /* The multiple "Capture Source" controls confuse alsamixer | ||
5523 | * So call somewhat different.. | ||
5524 | */ | ||
5525 | /* .name = "Capture Source", */ | ||
5526 | .name = "Input Source", | ||
5527 | .count = 2, | ||
5528 | .info = via_mux_enum_info, | ||
5529 | .get = via_mux_enum_get, | ||
5530 | .put = via_mux_enum_put, | ||
5531 | }, | ||
5532 | { } /* end */ | ||
5533 | }; | ||
5534 | |||
5535 | static struct hda_verb vt2002P_volume_init_verbs[] = { | ||
5536 | /* | ||
5537 | * Unmute ADC0-1 and set the default input to mic-in | ||
5538 | */ | ||
5539 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5540 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5541 | |||
5542 | |||
5543 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | ||
5544 | * mixer widget | ||
5545 | */ | ||
5546 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | ||
5547 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | ||
5548 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
5549 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | ||
5550 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | ||
5551 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | ||
5552 | |||
5553 | /* MUX Indices: Mic = 0 */ | ||
5554 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5555 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5556 | |||
5557 | /* PW9 Output enable */ | ||
5558 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | ||
5559 | |||
5560 | /* Enable Boost Volume backdoor */ | ||
5561 | {0x1, 0xfb9, 0x24}, | ||
5562 | |||
5563 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | ||
5564 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5565 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5566 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5567 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5568 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5569 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5570 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5571 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5572 | |||
5573 | /* set MUX0/1/4/8 = 0 (AOW0) */ | ||
5574 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5575 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5576 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5577 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5578 | |||
5579 | /* set PW0 index=0 (MW0) */ | ||
5580 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5581 | |||
5582 | /* Enable AOW0 to MW9 */ | ||
5583 | {0x1, 0xfb8, 0x88}, | ||
5584 | { } | ||
5585 | }; | ||
5586 | |||
5587 | |||
5588 | static struct hda_verb vt2002P_uniwill_init_verbs[] = { | ||
5589 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
5590 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | ||
5591 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
5592 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | ||
5593 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5594 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5595 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5596 | { } | ||
5597 | }; | ||
5598 | |||
5599 | static struct hda_pcm_stream vt2002P_pcm_analog_playback = { | ||
5600 | .substreams = 2, | ||
5601 | .channels_min = 2, | ||
5602 | .channels_max = 2, | ||
5603 | .nid = 0x8, /* NID to query formats and rates */ | ||
5604 | .ops = { | ||
5605 | .open = via_playback_pcm_open, | ||
5606 | .prepare = via_playback_multi_pcm_prepare, | ||
5607 | .cleanup = via_playback_multi_pcm_cleanup, | ||
5608 | .close = via_pcm_open_close, | ||
5609 | }, | ||
5610 | }; | ||
5611 | |||
5612 | static struct hda_pcm_stream vt2002P_pcm_analog_capture = { | ||
5613 | .substreams = 2, | ||
5614 | .channels_min = 2, | ||
5615 | .channels_max = 2, | ||
5616 | .nid = 0x10, /* NID to query formats and rates */ | ||
5617 | .ops = { | ||
5618 | .open = via_pcm_open_close, | ||
5619 | .prepare = via_capture_pcm_prepare, | ||
5620 | .cleanup = via_capture_pcm_cleanup, | ||
5621 | .close = via_pcm_open_close, | ||
5622 | }, | ||
5623 | }; | ||
5624 | |||
5625 | static struct hda_pcm_stream vt2002P_pcm_digital_playback = { | ||
5626 | .substreams = 1, | ||
5627 | .channels_min = 2, | ||
5628 | .channels_max = 2, | ||
5629 | /* NID is set in via_build_pcms */ | ||
5630 | .ops = { | ||
5631 | .open = via_dig_playback_pcm_open, | ||
5632 | .close = via_dig_playback_pcm_close, | ||
5633 | .prepare = via_dig_playback_pcm_prepare, | ||
5634 | .cleanup = via_dig_playback_pcm_cleanup | ||
5635 | }, | ||
5636 | }; | ||
5637 | |||
5638 | /* fill in the dac_nids table from the parsed pin configuration */ | ||
5639 | static int vt2002P_auto_fill_dac_nids(struct via_spec *spec, | ||
5640 | const struct auto_pin_cfg *cfg) | ||
5641 | { | ||
5642 | spec->multiout.num_dacs = 1; | ||
5643 | spec->multiout.dac_nids = spec->private_dac_nids; | ||
5644 | if (cfg->line_out_pins[0]) | ||
5645 | spec->multiout.dac_nids[0] = 0x8; | ||
5646 | return 0; | ||
5647 | } | ||
5648 | |||
5649 | /* add playback controls from the parsed DAC table */ | ||
5650 | static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec, | ||
5651 | const struct auto_pin_cfg *cfg) | ||
5652 | { | ||
5653 | int err; | ||
5654 | |||
5655 | if (!cfg->line_out_pins[0]) | ||
5656 | return -1; | ||
5657 | |||
5658 | |||
5659 | /* Line-Out: PortE */ | ||
5660 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
5661 | "Master Front Playback Volume", | ||
5662 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); | ||
5663 | if (err < 0) | ||
5664 | return err; | ||
5665 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, | ||
5666 | "Master Front Playback Switch", | ||
5667 | HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT)); | ||
5668 | if (err < 0) | ||
5669 | return err; | ||
5670 | |||
5671 | return 0; | ||
5672 | } | ||
5673 | |||
5674 | static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | ||
5675 | { | ||
5676 | int err; | ||
5677 | |||
5678 | if (!pin) | ||
5679 | return 0; | ||
5680 | |||
5681 | spec->multiout.hp_nid = 0x9; | ||
5682 | spec->hp_independent_mode_index = 1; | ||
5683 | |||
5684 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
5685 | "Headphone Playback Volume", | ||
5686 | HDA_COMPOSE_AMP_VAL( | ||
5687 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); | ||
5688 | if (err < 0) | ||
5689 | return err; | ||
5690 | |||
5691 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | ||
5692 | "Headphone Playback Switch", | ||
5693 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); | ||
5694 | if (err < 0) | ||
5695 | return err; | ||
5696 | |||
5697 | create_hp_imux(spec); | ||
5698 | return 0; | ||
5699 | } | ||
5700 | |||
5701 | /* create playback/capture controls for input pins */ | ||
5702 | static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec, | ||
5703 | const struct auto_pin_cfg *cfg) | ||
5704 | { | ||
5705 | static char *labels[] = { | ||
5706 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | ||
5707 | }; | ||
5708 | struct hda_input_mux *imux = &spec->private_imux[0]; | ||
5709 | int i, err, idx = 0; | ||
5710 | |||
5711 | for (i = 0; i < AUTO_PIN_LAST; i++) { | ||
5712 | if (!cfg->input_pins[i]) | ||
5713 | continue; | ||
5714 | |||
5715 | switch (cfg->input_pins[i]) { | ||
5716 | case 0x2b: /* Mic */ | ||
5717 | idx = 0; | ||
5718 | break; | ||
5719 | |||
5720 | case 0x2a: /* Line In */ | ||
5721 | idx = 1; | ||
5722 | break; | ||
5723 | |||
5724 | case 0x29: /* Front Mic */ | ||
5725 | idx = 2; | ||
5726 | break; | ||
5727 | } | ||
5728 | err = via_new_analog_input(spec, labels[i], idx, 0x21); | ||
5729 | if (err < 0) | ||
5730 | return err; | ||
5731 | imux->items[imux->num_items].label = labels[i]; | ||
5732 | imux->items[imux->num_items].index = idx; | ||
5733 | imux->num_items++; | ||
5734 | } | ||
5735 | |||
5736 | /* build volume/mute control of loopback */ | ||
5737 | err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21); | ||
5738 | if (err < 0) | ||
5739 | return err; | ||
5740 | |||
5741 | /* for internal loopback recording select */ | ||
5742 | imux->items[imux->num_items].label = "Stereo Mixer"; | ||
5743 | imux->items[imux->num_items].index = 3; | ||
5744 | imux->num_items++; | ||
5745 | |||
5746 | /* for digital mic select */ | ||
5747 | imux->items[imux->num_items].label = "Digital Mic"; | ||
5748 | imux->items[imux->num_items].index = 4; | ||
5749 | imux->num_items++; | ||
5750 | |||
5751 | return 0; | ||
5752 | } | ||
5753 | |||
5754 | static int vt2002P_parse_auto_config(struct hda_codec *codec) | ||
5755 | { | ||
5756 | struct via_spec *spec = codec->spec; | ||
5757 | int err; | ||
5758 | |||
5759 | |||
5760 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | ||
5761 | if (err < 0) | ||
5762 | return err; | ||
5763 | |||
5764 | err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg); | ||
5765 | if (err < 0) | ||
5766 | return err; | ||
5767 | |||
5768 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | ||
5769 | return 0; /* can't find valid BIOS pin config */ | ||
5770 | |||
5771 | err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg); | ||
5772 | if (err < 0) | ||
5773 | return err; | ||
5774 | err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | ||
5775 | if (err < 0) | ||
5776 | return err; | ||
5777 | err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg); | ||
5778 | if (err < 0) | ||
5779 | return err; | ||
5780 | |||
5781 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | ||
5782 | |||
5783 | fill_dig_outs(codec); | ||
5784 | |||
5785 | if (spec->kctls.list) | ||
5786 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | ||
5787 | |||
5788 | spec->input_mux = &spec->private_imux[0]; | ||
5789 | |||
5790 | if (spec->hp_mux) | ||
5791 | via_hp_build(codec); | ||
5792 | |||
5793 | return 1; | ||
5794 | } | ||
5795 | |||
5796 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
5797 | static struct hda_amp_list vt2002P_loopbacks[] = { | ||
5798 | { 0x21, HDA_INPUT, 0 }, | ||
5799 | { 0x21, HDA_INPUT, 1 }, | ||
5800 | { 0x21, HDA_INPUT, 2 }, | ||
5801 | { } /* end */ | ||
5802 | }; | ||
5803 | #endif | ||
5804 | |||
5805 | |||
5806 | /* patch for vt2002P */ | ||
5807 | static int patch_vt2002P(struct hda_codec *codec) | ||
5808 | { | ||
5809 | struct via_spec *spec; | ||
5810 | int err; | ||
5811 | |||
5812 | /* create a codec specific record */ | ||
5813 | spec = via_new_spec(codec); | ||
5814 | if (spec == NULL) | ||
5815 | return -ENOMEM; | ||
5816 | |||
5817 | /* automatic parse from the BIOS config */ | ||
5818 | err = vt2002P_parse_auto_config(codec); | ||
5819 | if (err < 0) { | ||
5820 | via_free(codec); | ||
5821 | return err; | ||
5822 | } else if (!err) { | ||
5823 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | ||
5824 | "from BIOS. Using genenic mode...\n"); | ||
5825 | } | ||
5826 | |||
5827 | spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs; | ||
5828 | spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs; | ||
5829 | |||
5830 | spec->stream_name_analog = "VT2002P Analog"; | ||
5831 | spec->stream_analog_playback = &vt2002P_pcm_analog_playback; | ||
5832 | spec->stream_analog_capture = &vt2002P_pcm_analog_capture; | ||
5833 | |||
5834 | spec->stream_name_digital = "VT2002P Digital"; | ||
5835 | spec->stream_digital_playback = &vt2002P_pcm_digital_playback; | ||
5836 | |||
5837 | if (!spec->adc_nids && spec->input_mux) { | ||
5838 | spec->adc_nids = vt2002P_adc_nids; | ||
5839 | spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids); | ||
5840 | get_mux_nids(codec); | ||
5841 | override_mic_boost(codec, 0x2b, 0, 3, 40); | ||
5842 | override_mic_boost(codec, 0x29, 0, 3, 40); | ||
5843 | spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; | ||
5844 | spec->num_mixers++; | ||
5845 | } | ||
5846 | |||
5847 | codec->patch_ops = via_patch_ops; | ||
5848 | |||
5849 | codec->patch_ops.init = via_auto_init; | ||
5850 | codec->patch_ops.unsol_event = via_unsol_event; | ||
5851 | |||
5852 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
5853 | spec->loopback.amplist = vt2002P_loopbacks; | ||
5854 | #endif | ||
5855 | |||
5856 | return 0; | ||
5857 | } | ||
5858 | |||
5859 | /* for vt1812 */ | ||
5860 | |||
5861 | /* capture mixer elements */ | ||
5862 | static struct snd_kcontrol_new vt1812_capture_mixer[] = { | ||
5863 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), | ||
5864 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), | ||
5865 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), | ||
5866 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), | ||
5867 | HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), | ||
5868 | HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, | ||
5869 | HDA_INPUT), | ||
5870 | { | ||
5871 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | ||
5872 | /* The multiple "Capture Source" controls confuse alsamixer | ||
5873 | * So call somewhat different.. | ||
5874 | */ | ||
5875 | .name = "Input Source", | ||
5876 | .count = 2, | ||
5877 | .info = via_mux_enum_info, | ||
5878 | .get = via_mux_enum_get, | ||
5879 | .put = via_mux_enum_put, | ||
5880 | }, | ||
5881 | { } /* end */ | ||
5882 | }; | ||
5883 | |||
5884 | static struct hda_verb vt1812_volume_init_verbs[] = { | ||
5885 | /* | ||
5886 | * Unmute ADC0-1 and set the default input to mic-in | ||
5887 | */ | ||
5888 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5889 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5890 | |||
5891 | |||
5892 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | ||
5893 | * mixer widget | ||
5894 | */ | ||
5895 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | ||
5896 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | ||
5897 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | ||
5898 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | ||
5899 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | ||
5900 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | ||
5901 | |||
5902 | /* MUX Indices: Mic = 0 */ | ||
5903 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5904 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5905 | |||
5906 | /* PW9 Output enable */ | ||
5907 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | ||
5908 | |||
5909 | /* Enable Boost Volume backdoor */ | ||
5910 | {0x1, 0xfb9, 0x24}, | ||
5911 | |||
5912 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | ||
5913 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5914 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5915 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5916 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5917 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | ||
5918 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5919 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5920 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5921 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5922 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | ||
5923 | |||
5924 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ | ||
5925 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5926 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5927 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5928 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5929 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, | ||
5930 | |||
5931 | /* Enable AOW0 to MW9 */ | ||
5932 | {0x1, 0xfb8, 0xa8}, | ||
5933 | { } | ||
5934 | }; | ||
5935 | |||
5936 | |||
5937 | static struct hda_verb vt1812_uniwill_init_verbs[] = { | ||
5938 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
5939 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | ||
5940 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, | ||
5941 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, | ||
5942 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | ||
5943 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5944 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5945 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | ||
5946 | { } | ||
5947 | }; | ||
5948 | |||
5949 | static struct hda_pcm_stream vt1812_pcm_analog_playback = { | ||
5950 | .substreams = 2, | ||
5951 | .channels_min = 2, | ||
5952 | .channels_max = 2, | ||
5953 | .nid = 0x8, /* NID to query formats and rates */ | ||
5954 | .ops = { | ||
5955 | .open = via_playback_pcm_open, | ||
5956 | .prepare = via_playback_multi_pcm_prepare, | ||
5957 | .cleanup = via_playback_multi_pcm_cleanup, | ||
5958 | .close = via_pcm_open_close, | ||
5959 | }, | ||
5960 | }; | ||
5961 | |||
5962 | static struct hda_pcm_stream vt1812_pcm_analog_capture = { | ||
5963 | .substreams = 2, | ||
5964 | .channels_min = 2, | ||
5965 | .channels_max = 2, | ||
5966 | .nid = 0x10, /* NID to query formats and rates */ | ||
5967 | .ops = { | ||
5968 | .open = via_pcm_open_close, | ||
5969 | .prepare = via_capture_pcm_prepare, | ||
5970 | .cleanup = via_capture_pcm_cleanup, | ||
5971 | .close = via_pcm_open_close, | ||
5972 | }, | ||
5973 | }; | ||
5974 | |||
5975 | static struct hda_pcm_stream vt1812_pcm_digital_playback = { | ||
5976 | .substreams = 1, | ||
5977 | .channels_min = 2, | ||
5978 | .channels_max = 2, | ||
5979 | /* NID is set in via_build_pcms */ | ||
5980 | .ops = { | ||
5981 | .open = via_dig_playback_pcm_open, | ||
5982 | .close = via_dig_playback_pcm_close, | ||
5983 | .prepare = via_dig_playback_pcm_prepare, | ||
5984 | .cleanup = via_dig_playback_pcm_cleanup | ||
5985 | }, | ||
5986 | }; | ||
5987 | /* fill in the dac_nids table from the parsed pin configuration */ | ||
5988 | static int vt1812_auto_fill_dac_nids(struct via_spec *spec, | ||
5989 | const struct auto_pin_cfg *cfg) | ||
5990 | { | ||
5991 | spec->multiout.num_dacs = 1; | ||
5992 | spec->multiout.dac_nids = spec->private_dac_nids; | ||
5993 | if (cfg->line_out_pins[0]) | ||
5994 | spec->multiout.dac_nids[0] = 0x8; | ||
5995 | return 0; | ||
5996 | } | ||
5997 | |||
5998 | |||
5999 | /* add playback controls from the parsed DAC table */ | ||
6000 | static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec, | ||
6001 | const struct auto_pin_cfg *cfg) | ||
6002 | { | ||
6003 | int err; | ||
6004 | |||
6005 | if (!cfg->line_out_pins[0]) | ||
6006 | return -1; | ||
6007 | |||
6008 | /* Line-Out: PortE */ | ||
6009 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
6010 | "Front Playback Volume", | ||
6011 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); | ||
6012 | if (err < 0) | ||
6013 | return err; | ||
6014 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, | ||
6015 | "Front Playback Switch", | ||
6016 | HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT)); | ||
6017 | if (err < 0) | ||
6018 | return err; | ||
6019 | |||
6020 | return 0; | ||
6021 | } | ||
6022 | |||
6023 | static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | ||
6024 | { | ||
6025 | int err; | ||
6026 | |||
6027 | if (!pin) | ||
6028 | return 0; | ||
6029 | |||
6030 | spec->multiout.hp_nid = 0x9; | ||
6031 | spec->hp_independent_mode_index = 1; | ||
6032 | |||
6033 | |||
6034 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | ||
6035 | "Headphone Playback Volume", | ||
6036 | HDA_COMPOSE_AMP_VAL( | ||
6037 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); | ||
6038 | if (err < 0) | ||
6039 | return err; | ||
6040 | |||
6041 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | ||
6042 | "Headphone Playback Switch", | ||
6043 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | ||
6044 | if (err < 0) | ||
6045 | return err; | ||
6046 | |||
6047 | create_hp_imux(spec); | ||
6048 | return 0; | ||
6049 | } | ||
6050 | |||
6051 | /* create playback/capture controls for input pins */ | ||
6052 | static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec, | ||
6053 | const struct auto_pin_cfg *cfg) | ||
6054 | { | ||
6055 | static char *labels[] = { | ||
6056 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | ||
6057 | }; | ||
6058 | struct hda_input_mux *imux = &spec->private_imux[0]; | ||
6059 | int i, err, idx = 0; | ||
6060 | |||
6061 | for (i = 0; i < AUTO_PIN_LAST; i++) { | ||
6062 | if (!cfg->input_pins[i]) | ||
6063 | continue; | ||
6064 | |||
6065 | switch (cfg->input_pins[i]) { | ||
6066 | case 0x2b: /* Mic */ | ||
6067 | idx = 0; | ||
6068 | break; | ||
6069 | |||
6070 | case 0x2a: /* Line In */ | ||
6071 | idx = 1; | ||
6072 | break; | ||
6073 | |||
6074 | case 0x29: /* Front Mic */ | ||
6075 | idx = 2; | ||
6076 | break; | ||
6077 | } | ||
6078 | err = via_new_analog_input(spec, labels[i], idx, 0x21); | ||
6079 | if (err < 0) | ||
6080 | return err; | ||
6081 | imux->items[imux->num_items].label = labels[i]; | ||
6082 | imux->items[imux->num_items].index = idx; | ||
6083 | imux->num_items++; | ||
6084 | } | ||
6085 | /* build volume/mute control of loopback */ | ||
6086 | err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21); | ||
6087 | if (err < 0) | ||
6088 | return err; | ||
6089 | |||
6090 | /* for internal loopback recording select */ | ||
6091 | imux->items[imux->num_items].label = "Stereo Mixer"; | ||
6092 | imux->items[imux->num_items].index = 5; | ||
6093 | imux->num_items++; | ||
6094 | |||
6095 | /* for digital mic select */ | ||
6096 | imux->items[imux->num_items].label = "Digital Mic"; | ||
6097 | imux->items[imux->num_items].index = 6; | ||
6098 | imux->num_items++; | ||
6099 | |||
6100 | return 0; | ||
6101 | } | ||
6102 | |||
6103 | static int vt1812_parse_auto_config(struct hda_codec *codec) | ||
6104 | { | ||
6105 | struct via_spec *spec = codec->spec; | ||
6106 | int err; | ||
6107 | |||
6108 | |||
6109 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | ||
6110 | if (err < 0) | ||
6111 | return err; | ||
6112 | fill_dig_outs(codec); | ||
6113 | err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg); | ||
6114 | if (err < 0) | ||
6115 | return err; | ||
6116 | |||
6117 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) | ||
6118 | return 0; /* can't find valid BIOS pin config */ | ||
6119 | |||
6120 | err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg); | ||
6121 | if (err < 0) | ||
6122 | return err; | ||
6123 | err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | ||
6124 | if (err < 0) | ||
6125 | return err; | ||
6126 | err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg); | ||
6127 | if (err < 0) | ||
6128 | return err; | ||
6129 | |||
6130 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | ||
6131 | |||
6132 | fill_dig_outs(codec); | ||
6133 | |||
6134 | if (spec->kctls.list) | ||
6135 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | ||
6136 | |||
6137 | spec->input_mux = &spec->private_imux[0]; | ||
6138 | |||
6139 | if (spec->hp_mux) | ||
6140 | via_hp_build(codec); | ||
6141 | |||
6142 | return 1; | ||
6143 | } | ||
6144 | |||
6145 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
6146 | static struct hda_amp_list vt1812_loopbacks[] = { | ||
6147 | { 0x21, HDA_INPUT, 0 }, | ||
6148 | { 0x21, HDA_INPUT, 1 }, | ||
6149 | { 0x21, HDA_INPUT, 2 }, | ||
6150 | { } /* end */ | ||
6151 | }; | ||
6152 | #endif | ||
6153 | |||
6154 | |||
6155 | /* patch for vt1812 */ | ||
6156 | static int patch_vt1812(struct hda_codec *codec) | ||
6157 | { | ||
6158 | struct via_spec *spec; | ||
6159 | int err; | ||
6160 | |||
6161 | /* create a codec specific record */ | ||
6162 | spec = via_new_spec(codec); | ||
6163 | if (spec == NULL) | ||
6164 | return -ENOMEM; | ||
6165 | |||
6166 | /* automatic parse from the BIOS config */ | ||
6167 | err = vt1812_parse_auto_config(codec); | ||
6168 | if (err < 0) { | ||
6169 | via_free(codec); | ||
6170 | return err; | ||
6171 | } else if (!err) { | ||
6172 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | ||
6173 | "from BIOS. Using genenic mode...\n"); | ||
6174 | } | ||
6175 | |||
6176 | |||
6177 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; | ||
6178 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; | ||
6179 | |||
6180 | spec->stream_name_analog = "VT1812 Analog"; | ||
6181 | spec->stream_analog_playback = &vt1812_pcm_analog_playback; | ||
6182 | spec->stream_analog_capture = &vt1812_pcm_analog_capture; | ||
3239 | 6183 | ||
3240 | /* Enable GPIO 0&1 for volume&mute control */ | 6184 | spec->stream_name_digital = "VT1812 Digital"; |
3241 | /* Enable GPIO 2 for DMIC-DATA */ | 6185 | spec->stream_digital_playback = &vt1812_pcm_digital_playback; |
3242 | response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0); | 6186 | |
3243 | control = (unsigned char)((response >> 16) & 0x3f); | 6187 | |
3244 | snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control); | 6188 | if (!spec->adc_nids && spec->input_mux) { |
6189 | spec->adc_nids = vt1812_adc_nids; | ||
6190 | spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids); | ||
6191 | get_mux_nids(codec); | ||
6192 | override_mic_boost(codec, 0x2b, 0, 3, 40); | ||
6193 | override_mic_boost(codec, 0x29, 0, 3, 40); | ||
6194 | spec->mixers[spec->num_mixers] = vt1812_capture_mixer; | ||
6195 | spec->num_mixers++; | ||
6196 | } | ||
6197 | |||
6198 | codec->patch_ops = via_patch_ops; | ||
6199 | |||
6200 | codec->patch_ops.init = via_auto_init; | ||
6201 | codec->patch_ops.unsol_event = via_unsol_event; | ||
6202 | |||
6203 | #ifdef CONFIG_SND_HDA_POWER_SAVE | ||
6204 | spec->loopback.amplist = vt1812_loopbacks; | ||
6205 | #endif | ||
3245 | 6206 | ||
3246 | return 0; | 6207 | return 0; |
3247 | } | 6208 | } |
@@ -3318,6 +6279,23 @@ static struct hda_codec_preset snd_hda_preset_via[] = { | |||
3318 | .patch = patch_vt1702}, | 6279 | .patch = patch_vt1702}, |
3319 | { .id = 0x11067398, .name = "VT1702", | 6280 | { .id = 0x11067398, .name = "VT1702", |
3320 | .patch = patch_vt1702}, | 6281 | .patch = patch_vt1702}, |
6282 | { .id = 0x11060428, .name = "VT1718S", | ||
6283 | .patch = patch_vt1718S}, | ||
6284 | { .id = 0x11064428, .name = "VT1718S", | ||
6285 | .patch = patch_vt1718S}, | ||
6286 | { .id = 0x11060441, .name = "VT2020", | ||
6287 | .patch = patch_vt1718S}, | ||
6288 | { .id = 0x11064441, .name = "VT1828S", | ||
6289 | .patch = patch_vt1718S}, | ||
6290 | { .id = 0x11060433, .name = "VT1716S", | ||
6291 | .patch = patch_vt1716S}, | ||
6292 | { .id = 0x1106a721, .name = "VT1716S", | ||
6293 | .patch = patch_vt1716S}, | ||
6294 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, | ||
6295 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, | ||
6296 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, | ||
6297 | { .id = 0x11060440, .name = "VT1818S", | ||
6298 | .patch = patch_vt1708S}, | ||
3321 | {} /* terminator */ | 6299 | {} /* terminator */ |
3322 | }; | 6300 | }; |
3323 | 6301 | ||