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