Commit | Line | Data |
---|---|---|
c577b8a1 JC |
1 | /* |
2 | * Universal Interface for Intel High Definition Audio Codec | |
3 | * | |
d949cac1 | 4 | * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec |
c577b8a1 | 5 | * |
76d9b0dd HW |
6 | * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com> |
7 | * 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 * * * * * * * * * * * * * * * * */ | |
25 | /* */ | |
26 | /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ | |
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 */ | |
29 | /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ | |
f7278fd0 JC |
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 */ |
d949cac1 | 34 | /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ |
69e52a80 | 35 | /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ |
0aa62aef | 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 */ |
d7426329 | 38 | /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ |
c577b8a1 JC |
39 | /* */ |
40 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
41 | ||
42 | ||
c577b8a1 JC |
43 | #include <linux/init.h> |
44 | #include <linux/delay.h> | |
45 | #include <linux/slab.h> | |
c577b8a1 | 46 | #include <sound/core.h> |
0aa62aef | 47 | #include <sound/asoundef.h> |
c577b8a1 JC |
48 | #include "hda_codec.h" |
49 | #include "hda_local.h" | |
c577b8a1 JC |
50 | |
51 | /* amp values */ | |
52 | #define AMP_VAL_IDX_SHIFT 19 | |
53 | #define AMP_VAL_IDX_MASK (0x0f<<19) | |
54 | ||
c577b8a1 JC |
55 | /* Pin Widget NID */ |
56 | #define VT1708_HP_NID 0x13 | |
57 | #define VT1708_DIGOUT_NID 0x14 | |
58 | #define VT1708_DIGIN_NID 0x16 | |
f7278fd0 | 59 | #define VT1708_DIGIN_PIN 0x26 |
d949cac1 HW |
60 | #define VT1708_HP_PIN_NID 0x20 |
61 | #define VT1708_CD_PIN_NID 0x24 | |
c577b8a1 JC |
62 | |
63 | #define VT1709_HP_DAC_NID 0x28 | |
64 | #define VT1709_DIGOUT_NID 0x13 | |
65 | #define VT1709_DIGIN_NID 0x17 | |
f7278fd0 JC |
66 | #define VT1709_DIGIN_PIN 0x25 |
67 | ||
68 | #define VT1708B_HP_NID 0x25 | |
69 | #define VT1708B_DIGOUT_NID 0x12 | |
70 | #define VT1708B_DIGIN_NID 0x15 | |
71 | #define VT1708B_DIGIN_PIN 0x21 | |
c577b8a1 | 72 | |
d949cac1 HW |
73 | #define VT1708S_HP_NID 0x25 |
74 | #define VT1708S_DIGOUT_NID 0x12 | |
75 | ||
76 | #define VT1702_HP_NID 0x17 | |
77 | #define VT1702_DIGOUT_NID 0x11 | |
78 | ||
c577b8a1 JC |
79 | #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b) |
80 | #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713) | |
81 | #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717) | |
f7278fd0 JC |
82 | #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723) |
83 | #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727) | |
d949cac1 HW |
84 | #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397) |
85 | #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398) | |
c577b8a1 | 86 | |
d7426329 HW |
87 | enum VIA_HDA_CODEC { |
88 | UNKNOWN = -1, | |
89 | VT1708, | |
90 | VT1709_10CH, | |
91 | VT1709_6CH, | |
92 | VT1708B_8CH, | |
93 | VT1708B_4CH, | |
94 | VT1708S, | |
95 | VT1702, | |
96 | CODEC_TYPES, | |
97 | }; | |
98 | ||
99 | static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id) | |
100 | { | |
101 | u16 ven_id = vendor_id >> 16; | |
102 | u16 dev_id = vendor_id & 0xffff; | |
103 | enum VIA_HDA_CODEC codec_type; | |
104 | ||
105 | /* get codec type */ | |
106 | if (ven_id != 0x1106) | |
107 | codec_type = UNKNOWN; | |
108 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) | |
109 | codec_type = VT1708; | |
110 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) | |
111 | codec_type = VT1709_10CH; | |
112 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) | |
113 | codec_type = VT1709_6CH; | |
114 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) | |
115 | codec_type = VT1708B_8CH; | |
116 | else if (dev_id >= 0xe724 && dev_id <= 0xe727) | |
117 | codec_type = VT1708B_4CH; | |
118 | else if ((dev_id & 0xfff) == 0x397 | |
119 | && (dev_id >> 12) < 8) | |
120 | codec_type = VT1708S; | |
121 | else if ((dev_id & 0xfff) == 0x398 | |
122 | && (dev_id >> 12) < 8) | |
123 | codec_type = VT1702; | |
124 | else | |
125 | codec_type = UNKNOWN; | |
126 | return codec_type; | |
127 | }; | |
128 | ||
69e52a80 HW |
129 | #define VIA_HP_EVENT 0x01 |
130 | #define VIA_GPIO_EVENT 0x02 | |
131 | ||
c577b8a1 JC |
132 | enum { |
133 | VIA_CTL_WIDGET_VOL, | |
134 | VIA_CTL_WIDGET_MUTE, | |
135 | }; | |
136 | ||
137 | enum { | |
eb14a46c | 138 | AUTO_SEQ_FRONT = 0, |
c577b8a1 JC |
139 | AUTO_SEQ_SURROUND, |
140 | AUTO_SEQ_CENLFE, | |
141 | AUTO_SEQ_SIDE | |
142 | }; | |
143 | ||
d7426329 HW |
144 | /* Some VT1708S based boards gets the micboost setting wrong, so we have |
145 | * to apply some brute-force and re-write the TLV's by software. */ | |
146 | static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag, | |
147 | unsigned int size, unsigned int __user *_tlv) | |
148 | { | |
149 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
150 | hda_nid_t nid = get_amp_nid(kcontrol); | |
151 | ||
152 | if (get_codec_type(codec->vendor_id) == VT1708S | |
153 | && (nid == 0x1a || nid == 0x1e)) { | |
154 | if (size < 4 * sizeof(unsigned int)) | |
155 | return -ENOMEM; | |
156 | if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */ | |
157 | return -EFAULT; | |
158 | if (put_user(2 * sizeof(unsigned int), _tlv + 1)) | |
159 | return -EFAULT; | |
160 | if (put_user(0, _tlv + 2)) /* offset = 0 */ | |
161 | return -EFAULT; | |
162 | if (put_user(1000, _tlv + 3)) /* step size = 10 dB */ | |
163 | return -EFAULT; | |
164 | } | |
165 | return 0; | |
166 | } | |
167 | ||
168 | static int mic_boost_volume_info(struct snd_kcontrol *kcontrol, | |
169 | struct snd_ctl_elem_info *uinfo) | |
170 | { | |
171 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
172 | hda_nid_t nid = get_amp_nid(kcontrol); | |
173 | ||
174 | if (get_codec_type(codec->vendor_id) == VT1708S | |
175 | && (nid == 0x1a || nid == 0x1e)) { | |
176 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
177 | uinfo->count = 2; | |
178 | uinfo->value.integer.min = 0; | |
179 | uinfo->value.integer.max = 3; | |
180 | } | |
181 | return 0; | |
182 | } | |
183 | ||
c577b8a1 JC |
184 | static struct snd_kcontrol_new vt1708_control_templates[] = { |
185 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), | |
186 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
187 | }; | |
188 | ||
189 | ||
190 | struct via_spec { | |
191 | /* codec parameterization */ | |
192 | struct snd_kcontrol_new *mixers[3]; | |
193 | unsigned int num_mixers; | |
194 | ||
69e52a80 HW |
195 | struct hda_verb *init_verbs[5]; |
196 | unsigned int num_iverbs; | |
c577b8a1 JC |
197 | |
198 | char *stream_name_analog; | |
199 | struct hda_pcm_stream *stream_analog_playback; | |
200 | struct hda_pcm_stream *stream_analog_capture; | |
201 | ||
202 | char *stream_name_digital; | |
203 | struct hda_pcm_stream *stream_digital_playback; | |
204 | struct hda_pcm_stream *stream_digital_capture; | |
205 | ||
206 | /* playback */ | |
207 | struct hda_multi_out multiout; | |
9da29271 | 208 | hda_nid_t slave_dig_outs[2]; |
c577b8a1 JC |
209 | |
210 | /* capture */ | |
211 | unsigned int num_adc_nids; | |
212 | hda_nid_t *adc_nids; | |
213 | hda_nid_t dig_in_nid; | |
55d1d6c1 | 214 | hda_nid_t dig_in_pin; |
c577b8a1 JC |
215 | |
216 | /* capture source */ | |
217 | const struct hda_input_mux *input_mux; | |
218 | unsigned int cur_mux[3]; | |
219 | ||
220 | /* PCM information */ | |
98aa34c0 | 221 | struct hda_pcm pcm_rec[3]; |
c577b8a1 JC |
222 | |
223 | /* dynamic controls, init_verbs and input_mux */ | |
224 | struct auto_pin_cfg autocfg; | |
603c4019 | 225 | struct snd_array kctls; |
0aa62aef | 226 | struct hda_input_mux private_imux[2]; |
41923e44 | 227 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
cb53c626 | 228 | |
0aa62aef HW |
229 | /* HP mode source */ |
230 | const struct hda_input_mux *hp_mux; | |
231 | unsigned int hp_independent_mode; | |
232 | ||
cb53c626 TI |
233 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
234 | struct hda_loopback_check loopback; | |
235 | #endif | |
c577b8a1 JC |
236 | }; |
237 | ||
238 | static hda_nid_t vt1708_adc_nids[2] = { | |
239 | /* ADC1-2 */ | |
240 | 0x15, 0x27 | |
241 | }; | |
242 | ||
243 | static hda_nid_t vt1709_adc_nids[3] = { | |
244 | /* ADC1-2 */ | |
245 | 0x14, 0x15, 0x16 | |
246 | }; | |
247 | ||
f7278fd0 JC |
248 | static hda_nid_t vt1708B_adc_nids[2] = { |
249 | /* ADC1-2 */ | |
250 | 0x13, 0x14 | |
251 | }; | |
252 | ||
d949cac1 HW |
253 | static hda_nid_t vt1708S_adc_nids[2] = { |
254 | /* ADC1-2 */ | |
255 | 0x13, 0x14 | |
256 | }; | |
257 | ||
258 | static hda_nid_t vt1702_adc_nids[3] = { | |
259 | /* ADC1-2 */ | |
260 | 0x12, 0x20, 0x1F | |
261 | }; | |
262 | ||
c577b8a1 JC |
263 | /* add dynamic controls */ |
264 | static int via_add_control(struct via_spec *spec, int type, const char *name, | |
265 | unsigned long val) | |
266 | { | |
267 | struct snd_kcontrol_new *knew; | |
268 | ||
603c4019 TI |
269 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
270 | knew = snd_array_new(&spec->kctls); | |
271 | if (!knew) | |
272 | return -ENOMEM; | |
c577b8a1 JC |
273 | *knew = vt1708_control_templates[type]; |
274 | knew->name = kstrdup(name, GFP_KERNEL); | |
c577b8a1 JC |
275 | if (!knew->name) |
276 | return -ENOMEM; | |
277 | knew->private_value = val; | |
c577b8a1 JC |
278 | return 0; |
279 | } | |
280 | ||
603c4019 TI |
281 | static void via_free_kctls(struct hda_codec *codec) |
282 | { | |
283 | struct via_spec *spec = codec->spec; | |
284 | ||
285 | if (spec->kctls.list) { | |
286 | struct snd_kcontrol_new *kctl = spec->kctls.list; | |
287 | int i; | |
288 | for (i = 0; i < spec->kctls.used; i++) | |
289 | kfree(kctl[i].name); | |
290 | } | |
291 | snd_array_free(&spec->kctls); | |
292 | } | |
293 | ||
c577b8a1 JC |
294 | /* create input playback/capture controls for the given pin */ |
295 | static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin, | |
296 | const char *ctlname, int idx, int mix_nid) | |
297 | { | |
298 | char name[32]; | |
299 | int err; | |
300 | ||
301 | sprintf(name, "%s Playback Volume", ctlname); | |
302 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
303 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); | |
304 | if (err < 0) | |
305 | return err; | |
306 | sprintf(name, "%s Playback Switch", ctlname); | |
307 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
308 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); | |
309 | if (err < 0) | |
310 | return err; | |
311 | return 0; | |
312 | } | |
313 | ||
314 | static void via_auto_set_output_and_unmute(struct hda_codec *codec, | |
315 | hda_nid_t nid, int pin_type, | |
316 | int dac_idx) | |
317 | { | |
318 | /* set as output */ | |
319 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
320 | pin_type); | |
321 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
322 | AMP_OUT_UNMUTE); | |
d3a11e60 TI |
323 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
324 | snd_hda_codec_write(codec, nid, 0, | |
325 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); | |
c577b8a1 JC |
326 | } |
327 | ||
328 | ||
329 | static void via_auto_init_multi_out(struct hda_codec *codec) | |
330 | { | |
331 | struct via_spec *spec = codec->spec; | |
332 | int i; | |
333 | ||
334 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
335 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
336 | if (nid) | |
337 | via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); | |
338 | } | |
339 | } | |
340 | ||
341 | static void via_auto_init_hp_out(struct hda_codec *codec) | |
342 | { | |
343 | struct via_spec *spec = codec->spec; | |
344 | hda_nid_t pin; | |
345 | ||
346 | pin = spec->autocfg.hp_pins[0]; | |
347 | if (pin) /* connect to front */ | |
348 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); | |
349 | } | |
350 | ||
351 | static void via_auto_init_analog_input(struct hda_codec *codec) | |
352 | { | |
353 | struct via_spec *spec = codec->spec; | |
354 | int i; | |
355 | ||
356 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
357 | hda_nid_t nid = spec->autocfg.input_pins[i]; | |
358 | ||
359 | snd_hda_codec_write(codec, nid, 0, | |
360 | AC_VERB_SET_PIN_WIDGET_CONTROL, | |
361 | (i <= AUTO_PIN_FRONT_MIC ? | |
362 | PIN_VREF50 : PIN_IN)); | |
363 | ||
364 | } | |
365 | } | |
366 | /* | |
367 | * input MUX handling | |
368 | */ | |
369 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, | |
370 | struct snd_ctl_elem_info *uinfo) | |
371 | { | |
372 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
373 | struct via_spec *spec = codec->spec; | |
374 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
375 | } | |
376 | ||
377 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, | |
378 | struct snd_ctl_elem_value *ucontrol) | |
379 | { | |
380 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
381 | struct via_spec *spec = codec->spec; | |
382 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
383 | ||
384 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; | |
385 | return 0; | |
386 | } | |
387 | ||
388 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, | |
389 | struct snd_ctl_elem_value *ucontrol) | |
390 | { | |
391 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
392 | struct via_spec *spec = codec->spec; | |
393 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); | |
394 | unsigned int vendor_id = codec->vendor_id; | |
395 | ||
396 | /* AIW0 lydia 060801 add for correct sw0 input select */ | |
397 | if (IS_VT1708_VENDORID(vendor_id) && (adc_idx == 0)) | |
398 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
399 | 0x18, &spec->cur_mux[adc_idx]); | |
400 | else if ((IS_VT1709_10CH_VENDORID(vendor_id) || | |
eb14a46c | 401 | IS_VT1709_6CH_VENDORID(vendor_id)) && (adc_idx == 0)) |
c577b8a1 JC |
402 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
403 | 0x19, &spec->cur_mux[adc_idx]); | |
f7278fd0 | 404 | else if ((IS_VT1708B_8CH_VENDORID(vendor_id) || |
eb14a46c | 405 | IS_VT1708B_4CH_VENDORID(vendor_id)) && (adc_idx == 0)) |
f7278fd0 JC |
406 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
407 | 0x17, &spec->cur_mux[adc_idx]); | |
d949cac1 HW |
408 | else if (IS_VT1702_VENDORID(vendor_id) && (adc_idx == 0)) |
409 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
410 | 0x13, &spec->cur_mux[adc_idx]); | |
c577b8a1 JC |
411 | else |
412 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
413 | spec->adc_nids[adc_idx], | |
414 | &spec->cur_mux[adc_idx]); | |
415 | } | |
416 | ||
0aa62aef HW |
417 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
418 | struct snd_ctl_elem_info *uinfo) | |
419 | { | |
420 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
421 | struct via_spec *spec = codec->spec; | |
422 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); | |
423 | } | |
424 | ||
425 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, | |
426 | struct snd_ctl_elem_value *ucontrol) | |
427 | { | |
428 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
429 | struct via_spec *spec = codec->spec; | |
430 | hda_nid_t nid = spec->autocfg.hp_pins[0]; | |
431 | unsigned int pinsel = snd_hda_codec_read(codec, nid, 0, | |
432 | AC_VERB_GET_CONNECT_SEL, | |
433 | 0x00); | |
434 | ||
435 | ucontrol->value.enumerated.item[0] = pinsel; | |
436 | ||
437 | return 0; | |
438 | } | |
439 | ||
440 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, | |
441 | struct snd_ctl_elem_value *ucontrol) | |
442 | { | |
443 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
444 | struct via_spec *spec = codec->spec; | |
445 | hda_nid_t nid = spec->autocfg.hp_pins[0]; | |
446 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; | |
447 | unsigned int con_nid = snd_hda_codec_read(codec, nid, 0, | |
448 | AC_VERB_GET_CONNECT_LIST, 0) & 0xff; | |
449 | ||
450 | if (con_nid == spec->multiout.hp_nid) { | |
451 | if (pinsel == 0) { | |
452 | if (!spec->hp_independent_mode) { | |
453 | if (spec->multiout.num_dacs > 1) | |
454 | spec->multiout.num_dacs -= 1; | |
455 | spec->hp_independent_mode = 1; | |
456 | } | |
457 | } else if (pinsel == 1) { | |
458 | if (spec->hp_independent_mode) { | |
459 | if (spec->multiout.num_dacs > 1) | |
460 | spec->multiout.num_dacs += 1; | |
461 | spec->hp_independent_mode = 0; | |
462 | } | |
463 | } | |
464 | } else { | |
465 | if (pinsel == 0) { | |
466 | if (spec->hp_independent_mode) { | |
467 | if (spec->multiout.num_dacs > 1) | |
468 | spec->multiout.num_dacs += 1; | |
469 | spec->hp_independent_mode = 0; | |
470 | } | |
471 | } else if (pinsel == 1) { | |
472 | if (!spec->hp_independent_mode) { | |
473 | if (spec->multiout.num_dacs > 1) | |
474 | spec->multiout.num_dacs -= 1; | |
475 | spec->hp_independent_mode = 1; | |
476 | } | |
477 | } | |
478 | } | |
479 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, | |
480 | pinsel); | |
481 | ||
482 | if (spec->multiout.hp_nid && | |
483 | spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT]) | |
484 | snd_hda_codec_setup_stream(codec, | |
485 | spec->multiout.hp_nid, | |
486 | 0, 0, 0); | |
487 | ||
488 | return 0; | |
489 | } | |
490 | ||
491 | static struct snd_kcontrol_new via_hp_mixer[] = { | |
492 | { | |
493 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
494 | .name = "Independent HP", | |
495 | .count = 1, | |
496 | .info = via_independent_hp_info, | |
497 | .get = via_independent_hp_get, | |
498 | .put = via_independent_hp_put, | |
499 | }, | |
500 | { } /* end */ | |
501 | }; | |
502 | ||
c577b8a1 JC |
503 | /* capture mixer elements */ |
504 | static struct snd_kcontrol_new vt1708_capture_mixer[] = { | |
505 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), | |
506 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT), | |
507 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT), | |
508 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT), | |
509 | { | |
510 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
511 | /* The multiple "Capture Source" controls confuse alsamixer | |
512 | * So call somewhat different.. | |
c577b8a1 JC |
513 | */ |
514 | /* .name = "Capture Source", */ | |
515 | .name = "Input Source", | |
516 | .count = 1, | |
517 | .info = via_mux_enum_info, | |
518 | .get = via_mux_enum_get, | |
519 | .put = via_mux_enum_put, | |
520 | }, | |
521 | { } /* end */ | |
522 | }; | |
523 | /* | |
524 | * generic initialization of ADC, input mixers and output mixers | |
525 | */ | |
526 | static struct hda_verb vt1708_volume_init_verbs[] = { | |
527 | /* | |
528 | * Unmute ADC0-1 and set the default input to mic-in | |
529 | */ | |
530 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
531 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
532 | ||
533 | ||
f7278fd0 | 534 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
c577b8a1 JC |
535 | * mixer widget |
536 | */ | |
537 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
f7278fd0 JC |
538 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
539 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
540 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
541 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
542 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
c577b8a1 JC |
543 | |
544 | /* | |
545 | * Set up output mixers (0x19 - 0x1b) | |
546 | */ | |
547 | /* set vol=0 to output mixers */ | |
548 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
549 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
550 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
551 | ||
552 | /* Setup default input to PW4 */ | |
553 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
c577b8a1 JC |
554 | /* PW9 Output enable */ |
555 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
f7278fd0 | 556 | { } |
c577b8a1 JC |
557 | }; |
558 | ||
559 | static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
560 | struct hda_codec *codec, | |
561 | struct snd_pcm_substream *substream) | |
562 | { | |
563 | struct via_spec *spec = codec->spec; | |
9a08160b TI |
564 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
565 | hinfo); | |
c577b8a1 JC |
566 | } |
567 | ||
568 | static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
569 | struct hda_codec *codec, | |
570 | unsigned int stream_tag, | |
571 | unsigned int format, | |
572 | struct snd_pcm_substream *substream) | |
573 | { | |
574 | struct via_spec *spec = codec->spec; | |
575 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, | |
576 | stream_tag, format, substream); | |
577 | } | |
578 | ||
579 | static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
580 | struct hda_codec *codec, | |
581 | struct snd_pcm_substream *substream) | |
582 | { | |
583 | struct via_spec *spec = codec->spec; | |
584 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
585 | } | |
586 | ||
0aa62aef HW |
587 | |
588 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, | |
589 | unsigned int stream_tag, | |
590 | unsigned int format, | |
591 | struct snd_pcm_substream *substream) | |
592 | { | |
593 | struct via_spec *spec = codec->spec; | |
594 | struct hda_multi_out *mout = &spec->multiout; | |
595 | hda_nid_t *nids = mout->dac_nids; | |
596 | int chs = substream->runtime->channels; | |
597 | int i; | |
598 | ||
599 | mutex_lock(&codec->spdif_mutex); | |
600 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { | |
601 | if (chs == 2 && | |
602 | snd_hda_is_supported_format(codec, mout->dig_out_nid, | |
603 | format) && | |
604 | !(codec->spdif_status & IEC958_AES0_NONAUDIO)) { | |
605 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; | |
606 | /* turn off SPDIF once; otherwise the IEC958 bits won't | |
607 | * be updated */ | |
608 | if (codec->spdif_ctls & AC_DIG1_ENABLE) | |
609 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, | |
610 | AC_VERB_SET_DIGI_CONVERT_1, | |
611 | codec->spdif_ctls & | |
612 | ~AC_DIG1_ENABLE & 0xff); | |
613 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
614 | stream_tag, 0, format); | |
615 | /* turn on again (if needed) */ | |
616 | if (codec->spdif_ctls & AC_DIG1_ENABLE) | |
617 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, | |
618 | AC_VERB_SET_DIGI_CONVERT_1, | |
619 | codec->spdif_ctls & 0xff); | |
620 | } else { | |
621 | mout->dig_out_used = 0; | |
622 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
623 | 0, 0, 0); | |
624 | } | |
625 | } | |
626 | mutex_unlock(&codec->spdif_mutex); | |
627 | ||
628 | /* front */ | |
629 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, | |
630 | 0, format); | |
631 | ||
632 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && | |
633 | !spec->hp_independent_mode) | |
634 | /* headphone out will just decode front left/right (stereo) */ | |
635 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, | |
636 | 0, format); | |
637 | ||
638 | /* extra outputs copied from front */ | |
639 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) | |
640 | if (mout->extra_out_nid[i]) | |
641 | snd_hda_codec_setup_stream(codec, | |
642 | mout->extra_out_nid[i], | |
643 | stream_tag, 0, format); | |
644 | ||
645 | /* surrounds */ | |
646 | for (i = 1; i < mout->num_dacs; i++) { | |
647 | if (chs >= (i + 1) * 2) /* independent out */ | |
648 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, | |
649 | i * 2, format); | |
650 | else /* copy front */ | |
651 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, | |
652 | 0, format); | |
653 | } | |
654 | } | |
655 | ||
656 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, | |
657 | struct hda_codec *codec, | |
658 | unsigned int stream_tag, | |
659 | unsigned int format, | |
660 | struct snd_pcm_substream *substream) | |
661 | { | |
662 | struct via_spec *spec = codec->spec; | |
663 | struct hda_multi_out *mout = &spec->multiout; | |
664 | hda_nid_t *nids = mout->dac_nids; | |
665 | ||
666 | if (substream->number == 0) | |
667 | playback_multi_pcm_prep_0(codec, stream_tag, format, | |
668 | substream); | |
669 | else { | |
670 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && | |
671 | spec->hp_independent_mode) | |
672 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
673 | stream_tag, 0, format); | |
674 | } | |
675 | ||
676 | return 0; | |
677 | } | |
678 | ||
679 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
680 | struct hda_codec *codec, | |
681 | struct snd_pcm_substream *substream) | |
682 | { | |
683 | struct via_spec *spec = codec->spec; | |
684 | struct hda_multi_out *mout = &spec->multiout; | |
685 | hda_nid_t *nids = mout->dac_nids; | |
686 | int i; | |
687 | ||
688 | if (substream->number == 0) { | |
689 | for (i = 0; i < mout->num_dacs; i++) | |
690 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); | |
691 | ||
692 | if (mout->hp_nid && !spec->hp_independent_mode) | |
693 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
694 | 0, 0, 0); | |
695 | ||
696 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) | |
697 | if (mout->extra_out_nid[i]) | |
698 | snd_hda_codec_setup_stream(codec, | |
699 | mout->extra_out_nid[i], | |
700 | 0, 0, 0); | |
701 | mutex_lock(&codec->spdif_mutex); | |
702 | if (mout->dig_out_nid && | |
703 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { | |
704 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, | |
705 | 0, 0, 0); | |
706 | mout->dig_out_used = 0; | |
707 | } | |
708 | mutex_unlock(&codec->spdif_mutex); | |
709 | } else { | |
710 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && | |
711 | spec->hp_independent_mode) | |
712 | snd_hda_codec_setup_stream(codec, mout->hp_nid, | |
713 | 0, 0, 0); | |
714 | } | |
715 | ||
716 | return 0; | |
717 | } | |
718 | ||
c577b8a1 JC |
719 | /* |
720 | * Digital out | |
721 | */ | |
722 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
723 | struct hda_codec *codec, | |
724 | struct snd_pcm_substream *substream) | |
725 | { | |
726 | struct via_spec *spec = codec->spec; | |
727 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
728 | } | |
729 | ||
730 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
731 | struct hda_codec *codec, | |
732 | struct snd_pcm_substream *substream) | |
733 | { | |
734 | struct via_spec *spec = codec->spec; | |
735 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
736 | } | |
737 | ||
5691ec7f | 738 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
98aa34c0 HW |
739 | struct hda_codec *codec, |
740 | unsigned int stream_tag, | |
741 | unsigned int format, | |
742 | struct snd_pcm_substream *substream) | |
743 | { | |
744 | struct via_spec *spec = codec->spec; | |
9da29271 TI |
745 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
746 | stream_tag, format, substream); | |
747 | } | |
98aa34c0 | 748 | |
9da29271 TI |
749 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
750 | struct hda_codec *codec, | |
751 | struct snd_pcm_substream *substream) | |
752 | { | |
753 | struct via_spec *spec = codec->spec; | |
754 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); | |
98aa34c0 HW |
755 | return 0; |
756 | } | |
757 | ||
c577b8a1 JC |
758 | /* |
759 | * Analog capture | |
760 | */ | |
761 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
762 | struct hda_codec *codec, | |
763 | unsigned int stream_tag, | |
764 | unsigned int format, | |
765 | struct snd_pcm_substream *substream) | |
766 | { | |
767 | struct via_spec *spec = codec->spec; | |
768 | ||
769 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], | |
770 | stream_tag, 0, format); | |
771 | return 0; | |
772 | } | |
773 | ||
774 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
775 | struct hda_codec *codec, | |
776 | struct snd_pcm_substream *substream) | |
777 | { | |
778 | struct via_spec *spec = codec->spec; | |
888afa15 | 779 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
c577b8a1 JC |
780 | return 0; |
781 | } | |
782 | ||
783 | static struct hda_pcm_stream vt1708_pcm_analog_playback = { | |
0aa62aef | 784 | .substreams = 2, |
c577b8a1 JC |
785 | .channels_min = 2, |
786 | .channels_max = 8, | |
787 | .nid = 0x10, /* NID to query formats and rates */ | |
788 | .ops = { | |
789 | .open = via_playback_pcm_open, | |
0aa62aef HW |
790 | .prepare = via_playback_multi_pcm_prepare, |
791 | .cleanup = via_playback_multi_pcm_cleanup | |
c577b8a1 JC |
792 | }, |
793 | }; | |
794 | ||
bc9b5623 TI |
795 | static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
796 | .substreams = 1, | |
797 | .channels_min = 2, | |
798 | .channels_max = 8, | |
799 | .nid = 0x10, /* NID to query formats and rates */ | |
800 | /* We got noisy outputs on the right channel on VT1708 when | |
801 | * 24bit samples are used. Until any workaround is found, | |
802 | * disable the 24bit format, so far. | |
803 | */ | |
804 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
805 | .ops = { | |
806 | .open = via_playback_pcm_open, | |
807 | .prepare = via_playback_pcm_prepare, | |
808 | .cleanup = via_playback_pcm_cleanup | |
809 | }, | |
810 | }; | |
811 | ||
c577b8a1 JC |
812 | static struct hda_pcm_stream vt1708_pcm_analog_capture = { |
813 | .substreams = 2, | |
814 | .channels_min = 2, | |
815 | .channels_max = 2, | |
816 | .nid = 0x15, /* NID to query formats and rates */ | |
817 | .ops = { | |
818 | .prepare = via_capture_pcm_prepare, | |
819 | .cleanup = via_capture_pcm_cleanup | |
820 | }, | |
821 | }; | |
822 | ||
823 | static struct hda_pcm_stream vt1708_pcm_digital_playback = { | |
824 | .substreams = 1, | |
825 | .channels_min = 2, | |
826 | .channels_max = 2, | |
827 | /* NID is set in via_build_pcms */ | |
828 | .ops = { | |
829 | .open = via_dig_playback_pcm_open, | |
6b97eb45 | 830 | .close = via_dig_playback_pcm_close, |
9da29271 TI |
831 | .prepare = via_dig_playback_pcm_prepare, |
832 | .cleanup = via_dig_playback_pcm_cleanup | |
c577b8a1 JC |
833 | }, |
834 | }; | |
835 | ||
836 | static struct hda_pcm_stream vt1708_pcm_digital_capture = { | |
837 | .substreams = 1, | |
838 | .channels_min = 2, | |
839 | .channels_max = 2, | |
840 | }; | |
841 | ||
842 | static int via_build_controls(struct hda_codec *codec) | |
843 | { | |
844 | struct via_spec *spec = codec->spec; | |
845 | int err; | |
846 | int i; | |
847 | ||
848 | for (i = 0; i < spec->num_mixers; i++) { | |
849 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
850 | if (err < 0) | |
851 | return err; | |
852 | } | |
853 | ||
854 | if (spec->multiout.dig_out_nid) { | |
855 | err = snd_hda_create_spdif_out_ctls(codec, | |
856 | spec->multiout.dig_out_nid); | |
857 | if (err < 0) | |
858 | return err; | |
9a08160b TI |
859 | err = snd_hda_create_spdif_share_sw(codec, |
860 | &spec->multiout); | |
861 | if (err < 0) | |
862 | return err; | |
863 | spec->multiout.share_spdif = 1; | |
c577b8a1 JC |
864 | } |
865 | if (spec->dig_in_nid) { | |
866 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
867 | if (err < 0) | |
868 | return err; | |
869 | } | |
603c4019 | 870 | via_free_kctls(codec); /* no longer needed */ |
c577b8a1 JC |
871 | return 0; |
872 | } | |
873 | ||
874 | static int via_build_pcms(struct hda_codec *codec) | |
875 | { | |
876 | struct via_spec *spec = codec->spec; | |
877 | struct hda_pcm *info = spec->pcm_rec; | |
878 | ||
879 | codec->num_pcms = 1; | |
880 | codec->pcm_info = info; | |
881 | ||
882 | info->name = spec->stream_name_analog; | |
883 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback); | |
884 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; | |
885 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); | |
886 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
887 | ||
888 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = | |
889 | spec->multiout.max_channels; | |
890 | ||
891 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { | |
892 | codec->num_pcms++; | |
893 | info++; | |
894 | info->name = spec->stream_name_digital; | |
7ba72ba1 | 895 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
c577b8a1 JC |
896 | if (spec->multiout.dig_out_nid) { |
897 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = | |
898 | *(spec->stream_digital_playback); | |
899 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = | |
900 | spec->multiout.dig_out_nid; | |
901 | } | |
902 | if (spec->dig_in_nid) { | |
903 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = | |
904 | *(spec->stream_digital_capture); | |
905 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = | |
906 | spec->dig_in_nid; | |
907 | } | |
908 | } | |
909 | ||
910 | return 0; | |
911 | } | |
912 | ||
913 | static void via_free(struct hda_codec *codec) | |
914 | { | |
915 | struct via_spec *spec = codec->spec; | |
c577b8a1 JC |
916 | |
917 | if (!spec) | |
918 | return; | |
919 | ||
603c4019 | 920 | via_free_kctls(codec); |
c577b8a1 JC |
921 | kfree(codec->spec); |
922 | } | |
923 | ||
69e52a80 HW |
924 | /* mute internal speaker if HP is plugged */ |
925 | static void via_hp_automute(struct hda_codec *codec) | |
926 | { | |
927 | unsigned int present; | |
928 | struct via_spec *spec = codec->spec; | |
929 | ||
930 | present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, | |
931 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
932 | snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], | |
933 | HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
934 | present ? HDA_AMP_MUTE : 0); | |
935 | } | |
936 | ||
937 | static void via_gpio_control(struct hda_codec *codec) | |
938 | { | |
939 | unsigned int gpio_data; | |
940 | unsigned int vol_counter; | |
941 | unsigned int vol; | |
942 | unsigned int master_vol; | |
943 | ||
944 | struct via_spec *spec = codec->spec; | |
945 | ||
946 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, | |
947 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; | |
948 | ||
949 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, | |
950 | 0xF84, 0) & 0x3F0000) >> 16; | |
951 | ||
952 | vol = vol_counter & 0x1F; | |
953 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, | |
954 | AC_VERB_GET_AMP_GAIN_MUTE, | |
955 | AC_AMP_GET_INPUT); | |
956 | ||
957 | if (gpio_data == 0x02) { | |
958 | /* unmute line out */ | |
959 | snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], | |
960 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); | |
961 | ||
962 | if (vol_counter & 0x20) { | |
963 | /* decrease volume */ | |
964 | if (vol > master_vol) | |
965 | vol = master_vol; | |
966 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, | |
967 | 0, HDA_AMP_VOLMASK, | |
968 | master_vol-vol); | |
969 | } else { | |
970 | /* increase volume */ | |
971 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, | |
972 | HDA_AMP_VOLMASK, | |
973 | ((master_vol+vol) > 0x2A) ? 0x2A : | |
974 | (master_vol+vol)); | |
975 | } | |
976 | } else if (!(gpio_data & 0x02)) { | |
977 | /* mute line out */ | |
978 | snd_hda_codec_amp_stereo(codec, | |
979 | spec->autocfg.line_out_pins[0], | |
980 | HDA_OUTPUT, 0, HDA_AMP_MUTE, | |
981 | HDA_AMP_MUTE); | |
982 | } | |
983 | } | |
984 | ||
985 | /* unsolicited event for jack sensing */ | |
986 | static void via_unsol_event(struct hda_codec *codec, | |
987 | unsigned int res) | |
988 | { | |
989 | res >>= 26; | |
990 | if (res == VIA_HP_EVENT) | |
991 | via_hp_automute(codec); | |
992 | else if (res == VIA_GPIO_EVENT) | |
993 | via_gpio_control(codec); | |
994 | } | |
995 | ||
c577b8a1 JC |
996 | static int via_init(struct hda_codec *codec) |
997 | { | |
998 | struct via_spec *spec = codec->spec; | |
69e52a80 HW |
999 | int i; |
1000 | for (i = 0; i < spec->num_iverbs; i++) | |
1001 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
1002 | ||
f7278fd0 JC |
1003 | /* Lydia Add for EAPD enable */ |
1004 | if (!spec->dig_in_nid) { /* No Digital In connection */ | |
55d1d6c1 TI |
1005 | if (spec->dig_in_pin) { |
1006 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, | |
f7278fd0 | 1007 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
12b74c80 | 1008 | PIN_OUT); |
55d1d6c1 | 1009 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
f7278fd0 JC |
1010 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
1011 | } | |
12b74c80 TI |
1012 | } else /* enable SPDIF-input pin */ |
1013 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, | |
1014 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); | |
f7278fd0 | 1015 | |
9da29271 TI |
1016 | /* assign slave outs */ |
1017 | if (spec->slave_dig_outs[0]) | |
1018 | codec->slave_dig_outs = spec->slave_dig_outs; | |
5691ec7f | 1019 | |
c577b8a1 JC |
1020 | return 0; |
1021 | } | |
1022 | ||
cb53c626 TI |
1023 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1024 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) | |
1025 | { | |
1026 | struct via_spec *spec = codec->spec; | |
1027 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); | |
1028 | } | |
1029 | #endif | |
1030 | ||
c577b8a1 JC |
1031 | /* |
1032 | */ | |
1033 | static struct hda_codec_ops via_patch_ops = { | |
1034 | .build_controls = via_build_controls, | |
1035 | .build_pcms = via_build_pcms, | |
1036 | .init = via_init, | |
1037 | .free = via_free, | |
cb53c626 TI |
1038 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1039 | .check_power_status = via_check_power_status, | |
1040 | #endif | |
c577b8a1 JC |
1041 | }; |
1042 | ||
1043 | /* fill in the dac_nids table from the parsed pin configuration */ | |
1044 | static int vt1708_auto_fill_dac_nids(struct via_spec *spec, | |
1045 | const struct auto_pin_cfg *cfg) | |
1046 | { | |
1047 | int i; | |
1048 | hda_nid_t nid; | |
1049 | ||
1050 | spec->multiout.num_dacs = cfg->line_outs; | |
1051 | ||
1052 | spec->multiout.dac_nids = spec->private_dac_nids; | |
1053 | ||
1054 | for(i = 0; i < 4; i++) { | |
1055 | nid = cfg->line_out_pins[i]; | |
1056 | if (nid) { | |
1057 | /* config dac list */ | |
1058 | switch (i) { | |
1059 | case AUTO_SEQ_FRONT: | |
1060 | spec->multiout.dac_nids[i] = 0x10; | |
1061 | break; | |
1062 | case AUTO_SEQ_CENLFE: | |
1063 | spec->multiout.dac_nids[i] = 0x12; | |
1064 | break; | |
1065 | case AUTO_SEQ_SURROUND: | |
fb4cb772 | 1066 | spec->multiout.dac_nids[i] = 0x11; |
c577b8a1 JC |
1067 | break; |
1068 | case AUTO_SEQ_SIDE: | |
fb4cb772 | 1069 | spec->multiout.dac_nids[i] = 0x13; |
c577b8a1 JC |
1070 | break; |
1071 | } | |
1072 | } | |
1073 | } | |
1074 | ||
1075 | return 0; | |
1076 | } | |
1077 | ||
1078 | /* add playback controls from the parsed DAC table */ | |
1079 | static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, | |
1080 | const struct auto_pin_cfg *cfg) | |
1081 | { | |
1082 | char name[32]; | |
1083 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | |
1084 | hda_nid_t nid, nid_vol = 0; | |
1085 | int i, err; | |
1086 | ||
1087 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
1088 | nid = cfg->line_out_pins[i]; | |
1089 | ||
1090 | if (!nid) | |
1091 | continue; | |
1092 | ||
1093 | if (i != AUTO_SEQ_FRONT) | |
fb4cb772 | 1094 | nid_vol = 0x18 + i; |
c577b8a1 JC |
1095 | |
1096 | if (i == AUTO_SEQ_CENLFE) { | |
1097 | /* Center/LFE */ | |
1098 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
f7278fd0 JC |
1099 | "Center Playback Volume", |
1100 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
1101 | HDA_OUTPUT)); | |
c577b8a1 JC |
1102 | if (err < 0) |
1103 | return err; | |
1104 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1105 | "LFE Playback Volume", | |
f7278fd0 JC |
1106 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
1107 | HDA_OUTPUT)); | |
c577b8a1 JC |
1108 | if (err < 0) |
1109 | return err; | |
1110 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1111 | "Center Playback Switch", | |
f7278fd0 JC |
1112 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
1113 | HDA_OUTPUT)); | |
c577b8a1 JC |
1114 | if (err < 0) |
1115 | return err; | |
1116 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1117 | "LFE Playback Switch", | |
f7278fd0 JC |
1118 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
1119 | HDA_OUTPUT)); | |
c577b8a1 JC |
1120 | if (err < 0) |
1121 | return err; | |
1122 | } else if (i == AUTO_SEQ_FRONT){ | |
1123 | /* add control to mixer index 0 */ | |
1124 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1125 | "Master Front Playback Volume", | |
f7278fd0 JC |
1126 | HDA_COMPOSE_AMP_VAL(0x17, 3, 0, |
1127 | HDA_INPUT)); | |
c577b8a1 JC |
1128 | if (err < 0) |
1129 | return err; | |
1130 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1131 | "Master Front Playback Switch", | |
f7278fd0 JC |
1132 | HDA_COMPOSE_AMP_VAL(0x17, 3, 0, |
1133 | HDA_INPUT)); | |
c577b8a1 JC |
1134 | if (err < 0) |
1135 | return err; | |
1136 | ||
1137 | /* add control to PW3 */ | |
1138 | sprintf(name, "%s Playback Volume", chname[i]); | |
1139 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
f7278fd0 JC |
1140 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
1141 | HDA_OUTPUT)); | |
c577b8a1 JC |
1142 | if (err < 0) |
1143 | return err; | |
1144 | sprintf(name, "%s Playback Switch", chname[i]); | |
1145 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
f7278fd0 JC |
1146 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
1147 | HDA_OUTPUT)); | |
c577b8a1 JC |
1148 | if (err < 0) |
1149 | return err; | |
1150 | } else { | |
1151 | sprintf(name, "%s Playback Volume", chname[i]); | |
1152 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
f7278fd0 JC |
1153 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1154 | HDA_OUTPUT)); | |
c577b8a1 JC |
1155 | if (err < 0) |
1156 | return err; | |
1157 | sprintf(name, "%s Playback Switch", chname[i]); | |
1158 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
f7278fd0 JC |
1159 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
1160 | HDA_OUTPUT)); | |
c577b8a1 JC |
1161 | if (err < 0) |
1162 | return err; | |
1163 | } | |
1164 | } | |
1165 | ||
1166 | return 0; | |
1167 | } | |
1168 | ||
0aa62aef HW |
1169 | static void create_hp_imux(struct via_spec *spec) |
1170 | { | |
1171 | int i; | |
1172 | struct hda_input_mux *imux = &spec->private_imux[1]; | |
1173 | static const char *texts[] = { "OFF", "ON", NULL}; | |
1174 | ||
1175 | /* for hp mode select */ | |
1176 | i = 0; | |
1177 | while (texts[i] != NULL) { | |
1178 | imux->items[imux->num_items].label = texts[i]; | |
1179 | imux->items[imux->num_items].index = i; | |
1180 | imux->num_items++; | |
1181 | i++; | |
1182 | } | |
1183 | ||
1184 | spec->hp_mux = &spec->private_imux[1]; | |
1185 | } | |
1186 | ||
c577b8a1 JC |
1187 | static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
1188 | { | |
1189 | int err; | |
1190 | ||
1191 | if (!pin) | |
1192 | return 0; | |
1193 | ||
1194 | spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ | |
1195 | ||
1196 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1197 | "Headphone Playback Volume", | |
1198 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
1199 | if (err < 0) | |
1200 | return err; | |
1201 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1202 | "Headphone Playback Switch", | |
1203 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
1204 | if (err < 0) | |
1205 | return err; | |
1206 | ||
0aa62aef HW |
1207 | create_hp_imux(spec); |
1208 | ||
c577b8a1 JC |
1209 | return 0; |
1210 | } | |
1211 | ||
1212 | /* create playback/capture controls for input pins */ | |
1213 | static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec, | |
1214 | const struct auto_pin_cfg *cfg) | |
1215 | { | |
1216 | static char *labels[] = { | |
1217 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | |
1218 | }; | |
0aa62aef | 1219 | struct hda_input_mux *imux = &spec->private_imux[0]; |
c577b8a1 JC |
1220 | int i, err, idx = 0; |
1221 | ||
1222 | /* for internal loopback recording select */ | |
1223 | imux->items[imux->num_items].label = "Stereo Mixer"; | |
1224 | imux->items[imux->num_items].index = idx; | |
1225 | imux->num_items++; | |
1226 | ||
1227 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
1228 | if (!cfg->input_pins[i]) | |
1229 | continue; | |
1230 | ||
1231 | switch (cfg->input_pins[i]) { | |
1232 | case 0x1d: /* Mic */ | |
1233 | idx = 2; | |
1234 | break; | |
1235 | ||
1236 | case 0x1e: /* Line In */ | |
1237 | idx = 3; | |
1238 | break; | |
1239 | ||
1240 | case 0x21: /* Front Mic */ | |
1241 | idx = 4; | |
1242 | break; | |
1243 | ||
1244 | case 0x24: /* CD */ | |
1245 | idx = 1; | |
1246 | break; | |
1247 | } | |
1248 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | |
1249 | idx, 0x17); | |
1250 | if (err < 0) | |
1251 | return err; | |
1252 | imux->items[imux->num_items].label = labels[i]; | |
1253 | imux->items[imux->num_items].index = idx; | |
1254 | imux->num_items++; | |
1255 | } | |
1256 | return 0; | |
1257 | } | |
1258 | ||
cb53c626 TI |
1259 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1260 | static struct hda_amp_list vt1708_loopbacks[] = { | |
1261 | { 0x17, HDA_INPUT, 1 }, | |
1262 | { 0x17, HDA_INPUT, 2 }, | |
1263 | { 0x17, HDA_INPUT, 3 }, | |
1264 | { 0x17, HDA_INPUT, 4 }, | |
1265 | { } /* end */ | |
1266 | }; | |
1267 | #endif | |
1268 | ||
76d9b0dd HW |
1269 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
1270 | { | |
1271 | unsigned int def_conf; | |
1272 | unsigned char seqassoc; | |
1273 | ||
2f334f92 | 1274 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
76d9b0dd HW |
1275 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
1276 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); | |
1277 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { | |
1278 | if (seqassoc == 0xff) { | |
1279 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); | |
2f334f92 | 1280 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
76d9b0dd HW |
1281 | } |
1282 | } | |
1283 | ||
1284 | return; | |
1285 | } | |
1286 | ||
c577b8a1 JC |
1287 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
1288 | { | |
1289 | struct via_spec *spec = codec->spec; | |
1290 | int err; | |
1291 | ||
76d9b0dd HW |
1292 | /* Add HP and CD pin config connect bit re-config action */ |
1293 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); | |
1294 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); | |
1295 | ||
c577b8a1 JC |
1296 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
1297 | if (err < 0) | |
1298 | return err; | |
1299 | err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg); | |
1300 | if (err < 0) | |
1301 | return err; | |
1302 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
1303 | return 0; /* can't find valid BIOS pin config */ | |
1304 | ||
1305 | err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
1306 | if (err < 0) | |
1307 | return err; | |
1308 | err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
1309 | if (err < 0) | |
1310 | return err; | |
1311 | err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); | |
1312 | if (err < 0) | |
1313 | return err; | |
1314 | ||
1315 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
1316 | ||
0852d7a6 | 1317 | if (spec->autocfg.dig_outs) |
c577b8a1 | 1318 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
55d1d6c1 | 1319 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
c577b8a1 JC |
1320 | if (spec->autocfg.dig_in_pin) |
1321 | spec->dig_in_nid = VT1708_DIGIN_NID; | |
1322 | ||
603c4019 TI |
1323 | if (spec->kctls.list) |
1324 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 1325 | |
69e52a80 | 1326 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
c577b8a1 | 1327 | |
0aa62aef HW |
1328 | spec->input_mux = &spec->private_imux[0]; |
1329 | ||
f8fdd495 HW |
1330 | if (spec->hp_mux) |
1331 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | |
c577b8a1 JC |
1332 | |
1333 | return 1; | |
1334 | } | |
1335 | ||
1336 | /* init callback for auto-configuration model -- overriding the default init */ | |
1337 | static int via_auto_init(struct hda_codec *codec) | |
1338 | { | |
1339 | via_init(codec); | |
1340 | via_auto_init_multi_out(codec); | |
1341 | via_auto_init_hp_out(codec); | |
1342 | via_auto_init_analog_input(codec); | |
1343 | return 0; | |
1344 | } | |
1345 | ||
1346 | static int patch_vt1708(struct hda_codec *codec) | |
1347 | { | |
1348 | struct via_spec *spec; | |
1349 | int err; | |
1350 | ||
1351 | /* create a codec specific record */ | |
eb14a46c | 1352 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
c577b8a1 JC |
1353 | if (spec == NULL) |
1354 | return -ENOMEM; | |
1355 | ||
1356 | codec->spec = spec; | |
1357 | ||
1358 | /* automatic parse from the BIOS config */ | |
1359 | err = vt1708_parse_auto_config(codec); | |
1360 | if (err < 0) { | |
1361 | via_free(codec); | |
1362 | return err; | |
1363 | } else if (!err) { | |
1364 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
1365 | "from BIOS. Using genenic mode...\n"); | |
1366 | } | |
1367 | ||
1368 | ||
1369 | spec->stream_name_analog = "VT1708 Analog"; | |
1370 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; | |
bc9b5623 TI |
1371 | /* disable 32bit format on VT1708 */ |
1372 | if (codec->vendor_id == 0x11061708) | |
1373 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; | |
c577b8a1 JC |
1374 | spec->stream_analog_capture = &vt1708_pcm_analog_capture; |
1375 | ||
1376 | spec->stream_name_digital = "VT1708 Digital"; | |
1377 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; | |
1378 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; | |
1379 | ||
1380 | ||
1381 | if (!spec->adc_nids && spec->input_mux) { | |
1382 | spec->adc_nids = vt1708_adc_nids; | |
1383 | spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); | |
1384 | spec->mixers[spec->num_mixers] = vt1708_capture_mixer; | |
1385 | spec->num_mixers++; | |
1386 | } | |
1387 | ||
1388 | codec->patch_ops = via_patch_ops; | |
1389 | ||
1390 | codec->patch_ops.init = via_auto_init; | |
cb53c626 TI |
1391 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1392 | spec->loopback.amplist = vt1708_loopbacks; | |
1393 | #endif | |
c577b8a1 JC |
1394 | |
1395 | return 0; | |
1396 | } | |
1397 | ||
1398 | /* capture mixer elements */ | |
1399 | static struct snd_kcontrol_new vt1709_capture_mixer[] = { | |
1400 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), | |
1401 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), | |
1402 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), | |
1403 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), | |
1404 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), | |
1405 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), | |
1406 | { | |
1407 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1408 | /* The multiple "Capture Source" controls confuse alsamixer | |
1409 | * So call somewhat different.. | |
c577b8a1 JC |
1410 | */ |
1411 | /* .name = "Capture Source", */ | |
1412 | .name = "Input Source", | |
1413 | .count = 1, | |
1414 | .info = via_mux_enum_info, | |
1415 | .get = via_mux_enum_get, | |
1416 | .put = via_mux_enum_put, | |
1417 | }, | |
1418 | { } /* end */ | |
1419 | }; | |
1420 | ||
69e52a80 HW |
1421 | static struct hda_verb vt1709_uniwill_init_verbs[] = { |
1422 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | |
1423 | { } | |
1424 | }; | |
1425 | ||
c577b8a1 JC |
1426 | /* |
1427 | * generic initialization of ADC, input mixers and output mixers | |
1428 | */ | |
1429 | static struct hda_verb vt1709_10ch_volume_init_verbs[] = { | |
1430 | /* | |
1431 | * Unmute ADC0-2 and set the default input to mic-in | |
1432 | */ | |
1433 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1434 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1435 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1436 | ||
1437 | ||
f7278fd0 | 1438 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
c577b8a1 JC |
1439 | * mixer widget |
1440 | */ | |
1441 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
f7278fd0 JC |
1442 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
1443 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
1444 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
1445 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
1446 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
c577b8a1 JC |
1447 | |
1448 | /* | |
1449 | * Set up output selector (0x1a, 0x1b, 0x29) | |
1450 | */ | |
1451 | /* set vol=0 to output mixers */ | |
1452 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1453 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1454 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1455 | ||
1456 | /* | |
1457 | * Unmute PW3 and PW4 | |
1458 | */ | |
1459 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1460 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1461 | ||
1462 | /* Set input of PW4 as AOW4 */ | |
1463 | {0x20, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
c577b8a1 JC |
1464 | /* PW9 Output enable */ |
1465 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
1466 | { } | |
1467 | }; | |
1468 | ||
1469 | static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { | |
1470 | .substreams = 1, | |
1471 | .channels_min = 2, | |
1472 | .channels_max = 10, | |
1473 | .nid = 0x10, /* NID to query formats and rates */ | |
1474 | .ops = { | |
1475 | .open = via_playback_pcm_open, | |
1476 | .prepare = via_playback_pcm_prepare, | |
1477 | .cleanup = via_playback_pcm_cleanup | |
1478 | }, | |
1479 | }; | |
1480 | ||
1481 | static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { | |
1482 | .substreams = 1, | |
1483 | .channels_min = 2, | |
1484 | .channels_max = 6, | |
1485 | .nid = 0x10, /* NID to query formats and rates */ | |
1486 | .ops = { | |
1487 | .open = via_playback_pcm_open, | |
1488 | .prepare = via_playback_pcm_prepare, | |
1489 | .cleanup = via_playback_pcm_cleanup | |
1490 | }, | |
1491 | }; | |
1492 | ||
1493 | static struct hda_pcm_stream vt1709_pcm_analog_capture = { | |
1494 | .substreams = 2, | |
1495 | .channels_min = 2, | |
1496 | .channels_max = 2, | |
1497 | .nid = 0x14, /* NID to query formats and rates */ | |
1498 | .ops = { | |
1499 | .prepare = via_capture_pcm_prepare, | |
1500 | .cleanup = via_capture_pcm_cleanup | |
1501 | }, | |
1502 | }; | |
1503 | ||
1504 | static struct hda_pcm_stream vt1709_pcm_digital_playback = { | |
1505 | .substreams = 1, | |
1506 | .channels_min = 2, | |
1507 | .channels_max = 2, | |
1508 | /* NID is set in via_build_pcms */ | |
1509 | .ops = { | |
1510 | .open = via_dig_playback_pcm_open, | |
1511 | .close = via_dig_playback_pcm_close | |
1512 | }, | |
1513 | }; | |
1514 | ||
1515 | static struct hda_pcm_stream vt1709_pcm_digital_capture = { | |
1516 | .substreams = 1, | |
1517 | .channels_min = 2, | |
1518 | .channels_max = 2, | |
1519 | }; | |
1520 | ||
1521 | static int vt1709_auto_fill_dac_nids(struct via_spec *spec, | |
1522 | const struct auto_pin_cfg *cfg) | |
1523 | { | |
1524 | int i; | |
1525 | hda_nid_t nid; | |
1526 | ||
1527 | if (cfg->line_outs == 4) /* 10 channels */ | |
1528 | spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */ | |
1529 | else if (cfg->line_outs == 3) /* 6 channels */ | |
1530 | spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */ | |
1531 | ||
1532 | spec->multiout.dac_nids = spec->private_dac_nids; | |
1533 | ||
1534 | if (cfg->line_outs == 4) { /* 10 channels */ | |
1535 | for (i = 0; i < cfg->line_outs; i++) { | |
1536 | nid = cfg->line_out_pins[i]; | |
1537 | if (nid) { | |
1538 | /* config dac list */ | |
1539 | switch (i) { | |
1540 | case AUTO_SEQ_FRONT: | |
1541 | /* AOW0 */ | |
1542 | spec->multiout.dac_nids[i] = 0x10; | |
1543 | break; | |
1544 | case AUTO_SEQ_CENLFE: | |
1545 | /* AOW2 */ | |
1546 | spec->multiout.dac_nids[i] = 0x12; | |
1547 | break; | |
1548 | case AUTO_SEQ_SURROUND: | |
1549 | /* AOW3 */ | |
fb4cb772 | 1550 | spec->multiout.dac_nids[i] = 0x11; |
c577b8a1 JC |
1551 | break; |
1552 | case AUTO_SEQ_SIDE: | |
1553 | /* AOW1 */ | |
fb4cb772 | 1554 | spec->multiout.dac_nids[i] = 0x27; |
c577b8a1 JC |
1555 | break; |
1556 | default: | |
1557 | break; | |
1558 | } | |
1559 | } | |
1560 | } | |
1561 | spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ | |
1562 | ||
1563 | } else if (cfg->line_outs == 3) { /* 6 channels */ | |
1564 | for(i = 0; i < cfg->line_outs; i++) { | |
1565 | nid = cfg->line_out_pins[i]; | |
1566 | if (nid) { | |
1567 | /* config dac list */ | |
1568 | switch(i) { | |
1569 | case AUTO_SEQ_FRONT: | |
1570 | /* AOW0 */ | |
1571 | spec->multiout.dac_nids[i] = 0x10; | |
1572 | break; | |
1573 | case AUTO_SEQ_CENLFE: | |
1574 | /* AOW2 */ | |
1575 | spec->multiout.dac_nids[i] = 0x12; | |
1576 | break; | |
1577 | case AUTO_SEQ_SURROUND: | |
1578 | /* AOW1 */ | |
1579 | spec->multiout.dac_nids[i] = 0x11; | |
1580 | break; | |
1581 | default: | |
1582 | break; | |
1583 | } | |
1584 | } | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | return 0; | |
1589 | } | |
1590 | ||
1591 | /* add playback controls from the parsed DAC table */ | |
1592 | static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, | |
1593 | const struct auto_pin_cfg *cfg) | |
1594 | { | |
1595 | char name[32]; | |
1596 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | |
1597 | hda_nid_t nid = 0; | |
1598 | int i, err; | |
1599 | ||
1600 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
1601 | nid = cfg->line_out_pins[i]; | |
1602 | ||
1603 | if (!nid) | |
1604 | continue; | |
1605 | ||
1606 | if (i == AUTO_SEQ_CENLFE) { | |
1607 | /* Center/LFE */ | |
1608 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1609 | "Center Playback Volume", | |
f7278fd0 JC |
1610 | HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, |
1611 | HDA_OUTPUT)); | |
c577b8a1 JC |
1612 | if (err < 0) |
1613 | return err; | |
1614 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1615 | "LFE Playback Volume", | |
f7278fd0 JC |
1616 | HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, |
1617 | HDA_OUTPUT)); | |
c577b8a1 JC |
1618 | if (err < 0) |
1619 | return err; | |
1620 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1621 | "Center Playback Switch", | |
f7278fd0 JC |
1622 | HDA_COMPOSE_AMP_VAL(0x1b, 1, 0, |
1623 | HDA_OUTPUT)); | |
c577b8a1 JC |
1624 | if (err < 0) |
1625 | return err; | |
1626 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1627 | "LFE Playback Switch", | |
f7278fd0 JC |
1628 | HDA_COMPOSE_AMP_VAL(0x1b, 2, 0, |
1629 | HDA_OUTPUT)); | |
c577b8a1 JC |
1630 | if (err < 0) |
1631 | return err; | |
1632 | } else if (i == AUTO_SEQ_FRONT){ | |
1633 | /* add control to mixer index 0 */ | |
1634 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1635 | "Master Front Playback Volume", | |
f7278fd0 JC |
1636 | HDA_COMPOSE_AMP_VAL(0x18, 3, 0, |
1637 | HDA_INPUT)); | |
c577b8a1 JC |
1638 | if (err < 0) |
1639 | return err; | |
1640 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1641 | "Master Front Playback Switch", | |
f7278fd0 JC |
1642 | HDA_COMPOSE_AMP_VAL(0x18, 3, 0, |
1643 | HDA_INPUT)); | |
c577b8a1 JC |
1644 | if (err < 0) |
1645 | return err; | |
1646 | ||
1647 | /* add control to PW3 */ | |
1648 | sprintf(name, "%s Playback Volume", chname[i]); | |
1649 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
f7278fd0 JC |
1650 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
1651 | HDA_OUTPUT)); | |
c577b8a1 JC |
1652 | if (err < 0) |
1653 | return err; | |
1654 | sprintf(name, "%s Playback Switch", chname[i]); | |
1655 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
f7278fd0 JC |
1656 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
1657 | HDA_OUTPUT)); | |
c577b8a1 JC |
1658 | if (err < 0) |
1659 | return err; | |
1660 | } else if (i == AUTO_SEQ_SURROUND) { | |
1661 | sprintf(name, "%s Playback Volume", chname[i]); | |
1662 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
fb4cb772 | 1663 | HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, |
f7278fd0 | 1664 | HDA_OUTPUT)); |
c577b8a1 JC |
1665 | if (err < 0) |
1666 | return err; | |
1667 | sprintf(name, "%s Playback Switch", chname[i]); | |
1668 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
fb4cb772 | 1669 | HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, |
f7278fd0 | 1670 | HDA_OUTPUT)); |
c577b8a1 JC |
1671 | if (err < 0) |
1672 | return err; | |
1673 | } else if (i == AUTO_SEQ_SIDE) { | |
1674 | sprintf(name, "%s Playback Volume", chname[i]); | |
1675 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
fb4cb772 | 1676 | HDA_COMPOSE_AMP_VAL(0x29, 3, 0, |
f7278fd0 | 1677 | HDA_OUTPUT)); |
c577b8a1 JC |
1678 | if (err < 0) |
1679 | return err; | |
1680 | sprintf(name, "%s Playback Switch", chname[i]); | |
1681 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
fb4cb772 | 1682 | HDA_COMPOSE_AMP_VAL(0x29, 3, 0, |
f7278fd0 | 1683 | HDA_OUTPUT)); |
c577b8a1 JC |
1684 | if (err < 0) |
1685 | return err; | |
1686 | } | |
1687 | } | |
1688 | ||
1689 | return 0; | |
1690 | } | |
1691 | ||
1692 | static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
1693 | { | |
1694 | int err; | |
1695 | ||
1696 | if (!pin) | |
1697 | return 0; | |
1698 | ||
1699 | if (spec->multiout.num_dacs == 5) /* 10 channels */ | |
1700 | spec->multiout.hp_nid = VT1709_HP_DAC_NID; | |
1701 | else if (spec->multiout.num_dacs == 3) /* 6 channels */ | |
1702 | spec->multiout.hp_nid = 0; | |
1703 | ||
1704 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
1705 | "Headphone Playback Volume", | |
1706 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
1707 | if (err < 0) | |
1708 | return err; | |
1709 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
1710 | "Headphone Playback Switch", | |
1711 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
1712 | if (err < 0) | |
1713 | return err; | |
1714 | ||
1715 | return 0; | |
1716 | } | |
1717 | ||
1718 | /* create playback/capture controls for input pins */ | |
1719 | static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec, | |
1720 | const struct auto_pin_cfg *cfg) | |
1721 | { | |
1722 | static char *labels[] = { | |
1723 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | |
1724 | }; | |
0aa62aef | 1725 | struct hda_input_mux *imux = &spec->private_imux[0]; |
c577b8a1 JC |
1726 | int i, err, idx = 0; |
1727 | ||
1728 | /* for internal loopback recording select */ | |
1729 | imux->items[imux->num_items].label = "Stereo Mixer"; | |
1730 | imux->items[imux->num_items].index = idx; | |
1731 | imux->num_items++; | |
1732 | ||
1733 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
1734 | if (!cfg->input_pins[i]) | |
1735 | continue; | |
1736 | ||
1737 | switch (cfg->input_pins[i]) { | |
1738 | case 0x1d: /* Mic */ | |
1739 | idx = 2; | |
1740 | break; | |
1741 | ||
1742 | case 0x1e: /* Line In */ | |
1743 | idx = 3; | |
1744 | break; | |
1745 | ||
1746 | case 0x21: /* Front Mic */ | |
1747 | idx = 4; | |
1748 | break; | |
1749 | ||
1750 | case 0x23: /* CD */ | |
1751 | idx = 1; | |
1752 | break; | |
1753 | } | |
1754 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | |
1755 | idx, 0x18); | |
1756 | if (err < 0) | |
1757 | return err; | |
1758 | imux->items[imux->num_items].label = labels[i]; | |
1759 | imux->items[imux->num_items].index = idx; | |
1760 | imux->num_items++; | |
1761 | } | |
1762 | return 0; | |
1763 | } | |
1764 | ||
1765 | static int vt1709_parse_auto_config(struct hda_codec *codec) | |
1766 | { | |
1767 | struct via_spec *spec = codec->spec; | |
1768 | int err; | |
1769 | ||
1770 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
1771 | if (err < 0) | |
1772 | return err; | |
1773 | err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg); | |
1774 | if (err < 0) | |
1775 | return err; | |
1776 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
1777 | return 0; /* can't find valid BIOS pin config */ | |
1778 | ||
1779 | err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
1780 | if (err < 0) | |
1781 | return err; | |
1782 | err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
1783 | if (err < 0) | |
1784 | return err; | |
1785 | err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg); | |
1786 | if (err < 0) | |
1787 | return err; | |
1788 | ||
1789 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
1790 | ||
0852d7a6 | 1791 | if (spec->autocfg.dig_outs) |
c577b8a1 | 1792 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
55d1d6c1 | 1793 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
c577b8a1 JC |
1794 | if (spec->autocfg.dig_in_pin) |
1795 | spec->dig_in_nid = VT1709_DIGIN_NID; | |
1796 | ||
603c4019 TI |
1797 | if (spec->kctls.list) |
1798 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
c577b8a1 | 1799 | |
0aa62aef | 1800 | spec->input_mux = &spec->private_imux[0]; |
c577b8a1 | 1801 | |
f8fdd495 HW |
1802 | if (spec->hp_mux) |
1803 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | |
1804 | ||
c577b8a1 JC |
1805 | return 1; |
1806 | } | |
1807 | ||
cb53c626 TI |
1808 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1809 | static struct hda_amp_list vt1709_loopbacks[] = { | |
1810 | { 0x18, HDA_INPUT, 1 }, | |
1811 | { 0x18, HDA_INPUT, 2 }, | |
1812 | { 0x18, HDA_INPUT, 3 }, | |
1813 | { 0x18, HDA_INPUT, 4 }, | |
1814 | { } /* end */ | |
1815 | }; | |
1816 | #endif | |
1817 | ||
c577b8a1 JC |
1818 | static int patch_vt1709_10ch(struct hda_codec *codec) |
1819 | { | |
1820 | struct via_spec *spec; | |
1821 | int err; | |
1822 | ||
1823 | /* create a codec specific record */ | |
eb14a46c | 1824 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
c577b8a1 JC |
1825 | if (spec == NULL) |
1826 | return -ENOMEM; | |
1827 | ||
1828 | codec->spec = spec; | |
1829 | ||
1830 | err = vt1709_parse_auto_config(codec); | |
1831 | if (err < 0) { | |
1832 | via_free(codec); | |
1833 | return err; | |
1834 | } else if (!err) { | |
1835 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " | |
1836 | "Using genenic mode...\n"); | |
1837 | } | |
1838 | ||
69e52a80 HW |
1839 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
1840 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; | |
c577b8a1 JC |
1841 | |
1842 | spec->stream_name_analog = "VT1709 Analog"; | |
1843 | spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; | |
1844 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; | |
1845 | ||
1846 | spec->stream_name_digital = "VT1709 Digital"; | |
1847 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; | |
1848 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; | |
1849 | ||
1850 | ||
1851 | if (!spec->adc_nids && spec->input_mux) { | |
1852 | spec->adc_nids = vt1709_adc_nids; | |
1853 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); | |
1854 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; | |
1855 | spec->num_mixers++; | |
1856 | } | |
1857 | ||
1858 | codec->patch_ops = via_patch_ops; | |
1859 | ||
1860 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 1861 | codec->patch_ops.unsol_event = via_unsol_event; |
cb53c626 TI |
1862 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1863 | spec->loopback.amplist = vt1709_loopbacks; | |
1864 | #endif | |
c577b8a1 JC |
1865 | |
1866 | return 0; | |
1867 | } | |
1868 | /* | |
1869 | * generic initialization of ADC, input mixers and output mixers | |
1870 | */ | |
1871 | static struct hda_verb vt1709_6ch_volume_init_verbs[] = { | |
1872 | /* | |
1873 | * Unmute ADC0-2 and set the default input to mic-in | |
1874 | */ | |
1875 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1876 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1877 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1878 | ||
1879 | ||
1880 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
1881 | * mixer widget | |
1882 | */ | |
1883 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
1884 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1885 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
1886 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
1887 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
1888 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
1889 | ||
1890 | /* | |
1891 | * Set up output selector (0x1a, 0x1b, 0x29) | |
1892 | */ | |
1893 | /* set vol=0 to output mixers */ | |
1894 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1895 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1896 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1897 | ||
1898 | /* | |
1899 | * Unmute PW3 and PW4 | |
1900 | */ | |
1901 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1902 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1903 | ||
1904 | /* Set input of PW4 as MW0 */ | |
1905 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, | |
c577b8a1 JC |
1906 | /* PW9 Output enable */ |
1907 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
1908 | { } | |
1909 | }; | |
1910 | ||
1911 | static int patch_vt1709_6ch(struct hda_codec *codec) | |
1912 | { | |
1913 | struct via_spec *spec; | |
1914 | int err; | |
1915 | ||
1916 | /* create a codec specific record */ | |
eb14a46c | 1917 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
c577b8a1 JC |
1918 | if (spec == NULL) |
1919 | return -ENOMEM; | |
1920 | ||
1921 | codec->spec = spec; | |
1922 | ||
1923 | err = vt1709_parse_auto_config(codec); | |
1924 | if (err < 0) { | |
1925 | via_free(codec); | |
1926 | return err; | |
1927 | } else if (!err) { | |
1928 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " | |
1929 | "Using genenic mode...\n"); | |
1930 | } | |
1931 | ||
69e52a80 HW |
1932 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
1933 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; | |
c577b8a1 JC |
1934 | |
1935 | spec->stream_name_analog = "VT1709 Analog"; | |
1936 | spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; | |
1937 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; | |
1938 | ||
1939 | spec->stream_name_digital = "VT1709 Digital"; | |
1940 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; | |
1941 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; | |
1942 | ||
1943 | ||
1944 | if (!spec->adc_nids && spec->input_mux) { | |
1945 | spec->adc_nids = vt1709_adc_nids; | |
1946 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); | |
1947 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; | |
1948 | spec->num_mixers++; | |
1949 | } | |
1950 | ||
1951 | codec->patch_ops = via_patch_ops; | |
1952 | ||
1953 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 1954 | codec->patch_ops.unsol_event = via_unsol_event; |
cb53c626 TI |
1955 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
1956 | spec->loopback.amplist = vt1709_loopbacks; | |
1957 | #endif | |
f7278fd0 JC |
1958 | return 0; |
1959 | } | |
1960 | ||
1961 | /* capture mixer elements */ | |
1962 | static struct snd_kcontrol_new vt1708B_capture_mixer[] = { | |
1963 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), | |
1964 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | |
1965 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | |
1966 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | |
1967 | { | |
1968 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1969 | /* The multiple "Capture Source" controls confuse alsamixer | |
1970 | * So call somewhat different.. | |
f7278fd0 JC |
1971 | */ |
1972 | /* .name = "Capture Source", */ | |
1973 | .name = "Input Source", | |
1974 | .count = 1, | |
1975 | .info = via_mux_enum_info, | |
1976 | .get = via_mux_enum_get, | |
1977 | .put = via_mux_enum_put, | |
1978 | }, | |
1979 | { } /* end */ | |
1980 | }; | |
1981 | /* | |
1982 | * generic initialization of ADC, input mixers and output mixers | |
1983 | */ | |
1984 | static struct hda_verb vt1708B_8ch_volume_init_verbs[] = { | |
1985 | /* | |
1986 | * Unmute ADC0-1 and set the default input to mic-in | |
1987 | */ | |
1988 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1989 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1990 | ||
1991 | ||
1992 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
1993 | * mixer widget | |
1994 | */ | |
1995 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
1996 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1997 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
1998 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
1999 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2000 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2001 | ||
2002 | /* | |
2003 | * Set up output mixers | |
2004 | */ | |
2005 | /* set vol=0 to output mixers */ | |
2006 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2007 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2008 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2009 | ||
2010 | /* Setup default input to PW4 */ | |
2011 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
2012 | /* PW9 Output enable */ | |
2013 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2014 | /* PW10 Input enable */ | |
2015 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, | |
2016 | { } | |
2017 | }; | |
2018 | ||
2019 | static struct hda_verb vt1708B_4ch_volume_init_verbs[] = { | |
2020 | /* | |
2021 | * Unmute ADC0-1 and set the default input to mic-in | |
2022 | */ | |
2023 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2024 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2025 | ||
2026 | ||
2027 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2028 | * mixer widget | |
2029 | */ | |
2030 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2031 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2032 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2033 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2034 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2035 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2036 | ||
2037 | /* | |
2038 | * Set up output mixers | |
2039 | */ | |
2040 | /* set vol=0 to output mixers */ | |
2041 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2042 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2043 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2044 | ||
2045 | /* Setup default input of PW4 to MW0 */ | |
2046 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2047 | /* PW9 Output enable */ | |
2048 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2049 | /* PW10 Input enable */ | |
2050 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, | |
2051 | { } | |
2052 | }; | |
2053 | ||
69e52a80 HW |
2054 | static struct hda_verb vt1708B_uniwill_init_verbs[] = { |
2055 | {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | |
2056 | { } | |
2057 | }; | |
2058 | ||
f7278fd0 | 2059 | static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { |
0aa62aef | 2060 | .substreams = 2, |
f7278fd0 JC |
2061 | .channels_min = 2, |
2062 | .channels_max = 8, | |
2063 | .nid = 0x10, /* NID to query formats and rates */ | |
2064 | .ops = { | |
2065 | .open = via_playback_pcm_open, | |
0aa62aef HW |
2066 | .prepare = via_playback_multi_pcm_prepare, |
2067 | .cleanup = via_playback_multi_pcm_cleanup | |
f7278fd0 JC |
2068 | }, |
2069 | }; | |
2070 | ||
2071 | static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { | |
0aa62aef | 2072 | .substreams = 2, |
f7278fd0 JC |
2073 | .channels_min = 2, |
2074 | .channels_max = 4, | |
2075 | .nid = 0x10, /* NID to query formats and rates */ | |
2076 | .ops = { | |
2077 | .open = via_playback_pcm_open, | |
0aa62aef HW |
2078 | .prepare = via_playback_multi_pcm_prepare, |
2079 | .cleanup = via_playback_multi_pcm_cleanup | |
f7278fd0 JC |
2080 | }, |
2081 | }; | |
2082 | ||
2083 | static struct hda_pcm_stream vt1708B_pcm_analog_capture = { | |
2084 | .substreams = 2, | |
2085 | .channels_min = 2, | |
2086 | .channels_max = 2, | |
2087 | .nid = 0x13, /* NID to query formats and rates */ | |
2088 | .ops = { | |
2089 | .prepare = via_capture_pcm_prepare, | |
2090 | .cleanup = via_capture_pcm_cleanup | |
2091 | }, | |
2092 | }; | |
2093 | ||
2094 | static struct hda_pcm_stream vt1708B_pcm_digital_playback = { | |
2095 | .substreams = 1, | |
2096 | .channels_min = 2, | |
2097 | .channels_max = 2, | |
2098 | /* NID is set in via_build_pcms */ | |
2099 | .ops = { | |
2100 | .open = via_dig_playback_pcm_open, | |
2101 | .close = via_dig_playback_pcm_close, | |
9da29271 TI |
2102 | .prepare = via_dig_playback_pcm_prepare, |
2103 | .cleanup = via_dig_playback_pcm_cleanup | |
f7278fd0 JC |
2104 | }, |
2105 | }; | |
2106 | ||
2107 | static struct hda_pcm_stream vt1708B_pcm_digital_capture = { | |
2108 | .substreams = 1, | |
2109 | .channels_min = 2, | |
2110 | .channels_max = 2, | |
2111 | }; | |
2112 | ||
2113 | /* fill in the dac_nids table from the parsed pin configuration */ | |
2114 | static int vt1708B_auto_fill_dac_nids(struct via_spec *spec, | |
2115 | const struct auto_pin_cfg *cfg) | |
2116 | { | |
2117 | int i; | |
2118 | hda_nid_t nid; | |
2119 | ||
2120 | spec->multiout.num_dacs = cfg->line_outs; | |
2121 | ||
2122 | spec->multiout.dac_nids = spec->private_dac_nids; | |
2123 | ||
2124 | for (i = 0; i < 4; i++) { | |
2125 | nid = cfg->line_out_pins[i]; | |
2126 | if (nid) { | |
2127 | /* config dac list */ | |
2128 | switch (i) { | |
2129 | case AUTO_SEQ_FRONT: | |
2130 | spec->multiout.dac_nids[i] = 0x10; | |
2131 | break; | |
2132 | case AUTO_SEQ_CENLFE: | |
2133 | spec->multiout.dac_nids[i] = 0x24; | |
2134 | break; | |
2135 | case AUTO_SEQ_SURROUND: | |
fb4cb772 | 2136 | spec->multiout.dac_nids[i] = 0x11; |
f7278fd0 JC |
2137 | break; |
2138 | case AUTO_SEQ_SIDE: | |
fb4cb772 | 2139 | spec->multiout.dac_nids[i] = 0x25; |
f7278fd0 JC |
2140 | break; |
2141 | } | |
2142 | } | |
2143 | } | |
2144 | ||
2145 | return 0; | |
2146 | } | |
2147 | ||
2148 | /* add playback controls from the parsed DAC table */ | |
2149 | static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec, | |
2150 | const struct auto_pin_cfg *cfg) | |
2151 | { | |
2152 | char name[32]; | |
2153 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | |
fb4cb772 | 2154 | hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27}; |
f7278fd0 JC |
2155 | hda_nid_t nid, nid_vol = 0; |
2156 | int i, err; | |
2157 | ||
2158 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
2159 | nid = cfg->line_out_pins[i]; | |
2160 | ||
2161 | if (!nid) | |
2162 | continue; | |
2163 | ||
2164 | nid_vol = nid_vols[i]; | |
2165 | ||
2166 | if (i == AUTO_SEQ_CENLFE) { | |
2167 | /* Center/LFE */ | |
2168 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2169 | "Center Playback Volume", | |
2170 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
2171 | HDA_OUTPUT)); | |
2172 | if (err < 0) | |
2173 | return err; | |
2174 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2175 | "LFE Playback Volume", | |
2176 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
2177 | HDA_OUTPUT)); | |
2178 | if (err < 0) | |
2179 | return err; | |
2180 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2181 | "Center Playback Switch", | |
2182 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
2183 | HDA_OUTPUT)); | |
2184 | if (err < 0) | |
2185 | return err; | |
2186 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2187 | "LFE Playback Switch", | |
2188 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
2189 | HDA_OUTPUT)); | |
2190 | if (err < 0) | |
2191 | return err; | |
2192 | } else if (i == AUTO_SEQ_FRONT) { | |
2193 | /* add control to mixer index 0 */ | |
2194 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2195 | "Master Front Playback Volume", | |
2196 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
2197 | HDA_INPUT)); | |
2198 | if (err < 0) | |
2199 | return err; | |
2200 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2201 | "Master Front Playback Switch", | |
2202 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
2203 | HDA_INPUT)); | |
2204 | if (err < 0) | |
2205 | return err; | |
2206 | ||
2207 | /* add control to PW3 */ | |
2208 | sprintf(name, "%s Playback Volume", chname[i]); | |
2209 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
2210 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, | |
2211 | HDA_OUTPUT)); | |
2212 | if (err < 0) | |
2213 | return err; | |
2214 | sprintf(name, "%s Playback Switch", chname[i]); | |
2215 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
2216 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, | |
2217 | HDA_OUTPUT)); | |
2218 | if (err < 0) | |
2219 | return err; | |
2220 | } else { | |
2221 | sprintf(name, "%s Playback Volume", chname[i]); | |
2222 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
2223 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
2224 | HDA_OUTPUT)); | |
2225 | if (err < 0) | |
2226 | return err; | |
2227 | sprintf(name, "%s Playback Switch", chname[i]); | |
2228 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
2229 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
2230 | HDA_OUTPUT)); | |
2231 | if (err < 0) | |
2232 | return err; | |
2233 | } | |
2234 | } | |
2235 | ||
2236 | return 0; | |
2237 | } | |
2238 | ||
2239 | static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
2240 | { | |
2241 | int err; | |
2242 | ||
2243 | if (!pin) | |
2244 | return 0; | |
2245 | ||
2246 | spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ | |
2247 | ||
2248 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2249 | "Headphone Playback Volume", | |
2250 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
2251 | if (err < 0) | |
2252 | return err; | |
2253 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2254 | "Headphone Playback Switch", | |
2255 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
2256 | if (err < 0) | |
2257 | return err; | |
2258 | ||
0aa62aef HW |
2259 | create_hp_imux(spec); |
2260 | ||
f7278fd0 JC |
2261 | return 0; |
2262 | } | |
2263 | ||
2264 | /* create playback/capture controls for input pins */ | |
2265 | static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec, | |
2266 | const struct auto_pin_cfg *cfg) | |
2267 | { | |
2268 | static char *labels[] = { | |
2269 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | |
2270 | }; | |
0aa62aef | 2271 | struct hda_input_mux *imux = &spec->private_imux[0]; |
f7278fd0 JC |
2272 | int i, err, idx = 0; |
2273 | ||
2274 | /* for internal loopback recording select */ | |
2275 | imux->items[imux->num_items].label = "Stereo Mixer"; | |
2276 | imux->items[imux->num_items].index = idx; | |
2277 | imux->num_items++; | |
2278 | ||
2279 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
2280 | if (!cfg->input_pins[i]) | |
2281 | continue; | |
2282 | ||
2283 | switch (cfg->input_pins[i]) { | |
2284 | case 0x1a: /* Mic */ | |
2285 | idx = 2; | |
2286 | break; | |
2287 | ||
2288 | case 0x1b: /* Line In */ | |
2289 | idx = 3; | |
2290 | break; | |
2291 | ||
2292 | case 0x1e: /* Front Mic */ | |
2293 | idx = 4; | |
2294 | break; | |
2295 | ||
2296 | case 0x1f: /* CD */ | |
2297 | idx = 1; | |
2298 | break; | |
2299 | } | |
2300 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | |
2301 | idx, 0x16); | |
2302 | if (err < 0) | |
2303 | return err; | |
2304 | imux->items[imux->num_items].label = labels[i]; | |
2305 | imux->items[imux->num_items].index = idx; | |
2306 | imux->num_items++; | |
2307 | } | |
2308 | return 0; | |
2309 | } | |
2310 | ||
2311 | static int vt1708B_parse_auto_config(struct hda_codec *codec) | |
2312 | { | |
2313 | struct via_spec *spec = codec->spec; | |
2314 | int err; | |
2315 | ||
2316 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); | |
2317 | if (err < 0) | |
2318 | return err; | |
2319 | err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg); | |
2320 | if (err < 0) | |
2321 | return err; | |
2322 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
2323 | return 0; /* can't find valid BIOS pin config */ | |
2324 | ||
2325 | err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
2326 | if (err < 0) | |
2327 | return err; | |
2328 | err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
2329 | if (err < 0) | |
2330 | return err; | |
2331 | err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg); | |
2332 | if (err < 0) | |
2333 | return err; | |
2334 | ||
2335 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2336 | ||
0852d7a6 | 2337 | if (spec->autocfg.dig_outs) |
f7278fd0 | 2338 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
55d1d6c1 | 2339 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
f7278fd0 JC |
2340 | if (spec->autocfg.dig_in_pin) |
2341 | spec->dig_in_nid = VT1708B_DIGIN_NID; | |
2342 | ||
603c4019 TI |
2343 | if (spec->kctls.list) |
2344 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
f7278fd0 | 2345 | |
0aa62aef HW |
2346 | spec->input_mux = &spec->private_imux[0]; |
2347 | ||
f8fdd495 HW |
2348 | if (spec->hp_mux) |
2349 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | |
f7278fd0 JC |
2350 | |
2351 | return 1; | |
2352 | } | |
2353 | ||
2354 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
2355 | static struct hda_amp_list vt1708B_loopbacks[] = { | |
2356 | { 0x16, HDA_INPUT, 1 }, | |
2357 | { 0x16, HDA_INPUT, 2 }, | |
2358 | { 0x16, HDA_INPUT, 3 }, | |
2359 | { 0x16, HDA_INPUT, 4 }, | |
2360 | { } /* end */ | |
2361 | }; | |
2362 | #endif | |
2363 | ||
2364 | static int patch_vt1708B_8ch(struct hda_codec *codec) | |
2365 | { | |
2366 | struct via_spec *spec; | |
2367 | int err; | |
2368 | ||
2369 | /* create a codec specific record */ | |
eb14a46c | 2370 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
f7278fd0 JC |
2371 | if (spec == NULL) |
2372 | return -ENOMEM; | |
2373 | ||
2374 | codec->spec = spec; | |
2375 | ||
2376 | /* automatic parse from the BIOS config */ | |
2377 | err = vt1708B_parse_auto_config(codec); | |
2378 | if (err < 0) { | |
2379 | via_free(codec); | |
2380 | return err; | |
2381 | } else if (!err) { | |
2382 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
2383 | "from BIOS. Using genenic mode...\n"); | |
2384 | } | |
2385 | ||
69e52a80 HW |
2386 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
2387 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; | |
f7278fd0 JC |
2388 | |
2389 | spec->stream_name_analog = "VT1708B Analog"; | |
2390 | spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; | |
2391 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; | |
2392 | ||
2393 | spec->stream_name_digital = "VT1708B Digital"; | |
2394 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; | |
2395 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; | |
2396 | ||
2397 | if (!spec->adc_nids && spec->input_mux) { | |
2398 | spec->adc_nids = vt1708B_adc_nids; | |
2399 | spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); | |
2400 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; | |
2401 | spec->num_mixers++; | |
2402 | } | |
2403 | ||
2404 | codec->patch_ops = via_patch_ops; | |
2405 | ||
2406 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2407 | codec->patch_ops.unsol_event = via_unsol_event; |
f7278fd0 JC |
2408 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2409 | spec->loopback.amplist = vt1708B_loopbacks; | |
2410 | #endif | |
2411 | ||
2412 | return 0; | |
2413 | } | |
2414 | ||
2415 | static int patch_vt1708B_4ch(struct hda_codec *codec) | |
2416 | { | |
2417 | struct via_spec *spec; | |
2418 | int err; | |
2419 | ||
2420 | /* create a codec specific record */ | |
eb14a46c | 2421 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
f7278fd0 JC |
2422 | if (spec == NULL) |
2423 | return -ENOMEM; | |
2424 | ||
2425 | codec->spec = spec; | |
2426 | ||
2427 | /* automatic parse from the BIOS config */ | |
2428 | err = vt1708B_parse_auto_config(codec); | |
2429 | if (err < 0) { | |
2430 | via_free(codec); | |
2431 | return err; | |
2432 | } else if (!err) { | |
2433 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
2434 | "from BIOS. Using genenic mode...\n"); | |
2435 | } | |
2436 | ||
69e52a80 HW |
2437 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
2438 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; | |
f7278fd0 JC |
2439 | |
2440 | spec->stream_name_analog = "VT1708B Analog"; | |
2441 | spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; | |
2442 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; | |
2443 | ||
2444 | spec->stream_name_digital = "VT1708B Digital"; | |
2445 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; | |
2446 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; | |
2447 | ||
2448 | if (!spec->adc_nids && spec->input_mux) { | |
2449 | spec->adc_nids = vt1708B_adc_nids; | |
2450 | spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); | |
2451 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; | |
2452 | spec->num_mixers++; | |
2453 | } | |
2454 | ||
2455 | codec->patch_ops = via_patch_ops; | |
2456 | ||
2457 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2458 | codec->patch_ops.unsol_event = via_unsol_event; |
f7278fd0 JC |
2459 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2460 | spec->loopback.amplist = vt1708B_loopbacks; | |
2461 | #endif | |
c577b8a1 JC |
2462 | |
2463 | return 0; | |
2464 | } | |
2465 | ||
d949cac1 HW |
2466 | /* Patch for VT1708S */ |
2467 | ||
d7426329 HW |
2468 | /* VT1708S software backdoor based override for buggy hardware micboost |
2469 | * setting */ | |
2470 | #define MIC_BOOST_VOLUME(xname, nid) { \ | |
2471 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
2472 | .name = xname, \ | |
2473 | .index = 0, \ | |
2474 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ | |
2475 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ | |
2476 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \ | |
2477 | .info = mic_boost_volume_info, \ | |
2478 | .get = snd_hda_mixer_amp_volume_get, \ | |
2479 | .put = snd_hda_mixer_amp_volume_put, \ | |
2480 | .tlv = { .c = mic_boost_tlv }, \ | |
2481 | .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) } | |
2482 | ||
d949cac1 HW |
2483 | /* capture mixer elements */ |
2484 | static struct snd_kcontrol_new vt1708S_capture_mixer[] = { | |
2485 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), | |
2486 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), | |
2487 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), | |
2488 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), | |
d7426329 HW |
2489 | MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A), |
2490 | MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E), | |
d949cac1 HW |
2491 | { |
2492 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2493 | /* The multiple "Capture Source" controls confuse alsamixer | |
2494 | * So call somewhat different.. | |
2495 | */ | |
2496 | /* .name = "Capture Source", */ | |
2497 | .name = "Input Source", | |
2498 | .count = 1, | |
2499 | .info = via_mux_enum_info, | |
2500 | .get = via_mux_enum_get, | |
2501 | .put = via_mux_enum_put, | |
2502 | }, | |
2503 | { } /* end */ | |
2504 | }; | |
2505 | ||
2506 | static struct hda_verb vt1708S_volume_init_verbs[] = { | |
2507 | /* Unmute ADC0-1 and set the default input to mic-in */ | |
2508 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2509 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2510 | ||
2511 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the | |
2512 | * analog-loopback mixer widget */ | |
2513 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ | |
2514 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2515 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2516 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2517 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2518 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, | |
2519 | ||
2520 | /* Setup default input of PW4 to MW0 */ | |
2521 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
5691ec7f | 2522 | /* PW9, PW10 Output enable */ |
d949cac1 | 2523 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
5691ec7f | 2524 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
d7426329 HW |
2525 | /* Enable Mic Boost Volume backdoor */ |
2526 | {0x1, 0xf98, 0x1}, | |
d949cac1 HW |
2527 | { } |
2528 | }; | |
2529 | ||
69e52a80 HW |
2530 | static struct hda_verb vt1708S_uniwill_init_verbs[] = { |
2531 | {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | |
2532 | { } | |
2533 | }; | |
2534 | ||
d949cac1 HW |
2535 | static struct hda_pcm_stream vt1708S_pcm_analog_playback = { |
2536 | .substreams = 2, | |
2537 | .channels_min = 2, | |
2538 | .channels_max = 8, | |
2539 | .nid = 0x10, /* NID to query formats and rates */ | |
2540 | .ops = { | |
2541 | .open = via_playback_pcm_open, | |
2542 | .prepare = via_playback_pcm_prepare, | |
2543 | .cleanup = via_playback_pcm_cleanup | |
2544 | }, | |
2545 | }; | |
2546 | ||
2547 | static struct hda_pcm_stream vt1708S_pcm_analog_capture = { | |
2548 | .substreams = 2, | |
2549 | .channels_min = 2, | |
2550 | .channels_max = 2, | |
2551 | .nid = 0x13, /* NID to query formats and rates */ | |
2552 | .ops = { | |
2553 | .prepare = via_capture_pcm_prepare, | |
2554 | .cleanup = via_capture_pcm_cleanup | |
2555 | }, | |
2556 | }; | |
2557 | ||
2558 | static struct hda_pcm_stream vt1708S_pcm_digital_playback = { | |
9da29271 | 2559 | .substreams = 1, |
d949cac1 HW |
2560 | .channels_min = 2, |
2561 | .channels_max = 2, | |
2562 | /* NID is set in via_build_pcms */ | |
2563 | .ops = { | |
2564 | .open = via_dig_playback_pcm_open, | |
2565 | .close = via_dig_playback_pcm_close, | |
9da29271 TI |
2566 | .prepare = via_dig_playback_pcm_prepare, |
2567 | .cleanup = via_dig_playback_pcm_cleanup | |
d949cac1 HW |
2568 | }, |
2569 | }; | |
2570 | ||
2571 | /* fill in the dac_nids table from the parsed pin configuration */ | |
2572 | static int vt1708S_auto_fill_dac_nids(struct via_spec *spec, | |
2573 | const struct auto_pin_cfg *cfg) | |
2574 | { | |
2575 | int i; | |
2576 | hda_nid_t nid; | |
2577 | ||
2578 | spec->multiout.num_dacs = cfg->line_outs; | |
2579 | ||
2580 | spec->multiout.dac_nids = spec->private_dac_nids; | |
2581 | ||
2582 | for (i = 0; i < 4; i++) { | |
2583 | nid = cfg->line_out_pins[i]; | |
2584 | if (nid) { | |
2585 | /* config dac list */ | |
2586 | switch (i) { | |
2587 | case AUTO_SEQ_FRONT: | |
2588 | spec->multiout.dac_nids[i] = 0x10; | |
2589 | break; | |
2590 | case AUTO_SEQ_CENLFE: | |
2591 | spec->multiout.dac_nids[i] = 0x24; | |
2592 | break; | |
2593 | case AUTO_SEQ_SURROUND: | |
2594 | spec->multiout.dac_nids[i] = 0x11; | |
2595 | break; | |
2596 | case AUTO_SEQ_SIDE: | |
2597 | spec->multiout.dac_nids[i] = 0x25; | |
2598 | break; | |
2599 | } | |
2600 | } | |
2601 | } | |
2602 | ||
2603 | return 0; | |
2604 | } | |
2605 | ||
2606 | /* add playback controls from the parsed DAC table */ | |
2607 | static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec, | |
2608 | const struct auto_pin_cfg *cfg) | |
2609 | { | |
2610 | char name[32]; | |
2611 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; | |
2612 | hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25}; | |
2613 | hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27}; | |
2614 | hda_nid_t nid, nid_vol, nid_mute; | |
2615 | int i, err; | |
2616 | ||
2617 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { | |
2618 | nid = cfg->line_out_pins[i]; | |
2619 | ||
2620 | if (!nid) | |
2621 | continue; | |
2622 | ||
2623 | nid_vol = nid_vols[i]; | |
2624 | nid_mute = nid_mutes[i]; | |
2625 | ||
2626 | if (i == AUTO_SEQ_CENLFE) { | |
2627 | /* Center/LFE */ | |
2628 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2629 | "Center Playback Volume", | |
2630 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, | |
2631 | HDA_OUTPUT)); | |
2632 | if (err < 0) | |
2633 | return err; | |
2634 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2635 | "LFE Playback Volume", | |
2636 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, | |
2637 | HDA_OUTPUT)); | |
2638 | if (err < 0) | |
2639 | return err; | |
2640 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2641 | "Center Playback Switch", | |
2642 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
2643 | 1, 0, | |
2644 | HDA_OUTPUT)); | |
2645 | if (err < 0) | |
2646 | return err; | |
2647 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2648 | "LFE Playback Switch", | |
2649 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
2650 | 2, 0, | |
2651 | HDA_OUTPUT)); | |
2652 | if (err < 0) | |
2653 | return err; | |
2654 | } else if (i == AUTO_SEQ_FRONT) { | |
2655 | /* add control to mixer index 0 */ | |
2656 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2657 | "Master Front Playback Volume", | |
2658 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, | |
2659 | HDA_INPUT)); | |
2660 | if (err < 0) | |
2661 | return err; | |
2662 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2663 | "Master Front Playback Switch", | |
2664 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, | |
2665 | HDA_INPUT)); | |
2666 | if (err < 0) | |
2667 | return err; | |
2668 | ||
2669 | /* Front */ | |
2670 | sprintf(name, "%s Playback Volume", chname[i]); | |
2671 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
2672 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
2673 | HDA_OUTPUT)); | |
2674 | if (err < 0) | |
2675 | return err; | |
2676 | sprintf(name, "%s Playback Switch", chname[i]); | |
2677 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
2678 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
2679 | 3, 0, | |
2680 | HDA_OUTPUT)); | |
2681 | if (err < 0) | |
2682 | return err; | |
2683 | } else { | |
2684 | sprintf(name, "%s Playback Volume", chname[i]); | |
2685 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, | |
2686 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, | |
2687 | HDA_OUTPUT)); | |
2688 | if (err < 0) | |
2689 | return err; | |
2690 | sprintf(name, "%s Playback Switch", chname[i]); | |
2691 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, | |
2692 | HDA_COMPOSE_AMP_VAL(nid_mute, | |
2693 | 3, 0, | |
2694 | HDA_OUTPUT)); | |
2695 | if (err < 0) | |
2696 | return err; | |
2697 | } | |
2698 | } | |
2699 | ||
2700 | return 0; | |
2701 | } | |
2702 | ||
2703 | static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
2704 | { | |
2705 | int err; | |
2706 | ||
2707 | if (!pin) | |
2708 | return 0; | |
2709 | ||
2710 | spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ | |
2711 | ||
2712 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
2713 | "Headphone Playback Volume", | |
2714 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); | |
2715 | if (err < 0) | |
2716 | return err; | |
2717 | ||
2718 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
2719 | "Headphone Playback Switch", | |
2720 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
2721 | if (err < 0) | |
2722 | return err; | |
2723 | ||
0aa62aef HW |
2724 | create_hp_imux(spec); |
2725 | ||
d949cac1 HW |
2726 | return 0; |
2727 | } | |
2728 | ||
2729 | /* create playback/capture controls for input pins */ | |
2730 | static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec, | |
2731 | const struct auto_pin_cfg *cfg) | |
2732 | { | |
2733 | static char *labels[] = { | |
2734 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | |
2735 | }; | |
0aa62aef | 2736 | struct hda_input_mux *imux = &spec->private_imux[0]; |
d949cac1 HW |
2737 | int i, err, idx = 0; |
2738 | ||
2739 | /* for internal loopback recording select */ | |
2740 | imux->items[imux->num_items].label = "Stereo Mixer"; | |
2741 | imux->items[imux->num_items].index = 5; | |
2742 | imux->num_items++; | |
2743 | ||
2744 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
2745 | if (!cfg->input_pins[i]) | |
2746 | continue; | |
2747 | ||
2748 | switch (cfg->input_pins[i]) { | |
2749 | case 0x1a: /* Mic */ | |
2750 | idx = 2; | |
2751 | break; | |
2752 | ||
2753 | case 0x1b: /* Line In */ | |
2754 | idx = 3; | |
2755 | break; | |
2756 | ||
2757 | case 0x1e: /* Front Mic */ | |
2758 | idx = 4; | |
2759 | break; | |
2760 | ||
2761 | case 0x1f: /* CD */ | |
2762 | idx = 1; | |
2763 | break; | |
2764 | } | |
2765 | err = via_new_analog_input(spec, cfg->input_pins[i], labels[i], | |
2766 | idx, 0x16); | |
2767 | if (err < 0) | |
2768 | return err; | |
2769 | imux->items[imux->num_items].label = labels[i]; | |
2770 | imux->items[imux->num_items].index = idx-1; | |
2771 | imux->num_items++; | |
2772 | } | |
2773 | return 0; | |
2774 | } | |
2775 | ||
9da29271 TI |
2776 | /* fill out digital output widgets; one for master and one for slave outputs */ |
2777 | static void fill_dig_outs(struct hda_codec *codec) | |
2778 | { | |
2779 | struct via_spec *spec = codec->spec; | |
2780 | int i; | |
2781 | ||
2782 | for (i = 0; i < spec->autocfg.dig_outs; i++) { | |
2783 | hda_nid_t nid; | |
2784 | int conn; | |
2785 | ||
2786 | nid = spec->autocfg.dig_out_pins[i]; | |
2787 | if (!nid) | |
2788 | continue; | |
2789 | conn = snd_hda_get_connections(codec, nid, &nid, 1); | |
2790 | if (conn < 1) | |
2791 | continue; | |
2792 | if (!spec->multiout.dig_out_nid) | |
2793 | spec->multiout.dig_out_nid = nid; | |
2794 | else { | |
2795 | spec->slave_dig_outs[0] = nid; | |
2796 | break; /* at most two dig outs */ | |
2797 | } | |
2798 | } | |
2799 | } | |
2800 | ||
d949cac1 HW |
2801 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
2802 | { | |
2803 | struct via_spec *spec = codec->spec; | |
2804 | int err; | |
d949cac1 | 2805 | |
9da29271 | 2806 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
d949cac1 HW |
2807 | if (err < 0) |
2808 | return err; | |
2809 | err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg); | |
2810 | if (err < 0) | |
2811 | return err; | |
2812 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
2813 | return 0; /* can't find valid BIOS pin config */ | |
2814 | ||
2815 | err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg); | |
2816 | if (err < 0) | |
2817 | return err; | |
2818 | err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
2819 | if (err < 0) | |
2820 | return err; | |
2821 | err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg); | |
2822 | if (err < 0) | |
2823 | return err; | |
2824 | ||
2825 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2826 | ||
9da29271 | 2827 | fill_dig_outs(codec); |
98aa34c0 | 2828 | |
603c4019 TI |
2829 | if (spec->kctls.list) |
2830 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
d949cac1 | 2831 | |
0aa62aef HW |
2832 | spec->input_mux = &spec->private_imux[0]; |
2833 | ||
f8fdd495 HW |
2834 | if (spec->hp_mux) |
2835 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | |
d949cac1 HW |
2836 | |
2837 | return 1; | |
2838 | } | |
2839 | ||
2840 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
2841 | static struct hda_amp_list vt1708S_loopbacks[] = { | |
2842 | { 0x16, HDA_INPUT, 1 }, | |
2843 | { 0x16, HDA_INPUT, 2 }, | |
2844 | { 0x16, HDA_INPUT, 3 }, | |
2845 | { 0x16, HDA_INPUT, 4 }, | |
2846 | { } /* end */ | |
2847 | }; | |
2848 | #endif | |
2849 | ||
2850 | static int patch_vt1708S(struct hda_codec *codec) | |
2851 | { | |
2852 | struct via_spec *spec; | |
2853 | int err; | |
2854 | ||
2855 | /* create a codec specific record */ | |
2856 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
2857 | if (spec == NULL) | |
2858 | return -ENOMEM; | |
2859 | ||
2860 | codec->spec = spec; | |
2861 | ||
2862 | /* automatic parse from the BIOS config */ | |
2863 | err = vt1708S_parse_auto_config(codec); | |
2864 | if (err < 0) { | |
2865 | via_free(codec); | |
2866 | return err; | |
2867 | } else if (!err) { | |
2868 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
2869 | "from BIOS. Using genenic mode...\n"); | |
2870 | } | |
2871 | ||
69e52a80 HW |
2872 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
2873 | spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; | |
d949cac1 HW |
2874 | |
2875 | spec->stream_name_analog = "VT1708S Analog"; | |
2876 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; | |
2877 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; | |
2878 | ||
2879 | spec->stream_name_digital = "VT1708S Digital"; | |
2880 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; | |
2881 | ||
2882 | if (!spec->adc_nids && spec->input_mux) { | |
2883 | spec->adc_nids = vt1708S_adc_nids; | |
2884 | spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); | |
2885 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; | |
2886 | spec->num_mixers++; | |
2887 | } | |
2888 | ||
2889 | codec->patch_ops = via_patch_ops; | |
2890 | ||
2891 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 2892 | codec->patch_ops.unsol_event = via_unsol_event; |
d949cac1 HW |
2893 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
2894 | spec->loopback.amplist = vt1708S_loopbacks; | |
2895 | #endif | |
2896 | ||
2897 | return 0; | |
2898 | } | |
2899 | ||
2900 | /* Patch for VT1702 */ | |
2901 | ||
2902 | /* capture mixer elements */ | |
2903 | static struct snd_kcontrol_new vt1702_capture_mixer[] = { | |
2904 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), | |
2905 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), | |
2906 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), | |
2907 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), | |
2908 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), | |
2909 | HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), | |
2910 | HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, | |
2911 | HDA_INPUT), | |
2912 | { | |
2913 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
2914 | /* The multiple "Capture Source" controls confuse alsamixer | |
2915 | * So call somewhat different.. | |
2916 | */ | |
2917 | /* .name = "Capture Source", */ | |
2918 | .name = "Input Source", | |
2919 | .count = 1, | |
2920 | .info = via_mux_enum_info, | |
2921 | .get = via_mux_enum_get, | |
2922 | .put = via_mux_enum_put, | |
2923 | }, | |
2924 | { } /* end */ | |
2925 | }; | |
2926 | ||
2927 | static struct hda_verb vt1702_volume_init_verbs[] = { | |
2928 | /* | |
2929 | * Unmute ADC0-1 and set the default input to mic-in | |
2930 | */ | |
2931 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2932 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2933 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2934 | ||
2935 | ||
2936 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback | |
2937 | * mixer widget | |
2938 | */ | |
2939 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ | |
2940 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
2941 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
2942 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, | |
2943 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, | |
2944 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
2945 | ||
2946 | /* Setup default input of PW4 to MW0 */ | |
2947 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
2948 | /* PW6 PW7 Output enable */ | |
2949 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2950 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, | |
2951 | { } | |
2952 | }; | |
2953 | ||
69e52a80 HW |
2954 | static struct hda_verb vt1702_uniwill_init_verbs[] = { |
2955 | {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT}, | |
2956 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT}, | |
2957 | { } | |
2958 | }; | |
2959 | ||
d949cac1 | 2960 | static struct hda_pcm_stream vt1702_pcm_analog_playback = { |
0aa62aef | 2961 | .substreams = 2, |
d949cac1 HW |
2962 | .channels_min = 2, |
2963 | .channels_max = 2, | |
2964 | .nid = 0x10, /* NID to query formats and rates */ | |
2965 | .ops = { | |
2966 | .open = via_playback_pcm_open, | |
0aa62aef HW |
2967 | .prepare = via_playback_multi_pcm_prepare, |
2968 | .cleanup = via_playback_multi_pcm_cleanup | |
d949cac1 HW |
2969 | }, |
2970 | }; | |
2971 | ||
2972 | static struct hda_pcm_stream vt1702_pcm_analog_capture = { | |
2973 | .substreams = 3, | |
2974 | .channels_min = 2, | |
2975 | .channels_max = 2, | |
2976 | .nid = 0x12, /* NID to query formats and rates */ | |
2977 | .ops = { | |
2978 | .prepare = via_capture_pcm_prepare, | |
2979 | .cleanup = via_capture_pcm_cleanup | |
2980 | }, | |
2981 | }; | |
2982 | ||
2983 | static struct hda_pcm_stream vt1702_pcm_digital_playback = { | |
5691ec7f | 2984 | .substreams = 2, |
d949cac1 HW |
2985 | .channels_min = 2, |
2986 | .channels_max = 2, | |
2987 | /* NID is set in via_build_pcms */ | |
2988 | .ops = { | |
2989 | .open = via_dig_playback_pcm_open, | |
2990 | .close = via_dig_playback_pcm_close, | |
9da29271 TI |
2991 | .prepare = via_dig_playback_pcm_prepare, |
2992 | .cleanup = via_dig_playback_pcm_cleanup | |
d949cac1 HW |
2993 | }, |
2994 | }; | |
2995 | ||
2996 | /* fill in the dac_nids table from the parsed pin configuration */ | |
2997 | static int vt1702_auto_fill_dac_nids(struct via_spec *spec, | |
2998 | const struct auto_pin_cfg *cfg) | |
2999 | { | |
3000 | spec->multiout.num_dacs = 1; | |
3001 | spec->multiout.dac_nids = spec->private_dac_nids; | |
3002 | ||
3003 | if (cfg->line_out_pins[0]) { | |
3004 | /* config dac list */ | |
3005 | spec->multiout.dac_nids[0] = 0x10; | |
3006 | } | |
3007 | ||
3008 | return 0; | |
3009 | } | |
3010 | ||
3011 | /* add playback controls from the parsed DAC table */ | |
3012 | static int vt1702_auto_create_line_out_ctls(struct via_spec *spec, | |
3013 | const struct auto_pin_cfg *cfg) | |
3014 | { | |
3015 | int err; | |
3016 | ||
3017 | if (!cfg->line_out_pins[0]) | |
3018 | return -1; | |
3019 | ||
3020 | /* add control to mixer index 0 */ | |
3021 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3022 | "Master Front Playback Volume", | |
3023 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); | |
3024 | if (err < 0) | |
3025 | return err; | |
3026 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3027 | "Master Front Playback Switch", | |
3028 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); | |
3029 | if (err < 0) | |
3030 | return err; | |
3031 | ||
3032 | /* Front */ | |
3033 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3034 | "Front Playback Volume", | |
3035 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT)); | |
3036 | if (err < 0) | |
3037 | return err; | |
3038 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3039 | "Front Playback Switch", | |
3040 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT)); | |
3041 | if (err < 0) | |
3042 | return err; | |
3043 | ||
3044 | return 0; | |
3045 | } | |
3046 | ||
3047 | static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) | |
3048 | { | |
3049 | int err; | |
3050 | ||
3051 | if (!pin) | |
3052 | return 0; | |
3053 | ||
3054 | spec->multiout.hp_nid = 0x1D; | |
3055 | ||
3056 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, | |
3057 | "Headphone Playback Volume", | |
3058 | HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT)); | |
3059 | if (err < 0) | |
3060 | return err; | |
3061 | ||
3062 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, | |
3063 | "Headphone Playback Switch", | |
3064 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); | |
3065 | if (err < 0) | |
3066 | return err; | |
3067 | ||
0aa62aef HW |
3068 | create_hp_imux(spec); |
3069 | ||
d949cac1 HW |
3070 | return 0; |
3071 | } | |
3072 | ||
3073 | /* create playback/capture controls for input pins */ | |
3074 | static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec, | |
3075 | const struct auto_pin_cfg *cfg) | |
3076 | { | |
3077 | static char *labels[] = { | |
3078 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL | |
3079 | }; | |
0aa62aef | 3080 | struct hda_input_mux *imux = &spec->private_imux[0]; |
d949cac1 HW |
3081 | int i, err, idx = 0; |
3082 | ||
3083 | /* for internal loopback recording select */ | |
3084 | imux->items[imux->num_items].label = "Stereo Mixer"; | |
3085 | imux->items[imux->num_items].index = 3; | |
3086 | imux->num_items++; | |
3087 | ||
3088 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
3089 | if (!cfg->input_pins[i]) | |
3090 | continue; | |
3091 | ||
3092 | switch (cfg->input_pins[i]) { | |
3093 | case 0x14: /* Mic */ | |
3094 | idx = 1; | |
3095 | break; | |
3096 | ||
3097 | case 0x15: /* Line In */ | |
3098 | idx = 2; | |
3099 | break; | |
3100 | ||
3101 | case 0x18: /* Front Mic */ | |
3102 | idx = 3; | |
3103 | break; | |
3104 | } | |
3105 | err = via_new_analog_input(spec, cfg->input_pins[i], | |
3106 | labels[i], idx, 0x1A); | |
3107 | if (err < 0) | |
3108 | return err; | |
3109 | imux->items[imux->num_items].label = labels[i]; | |
3110 | imux->items[imux->num_items].index = idx-1; | |
3111 | imux->num_items++; | |
3112 | } | |
3113 | return 0; | |
3114 | } | |
3115 | ||
3116 | static int vt1702_parse_auto_config(struct hda_codec *codec) | |
3117 | { | |
3118 | struct via_spec *spec = codec->spec; | |
3119 | int err; | |
d949cac1 | 3120 | |
9da29271 | 3121 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
d949cac1 HW |
3122 | if (err < 0) |
3123 | return err; | |
3124 | err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg); | |
3125 | if (err < 0) | |
3126 | return err; | |
3127 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) | |
3128 | return 0; /* can't find valid BIOS pin config */ | |
3129 | ||
3130 | err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg); | |
3131 | if (err < 0) | |
3132 | return err; | |
3133 | err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); | |
3134 | if (err < 0) | |
3135 | return err; | |
3136 | err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); | |
3137 | if (err < 0) | |
3138 | return err; | |
3139 | ||
3140 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
3141 | ||
9da29271 | 3142 | fill_dig_outs(codec); |
98aa34c0 | 3143 | |
603c4019 TI |
3144 | if (spec->kctls.list) |
3145 | spec->mixers[spec->num_mixers++] = spec->kctls.list; | |
d949cac1 | 3146 | |
0aa62aef HW |
3147 | spec->input_mux = &spec->private_imux[0]; |
3148 | ||
f8fdd495 HW |
3149 | if (spec->hp_mux) |
3150 | spec->mixers[spec->num_mixers++] = via_hp_mixer; | |
d949cac1 HW |
3151 | |
3152 | return 1; | |
3153 | } | |
3154 | ||
3155 | #ifdef CONFIG_SND_HDA_POWER_SAVE | |
3156 | static struct hda_amp_list vt1702_loopbacks[] = { | |
3157 | { 0x1A, HDA_INPUT, 1 }, | |
3158 | { 0x1A, HDA_INPUT, 2 }, | |
3159 | { 0x1A, HDA_INPUT, 3 }, | |
3160 | { 0x1A, HDA_INPUT, 4 }, | |
3161 | { } /* end */ | |
3162 | }; | |
3163 | #endif | |
3164 | ||
3165 | static int patch_vt1702(struct hda_codec *codec) | |
3166 | { | |
3167 | struct via_spec *spec; | |
3168 | int err; | |
3169 | unsigned int response; | |
3170 | unsigned char control; | |
3171 | ||
3172 | /* create a codec specific record */ | |
3173 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
3174 | if (spec == NULL) | |
3175 | return -ENOMEM; | |
3176 | ||
3177 | codec->spec = spec; | |
3178 | ||
3179 | /* automatic parse from the BIOS config */ | |
3180 | err = vt1702_parse_auto_config(codec); | |
3181 | if (err < 0) { | |
3182 | via_free(codec); | |
3183 | return err; | |
3184 | } else if (!err) { | |
3185 | printk(KERN_INFO "hda_codec: Cannot set up configuration " | |
3186 | "from BIOS. Using genenic mode...\n"); | |
3187 | } | |
3188 | ||
69e52a80 HW |
3189 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
3190 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; | |
d949cac1 HW |
3191 | |
3192 | spec->stream_name_analog = "VT1702 Analog"; | |
3193 | spec->stream_analog_playback = &vt1702_pcm_analog_playback; | |
3194 | spec->stream_analog_capture = &vt1702_pcm_analog_capture; | |
3195 | ||
3196 | spec->stream_name_digital = "VT1702 Digital"; | |
3197 | spec->stream_digital_playback = &vt1702_pcm_digital_playback; | |
3198 | ||
3199 | if (!spec->adc_nids && spec->input_mux) { | |
3200 | spec->adc_nids = vt1702_adc_nids; | |
3201 | spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids); | |
3202 | spec->mixers[spec->num_mixers] = vt1702_capture_mixer; | |
3203 | spec->num_mixers++; | |
3204 | } | |
3205 | ||
3206 | codec->patch_ops = via_patch_ops; | |
3207 | ||
3208 | codec->patch_ops.init = via_auto_init; | |
69e52a80 | 3209 | codec->patch_ops.unsol_event = via_unsol_event; |
d949cac1 HW |
3210 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
3211 | spec->loopback.amplist = vt1702_loopbacks; | |
3212 | #endif | |
3213 | ||
3214 | /* Open backdoor */ | |
3215 | response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0); | |
3216 | control = (unsigned char)(response & 0xff); | |
3217 | control |= 0x3; | |
3218 | snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control); | |
3219 | ||
3220 | /* Enable GPIO 0&1 for volume&mute control */ | |
3221 | /* Enable GPIO 2 for DMIC-DATA */ | |
3222 | response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0); | |
3223 | control = (unsigned char)((response >> 16) & 0x3f); | |
3224 | snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control); | |
3225 | ||
3226 | return 0; | |
3227 | } | |
3228 | ||
c577b8a1 JC |
3229 | /* |
3230 | * patch entries | |
3231 | */ | |
1289e9e8 | 3232 | static struct hda_codec_preset snd_hda_preset_via[] = { |
3218c178 TI |
3233 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
3234 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, | |
3235 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, | |
3236 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, | |
3237 | { .id = 0x1106e710, .name = "VT1709 10-Ch", | |
f7278fd0 | 3238 | .patch = patch_vt1709_10ch}, |
3218c178 | 3239 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
f7278fd0 | 3240 | .patch = patch_vt1709_10ch}, |
3218c178 | 3241 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
f7278fd0 | 3242 | .patch = patch_vt1709_10ch}, |
3218c178 | 3243 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
f7278fd0 | 3244 | .patch = patch_vt1709_10ch}, |
3218c178 | 3245 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
f7278fd0 | 3246 | .patch = patch_vt1709_6ch}, |
3218c178 | 3247 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
f7278fd0 | 3248 | .patch = patch_vt1709_6ch}, |
3218c178 | 3249 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
f7278fd0 | 3250 | .patch = patch_vt1709_6ch}, |
3218c178 | 3251 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
f7278fd0 | 3252 | .patch = patch_vt1709_6ch}, |
3218c178 | 3253 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
f7278fd0 | 3254 | .patch = patch_vt1708B_8ch}, |
3218c178 | 3255 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
f7278fd0 | 3256 | .patch = patch_vt1708B_8ch}, |
3218c178 | 3257 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
f7278fd0 | 3258 | .patch = patch_vt1708B_8ch}, |
3218c178 | 3259 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
f7278fd0 | 3260 | .patch = patch_vt1708B_8ch}, |
3218c178 | 3261 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
f7278fd0 | 3262 | .patch = patch_vt1708B_4ch}, |
3218c178 | 3263 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
f7278fd0 | 3264 | .patch = patch_vt1708B_4ch}, |
3218c178 | 3265 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
f7278fd0 | 3266 | .patch = patch_vt1708B_4ch}, |
3218c178 | 3267 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
f7278fd0 | 3268 | .patch = patch_vt1708B_4ch}, |
3218c178 | 3269 | { .id = 0x11060397, .name = "VT1708S", |
d949cac1 | 3270 | .patch = patch_vt1708S}, |
3218c178 | 3271 | { .id = 0x11061397, .name = "VT1708S", |
d949cac1 | 3272 | .patch = patch_vt1708S}, |
3218c178 | 3273 | { .id = 0x11062397, .name = "VT1708S", |
d949cac1 | 3274 | .patch = patch_vt1708S}, |
3218c178 | 3275 | { .id = 0x11063397, .name = "VT1708S", |
d949cac1 | 3276 | .patch = patch_vt1708S}, |
3218c178 | 3277 | { .id = 0x11064397, .name = "VT1708S", |
d949cac1 | 3278 | .patch = patch_vt1708S}, |
3218c178 | 3279 | { .id = 0x11065397, .name = "VT1708S", |
d949cac1 | 3280 | .patch = patch_vt1708S}, |
3218c178 | 3281 | { .id = 0x11066397, .name = "VT1708S", |
d949cac1 | 3282 | .patch = patch_vt1708S}, |
3218c178 | 3283 | { .id = 0x11067397, .name = "VT1708S", |
d949cac1 | 3284 | .patch = patch_vt1708S}, |
3218c178 | 3285 | { .id = 0x11060398, .name = "VT1702", |
d949cac1 | 3286 | .patch = patch_vt1702}, |
3218c178 | 3287 | { .id = 0x11061398, .name = "VT1702", |
d949cac1 | 3288 | .patch = patch_vt1702}, |
3218c178 | 3289 | { .id = 0x11062398, .name = "VT1702", |
d949cac1 | 3290 | .patch = patch_vt1702}, |
3218c178 | 3291 | { .id = 0x11063398, .name = "VT1702", |
d949cac1 | 3292 | .patch = patch_vt1702}, |
3218c178 | 3293 | { .id = 0x11064398, .name = "VT1702", |
d949cac1 | 3294 | .patch = patch_vt1702}, |
3218c178 | 3295 | { .id = 0x11065398, .name = "VT1702", |
d949cac1 | 3296 | .patch = patch_vt1702}, |
3218c178 | 3297 | { .id = 0x11066398, .name = "VT1702", |
d949cac1 | 3298 | .patch = patch_vt1702}, |
3218c178 | 3299 | { .id = 0x11067398, .name = "VT1702", |
d949cac1 | 3300 | .patch = patch_vt1702}, |
c577b8a1 JC |
3301 | {} /* terminator */ |
3302 | }; | |
1289e9e8 TI |
3303 | |
3304 | MODULE_ALIAS("snd-hda-codec-id:1106*"); | |
3305 | ||
3306 | static struct hda_codec_preset_list via_list = { | |
3307 | .preset = snd_hda_preset_via, | |
3308 | .owner = THIS_MODULE, | |
3309 | }; | |
3310 | ||
3311 | MODULE_LICENSE("GPL"); | |
3312 | MODULE_DESCRIPTION("VIA HD-audio codec"); | |
3313 | ||
3314 | static int __init patch_via_init(void) | |
3315 | { | |
3316 | return snd_hda_add_codec_preset(&via_list); | |
3317 | } | |
3318 | ||
3319 | static void __exit patch_via_exit(void) | |
3320 | { | |
3321 | snd_hda_delete_codec_preset(&via_list); | |
3322 | } | |
3323 | ||
3324 | module_init(patch_via_init) | |
3325 | module_exit(patch_via_exit) |