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 | ||
1f2e99fe LW |
110 | struct via_spec { |
111 | /* codec parameterization */ | |
90dd48a1 | 112 | const struct snd_kcontrol_new *mixers[6]; |
1f2e99fe LW |
113 | unsigned int num_mixers; |
114 | ||
90dd48a1 | 115 | const struct hda_verb *init_verbs[5]; |
1f2e99fe LW |
116 | unsigned int num_iverbs; |
117 | ||
118 | char *stream_name_analog; | |
90dd48a1 TI |
119 | const struct hda_pcm_stream *stream_analog_playback; |
120 | const struct hda_pcm_stream *stream_analog_capture; | |
1f2e99fe LW |
121 | |
122 | char *stream_name_digital; | |
90dd48a1 TI |
123 | const struct hda_pcm_stream *stream_digital_playback; |
124 | const struct hda_pcm_stream *stream_digital_capture; | |
1f2e99fe LW |
125 | |
126 | /* playback */ | |
127 | struct hda_multi_out multiout; | |
128 | hda_nid_t slave_dig_outs[2]; | |
129 | ||
130 | /* capture */ | |
131 | unsigned int num_adc_nids; | |
a766d0d7 | 132 | hda_nid_t adc_nids[3]; |
1f2e99fe LW |
133 | hda_nid_t mux_nids[3]; |
134 | hda_nid_t dig_in_nid; | |
135 | hda_nid_t dig_in_pin; | |
136 | ||
137 | /* capture source */ | |
138 | const struct hda_input_mux *input_mux; | |
139 | unsigned int cur_mux[3]; | |
140 | ||
141 | /* PCM information */ | |
142 | struct hda_pcm pcm_rec[3]; | |
143 | ||
144 | /* dynamic controls, init_verbs and input_mux */ | |
145 | struct auto_pin_cfg autocfg; | |
146 | struct snd_array kctls; | |
147 | struct hda_input_mux private_imux[2]; | |
148 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; | |
149 | ||
150 | /* HP mode source */ | |
151 | const struct hda_input_mux *hp_mux; | |
152 | unsigned int hp_independent_mode; | |
153 | unsigned int hp_independent_mode_index; | |
154 | unsigned int smart51_enabled; | |
f3db423d | 155 | unsigned int dmic_enabled; |
24088a58 | 156 | unsigned int no_pin_power_ctl; |
1f2e99fe LW |
157 | enum VIA_HDA_CODEC codec_type; |
158 | ||
159 | /* work to check hp jack state */ | |
160 | struct hda_codec *codec; | |
161 | struct delayed_work vt1708_hp_work; | |
e06e5a29 | 162 | int vt1708_jack_detect; |
1f2e99fe | 163 | int vt1708_hp_present; |
3e95b9ab LW |
164 | |
165 | void (*set_widgets_power_state)(struct hda_codec *codec); | |
166 | ||
1f2e99fe LW |
167 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
168 | struct hda_loopback_check loopback; | |
169 | #endif | |
170 | }; | |
171 | ||
0341ccd7 | 172 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
5b0cb1d8 JK |
173 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
174 | { | |
175 | struct via_spec *spec; | |
176 | ||
177 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
178 | if (spec == NULL) | |
179 | return NULL; | |
180 | ||
181 | codec->spec = spec; | |
182 | spec->codec = codec; | |
0341ccd7 LW |
183 | spec->codec_type = get_codec_type(codec); |
184 | /* VT1708BCE & VT1708S are almost same */ | |
185 | if (spec->codec_type == VT1708BCE) | |
186 | spec->codec_type = VT1708S; | |
5b0cb1d8 JK |
187 | return spec; |
188 | } | |
189 | ||
744ff5f4 | 190 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
d7426329 | 191 | { |
744ff5f4 | 192 | u32 vendor_id = codec->vendor_id; |
d7426329 HW |
193 | u16 ven_id = vendor_id >> 16; |
194 | u16 dev_id = vendor_id & 0xffff; | |
195 | enum VIA_HDA_CODEC codec_type; | |
196 | ||
197 | /* get codec type */ | |
198 | if (ven_id != 0x1106) | |
199 | codec_type = UNKNOWN; | |
200 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) | |
201 | codec_type = VT1708; | |
202 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) | |
203 | codec_type = VT1709_10CH; | |
204 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) | |
205 | codec_type = VT1709_6CH; | |
518bf3ba | 206 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
d7426329 | 207 | codec_type = VT1708B_8CH; |
518bf3ba LW |
208 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
209 | codec_type = VT1708BCE; | |
210 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) | |
d7426329 HW |
211 | codec_type = VT1708B_4CH; |
212 | else if ((dev_id & 0xfff) == 0x397 | |
213 | && (dev_id >> 12) < 8) | |
214 | codec_type = VT1708S; | |
215 | else if ((dev_id & 0xfff) == 0x398 | |
216 | && (dev_id >> 12) < 8) | |
217 | codec_type = VT1702; | |
eb7188ca LW |
218 | else if ((dev_id & 0xfff) == 0x428 |
219 | && (dev_id >> 12) < 8) | |
220 | codec_type = VT1718S; | |
f3db423d LW |
221 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
222 | codec_type = VT1716S; | |
bb3c6bfc LW |
223 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
224 | codec_type = VT1718S; | |
25eaba2f LW |
225 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
226 | codec_type = VT2002P; | |
ab6734e7 LW |
227 | else if (dev_id == 0x0448) |
228 | codec_type = VT1812; | |
36dd5c4a LW |
229 | else if (dev_id == 0x0440) |
230 | codec_type = VT1708S; | |
11890956 LW |
231 | else if ((dev_id & 0xfff) == 0x446) |
232 | codec_type = VT1802; | |
d7426329 HW |
233 | else |
234 | codec_type = UNKNOWN; | |
235 | return codec_type; | |
236 | }; | |
237 | ||
ec7e7e42 | 238 | #define VIA_JACK_EVENT 0x20 |
69e52a80 HW |
239 | #define VIA_HP_EVENT 0x01 |
240 | #define VIA_GPIO_EVENT 0x02 | |
ec7e7e42 LW |
241 | #define VIA_MONO_EVENT 0x03 |
242 | #define VIA_SPEAKER_EVENT 0x04 | |
243 | #define VIA_BIND_HP_EVENT 0x05 | |
69e52a80 | 244 | |
c577b8a1 JC |
245 | enum { |
246 | VIA_CTL_WIDGET_VOL, | |
247 | VIA_CTL_WIDGET_MUTE, | |
f5271101 | 248 | VIA_CTL_WIDGET_ANALOG_MUTE, |
25eaba2f | 249 | VIA_CTL_WIDGET_BIND_PIN_MUTE, |
c577b8a1 JC |
250 | }; |
251 | ||
252 | enum { | |
eb14a46c | 253 | AUTO_SEQ_FRONT = 0, |
c577b8a1 JC |
254 | AUTO_SEQ_SURROUND, |
255 | AUTO_SEQ_CENLFE, | |
256 | AUTO_SEQ_SIDE | |
257 | }; | |
258 | ||
f5271101 | 259 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); |
1f2e99fe LW |
260 | static int is_aa_path_mute(struct hda_codec *codec); |
261 | ||
262 | static void vt1708_start_hp_work(struct via_spec *spec) | |
263 | { | |
264 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) | |
265 | return; | |
266 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, | |
e06e5a29 | 267 | !spec->vt1708_jack_detect); |
1f2e99fe LW |
268 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
269 | schedule_delayed_work(&spec->vt1708_hp_work, | |
270 | msecs_to_jiffies(100)); | |
271 | } | |
272 | ||
273 | static void vt1708_stop_hp_work(struct via_spec *spec) | |
274 | { | |
275 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) | |
276 | return; | |
277 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 | |
278 | && !is_aa_path_mute(spec->codec)) | |
279 | return; | |
280 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, | |
e06e5a29 | 281 | !spec->vt1708_jack_detect); |
5b84ba26 | 282 | cancel_delayed_work_sync(&spec->vt1708_hp_work); |
1f2e99fe | 283 | } |
f5271101 | 284 | |
3e95b9ab LW |
285 | static void set_widgets_power_state(struct hda_codec *codec) |
286 | { | |
287 | struct via_spec *spec = codec->spec; | |
288 | if (spec->set_widgets_power_state) | |
289 | spec->set_widgets_power_state(codec); | |
290 | } | |
25eaba2f | 291 | |
f5271101 LW |
292 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
293 | struct snd_ctl_elem_value *ucontrol) | |
294 | { | |
295 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); | |
296 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
297 | ||
3e95b9ab | 298 | set_widgets_power_state(codec); |
f5271101 | 299 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
1f2e99fe LW |
300 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
301 | if (is_aa_path_mute(codec)) | |
302 | vt1708_start_hp_work(codec->spec); | |
303 | else | |
304 | vt1708_stop_hp_work(codec->spec); | |
305 | } | |
f5271101 LW |
306 | return change; |
307 | } | |
308 | ||
309 | /* modify .put = snd_hda_mixer_amp_switch_put */ | |
310 | #define ANALOG_INPUT_MUTE \ | |
311 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
312 | .name = NULL, \ | |
313 | .index = 0, \ | |
314 | .info = snd_hda_mixer_amp_switch_info, \ | |
315 | .get = snd_hda_mixer_amp_switch_get, \ | |
316 | .put = analog_input_switch_put, \ | |
317 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | |
318 | ||
25eaba2f LW |
319 | static void via_hp_bind_automute(struct hda_codec *codec); |
320 | ||
321 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, | |
322 | struct snd_ctl_elem_value *ucontrol) | |
323 | { | |
324 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
325 | struct via_spec *spec = codec->spec; | |
326 | int i; | |
327 | int change = 0; | |
328 | ||
329 | long *valp = ucontrol->value.integer.value; | |
330 | int lmute, rmute; | |
331 | if (strstr(kcontrol->id.name, "Switch") == NULL) { | |
332 | snd_printd("Invalid control!\n"); | |
333 | return change; | |
334 | } | |
335 | change = snd_hda_mixer_amp_switch_put(kcontrol, | |
336 | ucontrol); | |
337 | /* Get mute value */ | |
338 | lmute = *valp ? 0 : HDA_AMP_MUTE; | |
339 | valp++; | |
340 | rmute = *valp ? 0 : HDA_AMP_MUTE; | |
341 | ||
342 | /* Set hp pins */ | |
343 | if (!spec->hp_independent_mode) { | |
344 | for (i = 0; i < spec->autocfg.hp_outs; i++) { | |
345 | snd_hda_codec_amp_update( | |
346 | codec, spec->autocfg.hp_pins[i], | |
347 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
348 | lmute); | |
349 | snd_hda_codec_amp_update( | |
350 | codec, spec->autocfg.hp_pins[i], | |
351 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
352 | rmute); | |
353 | } | |
354 | } | |
355 | ||
356 | if (!lmute && !rmute) { | |
357 | /* Line Outs */ | |
358 | for (i = 0; i < spec->autocfg.line_outs; i++) | |
359 | snd_hda_codec_amp_stereo( | |
360 | codec, spec->autocfg.line_out_pins[i], | |
361 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | |
362 | /* Speakers */ | |
363 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
364 | snd_hda_codec_amp_stereo( | |
365 | codec, spec->autocfg.speaker_pins[i], | |
366 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | |
367 | /* unmute */ | |
368 | via_hp_bind_automute(codec); | |
369 | ||
370 | } else { | |
371 | if (lmute) { | |
372 | /* Mute all left channels */ | |
373 | for (i = 1; i < spec->autocfg.line_outs; i++) | |
374 | snd_hda_codec_amp_update( | |
375 | codec, | |
376 | spec->autocfg.line_out_pins[i], | |
377 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
378 | lmute); | |
379 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
380 | snd_hda_codec_amp_update( | |
381 | codec, | |
382 | spec->autocfg.speaker_pins[i], | |
383 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
384 | lmute); | |
385 | } | |
386 | if (rmute) { | |
387 | /* mute all right channels */ | |
388 | for (i = 1; i < spec->autocfg.line_outs; i++) | |
389 | snd_hda_codec_amp_update( | |
390 | codec, | |
391 | spec->autocfg.line_out_pins[i], | |
392 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
393 | rmute); | |
394 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
395 | snd_hda_codec_amp_update( | |
396 | codec, | |
397 | spec->autocfg.speaker_pins[i], | |
398 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
399 | rmute); | |
400 | } | |
401 | } | |
402 | return change; | |
403 | } | |
404 | ||
405 | #define BIND_PIN_MUTE \ | |
406 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
407 | .name = NULL, \ | |
408 | .index = 0, \ | |
409 | .info = snd_hda_mixer_amp_switch_info, \ | |
410 | .get = snd_hda_mixer_amp_switch_get, \ | |
411 | .put = bind_pin_switch_put, \ | |
412 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | |
413 | ||
90dd48a1 | 414 | static const struct snd_kcontrol_new via_control_templates[] = { |
c577b8a1 JC |
415 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
416 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
f5271101 | 417 | ANALOG_INPUT_MUTE, |
25eaba2f | 418 | BIND_PIN_MUTE, |
c577b8a1 JC |
419 | }; |
420 | ||
ab6734e7 | 421 | |
c577b8a1 | 422 | /* add dynamic controls */ |
291c9e33 TI |
423 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
424 | const struct snd_kcontrol_new *tmpl, | |
425 | const char *name) | |
c577b8a1 JC |
426 | { |
427 | struct snd_kcontrol_new *knew; | |
428 | ||
603c4019 TI |
429 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
430 | knew = snd_array_new(&spec->kctls); | |
431 | if (!knew) | |
291c9e33 TI |
432 | return NULL; |
433 | *knew = *tmpl; | |
434 | if (!name) | |
435 | name = tmpl->name; | |
436 | if (name) { | |
437 | knew->name = kstrdup(name, GFP_KERNEL); | |
438 | if (!knew->name) | |
439 | return NULL; | |
440 | } | |
441 | return knew; | |
442 | } | |
443 | ||
444 | static int __via_add_control(struct via_spec *spec, int type, const char *name, | |
445 | int idx, unsigned long val) | |
446 | { | |
447 | struct snd_kcontrol_new *knew; | |
448 | ||
449 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); | |
450 | if (!knew) | |
c577b8a1 | 451 | return -ENOMEM; |
4d02d1b6 | 452 | if (get_amp_nid_(val)) |
5e26dfd0 | 453 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
c577b8a1 | 454 | knew->private_value = val; |
c577b8a1 JC |
455 | return 0; |
456 | } | |
457 | ||
7b315bb4 TI |
458 | #define via_add_control(spec, type, name, val) \ |
459 | __via_add_control(spec, type, name, 0, val) | |
460 | ||
291c9e33 | 461 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
5b0cb1d8 | 462 | |
603c4019 TI |
463 | static void via_free_kctls(struct hda_codec *codec) |
464 | { | |
465 | struct via_spec *spec = codec->spec; | |
466 | ||
467 | if (spec->kctls.list) { | |
468 | struct snd_kcontrol_new *kctl = spec->kctls.list; | |
469 | int i; | |
470 | for (i = 0; i < spec->kctls.used; i++) | |
471 | kfree(kctl[i].name); | |
472 | } | |
473 | snd_array_free(&spec->kctls); | |
474 | } | |
475 | ||
c577b8a1 | 476 | /* create input playback/capture controls for the given pin */ |
9510e8dd | 477 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
7b315bb4 | 478 | int type_idx, int idx, int mix_nid) |
c577b8a1 JC |
479 | { |
480 | char name[32]; | |
481 | int err; | |
482 | ||
483 | sprintf(name, "%s Playback Volume", ctlname); | |
7b315bb4 | 484 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
c577b8a1 JC |
485 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
486 | if (err < 0) | |
487 | return err; | |
488 | sprintf(name, "%s Playback Switch", ctlname); | |
7b315bb4 | 489 | err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx, |
c577b8a1 JC |
490 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
491 | if (err < 0) | |
492 | return err; | |
493 | return 0; | |
494 | } | |
495 | ||
496 | static void via_auto_set_output_and_unmute(struct hda_codec *codec, | |
497 | hda_nid_t nid, int pin_type, | |
498 | int dac_idx) | |
499 | { | |
500 | /* set as output */ | |
501 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
502 | pin_type); | |
503 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
504 | AMP_OUT_UNMUTE); | |
d3a11e60 | 505 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
377ff31a | 506 | snd_hda_codec_write(codec, nid, 0, |
d3a11e60 | 507 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
c577b8a1 JC |
508 | } |
509 | ||
510 | ||
511 | static void via_auto_init_multi_out(struct hda_codec *codec) | |
512 | { | |
513 | struct via_spec *spec = codec->spec; | |
514 | int i; | |
515 | ||
516 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
517 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
518 | if (nid) | |
519 | via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); | |
520 | } | |
521 | } | |
522 | ||
523 | static void via_auto_init_hp_out(struct hda_codec *codec) | |
524 | { | |
525 | struct via_spec *spec = codec->spec; | |
526 | hda_nid_t pin; | |
25eaba2f | 527 | int i; |
c577b8a1 | 528 | |
25eaba2f LW |
529 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
530 | pin = spec->autocfg.hp_pins[i]; | |
531 | if (pin) /* connect to front */ | |
532 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); | |
533 | } | |
c577b8a1 JC |
534 | } |
535 | ||
32e0191d CL |
536 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin); |
537 | ||
c577b8a1 JC |
538 | static void via_auto_init_analog_input(struct hda_codec *codec) |
539 | { | |
540 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 541 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
32e0191d | 542 | unsigned int ctl; |
c577b8a1 JC |
543 | int i; |
544 | ||
7b315bb4 TI |
545 | for (i = 0; i < cfg->num_inputs; i++) { |
546 | hda_nid_t nid = cfg->inputs[i].pin; | |
32e0191d CL |
547 | if (spec->smart51_enabled && is_smart51_pins(spec, nid)) |
548 | ctl = PIN_OUT; | |
30649676 | 549 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) |
32e0191d CL |
550 | ctl = PIN_VREF50; |
551 | else | |
552 | ctl = PIN_IN; | |
c577b8a1 | 553 | snd_hda_codec_write(codec, nid, 0, |
32e0191d | 554 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); |
c577b8a1 JC |
555 | } |
556 | } | |
f5271101 LW |
557 | |
558 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, | |
559 | unsigned int *affected_parm) | |
560 | { | |
561 | unsigned parm; | |
562 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); | |
563 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) | |
564 | >> AC_DEFCFG_MISC_SHIFT | |
565 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ | |
1564b287 | 566 | struct via_spec *spec = codec->spec; |
24088a58 TI |
567 | unsigned present = 0; |
568 | ||
569 | no_presence |= spec->no_pin_power_ctl; | |
570 | if (!no_presence) | |
571 | present = snd_hda_jack_detect(codec, nid); | |
1564b287 LW |
572 | if ((spec->smart51_enabled && is_smart51_pins(spec, nid)) |
573 | || ((no_presence || present) | |
574 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { | |
f5271101 LW |
575 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
576 | parm = AC_PWRST_D0; | |
577 | } else | |
578 | parm = AC_PWRST_D3; | |
579 | ||
580 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); | |
581 | } | |
582 | ||
24088a58 TI |
583 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
584 | struct snd_ctl_elem_info *uinfo) | |
585 | { | |
586 | static const char * const texts[] = { | |
587 | "Disabled", "Enabled" | |
588 | }; | |
589 | ||
590 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
591 | uinfo->count = 1; | |
592 | uinfo->value.enumerated.items = 2; | |
593 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | |
594 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; | |
595 | strcpy(uinfo->value.enumerated.name, | |
596 | texts[uinfo->value.enumerated.item]); | |
597 | return 0; | |
598 | } | |
599 | ||
600 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, | |
601 | struct snd_ctl_elem_value *ucontrol) | |
602 | { | |
603 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
604 | struct via_spec *spec = codec->spec; | |
605 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; | |
606 | return 0; | |
607 | } | |
608 | ||
609 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, | |
610 | struct snd_ctl_elem_value *ucontrol) | |
611 | { | |
612 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
613 | struct via_spec *spec = codec->spec; | |
614 | unsigned int val = !ucontrol->value.enumerated.item[0]; | |
615 | ||
616 | if (val == spec->no_pin_power_ctl) | |
617 | return 0; | |
618 | spec->no_pin_power_ctl = val; | |
619 | set_widgets_power_state(codec); | |
620 | return 1; | |
621 | } | |
622 | ||
623 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { | |
624 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
625 | .name = "Dynamic Power-Control", | |
626 | .info = via_pin_power_ctl_info, | |
627 | .get = via_pin_power_ctl_get, | |
628 | .put = via_pin_power_ctl_put, | |
629 | }; | |
630 | ||
631 | ||
c577b8a1 JC |
632 | /* |
633 | * input MUX handling | |
634 | */ | |
635 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, | |
636 | struct snd_ctl_elem_info *uinfo) | |
637 | { | |
638 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
639 | struct via_spec *spec = codec->spec; | |
640 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
641 | } | |
642 | ||
643 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, | |
644 | struct snd_ctl_elem_value *ucontrol) | |
645 | { | |
646 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
647 | struct via_spec *spec = codec->spec; | |
648 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
649 | ||
650 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
651 | return 0; | |
652 | } | |
653 | ||
654 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | |
655 | struct snd_ctl_elem_value *ucontrol) | |
656 | { | |
657 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
658 | struct via_spec *spec = codec->spec; | |
659 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
bff5fbf5 | 660 | int ret; |
c577b8a1 | 661 | |
337b9d02 TI |
662 | if (!spec->mux_nids[adc_idx]) |
663 | return -EINVAL; | |
a80e6e3c LW |
664 | /* switch to D0 beofre change index */ |
665 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, | |
666 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) | |
667 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, | |
668 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
a80e6e3c | 669 | |
bff5fbf5 | 670 | ret = snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
337b9d02 TI |
671 | spec->mux_nids[adc_idx], |
672 | &spec->cur_mux[adc_idx]); | |
bff5fbf5 | 673 | /* update jack power state */ |
3e95b9ab | 674 | set_widgets_power_state(codec); |
bff5fbf5 LW |
675 | |
676 | return ret; | |
c577b8a1 JC |
677 | } |
678 | ||
0aa62aef HW |
679 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
680 | struct snd_ctl_elem_info *uinfo) | |
681 | { | |
682 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
683 | struct via_spec *spec = codec->spec; | |
684 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); | |
685 | } | |
686 | ||
687 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, | |
688 | struct snd_ctl_elem_value *ucontrol) | |
689 | { | |
690 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
5b0cb1d8 | 691 | hda_nid_t nid = kcontrol->private_value; |
eb7188ca | 692 | unsigned int pinsel; |
0aa62aef | 693 | |
eb7188ca LW |
694 | /* use !! to translate conn sel 2 for VT1718S */ |
695 | pinsel = !!snd_hda_codec_read(codec, nid, 0, | |
696 | AC_VERB_GET_CONNECT_SEL, | |
697 | 0x00); | |
0aa62aef HW |
698 | ucontrol->value.enumerated.item[0] = pinsel; |
699 | ||
700 | return 0; | |
701 | } | |
702 | ||
0713efeb LW |
703 | static void activate_ctl(struct hda_codec *codec, const char *name, int active) |
704 | { | |
705 | struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); | |
706 | if (ctl) { | |
707 | ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; | |
708 | ctl->vd[0].access |= active | |
709 | ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; | |
710 | snd_ctl_notify(codec->bus->card, | |
711 | SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); | |
712 | } | |
713 | } | |
714 | ||
5b0cb1d8 JK |
715 | static hda_nid_t side_mute_channel(struct via_spec *spec) |
716 | { | |
717 | switch (spec->codec_type) { | |
718 | case VT1708: return 0x1b; | |
719 | case VT1709_10CH: return 0x29; | |
720 | case VT1708B_8CH: /* fall thru */ | |
721 | case VT1708S: return 0x27; | |
e87885fe LW |
722 | case VT2002P: return 0x19; |
723 | case VT1802: return 0x15; | |
724 | case VT1812: return 0x15; | |
5b0cb1d8 JK |
725 | default: return 0; |
726 | } | |
727 | } | |
728 | ||
cdc1784d LW |
729 | static int update_side_mute_status(struct hda_codec *codec) |
730 | { | |
731 | /* mute side channel */ | |
732 | struct via_spec *spec = codec->spec; | |
e87885fe | 733 | unsigned int parm; |
5b0cb1d8 | 734 | hda_nid_t sw3 = side_mute_channel(spec); |
cdc1784d | 735 | |
e87885fe LW |
736 | if (sw3) { |
737 | if (VT2002P_COMPATIBLE(spec)) | |
738 | parm = spec->hp_independent_mode ? | |
739 | AMP_IN_MUTE(1) : AMP_IN_UNMUTE(1); | |
740 | else | |
741 | parm = spec->hp_independent_mode ? | |
742 | AMP_OUT_MUTE : AMP_OUT_UNMUTE; | |
743 | snd_hda_codec_write(codec, sw3, 0, | |
744 | AC_VERB_SET_AMP_GAIN_MUTE, parm); | |
745 | if (spec->codec_type == VT1812) | |
746 | snd_hda_codec_write(codec, 0x1d, 0, | |
747 | AC_VERB_SET_AMP_GAIN_MUTE, parm); | |
748 | } | |
cdc1784d LW |
749 | return 0; |
750 | } | |
751 | ||
0aa62aef HW |
752 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
753 | struct snd_ctl_elem_value *ucontrol) | |
754 | { | |
755 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
756 | struct via_spec *spec = codec->spec; | |
5b0cb1d8 | 757 | hda_nid_t nid = kcontrol->private_value; |
0aa62aef | 758 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
cdc1784d LW |
759 | /* Get Independent Mode index of headphone pin widget */ |
760 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel | |
761 | ? 1 : 0; | |
ce0e5a9e LW |
762 | if (spec->codec_type == VT1718S) |
763 | snd_hda_codec_write(codec, nid, 0, | |
764 | AC_VERB_SET_CONNECT_SEL, pinsel ? 2 : 0); | |
765 | else | |
766 | snd_hda_codec_write(codec, nid, 0, | |
767 | AC_VERB_SET_CONNECT_SEL, pinsel); | |
cdc1784d | 768 | |
ce0e5a9e LW |
769 | if (spec->codec_type == VT1812) |
770 | snd_hda_codec_write(codec, 0x35, 0, | |
771 | AC_VERB_SET_CONNECT_SEL, pinsel); | |
cdc1784d LW |
772 | if (spec->multiout.hp_nid && spec->multiout.hp_nid |
773 | != spec->multiout.dac_nids[HDA_FRONT]) | |
774 | snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, | |
775 | 0, 0, 0); | |
0aa62aef | 776 | |
cdc1784d | 777 | update_side_mute_status(codec); |
0713efeb LW |
778 | /* update HP volume/swtich active state */ |
779 | if (spec->codec_type == VT1708S | |
eb7188ca | 780 | || spec->codec_type == VT1702 |
f3db423d | 781 | || spec->codec_type == VT1718S |
25eaba2f | 782 | || spec->codec_type == VT1716S |
11890956 | 783 | || VT2002P_COMPATIBLE(spec)) { |
0713efeb LW |
784 | activate_ctl(codec, "Headphone Playback Volume", |
785 | spec->hp_independent_mode); | |
786 | activate_ctl(codec, "Headphone Playback Switch", | |
787 | spec->hp_independent_mode); | |
788 | } | |
ce0e5a9e | 789 | /* update jack power state */ |
3e95b9ab | 790 | set_widgets_power_state(codec); |
0aa62aef HW |
791 | return 0; |
792 | } | |
793 | ||
90dd48a1 | 794 | static const struct snd_kcontrol_new via_hp_mixer[2] = { |
0aa62aef HW |
795 | { |
796 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
797 | .name = "Independent HP", | |
0aa62aef HW |
798 | .info = via_independent_hp_info, |
799 | .get = via_independent_hp_get, | |
800 | .put = via_independent_hp_put, | |
801 | }, | |
5b0cb1d8 JK |
802 | { |
803 | .iface = NID_MAPPING, | |
804 | .name = "Independent HP", | |
805 | }, | |
0aa62aef HW |
806 | }; |
807 | ||
3d83e577 | 808 | static int via_hp_build(struct hda_codec *codec) |
5b0cb1d8 | 809 | { |
3d83e577 | 810 | struct via_spec *spec = codec->spec; |
5b0cb1d8 JK |
811 | struct snd_kcontrol_new *knew; |
812 | hda_nid_t nid; | |
3d83e577 TI |
813 | int nums; |
814 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; | |
5b0cb1d8 JK |
815 | |
816 | switch (spec->codec_type) { | |
817 | case VT1718S: | |
818 | nid = 0x34; | |
819 | break; | |
820 | case VT2002P: | |
11890956 | 821 | case VT1802: |
5b0cb1d8 JK |
822 | nid = 0x35; |
823 | break; | |
824 | case VT1812: | |
825 | nid = 0x3d; | |
826 | break; | |
827 | default: | |
828 | nid = spec->autocfg.hp_pins[0]; | |
829 | break; | |
830 | } | |
831 | ||
ee3c35c0 LW |
832 | if (spec->codec_type != VT1708) { |
833 | nums = snd_hda_get_connections(codec, nid, | |
834 | conn, HDA_MAX_CONNECTIONS); | |
835 | if (nums <= 1) | |
836 | return 0; | |
837 | } | |
3d83e577 TI |
838 | |
839 | knew = via_clone_control(spec, &via_hp_mixer[0]); | |
840 | if (knew == NULL) | |
841 | return -ENOMEM; | |
842 | ||
5b0cb1d8 JK |
843 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
844 | knew->private_value = nid; | |
845 | ||
846 | knew = via_clone_control(spec, &via_hp_mixer[1]); | |
847 | if (knew == NULL) | |
848 | return -ENOMEM; | |
849 | knew->subdevice = side_mute_channel(spec); | |
850 | ||
851 | return 0; | |
852 | } | |
853 | ||
1564b287 LW |
854 | static void notify_aa_path_ctls(struct hda_codec *codec) |
855 | { | |
856 | int i; | |
857 | struct snd_ctl_elem_id id; | |
525566cb LW |
858 | const char *labels[] = {"Mic", "Front Mic", "Line", "Rear Mic"}; |
859 | struct snd_kcontrol *ctl; | |
1564b287 LW |
860 | |
861 | memset(&id, 0, sizeof(id)); | |
862 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
863 | for (i = 0; i < ARRAY_SIZE(labels); i++) { | |
864 | sprintf(id.name, "%s Playback Volume", labels[i]); | |
525566cb LW |
865 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
866 | if (ctl) | |
867 | snd_ctl_notify(codec->bus->card, | |
868 | SNDRV_CTL_EVENT_MASK_VALUE, | |
869 | &ctl->id); | |
1564b287 LW |
870 | } |
871 | } | |
872 | ||
873 | static void mute_aa_path(struct hda_codec *codec, int mute) | |
874 | { | |
875 | struct via_spec *spec = codec->spec; | |
876 | hda_nid_t nid_mixer; | |
877 | int start_idx; | |
878 | int end_idx; | |
879 | int i; | |
880 | /* get nid of MW0 and start & end index */ | |
881 | switch (spec->codec_type) { | |
882 | case VT1708: | |
883 | nid_mixer = 0x17; | |
884 | start_idx = 2; | |
885 | end_idx = 4; | |
886 | break; | |
887 | case VT1709_10CH: | |
888 | case VT1709_6CH: | |
889 | nid_mixer = 0x18; | |
890 | start_idx = 2; | |
891 | end_idx = 4; | |
892 | break; | |
893 | case VT1708B_8CH: | |
894 | case VT1708B_4CH: | |
895 | case VT1708S: | |
f3db423d | 896 | case VT1716S: |
1564b287 LW |
897 | nid_mixer = 0x16; |
898 | start_idx = 2; | |
899 | end_idx = 4; | |
900 | break; | |
ab657e0c LW |
901 | case VT1718S: |
902 | nid_mixer = 0x21; | |
903 | start_idx = 1; | |
904 | end_idx = 3; | |
905 | break; | |
1564b287 LW |
906 | default: |
907 | return; | |
908 | } | |
909 | /* check AA path's mute status */ | |
910 | for (i = start_idx; i <= end_idx; i++) { | |
911 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; | |
912 | snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i, | |
913 | HDA_AMP_MUTE, val); | |
914 | } | |
915 | } | |
916 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin) | |
917 | { | |
7b315bb4 TI |
918 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
919 | int i; | |
920 | ||
921 | for (i = 0; i < cfg->num_inputs; i++) { | |
922 | if (pin == cfg->inputs[i].pin) | |
86e2959a | 923 | return cfg->inputs[i].type <= AUTO_PIN_LINE_IN; |
1564b287 | 924 | } |
7b315bb4 | 925 | return 0; |
1564b287 LW |
926 | } |
927 | ||
928 | static int via_smart51_info(struct snd_kcontrol *kcontrol, | |
929 | struct snd_ctl_elem_info *uinfo) | |
930 | { | |
931 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
932 | uinfo->count = 1; | |
933 | uinfo->value.integer.min = 0; | |
934 | uinfo->value.integer.max = 1; | |
935 | return 0; | |
936 | } | |
937 | ||
938 | static int via_smart51_get(struct snd_kcontrol *kcontrol, | |
939 | struct snd_ctl_elem_value *ucontrol) | |
940 | { | |
941 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
942 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 943 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
1564b287 LW |
944 | int on = 1; |
945 | int i; | |
946 | ||
7b315bb4 TI |
947 | for (i = 0; i < cfg->num_inputs; i++) { |
948 | hda_nid_t nid = cfg->inputs[i].pin; | |
949 | int ctl = snd_hda_codec_read(codec, nid, 0, | |
950 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
86e2959a | 951 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
7b315bb4 | 952 | continue; |
86e2959a | 953 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
7b315bb4 TI |
954 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
955 | continue; /* ignore FMic for independent HP */ | |
956 | if ((ctl & AC_PINCTL_IN_EN) && !(ctl & AC_PINCTL_OUT_EN)) | |
957 | on = 0; | |
1564b287 LW |
958 | } |
959 | *ucontrol->value.integer.value = on; | |
960 | return 0; | |
961 | } | |
962 | ||
963 | static int via_smart51_put(struct snd_kcontrol *kcontrol, | |
964 | struct snd_ctl_elem_value *ucontrol) | |
965 | { | |
966 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
967 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 968 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
1564b287 LW |
969 | int out_in = *ucontrol->value.integer.value |
970 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; | |
1564b287 LW |
971 | int i; |
972 | ||
7b315bb4 TI |
973 | for (i = 0; i < cfg->num_inputs; i++) { |
974 | hda_nid_t nid = cfg->inputs[i].pin; | |
975 | unsigned int parm; | |
976 | ||
86e2959a | 977 | if (cfg->inputs[i].type > AUTO_PIN_LINE_IN) |
7b315bb4 | 978 | continue; |
86e2959a | 979 | if (cfg->inputs[i].type == AUTO_PIN_MIC && |
7b315bb4 | 980 | spec->hp_independent_mode && spec->codec_type != VT1718S) |
1564b287 | 981 | continue; /* don't retask FMic for independent HP */ |
7b315bb4 TI |
982 | |
983 | parm = snd_hda_codec_read(codec, nid, 0, | |
984 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
985 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); | |
986 | parm |= out_in; | |
987 | snd_hda_codec_write(codec, nid, 0, | |
988 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
989 | parm); | |
990 | if (out_in == AC_PINCTL_OUT_EN) { | |
991 | mute_aa_path(codec, 1); | |
992 | notify_aa_path_ctls(codec); | |
993 | } | |
994 | if (spec->codec_type == VT1718S) { | |
995 | snd_hda_codec_amp_stereo( | |
eb7188ca LW |
996 | codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
997 | HDA_AMP_UNMUTE); | |
1564b287 | 998 | } |
86e2959a | 999 | if (cfg->inputs[i].type == AUTO_PIN_MIC) { |
f3db423d LW |
1000 | if (spec->codec_type == VT1708S |
1001 | || spec->codec_type == VT1716S) { | |
1564b287 LW |
1002 | /* input = index 1 (AOW3) */ |
1003 | snd_hda_codec_write( | |
1004 | codec, nid, 0, | |
1005 | AC_VERB_SET_CONNECT_SEL, 1); | |
1006 | snd_hda_codec_amp_stereo( | |
1007 | codec, nid, HDA_OUTPUT, | |
1008 | 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE); | |
1009 | } | |
1010 | } | |
1011 | } | |
1012 | spec->smart51_enabled = *ucontrol->value.integer.value; | |
3e95b9ab | 1013 | set_widgets_power_state(codec); |
1564b287 LW |
1014 | return 1; |
1015 | } | |
1016 | ||
5f4b36d6 TI |
1017 | static const struct snd_kcontrol_new via_smart51_mixer = { |
1018 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1019 | .name = "Smart 5.1", | |
1020 | .count = 1, | |
1021 | .info = via_smart51_info, | |
1022 | .get = via_smart51_get, | |
1023 | .put = via_smart51_put, | |
1564b287 LW |
1024 | }; |
1025 | ||
5b0cb1d8 JK |
1026 | static int via_smart51_build(struct via_spec *spec) |
1027 | { | |
1028 | struct snd_kcontrol_new *knew; | |
7b315bb4 | 1029 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
5b0cb1d8 JK |
1030 | hda_nid_t nid; |
1031 | int i; | |
1032 | ||
cb34c207 LW |
1033 | if (!cfg) |
1034 | return 0; | |
1035 | if (cfg->line_outs > 2) | |
1036 | return 0; | |
1037 | ||
5f4b36d6 | 1038 | knew = via_clone_control(spec, &via_smart51_mixer); |
5b0cb1d8 JK |
1039 | if (knew == NULL) |
1040 | return -ENOMEM; | |
1041 | ||
7b315bb4 TI |
1042 | for (i = 0; i < cfg->num_inputs; i++) { |
1043 | nid = cfg->inputs[i].pin; | |
86e2959a | 1044 | if (cfg->inputs[i].type <= AUTO_PIN_LINE_IN) { |
5f4b36d6 | 1045 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
7b315bb4 | 1046 | break; |
5b0cb1d8 JK |
1047 | } |
1048 | } | |
1049 | ||
1050 | return 0; | |
1051 | } | |
1052 | ||
c577b8a1 | 1053 | /* capture mixer elements */ |
90dd48a1 | 1054 | static const struct snd_kcontrol_new vt1708_capture_mixer[] = { |
c577b8a1 JC |
1055 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), |
1056 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT), | |
1057 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT), | |
1058 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT), | |
1059 | { | |
1060 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1061 | /* The multiple "Capture Source" controls confuse alsamixer | |
1062 | * So call somewhat different.. | |
c577b8a1 JC |
1063 | */ |
1064 | /* .name = "Capture Source", */ | |
1065 | .name = "Input Source", | |
1066 | .count = 1, | |
1067 | .info = via_mux_enum_info, | |
1068 | .get = via_mux_enum_get, | |
1069 | .put = via_mux_enum_put, | |
1070 | }, | |
1071 | { } /* end */ | |
1072 | }; | |
f5271101 LW |
1073 | |
1074 | /* check AA path's mute statue */ | |
1075 | static int is_aa_path_mute(struct hda_codec *codec) | |
1076 | { | |
1077 | int mute = 1; | |
1078 | hda_nid_t nid_mixer; | |
1079 | int start_idx; | |
1080 | int end_idx; | |
1081 | int i; | |
1082 | struct via_spec *spec = codec->spec; | |
1083 | /* get nid of MW0 and start & end index */ | |
1084 | switch (spec->codec_type) { | |
1085 | case VT1708B_8CH: | |
1086 | case VT1708B_4CH: | |
1087 | case VT1708S: | |
f3db423d | 1088 | case VT1716S: |
f5271101 LW |
1089 | nid_mixer = 0x16; |
1090 | start_idx = 2; | |
1091 | end_idx = 4; | |
1092 | break; | |
1093 | case VT1702: | |
1094 | nid_mixer = 0x1a; | |
1095 | start_idx = 1; | |
1096 | end_idx = 3; | |
1097 | break; | |
eb7188ca LW |
1098 | case VT1718S: |
1099 | nid_mixer = 0x21; | |
1100 | start_idx = 1; | |
1101 | end_idx = 3; | |
1102 | break; | |
25eaba2f | 1103 | case VT2002P: |
ab6734e7 | 1104 | case VT1812: |
11890956 | 1105 | case VT1802: |
25eaba2f LW |
1106 | nid_mixer = 0x21; |
1107 | start_idx = 0; | |
1108 | end_idx = 2; | |
1109 | break; | |
f5271101 LW |
1110 | default: |
1111 | return 0; | |
1112 | } | |
1113 | /* check AA path's mute status */ | |
1114 | for (i = start_idx; i <= end_idx; i++) { | |
1115 | unsigned int con_list = snd_hda_codec_read( | |
1116 | codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); | |
1117 | int shift = 8 * (i % 4); | |
1118 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; | |
1119 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); | |
1120 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { | |
1121 | /* check mute status while the pin is connected */ | |
1122 | int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0, | |
1123 | HDA_INPUT, i) >> 7; | |
1124 | int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1, | |
1125 | HDA_INPUT, i) >> 7; | |
1126 | if (!mute_l || !mute_r) { | |
1127 | mute = 0; | |
1128 | break; | |
1129 | } | |
1130 | } | |
1131 | } | |
1132 | return mute; | |
1133 | } | |
1134 | ||
1135 | /* enter/exit analog low-current mode */ | |
1136 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) | |
1137 | { | |
1138 | struct via_spec *spec = codec->spec; | |
1139 | static int saved_stream_idle = 1; /* saved stream idle status */ | |
1140 | int enable = is_aa_path_mute(codec); | |
1141 | unsigned int verb = 0; | |
1142 | unsigned int parm = 0; | |
1143 | ||
1144 | if (stream_idle == -1) /* stream status did not change */ | |
1145 | enable = enable && saved_stream_idle; | |
1146 | else { | |
1147 | enable = enable && stream_idle; | |
1148 | saved_stream_idle = stream_idle; | |
1149 | } | |
1150 | ||
1151 | /* decide low current mode's verb & parameter */ | |
1152 | switch (spec->codec_type) { | |
1153 | case VT1708B_8CH: | |
1154 | case VT1708B_4CH: | |
1155 | verb = 0xf70; | |
1156 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ | |
1157 | break; | |
1158 | case VT1708S: | |
eb7188ca | 1159 | case VT1718S: |
f3db423d | 1160 | case VT1716S: |
f5271101 LW |
1161 | verb = 0xf73; |
1162 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ | |
1163 | break; | |
1164 | case VT1702: | |
1165 | verb = 0xf73; | |
1166 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ | |
1167 | break; | |
25eaba2f | 1168 | case VT2002P: |
ab6734e7 | 1169 | case VT1812: |
11890956 | 1170 | case VT1802: |
25eaba2f LW |
1171 | verb = 0xf93; |
1172 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ | |
1173 | break; | |
f5271101 LW |
1174 | default: |
1175 | return; /* other codecs are not supported */ | |
1176 | } | |
1177 | /* send verb */ | |
1178 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); | |
1179 | } | |
1180 | ||
c577b8a1 JC |
1181 | /* |
1182 | * generic initialization of ADC, input mixers and output mixers | |
1183 | */ | |
90dd48a1 | 1184 | static const struct hda_verb vt1708_volume_init_verbs[] = { |
c577b8a1 JC |
1185 | /* |
1186 | * Unmute ADC0-1 and set the default input to mic-in | |
1187 | */ | |
1188 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1189 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1190 | ||
1191 | ||
f7278fd0 | 1192 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
c577b8a1 JC |
1193 | * mixer widget |
1194 | */ | |
1195 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
f7278fd0 JC |
1196 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
1197 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
1198 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
1199 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
1200 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
c577b8a1 JC |
1201 | |
1202 | /* | |
1203 | * Set up output mixers (0x19 - 0x1b) | |
1204 | */ | |
1205 | /* set vol=0 to output mixers */ | |
1206 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1207 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1208 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
377ff31a | 1209 | |
bfdc675a LW |
1210 | /* Setup default input MW0 to PW4 */ |
1211 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
1212 | /* PW9 Output enable */ |
1213 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
aa266fcc LW |
1214 | /* power down jack detect function */ |
1215 | {0x1, 0xf81, 0x1}, | |
f7278fd0 | 1216 | { } |
c577b8a1 JC |
1217 | }; |
1218 | ||
1219 | static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
1220 | struct hda_codec *codec, | |
1221 | struct snd_pcm_substream *substream) | |
1222 | { | |
1223 | struct via_spec *spec = codec->spec; | |
17314379 LW |
1224 | int idle = substream->pstr->substream_opened == 1 |
1225 | && substream->ref_count == 0; | |
17314379 | 1226 | analog_low_current_mode(codec, idle); |
9a08160b TI |
1227 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
1228 | hinfo); | |
c577b8a1 JC |
1229 | } |
1230 | ||
0aa62aef HW |
1231 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, |
1232 | unsigned int stream_tag, | |
1233 | unsigned int format, | |
1234 | struct snd_pcm_substream *substream) | |
1235 | { | |
1236 | struct via_spec *spec = codec->spec; | |
1237 | struct hda_multi_out *mout = &spec->multiout; | |
dda14410 | 1238 | const hda_nid_t *nids = mout->dac_nids; |
0aa62aef HW |
1239 | int chs = substream->runtime->channels; |
1240 | int i; | |
7c935976 SW |
1241 | struct hda_spdif_out *spdif = |
1242 | snd_hda_spdif_out_of_nid(codec, spec->multiout.dig_out_nid); | |
0aa62aef HW |
1243 | |
1244 | mutex_lock(&codec->spdif_mutex); | |
1245 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { | |
1246 | if (chs == 2 && | |
1247 | snd_hda_is_supported_format(codec, mout->dig_out_nid, | |
1248 | format) && | |
7c935976 | 1249 | !(spdif->status & IEC958_AES0_NONAUDIO)) { |
0aa62aef HW |
1250 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
1251 | /* turn off SPDIF once; otherwise the IEC958 bits won't | |
1252 | * be updated */ | |
7c935976 | 1253 | if (spdif->ctls & AC_DIG1_ENABLE) |
0aa62aef HW |
1254 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
1255 | AC_VERB_SET_DIGI_CONVERT_1, | |
7c935976 | 1256 | spdif->ctls & |
0aa62aef HW |
1257 | ~AC_DIG1_ENABLE & 0xff); |
1258 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
1259 | stream_tag, 0, format); | |
1260 | /* turn on again (if needed) */ | |
7c935976 | 1261 | if (spdif->ctls & AC_DIG1_ENABLE) |
0aa62aef HW |
1262 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
1263 | AC_VERB_SET_DIGI_CONVERT_1, | |
7c935976 | 1264 | spdif->ctls & 0xff); |
0aa62aef HW |
1265 | } else { |
1266 | mout->dig_out_used = 0; | |
1267 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
1268 | 0, 0, 0); | |
1269 | } | |
1270 | } | |
1271 | mutex_unlock(&codec->spdif_mutex); | |
1272 | ||
1273 | /* front */ | |
1274 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, | |
1275 | 0, format); | |
1276 | ||
eb7188ca LW |
1277 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
1278 | && !spec->hp_independent_mode) | |
0aa62aef HW |
1279 | /* headphone out will just decode front left/right (stereo) */ |
1280 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, | |
1281 | 0, format); | |
1282 | ||
1283 | /* extra outputs copied from front */ | |
1284 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) | |
1285 | if (mout->extra_out_nid[i]) | |
1286 | snd_hda_codec_setup_stream(codec, | |
1287 | mout->extra_out_nid[i], | |
1288 | stream_tag, 0, format); | |
1289 | ||
1290 | /* surrounds */ | |
1291 | for (i = 1; i < mout->num_dacs; i++) { | |
1292 | if (chs >= (i + 1) * 2) /* independent out */ | |
1293 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, | |
1294 | i * 2, format); | |
1295 | else /* copy front */ | |
1296 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, | |
1297 | 0, format); | |
1298 | } | |
1299 | } | |
1300 | ||
1301 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1302 | struct hda_codec *codec, | |
1303 | unsigned int stream_tag, | |
1304 | unsigned int format, | |
1305 | struct snd_pcm_substream *substream) | |
1306 | { | |
1307 | struct via_spec *spec = codec->spec; | |
1308 | struct hda_multi_out *mout = &spec->multiout; | |
dda14410 | 1309 | const hda_nid_t *nids = mout->dac_nids; |
0aa62aef HW |
1310 | |
1311 | if (substream->number == 0) | |
1312 | playback_multi_pcm_prep_0(codec, stream_tag, format, | |
1313 | substream); | |
1314 | else { | |
1315 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && | |
1316 | spec->hp_independent_mode) | |
1317 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
1318 | stream_tag, 0, format); | |
1319 | } | |
1f2e99fe | 1320 | vt1708_start_hp_work(spec); |
0aa62aef HW |
1321 | return 0; |
1322 | } | |
1323 | ||
1324 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1325 | struct hda_codec *codec, | |
1326 | struct snd_pcm_substream *substream) | |
1327 | { | |
1328 | struct via_spec *spec = codec->spec; | |
1329 | struct hda_multi_out *mout = &spec->multiout; | |
dda14410 | 1330 | const hda_nid_t *nids = mout->dac_nids; |
0aa62aef HW |
1331 | int i; |
1332 | ||
1333 | if (substream->number == 0) { | |
1334 | for (i = 0; i < mout->num_dacs; i++) | |
1335 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); | |
1336 | ||
1337 | if (mout->hp_nid && !spec->hp_independent_mode) | |
1338 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
1339 | 0, 0, 0); | |
1340 | ||
1341 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) | |
1342 | if (mout->extra_out_nid[i]) | |
1343 | snd_hda_codec_setup_stream(codec, | |
1344 | mout->extra_out_nid[i], | |
1345 | 0, 0, 0); | |
1346 | mutex_lock(&codec->spdif_mutex); | |
1347 | if (mout->dig_out_nid && | |
1348 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { | |
1349 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
1350 | 0, 0, 0); | |
1351 | mout->dig_out_used = 0; | |
1352 | } | |
1353 | mutex_unlock(&codec->spdif_mutex); | |
1354 | } else { | |
1355 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && | |
1356 | spec->hp_independent_mode) | |
1357 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
1358 | 0, 0, 0); | |
1359 | } | |
1f2e99fe | 1360 | vt1708_stop_hp_work(spec); |
0aa62aef HW |
1361 | return 0; |
1362 | } | |
1363 | ||
c577b8a1 JC |
1364 | /* |
1365 | * Digital out | |
1366 | */ | |
1367 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
1368 | struct hda_codec *codec, | |
1369 | struct snd_pcm_substream *substream) | |
1370 | { | |
1371 | struct via_spec *spec = codec->spec; | |
1372 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
1373 | } | |
1374 | ||
1375 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
1376 | struct hda_codec *codec, | |
1377 | struct snd_pcm_substream *substream) | |
1378 | { | |
1379 | struct via_spec *spec = codec->spec; | |
1380 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
1381 | } | |
1382 | ||
5691ec7f | 1383 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
98aa34c0 HW |
1384 | struct hda_codec *codec, |
1385 | unsigned int stream_tag, | |
1386 | unsigned int format, | |
1387 | struct snd_pcm_substream *substream) | |
1388 | { | |
1389 | struct via_spec *spec = codec->spec; | |
9da29271 TI |
1390 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
1391 | stream_tag, format, substream); | |
1392 | } | |
98aa34c0 | 1393 | |
9da29271 TI |
1394 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1395 | struct hda_codec *codec, | |
1396 | struct snd_pcm_substream *substream) | |
1397 | { | |
1398 | struct via_spec *spec = codec->spec; | |
1399 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
98aa34c0 HW |
1400 | return 0; |
1401 | } | |
1402 | ||
c577b8a1 JC |
1403 | /* |
1404 | * Analog capture | |
1405 | */ | |
1406 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1407 | struct hda_codec *codec, | |
1408 | unsigned int stream_tag, | |
1409 | unsigned int format, | |
1410 | struct snd_pcm_substream *substream) | |
1411 | { | |
1412 | struct via_spec *spec = codec->spec; | |
1413 | ||
1414 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
1415 | stream_tag, 0, format); | |
1416 | return 0; | |
1417 | } | |
1418 | ||
1419 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1420 | struct hda_codec *codec, | |
1421 | struct snd_pcm_substream *substream) | |
1422 | { | |
1423 | struct via_spec *spec = codec->spec; | |
888afa15 | 1424 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
c577b8a1 JC |
1425 | return 0; |
1426 | } | |
1427 | ||
90dd48a1 | 1428 | static const struct hda_pcm_stream vt1708_pcm_analog_playback = { |
0aa62aef | 1429 | .substreams = 2, |
c577b8a1 JC |
1430 | .channels_min = 2, |
1431 | .channels_max = 8, | |
1432 | .nid = 0x10, /* NID to query formats and rates */ | |
1433 | .ops = { | |
1434 | .open = via_playback_pcm_open, | |
0aa62aef HW |
1435 | .prepare = via_playback_multi_pcm_prepare, |
1436 | .cleanup = via_playback_multi_pcm_cleanup | |
c577b8a1 JC |
1437 | }, |
1438 | }; | |
1439 | ||
90dd48a1 | 1440 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
c873cc25 | 1441 | .substreams = 2, |
bc9b5623 TI |
1442 | .channels_min = 2, |
1443 | .channels_max = 8, | |
1444 | .nid = 0x10, /* NID to query formats and rates */ | |
1445 | /* We got noisy outputs on the right channel on VT1708 when | |
1446 | * 24bit samples are used. Until any workaround is found, | |
1447 | * disable the 24bit format, so far. | |
1448 | */ | |
1449 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
1450 | .ops = { | |
1451 | .open = via_playback_pcm_open, | |
c873cc25 LW |
1452 | .prepare = via_playback_multi_pcm_prepare, |
1453 | .cleanup = via_playback_multi_pcm_cleanup | |
bc9b5623 TI |
1454 | }, |
1455 | }; | |
1456 | ||
90dd48a1 | 1457 | static const struct hda_pcm_stream vt1708_pcm_analog_capture = { |
c577b8a1 JC |
1458 | .substreams = 2, |
1459 | .channels_min = 2, | |
1460 | .channels_max = 2, | |
1461 | .nid = 0x15, /* NID to query formats and rates */ | |
1462 | .ops = { | |
1463 | .prepare = via_capture_pcm_prepare, | |
1464 | .cleanup = via_capture_pcm_cleanup | |
1465 | }, | |
1466 | }; | |
1467 | ||
90dd48a1 | 1468 | static const struct hda_pcm_stream vt1708_pcm_digital_playback = { |
c577b8a1 JC |
1469 | .substreams = 1, |
1470 | .channels_min = 2, | |
1471 | .channels_max = 2, | |
1472 | /* NID is set in via_build_pcms */ | |
1473 | .ops = { | |
1474 | .open = via_dig_playback_pcm_open, | |
6b97eb45 | 1475 | .close = via_dig_playback_pcm_close, |
9da29271 TI |
1476 | .prepare = via_dig_playback_pcm_prepare, |
1477 | .cleanup = via_dig_playback_pcm_cleanup | |
c577b8a1 JC |
1478 | }, |
1479 | }; | |
1480 | ||
90dd48a1 | 1481 | static const struct hda_pcm_stream vt1708_pcm_digital_capture = { |
c577b8a1 JC |
1482 | .substreams = 1, |
1483 | .channels_min = 2, | |
1484 | .channels_max = 2, | |
1485 | }; | |
1486 | ||
1487 | static int via_build_controls(struct hda_codec *codec) | |
1488 | { | |
1489 | struct via_spec *spec = codec->spec; | |
5b0cb1d8 | 1490 | struct snd_kcontrol *kctl; |
90dd48a1 | 1491 | const struct snd_kcontrol_new *knew; |
5b0cb1d8 | 1492 | int err, i; |
c577b8a1 | 1493 | |
24088a58 TI |
1494 | if (spec->set_widgets_power_state) |
1495 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) | |
1496 | return -ENOMEM; | |
1497 | ||
c577b8a1 JC |
1498 | for (i = 0; i < spec->num_mixers; i++) { |
1499 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
1500 | if (err < 0) | |
1501 | return err; | |
1502 | } | |
1503 | ||
1504 | if (spec->multiout.dig_out_nid) { | |
1505 | err = snd_hda_create_spdif_out_ctls(codec, | |
74b654c9 | 1506 | spec->multiout.dig_out_nid, |
c577b8a1 JC |
1507 | spec->multiout.dig_out_nid); |
1508 | if (err < 0) | |
1509 | return err; | |
9a08160b TI |
1510 | err = snd_hda_create_spdif_share_sw(codec, |
1511 | &spec->multiout); | |
1512 | if (err < 0) | |
1513 | return err; | |
1514 | spec->multiout.share_spdif = 1; | |
c577b8a1 JC |
1515 | } |
1516 | if (spec->dig_in_nid) { | |
1517 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
1518 | if (err < 0) | |
1519 | return err; | |
1520 | } | |
17314379 | 1521 | |
5b0cb1d8 JK |
1522 | /* assign Capture Source enums to NID */ |
1523 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); | |
1524 | for (i = 0; kctl && i < kctl->count; i++) { | |
21949f00 | 1525 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
5b0cb1d8 JK |
1526 | if (err < 0) |
1527 | return err; | |
1528 | } | |
1529 | ||
1530 | /* other nid->control mapping */ | |
1531 | for (i = 0; i < spec->num_mixers; i++) { | |
1532 | for (knew = spec->mixers[i]; knew->name; knew++) { | |
1533 | if (knew->iface != NID_MAPPING) | |
1534 | continue; | |
1535 | kctl = snd_hda_find_mixer_ctl(codec, knew->name); | |
1536 | if (kctl == NULL) | |
1537 | continue; | |
1538 | err = snd_hda_add_nid(codec, kctl, 0, | |
1539 | knew->subdevice); | |
1540 | } | |
1541 | } | |
1542 | ||
17314379 | 1543 | /* init power states */ |
3e95b9ab | 1544 | set_widgets_power_state(codec); |
17314379 LW |
1545 | analog_low_current_mode(codec, 1); |
1546 | ||
603c4019 | 1547 | via_free_kctls(codec); /* no longer needed */ |
c577b8a1 JC |
1548 | return 0; |
1549 | } | |
1550 | ||
1551 | static int via_build_pcms(struct hda_codec *codec) | |
1552 | { | |
1553 | struct via_spec *spec = codec->spec; | |
1554 | struct hda_pcm *info = spec->pcm_rec; | |
1555 | ||
1556 | codec->num_pcms = 1; | |
1557 | codec->pcm_info = info; | |
1558 | ||
1559 | info->name = spec->stream_name_analog; | |
377ff31a LW |
1560 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
1561 | *(spec->stream_analog_playback); | |
1562 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
1563 | spec->multiout.dac_nids[0]; | |
c577b8a1 JC |
1564 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); |
1565 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
1566 | ||
1567 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
1568 | spec->multiout.max_channels; | |
1569 | ||
1570 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | |
1571 | codec->num_pcms++; | |
1572 | info++; | |
1573 | info->name = spec->stream_name_digital; | |
7ba72ba1 | 1574 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
c577b8a1 JC |
1575 | if (spec->multiout.dig_out_nid) { |
1576 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | |
1577 | *(spec->stream_digital_playback); | |
1578 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
1579 | spec->multiout.dig_out_nid; | |
1580 | } | |
1581 | if (spec->dig_in_nid) { | |
1582 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
1583 | *(spec->stream_digital_capture); | |
1584 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
1585 | spec->dig_in_nid; | |
1586 | } | |
1587 | } | |
1588 | ||
1589 | return 0; | |
1590 | } | |
1591 | ||
1592 | static void via_free(struct hda_codec *codec) | |
1593 | { | |
1594 | struct via_spec *spec = codec->spec; | |
c577b8a1 JC |
1595 | |
1596 | if (!spec) | |
1597 | return; | |
1598 | ||
603c4019 | 1599 | via_free_kctls(codec); |
1f2e99fe | 1600 | vt1708_stop_hp_work(spec); |
c577b8a1 JC |
1601 | kfree(codec->spec); |
1602 | } | |
1603 | ||
69e52a80 HW |
1604 | /* mute internal speaker if HP is plugged */ |
1605 | static void via_hp_automute(struct hda_codec *codec) | |
1606 | { | |
dcf34c8c | 1607 | unsigned int present = 0; |
69e52a80 HW |
1608 | struct via_spec *spec = codec->spec; |
1609 | ||
d56757ab | 1610 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
dcf34c8c LW |
1611 | |
1612 | if (!spec->hp_independent_mode) { | |
1613 | struct snd_ctl_elem_id id; | |
1614 | /* auto mute */ | |
1615 | snd_hda_codec_amp_stereo( | |
1616 | codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0, | |
1617 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); | |
1618 | /* notify change */ | |
1619 | memset(&id, 0, sizeof(id)); | |
1620 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
1621 | strcpy(id.name, "Front Playback Switch"); | |
1622 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
1623 | &id); | |
1624 | } | |
69e52a80 HW |
1625 | } |
1626 | ||
f3db423d LW |
1627 | /* mute mono out if HP or Line out is plugged */ |
1628 | static void via_mono_automute(struct hda_codec *codec) | |
1629 | { | |
1630 | unsigned int hp_present, lineout_present; | |
1631 | struct via_spec *spec = codec->spec; | |
1632 | ||
1633 | if (spec->codec_type != VT1716S) | |
1634 | return; | |
1635 | ||
d56757ab TI |
1636 | lineout_present = snd_hda_jack_detect(codec, |
1637 | spec->autocfg.line_out_pins[0]); | |
f3db423d LW |
1638 | |
1639 | /* Mute Mono Out if Line Out is plugged */ | |
1640 | if (lineout_present) { | |
1641 | snd_hda_codec_amp_stereo( | |
1642 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE); | |
1643 | return; | |
1644 | } | |
1645 | ||
d56757ab | 1646 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
f3db423d LW |
1647 | |
1648 | if (!spec->hp_independent_mode) | |
1649 | snd_hda_codec_amp_stereo( | |
1650 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
1651 | hp_present ? HDA_AMP_MUTE : 0); | |
1652 | } | |
1653 | ||
69e52a80 HW |
1654 | static void via_gpio_control(struct hda_codec *codec) |
1655 | { | |
1656 | unsigned int gpio_data; | |
1657 | unsigned int vol_counter; | |
1658 | unsigned int vol; | |
1659 | unsigned int master_vol; | |
1660 | ||
1661 | struct via_spec *spec = codec->spec; | |
1662 | ||
1663 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, | |
1664 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; | |
1665 | ||
1666 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, | |
1667 | 0xF84, 0) & 0x3F0000) >> 16; | |
1668 | ||
1669 | vol = vol_counter & 0x1F; | |
1670 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, | |
1671 | AC_VERB_GET_AMP_GAIN_MUTE, | |
1672 | AC_AMP_GET_INPUT); | |
1673 | ||
1674 | if (gpio_data == 0x02) { | |
1675 | /* unmute line out */ | |
1676 | snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], | |
1677 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | |
1678 | ||
1679 | if (vol_counter & 0x20) { | |
1680 | /* decrease volume */ | |
1681 | if (vol > master_vol) | |
1682 | vol = master_vol; | |
1683 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, | |
1684 | 0, HDA_AMP_VOLMASK, | |
1685 | master_vol-vol); | |
1686 | } else { | |
1687 | /* increase volume */ | |
1688 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, | |
1689 | HDA_AMP_VOLMASK, | |
1690 | ((master_vol+vol) > 0x2A) ? 0x2A : | |
1691 | (master_vol+vol)); | |
1692 | } | |
1693 | } else if (!(gpio_data & 0x02)) { | |
1694 | /* mute line out */ | |
1695 | snd_hda_codec_amp_stereo(codec, | |
1696 | spec->autocfg.line_out_pins[0], | |
1697 | HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
1698 | HDA_AMP_MUTE); | |
1699 | } | |
1700 | } | |
1701 | ||
25eaba2f LW |
1702 | /* mute Internal-Speaker if HP is plugged */ |
1703 | static void via_speaker_automute(struct hda_codec *codec) | |
1704 | { | |
1705 | unsigned int hp_present; | |
1706 | struct via_spec *spec = codec->spec; | |
1707 | ||
27439ce7 | 1708 | if (!VT2002P_COMPATIBLE(spec)) |
25eaba2f LW |
1709 | return; |
1710 | ||
d56757ab | 1711 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
25eaba2f LW |
1712 | |
1713 | if (!spec->hp_independent_mode) { | |
1714 | struct snd_ctl_elem_id id; | |
1715 | snd_hda_codec_amp_stereo( | |
1716 | codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0, | |
1717 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); | |
1718 | /* notify change */ | |
1719 | memset(&id, 0, sizeof(id)); | |
1720 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
1721 | strcpy(id.name, "Speaker Playback Switch"); | |
1722 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, | |
1723 | &id); | |
1724 | } | |
1725 | } | |
1726 | ||
1727 | /* mute line-out and internal speaker if HP is plugged */ | |
1728 | static void via_hp_bind_automute(struct hda_codec *codec) | |
1729 | { | |
01a1796b | 1730 | /* use long instead of int below just to avoid an internal compiler |
1731 | * error with gcc 4.0.x | |
1732 | */ | |
1733 | unsigned long hp_present, present = 0; | |
25eaba2f LW |
1734 | struct via_spec *spec = codec->spec; |
1735 | int i; | |
1736 | ||
1737 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) | |
1738 | return; | |
1739 | ||
d56757ab | 1740 | hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
25eaba2f | 1741 | |
d56757ab | 1742 | present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]); |
25eaba2f LW |
1743 | |
1744 | if (!spec->hp_independent_mode) { | |
1745 | /* Mute Line-Outs */ | |
1746 | for (i = 0; i < spec->autocfg.line_outs; i++) | |
1747 | snd_hda_codec_amp_stereo( | |
1748 | codec, spec->autocfg.line_out_pins[i], | |
1749 | HDA_OUTPUT, 0, | |
1750 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); | |
1751 | if (hp_present) | |
1752 | present = hp_present; | |
1753 | } | |
1754 | /* Speakers */ | |
1755 | for (i = 0; i < spec->autocfg.speaker_outs; i++) | |
1756 | snd_hda_codec_amp_stereo( | |
1757 | codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0, | |
1758 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); | |
1759 | } | |
1760 | ||
1761 | ||
69e52a80 HW |
1762 | /* unsolicited event for jack sensing */ |
1763 | static void via_unsol_event(struct hda_codec *codec, | |
1764 | unsigned int res) | |
1765 | { | |
1766 | res >>= 26; | |
ec7e7e42 | 1767 | |
a34df19a | 1768 | if (res & VIA_JACK_EVENT) |
3e95b9ab | 1769 | set_widgets_power_state(codec); |
ec7e7e42 LW |
1770 | |
1771 | res &= ~VIA_JACK_EVENT; | |
1772 | ||
1773 | if (res == VIA_HP_EVENT) | |
1774 | via_hp_automute(codec); | |
1775 | else if (res == VIA_GPIO_EVENT) | |
1776 | via_gpio_control(codec); | |
1777 | else if (res == VIA_MONO_EVENT) | |
f3db423d | 1778 | via_mono_automute(codec); |
ec7e7e42 | 1779 | else if (res == VIA_SPEAKER_EVENT) |
25eaba2f | 1780 | via_speaker_automute(codec); |
ec7e7e42 | 1781 | else if (res == VIA_BIND_HP_EVENT) |
25eaba2f | 1782 | via_hp_bind_automute(codec); |
69e52a80 HW |
1783 | } |
1784 | ||
c577b8a1 JC |
1785 | static int via_init(struct hda_codec *codec) |
1786 | { | |
1787 | struct via_spec *spec = codec->spec; | |
69e52a80 HW |
1788 | int i; |
1789 | for (i = 0; i < spec->num_iverbs; i++) | |
1790 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
1791 | ||
f7278fd0 JC |
1792 | /* Lydia Add for EAPD enable */ |
1793 | if (!spec->dig_in_nid) { /* No Digital In connection */ | |
55d1d6c1 TI |
1794 | if (spec->dig_in_pin) { |
1795 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, | |
f7278fd0 | 1796 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
12b74c80 | 1797 | PIN_OUT); |
55d1d6c1 | 1798 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
f7278fd0 JC |
1799 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
1800 | } | |
12b74c80 TI |
1801 | } else /* enable SPDIF-input pin */ |
1802 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, | |
1803 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | |
f7278fd0 | 1804 | |
9da29271 TI |
1805 | /* assign slave outs */ |
1806 | if (spec->slave_dig_outs[0]) | |
1807 | codec->slave_dig_outs = spec->slave_dig_outs; | |
5691ec7f | 1808 | |
377ff31a | 1809 | return 0; |
c577b8a1 JC |
1810 | } |
1811 | ||
1f2e99fe LW |
1812 | #ifdef SND_HDA_NEEDS_RESUME |
1813 | static int via_suspend(struct hda_codec *codec, pm_message_t state) | |
1814 | { | |
1815 | struct via_spec *spec = codec->spec; | |
1816 | vt1708_stop_hp_work(spec); | |
1817 | return 0; | |
1818 | } | |
1819 | #endif | |
1820 | ||
cb53c626 TI |
1821 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1822 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) | |
1823 | { | |
1824 | struct via_spec *spec = codec->spec; | |
1825 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | |
1826 | } | |
1827 | #endif | |
1828 | ||
c577b8a1 JC |
1829 | /* |
1830 | */ | |
90dd48a1 | 1831 | static const struct hda_codec_ops via_patch_ops = { |
c577b8a1 JC |
1832 | .build_controls = via_build_controls, |
1833 | .build_pcms = via_build_pcms, | |
1834 | .init = via_init, | |
1835 | .free = via_free, | |
1f2e99fe LW |
1836 | #ifdef SND_HDA_NEEDS_RESUME |
1837 | .suspend = via_suspend, | |
1838 | #endif | |
cb53c626 TI |
1839 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1840 | .check_power_status = via_check_power_status, | |
1841 | #endif | |
c577b8a1 JC |
1842 | }; |
1843 | ||
1844 | /* fill in the dac_nids table from the parsed pin configuration */ | |
1845 | static int vt1708_auto_fill_dac_nids(struct via_spec *spec, | |
1846 | const struct auto_pin_cfg *cfg) | |
1847 | { | |
1848 | int i; | |
1849 | hda_nid_t nid; | |
1850 | ||
1851 | spec->multiout.num_dacs = cfg->line_outs; | |
1852 | ||
1853 | spec->multiout.dac_nids = spec->private_dac_nids; | |
377ff31a LW |
1854 | |
1855 | for (i = 0; i < 4; i++) { | |
c577b8a1 JC |
1856 | nid = cfg->line_out_pins[i]; |
1857 | if (nid) { | |
1858 | /* config dac list */ | |
1859 | switch (i) { | |
1860 | case AUTO_SEQ_FRONT: | |
dda14410 | 1861 | spec->private_dac_nids[i] = 0x10; |
c577b8a1 JC |
1862 | break; |
1863 | case AUTO_SEQ_CENLFE: | |
dda14410 | 1864 | spec->private_dac_nids[i] = 0x12; |
c577b8a1 JC |
1865 | break; |
1866 | case AUTO_SEQ_SURROUND: | |
dda14410 | 1867 | spec->private_dac_nids[i] = 0x11; |
c577b8a1 JC |
1868 | break; |
1869 | case AUTO_SEQ_SIDE: | |
dda14410 | 1870 | spec->private_dac_nids[i] = 0x13; |
c577b8a1 JC |
1871 | break; |
1872 | } | |
1873 | } | |
1874 | } | |
1875 | ||
1876 | return 0; | |
1877 | } | |
1878 | ||
1879 | /* add playback controls from the parsed DAC table */ | |
1880 | static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, | |
1881 | const struct auto_pin_cfg *cfg) | |
1882 | { | |
1883 | char name[32]; | |
ea734963 TI |
1884 | static const char * const chname[4] = { |
1885 | "Front", "Surround", "C/LFE", "Side" | |
1886 | }; | |
9645c203 | 1887 | hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b}; |
c577b8a1 JC |
1888 | int i, err; |
1889 | ||
1890 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
1891 | nid = cfg->line_out_pins[i]; | |
1892 | ||
1893 | if (!nid) | |
1894 | continue; | |
377ff31a | 1895 | |
9645c203 | 1896 | nid_vol = nid_vols[i]; |
c577b8a1 JC |
1897 | |
1898 | if (i == AUTO_SEQ_CENLFE) { | |
1899 | /* Center/LFE */ | |
1900 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
f7278fd0 JC |
1901 | "Center Playback Volume", |
1902 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
1903 | HDA_OUTPUT)); | |
c577b8a1 JC |
1904 | if (err < 0) |
1905 | return err; | |
1906 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1907 | "LFE Playback Volume", | |
f7278fd0 JC |
1908 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
1909 | HDA_OUTPUT)); | |
c577b8a1 JC |
1910 | if (err < 0) |
1911 | return err; | |
1912 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1913 | "Center Playback Switch", | |
f7278fd0 JC |
1914 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
1915 | HDA_OUTPUT)); | |
c577b8a1 JC |
1916 | if (err < 0) |
1917 | return err; | |
1918 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1919 | "LFE Playback Switch", | |
f7278fd0 JC |
1920 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
1921 | HDA_OUTPUT)); | |
c577b8a1 JC |
1922 | if (err < 0) |
1923 | return err; | |
377ff31a | 1924 | } else if (i == AUTO_SEQ_FRONT) { |
c577b8a1 JC |
1925 | /* add control to mixer index 0 */ |
1926 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1927 | "Master Front Playback Volume", | |
9645c203 | 1928 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 1929 | HDA_INPUT)); |
c577b8a1 JC |
1930 | if (err < 0) |
1931 | return err; | |
1932 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1933 | "Master Front Playback Switch", | |
9645c203 | 1934 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 1935 | HDA_INPUT)); |
c577b8a1 JC |
1936 | if (err < 0) |
1937 | return err; | |
377ff31a | 1938 | |
c577b8a1 JC |
1939 | /* add control to PW3 */ |
1940 | sprintf(name, "%s Playback Volume", chname[i]); | |
1941 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
f7278fd0 JC |
1942 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
1943 | HDA_OUTPUT)); | |
c577b8a1 JC |
1944 | if (err < 0) |
1945 | return err; | |
1946 | sprintf(name, "%s Playback Switch", chname[i]); | |
1947 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
f7278fd0 JC |
1948 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
1949 | HDA_OUTPUT)); | |
c577b8a1 JC |
1950 | if (err < 0) |
1951 | return err; | |
1952 | } else { | |
1953 | sprintf(name, "%s Playback Volume", chname[i]); | |
1954 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
f7278fd0 JC |
1955 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1956 | HDA_OUTPUT)); | |
c577b8a1 JC |
1957 | if (err < 0) |
1958 | return err; | |
1959 | sprintf(name, "%s Playback Switch", chname[i]); | |
1960 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
f7278fd0 JC |
1961 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1962 | HDA_OUTPUT)); | |
c577b8a1 JC |
1963 | if (err < 0) |
1964 | return err; | |
1965 | } | |
1966 | } | |
1967 | ||
1968 | return 0; | |
1969 | } | |
1970 | ||
0aa62aef HW |
1971 | static void create_hp_imux(struct via_spec *spec) |
1972 | { | |
1973 | int i; | |
1974 | struct hda_input_mux *imux = &spec->private_imux[1]; | |
ea734963 | 1975 | static const char * const texts[] = { "OFF", "ON", NULL}; |
0aa62aef HW |
1976 | |
1977 | /* for hp mode select */ | |
10a20af7 TI |
1978 | for (i = 0; texts[i]; i++) |
1979 | snd_hda_add_imux_item(imux, texts[i], i, NULL); | |
0aa62aef HW |
1980 | |
1981 | spec->hp_mux = &spec->private_imux[1]; | |
1982 | } | |
1983 | ||
c577b8a1 JC |
1984 | static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
1985 | { | |
1986 | int err; | |
1987 | ||
1988 | if (!pin) | |
1989 | return 0; | |
1990 | ||
1991 | spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ | |
cdc1784d | 1992 | spec->hp_independent_mode_index = 1; |
c577b8a1 JC |
1993 | |
1994 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1995 | "Headphone Playback Volume", | |
1996 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
1997 | if (err < 0) | |
1998 | return err; | |
1999 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2000 | "Headphone Playback Switch", | |
2001 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
2002 | if (err < 0) | |
2003 | return err; | |
2004 | ||
0aa62aef HW |
2005 | create_hp_imux(spec); |
2006 | ||
c577b8a1 JC |
2007 | return 0; |
2008 | } | |
2009 | ||
a766d0d7 TI |
2010 | static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, |
2011 | hda_nid_t nid) | |
2012 | { | |
2013 | hda_nid_t conn[HDA_MAX_NUM_INPUTS]; | |
2014 | int i, nums; | |
2015 | ||
2016 | nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); | |
2017 | for (i = 0; i < nums; i++) | |
2018 | if (conn[i] == nid) | |
2019 | return i; | |
2020 | return -1; | |
2021 | } | |
2022 | ||
2023 | /* look for ADCs */ | |
2024 | static int via_fill_adcs(struct hda_codec *codec) | |
2025 | { | |
2026 | struct via_spec *spec = codec->spec; | |
2027 | hda_nid_t nid = codec->start_nid; | |
2028 | int i; | |
2029 | ||
2030 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
2031 | unsigned int wcaps = get_wcaps(codec, nid); | |
2032 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | |
2033 | continue; | |
2034 | if (wcaps & AC_WCAP_DIGITAL) | |
2035 | continue; | |
2036 | if (!(wcaps & AC_WCAP_CONN_LIST)) | |
2037 | continue; | |
2038 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) | |
2039 | return -ENOMEM; | |
2040 | spec->adc_nids[spec->num_adc_nids++] = nid; | |
2041 | } | |
2042 | return 0; | |
2043 | } | |
2044 | ||
2045 | static int get_mux_nids(struct hda_codec *codec); | |
2046 | ||
c577b8a1 | 2047 | /* create playback/capture controls for input pins */ |
10a20af7 | 2048 | static int vt_auto_create_analog_input_ctls(struct hda_codec *codec, |
f3268512 | 2049 | const struct auto_pin_cfg *cfg, |
a766d0d7 | 2050 | hda_nid_t mix_nid) |
c577b8a1 | 2051 | { |
10a20af7 | 2052 | struct via_spec *spec = codec->spec; |
0aa62aef | 2053 | struct hda_input_mux *imux = &spec->private_imux[0]; |
a766d0d7 TI |
2054 | int i, err, idx, idx2, type, type_idx = 0; |
2055 | hda_nid_t cap_nid; | |
2056 | hda_nid_t pin_idxs[8]; | |
2057 | int num_idxs; | |
2058 | ||
2059 | err = via_fill_adcs(codec); | |
2060 | if (err < 0) | |
2061 | return err; | |
2062 | err = get_mux_nids(codec); | |
2063 | if (err < 0) | |
2064 | return err; | |
2065 | cap_nid = spec->mux_nids[0]; | |
2066 | ||
2067 | num_idxs = snd_hda_get_connections(codec, cap_nid, pin_idxs, | |
2068 | ARRAY_SIZE(pin_idxs)); | |
2069 | if (num_idxs <= 0) | |
2070 | return 0; | |
c577b8a1 JC |
2071 | |
2072 | /* for internal loopback recording select */ | |
f3268512 | 2073 | for (idx = 0; idx < num_idxs; idx++) { |
a766d0d7 | 2074 | if (pin_idxs[idx] == mix_nid) { |
10a20af7 | 2075 | snd_hda_add_imux_item(imux, "Stereo Mixer", idx, NULL); |
f3268512 TI |
2076 | break; |
2077 | } | |
2078 | } | |
c577b8a1 | 2079 | |
7b315bb4 | 2080 | for (i = 0; i < cfg->num_inputs; i++) { |
10a20af7 | 2081 | const char *label; |
7b315bb4 | 2082 | type = cfg->inputs[i].type; |
f3268512 | 2083 | for (idx = 0; idx < num_idxs; idx++) |
7b315bb4 | 2084 | if (pin_idxs[idx] == cfg->inputs[i].pin) |
f3268512 TI |
2085 | break; |
2086 | if (idx >= num_idxs) | |
2087 | continue; | |
7b315bb4 TI |
2088 | if (i > 0 && type == cfg->inputs[i - 1].type) |
2089 | type_idx++; | |
2090 | else | |
2091 | type_idx = 0; | |
10a20af7 | 2092 | label = hda_get_autocfg_input_label(codec, cfg, i); |
a766d0d7 TI |
2093 | idx2 = get_connection_index(codec, mix_nid, pin_idxs[idx]); |
2094 | if (idx2 >= 0) | |
16922281 | 2095 | err = via_new_analog_input(spec, label, type_idx, |
a766d0d7 | 2096 | idx2, mix_nid); |
c577b8a1 JC |
2097 | if (err < 0) |
2098 | return err; | |
10a20af7 | 2099 | snd_hda_add_imux_item(imux, label, idx, NULL); |
c577b8a1 JC |
2100 | } |
2101 | return 0; | |
2102 | } | |
2103 | ||
f3268512 | 2104 | /* create playback/capture controls for input pins */ |
10a20af7 | 2105 | static int vt1708_auto_create_analog_input_ctls(struct hda_codec *codec, |
f3268512 TI |
2106 | const struct auto_pin_cfg *cfg) |
2107 | { | |
a766d0d7 | 2108 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x17); |
f3268512 TI |
2109 | } |
2110 | ||
cb53c626 | 2111 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
90dd48a1 | 2112 | static const struct hda_amp_list vt1708_loopbacks[] = { |
cb53c626 TI |
2113 | { 0x17, HDA_INPUT, 1 }, |
2114 | { 0x17, HDA_INPUT, 2 }, | |
2115 | { 0x17, HDA_INPUT, 3 }, | |
2116 | { 0x17, HDA_INPUT, 4 }, | |
2117 | { } /* end */ | |
2118 | }; | |
2119 | #endif | |
2120 | ||
76d9b0dd HW |
2121 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
2122 | { | |
2123 | unsigned int def_conf; | |
2124 | unsigned char seqassoc; | |
2125 | ||
2f334f92 | 2126 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
76d9b0dd HW |
2127 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
2128 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); | |
82ef9e45 LW |
2129 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
2130 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { | |
2131 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); | |
2132 | snd_hda_codec_set_pincfg(codec, nid, def_conf); | |
76d9b0dd HW |
2133 | } |
2134 | ||
2135 | return; | |
2136 | } | |
2137 | ||
e06e5a29 | 2138 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
1f2e99fe LW |
2139 | struct snd_ctl_elem_value *ucontrol) |
2140 | { | |
2141 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2142 | struct via_spec *spec = codec->spec; | |
2143 | ||
2144 | if (spec->codec_type != VT1708) | |
2145 | return 0; | |
e06e5a29 | 2146 | spec->vt1708_jack_detect = |
1f2e99fe | 2147 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
e06e5a29 | 2148 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
1f2e99fe LW |
2149 | return 0; |
2150 | } | |
2151 | ||
e06e5a29 | 2152 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
1f2e99fe LW |
2153 | struct snd_ctl_elem_value *ucontrol) |
2154 | { | |
2155 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2156 | struct via_spec *spec = codec->spec; | |
2157 | int change; | |
2158 | ||
2159 | if (spec->codec_type != VT1708) | |
2160 | return 0; | |
e06e5a29 | 2161 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
1f2e99fe | 2162 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
e06e5a29 TI |
2163 | == !spec->vt1708_jack_detect; |
2164 | if (spec->vt1708_jack_detect) { | |
1f2e99fe LW |
2165 | mute_aa_path(codec, 1); |
2166 | notify_aa_path_ctls(codec); | |
2167 | } | |
2168 | return change; | |
2169 | } | |
2170 | ||
e06e5a29 TI |
2171 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
2172 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2173 | .name = "Jack Detect", | |
2174 | .count = 1, | |
2175 | .info = snd_ctl_boolean_mono_info, | |
2176 | .get = vt1708_jack_detect_get, | |
2177 | .put = vt1708_jack_detect_put, | |
1f2e99fe LW |
2178 | }; |
2179 | ||
c577b8a1 JC |
2180 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
2181 | { | |
2182 | struct via_spec *spec = codec->spec; | |
2183 | int err; | |
2184 | ||
76d9b0dd HW |
2185 | /* Add HP and CD pin config connect bit re-config action */ |
2186 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); | |
2187 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); | |
2188 | ||
c577b8a1 JC |
2189 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
2190 | if (err < 0) | |
2191 | return err; | |
2192 | err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg); | |
2193 | if (err < 0) | |
2194 | return err; | |
2195 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
2196 | return 0; /* can't find valid BIOS pin config */ | |
2197 | ||
2198 | err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
2199 | if (err < 0) | |
2200 | return err; | |
2201 | err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
2202 | if (err < 0) | |
2203 | return err; | |
10a20af7 | 2204 | err = vt1708_auto_create_analog_input_ctls(codec, &spec->autocfg); |
1f2e99fe LW |
2205 | if (err < 0) |
2206 | return err; | |
2207 | /* add jack detect on/off control */ | |
e06e5a29 TI |
2208 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
2209 | return -ENOMEM; | |
c577b8a1 JC |
2210 | |
2211 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2212 | ||
0852d7a6 | 2213 | if (spec->autocfg.dig_outs) |
c577b8a1 | 2214 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
55d1d6c1 | 2215 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
c577b8a1 JC |
2216 | if (spec->autocfg.dig_in_pin) |
2217 | spec->dig_in_nid = VT1708_DIGIN_NID; | |
2218 | ||
603c4019 TI |
2219 | if (spec->kctls.list) |
2220 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 2221 | |
69e52a80 | 2222 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
c577b8a1 | 2223 | |
0aa62aef HW |
2224 | spec->input_mux = &spec->private_imux[0]; |
2225 | ||
f8fdd495 | 2226 | if (spec->hp_mux) |
3d83e577 | 2227 | via_hp_build(codec); |
c577b8a1 | 2228 | |
5b0cb1d8 | 2229 | via_smart51_build(spec); |
c577b8a1 JC |
2230 | return 1; |
2231 | } | |
2232 | ||
2233 | /* init callback for auto-configuration model -- overriding the default init */ | |
2234 | static int via_auto_init(struct hda_codec *codec) | |
2235 | { | |
25eaba2f LW |
2236 | struct via_spec *spec = codec->spec; |
2237 | ||
c577b8a1 JC |
2238 | via_init(codec); |
2239 | via_auto_init_multi_out(codec); | |
2240 | via_auto_init_hp_out(codec); | |
2241 | via_auto_init_analog_input(codec); | |
11890956 LW |
2242 | |
2243 | if (VT2002P_COMPATIBLE(spec)) { | |
25eaba2f LW |
2244 | via_hp_bind_automute(codec); |
2245 | } else { | |
2246 | via_hp_automute(codec); | |
2247 | via_speaker_automute(codec); | |
2248 | } | |
2249 | ||
c577b8a1 JC |
2250 | return 0; |
2251 | } | |
2252 | ||
1f2e99fe LW |
2253 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
2254 | { | |
2255 | struct via_spec *spec = container_of(work, struct via_spec, | |
2256 | vt1708_hp_work.work); | |
2257 | if (spec->codec_type != VT1708) | |
2258 | return; | |
2259 | /* if jack state toggled */ | |
2260 | if (spec->vt1708_hp_present | |
d56757ab | 2261 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
1f2e99fe LW |
2262 | spec->vt1708_hp_present ^= 1; |
2263 | via_hp_automute(spec->codec); | |
2264 | } | |
2265 | vt1708_start_hp_work(spec); | |
2266 | } | |
2267 | ||
337b9d02 TI |
2268 | static int get_mux_nids(struct hda_codec *codec) |
2269 | { | |
2270 | struct via_spec *spec = codec->spec; | |
2271 | hda_nid_t nid, conn[8]; | |
2272 | unsigned int type; | |
2273 | int i, n; | |
2274 | ||
2275 | for (i = 0; i < spec->num_adc_nids; i++) { | |
2276 | nid = spec->adc_nids[i]; | |
2277 | while (nid) { | |
a22d543a | 2278 | type = get_wcaps_type(get_wcaps(codec, nid)); |
1c55d521 TI |
2279 | if (type == AC_WID_PIN) |
2280 | break; | |
337b9d02 TI |
2281 | n = snd_hda_get_connections(codec, nid, conn, |
2282 | ARRAY_SIZE(conn)); | |
2283 | if (n <= 0) | |
2284 | break; | |
2285 | if (n > 1) { | |
2286 | spec->mux_nids[i] = nid; | |
2287 | break; | |
2288 | } | |
2289 | nid = conn[0]; | |
2290 | } | |
2291 | } | |
1c55d521 | 2292 | return 0; |
337b9d02 TI |
2293 | } |
2294 | ||
c577b8a1 JC |
2295 | static int patch_vt1708(struct hda_codec *codec) |
2296 | { | |
2297 | struct via_spec *spec; | |
2298 | int err; | |
2299 | ||
2300 | /* create a codec specific record */ | |
5b0cb1d8 | 2301 | spec = via_new_spec(codec); |
c577b8a1 JC |
2302 | if (spec == NULL) |
2303 | return -ENOMEM; | |
2304 | ||
c577b8a1 JC |
2305 | /* automatic parse from the BIOS config */ |
2306 | err = vt1708_parse_auto_config(codec); | |
2307 | if (err < 0) { | |
2308 | via_free(codec); | |
2309 | return err; | |
2310 | } else if (!err) { | |
2311 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
2312 | "from BIOS. Using genenic mode...\n"); | |
2313 | } | |
2314 | ||
377ff31a | 2315 | |
c577b8a1 JC |
2316 | spec->stream_name_analog = "VT1708 Analog"; |
2317 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; | |
bc9b5623 TI |
2318 | /* disable 32bit format on VT1708 */ |
2319 | if (codec->vendor_id == 0x11061708) | |
2320 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; | |
c577b8a1 JC |
2321 | spec->stream_analog_capture = &vt1708_pcm_analog_capture; |
2322 | ||
2323 | spec->stream_name_digital = "VT1708 Digital"; | |
2324 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; | |
2325 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; | |
2326 | ||
a766d0d7 | 2327 | if (spec->adc_nids && spec->input_mux) { |
c577b8a1 JC |
2328 | spec->mixers[spec->num_mixers] = vt1708_capture_mixer; |
2329 | spec->num_mixers++; | |
2330 | } | |
2331 | ||
2332 | codec->patch_ops = via_patch_ops; | |
2333 | ||
2334 | codec->patch_ops.init = via_auto_init; | |
cb53c626 TI |
2335 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2336 | spec->loopback.amplist = vt1708_loopbacks; | |
2337 | #endif | |
1f2e99fe | 2338 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
c577b8a1 JC |
2339 | return 0; |
2340 | } | |
2341 | ||
2342 | /* capture mixer elements */ | |
90dd48a1 | 2343 | static const struct snd_kcontrol_new vt1709_capture_mixer[] = { |
c577b8a1 JC |
2344 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), |
2345 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), | |
2346 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), | |
2347 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), | |
2348 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), | |
2349 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), | |
2350 | { | |
2351 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2352 | /* The multiple "Capture Source" controls confuse alsamixer | |
2353 | * So call somewhat different.. | |
c577b8a1 JC |
2354 | */ |
2355 | /* .name = "Capture Source", */ | |
2356 | .name = "Input Source", | |
2357 | .count = 1, | |
2358 | .info = via_mux_enum_info, | |
2359 | .get = via_mux_enum_get, | |
2360 | .put = via_mux_enum_put, | |
2361 | }, | |
2362 | { } /* end */ | |
2363 | }; | |
2364 | ||
90dd48a1 | 2365 | static const struct hda_verb vt1709_uniwill_init_verbs[] = { |
a34df19a LW |
2366 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
2367 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
69e52a80 HW |
2368 | { } |
2369 | }; | |
2370 | ||
c577b8a1 JC |
2371 | /* |
2372 | * generic initialization of ADC, input mixers and output mixers | |
2373 | */ | |
90dd48a1 | 2374 | static const struct hda_verb vt1709_10ch_volume_init_verbs[] = { |
c577b8a1 JC |
2375 | /* |
2376 | * Unmute ADC0-2 and set the default input to mic-in | |
2377 | */ | |
2378 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2379 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2380 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2381 | ||
2382 | ||
f7278fd0 | 2383 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
c577b8a1 JC |
2384 | * mixer widget |
2385 | */ | |
2386 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
f7278fd0 JC |
2387 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
2388 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2389 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2390 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2391 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
c577b8a1 JC |
2392 | |
2393 | /* | |
2394 | * Set up output selector (0x1a, 0x1b, 0x29) | |
2395 | */ | |
2396 | /* set vol=0 to output mixers */ | |
2397 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2398 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2399 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2400 | ||
2401 | /* | |
2402 | * Unmute PW3 and PW4 | |
2403 | */ | |
2404 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2405 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2406 | ||
bfdc675a LW |
2407 | /* Set input of PW4 as MW0 */ |
2408 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
2409 | /* PW9 Output enable */ |
2410 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2411 | { } | |
2412 | }; | |
2413 | ||
90dd48a1 | 2414 | static const struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { |
c577b8a1 JC |
2415 | .substreams = 1, |
2416 | .channels_min = 2, | |
2417 | .channels_max = 10, | |
2418 | .nid = 0x10, /* NID to query formats and rates */ | |
2419 | .ops = { | |
2420 | .open = via_playback_pcm_open, | |
c873cc25 LW |
2421 | .prepare = via_playback_multi_pcm_prepare, |
2422 | .cleanup = via_playback_multi_pcm_cleanup, | |
c577b8a1 JC |
2423 | }, |
2424 | }; | |
2425 | ||
90dd48a1 | 2426 | static const struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { |
c577b8a1 JC |
2427 | .substreams = 1, |
2428 | .channels_min = 2, | |
2429 | .channels_max = 6, | |
2430 | .nid = 0x10, /* NID to query formats and rates */ | |
2431 | .ops = { | |
2432 | .open = via_playback_pcm_open, | |
c873cc25 LW |
2433 | .prepare = via_playback_multi_pcm_prepare, |
2434 | .cleanup = via_playback_multi_pcm_cleanup, | |
c577b8a1 JC |
2435 | }, |
2436 | }; | |
2437 | ||
90dd48a1 | 2438 | static const struct hda_pcm_stream vt1709_pcm_analog_capture = { |
c577b8a1 JC |
2439 | .substreams = 2, |
2440 | .channels_min = 2, | |
2441 | .channels_max = 2, | |
2442 | .nid = 0x14, /* NID to query formats and rates */ | |
2443 | .ops = { | |
2444 | .prepare = via_capture_pcm_prepare, | |
2445 | .cleanup = via_capture_pcm_cleanup | |
2446 | }, | |
2447 | }; | |
2448 | ||
90dd48a1 | 2449 | static const struct hda_pcm_stream vt1709_pcm_digital_playback = { |
c577b8a1 JC |
2450 | .substreams = 1, |
2451 | .channels_min = 2, | |
2452 | .channels_max = 2, | |
2453 | /* NID is set in via_build_pcms */ | |
2454 | .ops = { | |
2455 | .open = via_dig_playback_pcm_open, | |
2456 | .close = via_dig_playback_pcm_close | |
2457 | }, | |
2458 | }; | |
2459 | ||
90dd48a1 | 2460 | static const struct hda_pcm_stream vt1709_pcm_digital_capture = { |
c577b8a1 JC |
2461 | .substreams = 1, |
2462 | .channels_min = 2, | |
2463 | .channels_max = 2, | |
2464 | }; | |
2465 | ||
2466 | static int vt1709_auto_fill_dac_nids(struct via_spec *spec, | |
2467 | const struct auto_pin_cfg *cfg) | |
2468 | { | |
2469 | int i; | |
2470 | hda_nid_t nid; | |
2471 | ||
2472 | if (cfg->line_outs == 4) /* 10 channels */ | |
2473 | spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */ | |
2474 | else if (cfg->line_outs == 3) /* 6 channels */ | |
2475 | spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */ | |
2476 | ||
2477 | spec->multiout.dac_nids = spec->private_dac_nids; | |
2478 | ||
2479 | if (cfg->line_outs == 4) { /* 10 channels */ | |
2480 | for (i = 0; i < cfg->line_outs; i++) { | |
2481 | nid = cfg->line_out_pins[i]; | |
2482 | if (nid) { | |
2483 | /* config dac list */ | |
2484 | switch (i) { | |
2485 | case AUTO_SEQ_FRONT: | |
2486 | /* AOW0 */ | |
dda14410 | 2487 | spec->private_dac_nids[i] = 0x10; |
c577b8a1 JC |
2488 | break; |
2489 | case AUTO_SEQ_CENLFE: | |
2490 | /* AOW2 */ | |
dda14410 | 2491 | spec->private_dac_nids[i] = 0x12; |
c577b8a1 JC |
2492 | break; |
2493 | case AUTO_SEQ_SURROUND: | |
2494 | /* AOW3 */ | |
dda14410 | 2495 | spec->private_dac_nids[i] = 0x11; |
c577b8a1 JC |
2496 | break; |
2497 | case AUTO_SEQ_SIDE: | |
2498 | /* AOW1 */ | |
dda14410 | 2499 | spec->private_dac_nids[i] = 0x27; |
c577b8a1 JC |
2500 | break; |
2501 | default: | |
2502 | break; | |
2503 | } | |
2504 | } | |
2505 | } | |
dda14410 | 2506 | spec->private_dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ |
c577b8a1 JC |
2507 | |
2508 | } else if (cfg->line_outs == 3) { /* 6 channels */ | |
377ff31a | 2509 | for (i = 0; i < cfg->line_outs; i++) { |
c577b8a1 JC |
2510 | nid = cfg->line_out_pins[i]; |
2511 | if (nid) { | |
2512 | /* config dac list */ | |
377ff31a | 2513 | switch (i) { |
c577b8a1 JC |
2514 | case AUTO_SEQ_FRONT: |
2515 | /* AOW0 */ | |
dda14410 | 2516 | spec->private_dac_nids[i] = 0x10; |
c577b8a1 JC |
2517 | break; |
2518 | case AUTO_SEQ_CENLFE: | |
2519 | /* AOW2 */ | |
dda14410 | 2520 | spec->private_dac_nids[i] = 0x12; |
c577b8a1 JC |
2521 | break; |
2522 | case AUTO_SEQ_SURROUND: | |
2523 | /* AOW1 */ | |
dda14410 | 2524 | spec->private_dac_nids[i] = 0x11; |
c577b8a1 JC |
2525 | break; |
2526 | default: | |
2527 | break; | |
2528 | } | |
2529 | } | |
2530 | } | |
2531 | } | |
2532 | ||
2533 | return 0; | |
2534 | } | |
2535 | ||
2536 | /* add playback controls from the parsed DAC table */ | |
2537 | static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, | |
2538 | const struct auto_pin_cfg *cfg) | |
2539 | { | |
2540 | char name[32]; | |
ea734963 TI |
2541 | static const char * const chname[4] = { |
2542 | "Front", "Surround", "C/LFE", "Side" | |
2543 | }; | |
4483a2f5 | 2544 | hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29}; |
c577b8a1 JC |
2545 | int i, err; |
2546 | ||
2547 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
2548 | nid = cfg->line_out_pins[i]; | |
2549 | ||
377ff31a | 2550 | if (!nid) |
c577b8a1 JC |
2551 | continue; |
2552 | ||
4483a2f5 LW |
2553 | nid_vol = nid_vols[i]; |
2554 | ||
c577b8a1 JC |
2555 | if (i == AUTO_SEQ_CENLFE) { |
2556 | /* Center/LFE */ | |
2557 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2558 | "Center Playback Volume", | |
4483a2f5 | 2559 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
f7278fd0 | 2560 | HDA_OUTPUT)); |
c577b8a1 JC |
2561 | if (err < 0) |
2562 | return err; | |
2563 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2564 | "LFE Playback Volume", | |
4483a2f5 | 2565 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
f7278fd0 | 2566 | HDA_OUTPUT)); |
c577b8a1 JC |
2567 | if (err < 0) |
2568 | return err; | |
2569 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2570 | "Center Playback Switch", | |
4483a2f5 | 2571 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
f7278fd0 | 2572 | HDA_OUTPUT)); |
c577b8a1 JC |
2573 | if (err < 0) |
2574 | return err; | |
2575 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2576 | "LFE Playback Switch", | |
4483a2f5 | 2577 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
f7278fd0 | 2578 | HDA_OUTPUT)); |
c577b8a1 JC |
2579 | if (err < 0) |
2580 | return err; | |
377ff31a | 2581 | } else if (i == AUTO_SEQ_FRONT) { |
4483a2f5 | 2582 | /* ADD control to mixer index 0 */ |
c577b8a1 JC |
2583 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
2584 | "Master Front Playback Volume", | |
4483a2f5 | 2585 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 2586 | HDA_INPUT)); |
c577b8a1 JC |
2587 | if (err < 0) |
2588 | return err; | |
2589 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2590 | "Master Front Playback Switch", | |
4483a2f5 | 2591 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 2592 | HDA_INPUT)); |
c577b8a1 JC |
2593 | if (err < 0) |
2594 | return err; | |
377ff31a | 2595 | |
c577b8a1 JC |
2596 | /* add control to PW3 */ |
2597 | sprintf(name, "%s Playback Volume", chname[i]); | |
2598 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
f7278fd0 JC |
2599 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
2600 | HDA_OUTPUT)); | |
c577b8a1 JC |
2601 | if (err < 0) |
2602 | return err; | |
2603 | sprintf(name, "%s Playback Switch", chname[i]); | |
2604 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
f7278fd0 JC |
2605 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
2606 | HDA_OUTPUT)); | |
c577b8a1 JC |
2607 | if (err < 0) |
2608 | return err; | |
2609 | } else if (i == AUTO_SEQ_SURROUND) { | |
2610 | sprintf(name, "%s Playback Volume", chname[i]); | |
2611 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
4483a2f5 | 2612 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 2613 | HDA_OUTPUT)); |
c577b8a1 JC |
2614 | if (err < 0) |
2615 | return err; | |
2616 | sprintf(name, "%s Playback Switch", chname[i]); | |
2617 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
4483a2f5 | 2618 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 2619 | HDA_OUTPUT)); |
c577b8a1 JC |
2620 | if (err < 0) |
2621 | return err; | |
2622 | } else if (i == AUTO_SEQ_SIDE) { | |
2623 | sprintf(name, "%s Playback Volume", chname[i]); | |
2624 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
4483a2f5 | 2625 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 2626 | HDA_OUTPUT)); |
c577b8a1 JC |
2627 | if (err < 0) |
2628 | return err; | |
2629 | sprintf(name, "%s Playback Switch", chname[i]); | |
2630 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
4483a2f5 | 2631 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
f7278fd0 | 2632 | HDA_OUTPUT)); |
c577b8a1 JC |
2633 | if (err < 0) |
2634 | return err; | |
2635 | } | |
2636 | } | |
2637 | ||
2638 | return 0; | |
2639 | } | |
2640 | ||
2641 | static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
2642 | { | |
2643 | int err; | |
2644 | ||
2645 | if (!pin) | |
2646 | return 0; | |
2647 | ||
2648 | if (spec->multiout.num_dacs == 5) /* 10 channels */ | |
2649 | spec->multiout.hp_nid = VT1709_HP_DAC_NID; | |
2650 | else if (spec->multiout.num_dacs == 3) /* 6 channels */ | |
2651 | spec->multiout.hp_nid = 0; | |
cdc1784d | 2652 | spec->hp_independent_mode_index = 1; |
c577b8a1 JC |
2653 | |
2654 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2655 | "Headphone Playback Volume", | |
2656 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
2657 | if (err < 0) | |
2658 | return err; | |
2659 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2660 | "Headphone Playback Switch", | |
2661 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
2662 | if (err < 0) | |
2663 | return err; | |
2664 | ||
2665 | return 0; | |
2666 | } | |
2667 | ||
2668 | /* create playback/capture controls for input pins */ | |
10a20af7 | 2669 | static int vt1709_auto_create_analog_input_ctls(struct hda_codec *codec, |
c577b8a1 JC |
2670 | const struct auto_pin_cfg *cfg) |
2671 | { | |
a766d0d7 | 2672 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x18); |
c577b8a1 JC |
2673 | } |
2674 | ||
2675 | static int vt1709_parse_auto_config(struct hda_codec *codec) | |
2676 | { | |
2677 | struct via_spec *spec = codec->spec; | |
2678 | int err; | |
2679 | ||
2680 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
2681 | if (err < 0) | |
2682 | return err; | |
2683 | err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg); | |
2684 | if (err < 0) | |
2685 | return err; | |
2686 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
2687 | return 0; /* can't find valid BIOS pin config */ | |
2688 | ||
2689 | err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
2690 | if (err < 0) | |
2691 | return err; | |
2692 | err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
2693 | if (err < 0) | |
2694 | return err; | |
10a20af7 | 2695 | err = vt1709_auto_create_analog_input_ctls(codec, &spec->autocfg); |
c577b8a1 JC |
2696 | if (err < 0) |
2697 | return err; | |
2698 | ||
2699 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2700 | ||
0852d7a6 | 2701 | if (spec->autocfg.dig_outs) |
c577b8a1 | 2702 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
55d1d6c1 | 2703 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
c577b8a1 JC |
2704 | if (spec->autocfg.dig_in_pin) |
2705 | spec->dig_in_nid = VT1709_DIGIN_NID; | |
2706 | ||
603c4019 TI |
2707 | if (spec->kctls.list) |
2708 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 2709 | |
0aa62aef | 2710 | spec->input_mux = &spec->private_imux[0]; |
c577b8a1 | 2711 | |
f8fdd495 | 2712 | if (spec->hp_mux) |
3d83e577 | 2713 | via_hp_build(codec); |
f8fdd495 | 2714 | |
5b0cb1d8 | 2715 | via_smart51_build(spec); |
c577b8a1 JC |
2716 | return 1; |
2717 | } | |
2718 | ||
cb53c626 | 2719 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
90dd48a1 | 2720 | static const struct hda_amp_list vt1709_loopbacks[] = { |
cb53c626 TI |
2721 | { 0x18, HDA_INPUT, 1 }, |
2722 | { 0x18, HDA_INPUT, 2 }, | |
2723 | { 0x18, HDA_INPUT, 3 }, | |
2724 | { 0x18, HDA_INPUT, 4 }, | |
2725 | { } /* end */ | |
2726 | }; | |
2727 | #endif | |
2728 | ||
c577b8a1 JC |
2729 | static int patch_vt1709_10ch(struct hda_codec *codec) |
2730 | { | |
2731 | struct via_spec *spec; | |
2732 | int err; | |
2733 | ||
2734 | /* create a codec specific record */ | |
5b0cb1d8 | 2735 | spec = via_new_spec(codec); |
c577b8a1 JC |
2736 | if (spec == NULL) |
2737 | return -ENOMEM; | |
2738 | ||
c577b8a1 JC |
2739 | err = vt1709_parse_auto_config(codec); |
2740 | if (err < 0) { | |
2741 | via_free(codec); | |
2742 | return err; | |
2743 | } else if (!err) { | |
2744 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " | |
2745 | "Using genenic mode...\n"); | |
2746 | } | |
2747 | ||
69e52a80 HW |
2748 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
2749 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; | |
c577b8a1 JC |
2750 | |
2751 | spec->stream_name_analog = "VT1709 Analog"; | |
2752 | spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; | |
2753 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; | |
2754 | ||
2755 | spec->stream_name_digital = "VT1709 Digital"; | |
2756 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; | |
2757 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; | |
2758 | ||
a766d0d7 | 2759 | if (spec->adc_nids && spec->input_mux) { |
c577b8a1 JC |
2760 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
2761 | spec->num_mixers++; | |
2762 | } | |
2763 | ||
2764 | codec->patch_ops = via_patch_ops; | |
2765 | ||
2766 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2767 | codec->patch_ops.unsol_event = via_unsol_event; |
cb53c626 TI |
2768 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2769 | spec->loopback.amplist = vt1709_loopbacks; | |
2770 | #endif | |
c577b8a1 JC |
2771 | |
2772 | return 0; | |
2773 | } | |
2774 | /* | |
2775 | * generic initialization of ADC, input mixers and output mixers | |
2776 | */ | |
90dd48a1 | 2777 | static const struct hda_verb vt1709_6ch_volume_init_verbs[] = { |
c577b8a1 JC |
2778 | /* |
2779 | * Unmute ADC0-2 and set the default input to mic-in | |
2780 | */ | |
2781 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2782 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2783 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2784 | ||
2785 | ||
2786 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2787 | * mixer widget | |
2788 | */ | |
2789 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2790 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2791 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2792 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2793 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2794 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2795 | ||
2796 | /* | |
2797 | * Set up output selector (0x1a, 0x1b, 0x29) | |
2798 | */ | |
2799 | /* set vol=0 to output mixers */ | |
2800 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2801 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2802 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2803 | ||
2804 | /* | |
2805 | * Unmute PW3 and PW4 | |
2806 | */ | |
2807 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2808 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2809 | ||
2810 | /* Set input of PW4 as MW0 */ | |
2811 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
2812 | /* PW9 Output enable */ |
2813 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2814 | { } | |
2815 | }; | |
2816 | ||
2817 | static int patch_vt1709_6ch(struct hda_codec *codec) | |
2818 | { | |
2819 | struct via_spec *spec; | |
2820 | int err; | |
2821 | ||
2822 | /* create a codec specific record */ | |
5b0cb1d8 | 2823 | spec = via_new_spec(codec); |
c577b8a1 JC |
2824 | if (spec == NULL) |
2825 | return -ENOMEM; | |
2826 | ||
c577b8a1 JC |
2827 | err = vt1709_parse_auto_config(codec); |
2828 | if (err < 0) { | |
2829 | via_free(codec); | |
2830 | return err; | |
2831 | } else if (!err) { | |
2832 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " | |
2833 | "Using genenic mode...\n"); | |
2834 | } | |
2835 | ||
69e52a80 HW |
2836 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
2837 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; | |
c577b8a1 JC |
2838 | |
2839 | spec->stream_name_analog = "VT1709 Analog"; | |
2840 | spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; | |
2841 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; | |
2842 | ||
2843 | spec->stream_name_digital = "VT1709 Digital"; | |
2844 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; | |
2845 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; | |
2846 | ||
a766d0d7 | 2847 | if (spec->adc_nids && spec->input_mux) { |
c577b8a1 JC |
2848 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
2849 | spec->num_mixers++; | |
2850 | } | |
2851 | ||
2852 | codec->patch_ops = via_patch_ops; | |
2853 | ||
2854 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2855 | codec->patch_ops.unsol_event = via_unsol_event; |
cb53c626 TI |
2856 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2857 | spec->loopback.amplist = vt1709_loopbacks; | |
2858 | #endif | |
f7278fd0 JC |
2859 | return 0; |
2860 | } | |
2861 | ||
2862 | /* capture mixer elements */ | |
90dd48a1 | 2863 | static const struct snd_kcontrol_new vt1708B_capture_mixer[] = { |
f7278fd0 JC |
2864 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
2865 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | |
2866 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | |
2867 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | |
2868 | { | |
2869 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2870 | /* The multiple "Capture Source" controls confuse alsamixer | |
2871 | * So call somewhat different.. | |
f7278fd0 JC |
2872 | */ |
2873 | /* .name = "Capture Source", */ | |
2874 | .name = "Input Source", | |
2875 | .count = 1, | |
2876 | .info = via_mux_enum_info, | |
2877 | .get = via_mux_enum_get, | |
2878 | .put = via_mux_enum_put, | |
2879 | }, | |
2880 | { } /* end */ | |
2881 | }; | |
2882 | /* | |
2883 | * generic initialization of ADC, input mixers and output mixers | |
2884 | */ | |
90dd48a1 | 2885 | static const struct hda_verb vt1708B_8ch_volume_init_verbs[] = { |
f7278fd0 JC |
2886 | /* |
2887 | * Unmute ADC0-1 and set the default input to mic-in | |
2888 | */ | |
2889 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2890 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2891 | ||
2892 | ||
2893 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2894 | * mixer widget | |
2895 | */ | |
2896 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2897 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2898 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2899 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2900 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2901 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2902 | ||
2903 | /* | |
2904 | * Set up output mixers | |
2905 | */ | |
2906 | /* set vol=0 to output mixers */ | |
2907 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2908 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2909 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2910 | ||
2911 | /* Setup default input to PW4 */ | |
bfdc675a | 2912 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
f7278fd0 JC |
2913 | /* PW9 Output enable */ |
2914 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2915 | /* PW10 Input enable */ | |
2916 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, | |
2917 | { } | |
2918 | }; | |
2919 | ||
90dd48a1 | 2920 | static const struct hda_verb vt1708B_4ch_volume_init_verbs[] = { |
f7278fd0 JC |
2921 | /* |
2922 | * Unmute ADC0-1 and set the default input to mic-in | |
2923 | */ | |
2924 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2925 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2926 | ||
2927 | ||
2928 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2929 | * mixer widget | |
2930 | */ | |
2931 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2932 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2933 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2934 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2935 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2936 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2937 | ||
2938 | /* | |
2939 | * Set up output mixers | |
2940 | */ | |
2941 | /* set vol=0 to output mixers */ | |
2942 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2943 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2944 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2945 | ||
2946 | /* Setup default input of PW4 to MW0 */ | |
2947 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2948 | /* PW9 Output enable */ | |
2949 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2950 | /* PW10 Input enable */ | |
2951 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, | |
2952 | { } | |
2953 | }; | |
2954 | ||
90dd48a1 | 2955 | static const struct hda_verb vt1708B_uniwill_init_verbs[] = { |
a34df19a LW |
2956 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
2957 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
2958 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2959 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2960 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2961 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2962 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2963 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
2964 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
69e52a80 HW |
2965 | { } |
2966 | }; | |
2967 | ||
17314379 LW |
2968 | static int via_pcm_open_close(struct hda_pcm_stream *hinfo, |
2969 | struct hda_codec *codec, | |
2970 | struct snd_pcm_substream *substream) | |
2971 | { | |
2972 | int idle = substream->pstr->substream_opened == 1 | |
2973 | && substream->ref_count == 0; | |
2974 | ||
2975 | analog_low_current_mode(codec, idle); | |
2976 | return 0; | |
2977 | } | |
2978 | ||
90dd48a1 | 2979 | static const struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { |
0aa62aef | 2980 | .substreams = 2, |
f7278fd0 JC |
2981 | .channels_min = 2, |
2982 | .channels_max = 8, | |
2983 | .nid = 0x10, /* NID to query formats and rates */ | |
2984 | .ops = { | |
2985 | .open = via_playback_pcm_open, | |
0aa62aef | 2986 | .prepare = via_playback_multi_pcm_prepare, |
17314379 LW |
2987 | .cleanup = via_playback_multi_pcm_cleanup, |
2988 | .close = via_pcm_open_close | |
f7278fd0 JC |
2989 | }, |
2990 | }; | |
2991 | ||
90dd48a1 | 2992 | static const struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { |
0aa62aef | 2993 | .substreams = 2, |
f7278fd0 JC |
2994 | .channels_min = 2, |
2995 | .channels_max = 4, | |
2996 | .nid = 0x10, /* NID to query formats and rates */ | |
2997 | .ops = { | |
2998 | .open = via_playback_pcm_open, | |
0aa62aef HW |
2999 | .prepare = via_playback_multi_pcm_prepare, |
3000 | .cleanup = via_playback_multi_pcm_cleanup | |
f7278fd0 JC |
3001 | }, |
3002 | }; | |
3003 | ||
90dd48a1 | 3004 | static const struct hda_pcm_stream vt1708B_pcm_analog_capture = { |
f7278fd0 JC |
3005 | .substreams = 2, |
3006 | .channels_min = 2, | |
3007 | .channels_max = 2, | |
3008 | .nid = 0x13, /* NID to query formats and rates */ | |
3009 | .ops = { | |
17314379 | 3010 | .open = via_pcm_open_close, |
f7278fd0 | 3011 | .prepare = via_capture_pcm_prepare, |
17314379 LW |
3012 | .cleanup = via_capture_pcm_cleanup, |
3013 | .close = via_pcm_open_close | |
f7278fd0 JC |
3014 | }, |
3015 | }; | |
3016 | ||
90dd48a1 | 3017 | static const struct hda_pcm_stream vt1708B_pcm_digital_playback = { |
f7278fd0 JC |
3018 | .substreams = 1, |
3019 | .channels_min = 2, | |
3020 | .channels_max = 2, | |
3021 | /* NID is set in via_build_pcms */ | |
3022 | .ops = { | |
3023 | .open = via_dig_playback_pcm_open, | |
3024 | .close = via_dig_playback_pcm_close, | |
9da29271 TI |
3025 | .prepare = via_dig_playback_pcm_prepare, |
3026 | .cleanup = via_dig_playback_pcm_cleanup | |
f7278fd0 JC |
3027 | }, |
3028 | }; | |
3029 | ||
90dd48a1 | 3030 | static const struct hda_pcm_stream vt1708B_pcm_digital_capture = { |
f7278fd0 JC |
3031 | .substreams = 1, |
3032 | .channels_min = 2, | |
3033 | .channels_max = 2, | |
3034 | }; | |
3035 | ||
3036 | /* fill in the dac_nids table from the parsed pin configuration */ | |
3037 | static int vt1708B_auto_fill_dac_nids(struct via_spec *spec, | |
3038 | const struct auto_pin_cfg *cfg) | |
3039 | { | |
3040 | int i; | |
3041 | hda_nid_t nid; | |
3042 | ||
3043 | spec->multiout.num_dacs = cfg->line_outs; | |
3044 | ||
3045 | spec->multiout.dac_nids = spec->private_dac_nids; | |
3046 | ||
3047 | for (i = 0; i < 4; i++) { | |
3048 | nid = cfg->line_out_pins[i]; | |
3049 | if (nid) { | |
3050 | /* config dac list */ | |
3051 | switch (i) { | |
3052 | case AUTO_SEQ_FRONT: | |
dda14410 | 3053 | spec->private_dac_nids[i] = 0x10; |
f7278fd0 JC |
3054 | break; |
3055 | case AUTO_SEQ_CENLFE: | |
dda14410 | 3056 | spec->private_dac_nids[i] = 0x24; |
f7278fd0 JC |
3057 | break; |
3058 | case AUTO_SEQ_SURROUND: | |
dda14410 | 3059 | spec->private_dac_nids[i] = 0x11; |
f7278fd0 JC |
3060 | break; |
3061 | case AUTO_SEQ_SIDE: | |
dda14410 | 3062 | spec->private_dac_nids[i] = 0x25; |
f7278fd0 JC |
3063 | break; |
3064 | } | |
3065 | } | |
3066 | } | |
3067 | ||
3068 | return 0; | |
3069 | } | |
3070 | ||
3071 | /* add playback controls from the parsed DAC table */ | |
3072 | static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec, | |
3073 | const struct auto_pin_cfg *cfg) | |
3074 | { | |
3075 | char name[32]; | |
ea734963 TI |
3076 | static const char * const chname[4] = { |
3077 | "Front", "Surround", "C/LFE", "Side" | |
3078 | }; | |
fb4cb772 | 3079 | hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27}; |
f7278fd0 JC |
3080 | hda_nid_t nid, nid_vol = 0; |
3081 | int i, err; | |
3082 | ||
3083 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
3084 | nid = cfg->line_out_pins[i]; | |
3085 | ||
3086 | if (!nid) | |
3087 | continue; | |
3088 | ||
3089 | nid_vol = nid_vols[i]; | |
3090 | ||
3091 | if (i == AUTO_SEQ_CENLFE) { | |
3092 | /* Center/LFE */ | |
3093 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3094 | "Center Playback Volume", | |
3095 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
3096 | HDA_OUTPUT)); | |
3097 | if (err < 0) | |
3098 | return err; | |
3099 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3100 | "LFE Playback Volume", | |
3101 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
3102 | HDA_OUTPUT)); | |
3103 | if (err < 0) | |
3104 | return err; | |
3105 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3106 | "Center Playback Switch", | |
3107 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
3108 | HDA_OUTPUT)); | |
3109 | if (err < 0) | |
3110 | return err; | |
3111 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3112 | "LFE Playback Switch", | |
3113 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
3114 | HDA_OUTPUT)); | |
3115 | if (err < 0) | |
3116 | return err; | |
3117 | } else if (i == AUTO_SEQ_FRONT) { | |
3118 | /* add control to mixer index 0 */ | |
3119 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3120 | "Master Front Playback Volume", | |
3121 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
3122 | HDA_INPUT)); | |
3123 | if (err < 0) | |
3124 | return err; | |
3125 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3126 | "Master Front Playback Switch", | |
3127 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
3128 | HDA_INPUT)); | |
3129 | if (err < 0) | |
3130 | return err; | |
3131 | ||
3132 | /* add control to PW3 */ | |
3133 | sprintf(name, "%s Playback Volume", chname[i]); | |
3134 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
3135 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, | |
3136 | HDA_OUTPUT)); | |
3137 | if (err < 0) | |
3138 | return err; | |
3139 | sprintf(name, "%s Playback Switch", chname[i]); | |
3140 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
3141 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, | |
3142 | HDA_OUTPUT)); | |
3143 | if (err < 0) | |
3144 | return err; | |
3145 | } else { | |
3146 | sprintf(name, "%s Playback Volume", chname[i]); | |
3147 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
3148 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
3149 | HDA_OUTPUT)); | |
3150 | if (err < 0) | |
3151 | return err; | |
3152 | sprintf(name, "%s Playback Switch", chname[i]); | |
3153 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
3154 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
3155 | HDA_OUTPUT)); | |
3156 | if (err < 0) | |
3157 | return err; | |
3158 | } | |
3159 | } | |
3160 | ||
3161 | return 0; | |
3162 | } | |
3163 | ||
3164 | static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
3165 | { | |
3166 | int err; | |
3167 | ||
3168 | if (!pin) | |
3169 | return 0; | |
3170 | ||
3171 | spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ | |
cdc1784d | 3172 | spec->hp_independent_mode_index = 1; |
f7278fd0 JC |
3173 | |
3174 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3175 | "Headphone Playback Volume", | |
3176 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
3177 | if (err < 0) | |
3178 | return err; | |
3179 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3180 | "Headphone Playback Switch", | |
3181 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
3182 | if (err < 0) | |
3183 | return err; | |
3184 | ||
0aa62aef HW |
3185 | create_hp_imux(spec); |
3186 | ||
f7278fd0 JC |
3187 | return 0; |
3188 | } | |
3189 | ||
3190 | /* create playback/capture controls for input pins */ | |
10a20af7 | 3191 | static int vt1708B_auto_create_analog_input_ctls(struct hda_codec *codec, |
f7278fd0 JC |
3192 | const struct auto_pin_cfg *cfg) |
3193 | { | |
a766d0d7 | 3194 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); |
f7278fd0 JC |
3195 | } |
3196 | ||
3197 | static int vt1708B_parse_auto_config(struct hda_codec *codec) | |
3198 | { | |
3199 | struct via_spec *spec = codec->spec; | |
3200 | int err; | |
3201 | ||
3202 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
3203 | if (err < 0) | |
3204 | return err; | |
3205 | err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg); | |
3206 | if (err < 0) | |
3207 | return err; | |
3208 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
3209 | return 0; /* can't find valid BIOS pin config */ | |
3210 | ||
3211 | err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
3212 | if (err < 0) | |
3213 | return err; | |
3214 | err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
3215 | if (err < 0) | |
3216 | return err; | |
10a20af7 | 3217 | err = vt1708B_auto_create_analog_input_ctls(codec, &spec->autocfg); |
f7278fd0 JC |
3218 | if (err < 0) |
3219 | return err; | |
3220 | ||
3221 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3222 | ||
0852d7a6 | 3223 | if (spec->autocfg.dig_outs) |
f7278fd0 | 3224 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
55d1d6c1 | 3225 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
f7278fd0 JC |
3226 | if (spec->autocfg.dig_in_pin) |
3227 | spec->dig_in_nid = VT1708B_DIGIN_NID; | |
3228 | ||
603c4019 TI |
3229 | if (spec->kctls.list) |
3230 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
f7278fd0 | 3231 | |
0aa62aef HW |
3232 | spec->input_mux = &spec->private_imux[0]; |
3233 | ||
f8fdd495 | 3234 | if (spec->hp_mux) |
3d83e577 | 3235 | via_hp_build(codec); |
f7278fd0 | 3236 | |
5b0cb1d8 | 3237 | via_smart51_build(spec); |
f7278fd0 JC |
3238 | return 1; |
3239 | } | |
3240 | ||
3241 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 3242 | static const struct hda_amp_list vt1708B_loopbacks[] = { |
f7278fd0 JC |
3243 | { 0x16, HDA_INPUT, 1 }, |
3244 | { 0x16, HDA_INPUT, 2 }, | |
3245 | { 0x16, HDA_INPUT, 3 }, | |
3246 | { 0x16, HDA_INPUT, 4 }, | |
3247 | { } /* end */ | |
3248 | }; | |
3249 | #endif | |
3e95b9ab LW |
3250 | |
3251 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) | |
3252 | { | |
3253 | struct via_spec *spec = codec->spec; | |
3254 | int imux_is_smixer; | |
3255 | unsigned int parm; | |
3256 | int is_8ch = 0; | |
bc92df7f LW |
3257 | if ((spec->codec_type != VT1708B_4CH) && |
3258 | (codec->vendor_id != 0x11064397)) | |
3e95b9ab LW |
3259 | is_8ch = 1; |
3260 | ||
3261 | /* SW0 (17h) = stereo mixer */ | |
3262 | imux_is_smixer = | |
3263 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) | |
3264 | == ((spec->codec_type == VT1708S) ? 5 : 0)); | |
3265 | /* inputs */ | |
3266 | /* PW 1/2/5 (1ah/1bh/1eh) */ | |
3267 | parm = AC_PWRST_D3; | |
3268 | set_pin_power_state(codec, 0x1a, &parm); | |
3269 | set_pin_power_state(codec, 0x1b, &parm); | |
3270 | set_pin_power_state(codec, 0x1e, &parm); | |
3271 | if (imux_is_smixer) | |
3272 | parm = AC_PWRST_D0; | |
3273 | /* SW0 (17h), AIW 0/1 (13h/14h) */ | |
3274 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); | |
3275 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); | |
3276 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); | |
3277 | ||
3278 | /* outputs */ | |
3279 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | |
3280 | parm = AC_PWRST_D3; | |
3281 | set_pin_power_state(codec, 0x19, &parm); | |
3282 | if (spec->smart51_enabled) | |
3283 | set_pin_power_state(codec, 0x1b, &parm); | |
3284 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); | |
3285 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
3286 | ||
3287 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ | |
3288 | if (is_8ch) { | |
3289 | parm = AC_PWRST_D3; | |
3290 | set_pin_power_state(codec, 0x22, &parm); | |
3291 | if (spec->smart51_enabled) | |
3292 | set_pin_power_state(codec, 0x1a, &parm); | |
3293 | snd_hda_codec_write(codec, 0x26, 0, | |
3294 | AC_VERB_SET_POWER_STATE, parm); | |
3295 | snd_hda_codec_write(codec, 0x24, 0, | |
3296 | AC_VERB_SET_POWER_STATE, parm); | |
bc92df7f LW |
3297 | } else if (codec->vendor_id == 0x11064397) { |
3298 | /* PW7(23h), SW2(27h), AOW2(25h) */ | |
3299 | parm = AC_PWRST_D3; | |
3300 | set_pin_power_state(codec, 0x23, &parm); | |
3301 | if (spec->smart51_enabled) | |
3302 | set_pin_power_state(codec, 0x1a, &parm); | |
3303 | snd_hda_codec_write(codec, 0x27, 0, | |
3304 | AC_VERB_SET_POWER_STATE, parm); | |
3305 | snd_hda_codec_write(codec, 0x25, 0, | |
3306 | AC_VERB_SET_POWER_STATE, parm); | |
3e95b9ab LW |
3307 | } |
3308 | ||
3309 | /* PW 3/4/7 (1ch/1dh/23h) */ | |
3310 | parm = AC_PWRST_D3; | |
3311 | /* force to D0 for internal Speaker */ | |
3312 | set_pin_power_state(codec, 0x1c, &parm); | |
3313 | set_pin_power_state(codec, 0x1d, &parm); | |
3314 | if (is_8ch) | |
3315 | set_pin_power_state(codec, 0x23, &parm); | |
3316 | ||
3317 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ | |
3318 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, | |
3319 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
3320 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
3321 | if (is_8ch) { | |
3322 | snd_hda_codec_write(codec, 0x25, 0, | |
3323 | AC_VERB_SET_POWER_STATE, parm); | |
3324 | snd_hda_codec_write(codec, 0x27, 0, | |
3325 | AC_VERB_SET_POWER_STATE, parm); | |
bc92df7f LW |
3326 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
3327 | snd_hda_codec_write(codec, 0x25, 0, | |
3328 | AC_VERB_SET_POWER_STATE, parm); | |
3e95b9ab LW |
3329 | } |
3330 | ||
518bf3ba | 3331 | static int patch_vt1708S(struct hda_codec *codec); |
f7278fd0 JC |
3332 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
3333 | { | |
3334 | struct via_spec *spec; | |
3335 | int err; | |
3336 | ||
518bf3ba LW |
3337 | if (get_codec_type(codec) == VT1708BCE) |
3338 | return patch_vt1708S(codec); | |
f7278fd0 | 3339 | /* create a codec specific record */ |
5b0cb1d8 | 3340 | spec = via_new_spec(codec); |
f7278fd0 JC |
3341 | if (spec == NULL) |
3342 | return -ENOMEM; | |
3343 | ||
f7278fd0 JC |
3344 | /* automatic parse from the BIOS config */ |
3345 | err = vt1708B_parse_auto_config(codec); | |
3346 | if (err < 0) { | |
3347 | via_free(codec); | |
3348 | return err; | |
3349 | } else if (!err) { | |
3350 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
3351 | "from BIOS. Using genenic mode...\n"); | |
3352 | } | |
3353 | ||
69e52a80 HW |
3354 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
3355 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; | |
f7278fd0 JC |
3356 | |
3357 | spec->stream_name_analog = "VT1708B Analog"; | |
3358 | spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; | |
3359 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; | |
3360 | ||
3361 | spec->stream_name_digital = "VT1708B Digital"; | |
3362 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; | |
3363 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; | |
3364 | ||
a766d0d7 | 3365 | if (spec->adc_nids && spec->input_mux) { |
f7278fd0 JC |
3366 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
3367 | spec->num_mixers++; | |
3368 | } | |
3369 | ||
3370 | codec->patch_ops = via_patch_ops; | |
3371 | ||
3372 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 3373 | codec->patch_ops.unsol_event = via_unsol_event; |
f7278fd0 JC |
3374 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3375 | spec->loopback.amplist = vt1708B_loopbacks; | |
3376 | #endif | |
3377 | ||
3e95b9ab LW |
3378 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
3379 | ||
f7278fd0 JC |
3380 | return 0; |
3381 | } | |
3382 | ||
3383 | static int patch_vt1708B_4ch(struct hda_codec *codec) | |
3384 | { | |
3385 | struct via_spec *spec; | |
3386 | int err; | |
3387 | ||
3388 | /* create a codec specific record */ | |
5b0cb1d8 | 3389 | spec = via_new_spec(codec); |
f7278fd0 JC |
3390 | if (spec == NULL) |
3391 | return -ENOMEM; | |
3392 | ||
f7278fd0 JC |
3393 | /* automatic parse from the BIOS config */ |
3394 | err = vt1708B_parse_auto_config(codec); | |
3395 | if (err < 0) { | |
3396 | via_free(codec); | |
3397 | return err; | |
3398 | } else if (!err) { | |
3399 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
3400 | "from BIOS. Using genenic mode...\n"); | |
3401 | } | |
3402 | ||
69e52a80 HW |
3403 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
3404 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; | |
f7278fd0 JC |
3405 | |
3406 | spec->stream_name_analog = "VT1708B Analog"; | |
3407 | spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; | |
3408 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; | |
3409 | ||
3410 | spec->stream_name_digital = "VT1708B Digital"; | |
3411 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; | |
3412 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; | |
3413 | ||
a766d0d7 | 3414 | if (spec->adc_nids && spec->input_mux) { |
f7278fd0 JC |
3415 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
3416 | spec->num_mixers++; | |
3417 | } | |
3418 | ||
3419 | codec->patch_ops = via_patch_ops; | |
3420 | ||
3421 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 3422 | codec->patch_ops.unsol_event = via_unsol_event; |
f7278fd0 JC |
3423 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3424 | spec->loopback.amplist = vt1708B_loopbacks; | |
3425 | #endif | |
c577b8a1 | 3426 | |
3e95b9ab LW |
3427 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
3428 | ||
c577b8a1 JC |
3429 | return 0; |
3430 | } | |
3431 | ||
d949cac1 HW |
3432 | /* Patch for VT1708S */ |
3433 | ||
3434 | /* capture mixer elements */ | |
90dd48a1 | 3435 | static const struct snd_kcontrol_new vt1708S_capture_mixer[] = { |
d949cac1 HW |
3436 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
3437 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | |
3438 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | |
3439 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | |
6369bcfc LW |
3440 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
3441 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, | |
3442 | HDA_INPUT), | |
d949cac1 HW |
3443 | { |
3444 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3445 | /* The multiple "Capture Source" controls confuse alsamixer | |
3446 | * So call somewhat different.. | |
3447 | */ | |
3448 | /* .name = "Capture Source", */ | |
3449 | .name = "Input Source", | |
3450 | .count = 1, | |
3451 | .info = via_mux_enum_info, | |
3452 | .get = via_mux_enum_get, | |
3453 | .put = via_mux_enum_put, | |
3454 | }, | |
3455 | { } /* end */ | |
3456 | }; | |
3457 | ||
90dd48a1 | 3458 | static const struct hda_verb vt1708S_volume_init_verbs[] = { |
d949cac1 HW |
3459 | /* Unmute ADC0-1 and set the default input to mic-in */ |
3460 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3461 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3462 | ||
3463 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the | |
3464 | * analog-loopback mixer widget */ | |
3465 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
3466 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3467 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3468 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
3469 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
3470 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
3471 | ||
3472 | /* Setup default input of PW4 to MW0 */ | |
3473 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
5691ec7f | 3474 | /* PW9, PW10 Output enable */ |
d949cac1 | 3475 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
5691ec7f | 3476 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
d7426329 HW |
3477 | /* Enable Mic Boost Volume backdoor */ |
3478 | {0x1, 0xf98, 0x1}, | |
bc7e7e5c LW |
3479 | /* don't bybass mixer */ |
3480 | {0x1, 0xf88, 0xc0}, | |
d949cac1 HW |
3481 | { } |
3482 | }; | |
3483 | ||
90dd48a1 | 3484 | static const struct hda_verb vt1708S_uniwill_init_verbs[] = { |
a34df19a LW |
3485 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3486 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3487 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3488 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3489 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3490 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3491 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3492 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3493 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
69e52a80 HW |
3494 | { } |
3495 | }; | |
3496 | ||
90dd48a1 | 3497 | static const struct hda_verb vt1705_uniwill_init_verbs[] = { |
bc92df7f LW |
3498 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
3499 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3500 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3501 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3502 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3503 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3504 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3505 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3506 | { } | |
3507 | }; | |
3508 | ||
90dd48a1 | 3509 | static const struct hda_pcm_stream vt1708S_pcm_analog_playback = { |
d949cac1 HW |
3510 | .substreams = 2, |
3511 | .channels_min = 2, | |
3512 | .channels_max = 8, | |
3513 | .nid = 0x10, /* NID to query formats and rates */ | |
3514 | .ops = { | |
3515 | .open = via_playback_pcm_open, | |
c873cc25 LW |
3516 | .prepare = via_playback_multi_pcm_prepare, |
3517 | .cleanup = via_playback_multi_pcm_cleanup, | |
17314379 | 3518 | .close = via_pcm_open_close |
d949cac1 HW |
3519 | }, |
3520 | }; | |
3521 | ||
90dd48a1 | 3522 | static const struct hda_pcm_stream vt1705_pcm_analog_playback = { |
bc92df7f LW |
3523 | .substreams = 2, |
3524 | .channels_min = 2, | |
3525 | .channels_max = 6, | |
3526 | .nid = 0x10, /* NID to query formats and rates */ | |
3527 | .ops = { | |
3528 | .open = via_playback_pcm_open, | |
3529 | .prepare = via_playback_multi_pcm_prepare, | |
3530 | .cleanup = via_playback_multi_pcm_cleanup, | |
3531 | .close = via_pcm_open_close | |
3532 | }, | |
3533 | }; | |
3534 | ||
90dd48a1 | 3535 | static const struct hda_pcm_stream vt1708S_pcm_analog_capture = { |
d949cac1 HW |
3536 | .substreams = 2, |
3537 | .channels_min = 2, | |
3538 | .channels_max = 2, | |
3539 | .nid = 0x13, /* NID to query formats and rates */ | |
3540 | .ops = { | |
17314379 | 3541 | .open = via_pcm_open_close, |
d949cac1 | 3542 | .prepare = via_capture_pcm_prepare, |
17314379 LW |
3543 | .cleanup = via_capture_pcm_cleanup, |
3544 | .close = via_pcm_open_close | |
d949cac1 HW |
3545 | }, |
3546 | }; | |
3547 | ||
90dd48a1 | 3548 | static const struct hda_pcm_stream vt1708S_pcm_digital_playback = { |
9da29271 | 3549 | .substreams = 1, |
d949cac1 HW |
3550 | .channels_min = 2, |
3551 | .channels_max = 2, | |
3552 | /* NID is set in via_build_pcms */ | |
3553 | .ops = { | |
3554 | .open = via_dig_playback_pcm_open, | |
3555 | .close = via_dig_playback_pcm_close, | |
9da29271 TI |
3556 | .prepare = via_dig_playback_pcm_prepare, |
3557 | .cleanup = via_dig_playback_pcm_cleanup | |
d949cac1 HW |
3558 | }, |
3559 | }; | |
3560 | ||
3561 | /* fill in the dac_nids table from the parsed pin configuration */ | |
3562 | static int vt1708S_auto_fill_dac_nids(struct via_spec *spec, | |
3563 | const struct auto_pin_cfg *cfg) | |
3564 | { | |
3565 | int i; | |
3566 | hda_nid_t nid; | |
3567 | ||
3568 | spec->multiout.num_dacs = cfg->line_outs; | |
3569 | ||
3570 | spec->multiout.dac_nids = spec->private_dac_nids; | |
3571 | ||
3572 | for (i = 0; i < 4; i++) { | |
3573 | nid = cfg->line_out_pins[i]; | |
3574 | if (nid) { | |
3575 | /* config dac list */ | |
3576 | switch (i) { | |
3577 | case AUTO_SEQ_FRONT: | |
dda14410 | 3578 | spec->private_dac_nids[i] = 0x10; |
d949cac1 HW |
3579 | break; |
3580 | case AUTO_SEQ_CENLFE: | |
bc92df7f | 3581 | if (spec->codec->vendor_id == 0x11064397) |
dda14410 | 3582 | spec->private_dac_nids[i] = 0x25; |
bc92df7f | 3583 | else |
dda14410 | 3584 | spec->private_dac_nids[i] = 0x24; |
d949cac1 HW |
3585 | break; |
3586 | case AUTO_SEQ_SURROUND: | |
dda14410 | 3587 | spec->private_dac_nids[i] = 0x11; |
d949cac1 HW |
3588 | break; |
3589 | case AUTO_SEQ_SIDE: | |
dda14410 | 3590 | spec->private_dac_nids[i] = 0x25; |
d949cac1 HW |
3591 | break; |
3592 | } | |
3593 | } | |
3594 | } | |
3595 | ||
32e0191d CL |
3596 | /* for Smart 5.1, line/mic inputs double as output pins */ |
3597 | if (cfg->line_outs == 1) { | |
3598 | spec->multiout.num_dacs = 3; | |
dda14410 | 3599 | spec->private_dac_nids[AUTO_SEQ_SURROUND] = 0x11; |
bc92df7f | 3600 | if (spec->codec->vendor_id == 0x11064397) |
dda14410 | 3601 | spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x25; |
bc92df7f | 3602 | else |
dda14410 | 3603 | spec->private_dac_nids[AUTO_SEQ_CENLFE] = 0x24; |
32e0191d CL |
3604 | } |
3605 | ||
d949cac1 HW |
3606 | return 0; |
3607 | } | |
3608 | ||
3609 | /* add playback controls from the parsed DAC table */ | |
bc92df7f | 3610 | static int vt1708S_auto_create_multi_out_ctls(struct hda_codec *codec, |
d949cac1 HW |
3611 | const struct auto_pin_cfg *cfg) |
3612 | { | |
bc92df7f | 3613 | struct via_spec *spec = codec->spec; |
d949cac1 | 3614 | char name[32]; |
ea734963 TI |
3615 | static const char * const chname[4] = { |
3616 | "Front", "Surround", "C/LFE", "Side" | |
3617 | }; | |
bc92df7f LW |
3618 | hda_nid_t nid_vols[2][4] = { {0x10, 0x11, 0x24, 0x25}, |
3619 | {0x10, 0x11, 0x25, 0} }; | |
3620 | hda_nid_t nid_mutes[2][4] = { {0x1C, 0x18, 0x26, 0x27}, | |
3621 | {0x1C, 0x18, 0x27, 0} }; | |
d949cac1 HW |
3622 | hda_nid_t nid, nid_vol, nid_mute; |
3623 | int i, err; | |
3624 | ||
3625 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
3626 | nid = cfg->line_out_pins[i]; | |
3627 | ||
32e0191d CL |
3628 | /* for Smart 5.1, there are always at least six channels */ |
3629 | if (!nid && i > AUTO_SEQ_CENLFE) | |
d949cac1 HW |
3630 | continue; |
3631 | ||
bc92df7f LW |
3632 | if (codec->vendor_id == 0x11064397) { |
3633 | nid_vol = nid_vols[1][i]; | |
3634 | nid_mute = nid_mutes[1][i]; | |
3635 | } else { | |
3636 | nid_vol = nid_vols[0][i]; | |
3637 | nid_mute = nid_mutes[0][i]; | |
3638 | } | |
3639 | if (!nid_vol && !nid_mute) | |
3640 | continue; | |
d949cac1 HW |
3641 | |
3642 | if (i == AUTO_SEQ_CENLFE) { | |
3643 | /* Center/LFE */ | |
3644 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3645 | "Center Playback Volume", | |
3646 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
3647 | HDA_OUTPUT)); | |
3648 | if (err < 0) | |
3649 | return err; | |
3650 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3651 | "LFE Playback Volume", | |
3652 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
3653 | HDA_OUTPUT)); | |
3654 | if (err < 0) | |
3655 | return err; | |
3656 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3657 | "Center Playback Switch", | |
3658 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
3659 | 1, 0, | |
3660 | HDA_OUTPUT)); | |
3661 | if (err < 0) | |
3662 | return err; | |
3663 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3664 | "LFE Playback Switch", | |
3665 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
3666 | 2, 0, | |
3667 | HDA_OUTPUT)); | |
3668 | if (err < 0) | |
3669 | return err; | |
3670 | } else if (i == AUTO_SEQ_FRONT) { | |
3671 | /* add control to mixer index 0 */ | |
3672 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3673 | "Master Front Playback Volume", | |
3674 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, | |
3675 | HDA_INPUT)); | |
3676 | if (err < 0) | |
3677 | return err; | |
3678 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3679 | "Master Front Playback Switch", | |
3680 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, | |
3681 | HDA_INPUT)); | |
3682 | if (err < 0) | |
3683 | return err; | |
3684 | ||
3685 | /* Front */ | |
3686 | sprintf(name, "%s Playback Volume", chname[i]); | |
3687 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
3688 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
3689 | HDA_OUTPUT)); | |
3690 | if (err < 0) | |
3691 | return err; | |
3692 | sprintf(name, "%s Playback Switch", chname[i]); | |
3693 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
3694 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
3695 | 3, 0, | |
3696 | HDA_OUTPUT)); | |
3697 | if (err < 0) | |
3698 | return err; | |
3699 | } else { | |
3700 | sprintf(name, "%s Playback Volume", chname[i]); | |
3701 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
3702 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
3703 | HDA_OUTPUT)); | |
3704 | if (err < 0) | |
3705 | return err; | |
3706 | sprintf(name, "%s Playback Switch", chname[i]); | |
3707 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
3708 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
3709 | 3, 0, | |
3710 | HDA_OUTPUT)); | |
3711 | if (err < 0) | |
3712 | return err; | |
3713 | } | |
3714 | } | |
3715 | ||
3716 | return 0; | |
3717 | } | |
3718 | ||
3719 | static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
3720 | { | |
3721 | int err; | |
3722 | ||
3723 | if (!pin) | |
3724 | return 0; | |
3725 | ||
3726 | spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ | |
cdc1784d | 3727 | spec->hp_independent_mode_index = 1; |
d949cac1 HW |
3728 | |
3729 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3730 | "Headphone Playback Volume", | |
3731 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); | |
3732 | if (err < 0) | |
3733 | return err; | |
3734 | ||
3735 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3736 | "Headphone Playback Switch", | |
3737 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
3738 | if (err < 0) | |
3739 | return err; | |
3740 | ||
0aa62aef HW |
3741 | create_hp_imux(spec); |
3742 | ||
d949cac1 HW |
3743 | return 0; |
3744 | } | |
3745 | ||
3746 | /* create playback/capture controls for input pins */ | |
10a20af7 | 3747 | static int vt1708S_auto_create_analog_input_ctls(struct hda_codec *codec, |
d949cac1 HW |
3748 | const struct auto_pin_cfg *cfg) |
3749 | { | |
a766d0d7 | 3750 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); |
d949cac1 HW |
3751 | } |
3752 | ||
9da29271 TI |
3753 | /* fill out digital output widgets; one for master and one for slave outputs */ |
3754 | static void fill_dig_outs(struct hda_codec *codec) | |
3755 | { | |
3756 | struct via_spec *spec = codec->spec; | |
3757 | int i; | |
3758 | ||
3759 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
3760 | hda_nid_t nid; | |
3761 | int conn; | |
3762 | ||
3763 | nid = spec->autocfg.dig_out_pins[i]; | |
3764 | if (!nid) | |
3765 | continue; | |
3766 | conn = snd_hda_get_connections(codec, nid, &nid, 1); | |
3767 | if (conn < 1) | |
3768 | continue; | |
3769 | if (!spec->multiout.dig_out_nid) | |
3770 | spec->multiout.dig_out_nid = nid; | |
3771 | else { | |
3772 | spec->slave_dig_outs[0] = nid; | |
3773 | break; /* at most two dig outs */ | |
3774 | } | |
3775 | } | |
3776 | } | |
3777 | ||
d949cac1 HW |
3778 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
3779 | { | |
3780 | struct via_spec *spec = codec->spec; | |
3781 | int err; | |
d949cac1 | 3782 | |
9da29271 | 3783 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
d949cac1 HW |
3784 | if (err < 0) |
3785 | return err; | |
3786 | err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg); | |
3787 | if (err < 0) | |
3788 | return err; | |
3789 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
3790 | return 0; /* can't find valid BIOS pin config */ | |
3791 | ||
bc92df7f | 3792 | err = vt1708S_auto_create_multi_out_ctls(codec, &spec->autocfg); |
d949cac1 HW |
3793 | if (err < 0) |
3794 | return err; | |
3795 | err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
3796 | if (err < 0) | |
3797 | return err; | |
10a20af7 | 3798 | err = vt1708S_auto_create_analog_input_ctls(codec, &spec->autocfg); |
d949cac1 HW |
3799 | if (err < 0) |
3800 | return err; | |
3801 | ||
3802 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3803 | ||
9da29271 | 3804 | fill_dig_outs(codec); |
98aa34c0 | 3805 | |
603c4019 TI |
3806 | if (spec->kctls.list) |
3807 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
d949cac1 | 3808 | |
0aa62aef HW |
3809 | spec->input_mux = &spec->private_imux[0]; |
3810 | ||
f8fdd495 | 3811 | if (spec->hp_mux) |
3d83e577 | 3812 | via_hp_build(codec); |
d949cac1 | 3813 | |
5b0cb1d8 | 3814 | via_smart51_build(spec); |
d949cac1 HW |
3815 | return 1; |
3816 | } | |
3817 | ||
3818 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 3819 | static const struct hda_amp_list vt1708S_loopbacks[] = { |
d949cac1 HW |
3820 | { 0x16, HDA_INPUT, 1 }, |
3821 | { 0x16, HDA_INPUT, 2 }, | |
3822 | { 0x16, HDA_INPUT, 3 }, | |
3823 | { 0x16, HDA_INPUT, 4 }, | |
3824 | { } /* end */ | |
3825 | }; | |
3826 | #endif | |
3827 | ||
6369bcfc LW |
3828 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
3829 | int offset, int num_steps, int step_size) | |
3830 | { | |
3831 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, | |
3832 | (offset << AC_AMPCAP_OFFSET_SHIFT) | | |
3833 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
3834 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
3835 | (0 << AC_AMPCAP_MUTE_SHIFT)); | |
3836 | } | |
3837 | ||
d949cac1 HW |
3838 | static int patch_vt1708S(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); |
d949cac1 HW |
3845 | if (spec == NULL) |
3846 | return -ENOMEM; | |
3847 | ||
d949cac1 HW |
3848 | /* automatic parse from the BIOS config */ |
3849 | err = vt1708S_parse_auto_config(codec); | |
3850 | if (err < 0) { | |
3851 | via_free(codec); | |
3852 | return err; | |
3853 | } else if (!err) { | |
3854 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
3855 | "from BIOS. Using genenic mode...\n"); | |
3856 | } | |
3857 | ||
69e52a80 | 3858 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
bc92df7f LW |
3859 | if (codec->vendor_id == 0x11064397) |
3860 | spec->init_verbs[spec->num_iverbs++] = | |
3861 | vt1705_uniwill_init_verbs; | |
3862 | else | |
3863 | spec->init_verbs[spec->num_iverbs++] = | |
3864 | vt1708S_uniwill_init_verbs; | |
d949cac1 | 3865 | |
36dd5c4a LW |
3866 | if (codec->vendor_id == 0x11060440) |
3867 | spec->stream_name_analog = "VT1818S Analog"; | |
bc92df7f LW |
3868 | else if (codec->vendor_id == 0x11064397) |
3869 | spec->stream_name_analog = "VT1705 Analog"; | |
36dd5c4a LW |
3870 | else |
3871 | spec->stream_name_analog = "VT1708S Analog"; | |
bc92df7f LW |
3872 | if (codec->vendor_id == 0x11064397) |
3873 | spec->stream_analog_playback = &vt1705_pcm_analog_playback; | |
3874 | else | |
3875 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; | |
d949cac1 HW |
3876 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; |
3877 | ||
36dd5c4a LW |
3878 | if (codec->vendor_id == 0x11060440) |
3879 | spec->stream_name_digital = "VT1818S Digital"; | |
bc92df7f LW |
3880 | else if (codec->vendor_id == 0x11064397) |
3881 | spec->stream_name_digital = "VT1705 Digital"; | |
36dd5c4a LW |
3882 | else |
3883 | spec->stream_name_digital = "VT1708S Digital"; | |
d949cac1 HW |
3884 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; |
3885 | ||
a766d0d7 | 3886 | if (spec->adc_nids && spec->input_mux) { |
6369bcfc LW |
3887 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
3888 | override_mic_boost(codec, 0x1e, 0, 3, 40); | |
d949cac1 HW |
3889 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; |
3890 | spec->num_mixers++; | |
3891 | } | |
3892 | ||
3893 | codec->patch_ops = via_patch_ops; | |
3894 | ||
3895 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 3896 | codec->patch_ops.unsol_event = via_unsol_event; |
d949cac1 HW |
3897 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3898 | spec->loopback.amplist = vt1708S_loopbacks; | |
3899 | #endif | |
3900 | ||
518bf3ba LW |
3901 | /* correct names for VT1708BCE */ |
3902 | if (get_codec_type(codec) == VT1708BCE) { | |
3903 | kfree(codec->chip_name); | |
3904 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); | |
3905 | snprintf(codec->bus->card->mixername, | |
3906 | sizeof(codec->bus->card->mixername), | |
3907 | "%s %s", codec->vendor_name, codec->chip_name); | |
3908 | spec->stream_name_analog = "VT1708BCE Analog"; | |
3909 | spec->stream_name_digital = "VT1708BCE Digital"; | |
3910 | } | |
970f630f LW |
3911 | /* correct names for VT1818S */ |
3912 | if (codec->vendor_id == 0x11060440) { | |
3913 | spec->stream_name_analog = "VT1818S Analog"; | |
3914 | spec->stream_name_digital = "VT1818S Digital"; | |
3915 | } | |
bc92df7f LW |
3916 | /* correct names for VT1705 */ |
3917 | if (codec->vendor_id == 0x11064397) { | |
3918 | kfree(codec->chip_name); | |
3919 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); | |
3920 | snprintf(codec->bus->card->mixername, | |
3921 | sizeof(codec->bus->card->mixername), | |
3922 | "%s %s", codec->vendor_name, codec->chip_name); | |
3923 | } | |
3e95b9ab | 3924 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
d949cac1 HW |
3925 | return 0; |
3926 | } | |
3927 | ||
3928 | /* Patch for VT1702 */ | |
3929 | ||
3930 | /* capture mixer elements */ | |
90dd48a1 | 3931 | static const struct snd_kcontrol_new vt1702_capture_mixer[] = { |
d949cac1 HW |
3932 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), |
3933 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), | |
3934 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), | |
3935 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), | |
3936 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), | |
3937 | HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), | |
3938 | HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, | |
3939 | HDA_INPUT), | |
3940 | { | |
3941 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3942 | /* The multiple "Capture Source" controls confuse alsamixer | |
3943 | * So call somewhat different.. | |
3944 | */ | |
3945 | /* .name = "Capture Source", */ | |
3946 | .name = "Input Source", | |
3947 | .count = 1, | |
3948 | .info = via_mux_enum_info, | |
3949 | .get = via_mux_enum_get, | |
3950 | .put = via_mux_enum_put, | |
3951 | }, | |
3952 | { } /* end */ | |
3953 | }; | |
3954 | ||
90dd48a1 | 3955 | static const struct hda_verb vt1702_volume_init_verbs[] = { |
d949cac1 HW |
3956 | /* |
3957 | * Unmute ADC0-1 and set the default input to mic-in | |
3958 | */ | |
3959 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3960 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3961 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3962 | ||
3963 | ||
3964 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
3965 | * mixer widget | |
3966 | */ | |
3967 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ | |
3968 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
3969 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
3970 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
3971 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
3972 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
3973 | ||
3974 | /* Setup default input of PW4 to MW0 */ | |
3975 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
3976 | /* PW6 PW7 Output enable */ | |
3977 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
3978 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
bc7e7e5c LW |
3979 | /* mixer enable */ |
3980 | {0x1, 0xF88, 0x3}, | |
3981 | /* GPIO 0~2 */ | |
3982 | {0x1, 0xF82, 0x3F}, | |
d949cac1 HW |
3983 | { } |
3984 | }; | |
3985 | ||
90dd48a1 | 3986 | static const struct hda_verb vt1702_uniwill_init_verbs[] = { |
a34df19a LW |
3987 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
3988 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
3989 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3990 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3991 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
3992 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
69e52a80 HW |
3993 | { } |
3994 | }; | |
3995 | ||
90dd48a1 | 3996 | static const struct hda_pcm_stream vt1702_pcm_analog_playback = { |
0aa62aef | 3997 | .substreams = 2, |
d949cac1 HW |
3998 | .channels_min = 2, |
3999 | .channels_max = 2, | |
4000 | .nid = 0x10, /* NID to query formats and rates */ | |
4001 | .ops = { | |
4002 | .open = via_playback_pcm_open, | |
0aa62aef | 4003 | .prepare = via_playback_multi_pcm_prepare, |
17314379 LW |
4004 | .cleanup = via_playback_multi_pcm_cleanup, |
4005 | .close = via_pcm_open_close | |
d949cac1 HW |
4006 | }, |
4007 | }; | |
4008 | ||
90dd48a1 | 4009 | static const struct hda_pcm_stream vt1702_pcm_analog_capture = { |
d949cac1 HW |
4010 | .substreams = 3, |
4011 | .channels_min = 2, | |
4012 | .channels_max = 2, | |
4013 | .nid = 0x12, /* NID to query formats and rates */ | |
4014 | .ops = { | |
17314379 | 4015 | .open = via_pcm_open_close, |
d949cac1 | 4016 | .prepare = via_capture_pcm_prepare, |
17314379 LW |
4017 | .cleanup = via_capture_pcm_cleanup, |
4018 | .close = via_pcm_open_close | |
d949cac1 HW |
4019 | }, |
4020 | }; | |
4021 | ||
90dd48a1 | 4022 | static const struct hda_pcm_stream vt1702_pcm_digital_playback = { |
5691ec7f | 4023 | .substreams = 2, |
d949cac1 HW |
4024 | .channels_min = 2, |
4025 | .channels_max = 2, | |
4026 | /* NID is set in via_build_pcms */ | |
4027 | .ops = { | |
4028 | .open = via_dig_playback_pcm_open, | |
4029 | .close = via_dig_playback_pcm_close, | |
9da29271 TI |
4030 | .prepare = via_dig_playback_pcm_prepare, |
4031 | .cleanup = via_dig_playback_pcm_cleanup | |
d949cac1 HW |
4032 | }, |
4033 | }; | |
4034 | ||
4035 | /* fill in the dac_nids table from the parsed pin configuration */ | |
4036 | static int vt1702_auto_fill_dac_nids(struct via_spec *spec, | |
4037 | const struct auto_pin_cfg *cfg) | |
4038 | { | |
4039 | spec->multiout.num_dacs = 1; | |
4040 | spec->multiout.dac_nids = spec->private_dac_nids; | |
4041 | ||
4042 | if (cfg->line_out_pins[0]) { | |
4043 | /* config dac list */ | |
dda14410 | 4044 | spec->private_dac_nids[0] = 0x10; |
d949cac1 HW |
4045 | } |
4046 | ||
4047 | return 0; | |
4048 | } | |
4049 | ||
4050 | /* add playback controls from the parsed DAC table */ | |
4051 | static int vt1702_auto_create_line_out_ctls(struct via_spec *spec, | |
4052 | const struct auto_pin_cfg *cfg) | |
4053 | { | |
4054 | int err; | |
4055 | ||
4056 | if (!cfg->line_out_pins[0]) | |
4057 | return -1; | |
4058 | ||
4059 | /* add control to mixer index 0 */ | |
4060 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
4061 | "Master Front Playback Volume", | |
4062 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); | |
4063 | if (err < 0) | |
4064 | return err; | |
4065 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
4066 | "Master Front Playback Switch", | |
4067 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); | |
4068 | if (err < 0) | |
4069 | return err; | |
4070 | ||
4071 | /* Front */ | |
4072 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
4073 | "Front Playback Volume", | |
4074 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT)); | |
4075 | if (err < 0) | |
4076 | return err; | |
4077 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
4078 | "Front Playback Switch", | |
4079 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT)); | |
4080 | if (err < 0) | |
4081 | return err; | |
4082 | ||
4083 | return 0; | |
4084 | } | |
4085 | ||
4086 | static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
4087 | { | |
0713efeb LW |
4088 | int err, i; |
4089 | struct hda_input_mux *imux; | |
ea734963 | 4090 | static const char * const texts[] = { "ON", "OFF", NULL}; |
d949cac1 HW |
4091 | if (!pin) |
4092 | return 0; | |
d949cac1 | 4093 | spec->multiout.hp_nid = 0x1D; |
cdc1784d | 4094 | spec->hp_independent_mode_index = 0; |
d949cac1 HW |
4095 | |
4096 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
4097 | "Headphone Playback Volume", | |
4098 | HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT)); | |
4099 | if (err < 0) | |
4100 | return err; | |
4101 | ||
4102 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
4103 | "Headphone Playback Switch", | |
4104 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
4105 | if (err < 0) | |
4106 | return err; | |
4107 | ||
0713efeb | 4108 | imux = &spec->private_imux[1]; |
0aa62aef | 4109 | |
0713efeb | 4110 | /* for hp mode select */ |
10a20af7 TI |
4111 | for (i = 0; texts[i]; i++) |
4112 | snd_hda_add_imux_item(imux, texts[i], i, NULL); | |
0713efeb LW |
4113 | |
4114 | spec->hp_mux = &spec->private_imux[1]; | |
d949cac1 HW |
4115 | return 0; |
4116 | } | |
4117 | ||
4118 | /* create playback/capture controls for input pins */ | |
10a20af7 | 4119 | static int vt1702_auto_create_analog_input_ctls(struct hda_codec *codec, |
d949cac1 HW |
4120 | const struct auto_pin_cfg *cfg) |
4121 | { | |
a766d0d7 | 4122 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x1a); |
d949cac1 HW |
4123 | } |
4124 | ||
4125 | static int vt1702_parse_auto_config(struct hda_codec *codec) | |
4126 | { | |
4127 | struct via_spec *spec = codec->spec; | |
4128 | int err; | |
d949cac1 | 4129 | |
9da29271 | 4130 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
d949cac1 HW |
4131 | if (err < 0) |
4132 | return err; | |
4133 | err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg); | |
4134 | if (err < 0) | |
4135 | return err; | |
4136 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
4137 | return 0; /* can't find valid BIOS pin config */ | |
4138 | ||
4139 | err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg); | |
4140 | if (err < 0) | |
4141 | return err; | |
4142 | err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
4143 | if (err < 0) | |
4144 | return err; | |
c2c02ea3 LW |
4145 | /* limit AA path volume to 0 dB */ |
4146 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, | |
4147 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | | |
4148 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
4149 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
4150 | (1 << AC_AMPCAP_MUTE_SHIFT)); | |
10a20af7 | 4151 | err = vt1702_auto_create_analog_input_ctls(codec, &spec->autocfg); |
d949cac1 HW |
4152 | if (err < 0) |
4153 | return err; | |
4154 | ||
4155 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
4156 | ||
9da29271 | 4157 | fill_dig_outs(codec); |
98aa34c0 | 4158 | |
603c4019 TI |
4159 | if (spec->kctls.list) |
4160 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
d949cac1 | 4161 | |
0aa62aef HW |
4162 | spec->input_mux = &spec->private_imux[0]; |
4163 | ||
f8fdd495 | 4164 | if (spec->hp_mux) |
3d83e577 | 4165 | via_hp_build(codec); |
d949cac1 HW |
4166 | |
4167 | return 1; | |
4168 | } | |
4169 | ||
4170 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 4171 | static const struct hda_amp_list vt1702_loopbacks[] = { |
d949cac1 HW |
4172 | { 0x1A, HDA_INPUT, 1 }, |
4173 | { 0x1A, HDA_INPUT, 2 }, | |
4174 | { 0x1A, HDA_INPUT, 3 }, | |
4175 | { 0x1A, HDA_INPUT, 4 }, | |
4176 | { } /* end */ | |
4177 | }; | |
4178 | #endif | |
4179 | ||
3e95b9ab LW |
4180 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
4181 | { | |
4182 | int imux_is_smixer = | |
4183 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
4184 | unsigned int parm; | |
4185 | /* inputs */ | |
4186 | /* PW 1/2/5 (14h/15h/18h) */ | |
4187 | parm = AC_PWRST_D3; | |
4188 | set_pin_power_state(codec, 0x14, &parm); | |
4189 | set_pin_power_state(codec, 0x15, &parm); | |
4190 | set_pin_power_state(codec, 0x18, &parm); | |
4191 | if (imux_is_smixer) | |
4192 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ | |
4193 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ | |
4194 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); | |
4195 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); | |
4196 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
4197 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); | |
4198 | ||
4199 | /* outputs */ | |
4200 | /* PW 3/4 (16h/17h) */ | |
4201 | parm = AC_PWRST_D3; | |
4202 | set_pin_power_state(codec, 0x17, &parm); | |
4203 | set_pin_power_state(codec, 0x16, &parm); | |
4204 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ | |
4205 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, | |
4206 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
4207 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
4208 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); | |
4209 | } | |
4210 | ||
d949cac1 HW |
4211 | static int patch_vt1702(struct hda_codec *codec) |
4212 | { | |
4213 | struct via_spec *spec; | |
4214 | int err; | |
d949cac1 HW |
4215 | |
4216 | /* create a codec specific record */ | |
5b0cb1d8 | 4217 | spec = via_new_spec(codec); |
d949cac1 HW |
4218 | if (spec == NULL) |
4219 | return -ENOMEM; | |
4220 | ||
d949cac1 HW |
4221 | /* automatic parse from the BIOS config */ |
4222 | err = vt1702_parse_auto_config(codec); | |
4223 | if (err < 0) { | |
4224 | via_free(codec); | |
4225 | return err; | |
4226 | } else if (!err) { | |
4227 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
4228 | "from BIOS. Using genenic mode...\n"); | |
4229 | } | |
4230 | ||
69e52a80 HW |
4231 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
4232 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; | |
d949cac1 HW |
4233 | |
4234 | spec->stream_name_analog = "VT1702 Analog"; | |
4235 | spec->stream_analog_playback = &vt1702_pcm_analog_playback; | |
4236 | spec->stream_analog_capture = &vt1702_pcm_analog_capture; | |
4237 | ||
4238 | spec->stream_name_digital = "VT1702 Digital"; | |
4239 | spec->stream_digital_playback = &vt1702_pcm_digital_playback; | |
4240 | ||
a766d0d7 | 4241 | if (spec->adc_nids && spec->input_mux) { |
d949cac1 HW |
4242 | spec->mixers[spec->num_mixers] = vt1702_capture_mixer; |
4243 | spec->num_mixers++; | |
4244 | } | |
4245 | ||
4246 | codec->patch_ops = via_patch_ops; | |
4247 | ||
4248 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 4249 | codec->patch_ops.unsol_event = via_unsol_event; |
d949cac1 HW |
4250 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
4251 | spec->loopback.amplist = vt1702_loopbacks; | |
4252 | #endif | |
4253 | ||
3e95b9ab | 4254 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
d949cac1 HW |
4255 | return 0; |
4256 | } | |
4257 | ||
eb7188ca LW |
4258 | /* Patch for VT1718S */ |
4259 | ||
4260 | /* capture mixer elements */ | |
90dd48a1 | 4261 | static const struct snd_kcontrol_new vt1718S_capture_mixer[] = { |
eb7188ca LW |
4262 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
4263 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), | |
4264 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), | |
4265 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), | |
4266 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), | |
4267 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, | |
4268 | HDA_INPUT), | |
4269 | { | |
4270 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
4271 | /* The multiple "Capture Source" controls confuse alsamixer | |
4272 | * So call somewhat different.. | |
4273 | */ | |
4274 | .name = "Input Source", | |
4275 | .count = 2, | |
4276 | .info = via_mux_enum_info, | |
4277 | .get = via_mux_enum_get, | |
4278 | .put = via_mux_enum_put, | |
4279 | }, | |
4280 | { } /* end */ | |
4281 | }; | |
4282 | ||
90dd48a1 | 4283 | static const struct hda_verb vt1718S_volume_init_verbs[] = { |
eb7188ca LW |
4284 | /* |
4285 | * Unmute ADC0-1 and set the default input to mic-in | |
4286 | */ | |
4287 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4288 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4289 | ||
4ab2d53a LW |
4290 | /* Enable MW0 adjust Gain 5 */ |
4291 | {0x1, 0xfb2, 0x10}, | |
eb7188ca LW |
4292 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
4293 | * mixer widget | |
4294 | */ | |
4295 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
4296 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
4297 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4298 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
4299 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
4ab2d53a | 4300 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5)}, |
eb7188ca LW |
4301 | |
4302 | /* Setup default input of Front HP to MW9 */ | |
4303 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
4304 | /* PW9 PW10 Output enable */ | |
4305 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
4306 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
4307 | /* PW11 Input enable */ | |
4308 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, | |
4309 | /* Enable Boost Volume backdoor */ | |
4310 | {0x1, 0xf88, 0x8}, | |
4311 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ | |
4312 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4313 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4314 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4315 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4316 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4317 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4318 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4319 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4320 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
4321 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4322 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ | |
4323 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, | |
4324 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
4325 | /* Unmute MW4's index 0 */ | |
4326 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4327 | { } | |
4328 | }; | |
4329 | ||
4330 | ||
90dd48a1 | 4331 | static const struct hda_verb vt1718S_uniwill_init_verbs[] = { |
eb7188ca LW |
4332 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
4333 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
4334 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4335 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4336 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4337 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4338 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4339 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4340 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4341 | { } | |
4342 | }; | |
4343 | ||
90dd48a1 | 4344 | static const struct hda_pcm_stream vt1718S_pcm_analog_playback = { |
eb7188ca LW |
4345 | .substreams = 2, |
4346 | .channels_min = 2, | |
4347 | .channels_max = 10, | |
4348 | .nid = 0x8, /* NID to query formats and rates */ | |
4349 | .ops = { | |
4350 | .open = via_playback_pcm_open, | |
4351 | .prepare = via_playback_multi_pcm_prepare, | |
4352 | .cleanup = via_playback_multi_pcm_cleanup, | |
4353 | .close = via_pcm_open_close, | |
4354 | }, | |
4355 | }; | |
4356 | ||
90dd48a1 | 4357 | static const struct hda_pcm_stream vt1718S_pcm_analog_capture = { |
eb7188ca LW |
4358 | .substreams = 2, |
4359 | .channels_min = 2, | |
4360 | .channels_max = 2, | |
4361 | .nid = 0x10, /* NID to query formats and rates */ | |
4362 | .ops = { | |
4363 | .open = via_pcm_open_close, | |
4364 | .prepare = via_capture_pcm_prepare, | |
4365 | .cleanup = via_capture_pcm_cleanup, | |
4366 | .close = via_pcm_open_close, | |
4367 | }, | |
4368 | }; | |
4369 | ||
90dd48a1 | 4370 | static const struct hda_pcm_stream vt1718S_pcm_digital_playback = { |
eb7188ca LW |
4371 | .substreams = 2, |
4372 | .channels_min = 2, | |
4373 | .channels_max = 2, | |
eb7188ca LW |
4374 | /* NID is set in via_build_pcms */ |
4375 | .ops = { | |
4376 | .open = via_dig_playback_pcm_open, | |
4377 | .close = via_dig_playback_pcm_close, | |
4378 | .prepare = via_dig_playback_pcm_prepare, | |
4379 | .cleanup = via_dig_playback_pcm_cleanup | |
4380 | }, | |
4381 | }; | |
4382 | ||
90dd48a1 | 4383 | static const struct hda_pcm_stream vt1718S_pcm_digital_capture = { |
eb7188ca LW |
4384 | .substreams = 1, |
4385 | .channels_min = 2, | |
4386 | .channels_max = 2, | |
4387 | }; | |
4388 | ||
4389 | /* fill in the dac_nids table from the parsed pin configuration */ | |
4390 | static int vt1718S_auto_fill_dac_nids(struct via_spec *spec, | |
4391 | const struct auto_pin_cfg *cfg) | |
4392 | { | |
4393 | int i; | |
4394 | hda_nid_t nid; | |
4395 | ||
4396 | spec->multiout.num_dacs = cfg->line_outs; | |
4397 | ||
4398 | spec->multiout.dac_nids = spec->private_dac_nids; | |
4399 | ||
4400 | for (i = 0; i < 4; i++) { | |
4401 | nid = cfg->line_out_pins[i]; | |
4402 | if (nid) { | |
4403 | /* config dac list */ | |
4404 | switch (i) { | |
4405 | case AUTO_SEQ_FRONT: | |
dda14410 | 4406 | spec->private_dac_nids[i] = 0x8; |
eb7188ca LW |
4407 | break; |
4408 | case AUTO_SEQ_CENLFE: | |
dda14410 | 4409 | spec->private_dac_nids[i] = 0xa; |
eb7188ca LW |
4410 | break; |
4411 | case AUTO_SEQ_SURROUND: | |
dda14410 | 4412 | spec->private_dac_nids[i] = 0x9; |
eb7188ca LW |
4413 | break; |
4414 | case AUTO_SEQ_SIDE: | |
dda14410 | 4415 | spec->private_dac_nids[i] = 0xb; |
eb7188ca LW |
4416 | break; |
4417 | } | |
4418 | } | |
4419 | } | |
4420 | ||
4421 | return 0; | |
4422 | } | |
4423 | ||
4424 | /* add playback controls from the parsed DAC table */ | |
4425 | static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec, | |
4426 | const struct auto_pin_cfg *cfg) | |
4427 | { | |
4428 | char name[32]; | |
ea734963 TI |
4429 | static const char * const chname[4] = { |
4430 | "Front", "Surround", "C/LFE", "Side" | |
4431 | }; | |
eb7188ca LW |
4432 | hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb}; |
4433 | hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27}; | |
4434 | hda_nid_t nid, nid_vol, nid_mute = 0; | |
4435 | int i, err; | |
4436 | ||
4437 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
4438 | nid = cfg->line_out_pins[i]; | |
4439 | ||
4440 | if (!nid) | |
4441 | continue; | |
4442 | nid_vol = nid_vols[i]; | |
4443 | nid_mute = nid_mutes[i]; | |
4444 | ||
4445 | if (i == AUTO_SEQ_CENLFE) { | |
4446 | /* Center/LFE */ | |
4447 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
4448 | "Center Playback Volume", | |
4449 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
4450 | HDA_OUTPUT)); | |
4451 | if (err < 0) | |
4452 | return err; | |
4453 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
4454 | "LFE Playback Volume", | |
4455 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
4456 | HDA_OUTPUT)); | |
4457 | if (err < 0) | |
4458 | return err; | |
4459 | err = via_add_control( | |
4460 | spec, VIA_CTL_WIDGET_MUTE, | |
4461 | "Center Playback Switch", | |
4462 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, | |
4463 | HDA_OUTPUT)); | |
4464 | if (err < 0) | |
4465 | return err; | |
4466 | err = via_add_control( | |
4467 | spec, VIA_CTL_WIDGET_MUTE, | |
4468 | "LFE Playback Switch", | |
4469 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, | |
4470 | HDA_OUTPUT)); | |
4471 | if (err < 0) | |
4472 | return err; | |
4473 | } else if (i == AUTO_SEQ_FRONT) { | |
4474 | /* Front */ | |
4475 | sprintf(name, "%s Playback Volume", chname[i]); | |
4476 | err = via_add_control( | |
4477 | spec, VIA_CTL_WIDGET_VOL, name, | |
4478 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | |
4479 | if (err < 0) | |
4480 | return err; | |
4481 | sprintf(name, "%s Playback Switch", chname[i]); | |
4482 | err = via_add_control( | |
4483 | spec, VIA_CTL_WIDGET_MUTE, name, | |
4484 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | |
4485 | HDA_OUTPUT)); | |
4486 | if (err < 0) | |
4487 | return err; | |
4488 | } else { | |
4489 | sprintf(name, "%s Playback Volume", chname[i]); | |
4490 | err = via_add_control( | |
4491 | spec, VIA_CTL_WIDGET_VOL, name, | |
4492 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | |
4493 | if (err < 0) | |
4494 | return err; | |
4495 | sprintf(name, "%s Playback Switch", chname[i]); | |
4496 | err = via_add_control( | |
4497 | spec, VIA_CTL_WIDGET_MUTE, name, | |
4498 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | |
4499 | HDA_OUTPUT)); | |
4500 | if (err < 0) | |
4501 | return err; | |
4502 | } | |
4503 | } | |
4504 | return 0; | |
4505 | } | |
4506 | ||
4507 | static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
4508 | { | |
4509 | int err; | |
4510 | ||
4511 | if (!pin) | |
4512 | return 0; | |
4513 | ||
4514 | spec->multiout.hp_nid = 0xc; /* AOW4 */ | |
4515 | spec->hp_independent_mode_index = 1; | |
4516 | ||
4517 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
4518 | "Headphone Playback Volume", | |
4519 | HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT)); | |
4520 | if (err < 0) | |
4521 | return err; | |
4522 | ||
4523 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
4524 | "Headphone Playback Switch", | |
4525 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
4526 | if (err < 0) | |
4527 | return err; | |
4528 | ||
4529 | create_hp_imux(spec); | |
4530 | return 0; | |
4531 | } | |
4532 | ||
4533 | /* create playback/capture controls for input pins */ | |
10a20af7 | 4534 | static int vt1718S_auto_create_analog_input_ctls(struct hda_codec *codec, |
eb7188ca LW |
4535 | const struct auto_pin_cfg *cfg) |
4536 | { | |
a766d0d7 | 4537 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); |
eb7188ca LW |
4538 | } |
4539 | ||
4540 | static int vt1718S_parse_auto_config(struct hda_codec *codec) | |
4541 | { | |
4542 | struct via_spec *spec = codec->spec; | |
4543 | int err; | |
4544 | ||
4545 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
4546 | ||
4547 | if (err < 0) | |
4548 | return err; | |
4549 | err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg); | |
4550 | if (err < 0) | |
4551 | return err; | |
4552 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
4553 | return 0; /* can't find valid BIOS pin config */ | |
4554 | ||
4555 | err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
4556 | if (err < 0) | |
4557 | return err; | |
4558 | err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
4559 | if (err < 0) | |
4560 | return err; | |
10a20af7 | 4561 | err = vt1718S_auto_create_analog_input_ctls(codec, &spec->autocfg); |
eb7188ca LW |
4562 | if (err < 0) |
4563 | return err; | |
4564 | ||
4565 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
4566 | ||
4567 | fill_dig_outs(codec); | |
4568 | ||
4569 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) | |
4570 | spec->dig_in_nid = 0x13; | |
4571 | ||
4572 | if (spec->kctls.list) | |
4573 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
4574 | ||
4575 | spec->input_mux = &spec->private_imux[0]; | |
4576 | ||
4577 | if (spec->hp_mux) | |
3d83e577 | 4578 | via_hp_build(codec); |
eb7188ca | 4579 | |
5b0cb1d8 | 4580 | via_smart51_build(spec); |
eb7188ca LW |
4581 | |
4582 | return 1; | |
4583 | } | |
4584 | ||
4585 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 4586 | static const struct hda_amp_list vt1718S_loopbacks[] = { |
eb7188ca LW |
4587 | { 0x21, HDA_INPUT, 1 }, |
4588 | { 0x21, HDA_INPUT, 2 }, | |
4589 | { 0x21, HDA_INPUT, 3 }, | |
4590 | { 0x21, HDA_INPUT, 4 }, | |
4591 | { } /* end */ | |
4592 | }; | |
4593 | #endif | |
4594 | ||
3e95b9ab LW |
4595 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
4596 | { | |
4597 | struct via_spec *spec = codec->spec; | |
4598 | int imux_is_smixer; | |
4599 | unsigned int parm; | |
4600 | /* MUX6 (1eh) = stereo mixer */ | |
4601 | imux_is_smixer = | |
4602 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | |
4603 | /* inputs */ | |
4604 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
4605 | parm = AC_PWRST_D3; | |
4606 | set_pin_power_state(codec, 0x29, &parm); | |
4607 | set_pin_power_state(codec, 0x2a, &parm); | |
4608 | set_pin_power_state(codec, 0x2b, &parm); | |
4609 | if (imux_is_smixer) | |
4610 | parm = AC_PWRST_D0; | |
4611 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
4612 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); | |
4613 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
4614 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
4615 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
4616 | ||
4617 | /* outputs */ | |
4618 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ | |
4619 | parm = AC_PWRST_D3; | |
4620 | set_pin_power_state(codec, 0x27, &parm); | |
4621 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); | |
4622 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); | |
4623 | ||
4624 | /* PW2 (26h), AOW2 (ah) */ | |
4625 | parm = AC_PWRST_D3; | |
4626 | set_pin_power_state(codec, 0x26, &parm); | |
4627 | if (spec->smart51_enabled) | |
4628 | set_pin_power_state(codec, 0x2b, &parm); | |
4629 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); | |
4630 | ||
4631 | /* PW0 (24h), AOW0 (8h) */ | |
4632 | parm = AC_PWRST_D3; | |
4633 | set_pin_power_state(codec, 0x24, &parm); | |
4634 | if (!spec->hp_independent_mode) /* check for redirected HP */ | |
4635 | set_pin_power_state(codec, 0x28, &parm); | |
4636 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); | |
4637 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ | |
4638 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, | |
4639 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
4640 | ||
4641 | /* PW1 (25h), AOW1 (9h) */ | |
4642 | parm = AC_PWRST_D3; | |
4643 | set_pin_power_state(codec, 0x25, &parm); | |
4644 | if (spec->smart51_enabled) | |
4645 | set_pin_power_state(codec, 0x2a, &parm); | |
4646 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); | |
4647 | ||
4648 | if (spec->hp_independent_mode) { | |
4649 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ | |
4650 | parm = AC_PWRST_D3; | |
4651 | set_pin_power_state(codec, 0x28, &parm); | |
4652 | snd_hda_codec_write(codec, 0x1b, 0, | |
4653 | AC_VERB_SET_POWER_STATE, parm); | |
4654 | snd_hda_codec_write(codec, 0x34, 0, | |
4655 | AC_VERB_SET_POWER_STATE, parm); | |
4656 | snd_hda_codec_write(codec, 0xc, 0, | |
4657 | AC_VERB_SET_POWER_STATE, parm); | |
4658 | } | |
4659 | } | |
4660 | ||
eb7188ca LW |
4661 | static int patch_vt1718S(struct hda_codec *codec) |
4662 | { | |
4663 | struct via_spec *spec; | |
4664 | int err; | |
4665 | ||
4666 | /* create a codec specific record */ | |
5b0cb1d8 | 4667 | spec = via_new_spec(codec); |
eb7188ca LW |
4668 | if (spec == NULL) |
4669 | return -ENOMEM; | |
4670 | ||
eb7188ca LW |
4671 | /* automatic parse from the BIOS config */ |
4672 | err = vt1718S_parse_auto_config(codec); | |
4673 | if (err < 0) { | |
4674 | via_free(codec); | |
4675 | return err; | |
4676 | } else if (!err) { | |
4677 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
4678 | "from BIOS. Using genenic mode...\n"); | |
4679 | } | |
4680 | ||
4681 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; | |
4682 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; | |
4683 | ||
bb3c6bfc LW |
4684 | if (codec->vendor_id == 0x11060441) |
4685 | spec->stream_name_analog = "VT2020 Analog"; | |
4686 | else if (codec->vendor_id == 0x11064441) | |
4687 | spec->stream_name_analog = "VT1828S Analog"; | |
4688 | else | |
4689 | spec->stream_name_analog = "VT1718S Analog"; | |
eb7188ca LW |
4690 | spec->stream_analog_playback = &vt1718S_pcm_analog_playback; |
4691 | spec->stream_analog_capture = &vt1718S_pcm_analog_capture; | |
4692 | ||
bb3c6bfc LW |
4693 | if (codec->vendor_id == 0x11060441) |
4694 | spec->stream_name_digital = "VT2020 Digital"; | |
4695 | else if (codec->vendor_id == 0x11064441) | |
4696 | spec->stream_name_digital = "VT1828S Digital"; | |
4697 | else | |
4698 | spec->stream_name_digital = "VT1718S Digital"; | |
eb7188ca | 4699 | spec->stream_digital_playback = &vt1718S_pcm_digital_playback; |
bb3c6bfc | 4700 | if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) |
eb7188ca LW |
4701 | spec->stream_digital_capture = &vt1718S_pcm_digital_capture; |
4702 | ||
a766d0d7 | 4703 | if (spec->adc_nids && spec->input_mux) { |
bb3c6bfc LW |
4704 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
4705 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
eb7188ca LW |
4706 | spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; |
4707 | spec->num_mixers++; | |
4708 | } | |
4709 | ||
4710 | codec->patch_ops = via_patch_ops; | |
4711 | ||
4712 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 4713 | codec->patch_ops.unsol_event = via_unsol_event; |
eb7188ca LW |
4714 | |
4715 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
4716 | spec->loopback.amplist = vt1718S_loopbacks; | |
4717 | #endif | |
4718 | ||
3e95b9ab LW |
4719 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
4720 | ||
eb7188ca LW |
4721 | return 0; |
4722 | } | |
f3db423d LW |
4723 | |
4724 | /* Patch for VT1716S */ | |
4725 | ||
4726 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, | |
4727 | struct snd_ctl_elem_info *uinfo) | |
4728 | { | |
4729 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
4730 | uinfo->count = 1; | |
4731 | uinfo->value.integer.min = 0; | |
4732 | uinfo->value.integer.max = 1; | |
4733 | return 0; | |
4734 | } | |
4735 | ||
4736 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, | |
4737 | struct snd_ctl_elem_value *ucontrol) | |
4738 | { | |
4739 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4740 | int index = 0; | |
4741 | ||
4742 | index = snd_hda_codec_read(codec, 0x26, 0, | |
4743 | AC_VERB_GET_CONNECT_SEL, 0); | |
4744 | if (index != -1) | |
4745 | *ucontrol->value.integer.value = index; | |
4746 | ||
4747 | return 0; | |
4748 | } | |
4749 | ||
4750 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, | |
4751 | struct snd_ctl_elem_value *ucontrol) | |
4752 | { | |
4753 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4754 | struct via_spec *spec = codec->spec; | |
4755 | int index = *ucontrol->value.integer.value; | |
4756 | ||
4757 | snd_hda_codec_write(codec, 0x26, 0, | |
4758 | AC_VERB_SET_CONNECT_SEL, index); | |
4759 | spec->dmic_enabled = index; | |
3e95b9ab | 4760 | set_widgets_power_state(codec); |
f3db423d LW |
4761 | return 1; |
4762 | } | |
4763 | ||
4764 | /* capture mixer elements */ | |
90dd48a1 | 4765 | static const struct snd_kcontrol_new vt1716S_capture_mixer[] = { |
f3db423d LW |
4766 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
4767 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | |
4768 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | |
4769 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | |
4770 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), | |
4771 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, | |
4772 | HDA_INPUT), | |
4773 | { | |
4774 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
4775 | .name = "Input Source", | |
4776 | .count = 1, | |
4777 | .info = via_mux_enum_info, | |
4778 | .get = via_mux_enum_get, | |
4779 | .put = via_mux_enum_put, | |
4780 | }, | |
4781 | { } /* end */ | |
4782 | }; | |
4783 | ||
90dd48a1 | 4784 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
f3db423d LW |
4785 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
4786 | { | |
4787 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
4788 | .name = "Digital Mic Capture Switch", | |
5b0cb1d8 | 4789 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
f3db423d LW |
4790 | .count = 1, |
4791 | .info = vt1716s_dmic_info, | |
4792 | .get = vt1716s_dmic_get, | |
4793 | .put = vt1716s_dmic_put, | |
4794 | }, | |
4795 | {} /* end */ | |
4796 | }; | |
4797 | ||
4798 | ||
4799 | /* mono-out mixer elements */ | |
90dd48a1 | 4800 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
f3db423d LW |
4801 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
4802 | { } /* end */ | |
4803 | }; | |
4804 | ||
90dd48a1 | 4805 | static const struct hda_verb vt1716S_volume_init_verbs[] = { |
f3db423d LW |
4806 | /* |
4807 | * Unmute ADC0-1 and set the default input to mic-in | |
4808 | */ | |
4809 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4810 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4811 | ||
4812 | ||
4813 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
4814 | * mixer widget | |
4815 | */ | |
4816 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
4817 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
4818 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
4819 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
4820 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
4821 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
4822 | ||
4823 | /* MUX Indices: Stereo Mixer = 5 */ | |
4824 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, | |
4825 | ||
4826 | /* Setup default input of PW4 to MW0 */ | |
4827 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
4828 | ||
4829 | /* Setup default input of SW1 as MW0 */ | |
4830 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
4831 | ||
4832 | /* Setup default input of SW4 as AOW0 */ | |
4833 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
4834 | ||
4835 | /* PW9 PW10 Output enable */ | |
4836 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
4837 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
4838 | ||
4839 | /* Unmute SW1, PW12 */ | |
4840 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
4841 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
4842 | /* PW12 Output enable */ | |
4843 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
4844 | /* Enable Boost Volume backdoor */ | |
4845 | {0x1, 0xf8a, 0x80}, | |
4846 | /* don't bybass mixer */ | |
4847 | {0x1, 0xf88, 0xc0}, | |
4848 | /* Enable mono output */ | |
4849 | {0x1, 0xf90, 0x08}, | |
4850 | { } | |
4851 | }; | |
4852 | ||
4853 | ||
90dd48a1 | 4854 | static const struct hda_verb vt1716S_uniwill_init_verbs[] = { |
f3db423d LW |
4855 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
4856 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, | |
4857 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4858 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4859 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4860 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, | |
4861 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, | |
4862 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4863 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
4864 | { } | |
4865 | }; | |
4866 | ||
90dd48a1 | 4867 | static const struct hda_pcm_stream vt1716S_pcm_analog_playback = { |
f3db423d LW |
4868 | .substreams = 2, |
4869 | .channels_min = 2, | |
4870 | .channels_max = 6, | |
4871 | .nid = 0x10, /* NID to query formats and rates */ | |
4872 | .ops = { | |
4873 | .open = via_playback_pcm_open, | |
4874 | .prepare = via_playback_multi_pcm_prepare, | |
4875 | .cleanup = via_playback_multi_pcm_cleanup, | |
4876 | .close = via_pcm_open_close, | |
4877 | }, | |
4878 | }; | |
4879 | ||
90dd48a1 | 4880 | static const struct hda_pcm_stream vt1716S_pcm_analog_capture = { |
f3db423d LW |
4881 | .substreams = 2, |
4882 | .channels_min = 2, | |
4883 | .channels_max = 2, | |
4884 | .nid = 0x13, /* NID to query formats and rates */ | |
4885 | .ops = { | |
4886 | .open = via_pcm_open_close, | |
4887 | .prepare = via_capture_pcm_prepare, | |
4888 | .cleanup = via_capture_pcm_cleanup, | |
4889 | .close = via_pcm_open_close, | |
4890 | }, | |
4891 | }; | |
4892 | ||
90dd48a1 | 4893 | static const struct hda_pcm_stream vt1716S_pcm_digital_playback = { |
f3db423d LW |
4894 | .substreams = 2, |
4895 | .channels_min = 2, | |
4896 | .channels_max = 2, | |
f3db423d LW |
4897 | /* NID is set in via_build_pcms */ |
4898 | .ops = { | |
4899 | .open = via_dig_playback_pcm_open, | |
4900 | .close = via_dig_playback_pcm_close, | |
4901 | .prepare = via_dig_playback_pcm_prepare, | |
4902 | .cleanup = via_dig_playback_pcm_cleanup | |
4903 | }, | |
4904 | }; | |
4905 | ||
4906 | /* fill in the dac_nids table from the parsed pin configuration */ | |
4907 | static int vt1716S_auto_fill_dac_nids(struct via_spec *spec, | |
4908 | const struct auto_pin_cfg *cfg) | |
4909 | { int i; | |
4910 | hda_nid_t nid; | |
4911 | ||
4912 | spec->multiout.num_dacs = cfg->line_outs; | |
4913 | ||
4914 | spec->multiout.dac_nids = spec->private_dac_nids; | |
4915 | ||
4916 | for (i = 0; i < 3; i++) { | |
4917 | nid = cfg->line_out_pins[i]; | |
4918 | if (nid) { | |
4919 | /* config dac list */ | |
4920 | switch (i) { | |
4921 | case AUTO_SEQ_FRONT: | |
dda14410 | 4922 | spec->private_dac_nids[i] = 0x10; |
f3db423d LW |
4923 | break; |
4924 | case AUTO_SEQ_CENLFE: | |
dda14410 | 4925 | spec->private_dac_nids[i] = 0x25; |
f3db423d LW |
4926 | break; |
4927 | case AUTO_SEQ_SURROUND: | |
dda14410 | 4928 | spec->private_dac_nids[i] = 0x11; |
f3db423d LW |
4929 | break; |
4930 | } | |
4931 | } | |
4932 | } | |
4933 | ||
4934 | return 0; | |
4935 | } | |
4936 | ||
4937 | /* add playback controls from the parsed DAC table */ | |
4938 | static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec, | |
4939 | const struct auto_pin_cfg *cfg) | |
4940 | { | |
4941 | char name[32]; | |
ea734963 TI |
4942 | static const char * const chname[3] = { |
4943 | "Front", "Surround", "C/LFE" | |
4944 | }; | |
f3db423d LW |
4945 | hda_nid_t nid_vols[] = {0x10, 0x11, 0x25}; |
4946 | hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27}; | |
4947 | hda_nid_t nid, nid_vol, nid_mute; | |
4948 | int i, err; | |
4949 | ||
4950 | for (i = 0; i <= AUTO_SEQ_CENLFE; i++) { | |
4951 | nid = cfg->line_out_pins[i]; | |
4952 | ||
4953 | if (!nid) | |
4954 | continue; | |
4955 | ||
4956 | nid_vol = nid_vols[i]; | |
4957 | nid_mute = nid_mutes[i]; | |
4958 | ||
4959 | if (i == AUTO_SEQ_CENLFE) { | |
4960 | err = via_add_control( | |
4961 | spec, VIA_CTL_WIDGET_VOL, | |
4962 | "Center Playback Volume", | |
4963 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT)); | |
4964 | if (err < 0) | |
4965 | return err; | |
4966 | err = via_add_control( | |
4967 | spec, VIA_CTL_WIDGET_VOL, | |
4968 | "LFE Playback Volume", | |
4969 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT)); | |
4970 | if (err < 0) | |
4971 | return err; | |
4972 | err = via_add_control( | |
4973 | spec, VIA_CTL_WIDGET_MUTE, | |
4974 | "Center Playback Switch", | |
4975 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, | |
4976 | HDA_OUTPUT)); | |
4977 | if (err < 0) | |
4978 | return err; | |
4979 | err = via_add_control( | |
4980 | spec, VIA_CTL_WIDGET_MUTE, | |
4981 | "LFE Playback Switch", | |
4982 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, | |
4983 | HDA_OUTPUT)); | |
4984 | if (err < 0) | |
4985 | return err; | |
4986 | } else if (i == AUTO_SEQ_FRONT) { | |
4987 | ||
4988 | err = via_add_control( | |
4989 | spec, VIA_CTL_WIDGET_VOL, | |
4990 | "Master Front Playback Volume", | |
4991 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); | |
4992 | if (err < 0) | |
4993 | return err; | |
4994 | err = via_add_control( | |
4995 | spec, VIA_CTL_WIDGET_MUTE, | |
4996 | "Master Front Playback Switch", | |
4997 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); | |
4998 | if (err < 0) | |
4999 | return err; | |
5000 | ||
5001 | sprintf(name, "%s Playback Volume", chname[i]); | |
5002 | err = via_add_control( | |
5003 | spec, VIA_CTL_WIDGET_VOL, name, | |
5004 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | |
5005 | if (err < 0) | |
5006 | return err; | |
5007 | sprintf(name, "%s Playback Switch", chname[i]); | |
5008 | err = via_add_control( | |
5009 | spec, VIA_CTL_WIDGET_MUTE, name, | |
5010 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | |
5011 | HDA_OUTPUT)); | |
5012 | if (err < 0) | |
5013 | return err; | |
5014 | } else { | |
5015 | sprintf(name, "%s Playback Volume", chname[i]); | |
5016 | err = via_add_control( | |
5017 | spec, VIA_CTL_WIDGET_VOL, name, | |
5018 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); | |
5019 | if (err < 0) | |
5020 | return err; | |
5021 | sprintf(name, "%s Playback Switch", chname[i]); | |
5022 | err = via_add_control( | |
5023 | spec, VIA_CTL_WIDGET_MUTE, name, | |
5024 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, | |
5025 | HDA_OUTPUT)); | |
5026 | if (err < 0) | |
5027 | return err; | |
5028 | } | |
5029 | } | |
5030 | return 0; | |
5031 | } | |
5032 | ||
5033 | static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
5034 | { | |
5035 | int err; | |
5036 | ||
5037 | if (!pin) | |
5038 | return 0; | |
5039 | ||
5040 | spec->multiout.hp_nid = 0x25; /* AOW3 */ | |
5041 | spec->hp_independent_mode_index = 1; | |
5042 | ||
5043 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
5044 | "Headphone Playback Volume", | |
5045 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); | |
5046 | if (err < 0) | |
5047 | return err; | |
5048 | ||
5049 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
5050 | "Headphone Playback Switch", | |
5051 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
5052 | if (err < 0) | |
5053 | return err; | |
5054 | ||
5055 | create_hp_imux(spec); | |
5056 | return 0; | |
5057 | } | |
5058 | ||
5059 | /* create playback/capture controls for input pins */ | |
10a20af7 | 5060 | static int vt1716S_auto_create_analog_input_ctls(struct hda_codec *codec, |
f3db423d LW |
5061 | const struct auto_pin_cfg *cfg) |
5062 | { | |
a766d0d7 | 5063 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x16); |
f3db423d LW |
5064 | } |
5065 | ||
5066 | static int vt1716S_parse_auto_config(struct hda_codec *codec) | |
5067 | { | |
5068 | struct via_spec *spec = codec->spec; | |
5069 | int err; | |
5070 | ||
5071 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
5072 | if (err < 0) | |
5073 | return err; | |
5074 | err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg); | |
5075 | if (err < 0) | |
5076 | return err; | |
5077 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
5078 | return 0; /* can't find valid BIOS pin config */ | |
5079 | ||
5080 | err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
5081 | if (err < 0) | |
5082 | return err; | |
5083 | err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
5084 | if (err < 0) | |
5085 | return err; | |
10a20af7 | 5086 | err = vt1716S_auto_create_analog_input_ctls(codec, &spec->autocfg); |
f3db423d LW |
5087 | if (err < 0) |
5088 | return err; | |
5089 | ||
5090 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
5091 | ||
5092 | fill_dig_outs(codec); | |
5093 | ||
5094 | if (spec->kctls.list) | |
5095 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
5096 | ||
5097 | spec->input_mux = &spec->private_imux[0]; | |
5098 | ||
5099 | if (spec->hp_mux) | |
3d83e577 | 5100 | via_hp_build(codec); |
f3db423d | 5101 | |
5b0cb1d8 | 5102 | via_smart51_build(spec); |
f3db423d LW |
5103 | |
5104 | return 1; | |
5105 | } | |
5106 | ||
5107 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 5108 | static const struct hda_amp_list vt1716S_loopbacks[] = { |
f3db423d LW |
5109 | { 0x16, HDA_INPUT, 1 }, |
5110 | { 0x16, HDA_INPUT, 2 }, | |
5111 | { 0x16, HDA_INPUT, 3 }, | |
5112 | { 0x16, HDA_INPUT, 4 }, | |
5113 | { } /* end */ | |
5114 | }; | |
5115 | #endif | |
5116 | ||
3e95b9ab LW |
5117 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
5118 | { | |
5119 | struct via_spec *spec = codec->spec; | |
5120 | int imux_is_smixer; | |
5121 | unsigned int parm; | |
5122 | unsigned int mono_out, present; | |
5123 | /* SW0 (17h) = stereo mixer */ | |
5124 | imux_is_smixer = | |
5125 | (snd_hda_codec_read(codec, 0x17, 0, | |
5126 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); | |
5127 | /* inputs */ | |
5128 | /* PW 1/2/5 (1ah/1bh/1eh) */ | |
5129 | parm = AC_PWRST_D3; | |
5130 | set_pin_power_state(codec, 0x1a, &parm); | |
5131 | set_pin_power_state(codec, 0x1b, &parm); | |
5132 | set_pin_power_state(codec, 0x1e, &parm); | |
5133 | if (imux_is_smixer) | |
5134 | parm = AC_PWRST_D0; | |
5135 | /* SW0 (17h), AIW0(13h) */ | |
5136 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); | |
5137 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); | |
5138 | ||
5139 | parm = AC_PWRST_D3; | |
5140 | set_pin_power_state(codec, 0x1e, &parm); | |
5141 | /* PW11 (22h) */ | |
5142 | if (spec->dmic_enabled) | |
5143 | set_pin_power_state(codec, 0x22, &parm); | |
5144 | else | |
5145 | snd_hda_codec_write(codec, 0x22, 0, | |
5146 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
5147 | ||
5148 | /* SW2(26h), AIW1(14h) */ | |
5149 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); | |
5150 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); | |
5151 | ||
5152 | /* outputs */ | |
5153 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | |
5154 | parm = AC_PWRST_D3; | |
5155 | set_pin_power_state(codec, 0x19, &parm); | |
5156 | /* Smart 5.1 PW2(1bh) */ | |
5157 | if (spec->smart51_enabled) | |
5158 | set_pin_power_state(codec, 0x1b, &parm); | |
5159 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); | |
5160 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
5161 | ||
5162 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ | |
5163 | parm = AC_PWRST_D3; | |
5164 | set_pin_power_state(codec, 0x23, &parm); | |
5165 | /* Smart 5.1 PW1(1ah) */ | |
5166 | if (spec->smart51_enabled) | |
5167 | set_pin_power_state(codec, 0x1a, &parm); | |
5168 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); | |
5169 | ||
5170 | /* Smart 5.1 PW5(1eh) */ | |
5171 | if (spec->smart51_enabled) | |
5172 | set_pin_power_state(codec, 0x1e, &parm); | |
5173 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); | |
5174 | ||
5175 | /* Mono out */ | |
5176 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ | |
5177 | present = snd_hda_jack_detect(codec, 0x1c); | |
5178 | ||
5179 | if (present) | |
5180 | mono_out = 0; | |
5181 | else { | |
5182 | present = snd_hda_jack_detect(codec, 0x1d); | |
5183 | if (!spec->hp_independent_mode && present) | |
5184 | mono_out = 0; | |
5185 | else | |
5186 | mono_out = 1; | |
5187 | } | |
5188 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; | |
5189 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); | |
5190 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); | |
5191 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); | |
5192 | ||
5193 | /* PW 3/4 (1ch/1dh) */ | |
5194 | parm = AC_PWRST_D3; | |
5195 | set_pin_power_state(codec, 0x1c, &parm); | |
5196 | set_pin_power_state(codec, 0x1d, &parm); | |
5197 | /* HP Independent Mode, power on AOW3 */ | |
5198 | if (spec->hp_independent_mode) | |
5199 | snd_hda_codec_write(codec, 0x25, 0, | |
5200 | AC_VERB_SET_POWER_STATE, parm); | |
5201 | ||
5202 | /* force to D0 for internal Speaker */ | |
5203 | /* MW0 (16h), AOW0 (10h) */ | |
5204 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, | |
5205 | imux_is_smixer ? AC_PWRST_D0 : parm); | |
5206 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, | |
5207 | mono_out ? AC_PWRST_D0 : parm); | |
5208 | } | |
5209 | ||
f3db423d LW |
5210 | static int patch_vt1716S(struct hda_codec *codec) |
5211 | { | |
5212 | struct via_spec *spec; | |
5213 | int err; | |
5214 | ||
5215 | /* create a codec specific record */ | |
5b0cb1d8 | 5216 | spec = via_new_spec(codec); |
f3db423d LW |
5217 | if (spec == NULL) |
5218 | return -ENOMEM; | |
5219 | ||
f3db423d LW |
5220 | /* automatic parse from the BIOS config */ |
5221 | err = vt1716S_parse_auto_config(codec); | |
5222 | if (err < 0) { | |
5223 | via_free(codec); | |
5224 | return err; | |
5225 | } else if (!err) { | |
5226 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
5227 | "from BIOS. Using genenic mode...\n"); | |
5228 | } | |
5229 | ||
5230 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; | |
5231 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; | |
5232 | ||
5233 | spec->stream_name_analog = "VT1716S Analog"; | |
5234 | spec->stream_analog_playback = &vt1716S_pcm_analog_playback; | |
5235 | spec->stream_analog_capture = &vt1716S_pcm_analog_capture; | |
5236 | ||
5237 | spec->stream_name_digital = "VT1716S Digital"; | |
5238 | spec->stream_digital_playback = &vt1716S_pcm_digital_playback; | |
5239 | ||
a766d0d7 | 5240 | if (spec->adc_nids && spec->input_mux) { |
f3db423d LW |
5241 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
5242 | override_mic_boost(codec, 0x1e, 0, 3, 40); | |
5243 | spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; | |
5244 | spec->num_mixers++; | |
5245 | } | |
5246 | ||
5247 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; | |
5248 | spec->num_mixers++; | |
5249 | ||
5250 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; | |
5251 | ||
5252 | codec->patch_ops = via_patch_ops; | |
5253 | ||
5254 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 5255 | codec->patch_ops.unsol_event = via_unsol_event; |
f3db423d LW |
5256 | |
5257 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
5258 | spec->loopback.amplist = vt1716S_loopbacks; | |
5259 | #endif | |
5260 | ||
3e95b9ab | 5261 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
f3db423d LW |
5262 | return 0; |
5263 | } | |
25eaba2f LW |
5264 | |
5265 | /* for vt2002P */ | |
5266 | ||
5267 | /* capture mixer elements */ | |
90dd48a1 | 5268 | static const struct snd_kcontrol_new vt2002P_capture_mixer[] = { |
25eaba2f LW |
5269 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
5270 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), | |
5271 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), | |
5272 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), | |
5273 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), | |
5274 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, | |
5275 | HDA_INPUT), | |
5276 | { | |
5277 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
5278 | /* The multiple "Capture Source" controls confuse alsamixer | |
5279 | * So call somewhat different.. | |
5280 | */ | |
5281 | /* .name = "Capture Source", */ | |
5282 | .name = "Input Source", | |
5283 | .count = 2, | |
5284 | .info = via_mux_enum_info, | |
5285 | .get = via_mux_enum_get, | |
5286 | .put = via_mux_enum_put, | |
5287 | }, | |
5288 | { } /* end */ | |
5289 | }; | |
5290 | ||
90dd48a1 | 5291 | static const struct hda_verb vt2002P_volume_init_verbs[] = { |
eadb9a80 LW |
5292 | /* Class-D speaker related verbs */ |
5293 | {0x1, 0xfe0, 0x4}, | |
5294 | {0x1, 0xfe9, 0x80}, | |
5295 | {0x1, 0xfe2, 0x22}, | |
25eaba2f LW |
5296 | /* |
5297 | * Unmute ADC0-1 and set the default input to mic-in | |
5298 | */ | |
5299 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5300 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5301 | ||
5302 | ||
5303 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
5304 | * mixer widget | |
5305 | */ | |
5306 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
5307 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
5308 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
5309 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
5310 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
5311 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
5312 | ||
5313 | /* MUX Indices: Mic = 0 */ | |
5314 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | |
5315 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | |
5316 | ||
5317 | /* PW9 Output enable */ | |
5318 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
5319 | ||
5320 | /* Enable Boost Volume backdoor */ | |
5321 | {0x1, 0xfb9, 0x24}, | |
5322 | ||
5323 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | |
5324 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5325 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5326 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5327 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5328 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5329 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5330 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5331 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5332 | ||
5333 | /* set MUX0/1/4/8 = 0 (AOW0) */ | |
5334 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | |
5335 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | |
5336 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, | |
5337 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, | |
5338 | ||
5339 | /* set PW0 index=0 (MW0) */ | |
5340 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, | |
5341 | ||
5342 | /* Enable AOW0 to MW9 */ | |
5343 | {0x1, 0xfb8, 0x88}, | |
5344 | { } | |
5345 | }; | |
90dd48a1 | 5346 | static const struct hda_verb vt1802_volume_init_verbs[] = { |
11890956 LW |
5347 | /* |
5348 | * Unmute ADC0-1 and set the default input to mic-in | |
5349 | */ | |
5350 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5351 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5352 | ||
5353 | ||
5354 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
5355 | * mixer widget | |
5356 | */ | |
5357 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
5358 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
5359 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
5360 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
5361 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
5362 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
5363 | ||
5364 | /* MUX Indices: Mic = 0 */ | |
5365 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | |
5366 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | |
5367 | ||
5368 | /* PW9 Output enable */ | |
5369 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
5370 | ||
5371 | /* Enable Boost Volume backdoor */ | |
5372 | {0x1, 0xfb9, 0x24}, | |
5373 | ||
5374 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | |
5375 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5376 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5377 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5378 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5379 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5380 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5381 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5382 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5383 | ||
5384 | /* set MUX0/1/4/8 = 0 (AOW0) */ | |
5385 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | |
5386 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | |
5387 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, | |
5388 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, | |
5389 | ||
5390 | /* set PW0 index=0 (MW0) */ | |
5391 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, | |
5392 | ||
5393 | /* Enable AOW0 to MW9 */ | |
5394 | {0x1, 0xfb8, 0x88}, | |
5395 | { } | |
5396 | }; | |
25eaba2f LW |
5397 | |
5398 | ||
90dd48a1 | 5399 | static const struct hda_verb vt2002P_uniwill_init_verbs[] = { |
25eaba2f LW |
5400 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
5401 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
5402 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, | |
5403 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
5404 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5405 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5406 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5407 | { } | |
5408 | }; | |
90dd48a1 | 5409 | static const struct hda_verb vt1802_uniwill_init_verbs[] = { |
11890956 LW |
5410 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
5411 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
5412 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, | |
5413 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
5414 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5415 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5416 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5417 | { } | |
5418 | }; | |
25eaba2f | 5419 | |
90dd48a1 | 5420 | static const struct hda_pcm_stream vt2002P_pcm_analog_playback = { |
25eaba2f LW |
5421 | .substreams = 2, |
5422 | .channels_min = 2, | |
5423 | .channels_max = 2, | |
5424 | .nid = 0x8, /* NID to query formats and rates */ | |
5425 | .ops = { | |
5426 | .open = via_playback_pcm_open, | |
5427 | .prepare = via_playback_multi_pcm_prepare, | |
5428 | .cleanup = via_playback_multi_pcm_cleanup, | |
5429 | .close = via_pcm_open_close, | |
5430 | }, | |
5431 | }; | |
5432 | ||
90dd48a1 | 5433 | static const struct hda_pcm_stream vt2002P_pcm_analog_capture = { |
25eaba2f LW |
5434 | .substreams = 2, |
5435 | .channels_min = 2, | |
5436 | .channels_max = 2, | |
5437 | .nid = 0x10, /* NID to query formats and rates */ | |
5438 | .ops = { | |
5439 | .open = via_pcm_open_close, | |
5440 | .prepare = via_capture_pcm_prepare, | |
5441 | .cleanup = via_capture_pcm_cleanup, | |
5442 | .close = via_pcm_open_close, | |
5443 | }, | |
5444 | }; | |
5445 | ||
90dd48a1 | 5446 | static const struct hda_pcm_stream vt2002P_pcm_digital_playback = { |
25eaba2f LW |
5447 | .substreams = 1, |
5448 | .channels_min = 2, | |
5449 | .channels_max = 2, | |
25eaba2f LW |
5450 | /* NID is set in via_build_pcms */ |
5451 | .ops = { | |
5452 | .open = via_dig_playback_pcm_open, | |
5453 | .close = via_dig_playback_pcm_close, | |
5454 | .prepare = via_dig_playback_pcm_prepare, | |
5455 | .cleanup = via_dig_playback_pcm_cleanup | |
5456 | }, | |
5457 | }; | |
5458 | ||
5459 | /* fill in the dac_nids table from the parsed pin configuration */ | |
5460 | static int vt2002P_auto_fill_dac_nids(struct via_spec *spec, | |
5461 | const struct auto_pin_cfg *cfg) | |
5462 | { | |
5463 | spec->multiout.num_dacs = 1; | |
5464 | spec->multiout.dac_nids = spec->private_dac_nids; | |
5465 | if (cfg->line_out_pins[0]) | |
dda14410 | 5466 | spec->private_dac_nids[0] = 0x8; |
25eaba2f LW |
5467 | return 0; |
5468 | } | |
5469 | ||
5470 | /* add playback controls from the parsed DAC table */ | |
5471 | static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec, | |
5472 | const struct auto_pin_cfg *cfg) | |
5473 | { | |
5474 | int err; | |
11890956 | 5475 | hda_nid_t sw_nid; |
25eaba2f LW |
5476 | |
5477 | if (!cfg->line_out_pins[0]) | |
5478 | return -1; | |
5479 | ||
11890956 LW |
5480 | if (spec->codec_type == VT1802) |
5481 | sw_nid = 0x28; | |
5482 | else | |
5483 | sw_nid = 0x26; | |
25eaba2f LW |
5484 | |
5485 | /* Line-Out: PortE */ | |
5486 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
5487 | "Master Front Playback Volume", | |
5488 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); | |
5489 | if (err < 0) | |
5490 | return err; | |
5491 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, | |
5492 | "Master Front Playback Switch", | |
11890956 | 5493 | HDA_COMPOSE_AMP_VAL(sw_nid, 3, 0, HDA_OUTPUT)); |
25eaba2f LW |
5494 | if (err < 0) |
5495 | return err; | |
5496 | ||
5497 | return 0; | |
5498 | } | |
5499 | ||
5500 | static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
5501 | { | |
5502 | int err; | |
5503 | ||
5504 | if (!pin) | |
5505 | return 0; | |
5506 | ||
5507 | spec->multiout.hp_nid = 0x9; | |
5508 | spec->hp_independent_mode_index = 1; | |
5509 | ||
5510 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
5511 | "Headphone Playback Volume", | |
5512 | HDA_COMPOSE_AMP_VAL( | |
5513 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); | |
5514 | if (err < 0) | |
5515 | return err; | |
5516 | ||
5517 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
5518 | "Headphone Playback Switch", | |
5519 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); | |
5520 | if (err < 0) | |
5521 | return err; | |
5522 | ||
5523 | create_hp_imux(spec); | |
5524 | return 0; | |
5525 | } | |
5526 | ||
5527 | /* create playback/capture controls for input pins */ | |
10a20af7 | 5528 | static int vt2002P_auto_create_analog_input_ctls(struct hda_codec *codec, |
25eaba2f LW |
5529 | const struct auto_pin_cfg *cfg) |
5530 | { | |
a766d0d7 | 5531 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); |
25eaba2f LW |
5532 | } |
5533 | ||
5534 | static int vt2002P_parse_auto_config(struct hda_codec *codec) | |
5535 | { | |
5536 | struct via_spec *spec = codec->spec; | |
5537 | int err; | |
5538 | ||
5539 | ||
5540 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
5541 | if (err < 0) | |
5542 | return err; | |
5543 | ||
5544 | err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg); | |
5545 | if (err < 0) | |
5546 | return err; | |
5547 | ||
5548 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
5549 | return 0; /* can't find valid BIOS pin config */ | |
5550 | ||
5551 | err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
5552 | if (err < 0) | |
5553 | return err; | |
5554 | err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
5555 | if (err < 0) | |
5556 | return err; | |
10a20af7 | 5557 | err = vt2002P_auto_create_analog_input_ctls(codec, &spec->autocfg); |
25eaba2f LW |
5558 | if (err < 0) |
5559 | return err; | |
5560 | ||
5561 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
5562 | ||
5563 | fill_dig_outs(codec); | |
5564 | ||
5565 | if (spec->kctls.list) | |
5566 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
5567 | ||
5568 | spec->input_mux = &spec->private_imux[0]; | |
5569 | ||
5570 | if (spec->hp_mux) | |
3d83e577 | 5571 | via_hp_build(codec); |
25eaba2f LW |
5572 | |
5573 | return 1; | |
5574 | } | |
5575 | ||
5576 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 5577 | static const struct hda_amp_list vt2002P_loopbacks[] = { |
25eaba2f LW |
5578 | { 0x21, HDA_INPUT, 0 }, |
5579 | { 0x21, HDA_INPUT, 1 }, | |
5580 | { 0x21, HDA_INPUT, 2 }, | |
5581 | { } /* end */ | |
5582 | }; | |
5583 | #endif | |
5584 | ||
3e95b9ab LW |
5585 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
5586 | { | |
5587 | struct via_spec *spec = codec->spec; | |
5588 | int imux_is_smixer; | |
5589 | unsigned int parm; | |
5590 | unsigned int present; | |
5591 | /* MUX9 (1eh) = stereo mixer */ | |
5592 | imux_is_smixer = | |
5593 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
5594 | /* inputs */ | |
5595 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
5596 | parm = AC_PWRST_D3; | |
5597 | set_pin_power_state(codec, 0x29, &parm); | |
5598 | set_pin_power_state(codec, 0x2a, &parm); | |
5599 | set_pin_power_state(codec, 0x2b, &parm); | |
5600 | parm = AC_PWRST_D0; | |
5601 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
5602 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); | |
5603 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
5604 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
5605 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
5606 | ||
5607 | /* outputs */ | |
5608 | /* AOW0 (8h)*/ | |
5609 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); | |
5610 | ||
11890956 LW |
5611 | if (spec->codec_type == VT1802) { |
5612 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | |
5613 | parm = AC_PWRST_D3; | |
5614 | set_pin_power_state(codec, 0x28, &parm); | |
5615 | snd_hda_codec_write(codec, 0x18, 0, | |
5616 | AC_VERB_SET_POWER_STATE, parm); | |
5617 | snd_hda_codec_write(codec, 0x38, 0, | |
5618 | AC_VERB_SET_POWER_STATE, parm); | |
5619 | } else { | |
5620 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ | |
5621 | parm = AC_PWRST_D3; | |
5622 | set_pin_power_state(codec, 0x26, &parm); | |
5623 | snd_hda_codec_write(codec, 0x1c, 0, | |
5624 | AC_VERB_SET_POWER_STATE, parm); | |
5625 | snd_hda_codec_write(codec, 0x37, 0, | |
5626 | AC_VERB_SET_POWER_STATE, parm); | |
5627 | } | |
3e95b9ab | 5628 | |
11890956 LW |
5629 | if (spec->codec_type == VT1802) { |
5630 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | |
5631 | parm = AC_PWRST_D3; | |
5632 | set_pin_power_state(codec, 0x25, &parm); | |
5633 | snd_hda_codec_write(codec, 0x15, 0, | |
5634 | AC_VERB_SET_POWER_STATE, parm); | |
5635 | snd_hda_codec_write(codec, 0x35, 0, | |
5636 | AC_VERB_SET_POWER_STATE, parm); | |
5637 | } else { | |
5638 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ | |
5639 | parm = AC_PWRST_D3; | |
5640 | set_pin_power_state(codec, 0x25, &parm); | |
5641 | snd_hda_codec_write(codec, 0x19, 0, | |
5642 | AC_VERB_SET_POWER_STATE, parm); | |
5643 | snd_hda_codec_write(codec, 0x35, 0, | |
5644 | AC_VERB_SET_POWER_STATE, parm); | |
5645 | } | |
3e95b9ab LW |
5646 | |
5647 | if (spec->hp_independent_mode) | |
5648 | snd_hda_codec_write(codec, 0x9, 0, | |
5649 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
5650 | ||
5651 | /* Class-D */ | |
5652 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ | |
5653 | present = snd_hda_jack_detect(codec, 0x25); | |
5654 | ||
5655 | parm = AC_PWRST_D3; | |
5656 | set_pin_power_state(codec, 0x24, &parm); | |
5657 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; | |
11890956 LW |
5658 | if (spec->codec_type == VT1802) |
5659 | snd_hda_codec_write(codec, 0x14, 0, | |
5660 | AC_VERB_SET_POWER_STATE, parm); | |
5661 | else | |
5662 | snd_hda_codec_write(codec, 0x18, 0, | |
5663 | AC_VERB_SET_POWER_STATE, parm); | |
3e95b9ab LW |
5664 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
5665 | ||
5666 | /* Mono Out */ | |
5667 | present = snd_hda_jack_detect(codec, 0x26); | |
5668 | ||
5669 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; | |
11890956 LW |
5670 | if (spec->codec_type == VT1802) { |
5671 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ | |
5672 | snd_hda_codec_write(codec, 0x33, 0, | |
5673 | AC_VERB_SET_POWER_STATE, parm); | |
5674 | snd_hda_codec_write(codec, 0x1c, 0, | |
5675 | AC_VERB_SET_POWER_STATE, parm); | |
5676 | snd_hda_codec_write(codec, 0x3c, 0, | |
5677 | AC_VERB_SET_POWER_STATE, parm); | |
5678 | } else { | |
5679 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ | |
5680 | snd_hda_codec_write(codec, 0x31, 0, | |
5681 | AC_VERB_SET_POWER_STATE, parm); | |
5682 | snd_hda_codec_write(codec, 0x17, 0, | |
5683 | AC_VERB_SET_POWER_STATE, parm); | |
5684 | snd_hda_codec_write(codec, 0x3b, 0, | |
5685 | AC_VERB_SET_POWER_STATE, parm); | |
5686 | } | |
3e95b9ab LW |
5687 | /* MW9 (21h) */ |
5688 | if (imux_is_smixer || !is_aa_path_mute(codec)) | |
5689 | snd_hda_codec_write(codec, 0x21, 0, | |
5690 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
5691 | else | |
5692 | snd_hda_codec_write(codec, 0x21, 0, | |
5693 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
5694 | } | |
25eaba2f LW |
5695 | |
5696 | /* patch for vt2002P */ | |
5697 | static int patch_vt2002P(struct hda_codec *codec) | |
5698 | { | |
5699 | struct via_spec *spec; | |
5700 | int err; | |
5701 | ||
5702 | /* create a codec specific record */ | |
5b0cb1d8 | 5703 | spec = via_new_spec(codec); |
25eaba2f LW |
5704 | if (spec == NULL) |
5705 | return -ENOMEM; | |
5706 | ||
25eaba2f LW |
5707 | /* automatic parse from the BIOS config */ |
5708 | err = vt2002P_parse_auto_config(codec); | |
5709 | if (err < 0) { | |
5710 | via_free(codec); | |
5711 | return err; | |
5712 | } else if (!err) { | |
5713 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
5714 | "from BIOS. Using genenic mode...\n"); | |
5715 | } | |
5716 | ||
11890956 LW |
5717 | if (spec->codec_type == VT1802) |
5718 | spec->init_verbs[spec->num_iverbs++] = | |
5719 | vt1802_volume_init_verbs; | |
5720 | else | |
5721 | spec->init_verbs[spec->num_iverbs++] = | |
5722 | vt2002P_volume_init_verbs; | |
25eaba2f | 5723 | |
11890956 LW |
5724 | if (spec->codec_type == VT1802) |
5725 | spec->init_verbs[spec->num_iverbs++] = | |
5726 | vt1802_uniwill_init_verbs; | |
5727 | else | |
5728 | spec->init_verbs[spec->num_iverbs++] = | |
5729 | vt2002P_uniwill_init_verbs; | |
5730 | ||
5731 | if (spec->codec_type == VT1802) | |
5732 | spec->stream_name_analog = "VT1802 Analog"; | |
5733 | else | |
5734 | spec->stream_name_analog = "VT2002P Analog"; | |
25eaba2f LW |
5735 | spec->stream_analog_playback = &vt2002P_pcm_analog_playback; |
5736 | spec->stream_analog_capture = &vt2002P_pcm_analog_capture; | |
5737 | ||
11890956 LW |
5738 | if (spec->codec_type == VT1802) |
5739 | spec->stream_name_digital = "VT1802 Digital"; | |
5740 | else | |
5741 | spec->stream_name_digital = "VT2002P Digital"; | |
25eaba2f LW |
5742 | spec->stream_digital_playback = &vt2002P_pcm_digital_playback; |
5743 | ||
a766d0d7 | 5744 | if (spec->adc_nids && spec->input_mux) { |
25eaba2f LW |
5745 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
5746 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
5747 | spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; | |
5748 | spec->num_mixers++; | |
5749 | } | |
5750 | ||
5751 | codec->patch_ops = via_patch_ops; | |
5752 | ||
5753 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 5754 | codec->patch_ops.unsol_event = via_unsol_event; |
25eaba2f LW |
5755 | |
5756 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
5757 | spec->loopback.amplist = vt2002P_loopbacks; | |
5758 | #endif | |
5759 | ||
3e95b9ab | 5760 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
25eaba2f LW |
5761 | return 0; |
5762 | } | |
ab6734e7 LW |
5763 | |
5764 | /* for vt1812 */ | |
5765 | ||
5766 | /* capture mixer elements */ | |
90dd48a1 | 5767 | static const struct snd_kcontrol_new vt1812_capture_mixer[] = { |
ab6734e7 LW |
5768 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
5769 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), | |
5770 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), | |
5771 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), | |
5772 | HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), | |
5773 | HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, | |
5774 | HDA_INPUT), | |
5775 | { | |
5776 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
5777 | /* The multiple "Capture Source" controls confuse alsamixer | |
5778 | * So call somewhat different.. | |
5779 | */ | |
5780 | .name = "Input Source", | |
5781 | .count = 2, | |
5782 | .info = via_mux_enum_info, | |
5783 | .get = via_mux_enum_get, | |
5784 | .put = via_mux_enum_put, | |
5785 | }, | |
5786 | { } /* end */ | |
5787 | }; | |
5788 | ||
90dd48a1 | 5789 | static const struct hda_verb vt1812_volume_init_verbs[] = { |
ab6734e7 LW |
5790 | /* |
5791 | * Unmute ADC0-1 and set the default input to mic-in | |
5792 | */ | |
5793 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5794 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5795 | ||
5796 | ||
5797 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
5798 | * mixer widget | |
5799 | */ | |
5800 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
5801 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
5802 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
5803 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
5804 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
5805 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
5806 | ||
5807 | /* MUX Indices: Mic = 0 */ | |
5808 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, | |
5809 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, | |
5810 | ||
5811 | /* PW9 Output enable */ | |
5812 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, | |
5813 | ||
5814 | /* Enable Boost Volume backdoor */ | |
5815 | {0x1, 0xfb9, 0x24}, | |
5816 | ||
5817 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ | |
5818 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5819 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5820 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5821 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5822 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
5823 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5824 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5825 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5826 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5827 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
5828 | ||
5829 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ | |
5830 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, | |
5831 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, | |
5832 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, | |
5833 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, | |
5834 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, | |
5835 | ||
5836 | /* Enable AOW0 to MW9 */ | |
5837 | {0x1, 0xfb8, 0xa8}, | |
5838 | { } | |
5839 | }; | |
5840 | ||
5841 | ||
90dd48a1 | 5842 | static const struct hda_verb vt1812_uniwill_init_verbs[] = { |
ab6734e7 LW |
5843 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
5844 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
5845 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, | |
5846 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, | |
5847 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, | |
5848 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5849 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5850 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, | |
5851 | { } | |
5852 | }; | |
5853 | ||
90dd48a1 | 5854 | static const struct hda_pcm_stream vt1812_pcm_analog_playback = { |
ab6734e7 LW |
5855 | .substreams = 2, |
5856 | .channels_min = 2, | |
5857 | .channels_max = 2, | |
5858 | .nid = 0x8, /* NID to query formats and rates */ | |
5859 | .ops = { | |
5860 | .open = via_playback_pcm_open, | |
5861 | .prepare = via_playback_multi_pcm_prepare, | |
5862 | .cleanup = via_playback_multi_pcm_cleanup, | |
5863 | .close = via_pcm_open_close, | |
5864 | }, | |
5865 | }; | |
5866 | ||
90dd48a1 | 5867 | static const struct hda_pcm_stream vt1812_pcm_analog_capture = { |
ab6734e7 LW |
5868 | .substreams = 2, |
5869 | .channels_min = 2, | |
5870 | .channels_max = 2, | |
5871 | .nid = 0x10, /* NID to query formats and rates */ | |
5872 | .ops = { | |
5873 | .open = via_pcm_open_close, | |
5874 | .prepare = via_capture_pcm_prepare, | |
5875 | .cleanup = via_capture_pcm_cleanup, | |
5876 | .close = via_pcm_open_close, | |
5877 | }, | |
5878 | }; | |
5879 | ||
90dd48a1 | 5880 | static const struct hda_pcm_stream vt1812_pcm_digital_playback = { |
ab6734e7 LW |
5881 | .substreams = 1, |
5882 | .channels_min = 2, | |
5883 | .channels_max = 2, | |
ab6734e7 LW |
5884 | /* NID is set in via_build_pcms */ |
5885 | .ops = { | |
5886 | .open = via_dig_playback_pcm_open, | |
5887 | .close = via_dig_playback_pcm_close, | |
5888 | .prepare = via_dig_playback_pcm_prepare, | |
5889 | .cleanup = via_dig_playback_pcm_cleanup | |
5890 | }, | |
5891 | }; | |
5892 | /* fill in the dac_nids table from the parsed pin configuration */ | |
5893 | static int vt1812_auto_fill_dac_nids(struct via_spec *spec, | |
5894 | const struct auto_pin_cfg *cfg) | |
5895 | { | |
5896 | spec->multiout.num_dacs = 1; | |
5897 | spec->multiout.dac_nids = spec->private_dac_nids; | |
5898 | if (cfg->line_out_pins[0]) | |
dda14410 | 5899 | spec->private_dac_nids[0] = 0x8; |
ab6734e7 LW |
5900 | return 0; |
5901 | } | |
5902 | ||
5903 | ||
5904 | /* add playback controls from the parsed DAC table */ | |
5905 | static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec, | |
5906 | const struct auto_pin_cfg *cfg) | |
5907 | { | |
5908 | int err; | |
5909 | ||
5910 | if (!cfg->line_out_pins[0]) | |
5911 | return -1; | |
5912 | ||
5913 | /* Line-Out: PortE */ | |
5914 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3d83e577 | 5915 | "Front Playback Volume", |
ab6734e7 LW |
5916 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); |
5917 | if (err < 0) | |
5918 | return err; | |
5919 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, | |
3d83e577 | 5920 | "Front Playback Switch", |
ab6734e7 LW |
5921 | HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT)); |
5922 | if (err < 0) | |
5923 | return err; | |
5924 | ||
5925 | return 0; | |
5926 | } | |
5927 | ||
5928 | static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
5929 | { | |
5930 | int err; | |
5931 | ||
5932 | if (!pin) | |
5933 | return 0; | |
5934 | ||
5935 | spec->multiout.hp_nid = 0x9; | |
5936 | spec->hp_independent_mode_index = 1; | |
5937 | ||
5938 | ||
5939 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
5940 | "Headphone Playback Volume", | |
5941 | HDA_COMPOSE_AMP_VAL( | |
5942 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); | |
5943 | if (err < 0) | |
5944 | return err; | |
5945 | ||
5946 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
5947 | "Headphone Playback Switch", | |
5948 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
5949 | if (err < 0) | |
5950 | return err; | |
5951 | ||
5952 | create_hp_imux(spec); | |
5953 | return 0; | |
5954 | } | |
5955 | ||
5956 | /* create playback/capture controls for input pins */ | |
10a20af7 | 5957 | static int vt1812_auto_create_analog_input_ctls(struct hda_codec *codec, |
ab6734e7 LW |
5958 | const struct auto_pin_cfg *cfg) |
5959 | { | |
a766d0d7 | 5960 | return vt_auto_create_analog_input_ctls(codec, cfg, 0x21); |
ab6734e7 LW |
5961 | } |
5962 | ||
5963 | static int vt1812_parse_auto_config(struct hda_codec *codec) | |
5964 | { | |
5965 | struct via_spec *spec = codec->spec; | |
5966 | int err; | |
5967 | ||
5968 | ||
5969 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
5970 | if (err < 0) | |
5971 | return err; | |
5972 | fill_dig_outs(codec); | |
5973 | err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg); | |
5974 | if (err < 0) | |
5975 | return err; | |
5976 | ||
5977 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) | |
5978 | return 0; /* can't find valid BIOS pin config */ | |
5979 | ||
5980 | err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
5981 | if (err < 0) | |
5982 | return err; | |
5983 | err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
5984 | if (err < 0) | |
5985 | return err; | |
10a20af7 | 5986 | err = vt1812_auto_create_analog_input_ctls(codec, &spec->autocfg); |
ab6734e7 LW |
5987 | if (err < 0) |
5988 | return err; | |
5989 | ||
5990 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
5991 | ||
5992 | fill_dig_outs(codec); | |
5993 | ||
5994 | if (spec->kctls.list) | |
5995 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
5996 | ||
5997 | spec->input_mux = &spec->private_imux[0]; | |
5998 | ||
5999 | if (spec->hp_mux) | |
3d83e577 | 6000 | via_hp_build(codec); |
ab6734e7 LW |
6001 | |
6002 | return 1; | |
6003 | } | |
6004 | ||
6005 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
90dd48a1 | 6006 | static const struct hda_amp_list vt1812_loopbacks[] = { |
ab6734e7 LW |
6007 | { 0x21, HDA_INPUT, 0 }, |
6008 | { 0x21, HDA_INPUT, 1 }, | |
6009 | { 0x21, HDA_INPUT, 2 }, | |
6010 | { } /* end */ | |
6011 | }; | |
6012 | #endif | |
6013 | ||
3e95b9ab LW |
6014 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
6015 | { | |
6016 | struct via_spec *spec = codec->spec; | |
6017 | int imux_is_smixer = | |
6018 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
6019 | unsigned int parm; | |
6020 | unsigned int present; | |
6021 | /* MUX10 (1eh) = stereo mixer */ | |
6022 | imux_is_smixer = | |
6023 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | |
6024 | /* inputs */ | |
6025 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
6026 | parm = AC_PWRST_D3; | |
6027 | set_pin_power_state(codec, 0x29, &parm); | |
6028 | set_pin_power_state(codec, 0x2a, &parm); | |
6029 | set_pin_power_state(codec, 0x2b, &parm); | |
6030 | parm = AC_PWRST_D0; | |
6031 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
6032 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); | |
6033 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); | |
6034 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); | |
6035 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); | |
6036 | ||
6037 | /* outputs */ | |
6038 | /* AOW0 (8h)*/ | |
6039 | snd_hda_codec_write(codec, 0x8, 0, | |
6040 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6041 | ||
6042 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | |
6043 | parm = AC_PWRST_D3; | |
6044 | set_pin_power_state(codec, 0x28, &parm); | |
6045 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); | |
6046 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); | |
6047 | ||
6048 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | |
6049 | parm = AC_PWRST_D3; | |
6050 | set_pin_power_state(codec, 0x25, &parm); | |
6051 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); | |
6052 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); | |
6053 | if (spec->hp_independent_mode) | |
6054 | snd_hda_codec_write(codec, 0x9, 0, | |
6055 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6056 | ||
6057 | /* Internal Speaker */ | |
6058 | /* PW0 (24h), MW0(14h), MUX0(34h) */ | |
6059 | present = snd_hda_jack_detect(codec, 0x25); | |
6060 | ||
6061 | parm = AC_PWRST_D3; | |
6062 | set_pin_power_state(codec, 0x24, &parm); | |
6063 | if (present) { | |
6064 | snd_hda_codec_write(codec, 0x14, 0, | |
6065 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
6066 | snd_hda_codec_write(codec, 0x34, 0, | |
6067 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
6068 | } else { | |
6069 | snd_hda_codec_write(codec, 0x14, 0, | |
6070 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6071 | snd_hda_codec_write(codec, 0x34, 0, | |
6072 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6073 | } | |
6074 | ||
6075 | ||
6076 | /* Mono Out */ | |
6077 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ | |
6078 | present = snd_hda_jack_detect(codec, 0x28); | |
6079 | ||
6080 | parm = AC_PWRST_D3; | |
6081 | set_pin_power_state(codec, 0x31, &parm); | |
6082 | if (present) { | |
6083 | snd_hda_codec_write(codec, 0x1c, 0, | |
6084 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
6085 | snd_hda_codec_write(codec, 0x3c, 0, | |
6086 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
6087 | snd_hda_codec_write(codec, 0x3e, 0, | |
6088 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
6089 | } else { | |
6090 | snd_hda_codec_write(codec, 0x1c, 0, | |
6091 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6092 | snd_hda_codec_write(codec, 0x3c, 0, | |
6093 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6094 | snd_hda_codec_write(codec, 0x3e, 0, | |
6095 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
6096 | } | |
6097 | ||
6098 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ | |
6099 | parm = AC_PWRST_D3; | |
6100 | set_pin_power_state(codec, 0x33, &parm); | |
6101 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); | |
6102 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); | |
6103 | ||
6104 | } | |
ab6734e7 LW |
6105 | |
6106 | /* patch for vt1812 */ | |
6107 | static int patch_vt1812(struct hda_codec *codec) | |
6108 | { | |
6109 | struct via_spec *spec; | |
6110 | int err; | |
6111 | ||
6112 | /* create a codec specific record */ | |
5b0cb1d8 | 6113 | spec = via_new_spec(codec); |
ab6734e7 LW |
6114 | if (spec == NULL) |
6115 | return -ENOMEM; | |
6116 | ||
ab6734e7 LW |
6117 | /* automatic parse from the BIOS config */ |
6118 | err = vt1812_parse_auto_config(codec); | |
6119 | if (err < 0) { | |
6120 | via_free(codec); | |
6121 | return err; | |
6122 | } else if (!err) { | |
6123 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
6124 | "from BIOS. Using genenic mode...\n"); | |
6125 | } | |
6126 | ||
6127 | ||
6128 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; | |
6129 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; | |
6130 | ||
6131 | spec->stream_name_analog = "VT1812 Analog"; | |
6132 | spec->stream_analog_playback = &vt1812_pcm_analog_playback; | |
6133 | spec->stream_analog_capture = &vt1812_pcm_analog_capture; | |
6134 | ||
6135 | spec->stream_name_digital = "VT1812 Digital"; | |
6136 | spec->stream_digital_playback = &vt1812_pcm_digital_playback; | |
6137 | ||
a766d0d7 | 6138 | if (spec->adc_nids && spec->input_mux) { |
ab6734e7 LW |
6139 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
6140 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
6141 | spec->mixers[spec->num_mixers] = vt1812_capture_mixer; | |
6142 | spec->num_mixers++; | |
6143 | } | |
6144 | ||
6145 | codec->patch_ops = via_patch_ops; | |
6146 | ||
6147 | codec->patch_ops.init = via_auto_init; | |
0f48327e | 6148 | codec->patch_ops.unsol_event = via_unsol_event; |
ab6734e7 LW |
6149 | |
6150 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
6151 | spec->loopback.amplist = vt1812_loopbacks; | |
6152 | #endif | |
6153 | ||
3e95b9ab | 6154 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
ab6734e7 LW |
6155 | return 0; |
6156 | } | |
6157 | ||
c577b8a1 JC |
6158 | /* |
6159 | * patch entries | |
6160 | */ | |
90dd48a1 | 6161 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
3218c178 TI |
6162 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
6163 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, | |
6164 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, | |
6165 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, | |
6166 | { .id = 0x1106e710, .name = "VT1709 10-Ch", | |
f7278fd0 | 6167 | .patch = patch_vt1709_10ch}, |
3218c178 | 6168 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
f7278fd0 | 6169 | .patch = patch_vt1709_10ch}, |
3218c178 | 6170 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
f7278fd0 | 6171 | .patch = patch_vt1709_10ch}, |
3218c178 | 6172 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
f7278fd0 | 6173 | .patch = patch_vt1709_10ch}, |
3218c178 | 6174 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
f7278fd0 | 6175 | .patch = patch_vt1709_6ch}, |
3218c178 | 6176 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
f7278fd0 | 6177 | .patch = patch_vt1709_6ch}, |
3218c178 | 6178 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
f7278fd0 | 6179 | .patch = patch_vt1709_6ch}, |
3218c178 | 6180 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
f7278fd0 | 6181 | .patch = patch_vt1709_6ch}, |
3218c178 | 6182 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
f7278fd0 | 6183 | .patch = patch_vt1708B_8ch}, |
3218c178 | 6184 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
f7278fd0 | 6185 | .patch = patch_vt1708B_8ch}, |
3218c178 | 6186 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
f7278fd0 | 6187 | .patch = patch_vt1708B_8ch}, |
3218c178 | 6188 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
f7278fd0 | 6189 | .patch = patch_vt1708B_8ch}, |
3218c178 | 6190 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
f7278fd0 | 6191 | .patch = patch_vt1708B_4ch}, |
3218c178 | 6192 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
f7278fd0 | 6193 | .patch = patch_vt1708B_4ch}, |
3218c178 | 6194 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
f7278fd0 | 6195 | .patch = patch_vt1708B_4ch}, |
3218c178 | 6196 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
f7278fd0 | 6197 | .patch = patch_vt1708B_4ch}, |
3218c178 | 6198 | { .id = 0x11060397, .name = "VT1708S", |
d949cac1 | 6199 | .patch = patch_vt1708S}, |
3218c178 | 6200 | { .id = 0x11061397, .name = "VT1708S", |
d949cac1 | 6201 | .patch = patch_vt1708S}, |
3218c178 | 6202 | { .id = 0x11062397, .name = "VT1708S", |
d949cac1 | 6203 | .patch = patch_vt1708S}, |
3218c178 | 6204 | { .id = 0x11063397, .name = "VT1708S", |
d949cac1 | 6205 | .patch = patch_vt1708S}, |
bc92df7f | 6206 | { .id = 0x11064397, .name = "VT1705", |
d949cac1 | 6207 | .patch = patch_vt1708S}, |
3218c178 | 6208 | { .id = 0x11065397, .name = "VT1708S", |
d949cac1 | 6209 | .patch = patch_vt1708S}, |
3218c178 | 6210 | { .id = 0x11066397, .name = "VT1708S", |
d949cac1 | 6211 | .patch = patch_vt1708S}, |
3218c178 | 6212 | { .id = 0x11067397, .name = "VT1708S", |
d949cac1 | 6213 | .patch = patch_vt1708S}, |
3218c178 | 6214 | { .id = 0x11060398, .name = "VT1702", |
d949cac1 | 6215 | .patch = patch_vt1702}, |
3218c178 | 6216 | { .id = 0x11061398, .name = "VT1702", |
d949cac1 | 6217 | .patch = patch_vt1702}, |
3218c178 | 6218 | { .id = 0x11062398, .name = "VT1702", |
d949cac1 | 6219 | .patch = patch_vt1702}, |
3218c178 | 6220 | { .id = 0x11063398, .name = "VT1702", |
d949cac1 | 6221 | .patch = patch_vt1702}, |
3218c178 | 6222 | { .id = 0x11064398, .name = "VT1702", |
d949cac1 | 6223 | .patch = patch_vt1702}, |
3218c178 | 6224 | { .id = 0x11065398, .name = "VT1702", |
d949cac1 | 6225 | .patch = patch_vt1702}, |
3218c178 | 6226 | { .id = 0x11066398, .name = "VT1702", |
d949cac1 | 6227 | .patch = patch_vt1702}, |
3218c178 | 6228 | { .id = 0x11067398, .name = "VT1702", |
d949cac1 | 6229 | .patch = patch_vt1702}, |
eb7188ca LW |
6230 | { .id = 0x11060428, .name = "VT1718S", |
6231 | .patch = patch_vt1718S}, | |
6232 | { .id = 0x11064428, .name = "VT1718S", | |
6233 | .patch = patch_vt1718S}, | |
bb3c6bfc LW |
6234 | { .id = 0x11060441, .name = "VT2020", |
6235 | .patch = patch_vt1718S}, | |
6236 | { .id = 0x11064441, .name = "VT1828S", | |
6237 | .patch = patch_vt1718S}, | |
f3db423d LW |
6238 | { .id = 0x11060433, .name = "VT1716S", |
6239 | .patch = patch_vt1716S}, | |
6240 | { .id = 0x1106a721, .name = "VT1716S", | |
6241 | .patch = patch_vt1716S}, | |
25eaba2f LW |
6242 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
6243 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, | |
ab6734e7 | 6244 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
36dd5c4a LW |
6245 | { .id = 0x11060440, .name = "VT1818S", |
6246 | .patch = patch_vt1708S}, | |
11890956 LW |
6247 | { .id = 0x11060446, .name = "VT1802", |
6248 | .patch = patch_vt2002P}, | |
6249 | { .id = 0x11068446, .name = "VT1802", | |
6250 | .patch = patch_vt2002P}, | |
c577b8a1 JC |
6251 | {} /* terminator */ |
6252 | }; | |
1289e9e8 TI |
6253 | |
6254 | MODULE_ALIAS("snd-hda-codec-id:1106*"); | |
6255 | ||
6256 | static struct hda_codec_preset_list via_list = { | |
6257 | .preset = snd_hda_preset_via, | |
6258 | .owner = THIS_MODULE, | |
6259 | }; | |
6260 | ||
6261 | MODULE_LICENSE("GPL"); | |
6262 | MODULE_DESCRIPTION("VIA HD-audio codec"); | |
6263 | ||
6264 | static int __init patch_via_init(void) | |
6265 | { | |
6266 | return snd_hda_add_codec_preset(&via_list); | |
6267 | } | |
6268 | ||
6269 | static void __exit patch_via_exit(void) | |
6270 | { | |
6271 | snd_hda_delete_codec_preset(&via_list); | |
6272 | } | |
6273 | ||
6274 | module_init(patch_via_init) | |
6275 | module_exit(patch_via_exit) |