Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
d32410b1 | 2 | * HD audio interface patch for AD1981HD, AD1983, AD1986A, AD1988 |
1da177e4 LT |
3 | * |
4 | * Copyright (c) 2005 Takashi Iwai <tiwai@suse.de> | |
5 | * | |
6 | * This driver is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This driver is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | */ | |
20 | ||
21 | #include <sound/driver.h> | |
22 | #include <linux/init.h> | |
23 | #include <linux/delay.h> | |
24 | #include <linux/slab.h> | |
25 | #include <linux/pci.h> | |
62932df8 IM |
26 | #include <linux/mutex.h> |
27 | ||
1da177e4 LT |
28 | #include <sound/core.h> |
29 | #include "hda_codec.h" | |
30 | #include "hda_local.h" | |
31 | ||
4a3fdf3d | 32 | struct ad198x_spec { |
c8b6bf9b | 33 | struct snd_kcontrol_new *mixers[5]; |
985be54b TI |
34 | int num_mixers; |
35 | ||
d32410b1 | 36 | const struct hda_verb *init_verbs[5]; /* initialization verbs |
985be54b TI |
37 | * don't forget NULL termination! |
38 | */ | |
39 | unsigned int num_init_verbs; | |
40 | ||
41 | /* playback */ | |
42 | struct hda_multi_out multiout; /* playback set-up | |
43 | * max_channels, dacs must be set | |
44 | * dig_out_nid and hp_nid are optional | |
45 | */ | |
fd66e0d0 | 46 | unsigned int cur_eapd; |
2125cad2 | 47 | unsigned int need_dac_fix; |
985be54b TI |
48 | |
49 | /* capture */ | |
50 | unsigned int num_adc_nids; | |
51 | hda_nid_t *adc_nids; | |
52 | hda_nid_t dig_in_nid; /* digital-in NID; optional */ | |
53 | ||
54 | /* capture source */ | |
4a3fdf3d | 55 | const struct hda_input_mux *input_mux; |
2e5b9567 | 56 | hda_nid_t *capsrc_nids; |
985be54b TI |
57 | unsigned int cur_mux[3]; |
58 | ||
59 | /* channel model */ | |
d2a6d7dc | 60 | const struct hda_channel_mode *channel_mode; |
985be54b TI |
61 | int num_channel_mode; |
62 | ||
63 | /* PCM information */ | |
64 | struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */ | |
65 | ||
62932df8 | 66 | struct mutex amp_mutex; /* PCM volume/mute control mutex */ |
4a3fdf3d | 67 | unsigned int spdif_route; |
d32410b1 TI |
68 | |
69 | /* dynamic controls, init_verbs and input_mux */ | |
70 | struct auto_pin_cfg autocfg; | |
71 | unsigned int num_kctl_alloc, num_kctl_used; | |
72 | struct snd_kcontrol_new *kctl_alloc; | |
73 | struct hda_input_mux private_imux; | |
74 | hda_nid_t private_dac_nids[4]; | |
1da177e4 LT |
75 | }; |
76 | ||
4a3fdf3d TI |
77 | /* |
78 | * input MUX handling (common part) | |
79 | */ | |
c8b6bf9b | 80 | static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
4a3fdf3d TI |
81 | { |
82 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
83 | struct ad198x_spec *spec = codec->spec; | |
84 | ||
85 | return snd_hda_input_mux_info(spec->input_mux, uinfo); | |
86 | } | |
87 | ||
c8b6bf9b | 88 | static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
4a3fdf3d TI |
89 | { |
90 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
91 | struct ad198x_spec *spec = codec->spec; | |
985be54b | 92 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
4a3fdf3d | 93 | |
985be54b | 94 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
4a3fdf3d TI |
95 | return 0; |
96 | } | |
97 | ||
c8b6bf9b | 98 | static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
4a3fdf3d TI |
99 | { |
100 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
101 | struct ad198x_spec *spec = codec->spec; | |
985be54b | 102 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
4a3fdf3d TI |
103 | |
104 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, | |
2e5b9567 TI |
105 | spec->capsrc_nids[adc_idx], |
106 | &spec->cur_mux[adc_idx]); | |
4a3fdf3d TI |
107 | } |
108 | ||
109 | /* | |
110 | * initialization (common callbacks) | |
111 | */ | |
112 | static int ad198x_init(struct hda_codec *codec) | |
113 | { | |
114 | struct ad198x_spec *spec = codec->spec; | |
985be54b TI |
115 | int i; |
116 | ||
117 | for (i = 0; i < spec->num_init_verbs; i++) | |
118 | snd_hda_sequence_write(codec, spec->init_verbs[i]); | |
4a3fdf3d TI |
119 | return 0; |
120 | } | |
121 | ||
122 | static int ad198x_build_controls(struct hda_codec *codec) | |
123 | { | |
124 | struct ad198x_spec *spec = codec->spec; | |
985be54b | 125 | unsigned int i; |
4a3fdf3d TI |
126 | int err; |
127 | ||
985be54b TI |
128 | for (i = 0; i < spec->num_mixers; i++) { |
129 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); | |
130 | if (err < 0) | |
131 | return err; | |
132 | } | |
133 | if (spec->multiout.dig_out_nid) { | |
4a3fdf3d | 134 | err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); |
985be54b TI |
135 | if (err < 0) |
136 | return err; | |
137 | } | |
138 | if (spec->dig_in_nid) { | |
139 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); | |
140 | if (err < 0) | |
141 | return err; | |
142 | } | |
4a3fdf3d TI |
143 | return 0; |
144 | } | |
145 | ||
146 | /* | |
147 | * Analog playback callbacks | |
148 | */ | |
149 | static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
150 | struct hda_codec *codec, | |
c8b6bf9b | 151 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
152 | { |
153 | struct ad198x_spec *spec = codec->spec; | |
154 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); | |
155 | } | |
156 | ||
157 | static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |
158 | struct hda_codec *codec, | |
159 | unsigned int stream_tag, | |
160 | unsigned int format, | |
c8b6bf9b | 161 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
162 | { |
163 | struct ad198x_spec *spec = codec->spec; | |
164 | return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, | |
165 | format, substream); | |
166 | } | |
167 | ||
168 | static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
169 | struct hda_codec *codec, | |
c8b6bf9b | 170 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
171 | { |
172 | struct ad198x_spec *spec = codec->spec; | |
173 | return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); | |
174 | } | |
175 | ||
176 | /* | |
177 | * Digital out | |
178 | */ | |
179 | static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, | |
180 | struct hda_codec *codec, | |
c8b6bf9b | 181 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
182 | { |
183 | struct ad198x_spec *spec = codec->spec; | |
184 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); | |
185 | } | |
186 | ||
187 | static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, | |
188 | struct hda_codec *codec, | |
c8b6bf9b | 189 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
190 | { |
191 | struct ad198x_spec *spec = codec->spec; | |
192 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); | |
193 | } | |
194 | ||
195 | /* | |
196 | * Analog capture | |
197 | */ | |
198 | static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo, | |
199 | struct hda_codec *codec, | |
200 | unsigned int stream_tag, | |
201 | unsigned int format, | |
c8b6bf9b | 202 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
203 | { |
204 | struct ad198x_spec *spec = codec->spec; | |
985be54b TI |
205 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
206 | stream_tag, 0, format); | |
4a3fdf3d TI |
207 | return 0; |
208 | } | |
209 | ||
210 | static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, | |
211 | struct hda_codec *codec, | |
c8b6bf9b | 212 | struct snd_pcm_substream *substream) |
4a3fdf3d TI |
213 | { |
214 | struct ad198x_spec *spec = codec->spec; | |
985be54b TI |
215 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
216 | 0, 0, 0); | |
4a3fdf3d TI |
217 | return 0; |
218 | } | |
219 | ||
220 | ||
221 | /* | |
222 | */ | |
223 | static struct hda_pcm_stream ad198x_pcm_analog_playback = { | |
224 | .substreams = 1, | |
225 | .channels_min = 2, | |
985be54b | 226 | .channels_max = 6, /* changed later */ |
4a3fdf3d TI |
227 | .nid = 0, /* fill later */ |
228 | .ops = { | |
229 | .open = ad198x_playback_pcm_open, | |
230 | .prepare = ad198x_playback_pcm_prepare, | |
231 | .cleanup = ad198x_playback_pcm_cleanup | |
232 | }, | |
233 | }; | |
234 | ||
235 | static struct hda_pcm_stream ad198x_pcm_analog_capture = { | |
985be54b | 236 | .substreams = 1, |
4a3fdf3d TI |
237 | .channels_min = 2, |
238 | .channels_max = 2, | |
239 | .nid = 0, /* fill later */ | |
240 | .ops = { | |
241 | .prepare = ad198x_capture_pcm_prepare, | |
242 | .cleanup = ad198x_capture_pcm_cleanup | |
243 | }, | |
244 | }; | |
245 | ||
246 | static struct hda_pcm_stream ad198x_pcm_digital_playback = { | |
247 | .substreams = 1, | |
248 | .channels_min = 2, | |
249 | .channels_max = 2, | |
250 | .nid = 0, /* fill later */ | |
251 | .ops = { | |
252 | .open = ad198x_dig_playback_pcm_open, | |
253 | .close = ad198x_dig_playback_pcm_close | |
254 | }, | |
255 | }; | |
256 | ||
985be54b TI |
257 | static struct hda_pcm_stream ad198x_pcm_digital_capture = { |
258 | .substreams = 1, | |
259 | .channels_min = 2, | |
260 | .channels_max = 2, | |
261 | /* NID is set in alc_build_pcms */ | |
262 | }; | |
263 | ||
4a3fdf3d TI |
264 | static int ad198x_build_pcms(struct hda_codec *codec) |
265 | { | |
266 | struct ad198x_spec *spec = codec->spec; | |
267 | struct hda_pcm *info = spec->pcm_rec; | |
268 | ||
269 | codec->num_pcms = 1; | |
270 | codec->pcm_info = info; | |
271 | ||
272 | info->name = "AD198x Analog"; | |
273 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback; | |
274 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; | |
275 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; | |
276 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture; | |
985be54b TI |
277 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids; |
278 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; | |
4a3fdf3d TI |
279 | |
280 | if (spec->multiout.dig_out_nid) { | |
281 | info++; | |
282 | codec->num_pcms++; | |
283 | info->name = "AD198x Digital"; | |
284 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback; | |
285 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; | |
985be54b TI |
286 | if (spec->dig_in_nid) { |
287 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture; | |
288 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid; | |
289 | } | |
4a3fdf3d TI |
290 | } |
291 | ||
292 | return 0; | |
293 | } | |
294 | ||
295 | static void ad198x_free(struct hda_codec *codec) | |
296 | { | |
d32410b1 TI |
297 | struct ad198x_spec *spec = codec->spec; |
298 | unsigned int i; | |
299 | ||
300 | if (spec->kctl_alloc) { | |
301 | for (i = 0; i < spec->num_kctl_used; i++) | |
302 | kfree(spec->kctl_alloc[i].name); | |
303 | kfree(spec->kctl_alloc); | |
304 | } | |
4a3fdf3d TI |
305 | kfree(codec->spec); |
306 | } | |
307 | ||
308 | #ifdef CONFIG_PM | |
309 | static int ad198x_resume(struct hda_codec *codec) | |
310 | { | |
311 | struct ad198x_spec *spec = codec->spec; | |
985be54b | 312 | int i; |
4a3fdf3d | 313 | |
18a815d7 | 314 | codec->patch_ops.init(codec); |
985be54b TI |
315 | for (i = 0; i < spec->num_mixers; i++) |
316 | snd_hda_resume_ctls(codec, spec->mixers[i]); | |
317 | if (spec->multiout.dig_out_nid) | |
318 | snd_hda_resume_spdif_out(codec); | |
319 | if (spec->dig_in_nid) | |
320 | snd_hda_resume_spdif_in(codec); | |
4a3fdf3d TI |
321 | return 0; |
322 | } | |
323 | #endif | |
324 | ||
325 | static struct hda_codec_ops ad198x_patch_ops = { | |
326 | .build_controls = ad198x_build_controls, | |
327 | .build_pcms = ad198x_build_pcms, | |
328 | .init = ad198x_init, | |
329 | .free = ad198x_free, | |
330 | #ifdef CONFIG_PM | |
331 | .resume = ad198x_resume, | |
332 | #endif | |
333 | }; | |
334 | ||
335 | ||
18a815d7 TI |
336 | /* |
337 | * EAPD control | |
338 | * the private value = nid | (invert << 8) | |
339 | */ | |
340 | static int ad198x_eapd_info(struct snd_kcontrol *kcontrol, | |
341 | struct snd_ctl_elem_info *uinfo) | |
342 | { | |
343 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
344 | uinfo->count = 1; | |
345 | uinfo->value.integer.min = 0; | |
346 | uinfo->value.integer.max = 1; | |
347 | return 0; | |
348 | } | |
349 | ||
350 | static int ad198x_eapd_get(struct snd_kcontrol *kcontrol, | |
351 | struct snd_ctl_elem_value *ucontrol) | |
352 | { | |
353 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
354 | struct ad198x_spec *spec = codec->spec; | |
355 | int invert = (kcontrol->private_value >> 8) & 1; | |
356 | if (invert) | |
357 | ucontrol->value.integer.value[0] = ! spec->cur_eapd; | |
358 | else | |
359 | ucontrol->value.integer.value[0] = spec->cur_eapd; | |
360 | return 0; | |
361 | } | |
362 | ||
363 | static int ad198x_eapd_put(struct snd_kcontrol *kcontrol, | |
364 | struct snd_ctl_elem_value *ucontrol) | |
365 | { | |
366 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
367 | struct ad198x_spec *spec = codec->spec; | |
368 | int invert = (kcontrol->private_value >> 8) & 1; | |
369 | hda_nid_t nid = kcontrol->private_value & 0xff; | |
370 | unsigned int eapd; | |
371 | eapd = ucontrol->value.integer.value[0]; | |
372 | if (invert) | |
373 | eapd = !eapd; | |
374 | if (eapd == spec->cur_eapd && ! codec->in_resume) | |
375 | return 0; | |
376 | spec->cur_eapd = eapd; | |
377 | snd_hda_codec_write(codec, nid, | |
378 | 0, AC_VERB_SET_EAPD_BTLENABLE, | |
379 | eapd ? 0x02 : 0x00); | |
380 | return 1; | |
381 | } | |
382 | ||
9230d214 TI |
383 | static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol, |
384 | struct snd_ctl_elem_info *uinfo); | |
385 | static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol, | |
386 | struct snd_ctl_elem_value *ucontrol); | |
387 | static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol, | |
388 | struct snd_ctl_elem_value *ucontrol); | |
389 | ||
390 | ||
4a3fdf3d TI |
391 | /* |
392 | * AD1986A specific | |
393 | */ | |
394 | ||
1da177e4 LT |
395 | #define AD1986A_SPDIF_OUT 0x02 |
396 | #define AD1986A_FRONT_DAC 0x03 | |
397 | #define AD1986A_SURR_DAC 0x04 | |
398 | #define AD1986A_CLFE_DAC 0x05 | |
399 | #define AD1986A_ADC 0x06 | |
400 | ||
401 | static hda_nid_t ad1986a_dac_nids[3] = { | |
402 | AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC | |
403 | }; | |
985be54b | 404 | static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC }; |
18a815d7 | 405 | static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 }; |
1da177e4 LT |
406 | |
407 | static struct hda_input_mux ad1986a_capture_source = { | |
408 | .num_items = 7, | |
409 | .items = { | |
410 | { "Mic", 0x0 }, | |
411 | { "CD", 0x1 }, | |
412 | { "Aux", 0x3 }, | |
413 | { "Line", 0x4 }, | |
414 | { "Mix", 0x5 }, | |
415 | { "Mono", 0x6 }, | |
416 | { "Phone", 0x7 }, | |
417 | }, | |
418 | }; | |
419 | ||
420 | /* | |
421 | * PCM control | |
422 | * | |
423 | * bind volumes/mutes of 3 DACs as a single PCM control for simplicity | |
424 | */ | |
425 | ||
426 | #define ad1986a_pcm_amp_vol_info snd_hda_mixer_amp_volume_info | |
427 | ||
c8b6bf9b | 428 | static int ad1986a_pcm_amp_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
429 | { |
430 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4a3fdf3d | 431 | struct ad198x_spec *ad = codec->spec; |
1da177e4 | 432 | |
62932df8 | 433 | mutex_lock(&ad->amp_mutex); |
1da177e4 | 434 | snd_hda_mixer_amp_volume_get(kcontrol, ucontrol); |
62932df8 | 435 | mutex_unlock(&ad->amp_mutex); |
1da177e4 LT |
436 | return 0; |
437 | } | |
438 | ||
c8b6bf9b | 439 | static int ad1986a_pcm_amp_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
440 | { |
441 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4a3fdf3d | 442 | struct ad198x_spec *ad = codec->spec; |
1da177e4 LT |
443 | int i, change = 0; |
444 | ||
62932df8 | 445 | mutex_lock(&ad->amp_mutex); |
1da177e4 LT |
446 | for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) { |
447 | kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT); | |
448 | change |= snd_hda_mixer_amp_volume_put(kcontrol, ucontrol); | |
449 | } | |
450 | kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT); | |
62932df8 | 451 | mutex_unlock(&ad->amp_mutex); |
1da177e4 LT |
452 | return change; |
453 | } | |
454 | ||
ead9b7c3 | 455 | #define ad1986a_pcm_amp_sw_info snd_hda_mixer_amp_switch_info |
1da177e4 | 456 | |
c8b6bf9b | 457 | static int ad1986a_pcm_amp_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
458 | { |
459 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4a3fdf3d | 460 | struct ad198x_spec *ad = codec->spec; |
1da177e4 | 461 | |
62932df8 | 462 | mutex_lock(&ad->amp_mutex); |
1da177e4 | 463 | snd_hda_mixer_amp_switch_get(kcontrol, ucontrol); |
62932df8 | 464 | mutex_unlock(&ad->amp_mutex); |
1da177e4 LT |
465 | return 0; |
466 | } | |
467 | ||
c8b6bf9b | 468 | static int ad1986a_pcm_amp_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 LT |
469 | { |
470 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
4a3fdf3d | 471 | struct ad198x_spec *ad = codec->spec; |
1da177e4 LT |
472 | int i, change = 0; |
473 | ||
62932df8 | 474 | mutex_lock(&ad->amp_mutex); |
1da177e4 LT |
475 | for (i = 0; i < ARRAY_SIZE(ad1986a_dac_nids); i++) { |
476 | kcontrol->private_value = HDA_COMPOSE_AMP_VAL(ad1986a_dac_nids[i], 3, 0, HDA_OUTPUT); | |
477 | change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); | |
478 | } | |
479 | kcontrol->private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT); | |
62932df8 | 480 | mutex_unlock(&ad->amp_mutex); |
1da177e4 LT |
481 | return change; |
482 | } | |
483 | ||
1da177e4 LT |
484 | /* |
485 | * mixers | |
486 | */ | |
c8b6bf9b | 487 | static struct snd_kcontrol_new ad1986a_mixers[] = { |
1da177e4 LT |
488 | { |
489 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
490 | .name = "PCM Playback Volume", | |
491 | .info = ad1986a_pcm_amp_vol_info, | |
492 | .get = ad1986a_pcm_amp_vol_get, | |
493 | .put = ad1986a_pcm_amp_vol_put, | |
494 | .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT) | |
495 | }, | |
496 | { | |
497 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
498 | .name = "PCM Playback Switch", | |
499 | .info = ad1986a_pcm_amp_sw_info, | |
500 | .get = ad1986a_pcm_amp_sw_get, | |
501 | .put = ad1986a_pcm_amp_sw_put, | |
502 | .private_value = HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT) | |
503 | }, | |
504 | HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT), | |
505 | HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT), | |
506 | HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT), | |
507 | HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT), | |
508 | HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT), | |
509 | HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT), | |
510 | HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT), | |
511 | HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT), | |
512 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT), | |
513 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), | |
514 | HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT), | |
515 | HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT), | |
516 | HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT), | |
517 | HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT), | |
518 | HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT), | |
519 | HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT), | |
520 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
521 | HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
522 | HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT), | |
523 | HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT), | |
524 | HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT), | |
525 | HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), | |
526 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), | |
527 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT), | |
528 | { | |
529 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
530 | .name = "Capture Source", | |
4a3fdf3d TI |
531 | .info = ad198x_mux_enum_info, |
532 | .get = ad198x_mux_enum_get, | |
533 | .put = ad198x_mux_enum_put, | |
1da177e4 LT |
534 | }, |
535 | HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT), | |
536 | { } /* end */ | |
537 | }; | |
538 | ||
9230d214 TI |
539 | /* additional mixers for 3stack mode */ |
540 | static struct snd_kcontrol_new ad1986a_3st_mixers[] = { | |
541 | { | |
542 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
543 | .name = "Channel Mode", | |
544 | .info = ad198x_ch_mode_info, | |
545 | .get = ad198x_ch_mode_get, | |
546 | .put = ad198x_ch_mode_put, | |
547 | }, | |
548 | { } /* end */ | |
549 | }; | |
550 | ||
551 | /* laptop model - 2ch only */ | |
552 | static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC }; | |
553 | ||
554 | static struct snd_kcontrol_new ad1986a_laptop_mixers[] = { | |
555 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), | |
556 | HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), | |
557 | HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT), | |
558 | HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT), | |
559 | /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT), | |
560 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */ | |
561 | HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT), | |
562 | HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT), | |
563 | HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT), | |
564 | HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT), | |
565 | HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT), | |
566 | HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT), | |
567 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
568 | HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
569 | /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT), | |
570 | HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT), | |
571 | HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT), | |
572 | HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */ | |
573 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), | |
574 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT), | |
575 | { | |
576 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
577 | .name = "Capture Source", | |
578 | .info = ad198x_mux_enum_info, | |
579 | .get = ad198x_mux_enum_get, | |
580 | .put = ad198x_mux_enum_put, | |
581 | }, | |
582 | { } /* end */ | |
583 | }; | |
584 | ||
825aa972 TI |
585 | /* laptop-eapd model - 2ch only */ |
586 | ||
587 | /* master controls both pins 0x1a and 0x1b */ | |
588 | static int ad1986a_laptop_master_vol_put(struct snd_kcontrol *kcontrol, | |
589 | struct snd_ctl_elem_value *ucontrol) | |
590 | { | |
591 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
592 | long *valp = ucontrol->value.integer.value; | |
593 | int change; | |
594 | ||
595 | change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0, | |
596 | 0x7f, valp[0] & 0x7f); | |
597 | change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0, | |
598 | 0x7f, valp[1] & 0x7f); | |
599 | snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0, | |
600 | 0x7f, valp[0] & 0x7f); | |
601 | snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0, | |
602 | 0x7f, valp[1] & 0x7f); | |
603 | return change; | |
604 | } | |
605 | ||
606 | static int ad1986a_laptop_master_sw_put(struct snd_kcontrol *kcontrol, | |
607 | struct snd_ctl_elem_value *ucontrol) | |
608 | { | |
609 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
610 | long *valp = ucontrol->value.integer.value; | |
611 | int change; | |
612 | ||
613 | change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0, | |
614 | 0x80, valp[0] ? 0 : 0x80); | |
615 | change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0, | |
616 | 0x80, valp[1] ? 0 : 0x80); | |
617 | snd_hda_codec_amp_update(codec, 0x1b, 0, HDA_OUTPUT, 0, | |
618 | 0x80, valp[0] ? 0 : 0x80); | |
619 | snd_hda_codec_amp_update(codec, 0x1b, 1, HDA_OUTPUT, 0, | |
620 | 0x80, valp[1] ? 0 : 0x80); | |
621 | return change; | |
622 | } | |
623 | ||
624 | static struct hda_input_mux ad1986a_laptop_eapd_capture_source = { | |
625 | .num_items = 3, | |
626 | .items = { | |
627 | { "Mic", 0x0 }, | |
628 | { "Internal Mic", 0x4 }, | |
629 | { "Mix", 0x5 }, | |
630 | }, | |
631 | }; | |
632 | ||
633 | static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = { | |
634 | { | |
635 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
636 | .name = "Master Playback Volume", | |
637 | .info = snd_hda_mixer_amp_volume_info, | |
638 | .get = snd_hda_mixer_amp_volume_get, | |
639 | .put = ad1986a_laptop_master_vol_put, | |
640 | .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT), | |
641 | }, | |
642 | { | |
643 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
644 | .name = "Master Playback Switch", | |
645 | .info = snd_hda_mixer_amp_switch_info, | |
646 | .get = snd_hda_mixer_amp_switch_get, | |
647 | .put = ad1986a_laptop_master_sw_put, | |
648 | .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT), | |
649 | }, | |
650 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), | |
651 | HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), | |
652 | HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT), | |
653 | HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT), | |
654 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
655 | HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
656 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), | |
657 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT), | |
658 | { | |
659 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
660 | .name = "Capture Source", | |
661 | .info = ad198x_mux_enum_info, | |
662 | .get = ad198x_mux_enum_get, | |
663 | .put = ad198x_mux_enum_put, | |
664 | }, | |
665 | { | |
666 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
667 | .name = "External Amplifier", | |
668 | .info = ad198x_eapd_info, | |
669 | .get = ad198x_eapd_get, | |
670 | .put = ad198x_eapd_put, | |
671 | .private_value = 0x1b | (1 << 8), /* port-D, inversed */ | |
672 | }, | |
673 | { } /* end */ | |
674 | }; | |
675 | ||
1da177e4 LT |
676 | /* |
677 | * initialization verbs | |
678 | */ | |
679 | static struct hda_verb ad1986a_init_verbs[] = { | |
680 | /* Front, Surround, CLFE DAC; mute as default */ | |
681 | {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
682 | {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
683 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
684 | /* Downmix - off */ | |
685 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
686 | /* HP, Line-Out, Surround, CLFE selectors */ | |
687 | {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
688 | {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
689 | {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
690 | {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
691 | /* Mono selector */ | |
692 | {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
693 | /* Mic selector: Mic 1/2 pin */ | |
694 | {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
695 | /* Line-in selector: Line-in */ | |
696 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
697 | /* Mic 1/2 swap */ | |
698 | {0x11, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
699 | /* Record selector: mic */ | |
700 | {0x12, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
701 | /* Mic, Phone, CD, Aux, Line-In amp; mute as default */ | |
702 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
703 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
704 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
705 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
706 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
707 | /* PC beep */ | |
708 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
709 | /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */ | |
710 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
711 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
712 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
713 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
714 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
4a3fdf3d TI |
715 | /* HP Pin */ |
716 | {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, | |
717 | /* Front, Surround, CLFE Pins */ | |
718 | {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
719 | {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
720 | {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
721 | /* Mono Pin */ | |
722 | {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
723 | /* Mic Pin */ | |
724 | {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
725 | /* Line, Aux, CD, Beep-In Pin */ | |
726 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
727 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
728 | {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
729 | {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
730 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
1da177e4 LT |
731 | { } /* end */ |
732 | }; | |
733 | ||
9230d214 TI |
734 | /* additional verbs for 3-stack model */ |
735 | static struct hda_verb ad1986a_3st_init_verbs[] = { | |
736 | /* Mic and line-in selectors */ | |
737 | {0x0f, AC_VERB_SET_CONNECT_SEL, 0x2}, | |
738 | {0x10, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
739 | { } /* end */ | |
740 | }; | |
741 | ||
742 | static struct hda_verb ad1986a_ch2_init[] = { | |
743 | /* Surround out -> Line In */ | |
744 | { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
745 | { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
746 | /* CLFE -> Mic in */ | |
747 | { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
748 | { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
749 | { } /* end */ | |
750 | }; | |
751 | ||
752 | static struct hda_verb ad1986a_ch4_init[] = { | |
753 | /* Surround out -> Surround */ | |
754 | { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
755 | { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
756 | /* CLFE -> Mic in */ | |
757 | { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
758 | { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
759 | { } /* end */ | |
760 | }; | |
761 | ||
762 | static struct hda_verb ad1986a_ch6_init[] = { | |
763 | /* Surround out -> Surround out */ | |
764 | { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
765 | { 0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
766 | /* CLFE -> CLFE */ | |
767 | { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
768 | { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
769 | { } /* end */ | |
770 | }; | |
771 | ||
772 | static struct hda_channel_mode ad1986a_modes[3] = { | |
773 | { 2, ad1986a_ch2_init }, | |
774 | { 4, ad1986a_ch4_init }, | |
775 | { 6, ad1986a_ch6_init }, | |
776 | }; | |
777 | ||
825aa972 TI |
778 | /* eapd initialization */ |
779 | static struct hda_verb ad1986a_eapd_init_verbs[] = { | |
780 | {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, | |
781 | {} | |
782 | }; | |
783 | ||
9230d214 | 784 | /* models */ |
825aa972 | 785 | enum { AD1986A_6STACK, AD1986A_3STACK, AD1986A_LAPTOP, AD1986A_LAPTOP_EAPD }; |
9230d214 TI |
786 | |
787 | static struct hda_board_config ad1986a_cfg_tbl[] = { | |
788 | { .modelname = "6stack", .config = AD1986A_6STACK }, | |
789 | { .modelname = "3stack", .config = AD1986A_3STACK }, | |
82bc955f TI |
790 | { .pci_subvendor = 0x10de, .pci_subdevice = 0xcb84, |
791 | .config = AD1986A_3STACK }, /* ASUS A8N-VM CSM */ | |
9230d214 TI |
792 | { .modelname = "laptop", .config = AD1986A_LAPTOP }, |
793 | { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e, | |
794 | .config = AD1986A_LAPTOP }, /* FSC V2060 */ | |
795 | { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017, | |
796 | .config = AD1986A_LAPTOP }, /* Samsung M50 */ | |
825aa972 TI |
797 | { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f, |
798 | .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */ | |
799 | { .modelname = "laptop-eapd", .config = AD1986A_LAPTOP_EAPD }, | |
800 | { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024, | |
801 | .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */ | |
802 | { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213, | |
803 | .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */ | |
be28e7cc CQH |
804 | { .pci_subvendor = 0x103c, .pci_subdevice = 0x30af, |
805 | .config = AD1986A_LAPTOP_EAPD }, /* HP Compaq Presario B2800 */ | |
9230d214 TI |
806 | {} |
807 | }; | |
1da177e4 | 808 | |
4a3fdf3d | 809 | static int patch_ad1986a(struct hda_codec *codec) |
1da177e4 | 810 | { |
4a3fdf3d | 811 | struct ad198x_spec *spec; |
9230d214 | 812 | int board_config; |
1da177e4 | 813 | |
e560d8d8 | 814 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
4a3fdf3d TI |
815 | if (spec == NULL) |
816 | return -ENOMEM; | |
817 | ||
62932df8 | 818 | mutex_init(&spec->amp_mutex); |
4a3fdf3d TI |
819 | codec->spec = spec; |
820 | ||
821 | spec->multiout.max_channels = 6; | |
822 | spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids); | |
823 | spec->multiout.dac_nids = ad1986a_dac_nids; | |
824 | spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT; | |
985be54b TI |
825 | spec->num_adc_nids = 1; |
826 | spec->adc_nids = ad1986a_adc_nids; | |
a7ee8201 | 827 | spec->capsrc_nids = ad1986a_capsrc_nids; |
4a3fdf3d | 828 | spec->input_mux = &ad1986a_capture_source; |
985be54b TI |
829 | spec->num_mixers = 1; |
830 | spec->mixers[0] = ad1986a_mixers; | |
831 | spec->num_init_verbs = 1; | |
832 | spec->init_verbs[0] = ad1986a_init_verbs; | |
4a3fdf3d TI |
833 | |
834 | codec->patch_ops = ad198x_patch_ops; | |
1da177e4 | 835 | |
9230d214 TI |
836 | /* override some parameters */ |
837 | board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl); | |
838 | switch (board_config) { | |
839 | case AD1986A_3STACK: | |
840 | spec->num_mixers = 2; | |
841 | spec->mixers[1] = ad1986a_3st_mixers; | |
2125cad2 | 842 | spec->num_init_verbs = 3; |
9230d214 | 843 | spec->init_verbs[1] = ad1986a_3st_init_verbs; |
2125cad2 | 844 | spec->init_verbs[2] = ad1986a_ch2_init; |
9230d214 TI |
845 | spec->channel_mode = ad1986a_modes; |
846 | spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes); | |
2125cad2 TI |
847 | spec->need_dac_fix = 1; |
848 | spec->multiout.max_channels = 2; | |
849 | spec->multiout.num_dacs = 1; | |
9230d214 TI |
850 | break; |
851 | case AD1986A_LAPTOP: | |
852 | spec->mixers[0] = ad1986a_laptop_mixers; | |
853 | spec->multiout.max_channels = 2; | |
854 | spec->multiout.num_dacs = 1; | |
855 | spec->multiout.dac_nids = ad1986a_laptop_dac_nids; | |
856 | break; | |
825aa972 TI |
857 | case AD1986A_LAPTOP_EAPD: |
858 | spec->mixers[0] = ad1986a_laptop_eapd_mixers; | |
859 | spec->num_init_verbs = 2; | |
860 | spec->init_verbs[1] = ad1986a_eapd_init_verbs; | |
861 | spec->multiout.max_channels = 2; | |
862 | spec->multiout.num_dacs = 1; | |
863 | spec->multiout.dac_nids = ad1986a_laptop_dac_nids; | |
864 | spec->multiout.dig_out_nid = 0; | |
865 | spec->input_mux = &ad1986a_laptop_eapd_capture_source; | |
866 | break; | |
9230d214 TI |
867 | } |
868 | ||
1da177e4 LT |
869 | return 0; |
870 | } | |
871 | ||
872 | /* | |
4a3fdf3d | 873 | * AD1983 specific |
1da177e4 | 874 | */ |
1da177e4 | 875 | |
4a3fdf3d TI |
876 | #define AD1983_SPDIF_OUT 0x02 |
877 | #define AD1983_DAC 0x03 | |
878 | #define AD1983_ADC 0x04 | |
1da177e4 | 879 | |
4a3fdf3d | 880 | static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC }; |
985be54b | 881 | static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC }; |
18a815d7 | 882 | static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 }; |
4a3fdf3d TI |
883 | |
884 | static struct hda_input_mux ad1983_capture_source = { | |
885 | .num_items = 4, | |
886 | .items = { | |
887 | { "Mic", 0x0 }, | |
888 | { "Line", 0x1 }, | |
889 | { "Mix", 0x2 }, | |
890 | { "Mix Mono", 0x3 }, | |
891 | }, | |
892 | }; | |
1da177e4 LT |
893 | |
894 | /* | |
4a3fdf3d | 895 | * SPDIF playback route |
1da177e4 | 896 | */ |
c8b6bf9b | 897 | static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
1da177e4 | 898 | { |
4a3fdf3d TI |
899 | static char *texts[] = { "PCM", "ADC" }; |
900 | ||
901 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
902 | uinfo->count = 1; | |
903 | uinfo->value.enumerated.items = 2; | |
904 | if (uinfo->value.enumerated.item > 1) | |
905 | uinfo->value.enumerated.item = 1; | |
906 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | |
907 | return 0; | |
1da177e4 LT |
908 | } |
909 | ||
c8b6bf9b | 910 | static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 911 | { |
4a3fdf3d TI |
912 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
913 | struct ad198x_spec *spec = codec->spec; | |
1da177e4 | 914 | |
4a3fdf3d | 915 | ucontrol->value.enumerated.item[0] = spec->spdif_route; |
1da177e4 LT |
916 | return 0; |
917 | } | |
918 | ||
c8b6bf9b | 919 | static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
1da177e4 | 920 | { |
4a3fdf3d TI |
921 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
922 | struct ad198x_spec *spec = codec->spec; | |
923 | ||
924 | if (spec->spdif_route != ucontrol->value.enumerated.item[0]) { | |
925 | spec->spdif_route = ucontrol->value.enumerated.item[0]; | |
926 | snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0, | |
927 | AC_VERB_SET_CONNECT_SEL, spec->spdif_route); | |
928 | return 1; | |
929 | } | |
1da177e4 LT |
930 | return 0; |
931 | } | |
932 | ||
c8b6bf9b | 933 | static struct snd_kcontrol_new ad1983_mixers[] = { |
4a3fdf3d TI |
934 | HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT), |
935 | HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT), | |
936 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT), | |
937 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT), | |
938 | HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT), | |
939 | HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT), | |
940 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT), | |
941 | HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT), | |
942 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT), | |
943 | HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT), | |
944 | HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
945 | HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
946 | HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT), | |
947 | HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT), | |
948 | HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT), | |
949 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
950 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), | |
951 | { | |
952 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
953 | .name = "Capture Source", | |
954 | .info = ad198x_mux_enum_info, | |
955 | .get = ad198x_mux_enum_get, | |
956 | .put = ad198x_mux_enum_put, | |
1da177e4 | 957 | }, |
4a3fdf3d TI |
958 | { |
959 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
10e8d78a | 960 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route", |
4a3fdf3d TI |
961 | .info = ad1983_spdif_route_info, |
962 | .get = ad1983_spdif_route_get, | |
963 | .put = ad1983_spdif_route_put, | |
1da177e4 | 964 | }, |
4a3fdf3d | 965 | { } /* end */ |
1da177e4 LT |
966 | }; |
967 | ||
4a3fdf3d TI |
968 | static struct hda_verb ad1983_init_verbs[] = { |
969 | /* Front, HP, Mono; mute as default */ | |
970 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
971 | {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
972 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
973 | /* Beep, PCM, Mic, Line-In: mute */ | |
974 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
975 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
976 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
977 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
978 | /* Front, HP selectors; from Mix */ | |
979 | {0x05, AC_VERB_SET_CONNECT_SEL, 0x01}, | |
980 | {0x06, AC_VERB_SET_CONNECT_SEL, 0x01}, | |
981 | /* Mono selector; from Mix */ | |
982 | {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03}, | |
983 | /* Mic selector; Mic */ | |
984 | {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
985 | /* Line-in selector: Line-in */ | |
986 | {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
987 | /* Mic boost: 0dB */ | |
988 | {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
989 | /* Record selector: mic */ | |
990 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
991 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
992 | /* SPDIF route: PCM */ | |
993 | {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
994 | /* Front Pin */ | |
995 | {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
996 | /* HP Pin */ | |
997 | {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, | |
998 | /* Mono Pin */ | |
999 | {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
1000 | /* Mic Pin */ | |
1001 | {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
1002 | /* Line Pin */ | |
1003 | {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
1004 | { } /* end */ | |
1da177e4 LT |
1005 | }; |
1006 | ||
985be54b | 1007 | |
4a3fdf3d | 1008 | static int patch_ad1983(struct hda_codec *codec) |
1da177e4 | 1009 | { |
4a3fdf3d | 1010 | struct ad198x_spec *spec; |
1da177e4 | 1011 | |
e560d8d8 | 1012 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
4a3fdf3d TI |
1013 | if (spec == NULL) |
1014 | return -ENOMEM; | |
1da177e4 | 1015 | |
62932df8 | 1016 | mutex_init(&spec->amp_mutex); |
4a3fdf3d TI |
1017 | codec->spec = spec; |
1018 | ||
1019 | spec->multiout.max_channels = 2; | |
1020 | spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids); | |
1021 | spec->multiout.dac_nids = ad1983_dac_nids; | |
1022 | spec->multiout.dig_out_nid = AD1983_SPDIF_OUT; | |
985be54b TI |
1023 | spec->num_adc_nids = 1; |
1024 | spec->adc_nids = ad1983_adc_nids; | |
18a815d7 | 1025 | spec->capsrc_nids = ad1983_capsrc_nids; |
4a3fdf3d | 1026 | spec->input_mux = &ad1983_capture_source; |
985be54b TI |
1027 | spec->num_mixers = 1; |
1028 | spec->mixers[0] = ad1983_mixers; | |
1029 | spec->num_init_verbs = 1; | |
1030 | spec->init_verbs[0] = ad1983_init_verbs; | |
4a3fdf3d | 1031 | spec->spdif_route = 0; |
1da177e4 | 1032 | |
4a3fdf3d | 1033 | codec->patch_ops = ad198x_patch_ops; |
1da177e4 LT |
1034 | |
1035 | return 0; | |
1036 | } | |
1037 | ||
1da177e4 | 1038 | |
4a3fdf3d TI |
1039 | /* |
1040 | * AD1981 HD specific | |
1041 | */ | |
1da177e4 | 1042 | |
4a3fdf3d TI |
1043 | #define AD1981_SPDIF_OUT 0x02 |
1044 | #define AD1981_DAC 0x03 | |
1045 | #define AD1981_ADC 0x04 | |
1046 | ||
1047 | static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC }; | |
985be54b | 1048 | static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC }; |
18a815d7 | 1049 | static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 }; |
4a3fdf3d TI |
1050 | |
1051 | /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */ | |
1052 | static struct hda_input_mux ad1981_capture_source = { | |
1053 | .num_items = 7, | |
1054 | .items = { | |
1055 | { "Front Mic", 0x0 }, | |
1056 | { "Line", 0x1 }, | |
1057 | { "Mix", 0x2 }, | |
1058 | { "Mix Mono", 0x3 }, | |
1059 | { "CD", 0x4 }, | |
1060 | { "Mic", 0x6 }, | |
1061 | { "Aux", 0x7 }, | |
1062 | }, | |
1da177e4 LT |
1063 | }; |
1064 | ||
c8b6bf9b | 1065 | static struct snd_kcontrol_new ad1981_mixers[] = { |
4a3fdf3d TI |
1066 | HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT), |
1067 | HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT), | |
1068 | HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT), | |
1069 | HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT), | |
1070 | HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT), | |
1071 | HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT), | |
1072 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT), | |
1073 | HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT), | |
1074 | HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT), | |
1075 | HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT), | |
1076 | HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
1077 | HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
1078 | HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT), | |
1079 | HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT), | |
1080 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT), | |
1081 | HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT), | |
1082 | HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT), | |
1083 | HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | |
1084 | HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT), | |
1085 | HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT), | |
1086 | HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT), | |
1087 | HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT), | |
1088 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
1089 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), | |
1090 | { | |
1091 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1092 | .name = "Capture Source", | |
1093 | .info = ad198x_mux_enum_info, | |
1094 | .get = ad198x_mux_enum_get, | |
1095 | .put = ad198x_mux_enum_put, | |
1096 | }, | |
1097 | /* identical with AD1983 */ | |
1098 | { | |
1099 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
10e8d78a | 1100 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route", |
4a3fdf3d TI |
1101 | .info = ad1983_spdif_route_info, |
1102 | .get = ad1983_spdif_route_get, | |
1103 | .put = ad1983_spdif_route_put, | |
1104 | }, | |
1105 | { } /* end */ | |
1106 | }; | |
1107 | ||
1108 | static struct hda_verb ad1981_init_verbs[] = { | |
1109 | /* Front, HP, Mono; mute as default */ | |
1110 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1111 | {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1112 | {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1113 | /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */ | |
1114 | {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1115 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1116 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1117 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1118 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1119 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1120 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1121 | /* Front, HP selectors; from Mix */ | |
1122 | {0x05, AC_VERB_SET_CONNECT_SEL, 0x01}, | |
1123 | {0x06, AC_VERB_SET_CONNECT_SEL, 0x01}, | |
1124 | /* Mono selector; from Mix */ | |
1125 | {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03}, | |
1126 | /* Mic Mixer; select Front Mic */ | |
1127 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
1128 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1129 | /* Mic boost: 0dB */ | |
1130 | {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
1131 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
1132 | /* Record selector: Front mic */ | |
1133 | {0x15, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1134 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1135 | /* SPDIF route: PCM */ | |
1136 | {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1137 | /* Front Pin */ | |
1138 | {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
1139 | /* HP Pin */ | |
1140 | {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, | |
1141 | /* Mono Pin */ | |
1142 | {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 }, | |
1143 | /* Front & Rear Mic Pins */ | |
1144 | {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
1145 | {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 }, | |
1146 | /* Line Pin */ | |
1147 | {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 }, | |
1148 | /* Digital Beep */ | |
1149 | {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00}, | |
1150 | /* Line-Out as Input: disabled */ | |
1151 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1152 | { } /* end */ | |
1153 | }; | |
1154 | ||
18a815d7 TI |
1155 | /* |
1156 | * Patch for HP nx6320 | |
1157 | * | |
1158 | * nx6320 uses EAPD in the reserve way - EAPD-on means the internal | |
1159 | * speaker output enabled _and_ mute-LED off. | |
1160 | */ | |
1161 | ||
1162 | #define AD1981_HP_EVENT 0x37 | |
1163 | #define AD1981_MIC_EVENT 0x38 | |
1164 | ||
1165 | static struct hda_verb ad1981_hp_init_verbs[] = { | |
1166 | {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */ | |
1167 | /* pin sensing on HP and Mic jacks */ | |
1168 | {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT}, | |
1169 | {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT}, | |
1170 | {} | |
1171 | }; | |
1172 | ||
1173 | /* turn on/off EAPD (+ mute HP) as a master switch */ | |
1174 | static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol, | |
1175 | struct snd_ctl_elem_value *ucontrol) | |
1176 | { | |
1177 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1178 | struct ad198x_spec *spec = codec->spec; | |
1179 | ||
1180 | if (! ad198x_eapd_put(kcontrol, ucontrol)) | |
1181 | return 0; | |
1182 | ||
1183 | /* toggle HP mute appropriately */ | |
1184 | snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0, | |
1185 | 0x80, spec->cur_eapd ? 0 : 0x80); | |
1186 | snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0, | |
1187 | 0x80, spec->cur_eapd ? 0 : 0x80); | |
1188 | return 1; | |
1189 | } | |
1190 | ||
1191 | /* bind volumes of both NID 0x05 and 0x06 */ | |
1192 | static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol, | |
1193 | struct snd_ctl_elem_value *ucontrol) | |
1194 | { | |
1195 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1196 | long *valp = ucontrol->value.integer.value; | |
1197 | int change; | |
1198 | ||
1199 | change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, | |
1200 | 0x7f, valp[0] & 0x7f); | |
1201 | change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, | |
1202 | 0x7f, valp[1] & 0x7f); | |
1203 | snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0, | |
1204 | 0x7f, valp[0] & 0x7f); | |
1205 | snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0, | |
1206 | 0x7f, valp[1] & 0x7f); | |
1207 | return change; | |
1208 | } | |
1209 | ||
1210 | /* mute internal speaker if HP is plugged */ | |
1211 | static void ad1981_hp_automute(struct hda_codec *codec) | |
1212 | { | |
1213 | unsigned int present; | |
1214 | ||
1215 | present = snd_hda_codec_read(codec, 0x06, 0, | |
1216 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
1217 | snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0, | |
1218 | 0x80, present ? 0x80 : 0); | |
1219 | snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0, | |
1220 | 0x80, present ? 0x80 : 0); | |
1221 | } | |
1222 | ||
1223 | /* toggle input of built-in and mic jack appropriately */ | |
1224 | static void ad1981_hp_automic(struct hda_codec *codec) | |
1225 | { | |
1226 | static struct hda_verb mic_jack_on[] = { | |
1227 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1228 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
1229 | {} | |
1230 | }; | |
1231 | static struct hda_verb mic_jack_off[] = { | |
1232 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, | |
1233 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, | |
1234 | {} | |
1235 | }; | |
1236 | unsigned int present; | |
1237 | ||
1238 | present = snd_hda_codec_read(codec, 0x08, 0, | |
1239 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; | |
1240 | if (present) | |
1241 | snd_hda_sequence_write(codec, mic_jack_on); | |
1242 | else | |
1243 | snd_hda_sequence_write(codec, mic_jack_off); | |
1244 | } | |
1245 | ||
1246 | /* unsolicited event for HP jack sensing */ | |
1247 | static void ad1981_hp_unsol_event(struct hda_codec *codec, | |
1248 | unsigned int res) | |
1249 | { | |
1250 | res >>= 26; | |
1251 | switch (res) { | |
1252 | case AD1981_HP_EVENT: | |
1253 | ad1981_hp_automute(codec); | |
1254 | break; | |
1255 | case AD1981_MIC_EVENT: | |
1256 | ad1981_hp_automic(codec); | |
1257 | break; | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | static struct hda_input_mux ad1981_hp_capture_source = { | |
1262 | .num_items = 3, | |
1263 | .items = { | |
1264 | { "Mic", 0x0 }, | |
1265 | { "Docking-Station", 0x1 }, | |
1266 | { "Mix", 0x2 }, | |
1267 | }, | |
1268 | }; | |
1269 | ||
1270 | static struct snd_kcontrol_new ad1981_hp_mixers[] = { | |
1271 | { | |
1272 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1273 | .name = "Master Playback Volume", | |
1274 | .info = snd_hda_mixer_amp_volume_info, | |
1275 | .get = snd_hda_mixer_amp_volume_get, | |
1276 | .put = ad1981_hp_master_vol_put, | |
1277 | .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT), | |
1278 | }, | |
1279 | { | |
1280 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1281 | .name = "Master Playback Switch", | |
1282 | .info = ad198x_eapd_info, | |
1283 | .get = ad198x_eapd_get, | |
1284 | .put = ad1981_hp_master_sw_put, | |
1285 | .private_value = 0x05, | |
1286 | }, | |
1287 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT), | |
1288 | HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT), | |
1289 | #if 0 | |
1290 | /* FIXME: analog mic/line loopback doesn't work with my tests... | |
1291 | * (although recording is OK) | |
1292 | */ | |
1293 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT), | |
1294 | HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT), | |
1295 | HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT), | |
1296 | HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT), | |
1297 | HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT), | |
1298 | HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT), | |
1299 | /* FIXME: does this laptop have analog CD connection? */ | |
1300 | HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT), | |
1301 | HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT), | |
1302 | #endif | |
1303 | HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT), | |
1304 | HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT), | |
1305 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), | |
1306 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), | |
1307 | { | |
1308 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1309 | .name = "Capture Source", | |
1310 | .info = ad198x_mux_enum_info, | |
1311 | .get = ad198x_mux_enum_get, | |
1312 | .put = ad198x_mux_enum_put, | |
1313 | }, | |
1314 | { } /* end */ | |
1315 | }; | |
1316 | ||
1317 | /* initialize jack-sensing, too */ | |
1318 | static int ad1981_hp_init(struct hda_codec *codec) | |
1319 | { | |
1320 | ad198x_init(codec); | |
1321 | ad1981_hp_automute(codec); | |
1322 | ad1981_hp_automic(codec); | |
1323 | return 0; | |
1324 | } | |
1325 | ||
1326 | /* models */ | |
1327 | enum { AD1981_BASIC, AD1981_HP }; | |
1328 | ||
1329 | static struct hda_board_config ad1981_cfg_tbl[] = { | |
1330 | { .modelname = "hp", .config = AD1981_HP }, | |
1331 | { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa, | |
b2c2844c TI |
1332 | .config = AD1981_HP }, /* HP nx6320 */ |
1333 | { .pci_subvendor = 0x103c, .pci_subdevice = 0x309f, | |
1334 | .config = AD1981_HP }, /* HP nx9420 AngelFire */ | |
f556e6f6 TI |
1335 | { .pci_subvendor = 0x103c, .pci_subdevice = 0x30a2, |
1336 | .config = AD1981_HP }, /* HP nx9420 AngelFire */ | |
18a815d7 TI |
1337 | { .modelname = "basic", .config = AD1981_BASIC }, |
1338 | {} | |
1339 | }; | |
1340 | ||
4a3fdf3d | 1341 | static int patch_ad1981(struct hda_codec *codec) |
1da177e4 | 1342 | { |
4a3fdf3d | 1343 | struct ad198x_spec *spec; |
18a815d7 | 1344 | int board_config; |
1da177e4 | 1345 | |
e560d8d8 | 1346 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
1da177e4 LT |
1347 | if (spec == NULL) |
1348 | return -ENOMEM; | |
1349 | ||
62932df8 | 1350 | mutex_init(&spec->amp_mutex); |
1da177e4 LT |
1351 | codec->spec = spec; |
1352 | ||
4a3fdf3d TI |
1353 | spec->multiout.max_channels = 2; |
1354 | spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids); | |
1355 | spec->multiout.dac_nids = ad1981_dac_nids; | |
1356 | spec->multiout.dig_out_nid = AD1981_SPDIF_OUT; | |
985be54b TI |
1357 | spec->num_adc_nids = 1; |
1358 | spec->adc_nids = ad1981_adc_nids; | |
18a815d7 | 1359 | spec->capsrc_nids = ad1981_capsrc_nids; |
4a3fdf3d | 1360 | spec->input_mux = &ad1981_capture_source; |
985be54b TI |
1361 | spec->num_mixers = 1; |
1362 | spec->mixers[0] = ad1981_mixers; | |
1363 | spec->num_init_verbs = 1; | |
1364 | spec->init_verbs[0] = ad1981_init_verbs; | |
4a3fdf3d | 1365 | spec->spdif_route = 0; |
1da177e4 | 1366 | |
4a3fdf3d | 1367 | codec->patch_ops = ad198x_patch_ops; |
1da177e4 | 1368 | |
18a815d7 TI |
1369 | /* override some parameters */ |
1370 | board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl); | |
1371 | switch (board_config) { | |
1372 | case AD1981_HP: | |
1373 | spec->mixers[0] = ad1981_hp_mixers; | |
1374 | spec->num_init_verbs = 2; | |
1375 | spec->init_verbs[1] = ad1981_hp_init_verbs; | |
1376 | spec->multiout.dig_out_nid = 0; | |
1377 | spec->input_mux = &ad1981_hp_capture_source; | |
1378 | ||
1379 | codec->patch_ops.init = ad1981_hp_init; | |
1380 | codec->patch_ops.unsol_event = ad1981_hp_unsol_event; | |
1381 | break; | |
1382 | } | |
1383 | ||
1da177e4 LT |
1384 | return 0; |
1385 | } | |
1386 | ||
4a3fdf3d | 1387 | |
fd66e0d0 TI |
1388 | /* |
1389 | * AD1988 | |
1390 | * | |
1391 | * Output pins and routes | |
1392 | * | |
d32410b1 | 1393 | * Pin Mix Sel DAC (*) |
fd66e0d0 TI |
1394 | * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06 |
1395 | * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06 | |
1396 | * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a | |
1397 | * port-D 0x12 (mute/hp) <- 0x29 <- 04 | |
1398 | * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a | |
1399 | * port-F 0x16 (mute) <- 0x2a <- 06 | |
1400 | * port-G 0x24 (mute) <- 0x27 <- 05 | |
1401 | * port-H 0x25 (mute) <- 0x28 <- 0a | |
1402 | * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06 | |
1403 | * | |
d32410b1 TI |
1404 | * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah |
1405 | * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug. | |
fd66e0d0 TI |
1406 | * |
1407 | * Input pins and routes | |
1408 | * | |
1409 | * pin boost mix input # / adc input # | |
1410 | * port-A 0x11 -> 0x38 -> mix 2, ADC 0 | |
1411 | * port-B 0x14 -> 0x39 -> mix 0, ADC 1 | |
1412 | * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2 | |
1413 | * port-D 0x12 -> 0x3d -> mix 3, ADC 8 | |
1414 | * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4 | |
1415 | * port-F 0x16 -> 0x3b -> mix 5, ADC 3 | |
1416 | * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6 | |
1417 | * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7 | |
1418 | * | |
1419 | * | |
1420 | * DAC assignment | |
d32410b1 | 1421 | * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03 |
f8c7c7b8 | 1422 | * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03 |
fd66e0d0 TI |
1423 | * |
1424 | * Inputs of Analog Mix (0x20) | |
1425 | * 0:Port-B (front mic) | |
1426 | * 1:Port-C/G/H (line-in) | |
1427 | * 2:Port-A | |
1428 | * 3:Port-D (line-in/2) | |
1429 | * 4:Port-E/G/H (mic-in) | |
1430 | * 5:Port-F (mic2-in) | |
1431 | * 6:CD | |
1432 | * 7:Beep | |
1433 | * | |
1434 | * ADC selection | |
1435 | * 0:Port-A | |
1436 | * 1:Port-B (front mic-in) | |
1437 | * 2:Port-C (line-in) | |
1438 | * 3:Port-F (mic2-in) | |
1439 | * 4:Port-E (mic-in) | |
1440 | * 5:CD | |
1441 | * 6:Port-G | |
1442 | * 7:Port-H | |
1443 | * 8:Port-D (line-in/2) | |
1444 | * 9:Mix | |
1445 | * | |
1446 | * Proposed pin assignments by the datasheet | |
1447 | * | |
1448 | * 6-stack | |
1449 | * Port-A front headphone | |
1450 | * B front mic-in | |
1451 | * C rear line-in | |
1452 | * D rear front-out | |
1453 | * E rear mic-in | |
1454 | * F rear surround | |
1455 | * G rear CLFE | |
1456 | * H rear side | |
1457 | * | |
1458 | * 3-stack | |
1459 | * Port-A front headphone | |
1460 | * B front mic | |
1461 | * C rear line-in/surround | |
1462 | * D rear front-out | |
1463 | * E rear mic-in/CLFE | |
1464 | * | |
1465 | * laptop | |
1466 | * Port-A headphone | |
1467 | * B mic-in | |
1468 | * C docking station | |
1469 | * D internal speaker (with EAPD) | |
1470 | * E/F quad mic array | |
1471 | */ | |
1472 | ||
1473 | ||
1474 | /* models */ | |
1475 | enum { | |
1476 | AD1988_6STACK, | |
1477 | AD1988_6STACK_DIG, | |
1478 | AD1988_3STACK, | |
1479 | AD1988_3STACK_DIG, | |
1480 | AD1988_LAPTOP, | |
1481 | AD1988_LAPTOP_DIG, | |
d32410b1 | 1482 | AD1988_AUTO, |
fd66e0d0 TI |
1483 | AD1988_MODEL_LAST, |
1484 | }; | |
1485 | ||
d32410b1 TI |
1486 | /* reivision id to check workarounds */ |
1487 | #define AD1988A_REV2 0x100200 | |
1488 | ||
fd66e0d0 TI |
1489 | |
1490 | /* | |
1491 | * mixers | |
1492 | */ | |
1493 | ||
d32410b1 | 1494 | static hda_nid_t ad1988_6stack_dac_nids[4] = { |
fd66e0d0 TI |
1495 | 0x04, 0x06, 0x05, 0x0a |
1496 | }; | |
1497 | ||
d32410b1 | 1498 | static hda_nid_t ad1988_3stack_dac_nids[3] = { |
f8c7c7b8 | 1499 | 0x04, 0x05, 0x0a |
d32410b1 TI |
1500 | }; |
1501 | ||
1502 | /* for AD1988A revision-2, DAC2-4 are swapped */ | |
1503 | static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = { | |
1504 | 0x04, 0x05, 0x0a, 0x06 | |
1505 | }; | |
1506 | ||
1507 | static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = { | |
f8c7c7b8 | 1508 | 0x04, 0x0a, 0x06 |
d32410b1 TI |
1509 | }; |
1510 | ||
fd66e0d0 TI |
1511 | static hda_nid_t ad1988_adc_nids[3] = { |
1512 | 0x08, 0x09, 0x0f | |
1513 | }; | |
1514 | ||
2e5b9567 TI |
1515 | static hda_nid_t ad1988_capsrc_nids[3] = { |
1516 | 0x0c, 0x0d, 0x0e | |
1517 | }; | |
1518 | ||
fd66e0d0 TI |
1519 | #define AD1988_SPDIF_OUT 0x02 |
1520 | #define AD1988_SPDIF_IN 0x07 | |
1521 | ||
1522 | static struct hda_input_mux ad1988_6stack_capture_source = { | |
1523 | .num_items = 5, | |
1524 | .items = { | |
1525 | { "Front Mic", 0x0 }, | |
1526 | { "Line", 0x1 }, | |
1527 | { "Mic", 0x4 }, | |
1528 | { "CD", 0x5 }, | |
1529 | { "Mix", 0x9 }, | |
1530 | }, | |
1531 | }; | |
1532 | ||
1533 | static struct hda_input_mux ad1988_laptop_capture_source = { | |
1534 | .num_items = 3, | |
1535 | .items = { | |
1536 | { "Mic/Line", 0x0 }, | |
1537 | { "CD", 0x5 }, | |
1538 | { "Mix", 0x9 }, | |
1539 | }, | |
1540 | }; | |
1541 | ||
1542 | /* | |
1543 | */ | |
1544 | static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol, | |
1545 | struct snd_ctl_elem_info *uinfo) | |
1546 | { | |
1547 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1548 | struct ad198x_spec *spec = codec->spec; | |
1549 | return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode, | |
1550 | spec->num_channel_mode); | |
1551 | } | |
1552 | ||
1553 | static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol, | |
1554 | struct snd_ctl_elem_value *ucontrol) | |
1555 | { | |
1556 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1557 | struct ad198x_spec *spec = codec->spec; | |
1558 | return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode, | |
1559 | spec->num_channel_mode, spec->multiout.max_channels); | |
1560 | } | |
1561 | ||
1562 | static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol, | |
1563 | struct snd_ctl_elem_value *ucontrol) | |
1564 | { | |
1565 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1566 | struct ad198x_spec *spec = codec->spec; | |
2125cad2 TI |
1567 | if (spec->need_dac_fix) |
1568 | spec->multiout.num_dacs = spec->multiout.max_channels / 2; | |
fd66e0d0 TI |
1569 | return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode, |
1570 | spec->num_channel_mode, &spec->multiout.max_channels); | |
1571 | } | |
1572 | ||
fd66e0d0 | 1573 | /* 6-stack mode */ |
d32410b1 | 1574 | static struct snd_kcontrol_new ad1988_6stack_mixers1[] = { |
fd66e0d0 TI |
1575 | HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), |
1576 | HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT), | |
1577 | HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT), | |
1578 | HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT), | |
1579 | HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT), | |
d32410b1 TI |
1580 | }; |
1581 | ||
1582 | static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = { | |
1583 | HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), | |
1584 | HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT), | |
1585 | HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT), | |
1586 | HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT), | |
1587 | HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT), | |
1588 | }; | |
fd66e0d0 | 1589 | |
d32410b1 | 1590 | static struct snd_kcontrol_new ad1988_6stack_mixers2[] = { |
fd66e0d0 TI |
1591 | HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT), |
1592 | HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT), | |
1593 | HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT), | |
1594 | HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT), | |
1595 | HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT), | |
1596 | HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT), | |
1597 | HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT), | |
1598 | ||
1599 | HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT), | |
1600 | HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT), | |
1601 | HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT), | |
1602 | HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT), | |
1603 | HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT), | |
1604 | HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT), | |
1605 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT), | |
1606 | HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT), | |
1607 | ||
1608 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT), | |
1609 | HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
1610 | ||
2e5b9567 | 1611 | HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), |
fd66e0d0 TI |
1612 | HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), |
1613 | ||
1614 | HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT), | |
1615 | HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT), | |
1616 | ||
1617 | { } /* end */ | |
1618 | }; | |
1619 | ||
1620 | /* 3-stack mode */ | |
d32410b1 | 1621 | static struct snd_kcontrol_new ad1988_3stack_mixers1[] = { |
fd66e0d0 | 1622 | HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), |
d32410b1 | 1623 | HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT), |
fd66e0d0 TI |
1624 | HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT), |
1625 | HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT), | |
d32410b1 TI |
1626 | }; |
1627 | ||
1628 | static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = { | |
1629 | HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), | |
f8c7c7b8 TI |
1630 | HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT), |
1631 | HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT), | |
1632 | HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT), | |
d32410b1 | 1633 | }; |
fd66e0d0 | 1634 | |
d32410b1 | 1635 | static struct snd_kcontrol_new ad1988_3stack_mixers2[] = { |
fd66e0d0 | 1636 | HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT), |
d32410b1 TI |
1637 | HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT), |
1638 | HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT), | |
1639 | HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT), | |
fd66e0d0 TI |
1640 | HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT), |
1641 | HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT), | |
1642 | ||
1643 | HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT), | |
1644 | HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT), | |
1645 | HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT), | |
1646 | HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT), | |
1647 | HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT), | |
1648 | HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT), | |
1649 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT), | |
1650 | HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT), | |
1651 | ||
1652 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT), | |
1653 | HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
1654 | ||
2e5b9567 | 1655 | HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), |
fd66e0d0 TI |
1656 | HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), |
1657 | ||
1658 | HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT), | |
1659 | HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT), | |
1660 | { | |
1661 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1662 | .name = "Channel Mode", | |
1663 | .info = ad198x_ch_mode_info, | |
1664 | .get = ad198x_ch_mode_get, | |
1665 | .put = ad198x_ch_mode_put, | |
1666 | }, | |
1667 | ||
1668 | { } /* end */ | |
1669 | }; | |
1670 | ||
1671 | /* laptop mode */ | |
1672 | static struct snd_kcontrol_new ad1988_laptop_mixers[] = { | |
1673 | HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT), | |
1674 | HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT), | |
1675 | HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT), | |
1676 | ||
1677 | HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT), | |
1678 | HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT), | |
1679 | HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT), | |
1680 | HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT), | |
1681 | HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT), | |
1682 | HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT), | |
1683 | ||
1684 | HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT), | |
1685 | HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT), | |
1686 | ||
2e5b9567 | 1687 | HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), |
fd66e0d0 TI |
1688 | HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), |
1689 | ||
1690 | HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT), | |
1691 | ||
1692 | { | |
1693 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1694 | .name = "External Amplifier", | |
18a815d7 TI |
1695 | .info = ad198x_eapd_info, |
1696 | .get = ad198x_eapd_get, | |
1697 | .put = ad198x_eapd_put, | |
1698 | .private_value = 0x12 | (1 << 8), /* port-D, inversed */ | |
fd66e0d0 TI |
1699 | }, |
1700 | ||
1701 | { } /* end */ | |
1702 | }; | |
1703 | ||
1704 | /* capture */ | |
1705 | static struct snd_kcontrol_new ad1988_capture_mixers[] = { | |
1706 | HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), | |
1707 | HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), | |
1708 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), | |
1709 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT), | |
1710 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT), | |
1711 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT), | |
1712 | { | |
1713 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1714 | /* The multiple "Capture Source" controls confuse alsamixer | |
1715 | * So call somewhat different.. | |
1716 | * FIXME: the controls appear in the "playback" view! | |
1717 | */ | |
1718 | /* .name = "Capture Source", */ | |
1719 | .name = "Input Source", | |
1720 | .count = 3, | |
1721 | .info = ad198x_mux_enum_info, | |
1722 | .get = ad198x_mux_enum_get, | |
1723 | .put = ad198x_mux_enum_put, | |
1724 | }, | |
1725 | { } /* end */ | |
1726 | }; | |
1727 | ||
1728 | static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol, | |
1729 | struct snd_ctl_elem_info *uinfo) | |
1730 | { | |
1731 | static char *texts[] = { | |
1732 | "PCM", "ADC1", "ADC2", "ADC3" | |
1733 | }; | |
1734 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
1735 | uinfo->count = 1; | |
1736 | uinfo->value.enumerated.items = 4; | |
1737 | if (uinfo->value.enumerated.item >= 4) | |
1738 | uinfo->value.enumerated.item = 3; | |
1739 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); | |
1740 | return 0; | |
1741 | } | |
1742 | ||
1743 | static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol, | |
1744 | struct snd_ctl_elem_value *ucontrol) | |
1745 | { | |
1746 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1747 | unsigned int sel; | |
1748 | ||
1749 | sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0); | |
1750 | if (sel > 0) { | |
1751 | sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0); | |
1752 | if (sel <= 3) | |
1753 | sel++; | |
1754 | else | |
1755 | sel = 0; | |
1756 | } | |
1757 | ucontrol->value.enumerated.item[0] = sel; | |
1758 | return 0; | |
1759 | } | |
1760 | ||
1761 | static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol, | |
1762 | struct snd_ctl_elem_value *ucontrol) | |
1763 | { | |
1764 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); | |
1765 | unsigned int sel; | |
1766 | int change; | |
1767 | ||
1768 | sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0); | |
1769 | if (! ucontrol->value.enumerated.item[0]) { | |
1770 | change = sel != 0; | |
1771 | if (change) | |
1772 | snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0); | |
1773 | } else { | |
1774 | change = sel == 0; | |
1775 | if (change) | |
1776 | snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1); | |
1777 | sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1; | |
1778 | change |= sel == ucontrol->value.enumerated.item[0]; | |
1779 | if (change) | |
1780 | snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, | |
1781 | ucontrol->value.enumerated.item[0] - 1); | |
1782 | } | |
1783 | return change; | |
1784 | } | |
1785 | ||
1786 | static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = { | |
1787 | HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT), | |
1788 | { | |
1789 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, | |
1790 | .name = "IEC958 Playback Source", | |
1791 | .info = ad1988_spdif_playback_source_info, | |
1792 | .get = ad1988_spdif_playback_source_get, | |
1793 | .put = ad1988_spdif_playback_source_put, | |
1794 | }, | |
1795 | { } /* end */ | |
1796 | }; | |
1797 | ||
1798 | static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = { | |
1799 | HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT), | |
1800 | { } /* end */ | |
1801 | }; | |
1802 | ||
1803 | ||
1804 | /* | |
1805 | * initialization verbs | |
1806 | */ | |
1807 | ||
1808 | /* | |
1809 | * for 6-stack (+dig) | |
1810 | */ | |
1811 | static struct hda_verb ad1988_6stack_init_verbs[] = { | |
2e5b9567 TI |
1812 | /* Front, Surround, CLFE, side DAC; unmute as default */ |
1813 | {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1814 | {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1815 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1816 | {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
fd66e0d0 TI |
1817 | /* Port-A front headphon path */ |
1818 | {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */ | |
1819 | {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1820 | {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1821 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1822 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1823 | /* Port-D line-out path */ | |
1824 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1825 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1826 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1827 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1828 | /* Port-F surround path */ | |
1829 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1830 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1831 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1832 | {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1833 | /* Port-G CLFE path */ | |
1834 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1835 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1836 | {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1837 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1838 | /* Port-H side path */ | |
1839 | {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1840 | {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1841 | {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1842 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1843 | /* Mono out path */ | |
1844 | {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */ | |
1845 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1846 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1847 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1848 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */ | |
1849 | /* Port-B front mic-in path */ | |
1850 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1851 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1852 | {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1853 | /* Port-C line-in path */ | |
1854 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1855 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, | |
1856 | {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1857 | {0x33, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1858 | /* Port-E mic-in path */ | |
1859 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1860 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1861 | {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
1862 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
1863 | ||
1864 | { } | |
1865 | }; | |
1866 | ||
1867 | static struct hda_verb ad1988_capture_init_verbs[] = { | |
1868 | /* mute analog mix */ | |
1869 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1870 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1871 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
1872 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
1873 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
1874 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, | |
1875 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, | |
1876 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, | |
1877 | /* select ADCs - front-mic */ | |
1878 | {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1879 | {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1880 | {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1881 | /* ADCs; muted */ | |
1882 | {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1883 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1884 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1885 | ||
1886 | { } | |
1887 | }; | |
1888 | ||
1889 | static struct hda_verb ad1988_spdif_init_verbs[] = { | |
1890 | /* SPDIF out sel */ | |
1891 | {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */ | |
1892 | {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */ | |
1893 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, | |
1894 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, | |
1895 | /* SPDIF out pin */ | |
1896 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */ | |
1897 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */ | |
1898 | ||
1899 | { } | |
1900 | }; | |
1901 | ||
1902 | /* | |
1903 | * verbs for 3stack (+dig) | |
1904 | */ | |
1905 | static struct hda_verb ad1988_3stack_ch2_init[] = { | |
1906 | /* set port-C to line-in */ | |
1907 | { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | |
1908 | { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, | |
1909 | /* set port-E to mic-in */ | |
1910 | { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | |
1911 | { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, | |
1912 | { } /* end */ | |
1913 | }; | |
1914 | ||
1915 | static struct hda_verb ad1988_3stack_ch6_init[] = { | |
1916 | /* set port-C to surround out */ | |
fd66e0d0 | 1917 | { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
d32410b1 | 1918 | { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, |
fd66e0d0 | 1919 | /* set port-E to CLFE out */ |
fd66e0d0 | 1920 | { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, |
d32410b1 | 1921 | { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, |
fd66e0d0 TI |
1922 | { } /* end */ |
1923 | }; | |
1924 | ||
1925 | static struct hda_channel_mode ad1988_3stack_modes[2] = { | |
1926 | { 2, ad1988_3stack_ch2_init }, | |
1927 | { 6, ad1988_3stack_ch6_init }, | |
1928 | }; | |
1929 | ||
1930 | static struct hda_verb ad1988_3stack_init_verbs[] = { | |
2e5b9567 TI |
1931 | /* Front, Surround, CLFE, side DAC; unmute as default */ |
1932 | {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1933 | {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1934 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1935 | {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
fd66e0d0 TI |
1936 | /* Port-A front headphon path */ |
1937 | {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */ | |
1938 | {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1939 | {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1940 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1941 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
1942 | /* Port-D line-out path */ | |
1943 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1944 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1945 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
1946 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1947 | /* Mono out path */ | |
1948 | {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */ | |
1949 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1950 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1951 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1952 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */ | |
1953 | /* Port-B front mic-in path */ | |
1954 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1955 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
1956 | {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
d32410b1 TI |
1957 | /* Port-C line-in/surround path - 6ch mode as default */ |
1958 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1959 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
fd66e0d0 | 1960 | {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
d32410b1 | 1961 | {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */ |
fd66e0d0 | 1962 | {0x33, AC_VERB_SET_CONNECT_SEL, 0x0}, |
d32410b1 TI |
1963 | /* Port-E mic-in/CLFE path - 6ch mode as default */ |
1964 | {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
1965 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
fd66e0d0 | 1966 | {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
f8c7c7b8 | 1967 | {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */ |
fd66e0d0 TI |
1968 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x0}, |
1969 | /* mute analog mix */ | |
1970 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
1971 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
1972 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
1973 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
1974 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
1975 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, | |
1976 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, | |
1977 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, | |
1978 | /* select ADCs - front-mic */ | |
1979 | {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1980 | {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1981 | {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
1982 | /* ADCs; muted */ | |
1983 | {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1984 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1985 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
1986 | { } | |
1987 | }; | |
1988 | ||
1989 | /* | |
1990 | * verbs for laptop mode (+dig) | |
1991 | */ | |
1992 | static struct hda_verb ad1988_laptop_hp_on[] = { | |
1993 | /* unmute port-A and mute port-D */ | |
1994 | { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, | |
1995 | { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | |
1996 | { } /* end */ | |
1997 | }; | |
1998 | static struct hda_verb ad1988_laptop_hp_off[] = { | |
1999 | /* mute port-A and unmute port-D */ | |
2000 | { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, | |
2001 | { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, | |
2002 | { } /* end */ | |
2003 | }; | |
2004 | ||
2005 | #define AD1988_HP_EVENT 0x01 | |
2006 | ||
2007 | static struct hda_verb ad1988_laptop_init_verbs[] = { | |
2e5b9567 TI |
2008 | /* Front, Surround, CLFE, side DAC; unmute as default */ |
2009 | {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2010 | {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2011 | {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2012 | {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
fd66e0d0 TI |
2013 | /* Port-A front headphon path */ |
2014 | {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */ | |
2015 | {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2016 | {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2017 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2018 | {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, | |
2019 | /* unsolicited event for pin-sense */ | |
2020 | {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT }, | |
2021 | /* Port-D line-out path + EAPD */ | |
2022 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2023 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2024 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2025 | {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2026 | {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */ | |
2027 | /* Mono out path */ | |
2028 | {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */ | |
2029 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2030 | {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2031 | {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2032 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */ | |
2033 | /* Port-B mic-in path */ | |
2034 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
2035 | {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, | |
2036 | {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2037 | /* Port-C docking station - try to output */ | |
2038 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, | |
2039 | {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, | |
2040 | {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, | |
2041 | {0x33, AC_VERB_SET_CONNECT_SEL, 0x0}, | |
2042 | /* mute analog mix */ | |
2043 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, | |
2044 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, | |
2045 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, | |
2046 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, | |
2047 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, | |
2048 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, | |
2049 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, | |
2050 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, | |
2051 | /* select ADCs - mic */ | |
2052 | {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
2053 | {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
2054 | {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, | |
2055 | /* ADCs; muted */ | |
2056 | {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
2057 | {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
2058 | {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, | |
2059 | { } | |
2060 | }; | |
2061 | ||
2062 | static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res) | |
2063 | { | |
2064 | if ((res >> 26) != AD1988_HP_EVENT) | |
2065 | return; | |
2066 | if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31)) | |
2067 | snd_hda_sequence_write(codec, ad1988_laptop_hp_on); | |
2068 | else | |
2069 | snd_hda_sequence_write(codec, ad1988_laptop_hp_off); | |
2070 | } | |
2071 | ||
2072 | ||
d32410b1 TI |
2073 | /* |
2074 | * Automatic parse of I/O pins from the BIOS configuration | |
2075 | */ | |
2076 | ||
2077 | #define NUM_CONTROL_ALLOC 32 | |
2078 | #define NUM_VERB_ALLOC 32 | |
2079 | ||
2080 | enum { | |
2081 | AD_CTL_WIDGET_VOL, | |
2082 | AD_CTL_WIDGET_MUTE, | |
2083 | AD_CTL_BIND_MUTE, | |
2084 | }; | |
2085 | static struct snd_kcontrol_new ad1988_control_templates[] = { | |
2086 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), | |
2087 | HDA_CODEC_MUTE(NULL, 0, 0, 0), | |
2088 | HDA_BIND_MUTE(NULL, 0, 0, 0), | |
2089 | }; | |
2090 | ||
2091 | /* add dynamic controls */ | |
2092 | static int add_control(struct ad198x_spec *spec, int type, const char *name, | |
2093 | unsigned long val) | |
2094 | { | |
2095 | struct snd_kcontrol_new *knew; | |
2096 | ||
2097 | if (spec->num_kctl_used >= spec->num_kctl_alloc) { | |
2098 | int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC; | |
2099 | ||
2100 | knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */ | |
2101 | if (! knew) | |
2102 | return -ENOMEM; | |
2103 | if (spec->kctl_alloc) { | |
2104 | memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc); | |
2105 | kfree(spec->kctl_alloc); | |
2106 | } | |
2107 | spec->kctl_alloc = knew; | |
2108 | spec->num_kctl_alloc = num; | |
2109 | } | |
2110 | ||
2111 | knew = &spec->kctl_alloc[spec->num_kctl_used]; | |
2112 | *knew = ad1988_control_templates[type]; | |
2113 | knew->name = kstrdup(name, GFP_KERNEL); | |
2114 | if (! knew->name) | |
2115 | return -ENOMEM; | |
2116 | knew->private_value = val; | |
2117 | spec->num_kctl_used++; | |
2118 | return 0; | |
2119 | } | |
2120 | ||
2121 | #define AD1988_PIN_CD_NID 0x18 | |
2122 | #define AD1988_PIN_BEEP_NID 0x10 | |
2123 | ||
2124 | static hda_nid_t ad1988_mixer_nids[8] = { | |
2125 | /* A B C D E F G H */ | |
2126 | 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28 | |
2127 | }; | |
2128 | ||
2129 | static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx) | |
2130 | { | |
2131 | static hda_nid_t idx_to_dac[8] = { | |
2132 | /* A B C D E F G H */ | |
f8c7c7b8 | 2133 | 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a |
d32410b1 TI |
2134 | }; |
2135 | static hda_nid_t idx_to_dac_rev2[8] = { | |
2136 | /* A B C D E F G H */ | |
f8c7c7b8 | 2137 | 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06 |
d32410b1 TI |
2138 | }; |
2139 | if (codec->revision_id == AD1988A_REV2) | |
2140 | return idx_to_dac_rev2[idx]; | |
2141 | else | |
2142 | return idx_to_dac[idx]; | |
2143 | } | |
2144 | ||
2145 | static hda_nid_t ad1988_boost_nids[8] = { | |
2146 | 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0 | |
2147 | }; | |
2148 | ||
2149 | static int ad1988_pin_idx(hda_nid_t nid) | |
2150 | { | |
2151 | static hda_nid_t ad1988_io_pins[8] = { | |
2152 | 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25 | |
2153 | }; | |
2154 | int i; | |
2155 | for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++) | |
2156 | if (ad1988_io_pins[i] == nid) | |
2157 | return i; | |
2158 | return 0; /* should be -1 */ | |
2159 | } | |
2160 | ||
2161 | static int ad1988_pin_to_loopback_idx(hda_nid_t nid) | |
2162 | { | |
2163 | static int loopback_idx[8] = { | |
2164 | 2, 0, 1, 3, 4, 5, 1, 4 | |
2165 | }; | |
2166 | switch (nid) { | |
2167 | case AD1988_PIN_CD_NID: | |
2168 | return 6; | |
2169 | default: | |
2170 | return loopback_idx[ad1988_pin_idx(nid)]; | |
2171 | } | |
2172 | } | |
2173 | ||
2174 | static int ad1988_pin_to_adc_idx(hda_nid_t nid) | |
2175 | { | |
2176 | static int adc_idx[8] = { | |
2177 | 0, 1, 2, 8, 4, 3, 6, 7 | |
2178 | }; | |
2179 | switch (nid) { | |
2180 | case AD1988_PIN_CD_NID: | |
2181 | return 5; | |
2182 | default: | |
2183 | return adc_idx[ad1988_pin_idx(nid)]; | |
2184 | } | |
2185 | } | |
2186 | ||
2187 | /* fill in the dac_nids table from the parsed pin configuration */ | |
2188 | static int ad1988_auto_fill_dac_nids(struct hda_codec *codec, | |
2189 | const struct auto_pin_cfg *cfg) | |
2190 | { | |
2191 | struct ad198x_spec *spec = codec->spec; | |
2192 | int i, idx; | |
2193 | ||
2194 | spec->multiout.dac_nids = spec->private_dac_nids; | |
2195 | ||
2196 | /* check the pins hardwired to audio widget */ | |
2197 | for (i = 0; i < cfg->line_outs; i++) { | |
2198 | idx = ad1988_pin_idx(cfg->line_out_pins[i]); | |
2199 | spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx); | |
2200 | } | |
2201 | spec->multiout.num_dacs = cfg->line_outs; | |
2202 | return 0; | |
2203 | } | |
2204 | ||
2205 | /* add playback controls from the parsed DAC table */ | |
2206 | static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec, | |
2207 | const struct auto_pin_cfg *cfg) | |
2208 | { | |
2209 | char name[32]; | |
2210 | static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" }; | |
2211 | hda_nid_t nid; | |
2212 | int i, err; | |
2213 | ||
2214 | for (i = 0; i < cfg->line_outs; i++) { | |
2215 | hda_nid_t dac = spec->multiout.dac_nids[i]; | |
2216 | if (! dac) | |
2217 | continue; | |
2218 | nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])]; | |
2219 | if (i == 2) { | |
2220 | /* Center/LFE */ | |
2221 | err = add_control(spec, AD_CTL_WIDGET_VOL, | |
2222 | "Center Playback Volume", | |
2223 | HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT)); | |
2224 | if (err < 0) | |
2225 | return err; | |
2226 | err = add_control(spec, AD_CTL_WIDGET_VOL, | |
2227 | "LFE Playback Volume", | |
2228 | HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT)); | |
2229 | if (err < 0) | |
2230 | return err; | |
2231 | err = add_control(spec, AD_CTL_BIND_MUTE, | |
2232 | "Center Playback Switch", | |
2233 | HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT)); | |
2234 | if (err < 0) | |
2235 | return err; | |
2236 | err = add_control(spec, AD_CTL_BIND_MUTE, | |
2237 | "LFE Playback Switch", | |
2238 | HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT)); | |
2239 | if (err < 0) | |
2240 | return err; | |
2241 | } else { | |
2242 | sprintf(name, "%s Playback Volume", chname[i]); | |
2243 | err = add_control(spec, AD_CTL_WIDGET_VOL, name, | |
2244 | HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT)); | |
2245 | if (err < 0) | |
2246 | return err; | |
2247 | sprintf(name, "%s Playback Switch", chname[i]); | |
2248 | err = add_control(spec, AD_CTL_BIND_MUTE, name, | |
2249 | HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT)); | |
2250 | if (err < 0) | |
2251 | return err; | |
2252 | } | |
2253 | } | |
2254 | return 0; | |
2255 | } | |
2256 | ||
2257 | /* add playback controls for speaker and HP outputs */ | |
2258 | static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, | |
2259 | const char *pfx) | |
2260 | { | |
2261 | struct ad198x_spec *spec = codec->spec; | |
2262 | hda_nid_t nid; | |
2263 | int idx, err; | |
2264 | char name[32]; | |
2265 | ||
2266 | if (! pin) | |
2267 | return 0; | |
2268 | ||
2269 | idx = ad1988_pin_idx(pin); | |
2270 | nid = ad1988_idx_to_dac(codec, idx); | |
82bc955f TI |
2271 | /* specify the DAC as the extra output */ |
2272 | if (! spec->multiout.hp_nid) | |
d32410b1 | 2273 | spec->multiout.hp_nid = nid; |
82bc955f TI |
2274 | else |
2275 | spec->multiout.extra_out_nid[0] = nid; | |
d32410b1 TI |
2276 | /* control HP volume/switch on the output mixer amp */ |
2277 | sprintf(name, "%s Playback Volume", pfx); | |
2278 | if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name, | |
2279 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0) | |
2280 | return err; | |
2281 | nid = ad1988_mixer_nids[idx]; | |
2282 | sprintf(name, "%s Playback Switch", pfx); | |
2283 | if ((err = add_control(spec, AD_CTL_BIND_MUTE, name, | |
2284 | HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0) | |
2285 | return err; | |
2286 | return 0; | |
2287 | } | |
2288 | ||
2289 | /* create input playback/capture controls for the given pin */ | |
2290 | static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin, | |
2291 | const char *ctlname, int boost) | |
2292 | { | |
2293 | char name[32]; | |
2294 | int err, idx; | |
2295 | ||
2296 | sprintf(name, "%s Playback Volume", ctlname); | |
2297 | idx = ad1988_pin_to_loopback_idx(pin); | |
2298 | if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name, | |
2299 | HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0) | |
2300 | return err; | |
2301 | sprintf(name, "%s Playback Switch", ctlname); | |
2302 | if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name, | |
2303 | HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0) | |
2304 | return err; | |
2305 | if (boost) { | |
2306 | hda_nid_t bnid; | |
2307 | idx = ad1988_pin_idx(pin); | |
2308 | bnid = ad1988_boost_nids[idx]; | |
2309 | if (bnid) { | |
2310 | sprintf(name, "%s Boost", ctlname); | |
2311 | return add_control(spec, AD_CTL_WIDGET_VOL, name, | |
2312 | HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT)); | |
2313 | ||
2314 | } | |
2315 | } | |
2316 | return 0; | |
2317 | } | |
2318 | ||
2319 | /* create playback/capture controls for input pins */ | |
2320 | static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec, | |
2321 | const struct auto_pin_cfg *cfg) | |
2322 | { | |
d32410b1 TI |
2323 | struct hda_input_mux *imux = &spec->private_imux; |
2324 | int i, err; | |
2325 | ||
2326 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
4a471b7d TI |
2327 | err = new_analog_input(spec, cfg->input_pins[i], |
2328 | auto_pin_cfg_labels[i], | |
d32410b1 TI |
2329 | i <= AUTO_PIN_FRONT_MIC); |
2330 | if (err < 0) | |
2331 | return err; | |
4a471b7d | 2332 | imux->items[imux->num_items].label = auto_pin_cfg_labels[i]; |
d32410b1 TI |
2333 | imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]); |
2334 | imux->num_items++; | |
2335 | } | |
2336 | imux->items[imux->num_items].label = "Mix"; | |
2337 | imux->items[imux->num_items].index = 9; | |
2338 | imux->num_items++; | |
2339 | ||
2340 | if ((err = add_control(spec, AD_CTL_WIDGET_VOL, | |
2341 | "Analog Mix Playback Volume", | |
2342 | HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0) | |
2343 | return err; | |
2344 | if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, | |
2345 | "Analog Mix Playback Switch", | |
2346 | HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0) | |
2347 | return err; | |
2348 | ||
2349 | return 0; | |
2350 | } | |
2351 | ||
2352 | static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec, | |
2353 | hda_nid_t nid, int pin_type, | |
2354 | int dac_idx) | |
2355 | { | |
2356 | /* set as output */ | |
2357 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); | |
2358 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); | |
2359 | switch (nid) { | |
2360 | case 0x11: /* port-A - DAC 04 */ | |
2361 | snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01); | |
2362 | break; | |
2363 | case 0x14: /* port-B - DAC 06 */ | |
2364 | snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02); | |
2365 | break; | |
2366 | case 0x15: /* port-C - DAC 05 */ | |
2367 | snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00); | |
2368 | break; | |
f8c7c7b8 | 2369 | case 0x17: /* port-E - DAC 0a */ |
d32410b1 TI |
2370 | snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01); |
2371 | break; | |
2372 | case 0x13: /* mono - DAC 04 */ | |
2373 | snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01); | |
2374 | break; | |
2375 | } | |
2376 | } | |
2377 | ||
2378 | static void ad1988_auto_init_multi_out(struct hda_codec *codec) | |
2379 | { | |
2380 | struct ad198x_spec *spec = codec->spec; | |
2381 | int i; | |
2382 | ||
2383 | for (i = 0; i < spec->autocfg.line_outs; i++) { | |
2384 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; | |
2385 | ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); | |
2386 | } | |
2387 | } | |
2388 | ||
2389 | static void ad1988_auto_init_extra_out(struct hda_codec *codec) | |
2390 | { | |
2391 | struct ad198x_spec *spec = codec->spec; | |
2392 | hda_nid_t pin; | |
2393 | ||
82bc955f | 2394 | pin = spec->autocfg.speaker_pins[0]; |
d32410b1 TI |
2395 | if (pin) /* connect to front */ |
2396 | ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); | |
2397 | pin = spec->autocfg.hp_pin; | |
2398 | if (pin) /* connect to front */ | |
2399 | ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); | |
2400 | } | |
2401 | ||
2402 | static void ad1988_auto_init_analog_input(struct hda_codec *codec) | |
2403 | { | |
2404 | struct ad198x_spec *spec = codec->spec; | |
2405 | int i, idx; | |
2406 | ||
2407 | for (i = 0; i < AUTO_PIN_LAST; i++) { | |
2408 | hda_nid_t nid = spec->autocfg.input_pins[i]; | |
2409 | if (! nid) | |
2410 | continue; | |
2411 | switch (nid) { | |
2412 | case 0x15: /* port-C */ | |
2413 | snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0); | |
2414 | break; | |
2415 | case 0x17: /* port-E */ | |
2416 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0); | |
2417 | break; | |
2418 | } | |
2419 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, | |
2420 | i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN); | |
2421 | if (nid != AD1988_PIN_CD_NID) | |
2422 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, | |
2423 | AMP_OUT_MUTE); | |
2424 | idx = ad1988_pin_idx(nid); | |
2425 | if (ad1988_boost_nids[idx]) | |
2426 | snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0, | |
2427 | AC_VERB_SET_AMP_GAIN_MUTE, | |
2428 | AMP_OUT_ZERO); | |
2429 | } | |
2430 | } | |
2431 | ||
2432 | /* parse the BIOS configuration and set up the alc_spec */ | |
2433 | /* return 1 if successful, 0 if the proper config is not found, or a negative error code */ | |
2434 | static int ad1988_parse_auto_config(struct hda_codec *codec) | |
2435 | { | |
2436 | struct ad198x_spec *spec = codec->spec; | |
2437 | int err; | |
2438 | ||
df694daa | 2439 | if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0) |
d32410b1 TI |
2440 | return err; |
2441 | if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0) | |
2442 | return err; | |
82bc955f | 2443 | if (! spec->autocfg.line_outs) |
d32410b1 TI |
2444 | return 0; /* can't find valid BIOS pin config */ |
2445 | if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 || | |
82bc955f TI |
2446 | (err = ad1988_auto_create_extra_out(codec, |
2447 | spec->autocfg.speaker_pins[0], | |
d32410b1 | 2448 | "Speaker")) < 0 || |
82bc955f | 2449 | (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pin, |
d32410b1 TI |
2450 | "Headphone")) < 0 || |
2451 | (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0) | |
2452 | return err; | |
2453 | ||
2454 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; | |
2455 | ||
2456 | if (spec->autocfg.dig_out_pin) | |
2457 | spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; | |
2458 | if (spec->autocfg.dig_in_pin) | |
2459 | spec->dig_in_nid = AD1988_SPDIF_IN; | |
2460 | ||
2461 | if (spec->kctl_alloc) | |
2462 | spec->mixers[spec->num_mixers++] = spec->kctl_alloc; | |
2463 | ||
2464 | spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs; | |
2465 | ||
2466 | spec->input_mux = &spec->private_imux; | |
2467 | ||
2468 | return 1; | |
2469 | } | |
2470 | ||
2471 | /* init callback for auto-configuration model -- overriding the default init */ | |
2472 | static int ad1988_auto_init(struct hda_codec *codec) | |
2473 | { | |
2474 | ad198x_init(codec); | |
2475 | ad1988_auto_init_multi_out(codec); | |
2476 | ad1988_auto_init_extra_out(codec); | |
2477 | ad1988_auto_init_analog_input(codec); | |
2478 | return 0; | |
2479 | } | |
2480 | ||
2481 | ||
fd66e0d0 TI |
2482 | /* |
2483 | */ | |
2484 | ||
2485 | static struct hda_board_config ad1988_cfg_tbl[] = { | |
2486 | { .modelname = "6stack", .config = AD1988_6STACK }, | |
2487 | { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG }, | |
2488 | { .modelname = "3stack", .config = AD1988_3STACK }, | |
2489 | { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG }, | |
2490 | { .modelname = "laptop", .config = AD1988_LAPTOP }, | |
2491 | { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG }, | |
d32410b1 | 2492 | { .modelname = "auto", .config = AD1988_AUTO }, |
fd66e0d0 TI |
2493 | {} |
2494 | }; | |
2495 | ||
2496 | static int patch_ad1988(struct hda_codec *codec) | |
2497 | { | |
2498 | struct ad198x_spec *spec; | |
2499 | int board_config; | |
2500 | ||
2501 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | |
2502 | if (spec == NULL) | |
2503 | return -ENOMEM; | |
2504 | ||
62932df8 | 2505 | mutex_init(&spec->amp_mutex); |
fd66e0d0 TI |
2506 | codec->spec = spec; |
2507 | ||
f8c7c7b8 TI |
2508 | if (codec->revision_id == AD1988A_REV2) |
2509 | snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n"); | |
2510 | ||
fd66e0d0 TI |
2511 | board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl); |
2512 | if (board_config < 0 || board_config >= AD1988_MODEL_LAST) { | |
d32410b1 TI |
2513 | printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n"); |
2514 | board_config = AD1988_AUTO; | |
2515 | } | |
2516 | ||
2517 | if (board_config == AD1988_AUTO) { | |
2518 | /* automatic parse from the BIOS config */ | |
2519 | int err = ad1988_parse_auto_config(codec); | |
2520 | if (err < 0) { | |
2521 | ad198x_free(codec); | |
2522 | return err; | |
2523 | } else if (! err) { | |
2524 | printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n"); | |
2525 | board_config = AD1988_6STACK; | |
2526 | } | |
fd66e0d0 TI |
2527 | } |
2528 | ||
2529 | switch (board_config) { | |
2530 | case AD1988_6STACK: | |
2531 | case AD1988_6STACK_DIG: | |
2532 | spec->multiout.max_channels = 8; | |
2533 | spec->multiout.num_dacs = 4; | |
d32410b1 TI |
2534 | if (codec->revision_id == AD1988A_REV2) |
2535 | spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2; | |
2536 | else | |
2537 | spec->multiout.dac_nids = ad1988_6stack_dac_nids; | |
fd66e0d0 | 2538 | spec->input_mux = &ad1988_6stack_capture_source; |
d32410b1 TI |
2539 | spec->num_mixers = 2; |
2540 | if (codec->revision_id == AD1988A_REV2) | |
2541 | spec->mixers[0] = ad1988_6stack_mixers1_rev2; | |
2542 | else | |
2543 | spec->mixers[0] = ad1988_6stack_mixers1; | |
2544 | spec->mixers[1] = ad1988_6stack_mixers2; | |
fd66e0d0 TI |
2545 | spec->num_init_verbs = 1; |
2546 | spec->init_verbs[0] = ad1988_6stack_init_verbs; | |
2547 | if (board_config == AD1988_6STACK_DIG) { | |
2548 | spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; | |
2549 | spec->dig_in_nid = AD1988_SPDIF_IN; | |
2550 | } | |
2551 | break; | |
2552 | case AD1988_3STACK: | |
2553 | case AD1988_3STACK_DIG: | |
2554 | spec->multiout.max_channels = 6; | |
2555 | spec->multiout.num_dacs = 3; | |
d32410b1 TI |
2556 | if (codec->revision_id == AD1988A_REV2) |
2557 | spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2; | |
2558 | else | |
2559 | spec->multiout.dac_nids = ad1988_3stack_dac_nids; | |
fd66e0d0 TI |
2560 | spec->input_mux = &ad1988_6stack_capture_source; |
2561 | spec->channel_mode = ad1988_3stack_modes; | |
2562 | spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes); | |
d32410b1 TI |
2563 | spec->num_mixers = 2; |
2564 | if (codec->revision_id == AD1988A_REV2) | |
2565 | spec->mixers[0] = ad1988_3stack_mixers1_rev2; | |
2566 | else | |
2567 | spec->mixers[0] = ad1988_3stack_mixers1; | |
2568 | spec->mixers[1] = ad1988_3stack_mixers2; | |
fd66e0d0 TI |
2569 | spec->num_init_verbs = 1; |
2570 | spec->init_verbs[0] = ad1988_3stack_init_verbs; | |
2571 | if (board_config == AD1988_3STACK_DIG) | |
2572 | spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; | |
2573 | break; | |
2574 | case AD1988_LAPTOP: | |
2575 | case AD1988_LAPTOP_DIG: | |
2576 | spec->multiout.max_channels = 2; | |
2577 | spec->multiout.num_dacs = 1; | |
d32410b1 | 2578 | spec->multiout.dac_nids = ad1988_3stack_dac_nids; |
fd66e0d0 TI |
2579 | spec->input_mux = &ad1988_laptop_capture_source; |
2580 | spec->num_mixers = 1; | |
2581 | spec->mixers[0] = ad1988_laptop_mixers; | |
2582 | spec->num_init_verbs = 1; | |
2583 | spec->init_verbs[0] = ad1988_laptop_init_verbs; | |
2584 | if (board_config == AD1988_LAPTOP_DIG) | |
2585 | spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; | |
2586 | break; | |
2587 | } | |
2588 | ||
d32410b1 TI |
2589 | spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids); |
2590 | spec->adc_nids = ad1988_adc_nids; | |
2591 | spec->capsrc_nids = ad1988_capsrc_nids; | |
fd66e0d0 TI |
2592 | spec->mixers[spec->num_mixers++] = ad1988_capture_mixers; |
2593 | spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs; | |
2594 | if (spec->multiout.dig_out_nid) { | |
2595 | spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers; | |
2596 | spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs; | |
2597 | } | |
2598 | if (spec->dig_in_nid) | |
2599 | spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers; | |
2600 | ||
2601 | codec->patch_ops = ad198x_patch_ops; | |
2602 | switch (board_config) { | |
d32410b1 TI |
2603 | case AD1988_AUTO: |
2604 | codec->patch_ops.init = ad1988_auto_init; | |
2605 | break; | |
fd66e0d0 TI |
2606 | case AD1988_LAPTOP: |
2607 | case AD1988_LAPTOP_DIG: | |
2608 | codec->patch_ops.unsol_event = ad1988_laptop_unsol_event; | |
2609 | break; | |
2610 | } | |
2611 | ||
2612 | return 0; | |
2613 | } | |
2614 | ||
2615 | ||
1da177e4 LT |
2616 | /* |
2617 | * patch entries | |
2618 | */ | |
2619 | struct hda_codec_preset snd_hda_preset_analog[] = { | |
4a3fdf3d TI |
2620 | { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 }, |
2621 | { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 }, | |
1da177e4 | 2622 | { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, |
fd66e0d0 | 2623 | { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, |
1da177e4 LT |
2624 | {} /* terminator */ |
2625 | }; |