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> | |
da155d5b | 52 | #include <linux/module.h> |
c577b8a1 | 53 | #include <sound/core.h> |
0aa62aef | 54 | #include <sound/asoundef.h> |
c577b8a1 JC |
55 | #include "hda_codec.h" |
56 | #include "hda_local.h" | |
128bc4ba | 57 | #include "hda_auto_parser.h" |
1835a0f9 | 58 | #include "hda_jack.h" |
c577b8a1 | 59 | |
c577b8a1 | 60 | /* Pin Widget NID */ |
d949cac1 HW |
61 | #define VT1708_HP_PIN_NID 0x20 |
62 | #define VT1708_CD_PIN_NID 0x24 | |
c577b8a1 | 63 | |
d7426329 HW |
64 | enum VIA_HDA_CODEC { |
65 | UNKNOWN = -1, | |
66 | VT1708, | |
67 | VT1709_10CH, | |
68 | VT1709_6CH, | |
69 | VT1708B_8CH, | |
70 | VT1708B_4CH, | |
71 | VT1708S, | |
518bf3ba | 72 | VT1708BCE, |
d7426329 | 73 | VT1702, |
eb7188ca | 74 | VT1718S, |
f3db423d | 75 | VT1716S, |
25eaba2f | 76 | VT2002P, |
ab6734e7 | 77 | VT1812, |
11890956 | 78 | VT1802, |
d7426329 HW |
79 | CODEC_TYPES, |
80 | }; | |
81 | ||
11890956 LW |
82 | #define VT2002P_COMPATIBLE(spec) \ |
83 | ((spec)->codec_type == VT2002P ||\ | |
84 | (spec)->codec_type == VT1812 ||\ | |
85 | (spec)->codec_type == VT1802) | |
86 | ||
8e3679dc TI |
87 | #define MAX_NID_PATH_DEPTH 5 |
88 | ||
09a9ad69 TI |
89 | /* output-path: DAC -> ... -> pin |
90 | * idx[] contains the source index number of the next widget; | |
91 | * e.g. idx[0] is the index of the DAC selected by path[1] widget | |
92 | * multi[] indicates whether it's a selector widget with multi-connectors | |
93 | * (i.e. the connection selection is mandatory) | |
94 | * vol_ctl and mute_ctl contains the NIDs for the assigned mixers | |
95 | */ | |
4a79616d TI |
96 | struct nid_path { |
97 | int depth; | |
8e3679dc | 98 | hda_nid_t path[MAX_NID_PATH_DEPTH]; |
09a9ad69 TI |
99 | unsigned char idx[MAX_NID_PATH_DEPTH]; |
100 | unsigned char multi[MAX_NID_PATH_DEPTH]; | |
101 | unsigned int vol_ctl; | |
102 | unsigned int mute_ctl; | |
4a79616d TI |
103 | }; |
104 | ||
a86a88ea TI |
105 | /* input-path */ |
106 | struct via_input { | |
107 | hda_nid_t pin; /* input-pin or aa-mix */ | |
108 | int adc_idx; /* ADC index to be used */ | |
109 | int mux_idx; /* MUX index (if any) */ | |
110 | const char *label; /* input-source label */ | |
111 | }; | |
112 | ||
de6c74f3 TI |
113 | #define VIA_MAX_ADCS 3 |
114 | ||
3b607e3d TI |
115 | enum { |
116 | STREAM_MULTI_OUT = (1 << 0), | |
117 | STREAM_INDEP_HP = (1 << 1), | |
118 | }; | |
119 | ||
1f2e99fe | 120 | struct via_spec { |
7819d1c7 TI |
121 | struct hda_gen_spec gen; |
122 | ||
1f2e99fe | 123 | /* codec parameterization */ |
90dd48a1 | 124 | const struct snd_kcontrol_new *mixers[6]; |
1f2e99fe LW |
125 | unsigned int num_mixers; |
126 | ||
90dd48a1 | 127 | const struct hda_verb *init_verbs[5]; |
1f2e99fe LW |
128 | unsigned int num_iverbs; |
129 | ||
82673bc8 | 130 | char stream_name_analog[32]; |
7eb56e84 | 131 | char stream_name_hp[32]; |
90dd48a1 TI |
132 | const struct hda_pcm_stream *stream_analog_playback; |
133 | const struct hda_pcm_stream *stream_analog_capture; | |
1f2e99fe | 134 | |
82673bc8 | 135 | char stream_name_digital[32]; |
90dd48a1 TI |
136 | const struct hda_pcm_stream *stream_digital_playback; |
137 | const struct hda_pcm_stream *stream_digital_capture; | |
1f2e99fe LW |
138 | |
139 | /* playback */ | |
140 | struct hda_multi_out multiout; | |
141 | hda_nid_t slave_dig_outs[2]; | |
ece8d043 | 142 | hda_nid_t hp_dac_nid; |
3214b966 TI |
143 | hda_nid_t speaker_dac_nid; |
144 | int hp_indep_shared; /* indep HP-DAC is shared with side ch */ | |
3b607e3d TI |
145 | int opened_streams; /* STREAM_* bits */ |
146 | int active_streams; /* STREAM_* bits */ | |
3214b966 TI |
147 | int aamix_mode; /* loopback is enabled for output-path? */ |
148 | ||
149 | /* Output-paths: | |
150 | * There are different output-paths depending on the setup. | |
151 | * out_path, hp_path and speaker_path are primary paths. If both | |
152 | * direct DAC and aa-loopback routes are available, these contain | |
153 | * the former paths. Meanwhile *_mix_path contain the paths with | |
154 | * loopback mixer. (Since the loopback is only for front channel, | |
155 | * no out_mix_path for surround channels.) | |
156 | * The HP output has another path, hp_indep_path, which is used in | |
157 | * the independent-HP mode. | |
158 | */ | |
de6c74f3 | 159 | struct nid_path out_path[HDA_SIDE + 1]; |
3214b966 | 160 | struct nid_path out_mix_path; |
4a79616d | 161 | struct nid_path hp_path; |
3214b966 TI |
162 | struct nid_path hp_mix_path; |
163 | struct nid_path hp_indep_path; | |
4a918ffe | 164 | struct nid_path speaker_path; |
3214b966 | 165 | struct nid_path speaker_mix_path; |
4a79616d | 166 | |
1f2e99fe LW |
167 | /* capture */ |
168 | unsigned int num_adc_nids; | |
de6c74f3 TI |
169 | hda_nid_t adc_nids[VIA_MAX_ADCS]; |
170 | hda_nid_t mux_nids[VIA_MAX_ADCS]; | |
620e2b28 | 171 | hda_nid_t aa_mix_nid; |
1f2e99fe | 172 | hda_nid_t dig_in_nid; |
1f2e99fe LW |
173 | |
174 | /* capture source */ | |
a86a88ea TI |
175 | bool dyn_adc_switch; |
176 | int num_inputs; | |
177 | struct via_input inputs[AUTO_CFG_MAX_INS + 1]; | |
de6c74f3 | 178 | unsigned int cur_mux[VIA_MAX_ADCS]; |
1f2e99fe | 179 | |
3b607e3d TI |
180 | /* dynamic DAC switching */ |
181 | unsigned int cur_dac_stream_tag; | |
182 | unsigned int cur_dac_format; | |
183 | unsigned int cur_hp_stream_tag; | |
184 | unsigned int cur_hp_format; | |
185 | ||
a86a88ea TI |
186 | /* dynamic ADC switching */ |
187 | hda_nid_t cur_adc; | |
188 | unsigned int cur_adc_stream_tag; | |
189 | unsigned int cur_adc_format; | |
190 | ||
1f2e99fe LW |
191 | /* PCM information */ |
192 | struct hda_pcm pcm_rec[3]; | |
193 | ||
194 | /* dynamic controls, init_verbs and input_mux */ | |
195 | struct auto_pin_cfg autocfg; | |
196 | struct snd_array kctls; | |
1f2e99fe LW |
197 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
198 | ||
199 | /* HP mode source */ | |
1f2e99fe | 200 | unsigned int hp_independent_mode; |
f3db423d | 201 | unsigned int dmic_enabled; |
24088a58 | 202 | unsigned int no_pin_power_ctl; |
1f2e99fe LW |
203 | enum VIA_HDA_CODEC codec_type; |
204 | ||
e9d010c2 TI |
205 | /* analog low-power control */ |
206 | bool alc_mode; | |
207 | ||
e3d7a143 TI |
208 | /* smart51 setup */ |
209 | unsigned int smart51_nums; | |
210 | hda_nid_t smart51_pins[2]; | |
211 | int smart51_idxs[2]; | |
212 | const char *smart51_labels[2]; | |
213 | unsigned int smart51_enabled; | |
214 | ||
1f2e99fe LW |
215 | /* work to check hp jack state */ |
216 | struct hda_codec *codec; | |
217 | struct delayed_work vt1708_hp_work; | |
187d333e | 218 | int hp_work_active; |
e06e5a29 | 219 | int vt1708_jack_detect; |
1f2e99fe | 220 | int vt1708_hp_present; |
3e95b9ab LW |
221 | |
222 | void (*set_widgets_power_state)(struct hda_codec *codec); | |
223 | ||
1f2e99fe | 224 | struct hda_loopback_check loopback; |
13af8e77 TI |
225 | int num_loopbacks; |
226 | struct hda_amp_list loopback_list[8]; | |
a86a88ea TI |
227 | |
228 | /* bind capture-volume */ | |
229 | struct hda_bind_ctls *bind_cap_vol; | |
230 | struct hda_bind_ctls *bind_cap_sw; | |
3b607e3d TI |
231 | |
232 | struct mutex config_mutex; | |
1f2e99fe LW |
233 | }; |
234 | ||
0341ccd7 | 235 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
5b0cb1d8 JK |
236 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
237 | { | |
238 | struct via_spec *spec; | |
239 | ||
240 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
241 | if (spec == NULL) | |
242 | return NULL; | |
243 | ||
3b607e3d | 244 | mutex_init(&spec->config_mutex); |
5b0cb1d8 JK |
245 | codec->spec = spec; |
246 | spec->codec = codec; | |
0341ccd7 LW |
247 | spec->codec_type = get_codec_type(codec); |
248 | /* VT1708BCE & VT1708S are almost same */ | |
249 | if (spec->codec_type == VT1708BCE) | |
250 | spec->codec_type = VT1708S; | |
7819d1c7 | 251 | snd_hda_gen_init(&spec->gen); |
5b0cb1d8 JK |
252 | return spec; |
253 | } | |
254 | ||
744ff5f4 | 255 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
d7426329 | 256 | { |
744ff5f4 | 257 | u32 vendor_id = codec->vendor_id; |
d7426329 HW |
258 | u16 ven_id = vendor_id >> 16; |
259 | u16 dev_id = vendor_id & 0xffff; | |
260 | enum VIA_HDA_CODEC codec_type; | |
261 | ||
262 | /* get codec type */ | |
263 | if (ven_id != 0x1106) | |
264 | codec_type = UNKNOWN; | |
265 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) | |
266 | codec_type = VT1708; | |
267 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) | |
268 | codec_type = VT1709_10CH; | |
269 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) | |
270 | codec_type = VT1709_6CH; | |
518bf3ba | 271 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
d7426329 | 272 | codec_type = VT1708B_8CH; |
518bf3ba LW |
273 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
274 | codec_type = VT1708BCE; | |
275 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) | |
d7426329 HW |
276 | codec_type = VT1708B_4CH; |
277 | else if ((dev_id & 0xfff) == 0x397 | |
278 | && (dev_id >> 12) < 8) | |
279 | codec_type = VT1708S; | |
280 | else if ((dev_id & 0xfff) == 0x398 | |
281 | && (dev_id >> 12) < 8) | |
282 | codec_type = VT1702; | |
eb7188ca LW |
283 | else if ((dev_id & 0xfff) == 0x428 |
284 | && (dev_id >> 12) < 8) | |
285 | codec_type = VT1718S; | |
f3db423d LW |
286 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
287 | codec_type = VT1716S; | |
bb3c6bfc LW |
288 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
289 | codec_type = VT1718S; | |
25eaba2f LW |
290 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
291 | codec_type = VT2002P; | |
ab6734e7 LW |
292 | else if (dev_id == 0x0448) |
293 | codec_type = VT1812; | |
36dd5c4a LW |
294 | else if (dev_id == 0x0440) |
295 | codec_type = VT1708S; | |
11890956 LW |
296 | else if ((dev_id & 0xfff) == 0x446) |
297 | codec_type = VT1802; | |
d7426329 HW |
298 | else |
299 | codec_type = UNKNOWN; | |
300 | return codec_type; | |
301 | }; | |
302 | ||
ec7e7e42 | 303 | #define VIA_JACK_EVENT 0x20 |
69e52a80 | 304 | #define VIA_HP_EVENT 0x01 |
4a918ffe | 305 | #define VIA_LINE_EVENT 0x03 |
69e52a80 | 306 | |
c577b8a1 JC |
307 | enum { |
308 | VIA_CTL_WIDGET_VOL, | |
309 | VIA_CTL_WIDGET_MUTE, | |
f5271101 | 310 | VIA_CTL_WIDGET_ANALOG_MUTE, |
c577b8a1 JC |
311 | }; |
312 | ||
ada509ec TI |
313 | static void analog_low_current_mode(struct hda_codec *codec); |
314 | static bool is_aa_path_mute(struct hda_codec *codec); | |
1f2e99fe | 315 | |
187d333e TI |
316 | #define hp_detect_with_aa(codec) \ |
317 | (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \ | |
318 | !is_aa_path_mute(codec)) | |
319 | ||
320 | static void vt1708_stop_hp_work(struct via_spec *spec) | |
1f2e99fe LW |
321 | { |
322 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) | |
323 | return; | |
187d333e TI |
324 | if (spec->hp_work_active) { |
325 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1); | |
326 | cancel_delayed_work_sync(&spec->vt1708_hp_work); | |
327 | spec->hp_work_active = 0; | |
328 | } | |
1f2e99fe LW |
329 | } |
330 | ||
187d333e | 331 | static void vt1708_update_hp_work(struct via_spec *spec) |
1f2e99fe LW |
332 | { |
333 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) | |
334 | return; | |
187d333e TI |
335 | if (spec->vt1708_jack_detect && |
336 | (spec->active_streams || hp_detect_with_aa(spec->codec))) { | |
337 | if (!spec->hp_work_active) { | |
338 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0); | |
339 | schedule_delayed_work(&spec->vt1708_hp_work, | |
340 | msecs_to_jiffies(100)); | |
341 | spec->hp_work_active = 1; | |
342 | } | |
343 | } else if (!hp_detect_with_aa(spec->codec)) | |
344 | vt1708_stop_hp_work(spec); | |
1f2e99fe | 345 | } |
f5271101 | 346 | |
3e95b9ab LW |
347 | static void set_widgets_power_state(struct hda_codec *codec) |
348 | { | |
349 | struct via_spec *spec = codec->spec; | |
350 | if (spec->set_widgets_power_state) | |
351 | spec->set_widgets_power_state(codec); | |
352 | } | |
25eaba2f | 353 | |
f5271101 LW |
354 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
355 | struct snd_ctl_elem_value *ucontrol) | |
356 | { | |
357 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); | |
358 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
359 | ||
3e95b9ab | 360 | set_widgets_power_state(codec); |
ada509ec | 361 | analog_low_current_mode(snd_kcontrol_chip(kcontrol)); |
187d333e | 362 | vt1708_update_hp_work(codec->spec); |
f5271101 LW |
363 | return change; |
364 | } | |
365 | ||
366 | /* modify .put = snd_hda_mixer_amp_switch_put */ | |
367 | #define ANALOG_INPUT_MUTE \ | |
368 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
369 | .name = NULL, \ | |
370 | .index = 0, \ | |
371 | .info = snd_hda_mixer_amp_switch_info, \ | |
372 | .get = snd_hda_mixer_amp_switch_get, \ | |
373 | .put = analog_input_switch_put, \ | |
374 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } | |
375 | ||
90dd48a1 | 376 | static const struct snd_kcontrol_new via_control_templates[] = { |
c577b8a1 JC |
377 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
378 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
f5271101 | 379 | ANALOG_INPUT_MUTE, |
c577b8a1 JC |
380 | }; |
381 | ||
ab6734e7 | 382 | |
c577b8a1 | 383 | /* add dynamic controls */ |
291c9e33 TI |
384 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
385 | const struct snd_kcontrol_new *tmpl, | |
386 | const char *name) | |
c577b8a1 JC |
387 | { |
388 | struct snd_kcontrol_new *knew; | |
389 | ||
603c4019 TI |
390 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
391 | knew = snd_array_new(&spec->kctls); | |
392 | if (!knew) | |
291c9e33 TI |
393 | return NULL; |
394 | *knew = *tmpl; | |
395 | if (!name) | |
396 | name = tmpl->name; | |
397 | if (name) { | |
398 | knew->name = kstrdup(name, GFP_KERNEL); | |
399 | if (!knew->name) | |
400 | return NULL; | |
401 | } | |
402 | return knew; | |
403 | } | |
404 | ||
405 | static int __via_add_control(struct via_spec *spec, int type, const char *name, | |
406 | int idx, unsigned long val) | |
407 | { | |
408 | struct snd_kcontrol_new *knew; | |
409 | ||
410 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); | |
411 | if (!knew) | |
c577b8a1 | 412 | return -ENOMEM; |
d7a99cce | 413 | knew->index = idx; |
4d02d1b6 | 414 | if (get_amp_nid_(val)) |
5e26dfd0 | 415 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
c577b8a1 | 416 | knew->private_value = val; |
c577b8a1 JC |
417 | return 0; |
418 | } | |
419 | ||
7b315bb4 TI |
420 | #define via_add_control(spec, type, name, val) \ |
421 | __via_add_control(spec, type, name, 0, val) | |
422 | ||
291c9e33 | 423 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
5b0cb1d8 | 424 | |
603c4019 TI |
425 | static void via_free_kctls(struct hda_codec *codec) |
426 | { | |
427 | struct via_spec *spec = codec->spec; | |
428 | ||
429 | if (spec->kctls.list) { | |
430 | struct snd_kcontrol_new *kctl = spec->kctls.list; | |
431 | int i; | |
432 | for (i = 0; i < spec->kctls.used; i++) | |
433 | kfree(kctl[i].name); | |
434 | } | |
435 | snd_array_free(&spec->kctls); | |
436 | } | |
437 | ||
c577b8a1 | 438 | /* create input playback/capture controls for the given pin */ |
9510e8dd | 439 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
7b315bb4 | 440 | int type_idx, int idx, int mix_nid) |
c577b8a1 JC |
441 | { |
442 | char name[32]; | |
443 | int err; | |
444 | ||
445 | sprintf(name, "%s Playback Volume", ctlname); | |
7b315bb4 | 446 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
c577b8a1 JC |
447 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
448 | if (err < 0) | |
449 | return err; | |
450 | sprintf(name, "%s Playback Switch", ctlname); | |
7b315bb4 | 451 | err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx, |
c577b8a1 JC |
452 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
453 | if (err < 0) | |
454 | return err; | |
455 | return 0; | |
456 | } | |
457 | ||
5d41762a | 458 | #define get_connection_index(codec, mux, nid) \ |
8d087c76 | 459 | snd_hda_get_conn_index(codec, mux, nid, 0) |
5d41762a | 460 | |
8df2a312 TI |
461 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
462 | unsigned int mask) | |
463 | { | |
a934d5a9 TI |
464 | unsigned int caps; |
465 | if (!nid) | |
466 | return false; | |
467 | caps = get_wcaps(codec, nid); | |
8df2a312 TI |
468 | if (dir == HDA_INPUT) |
469 | caps &= AC_WCAP_IN_AMP; | |
470 | else | |
471 | caps &= AC_WCAP_OUT_AMP; | |
472 | if (!caps) | |
473 | return false; | |
474 | if (query_amp_caps(codec, nid, dir) & mask) | |
475 | return true; | |
476 | return false; | |
477 | } | |
478 | ||
09a9ad69 TI |
479 | #define have_mute(codec, nid, dir) \ |
480 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) | |
8df2a312 | 481 | |
d69607b3 LW |
482 | /* enable/disable the output-route mixers */ |
483 | static void activate_output_mix(struct hda_codec *codec, struct nid_path *path, | |
3214b966 | 484 | hda_nid_t mix_nid, int idx, bool enable) |
d69607b3 LW |
485 | { |
486 | int i, num, val; | |
d69607b3 LW |
487 | |
488 | if (!path) | |
489 | return; | |
09cf03b8 | 490 | num = snd_hda_get_num_conns(codec, mix_nid); |
d69607b3 | 491 | for (i = 0; i < num; i++) { |
3214b966 TI |
492 | if (i == idx) |
493 | val = AMP_IN_UNMUTE(i); | |
494 | else | |
495 | val = AMP_IN_MUTE(i); | |
d69607b3 LW |
496 | snd_hda_codec_write(codec, mix_nid, 0, |
497 | AC_VERB_SET_AMP_GAIN_MUTE, val); | |
498 | } | |
499 | } | |
500 | ||
09a9ad69 TI |
501 | /* enable/disable the output-route */ |
502 | static void activate_output_path(struct hda_codec *codec, struct nid_path *path, | |
503 | bool enable, bool force) | |
5d41762a | 504 | { |
d69607b3 | 505 | struct via_spec *spec = codec->spec; |
3214b966 | 506 | int i; |
09a9ad69 TI |
507 | for (i = 0; i < path->depth; i++) { |
508 | hda_nid_t src, dst; | |
509 | int idx = path->idx[i]; | |
510 | src = path->path[i]; | |
511 | if (i < path->depth - 1) | |
512 | dst = path->path[i + 1]; | |
513 | else | |
514 | dst = 0; | |
515 | if (enable && path->multi[i]) | |
516 | snd_hda_codec_write(codec, dst, 0, | |
517 | AC_VERB_SET_CONNECT_SEL, idx); | |
3214b966 | 518 | if (!force && (dst == spec->aa_mix_nid)) |
e5e14681 | 519 | continue; |
3214b966 TI |
520 | if (have_mute(codec, dst, HDA_INPUT)) |
521 | activate_output_mix(codec, path, dst, idx, enable); | |
09a9ad69 TI |
522 | if (!force && (src == path->vol_ctl || src == path->mute_ctl)) |
523 | continue; | |
524 | if (have_mute(codec, src, HDA_OUTPUT)) { | |
525 | int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE; | |
526 | snd_hda_codec_write(codec, src, 0, | |
527 | AC_VERB_SET_AMP_GAIN_MUTE, val); | |
528 | } | |
529 | } | |
5d41762a TI |
530 | } |
531 | ||
532 | /* set the given pin as output */ | |
533 | static void init_output_pin(struct hda_codec *codec, hda_nid_t pin, | |
534 | int pin_type) | |
535 | { | |
536 | if (!pin) | |
537 | return; | |
cdd03ced | 538 | snd_hda_set_pin_ctl(codec, pin, pin_type); |
5d41762a TI |
539 | if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) |
540 | snd_hda_codec_write(codec, pin, 0, | |
d3a11e60 | 541 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
c577b8a1 JC |
542 | } |
543 | ||
09a9ad69 | 544 | static void via_auto_init_output(struct hda_codec *codec, |
a353fbb1 | 545 | struct nid_path *path, int pin_type) |
5d41762a | 546 | { |
5d41762a | 547 | unsigned int caps; |
d69607b3 | 548 | hda_nid_t pin; |
5d41762a | 549 | |
09a9ad69 | 550 | if (!path->depth) |
5d41762a | 551 | return; |
09a9ad69 | 552 | pin = path->path[path->depth - 1]; |
5d41762a TI |
553 | |
554 | init_output_pin(codec, pin, pin_type); | |
77e314f7 TI |
555 | if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP) |
556 | caps = query_amp_caps(codec, pin, HDA_OUTPUT); | |
557 | else | |
558 | caps = 0; | |
5d41762a TI |
559 | if (caps & AC_AMPCAP_MUTE) { |
560 | unsigned int val; | |
561 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; | |
562 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
563 | AMP_OUT_MUTE | val); | |
564 | } | |
a353fbb1 | 565 | activate_output_path(codec, path, true, true); /* force on */ |
5d41762a TI |
566 | } |
567 | ||
c577b8a1 JC |
568 | static void via_auto_init_multi_out(struct hda_codec *codec) |
569 | { | |
570 | struct via_spec *spec = codec->spec; | |
3214b966 | 571 | struct nid_path *path; |
c577b8a1 JC |
572 | int i; |
573 | ||
3214b966 TI |
574 | for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) { |
575 | path = &spec->out_path[i]; | |
576 | if (!i && spec->aamix_mode && spec->out_mix_path.depth) | |
577 | path = &spec->out_mix_path; | |
a353fbb1 | 578 | via_auto_init_output(codec, path, PIN_OUT); |
3214b966 | 579 | } |
c577b8a1 JC |
580 | } |
581 | ||
020066d1 TI |
582 | /* deactivate the inactive headphone-paths */ |
583 | static void deactivate_hp_paths(struct hda_codec *codec) | |
c577b8a1 JC |
584 | { |
585 | struct via_spec *spec = codec->spec; | |
3214b966 | 586 | int shared = spec->hp_indep_shared; |
c577b8a1 | 587 | |
09a9ad69 | 588 | if (spec->hp_independent_mode) { |
09a9ad69 | 589 | activate_output_path(codec, &spec->hp_path, false, false); |
3214b966 TI |
590 | activate_output_path(codec, &spec->hp_mix_path, false, false); |
591 | if (shared) | |
592 | activate_output_path(codec, &spec->out_path[shared], | |
593 | false, false); | |
020066d1 TI |
594 | } else if (spec->aamix_mode || !spec->hp_path.depth) { |
595 | activate_output_path(codec, &spec->hp_indep_path, false, false); | |
3214b966 | 596 | activate_output_path(codec, &spec->hp_path, false, false); |
3214b966 | 597 | } else { |
020066d1 | 598 | activate_output_path(codec, &spec->hp_indep_path, false, false); |
3214b966 | 599 | activate_output_path(codec, &spec->hp_mix_path, false, false); |
09a9ad69 | 600 | } |
c577b8a1 JC |
601 | } |
602 | ||
020066d1 TI |
603 | static void via_auto_init_hp_out(struct hda_codec *codec) |
604 | { | |
605 | struct via_spec *spec = codec->spec; | |
606 | ||
607 | if (!spec->hp_path.depth) { | |
a353fbb1 | 608 | via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP); |
020066d1 TI |
609 | return; |
610 | } | |
611 | deactivate_hp_paths(codec); | |
612 | if (spec->hp_independent_mode) | |
a353fbb1 | 613 | via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP); |
020066d1 | 614 | else if (spec->aamix_mode) |
a353fbb1 | 615 | via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP); |
020066d1 | 616 | else |
a353fbb1 | 617 | via_auto_init_output(codec, &spec->hp_path, PIN_HP); |
020066d1 TI |
618 | } |
619 | ||
4a918ffe TI |
620 | static void via_auto_init_speaker_out(struct hda_codec *codec) |
621 | { | |
622 | struct via_spec *spec = codec->spec; | |
623 | ||
3214b966 TI |
624 | if (!spec->autocfg.speaker_outs) |
625 | return; | |
626 | if (!spec->speaker_path.depth) { | |
a353fbb1 | 627 | via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT); |
3214b966 TI |
628 | return; |
629 | } | |
630 | if (!spec->aamix_mode) { | |
631 | activate_output_path(codec, &spec->speaker_mix_path, | |
632 | false, false); | |
a353fbb1 | 633 | via_auto_init_output(codec, &spec->speaker_path, PIN_OUT); |
3214b966 TI |
634 | } else { |
635 | activate_output_path(codec, &spec->speaker_path, false, false); | |
a353fbb1 | 636 | via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT); |
3214b966 | 637 | } |
4a918ffe TI |
638 | } |
639 | ||
f4a7828b | 640 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); |
6e969d91 | 641 | static void via_hp_automute(struct hda_codec *codec); |
32e0191d | 642 | |
c577b8a1 JC |
643 | static void via_auto_init_analog_input(struct hda_codec *codec) |
644 | { | |
645 | struct via_spec *spec = codec->spec; | |
7b315bb4 | 646 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
096a8854 | 647 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; |
32e0191d | 648 | unsigned int ctl; |
096a8854 TI |
649 | int i, num_conns; |
650 | ||
651 | /* init ADCs */ | |
652 | for (i = 0; i < spec->num_adc_nids; i++) { | |
77e314f7 TI |
653 | hda_nid_t nid = spec->adc_nids[i]; |
654 | if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP) || | |
655 | !(query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)) | |
656 | continue; | |
096a8854 TI |
657 | snd_hda_codec_write(codec, spec->adc_nids[i], 0, |
658 | AC_VERB_SET_AMP_GAIN_MUTE, | |
659 | AMP_IN_UNMUTE(0)); | |
660 | } | |
c577b8a1 | 661 | |
096a8854 | 662 | /* init pins */ |
7b315bb4 TI |
663 | for (i = 0; i < cfg->num_inputs; i++) { |
664 | hda_nid_t nid = cfg->inputs[i].pin; | |
f4a7828b | 665 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) |
32e0191d | 666 | ctl = PIN_OUT; |
4740860b | 667 | else { |
32e0191d | 668 | ctl = PIN_IN; |
4740860b TI |
669 | if (cfg->inputs[i].type == AUTO_PIN_MIC) |
670 | ctl |= snd_hda_get_default_vref(codec, nid); | |
671 | } | |
cdd03ced | 672 | snd_hda_set_pin_ctl(codec, nid, ctl); |
c577b8a1 | 673 | } |
096a8854 TI |
674 | |
675 | /* init input-src */ | |
676 | for (i = 0; i < spec->num_adc_nids; i++) { | |
a86a88ea | 677 | int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx; |
fc1156c0 TI |
678 | /* secondary ADCs must have the unique MUX */ |
679 | if (i > 0 && !spec->mux_nids[i]) | |
680 | break; | |
a86a88ea TI |
681 | if (spec->mux_nids[adc_idx]) { |
682 | int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx; | |
683 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, | |
684 | AC_VERB_SET_CONNECT_SEL, | |
685 | mux_idx); | |
686 | } | |
687 | if (spec->dyn_adc_switch) | |
688 | break; /* only one input-src */ | |
096a8854 TI |
689 | } |
690 | ||
691 | /* init aa-mixer */ | |
692 | if (!spec->aa_mix_nid) | |
693 | return; | |
694 | num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, | |
695 | ARRAY_SIZE(conn)); | |
696 | for (i = 0; i < num_conns; i++) { | |
697 | unsigned int caps = get_wcaps(codec, conn[i]); | |
698 | if (get_wcaps_type(caps) == AC_WID_PIN) | |
699 | snd_hda_codec_write(codec, spec->aa_mix_nid, 0, | |
700 | AC_VERB_SET_AMP_GAIN_MUTE, | |
701 | AMP_IN_MUTE(i)); | |
702 | } | |
c577b8a1 | 703 | } |
f5271101 | 704 | |
054d867e TI |
705 | static void update_power_state(struct hda_codec *codec, hda_nid_t nid, |
706 | unsigned int parm) | |
707 | { | |
708 | if (snd_hda_codec_read(codec, nid, 0, | |
709 | AC_VERB_GET_POWER_STATE, 0) == parm) | |
710 | return; | |
711 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); | |
712 | } | |
713 | ||
f5271101 LW |
714 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
715 | unsigned int *affected_parm) | |
716 | { | |
717 | unsigned parm; | |
718 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); | |
719 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) | |
720 | >> AC_DEFCFG_MISC_SHIFT | |
721 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ | |
1564b287 | 722 | struct via_spec *spec = codec->spec; |
24088a58 TI |
723 | unsigned present = 0; |
724 | ||
725 | no_presence |= spec->no_pin_power_ctl; | |
726 | if (!no_presence) | |
727 | present = snd_hda_jack_detect(codec, nid); | |
f4a7828b | 728 | if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) |
1564b287 LW |
729 | || ((no_presence || present) |
730 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { | |
f5271101 LW |
731 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
732 | parm = AC_PWRST_D0; | |
733 | } else | |
734 | parm = AC_PWRST_D3; | |
735 | ||
054d867e | 736 | update_power_state(codec, nid, parm); |
f5271101 LW |
737 | } |
738 | ||
24088a58 TI |
739 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
740 | struct snd_ctl_elem_info *uinfo) | |
741 | { | |
742 | static const char * const texts[] = { | |
743 | "Disabled", "Enabled" | |
744 | }; | |
745 | ||
746 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
747 | uinfo->count = 1; | |
748 | uinfo->value.enumerated.items = 2; | |
749 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | |
750 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; | |
751 | strcpy(uinfo->value.enumerated.name, | |
752 | texts[uinfo->value.enumerated.item]); | |
753 | return 0; | |
754 | } | |
755 | ||
756 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, | |
757 | struct snd_ctl_elem_value *ucontrol) | |
758 | { | |
759 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
760 | struct via_spec *spec = codec->spec; | |
761 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; | |
762 | return 0; | |
763 | } | |
764 | ||
765 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, | |
766 | struct snd_ctl_elem_value *ucontrol) | |
767 | { | |
768 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
769 | struct via_spec *spec = codec->spec; | |
770 | unsigned int val = !ucontrol->value.enumerated.item[0]; | |
771 | ||
772 | if (val == spec->no_pin_power_ctl) | |
773 | return 0; | |
774 | spec->no_pin_power_ctl = val; | |
775 | set_widgets_power_state(codec); | |
e9d010c2 | 776 | analog_low_current_mode(codec); |
24088a58 TI |
777 | return 1; |
778 | } | |
779 | ||
780 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { | |
781 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
782 | .name = "Dynamic Power-Control", | |
783 | .info = via_pin_power_ctl_info, | |
784 | .get = via_pin_power_ctl_get, | |
785 | .put = via_pin_power_ctl_put, | |
786 | }; | |
787 | ||
788 | ||
0aa62aef HW |
789 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
790 | struct snd_ctl_elem_info *uinfo) | |
791 | { | |
8df2a312 TI |
792 | static const char * const texts[] = { "OFF", "ON" }; |
793 | ||
794 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
795 | uinfo->count = 1; | |
796 | uinfo->value.enumerated.items = 2; | |
797 | if (uinfo->value.enumerated.item >= 2) | |
798 | uinfo->value.enumerated.item = 1; | |
799 | strcpy(uinfo->value.enumerated.name, | |
800 | texts[uinfo->value.enumerated.item]); | |
801 | return 0; | |
0aa62aef HW |
802 | } |
803 | ||
804 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, | |
805 | struct snd_ctl_elem_value *ucontrol) | |
806 | { | |
807 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
cdc1784d | 808 | struct via_spec *spec = codec->spec; |
cdc1784d | 809 | |
ece8d043 | 810 | ucontrol->value.enumerated.item[0] = spec->hp_independent_mode; |
cdc1784d LW |
811 | return 0; |
812 | } | |
813 | ||
3b607e3d TI |
814 | /* adjust spec->multiout setup according to the current flags */ |
815 | static void setup_playback_multi_pcm(struct via_spec *spec) | |
816 | { | |
817 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
818 | spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums; | |
819 | spec->multiout.hp_nid = 0; | |
820 | if (!spec->hp_independent_mode) { | |
821 | if (!spec->hp_indep_shared) | |
822 | spec->multiout.hp_nid = spec->hp_dac_nid; | |
823 | } else { | |
824 | if (spec->hp_indep_shared) | |
825 | spec->multiout.num_dacs = cfg->line_outs - 1; | |
826 | } | |
827 | } | |
828 | ||
829 | /* update DAC setups according to indep-HP switch; | |
830 | * this function is called only when indep-HP is modified | |
831 | */ | |
832 | static void switch_indep_hp_dacs(struct hda_codec *codec) | |
833 | { | |
834 | struct via_spec *spec = codec->spec; | |
835 | int shared = spec->hp_indep_shared; | |
836 | hda_nid_t shared_dac, hp_dac; | |
837 | ||
838 | if (!spec->opened_streams) | |
839 | return; | |
840 | ||
841 | shared_dac = shared ? spec->multiout.dac_nids[shared] : 0; | |
842 | hp_dac = spec->hp_dac_nid; | |
843 | if (spec->hp_independent_mode) { | |
844 | /* switch to indep-HP mode */ | |
845 | if (spec->active_streams & STREAM_MULTI_OUT) { | |
846 | __snd_hda_codec_cleanup_stream(codec, hp_dac, 1); | |
847 | __snd_hda_codec_cleanup_stream(codec, shared_dac, 1); | |
848 | } | |
849 | if (spec->active_streams & STREAM_INDEP_HP) | |
850 | snd_hda_codec_setup_stream(codec, hp_dac, | |
851 | spec->cur_hp_stream_tag, 0, | |
852 | spec->cur_hp_format); | |
853 | } else { | |
854 | /* back to HP or shared-DAC */ | |
855 | if (spec->active_streams & STREAM_INDEP_HP) | |
856 | __snd_hda_codec_cleanup_stream(codec, hp_dac, 1); | |
857 | if (spec->active_streams & STREAM_MULTI_OUT) { | |
858 | hda_nid_t dac; | |
859 | int ch; | |
860 | if (shared_dac) { /* reset mutli-ch DAC */ | |
861 | dac = shared_dac; | |
862 | ch = shared * 2; | |
863 | } else { /* reset HP DAC */ | |
864 | dac = hp_dac; | |
865 | ch = 0; | |
866 | } | |
867 | snd_hda_codec_setup_stream(codec, dac, | |
868 | spec->cur_dac_stream_tag, ch, | |
869 | spec->cur_dac_format); | |
870 | } | |
871 | } | |
872 | setup_playback_multi_pcm(spec); | |
873 | } | |
874 | ||
0aa62aef HW |
875 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
876 | struct snd_ctl_elem_value *ucontrol) | |
877 | { | |
878 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
879 | struct via_spec *spec = codec->spec; | |
3214b966 | 880 | int cur, shared; |
8df2a312 | 881 | |
3b607e3d | 882 | mutex_lock(&spec->config_mutex); |
25250505 | 883 | cur = !!ucontrol->value.enumerated.item[0]; |
3b607e3d TI |
884 | if (spec->hp_independent_mode == cur) { |
885 | mutex_unlock(&spec->config_mutex); | |
25250505 | 886 | return 0; |
3b607e3d | 887 | } |
25250505 | 888 | spec->hp_independent_mode = cur; |
3214b966 | 889 | shared = spec->hp_indep_shared; |
020066d1 TI |
890 | deactivate_hp_paths(codec); |
891 | if (cur) | |
892 | activate_output_path(codec, &spec->hp_indep_path, true, false); | |
893 | else { | |
3214b966 TI |
894 | if (shared) |
895 | activate_output_path(codec, &spec->out_path[shared], | |
25250505 | 896 | true, false); |
020066d1 TI |
897 | if (spec->aamix_mode || !spec->hp_path.depth) |
898 | activate_output_path(codec, &spec->hp_mix_path, | |
899 | true, false); | |
900 | else | |
901 | activate_output_path(codec, &spec->hp_path, | |
902 | true, false); | |
8df2a312 | 903 | } |
ece8d043 | 904 | |
3b607e3d TI |
905 | switch_indep_hp_dacs(codec); |
906 | mutex_unlock(&spec->config_mutex); | |
907 | ||
ce0e5a9e | 908 | /* update jack power state */ |
3e95b9ab | 909 | set_widgets_power_state(codec); |
6e969d91 | 910 | via_hp_automute(codec); |
25250505 | 911 | return 1; |
0aa62aef HW |
912 | } |
913 | ||
ece8d043 TI |
914 | static const struct snd_kcontrol_new via_hp_mixer = { |
915 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
916 | .name = "Independent HP", | |
917 | .info = via_independent_hp_info, | |
918 | .get = via_independent_hp_get, | |
919 | .put = via_independent_hp_put, | |
0aa62aef HW |
920 | }; |
921 | ||
3d83e577 | 922 | static int via_hp_build(struct hda_codec *codec) |
5b0cb1d8 | 923 | { |
3d83e577 | 924 | struct via_spec *spec = codec->spec; |
5b0cb1d8 JK |
925 | struct snd_kcontrol_new *knew; |
926 | hda_nid_t nid; | |
5b0cb1d8 | 927 | |
ece8d043 TI |
928 | nid = spec->autocfg.hp_pins[0]; |
929 | knew = via_clone_control(spec, &via_hp_mixer); | |
3d83e577 TI |
930 | if (knew == NULL) |
931 | return -ENOMEM; | |
932 | ||
5b0cb1d8 | 933 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
5b0cb1d8 | 934 | |
5b0cb1d8 JK |
935 | return 0; |
936 | } | |
937 | ||
1564b287 LW |
938 | static void notify_aa_path_ctls(struct hda_codec *codec) |
939 | { | |
e3d7a143 | 940 | struct via_spec *spec = codec->spec; |
1564b287 | 941 | int i; |
e3d7a143 TI |
942 | |
943 | for (i = 0; i < spec->smart51_nums; i++) { | |
944 | struct snd_kcontrol *ctl; | |
945 | struct snd_ctl_elem_id id; | |
946 | memset(&id, 0, sizeof(id)); | |
947 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
948 | sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]); | |
525566cb LW |
949 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
950 | if (ctl) | |
951 | snd_ctl_notify(codec->bus->card, | |
952 | SNDRV_CTL_EVENT_MASK_VALUE, | |
953 | &ctl->id); | |
1564b287 LW |
954 | } |
955 | } | |
956 | ||
957 | static void mute_aa_path(struct hda_codec *codec, int mute) | |
958 | { | |
959 | struct via_spec *spec = codec->spec; | |
e3d7a143 | 960 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; |
1564b287 | 961 | int i; |
e3d7a143 | 962 | |
1564b287 | 963 | /* check AA path's mute status */ |
e3d7a143 TI |
964 | for (i = 0; i < spec->smart51_nums; i++) { |
965 | if (spec->smart51_idxs[i] < 0) | |
966 | continue; | |
967 | snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, | |
968 | HDA_INPUT, spec->smart51_idxs[i], | |
1564b287 LW |
969 | HDA_AMP_MUTE, val); |
970 | } | |
971 | } | |
f4a7828b | 972 | |
e3d7a143 TI |
973 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) |
974 | { | |
975 | struct via_spec *spec = codec->spec; | |
976 | int i; | |
977 | ||
978 | for (i = 0; i < spec->smart51_nums; i++) | |
979 | if (spec->smart51_pins[i] == pin) | |
980 | return true; | |
981 | return false; | |
982 | } | |
983 | ||
1564b287 LW |
984 | static int via_smart51_get(struct snd_kcontrol *kcontrol, |
985 | struct snd_ctl_elem_value *ucontrol) | |
986 | { | |
987 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
988 | struct via_spec *spec = codec->spec; | |
1564b287 | 989 | |
f2b1c9f0 | 990 | *ucontrol->value.integer.value = spec->smart51_enabled; |
1564b287 LW |
991 | return 0; |
992 | } | |
993 | ||
994 | static int via_smart51_put(struct snd_kcontrol *kcontrol, | |
995 | struct snd_ctl_elem_value *ucontrol) | |
996 | { | |
997 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
998 | struct via_spec *spec = codec->spec; | |
999 | int out_in = *ucontrol->value.integer.value | |
1000 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; | |
1564b287 LW |
1001 | int i; |
1002 | ||
e3d7a143 TI |
1003 | for (i = 0; i < spec->smart51_nums; i++) { |
1004 | hda_nid_t nid = spec->smart51_pins[i]; | |
7b315bb4 TI |
1005 | unsigned int parm; |
1006 | ||
7b315bb4 TI |
1007 | parm = snd_hda_codec_read(codec, nid, 0, |
1008 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
1009 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); | |
1010 | parm |= out_in; | |
cdd03ced | 1011 | snd_hda_set_pin_ctl(codec, nid, parm); |
7b315bb4 TI |
1012 | if (out_in == AC_PINCTL_OUT_EN) { |
1013 | mute_aa_path(codec, 1); | |
1014 | notify_aa_path_ctls(codec); | |
1015 | } | |
1564b287 LW |
1016 | } |
1017 | spec->smart51_enabled = *ucontrol->value.integer.value; | |
3e95b9ab | 1018 | set_widgets_power_state(codec); |
1564b287 LW |
1019 | return 1; |
1020 | } | |
1021 | ||
5f4b36d6 TI |
1022 | static const struct snd_kcontrol_new via_smart51_mixer = { |
1023 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1024 | .name = "Smart 5.1", | |
1025 | .count = 1, | |
f2b1c9f0 | 1026 | .info = snd_ctl_boolean_mono_info, |
5f4b36d6 TI |
1027 | .get = via_smart51_get, |
1028 | .put = via_smart51_put, | |
1564b287 LW |
1029 | }; |
1030 | ||
f4a7828b | 1031 | static int via_smart51_build(struct hda_codec *codec) |
5b0cb1d8 | 1032 | { |
f4a7828b | 1033 | struct via_spec *spec = codec->spec; |
5b0cb1d8 | 1034 | |
e3d7a143 | 1035 | if (!spec->smart51_nums) |
cb34c207 | 1036 | return 0; |
e3d7a143 | 1037 | if (!via_clone_control(spec, &via_smart51_mixer)) |
5b0cb1d8 | 1038 | return -ENOMEM; |
5b0cb1d8 JK |
1039 | return 0; |
1040 | } | |
1041 | ||
ada509ec TI |
1042 | /* check AA path's mute status */ |
1043 | static bool is_aa_path_mute(struct hda_codec *codec) | |
f5271101 | 1044 | { |
f5271101 | 1045 | struct via_spec *spec = codec->spec; |
ada509ec TI |
1046 | const struct hda_amp_list *p; |
1047 | int i, ch, v; | |
1048 | ||
1049 | for (i = 0; i < spec->num_loopbacks; i++) { | |
1050 | p = &spec->loopback_list[i]; | |
1051 | for (ch = 0; ch < 2; ch++) { | |
1052 | v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, | |
1053 | p->idx); | |
1054 | if (!(v & HDA_AMP_MUTE) && v > 0) | |
1055 | return false; | |
f5271101 LW |
1056 | } |
1057 | } | |
ada509ec | 1058 | return true; |
f5271101 LW |
1059 | } |
1060 | ||
1061 | /* enter/exit analog low-current mode */ | |
e9d010c2 | 1062 | static void __analog_low_current_mode(struct hda_codec *codec, bool force) |
f5271101 LW |
1063 | { |
1064 | struct via_spec *spec = codec->spec; | |
ada509ec TI |
1065 | bool enable; |
1066 | unsigned int verb, parm; | |
1067 | ||
e9d010c2 TI |
1068 | if (spec->no_pin_power_ctl) |
1069 | enable = false; | |
1070 | else | |
1071 | enable = is_aa_path_mute(codec) && !spec->opened_streams; | |
1072 | if (enable == spec->alc_mode && !force) | |
1073 | return; | |
1074 | spec->alc_mode = enable; | |
f5271101 LW |
1075 | |
1076 | /* decide low current mode's verb & parameter */ | |
1077 | switch (spec->codec_type) { | |
1078 | case VT1708B_8CH: | |
1079 | case VT1708B_4CH: | |
1080 | verb = 0xf70; | |
1081 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ | |
1082 | break; | |
1083 | case VT1708S: | |
eb7188ca | 1084 | case VT1718S: |
f3db423d | 1085 | case VT1716S: |
f5271101 LW |
1086 | verb = 0xf73; |
1087 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ | |
1088 | break; | |
1089 | case VT1702: | |
1090 | verb = 0xf73; | |
1091 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ | |
1092 | break; | |
25eaba2f | 1093 | case VT2002P: |
ab6734e7 | 1094 | case VT1812: |
11890956 | 1095 | case VT1802: |
25eaba2f LW |
1096 | verb = 0xf93; |
1097 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ | |
1098 | break; | |
f5271101 LW |
1099 | default: |
1100 | return; /* other codecs are not supported */ | |
1101 | } | |
1102 | /* send verb */ | |
1103 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); | |
1104 | } | |
1105 | ||
e9d010c2 TI |
1106 | static void analog_low_current_mode(struct hda_codec *codec) |
1107 | { | |
1108 | return __analog_low_current_mode(codec, false); | |
1109 | } | |
1110 | ||
c577b8a1 JC |
1111 | /* |
1112 | * generic initialization of ADC, input mixers and output mixers | |
1113 | */ | |
096a8854 | 1114 | static const struct hda_verb vt1708_init_verbs[] = { |
aa266fcc LW |
1115 | /* power down jack detect function */ |
1116 | {0x1, 0xf81, 0x1}, | |
f7278fd0 | 1117 | { } |
c577b8a1 JC |
1118 | }; |
1119 | ||
3b607e3d | 1120 | static void set_stream_open(struct hda_codec *codec, int bit, bool active) |
7eb56e84 | 1121 | { |
ada509ec TI |
1122 | struct via_spec *spec = codec->spec; |
1123 | ||
1124 | if (active) | |
3b607e3d | 1125 | spec->opened_streams |= bit; |
ada509ec | 1126 | else |
3b607e3d | 1127 | spec->opened_streams &= ~bit; |
ada509ec | 1128 | analog_low_current_mode(codec); |
7eb56e84 TI |
1129 | } |
1130 | ||
ece8d043 | 1131 | static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo, |
c577b8a1 JC |
1132 | struct hda_codec *codec, |
1133 | struct snd_pcm_substream *substream) | |
1134 | { | |
1135 | struct via_spec *spec = codec->spec; | |
25250505 | 1136 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
ada509ec | 1137 | int err; |
ece8d043 | 1138 | |
25250505 | 1139 | spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums; |
25250505 | 1140 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
3b607e3d | 1141 | set_stream_open(codec, STREAM_MULTI_OUT, true); |
ada509ec TI |
1142 | err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
1143 | hinfo); | |
1144 | if (err < 0) { | |
3b607e3d | 1145 | set_stream_open(codec, STREAM_MULTI_OUT, false); |
ada509ec TI |
1146 | return err; |
1147 | } | |
1148 | return 0; | |
c577b8a1 JC |
1149 | } |
1150 | ||
ece8d043 | 1151 | static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo, |
9af74210 TI |
1152 | struct hda_codec *codec, |
1153 | struct snd_pcm_substream *substream) | |
1154 | { | |
3b607e3d | 1155 | set_stream_open(codec, STREAM_MULTI_OUT, false); |
7eb56e84 TI |
1156 | return 0; |
1157 | } | |
9af74210 | 1158 | |
7eb56e84 TI |
1159 | static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, |
1160 | struct hda_codec *codec, | |
1161 | struct snd_pcm_substream *substream) | |
1162 | { | |
1163 | struct via_spec *spec = codec->spec; | |
7eb56e84 | 1164 | |
ece8d043 | 1165 | if (snd_BUG_ON(!spec->hp_dac_nid)) |
7eb56e84 | 1166 | return -EINVAL; |
3b607e3d | 1167 | set_stream_open(codec, STREAM_INDEP_HP, true); |
ece8d043 TI |
1168 | return 0; |
1169 | } | |
1170 | ||
1171 | static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo, | |
1172 | struct hda_codec *codec, | |
1173 | struct snd_pcm_substream *substream) | |
1174 | { | |
3b607e3d | 1175 | set_stream_open(codec, STREAM_INDEP_HP, false); |
9af74210 TI |
1176 | return 0; |
1177 | } | |
1178 | ||
7eb56e84 TI |
1179 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
1180 | struct hda_codec *codec, | |
1181 | unsigned int stream_tag, | |
1182 | unsigned int format, | |
1183 | struct snd_pcm_substream *substream) | |
0aa62aef HW |
1184 | { |
1185 | struct via_spec *spec = codec->spec; | |
ece8d043 | 1186 | |
3b607e3d TI |
1187 | mutex_lock(&spec->config_mutex); |
1188 | setup_playback_multi_pcm(spec); | |
ece8d043 TI |
1189 | snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, |
1190 | format, substream); | |
3b607e3d TI |
1191 | /* remember for dynamic DAC switch with indep-HP */ |
1192 | spec->active_streams |= STREAM_MULTI_OUT; | |
1193 | spec->cur_dac_stream_tag = stream_tag; | |
1194 | spec->cur_dac_format = format; | |
1195 | mutex_unlock(&spec->config_mutex); | |
187d333e | 1196 | vt1708_update_hp_work(spec); |
7eb56e84 | 1197 | return 0; |
0aa62aef HW |
1198 | } |
1199 | ||
7eb56e84 TI |
1200 | static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, |
1201 | struct hda_codec *codec, | |
1202 | unsigned int stream_tag, | |
1203 | unsigned int format, | |
1204 | struct snd_pcm_substream *substream) | |
0aa62aef HW |
1205 | { |
1206 | struct via_spec *spec = codec->spec; | |
0aa62aef | 1207 | |
3b607e3d TI |
1208 | mutex_lock(&spec->config_mutex); |
1209 | if (spec->hp_independent_mode) | |
1210 | snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, | |
1211 | stream_tag, 0, format); | |
1212 | spec->active_streams |= STREAM_INDEP_HP; | |
1213 | spec->cur_hp_stream_tag = stream_tag; | |
1214 | spec->cur_hp_format = format; | |
1215 | mutex_unlock(&spec->config_mutex); | |
187d333e | 1216 | vt1708_update_hp_work(spec); |
0aa62aef HW |
1217 | return 0; |
1218 | } | |
1219 | ||
1220 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1221 | struct hda_codec *codec, | |
1222 | struct snd_pcm_substream *substream) | |
1223 | { | |
1224 | struct via_spec *spec = codec->spec; | |
0aa62aef | 1225 | |
3b607e3d | 1226 | mutex_lock(&spec->config_mutex); |
ece8d043 | 1227 | snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
3b607e3d TI |
1228 | spec->active_streams &= ~STREAM_MULTI_OUT; |
1229 | mutex_unlock(&spec->config_mutex); | |
187d333e | 1230 | vt1708_update_hp_work(spec); |
7eb56e84 TI |
1231 | return 0; |
1232 | } | |
1233 | ||
1234 | static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1235 | struct hda_codec *codec, | |
1236 | struct snd_pcm_substream *substream) | |
1237 | { | |
1238 | struct via_spec *spec = codec->spec; | |
7eb56e84 | 1239 | |
3b607e3d TI |
1240 | mutex_lock(&spec->config_mutex); |
1241 | if (spec->hp_independent_mode) | |
1242 | snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0); | |
1243 | spec->active_streams &= ~STREAM_INDEP_HP; | |
1244 | mutex_unlock(&spec->config_mutex); | |
187d333e | 1245 | vt1708_update_hp_work(spec); |
0aa62aef HW |
1246 | return 0; |
1247 | } | |
1248 | ||
c577b8a1 JC |
1249 | /* |
1250 | * Digital out | |
1251 | */ | |
1252 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
1253 | struct hda_codec *codec, | |
1254 | struct snd_pcm_substream *substream) | |
1255 | { | |
1256 | struct via_spec *spec = codec->spec; | |
1257 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
1258 | } | |
1259 | ||
1260 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
1261 | struct hda_codec *codec, | |
1262 | struct snd_pcm_substream *substream) | |
1263 | { | |
1264 | struct via_spec *spec = codec->spec; | |
1265 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
1266 | } | |
1267 | ||
5691ec7f | 1268 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
98aa34c0 HW |
1269 | struct hda_codec *codec, |
1270 | unsigned int stream_tag, | |
1271 | unsigned int format, | |
1272 | struct snd_pcm_substream *substream) | |
1273 | { | |
1274 | struct via_spec *spec = codec->spec; | |
9da29271 TI |
1275 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
1276 | stream_tag, format, substream); | |
1277 | } | |
98aa34c0 | 1278 | |
9da29271 TI |
1279 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
1280 | struct hda_codec *codec, | |
1281 | struct snd_pcm_substream *substream) | |
1282 | { | |
1283 | struct via_spec *spec = codec->spec; | |
1284 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
98aa34c0 HW |
1285 | return 0; |
1286 | } | |
1287 | ||
c577b8a1 JC |
1288 | /* |
1289 | * Analog capture | |
1290 | */ | |
1291 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1292 | struct hda_codec *codec, | |
1293 | unsigned int stream_tag, | |
1294 | unsigned int format, | |
1295 | struct snd_pcm_substream *substream) | |
1296 | { | |
1297 | struct via_spec *spec = codec->spec; | |
1298 | ||
1299 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
1300 | stream_tag, 0, format); | |
1301 | return 0; | |
1302 | } | |
1303 | ||
1304 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1305 | struct hda_codec *codec, | |
1306 | struct snd_pcm_substream *substream) | |
1307 | { | |
1308 | struct via_spec *spec = codec->spec; | |
888afa15 | 1309 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
c577b8a1 JC |
1310 | return 0; |
1311 | } | |
1312 | ||
a86a88ea TI |
1313 | /* analog capture with dynamic ADC switching */ |
1314 | static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
1315 | struct hda_codec *codec, | |
1316 | unsigned int stream_tag, | |
1317 | unsigned int format, | |
1318 | struct snd_pcm_substream *substream) | |
1319 | { | |
1320 | struct via_spec *spec = codec->spec; | |
1321 | int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx; | |
1322 | ||
3b607e3d | 1323 | mutex_lock(&spec->config_mutex); |
a86a88ea TI |
1324 | spec->cur_adc = spec->adc_nids[adc_idx]; |
1325 | spec->cur_adc_stream_tag = stream_tag; | |
1326 | spec->cur_adc_format = format; | |
1327 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); | |
3b607e3d | 1328 | mutex_unlock(&spec->config_mutex); |
a86a88ea TI |
1329 | return 0; |
1330 | } | |
1331 | ||
1332 | static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
1333 | struct hda_codec *codec, | |
1334 | struct snd_pcm_substream *substream) | |
1335 | { | |
1336 | struct via_spec *spec = codec->spec; | |
1337 | ||
3b607e3d | 1338 | mutex_lock(&spec->config_mutex); |
a86a88ea TI |
1339 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
1340 | spec->cur_adc = 0; | |
3b607e3d | 1341 | mutex_unlock(&spec->config_mutex); |
a86a88ea TI |
1342 | return 0; |
1343 | } | |
1344 | ||
1345 | /* re-setup the stream if running; called from input-src put */ | |
1346 | static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) | |
1347 | { | |
1348 | struct via_spec *spec = codec->spec; | |
1349 | int adc_idx = spec->inputs[cur].adc_idx; | |
1350 | hda_nid_t adc = spec->adc_nids[adc_idx]; | |
3b607e3d | 1351 | bool ret = false; |
a86a88ea | 1352 | |
3b607e3d | 1353 | mutex_lock(&spec->config_mutex); |
a86a88ea TI |
1354 | if (spec->cur_adc && spec->cur_adc != adc) { |
1355 | /* stream is running, let's swap the current ADC */ | |
1356 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); | |
1357 | spec->cur_adc = adc; | |
1358 | snd_hda_codec_setup_stream(codec, adc, | |
1359 | spec->cur_adc_stream_tag, 0, | |
1360 | spec->cur_adc_format); | |
3b607e3d | 1361 | ret = true; |
a86a88ea | 1362 | } |
3b607e3d TI |
1363 | mutex_unlock(&spec->config_mutex); |
1364 | return ret; | |
a86a88ea TI |
1365 | } |
1366 | ||
9af74210 | 1367 | static const struct hda_pcm_stream via_pcm_analog_playback = { |
7eb56e84 | 1368 | .substreams = 1, |
c577b8a1 JC |
1369 | .channels_min = 2, |
1370 | .channels_max = 8, | |
9af74210 | 1371 | /* NID is set in via_build_pcms */ |
c577b8a1 | 1372 | .ops = { |
ece8d043 TI |
1373 | .open = via_playback_multi_pcm_open, |
1374 | .close = via_playback_multi_pcm_close, | |
0aa62aef HW |
1375 | .prepare = via_playback_multi_pcm_prepare, |
1376 | .cleanup = via_playback_multi_pcm_cleanup | |
c577b8a1 JC |
1377 | }, |
1378 | }; | |
1379 | ||
7eb56e84 TI |
1380 | static const struct hda_pcm_stream via_pcm_hp_playback = { |
1381 | .substreams = 1, | |
1382 | .channels_min = 2, | |
1383 | .channels_max = 2, | |
1384 | /* NID is set in via_build_pcms */ | |
1385 | .ops = { | |
1386 | .open = via_playback_hp_pcm_open, | |
ece8d043 | 1387 | .close = via_playback_hp_pcm_close, |
7eb56e84 TI |
1388 | .prepare = via_playback_hp_pcm_prepare, |
1389 | .cleanup = via_playback_hp_pcm_cleanup | |
1390 | }, | |
1391 | }; | |
1392 | ||
90dd48a1 | 1393 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
7eb56e84 | 1394 | .substreams = 1, |
bc9b5623 TI |
1395 | .channels_min = 2, |
1396 | .channels_max = 8, | |
9af74210 | 1397 | /* NID is set in via_build_pcms */ |
bc9b5623 TI |
1398 | /* We got noisy outputs on the right channel on VT1708 when |
1399 | * 24bit samples are used. Until any workaround is found, | |
1400 | * disable the 24bit format, so far. | |
1401 | */ | |
1402 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
1403 | .ops = { | |
ece8d043 TI |
1404 | .open = via_playback_multi_pcm_open, |
1405 | .close = via_playback_multi_pcm_close, | |
c873cc25 LW |
1406 | .prepare = via_playback_multi_pcm_prepare, |
1407 | .cleanup = via_playback_multi_pcm_cleanup | |
bc9b5623 TI |
1408 | }, |
1409 | }; | |
1410 | ||
9af74210 | 1411 | static const struct hda_pcm_stream via_pcm_analog_capture = { |
7eb56e84 | 1412 | .substreams = 1, /* will be changed in via_build_pcms() */ |
c577b8a1 JC |
1413 | .channels_min = 2, |
1414 | .channels_max = 2, | |
9af74210 | 1415 | /* NID is set in via_build_pcms */ |
c577b8a1 JC |
1416 | .ops = { |
1417 | .prepare = via_capture_pcm_prepare, | |
1418 | .cleanup = via_capture_pcm_cleanup | |
1419 | }, | |
1420 | }; | |
1421 | ||
a86a88ea TI |
1422 | static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = { |
1423 | .substreams = 1, | |
1424 | .channels_min = 2, | |
1425 | .channels_max = 2, | |
1426 | /* NID is set in via_build_pcms */ | |
1427 | .ops = { | |
1428 | .prepare = via_dyn_adc_capture_pcm_prepare, | |
1429 | .cleanup = via_dyn_adc_capture_pcm_cleanup, | |
1430 | }, | |
1431 | }; | |
1432 | ||
9af74210 | 1433 | static const struct hda_pcm_stream via_pcm_digital_playback = { |
c577b8a1 JC |
1434 | .substreams = 1, |
1435 | .channels_min = 2, | |
1436 | .channels_max = 2, | |
1437 | /* NID is set in via_build_pcms */ | |
1438 | .ops = { | |
1439 | .open = via_dig_playback_pcm_open, | |
6b97eb45 | 1440 | .close = via_dig_playback_pcm_close, |
9da29271 TI |
1441 | .prepare = via_dig_playback_pcm_prepare, |
1442 | .cleanup = via_dig_playback_pcm_cleanup | |
c577b8a1 JC |
1443 | }, |
1444 | }; | |
1445 | ||
9af74210 | 1446 | static const struct hda_pcm_stream via_pcm_digital_capture = { |
c577b8a1 JC |
1447 | .substreams = 1, |
1448 | .channels_min = 2, | |
1449 | .channels_max = 2, | |
1450 | }; | |
1451 | ||
370bafbd TI |
1452 | /* |
1453 | * slave controls for virtual master | |
1454 | */ | |
9322ca54 TI |
1455 | static const char * const via_slave_pfxs[] = { |
1456 | "Front", "Surround", "Center", "LFE", "Side", | |
1457 | "Headphone", "Speaker", | |
370bafbd TI |
1458 | NULL, |
1459 | }; | |
1460 | ||
c577b8a1 JC |
1461 | static int via_build_controls(struct hda_codec *codec) |
1462 | { | |
1463 | struct via_spec *spec = codec->spec; | |
5b0cb1d8 | 1464 | struct snd_kcontrol *kctl; |
5b0cb1d8 | 1465 | int err, i; |
c577b8a1 | 1466 | |
b5bcc189 | 1467 | spec->no_pin_power_ctl = 1; |
24088a58 TI |
1468 | if (spec->set_widgets_power_state) |
1469 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) | |
1470 | return -ENOMEM; | |
1471 | ||
c577b8a1 JC |
1472 | for (i = 0; i < spec->num_mixers; i++) { |
1473 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
1474 | if (err < 0) | |
1475 | return err; | |
1476 | } | |
1477 | ||
1478 | if (spec->multiout.dig_out_nid) { | |
1479 | err = snd_hda_create_spdif_out_ctls(codec, | |
74b654c9 | 1480 | spec->multiout.dig_out_nid, |
c577b8a1 JC |
1481 | spec->multiout.dig_out_nid); |
1482 | if (err < 0) | |
1483 | return err; | |
9a08160b TI |
1484 | err = snd_hda_create_spdif_share_sw(codec, |
1485 | &spec->multiout); | |
1486 | if (err < 0) | |
1487 | return err; | |
1488 | spec->multiout.share_spdif = 1; | |
c577b8a1 JC |
1489 | } |
1490 | if (spec->dig_in_nid) { | |
1491 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
1492 | if (err < 0) | |
1493 | return err; | |
1494 | } | |
17314379 | 1495 | |
370bafbd TI |
1496 | /* if we have no master control, let's create it */ |
1497 | if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { | |
1498 | unsigned int vmaster_tlv[4]; | |
1499 | snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], | |
1500 | HDA_OUTPUT, vmaster_tlv); | |
1501 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", | |
9322ca54 TI |
1502 | vmaster_tlv, via_slave_pfxs, |
1503 | "Playback Volume"); | |
370bafbd TI |
1504 | if (err < 0) |
1505 | return err; | |
1506 | } | |
1507 | if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { | |
1508 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", | |
9322ca54 TI |
1509 | NULL, via_slave_pfxs, |
1510 | "Playback Switch"); | |
370bafbd TI |
1511 | if (err < 0) |
1512 | return err; | |
1513 | } | |
1514 | ||
5b0cb1d8 JK |
1515 | /* assign Capture Source enums to NID */ |
1516 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); | |
1517 | for (i = 0; kctl && i < kctl->count; i++) { | |
77e314f7 TI |
1518 | if (!spec->mux_nids[i]) |
1519 | continue; | |
21949f00 | 1520 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
5b0cb1d8 JK |
1521 | if (err < 0) |
1522 | return err; | |
1523 | } | |
1524 | ||
603c4019 | 1525 | via_free_kctls(codec); /* no longer needed */ |
01a61e12 TI |
1526 | |
1527 | err = snd_hda_jack_add_kctls(codec, &spec->autocfg); | |
1528 | if (err < 0) | |
1529 | return err; | |
1530 | ||
c577b8a1 JC |
1531 | return 0; |
1532 | } | |
1533 | ||
1534 | static int via_build_pcms(struct hda_codec *codec) | |
1535 | { | |
1536 | struct via_spec *spec = codec->spec; | |
1537 | struct hda_pcm *info = spec->pcm_rec; | |
1538 | ||
a5973103 | 1539 | codec->num_pcms = 0; |
c577b8a1 JC |
1540 | codec->pcm_info = info; |
1541 | ||
a5973103 TI |
1542 | if (spec->multiout.num_dacs || spec->num_adc_nids) { |
1543 | snprintf(spec->stream_name_analog, | |
1544 | sizeof(spec->stream_name_analog), | |
1545 | "%s Analog", codec->chip_name); | |
1546 | info->name = spec->stream_name_analog; | |
9af74210 | 1547 | |
a5973103 TI |
1548 | if (spec->multiout.num_dacs) { |
1549 | if (!spec->stream_analog_playback) | |
1550 | spec->stream_analog_playback = | |
1551 | &via_pcm_analog_playback; | |
1552 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | |
1553 | *spec->stream_analog_playback; | |
1554 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
1555 | spec->multiout.dac_nids[0]; | |
1556 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
1557 | spec->multiout.max_channels; | |
1558 | } | |
c577b8a1 | 1559 | |
a5973103 TI |
1560 | if (!spec->stream_analog_capture) { |
1561 | if (spec->dyn_adc_switch) | |
1562 | spec->stream_analog_capture = | |
1563 | &via_pcm_dyn_adc_analog_capture; | |
1564 | else | |
1565 | spec->stream_analog_capture = | |
1566 | &via_pcm_analog_capture; | |
1567 | } | |
1568 | if (spec->num_adc_nids) { | |
1569 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
1570 | *spec->stream_analog_capture; | |
1571 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
1572 | spec->adc_nids[0]; | |
1573 | if (!spec->dyn_adc_switch) | |
1574 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = | |
1575 | spec->num_adc_nids; | |
1576 | } | |
1577 | codec->num_pcms++; | |
1578 | info++; | |
a86a88ea | 1579 | } |
c577b8a1 JC |
1580 | |
1581 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | |
82673bc8 TI |
1582 | snprintf(spec->stream_name_digital, |
1583 | sizeof(spec->stream_name_digital), | |
1584 | "%s Digital", codec->chip_name); | |
c577b8a1 | 1585 | info->name = spec->stream_name_digital; |
7ba72ba1 | 1586 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
c577b8a1 | 1587 | if (spec->multiout.dig_out_nid) { |
9af74210 TI |
1588 | if (!spec->stream_digital_playback) |
1589 | spec->stream_digital_playback = | |
1590 | &via_pcm_digital_playback; | |
c577b8a1 | 1591 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
9af74210 | 1592 | *spec->stream_digital_playback; |
c577b8a1 JC |
1593 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
1594 | spec->multiout.dig_out_nid; | |
1595 | } | |
1596 | if (spec->dig_in_nid) { | |
9af74210 TI |
1597 | if (!spec->stream_digital_capture) |
1598 | spec->stream_digital_capture = | |
1599 | &via_pcm_digital_capture; | |
c577b8a1 | 1600 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
9af74210 | 1601 | *spec->stream_digital_capture; |
c577b8a1 JC |
1602 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
1603 | spec->dig_in_nid; | |
1604 | } | |
a5973103 TI |
1605 | codec->num_pcms++; |
1606 | info++; | |
c577b8a1 JC |
1607 | } |
1608 | ||
ece8d043 | 1609 | if (spec->hp_dac_nid) { |
7eb56e84 TI |
1610 | snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), |
1611 | "%s HP", codec->chip_name); | |
1612 | info->name = spec->stream_name_hp; | |
1613 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; | |
1614 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
ece8d043 | 1615 | spec->hp_dac_nid; |
a5973103 TI |
1616 | codec->num_pcms++; |
1617 | info++; | |
7eb56e84 | 1618 | } |
c577b8a1 JC |
1619 | return 0; |
1620 | } | |
1621 | ||
1622 | static void via_free(struct hda_codec *codec) | |
1623 | { | |
1624 | struct via_spec *spec = codec->spec; | |
c577b8a1 JC |
1625 | |
1626 | if (!spec) | |
1627 | return; | |
1628 | ||
603c4019 | 1629 | via_free_kctls(codec); |
1f2e99fe | 1630 | vt1708_stop_hp_work(spec); |
a86a88ea TI |
1631 | kfree(spec->bind_cap_vol); |
1632 | kfree(spec->bind_cap_sw); | |
7819d1c7 | 1633 | snd_hda_gen_free(&spec->gen); |
a86a88ea | 1634 | kfree(spec); |
c577b8a1 JC |
1635 | } |
1636 | ||
64be285b TI |
1637 | /* mute/unmute outputs */ |
1638 | static void toggle_output_mutes(struct hda_codec *codec, int num_pins, | |
1639 | hda_nid_t *pins, bool mute) | |
1640 | { | |
1641 | int i; | |
94994734 TI |
1642 | for (i = 0; i < num_pins; i++) { |
1643 | unsigned int parm = snd_hda_codec_read(codec, pins[i], 0, | |
1644 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); | |
1645 | if (parm & AC_PINCTL_IN_EN) | |
1646 | continue; | |
1647 | if (mute) | |
1648 | parm &= ~AC_PINCTL_OUT_EN; | |
1649 | else | |
1650 | parm |= AC_PINCTL_OUT_EN; | |
cdd03ced | 1651 | snd_hda_set_pin_ctl(codec, pins[i], parm); |
94994734 | 1652 | } |
64be285b TI |
1653 | } |
1654 | ||
4a918ffe TI |
1655 | /* mute internal speaker if line-out is plugged */ |
1656 | static void via_line_automute(struct hda_codec *codec, int present) | |
69e52a80 | 1657 | { |
69e52a80 HW |
1658 | struct via_spec *spec = codec->spec; |
1659 | ||
4a918ffe TI |
1660 | if (!spec->autocfg.speaker_outs) |
1661 | return; | |
1662 | if (!present) | |
1663 | present = snd_hda_jack_detect(codec, | |
1664 | spec->autocfg.line_out_pins[0]); | |
1665 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, | |
1666 | spec->autocfg.speaker_pins, | |
1667 | present); | |
69e52a80 HW |
1668 | } |
1669 | ||
4a918ffe TI |
1670 | /* mute internal speaker if HP is plugged */ |
1671 | static void via_hp_automute(struct hda_codec *codec) | |
f3db423d | 1672 | { |
4a918ffe | 1673 | int present = 0; |
6e969d91 | 1674 | int nums; |
f3db423d LW |
1675 | struct via_spec *spec = codec->spec; |
1676 | ||
187d333e | 1677 | if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] && |
cf55e904 HRK |
1678 | (spec->codec_type != VT1708 || spec->vt1708_jack_detect) && |
1679 | is_jack_detectable(codec, spec->autocfg.hp_pins[0])) | |
4a918ffe | 1680 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
6e969d91 TI |
1681 | |
1682 | if (spec->smart51_enabled) | |
1683 | nums = spec->autocfg.line_outs + spec->smart51_nums; | |
1684 | else | |
1685 | nums = spec->autocfg.line_outs; | |
1686 | toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present); | |
1687 | ||
4a918ffe | 1688 | via_line_automute(codec, present); |
f3db423d LW |
1689 | } |
1690 | ||
2a43952a | 1691 | #ifdef CONFIG_PM |
68cb2b55 | 1692 | static int via_suspend(struct hda_codec *codec) |
1f2e99fe LW |
1693 | { |
1694 | struct via_spec *spec = codec->spec; | |
1695 | vt1708_stop_hp_work(spec); | |
94c142a1 DH |
1696 | |
1697 | if (spec->codec_type == VT1802) { | |
1698 | /* Fix pop noise on headphones */ | |
1699 | int i; | |
1700 | for (i = 0; i < spec->autocfg.hp_outs; i++) | |
1701 | snd_hda_set_pin_ctl(codec, spec->autocfg.hp_pins[i], 0); | |
1702 | } | |
1703 | ||
1f2e99fe LW |
1704 | return 0; |
1705 | } | |
1706 | #endif | |
1707 | ||
83012a7c | 1708 | #ifdef CONFIG_PM |
cb53c626 TI |
1709 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
1710 | { | |
1711 | struct via_spec *spec = codec->spec; | |
1712 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | |
1713 | } | |
1714 | #endif | |
1715 | ||
c577b8a1 JC |
1716 | /* |
1717 | */ | |
5d41762a TI |
1718 | |
1719 | static int via_init(struct hda_codec *codec); | |
1720 | ||
90dd48a1 | 1721 | static const struct hda_codec_ops via_patch_ops = { |
c577b8a1 JC |
1722 | .build_controls = via_build_controls, |
1723 | .build_pcms = via_build_pcms, | |
1724 | .init = via_init, | |
1725 | .free = via_free, | |
4e2d16d3 | 1726 | .unsol_event = snd_hda_jack_unsol_event, |
2a43952a | 1727 | #ifdef CONFIG_PM |
1f2e99fe | 1728 | .suspend = via_suspend, |
cb53c626 TI |
1729 | .check_power_status = via_check_power_status, |
1730 | #endif | |
c577b8a1 JC |
1731 | }; |
1732 | ||
4a79616d TI |
1733 | static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) |
1734 | { | |
1735 | struct via_spec *spec = codec->spec; | |
1736 | int i; | |
1737 | ||
1738 | for (i = 0; i < spec->multiout.num_dacs; i++) { | |
1739 | if (spec->multiout.dac_nids[i] == dac) | |
1740 | return false; | |
1741 | } | |
ece8d043 | 1742 | if (spec->hp_dac_nid == dac) |
4a79616d TI |
1743 | return false; |
1744 | return true; | |
1745 | } | |
1746 | ||
8e3679dc | 1747 | static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
3214b966 TI |
1748 | hda_nid_t target_dac, int with_aa_mix, |
1749 | struct nid_path *path, int depth) | |
4a79616d | 1750 | { |
3214b966 | 1751 | struct via_spec *spec = codec->spec; |
4a79616d TI |
1752 | hda_nid_t conn[8]; |
1753 | int i, nums; | |
1754 | ||
3214b966 TI |
1755 | if (nid == spec->aa_mix_nid) { |
1756 | if (!with_aa_mix) | |
1757 | return false; | |
1758 | with_aa_mix = 2; /* mark aa-mix is included */ | |
1759 | } | |
1760 | ||
4a79616d TI |
1761 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); |
1762 | for (i = 0; i < nums; i++) { | |
1763 | if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) | |
1764 | continue; | |
3214b966 TI |
1765 | if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { |
1766 | /* aa-mix is requested but not included? */ | |
1767 | if (!(spec->aa_mix_nid && with_aa_mix == 1)) | |
1768 | goto found; | |
1769 | } | |
4a79616d | 1770 | } |
8e3679dc | 1771 | if (depth >= MAX_NID_PATH_DEPTH) |
4a79616d TI |
1772 | return false; |
1773 | for (i = 0; i < nums; i++) { | |
1774 | unsigned int type; | |
1775 | type = get_wcaps_type(get_wcaps(codec, conn[i])); | |
3214b966 | 1776 | if (type == AC_WID_AUD_OUT) |
4a79616d | 1777 | continue; |
8e3679dc | 1778 | if (__parse_output_path(codec, conn[i], target_dac, |
3214b966 | 1779 | with_aa_mix, path, depth + 1)) |
09a9ad69 | 1780 | goto found; |
4a79616d TI |
1781 | } |
1782 | return false; | |
09a9ad69 TI |
1783 | |
1784 | found: | |
1785 | path->path[path->depth] = conn[i]; | |
1786 | path->idx[path->depth] = i; | |
1787 | if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) | |
1788 | path->multi[path->depth] = 1; | |
1789 | path->depth++; | |
1790 | return true; | |
4a79616d TI |
1791 | } |
1792 | ||
8e3679dc | 1793 | static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
3214b966 TI |
1794 | hda_nid_t target_dac, int with_aa_mix, |
1795 | struct nid_path *path) | |
8e3679dc | 1796 | { |
3214b966 | 1797 | if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) { |
8e3679dc TI |
1798 | path->path[path->depth] = nid; |
1799 | path->depth++; | |
3214b966 TI |
1800 | snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n", |
1801 | path->depth, path->path[0], path->path[1], | |
1802 | path->path[2], path->path[3], path->path[4]); | |
8e3679dc TI |
1803 | return true; |
1804 | } | |
1805 | return false; | |
1806 | } | |
1807 | ||
4a79616d | 1808 | static int via_auto_fill_dac_nids(struct hda_codec *codec) |
c577b8a1 | 1809 | { |
4a79616d TI |
1810 | struct via_spec *spec = codec->spec; |
1811 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
5b376195 | 1812 | int i; |
c577b8a1 JC |
1813 | hda_nid_t nid; |
1814 | ||
5b376195 | 1815 | spec->multiout.num_dacs = 0; |
4a79616d | 1816 | spec->multiout.dac_nids = spec->private_dac_nids; |
4a79616d | 1817 | for (i = 0; i < cfg->line_outs; i++) { |
3214b966 | 1818 | hda_nid_t dac = 0; |
4a79616d TI |
1819 | nid = cfg->line_out_pins[i]; |
1820 | if (!nid) | |
1821 | continue; | |
3214b966 TI |
1822 | if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i])) |
1823 | dac = spec->out_path[i].path[0]; | |
1824 | if (!i && parse_output_path(codec, nid, dac, 1, | |
1825 | &spec->out_mix_path)) | |
1826 | dac = spec->out_mix_path.path[0]; | |
5b376195 TI |
1827 | if (dac) |
1828 | spec->private_dac_nids[spec->multiout.num_dacs++] = dac; | |
4a79616d | 1829 | } |
3214b966 TI |
1830 | if (!spec->out_path[0].depth && spec->out_mix_path.depth) { |
1831 | spec->out_path[0] = spec->out_mix_path; | |
1832 | spec->out_mix_path.depth = 0; | |
1833 | } | |
4a79616d TI |
1834 | return 0; |
1835 | } | |
c577b8a1 | 1836 | |
4a79616d | 1837 | static int create_ch_ctls(struct hda_codec *codec, const char *pfx, |
09a9ad69 | 1838 | int chs, bool check_dac, struct nid_path *path) |
4a79616d TI |
1839 | { |
1840 | struct via_spec *spec = codec->spec; | |
1841 | char name[32]; | |
09a9ad69 TI |
1842 | hda_nid_t dac, pin, sel, nid; |
1843 | int err; | |
a934d5a9 | 1844 | |
09a9ad69 TI |
1845 | dac = check_dac ? path->path[0] : 0; |
1846 | pin = path->path[path->depth - 1]; | |
1847 | sel = path->depth > 1 ? path->path[1] : 0; | |
377ff31a | 1848 | |
8df2a312 | 1849 | if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) |
4a79616d | 1850 | nid = dac; |
8df2a312 | 1851 | else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) |
4a79616d | 1852 | nid = pin; |
a934d5a9 TI |
1853 | else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) |
1854 | nid = sel; | |
4a79616d TI |
1855 | else |
1856 | nid = 0; | |
1857 | if (nid) { | |
1858 | sprintf(name, "%s Playback Volume", pfx); | |
1859 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
a00a5fad | 1860 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
4a79616d TI |
1861 | if (err < 0) |
1862 | return err; | |
09a9ad69 | 1863 | path->vol_ctl = nid; |
c577b8a1 JC |
1864 | } |
1865 | ||
8df2a312 | 1866 | if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE)) |
4a79616d | 1867 | nid = dac; |
8df2a312 | 1868 | else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE)) |
4a79616d | 1869 | nid = pin; |
a934d5a9 TI |
1870 | else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE)) |
1871 | nid = sel; | |
4a79616d TI |
1872 | else |
1873 | nid = 0; | |
1874 | if (nid) { | |
1875 | sprintf(name, "%s Playback Switch", pfx); | |
1876 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
1877 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); | |
1878 | if (err < 0) | |
1879 | return err; | |
09a9ad69 | 1880 | path->mute_ctl = nid; |
4a79616d | 1881 | } |
c577b8a1 JC |
1882 | return 0; |
1883 | } | |
1884 | ||
f4a7828b TI |
1885 | static void mangle_smart51(struct hda_codec *codec) |
1886 | { | |
1887 | struct via_spec *spec = codec->spec; | |
1888 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
0f98c24b TI |
1889 | struct auto_pin_cfg_item *ins = cfg->inputs; |
1890 | int i, j, nums, attr; | |
1891 | int pins[AUTO_CFG_MAX_INS]; | |
1892 | ||
1893 | for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) { | |
1894 | nums = 0; | |
1895 | for (i = 0; i < cfg->num_inputs; i++) { | |
1896 | unsigned int def; | |
1897 | if (ins[i].type > AUTO_PIN_LINE_IN) | |
1898 | continue; | |
1899 | def = snd_hda_codec_get_pincfg(codec, ins[i].pin); | |
1900 | if (snd_hda_get_input_pin_attr(def) != attr) | |
1901 | continue; | |
1902 | for (j = 0; j < nums; j++) | |
1903 | if (ins[pins[j]].type < ins[i].type) { | |
1904 | memmove(pins + j + 1, pins + j, | |
21d45d2b | 1905 | (nums - j) * sizeof(int)); |
0f98c24b TI |
1906 | break; |
1907 | } | |
1908 | pins[j] = i; | |
e3d7a143 | 1909 | nums++; |
0f98c24b TI |
1910 | } |
1911 | if (cfg->line_outs + nums < 3) | |
f4a7828b | 1912 | continue; |
0f98c24b TI |
1913 | for (i = 0; i < nums; i++) { |
1914 | hda_nid_t pin = ins[pins[i]].pin; | |
1915 | spec->smart51_pins[spec->smart51_nums++] = pin; | |
1916 | cfg->line_out_pins[cfg->line_outs++] = pin; | |
1917 | if (cfg->line_outs == 3) | |
1918 | break; | |
1919 | } | |
1920 | return; | |
f4a7828b TI |
1921 | } |
1922 | } | |
1923 | ||
020066d1 TI |
1924 | static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src) |
1925 | { | |
1926 | dst->vol_ctl = src->vol_ctl; | |
1927 | dst->mute_ctl = src->mute_ctl; | |
1928 | } | |
1929 | ||
c577b8a1 | 1930 | /* add playback controls from the parsed DAC table */ |
4a79616d | 1931 | static int via_auto_create_multi_out_ctls(struct hda_codec *codec) |
c577b8a1 | 1932 | { |
4a79616d | 1933 | struct via_spec *spec = codec->spec; |
f4a7828b | 1934 | struct auto_pin_cfg *cfg = &spec->autocfg; |
3214b966 | 1935 | struct nid_path *path; |
ea734963 TI |
1936 | static const char * const chname[4] = { |
1937 | "Front", "Surround", "C/LFE", "Side" | |
1938 | }; | |
4a79616d | 1939 | int i, idx, err; |
f4a7828b TI |
1940 | int old_line_outs; |
1941 | ||
1942 | /* check smart51 */ | |
1943 | old_line_outs = cfg->line_outs; | |
1944 | if (cfg->line_outs == 1) | |
1945 | mangle_smart51(codec); | |
c577b8a1 | 1946 | |
e3d7a143 TI |
1947 | err = via_auto_fill_dac_nids(codec); |
1948 | if (err < 0) | |
1949 | return err; | |
1950 | ||
5c9a5615 LW |
1951 | if (spec->multiout.num_dacs < 3) { |
1952 | spec->smart51_nums = 0; | |
1953 | cfg->line_outs = old_line_outs; | |
1954 | } | |
4a79616d TI |
1955 | for (i = 0; i < cfg->line_outs; i++) { |
1956 | hda_nid_t pin, dac; | |
1957 | pin = cfg->line_out_pins[i]; | |
1958 | dac = spec->multiout.dac_nids[i]; | |
1959 | if (!pin || !dac) | |
c577b8a1 | 1960 | continue; |
3214b966 | 1961 | path = spec->out_path + i; |
0fe0adf8 | 1962 | if (i == HDA_CLFE) { |
3214b966 | 1963 | err = create_ch_ctls(codec, "Center", 1, true, path); |
c577b8a1 JC |
1964 | if (err < 0) |
1965 | return err; | |
3214b966 | 1966 | err = create_ch_ctls(codec, "LFE", 2, true, path); |
c577b8a1 JC |
1967 | if (err < 0) |
1968 | return err; | |
1969 | } else { | |
6aadf41d TI |
1970 | const char *pfx = chname[i]; |
1971 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && | |
1972 | cfg->line_outs == 1) | |
1973 | pfx = "Speaker"; | |
3214b966 | 1974 | err = create_ch_ctls(codec, pfx, 3, true, path); |
c577b8a1 JC |
1975 | if (err < 0) |
1976 | return err; | |
1977 | } | |
020066d1 TI |
1978 | if (path != spec->out_path + i) |
1979 | copy_path_mixer_ctls(&spec->out_path[i], path); | |
1980 | if (path == spec->out_path && spec->out_mix_path.depth) | |
1981 | copy_path_mixer_ctls(&spec->out_mix_path, path); | |
c577b8a1 JC |
1982 | } |
1983 | ||
4a79616d TI |
1984 | idx = get_connection_index(codec, spec->aa_mix_nid, |
1985 | spec->multiout.dac_nids[0]); | |
1986 | if (idx >= 0) { | |
1987 | /* add control to mixer */ | |
3214b966 TI |
1988 | const char *name; |
1989 | name = spec->out_mix_path.depth ? | |
1990 | "PCM Loopback Playback Volume" : "PCM Playback Volume"; | |
1991 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
4a79616d TI |
1992 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
1993 | idx, HDA_INPUT)); | |
1994 | if (err < 0) | |
1995 | return err; | |
3214b966 TI |
1996 | name = spec->out_mix_path.depth ? |
1997 | "PCM Loopback Playback Switch" : "PCM Playback Switch"; | |
1998 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
4a79616d TI |
1999 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
2000 | idx, HDA_INPUT)); | |
2001 | if (err < 0) | |
2002 | return err; | |
2003 | } | |
2004 | ||
f4a7828b TI |
2005 | cfg->line_outs = old_line_outs; |
2006 | ||
c577b8a1 JC |
2007 | return 0; |
2008 | } | |
2009 | ||
4a79616d | 2010 | static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) |
c577b8a1 | 2011 | { |
4a79616d | 2012 | struct via_spec *spec = codec->spec; |
09a9ad69 | 2013 | struct nid_path *path; |
18bd2c44 | 2014 | bool check_dac; |
3214b966 | 2015 | int i, err; |
c577b8a1 JC |
2016 | |
2017 | if (!pin) | |
2018 | return 0; | |
2019 | ||
3214b966 TI |
2020 | if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) { |
2021 | for (i = HDA_SIDE; i >= HDA_CLFE; i--) { | |
2022 | if (i < spec->multiout.num_dacs && | |
2023 | parse_output_path(codec, pin, | |
2024 | spec->multiout.dac_nids[i], 0, | |
2025 | &spec->hp_indep_path)) { | |
2026 | spec->hp_indep_shared = i; | |
2027 | break; | |
2028 | } | |
2029 | } | |
25250505 | 2030 | } |
3214b966 TI |
2031 | if (spec->hp_indep_path.depth) { |
2032 | spec->hp_dac_nid = spec->hp_indep_path.path[0]; | |
2033 | if (!spec->hp_indep_shared) | |
2034 | spec->hp_path = spec->hp_indep_path; | |
2035 | } | |
2036 | /* optionally check front-path w/o AA-mix */ | |
2037 | if (!spec->hp_path.depth) | |
2038 | parse_output_path(codec, pin, | |
2039 | spec->multiout.dac_nids[HDA_FRONT], 0, | |
2040 | &spec->hp_path); | |
c577b8a1 | 2041 | |
ece8d043 | 2042 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
3214b966 | 2043 | 1, &spec->hp_mix_path) && !spec->hp_path.depth) |
ece8d043 TI |
2044 | return 0; |
2045 | ||
3214b966 | 2046 | if (spec->hp_path.depth) { |
09a9ad69 | 2047 | path = &spec->hp_path; |
18bd2c44 TI |
2048 | check_dac = true; |
2049 | } else { | |
3214b966 | 2050 | path = &spec->hp_mix_path; |
18bd2c44 TI |
2051 | check_dac = false; |
2052 | } | |
2053 | err = create_ch_ctls(codec, "Headphone", 3, check_dac, path); | |
c577b8a1 JC |
2054 | if (err < 0) |
2055 | return err; | |
020066d1 TI |
2056 | if (check_dac) |
2057 | copy_path_mixer_ctls(&spec->hp_mix_path, path); | |
2058 | else | |
2059 | copy_path_mixer_ctls(&spec->hp_path, path); | |
2060 | if (spec->hp_indep_path.depth) | |
2061 | copy_path_mixer_ctls(&spec->hp_indep_path, path); | |
c577b8a1 JC |
2062 | return 0; |
2063 | } | |
2064 | ||
4a918ffe TI |
2065 | static int via_auto_create_speaker_ctls(struct hda_codec *codec) |
2066 | { | |
2067 | struct via_spec *spec = codec->spec; | |
3214b966 TI |
2068 | struct nid_path *path; |
2069 | bool check_dac; | |
81c0a78b | 2070 | hda_nid_t pin, dac = 0; |
3214b966 | 2071 | int err; |
4a918ffe TI |
2072 | |
2073 | pin = spec->autocfg.speaker_pins[0]; | |
2074 | if (!spec->autocfg.speaker_outs || !pin) | |
2075 | return 0; | |
2076 | ||
3214b966 | 2077 | if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path)) |
8e3679dc | 2078 | dac = spec->speaker_path.path[0]; |
3214b966 TI |
2079 | if (!dac) |
2080 | parse_output_path(codec, pin, | |
2081 | spec->multiout.dac_nids[HDA_FRONT], 0, | |
2082 | &spec->speaker_path); | |
2083 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], | |
2084 | 1, &spec->speaker_mix_path) && !dac) | |
2085 | return 0; | |
2086 | ||
2087 | /* no AA-path for front? */ | |
2088 | if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth) | |
2089 | dac = 0; | |
2090 | ||
2091 | spec->speaker_dac_nid = dac; | |
2092 | spec->multiout.extra_out_nid[0] = dac; | |
2093 | if (dac) { | |
2094 | path = &spec->speaker_path; | |
2095 | check_dac = true; | |
2096 | } else { | |
2097 | path = &spec->speaker_mix_path; | |
2098 | check_dac = false; | |
2099 | } | |
2100 | err = create_ch_ctls(codec, "Speaker", 3, check_dac, path); | |
2101 | if (err < 0) | |
2102 | return err; | |
020066d1 TI |
2103 | if (check_dac) |
2104 | copy_path_mixer_ctls(&spec->speaker_mix_path, path); | |
2105 | else | |
2106 | copy_path_mixer_ctls(&spec->speaker_path, path); | |
3214b966 TI |
2107 | return 0; |
2108 | } | |
2109 | ||
2110 | #define via_aamix_ctl_info via_pin_power_ctl_info | |
4a918ffe | 2111 | |
3214b966 TI |
2112 | static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol, |
2113 | struct snd_ctl_elem_value *ucontrol) | |
2114 | { | |
2115 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2116 | struct via_spec *spec = codec->spec; | |
2117 | ucontrol->value.enumerated.item[0] = spec->aamix_mode; | |
2118 | return 0; | |
2119 | } | |
2120 | ||
2121 | static void update_aamix_paths(struct hda_codec *codec, int do_mix, | |
2122 | struct nid_path *nomix, struct nid_path *mix) | |
2123 | { | |
2124 | if (do_mix) { | |
2125 | activate_output_path(codec, nomix, false, false); | |
2126 | activate_output_path(codec, mix, true, false); | |
2127 | } else { | |
2128 | activate_output_path(codec, mix, false, false); | |
2129 | activate_output_path(codec, nomix, true, false); | |
2130 | } | |
2131 | } | |
2132 | ||
2133 | static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol, | |
2134 | struct snd_ctl_elem_value *ucontrol) | |
2135 | { | |
2136 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2137 | struct via_spec *spec = codec->spec; | |
2138 | unsigned int val = ucontrol->value.enumerated.item[0]; | |
2139 | ||
2140 | if (val == spec->aamix_mode) | |
2141 | return 0; | |
2142 | spec->aamix_mode = val; | |
2143 | /* update front path */ | |
2144 | update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path); | |
2145 | /* update HP path */ | |
2146 | if (!spec->hp_independent_mode) { | |
2147 | update_aamix_paths(codec, val, &spec->hp_path, | |
2148 | &spec->hp_mix_path); | |
2149 | } | |
2150 | /* update speaker path */ | |
2151 | update_aamix_paths(codec, val, &spec->speaker_path, | |
2152 | &spec->speaker_mix_path); | |
2153 | return 1; | |
2154 | } | |
2155 | ||
2156 | static const struct snd_kcontrol_new via_aamix_ctl_enum = { | |
2157 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2158 | .name = "Loopback Mixing", | |
2159 | .info = via_aamix_ctl_info, | |
2160 | .get = via_aamix_ctl_get, | |
2161 | .put = via_aamix_ctl_put, | |
2162 | }; | |
2163 | ||
2164 | static int via_auto_create_loopback_switch(struct hda_codec *codec) | |
2165 | { | |
2166 | struct via_spec *spec = codec->spec; | |
2167 | ||
4808d12d TI |
2168 | if (!spec->aa_mix_nid) |
2169 | return 0; /* no loopback switching available */ | |
2170 | if (!(spec->out_mix_path.depth || spec->hp_mix_path.depth || | |
2171 | spec->speaker_path.depth)) | |
3214b966 TI |
2172 | return 0; /* no loopback switching available */ |
2173 | if (!via_clone_control(spec, &via_aamix_ctl_enum)) | |
2174 | return -ENOMEM; | |
4a918ffe TI |
2175 | return 0; |
2176 | } | |
2177 | ||
a766d0d7 TI |
2178 | /* look for ADCs */ |
2179 | static int via_fill_adcs(struct hda_codec *codec) | |
2180 | { | |
2181 | struct via_spec *spec = codec->spec; | |
2182 | hda_nid_t nid = codec->start_nid; | |
2183 | int i; | |
2184 | ||
2185 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
2186 | unsigned int wcaps = get_wcaps(codec, nid); | |
2187 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | |
2188 | continue; | |
2189 | if (wcaps & AC_WCAP_DIGITAL) | |
2190 | continue; | |
2191 | if (!(wcaps & AC_WCAP_CONN_LIST)) | |
2192 | continue; | |
2193 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) | |
2194 | return -ENOMEM; | |
2195 | spec->adc_nids[spec->num_adc_nids++] = nid; | |
2196 | } | |
2197 | return 0; | |
2198 | } | |
2199 | ||
a86a88ea TI |
2200 | /* input-src control */ |
2201 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, | |
2202 | struct snd_ctl_elem_info *uinfo) | |
2203 | { | |
2204 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2205 | struct via_spec *spec = codec->spec; | |
2206 | ||
2207 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
2208 | uinfo->count = 1; | |
2209 | uinfo->value.enumerated.items = spec->num_inputs; | |
2210 | if (uinfo->value.enumerated.item >= spec->num_inputs) | |
2211 | uinfo->value.enumerated.item = spec->num_inputs - 1; | |
2212 | strcpy(uinfo->value.enumerated.name, | |
2213 | spec->inputs[uinfo->value.enumerated.item].label); | |
2214 | return 0; | |
2215 | } | |
2216 | ||
2217 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, | |
2218 | struct snd_ctl_elem_value *ucontrol) | |
2219 | { | |
2220 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2221 | struct via_spec *spec = codec->spec; | |
2222 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
2223 | ||
2224 | ucontrol->value.enumerated.item[0] = spec->cur_mux[idx]; | |
2225 | return 0; | |
2226 | } | |
2227 | ||
2228 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | |
2229 | struct snd_ctl_elem_value *ucontrol) | |
2230 | { | |
2231 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2232 | struct via_spec *spec = codec->spec; | |
2233 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
2234 | hda_nid_t mux; | |
2235 | int cur; | |
2236 | ||
2237 | cur = ucontrol->value.enumerated.item[0]; | |
2238 | if (cur < 0 || cur >= spec->num_inputs) | |
2239 | return -EINVAL; | |
2240 | if (spec->cur_mux[idx] == cur) | |
2241 | return 0; | |
2242 | spec->cur_mux[idx] = cur; | |
2243 | if (spec->dyn_adc_switch) { | |
2244 | int adc_idx = spec->inputs[cur].adc_idx; | |
2245 | mux = spec->mux_nids[adc_idx]; | |
2246 | via_dyn_adc_pcm_resetup(codec, cur); | |
2247 | } else { | |
2248 | mux = spec->mux_nids[idx]; | |
2249 | if (snd_BUG_ON(!mux)) | |
2250 | return -EINVAL; | |
2251 | } | |
2252 | ||
2253 | if (mux) { | |
2254 | /* switch to D0 beofre change index */ | |
054d867e | 2255 | update_power_state(codec, mux, AC_PWRST_D0); |
a86a88ea TI |
2256 | snd_hda_codec_write(codec, mux, 0, |
2257 | AC_VERB_SET_CONNECT_SEL, | |
2258 | spec->inputs[cur].mux_idx); | |
2259 | } | |
2260 | ||
2261 | /* update jack power state */ | |
2262 | set_widgets_power_state(codec); | |
2263 | return 0; | |
2264 | } | |
a766d0d7 | 2265 | |
d7a99cce TI |
2266 | static const struct snd_kcontrol_new via_input_src_ctl = { |
2267 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2268 | /* The multiple "Capture Source" controls confuse alsamixer | |
2269 | * So call somewhat different.. | |
2270 | */ | |
2271 | /* .name = "Capture Source", */ | |
2272 | .name = "Input Source", | |
2273 | .info = via_mux_enum_info, | |
2274 | .get = via_mux_enum_get, | |
2275 | .put = via_mux_enum_put, | |
2276 | }; | |
2277 | ||
a86a88ea TI |
2278 | static int create_input_src_ctls(struct hda_codec *codec, int count) |
2279 | { | |
2280 | struct via_spec *spec = codec->spec; | |
2281 | struct snd_kcontrol_new *knew; | |
2282 | ||
2283 | if (spec->num_inputs <= 1 || !count) | |
2284 | return 0; /* no need for single src */ | |
2285 | ||
2286 | knew = via_clone_control(spec, &via_input_src_ctl); | |
2287 | if (!knew) | |
2288 | return -ENOMEM; | |
2289 | knew->count = count; | |
2290 | return 0; | |
2291 | } | |
2292 | ||
2293 | /* add the powersave loopback-list entry */ | |
13af8e77 TI |
2294 | static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) |
2295 | { | |
2296 | struct hda_amp_list *list; | |
2297 | ||
2298 | if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1) | |
2299 | return; | |
2300 | list = spec->loopback_list + spec->num_loopbacks; | |
2301 | list->nid = mix; | |
2302 | list->dir = HDA_INPUT; | |
2303 | list->idx = idx; | |
2304 | spec->num_loopbacks++; | |
2305 | spec->loopback.amplist = spec->loopback_list; | |
2306 | } | |
13af8e77 | 2307 | |
a86a88ea | 2308 | static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src, |
8d087c76 | 2309 | hda_nid_t dst) |
a86a88ea | 2310 | { |
8d087c76 | 2311 | return snd_hda_get_conn_index(codec, src, dst, 1) >= 0; |
a86a88ea TI |
2312 | } |
2313 | ||
2314 | /* add the input-route to the given pin */ | |
2315 | static bool add_input_route(struct hda_codec *codec, hda_nid_t pin) | |
c577b8a1 | 2316 | { |
10a20af7 | 2317 | struct via_spec *spec = codec->spec; |
a86a88ea TI |
2318 | int c, idx; |
2319 | ||
2320 | spec->inputs[spec->num_inputs].adc_idx = -1; | |
2321 | spec->inputs[spec->num_inputs].pin = pin; | |
2322 | for (c = 0; c < spec->num_adc_nids; c++) { | |
2323 | if (spec->mux_nids[c]) { | |
2324 | idx = get_connection_index(codec, spec->mux_nids[c], | |
2325 | pin); | |
2326 | if (idx < 0) | |
2327 | continue; | |
2328 | spec->inputs[spec->num_inputs].mux_idx = idx; | |
2329 | } else { | |
8d087c76 | 2330 | if (!is_reachable_nid(codec, spec->adc_nids[c], pin)) |
a86a88ea TI |
2331 | continue; |
2332 | } | |
2333 | spec->inputs[spec->num_inputs].adc_idx = c; | |
2334 | /* Can primary ADC satisfy all inputs? */ | |
2335 | if (!spec->dyn_adc_switch && | |
2336 | spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) { | |
2337 | snd_printd(KERN_INFO | |
2338 | "via: dynamic ADC switching enabled\n"); | |
2339 | spec->dyn_adc_switch = 1; | |
2340 | } | |
2341 | return true; | |
2342 | } | |
2343 | return false; | |
2344 | } | |
2345 | ||
2346 | static int get_mux_nids(struct hda_codec *codec); | |
2347 | ||
2348 | /* parse input-routes; fill ADCs, MUXs and input-src entries */ | |
2349 | static int parse_analog_inputs(struct hda_codec *codec) | |
2350 | { | |
2351 | struct via_spec *spec = codec->spec; | |
2352 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
2353 | int i, err; | |
a766d0d7 TI |
2354 | |
2355 | err = via_fill_adcs(codec); | |
2356 | if (err < 0) | |
2357 | return err; | |
2358 | err = get_mux_nids(codec); | |
2359 | if (err < 0) | |
2360 | return err; | |
c577b8a1 | 2361 | |
a86a88ea TI |
2362 | /* fill all input-routes */ |
2363 | for (i = 0; i < cfg->num_inputs; i++) { | |
2364 | if (add_input_route(codec, cfg->inputs[i].pin)) | |
2365 | spec->inputs[spec->num_inputs++].label = | |
2366 | hda_get_autocfg_input_label(codec, cfg, i); | |
f3268512 | 2367 | } |
c577b8a1 | 2368 | |
a86a88ea TI |
2369 | /* check for internal loopback recording */ |
2370 | if (spec->aa_mix_nid && | |
2371 | add_input_route(codec, spec->aa_mix_nid)) | |
2372 | spec->inputs[spec->num_inputs++].label = "Stereo Mixer"; | |
2373 | ||
2374 | return 0; | |
2375 | } | |
2376 | ||
2377 | /* create analog-loopback volume/switch controls */ | |
2378 | static int create_loopback_ctls(struct hda_codec *codec) | |
2379 | { | |
2380 | struct via_spec *spec = codec->spec; | |
2381 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
2382 | const char *prev_label = NULL; | |
2383 | int type_idx = 0; | |
2384 | int i, j, err, idx; | |
2385 | ||
2386 | if (!spec->aa_mix_nid) | |
2387 | return 0; | |
2388 | ||
7b315bb4 | 2389 | for (i = 0; i < cfg->num_inputs; i++) { |
a86a88ea TI |
2390 | hda_nid_t pin = cfg->inputs[i].pin; |
2391 | const char *label = hda_get_autocfg_input_label(codec, cfg, i); | |
2392 | ||
1e11cae1 | 2393 | if (prev_label && !strcmp(label, prev_label)) |
7b315bb4 TI |
2394 | type_idx++; |
2395 | else | |
2396 | type_idx = 0; | |
1e11cae1 | 2397 | prev_label = label; |
a86a88ea TI |
2398 | idx = get_connection_index(codec, spec->aa_mix_nid, pin); |
2399 | if (idx >= 0) { | |
16922281 | 2400 | err = via_new_analog_input(spec, label, type_idx, |
a86a88ea | 2401 | idx, spec->aa_mix_nid); |
13af8e77 TI |
2402 | if (err < 0) |
2403 | return err; | |
a86a88ea | 2404 | add_loopback_list(spec, spec->aa_mix_nid, idx); |
13af8e77 | 2405 | } |
e3d7a143 TI |
2406 | |
2407 | /* remember the label for smart51 control */ | |
2408 | for (j = 0; j < spec->smart51_nums; j++) { | |
a86a88ea | 2409 | if (spec->smart51_pins[j] == pin) { |
e3d7a143 TI |
2410 | spec->smart51_idxs[j] = idx; |
2411 | spec->smart51_labels[j] = label; | |
2412 | break; | |
2413 | } | |
2414 | } | |
c577b8a1 | 2415 | } |
a86a88ea TI |
2416 | return 0; |
2417 | } | |
2418 | ||
2419 | /* create mic-boost controls (if present) */ | |
2420 | static int create_mic_boost_ctls(struct hda_codec *codec) | |
2421 | { | |
2422 | struct via_spec *spec = codec->spec; | |
2423 | const struct auto_pin_cfg *cfg = &spec->autocfg; | |
8d8bbc6f TI |
2424 | const char *prev_label = NULL; |
2425 | int type_idx = 0; | |
a86a88ea TI |
2426 | int i, err; |
2427 | ||
2428 | for (i = 0; i < cfg->num_inputs; i++) { | |
2429 | hda_nid_t pin = cfg->inputs[i].pin; | |
2430 | unsigned int caps; | |
2431 | const char *label; | |
2432 | char name[32]; | |
2433 | ||
2434 | if (cfg->inputs[i].type != AUTO_PIN_MIC) | |
2435 | continue; | |
2436 | caps = query_amp_caps(codec, pin, HDA_INPUT); | |
2437 | if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) | |
2438 | continue; | |
2439 | label = hda_get_autocfg_input_label(codec, cfg, i); | |
8d8bbc6f TI |
2440 | if (prev_label && !strcmp(label, prev_label)) |
2441 | type_idx++; | |
2442 | else | |
2443 | type_idx = 0; | |
2444 | prev_label = label; | |
a86a88ea | 2445 | snprintf(name, sizeof(name), "%s Boost Volume", label); |
8d8bbc6f | 2446 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
a86a88ea TI |
2447 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); |
2448 | if (err < 0) | |
2449 | return err; | |
2450 | } | |
2451 | return 0; | |
2452 | } | |
2453 | ||
2454 | /* create capture and input-src controls for multiple streams */ | |
2455 | static int create_multi_adc_ctls(struct hda_codec *codec) | |
2456 | { | |
2457 | struct via_spec *spec = codec->spec; | |
2458 | int i, err; | |
d7a99cce TI |
2459 | |
2460 | /* create capture mixer elements */ | |
2461 | for (i = 0; i < spec->num_adc_nids; i++) { | |
2462 | hda_nid_t adc = spec->adc_nids[i]; | |
2463 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2464 | "Capture Volume", i, | |
2465 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, | |
2466 | HDA_INPUT)); | |
2467 | if (err < 0) | |
2468 | return err; | |
2469 | err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2470 | "Capture Switch", i, | |
2471 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, | |
2472 | HDA_INPUT)); | |
2473 | if (err < 0) | |
2474 | return err; | |
2475 | } | |
2476 | ||
2477 | /* input-source control */ | |
2478 | for (i = 0; i < spec->num_adc_nids; i++) | |
2479 | if (!spec->mux_nids[i]) | |
2480 | break; | |
a86a88ea TI |
2481 | err = create_input_src_ctls(codec, i); |
2482 | if (err < 0) | |
2483 | return err; | |
2484 | return 0; | |
2485 | } | |
d7a99cce | 2486 | |
a86a88ea TI |
2487 | /* bind capture volume/switch */ |
2488 | static struct snd_kcontrol_new via_bind_cap_vol_ctl = | |
2489 | HDA_BIND_VOL("Capture Volume", 0); | |
2490 | static struct snd_kcontrol_new via_bind_cap_sw_ctl = | |
2491 | HDA_BIND_SW("Capture Switch", 0); | |
d7a99cce | 2492 | |
a86a88ea TI |
2493 | static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret, |
2494 | struct hda_ctl_ops *ops) | |
2495 | { | |
2496 | struct hda_bind_ctls *ctl; | |
2497 | int i; | |
d7a99cce | 2498 | |
a86a88ea TI |
2499 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL); |
2500 | if (!ctl) | |
2501 | return -ENOMEM; | |
2502 | ctl->ops = ops; | |
2503 | for (i = 0; i < spec->num_adc_nids; i++) | |
2504 | ctl->values[i] = | |
2505 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT); | |
2506 | *ctl_ret = ctl; | |
2507 | return 0; | |
2508 | } | |
2509 | ||
2510 | /* create capture and input-src controls for dynamic ADC-switch case */ | |
2511 | static int create_dyn_adc_ctls(struct hda_codec *codec) | |
2512 | { | |
2513 | struct via_spec *spec = codec->spec; | |
2514 | struct snd_kcontrol_new *knew; | |
2515 | int err; | |
2516 | ||
2517 | /* set up the bind capture ctls */ | |
2518 | err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol); | |
2519 | if (err < 0) | |
2520 | return err; | |
2521 | err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw); | |
2522 | if (err < 0) | |
2523 | return err; | |
2524 | ||
2525 | /* create capture mixer elements */ | |
2526 | knew = via_clone_control(spec, &via_bind_cap_vol_ctl); | |
2527 | if (!knew) | |
2528 | return -ENOMEM; | |
2529 | knew->private_value = (long)spec->bind_cap_vol; | |
2530 | ||
2531 | knew = via_clone_control(spec, &via_bind_cap_sw_ctl); | |
2532 | if (!knew) | |
2533 | return -ENOMEM; | |
2534 | knew->private_value = (long)spec->bind_cap_sw; | |
2535 | ||
2536 | /* input-source control */ | |
2537 | err = create_input_src_ctls(codec, 1); | |
2538 | if (err < 0) | |
2539 | return err; | |
2540 | return 0; | |
2541 | } | |
2542 | ||
2543 | /* parse and create capture-related stuff */ | |
2544 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec) | |
2545 | { | |
2546 | struct via_spec *spec = codec->spec; | |
2547 | int err; | |
2548 | ||
2549 | err = parse_analog_inputs(codec); | |
2550 | if (err < 0) | |
2551 | return err; | |
2552 | if (spec->dyn_adc_switch) | |
2553 | err = create_dyn_adc_ctls(codec); | |
2554 | else | |
2555 | err = create_multi_adc_ctls(codec); | |
2556 | if (err < 0) | |
2557 | return err; | |
2558 | err = create_loopback_ctls(codec); | |
2559 | if (err < 0) | |
2560 | return err; | |
2561 | err = create_mic_boost_ctls(codec); | |
2562 | if (err < 0) | |
2563 | return err; | |
c577b8a1 JC |
2564 | return 0; |
2565 | } | |
2566 | ||
76d9b0dd HW |
2567 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
2568 | { | |
2569 | unsigned int def_conf; | |
2570 | unsigned char seqassoc; | |
2571 | ||
2f334f92 | 2572 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
76d9b0dd HW |
2573 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
2574 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); | |
82ef9e45 LW |
2575 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
2576 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { | |
2577 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); | |
2578 | snd_hda_codec_set_pincfg(codec, nid, def_conf); | |
76d9b0dd HW |
2579 | } |
2580 | ||
2581 | return; | |
2582 | } | |
2583 | ||
e06e5a29 | 2584 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
1f2e99fe LW |
2585 | struct snd_ctl_elem_value *ucontrol) |
2586 | { | |
2587 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2588 | struct via_spec *spec = codec->spec; | |
2589 | ||
2590 | if (spec->codec_type != VT1708) | |
2591 | return 0; | |
e06e5a29 | 2592 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
1f2e99fe LW |
2593 | return 0; |
2594 | } | |
2595 | ||
e06e5a29 | 2596 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
1f2e99fe LW |
2597 | struct snd_ctl_elem_value *ucontrol) |
2598 | { | |
2599 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
2600 | struct via_spec *spec = codec->spec; | |
187d333e | 2601 | int val; |
1f2e99fe LW |
2602 | |
2603 | if (spec->codec_type != VT1708) | |
2604 | return 0; | |
187d333e TI |
2605 | val = !!ucontrol->value.integer.value[0]; |
2606 | if (spec->vt1708_jack_detect == val) | |
2607 | return 0; | |
2608 | spec->vt1708_jack_detect = val; | |
2609 | if (spec->vt1708_jack_detect && | |
2610 | snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) { | |
1f2e99fe LW |
2611 | mute_aa_path(codec, 1); |
2612 | notify_aa_path_ctls(codec); | |
2613 | } | |
187d333e TI |
2614 | via_hp_automute(codec); |
2615 | vt1708_update_hp_work(spec); | |
2616 | return 1; | |
1f2e99fe LW |
2617 | } |
2618 | ||
e06e5a29 TI |
2619 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
2620 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2621 | .name = "Jack Detect", | |
2622 | .count = 1, | |
2623 | .info = snd_ctl_boolean_mono_info, | |
2624 | .get = vt1708_jack_detect_get, | |
2625 | .put = vt1708_jack_detect_put, | |
1f2e99fe LW |
2626 | }; |
2627 | ||
12daef65 TI |
2628 | static void fill_dig_outs(struct hda_codec *codec); |
2629 | static void fill_dig_in(struct hda_codec *codec); | |
2630 | ||
2631 | static int via_parse_auto_config(struct hda_codec *codec) | |
c577b8a1 JC |
2632 | { |
2633 | struct via_spec *spec = codec->spec; | |
2634 | int err; | |
2635 | ||
2636 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
c577b8a1 JC |
2637 | if (err < 0) |
2638 | return err; | |
2639 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
7f0df88c | 2640 | return -EINVAL; |
c577b8a1 | 2641 | |
4a79616d | 2642 | err = via_auto_create_multi_out_ctls(codec); |
c577b8a1 JC |
2643 | if (err < 0) |
2644 | return err; | |
4a79616d | 2645 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
4a918ffe TI |
2646 | if (err < 0) |
2647 | return err; | |
2648 | err = via_auto_create_speaker_ctls(codec); | |
3214b966 TI |
2649 | if (err < 0) |
2650 | return err; | |
2651 | err = via_auto_create_loopback_switch(codec); | |
c577b8a1 JC |
2652 | if (err < 0) |
2653 | return err; | |
a86a88ea | 2654 | err = via_auto_create_analog_input_ctls(codec); |
1f2e99fe LW |
2655 | if (err < 0) |
2656 | return err; | |
c577b8a1 JC |
2657 | |
2658 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2659 | ||
12daef65 TI |
2660 | fill_dig_outs(codec); |
2661 | fill_dig_in(codec); | |
c577b8a1 | 2662 | |
603c4019 TI |
2663 | if (spec->kctls.list) |
2664 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 2665 | |
c577b8a1 | 2666 | |
3214b966 | 2667 | if (spec->hp_dac_nid && spec->hp_mix_path.depth) { |
ece8d043 TI |
2668 | err = via_hp_build(codec); |
2669 | if (err < 0) | |
2670 | return err; | |
2671 | } | |
c577b8a1 | 2672 | |
f4a7828b TI |
2673 | err = via_smart51_build(codec); |
2674 | if (err < 0) | |
2675 | return err; | |
2676 | ||
5d41762a TI |
2677 | /* assign slave outs */ |
2678 | if (spec->slave_dig_outs[0]) | |
2679 | codec->slave_dig_outs = spec->slave_dig_outs; | |
2680 | ||
c577b8a1 JC |
2681 | return 1; |
2682 | } | |
2683 | ||
5d41762a TI |
2684 | static void via_auto_init_dig_outs(struct hda_codec *codec) |
2685 | { | |
2686 | struct via_spec *spec = codec->spec; | |
2687 | if (spec->multiout.dig_out_nid) | |
2688 | init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT); | |
2689 | if (spec->slave_dig_outs[0]) | |
2690 | init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT); | |
2691 | } | |
2692 | ||
2693 | static void via_auto_init_dig_in(struct hda_codec *codec) | |
c577b8a1 | 2694 | { |
25eaba2f | 2695 | struct via_spec *spec = codec->spec; |
5d41762a TI |
2696 | if (!spec->dig_in_nid) |
2697 | return; | |
cdd03ced | 2698 | snd_hda_set_pin_ctl(codec, spec->autocfg.dig_in_pin, PIN_IN); |
5d41762a TI |
2699 | } |
2700 | ||
4e2d16d3 DH |
2701 | static void via_jack_output_event(struct hda_codec *codec, struct hda_jack_tbl *tbl) |
2702 | { | |
2703 | set_widgets_power_state(codec); | |
2704 | via_hp_automute(codec); | |
2705 | } | |
2706 | ||
2707 | static void via_jack_powerstate_event(struct hda_codec *codec, struct hda_jack_tbl *tbl) | |
2708 | { | |
2709 | set_widgets_power_state(codec); | |
2710 | } | |
2711 | ||
4a918ffe TI |
2712 | /* initialize the unsolicited events */ |
2713 | static void via_auto_init_unsol_event(struct hda_codec *codec) | |
2714 | { | |
2715 | struct via_spec *spec = codec->spec; | |
2716 | struct auto_pin_cfg *cfg = &spec->autocfg; | |
2717 | unsigned int ev; | |
2718 | int i; | |
4e2d16d3 | 2719 | hda_jack_callback cb; |
4a918ffe TI |
2720 | |
2721 | if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0])) | |
4e2d16d3 DH |
2722 | snd_hda_jack_detect_enable_callback(codec, cfg->hp_pins[0], |
2723 | VIA_HP_EVENT | VIA_JACK_EVENT, | |
2724 | via_jack_output_event); | |
4a918ffe TI |
2725 | |
2726 | if (cfg->speaker_pins[0]) | |
2727 | ev = VIA_LINE_EVENT; | |
2728 | else | |
2729 | ev = 0; | |
4e2d16d3 DH |
2730 | cb = ev ? via_jack_output_event : via_jack_powerstate_event; |
2731 | ||
4a918ffe TI |
2732 | for (i = 0; i < cfg->line_outs; i++) { |
2733 | if (cfg->line_out_pins[i] && | |
2734 | is_jack_detectable(codec, cfg->line_out_pins[i])) | |
4e2d16d3 DH |
2735 | snd_hda_jack_detect_enable_callback(codec, cfg->line_out_pins[i], |
2736 | ev | VIA_JACK_EVENT, cb); | |
4a918ffe TI |
2737 | } |
2738 | ||
2739 | for (i = 0; i < cfg->num_inputs; i++) { | |
2740 | if (is_jack_detectable(codec, cfg->inputs[i].pin)) | |
4e2d16d3 DH |
2741 | snd_hda_jack_detect_enable_callback(codec, cfg->inputs[i].pin, |
2742 | VIA_JACK_EVENT, | |
2743 | via_jack_powerstate_event); | |
4a918ffe TI |
2744 | } |
2745 | } | |
2746 | ||
5d41762a TI |
2747 | static int via_init(struct hda_codec *codec) |
2748 | { | |
2749 | struct via_spec *spec = codec->spec; | |
2750 | int i; | |
2751 | ||
2752 | for (i = 0; i < spec->num_iverbs; i++) | |
2753 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
25eaba2f | 2754 | |
e9d010c2 TI |
2755 | /* init power states */ |
2756 | set_widgets_power_state(codec); | |
2757 | __analog_low_current_mode(codec, true); | |
2758 | ||
c577b8a1 JC |
2759 | via_auto_init_multi_out(codec); |
2760 | via_auto_init_hp_out(codec); | |
4a918ffe | 2761 | via_auto_init_speaker_out(codec); |
c577b8a1 | 2762 | via_auto_init_analog_input(codec); |
5d41762a TI |
2763 | via_auto_init_dig_outs(codec); |
2764 | via_auto_init_dig_in(codec); | |
11890956 | 2765 | |
4a918ffe TI |
2766 | via_auto_init_unsol_event(codec); |
2767 | ||
2768 | via_hp_automute(codec); | |
187d333e | 2769 | vt1708_update_hp_work(spec); |
25eaba2f | 2770 | |
c577b8a1 JC |
2771 | return 0; |
2772 | } | |
2773 | ||
1f2e99fe LW |
2774 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
2775 | { | |
2776 | struct via_spec *spec = container_of(work, struct via_spec, | |
2777 | vt1708_hp_work.work); | |
2778 | if (spec->codec_type != VT1708) | |
2779 | return; | |
1835a0f9 | 2780 | snd_hda_jack_set_dirty_all(spec->codec); |
1f2e99fe LW |
2781 | /* if jack state toggled */ |
2782 | if (spec->vt1708_hp_present | |
d56757ab | 2783 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
1f2e99fe LW |
2784 | spec->vt1708_hp_present ^= 1; |
2785 | via_hp_automute(spec->codec); | |
2786 | } | |
187d333e TI |
2787 | if (spec->vt1708_jack_detect) |
2788 | schedule_delayed_work(&spec->vt1708_hp_work, | |
2789 | msecs_to_jiffies(100)); | |
1f2e99fe LW |
2790 | } |
2791 | ||
337b9d02 TI |
2792 | static int get_mux_nids(struct hda_codec *codec) |
2793 | { | |
2794 | struct via_spec *spec = codec->spec; | |
2795 | hda_nid_t nid, conn[8]; | |
2796 | unsigned int type; | |
2797 | int i, n; | |
2798 | ||
2799 | for (i = 0; i < spec->num_adc_nids; i++) { | |
2800 | nid = spec->adc_nids[i]; | |
2801 | while (nid) { | |
a22d543a | 2802 | type = get_wcaps_type(get_wcaps(codec, nid)); |
1c55d521 TI |
2803 | if (type == AC_WID_PIN) |
2804 | break; | |
337b9d02 TI |
2805 | n = snd_hda_get_connections(codec, nid, conn, |
2806 | ARRAY_SIZE(conn)); | |
2807 | if (n <= 0) | |
2808 | break; | |
2809 | if (n > 1) { | |
2810 | spec->mux_nids[i] = nid; | |
2811 | break; | |
2812 | } | |
2813 | nid = conn[0]; | |
2814 | } | |
2815 | } | |
1c55d521 | 2816 | return 0; |
337b9d02 TI |
2817 | } |
2818 | ||
c577b8a1 JC |
2819 | static int patch_vt1708(struct hda_codec *codec) |
2820 | { | |
2821 | struct via_spec *spec; | |
2822 | int err; | |
2823 | ||
2824 | /* create a codec specific record */ | |
5b0cb1d8 | 2825 | spec = via_new_spec(codec); |
c577b8a1 JC |
2826 | if (spec == NULL) |
2827 | return -ENOMEM; | |
2828 | ||
620e2b28 TI |
2829 | spec->aa_mix_nid = 0x17; |
2830 | ||
12daef65 TI |
2831 | /* Add HP and CD pin config connect bit re-config action */ |
2832 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); | |
2833 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); | |
2834 | ||
c577b8a1 | 2835 | /* automatic parse from the BIOS config */ |
12daef65 | 2836 | err = via_parse_auto_config(codec); |
c577b8a1 JC |
2837 | if (err < 0) { |
2838 | via_free(codec); | |
2839 | return err; | |
c577b8a1 JC |
2840 | } |
2841 | ||
12daef65 TI |
2842 | /* add jack detect on/off control */ |
2843 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) | |
2844 | return -ENOMEM; | |
2845 | ||
bc9b5623 TI |
2846 | /* disable 32bit format on VT1708 */ |
2847 | if (codec->vendor_id == 0x11061708) | |
2848 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; | |
c577b8a1 | 2849 | |
e322a36d LW |
2850 | spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; |
2851 | ||
c577b8a1 JC |
2852 | codec->patch_ops = via_patch_ops; |
2853 | ||
1f2e99fe | 2854 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
c577b8a1 JC |
2855 | return 0; |
2856 | } | |
2857 | ||
ddd304d8 | 2858 | static int patch_vt1709(struct hda_codec *codec) |
c577b8a1 JC |
2859 | { |
2860 | struct via_spec *spec; | |
2861 | int err; | |
2862 | ||
2863 | /* create a codec specific record */ | |
5b0cb1d8 | 2864 | spec = via_new_spec(codec); |
c577b8a1 JC |
2865 | if (spec == NULL) |
2866 | return -ENOMEM; | |
2867 | ||
620e2b28 TI |
2868 | spec->aa_mix_nid = 0x18; |
2869 | ||
12daef65 | 2870 | err = via_parse_auto_config(codec); |
c577b8a1 JC |
2871 | if (err < 0) { |
2872 | via_free(codec); | |
2873 | return err; | |
c577b8a1 JC |
2874 | } |
2875 | ||
c577b8a1 JC |
2876 | codec->patch_ops = via_patch_ops; |
2877 | ||
f7278fd0 JC |
2878 | return 0; |
2879 | } | |
2880 | ||
3e95b9ab LW |
2881 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
2882 | { | |
2883 | struct via_spec *spec = codec->spec; | |
2884 | int imux_is_smixer; | |
2885 | unsigned int parm; | |
2886 | int is_8ch = 0; | |
bc92df7f LW |
2887 | if ((spec->codec_type != VT1708B_4CH) && |
2888 | (codec->vendor_id != 0x11064397)) | |
3e95b9ab LW |
2889 | is_8ch = 1; |
2890 | ||
2891 | /* SW0 (17h) = stereo mixer */ | |
2892 | imux_is_smixer = | |
2893 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) | |
2894 | == ((spec->codec_type == VT1708S) ? 5 : 0)); | |
2895 | /* inputs */ | |
2896 | /* PW 1/2/5 (1ah/1bh/1eh) */ | |
2897 | parm = AC_PWRST_D3; | |
2898 | set_pin_power_state(codec, 0x1a, &parm); | |
2899 | set_pin_power_state(codec, 0x1b, &parm); | |
2900 | set_pin_power_state(codec, 0x1e, &parm); | |
2901 | if (imux_is_smixer) | |
2902 | parm = AC_PWRST_D0; | |
2903 | /* SW0 (17h), AIW 0/1 (13h/14h) */ | |
054d867e TI |
2904 | update_power_state(codec, 0x17, parm); |
2905 | update_power_state(codec, 0x13, parm); | |
2906 | update_power_state(codec, 0x14, parm); | |
3e95b9ab LW |
2907 | |
2908 | /* outputs */ | |
2909 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | |
2910 | parm = AC_PWRST_D3; | |
2911 | set_pin_power_state(codec, 0x19, &parm); | |
2912 | if (spec->smart51_enabled) | |
2913 | set_pin_power_state(codec, 0x1b, &parm); | |
054d867e TI |
2914 | update_power_state(codec, 0x18, parm); |
2915 | update_power_state(codec, 0x11, parm); | |
3e95b9ab LW |
2916 | |
2917 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ | |
2918 | if (is_8ch) { | |
2919 | parm = AC_PWRST_D3; | |
2920 | set_pin_power_state(codec, 0x22, &parm); | |
2921 | if (spec->smart51_enabled) | |
2922 | set_pin_power_state(codec, 0x1a, &parm); | |
054d867e TI |
2923 | update_power_state(codec, 0x26, parm); |
2924 | update_power_state(codec, 0x24, parm); | |
bc92df7f LW |
2925 | } else if (codec->vendor_id == 0x11064397) { |
2926 | /* PW7(23h), SW2(27h), AOW2(25h) */ | |
2927 | parm = AC_PWRST_D3; | |
2928 | set_pin_power_state(codec, 0x23, &parm); | |
2929 | if (spec->smart51_enabled) | |
2930 | set_pin_power_state(codec, 0x1a, &parm); | |
054d867e TI |
2931 | update_power_state(codec, 0x27, parm); |
2932 | update_power_state(codec, 0x25, parm); | |
3e95b9ab LW |
2933 | } |
2934 | ||
2935 | /* PW 3/4/7 (1ch/1dh/23h) */ | |
2936 | parm = AC_PWRST_D3; | |
2937 | /* force to D0 for internal Speaker */ | |
2938 | set_pin_power_state(codec, 0x1c, &parm); | |
2939 | set_pin_power_state(codec, 0x1d, &parm); | |
2940 | if (is_8ch) | |
2941 | set_pin_power_state(codec, 0x23, &parm); | |
2942 | ||
2943 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ | |
054d867e TI |
2944 | update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm); |
2945 | update_power_state(codec, 0x10, parm); | |
3e95b9ab | 2946 | if (is_8ch) { |
054d867e TI |
2947 | update_power_state(codec, 0x25, parm); |
2948 | update_power_state(codec, 0x27, parm); | |
bc92df7f | 2949 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
054d867e | 2950 | update_power_state(codec, 0x25, parm); |
3e95b9ab LW |
2951 | } |
2952 | ||
518bf3ba | 2953 | static int patch_vt1708S(struct hda_codec *codec); |
ddd304d8 | 2954 | static int patch_vt1708B(struct hda_codec *codec) |
f7278fd0 JC |
2955 | { |
2956 | struct via_spec *spec; | |
2957 | int err; | |
2958 | ||
518bf3ba LW |
2959 | if (get_codec_type(codec) == VT1708BCE) |
2960 | return patch_vt1708S(codec); | |
ddd304d8 | 2961 | |
f7278fd0 | 2962 | /* create a codec specific record */ |
5b0cb1d8 | 2963 | spec = via_new_spec(codec); |
f7278fd0 JC |
2964 | if (spec == NULL) |
2965 | return -ENOMEM; | |
2966 | ||
620e2b28 TI |
2967 | spec->aa_mix_nid = 0x16; |
2968 | ||
f7278fd0 | 2969 | /* automatic parse from the BIOS config */ |
12daef65 | 2970 | err = via_parse_auto_config(codec); |
f7278fd0 JC |
2971 | if (err < 0) { |
2972 | via_free(codec); | |
2973 | return err; | |
f7278fd0 JC |
2974 | } |
2975 | ||
f7278fd0 JC |
2976 | codec->patch_ops = via_patch_ops; |
2977 | ||
3e95b9ab LW |
2978 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
2979 | ||
f7278fd0 JC |
2980 | return 0; |
2981 | } | |
2982 | ||
d949cac1 | 2983 | /* Patch for VT1708S */ |
096a8854 | 2984 | static const struct hda_verb vt1708S_init_verbs[] = { |
d7426329 HW |
2985 | /* Enable Mic Boost Volume backdoor */ |
2986 | {0x1, 0xf98, 0x1}, | |
bc7e7e5c LW |
2987 | /* don't bybass mixer */ |
2988 | {0x1, 0xf88, 0xc0}, | |
d949cac1 HW |
2989 | { } |
2990 | }; | |
2991 | ||
4a79616d TI |
2992 | /* fill out digital output widgets; one for master and one for slave outputs */ |
2993 | static void fill_dig_outs(struct hda_codec *codec) | |
d949cac1 | 2994 | { |
4a79616d | 2995 | struct via_spec *spec = codec->spec; |
d949cac1 | 2996 | int i; |
d949cac1 | 2997 | |
4a79616d TI |
2998 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
2999 | hda_nid_t nid; | |
3000 | int conn; | |
9da29271 TI |
3001 | |
3002 | nid = spec->autocfg.dig_out_pins[i]; | |
3003 | if (!nid) | |
3004 | continue; | |
3005 | conn = snd_hda_get_connections(codec, nid, &nid, 1); | |
3006 | if (conn < 1) | |
3007 | continue; | |
3008 | if (!spec->multiout.dig_out_nid) | |
3009 | spec->multiout.dig_out_nid = nid; | |
3010 | else { | |
3011 | spec->slave_dig_outs[0] = nid; | |
3012 | break; /* at most two dig outs */ | |
3013 | } | |
3014 | } | |
3015 | } | |
3016 | ||
12daef65 | 3017 | static void fill_dig_in(struct hda_codec *codec) |
d949cac1 HW |
3018 | { |
3019 | struct via_spec *spec = codec->spec; | |
12daef65 TI |
3020 | hda_nid_t dig_nid; |
3021 | int i, err; | |
d949cac1 | 3022 | |
12daef65 TI |
3023 | if (!spec->autocfg.dig_in_pin) |
3024 | return; | |
f4a7828b | 3025 | |
12daef65 TI |
3026 | dig_nid = codec->start_nid; |
3027 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { | |
3028 | unsigned int wcaps = get_wcaps(codec, dig_nid); | |
3029 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) | |
3030 | continue; | |
3031 | if (!(wcaps & AC_WCAP_DIGITAL)) | |
3032 | continue; | |
3033 | if (!(wcaps & AC_WCAP_CONN_LIST)) | |
3034 | continue; | |
3035 | err = get_connection_index(codec, dig_nid, | |
3036 | spec->autocfg.dig_in_pin); | |
3037 | if (err >= 0) { | |
3038 | spec->dig_in_nid = dig_nid; | |
3039 | break; | |
3040 | } | |
3041 | } | |
d949cac1 HW |
3042 | } |
3043 | ||
6369bcfc LW |
3044 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
3045 | int offset, int num_steps, int step_size) | |
3046 | { | |
3047 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, | |
3048 | (offset << AC_AMPCAP_OFFSET_SHIFT) | | |
3049 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
3050 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
3051 | (0 << AC_AMPCAP_MUTE_SHIFT)); | |
3052 | } | |
3053 | ||
d949cac1 HW |
3054 | static int patch_vt1708S(struct hda_codec *codec) |
3055 | { | |
3056 | struct via_spec *spec; | |
3057 | int err; | |
3058 | ||
3059 | /* create a codec specific record */ | |
5b0cb1d8 | 3060 | spec = via_new_spec(codec); |
d949cac1 HW |
3061 | if (spec == NULL) |
3062 | return -ENOMEM; | |
3063 | ||
620e2b28 | 3064 | spec->aa_mix_nid = 0x16; |
d7a99cce TI |
3065 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
3066 | override_mic_boost(codec, 0x1e, 0, 3, 40); | |
620e2b28 | 3067 | |
d949cac1 | 3068 | /* automatic parse from the BIOS config */ |
12daef65 | 3069 | err = via_parse_auto_config(codec); |
d949cac1 HW |
3070 | if (err < 0) { |
3071 | via_free(codec); | |
3072 | return err; | |
d949cac1 HW |
3073 | } |
3074 | ||
096a8854 | 3075 | spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; |
d949cac1 | 3076 | |
d949cac1 HW |
3077 | codec->patch_ops = via_patch_ops; |
3078 | ||
518bf3ba LW |
3079 | /* correct names for VT1708BCE */ |
3080 | if (get_codec_type(codec) == VT1708BCE) { | |
3081 | kfree(codec->chip_name); | |
3082 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); | |
3083 | snprintf(codec->bus->card->mixername, | |
3084 | sizeof(codec->bus->card->mixername), | |
3085 | "%s %s", codec->vendor_name, codec->chip_name); | |
970f630f | 3086 | } |
bc92df7f LW |
3087 | /* correct names for VT1705 */ |
3088 | if (codec->vendor_id == 0x11064397) { | |
3089 | kfree(codec->chip_name); | |
3090 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); | |
3091 | snprintf(codec->bus->card->mixername, | |
3092 | sizeof(codec->bus->card->mixername), | |
3093 | "%s %s", codec->vendor_name, codec->chip_name); | |
3094 | } | |
3e95b9ab | 3095 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
d949cac1 HW |
3096 | return 0; |
3097 | } | |
3098 | ||
3099 | /* Patch for VT1702 */ | |
3100 | ||
096a8854 | 3101 | static const struct hda_verb vt1702_init_verbs[] = { |
bc7e7e5c LW |
3102 | /* mixer enable */ |
3103 | {0x1, 0xF88, 0x3}, | |
3104 | /* GPIO 0~2 */ | |
3105 | {0x1, 0xF82, 0x3F}, | |
d949cac1 HW |
3106 | { } |
3107 | }; | |
3108 | ||
3e95b9ab LW |
3109 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
3110 | { | |
3111 | int imux_is_smixer = | |
3112 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
3113 | unsigned int parm; | |
3114 | /* inputs */ | |
3115 | /* PW 1/2/5 (14h/15h/18h) */ | |
3116 | parm = AC_PWRST_D3; | |
3117 | set_pin_power_state(codec, 0x14, &parm); | |
3118 | set_pin_power_state(codec, 0x15, &parm); | |
3119 | set_pin_power_state(codec, 0x18, &parm); | |
3120 | if (imux_is_smixer) | |
3121 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ | |
3122 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ | |
054d867e TI |
3123 | update_power_state(codec, 0x13, parm); |
3124 | update_power_state(codec, 0x12, parm); | |
3125 | update_power_state(codec, 0x1f, parm); | |
3126 | update_power_state(codec, 0x20, parm); | |
3e95b9ab LW |
3127 | |
3128 | /* outputs */ | |
3129 | /* PW 3/4 (16h/17h) */ | |
3130 | parm = AC_PWRST_D3; | |
3131 | set_pin_power_state(codec, 0x17, &parm); | |
3132 | set_pin_power_state(codec, 0x16, &parm); | |
3133 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ | |
054d867e TI |
3134 | update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm); |
3135 | update_power_state(codec, 0x10, parm); | |
3136 | update_power_state(codec, 0x1d, parm); | |
3e95b9ab LW |
3137 | } |
3138 | ||
d949cac1 HW |
3139 | static int patch_vt1702(struct hda_codec *codec) |
3140 | { | |
3141 | struct via_spec *spec; | |
3142 | int err; | |
d949cac1 HW |
3143 | |
3144 | /* create a codec specific record */ | |
5b0cb1d8 | 3145 | spec = via_new_spec(codec); |
d949cac1 HW |
3146 | if (spec == NULL) |
3147 | return -ENOMEM; | |
3148 | ||
620e2b28 TI |
3149 | spec->aa_mix_nid = 0x1a; |
3150 | ||
12daef65 TI |
3151 | /* limit AA path volume to 0 dB */ |
3152 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, | |
3153 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | | |
3154 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | | |
3155 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | | |
3156 | (1 << AC_AMPCAP_MUTE_SHIFT)); | |
3157 | ||
d949cac1 | 3158 | /* automatic parse from the BIOS config */ |
12daef65 | 3159 | err = via_parse_auto_config(codec); |
d949cac1 HW |
3160 | if (err < 0) { |
3161 | via_free(codec); | |
3162 | return err; | |
d949cac1 HW |
3163 | } |
3164 | ||
096a8854 | 3165 | spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; |
d949cac1 | 3166 | |
d949cac1 HW |
3167 | codec->patch_ops = via_patch_ops; |
3168 | ||
3e95b9ab | 3169 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
d949cac1 HW |
3170 | return 0; |
3171 | } | |
3172 | ||
eb7188ca LW |
3173 | /* Patch for VT1718S */ |
3174 | ||
096a8854 | 3175 | static const struct hda_verb vt1718S_init_verbs[] = { |
4ab2d53a LW |
3176 | /* Enable MW0 adjust Gain 5 */ |
3177 | {0x1, 0xfb2, 0x10}, | |
eb7188ca LW |
3178 | /* Enable Boost Volume backdoor */ |
3179 | {0x1, 0xf88, 0x8}, | |
5d41762a | 3180 | |
eb7188ca LW |
3181 | { } |
3182 | }; | |
3183 | ||
3e95b9ab LW |
3184 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
3185 | { | |
3186 | struct via_spec *spec = codec->spec; | |
3187 | int imux_is_smixer; | |
6162552b | 3188 | unsigned int parm, parm2; |
3e95b9ab LW |
3189 | /* MUX6 (1eh) = stereo mixer */ |
3190 | imux_is_smixer = | |
3191 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; | |
3192 | /* inputs */ | |
3193 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
3194 | parm = AC_PWRST_D3; | |
3195 | set_pin_power_state(codec, 0x29, &parm); | |
3196 | set_pin_power_state(codec, 0x2a, &parm); | |
3197 | set_pin_power_state(codec, 0x2b, &parm); | |
3198 | if (imux_is_smixer) | |
3199 | parm = AC_PWRST_D0; | |
3200 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
054d867e TI |
3201 | update_power_state(codec, 0x1e, parm); |
3202 | update_power_state(codec, 0x1f, parm); | |
3203 | update_power_state(codec, 0x10, parm); | |
3204 | update_power_state(codec, 0x11, parm); | |
3e95b9ab LW |
3205 | |
3206 | /* outputs */ | |
3207 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ | |
3208 | parm = AC_PWRST_D3; | |
3209 | set_pin_power_state(codec, 0x27, &parm); | |
054d867e | 3210 | update_power_state(codec, 0x1a, parm); |
6162552b | 3211 | parm2 = parm; /* for pin 0x0b */ |
3e95b9ab LW |
3212 | |
3213 | /* PW2 (26h), AOW2 (ah) */ | |
3214 | parm = AC_PWRST_D3; | |
3215 | set_pin_power_state(codec, 0x26, &parm); | |
3216 | if (spec->smart51_enabled) | |
3217 | set_pin_power_state(codec, 0x2b, &parm); | |
054d867e | 3218 | update_power_state(codec, 0xa, parm); |
3e95b9ab LW |
3219 | |
3220 | /* PW0 (24h), AOW0 (8h) */ | |
3221 | parm = AC_PWRST_D3; | |
3222 | set_pin_power_state(codec, 0x24, &parm); | |
3223 | if (!spec->hp_independent_mode) /* check for redirected HP */ | |
3224 | set_pin_power_state(codec, 0x28, &parm); | |
054d867e | 3225 | update_power_state(codec, 0x8, parm); |
6162552b TI |
3226 | if (!spec->hp_independent_mode && parm2 != AC_PWRST_D3) |
3227 | parm = parm2; | |
3228 | update_power_state(codec, 0xb, parm); | |
3e95b9ab | 3229 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
054d867e | 3230 | update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm); |
3e95b9ab LW |
3231 | |
3232 | /* PW1 (25h), AOW1 (9h) */ | |
3233 | parm = AC_PWRST_D3; | |
3234 | set_pin_power_state(codec, 0x25, &parm); | |
3235 | if (spec->smart51_enabled) | |
3236 | set_pin_power_state(codec, 0x2a, &parm); | |
054d867e | 3237 | update_power_state(codec, 0x9, parm); |
3e95b9ab LW |
3238 | |
3239 | if (spec->hp_independent_mode) { | |
3240 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ | |
3241 | parm = AC_PWRST_D3; | |
3242 | set_pin_power_state(codec, 0x28, &parm); | |
054d867e TI |
3243 | update_power_state(codec, 0x1b, parm); |
3244 | update_power_state(codec, 0x34, parm); | |
3245 | update_power_state(codec, 0xc, parm); | |
3e95b9ab LW |
3246 | } |
3247 | } | |
3248 | ||
30b45033 TI |
3249 | /* Add a connection to the primary DAC from AA-mixer for some codecs |
3250 | * This isn't listed from the raw info, but the chip has a secret connection. | |
3251 | */ | |
3252 | static int add_secret_dac_path(struct hda_codec *codec) | |
3253 | { | |
3254 | struct via_spec *spec = codec->spec; | |
3255 | int i, nums; | |
3256 | hda_nid_t conn[8]; | |
3257 | hda_nid_t nid; | |
3258 | ||
3259 | if (!spec->aa_mix_nid) | |
3260 | return 0; | |
3261 | nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, | |
3262 | ARRAY_SIZE(conn) - 1); | |
3263 | for (i = 0; i < nums; i++) { | |
3264 | if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT) | |
3265 | return 0; | |
3266 | } | |
3267 | ||
3268 | /* find the primary DAC and add to the connection list */ | |
3269 | nid = codec->start_nid; | |
3270 | for (i = 0; i < codec->num_nodes; i++, nid++) { | |
3271 | unsigned int caps = get_wcaps(codec, nid); | |
3272 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT && | |
3273 | !(caps & AC_WCAP_DIGITAL)) { | |
3274 | conn[nums++] = nid; | |
3275 | return snd_hda_override_conn_list(codec, | |
3276 | spec->aa_mix_nid, | |
3277 | nums, conn); | |
3278 | } | |
3279 | } | |
3280 | return 0; | |
3281 | } | |
3282 | ||
3283 | ||
eb7188ca LW |
3284 | static int patch_vt1718S(struct hda_codec *codec) |
3285 | { | |
3286 | struct via_spec *spec; | |
3287 | int err; | |
3288 | ||
3289 | /* create a codec specific record */ | |
5b0cb1d8 | 3290 | spec = via_new_spec(codec); |
eb7188ca LW |
3291 | if (spec == NULL) |
3292 | return -ENOMEM; | |
3293 | ||
620e2b28 | 3294 | spec->aa_mix_nid = 0x21; |
d7a99cce TI |
3295 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
3296 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
30b45033 | 3297 | add_secret_dac_path(codec); |
620e2b28 | 3298 | |
eb7188ca | 3299 | /* automatic parse from the BIOS config */ |
12daef65 | 3300 | err = via_parse_auto_config(codec); |
eb7188ca LW |
3301 | if (err < 0) { |
3302 | via_free(codec); | |
3303 | return err; | |
eb7188ca LW |
3304 | } |
3305 | ||
096a8854 | 3306 | spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; |
eb7188ca | 3307 | |
eb7188ca LW |
3308 | codec->patch_ops = via_patch_ops; |
3309 | ||
3e95b9ab LW |
3310 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
3311 | ||
eb7188ca LW |
3312 | return 0; |
3313 | } | |
f3db423d LW |
3314 | |
3315 | /* Patch for VT1716S */ | |
3316 | ||
3317 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, | |
3318 | struct snd_ctl_elem_info *uinfo) | |
3319 | { | |
3320 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
3321 | uinfo->count = 1; | |
3322 | uinfo->value.integer.min = 0; | |
3323 | uinfo->value.integer.max = 1; | |
3324 | return 0; | |
3325 | } | |
3326 | ||
3327 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, | |
3328 | struct snd_ctl_elem_value *ucontrol) | |
3329 | { | |
3330 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3331 | int index = 0; | |
3332 | ||
3333 | index = snd_hda_codec_read(codec, 0x26, 0, | |
3334 | AC_VERB_GET_CONNECT_SEL, 0); | |
3335 | if (index != -1) | |
3336 | *ucontrol->value.integer.value = index; | |
3337 | ||
3338 | return 0; | |
3339 | } | |
3340 | ||
3341 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, | |
3342 | struct snd_ctl_elem_value *ucontrol) | |
3343 | { | |
3344 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
3345 | struct via_spec *spec = codec->spec; | |
3346 | int index = *ucontrol->value.integer.value; | |
3347 | ||
3348 | snd_hda_codec_write(codec, 0x26, 0, | |
3349 | AC_VERB_SET_CONNECT_SEL, index); | |
3350 | spec->dmic_enabled = index; | |
3e95b9ab | 3351 | set_widgets_power_state(codec); |
f3db423d LW |
3352 | return 1; |
3353 | } | |
3354 | ||
90dd48a1 | 3355 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
f3db423d LW |
3356 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
3357 | { | |
3358 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
3359 | .name = "Digital Mic Capture Switch", | |
5b0cb1d8 | 3360 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
f3db423d LW |
3361 | .count = 1, |
3362 | .info = vt1716s_dmic_info, | |
3363 | .get = vt1716s_dmic_get, | |
3364 | .put = vt1716s_dmic_put, | |
3365 | }, | |
3366 | {} /* end */ | |
3367 | }; | |
3368 | ||
3369 | ||
3370 | /* mono-out mixer elements */ | |
90dd48a1 | 3371 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
f3db423d LW |
3372 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
3373 | { } /* end */ | |
3374 | }; | |
3375 | ||
096a8854 | 3376 | static const struct hda_verb vt1716S_init_verbs[] = { |
f3db423d LW |
3377 | /* Enable Boost Volume backdoor */ |
3378 | {0x1, 0xf8a, 0x80}, | |
3379 | /* don't bybass mixer */ | |
3380 | {0x1, 0xf88, 0xc0}, | |
3381 | /* Enable mono output */ | |
3382 | {0x1, 0xf90, 0x08}, | |
3383 | { } | |
3384 | }; | |
3385 | ||
3e95b9ab LW |
3386 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
3387 | { | |
3388 | struct via_spec *spec = codec->spec; | |
3389 | int imux_is_smixer; | |
3390 | unsigned int parm; | |
3391 | unsigned int mono_out, present; | |
3392 | /* SW0 (17h) = stereo mixer */ | |
3393 | imux_is_smixer = | |
3394 | (snd_hda_codec_read(codec, 0x17, 0, | |
3395 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); | |
3396 | /* inputs */ | |
3397 | /* PW 1/2/5 (1ah/1bh/1eh) */ | |
3398 | parm = AC_PWRST_D3; | |
3399 | set_pin_power_state(codec, 0x1a, &parm); | |
3400 | set_pin_power_state(codec, 0x1b, &parm); | |
3401 | set_pin_power_state(codec, 0x1e, &parm); | |
3402 | if (imux_is_smixer) | |
3403 | parm = AC_PWRST_D0; | |
3404 | /* SW0 (17h), AIW0(13h) */ | |
054d867e TI |
3405 | update_power_state(codec, 0x17, parm); |
3406 | update_power_state(codec, 0x13, parm); | |
3e95b9ab LW |
3407 | |
3408 | parm = AC_PWRST_D3; | |
3409 | set_pin_power_state(codec, 0x1e, &parm); | |
3410 | /* PW11 (22h) */ | |
3411 | if (spec->dmic_enabled) | |
3412 | set_pin_power_state(codec, 0x22, &parm); | |
3413 | else | |
054d867e | 3414 | update_power_state(codec, 0x22, AC_PWRST_D3); |
3e95b9ab LW |
3415 | |
3416 | /* SW2(26h), AIW1(14h) */ | |
054d867e TI |
3417 | update_power_state(codec, 0x26, parm); |
3418 | update_power_state(codec, 0x14, parm); | |
3e95b9ab LW |
3419 | |
3420 | /* outputs */ | |
3421 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ | |
3422 | parm = AC_PWRST_D3; | |
3423 | set_pin_power_state(codec, 0x19, &parm); | |
3424 | /* Smart 5.1 PW2(1bh) */ | |
3425 | if (spec->smart51_enabled) | |
3426 | set_pin_power_state(codec, 0x1b, &parm); | |
054d867e TI |
3427 | update_power_state(codec, 0x18, parm); |
3428 | update_power_state(codec, 0x11, parm); | |
3e95b9ab LW |
3429 | |
3430 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ | |
3431 | parm = AC_PWRST_D3; | |
3432 | set_pin_power_state(codec, 0x23, &parm); | |
3433 | /* Smart 5.1 PW1(1ah) */ | |
3434 | if (spec->smart51_enabled) | |
3435 | set_pin_power_state(codec, 0x1a, &parm); | |
054d867e | 3436 | update_power_state(codec, 0x27, parm); |
3e95b9ab LW |
3437 | |
3438 | /* Smart 5.1 PW5(1eh) */ | |
3439 | if (spec->smart51_enabled) | |
3440 | set_pin_power_state(codec, 0x1e, &parm); | |
054d867e | 3441 | update_power_state(codec, 0x25, parm); |
3e95b9ab LW |
3442 | |
3443 | /* Mono out */ | |
3444 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ | |
3445 | present = snd_hda_jack_detect(codec, 0x1c); | |
3446 | ||
3447 | if (present) | |
3448 | mono_out = 0; | |
3449 | else { | |
3450 | present = snd_hda_jack_detect(codec, 0x1d); | |
3451 | if (!spec->hp_independent_mode && present) | |
3452 | mono_out = 0; | |
3453 | else | |
3454 | mono_out = 1; | |
3455 | } | |
3456 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; | |
054d867e TI |
3457 | update_power_state(codec, 0x28, parm); |
3458 | update_power_state(codec, 0x29, parm); | |
3459 | update_power_state(codec, 0x2a, parm); | |
3e95b9ab LW |
3460 | |
3461 | /* PW 3/4 (1ch/1dh) */ | |
3462 | parm = AC_PWRST_D3; | |
3463 | set_pin_power_state(codec, 0x1c, &parm); | |
3464 | set_pin_power_state(codec, 0x1d, &parm); | |
3465 | /* HP Independent Mode, power on AOW3 */ | |
3466 | if (spec->hp_independent_mode) | |
054d867e | 3467 | update_power_state(codec, 0x25, parm); |
3e95b9ab LW |
3468 | |
3469 | /* force to D0 for internal Speaker */ | |
3470 | /* MW0 (16h), AOW0 (10h) */ | |
054d867e TI |
3471 | update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm); |
3472 | update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm); | |
3e95b9ab LW |
3473 | } |
3474 | ||
f3db423d LW |
3475 | static int patch_vt1716S(struct hda_codec *codec) |
3476 | { | |
3477 | struct via_spec *spec; | |
3478 | int err; | |
3479 | ||
3480 | /* create a codec specific record */ | |
5b0cb1d8 | 3481 | spec = via_new_spec(codec); |
f3db423d LW |
3482 | if (spec == NULL) |
3483 | return -ENOMEM; | |
3484 | ||
620e2b28 | 3485 | spec->aa_mix_nid = 0x16; |
d7a99cce TI |
3486 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
3487 | override_mic_boost(codec, 0x1e, 0, 3, 40); | |
620e2b28 | 3488 | |
f3db423d | 3489 | /* automatic parse from the BIOS config */ |
12daef65 | 3490 | err = via_parse_auto_config(codec); |
f3db423d LW |
3491 | if (err < 0) { |
3492 | via_free(codec); | |
3493 | return err; | |
f3db423d LW |
3494 | } |
3495 | ||
096a8854 | 3496 | spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; |
f3db423d | 3497 | |
f3db423d LW |
3498 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
3499 | spec->num_mixers++; | |
3500 | ||
3501 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; | |
3502 | ||
3503 | codec->patch_ops = via_patch_ops; | |
3504 | ||
3e95b9ab | 3505 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
f3db423d LW |
3506 | return 0; |
3507 | } | |
25eaba2f LW |
3508 | |
3509 | /* for vt2002P */ | |
3510 | ||
096a8854 | 3511 | static const struct hda_verb vt2002P_init_verbs[] = { |
eadb9a80 LW |
3512 | /* Class-D speaker related verbs */ |
3513 | {0x1, 0xfe0, 0x4}, | |
3514 | {0x1, 0xfe9, 0x80}, | |
3515 | {0x1, 0xfe2, 0x22}, | |
25eaba2f LW |
3516 | /* Enable Boost Volume backdoor */ |
3517 | {0x1, 0xfb9, 0x24}, | |
25eaba2f LW |
3518 | /* Enable AOW0 to MW9 */ |
3519 | {0x1, 0xfb8, 0x88}, | |
3520 | { } | |
3521 | }; | |
4a918ffe | 3522 | |
096a8854 | 3523 | static const struct hda_verb vt1802_init_verbs[] = { |
11890956 LW |
3524 | /* Enable Boost Volume backdoor */ |
3525 | {0x1, 0xfb9, 0x24}, | |
11890956 LW |
3526 | /* Enable AOW0 to MW9 */ |
3527 | {0x1, 0xfb8, 0x88}, | |
3528 | { } | |
3529 | }; | |
25eaba2f | 3530 | |
3e95b9ab LW |
3531 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
3532 | { | |
3533 | struct via_spec *spec = codec->spec; | |
3534 | int imux_is_smixer; | |
3535 | unsigned int parm; | |
3536 | unsigned int present; | |
3537 | /* MUX9 (1eh) = stereo mixer */ | |
3538 | imux_is_smixer = | |
3539 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; | |
3540 | /* inputs */ | |
3541 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
3542 | parm = AC_PWRST_D3; | |
3543 | set_pin_power_state(codec, 0x29, &parm); | |
3544 | set_pin_power_state(codec, 0x2a, &parm); | |
3545 | set_pin_power_state(codec, 0x2b, &parm); | |
3546 | parm = AC_PWRST_D0; | |
3547 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
054d867e TI |
3548 | update_power_state(codec, 0x1e, parm); |
3549 | update_power_state(codec, 0x1f, parm); | |
3550 | update_power_state(codec, 0x10, parm); | |
3551 | update_power_state(codec, 0x11, parm); | |
3e95b9ab LW |
3552 | |
3553 | /* outputs */ | |
3554 | /* AOW0 (8h)*/ | |
054d867e | 3555 | update_power_state(codec, 0x8, parm); |
3e95b9ab | 3556 | |
11890956 LW |
3557 | if (spec->codec_type == VT1802) { |
3558 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | |
3559 | parm = AC_PWRST_D3; | |
3560 | set_pin_power_state(codec, 0x28, &parm); | |
054d867e TI |
3561 | update_power_state(codec, 0x18, parm); |
3562 | update_power_state(codec, 0x38, parm); | |
11890956 LW |
3563 | } else { |
3564 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ | |
3565 | parm = AC_PWRST_D3; | |
3566 | set_pin_power_state(codec, 0x26, &parm); | |
054d867e TI |
3567 | update_power_state(codec, 0x1c, parm); |
3568 | update_power_state(codec, 0x37, parm); | |
11890956 | 3569 | } |
3e95b9ab | 3570 | |
11890956 LW |
3571 | if (spec->codec_type == VT1802) { |
3572 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | |
3573 | parm = AC_PWRST_D3; | |
3574 | set_pin_power_state(codec, 0x25, &parm); | |
054d867e TI |
3575 | update_power_state(codec, 0x15, parm); |
3576 | update_power_state(codec, 0x35, parm); | |
11890956 LW |
3577 | } else { |
3578 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ | |
3579 | parm = AC_PWRST_D3; | |
3580 | set_pin_power_state(codec, 0x25, &parm); | |
054d867e TI |
3581 | update_power_state(codec, 0x19, parm); |
3582 | update_power_state(codec, 0x35, parm); | |
11890956 | 3583 | } |
3e95b9ab LW |
3584 | |
3585 | if (spec->hp_independent_mode) | |
054d867e | 3586 | update_power_state(codec, 0x9, AC_PWRST_D0); |
3e95b9ab LW |
3587 | |
3588 | /* Class-D */ | |
3589 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ | |
3590 | present = snd_hda_jack_detect(codec, 0x25); | |
3591 | ||
3592 | parm = AC_PWRST_D3; | |
3593 | set_pin_power_state(codec, 0x24, &parm); | |
3594 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; | |
11890956 | 3595 | if (spec->codec_type == VT1802) |
054d867e | 3596 | update_power_state(codec, 0x14, parm); |
11890956 | 3597 | else |
054d867e TI |
3598 | update_power_state(codec, 0x18, parm); |
3599 | update_power_state(codec, 0x34, parm); | |
3e95b9ab LW |
3600 | |
3601 | /* Mono Out */ | |
3602 | present = snd_hda_jack_detect(codec, 0x26); | |
3603 | ||
3604 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; | |
11890956 LW |
3605 | if (spec->codec_type == VT1802) { |
3606 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ | |
054d867e TI |
3607 | update_power_state(codec, 0x33, parm); |
3608 | update_power_state(codec, 0x1c, parm); | |
3609 | update_power_state(codec, 0x3c, parm); | |
11890956 LW |
3610 | } else { |
3611 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ | |
054d867e TI |
3612 | update_power_state(codec, 0x31, parm); |
3613 | update_power_state(codec, 0x17, parm); | |
3614 | update_power_state(codec, 0x3b, parm); | |
11890956 | 3615 | } |
3e95b9ab LW |
3616 | /* MW9 (21h) */ |
3617 | if (imux_is_smixer || !is_aa_path_mute(codec)) | |
054d867e | 3618 | update_power_state(codec, 0x21, AC_PWRST_D0); |
3e95b9ab | 3619 | else |
054d867e | 3620 | update_power_state(codec, 0x21, AC_PWRST_D3); |
3e95b9ab | 3621 | } |
25eaba2f | 3622 | |
4b527b65 DH |
3623 | /* |
3624 | * pin fix-up | |
3625 | */ | |
3626 | enum { | |
3627 | VIA_FIXUP_INTMIC_BOOST, | |
d5266125 | 3628 | VIA_FIXUP_ASUS_G75, |
4b527b65 DH |
3629 | }; |
3630 | ||
3631 | static void via_fixup_intmic_boost(struct hda_codec *codec, | |
3632 | const struct hda_fixup *fix, int action) | |
3633 | { | |
3634 | if (action == HDA_FIXUP_ACT_PRE_PROBE) | |
3635 | override_mic_boost(codec, 0x30, 0, 2, 40); | |
3636 | } | |
3637 | ||
3638 | static const struct hda_fixup via_fixups[] = { | |
3639 | [VIA_FIXUP_INTMIC_BOOST] = { | |
3640 | .type = HDA_FIXUP_FUNC, | |
3641 | .v.func = via_fixup_intmic_boost, | |
3642 | }, | |
d5266125 TI |
3643 | [VIA_FIXUP_ASUS_G75] = { |
3644 | .type = HDA_FIXUP_PINS, | |
3645 | .v.pins = (const struct hda_pintbl[]) { | |
3646 | /* set 0x24 and 0x33 as speakers */ | |
3647 | { 0x24, 0x991301f0 }, | |
3648 | { 0x33, 0x991301f1 }, /* subwoofer */ | |
3649 | { } | |
3650 | } | |
3651 | }, | |
4b527b65 DH |
3652 | }; |
3653 | ||
3654 | static const struct snd_pci_quirk vt2002p_fixups[] = { | |
d5266125 | 3655 | SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75), |
4b527b65 DH |
3656 | SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST), |
3657 | {} | |
3658 | }; | |
3659 | ||
ef4da458 TI |
3660 | /* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e |
3661 | * Replace this with mixer NID 0x1c | |
3662 | */ | |
3663 | static void fix_vt1802_connections(struct hda_codec *codec) | |
3664 | { | |
3665 | static hda_nid_t conn_24[] = { 0x14, 0x1c }; | |
3666 | static hda_nid_t conn_33[] = { 0x1c }; | |
3667 | ||
3668 | snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24); | |
3669 | snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33); | |
3670 | } | |
3671 | ||
25eaba2f LW |
3672 | /* patch for vt2002P */ |
3673 | static int patch_vt2002P(struct hda_codec *codec) | |
3674 | { | |
3675 | struct via_spec *spec; | |
3676 | int err; | |
3677 | ||
3678 | /* create a codec specific record */ | |
5b0cb1d8 | 3679 | spec = via_new_spec(codec); |
25eaba2f LW |
3680 | if (spec == NULL) |
3681 | return -ENOMEM; | |
3682 | ||
620e2b28 | 3683 | spec->aa_mix_nid = 0x21; |
d7a99cce TI |
3684 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
3685 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
ef4da458 TI |
3686 | if (spec->codec_type == VT1802) |
3687 | fix_vt1802_connections(codec); | |
30b45033 | 3688 | add_secret_dac_path(codec); |
620e2b28 | 3689 | |
4b527b65 DH |
3690 | snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups); |
3691 | snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); | |
3692 | ||
25eaba2f | 3693 | /* automatic parse from the BIOS config */ |
12daef65 | 3694 | err = via_parse_auto_config(codec); |
25eaba2f LW |
3695 | if (err < 0) { |
3696 | via_free(codec); | |
3697 | return err; | |
25eaba2f LW |
3698 | } |
3699 | ||
11890956 | 3700 | if (spec->codec_type == VT1802) |
4a918ffe | 3701 | spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs; |
11890956 | 3702 | else |
4a918ffe | 3703 | spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; |
11890956 | 3704 | |
25eaba2f LW |
3705 | codec->patch_ops = via_patch_ops; |
3706 | ||
3e95b9ab | 3707 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
25eaba2f LW |
3708 | return 0; |
3709 | } | |
ab6734e7 LW |
3710 | |
3711 | /* for vt1812 */ | |
3712 | ||
096a8854 | 3713 | static const struct hda_verb vt1812_init_verbs[] = { |
ab6734e7 LW |
3714 | /* Enable Boost Volume backdoor */ |
3715 | {0x1, 0xfb9, 0x24}, | |
ab6734e7 LW |
3716 | /* Enable AOW0 to MW9 */ |
3717 | {0x1, 0xfb8, 0xa8}, | |
3718 | { } | |
3719 | }; | |
3720 | ||
3e95b9ab LW |
3721 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
3722 | { | |
3723 | struct via_spec *spec = codec->spec; | |
3e95b9ab LW |
3724 | unsigned int parm; |
3725 | unsigned int present; | |
3e95b9ab LW |
3726 | /* inputs */ |
3727 | /* PW 5/6/7 (29h/2ah/2bh) */ | |
3728 | parm = AC_PWRST_D3; | |
3729 | set_pin_power_state(codec, 0x29, &parm); | |
3730 | set_pin_power_state(codec, 0x2a, &parm); | |
3731 | set_pin_power_state(codec, 0x2b, &parm); | |
3732 | parm = AC_PWRST_D0; | |
3733 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ | |
054d867e TI |
3734 | update_power_state(codec, 0x1e, parm); |
3735 | update_power_state(codec, 0x1f, parm); | |
3736 | update_power_state(codec, 0x10, parm); | |
3737 | update_power_state(codec, 0x11, parm); | |
3e95b9ab LW |
3738 | |
3739 | /* outputs */ | |
3740 | /* AOW0 (8h)*/ | |
054d867e | 3741 | update_power_state(codec, 0x8, AC_PWRST_D0); |
3e95b9ab LW |
3742 | |
3743 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ | |
3744 | parm = AC_PWRST_D3; | |
3745 | set_pin_power_state(codec, 0x28, &parm); | |
054d867e TI |
3746 | update_power_state(codec, 0x18, parm); |
3747 | update_power_state(codec, 0x38, parm); | |
3e95b9ab LW |
3748 | |
3749 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ | |
3750 | parm = AC_PWRST_D3; | |
3751 | set_pin_power_state(codec, 0x25, &parm); | |
054d867e TI |
3752 | update_power_state(codec, 0x15, parm); |
3753 | update_power_state(codec, 0x35, parm); | |
3e95b9ab | 3754 | if (spec->hp_independent_mode) |
054d867e | 3755 | update_power_state(codec, 0x9, AC_PWRST_D0); |
3e95b9ab LW |
3756 | |
3757 | /* Internal Speaker */ | |
3758 | /* PW0 (24h), MW0(14h), MUX0(34h) */ | |
3759 | present = snd_hda_jack_detect(codec, 0x25); | |
3760 | ||
3761 | parm = AC_PWRST_D3; | |
3762 | set_pin_power_state(codec, 0x24, &parm); | |
3763 | if (present) { | |
054d867e TI |
3764 | update_power_state(codec, 0x14, AC_PWRST_D3); |
3765 | update_power_state(codec, 0x34, AC_PWRST_D3); | |
3e95b9ab | 3766 | } else { |
054d867e TI |
3767 | update_power_state(codec, 0x14, AC_PWRST_D0); |
3768 | update_power_state(codec, 0x34, AC_PWRST_D0); | |
3e95b9ab LW |
3769 | } |
3770 | ||
3771 | ||
3772 | /* Mono Out */ | |
3773 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ | |
3774 | present = snd_hda_jack_detect(codec, 0x28); | |
3775 | ||
3776 | parm = AC_PWRST_D3; | |
3777 | set_pin_power_state(codec, 0x31, &parm); | |
3778 | if (present) { | |
054d867e TI |
3779 | update_power_state(codec, 0x1c, AC_PWRST_D3); |
3780 | update_power_state(codec, 0x3c, AC_PWRST_D3); | |
3781 | update_power_state(codec, 0x3e, AC_PWRST_D3); | |
3e95b9ab | 3782 | } else { |
054d867e TI |
3783 | update_power_state(codec, 0x1c, AC_PWRST_D0); |
3784 | update_power_state(codec, 0x3c, AC_PWRST_D0); | |
3785 | update_power_state(codec, 0x3e, AC_PWRST_D0); | |
3e95b9ab LW |
3786 | } |
3787 | ||
3788 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ | |
3789 | parm = AC_PWRST_D3; | |
3790 | set_pin_power_state(codec, 0x33, &parm); | |
054d867e TI |
3791 | update_power_state(codec, 0x1d, parm); |
3792 | update_power_state(codec, 0x3d, parm); | |
3e95b9ab LW |
3793 | |
3794 | } | |
ab6734e7 LW |
3795 | |
3796 | /* patch for vt1812 */ | |
3797 | static int patch_vt1812(struct hda_codec *codec) | |
3798 | { | |
3799 | struct via_spec *spec; | |
3800 | int err; | |
3801 | ||
3802 | /* create a codec specific record */ | |
5b0cb1d8 | 3803 | spec = via_new_spec(codec); |
ab6734e7 LW |
3804 | if (spec == NULL) |
3805 | return -ENOMEM; | |
3806 | ||
620e2b28 | 3807 | spec->aa_mix_nid = 0x21; |
d7a99cce TI |
3808 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
3809 | override_mic_boost(codec, 0x29, 0, 3, 40); | |
30b45033 | 3810 | add_secret_dac_path(codec); |
620e2b28 | 3811 | |
ab6734e7 | 3812 | /* automatic parse from the BIOS config */ |
12daef65 | 3813 | err = via_parse_auto_config(codec); |
ab6734e7 LW |
3814 | if (err < 0) { |
3815 | via_free(codec); | |
3816 | return err; | |
ab6734e7 LW |
3817 | } |
3818 | ||
096a8854 | 3819 | spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; |
ab6734e7 | 3820 | |
ab6734e7 LW |
3821 | codec->patch_ops = via_patch_ops; |
3822 | ||
3e95b9ab | 3823 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
ab6734e7 LW |
3824 | return 0; |
3825 | } | |
3826 | ||
c577b8a1 JC |
3827 | /* |
3828 | * patch entries | |
3829 | */ | |
90dd48a1 | 3830 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
3218c178 TI |
3831 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
3832 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, | |
3833 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, | |
3834 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, | |
3835 | { .id = 0x1106e710, .name = "VT1709 10-Ch", | |
ddd304d8 | 3836 | .patch = patch_vt1709}, |
3218c178 | 3837 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
ddd304d8 | 3838 | .patch = patch_vt1709}, |
3218c178 | 3839 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
ddd304d8 | 3840 | .patch = patch_vt1709}, |
3218c178 | 3841 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
ddd304d8 | 3842 | .patch = patch_vt1709}, |
3218c178 | 3843 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
ddd304d8 | 3844 | .patch = patch_vt1709}, |
3218c178 | 3845 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
ddd304d8 | 3846 | .patch = patch_vt1709}, |
3218c178 | 3847 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
ddd304d8 | 3848 | .patch = patch_vt1709}, |
3218c178 | 3849 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
ddd304d8 | 3850 | .patch = patch_vt1709}, |
3218c178 | 3851 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
ddd304d8 | 3852 | .patch = patch_vt1708B}, |
3218c178 | 3853 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
ddd304d8 | 3854 | .patch = patch_vt1708B}, |
3218c178 | 3855 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
ddd304d8 | 3856 | .patch = patch_vt1708B}, |
3218c178 | 3857 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
ddd304d8 | 3858 | .patch = patch_vt1708B}, |
3218c178 | 3859 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
ddd304d8 | 3860 | .patch = patch_vt1708B}, |
3218c178 | 3861 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
ddd304d8 | 3862 | .patch = patch_vt1708B}, |
3218c178 | 3863 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
ddd304d8 | 3864 | .patch = patch_vt1708B}, |
3218c178 | 3865 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
ddd304d8 | 3866 | .patch = patch_vt1708B}, |
3218c178 | 3867 | { .id = 0x11060397, .name = "VT1708S", |
d949cac1 | 3868 | .patch = patch_vt1708S}, |
3218c178 | 3869 | { .id = 0x11061397, .name = "VT1708S", |
d949cac1 | 3870 | .patch = patch_vt1708S}, |
3218c178 | 3871 | { .id = 0x11062397, .name = "VT1708S", |
d949cac1 | 3872 | .patch = patch_vt1708S}, |
3218c178 | 3873 | { .id = 0x11063397, .name = "VT1708S", |
d949cac1 | 3874 | .patch = patch_vt1708S}, |
bc92df7f | 3875 | { .id = 0x11064397, .name = "VT1705", |
d949cac1 | 3876 | .patch = patch_vt1708S}, |
3218c178 | 3877 | { .id = 0x11065397, .name = "VT1708S", |
d949cac1 | 3878 | .patch = patch_vt1708S}, |
3218c178 | 3879 | { .id = 0x11066397, .name = "VT1708S", |
d949cac1 | 3880 | .patch = patch_vt1708S}, |
3218c178 | 3881 | { .id = 0x11067397, .name = "VT1708S", |
d949cac1 | 3882 | .patch = patch_vt1708S}, |
3218c178 | 3883 | { .id = 0x11060398, .name = "VT1702", |
d949cac1 | 3884 | .patch = patch_vt1702}, |
3218c178 | 3885 | { .id = 0x11061398, .name = "VT1702", |
d949cac1 | 3886 | .patch = patch_vt1702}, |
3218c178 | 3887 | { .id = 0x11062398, .name = "VT1702", |
d949cac1 | 3888 | .patch = patch_vt1702}, |
3218c178 | 3889 | { .id = 0x11063398, .name = "VT1702", |
d949cac1 | 3890 | .patch = patch_vt1702}, |
3218c178 | 3891 | { .id = 0x11064398, .name = "VT1702", |
d949cac1 | 3892 | .patch = patch_vt1702}, |
3218c178 | 3893 | { .id = 0x11065398, .name = "VT1702", |
d949cac1 | 3894 | .patch = patch_vt1702}, |
3218c178 | 3895 | { .id = 0x11066398, .name = "VT1702", |
d949cac1 | 3896 | .patch = patch_vt1702}, |
3218c178 | 3897 | { .id = 0x11067398, .name = "VT1702", |
d949cac1 | 3898 | .patch = patch_vt1702}, |
eb7188ca LW |
3899 | { .id = 0x11060428, .name = "VT1718S", |
3900 | .patch = patch_vt1718S}, | |
3901 | { .id = 0x11064428, .name = "VT1718S", | |
3902 | .patch = patch_vt1718S}, | |
bb3c6bfc LW |
3903 | { .id = 0x11060441, .name = "VT2020", |
3904 | .patch = patch_vt1718S}, | |
3905 | { .id = 0x11064441, .name = "VT1828S", | |
3906 | .patch = patch_vt1718S}, | |
f3db423d LW |
3907 | { .id = 0x11060433, .name = "VT1716S", |
3908 | .patch = patch_vt1716S}, | |
3909 | { .id = 0x1106a721, .name = "VT1716S", | |
3910 | .patch = patch_vt1716S}, | |
25eaba2f LW |
3911 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
3912 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, | |
ab6734e7 | 3913 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
36dd5c4a LW |
3914 | { .id = 0x11060440, .name = "VT1818S", |
3915 | .patch = patch_vt1708S}, | |
11890956 LW |
3916 | { .id = 0x11060446, .name = "VT1802", |
3917 | .patch = patch_vt2002P}, | |
3918 | { .id = 0x11068446, .name = "VT1802", | |
3919 | .patch = patch_vt2002P}, | |
c577b8a1 JC |
3920 | {} /* terminator */ |
3921 | }; | |
1289e9e8 TI |
3922 | |
3923 | MODULE_ALIAS("snd-hda-codec-id:1106*"); | |
3924 | ||
3925 | static struct hda_codec_preset_list via_list = { | |
3926 | .preset = snd_hda_preset_via, | |
3927 | .owner = THIS_MODULE, | |
3928 | }; | |
3929 | ||
3930 | MODULE_LICENSE("GPL"); | |
3931 | MODULE_DESCRIPTION("VIA HD-audio codec"); | |
3932 | ||
3933 | static int __init patch_via_init(void) | |
3934 | { | |
3935 | return snd_hda_add_codec_preset(&via_list); | |
3936 | } | |
3937 | ||
3938 | static void __exit patch_via_exit(void) | |
3939 | { | |
3940 | snd_hda_delete_codec_preset(&via_list); | |
3941 | } | |
3942 | ||
3943 | module_init(patch_via_init) | |
3944 | module_exit(patch_via_exit) |