Commit | Line | Data |
---|---|---|
c577b8a1 JC |
1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
8e86597f | 4 | * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec |
c577b8a1 | 5 | * |
8e86597f LW |
6 | * (C) 2006-2009 VIA Technology, Inc. |
7 | * (C) 2006-2008 Takashi Iwai <tiwai@suse.de> | |
c577b8a1 JC |
8 | * |
9 | * This driver is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This driver is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 | */ | |
23 | ||
24 | /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ | |
377ff31a | 25 | /* */ |
c577b8a1 | 26 | /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ |
377ff31a LW |
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 */ | |
c577b8a1 | 29 | /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ |
377ff31a LW |
30 | /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ |
31 | /* 2007-09-17 Lydia Wang Add VT1708B codec support */ | |
76d9b0dd | 32 | /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ |
fb4cb772 | 33 | /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ |
377ff31a LW |
34 | /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ |
35 | /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ | |
36 | /* 2008-04-09 Lydia Wang Add Independent HP feature */ | |
98aa34c0 | 37 | /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ |
377ff31a | 38 | /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ |
8e86597f LW |
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 */ | |
36dd5c4a | 44 | /* 2009-09-19 Lydia Wang Add support for VT1818S */ |
377ff31a | 45 | /* */ |
c577b8a1 JC |
46 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
47 | ||
48 | ||
c577b8a1 JC |
49 | #include <linux/init.h> |
50 | #include <linux/delay.h> | |
51 | #include <linux/slab.h> | |
c577b8a1 | 52 | #include <sound/core.h> |
0aa62aef | 53 | #include <sound/asoundef.h> |
c577b8a1 JC |
54 | #include "hda_codec.h" |
55 | #include "hda_local.h" | |
c577b8a1 | 56 | |
5b0cb1d8 JK |
57 | #define NID_MAPPING (-1) |
58 | ||
c577b8a1 JC |
59 | /* amp values */ |
60 | #define AMP_VAL_IDX_SHIFT 19 | |
61 | #define AMP_VAL_IDX_MASK (0x0f<<19) | |
62 | ||
c577b8a1 JC |
63 | /* Pin Widget NID */ |
64 | #define VT1708_HP_NID 0x13 | |
65 | #define VT1708_DIGOUT_NID 0x14 | |
66 | #define VT1708_DIGIN_NID 0x16 | |
f7278fd0 | 67 | #define VT1708_DIGIN_PIN 0x26 |
d949cac1 HW |
68 | #define VT1708_HP_PIN_NID 0x20 |
69 | #define VT1708_CD_PIN_NID 0x24 | |
c577b8a1 JC |
70 | |
71 | #define VT1709_HP_DAC_NID 0x28 | |
72 | #define VT1709_DIGOUT_NID 0x13 | |
73 | #define VT1709_DIGIN_NID 0x17 | |
f7278fd0 JC |
74 | #define VT1709_DIGIN_PIN 0x25 |
75 | ||
76 | #define VT1708B_HP_NID 0x25 | |
77 | #define VT1708B_DIGOUT_NID 0x12 | |
78 | #define VT1708B_DIGIN_NID 0x15 | |
79 | #define VT1708B_DIGIN_PIN 0x21 | |
c577b8a1 | 80 | |
d949cac1 HW |
81 | #define VT1708S_HP_NID 0x25 |
82 | #define VT1708S_DIGOUT_NID 0x12 | |
83 | ||
84 | #define VT1702_HP_NID 0x17 | |
85 | #define VT1702_DIGOUT_NID 0x11 | |
86 | ||
d7426329 HW |
87 | enum VIA_HDA_CODEC { |
88 | UNKNOWN = -1, | |
89 | VT1708, | |
90 | VT1709_10CH, | |
91 | VT1709_6CH, | |
92 | VT1708B_8CH, | |
93 | VT1708B_4CH, | |
94 | VT1708S, | |
518bf3ba | 95 | VT1708BCE, |
d7426329 | 96 | VT1702, |
eb7188ca | 97 | VT1718S, |
f3db423d | 98 | VT1716S, |
25eaba2f | 99 | VT2002P, |
ab6734e7 | 100 | VT1812, |
11890956 | 101 | VT1802, |
d7426329 HW |
102 | CODEC_TYPES, |
103 | }; | |
104 | ||
11890956 LW |
105 | #define VT2002P_COMPATIBLE(spec) \ |
106 | ((spec)->codec_type == VT2002P ||\ | |
107 | (spec)->codec_type == VT1812 ||\ | |
108 | (spec)->codec_type == VT1802) | |
109 | ||
4a79616d TI |
110 | struct nid_path { |
111 | int depth; | |
112 | hda_nid_t path[5]; | |
113 | short idx[5]; | |
114 | }; | |
115 | ||
1f2e99fe LW |
116 | struct via_spec { |
117 | /* codec parameterization */ | |
90dd48a1 | 118 | const struct snd_kcontrol_new *mixers[6]; |
1f2e99fe LW |
119 | unsigned int num_mixers; |
120 | ||
90dd48a1 | 121 | const struct hda_verb *init_verbs[5]; |
1f2e99fe LW |
122 | unsigned int num_iverbs; |
123 | ||
82673bc8 | 124 | char stream_name_analog[32]; |
7eb56e84 | 125 | char stream_name_hp[32]; |
90dd48a1 TI |
126 | const struct hda_pcm_stream *stream_analog_playback; |
127 | const struct hda_pcm_stream *stream_analog_capture; | |
1f2e99fe | 128 | |
82673bc8 | 129 | char stream_name_digital[32]; |
90dd48a1 TI |
130 | const struct hda_pcm_stream *stream_digital_playback; |
131 | const struct hda_pcm_stream *stream_digital_capture; | |
1f2e99fe LW |
132 | |
133 | /* playback */ | |
134 | struct hda_multi_out multiout; | |
135 | hda_nid_t slave_dig_outs[2]; | |
136 | ||
4a79616d TI |
137 | struct nid_path out_path[4]; |
138 | struct nid_path hp_path; | |
139 | struct nid_path hp_dep_path; | |
140 | ||
1f2e99fe LW |
141 | /* capture */ |
142 | unsigned int num_adc_nids; | |
a766d0d7 | 143 | hda_nid_t adc_nids[3]; |
1f2e99fe | 144 | hda_nid_t mux_nids[3]; |
620e2b28 | 145 | hda_nid_t aa_mix_nid; |
1f2e99fe LW |
146 | hda_nid_t dig_in_nid; |
147 | hda_nid_t dig_in_pin; | |
148 | ||
149 | /* capture source */ | |
150 | const struct hda_input_mux *input_mux; | |
151 | unsigned int cur_mux[3]; | |
152 | ||
153 | /* PCM information */ | |
154 | struct hda_pcm pcm_rec[3]; | |
155 | ||
156 | /* dynamic controls, init_verbs and input_mux */ | |
157 | struct auto_pin_cfg autocfg; | |
158 | struct snd_array kctls; | |
159 | struct hda_input_mux private_imux[2]; | |
160 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | |
161 | ||
162 | /* HP mode source */ | |
163 | const struct hda_input_mux *hp_mux; | |
164 | unsigned int hp_independent_mode; | |
165 | unsigned int hp_independent_mode_index; | |
f4a7828b | 166 | unsigned int can_smart51; |
1f2e99fe | 167 | unsigned int smart51_enabled; |
f3db423d | 168 | unsigned int dmic_enabled; |
24088a58 | 169 | unsigned int no_pin_power_ctl; |
1f2e99fe LW |
170 | enum VIA_HDA_CODEC codec_type; |
171 | ||
172 | /* work to check hp jack state */ | |
173 | struct hda_codec *codec; | |
174 | struct delayed_work vt1708_hp_work; | |
e06e5a29 | 175 | int vt1708_jack_detect; |
1f2e99fe | 176 | int vt1708_hp_present; |
3e95b9ab LW |
177 | |
178 | void (*set_widgets_power_state)(struct hda_codec *codec); | |
179 | ||
1f2e99fe LW |
180 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
181 | struct hda_loopback_check loopback; | |
182 | #endif | |
183 | }; | |
184 | ||
0341ccd7 | 185 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
5b0cb1d8 JK |
186 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
187 | { | |
188 | struct via_spec *spec; | |
189 | ||
190 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
191 | if (spec == NULL) | |
192 | return NULL; | |
193 | ||
194 | codec->spec = spec; | |
195 | spec->codec = codec; | |
0341ccd7 LW |
196 | spec->codec_type = get_codec_type(codec); |
197 | /* VT1708BCE & VT1708S are almost same */ | |
198 | if (spec->codec_type == VT1708BCE) | |
199 | spec->codec_type = VT1708S; | |
5b0cb1d8 JK |
200 | return spec; |
201 | } | |
202 | ||
744ff5f4 | 203 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
d7426329 | 204 | { |
744ff5f4 | 205 | u32 vendor_id = codec->vendor_id; |
d7426329 HW |
206 | u16 ven_id = vendor_id >> 16; |
207 | u16 dev_id = vendor_id & 0xffff; | |
208 | enum VIA_HDA_CODEC codec_type; | |
209 | ||
210 | /* get codec type */ | |
211 | if (ven_id != 0x1106) | |
212 | codec_type = UNKNOWN; | |
213 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) | |
214 | codec_type = VT1708; | |
215 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) | |
216 | codec_type = VT1709_10CH; | |
217 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) | |
218 | codec_type = VT1709_6CH; | |
518bf3ba | 219 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
d7426329 | 220 | codec_type = VT1708B_8CH; |
518bf3ba LW |
221 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
222 | codec_type = VT1708BCE; | |
223 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) | |
d7426329 HW |
224 | codec_type = VT1708B_4CH; |
225 | else if ((dev_id & 0xfff) == 0x397 | |
226 | && (dev_id >> 12) < 8) | |
227 | codec_type = VT1708S; | |
228 | else if ((dev_id & 0xfff) == 0x398 | |
229 | && (dev_id >> 12) < 8) | |
230 | codec_type = VT1702; | |
eb7188ca LW |
231 | else if ((dev_id & 0xfff) == 0x428 |
232 | && (dev_id >> 12) < 8) | |
233 | codec_type = VT1718S; | |
f3db423d LW |
234 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
235 | codec_type = VT1716S; | |
bb3c6bfc LW |
236 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
237 | codec_type = VT1718S; | |
25eaba2f LW |
238 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
239 | codec_type = VT2002P; | |
ab6734e7 LW |
240 | else if (dev_id == 0x0448) |
241 | codec_type = VT1812; | |
36dd5c4a LW |
242 | else if (dev_id == 0x0440) |
243 | codec_type = VT1708S; | |
11890956 LW |
244 | else if ((dev_id & 0xfff) == 0x446) |
245 | codec_type = VT1802; | |
d7426329 HW |
246 | else |
247 | codec_type = UNKNOWN; | |
248 | return codec_type; | |
249 | }; | |
250 | ||
ec7e7e42 | 251 | #define VIA_JACK_EVENT 0x20 |
69e52a80 HW |
252 | #define VIA_HP_EVENT 0x01 |
253 | #define VIA_GPIO_EVENT 0x02 | |
ec7e7e42 LW |
254 | #define VIA_MONO_EVENT 0x03 |
255 | #define VIA_SPEAKER_EVENT 0x04 | |
256 | #define VIA_BIND_HP_EVENT 0x05 | |
69e52a80 | 257 | |
c577b8a1 JC |
258 | enum { |
259 | VIA_CTL_WIDGET_VOL, | |
260 | VIA_CTL_WIDGET_MUTE, | |
f5271101 | 261 | VIA_CTL_WIDGET_ANALOG_MUTE, |
25eaba2f | 262 | VIA_CTL_WIDGET_BIND_PIN_MUTE, |
c577b8a1 JC |
263 | }; |
264 | ||
265 | enum { | |
eb14a46c | 266 | AUTO_SEQ_FRONT = 0, |
c577b8a1 JC |
267 | AUTO_SEQ_SURROUND, |
268 | AUTO_SEQ_CENLFE, | |
269 | AUTO_SEQ_SIDE | |
270 | }; | |
271 | ||
f5271101 | 272 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); |
1f2e99fe LW |
273 | static int is_aa_path_mute(struct hda_codec *codec); |
274 | ||
275 | static void vt1708_start_hp_work(struct via_spec *spec) | |
276 | { | |
277 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) | |
278 | return; | |
279 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, | |
e06e5a29 | 280 | !spec->vt1708_jack_detect); |
1f2e99fe LW |
281 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
282 | schedule_delayed_work(&spec->vt1708_hp_work, | |
283 | msecs_to_jiffies(100)); | |
284 | } | |
285 | ||
286 | static void vt1708_stop_hp_work(struct via_spec *spec) | |
287 | { | |
288 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) | |
289 | return; | |
290 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 | |
291 | && !is_aa_path_mute(spec->codec)) | |
292 | return; | |
293 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, | |
e06e5a29 | 294 | !spec->vt1708_jack_detect); |
5b84ba26 | 295 | cancel_delayed_work_sync(&spec->vt1708_hp_work); |
1f2e99fe | 296 | } |
f5271101 | 297 | |
3e95b9ab LW |
298 | static void set_widgets_power_state(struct hda_codec *codec) |
299 | { | |
300 | struct via_spec *spec = codec->spec; | |
301 | if (spec->set_widgets_power_state) | |
302 | spec->set_widgets_power_state(codec); | |
303 | } | |
25eaba2f | 304 | |
f5271101 LW |
305 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
306 | struct snd_ctl_elem_value *ucontrol) | |
307 | { | |
308 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); | |
309 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
310 | ||
3e95b9ab | 311 | set_widgets_power_state(codec); |
f5271101 | 312 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
1f2e99fe LW |
313 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
314 | if (is_aa_path_mute(codec)) | |
315 | vt1708_start_hp_work(codec->spec); | |
316 | else | |
317 | vt1708_stop_hp_work(codec->spec); | |
318 | } | |
f5271101 LW |
319 | return change; |
320 | } | |
321 | ||
322 | /* modify .put = snd_hda_mixer_amp_switch_put */ | |
323 | #define ANALOG_INPUT_MUTE \ | |
324 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
325 | .name = NULL, \ | |
326 | .index = 0, \ | |
327 | .info = snd_hda_mixer_amp_switch_info, \ | |
328 | .get = snd_hda_mixer_amp_switch_get, \ | |
329 | .put = analog_input_switch_put, \ | |
330 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | |
331 | ||
25eaba2f LW |
332 | static void via_hp_bind_automute(struct hda_codec *codec); |
333 | ||
334 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, | |
335 | struct snd_ctl_elem_value *ucontrol) | |
336 | { | |
337 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
338 | struct via_spec *spec = codec->spec; | |
339 | int i; | |
340 | int change = 0; | |
341 | ||
342 | long *valp = ucontrol->value.integer.value; | |
343 | int lmute, rmute; | |
344 | if (strstr(kcontrol->id.name, "Switch") == NULL) { | |
345 | snd_printd("Invalid control!\n"); | |
346 | return change; | |
347 | } | |
348 | change = snd_hda_mixer_amp_switch_put(kcontrol, | |
349 | ucontrol); | |
350 | /* Get mute value */ | |
351 | lmute = *valp ? 0 : HDA_AMP_MUTE; | |
352 | valp++; | |
353 | rmute = *valp ? 0 : HDA_AMP_MUTE; | |
354 | ||
355 | /* Set hp pins */ | |
356 | if (!spec->hp_independent_mode) { | |
357 | for (i = 0; i < spec->autocfg.hp_outs; i++) { | |
358 | snd_hda_codec_amp_update( | |
359 | codec, spec->autocfg.hp_pins[i], | |
360 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
361 | lmute); | |
362 | snd_hda_codec_amp_update( | |
363 | codec, spec->autocfg.hp_pins[i], | |
364 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
365 | rmute); | |
366 | } | |
367 | } | |
368 | ||
369 | if (!lmute && !rmute) { | |
370 | /* Line Outs */ | |
371 | for (i = 0; i < spec->autocfg.line_outs; i++) | |
372 | snd_hda_codec_amp_stereo( | |
373 | codec, spec->autocfg.line_out_pins[i], | |
374 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | |
375 | /* Speakers */ | |
376 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
377 | snd_hda_codec_amp_stereo( | |
378 | codec, spec->autocfg.speaker_pins[i], | |
379 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | |
380 | /* unmute */ | |
381 | via_hp_bind_automute(codec); | |
382 | ||
383 | } else { | |
384 | if (lmute) { | |
385 | /* Mute all left channels */ | |
386 | for (i = 1; i < spec->autocfg.line_outs; i++) | |
387 | snd_hda_codec_amp_update( | |
388 | codec, | |
389 | spec->autocfg.line_out_pins[i], | |
390 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
391 | lmute); | |
392 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
393 | snd_hda_codec_amp_update( | |
394 | codec, | |
395 | spec->autocfg.speaker_pins[i], | |
396 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
397 | lmute); | |
398 | } | |
399 | if (rmute) { | |
400 | /* mute all right channels */ | |
401 | for (i = 1; i < spec->autocfg.line_outs; i++) | |
402 | snd_hda_codec_amp_update( | |
403 | codec, | |
404 | spec->autocfg.line_out_pins[i], | |
405 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
406 | rmute); | |
407 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
408 | snd_hda_codec_amp_update( | |
409 | codec, | |
410 | spec->autocfg.speaker_pins[i], | |
411 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
412 | rmute); | |
413 | } | |
414 | } | |
415 | return change; | |
416 | } | |
417 | ||
418 | #define BIND_PIN_MUTE \ | |
419 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
420 | .name = NULL, \ | |
421 | .index = 0, \ | |
422 | .info = snd_hda_mixer_amp_switch_info, \ | |
423 | .get = snd_hda_mixer_amp_switch_get, \ | |
424 | .put = bind_pin_switch_put, \ | |
425 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | |
426 | ||
90dd48a1 | 427 | static const struct snd_kcontrol_new via_control_templates[] = { |
c577b8a1 JC |
428 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
429 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
f5271101 | 430 | ANALOG_INPUT_MUTE, |
25eaba2f | 431 | BIND_PIN_MUTE, |
c577b8a1 JC |
432 | }; |
433 | ||
ab6734e7 | 434 | |
c577b8a1 | 435 | /* add dynamic controls */ |
291c9e33 TI |
436 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
437 | const struct snd_kcontrol_new *tmpl, | |
438 | const char *name) | |
c577b8a1 JC |
439 | { |
440 | struct snd_kcontrol_new *knew; | |
441 | ||
603c4019 TI |
442 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
443 | knew = snd_array_new(&spec->kctls); | |
444 | if (!knew) | |
291c9e33 TI |
445 | return NULL; |
446 | *knew = *tmpl; | |
447 | if (!name) | |
448 | name = tmpl->name; | |
449 | if (name) { | |
450 | knew->name = kstrdup(name, GFP_KERNEL); | |
451 | if (!knew->name) | |
452 | return NULL; | |
453 | } | |
454 | return knew; | |
455 | } | |
456 | ||
457 | static int __via_add_control(struct via_spec *spec, int type, const char *name, | |
458 | int idx, unsigned long val) | |
459 | { | |
460 | struct snd_kcontrol_new *knew; | |
461 | ||
462 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); | |
463 | if (!knew) | |
c577b8a1 | 464 | return -ENOMEM; |
d7a99cce | 465 | knew->index = idx; |
4d02d1b6 | 466 | if (get_amp_nid_(val)) |
5e26dfd0 | 467 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
c577b8a1 | 468 | knew->private_value = val; |
c577b8a1 JC |
469 | return 0; |
470 | } | |
471 | ||
7b315bb4 TI |
472 | #define via_add_control(spec, type, name, val) \ |
473 | __via_add_control(spec, type, name, 0, val) | |
474 | ||
291c9e33 | 475 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
5b0cb1d8 | 476 | |
603c4019 TI |
477 | static void via_free_kctls(struct hda_codec *codec) |
478 | { | |
479 | struct via_spec *spec = codec->spec; | |
480 | ||
481 | if (spec->kctls.list) { | |
482 | struct snd_kcontrol_new *kctl = spec->kctls.list; | |
483 | int i; | |
484 | for (i = 0; i < spec->kctls.used; i++) | |
485 | kfree(kctl[i].name); | |
486 | } | |
487 | snd_array_free(&spec->kctls); | |
488 | } | |
489 | ||
c577b8a1 | 490 | /* create input playback/capture controls for the given pin */ |
9510e8dd | 491 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
7b315bb4 | 492 | int type_idx, int idx, int mix_nid) |
c577b8a1 JC |
493 | { |
494 | char name[32]; | |
495 | int err; | |
496 | ||
497 | sprintf(name, "%s Playback Volume", ctlname); | |
7b315bb4 | 498 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
c577b8a1 JC |
499 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
500 | if (err < 0) | |
501 | return err; | |
502 | sprintf(name, "%s Playback Switch", ctlname); | |
7b315bb4 | 503 | err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx, |
c577b8a1 JC |
504 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
505 | if (err < 0) | |
506 | return err; | |
507 | return 0; | |
508 | } | |
509 | ||
510 | static void via_auto_set_output_and_unmute(struct hda_codec *codec, | |
511 | hda_nid_t nid, int pin_type, | |
512 | int dac_idx) | |
513 | { | |
514 | /* set as output */ | |
515 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
516 | pin_type); | |
517 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
518 | AMP_OUT_UNMUTE); | |
d3a11e60 | 519 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
377ff31a | 520 | snd_hda_codec_write(codec, nid, 0, |
d3a11e60 | 521 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
c577b8a1 JC |
522 | } |
523 | ||
524 | ||
525 | static void via_auto_init_multi_out(struct hda_codec *codec) | |
526 | { | |
527 | struct via_spec *spec = codec->spec; | |
528 | int i; | |
529 | ||
530 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
531 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
532 | if (nid) | |
533 | via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); | |
534 | } | |
535 | } | |
536 | ||
537 | static void via_auto_init_hp_out(struct hda_codec *codec) | |
538 | { | |
539 | struct via_spec *spec = codec->spec; | |
540 | hda_nid_t pin; | |
25eaba2f | 541 | int i; |
c577b8a1 | 542 | |
25eaba2f LW |
543 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
544 | pin = spec->autocfg.hp_pins[i]; | |
545 | if (pin) /* connect to front */ | |
546 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); | |
547 | } | |
c577b8a1 JC |
548 | } |
549 | ||
f4a7828b | 550 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); |
32e0191d | 551 | |
c577b8a1 JC |
552 | static void via_auto_init_analog_input(struct hda_codec *codec) |
553 | { | |
554 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 555 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
32e0191d | 556 | unsigned int ctl; |
c577b8a1 JC |
557 | int i; |
558 | ||
7b315bb4 TI |
559 | for (i = 0; i < cfg->num_inputs; i++) { |
560 | hda_nid_t nid = cfg->inputs[i].pin; | |
f4a7828b | 561 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) |
32e0191d | 562 | ctl = PIN_OUT; |
30649676 | 563 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) |
32e0191d CL |
564 | ctl = PIN_VREF50; |
565 | else | |
566 | ctl = PIN_IN; | |
c577b8a1 | 567 | snd_hda_codec_write(codec, nid, 0, |
32e0191d | 568 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); |
c577b8a1 JC |
569 | } |
570 | } | |
f5271101 LW |
571 | |
572 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, | |
573 | unsigned int *affected_parm) | |
574 | { | |
575 | unsigned parm; | |
576 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); | |
577 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) | |
578 | >> AC_DEFCFG_MISC_SHIFT | |
579 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ | |
1564b287 | 580 | struct via_spec *spec = codec->spec; |
24088a58 TI |
581 | unsigned present = 0; |
582 | ||
583 | no_presence |= spec->no_pin_power_ctl; | |
584 | if (!no_presence) | |
585 | present = snd_hda_jack_detect(codec, nid); | |
f4a7828b | 586 | if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) |
1564b287 LW |
587 | || ((no_presence || present) |
588 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { | |
f5271101 LW |
589 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
590 | parm = AC_PWRST_D0; | |
591 | } else | |
592 | parm = AC_PWRST_D3; | |
593 | ||
594 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); | |
595 | } | |
596 | ||
24088a58 TI |
597 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
598 | struct snd_ctl_elem_info *uinfo) | |
599 | { | |
600 | static const char * const texts[] = { | |
601 | "Disabled", "Enabled" | |
602 | }; | |
603 | ||
604 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
605 | uinfo->count = 1; | |
606 | uinfo->value.enumerated.items = 2; | |
607 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | |
608 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; | |
609 | strcpy(uinfo->value.enumerated.name, | |
610 | texts[uinfo->value.enumerated.item]); | |
611 | return 0; | |
612 | } | |
613 | ||
614 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, | |
615 | struct snd_ctl_elem_value *ucontrol) | |
616 | { | |
617 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
618 | struct via_spec *spec = codec->spec; | |
619 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; | |
620 | return 0; | |
621 | } | |
622 | ||
623 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, | |
624 | struct snd_ctl_elem_value *ucontrol) | |
625 | { | |
626 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
627 | struct via_spec *spec = codec->spec; | |
628 | unsigned int val = !ucontrol->value.enumerated.item[0]; | |
629 | ||
630 | if (val == spec->no_pin_power_ctl) | |
631 | return 0; | |
632 | spec->no_pin_power_ctl = val; | |
633 | set_widgets_power_state(codec); | |
634 | return 1; | |
635 | } | |
636 | ||
637 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { | |
638 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
639 | .name = "Dynamic Power-Control", | |
640 | .info = via_pin_power_ctl_info, | |
641 | .get = via_pin_power_ctl_get, | |
642 | .put = via_pin_power_ctl_put, | |
643 | }; | |
644 | ||
645 | ||
c577b8a1 JC |
646 | /* |
647 | * input MUX handling | |
648 | */ | |
649 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, | |
650 | struct snd_ctl_elem_info *uinfo) | |
651 | { | |
652 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
653 | struct via_spec *spec = codec->spec; | |
654 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
655 | } | |
656 | ||
657 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, | |
658 | struct snd_ctl_elem_value *ucontrol) | |
659 | { | |
660 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
661 | struct via_spec *spec = codec->spec; | |
662 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
663 | ||
664 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
665 | return 0; | |
666 | } | |
667 | ||
668 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | |
669 | struct snd_ctl_elem_value *ucontrol) | |
670 | { | |
671 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
672 | struct via_spec *spec = codec->spec; | |
673 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
bff5fbf5 | 674 | int ret; |
c577b8a1 | 675 | |
337b9d02 TI |
676 | if (!spec->mux_nids[adc_idx]) |
677 | return -EINVAL; | |
a80e6e3c LW |
678 | /* switch to D0 beofre change index */ |
679 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, | |
680 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) | |
681 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, | |
682 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
a80e6e3c | 683 | |
bff5fbf5 | 684 | ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
337b9d02 TI |
685 | spec->mux_nids[adc_idx], |
686 | &spec->cur_mux[adc_idx]); | |
bff5fbf5 | 687 | /* update jack power state */ |
3e95b9ab | 688 | set_widgets_power_state(codec); |
bff5fbf5 LW |
689 | |
690 | return ret; | |
c577b8a1 JC |
691 | } |
692 | ||
0aa62aef HW |
693 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
694 | struct snd_ctl_elem_info *uinfo) | |
695 | { | |
696 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
697 | struct via_spec *spec = codec->spec; | |
698 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); | |
699 | } | |
700 | ||
701 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, | |
702 | struct snd_ctl_elem_value *ucontrol) | |
703 | { | |
704 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
5b0cb1d8 | 705 | hda_nid_t nid = kcontrol->private_value; |
eb7188ca | 706 | unsigned int pinsel; |
0aa62aef | 707 | |
eb7188ca LW |
708 | /* use !! to translate conn sel 2 for VT1718S */ |
709 | pinsel = !!snd_hda_codec_read(codec, nid, 0, | |
710 | AC_VERB_GET_CONNECT_SEL, | |
711 | 0x00); | |
0aa62aef HW |
712 | ucontrol->value.enumerated.item[0] = pinsel; |
713 | ||
714 | return 0; | |
715 | } | |
716 | ||
0713efeb LW |
717 | static void activate_ctl(struct hda_codec *codec, const char *name, int active) |
718 | { | |
719 | struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); | |
720 | if (ctl) { | |
721 | ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; | |
722 | ctl->vd[0].access |= active | |
723 | ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; | |
724 | snd_ctl_notify(codec->bus->card, | |
725 | SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); | |
726 | } | |
727 | } | |
728 | ||
5b0cb1d8 JK |
729 | static hda_nid_t side_mute_channel(struct via_spec *spec) |
730 | { | |
731 | switch (spec->codec_type) { | |
732 | case VT1708: return 0x1b; | |
733 | case VT1709_10CH: return 0x29; | |
734 | case VT1708B_8CH: /* fall thru */ | |
735 | case VT1708S: return 0x27; | |
e87885fe LW |
736 | case VT2002P: return 0x19; |
737 | case VT1802: return 0x15; | |
738 | case VT1812: return 0x15; | |
5b0cb1d8 JK |
739 | default: return 0; |
740 | } | |
741 | } | |
742 | ||
cdc1784d LW |
743 | static int update_side_mute_status(struct hda_codec *codec) |
744 | { | |
745 | /* mute side channel */ | |
746 | struct via_spec *spec = codec->spec; | |
e87885fe | 747 | unsigned int parm; |
5b0cb1d8 | 748 | hda_nid_t sw3 = side_mute_channel(spec); |
cdc1784d | 749 | |
e87885fe LW |
750 | if (sw3) { |
751 | if (VT2002P_COMPATIBLE(spec)) | |
752 | parm = spec->hp_independent_mode ? | |
753 | AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1); | |
754 | else | |
755 | parm = spec->hp_independent_mode ? | |
756 | AMP_OUT_MUTE : AMP_OUT_UNMUTE; | |
757 | snd_hda_codec_write(codec, sw3, 0, | |
758 | AC_VERB_SET_AMP_GAIN_MUTE, parm); | |
759 | if (spec->codec_type == VT1812) | |
760 | snd_hda_codec_write(codec, 0x1d, 0, | |
761 | AC_VERB_SET_AMP_GAIN_MUTE, parm); | |
762 | } | |
cdc1784d LW |
763 | return 0; |
764 | } | |
765 | ||
0aa62aef HW |
766 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
767 | struct snd_ctl_elem_value *ucontrol) | |
768 | { | |
769 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
770 | struct via_spec *spec = codec->spec; | |
5b0cb1d8 | 771 | hda_nid_t nid = kcontrol->private_value; |
0aa62aef | 772 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
cdc1784d LW |
773 | /* Get Independent Mode index of headphone pin widget */ |
774 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel | |
775 | ? 1 : 0; | |
ce0e5a9e LW |
776 | if (spec->codec_type == VT1718S) |
777 | snd_hda_codec_write(codec, nid, 0, | |
778 | AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0); | |
779 | else | |
780 | snd_hda_codec_write(codec, nid, 0, | |
781 | AC_VERB_SET_CONNECT_SEL, pinsel); | |
cdc1784d | 782 | |
ce0e5a9e LW |
783 | if (spec->codec_type == VT1812) |
784 | snd_hda_codec_write(codec, 0x35, 0, | |
785 | AC_VERB_SET_CONNECT_SEL, pinsel); | |
cdc1784d LW |
786 | if (spec->multiout.hp_nid && spec->multiout.hp_nid |
787 | != spec->multiout.dac_nids[HDA_FRONT]) | |
788 | snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, | |
789 | 0, 0, 0); | |
0aa62aef | 790 | |
cdc1784d | 791 | update_side_mute_status(codec); |
0713efeb LW |
792 | /* update HP volume/swtich active state */ |
793 | if (spec->codec_type == VT1708S | |
eb7188ca | 794 | || spec->codec_type == VT1702 |
f3db423d | 795 | || spec->codec_type == VT1718S |
25eaba2f | 796 | || spec->codec_type == VT1716S |
11890956 | 797 | || VT2002P_COMPATIBLE(spec)) { |
0713efeb LW |
798 | activate_ctl(codec, "Headphone Playback Volume", |
799 | spec->hp_independent_mode); | |
800 | activate_ctl(codec, "Headphone Playback Switch", | |
801 | spec->hp_independent_mode); | |
802 | } | |
ce0e5a9e | 803 | /* update jack power state */ |
3e95b9ab | 804 | set_widgets_power_state(codec); |
0aa62aef HW |
805 | return 0; |
806 | } | |
807 | ||
90dd48a1 | 808 | static const struct snd_kcontrol_new via_hp_mixer[2] = { |
0aa62aef HW |
809 | { |
810 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
811 | .name = "Independent HP", | |
0aa62aef HW |
812 | .info = via_independent_hp_info, |
813 | .get = via_independent_hp_get, | |
814 | .put = via_independent_hp_put, | |
815 | }, | |
5b0cb1d8 JK |
816 | { |
817 | .iface = NID_MAPPING, | |
818 | .name = "Independent HP", | |
819 | }, | |
0aa62aef HW |
820 | }; |
821 | ||
3d83e577 | 822 | static int via_hp_build(struct hda_codec *codec) |
5b0cb1d8 | 823 | { |
3d83e577 | 824 | struct via_spec *spec = codec->spec; |
5b0cb1d8 JK |
825 | struct snd_kcontrol_new *knew; |
826 | hda_nid_t nid; | |
3d83e577 TI |
827 | int nums; |
828 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; | |
5b0cb1d8 JK |
829 | |
830 | switch (spec->codec_type) { | |
831 | case VT1718S: | |
832 | nid = 0x34; | |
833 | break; | |
834 | case VT2002P: | |
11890956 | 835 | case VT1802: |
5b0cb1d8 JK |
836 | nid = 0x35; |
837 | break; | |
838 | case VT1812: | |
839 | nid = 0x3d; | |
840 | break; | |
841 | default: | |
842 | nid = spec->autocfg.hp_pins[0]; | |
843 | break; | |
844 | } | |
845 | ||
ee3c35c0 LW |
846 | if (spec->codec_type != VT1708) { |
847 | nums = snd_hda_get_connections(codec, nid, | |
848 | conn, HDA_MAX_CONNECTIONS); | |
849 | if (nums <= 1) | |
850 | return 0; | |
851 | } | |
3d83e577 TI |
852 | |
853 | knew = via_clone_control(spec, &via_hp_mixer[0]); | |
854 | if (knew == NULL) | |
855 | return -ENOMEM; | |
856 | ||
5b0cb1d8 JK |
857 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
858 | knew->private_value = nid; | |
859 | ||
860 | knew = via_clone_control(spec, &via_hp_mixer[1]); | |
861 | if (knew == NULL) | |
862 | return -ENOMEM; | |
863 | knew->subdevice = side_mute_channel(spec); | |
864 | ||
865 | return 0; | |
866 | } | |
867 | ||
1564b287 LW |
868 | static void notify_aa_path_ctls(struct hda_codec *codec) |
869 | { | |
870 | int i; | |
871 | struct snd_ctl_elem_id id; | |
525566cb LW |
872 | const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"}; |
873 | struct snd_kcontrol *ctl; | |
1564b287 LW |
874 | |
875 | memset(&id, 0, sizeof(id)); | |
876 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
877 | for (i = 0; i < ARRAY_SIZE(labels); i++) { | |
878 | sprintf(id.name, "%s Playback Volume", labels[i]); | |
525566cb LW |
879 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
880 | if (ctl) | |
881 | snd_ctl_notify(codec->bus->card, | |
882 | SNDRV_CTL_EVENT_MASK_VALUE, | |
883 | &ctl->id); | |
1564b287 LW |
884 | } |
885 | } | |
886 | ||
887 | static void mute_aa_path(struct hda_codec *codec, int mute) | |
888 | { | |
889 | struct via_spec *spec = codec->spec; | |
1564b287 LW |
890 | int start_idx; |
891 | int end_idx; | |
892 | int i; | |
893 | /* get nid of MW0 and start & end index */ | |
894 | switch (spec->codec_type) { | |
895 | case VT1708: | |
1564b287 LW |
896 | start_idx = 2; |
897 | end_idx = 4; | |
898 | break; | |
899 | case VT1709_10CH: | |
900 | case VT1709_6CH: | |
1564b287 LW |
901 | start_idx = 2; |
902 | end_idx = 4; | |
903 | break; | |
904 | case VT1708B_8CH: | |
905 | case VT1708B_4CH: | |
906 | case VT1708S: | |
f3db423d | 907 | case VT1716S: |
1564b287 LW |
908 | start_idx = 2; |
909 | end_idx = 4; | |
910 | break; | |
ab657e0c | 911 | case VT1718S: |
ab657e0c LW |
912 | start_idx = 1; |
913 | end_idx = 3; | |
914 | break; | |
1564b287 LW |
915 | default: |
916 | return; | |
917 | } | |
918 | /* check AA path's mute status */ | |
919 | for (i = start_idx; i <= end_idx; i++) { | |
920 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; | |
620e2b28 | 921 | snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, HDA_INPUT, i, |
1564b287 LW |
922 | HDA_AMP_MUTE, val); |
923 | } | |
924 | } | |
f4a7828b TI |
925 | |
926 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) | |
1564b287 | 927 | { |
f4a7828b | 928 | struct via_spec *spec = codec->spec; |
7b315bb4 TI |
929 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
930 | int i; | |
931 | ||
932 | for (i = 0; i < cfg->num_inputs; i++) { | |
f4a7828b TI |
933 | unsigned int defcfg; |
934 | if (pin != cfg->inputs[i].pin) | |
935 | continue; | |
936 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) | |
937 | return false; | |
938 | defcfg = snd_hda_codec_get_pincfg(codec, pin); | |
939 | if (snd_hda_get_input_pin_attr(defcfg) < INPUT_PIN_ATTR_NORMAL) | |
940 | return false; | |
941 | return true; | |
1564b287 | 942 | } |
f4a7828b | 943 | return false; |
1564b287 LW |
944 | } |
945 | ||
946 | static int via_smart51_info(struct snd_kcontrol *kcontrol, | |
947 | struct snd_ctl_elem_info *uinfo) | |
948 | { | |
949 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
950 | uinfo->count = 1; | |
951 | uinfo->value.integer.min = 0; | |
952 | uinfo->value.integer.max = 1; | |
953 | return 0; | |
954 | } | |
955 | ||
956 | static int via_smart51_get(struct snd_kcontrol *kcontrol, | |
957 | struct snd_ctl_elem_value *ucontrol) | |
958 | { | |
959 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
960 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 961 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
1564b287 LW |
962 | int on = 1; |
963 | int i; | |
964 | ||
7b315bb4 TI |
965 | for (i = 0; i < cfg->num_inputs; i++) { |
966 | hda_nid_t nid = cfg->inputs[i].pin; | |
f4a7828b | 967 | unsigned int ctl; |
86e2959a | 968 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
7b315bb4 TI |
969 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
970 | continue; /* ignore FMic for independent HP */ | |
f4a7828b TI |
971 | if (!is_smart51_pins(codec, nid)) |
972 | continue; | |
973 | ctl = snd_hda_codec_read(codec, nid, 0, | |
974 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
7b315bb4 TI |
975 | if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) |
976 | on = 0; | |
1564b287 LW |
977 | } |
978 | *ucontrol->value.integer.value = on; | |
979 | return 0; | |
980 | } | |
981 | ||
982 | static int via_smart51_put(struct snd_kcontrol *kcontrol, | |
983 | struct snd_ctl_elem_value *ucontrol) | |
984 | { | |
985 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
986 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 987 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
1564b287 LW |
988 | int out_in = *ucontrol->value.integer.value |
989 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; | |
1564b287 LW |
990 | int i; |
991 | ||
7b315bb4 TI |
992 | for (i = 0; i < cfg->num_inputs; i++) { |
993 | hda_nid_t nid = cfg->inputs[i].pin; | |
994 | unsigned int parm; | |
995 | ||
86e2959a | 996 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
7b315bb4 | 997 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
1564b287 | 998 | continue; /* don't retask FMic for independent HP */ |
f4a7828b TI |
999 | if (!is_smart51_pins(codec, nid)) |
1000 | continue; | |
7b315bb4 TI |
1001 | |
1002 | parm = snd_hda_codec_read(codec, nid, 0, | |
1003 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
1004 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); | |
1005 | parm |= out_in; | |
1006 | snd_hda_codec_write(codec, nid, 0, | |
1007 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1008 | parm); | |
1009 | if (out_in == AC_PINCTL_OUT_EN) { | |
1010 | mute_aa_path(codec, 1); | |
1011 | notify_aa_path_ctls(codec); | |
1012 | } | |
1564b287 LW |
1013 | } |
1014 | spec->smart51_enabled = *ucontrol->value.integer.value; | |
3e95b9ab | 1015 | set_widgets_power_state(codec); |
1564b287 LW |
1016 | return 1; |
1017 | } | |
1018 | ||
5f4b36d6 TI |
1019 | static const struct snd_kcontrol_new via_smart51_mixer = { |
1020 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1021 | .name = "Smart 5.1", | |
1022 | .count = 1, | |
1023 | .info = via_smart51_info, | |
1024 | .get = via_smart51_get, | |
1025 | .put = via_smart51_put, | |
1564b287 LW |
1026 | }; |
1027 | ||
f4a7828b | 1028 | static int via_smart51_build(struct hda_codec *codec) |
5b0cb1d8 | 1029 | { |
f4a7828b | 1030 | struct via_spec *spec = codec->spec; |
5b0cb1d8 | 1031 | struct snd_kcontrol_new *knew; |
7b315bb4 | 1032 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
5b0cb1d8 JK |
1033 | hda_nid_t nid; |
1034 | int i; | |
1035 | ||
f4a7828b | 1036 | if (!spec->can_smart51) |
cb34c207 LW |
1037 | return 0; |
1038 | ||
5f4b36d6 | 1039 | knew = via_clone_control(spec, &via_smart51_mixer); |
5b0cb1d8 JK |
1040 | if (knew == NULL) |
1041 | return -ENOMEM; | |
1042 | ||
7b315bb4 TI |
1043 | for (i = 0; i < cfg->num_inputs; i++) { |
1044 | nid = cfg->inputs[i].pin; | |
f4a7828b | 1045 | if (is_smart51_pins(codec, nid)) { |
5f4b36d6 | 1046 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
7b315bb4 | 1047 | break; |
5b0cb1d8 JK |
1048 | } |
1049 | } | |
1050 | ||
1051 | return 0; | |
1052 | } | |
1053 | ||
f5271101 LW |
1054 | /* check AA path's mute statue */ |
1055 | static int is_aa_path_mute(struct hda_codec *codec) | |
1056 | { | |
1057 | int mute = 1; | |
f5271101 LW |
1058 | int start_idx; |
1059 | int end_idx; | |
1060 | int i; | |
1061 | struct via_spec *spec = codec->spec; | |
1062 | /* get nid of MW0 and start & end index */ | |
1063 | switch (spec->codec_type) { | |
1064 | case VT1708B_8CH: | |
1065 | case VT1708B_4CH: | |
1066 | case VT1708S: | |
f3db423d | 1067 | case VT1716S: |
f5271101 LW |
1068 | start_idx = 2; |
1069 | end_idx = 4; | |
1070 | break; | |
1071 | case VT1702: | |
f5271101 LW |
1072 | start_idx = 1; |
1073 | end_idx = 3; | |
1074 | break; | |
eb7188ca | 1075 | case VT1718S: |
eb7188ca LW |
1076 | start_idx = 1; |
1077 | end_idx = 3; | |
1078 | break; | |
25eaba2f | 1079 | case VT2002P: |
ab6734e7 | 1080 | case VT1812: |
11890956 | 1081 | case VT1802: |
25eaba2f LW |
1082 | start_idx = 0; |
1083 | end_idx = 2; | |
1084 | break; | |
f5271101 LW |
1085 | default: |
1086 | return 0; | |
1087 | } | |
1088 | /* check AA path's mute status */ | |
1089 | for (i = start_idx; i <= end_idx; i++) { | |
1090 | unsigned int con_list = snd_hda_codec_read( | |
620e2b28 | 1091 | codec, spec->aa_mix_nid, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); |
f5271101 LW |
1092 | int shift = 8 * (i % 4); |
1093 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; | |
1094 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); | |
1095 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { | |
1096 | /* check mute status while the pin is connected */ | |
620e2b28 | 1097 | int mute_l = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 0, |
f5271101 | 1098 | HDA_INPUT, i) >> 7; |
620e2b28 | 1099 | int mute_r = snd_hda_codec_amp_read(codec, spec->aa_mix_nid, 1, |
f5271101 LW |
1100 | HDA_INPUT, i) >> 7; |
1101 | if (!mute_l || !mute_r) { | |
1102 | mute = 0; | |
1103 | break; | |
1104 | } | |
1105 | } | |
1106 | } | |
1107 | return mute; | |
1108 | } | |
1109 | ||
1110 | /* enter/exit analog low-current mode */ | |
1111 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) | |
1112 | { | |
1113 | struct via_spec *spec = codec->spec; | |
1114 | static int saved_stream_idle = 1; /* saved stream idle status */ | |
1115 | int enable = is_aa_path_mute(codec); | |
1116 | unsigned int verb = 0; | |
1117 | unsigned int parm = 0; | |
1118 | ||
1119 | if (stream_idle == -1) /* stream status did not change */ | |
1120 | enable = enable && saved_stream_idle; | |
1121 | else { | |
1122 | enable = enable && stream_idle; | |
1123 | saved_stream_idle = stream_idle; | |
1124 | } | |
1125 | ||
1126 | /* decide low current mode's verb & parameter */ | |
1127 | switch (spec->codec_type) { | |
1128 | case VT1708B_8CH: | |
1129 | case VT1708B_4CH: | |
1130 | verb = 0xf70; | |
1131 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ | |
1132 | break; | |
1133 | case VT1708S: | |
eb7188ca | 1134 | case VT1718S: |
f3db423d | 1135 | case VT1716S: |
f5271101 LW |
1136 | verb = 0xf73; |
1137 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ | |
1138 | break; | |
1139 | case VT1702: | |
1140 | verb = 0xf73; | |
1141 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ | |
1142 | break; | |
25eaba2f | 1143 | case VT2002P: |
ab6734e7 | 1144 | case VT1812: |
11890956 | 1145 | case VT1802: |
25eaba2f LW |
1146 | verb = 0xf93; |
1147 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ | |
1148 | break; | |
f5271101 LW |
1149 | default: |
1150 | return; /* other codecs are not supported */ | |
1151 | } | |
1152 | /* send verb */ | |
1153 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); | |
1154 | } | |
1155 | ||
c577b8a1 JC |
1156 | /* |
1157 | * generic initialization of ADC, input mixers and output mixers | |
1158 | */ | |
90dd48a1 | 1159 | static const struct hda_verb vt1708_volume_init_verbs[] = { |
c577b8a1 JC |
1160 | /* |
1161 | * Unmute ADC0-1 and set the default input to mic-in | |
1162 | */ | |
1163 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1164 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1165 | ||
1166 | ||
f7278fd0 | 1167 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
c577b8a1 JC |
1168 | * mixer widget |
1169 | */ | |
1170 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
f7278fd0 JC |
1171 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
1172 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
1173 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
1174 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
1175 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
c577b8a1 JC |
1176 | |
1177 | /* | |
1178 | * Set up output mixers (0x19 - 0x1b) | |
1179 | */ | |
1180 | /* set vol=0 to output mixers */ | |
1181 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1182 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1183 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
377ff31a | 1184 | |
bfdc675a LW |
1185 | /* Setup default input MW0 to PW4 */ |
1186 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
1187 | /* PW9 Output enable */ |
1188 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
aa266fcc LW |
1189 | /* power down jack detect function */ |
1190 | {0x1, 0xf81, 0x1}, | |
f7278fd0 | 1191 | { } |
c577b8a1 JC |
1192 | }; |
1193 | ||
7eb56e84 TI |
1194 | static void substream_set_idle(struct hda_codec *codec, |
1195 | struct snd_pcm_substream *substream) | |
1196 | { | |
1197 | int idle = substream->pstr->substream_opened == 1 | |
1198 | && substream->ref_count == 0; | |
1199 | analog_low_current_mode(codec, idle); | |
1200 | } | |
1201 | ||
c577b8a1 JC |
1202 | static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, |
1203 | struct hda_codec *codec, | |
1204 | struct snd_pcm_substream *substream) | |
1205 | { | |
1206 | struct via_spec *spec = codec->spec; | |
7eb56e84 | 1207 | substream_set_idle(codec, substream); |
9a08160b TI |
1208 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
1209 | hinfo); | |
c577b8a1 JC |
1210 | } |
1211 | ||
9af74210 TI |
1212 | static int via_playback_pcm_close(struct hda_pcm_stream *hinfo, |
1213 | struct hda_codec *codec, | |
1214 | struct snd_pcm_substream *substream) | |
1215 | { | |
7eb56e84 TI |
1216 | substream_set_idle(codec, substream); |
1217 | return 0; | |
1218 | } | |
9af74210 | 1219 | |
7eb56e84 TI |
1220 | static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, |
1221 | struct hda_codec *codec, | |
1222 | struct snd_pcm_substream *substream) | |
1223 | { | |
1224 | struct via_spec *spec = codec->spec; | |
1225 | struct hda_multi_out *mout = &spec->multiout; | |
1226 | ||
1227 | if (!mout->hp_nid || mout->hp_nid == mout->dac_nids[HDA_FRONT] || | |
1228 | !spec->hp_independent_mode) | |
1229 | return -EINVAL; | |
1230 | substream_set_idle(codec, substream); | |
9af74210 TI |
1231 | return 0; |
1232 | } | |
1233 | ||
7eb56e84 TI |
1234 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
1235 | struct hda_codec *codec, | |
1236 | unsigned int stream_tag, | |
1237 | unsigned int format, | |
1238 | struct snd_pcm_substream *substream) | |
0aa62aef HW |
1239 | { |
1240 | struct via_spec *spec = codec->spec; | |
1241 | struct hda_multi_out *mout = &spec->multiout; | |
dda14410 | 1242 | const hda_nid_t *nids = mout->dac_nids; |
0aa62aef HW |
1243 | int chs = substream->runtime->channels; |
1244 | int i; | |
7c935976 SW |
1245 | struct hda_spdif_out *spdif = |
1246 | snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid); | |
0aa62aef HW |
1247 | |
1248 | mutex_lock(&codec->spdif_mutex); | |
1249 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { | |
1250 | if (chs == 2 && | |
1251 | snd_hda_is_supported_format(codec, mout->dig_out_nid, | |
1252 | format) && | |
7c935976 | 1253 | !(spdif->status & IEC958_AES0_NONAUDIO)) { |
0aa62aef HW |
1254 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
1255 | /* turn off SPDIF once; otherwise the IEC958 bits won't | |
1256 | * be updated */ | |
7c935976 | 1257 | if (spdif->ctls & AC_DIG1_ENABLE) |
0aa62aef HW |
1258 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
1259 | AC_VERB_SET_DIGI_CONVERT_1, | |
7c935976 | 1260 | spdif->ctls & |
0aa62aef HW |
1261 | ~AC_DIG1_ENABLE & 0xff); |
1262 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
1263 | stream_tag, 0, format); | |
1264 | /* turn on again (if needed) */ | |
7c935976 | 1265 | if (spdif->ctls & AC_DIG1_ENABLE) |
0aa62aef HW |
1266 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
1267 | AC_VERB_SET_DIGI_CONVERT_1, | |
7c935976 | 1268 | spdif->ctls & 0xff); |
0aa62aef HW |
1269 | } else { |
1270 | mout->dig_out_used = 0; | |
1271 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
1272 | 0, 0, 0); | |
1273 | } | |
1274 | } | |
1275 | mutex_unlock(&codec->spdif_mutex); | |
1276 | ||
1277 | /* front */ | |
1278 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, | |
1279 | 0, format); | |
1280 | ||
eb7188ca LW |
1281 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
1282 | && !spec->hp_independent_mode) | |
0aa62aef HW |
1283 | /* headphone out will just decode front left/right (stereo) */ |
1284 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, | |
1285 | 0, format); | |
1286 | ||
1287 | /* extra outputs copied from front */ | |
1288 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) | |
1289 | if (mout->extra_out_nid[i]) | |
1290 | snd_hda_codec_setup_stream(codec, | |
1291 | mout->extra_out_nid[i], | |
1292 | stream_tag, 0, format); | |
1293 | ||
1294 | /* surrounds */ | |
1295 | for (i = 1; i < mout->num_dacs; i++) { | |
1296 | if (chs >= (i + 1) * 2) /* independent out */ | |
1297 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, | |
1298 | i * 2, format); | |
1299 | else /* copy front */ | |
1300 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, | |
1301 | 0, format); | |
1302 | } | |
7eb56e84 TI |
1303 | vt1708_start_hp_work(spec); |
1304 | return 0; | |
0aa62aef HW |
1305 | } |
1306 | ||
7eb56e84 TI |
1307 | static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, |
1308 | struct hda_codec *codec, | |
1309 | unsigned int stream_tag, | |
1310 | unsigned int format, | |
1311 | struct snd_pcm_substream *substream) | |
0aa62aef HW |
1312 | { |
1313 | struct via_spec *spec = codec->spec; | |
1314 | struct hda_multi_out *mout = &spec->multiout; | |
0aa62aef | 1315 | |
7eb56e84 | 1316 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 0, format); |
1f2e99fe | 1317 | vt1708_start_hp_work(spec); |
0aa62aef HW |
1318 | return 0; |
1319 | } | |
1320 | ||
1321 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1322 | struct hda_codec *codec, | |
1323 | struct snd_pcm_substream *substream) | |
1324 | { | |
1325 | struct via_spec *spec = codec->spec; | |
1326 | struct hda_multi_out *mout = &spec->multiout; | |
dda14410 | 1327 | const hda_nid_t *nids = mout->dac_nids; |
0aa62aef HW |
1328 | int i; |
1329 | ||
7eb56e84 TI |
1330 | for (i = 0; i < mout->num_dacs; i++) |
1331 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); | |
0aa62aef | 1332 | |
7eb56e84 TI |
1333 | if (mout->hp_nid && !spec->hp_independent_mode) |
1334 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
1335 | 0, 0, 0); | |
0aa62aef | 1336 | |
7eb56e84 TI |
1337 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
1338 | if (mout->extra_out_nid[i]) | |
1339 | snd_hda_codec_setup_stream(codec, | |
1340 | mout->extra_out_nid[i], | |
0aa62aef | 1341 | 0, 0, 0); |
7eb56e84 TI |
1342 | mutex_lock(&codec->spdif_mutex); |
1343 | if (mout->dig_out_nid && | |
1344 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { | |
1345 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
1346 | 0, 0, 0); | |
1347 | mout->dig_out_used = 0; | |
0aa62aef | 1348 | } |
7eb56e84 TI |
1349 | mutex_unlock(&codec->spdif_mutex); |
1350 | vt1708_stop_hp_work(spec); | |
1351 | return 0; | |
1352 | } | |
1353 | ||
1354 | static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1355 | struct hda_codec *codec, | |
1356 | struct snd_pcm_substream *substream) | |
1357 | { | |
1358 | struct via_spec *spec = codec->spec; | |
1359 | struct hda_multi_out *mout = &spec->multiout; | |
1360 | ||
1361 | snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0); | |
1f2e99fe | 1362 | vt1708_stop_hp_work(spec); |
0aa62aef HW |
1363 | return 0; |
1364 | } | |
1365 | ||
c577b8a1 JC |
1366 | /* |
1367 | * Digital out | |
1368 | */ | |
1369 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
1370 | struct hda_codec *codec, | |
1371 | struct snd_pcm_substream *substream) | |
1372 | { | |
1373 | struct via_spec *spec = codec->spec; | |
1374 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
1375 | } | |
1376 | ||
1377 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
1378 | struct hda_codec *codec, | |
1379 | struct snd_pcm_substream *substream) | |
1380 | { | |
1381 | struct via_spec *spec = codec->spec; | |
1382 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
1383 | } | |
1384 | ||
5691ec7f | 1385 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
98aa34c0 HW |
1386 | struct hda_codec *codec, |
1387 | unsigned int stream_tag, | |
1388 | unsigned int format, | |
1389 | struct snd_pcm_substream *substream) | |
1390 | { | |
1391 | struct via_spec *spec = codec->spec; | |
9da29271 TI |
1392 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
1393 | stream_tag, format, substream); | |
1394 | } | |
98aa34c0 | 1395 | |
9da29271 TI |
1396 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1397 | struct hda_codec *codec, | |
1398 | struct snd_pcm_substream *substream) | |
1399 | { | |
1400 | struct via_spec *spec = codec->spec; | |
1401 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
98aa34c0 HW |
1402 | return 0; |
1403 | } | |
1404 | ||
c577b8a1 JC |
1405 | /* |
1406 | * Analog capture | |
1407 | */ | |
1408 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1409 | struct hda_codec *codec, | |
1410 | unsigned int stream_tag, | |
1411 | unsigned int format, | |
1412 | struct snd_pcm_substream *substream) | |
1413 | { | |
1414 | struct via_spec *spec = codec->spec; | |
1415 | ||
1416 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
1417 | stream_tag, 0, format); | |
1418 | return 0; | |
1419 | } | |
1420 | ||
1421 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1422 | struct hda_codec *codec, | |
1423 | struct snd_pcm_substream *substream) | |
1424 | { | |
1425 | struct via_spec *spec = codec->spec; | |
888afa15 | 1426 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
c577b8a1 JC |
1427 | return 0; |
1428 | } | |
1429 | ||
9af74210 | 1430 | static const struct hda_pcm_stream via_pcm_analog_playback = { |
7eb56e84 | 1431 | .substreams = 1, |
c577b8a1 JC |
1432 | .channels_min = 2, |
1433 | .channels_max = 8, | |
9af74210 | 1434 | /* NID is set in via_build_pcms */ |
c577b8a1 JC |
1435 | .ops = { |
1436 | .open = via_playback_pcm_open, | |
9af74210 | 1437 | .close = via_playback_pcm_close, |
0aa62aef HW |
1438 | .prepare = via_playback_multi_pcm_prepare, |
1439 | .cleanup = via_playback_multi_pcm_cleanup | |
c577b8a1 JC |
1440 | }, |
1441 | }; | |
1442 | ||
7eb56e84 TI |
1443 | static const struct hda_pcm_stream via_pcm_hp_playback = { |
1444 | .substreams = 1, | |
1445 | .channels_min = 2, | |
1446 | .channels_max = 2, | |
1447 | /* NID is set in via_build_pcms */ | |
1448 | .ops = { | |
1449 | .open = via_playback_hp_pcm_open, | |
1450 | .close = via_playback_pcm_close, | |
1451 | .prepare = via_playback_hp_pcm_prepare, | |
1452 | .cleanup = via_playback_hp_pcm_cleanup | |
1453 | }, | |
1454 | }; | |
1455 | ||
90dd48a1 | 1456 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
7eb56e84 | 1457 | .substreams = 1, |
bc9b5623 TI |
1458 | .channels_min = 2, |
1459 | .channels_max = 8, | |
9af74210 | 1460 | /* NID is set in via_build_pcms */ |
bc9b5623 TI |
1461 | /* We got noisy outputs on the right channel on VT1708 when |
1462 | * 24bit samples are used. Until any workaround is found, | |
1463 | * disable the 24bit format, so far. | |
1464 | */ | |
1465 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
1466 | .ops = { | |
1467 | .open = via_playback_pcm_open, | |
9af74210 | 1468 | .close = via_playback_pcm_close, |
c873cc25 LW |
1469 | .prepare = via_playback_multi_pcm_prepare, |
1470 | .cleanup = via_playback_multi_pcm_cleanup | |
bc9b5623 TI |
1471 | }, |
1472 | }; | |
1473 | ||
9af74210 | 1474 | static const struct hda_pcm_stream via_pcm_analog_capture = { |
7eb56e84 | 1475 | .substreams = 1, /* will be changed in via_build_pcms() */ |
c577b8a1 JC |
1476 | .channels_min = 2, |
1477 | .channels_max = 2, | |
9af74210 | 1478 | /* NID is set in via_build_pcms */ |
c577b8a1 | 1479 | .ops = { |
9af74210 TI |
1480 | .open = via_playback_pcm_open, |
1481 | .close = via_playback_pcm_close, | |
c577b8a1 JC |
1482 | .prepare = via_capture_pcm_prepare, |
1483 | .cleanup = via_capture_pcm_cleanup | |
1484 | }, | |
1485 | }; | |
1486 | ||
9af74210 | 1487 | static const struct hda_pcm_stream via_pcm_digital_playback = { |
c577b8a1 JC |
1488 | .substreams = 1, |
1489 | .channels_min = 2, | |
1490 | .channels_max = 2, | |
1491 | /* NID is set in via_build_pcms */ | |
1492 | .ops = { | |
1493 | .open = via_dig_playback_pcm_open, | |
6b97eb45 | 1494 | .close = via_dig_playback_pcm_close, |
9da29271 TI |
1495 | .prepare = via_dig_playback_pcm_prepare, |
1496 | .cleanup = via_dig_playback_pcm_cleanup | |
c577b8a1 JC |
1497 | }, |
1498 | }; | |
1499 | ||
9af74210 | 1500 | static const struct hda_pcm_stream via_pcm_digital_capture = { |
c577b8a1 JC |
1501 | .substreams = 1, |
1502 | .channels_min = 2, | |
1503 | .channels_max = 2, | |
1504 | }; | |
1505 | ||
1506 | static int via_build_controls(struct hda_codec *codec) | |
1507 | { | |
1508 | struct via_spec *spec = codec->spec; | |
5b0cb1d8 | 1509 | struct snd_kcontrol *kctl; |
90dd48a1 | 1510 | const struct snd_kcontrol_new *knew; |
5b0cb1d8 | 1511 | int err, i; |
c577b8a1 | 1512 | |
24088a58 TI |
1513 | if (spec->set_widgets_power_state) |
1514 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) | |
1515 | return -ENOMEM; | |
1516 | ||
c577b8a1 JC |
1517 | for (i = 0; i < spec->num_mixers; i++) { |
1518 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
1519 | if (err < 0) | |
1520 | return err; | |
1521 | } | |
1522 | ||
1523 | if (spec->multiout.dig_out_nid) { | |
1524 | err = snd_hda_create_spdif_out_ctls(codec, | |
74b654c9 | 1525 | spec->multiout.dig_out_nid, |
c577b8a1 JC |
1526 | spec->multiout.dig_out_nid); |
1527 | if (err < 0) | |
1528 | return err; | |
9a08160b TI |
1529 | err = snd_hda_create_spdif_share_sw(codec, |
1530 | &spec->multiout); | |
1531 | if (err < 0) | |
1532 | return err; | |
1533 | spec->multiout.share_spdif = 1; | |
c577b8a1 JC |
1534 | } |
1535 | if (spec->dig_in_nid) { | |
1536 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
1537 | if (err < 0) | |
1538 | return err; | |
1539 | } | |
17314379 | 1540 | |
5b0cb1d8 JK |
1541 | /* assign Capture Source enums to NID */ |
1542 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); | |
1543 | for (i = 0; kctl && i < kctl->count; i++) { | |
21949f00 | 1544 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
5b0cb1d8 JK |
1545 | if (err < 0) |
1546 | return err; | |
1547 | } | |
1548 | ||
1549 | /* other nid->control mapping */ | |
1550 | for (i = 0; i < spec->num_mixers; i++) { | |
1551 | for (knew = spec->mixers[i]; knew->name; knew++) { | |
1552 | if (knew->iface != NID_MAPPING) | |
1553 | continue; | |
1554 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); | |
1555 | if (kctl == NULL) | |
1556 | continue; | |
1557 | err = snd_hda_add_nid(codec, kctl, 0, | |
1558 | knew->subdevice); | |
1559 | } | |
1560 | } | |
1561 | ||
17314379 | 1562 | /* init power states */ |
3e95b9ab | 1563 | set_widgets_power_state(codec); |
17314379 LW |
1564 | analog_low_current_mode(codec, 1); |
1565 | ||
603c4019 | 1566 | via_free_kctls(codec); /* no longer needed */ |
c577b8a1 JC |
1567 | return 0; |
1568 | } | |
1569 | ||
1570 | static int via_build_pcms(struct hda_codec *codec) | |
1571 | { | |
1572 | struct via_spec *spec = codec->spec; | |
1573 | struct hda_pcm *info = spec->pcm_rec; | |
1574 | ||
1575 | codec->num_pcms = 1; | |
1576 | codec->pcm_info = info; | |
1577 | ||
82673bc8 TI |
1578 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
1579 | "%s Analog", codec->chip_name); | |
c577b8a1 | 1580 | info->name = spec->stream_name_analog; |
9af74210 TI |
1581 | |
1582 | if (!spec->stream_analog_playback) | |
1583 | spec->stream_analog_playback = &via_pcm_analog_playback; | |
377ff31a | 1584 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
9af74210 | 1585 | *spec->stream_analog_playback; |
377ff31a LW |
1586 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
1587 | spec->multiout.dac_nids[0]; | |
9af74210 TI |
1588 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
1589 | spec->multiout.max_channels; | |
c577b8a1 | 1590 | |
9af74210 TI |
1591 | if (!spec->stream_analog_capture) |
1592 | spec->stream_analog_capture = &via_pcm_analog_capture; | |
1593 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
1594 | *spec->stream_analog_capture; | |
1595 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
1596 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | |
1597 | spec->num_adc_nids; | |
c577b8a1 JC |
1598 | |
1599 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | |
1600 | codec->num_pcms++; | |
1601 | info++; | |
82673bc8 TI |
1602 | snprintf(spec->stream_name_digital, |
1603 | sizeof(spec->stream_name_digital), | |
1604 | "%s Digital", codec->chip_name); | |
c577b8a1 | 1605 | info->name = spec->stream_name_digital; |
7ba72ba1 | 1606 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
c577b8a1 | 1607 | if (spec->multiout.dig_out_nid) { |
9af74210 TI |
1608 | if (!spec->stream_digital_playback) |
1609 | spec->stream_digital_playback = | |
1610 | &via_pcm_digital_playback; | |
c577b8a1 | 1611 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
9af74210 | 1612 | *spec->stream_digital_playback; |
c577b8a1 JC |
1613 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
1614 | spec->multiout.dig_out_nid; | |
1615 | } | |
1616 | if (spec->dig_in_nid) { | |
9af74210 TI |
1617 | if (!spec->stream_digital_capture) |
1618 | spec->stream_digital_capture = | |
1619 | &via_pcm_digital_capture; | |
c577b8a1 | 1620 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
9af74210 | 1621 | *spec->stream_digital_capture; |
c577b8a1 JC |
1622 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
1623 | spec->dig_in_nid; | |
1624 | } | |
1625 | } | |
1626 | ||
7eb56e84 TI |
1627 | if (spec->multiout.hp_nid) { |
1628 | codec->num_pcms++; | |
1629 | info++; | |
1630 | snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), | |
1631 | "%s HP", codec->chip_name); | |
1632 | info->name = spec->stream_name_hp; | |
1633 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; | |
1634 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
1635 | spec->multiout.hp_nid; | |
1636 | } | |
c577b8a1 JC |
1637 | return 0; |
1638 | } | |
1639 | ||
1640 | static void via_free(struct hda_codec *codec) | |
1641 | { | |
1642 | struct via_spec *spec = codec->spec; | |
c577b8a1 JC |
1643 | |
1644 | if (!spec) | |
1645 | return; | |
1646 | ||
603c4019 | 1647 | via_free_kctls(codec); |
1f2e99fe | 1648 | vt1708_stop_hp_work(spec); |
c577b8a1 JC |
1649 | kfree(codec->spec); |
1650 | } | |
1651 | ||
64be285b TI |
1652 | /* mute/unmute outputs */ |
1653 | static void toggle_output_mutes(struct hda_codec *codec, int num_pins, | |
1654 | hda_nid_t *pins, bool mute) | |
1655 | { | |
1656 | int i; | |
1657 | for (i = 0; i < num_pins; i++) | |
1658 | snd_hda_codec_write(codec, pins[i], 0, | |
1659 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1660 | mute ? 0 : PIN_OUT); | |
1661 | } | |
1662 | ||
69e52a80 HW |
1663 | /* mute internal speaker if HP is plugged */ |
1664 | static void via_hp_automute(struct hda_codec *codec) | |
1665 | { | |
dcf34c8c | 1666 | unsigned int present = 0; |
69e52a80 HW |
1667 | struct via_spec *spec = codec->spec; |
1668 | ||
d56757ab | 1669 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
dcf34c8c | 1670 | |
64be285b TI |
1671 | if (!spec->hp_independent_mode) |
1672 | toggle_output_mutes(codec, spec->autocfg.line_outs, | |
1673 | spec->autocfg.line_out_pins, | |
1674 | present); | |
69e52a80 HW |
1675 | } |
1676 | ||
f3db423d LW |
1677 | /* mute mono out if HP or Line out is plugged */ |
1678 | static void via_mono_automute(struct hda_codec *codec) | |
1679 | { | |
1680 | unsigned int hp_present, lineout_present; | |
1681 | struct via_spec *spec = codec->spec; | |
1682 | ||
1683 | if (spec->codec_type != VT1716S) | |
1684 | return; | |
1685 | ||
d56757ab TI |
1686 | lineout_present = snd_hda_jack_detect(codec, |
1687 | spec->autocfg.line_out_pins[0]); | |
f3db423d LW |
1688 | |
1689 | /* Mute Mono Out if Line Out is plugged */ | |
1690 | if (lineout_present) { | |
3e0693e2 TI |
1691 | snd_hda_codec_write(codec, 0x2A, 0, |
1692 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1693 | lineout_present ? 0 : PIN_OUT); | |
f3db423d LW |
1694 | return; |
1695 | } | |
1696 | ||
d56757ab | 1697 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
f3db423d LW |
1698 | |
1699 | if (!spec->hp_independent_mode) | |
3e0693e2 TI |
1700 | snd_hda_codec_write(codec, 0x2A, 0, |
1701 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1702 | hp_present ? 0 : PIN_OUT); | |
f3db423d LW |
1703 | } |
1704 | ||
69e52a80 HW |
1705 | static void via_gpio_control(struct hda_codec *codec) |
1706 | { | |
1707 | unsigned int gpio_data; | |
1708 | unsigned int vol_counter; | |
1709 | unsigned int vol; | |
1710 | unsigned int master_vol; | |
1711 | ||
1712 | struct via_spec *spec = codec->spec; | |
1713 | ||
1714 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, | |
1715 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; | |
1716 | ||
1717 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, | |
1718 | 0xF84, 0) & 0x3F0000) >> 16; | |
1719 | ||
1720 | vol = vol_counter & 0x1F; | |
1721 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, | |
1722 | AC_VERB_GET_AMP_GAIN_MUTE, | |
1723 | AC_AMP_GET_INPUT); | |
1724 | ||
1725 | if (gpio_data == 0x02) { | |
1726 | /* unmute line out */ | |
3e0693e2 TI |
1727 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
1728 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1729 | PIN_OUT); | |
69e52a80 HW |
1730 | if (vol_counter & 0x20) { |
1731 | /* decrease volume */ | |
1732 | if (vol > master_vol) | |
1733 | vol = master_vol; | |
1734 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, | |
1735 | 0, HDA_AMP_VOLMASK, | |
1736 | master_vol-vol); | |
1737 | } else { | |
1738 | /* increase volume */ | |
1739 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, | |
1740 | HDA_AMP_VOLMASK, | |
1741 | ((master_vol+vol) > 0x2A) ? 0x2A : | |
1742 | (master_vol+vol)); | |
1743 | } | |
1744 | } else if (!(gpio_data & 0x02)) { | |
1745 | /* mute line out */ | |
3e0693e2 TI |
1746 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
1747 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
1748 | 0); | |
69e52a80 HW |
1749 | } |
1750 | } | |
1751 | ||
25eaba2f LW |
1752 | /* mute Internal-Speaker if HP is plugged */ |
1753 | static void via_speaker_automute(struct hda_codec *codec) | |
1754 | { | |
1755 | unsigned int hp_present; | |
1756 | struct via_spec *spec = codec->spec; | |
1757 | ||
27439ce7 | 1758 | if (!VT2002P_COMPATIBLE(spec)) |
25eaba2f LW |
1759 | return; |
1760 | ||
d56757ab | 1761 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
25eaba2f | 1762 | |
64be285b TI |
1763 | if (!spec->hp_independent_mode) |
1764 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, | |
1765 | spec->autocfg.speaker_pins, | |
1766 | hp_present); | |
25eaba2f LW |
1767 | } |
1768 | ||
1769 | /* mute line-out and internal speaker if HP is plugged */ | |
1770 | static void via_hp_bind_automute(struct hda_codec *codec) | |
1771 | { | |
64be285b | 1772 | int present; |
25eaba2f | 1773 | struct via_spec *spec = codec->spec; |
25eaba2f LW |
1774 | |
1775 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) | |
1776 | return; | |
1777 | ||
64be285b TI |
1778 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
1779 | if (!spec->hp_independent_mode) | |
1780 | toggle_output_mutes(codec, spec->autocfg.line_outs, | |
1781 | spec->autocfg.line_out_pins, | |
1782 | present); | |
25eaba2f | 1783 | |
64be285b TI |
1784 | if (!present) |
1785 | present = snd_hda_jack_detect(codec, | |
1786 | spec->autocfg.line_out_pins[0]); | |
25eaba2f | 1787 | |
25eaba2f | 1788 | /* Speakers */ |
64be285b TI |
1789 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
1790 | spec->autocfg.speaker_pins, | |
1791 | present); | |
25eaba2f LW |
1792 | } |
1793 | ||
1794 | ||
69e52a80 HW |
1795 | /* unsolicited event for jack sensing */ |
1796 | static void via_unsol_event(struct hda_codec *codec, | |
1797 | unsigned int res) | |
1798 | { | |
1799 | res >>= 26; | |
ec7e7e42 | 1800 | |
a34df19a | 1801 | if (res & VIA_JACK_EVENT) |
3e95b9ab | 1802 | set_widgets_power_state(codec); |
ec7e7e42 LW |
1803 | |
1804 | res &= ~VIA_JACK_EVENT; | |
1805 | ||
1806 | if (res == VIA_HP_EVENT) | |
1807 | via_hp_automute(codec); | |
1808 | else if (res == VIA_GPIO_EVENT) | |
1809 | via_gpio_control(codec); | |
1810 | else if (res == VIA_MONO_EVENT) | |
f3db423d | 1811 | via_mono_automute(codec); |
ec7e7e42 | 1812 | else if (res == VIA_SPEAKER_EVENT) |
25eaba2f | 1813 | via_speaker_automute(codec); |
ec7e7e42 | 1814 | else if (res == VIA_BIND_HP_EVENT) |
25eaba2f | 1815 | via_hp_bind_automute(codec); |
69e52a80 HW |
1816 | } |
1817 | ||
c577b8a1 JC |
1818 | static int via_init(struct hda_codec *codec) |
1819 | { | |
1820 | struct via_spec *spec = codec->spec; | |
69e52a80 HW |
1821 | int i; |
1822 | for (i = 0; i < spec->num_iverbs; i++) | |
1823 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
1824 | ||
f7278fd0 JC |
1825 | /* Lydia Add for EAPD enable */ |
1826 | if (!spec->dig_in_nid) { /* No Digital In connection */ | |
55d1d6c1 TI |
1827 | if (spec->dig_in_pin) { |
1828 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, | |
f7278fd0 | 1829 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
12b74c80 | 1830 | PIN_OUT); |
55d1d6c1 | 1831 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
f7278fd0 JC |
1832 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
1833 | } | |
12b74c80 TI |
1834 | } else /* enable SPDIF-input pin */ |
1835 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, | |
1836 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | |
f7278fd0 | 1837 | |
9da29271 TI |
1838 | /* assign slave outs */ |
1839 | if (spec->slave_dig_outs[0]) | |
1840 | codec->slave_dig_outs = spec->slave_dig_outs; | |
5691ec7f | 1841 | |
377ff31a | 1842 | return 0; |
c577b8a1 JC |
1843 | } |
1844 | ||
1f2e99fe LW |
1845 | #ifdef SND_HDA_NEEDS_RESUME |
1846 | static int via_suspend(struct hda_codec *codec, pm_message_t state) | |
1847 | { | |
1848 | struct via_spec *spec = codec->spec; | |
1849 | vt1708_stop_hp_work(spec); | |
1850 | return 0; | |
1851 | } | |
1852 | #endif | |
1853 | ||
cb53c626 TI |
1854 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1855 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) | |
1856 | { | |
1857 | struct via_spec *spec = codec->spec; | |
1858 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | |
1859 | } | |
1860 | #endif | |
1861 | ||
c577b8a1 JC |
1862 | /* |
1863 | */ | |
90dd48a1 | 1864 | static const struct hda_codec_ops via_patch_ops = { |
c577b8a1 JC |
1865 | .build_controls = via_build_controls, |
1866 | .build_pcms = via_build_pcms, | |
1867 | .init = via_init, | |
1868 | .free = via_free, | |
1f2e99fe LW |
1869 | #ifdef SND_HDA_NEEDS_RESUME |
1870 | .suspend = via_suspend, | |
1871 | #endif | |
cb53c626 TI |
1872 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1873 | .check_power_status = via_check_power_status, | |
1874 | #endif | |
c577b8a1 JC |
1875 | }; |
1876 | ||
4a79616d TI |
1877 | static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) |
1878 | { | |
1879 | struct via_spec *spec = codec->spec; | |
1880 | int i; | |
1881 | ||
1882 | for (i = 0; i < spec->multiout.num_dacs; i++) { | |
1883 | if (spec->multiout.dac_nids[i] == dac) | |
1884 | return false; | |
1885 | } | |
1886 | if (spec->multiout.hp_nid == dac) | |
1887 | return false; | |
1888 | return true; | |
1889 | } | |
1890 | ||
1891 | static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, | |
1892 | hda_nid_t target_dac, struct nid_path *path, | |
1893 | int depth, int wid_type) | |
1894 | { | |
1895 | hda_nid_t conn[8]; | |
1896 | int i, nums; | |
1897 | ||
1898 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); | |
1899 | for (i = 0; i < nums; i++) { | |
1900 | if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) | |
1901 | continue; | |
1902 | if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { | |
1903 | path->path[depth] = conn[i]; | |
1904 | path->idx[depth] = i; | |
1905 | path->depth = ++depth; | |
1906 | return true; | |
1907 | } | |
1908 | } | |
1909 | if (depth > 4) | |
1910 | return false; | |
1911 | for (i = 0; i < nums; i++) { | |
1912 | unsigned int type; | |
1913 | type = get_wcaps_type(get_wcaps(codec, conn[i])); | |
1914 | if (type == AC_WID_AUD_OUT || | |
1915 | (wid_type != -1 && type != wid_type)) | |
1916 | continue; | |
1917 | if (parse_output_path(codec, conn[i], target_dac, | |
1918 | path, depth + 1, AC_WID_AUD_SEL)) { | |
1919 | path->path[depth] = conn[i]; | |
1920 | path->idx[depth] = i; | |
1921 | return true; | |
1922 | } | |
1923 | } | |
1924 | return false; | |
1925 | } | |
1926 | ||
1927 | static int via_auto_fill_dac_nids(struct hda_codec *codec) | |
c577b8a1 | 1928 | { |
4a79616d TI |
1929 | struct via_spec *spec = codec->spec; |
1930 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
c577b8a1 JC |
1931 | int i; |
1932 | hda_nid_t nid; | |
1933 | ||
4a79616d | 1934 | spec->multiout.dac_nids = spec->private_dac_nids; |
c577b8a1 | 1935 | spec->multiout.num_dacs = cfg->line_outs; |
4a79616d TI |
1936 | for (i = 0; i < cfg->line_outs; i++) { |
1937 | nid = cfg->line_out_pins[i]; | |
1938 | if (!nid) | |
1939 | continue; | |
1940 | if (parse_output_path(codec, nid, 0, &spec->out_path[i], 0, -1)) | |
1941 | spec->private_dac_nids[i] = | |
1942 | spec->out_path[i].path[spec->out_path[i].depth - 1]; | |
1943 | } | |
1944 | return 0; | |
1945 | } | |
c577b8a1 | 1946 | |
4a79616d TI |
1947 | static int create_ch_ctls(struct hda_codec *codec, const char *pfx, |
1948 | hda_nid_t pin, hda_nid_t dac, int chs) | |
1949 | { | |
1950 | struct via_spec *spec = codec->spec; | |
1951 | char name[32]; | |
1952 | hda_nid_t nid; | |
1953 | int err; | |
377ff31a | 1954 | |
4a79616d TI |
1955 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) |
1956 | nid = dac; | |
1957 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_NUM_STEPS) | |
1958 | nid = pin; | |
1959 | else | |
1960 | nid = 0; | |
1961 | if (nid) { | |
1962 | sprintf(name, "%s Playback Volume", pfx); | |
1963 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
1964 | HDA_COMPOSE_AMP_VAL(dac, chs, 0, HDA_OUTPUT)); | |
1965 | if (err < 0) | |
1966 | return err; | |
c577b8a1 JC |
1967 | } |
1968 | ||
4a79616d TI |
1969 | if (dac && query_amp_caps(codec, dac, HDA_OUTPUT) & AC_AMPCAP_MUTE) |
1970 | nid = dac; | |
1971 | else if (query_amp_caps(codec, pin, HDA_OUTPUT) & AC_AMPCAP_MUTE) | |
1972 | nid = pin; | |
1973 | else | |
1974 | nid = 0; | |
1975 | if (nid) { | |
1976 | sprintf(name, "%s Playback Switch", pfx); | |
1977 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
1978 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); | |
1979 | if (err < 0) | |
1980 | return err; | |
1981 | } | |
c577b8a1 JC |
1982 | return 0; |
1983 | } | |
1984 | ||
4a79616d TI |
1985 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
1986 | hda_nid_t nid); | |
1987 | ||
f4a7828b TI |
1988 | static void mangle_smart51(struct hda_codec *codec) |
1989 | { | |
1990 | struct via_spec *spec = codec->spec; | |
1991 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
1992 | int i; | |
1993 | ||
1994 | for (i = 0; i < cfg->num_inputs; i++) { | |
1995 | if (!is_smart51_pins(codec, cfg->inputs[i].pin)) | |
1996 | continue; | |
1997 | spec->can_smart51 = 1; | |
1998 | cfg->line_out_pins[cfg->line_outs++] = cfg->inputs[i].pin; | |
1999 | if (cfg->line_outs == 3) | |
2000 | break; | |
2001 | } | |
2002 | } | |
2003 | ||
c577b8a1 | 2004 | /* add playback controls from the parsed DAC table */ |
4a79616d | 2005 | static int via_auto_create_multi_out_ctls(struct hda_codec *codec) |
c577b8a1 | 2006 | { |
4a79616d | 2007 | struct via_spec *spec = codec->spec; |
f4a7828b | 2008 | struct auto_pin_cfg *cfg = &spec->autocfg; |
ea734963 TI |
2009 | static const char * const chname[4] = { |
2010 | "Front", "Surround", "C/LFE", "Side" | |
2011 | }; | |
4a79616d | 2012 | int i, idx, err; |
f4a7828b TI |
2013 | int old_line_outs; |
2014 | ||
2015 | /* check smart51 */ | |
2016 | old_line_outs = cfg->line_outs; | |
2017 | if (cfg->line_outs == 1) | |
2018 | mangle_smart51(codec); | |
c577b8a1 | 2019 | |
4a79616d TI |
2020 | for (i = 0; i < cfg->line_outs; i++) { |
2021 | hda_nid_t pin, dac; | |
2022 | pin = cfg->line_out_pins[i]; | |
2023 | dac = spec->multiout.dac_nids[i]; | |
2024 | if (!pin || !dac) | |
c577b8a1 | 2025 | continue; |
c577b8a1 | 2026 | if (i == AUTO_SEQ_CENLFE) { |
4a79616d | 2027 | err = create_ch_ctls(codec, "Center", pin, dac, 1); |
c577b8a1 JC |
2028 | if (err < 0) |
2029 | return err; | |
4a79616d | 2030 | err = create_ch_ctls(codec, "LFE", pin, dac, 2); |
c577b8a1 JC |
2031 | if (err < 0) |
2032 | return err; | |
2033 | } else { | |
4a79616d | 2034 | err = create_ch_ctls(codec, chname[i], pin, dac, 3); |
c577b8a1 JC |
2035 | if (err < 0) |
2036 | return err; | |
2037 | } | |
2038 | } | |
2039 | ||
4a79616d TI |
2040 | idx = get_connection_index(codec, spec->aa_mix_nid, |
2041 | spec->multiout.dac_nids[0]); | |
2042 | if (idx >= 0) { | |
2043 | /* add control to mixer */ | |
2044 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2045 | "PCM Playback Volume", | |
2046 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, | |
2047 | idx, HDA_INPUT)); | |
2048 | if (err < 0) | |
2049 | return err; | |
2050 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2051 | "PCM Playback Switch", | |
2052 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, | |
2053 | idx, HDA_INPUT)); | |
2054 | if (err < 0) | |
2055 | return err; | |
2056 | } | |
2057 | ||
f4a7828b TI |
2058 | cfg->line_outs = old_line_outs; |
2059 | ||
c577b8a1 JC |
2060 | return 0; |
2061 | } | |
2062 | ||
0aa62aef HW |
2063 | static void create_hp_imux(struct via_spec *spec) |
2064 | { | |
2065 | int i; | |
2066 | struct hda_input_mux *imux = &spec->private_imux[1]; | |
ea734963 | 2067 | static const char * const texts[] = { "OFF", "ON", NULL}; |
0aa62aef HW |
2068 | |
2069 | /* for hp mode select */ | |
10a20af7 TI |
2070 | for (i = 0; texts[i]; i++) |
2071 | snd_hda_add_imux_item(imux, texts[i], i, NULL); | |
0aa62aef HW |
2072 | |
2073 | spec->hp_mux = &spec->private_imux[1]; | |
2074 | } | |
2075 | ||
4a79616d | 2076 | static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) |
c577b8a1 | 2077 | { |
4a79616d TI |
2078 | struct via_spec *spec = codec->spec; |
2079 | hda_nid_t dac = 0; | |
c577b8a1 JC |
2080 | int err; |
2081 | ||
2082 | if (!pin) | |
2083 | return 0; | |
2084 | ||
4a79616d TI |
2085 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
2086 | &spec->hp_dep_path, 0, -1)) | |
2087 | return 0; | |
2088 | if (parse_output_path(codec, pin, 0, &spec->hp_path, 0, -1)) { | |
2089 | dac = spec->hp_path.path[spec->hp_path.depth - 1]; | |
2090 | spec->multiout.hp_nid = dac; | |
2091 | spec->hp_independent_mode_index = | |
2092 | spec->hp_path.idx[spec->hp_path.depth - 1]; | |
2093 | create_hp_imux(spec); | |
2094 | } | |
c577b8a1 | 2095 | |
4a79616d | 2096 | err = create_ch_ctls(codec, "Headphone", pin, dac, 3); |
c577b8a1 JC |
2097 | if (err < 0) |
2098 | return err; | |
2099 | ||
2100 | return 0; | |
2101 | } | |
2102 | ||
a766d0d7 TI |
2103 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
2104 | hda_nid_t nid) | |
2105 | { | |
2106 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; | |
2107 | int i, nums; | |
2108 | ||
2109 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); | |
2110 | for (i = 0; i < nums; i++) | |
2111 | if (conn[i] == nid) | |
2112 | return i; | |
2113 | return -1; | |
2114 | } | |
2115 | ||
2116 | /* look for ADCs */ | |
2117 | static int via_fill_adcs(struct hda_codec *codec) | |
2118 | { | |
2119 | struct via_spec *spec = codec->spec; | |
2120 | hda_nid_t nid = codec->start_nid; | |
2121 | int i; | |
2122 | ||
2123 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
2124 | unsigned int wcaps = get_wcaps(codec, nid); | |
2125 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | |
2126 | continue; | |
2127 | if (wcaps & AC_WCAP_DIGITAL) | |
2128 | continue; | |
2129 | if (!(wcaps & AC_WCAP_CONN_LIST)) | |
2130 | continue; | |
2131 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) | |
2132 | return -ENOMEM; | |
2133 | spec->adc_nids[spec->num_adc_nids++] = nid; | |
2134 | } | |
2135 | return 0; | |
2136 | } | |
2137 | ||
2138 | static int get_mux_nids(struct hda_codec *codec); | |
2139 | ||
d7a99cce TI |
2140 | static const struct snd_kcontrol_new via_input_src_ctl = { |
2141 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2142 | /* The multiple "Capture Source" controls confuse alsamixer | |
2143 | * So call somewhat different.. | |
2144 | */ | |
2145 | /* .name = "Capture Source", */ | |
2146 | .name = "Input Source", | |
2147 | .info = via_mux_enum_info, | |
2148 | .get = via_mux_enum_get, | |
2149 | .put = via_mux_enum_put, | |
2150 | }; | |
2151 | ||
c577b8a1 | 2152 | /* create playback/capture controls for input pins */ |
620e2b28 TI |
2153 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec, |
2154 | const struct auto_pin_cfg *cfg) | |
c577b8a1 | 2155 | { |
10a20af7 | 2156 | struct via_spec *spec = codec->spec; |
0aa62aef | 2157 | struct hda_input_mux *imux = &spec->private_imux[0]; |
a766d0d7 TI |
2158 | int i, err, idx, idx2, type, type_idx = 0; |
2159 | hda_nid_t cap_nid; | |
2160 | hda_nid_t pin_idxs[8]; | |
2161 | int num_idxs; | |
2162 | ||
2163 | err = via_fill_adcs(codec); | |
2164 | if (err < 0) | |
2165 | return err; | |
2166 | err = get_mux_nids(codec); | |
2167 | if (err < 0) | |
2168 | return err; | |
2169 | cap_nid = spec->mux_nids[0]; | |
2170 | ||
2171 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, | |
2172 | ARRAY_SIZE(pin_idxs)); | |
2173 | if (num_idxs <= 0) | |
2174 | return 0; | |
c577b8a1 JC |
2175 | |
2176 | /* for internal loopback recording select */ | |
f3268512 | 2177 | for (idx = 0; idx < num_idxs; idx++) { |
620e2b28 | 2178 | if (pin_idxs[idx] == spec->aa_mix_nid) { |
10a20af7 | 2179 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); |
f3268512 TI |
2180 | break; |
2181 | } | |
2182 | } | |
c577b8a1 | 2183 | |
7b315bb4 | 2184 | for (i = 0; i < cfg->num_inputs; i++) { |
10a20af7 | 2185 | const char *label; |
7b315bb4 | 2186 | type = cfg->inputs[i].type; |
f3268512 | 2187 | for (idx = 0; idx < num_idxs; idx++) |
7b315bb4 | 2188 | if (pin_idxs[idx] == cfg->inputs[i].pin) |
f3268512 TI |
2189 | break; |
2190 | if (idx >= num_idxs) | |
2191 | continue; | |
7b315bb4 TI |
2192 | if (i > 0 && type == cfg->inputs[i - 1].type) |
2193 | type_idx++; | |
2194 | else | |
2195 | type_idx = 0; | |
10a20af7 | 2196 | label = hda_get_autocfg_input_label(codec, cfg, i); |
620e2b28 TI |
2197 | idx2 = get_connection_index(codec, spec->aa_mix_nid, |
2198 | pin_idxs[idx]); | |
a766d0d7 | 2199 | if (idx2 >= 0) |
16922281 | 2200 | err = via_new_analog_input(spec, label, type_idx, |
620e2b28 | 2201 | idx2, spec->aa_mix_nid); |
c577b8a1 JC |
2202 | if (err < 0) |
2203 | return err; | |
10a20af7 | 2204 | snd_hda_add_imux_item(imux, label, idx, NULL); |
c577b8a1 | 2205 | } |
d7a99cce TI |
2206 | |
2207 | /* create capture mixer elements */ | |
2208 | for (i = 0; i < spec->num_adc_nids; i++) { | |
2209 | hda_nid_t adc = spec->adc_nids[i]; | |
2210 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2211 | "Capture Volume", i, | |
2212 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, | |
2213 | HDA_INPUT)); | |
2214 | if (err < 0) | |
2215 | return err; | |
2216 | err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2217 | "Capture Switch", i, | |
2218 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, | |
2219 | HDA_INPUT)); | |
2220 | if (err < 0) | |
2221 | return err; | |
2222 | } | |
2223 | ||
2224 | /* input-source control */ | |
2225 | for (i = 0; i < spec->num_adc_nids; i++) | |
2226 | if (!spec->mux_nids[i]) | |
2227 | break; | |
2228 | if (i) { | |
2229 | struct snd_kcontrol_new *knew; | |
2230 | knew = via_clone_control(spec, &via_input_src_ctl); | |
2231 | if (!knew) | |
2232 | return -ENOMEM; | |
2233 | knew->count = i; | |
2234 | } | |
2235 | ||
2236 | /* mic-boosts */ | |
2237 | for (i = 0; i < cfg->num_inputs; i++) { | |
2238 | hda_nid_t pin = cfg->inputs[i].pin; | |
2239 | unsigned int caps; | |
2240 | const char *label; | |
2241 | char name[32]; | |
2242 | ||
2243 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | |
2244 | continue; | |
2245 | caps = query_amp_caps(codec, pin, HDA_INPUT); | |
2246 | if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) | |
2247 | continue; | |
2248 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
2249 | snprintf(name, sizeof(name), "%s Boost Capture Volume", label); | |
2250 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
2251 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); | |
2252 | if (err < 0) | |
2253 | return err; | |
2254 | } | |
2255 | ||
c577b8a1 JC |
2256 | return 0; |
2257 | } | |
2258 | ||
cb53c626 | 2259 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
90dd48a1 | 2260 | static const struct hda_amp_list vt1708_loopbacks[] = { |
cb53c626 TI |
2261 | { 0x17, HDA_INPUT, 1 }, |
2262 | { 0x17, HDA_INPUT, 2 }, | |
2263 | { 0x17, HDA_INPUT, 3 }, | |
2264 | { 0x17, HDA_INPUT, 4 }, | |
2265 | { } /* end */ | |
2266 | }; | |
2267 | #endif | |
2268 | ||
76d9b0dd HW |
2269 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
2270 | { | |
2271 | unsigned int def_conf; | |
2272 | unsigned char seqassoc; | |
2273 | ||
2f334f92 | 2274 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
76d9b0dd HW |
2275 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
2276 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); | |
82ef9e45 LW |
2277 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
2278 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { | |
2279 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); | |
2280 | snd_hda_codec_set_pincfg(codec, nid, def_conf); | |
76d9b0dd HW |
2281 | } |
2282 | ||
2283 | return; | |
2284 | } | |
2285 | ||
e06e5a29 | 2286 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
1f2e99fe LW |
2287 | struct snd_ctl_elem_value *ucontrol) |
2288 | { | |
2289 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2290 | struct via_spec *spec = codec->spec; | |
2291 | ||
2292 | if (spec->codec_type != VT1708) | |
2293 | return 0; | |
e06e5a29 | 2294 | spec->vt1708_jack_detect = |
1f2e99fe | 2295 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
e06e5a29 | 2296 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
1f2e99fe LW |
2297 | return 0; |
2298 | } | |
2299 | ||
e06e5a29 | 2300 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
1f2e99fe LW |
2301 | struct snd_ctl_elem_value *ucontrol) |
2302 | { | |
2303 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2304 | struct via_spec *spec = codec->spec; | |
2305 | int change; | |
2306 | ||
2307 | if (spec->codec_type != VT1708) | |
2308 | return 0; | |
e06e5a29 | 2309 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
1f2e99fe | 2310 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
e06e5a29 TI |
2311 | == !spec->vt1708_jack_detect; |
2312 | if (spec->vt1708_jack_detect) { | |
1f2e99fe LW |
2313 | mute_aa_path(codec, 1); |
2314 | notify_aa_path_ctls(codec); | |
2315 | } | |
2316 | return change; | |
2317 | } | |
2318 | ||
e06e5a29 TI |
2319 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
2320 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2321 | .name = "Jack Detect", | |
2322 | .count = 1, | |
2323 | .info = snd_ctl_boolean_mono_info, | |
2324 | .get = vt1708_jack_detect_get, | |
2325 | .put = vt1708_jack_detect_put, | |
1f2e99fe LW |
2326 | }; |
2327 | ||
c577b8a1 JC |
2328 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
2329 | { | |
2330 | struct via_spec *spec = codec->spec; | |
2331 | int err; | |
2332 | ||
76d9b0dd HW |
2333 | /* Add HP and CD pin config connect bit re-config action */ |
2334 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); | |
2335 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); | |
2336 | ||
c577b8a1 JC |
2337 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
2338 | if (err < 0) | |
2339 | return err; | |
4a79616d | 2340 | err = via_auto_fill_dac_nids(codec); |
c577b8a1 JC |
2341 | if (err < 0) |
2342 | return err; | |
2343 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 2344 | return -EINVAL; |
c577b8a1 | 2345 | |
4a79616d | 2346 | err = via_auto_create_multi_out_ctls(codec); |
c577b8a1 JC |
2347 | if (err < 0) |
2348 | return err; | |
4a79616d | 2349 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
c577b8a1 JC |
2350 | if (err < 0) |
2351 | return err; | |
620e2b28 | 2352 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
1f2e99fe LW |
2353 | if (err < 0) |
2354 | return err; | |
2355 | /* add jack detect on/off control */ | |
e06e5a29 TI |
2356 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
2357 | return -ENOMEM; | |
c577b8a1 JC |
2358 | |
2359 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2360 | ||
0852d7a6 | 2361 | if (spec->autocfg.dig_outs) |
c577b8a1 | 2362 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
55d1d6c1 | 2363 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
c577b8a1 JC |
2364 | if (spec->autocfg.dig_in_pin) |
2365 | spec->dig_in_nid = VT1708_DIGIN_NID; | |
2366 | ||
603c4019 TI |
2367 | if (spec->kctls.list) |
2368 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 2369 | |
69e52a80 | 2370 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
c577b8a1 | 2371 | |
0aa62aef HW |
2372 | spec->input_mux = &spec->private_imux[0]; |
2373 | ||
f8fdd495 | 2374 | if (spec->hp_mux) |
3d83e577 | 2375 | via_hp_build(codec); |
c577b8a1 | 2376 | |
f4a7828b TI |
2377 | err = via_smart51_build(codec); |
2378 | if (err < 0) | |
2379 | return err; | |
2380 | ||
c577b8a1 JC |
2381 | return 1; |
2382 | } | |
2383 | ||
2384 | /* init callback for auto-configuration model -- overriding the default init */ | |
2385 | static int via_auto_init(struct hda_codec *codec) | |
2386 | { | |
25eaba2f LW |
2387 | struct via_spec *spec = codec->spec; |
2388 | ||
c577b8a1 JC |
2389 | via_init(codec); |
2390 | via_auto_init_multi_out(codec); | |
2391 | via_auto_init_hp_out(codec); | |
2392 | via_auto_init_analog_input(codec); | |
11890956 LW |
2393 | |
2394 | if (VT2002P_COMPATIBLE(spec)) { | |
25eaba2f LW |
2395 | via_hp_bind_automute(codec); |
2396 | } else { | |
2397 | via_hp_automute(codec); | |
2398 | via_speaker_automute(codec); | |
2399 | } | |
2400 | ||
c577b8a1 JC |
2401 | return 0; |
2402 | } | |
2403 | ||
1f2e99fe LW |
2404 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
2405 | { | |
2406 | struct via_spec *spec = container_of(work, struct via_spec, | |
2407 | vt1708_hp_work.work); | |
2408 | if (spec->codec_type != VT1708) | |
2409 | return; | |
2410 | /* if jack state toggled */ | |
2411 | if (spec->vt1708_hp_present | |
d56757ab | 2412 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
1f2e99fe LW |
2413 | spec->vt1708_hp_present ^= 1; |
2414 | via_hp_automute(spec->codec); | |
2415 | } | |
2416 | vt1708_start_hp_work(spec); | |
2417 | } | |
2418 | ||
337b9d02 TI |
2419 | static int get_mux_nids(struct hda_codec *codec) |
2420 | { | |
2421 | struct via_spec *spec = codec->spec; | |
2422 | hda_nid_t nid, conn[8]; | |
2423 | unsigned int type; | |
2424 | int i, n; | |
2425 | ||
2426 | for (i = 0; i < spec->num_adc_nids; i++) { | |
2427 | nid = spec->adc_nids[i]; | |
2428 | while (nid) { | |
a22d543a | 2429 | type = get_wcaps_type(get_wcaps(codec, nid)); |
1c55d521 TI |
2430 | if (type == AC_WID_PIN) |
2431 | break; | |
337b9d02 TI |
2432 | n = snd_hda_get_connections(codec, nid, conn, |
2433 | ARRAY_SIZE(conn)); | |
2434 | if (n <= 0) | |
2435 | break; | |
2436 | if (n > 1) { | |
2437 | spec->mux_nids[i] = nid; | |
2438 | break; | |
2439 | } | |
2440 | nid = conn[0]; | |
2441 | } | |
2442 | } | |
1c55d521 | 2443 | return 0; |
337b9d02 TI |
2444 | } |
2445 | ||
c577b8a1 JC |
2446 | static int patch_vt1708(struct hda_codec *codec) |
2447 | { | |
2448 | struct via_spec *spec; | |
2449 | int err; | |
2450 | ||
2451 | /* create a codec specific record */ | |
5b0cb1d8 | 2452 | spec = via_new_spec(codec); |
c577b8a1 JC |
2453 | if (spec == NULL) |
2454 | return -ENOMEM; | |
2455 | ||
620e2b28 TI |
2456 | spec->aa_mix_nid = 0x17; |
2457 | ||
c577b8a1 JC |
2458 | /* automatic parse from the BIOS config */ |
2459 | err = vt1708_parse_auto_config(codec); | |
2460 | if (err < 0) { | |
2461 | via_free(codec); | |
2462 | return err; | |
c577b8a1 JC |
2463 | } |
2464 | ||
bc9b5623 TI |
2465 | /* disable 32bit format on VT1708 */ |
2466 | if (codec->vendor_id == 0x11061708) | |
2467 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; | |
c577b8a1 | 2468 | |
c577b8a1 JC |
2469 | codec->patch_ops = via_patch_ops; |
2470 | ||
2471 | codec->patch_ops.init = via_auto_init; | |
cb53c626 TI |
2472 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2473 | spec->loopback.amplist = vt1708_loopbacks; | |
2474 | #endif | |
1f2e99fe | 2475 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
c577b8a1 JC |
2476 | return 0; |
2477 | } | |
2478 | ||
90dd48a1 | 2479 | static const struct hda_verb vt1709_uniwill_init_verbs[] = { |
a34df19a LW |
2480 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
2481 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
69e52a80 HW |
2482 | { } |
2483 | }; | |
2484 | ||
c577b8a1 JC |
2485 | /* |
2486 | * generic initialization of ADC, input mixers and output mixers | |
2487 | */ | |
90dd48a1 | 2488 | static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { |
c577b8a1 JC |
2489 | /* |
2490 | * Unmute ADC0-2 and set the default input to mic-in | |
2491 | */ | |
2492 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2493 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2494 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2495 | ||
2496 | ||
f7278fd0 | 2497 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
c577b8a1 JC |
2498 | * mixer widget |
2499 | */ | |
2500 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
f7278fd0 JC |
2501 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
2502 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2503 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2504 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2505 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
c577b8a1 JC |
2506 | |
2507 | /* | |
2508 | * Set up output selector (0x1a, 0x1b, 0x29) | |
2509 | */ | |
2510 | /* set vol=0 to output mixers */ | |
2511 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2512 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2513 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2514 | ||
2515 | /* | |
2516 | * Unmute PW3 and PW4 | |
2517 | */ | |
2518 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2519 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2520 | ||
bfdc675a LW |
2521 | /* Set input of PW4 as MW0 */ |
2522 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
2523 | /* PW9 Output enable */ |
2524 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2525 | { } | |
2526 | }; | |
2527 | ||
c577b8a1 JC |
2528 | static int vt1709_parse_auto_config(struct hda_codec *codec) |
2529 | { | |
2530 | struct via_spec *spec = codec->spec; | |
2531 | int err; | |
2532 | ||
2533 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
2534 | if (err < 0) | |
2535 | return err; | |
4a79616d | 2536 | err = via_auto_fill_dac_nids(codec); |
c577b8a1 JC |
2537 | if (err < 0) |
2538 | return err; | |
2539 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 2540 | return -EINVAL; |
c577b8a1 | 2541 | |
4a79616d | 2542 | err = via_auto_create_multi_out_ctls(codec); |
c577b8a1 JC |
2543 | if (err < 0) |
2544 | return err; | |
4a79616d | 2545 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
c577b8a1 JC |
2546 | if (err < 0) |
2547 | return err; | |
620e2b28 | 2548 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
c577b8a1 JC |
2549 | if (err < 0) |
2550 | return err; | |
2551 | ||
2552 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2553 | ||
0852d7a6 | 2554 | if (spec->autocfg.dig_outs) |
c577b8a1 | 2555 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
55d1d6c1 | 2556 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
c577b8a1 JC |
2557 | if (spec->autocfg.dig_in_pin) |
2558 | spec->dig_in_nid = VT1709_DIGIN_NID; | |
2559 | ||
603c4019 TI |
2560 | if (spec->kctls.list) |
2561 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 2562 | |
0aa62aef | 2563 | spec->input_mux = &spec->private_imux[0]; |
c577b8a1 | 2564 | |
f8fdd495 | 2565 | if (spec->hp_mux) |
3d83e577 | 2566 | via_hp_build(codec); |
f8fdd495 | 2567 | |
f4a7828b TI |
2568 | err = via_smart51_build(codec); |
2569 | if (err < 0) | |
2570 | return err; | |
2571 | ||
c577b8a1 JC |
2572 | return 1; |
2573 | } | |
2574 | ||
cb53c626 | 2575 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
90dd48a1 | 2576 | static const struct hda_amp_list vt1709_loopbacks[] = { |
cb53c626 TI |
2577 | { 0x18, HDA_INPUT, 1 }, |
2578 | { 0x18, HDA_INPUT, 2 }, | |
2579 | { 0x18, HDA_INPUT, 3 }, | |
2580 | { 0x18, HDA_INPUT, 4 }, | |
2581 | { } /* end */ | |
2582 | }; | |
2583 | #endif | |
2584 | ||
c577b8a1 JC |
2585 | static int patch_vt1709_10ch(struct hda_codec *codec) |
2586 | { | |
2587 | struct via_spec *spec; | |
2588 | int err; | |
2589 | ||
2590 | /* create a codec specific record */ | |
5b0cb1d8 | 2591 | spec = via_new_spec(codec); |
c577b8a1 JC |
2592 | if (spec == NULL) |
2593 | return -ENOMEM; | |
2594 | ||
620e2b28 TI |
2595 | spec->aa_mix_nid = 0x18; |
2596 | ||
c577b8a1 JC |
2597 | err = vt1709_parse_auto_config(codec); |
2598 | if (err < 0) { | |
2599 | via_free(codec); | |
2600 | return err; | |
c577b8a1 JC |
2601 | } |
2602 | ||
69e52a80 HW |
2603 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
2604 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; | |
c577b8a1 | 2605 | |
c577b8a1 JC |
2606 | codec->patch_ops = via_patch_ops; |
2607 | ||
2608 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2609 | codec->patch_ops.unsol_event = via_unsol_event; |
cb53c626 TI |
2610 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2611 | spec->loopback.amplist = vt1709_loopbacks; | |
2612 | #endif | |
c577b8a1 JC |
2613 | |
2614 | return 0; | |
2615 | } | |
2616 | /* | |
2617 | * generic initialization of ADC, input mixers and output mixers | |
2618 | */ | |
90dd48a1 | 2619 | static const struct hda_verb vt1709_6ch_volume_init_verbs[] = { |
c577b8a1 JC |
2620 | /* |
2621 | * Unmute ADC0-2 and set the default input to mic-in | |
2622 | */ | |
2623 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2624 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2625 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2626 | ||
2627 | ||
2628 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2629 | * mixer widget | |
2630 | */ | |
2631 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2632 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2633 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2634 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2635 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2636 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2637 | ||
2638 | /* | |
2639 | * Set up output selector (0x1a, 0x1b, 0x29) | |
2640 | */ | |
2641 | /* set vol=0 to output mixers */ | |
2642 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2643 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2644 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2645 | ||
2646 | /* | |
2647 | * Unmute PW3 and PW4 | |
2648 | */ | |
2649 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2650 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2651 | ||
2652 | /* Set input of PW4 as MW0 */ | |
2653 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
2654 | /* PW9 Output enable */ |
2655 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2656 | { } | |
2657 | }; | |
2658 | ||
2659 | static int patch_vt1709_6ch(struct hda_codec *codec) | |
2660 | { | |
2661 | struct via_spec *spec; | |
2662 | int err; | |
2663 | ||
2664 | /* create a codec specific record */ | |
5b0cb1d8 | 2665 | spec = via_new_spec(codec); |
c577b8a1 JC |
2666 | if (spec == NULL) |
2667 | return -ENOMEM; | |
2668 | ||
620e2b28 TI |
2669 | spec->aa_mix_nid = 0x18; |
2670 | ||
c577b8a1 JC |
2671 | err = vt1709_parse_auto_config(codec); |
2672 | if (err < 0) { | |
2673 | via_free(codec); | |
2674 | return err; | |
c577b8a1 JC |
2675 | } |
2676 | ||
69e52a80 HW |
2677 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
2678 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; | |
c577b8a1 | 2679 | |
c577b8a1 JC |
2680 | codec->patch_ops = via_patch_ops; |
2681 | ||
2682 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2683 | codec->patch_ops.unsol_event = via_unsol_event; |
cb53c626 TI |
2684 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2685 | spec->loopback.amplist = vt1709_loopbacks; | |
2686 | #endif | |
f7278fd0 JC |
2687 | return 0; |
2688 | } | |
2689 | ||
f7278fd0 JC |
2690 | /* |
2691 | * generic initialization of ADC, input mixers and output mixers | |
2692 | */ | |
90dd48a1 | 2693 | static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { |
f7278fd0 JC |
2694 | /* |
2695 | * Unmute ADC0-1 and set the default input to mic-in | |
2696 | */ | |
2697 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2698 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2699 | ||
2700 | ||
2701 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2702 | * mixer widget | |
2703 | */ | |
2704 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2705 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2706 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2707 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2708 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2709 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2710 | ||
2711 | /* | |
2712 | * Set up output mixers | |
2713 | */ | |
2714 | /* set vol=0 to output mixers */ | |
2715 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2716 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2717 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2718 | ||
2719 | /* Setup default input to PW4 */ | |
bfdc675a | 2720 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
f7278fd0 JC |
2721 | /* PW9 Output enable */ |
2722 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2723 | /* PW10 Input enable */ | |
2724 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, | |
2725 | { } | |
2726 | }; | |
2727 | ||
90dd48a1 | 2728 | static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { |
f7278fd0 JC |
2729 | /* |
2730 | * Unmute ADC0-1 and set the default input to mic-in | |
2731 | */ | |
2732 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2733 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2734 | ||
2735 | ||
2736 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2737 | * mixer widget | |
2738 | */ | |
2739 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2740 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2741 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2742 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2743 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2744 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2745 | ||
2746 | /* | |
2747 | * Set up output mixers | |
2748 | */ | |
2749 | /* set vol=0 to output mixers */ | |
2750 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2751 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2752 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2753 | ||
2754 | /* Setup default input of PW4 to MW0 */ | |
2755 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2756 | /* PW9 Output enable */ | |
2757 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2758 | /* PW10 Input enable */ | |
2759 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, | |
2760 | { } | |
2761 | }; | |
2762 | ||
90dd48a1 | 2763 | static const struct hda_verb vt1708B_uniwill_init_verbs[] = { |
a34df19a LW |
2764 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
2765 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
2766 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2767 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2768 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2769 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2770 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2771 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2772 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
69e52a80 HW |
2773 | { } |
2774 | }; | |
2775 | ||
f7278fd0 JC |
2776 | static int vt1708B_parse_auto_config(struct hda_codec *codec) |
2777 | { | |
2778 | struct via_spec *spec = codec->spec; | |
2779 | int err; | |
2780 | ||
2781 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
2782 | if (err < 0) | |
2783 | return err; | |
4a79616d | 2784 | err = via_auto_fill_dac_nids(codec); |
f7278fd0 JC |
2785 | if (err < 0) |
2786 | return err; | |
2787 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 2788 | return -EINVAL; |
f7278fd0 | 2789 | |
4a79616d | 2790 | err = via_auto_create_multi_out_ctls(codec); |
f7278fd0 JC |
2791 | if (err < 0) |
2792 | return err; | |
4a79616d | 2793 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
f7278fd0 JC |
2794 | if (err < 0) |
2795 | return err; | |
620e2b28 | 2796 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
f7278fd0 JC |
2797 | if (err < 0) |
2798 | return err; | |
2799 | ||
2800 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2801 | ||
0852d7a6 | 2802 | if (spec->autocfg.dig_outs) |
f7278fd0 | 2803 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
55d1d6c1 | 2804 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
f7278fd0 JC |
2805 | if (spec->autocfg.dig_in_pin) |
2806 | spec->dig_in_nid = VT1708B_DIGIN_NID; | |
2807 | ||
603c4019 TI |
2808 | if (spec->kctls.list) |
2809 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
f7278fd0 | 2810 | |
0aa62aef HW |
2811 | spec->input_mux = &spec->private_imux[0]; |
2812 | ||
f8fdd495 | 2813 | if (spec->hp_mux) |
3d83e577 | 2814 | via_hp_build(codec); |
f7278fd0 | 2815 | |
f4a7828b TI |
2816 | err = via_smart51_build(codec); |
2817 | if (err < 0) | |
2818 | return err; | |
2819 | ||
f7278fd0 JC |
2820 | return 1; |
2821 | } | |
2822 | ||
2823 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 2824 | static const struct hda_amp_list vt1708B_loopbacks[] = { |
f7278fd0 JC |
2825 | { 0x16, HDA_INPUT, 1 }, |
2826 | { 0x16, HDA_INPUT, 2 }, | |
2827 | { 0x16, HDA_INPUT, 3 }, | |
2828 | { 0x16, HDA_INPUT, 4 }, | |
2829 | { } /* end */ | |
2830 | }; | |
2831 | #endif | |
3e95b9ab LW |
2832 | |
2833 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) | |
2834 | { | |
2835 | struct via_spec *spec = codec->spec; | |
2836 | int imux_is_smixer; | |
2837 | unsigned int parm; | |
2838 | int is_8ch = 0; | |
bc92df7f LW |
2839 | if ((spec->codec_type != VT1708B_4CH) && |
2840 | (codec->vendor_id != 0x11064397)) | |
3e95b9ab LW |
2841 | is_8ch = 1; |
2842 | ||
2843 | /* SW0 (17h) = stereo mixer */ | |
2844 | imux_is_smixer = | |
2845 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) | |
2846 | == ((spec->codec_type == VT1708S) ? 5 : 0)); | |
2847 | /* inputs */ | |
2848 | /* PW 1/2/5 (1ah/1bh/1eh) */ | |
2849 | parm = AC_PWRST_D3; | |
2850 | set_pin_power_state(codec, 0x1a, &parm); | |
2851 | set_pin_power_state(codec, 0x1b, &parm); | |
2852 | set_pin_power_state(codec, 0x1e, &parm); | |
2853 | if (imux_is_smixer) | |
2854 | parm = AC_PWRST_D0; | |
2855 | /* SW0 (17h), AIW 0/1 (13h/14h) */ | |
2856 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); | |
2857 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); | |
2858 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); | |
2859 | ||
2860 | /* outputs */ | |
2861 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | |
2862 | parm = AC_PWRST_D3; | |
2863 | set_pin_power_state(codec, 0x19, &parm); | |
2864 | if (spec->smart51_enabled) | |
2865 | set_pin_power_state(codec, 0x1b, &parm); | |
2866 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); | |
2867 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
2868 | ||
2869 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ | |
2870 | if (is_8ch) { | |
2871 | parm = AC_PWRST_D3; | |
2872 | set_pin_power_state(codec, 0x22, &parm); | |
2873 | if (spec->smart51_enabled) | |
2874 | set_pin_power_state(codec, 0x1a, &parm); | |
2875 | snd_hda_codec_write(codec, 0x26, 0, | |
2876 | AC_VERB_SET_POWER_STATE, parm); | |
2877 | snd_hda_codec_write(codec, 0x24, 0, | |
2878 | AC_VERB_SET_POWER_STATE, parm); | |
bc92df7f LW |
2879 | } else if (codec->vendor_id == 0x11064397) { |
2880 | /* PW7(23h), SW2(27h), AOW2(25h) */ | |
2881 | parm = AC_PWRST_D3; | |
2882 | set_pin_power_state(codec, 0x23, &parm); | |
2883 | if (spec->smart51_enabled) | |
2884 | set_pin_power_state(codec, 0x1a, &parm); | |
2885 | snd_hda_codec_write(codec, 0x27, 0, | |
2886 | AC_VERB_SET_POWER_STATE, parm); | |
2887 | snd_hda_codec_write(codec, 0x25, 0, | |
2888 | AC_VERB_SET_POWER_STATE, parm); | |
3e95b9ab LW |
2889 | } |
2890 | ||
2891 | /* PW 3/4/7 (1ch/1dh/23h) */ | |
2892 | parm = AC_PWRST_D3; | |
2893 | /* force to D0 for internal Speaker */ | |
2894 | set_pin_power_state(codec, 0x1c, &parm); | |
2895 | set_pin_power_state(codec, 0x1d, &parm); | |
2896 | if (is_8ch) | |
2897 | set_pin_power_state(codec, 0x23, &parm); | |
2898 | ||
2899 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ | |
2900 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, | |
2901 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
2902 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
2903 | if (is_8ch) { | |
2904 | snd_hda_codec_write(codec, 0x25, 0, | |
2905 | AC_VERB_SET_POWER_STATE, parm); | |
2906 | snd_hda_codec_write(codec, 0x27, 0, | |
2907 | AC_VERB_SET_POWER_STATE, parm); | |
bc92df7f LW |
2908 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
2909 | snd_hda_codec_write(codec, 0x25, 0, | |
2910 | AC_VERB_SET_POWER_STATE, parm); | |
3e95b9ab LW |
2911 | } |
2912 | ||
518bf3ba | 2913 | static int patch_vt1708S(struct hda_codec *codec); |
f7278fd0 JC |
2914 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
2915 | { | |
2916 | struct via_spec *spec; | |
2917 | int err; | |
2918 | ||
518bf3ba LW |
2919 | if (get_codec_type(codec) == VT1708BCE) |
2920 | return patch_vt1708S(codec); | |
f7278fd0 | 2921 | /* create a codec specific record */ |
5b0cb1d8 | 2922 | spec = via_new_spec(codec); |
f7278fd0 JC |
2923 | if (spec == NULL) |
2924 | return -ENOMEM; | |
2925 | ||
620e2b28 TI |
2926 | spec->aa_mix_nid = 0x16; |
2927 | ||
f7278fd0 JC |
2928 | /* automatic parse from the BIOS config */ |
2929 | err = vt1708B_parse_auto_config(codec); | |
2930 | if (err < 0) { | |
2931 | via_free(codec); | |
2932 | return err; | |
f7278fd0 JC |
2933 | } |
2934 | ||
69e52a80 HW |
2935 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
2936 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; | |
f7278fd0 | 2937 | |
f7278fd0 JC |
2938 | codec->patch_ops = via_patch_ops; |
2939 | ||
2940 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2941 | codec->patch_ops.unsol_event = via_unsol_event; |
f7278fd0 JC |
2942 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2943 | spec->loopback.amplist = vt1708B_loopbacks; | |
2944 | #endif | |
2945 | ||
3e95b9ab LW |
2946 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
2947 | ||
f7278fd0 JC |
2948 | return 0; |
2949 | } | |
2950 | ||
2951 | static int patch_vt1708B_4ch(struct hda_codec *codec) | |
2952 | { | |
2953 | struct via_spec *spec; | |
2954 | int err; | |
2955 | ||
2956 | /* create a codec specific record */ | |
5b0cb1d8 | 2957 | spec = via_new_spec(codec); |
f7278fd0 JC |
2958 | if (spec == NULL) |
2959 | return -ENOMEM; | |
2960 | ||
f7278fd0 JC |
2961 | /* automatic parse from the BIOS config */ |
2962 | err = vt1708B_parse_auto_config(codec); | |
2963 | if (err < 0) { | |
2964 | via_free(codec); | |
2965 | return err; | |
f7278fd0 JC |
2966 | } |
2967 | ||
69e52a80 HW |
2968 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
2969 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; | |
f7278fd0 | 2970 | |
f7278fd0 JC |
2971 | codec->patch_ops = via_patch_ops; |
2972 | ||
2973 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2974 | codec->patch_ops.unsol_event = via_unsol_event; |
f7278fd0 JC |
2975 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2976 | spec->loopback.amplist = vt1708B_loopbacks; | |
2977 | #endif | |
c577b8a1 | 2978 | |
3e95b9ab LW |
2979 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
2980 | ||
c577b8a1 JC |
2981 | return 0; |
2982 | } | |
2983 | ||
d949cac1 HW |
2984 | /* Patch for VT1708S */ |
2985 | ||
90dd48a1 | 2986 | static const struct hda_verb vt1708S_volume_init_verbs[] = { |
d949cac1 HW |
2987 | /* Unmute ADC0-1 and set the default input to mic-in */ |
2988 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2989 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2990 | ||
2991 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the | |
2992 | * analog-loopback mixer widget */ | |
2993 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2994 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2995 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2996 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2997 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2998 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2999 | ||
3000 | /* Setup default input of PW4 to MW0 */ | |
3001 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
5691ec7f | 3002 | /* PW9, PW10 Output enable */ |
d949cac1 | 3003 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
5691ec7f | 3004 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
d7426329 HW |
3005 | /* Enable Mic Boost Volume backdoor */ |
3006 | {0x1, 0xf98, 0x1}, | |
bc7e7e5c LW |
3007 | /* don't bybass mixer */ |
3008 | {0x1, 0xf88, 0xc0}, | |
d949cac1 HW |
3009 | { } |
3010 | }; | |
3011 | ||
90dd48a1 | 3012 | static const struct hda_verb vt1708S_uniwill_init_verbs[] = { |
a34df19a LW |
3013 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3014 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3015 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3016 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3017 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3018 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3019 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3020 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3021 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
69e52a80 HW |
3022 | { } |
3023 | }; | |
3024 | ||
90dd48a1 | 3025 | static const struct hda_verb vt1705_uniwill_init_verbs[] = { |
bc92df7f LW |
3026 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3027 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3028 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3029 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3030 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3031 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3032 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3033 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3034 | { } | |
3035 | }; | |
3036 | ||
4a79616d TI |
3037 | /* fill out digital output widgets; one for master and one for slave outputs */ |
3038 | static void fill_dig_outs(struct hda_codec *codec) | |
d949cac1 | 3039 | { |
4a79616d | 3040 | struct via_spec *spec = codec->spec; |
d949cac1 | 3041 | int i; |
d949cac1 | 3042 | |
4a79616d TI |
3043 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
3044 | hda_nid_t nid; | |
3045 | int conn; | |
9da29271 TI |
3046 | |
3047 | nid = spec->autocfg.dig_out_pins[i]; | |
3048 | if (!nid) | |
3049 | continue; | |
3050 | conn = snd_hda_get_connections(codec, nid, &nid, 1); | |
3051 | if (conn < 1) | |
3052 | continue; | |
3053 | if (!spec->multiout.dig_out_nid) | |
3054 | spec->multiout.dig_out_nid = nid; | |
3055 | else { | |
3056 | spec->slave_dig_outs[0] = nid; | |
3057 | break; /* at most two dig outs */ | |
3058 | } | |
3059 | } | |
3060 | } | |
3061 | ||
d949cac1 HW |
3062 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
3063 | { | |
3064 | struct via_spec *spec = codec->spec; | |
3065 | int err; | |
d949cac1 | 3066 | |
9da29271 | 3067 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
d949cac1 HW |
3068 | if (err < 0) |
3069 | return err; | |
4a79616d | 3070 | err = via_auto_fill_dac_nids(codec); |
d949cac1 HW |
3071 | if (err < 0) |
3072 | return err; | |
3073 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 3074 | return -EINVAL; |
d949cac1 | 3075 | |
4a79616d | 3076 | err = via_auto_create_multi_out_ctls(codec); |
d949cac1 HW |
3077 | if (err < 0) |
3078 | return err; | |
4a79616d | 3079 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
d949cac1 HW |
3080 | if (err < 0) |
3081 | return err; | |
620e2b28 | 3082 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
d949cac1 HW |
3083 | if (err < 0) |
3084 | return err; | |
3085 | ||
3086 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3087 | ||
9da29271 | 3088 | fill_dig_outs(codec); |
98aa34c0 | 3089 | |
603c4019 TI |
3090 | if (spec->kctls.list) |
3091 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
d949cac1 | 3092 | |
0aa62aef HW |
3093 | spec->input_mux = &spec->private_imux[0]; |
3094 | ||
f8fdd495 | 3095 | if (spec->hp_mux) |
3d83e577 | 3096 | via_hp_build(codec); |
d949cac1 | 3097 | |
f4a7828b TI |
3098 | err = via_smart51_build(codec); |
3099 | if (err < 0) | |
3100 | return err; | |
3101 | ||
d949cac1 HW |
3102 | return 1; |
3103 | } | |
3104 | ||
3105 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 3106 | static const struct hda_amp_list vt1708S_loopbacks[] = { |
d949cac1 HW |
3107 | { 0x16, HDA_INPUT, 1 }, |
3108 | { 0x16, HDA_INPUT, 2 }, | |
3109 | { 0x16, HDA_INPUT, 3 }, | |
3110 | { 0x16, HDA_INPUT, 4 }, | |
3111 | { } /* end */ | |
3112 | }; | |
3113 | #endif | |
3114 | ||
6369bcfc LW |
3115 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
3116 | int offset, int num_steps, int step_size) | |
3117 | { | |
3118 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, | |
3119 | (offset << AC_AMPCAP_OFFSET_SHIFT) | | |
3120 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
3121 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
3122 | (0 << AC_AMPCAP_MUTE_SHIFT)); | |
3123 | } | |
3124 | ||
d949cac1 HW |
3125 | static int patch_vt1708S(struct hda_codec *codec) |
3126 | { | |
3127 | struct via_spec *spec; | |
3128 | int err; | |
3129 | ||
3130 | /* create a codec specific record */ | |
5b0cb1d8 | 3131 | spec = via_new_spec(codec); |
d949cac1 HW |
3132 | if (spec == NULL) |
3133 | return -ENOMEM; | |
3134 | ||
620e2b28 | 3135 | spec->aa_mix_nid = 0x16; |
d7a99cce TI |
3136 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
3137 | override_mic_boost(codec, 0x1e, 0, 3, 40); | |
620e2b28 | 3138 | |
d949cac1 HW |
3139 | /* automatic parse from the BIOS config */ |
3140 | err = vt1708S_parse_auto_config(codec); | |
3141 | if (err < 0) { | |
3142 | via_free(codec); | |
3143 | return err; | |
d949cac1 HW |
3144 | } |
3145 | ||
69e52a80 | 3146 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
bc92df7f LW |
3147 | if (codec->vendor_id == 0x11064397) |
3148 | spec->init_verbs[spec->num_iverbs++] = | |
3149 | vt1705_uniwill_init_verbs; | |
3150 | else | |
3151 | spec->init_verbs[spec->num_iverbs++] = | |
3152 | vt1708S_uniwill_init_verbs; | |
d949cac1 | 3153 | |
d949cac1 HW |
3154 | codec->patch_ops = via_patch_ops; |
3155 | ||
3156 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 3157 | codec->patch_ops.unsol_event = via_unsol_event; |
d949cac1 HW |
3158 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3159 | spec->loopback.amplist = vt1708S_loopbacks; | |
3160 | #endif | |
3161 | ||
518bf3ba LW |
3162 | /* correct names for VT1708BCE */ |
3163 | if (get_codec_type(codec) == VT1708BCE) { | |
3164 | kfree(codec->chip_name); | |
3165 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); | |
3166 | snprintf(codec->bus->card->mixername, | |
3167 | sizeof(codec->bus->card->mixername), | |
3168 | "%s %s", codec->vendor_name, codec->chip_name); | |
970f630f | 3169 | } |
bc92df7f LW |
3170 | /* correct names for VT1705 */ |
3171 | if (codec->vendor_id == 0x11064397) { | |
3172 | kfree(codec->chip_name); | |
3173 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); | |
3174 | snprintf(codec->bus->card->mixername, | |
3175 | sizeof(codec->bus->card->mixername), | |
3176 | "%s %s", codec->vendor_name, codec->chip_name); | |
3177 | } | |
3e95b9ab | 3178 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
d949cac1 HW |
3179 | return 0; |
3180 | } | |
3181 | ||
3182 | /* Patch for VT1702 */ | |
3183 | ||
90dd48a1 | 3184 | static const struct hda_verb vt1702_volume_init_verbs[] = { |
d949cac1 HW |
3185 | /* |
3186 | * Unmute ADC0-1 and set the default input to mic-in | |
3187 | */ | |
3188 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3189 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3190 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3191 | ||
3192 | ||
3193 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
3194 | * mixer widget | |
3195 | */ | |
3196 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ | |
3197 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3198 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3199 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
3200 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
3201 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
3202 | ||
3203 | /* Setup default input of PW4 to MW0 */ | |
3204 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
3205 | /* PW6 PW7 Output enable */ | |
3206 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
3207 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
bc7e7e5c LW |
3208 | /* mixer enable */ |
3209 | {0x1, 0xF88, 0x3}, | |
3210 | /* GPIO 0~2 */ | |
3211 | {0x1, 0xF82, 0x3F}, | |
d949cac1 HW |
3212 | { } |
3213 | }; | |
3214 | ||
90dd48a1 | 3215 | static const struct hda_verb vt1702_uniwill_init_verbs[] = { |
a34df19a LW |
3216 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
3217 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3218 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3219 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3220 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3221 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
69e52a80 HW |
3222 | { } |
3223 | }; | |
3224 | ||
d949cac1 HW |
3225 | static int vt1702_parse_auto_config(struct hda_codec *codec) |
3226 | { | |
3227 | struct via_spec *spec = codec->spec; | |
3228 | int err; | |
d949cac1 | 3229 | |
9da29271 | 3230 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
d949cac1 HW |
3231 | if (err < 0) |
3232 | return err; | |
4a79616d | 3233 | err = via_auto_fill_dac_nids(codec); |
d949cac1 HW |
3234 | if (err < 0) |
3235 | return err; | |
3236 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 3237 | return -EINVAL; |
d949cac1 | 3238 | |
4a79616d | 3239 | err = via_auto_create_multi_out_ctls(codec); |
d949cac1 HW |
3240 | if (err < 0) |
3241 | return err; | |
4a79616d | 3242 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
d949cac1 HW |
3243 | if (err < 0) |
3244 | return err; | |
c2c02ea3 LW |
3245 | /* limit AA path volume to 0 dB */ |
3246 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, | |
3247 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | | |
3248 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
3249 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
3250 | (1 << AC_AMPCAP_MUTE_SHIFT)); | |
620e2b28 | 3251 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
d949cac1 HW |
3252 | if (err < 0) |
3253 | return err; | |
3254 | ||
3255 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3256 | ||
9da29271 | 3257 | fill_dig_outs(codec); |
98aa34c0 | 3258 | |
603c4019 TI |
3259 | if (spec->kctls.list) |
3260 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
d949cac1 | 3261 | |
0aa62aef HW |
3262 | spec->input_mux = &spec->private_imux[0]; |
3263 | ||
f8fdd495 | 3264 | if (spec->hp_mux) |
3d83e577 | 3265 | via_hp_build(codec); |
d949cac1 HW |
3266 | |
3267 | return 1; | |
3268 | } | |
3269 | ||
3270 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 3271 | static const struct hda_amp_list vt1702_loopbacks[] = { |
d949cac1 HW |
3272 | { 0x1A, HDA_INPUT, 1 }, |
3273 | { 0x1A, HDA_INPUT, 2 }, | |
3274 | { 0x1A, HDA_INPUT, 3 }, | |
3275 | { 0x1A, HDA_INPUT, 4 }, | |
3276 | { } /* end */ | |
3277 | }; | |
3278 | #endif | |
3279 | ||
3e95b9ab LW |
3280 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
3281 | { | |
3282 | int imux_is_smixer = | |
3283 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
3284 | unsigned int parm; | |
3285 | /* inputs */ | |
3286 | /* PW 1/2/5 (14h/15h/18h) */ | |
3287 | parm = AC_PWRST_D3; | |
3288 | set_pin_power_state(codec, 0x14, &parm); | |
3289 | set_pin_power_state(codec, 0x15, &parm); | |
3290 | set_pin_power_state(codec, 0x18, &parm); | |
3291 | if (imux_is_smixer) | |
3292 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ | |
3293 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ | |
3294 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); | |
3295 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); | |
3296 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
3297 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); | |
3298 | ||
3299 | /* outputs */ | |
3300 | /* PW 3/4 (16h/17h) */ | |
3301 | parm = AC_PWRST_D3; | |
3302 | set_pin_power_state(codec, 0x17, &parm); | |
3303 | set_pin_power_state(codec, 0x16, &parm); | |
3304 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ | |
3305 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, | |
3306 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
3307 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
3308 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); | |
3309 | } | |
3310 | ||
d949cac1 HW |
3311 | static int patch_vt1702(struct hda_codec *codec) |
3312 | { | |
3313 | struct via_spec *spec; | |
3314 | int err; | |
d949cac1 HW |
3315 | |
3316 | /* create a codec specific record */ | |
5b0cb1d8 | 3317 | spec = via_new_spec(codec); |
d949cac1 HW |
3318 | if (spec == NULL) |
3319 | return -ENOMEM; | |
3320 | ||
620e2b28 TI |
3321 | spec->aa_mix_nid = 0x1a; |
3322 | ||
d949cac1 HW |
3323 | /* automatic parse from the BIOS config */ |
3324 | err = vt1702_parse_auto_config(codec); | |
3325 | if (err < 0) { | |
3326 | via_free(codec); | |
3327 | return err; | |
d949cac1 HW |
3328 | } |
3329 | ||
69e52a80 HW |
3330 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
3331 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; | |
d949cac1 | 3332 | |
d949cac1 HW |
3333 | codec->patch_ops = via_patch_ops; |
3334 | ||
3335 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 3336 | codec->patch_ops.unsol_event = via_unsol_event; |
d949cac1 HW |
3337 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3338 | spec->loopback.amplist = vt1702_loopbacks; | |
3339 | #endif | |
3340 | ||
3e95b9ab | 3341 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
d949cac1 HW |
3342 | return 0; |
3343 | } | |
3344 | ||
eb7188ca LW |
3345 | /* Patch for VT1718S */ |
3346 | ||
90dd48a1 | 3347 | static const struct hda_verb vt1718S_volume_init_verbs[] = { |
eb7188ca LW |
3348 | /* |
3349 | * Unmute ADC0-1 and set the default input to mic-in | |
3350 | */ | |
3351 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3352 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3353 | ||
4ab2d53a LW |
3354 | /* Enable MW0 adjust Gain 5 */ |
3355 | {0x1, 0xfb2, 0x10}, | |
eb7188ca LW |
3356 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
3357 | * mixer widget | |
3358 | */ | |
3359 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
3360 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
3361 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3362 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
3363 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
4ab2d53a | 3364 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, |
eb7188ca LW |
3365 | |
3366 | /* Setup default input of Front HP to MW9 */ | |
3367 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
3368 | /* PW9 PW10 Output enable */ | |
3369 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
3370 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
3371 | /* PW11 Input enable */ | |
3372 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, | |
3373 | /* Enable Boost Volume backdoor */ | |
3374 | {0x1, 0xf88, 0x8}, | |
3375 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ | |
3376 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3377 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3378 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3379 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3380 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3381 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3382 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3383 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3384 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3385 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3386 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ | |
3387 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, | |
3388 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
3389 | /* Unmute MW4's index 0 */ | |
3390 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3391 | { } | |
3392 | }; | |
3393 | ||
3394 | ||
90dd48a1 | 3395 | static const struct hda_verb vt1718S_uniwill_init_verbs[] = { |
eb7188ca LW |
3396 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
3397 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3398 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3399 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3400 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3401 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3402 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3403 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3404 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3405 | { } | |
3406 | }; | |
3407 | ||
eb7188ca LW |
3408 | static int vt1718S_parse_auto_config(struct hda_codec *codec) |
3409 | { | |
3410 | struct via_spec *spec = codec->spec; | |
3411 | int err; | |
3412 | ||
3413 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
3414 | ||
3415 | if (err < 0) | |
3416 | return err; | |
4a79616d | 3417 | err = via_auto_fill_dac_nids(codec); |
eb7188ca LW |
3418 | if (err < 0) |
3419 | return err; | |
3420 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 3421 | return -EINVAL; |
eb7188ca | 3422 | |
4a79616d | 3423 | err = via_auto_create_multi_out_ctls(codec); |
eb7188ca LW |
3424 | if (err < 0) |
3425 | return err; | |
4a79616d | 3426 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
eb7188ca LW |
3427 | if (err < 0) |
3428 | return err; | |
620e2b28 | 3429 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
eb7188ca LW |
3430 | if (err < 0) |
3431 | return err; | |
3432 | ||
3433 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3434 | ||
3435 | fill_dig_outs(codec); | |
3436 | ||
3437 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) | |
3438 | spec->dig_in_nid = 0x13; | |
3439 | ||
3440 | if (spec->kctls.list) | |
3441 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
3442 | ||
3443 | spec->input_mux = &spec->private_imux[0]; | |
3444 | ||
3445 | if (spec->hp_mux) | |
3d83e577 | 3446 | via_hp_build(codec); |
eb7188ca | 3447 | |
f4a7828b TI |
3448 | err = via_smart51_build(codec); |
3449 | if (err < 0) | |
3450 | return err; | |
eb7188ca LW |
3451 | |
3452 | return 1; | |
3453 | } | |
3454 | ||
3455 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 3456 | static const struct hda_amp_list vt1718S_loopbacks[] = { |
eb7188ca LW |
3457 | { 0x21, HDA_INPUT, 1 }, |
3458 | { 0x21, HDA_INPUT, 2 }, | |
3459 | { 0x21, HDA_INPUT, 3 }, | |
3460 | { 0x21, HDA_INPUT, 4 }, | |
3461 | { } /* end */ | |
3462 | }; | |
3463 | #endif | |
3464 | ||
3e95b9ab LW |
3465 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
3466 | { | |
3467 | struct via_spec *spec = codec->spec; | |
3468 | int imux_is_smixer; | |
3469 | unsigned int parm; | |
3470 | /* MUX6 (1eh) = stereo mixer */ | |
3471 | imux_is_smixer = | |
3472 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | |
3473 | /* inputs */ | |
3474 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
3475 | parm = AC_PWRST_D3; | |
3476 | set_pin_power_state(codec, 0x29, &parm); | |
3477 | set_pin_power_state(codec, 0x2a, &parm); | |
3478 | set_pin_power_state(codec, 0x2b, &parm); | |
3479 | if (imux_is_smixer) | |
3480 | parm = AC_PWRST_D0; | |
3481 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
3482 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); | |
3483 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
3484 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
3485 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
3486 | ||
3487 | /* outputs */ | |
3488 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ | |
3489 | parm = AC_PWRST_D3; | |
3490 | set_pin_power_state(codec, 0x27, &parm); | |
3491 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); | |
3492 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); | |
3493 | ||
3494 | /* PW2 (26h), AOW2 (ah) */ | |
3495 | parm = AC_PWRST_D3; | |
3496 | set_pin_power_state(codec, 0x26, &parm); | |
3497 | if (spec->smart51_enabled) | |
3498 | set_pin_power_state(codec, 0x2b, &parm); | |
3499 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); | |
3500 | ||
3501 | /* PW0 (24h), AOW0 (8h) */ | |
3502 | parm = AC_PWRST_D3; | |
3503 | set_pin_power_state(codec, 0x24, &parm); | |
3504 | if (!spec->hp_independent_mode) /* check for redirected HP */ | |
3505 | set_pin_power_state(codec, 0x28, &parm); | |
3506 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); | |
3507 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ | |
3508 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, | |
3509 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
3510 | ||
3511 | /* PW1 (25h), AOW1 (9h) */ | |
3512 | parm = AC_PWRST_D3; | |
3513 | set_pin_power_state(codec, 0x25, &parm); | |
3514 | if (spec->smart51_enabled) | |
3515 | set_pin_power_state(codec, 0x2a, &parm); | |
3516 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); | |
3517 | ||
3518 | if (spec->hp_independent_mode) { | |
3519 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ | |
3520 | parm = AC_PWRST_D3; | |
3521 | set_pin_power_state(codec, 0x28, &parm); | |
3522 | snd_hda_codec_write(codec, 0x1b, 0, | |
3523 | AC_VERB_SET_POWER_STATE, parm); | |
3524 | snd_hda_codec_write(codec, 0x34, 0, | |
3525 | AC_VERB_SET_POWER_STATE, parm); | |
3526 | snd_hda_codec_write(codec, 0xc, 0, | |
3527 | AC_VERB_SET_POWER_STATE, parm); | |
3528 | } | |
3529 | } | |
3530 | ||
eb7188ca LW |
3531 | static int patch_vt1718S(struct hda_codec *codec) |
3532 | { | |
3533 | struct via_spec *spec; | |
3534 | int err; | |
3535 | ||
3536 | /* create a codec specific record */ | |
5b0cb1d8 | 3537 | spec = via_new_spec(codec); |
eb7188ca LW |
3538 | if (spec == NULL) |
3539 | return -ENOMEM; | |
3540 | ||
620e2b28 | 3541 | spec->aa_mix_nid = 0x21; |
d7a99cce TI |
3542 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
3543 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
620e2b28 | 3544 | |
eb7188ca LW |
3545 | /* automatic parse from the BIOS config */ |
3546 | err = vt1718S_parse_auto_config(codec); | |
3547 | if (err < 0) { | |
3548 | via_free(codec); | |
3549 | return err; | |
eb7188ca LW |
3550 | } |
3551 | ||
3552 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; | |
3553 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; | |
3554 | ||
eb7188ca LW |
3555 | codec->patch_ops = via_patch_ops; |
3556 | ||
3557 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 3558 | codec->patch_ops.unsol_event = via_unsol_event; |
eb7188ca LW |
3559 | |
3560 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
3561 | spec->loopback.amplist = vt1718S_loopbacks; | |
3562 | #endif | |
3563 | ||
3e95b9ab LW |
3564 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
3565 | ||
eb7188ca LW |
3566 | return 0; |
3567 | } | |
f3db423d LW |
3568 | |
3569 | /* Patch for VT1716S */ | |
3570 | ||
3571 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, | |
3572 | struct snd_ctl_elem_info *uinfo) | |
3573 | { | |
3574 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
3575 | uinfo->count = 1; | |
3576 | uinfo->value.integer.min = 0; | |
3577 | uinfo->value.integer.max = 1; | |
3578 | return 0; | |
3579 | } | |
3580 | ||
3581 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, | |
3582 | struct snd_ctl_elem_value *ucontrol) | |
3583 | { | |
3584 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3585 | int index = 0; | |
3586 | ||
3587 | index = snd_hda_codec_read(codec, 0x26, 0, | |
3588 | AC_VERB_GET_CONNECT_SEL, 0); | |
3589 | if (index != -1) | |
3590 | *ucontrol->value.integer.value = index; | |
3591 | ||
3592 | return 0; | |
3593 | } | |
3594 | ||
3595 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, | |
3596 | struct snd_ctl_elem_value *ucontrol) | |
3597 | { | |
3598 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3599 | struct via_spec *spec = codec->spec; | |
3600 | int index = *ucontrol->value.integer.value; | |
3601 | ||
3602 | snd_hda_codec_write(codec, 0x26, 0, | |
3603 | AC_VERB_SET_CONNECT_SEL, index); | |
3604 | spec->dmic_enabled = index; | |
3e95b9ab | 3605 | set_widgets_power_state(codec); |
f3db423d LW |
3606 | return 1; |
3607 | } | |
3608 | ||
90dd48a1 | 3609 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
f3db423d LW |
3610 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
3611 | { | |
3612 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3613 | .name = "Digital Mic Capture Switch", | |
5b0cb1d8 | 3614 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
f3db423d LW |
3615 | .count = 1, |
3616 | .info = vt1716s_dmic_info, | |
3617 | .get = vt1716s_dmic_get, | |
3618 | .put = vt1716s_dmic_put, | |
3619 | }, | |
3620 | {} /* end */ | |
3621 | }; | |
3622 | ||
3623 | ||
3624 | /* mono-out mixer elements */ | |
90dd48a1 | 3625 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
f3db423d LW |
3626 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
3627 | { } /* end */ | |
3628 | }; | |
3629 | ||
90dd48a1 | 3630 | static const struct hda_verb vt1716S_volume_init_verbs[] = { |
f3db423d LW |
3631 | /* |
3632 | * Unmute ADC0-1 and set the default input to mic-in | |
3633 | */ | |
3634 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3635 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3636 | ||
3637 | ||
3638 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
3639 | * mixer widget | |
3640 | */ | |
3641 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
3642 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
3643 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3644 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
3645 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
3646 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
3647 | ||
3648 | /* MUX Indices: Stereo Mixer = 5 */ | |
3649 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, | |
3650 | ||
3651 | /* Setup default input of PW4 to MW0 */ | |
3652 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
3653 | ||
3654 | /* Setup default input of SW1 as MW0 */ | |
3655 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
3656 | ||
3657 | /* Setup default input of SW4 as AOW0 */ | |
3658 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
3659 | ||
3660 | /* PW9 PW10 Output enable */ | |
3661 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
3662 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
3663 | ||
3664 | /* Unmute SW1, PW12 */ | |
3665 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3666 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
3667 | /* PW12 Output enable */ | |
3668 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
3669 | /* Enable Boost Volume backdoor */ | |
3670 | {0x1, 0xf8a, 0x80}, | |
3671 | /* don't bybass mixer */ | |
3672 | {0x1, 0xf88, 0xc0}, | |
3673 | /* Enable mono output */ | |
3674 | {0x1, 0xf90, 0x08}, | |
3675 | { } | |
3676 | }; | |
3677 | ||
3678 | ||
90dd48a1 | 3679 | static const struct hda_verb vt1716S_uniwill_init_verbs[] = { |
f3db423d LW |
3680 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3681 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3682 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3683 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3684 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3685 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, | |
3686 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, | |
3687 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3688 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3689 | { } | |
3690 | }; | |
3691 | ||
f3db423d LW |
3692 | static int vt1716S_parse_auto_config(struct hda_codec *codec) |
3693 | { | |
3694 | struct via_spec *spec = codec->spec; | |
3695 | int err; | |
3696 | ||
3697 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
3698 | if (err < 0) | |
3699 | return err; | |
4a79616d | 3700 | err = via_auto_fill_dac_nids(codec); |
f3db423d LW |
3701 | if (err < 0) |
3702 | return err; | |
3703 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 3704 | return -EINVAL; |
f3db423d | 3705 | |
4a79616d | 3706 | err = via_auto_create_multi_out_ctls(codec); |
f3db423d LW |
3707 | if (err < 0) |
3708 | return err; | |
4a79616d | 3709 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
f3db423d LW |
3710 | if (err < 0) |
3711 | return err; | |
620e2b28 | 3712 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
f3db423d LW |
3713 | if (err < 0) |
3714 | return err; | |
3715 | ||
3716 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3717 | ||
3718 | fill_dig_outs(codec); | |
3719 | ||
3720 | if (spec->kctls.list) | |
3721 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
3722 | ||
3723 | spec->input_mux = &spec->private_imux[0]; | |
3724 | ||
3725 | if (spec->hp_mux) | |
3d83e577 | 3726 | via_hp_build(codec); |
f3db423d | 3727 | |
f4a7828b TI |
3728 | err = via_smart51_build(codec); |
3729 | if (err < 0) | |
3730 | return err; | |
f3db423d LW |
3731 | |
3732 | return 1; | |
3733 | } | |
3734 | ||
3735 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 3736 | static const struct hda_amp_list vt1716S_loopbacks[] = { |
f3db423d LW |
3737 | { 0x16, HDA_INPUT, 1 }, |
3738 | { 0x16, HDA_INPUT, 2 }, | |
3739 | { 0x16, HDA_INPUT, 3 }, | |
3740 | { 0x16, HDA_INPUT, 4 }, | |
3741 | { } /* end */ | |
3742 | }; | |
3743 | #endif | |
3744 | ||
3e95b9ab LW |
3745 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
3746 | { | |
3747 | struct via_spec *spec = codec->spec; | |
3748 | int imux_is_smixer; | |
3749 | unsigned int parm; | |
3750 | unsigned int mono_out, present; | |
3751 | /* SW0 (17h) = stereo mixer */ | |
3752 | imux_is_smixer = | |
3753 | (snd_hda_codec_read(codec, 0x17, 0, | |
3754 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); | |
3755 | /* inputs */ | |
3756 | /* PW 1/2/5 (1ah/1bh/1eh) */ | |
3757 | parm = AC_PWRST_D3; | |
3758 | set_pin_power_state(codec, 0x1a, &parm); | |
3759 | set_pin_power_state(codec, 0x1b, &parm); | |
3760 | set_pin_power_state(codec, 0x1e, &parm); | |
3761 | if (imux_is_smixer) | |
3762 | parm = AC_PWRST_D0; | |
3763 | /* SW0 (17h), AIW0(13h) */ | |
3764 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); | |
3765 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); | |
3766 | ||
3767 | parm = AC_PWRST_D3; | |
3768 | set_pin_power_state(codec, 0x1e, &parm); | |
3769 | /* PW11 (22h) */ | |
3770 | if (spec->dmic_enabled) | |
3771 | set_pin_power_state(codec, 0x22, &parm); | |
3772 | else | |
3773 | snd_hda_codec_write(codec, 0x22, 0, | |
3774 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
3775 | ||
3776 | /* SW2(26h), AIW1(14h) */ | |
3777 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); | |
3778 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); | |
3779 | ||
3780 | /* outputs */ | |
3781 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | |
3782 | parm = AC_PWRST_D3; | |
3783 | set_pin_power_state(codec, 0x19, &parm); | |
3784 | /* Smart 5.1 PW2(1bh) */ | |
3785 | if (spec->smart51_enabled) | |
3786 | set_pin_power_state(codec, 0x1b, &parm); | |
3787 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); | |
3788 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
3789 | ||
3790 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ | |
3791 | parm = AC_PWRST_D3; | |
3792 | set_pin_power_state(codec, 0x23, &parm); | |
3793 | /* Smart 5.1 PW1(1ah) */ | |
3794 | if (spec->smart51_enabled) | |
3795 | set_pin_power_state(codec, 0x1a, &parm); | |
3796 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); | |
3797 | ||
3798 | /* Smart 5.1 PW5(1eh) */ | |
3799 | if (spec->smart51_enabled) | |
3800 | set_pin_power_state(codec, 0x1e, &parm); | |
3801 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); | |
3802 | ||
3803 | /* Mono out */ | |
3804 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ | |
3805 | present = snd_hda_jack_detect(codec, 0x1c); | |
3806 | ||
3807 | if (present) | |
3808 | mono_out = 0; | |
3809 | else { | |
3810 | present = snd_hda_jack_detect(codec, 0x1d); | |
3811 | if (!spec->hp_independent_mode && present) | |
3812 | mono_out = 0; | |
3813 | else | |
3814 | mono_out = 1; | |
3815 | } | |
3816 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; | |
3817 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); | |
3818 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); | |
3819 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); | |
3820 | ||
3821 | /* PW 3/4 (1ch/1dh) */ | |
3822 | parm = AC_PWRST_D3; | |
3823 | set_pin_power_state(codec, 0x1c, &parm); | |
3824 | set_pin_power_state(codec, 0x1d, &parm); | |
3825 | /* HP Independent Mode, power on AOW3 */ | |
3826 | if (spec->hp_independent_mode) | |
3827 | snd_hda_codec_write(codec, 0x25, 0, | |
3828 | AC_VERB_SET_POWER_STATE, parm); | |
3829 | ||
3830 | /* force to D0 for internal Speaker */ | |
3831 | /* MW0 (16h), AOW0 (10h) */ | |
3832 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, | |
3833 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
3834 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, | |
3835 | mono_out ? AC_PWRST_D0 : parm); | |
3836 | } | |
3837 | ||
f3db423d LW |
3838 | static int patch_vt1716S(struct hda_codec *codec) |
3839 | { | |
3840 | struct via_spec *spec; | |
3841 | int err; | |
3842 | ||
3843 | /* create a codec specific record */ | |
5b0cb1d8 | 3844 | spec = via_new_spec(codec); |
f3db423d LW |
3845 | if (spec == NULL) |
3846 | return -ENOMEM; | |
3847 | ||
620e2b28 | 3848 | spec->aa_mix_nid = 0x16; |
d7a99cce TI |
3849 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
3850 | override_mic_boost(codec, 0x1e, 0, 3, 40); | |
620e2b28 | 3851 | |
f3db423d LW |
3852 | /* automatic parse from the BIOS config */ |
3853 | err = vt1716S_parse_auto_config(codec); | |
3854 | if (err < 0) { | |
3855 | via_free(codec); | |
3856 | return err; | |
f3db423d LW |
3857 | } |
3858 | ||
3859 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; | |
3860 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; | |
3861 | ||
f3db423d LW |
3862 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
3863 | spec->num_mixers++; | |
3864 | ||
3865 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; | |
3866 | ||
3867 | codec->patch_ops = via_patch_ops; | |
3868 | ||
3869 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 3870 | codec->patch_ops.unsol_event = via_unsol_event; |
f3db423d LW |
3871 | |
3872 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
3873 | spec->loopback.amplist = vt1716S_loopbacks; | |
3874 | #endif | |
3875 | ||
3e95b9ab | 3876 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
f3db423d LW |
3877 | return 0; |
3878 | } | |
25eaba2f LW |
3879 | |
3880 | /* for vt2002P */ | |
3881 | ||
90dd48a1 | 3882 | static const struct hda_verb vt2002P_volume_init_verbs[] = { |
eadb9a80 LW |
3883 | /* Class-D speaker related verbs */ |
3884 | {0x1, 0xfe0, 0x4}, | |
3885 | {0x1, 0xfe9, 0x80}, | |
3886 | {0x1, 0xfe2, 0x22}, | |
25eaba2f LW |
3887 | /* |
3888 | * Unmute ADC0-1 and set the default input to mic-in | |
3889 | */ | |
3890 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3891 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3892 | ||
3893 | ||
3894 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
3895 | * mixer widget | |
3896 | */ | |
3897 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
3898 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
3899 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3900 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
3901 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
3902 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
3903 | ||
3904 | /* MUX Indices: Mic = 0 */ | |
3905 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | |
3906 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | |
3907 | ||
3908 | /* PW9 Output enable */ | |
3909 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
3910 | ||
3911 | /* Enable Boost Volume backdoor */ | |
3912 | {0x1, 0xfb9, 0x24}, | |
3913 | ||
3914 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | |
3915 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3916 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3917 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3918 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3919 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3920 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3921 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3922 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3923 | ||
3924 | /* set MUX0/1/4/8 = 0 (AOW0) */ | |
3925 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | |
3926 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | |
3927 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, | |
3928 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, | |
3929 | ||
3930 | /* set PW0 index=0 (MW0) */ | |
3931 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, | |
3932 | ||
3933 | /* Enable AOW0 to MW9 */ | |
3934 | {0x1, 0xfb8, 0x88}, | |
3935 | { } | |
3936 | }; | |
90dd48a1 | 3937 | static const struct hda_verb vt1802_volume_init_verbs[] = { |
11890956 LW |
3938 | /* |
3939 | * Unmute ADC0-1 and set the default input to mic-in | |
3940 | */ | |
3941 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3942 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3943 | ||
3944 | ||
3945 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
3946 | * mixer widget | |
3947 | */ | |
3948 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
3949 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
3950 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
3951 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
3952 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
3953 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
3954 | ||
3955 | /* MUX Indices: Mic = 0 */ | |
3956 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | |
3957 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | |
3958 | ||
3959 | /* PW9 Output enable */ | |
3960 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
3961 | ||
3962 | /* Enable Boost Volume backdoor */ | |
3963 | {0x1, 0xfb9, 0x24}, | |
3964 | ||
3965 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | |
3966 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3967 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3968 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3969 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3970 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3971 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3972 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3973 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3974 | ||
3975 | /* set MUX0/1/4/8 = 0 (AOW0) */ | |
3976 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | |
3977 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | |
3978 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, | |
3979 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, | |
3980 | ||
3981 | /* set PW0 index=0 (MW0) */ | |
3982 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, | |
3983 | ||
3984 | /* Enable AOW0 to MW9 */ | |
3985 | {0x1, 0xfb8, 0x88}, | |
3986 | { } | |
3987 | }; | |
25eaba2f LW |
3988 | |
3989 | ||
90dd48a1 | 3990 | static const struct hda_verb vt2002P_uniwill_init_verbs[] = { |
25eaba2f LW |
3991 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
3992 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
3993 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, | |
3994 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
3995 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3996 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3997 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3998 | { } | |
3999 | }; | |
90dd48a1 | 4000 | static const struct hda_verb vt1802_uniwill_init_verbs[] = { |
11890956 LW |
4001 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
4002 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
4003 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, | |
4004 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
4005 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4006 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4007 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4008 | { } | |
4009 | }; | |
25eaba2f | 4010 | |
25eaba2f LW |
4011 | static int vt2002P_parse_auto_config(struct hda_codec *codec) |
4012 | { | |
4013 | struct via_spec *spec = codec->spec; | |
4014 | int err; | |
4015 | ||
4016 | ||
4017 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
4018 | if (err < 0) | |
4019 | return err; | |
4020 | ||
4a79616d | 4021 | err = via_auto_fill_dac_nids(codec); |
25eaba2f LW |
4022 | if (err < 0) |
4023 | return err; | |
4024 | ||
4025 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 4026 | return -EINVAL; |
25eaba2f | 4027 | |
4a79616d | 4028 | err = via_auto_create_multi_out_ctls(codec); |
25eaba2f LW |
4029 | if (err < 0) |
4030 | return err; | |
4a79616d | 4031 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
25eaba2f LW |
4032 | if (err < 0) |
4033 | return err; | |
620e2b28 | 4034 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
25eaba2f LW |
4035 | if (err < 0) |
4036 | return err; | |
4037 | ||
4038 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
4039 | ||
4040 | fill_dig_outs(codec); | |
4041 | ||
4042 | if (spec->kctls.list) | |
4043 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
4044 | ||
4045 | spec->input_mux = &spec->private_imux[0]; | |
4046 | ||
4047 | if (spec->hp_mux) | |
3d83e577 | 4048 | via_hp_build(codec); |
25eaba2f LW |
4049 | |
4050 | return 1; | |
4051 | } | |
4052 | ||
4053 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 4054 | static const struct hda_amp_list vt2002P_loopbacks[] = { |
25eaba2f LW |
4055 | { 0x21, HDA_INPUT, 0 }, |
4056 | { 0x21, HDA_INPUT, 1 }, | |
4057 | { 0x21, HDA_INPUT, 2 }, | |
4058 | { } /* end */ | |
4059 | }; | |
4060 | #endif | |
4061 | ||
3e95b9ab LW |
4062 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
4063 | { | |
4064 | struct via_spec *spec = codec->spec; | |
4065 | int imux_is_smixer; | |
4066 | unsigned int parm; | |
4067 | unsigned int present; | |
4068 | /* MUX9 (1eh) = stereo mixer */ | |
4069 | imux_is_smixer = | |
4070 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
4071 | /* inputs */ | |
4072 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
4073 | parm = AC_PWRST_D3; | |
4074 | set_pin_power_state(codec, 0x29, &parm); | |
4075 | set_pin_power_state(codec, 0x2a, &parm); | |
4076 | set_pin_power_state(codec, 0x2b, &parm); | |
4077 | parm = AC_PWRST_D0; | |
4078 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
4079 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); | |
4080 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
4081 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
4082 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
4083 | ||
4084 | /* outputs */ | |
4085 | /* AOW0 (8h)*/ | |
4086 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); | |
4087 | ||
11890956 LW |
4088 | if (spec->codec_type == VT1802) { |
4089 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | |
4090 | parm = AC_PWRST_D3; | |
4091 | set_pin_power_state(codec, 0x28, &parm); | |
4092 | snd_hda_codec_write(codec, 0x18, 0, | |
4093 | AC_VERB_SET_POWER_STATE, parm); | |
4094 | snd_hda_codec_write(codec, 0x38, 0, | |
4095 | AC_VERB_SET_POWER_STATE, parm); | |
4096 | } else { | |
4097 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ | |
4098 | parm = AC_PWRST_D3; | |
4099 | set_pin_power_state(codec, 0x26, &parm); | |
4100 | snd_hda_codec_write(codec, 0x1c, 0, | |
4101 | AC_VERB_SET_POWER_STATE, parm); | |
4102 | snd_hda_codec_write(codec, 0x37, 0, | |
4103 | AC_VERB_SET_POWER_STATE, parm); | |
4104 | } | |
3e95b9ab | 4105 | |
11890956 LW |
4106 | if (spec->codec_type == VT1802) { |
4107 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | |
4108 | parm = AC_PWRST_D3; | |
4109 | set_pin_power_state(codec, 0x25, &parm); | |
4110 | snd_hda_codec_write(codec, 0x15, 0, | |
4111 | AC_VERB_SET_POWER_STATE, parm); | |
4112 | snd_hda_codec_write(codec, 0x35, 0, | |
4113 | AC_VERB_SET_POWER_STATE, parm); | |
4114 | } else { | |
4115 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ | |
4116 | parm = AC_PWRST_D3; | |
4117 | set_pin_power_state(codec, 0x25, &parm); | |
4118 | snd_hda_codec_write(codec, 0x19, 0, | |
4119 | AC_VERB_SET_POWER_STATE, parm); | |
4120 | snd_hda_codec_write(codec, 0x35, 0, | |
4121 | AC_VERB_SET_POWER_STATE, parm); | |
4122 | } | |
3e95b9ab LW |
4123 | |
4124 | if (spec->hp_independent_mode) | |
4125 | snd_hda_codec_write(codec, 0x9, 0, | |
4126 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4127 | ||
4128 | /* Class-D */ | |
4129 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ | |
4130 | present = snd_hda_jack_detect(codec, 0x25); | |
4131 | ||
4132 | parm = AC_PWRST_D3; | |
4133 | set_pin_power_state(codec, 0x24, &parm); | |
4134 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; | |
11890956 LW |
4135 | if (spec->codec_type == VT1802) |
4136 | snd_hda_codec_write(codec, 0x14, 0, | |
4137 | AC_VERB_SET_POWER_STATE, parm); | |
4138 | else | |
4139 | snd_hda_codec_write(codec, 0x18, 0, | |
4140 | AC_VERB_SET_POWER_STATE, parm); | |
3e95b9ab LW |
4141 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
4142 | ||
4143 | /* Mono Out */ | |
4144 | present = snd_hda_jack_detect(codec, 0x26); | |
4145 | ||
4146 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; | |
11890956 LW |
4147 | if (spec->codec_type == VT1802) { |
4148 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ | |
4149 | snd_hda_codec_write(codec, 0x33, 0, | |
4150 | AC_VERB_SET_POWER_STATE, parm); | |
4151 | snd_hda_codec_write(codec, 0x1c, 0, | |
4152 | AC_VERB_SET_POWER_STATE, parm); | |
4153 | snd_hda_codec_write(codec, 0x3c, 0, | |
4154 | AC_VERB_SET_POWER_STATE, parm); | |
4155 | } else { | |
4156 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ | |
4157 | snd_hda_codec_write(codec, 0x31, 0, | |
4158 | AC_VERB_SET_POWER_STATE, parm); | |
4159 | snd_hda_codec_write(codec, 0x17, 0, | |
4160 | AC_VERB_SET_POWER_STATE, parm); | |
4161 | snd_hda_codec_write(codec, 0x3b, 0, | |
4162 | AC_VERB_SET_POWER_STATE, parm); | |
4163 | } | |
3e95b9ab LW |
4164 | /* MW9 (21h) */ |
4165 | if (imux_is_smixer || !is_aa_path_mute(codec)) | |
4166 | snd_hda_codec_write(codec, 0x21, 0, | |
4167 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4168 | else | |
4169 | snd_hda_codec_write(codec, 0x21, 0, | |
4170 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
4171 | } | |
25eaba2f LW |
4172 | |
4173 | /* patch for vt2002P */ | |
4174 | static int patch_vt2002P(struct hda_codec *codec) | |
4175 | { | |
4176 | struct via_spec *spec; | |
4177 | int err; | |
4178 | ||
4179 | /* create a codec specific record */ | |
5b0cb1d8 | 4180 | spec = via_new_spec(codec); |
25eaba2f LW |
4181 | if (spec == NULL) |
4182 | return -ENOMEM; | |
4183 | ||
620e2b28 | 4184 | spec->aa_mix_nid = 0x21; |
d7a99cce TI |
4185 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
4186 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
620e2b28 | 4187 | |
25eaba2f LW |
4188 | /* automatic parse from the BIOS config */ |
4189 | err = vt2002P_parse_auto_config(codec); | |
4190 | if (err < 0) { | |
4191 | via_free(codec); | |
4192 | return err; | |
25eaba2f LW |
4193 | } |
4194 | ||
11890956 LW |
4195 | if (spec->codec_type == VT1802) |
4196 | spec->init_verbs[spec->num_iverbs++] = | |
4197 | vt1802_volume_init_verbs; | |
4198 | else | |
4199 | spec->init_verbs[spec->num_iverbs++] = | |
4200 | vt2002P_volume_init_verbs; | |
25eaba2f | 4201 | |
11890956 LW |
4202 | if (spec->codec_type == VT1802) |
4203 | spec->init_verbs[spec->num_iverbs++] = | |
4204 | vt1802_uniwill_init_verbs; | |
4205 | else | |
4206 | spec->init_verbs[spec->num_iverbs++] = | |
4207 | vt2002P_uniwill_init_verbs; | |
4208 | ||
25eaba2f LW |
4209 | codec->patch_ops = via_patch_ops; |
4210 | ||
4211 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 4212 | codec->patch_ops.unsol_event = via_unsol_event; |
25eaba2f LW |
4213 | |
4214 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4215 | spec->loopback.amplist = vt2002P_loopbacks; | |
4216 | #endif | |
4217 | ||
3e95b9ab | 4218 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
25eaba2f LW |
4219 | return 0; |
4220 | } | |
ab6734e7 LW |
4221 | |
4222 | /* for vt1812 */ | |
4223 | ||
90dd48a1 | 4224 | static const struct hda_verb vt1812_volume_init_verbs[] = { |
ab6734e7 LW |
4225 | /* |
4226 | * Unmute ADC0-1 and set the default input to mic-in | |
4227 | */ | |
4228 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4229 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4230 | ||
4231 | ||
4232 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
4233 | * mixer widget | |
4234 | */ | |
4235 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
4236 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
4237 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4238 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
4239 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
4240 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
4241 | ||
4242 | /* MUX Indices: Mic = 0 */ | |
4243 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | |
4244 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | |
4245 | ||
4246 | /* PW9 Output enable */ | |
4247 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
4248 | ||
4249 | /* Enable Boost Volume backdoor */ | |
4250 | {0x1, 0xfb9, 0x24}, | |
4251 | ||
4252 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | |
4253 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4254 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4255 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4256 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4257 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4258 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4259 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4260 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4261 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4262 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4263 | ||
4264 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ | |
4265 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | |
4266 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | |
4267 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, | |
4268 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, | |
4269 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, | |
4270 | ||
4271 | /* Enable AOW0 to MW9 */ | |
4272 | {0x1, 0xfb8, 0xa8}, | |
4273 | { } | |
4274 | }; | |
4275 | ||
4276 | ||
90dd48a1 | 4277 | static const struct hda_verb vt1812_uniwill_init_verbs[] = { |
ab6734e7 LW |
4278 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
4279 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
4280 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, | |
4281 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, | |
4282 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
4283 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4284 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4285 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4286 | { } | |
4287 | }; | |
4288 | ||
ab6734e7 LW |
4289 | static int vt1812_parse_auto_config(struct hda_codec *codec) |
4290 | { | |
4291 | struct via_spec *spec = codec->spec; | |
4292 | int err; | |
4293 | ||
4294 | ||
4295 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
4296 | if (err < 0) | |
4297 | return err; | |
4298 | fill_dig_outs(codec); | |
4a79616d | 4299 | err = via_auto_fill_dac_nids(codec); |
ab6734e7 LW |
4300 | if (err < 0) |
4301 | return err; | |
4302 | ||
4303 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) | |
7f0df88c | 4304 | return -EINVAL; |
ab6734e7 | 4305 | |
4a79616d | 4306 | err = via_auto_create_multi_out_ctls(codec); |
ab6734e7 LW |
4307 | if (err < 0) |
4308 | return err; | |
4a79616d | 4309 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
ab6734e7 LW |
4310 | if (err < 0) |
4311 | return err; | |
620e2b28 | 4312 | err = via_auto_create_analog_input_ctls(codec, &spec->autocfg); |
ab6734e7 LW |
4313 | if (err < 0) |
4314 | return err; | |
4315 | ||
4316 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
4317 | ||
4318 | fill_dig_outs(codec); | |
4319 | ||
4320 | if (spec->kctls.list) | |
4321 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
4322 | ||
4323 | spec->input_mux = &spec->private_imux[0]; | |
4324 | ||
4325 | if (spec->hp_mux) | |
3d83e577 | 4326 | via_hp_build(codec); |
ab6734e7 LW |
4327 | |
4328 | return 1; | |
4329 | } | |
4330 | ||
4331 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 4332 | static const struct hda_amp_list vt1812_loopbacks[] = { |
ab6734e7 LW |
4333 | { 0x21, HDA_INPUT, 0 }, |
4334 | { 0x21, HDA_INPUT, 1 }, | |
4335 | { 0x21, HDA_INPUT, 2 }, | |
4336 | { } /* end */ | |
4337 | }; | |
4338 | #endif | |
4339 | ||
3e95b9ab LW |
4340 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
4341 | { | |
4342 | struct via_spec *spec = codec->spec; | |
4343 | int imux_is_smixer = | |
4344 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
4345 | unsigned int parm; | |
4346 | unsigned int present; | |
4347 | /* MUX10 (1eh) = stereo mixer */ | |
4348 | imux_is_smixer = | |
4349 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | |
4350 | /* inputs */ | |
4351 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
4352 | parm = AC_PWRST_D3; | |
4353 | set_pin_power_state(codec, 0x29, &parm); | |
4354 | set_pin_power_state(codec, 0x2a, &parm); | |
4355 | set_pin_power_state(codec, 0x2b, &parm); | |
4356 | parm = AC_PWRST_D0; | |
4357 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
4358 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); | |
4359 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
4360 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
4361 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
4362 | ||
4363 | /* outputs */ | |
4364 | /* AOW0 (8h)*/ | |
4365 | snd_hda_codec_write(codec, 0x8, 0, | |
4366 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4367 | ||
4368 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | |
4369 | parm = AC_PWRST_D3; | |
4370 | set_pin_power_state(codec, 0x28, &parm); | |
4371 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); | |
4372 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); | |
4373 | ||
4374 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | |
4375 | parm = AC_PWRST_D3; | |
4376 | set_pin_power_state(codec, 0x25, &parm); | |
4377 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); | |
4378 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); | |
4379 | if (spec->hp_independent_mode) | |
4380 | snd_hda_codec_write(codec, 0x9, 0, | |
4381 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4382 | ||
4383 | /* Internal Speaker */ | |
4384 | /* PW0 (24h), MW0(14h), MUX0(34h) */ | |
4385 | present = snd_hda_jack_detect(codec, 0x25); | |
4386 | ||
4387 | parm = AC_PWRST_D3; | |
4388 | set_pin_power_state(codec, 0x24, &parm); | |
4389 | if (present) { | |
4390 | snd_hda_codec_write(codec, 0x14, 0, | |
4391 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
4392 | snd_hda_codec_write(codec, 0x34, 0, | |
4393 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
4394 | } else { | |
4395 | snd_hda_codec_write(codec, 0x14, 0, | |
4396 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4397 | snd_hda_codec_write(codec, 0x34, 0, | |
4398 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4399 | } | |
4400 | ||
4401 | ||
4402 | /* Mono Out */ | |
4403 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ | |
4404 | present = snd_hda_jack_detect(codec, 0x28); | |
4405 | ||
4406 | parm = AC_PWRST_D3; | |
4407 | set_pin_power_state(codec, 0x31, &parm); | |
4408 | if (present) { | |
4409 | snd_hda_codec_write(codec, 0x1c, 0, | |
4410 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
4411 | snd_hda_codec_write(codec, 0x3c, 0, | |
4412 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
4413 | snd_hda_codec_write(codec, 0x3e, 0, | |
4414 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
4415 | } else { | |
4416 | snd_hda_codec_write(codec, 0x1c, 0, | |
4417 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4418 | snd_hda_codec_write(codec, 0x3c, 0, | |
4419 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4420 | snd_hda_codec_write(codec, 0x3e, 0, | |
4421 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
4422 | } | |
4423 | ||
4424 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ | |
4425 | parm = AC_PWRST_D3; | |
4426 | set_pin_power_state(codec, 0x33, &parm); | |
4427 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); | |
4428 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); | |
4429 | ||
4430 | } | |
ab6734e7 LW |
4431 | |
4432 | /* patch for vt1812 */ | |
4433 | static int patch_vt1812(struct hda_codec *codec) | |
4434 | { | |
4435 | struct via_spec *spec; | |
4436 | int err; | |
4437 | ||
4438 | /* create a codec specific record */ | |
5b0cb1d8 | 4439 | spec = via_new_spec(codec); |
ab6734e7 LW |
4440 | if (spec == NULL) |
4441 | return -ENOMEM; | |
4442 | ||
620e2b28 | 4443 | spec->aa_mix_nid = 0x21; |
d7a99cce TI |
4444 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
4445 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
620e2b28 | 4446 | |
ab6734e7 LW |
4447 | /* automatic parse from the BIOS config */ |
4448 | err = vt1812_parse_auto_config(codec); | |
4449 | if (err < 0) { | |
4450 | via_free(codec); | |
4451 | return err; | |
ab6734e7 LW |
4452 | } |
4453 | ||
ab6734e7 LW |
4454 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; |
4455 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; | |
4456 | ||
ab6734e7 LW |
4457 | codec->patch_ops = via_patch_ops; |
4458 | ||
4459 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 4460 | codec->patch_ops.unsol_event = via_unsol_event; |
ab6734e7 LW |
4461 | |
4462 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4463 | spec->loopback.amplist = vt1812_loopbacks; | |
4464 | #endif | |
4465 | ||
3e95b9ab | 4466 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
ab6734e7 LW |
4467 | return 0; |
4468 | } | |
4469 | ||
c577b8a1 JC |
4470 | /* |
4471 | * patch entries | |
4472 | */ | |
90dd48a1 | 4473 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
3218c178 TI |
4474 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
4475 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, | |
4476 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, | |
4477 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, | |
4478 | { .id = 0x1106e710, .name = "VT1709 10-Ch", | |
f7278fd0 | 4479 | .patch = patch_vt1709_10ch}, |
3218c178 | 4480 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
f7278fd0 | 4481 | .patch = patch_vt1709_10ch}, |
3218c178 | 4482 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
f7278fd0 | 4483 | .patch = patch_vt1709_10ch}, |
3218c178 | 4484 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
f7278fd0 | 4485 | .patch = patch_vt1709_10ch}, |
3218c178 | 4486 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
f7278fd0 | 4487 | .patch = patch_vt1709_6ch}, |
3218c178 | 4488 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
f7278fd0 | 4489 | .patch = patch_vt1709_6ch}, |
3218c178 | 4490 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
f7278fd0 | 4491 | .patch = patch_vt1709_6ch}, |
3218c178 | 4492 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
f7278fd0 | 4493 | .patch = patch_vt1709_6ch}, |
3218c178 | 4494 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
f7278fd0 | 4495 | .patch = patch_vt1708B_8ch}, |
3218c178 | 4496 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
f7278fd0 | 4497 | .patch = patch_vt1708B_8ch}, |
3218c178 | 4498 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
f7278fd0 | 4499 | .patch = patch_vt1708B_8ch}, |
3218c178 | 4500 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
f7278fd0 | 4501 | .patch = patch_vt1708B_8ch}, |
3218c178 | 4502 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
f7278fd0 | 4503 | .patch = patch_vt1708B_4ch}, |
3218c178 | 4504 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
f7278fd0 | 4505 | .patch = patch_vt1708B_4ch}, |
3218c178 | 4506 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
f7278fd0 | 4507 | .patch = patch_vt1708B_4ch}, |
3218c178 | 4508 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
f7278fd0 | 4509 | .patch = patch_vt1708B_4ch}, |
3218c178 | 4510 | { .id = 0x11060397, .name = "VT1708S", |
d949cac1 | 4511 | .patch = patch_vt1708S}, |
3218c178 | 4512 | { .id = 0x11061397, .name = "VT1708S", |
d949cac1 | 4513 | .patch = patch_vt1708S}, |
3218c178 | 4514 | { .id = 0x11062397, .name = "VT1708S", |
d949cac1 | 4515 | .patch = patch_vt1708S}, |
3218c178 | 4516 | { .id = 0x11063397, .name = "VT1708S", |
d949cac1 | 4517 | .patch = patch_vt1708S}, |
bc92df7f | 4518 | { .id = 0x11064397, .name = "VT1705", |
d949cac1 | 4519 | .patch = patch_vt1708S}, |
3218c178 | 4520 | { .id = 0x11065397, .name = "VT1708S", |
d949cac1 | 4521 | .patch = patch_vt1708S}, |
3218c178 | 4522 | { .id = 0x11066397, .name = "VT1708S", |
d949cac1 | 4523 | .patch = patch_vt1708S}, |
3218c178 | 4524 | { .id = 0x11067397, .name = "VT1708S", |
d949cac1 | 4525 | .patch = patch_vt1708S}, |
3218c178 | 4526 | { .id = 0x11060398, .name = "VT1702", |
d949cac1 | 4527 | .patch = patch_vt1702}, |
3218c178 | 4528 | { .id = 0x11061398, .name = "VT1702", |
d949cac1 | 4529 | .patch = patch_vt1702}, |
3218c178 | 4530 | { .id = 0x11062398, .name = "VT1702", |
d949cac1 | 4531 | .patch = patch_vt1702}, |
3218c178 | 4532 | { .id = 0x11063398, .name = "VT1702", |
d949cac1 | 4533 | .patch = patch_vt1702}, |
3218c178 | 4534 | { .id = 0x11064398, .name = "VT1702", |
d949cac1 | 4535 | .patch = patch_vt1702}, |
3218c178 | 4536 | { .id = 0x11065398, .name = "VT1702", |
d949cac1 | 4537 | .patch = patch_vt1702}, |
3218c178 | 4538 | { .id = 0x11066398, .name = "VT1702", |
d949cac1 | 4539 | .patch = patch_vt1702}, |
3218c178 | 4540 | { .id = 0x11067398, .name = "VT1702", |
d949cac1 | 4541 | .patch = patch_vt1702}, |
eb7188ca LW |
4542 | { .id = 0x11060428, .name = "VT1718S", |
4543 | .patch = patch_vt1718S}, | |
4544 | { .id = 0x11064428, .name = "VT1718S", | |
4545 | .patch = patch_vt1718S}, | |
bb3c6bfc LW |
4546 | { .id = 0x11060441, .name = "VT2020", |
4547 | .patch = patch_vt1718S}, | |
4548 | { .id = 0x11064441, .name = "VT1828S", | |
4549 | .patch = patch_vt1718S}, | |
f3db423d LW |
4550 | { .id = 0x11060433, .name = "VT1716S", |
4551 | .patch = patch_vt1716S}, | |
4552 | { .id = 0x1106a721, .name = "VT1716S", | |
4553 | .patch = patch_vt1716S}, | |
25eaba2f LW |
4554 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
4555 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, | |
ab6734e7 | 4556 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
36dd5c4a LW |
4557 | { .id = 0x11060440, .name = "VT1818S", |
4558 | .patch = patch_vt1708S}, | |
11890956 LW |
4559 | { .id = 0x11060446, .name = "VT1802", |
4560 | .patch = patch_vt2002P}, | |
4561 | { .id = 0x11068446, .name = "VT1802", | |
4562 | .patch = patch_vt2002P}, | |
c577b8a1 JC |
4563 | {} /* terminator */ |
4564 | }; | |
1289e9e8 TI |
4565 | |
4566 | MODULE_ALIAS("snd-hda-codec-id:1106*"); | |
4567 | ||
4568 | static struct hda_codec_preset_list via_list = { | |
4569 | .preset = snd_hda_preset_via, | |
4570 | .owner = THIS_MODULE, | |
4571 | }; | |
4572 | ||
4573 | MODULE_LICENSE("GPL"); | |
4574 | MODULE_DESCRIPTION("VIA HD-audio codec"); | |
4575 | ||
4576 | static int __init patch_via_init(void) | |
4577 | { | |
4578 | return snd_hda_add_codec_preset(&via_list); | |
4579 | } | |
4580 | ||
4581 | static void __exit patch_via_exit(void) | |
4582 | { | |
4583 | snd_hda_delete_codec_preset(&via_list); | |
4584 | } | |
4585 | ||
4586 | module_init(patch_via_init) | |
4587 | module_exit(patch_via_exit) |