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