add port definition for mcf UART driver
[linux-2.6/next.git] / sound / pci / hda / patch_analog.c
blob0ee8ae4d4410b89c7405ac3c5c25ba111fc8703d
1 /*
2 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
5 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/mutex.h>
29 #include <sound/core.h>
30 #include "hda_codec.h"
31 #include "hda_local.h"
33 struct ad198x_spec {
34 struct snd_kcontrol_new *mixers[5];
35 int num_mixers;
37 const struct hda_verb *init_verbs[5]; /* initialization verbs
38 * don't forget NULL termination!
40 unsigned int num_init_verbs;
42 /* playback */
43 struct hda_multi_out multiout; /* playback set-up
44 * max_channels, dacs must be set
45 * dig_out_nid and hp_nid are optional
47 unsigned int cur_eapd;
48 unsigned int need_dac_fix;
50 /* capture */
51 unsigned int num_adc_nids;
52 hda_nid_t *adc_nids;
53 hda_nid_t dig_in_nid; /* digital-in NID; optional */
55 /* capture source */
56 const struct hda_input_mux *input_mux;
57 hda_nid_t *capsrc_nids;
58 unsigned int cur_mux[3];
60 /* channel model */
61 const struct hda_channel_mode *channel_mode;
62 int num_channel_mode;
64 /* PCM information */
65 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
67 struct mutex amp_mutex; /* PCM volume/mute control mutex */
68 unsigned int spdif_route;
70 /* dynamic controls, init_verbs and input_mux */
71 struct auto_pin_cfg autocfg;
72 unsigned int num_kctl_alloc, num_kctl_used;
73 struct snd_kcontrol_new *kctl_alloc;
74 struct hda_input_mux private_imux;
75 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
77 unsigned int jack_present :1;
79 #ifdef CONFIG_SND_HDA_POWER_SAVE
80 struct hda_loopback_check loopback;
81 #endif
85 * input MUX handling (common part)
87 static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
89 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
90 struct ad198x_spec *spec = codec->spec;
92 return snd_hda_input_mux_info(spec->input_mux, uinfo);
95 static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
97 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
98 struct ad198x_spec *spec = codec->spec;
99 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
101 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
102 return 0;
105 static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
107 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
108 struct ad198x_spec *spec = codec->spec;
109 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
111 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
112 spec->capsrc_nids[adc_idx],
113 &spec->cur_mux[adc_idx]);
117 * initialization (common callbacks)
119 static int ad198x_init(struct hda_codec *codec)
121 struct ad198x_spec *spec = codec->spec;
122 int i;
124 for (i = 0; i < spec->num_init_verbs; i++)
125 snd_hda_sequence_write(codec, spec->init_verbs[i]);
126 return 0;
129 static int ad198x_build_controls(struct hda_codec *codec)
131 struct ad198x_spec *spec = codec->spec;
132 unsigned int i;
133 int err;
135 for (i = 0; i < spec->num_mixers; i++) {
136 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
137 if (err < 0)
138 return err;
140 if (spec->multiout.dig_out_nid) {
141 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
142 if (err < 0)
143 return err;
145 if (spec->dig_in_nid) {
146 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
147 if (err < 0)
148 return err;
150 return 0;
153 #ifdef CONFIG_SND_HDA_POWER_SAVE
154 static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
156 struct ad198x_spec *spec = codec->spec;
157 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
159 #endif
162 * Analog playback callbacks
164 static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
165 struct hda_codec *codec,
166 struct snd_pcm_substream *substream)
168 struct ad198x_spec *spec = codec->spec;
169 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
172 static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
173 struct hda_codec *codec,
174 unsigned int stream_tag,
175 unsigned int format,
176 struct snd_pcm_substream *substream)
178 struct ad198x_spec *spec = codec->spec;
179 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
180 format, substream);
183 static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
184 struct hda_codec *codec,
185 struct snd_pcm_substream *substream)
187 struct ad198x_spec *spec = codec->spec;
188 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
192 * Digital out
194 static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
195 struct hda_codec *codec,
196 struct snd_pcm_substream *substream)
198 struct ad198x_spec *spec = codec->spec;
199 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
202 static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
203 struct hda_codec *codec,
204 struct snd_pcm_substream *substream)
206 struct ad198x_spec *spec = codec->spec;
207 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
210 static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 unsigned int stream_tag,
213 unsigned int format,
214 struct snd_pcm_substream *substream)
216 struct ad198x_spec *spec = codec->spec;
217 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
218 format, substream);
222 * Analog capture
224 static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
225 struct hda_codec *codec,
226 unsigned int stream_tag,
227 unsigned int format,
228 struct snd_pcm_substream *substream)
230 struct ad198x_spec *spec = codec->spec;
231 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
232 stream_tag, 0, format);
233 return 0;
236 static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
237 struct hda_codec *codec,
238 struct snd_pcm_substream *substream)
240 struct ad198x_spec *spec = codec->spec;
241 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
242 0, 0, 0);
243 return 0;
249 static struct hda_pcm_stream ad198x_pcm_analog_playback = {
250 .substreams = 1,
251 .channels_min = 2,
252 .channels_max = 6, /* changed later */
253 .nid = 0, /* fill later */
254 .ops = {
255 .open = ad198x_playback_pcm_open,
256 .prepare = ad198x_playback_pcm_prepare,
257 .cleanup = ad198x_playback_pcm_cleanup
261 static struct hda_pcm_stream ad198x_pcm_analog_capture = {
262 .substreams = 1,
263 .channels_min = 2,
264 .channels_max = 2,
265 .nid = 0, /* fill later */
266 .ops = {
267 .prepare = ad198x_capture_pcm_prepare,
268 .cleanup = ad198x_capture_pcm_cleanup
272 static struct hda_pcm_stream ad198x_pcm_digital_playback = {
273 .substreams = 1,
274 .channels_min = 2,
275 .channels_max = 2,
276 .nid = 0, /* fill later */
277 .ops = {
278 .open = ad198x_dig_playback_pcm_open,
279 .close = ad198x_dig_playback_pcm_close,
280 .prepare = ad198x_dig_playback_pcm_prepare
284 static struct hda_pcm_stream ad198x_pcm_digital_capture = {
285 .substreams = 1,
286 .channels_min = 2,
287 .channels_max = 2,
288 /* NID is set in alc_build_pcms */
291 static int ad198x_build_pcms(struct hda_codec *codec)
293 struct ad198x_spec *spec = codec->spec;
294 struct hda_pcm *info = spec->pcm_rec;
296 codec->num_pcms = 1;
297 codec->pcm_info = info;
299 info->name = "AD198x Analog";
300 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
301 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
303 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
304 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
305 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
307 if (spec->multiout.dig_out_nid) {
308 info++;
309 codec->num_pcms++;
310 info->name = "AD198x Digital";
311 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
313 if (spec->dig_in_nid) {
314 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
315 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
319 return 0;
322 static void ad198x_free(struct hda_codec *codec)
324 struct ad198x_spec *spec = codec->spec;
325 unsigned int i;
327 if (spec->kctl_alloc) {
328 for (i = 0; i < spec->num_kctl_used; i++)
329 kfree(spec->kctl_alloc[i].name);
330 kfree(spec->kctl_alloc);
332 kfree(codec->spec);
335 static struct hda_codec_ops ad198x_patch_ops = {
336 .build_controls = ad198x_build_controls,
337 .build_pcms = ad198x_build_pcms,
338 .init = ad198x_init,
339 .free = ad198x_free,
340 #ifdef CONFIG_SND_HDA_POWER_SAVE
341 .check_power_status = ad198x_check_power_status,
342 #endif
347 * EAPD control
348 * the private value = nid | (invert << 8)
350 #define ad198x_eapd_info snd_ctl_boolean_mono_info
352 static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
353 struct snd_ctl_elem_value *ucontrol)
355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356 struct ad198x_spec *spec = codec->spec;
357 int invert = (kcontrol->private_value >> 8) & 1;
358 if (invert)
359 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
360 else
361 ucontrol->value.integer.value[0] = spec->cur_eapd;
362 return 0;
365 static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_value *ucontrol)
368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369 struct ad198x_spec *spec = codec->spec;
370 int invert = (kcontrol->private_value >> 8) & 1;
371 hda_nid_t nid = kcontrol->private_value & 0xff;
372 unsigned int eapd;
373 eapd = ucontrol->value.integer.value[0];
374 if (invert)
375 eapd = !eapd;
376 if (eapd == spec->cur_eapd)
377 return 0;
378 spec->cur_eapd = eapd;
379 snd_hda_codec_write_cache(codec, nid,
380 0, AC_VERB_SET_EAPD_BTLENABLE,
381 eapd ? 0x02 : 0x00);
382 return 1;
385 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
386 struct snd_ctl_elem_info *uinfo);
387 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol);
389 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
390 struct snd_ctl_elem_value *ucontrol);
394 * AD1986A specific
397 #define AD1986A_SPDIF_OUT 0x02
398 #define AD1986A_FRONT_DAC 0x03
399 #define AD1986A_SURR_DAC 0x04
400 #define AD1986A_CLFE_DAC 0x05
401 #define AD1986A_ADC 0x06
403 static hda_nid_t ad1986a_dac_nids[3] = {
404 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
406 static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
407 static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
409 static struct hda_input_mux ad1986a_capture_source = {
410 .num_items = 7,
411 .items = {
412 { "Mic", 0x0 },
413 { "CD", 0x1 },
414 { "Aux", 0x3 },
415 { "Line", 0x4 },
416 { "Mix", 0x5 },
417 { "Mono", 0x6 },
418 { "Phone", 0x7 },
423 static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
424 .ops = &snd_hda_bind_vol,
425 .values = {
426 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
427 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
428 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
433 static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
434 .ops = &snd_hda_bind_sw,
435 .values = {
436 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
437 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
438 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
444 * mixers
446 static struct snd_kcontrol_new ad1986a_mixers[] = {
448 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
450 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
451 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
452 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
453 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
454 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
455 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
456 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
457 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
458 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
459 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
460 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
461 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
462 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
463 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
464 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
465 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
466 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
467 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
468 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
469 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
470 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
471 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
472 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
473 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
474 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
475 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
476 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
479 .name = "Capture Source",
480 .info = ad198x_mux_enum_info,
481 .get = ad198x_mux_enum_get,
482 .put = ad198x_mux_enum_put,
484 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
485 { } /* end */
488 /* additional mixers for 3stack mode */
489 static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
492 .name = "Channel Mode",
493 .info = ad198x_ch_mode_info,
494 .get = ad198x_ch_mode_get,
495 .put = ad198x_ch_mode_put,
497 { } /* end */
500 /* laptop model - 2ch only */
501 static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
503 /* master controls both pins 0x1a and 0x1b */
504 static struct hda_bind_ctls ad1986a_laptop_master_vol = {
505 .ops = &snd_hda_bind_vol,
506 .values = {
507 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
508 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
513 static struct hda_bind_ctls ad1986a_laptop_master_sw = {
514 .ops = &snd_hda_bind_sw,
515 .values = {
516 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
517 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
522 static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
523 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
524 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
525 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
526 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
527 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
528 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
529 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
533 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
534 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
535 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
536 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
537 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
538 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
539 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
540 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
541 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
543 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
544 .name = "Capture Source",
545 .info = ad198x_mux_enum_info,
546 .get = ad198x_mux_enum_get,
547 .put = ad198x_mux_enum_put,
549 { } /* end */
552 /* laptop-eapd model - 2ch only */
554 static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
555 .num_items = 3,
556 .items = {
557 { "Mic", 0x0 },
558 { "Internal Mic", 0x4 },
559 { "Mix", 0x5 },
563 static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
564 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
565 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
566 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
567 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
568 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
569 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
570 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
571 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
572 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
574 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
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,
583 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
584 .name = "External Amplifier",
585 .info = ad198x_eapd_info,
586 .get = ad198x_eapd_get,
587 .put = ad198x_eapd_put,
588 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
590 { } /* end */
593 /* laptop-automute - 2ch only */
595 static void ad1986a_update_hp(struct hda_codec *codec)
597 struct ad198x_spec *spec = codec->spec;
598 unsigned int mute;
600 if (spec->jack_present)
601 mute = HDA_AMP_MUTE; /* mute internal speaker */
602 else
603 /* unmute internal speaker if necessary */
604 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
605 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
606 HDA_AMP_MUTE, mute);
609 static void ad1986a_hp_automute(struct hda_codec *codec)
611 struct ad198x_spec *spec = codec->spec;
612 unsigned int present;
614 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
615 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
616 spec->jack_present = !(present & 0x80000000);
617 ad1986a_update_hp(codec);
620 #define AD1986A_HP_EVENT 0x37
622 static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
624 if ((res >> 26) != AD1986A_HP_EVENT)
625 return;
626 ad1986a_hp_automute(codec);
629 static int ad1986a_hp_init(struct hda_codec *codec)
631 ad198x_init(codec);
632 ad1986a_hp_automute(codec);
633 return 0;
636 /* bind hp and internal speaker mute (with plug check) */
637 static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol)
640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641 long *valp = ucontrol->value.integer.value;
642 int change;
644 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
645 HDA_AMP_MUTE,
646 valp[0] ? 0 : HDA_AMP_MUTE);
647 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
648 HDA_AMP_MUTE,
649 valp[1] ? 0 : HDA_AMP_MUTE);
650 if (change)
651 ad1986a_update_hp(codec);
652 return change;
655 static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
656 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
659 .name = "Master Playback Switch",
660 .info = snd_hda_mixer_amp_switch_info,
661 .get = snd_hda_mixer_amp_switch_get,
662 .put = ad1986a_hp_master_sw_put,
663 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
665 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
666 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
667 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
668 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
669 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
670 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
671 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
672 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
673 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
674 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
675 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Capture Source",
679 .info = ad198x_mux_enum_info,
680 .get = ad198x_mux_enum_get,
681 .put = ad198x_mux_enum_put,
684 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
685 .name = "External Amplifier",
686 .info = ad198x_eapd_info,
687 .get = ad198x_eapd_get,
688 .put = ad198x_eapd_put,
689 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
691 { } /* end */
695 * initialization verbs
697 static struct hda_verb ad1986a_init_verbs[] = {
698 /* Front, Surround, CLFE DAC; mute as default */
699 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
700 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
701 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
702 /* Downmix - off */
703 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
704 /* HP, Line-Out, Surround, CLFE selectors */
705 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
706 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
707 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
708 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
709 /* Mono selector */
710 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
711 /* Mic selector: Mic 1/2 pin */
712 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
713 /* Line-in selector: Line-in */
714 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
715 /* Mic 1/2 swap */
716 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
717 /* Record selector: mic */
718 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
719 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
720 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
721 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
722 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
723 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
724 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
725 /* PC beep */
726 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
727 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
728 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
729 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
730 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
731 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
732 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
733 /* HP Pin */
734 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
735 /* Front, Surround, CLFE Pins */
736 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
737 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
738 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
739 /* Mono Pin */
740 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
741 /* Mic Pin */
742 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
743 /* Line, Aux, CD, Beep-In Pin */
744 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
745 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
746 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
747 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
748 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
749 { } /* end */
752 static struct hda_verb ad1986a_ch2_init[] = {
753 /* Surround out -> Line In */
754 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
755 /* Line-in selectors */
756 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
757 /* CLFE -> Mic in */
758 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
759 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
760 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
761 { } /* end */
764 static struct hda_verb ad1986a_ch4_init[] = {
765 /* Surround out -> Surround */
766 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
767 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
768 /* CLFE -> Mic in */
769 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
770 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
771 { } /* end */
774 static struct hda_verb ad1986a_ch6_init[] = {
775 /* Surround out -> Surround out */
776 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
777 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
778 /* CLFE -> CLFE */
779 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
780 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
781 { } /* end */
784 static struct hda_channel_mode ad1986a_modes[3] = {
785 { 2, ad1986a_ch2_init },
786 { 4, ad1986a_ch4_init },
787 { 6, ad1986a_ch6_init },
790 /* eapd initialization */
791 static struct hda_verb ad1986a_eapd_init_verbs[] = {
792 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
796 /* Ultra initialization */
797 static struct hda_verb ad1986a_ultra_init[] = {
798 /* eapd initialization */
799 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
800 /* CLFE -> Mic in */
801 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
802 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
803 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
804 { } /* end */
807 /* pin sensing on HP jack */
808 static struct hda_verb ad1986a_hp_init_verbs[] = {
809 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
814 /* models */
815 enum {
816 AD1986A_6STACK,
817 AD1986A_3STACK,
818 AD1986A_LAPTOP,
819 AD1986A_LAPTOP_EAPD,
820 AD1986A_LAPTOP_AUTOMUTE,
821 AD1986A_ULTRA,
822 AD1986A_MODELS
825 static const char *ad1986a_models[AD1986A_MODELS] = {
826 [AD1986A_6STACK] = "6stack",
827 [AD1986A_3STACK] = "3stack",
828 [AD1986A_LAPTOP] = "laptop",
829 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
830 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
831 [AD1986A_ULTRA] = "ultra",
834 static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
835 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
836 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
837 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
838 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
839 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
840 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
841 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
842 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
843 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
844 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
845 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
846 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
847 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
848 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
849 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
850 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
851 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
852 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
853 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
854 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
855 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
856 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
857 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
858 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
859 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
860 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
864 #ifdef CONFIG_SND_HDA_POWER_SAVE
865 static struct hda_amp_list ad1986a_loopbacks[] = {
866 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
867 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
868 { 0x15, HDA_OUTPUT, 0 }, /* CD */
869 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
870 { 0x17, HDA_OUTPUT, 0 }, /* Line */
871 { } /* end */
873 #endif
875 static int patch_ad1986a(struct hda_codec *codec)
877 struct ad198x_spec *spec;
878 int board_config;
880 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
881 if (spec == NULL)
882 return -ENOMEM;
884 codec->spec = spec;
886 spec->multiout.max_channels = 6;
887 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
888 spec->multiout.dac_nids = ad1986a_dac_nids;
889 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
890 spec->num_adc_nids = 1;
891 spec->adc_nids = ad1986a_adc_nids;
892 spec->capsrc_nids = ad1986a_capsrc_nids;
893 spec->input_mux = &ad1986a_capture_source;
894 spec->num_mixers = 1;
895 spec->mixers[0] = ad1986a_mixers;
896 spec->num_init_verbs = 1;
897 spec->init_verbs[0] = ad1986a_init_verbs;
898 #ifdef CONFIG_SND_HDA_POWER_SAVE
899 spec->loopback.amplist = ad1986a_loopbacks;
900 #endif
902 codec->patch_ops = ad198x_patch_ops;
904 /* override some parameters */
905 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
906 ad1986a_models,
907 ad1986a_cfg_tbl);
908 switch (board_config) {
909 case AD1986A_3STACK:
910 spec->num_mixers = 2;
911 spec->mixers[1] = ad1986a_3st_mixers;
912 spec->num_init_verbs = 2;
913 spec->init_verbs[1] = ad1986a_ch2_init;
914 spec->channel_mode = ad1986a_modes;
915 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
916 spec->need_dac_fix = 1;
917 spec->multiout.max_channels = 2;
918 spec->multiout.num_dacs = 1;
919 break;
920 case AD1986A_LAPTOP:
921 spec->mixers[0] = ad1986a_laptop_mixers;
922 spec->multiout.max_channels = 2;
923 spec->multiout.num_dacs = 1;
924 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
925 break;
926 case AD1986A_LAPTOP_EAPD:
927 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
928 spec->num_init_verbs = 2;
929 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
930 spec->multiout.max_channels = 2;
931 spec->multiout.num_dacs = 1;
932 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
933 spec->multiout.dig_out_nid = 0;
934 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
935 break;
936 case AD1986A_LAPTOP_AUTOMUTE:
937 spec->mixers[0] = ad1986a_laptop_automute_mixers;
938 spec->num_init_verbs = 3;
939 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
940 spec->init_verbs[2] = ad1986a_hp_init_verbs;
941 spec->multiout.max_channels = 2;
942 spec->multiout.num_dacs = 1;
943 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
944 spec->multiout.dig_out_nid = 0;
945 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
946 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
947 codec->patch_ops.init = ad1986a_hp_init;
948 break;
949 case AD1986A_ULTRA:
950 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
951 spec->num_init_verbs = 2;
952 spec->init_verbs[1] = ad1986a_ultra_init;
953 spec->multiout.max_channels = 2;
954 spec->multiout.num_dacs = 1;
955 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
956 spec->multiout.dig_out_nid = 0;
957 break;
960 return 0;
964 * AD1983 specific
967 #define AD1983_SPDIF_OUT 0x02
968 #define AD1983_DAC 0x03
969 #define AD1983_ADC 0x04
971 static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
972 static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
973 static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
975 static struct hda_input_mux ad1983_capture_source = {
976 .num_items = 4,
977 .items = {
978 { "Mic", 0x0 },
979 { "Line", 0x1 },
980 { "Mix", 0x2 },
981 { "Mix Mono", 0x3 },
986 * SPDIF playback route
988 static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
990 static char *texts[] = { "PCM", "ADC" };
992 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
993 uinfo->count = 1;
994 uinfo->value.enumerated.items = 2;
995 if (uinfo->value.enumerated.item > 1)
996 uinfo->value.enumerated.item = 1;
997 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
998 return 0;
1001 static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1003 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1004 struct ad198x_spec *spec = codec->spec;
1006 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1007 return 0;
1010 static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1012 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1013 struct ad198x_spec *spec = codec->spec;
1015 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1016 spec->spdif_route = ucontrol->value.enumerated.item[0];
1017 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1018 AC_VERB_SET_CONNECT_SEL,
1019 spec->spdif_route);
1020 return 1;
1022 return 0;
1025 static struct snd_kcontrol_new ad1983_mixers[] = {
1026 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1027 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1028 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1029 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1030 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1031 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1032 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1033 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1034 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1035 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1036 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1037 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1038 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1039 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1041 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1042 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1044 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1045 .name = "Capture Source",
1046 .info = ad198x_mux_enum_info,
1047 .get = ad198x_mux_enum_get,
1048 .put = ad198x_mux_enum_put,
1051 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1052 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1053 .info = ad1983_spdif_route_info,
1054 .get = ad1983_spdif_route_get,
1055 .put = ad1983_spdif_route_put,
1057 { } /* end */
1060 static struct hda_verb ad1983_init_verbs[] = {
1061 /* Front, HP, Mono; mute as default */
1062 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1063 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1064 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1065 /* Beep, PCM, Mic, Line-In: mute */
1066 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1067 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1068 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1069 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1070 /* Front, HP selectors; from Mix */
1071 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1072 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1073 /* Mono selector; from Mix */
1074 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1075 /* Mic selector; Mic */
1076 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1077 /* Line-in selector: Line-in */
1078 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1079 /* Mic boost: 0dB */
1080 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1081 /* Record selector: mic */
1082 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1083 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1084 /* SPDIF route: PCM */
1085 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1086 /* Front Pin */
1087 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1088 /* HP Pin */
1089 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1090 /* Mono Pin */
1091 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1092 /* Mic Pin */
1093 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1094 /* Line Pin */
1095 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1096 { } /* end */
1099 #ifdef CONFIG_SND_HDA_POWER_SAVE
1100 static struct hda_amp_list ad1983_loopbacks[] = {
1101 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1102 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1103 { } /* end */
1105 #endif
1107 static int patch_ad1983(struct hda_codec *codec)
1109 struct ad198x_spec *spec;
1111 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1112 if (spec == NULL)
1113 return -ENOMEM;
1115 codec->spec = spec;
1117 spec->multiout.max_channels = 2;
1118 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1119 spec->multiout.dac_nids = ad1983_dac_nids;
1120 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
1121 spec->num_adc_nids = 1;
1122 spec->adc_nids = ad1983_adc_nids;
1123 spec->capsrc_nids = ad1983_capsrc_nids;
1124 spec->input_mux = &ad1983_capture_source;
1125 spec->num_mixers = 1;
1126 spec->mixers[0] = ad1983_mixers;
1127 spec->num_init_verbs = 1;
1128 spec->init_verbs[0] = ad1983_init_verbs;
1129 spec->spdif_route = 0;
1130 #ifdef CONFIG_SND_HDA_POWER_SAVE
1131 spec->loopback.amplist = ad1983_loopbacks;
1132 #endif
1134 codec->patch_ops = ad198x_patch_ops;
1136 return 0;
1141 * AD1981 HD specific
1144 #define AD1981_SPDIF_OUT 0x02
1145 #define AD1981_DAC 0x03
1146 #define AD1981_ADC 0x04
1148 static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
1149 static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
1150 static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
1152 /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1153 static struct hda_input_mux ad1981_capture_source = {
1154 .num_items = 7,
1155 .items = {
1156 { "Front Mic", 0x0 },
1157 { "Line", 0x1 },
1158 { "Mix", 0x2 },
1159 { "Mix Mono", 0x3 },
1160 { "CD", 0x4 },
1161 { "Mic", 0x6 },
1162 { "Aux", 0x7 },
1166 static struct snd_kcontrol_new ad1981_mixers[] = {
1167 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1168 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1169 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1170 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1171 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1172 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1173 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1174 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1175 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1176 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1177 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1178 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1179 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1180 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1181 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1182 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1183 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1184 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1185 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1186 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1187 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1188 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1189 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1190 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1192 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1193 .name = "Capture Source",
1194 .info = ad198x_mux_enum_info,
1195 .get = ad198x_mux_enum_get,
1196 .put = ad198x_mux_enum_put,
1198 /* identical with AD1983 */
1200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1201 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1202 .info = ad1983_spdif_route_info,
1203 .get = ad1983_spdif_route_get,
1204 .put = ad1983_spdif_route_put,
1206 { } /* end */
1209 static struct hda_verb ad1981_init_verbs[] = {
1210 /* Front, HP, Mono; mute as default */
1211 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1212 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1213 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1214 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1215 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1216 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1217 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1218 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1219 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1220 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1221 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1222 /* Front, HP selectors; from Mix */
1223 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1224 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1225 /* Mono selector; from Mix */
1226 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1227 /* Mic Mixer; select Front Mic */
1228 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1229 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1230 /* Mic boost: 0dB */
1231 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1232 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1233 /* Record selector: Front mic */
1234 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1235 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1236 /* SPDIF route: PCM */
1237 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1238 /* Front Pin */
1239 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1240 /* HP Pin */
1241 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1242 /* Mono Pin */
1243 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1244 /* Front & Rear Mic Pins */
1245 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1246 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1247 /* Line Pin */
1248 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1249 /* Digital Beep */
1250 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1251 /* Line-Out as Input: disabled */
1252 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1253 { } /* end */
1256 #ifdef CONFIG_SND_HDA_POWER_SAVE
1257 static struct hda_amp_list ad1981_loopbacks[] = {
1258 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1259 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1260 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1261 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1262 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1263 { } /* end */
1265 #endif
1268 * Patch for HP nx6320
1270 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
1271 * speaker output enabled _and_ mute-LED off.
1274 #define AD1981_HP_EVENT 0x37
1275 #define AD1981_MIC_EVENT 0x38
1277 static struct hda_verb ad1981_hp_init_verbs[] = {
1278 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1279 /* pin sensing on HP and Mic jacks */
1280 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1281 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1285 /* turn on/off EAPD (+ mute HP) as a master switch */
1286 static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1287 struct snd_ctl_elem_value *ucontrol)
1289 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1290 struct ad198x_spec *spec = codec->spec;
1292 if (! ad198x_eapd_put(kcontrol, ucontrol))
1293 return 0;
1295 /* toggle HP mute appropriately */
1296 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1297 HDA_AMP_MUTE,
1298 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
1299 return 1;
1302 /* bind volumes of both NID 0x05 and 0x06 */
1303 static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1304 .ops = &snd_hda_bind_vol,
1305 .values = {
1306 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1307 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1312 /* mute internal speaker if HP is plugged */
1313 static void ad1981_hp_automute(struct hda_codec *codec)
1315 unsigned int present;
1317 present = snd_hda_codec_read(codec, 0x06, 0,
1318 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1319 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1320 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
1323 /* toggle input of built-in and mic jack appropriately */
1324 static void ad1981_hp_automic(struct hda_codec *codec)
1326 static struct hda_verb mic_jack_on[] = {
1327 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1328 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1331 static struct hda_verb mic_jack_off[] = {
1332 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1333 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1336 unsigned int present;
1338 present = snd_hda_codec_read(codec, 0x08, 0,
1339 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1340 if (present)
1341 snd_hda_sequence_write(codec, mic_jack_on);
1342 else
1343 snd_hda_sequence_write(codec, mic_jack_off);
1346 /* unsolicited event for HP jack sensing */
1347 static void ad1981_hp_unsol_event(struct hda_codec *codec,
1348 unsigned int res)
1350 res >>= 26;
1351 switch (res) {
1352 case AD1981_HP_EVENT:
1353 ad1981_hp_automute(codec);
1354 break;
1355 case AD1981_MIC_EVENT:
1356 ad1981_hp_automic(codec);
1357 break;
1361 static struct hda_input_mux ad1981_hp_capture_source = {
1362 .num_items = 3,
1363 .items = {
1364 { "Mic", 0x0 },
1365 { "Docking-Station", 0x1 },
1366 { "Mix", 0x2 },
1370 static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1371 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
1373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1374 .name = "Master Playback Switch",
1375 .info = ad198x_eapd_info,
1376 .get = ad198x_eapd_get,
1377 .put = ad1981_hp_master_sw_put,
1378 .private_value = 0x05,
1380 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1381 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1382 #if 0
1383 /* FIXME: analog mic/line loopback doesn't work with my tests...
1384 * (although recording is OK)
1386 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1387 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1388 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1389 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1390 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1391 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1392 /* FIXME: does this laptop have analog CD connection? */
1393 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1394 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1395 #endif
1396 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1397 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1398 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1399 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1401 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1402 .name = "Capture Source",
1403 .info = ad198x_mux_enum_info,
1404 .get = ad198x_mux_enum_get,
1405 .put = ad198x_mux_enum_put,
1407 { } /* end */
1410 /* initialize jack-sensing, too */
1411 static int ad1981_hp_init(struct hda_codec *codec)
1413 ad198x_init(codec);
1414 ad1981_hp_automute(codec);
1415 ad1981_hp_automic(codec);
1416 return 0;
1419 /* configuration for Toshiba Laptops */
1420 static struct hda_verb ad1981_toshiba_init_verbs[] = {
1421 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1422 /* pin sensing on HP and Mic jacks */
1423 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1424 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1428 static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1429 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1430 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1434 /* configuration for Lenovo Thinkpad T60 */
1435 static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1436 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1437 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1438 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1439 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1440 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1441 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1442 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1443 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1444 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1445 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1446 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1448 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1449 .name = "Capture Source",
1450 .info = ad198x_mux_enum_info,
1451 .get = ad198x_mux_enum_get,
1452 .put = ad198x_mux_enum_put,
1454 /* identical with AD1983 */
1456 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1457 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1458 .info = ad1983_spdif_route_info,
1459 .get = ad1983_spdif_route_get,
1460 .put = ad1983_spdif_route_put,
1462 { } /* end */
1465 static struct hda_input_mux ad1981_thinkpad_capture_source = {
1466 .num_items = 3,
1467 .items = {
1468 { "Mic", 0x0 },
1469 { "Mix", 0x2 },
1470 { "CD", 0x4 },
1474 /* models */
1475 enum {
1476 AD1981_BASIC,
1477 AD1981_HP,
1478 AD1981_THINKPAD,
1479 AD1981_TOSHIBA,
1480 AD1981_MODELS
1483 static const char *ad1981_models[AD1981_MODELS] = {
1484 [AD1981_HP] = "hp",
1485 [AD1981_THINKPAD] = "thinkpad",
1486 [AD1981_BASIC] = "basic",
1487 [AD1981_TOSHIBA] = "toshiba"
1490 static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1491 /* All HP models */
1492 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1493 /* HP nx6320 (reversed SSID, H/W bug) */
1494 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1495 /* Lenovo Thinkpad T60/X60/Z6xx */
1496 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1497 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1498 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1502 static int patch_ad1981(struct hda_codec *codec)
1504 struct ad198x_spec *spec;
1505 int board_config;
1507 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1508 if (spec == NULL)
1509 return -ENOMEM;
1511 codec->spec = spec;
1513 spec->multiout.max_channels = 2;
1514 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1515 spec->multiout.dac_nids = ad1981_dac_nids;
1516 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
1517 spec->num_adc_nids = 1;
1518 spec->adc_nids = ad1981_adc_nids;
1519 spec->capsrc_nids = ad1981_capsrc_nids;
1520 spec->input_mux = &ad1981_capture_source;
1521 spec->num_mixers = 1;
1522 spec->mixers[0] = ad1981_mixers;
1523 spec->num_init_verbs = 1;
1524 spec->init_verbs[0] = ad1981_init_verbs;
1525 spec->spdif_route = 0;
1526 #ifdef CONFIG_SND_HDA_POWER_SAVE
1527 spec->loopback.amplist = ad1981_loopbacks;
1528 #endif
1530 codec->patch_ops = ad198x_patch_ops;
1532 /* override some parameters */
1533 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1534 ad1981_models,
1535 ad1981_cfg_tbl);
1536 switch (board_config) {
1537 case AD1981_HP:
1538 spec->mixers[0] = ad1981_hp_mixers;
1539 spec->num_init_verbs = 2;
1540 spec->init_verbs[1] = ad1981_hp_init_verbs;
1541 spec->multiout.dig_out_nid = 0;
1542 spec->input_mux = &ad1981_hp_capture_source;
1544 codec->patch_ops.init = ad1981_hp_init;
1545 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1546 break;
1547 case AD1981_THINKPAD:
1548 spec->mixers[0] = ad1981_thinkpad_mixers;
1549 spec->input_mux = &ad1981_thinkpad_capture_source;
1550 break;
1551 case AD1981_TOSHIBA:
1552 spec->mixers[0] = ad1981_hp_mixers;
1553 spec->mixers[1] = ad1981_toshiba_mixers;
1554 spec->num_init_verbs = 2;
1555 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1556 spec->multiout.dig_out_nid = 0;
1557 spec->input_mux = &ad1981_hp_capture_source;
1558 codec->patch_ops.init = ad1981_hp_init;
1559 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1560 break;
1562 return 0;
1567 * AD1988
1569 * Output pins and routes
1571 * Pin Mix Sel DAC (*)
1572 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1573 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1574 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1575 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1576 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1577 * port-F 0x16 (mute) <- 0x2a <- 06
1578 * port-G 0x24 (mute) <- 0x27 <- 05
1579 * port-H 0x25 (mute) <- 0x28 <- 0a
1580 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1582 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1583 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
1585 * Input pins and routes
1587 * pin boost mix input # / adc input #
1588 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1589 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1590 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1591 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1592 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1593 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1594 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1595 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1598 * DAC assignment
1599 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
1600 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
1602 * Inputs of Analog Mix (0x20)
1603 * 0:Port-B (front mic)
1604 * 1:Port-C/G/H (line-in)
1605 * 2:Port-A
1606 * 3:Port-D (line-in/2)
1607 * 4:Port-E/G/H (mic-in)
1608 * 5:Port-F (mic2-in)
1609 * 6:CD
1610 * 7:Beep
1612 * ADC selection
1613 * 0:Port-A
1614 * 1:Port-B (front mic-in)
1615 * 2:Port-C (line-in)
1616 * 3:Port-F (mic2-in)
1617 * 4:Port-E (mic-in)
1618 * 5:CD
1619 * 6:Port-G
1620 * 7:Port-H
1621 * 8:Port-D (line-in/2)
1622 * 9:Mix
1624 * Proposed pin assignments by the datasheet
1626 * 6-stack
1627 * Port-A front headphone
1628 * B front mic-in
1629 * C rear line-in
1630 * D rear front-out
1631 * E rear mic-in
1632 * F rear surround
1633 * G rear CLFE
1634 * H rear side
1636 * 3-stack
1637 * Port-A front headphone
1638 * B front mic
1639 * C rear line-in/surround
1640 * D rear front-out
1641 * E rear mic-in/CLFE
1643 * laptop
1644 * Port-A headphone
1645 * B mic-in
1646 * C docking station
1647 * D internal speaker (with EAPD)
1648 * E/F quad mic array
1652 /* models */
1653 enum {
1654 AD1988_6STACK,
1655 AD1988_6STACK_DIG,
1656 AD1988_3STACK,
1657 AD1988_3STACK_DIG,
1658 AD1988_LAPTOP,
1659 AD1988_LAPTOP_DIG,
1660 AD1988_AUTO,
1661 AD1988_MODEL_LAST,
1664 /* reivision id to check workarounds */
1665 #define AD1988A_REV2 0x100200
1667 #define is_rev2(codec) \
1668 ((codec)->vendor_id == 0x11d41988 && \
1669 (codec)->revision_id == AD1988A_REV2)
1672 * mixers
1675 static hda_nid_t ad1988_6stack_dac_nids[4] = {
1676 0x04, 0x06, 0x05, 0x0a
1679 static hda_nid_t ad1988_3stack_dac_nids[3] = {
1680 0x04, 0x05, 0x0a
1683 /* for AD1988A revision-2, DAC2-4 are swapped */
1684 static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1685 0x04, 0x05, 0x0a, 0x06
1688 static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
1689 0x04, 0x0a, 0x06
1692 static hda_nid_t ad1988_adc_nids[3] = {
1693 0x08, 0x09, 0x0f
1696 static hda_nid_t ad1988_capsrc_nids[3] = {
1697 0x0c, 0x0d, 0x0e
1700 #define AD1988_SPDIF_OUT 0x02
1701 #define AD1988_SPDIF_IN 0x07
1703 static struct hda_input_mux ad1988_6stack_capture_source = {
1704 .num_items = 5,
1705 .items = {
1706 { "Front Mic", 0x0 },
1707 { "Line", 0x1 },
1708 { "Mic", 0x4 },
1709 { "CD", 0x5 },
1710 { "Mix", 0x9 },
1714 static struct hda_input_mux ad1988_laptop_capture_source = {
1715 .num_items = 3,
1716 .items = {
1717 { "Mic/Line", 0x0 },
1718 { "CD", 0x5 },
1719 { "Mix", 0x9 },
1725 static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1726 struct snd_ctl_elem_info *uinfo)
1728 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1729 struct ad198x_spec *spec = codec->spec;
1730 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1731 spec->num_channel_mode);
1734 static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_value *ucontrol)
1737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1738 struct ad198x_spec *spec = codec->spec;
1739 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1740 spec->num_channel_mode, spec->multiout.max_channels);
1743 static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1744 struct snd_ctl_elem_value *ucontrol)
1746 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1747 struct ad198x_spec *spec = codec->spec;
1748 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1749 spec->num_channel_mode,
1750 &spec->multiout.max_channels);
1751 if (err >= 0 && spec->need_dac_fix)
1752 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
1753 return err;
1756 /* 6-stack mode */
1757 static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
1758 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1759 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1760 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1761 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1762 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1763 { } /* end */
1766 static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1767 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1768 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1769 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1770 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1771 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1772 { } /* end */
1775 static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1776 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1777 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1778 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1779 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1780 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1781 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1782 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1784 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1785 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1786 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1787 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1788 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1789 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1790 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1791 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1793 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1794 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1796 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1797 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1799 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1800 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1802 { } /* end */
1805 /* 3-stack mode */
1806 static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
1807 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1808 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1809 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1810 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1811 { } /* end */
1814 static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1815 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1816 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1817 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1818 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
1819 { } /* end */
1822 static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
1823 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1824 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1825 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1826 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
1827 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1828 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1830 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1831 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1832 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1833 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1834 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1835 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1836 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1837 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1839 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1840 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1842 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1843 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1845 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1846 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1849 .name = "Channel Mode",
1850 .info = ad198x_ch_mode_info,
1851 .get = ad198x_ch_mode_get,
1852 .put = ad198x_ch_mode_put,
1855 { } /* end */
1858 /* laptop mode */
1859 static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1860 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1861 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1862 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1864 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1865 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1866 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1867 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1868 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1869 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1871 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1872 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1874 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1875 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1877 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1881 .name = "External Amplifier",
1882 .info = ad198x_eapd_info,
1883 .get = ad198x_eapd_get,
1884 .put = ad198x_eapd_put,
1885 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
1888 { } /* end */
1891 /* capture */
1892 static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1893 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1894 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1895 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1896 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1897 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1898 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1900 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1901 /* The multiple "Capture Source" controls confuse alsamixer
1902 * So call somewhat different..
1903 * FIXME: the controls appear in the "playback" view!
1905 /* .name = "Capture Source", */
1906 .name = "Input Source",
1907 .count = 3,
1908 .info = ad198x_mux_enum_info,
1909 .get = ad198x_mux_enum_get,
1910 .put = ad198x_mux_enum_put,
1912 { } /* end */
1915 static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1916 struct snd_ctl_elem_info *uinfo)
1918 static char *texts[] = {
1919 "PCM", "ADC1", "ADC2", "ADC3"
1921 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1922 uinfo->count = 1;
1923 uinfo->value.enumerated.items = 4;
1924 if (uinfo->value.enumerated.item >= 4)
1925 uinfo->value.enumerated.item = 3;
1926 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1927 return 0;
1930 static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1931 struct snd_ctl_elem_value *ucontrol)
1933 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1934 unsigned int sel;
1936 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
1937 AC_AMP_GET_INPUT);
1938 if (!(sel & 0x80))
1939 ucontrol->value.enumerated.item[0] = 0;
1940 else {
1941 sel = snd_hda_codec_read(codec, 0x0b, 0,
1942 AC_VERB_GET_CONNECT_SEL, 0);
1943 if (sel < 3)
1944 sel++;
1945 else
1946 sel = 0;
1947 ucontrol->value.enumerated.item[0] = sel;
1949 return 0;
1952 static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1953 struct snd_ctl_elem_value *ucontrol)
1955 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1956 unsigned int val, sel;
1957 int change;
1959 val = ucontrol->value.enumerated.item[0];
1960 if (!val) {
1961 sel = snd_hda_codec_read(codec, 0x1d, 0,
1962 AC_VERB_GET_AMP_GAIN_MUTE,
1963 AC_AMP_GET_INPUT);
1964 change = sel & 0x80;
1965 if (change) {
1966 snd_hda_codec_write_cache(codec, 0x1d, 0,
1967 AC_VERB_SET_AMP_GAIN_MUTE,
1968 AMP_IN_UNMUTE(0));
1969 snd_hda_codec_write_cache(codec, 0x1d, 0,
1970 AC_VERB_SET_AMP_GAIN_MUTE,
1971 AMP_IN_MUTE(1));
1973 } else {
1974 sel = snd_hda_codec_read(codec, 0x1d, 0,
1975 AC_VERB_GET_AMP_GAIN_MUTE,
1976 AC_AMP_GET_INPUT | 0x01);
1977 change = sel & 0x80;
1978 if (change) {
1979 snd_hda_codec_write_cache(codec, 0x1d, 0,
1980 AC_VERB_SET_AMP_GAIN_MUTE,
1981 AMP_IN_MUTE(0));
1982 snd_hda_codec_write_cache(codec, 0x1d, 0,
1983 AC_VERB_SET_AMP_GAIN_MUTE,
1984 AMP_IN_UNMUTE(1));
1986 sel = snd_hda_codec_read(codec, 0x0b, 0,
1987 AC_VERB_GET_CONNECT_SEL, 0) + 1;
1988 change |= sel != val;
1989 if (change)
1990 snd_hda_codec_write_cache(codec, 0x0b, 0,
1991 AC_VERB_SET_CONNECT_SEL,
1992 val - 1);
1994 return change;
1997 static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1998 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2000 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2001 .name = "IEC958 Playback Source",
2002 .info = ad1988_spdif_playback_source_info,
2003 .get = ad1988_spdif_playback_source_get,
2004 .put = ad1988_spdif_playback_source_put,
2006 { } /* end */
2009 static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2010 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2011 { } /* end */
2016 * initialization verbs
2020 * for 6-stack (+dig)
2022 static struct hda_verb ad1988_6stack_init_verbs[] = {
2023 /* Front, Surround, CLFE, side DAC; unmute as default */
2024 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2025 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2026 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2027 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2028 /* Port-A front headphon path */
2029 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2030 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2031 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2032 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2033 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2034 /* Port-D line-out path */
2035 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2036 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2037 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2038 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2039 /* Port-F surround path */
2040 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2041 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2042 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2043 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2044 /* Port-G CLFE path */
2045 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2046 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2047 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2048 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2049 /* Port-H side path */
2050 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2051 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2052 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2053 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2054 /* Mono out path */
2055 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2056 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2057 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2058 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2059 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2060 /* Port-B front mic-in path */
2061 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2062 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2063 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2064 /* Port-C line-in path */
2065 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2066 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2067 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2068 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2069 /* Port-E mic-in path */
2070 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2071 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2072 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2073 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2078 static struct hda_verb ad1988_capture_init_verbs[] = {
2079 /* mute analog mix */
2080 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2081 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2082 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2083 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2084 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2085 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2086 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2087 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2088 /* select ADCs - front-mic */
2089 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2090 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2091 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2092 /* ADCs; muted */
2093 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2094 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2095 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2100 static struct hda_verb ad1988_spdif_init_verbs[] = {
2101 /* SPDIF out sel */
2102 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2103 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2104 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2105 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2106 /* SPDIF out pin */
2107 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2113 * verbs for 3stack (+dig)
2115 static struct hda_verb ad1988_3stack_ch2_init[] = {
2116 /* set port-C to line-in */
2117 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2118 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2119 /* set port-E to mic-in */
2120 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2121 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2122 { } /* end */
2125 static struct hda_verb ad1988_3stack_ch6_init[] = {
2126 /* set port-C to surround out */
2127 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2128 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2129 /* set port-E to CLFE out */
2130 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2131 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2132 { } /* end */
2135 static struct hda_channel_mode ad1988_3stack_modes[2] = {
2136 { 2, ad1988_3stack_ch2_init },
2137 { 6, ad1988_3stack_ch6_init },
2140 static struct hda_verb ad1988_3stack_init_verbs[] = {
2141 /* Front, Surround, CLFE, side DAC; unmute as default */
2142 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2143 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2144 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2145 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2146 /* Port-A front headphon path */
2147 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2148 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2149 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2150 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2151 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2152 /* Port-D line-out path */
2153 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2154 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2155 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2156 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2157 /* Mono out path */
2158 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2159 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2160 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2161 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2162 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2163 /* Port-B front mic-in path */
2164 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2165 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2166 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2167 /* Port-C line-in/surround path - 6ch mode as default */
2168 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2169 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2170 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2171 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
2172 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2173 /* Port-E mic-in/CLFE path - 6ch mode as default */
2174 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2176 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2177 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
2178 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2179 /* mute analog mix */
2180 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2181 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2182 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2183 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2184 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2185 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2186 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2187 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2188 /* select ADCs - front-mic */
2189 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2190 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2191 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2192 /* ADCs; muted */
2193 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2194 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2195 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2200 * verbs for laptop mode (+dig)
2202 static struct hda_verb ad1988_laptop_hp_on[] = {
2203 /* unmute port-A and mute port-D */
2204 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2205 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2206 { } /* end */
2208 static struct hda_verb ad1988_laptop_hp_off[] = {
2209 /* mute port-A and unmute port-D */
2210 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2211 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2212 { } /* end */
2215 #define AD1988_HP_EVENT 0x01
2217 static struct hda_verb ad1988_laptop_init_verbs[] = {
2218 /* Front, Surround, CLFE, side DAC; unmute as default */
2219 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2220 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2221 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2222 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2223 /* Port-A front headphon path */
2224 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2225 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2226 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2227 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2228 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2229 /* unsolicited event for pin-sense */
2230 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2231 /* Port-D line-out path + EAPD */
2232 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2233 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2234 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2235 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2236 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2237 /* Mono out path */
2238 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2239 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2240 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2241 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2242 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2243 /* Port-B mic-in path */
2244 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2245 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2246 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2247 /* Port-C docking station - try to output */
2248 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2249 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2250 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2251 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2252 /* mute analog mix */
2253 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2254 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2255 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2256 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2257 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2258 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2259 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2260 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2261 /* select ADCs - mic */
2262 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2263 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2264 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2265 /* ADCs; muted */
2266 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2267 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2268 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2272 static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2274 if ((res >> 26) != AD1988_HP_EVENT)
2275 return;
2276 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2277 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2278 else
2279 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2282 #ifdef CONFIG_SND_HDA_POWER_SAVE
2283 static struct hda_amp_list ad1988_loopbacks[] = {
2284 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2285 { 0x20, HDA_INPUT, 1 }, /* Line */
2286 { 0x20, HDA_INPUT, 4 }, /* Mic */
2287 { 0x20, HDA_INPUT, 6 }, /* CD */
2288 { } /* end */
2290 #endif
2293 * Automatic parse of I/O pins from the BIOS configuration
2296 #define NUM_CONTROL_ALLOC 32
2297 #define NUM_VERB_ALLOC 32
2299 enum {
2300 AD_CTL_WIDGET_VOL,
2301 AD_CTL_WIDGET_MUTE,
2302 AD_CTL_BIND_MUTE,
2304 static struct snd_kcontrol_new ad1988_control_templates[] = {
2305 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2306 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2307 HDA_BIND_MUTE(NULL, 0, 0, 0),
2310 /* add dynamic controls */
2311 static int add_control(struct ad198x_spec *spec, int type, const char *name,
2312 unsigned long val)
2314 struct snd_kcontrol_new *knew;
2316 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2317 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2319 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2320 if (! knew)
2321 return -ENOMEM;
2322 if (spec->kctl_alloc) {
2323 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2324 kfree(spec->kctl_alloc);
2326 spec->kctl_alloc = knew;
2327 spec->num_kctl_alloc = num;
2330 knew = &spec->kctl_alloc[spec->num_kctl_used];
2331 *knew = ad1988_control_templates[type];
2332 knew->name = kstrdup(name, GFP_KERNEL);
2333 if (! knew->name)
2334 return -ENOMEM;
2335 knew->private_value = val;
2336 spec->num_kctl_used++;
2337 return 0;
2340 #define AD1988_PIN_CD_NID 0x18
2341 #define AD1988_PIN_BEEP_NID 0x10
2343 static hda_nid_t ad1988_mixer_nids[8] = {
2344 /* A B C D E F G H */
2345 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2348 static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2350 static hda_nid_t idx_to_dac[8] = {
2351 /* A B C D E F G H */
2352 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2354 static hda_nid_t idx_to_dac_rev2[8] = {
2355 /* A B C D E F G H */
2356 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2358 if (is_rev2(codec))
2359 return idx_to_dac_rev2[idx];
2360 else
2361 return idx_to_dac[idx];
2364 static hda_nid_t ad1988_boost_nids[8] = {
2365 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2368 static int ad1988_pin_idx(hda_nid_t nid)
2370 static hda_nid_t ad1988_io_pins[8] = {
2371 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2373 int i;
2374 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2375 if (ad1988_io_pins[i] == nid)
2376 return i;
2377 return 0; /* should be -1 */
2380 static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2382 static int loopback_idx[8] = {
2383 2, 0, 1, 3, 4, 5, 1, 4
2385 switch (nid) {
2386 case AD1988_PIN_CD_NID:
2387 return 6;
2388 default:
2389 return loopback_idx[ad1988_pin_idx(nid)];
2393 static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2395 static int adc_idx[8] = {
2396 0, 1, 2, 8, 4, 3, 6, 7
2398 switch (nid) {
2399 case AD1988_PIN_CD_NID:
2400 return 5;
2401 default:
2402 return adc_idx[ad1988_pin_idx(nid)];
2406 /* fill in the dac_nids table from the parsed pin configuration */
2407 static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2408 const struct auto_pin_cfg *cfg)
2410 struct ad198x_spec *spec = codec->spec;
2411 int i, idx;
2413 spec->multiout.dac_nids = spec->private_dac_nids;
2415 /* check the pins hardwired to audio widget */
2416 for (i = 0; i < cfg->line_outs; i++) {
2417 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2418 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2420 spec->multiout.num_dacs = cfg->line_outs;
2421 return 0;
2424 /* add playback controls from the parsed DAC table */
2425 static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2426 const struct auto_pin_cfg *cfg)
2428 char name[32];
2429 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2430 hda_nid_t nid;
2431 int i, err;
2433 for (i = 0; i < cfg->line_outs; i++) {
2434 hda_nid_t dac = spec->multiout.dac_nids[i];
2435 if (! dac)
2436 continue;
2437 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2438 if (i == 2) {
2439 /* Center/LFE */
2440 err = add_control(spec, AD_CTL_WIDGET_VOL,
2441 "Center Playback Volume",
2442 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2443 if (err < 0)
2444 return err;
2445 err = add_control(spec, AD_CTL_WIDGET_VOL,
2446 "LFE Playback Volume",
2447 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2448 if (err < 0)
2449 return err;
2450 err = add_control(spec, AD_CTL_BIND_MUTE,
2451 "Center Playback Switch",
2452 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2453 if (err < 0)
2454 return err;
2455 err = add_control(spec, AD_CTL_BIND_MUTE,
2456 "LFE Playback Switch",
2457 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2458 if (err < 0)
2459 return err;
2460 } else {
2461 sprintf(name, "%s Playback Volume", chname[i]);
2462 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2463 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2464 if (err < 0)
2465 return err;
2466 sprintf(name, "%s Playback Switch", chname[i]);
2467 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2468 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2469 if (err < 0)
2470 return err;
2473 return 0;
2476 /* add playback controls for speaker and HP outputs */
2477 static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2478 const char *pfx)
2480 struct ad198x_spec *spec = codec->spec;
2481 hda_nid_t nid;
2482 int idx, err;
2483 char name[32];
2485 if (! pin)
2486 return 0;
2488 idx = ad1988_pin_idx(pin);
2489 nid = ad1988_idx_to_dac(codec, idx);
2490 /* specify the DAC as the extra output */
2491 if (! spec->multiout.hp_nid)
2492 spec->multiout.hp_nid = nid;
2493 else
2494 spec->multiout.extra_out_nid[0] = nid;
2495 /* control HP volume/switch on the output mixer amp */
2496 sprintf(name, "%s Playback Volume", pfx);
2497 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2498 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2499 return err;
2500 nid = ad1988_mixer_nids[idx];
2501 sprintf(name, "%s Playback Switch", pfx);
2502 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2503 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2504 return err;
2505 return 0;
2508 /* create input playback/capture controls for the given pin */
2509 static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2510 const char *ctlname, int boost)
2512 char name[32];
2513 int err, idx;
2515 sprintf(name, "%s Playback Volume", ctlname);
2516 idx = ad1988_pin_to_loopback_idx(pin);
2517 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2518 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2519 return err;
2520 sprintf(name, "%s Playback Switch", ctlname);
2521 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2522 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2523 return err;
2524 if (boost) {
2525 hda_nid_t bnid;
2526 idx = ad1988_pin_idx(pin);
2527 bnid = ad1988_boost_nids[idx];
2528 if (bnid) {
2529 sprintf(name, "%s Boost", ctlname);
2530 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2531 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2535 return 0;
2538 /* create playback/capture controls for input pins */
2539 static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2540 const struct auto_pin_cfg *cfg)
2542 struct hda_input_mux *imux = &spec->private_imux;
2543 int i, err;
2545 for (i = 0; i < AUTO_PIN_LAST; i++) {
2546 err = new_analog_input(spec, cfg->input_pins[i],
2547 auto_pin_cfg_labels[i],
2548 i <= AUTO_PIN_FRONT_MIC);
2549 if (err < 0)
2550 return err;
2551 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2552 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2553 imux->num_items++;
2555 imux->items[imux->num_items].label = "Mix";
2556 imux->items[imux->num_items].index = 9;
2557 imux->num_items++;
2559 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2560 "Analog Mix Playback Volume",
2561 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2562 return err;
2563 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2564 "Analog Mix Playback Switch",
2565 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2566 return err;
2568 return 0;
2571 static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2572 hda_nid_t nid, int pin_type,
2573 int dac_idx)
2575 /* set as output */
2576 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2577 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2578 switch (nid) {
2579 case 0x11: /* port-A - DAC 04 */
2580 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2581 break;
2582 case 0x14: /* port-B - DAC 06 */
2583 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2584 break;
2585 case 0x15: /* port-C - DAC 05 */
2586 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2587 break;
2588 case 0x17: /* port-E - DAC 0a */
2589 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2590 break;
2591 case 0x13: /* mono - DAC 04 */
2592 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2593 break;
2597 static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2599 struct ad198x_spec *spec = codec->spec;
2600 int i;
2602 for (i = 0; i < spec->autocfg.line_outs; i++) {
2603 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2604 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2608 static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2610 struct ad198x_spec *spec = codec->spec;
2611 hda_nid_t pin;
2613 pin = spec->autocfg.speaker_pins[0];
2614 if (pin) /* connect to front */
2615 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2616 pin = spec->autocfg.hp_pins[0];
2617 if (pin) /* connect to front */
2618 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2621 static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2623 struct ad198x_spec *spec = codec->spec;
2624 int i, idx;
2626 for (i = 0; i < AUTO_PIN_LAST; i++) {
2627 hda_nid_t nid = spec->autocfg.input_pins[i];
2628 if (! nid)
2629 continue;
2630 switch (nid) {
2631 case 0x15: /* port-C */
2632 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2633 break;
2634 case 0x17: /* port-E */
2635 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2636 break;
2638 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2639 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2640 if (nid != AD1988_PIN_CD_NID)
2641 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2642 AMP_OUT_MUTE);
2643 idx = ad1988_pin_idx(nid);
2644 if (ad1988_boost_nids[idx])
2645 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2646 AC_VERB_SET_AMP_GAIN_MUTE,
2647 AMP_OUT_ZERO);
2651 /* parse the BIOS configuration and set up the alc_spec */
2652 /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2653 static int ad1988_parse_auto_config(struct hda_codec *codec)
2655 struct ad198x_spec *spec = codec->spec;
2656 int err;
2658 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
2659 return err;
2660 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2661 return err;
2662 if (! spec->autocfg.line_outs)
2663 return 0; /* can't find valid BIOS pin config */
2664 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2665 (err = ad1988_auto_create_extra_out(codec,
2666 spec->autocfg.speaker_pins[0],
2667 "Speaker")) < 0 ||
2668 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
2669 "Headphone")) < 0 ||
2670 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2671 return err;
2673 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2675 if (spec->autocfg.dig_out_pin)
2676 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2677 if (spec->autocfg.dig_in_pin)
2678 spec->dig_in_nid = AD1988_SPDIF_IN;
2680 if (spec->kctl_alloc)
2681 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2683 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2685 spec->input_mux = &spec->private_imux;
2687 return 1;
2690 /* init callback for auto-configuration model -- overriding the default init */
2691 static int ad1988_auto_init(struct hda_codec *codec)
2693 ad198x_init(codec);
2694 ad1988_auto_init_multi_out(codec);
2695 ad1988_auto_init_extra_out(codec);
2696 ad1988_auto_init_analog_input(codec);
2697 return 0;
2704 static const char *ad1988_models[AD1988_MODEL_LAST] = {
2705 [AD1988_6STACK] = "6stack",
2706 [AD1988_6STACK_DIG] = "6stack-dig",
2707 [AD1988_3STACK] = "3stack",
2708 [AD1988_3STACK_DIG] = "3stack-dig",
2709 [AD1988_LAPTOP] = "laptop",
2710 [AD1988_LAPTOP_DIG] = "laptop-dig",
2711 [AD1988_AUTO] = "auto",
2714 static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2715 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
2716 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
2720 static int patch_ad1988(struct hda_codec *codec)
2722 struct ad198x_spec *spec;
2723 int board_config;
2725 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2726 if (spec == NULL)
2727 return -ENOMEM;
2729 codec->spec = spec;
2731 if (is_rev2(codec))
2732 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2734 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
2735 ad1988_models, ad1988_cfg_tbl);
2736 if (board_config < 0) {
2737 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2738 board_config = AD1988_AUTO;
2741 if (board_config == AD1988_AUTO) {
2742 /* automatic parse from the BIOS config */
2743 int err = ad1988_parse_auto_config(codec);
2744 if (err < 0) {
2745 ad198x_free(codec);
2746 return err;
2747 } else if (! err) {
2748 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2749 board_config = AD1988_6STACK;
2753 switch (board_config) {
2754 case AD1988_6STACK:
2755 case AD1988_6STACK_DIG:
2756 spec->multiout.max_channels = 8;
2757 spec->multiout.num_dacs = 4;
2758 if (is_rev2(codec))
2759 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2760 else
2761 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
2762 spec->input_mux = &ad1988_6stack_capture_source;
2763 spec->num_mixers = 2;
2764 if (is_rev2(codec))
2765 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2766 else
2767 spec->mixers[0] = ad1988_6stack_mixers1;
2768 spec->mixers[1] = ad1988_6stack_mixers2;
2769 spec->num_init_verbs = 1;
2770 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2771 if (board_config == AD1988_6STACK_DIG) {
2772 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2773 spec->dig_in_nid = AD1988_SPDIF_IN;
2775 break;
2776 case AD1988_3STACK:
2777 case AD1988_3STACK_DIG:
2778 spec->multiout.max_channels = 6;
2779 spec->multiout.num_dacs = 3;
2780 if (is_rev2(codec))
2781 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2782 else
2783 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2784 spec->input_mux = &ad1988_6stack_capture_source;
2785 spec->channel_mode = ad1988_3stack_modes;
2786 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
2787 spec->num_mixers = 2;
2788 if (is_rev2(codec))
2789 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2790 else
2791 spec->mixers[0] = ad1988_3stack_mixers1;
2792 spec->mixers[1] = ad1988_3stack_mixers2;
2793 spec->num_init_verbs = 1;
2794 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2795 if (board_config == AD1988_3STACK_DIG)
2796 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2797 break;
2798 case AD1988_LAPTOP:
2799 case AD1988_LAPTOP_DIG:
2800 spec->multiout.max_channels = 2;
2801 spec->multiout.num_dacs = 1;
2802 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
2803 spec->input_mux = &ad1988_laptop_capture_source;
2804 spec->num_mixers = 1;
2805 spec->mixers[0] = ad1988_laptop_mixers;
2806 spec->num_init_verbs = 1;
2807 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2808 if (board_config == AD1988_LAPTOP_DIG)
2809 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2810 break;
2813 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2814 spec->adc_nids = ad1988_adc_nids;
2815 spec->capsrc_nids = ad1988_capsrc_nids;
2816 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2817 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2818 if (spec->multiout.dig_out_nid) {
2819 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2820 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2822 if (spec->dig_in_nid)
2823 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2825 codec->patch_ops = ad198x_patch_ops;
2826 switch (board_config) {
2827 case AD1988_AUTO:
2828 codec->patch_ops.init = ad1988_auto_init;
2829 break;
2830 case AD1988_LAPTOP:
2831 case AD1988_LAPTOP_DIG:
2832 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2833 break;
2835 #ifdef CONFIG_SND_HDA_POWER_SAVE
2836 spec->loopback.amplist = ad1988_loopbacks;
2837 #endif
2839 return 0;
2844 * AD1884 / AD1984
2846 * port-B - front line/mic-in
2847 * port-E - aux in/out
2848 * port-F - aux in/out
2849 * port-C - rear line/mic-in
2850 * port-D - rear line/hp-out
2851 * port-A - front line/hp-out
2853 * AD1984 = AD1884 + two digital mic-ins
2855 * FIXME:
2856 * For simplicity, we share the single DAC for both HP and line-outs
2857 * right now. The inidividual playbacks could be easily implemented,
2858 * but no build-up framework is given, so far.
2861 static hda_nid_t ad1884_dac_nids[1] = {
2862 0x04,
2865 static hda_nid_t ad1884_adc_nids[2] = {
2866 0x08, 0x09,
2869 static hda_nid_t ad1884_capsrc_nids[2] = {
2870 0x0c, 0x0d,
2873 #define AD1884_SPDIF_OUT 0x02
2875 static struct hda_input_mux ad1884_capture_source = {
2876 .num_items = 4,
2877 .items = {
2878 { "Front Mic", 0x0 },
2879 { "Mic", 0x1 },
2880 { "CD", 0x2 },
2881 { "Mix", 0x3 },
2885 static struct snd_kcontrol_new ad1884_base_mixers[] = {
2886 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2887 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2888 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2889 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2890 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2891 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
2892 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2893 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2894 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2895 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2896 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
2897 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
2899 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
2900 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
2901 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2902 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2904 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
2905 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
2906 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2907 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2908 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2909 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2911 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2912 /* The multiple "Capture Source" controls confuse alsamixer
2913 * So call somewhat different..
2914 * FIXME: the controls appear in the "playback" view!
2916 /* .name = "Capture Source", */
2917 .name = "Input Source",
2918 .count = 2,
2919 .info = ad198x_mux_enum_info,
2920 .get = ad198x_mux_enum_get,
2921 .put = ad198x_mux_enum_put,
2923 /* SPDIF controls */
2924 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2926 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2927 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2928 /* identical with ad1983 */
2929 .info = ad1983_spdif_route_info,
2930 .get = ad1983_spdif_route_get,
2931 .put = ad1983_spdif_route_put,
2933 { } /* end */
2936 static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
2937 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
2938 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
2939 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
2940 HDA_INPUT),
2941 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
2942 HDA_INPUT),
2943 { } /* end */
2947 * initialization verbs
2949 static struct hda_verb ad1884_init_verbs[] = {
2950 /* DACs; mute as default */
2951 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2952 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2953 /* Port-A (HP) mixer */
2954 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2955 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2956 /* Port-A pin */
2957 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2958 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2959 /* HP selector - select DAC2 */
2960 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
2961 /* Port-D (Line-out) mixer */
2962 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2963 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2964 /* Port-D pin */
2965 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2966 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2967 /* Mono-out mixer */
2968 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2969 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2970 /* Mono-out pin */
2971 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2972 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2973 /* Mono selector */
2974 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2975 /* Port-B (front mic) pin */
2976 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2977 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2978 /* Port-C (rear mic) pin */
2979 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2980 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2981 /* Analog mixer; mute as default */
2982 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2983 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2984 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2985 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2986 /* Analog Mix output amp */
2987 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2988 /* SPDIF output selector */
2989 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2990 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2991 { } /* end */
2994 #ifdef CONFIG_SND_HDA_POWER_SAVE
2995 static struct hda_amp_list ad1884_loopbacks[] = {
2996 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2997 { 0x20, HDA_INPUT, 1 }, /* Mic */
2998 { 0x20, HDA_INPUT, 2 }, /* CD */
2999 { 0x20, HDA_INPUT, 4 }, /* Docking */
3000 { } /* end */
3002 #endif
3004 static int patch_ad1884(struct hda_codec *codec)
3006 struct ad198x_spec *spec;
3008 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3009 if (spec == NULL)
3010 return -ENOMEM;
3012 mutex_init(&spec->amp_mutex);
3013 codec->spec = spec;
3015 spec->multiout.max_channels = 2;
3016 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3017 spec->multiout.dac_nids = ad1884_dac_nids;
3018 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3019 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3020 spec->adc_nids = ad1884_adc_nids;
3021 spec->capsrc_nids = ad1884_capsrc_nids;
3022 spec->input_mux = &ad1884_capture_source;
3023 spec->num_mixers = 1;
3024 spec->mixers[0] = ad1884_base_mixers;
3025 spec->num_init_verbs = 1;
3026 spec->init_verbs[0] = ad1884_init_verbs;
3027 spec->spdif_route = 0;
3028 #ifdef CONFIG_SND_HDA_POWER_SAVE
3029 spec->loopback.amplist = ad1884_loopbacks;
3030 #endif
3032 codec->patch_ops = ad198x_patch_ops;
3034 return 0;
3038 * Lenovo Thinkpad T61/X61
3040 static struct hda_input_mux ad1984_thinkpad_capture_source = {
3041 .num_items = 3,
3042 .items = {
3043 { "Mic", 0x0 },
3044 { "Internal Mic", 0x1 },
3045 { "Mix", 0x3 },
3049 static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3050 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3051 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3052 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3053 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3054 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3055 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3056 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3057 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3058 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3059 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3060 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3061 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3062 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3063 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3064 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3065 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3066 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3067 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3068 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3070 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3071 /* The multiple "Capture Source" controls confuse alsamixer
3072 * So call somewhat different..
3073 * FIXME: the controls appear in the "playback" view!
3075 /* .name = "Capture Source", */
3076 .name = "Input Source",
3077 .count = 2,
3078 .info = ad198x_mux_enum_info,
3079 .get = ad198x_mux_enum_get,
3080 .put = ad198x_mux_enum_put,
3082 { } /* end */
3085 /* additional verbs */
3086 static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3087 /* Port-E (docking station mic) pin */
3088 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3089 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3090 /* docking mic boost */
3091 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3092 /* Analog mixer - docking mic; mute as default */
3093 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3094 /* enable EAPD bit */
3095 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3096 { } /* end */
3099 /* Digial MIC ADC NID 0x05 + 0x06 */
3100 static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3101 struct hda_codec *codec,
3102 unsigned int stream_tag,
3103 unsigned int format,
3104 struct snd_pcm_substream *substream)
3106 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3107 stream_tag, 0, format);
3108 return 0;
3111 static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3112 struct hda_codec *codec,
3113 struct snd_pcm_substream *substream)
3115 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3116 0, 0, 0);
3117 return 0;
3120 static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3121 .substreams = 2,
3122 .channels_min = 2,
3123 .channels_max = 2,
3124 .nid = 0x05,
3125 .ops = {
3126 .prepare = ad1984_pcm_dmic_prepare,
3127 .cleanup = ad1984_pcm_dmic_cleanup
3131 static int ad1984_build_pcms(struct hda_codec *codec)
3133 struct ad198x_spec *spec = codec->spec;
3134 struct hda_pcm *info;
3135 int err;
3137 err = ad198x_build_pcms(codec);
3138 if (err < 0)
3139 return err;
3141 info = spec->pcm_rec + codec->num_pcms;
3142 codec->num_pcms++;
3143 info->name = "AD1984 Digital Mic";
3144 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3145 return 0;
3148 /* models */
3149 enum {
3150 AD1984_BASIC,
3151 AD1984_THINKPAD,
3152 AD1984_MODELS
3155 static const char *ad1984_models[AD1984_MODELS] = {
3156 [AD1984_BASIC] = "basic",
3157 [AD1984_THINKPAD] = "thinkpad",
3160 static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3161 /* Lenovo Thinkpad T61/X61 */
3162 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
3166 static int patch_ad1984(struct hda_codec *codec)
3168 struct ad198x_spec *spec;
3169 int board_config, err;
3171 err = patch_ad1884(codec);
3172 if (err < 0)
3173 return err;
3174 spec = codec->spec;
3175 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3176 ad1984_models, ad1984_cfg_tbl);
3177 switch (board_config) {
3178 case AD1984_BASIC:
3179 /* additional digital mics */
3180 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3181 codec->patch_ops.build_pcms = ad1984_build_pcms;
3182 break;
3183 case AD1984_THINKPAD:
3184 spec->multiout.dig_out_nid = 0;
3185 spec->input_mux = &ad1984_thinkpad_capture_source;
3186 spec->mixers[0] = ad1984_thinkpad_mixers;
3187 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3188 break;
3190 return 0;
3195 * AD1882
3197 * port-A - front hp-out
3198 * port-B - front mic-in
3199 * port-C - rear line-in, shared surr-out (3stack)
3200 * port-D - rear line-out
3201 * port-E - rear mic-in, shared clfe-out (3stack)
3202 * port-F - rear surr-out (6stack)
3203 * port-G - rear clfe-out (6stack)
3206 static hda_nid_t ad1882_dac_nids[3] = {
3207 0x04, 0x03, 0x05
3210 static hda_nid_t ad1882_adc_nids[2] = {
3211 0x08, 0x09,
3214 static hda_nid_t ad1882_capsrc_nids[2] = {
3215 0x0c, 0x0d,
3218 #define AD1882_SPDIF_OUT 0x02
3220 /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3221 static struct hda_input_mux ad1882_capture_source = {
3222 .num_items = 5,
3223 .items = {
3224 { "Front Mic", 0x1 },
3225 { "Mic", 0x4 },
3226 { "Line", 0x2 },
3227 { "CD", 0x3 },
3228 { "Mix", 0x7 },
3232 static struct snd_kcontrol_new ad1882_base_mixers[] = {
3233 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3234 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3235 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3236 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3237 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3238 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3239 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3240 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3241 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3242 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3243 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3244 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3245 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3246 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3247 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3248 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3249 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3250 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3251 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3252 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3253 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3254 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3255 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3256 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3257 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3259 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3260 /* The multiple "Capture Source" controls confuse alsamixer
3261 * So call somewhat different..
3262 * FIXME: the controls appear in the "playback" view!
3264 /* .name = "Capture Source", */
3265 .name = "Input Source",
3266 .count = 2,
3267 .info = ad198x_mux_enum_info,
3268 .get = ad198x_mux_enum_get,
3269 .put = ad198x_mux_enum_put,
3271 /* SPDIF controls */
3272 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3274 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3275 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3276 /* identical with ad1983 */
3277 .info = ad1983_spdif_route_info,
3278 .get = ad1983_spdif_route_get,
3279 .put = ad1983_spdif_route_put,
3281 { } /* end */
3284 static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3285 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3286 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3287 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3289 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3290 .name = "Channel Mode",
3291 .info = ad198x_ch_mode_info,
3292 .get = ad198x_ch_mode_get,
3293 .put = ad198x_ch_mode_put,
3295 { } /* end */
3298 static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
3299 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
3300 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
3301 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
3302 { } /* end */
3305 static struct hda_verb ad1882_ch2_init[] = {
3306 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3307 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3308 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3309 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3310 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3311 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3312 { } /* end */
3315 static struct hda_verb ad1882_ch4_init[] = {
3316 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3317 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3318 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3319 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3320 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3321 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3322 { } /* end */
3325 static struct hda_verb ad1882_ch6_init[] = {
3326 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3327 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3328 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3329 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3330 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3331 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3332 { } /* end */
3335 static struct hda_channel_mode ad1882_modes[3] = {
3336 { 2, ad1882_ch2_init },
3337 { 4, ad1882_ch4_init },
3338 { 6, ad1882_ch6_init },
3342 * initialization verbs
3344 static struct hda_verb ad1882_init_verbs[] = {
3345 /* DACs; mute as default */
3346 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3347 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3348 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3349 /* Port-A (HP) mixer */
3350 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3351 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3352 /* Port-A pin */
3353 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3354 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3355 /* HP selector - select DAC2 */
3356 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
3357 /* Port-D (Line-out) mixer */
3358 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3359 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3360 /* Port-D pin */
3361 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3362 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3363 /* Mono-out mixer */
3364 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3365 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3366 /* Mono-out pin */
3367 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3368 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3369 /* Port-B (front mic) pin */
3370 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3371 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3372 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3373 /* Port-C (line-in) pin */
3374 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3375 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3376 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3377 /* Port-C mixer - mute as input */
3378 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3379 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3380 /* Port-E (mic-in) pin */
3381 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3382 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3383 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3384 /* Port-E mixer - mute as input */
3385 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3386 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3387 /* Port-F (surround) */
3388 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3389 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3390 /* Port-G (CLFE) */
3391 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3392 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3393 /* Analog mixer; mute as default */
3394 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
3395 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3396 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3397 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3398 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3399 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3400 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3401 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3402 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3403 /* Analog Mix output amp */
3404 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3405 /* SPDIF output selector */
3406 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3407 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3408 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3409 { } /* end */
3412 #ifdef CONFIG_SND_HDA_POWER_SAVE
3413 static struct hda_amp_list ad1882_loopbacks[] = {
3414 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3415 { 0x20, HDA_INPUT, 1 }, /* Mic */
3416 { 0x20, HDA_INPUT, 4 }, /* Line */
3417 { 0x20, HDA_INPUT, 6 }, /* CD */
3418 { } /* end */
3420 #endif
3422 /* models */
3423 enum {
3424 AD1882_3STACK,
3425 AD1882_6STACK,
3426 AD1882_MODELS
3429 static const char *ad1882_models[AD1986A_MODELS] = {
3430 [AD1882_3STACK] = "3stack",
3431 [AD1882_6STACK] = "6stack",
3435 static int patch_ad1882(struct hda_codec *codec)
3437 struct ad198x_spec *spec;
3438 int board_config;
3440 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3441 if (spec == NULL)
3442 return -ENOMEM;
3444 mutex_init(&spec->amp_mutex);
3445 codec->spec = spec;
3447 spec->multiout.max_channels = 6;
3448 spec->multiout.num_dacs = 3;
3449 spec->multiout.dac_nids = ad1882_dac_nids;
3450 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
3451 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
3452 spec->adc_nids = ad1882_adc_nids;
3453 spec->capsrc_nids = ad1882_capsrc_nids;
3454 spec->input_mux = &ad1882_capture_source;
3455 spec->num_mixers = 1;
3456 spec->mixers[0] = ad1882_base_mixers;
3457 spec->num_init_verbs = 1;
3458 spec->init_verbs[0] = ad1882_init_verbs;
3459 spec->spdif_route = 0;
3460 #ifdef CONFIG_SND_HDA_POWER_SAVE
3461 spec->loopback.amplist = ad1882_loopbacks;
3462 #endif
3464 codec->patch_ops = ad198x_patch_ops;
3466 /* override some parameters */
3467 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
3468 ad1882_models, NULL);
3469 switch (board_config) {
3470 default:
3471 case AD1882_3STACK:
3472 spec->num_mixers = 2;
3473 spec->mixers[1] = ad1882_3stack_mixers;
3474 spec->channel_mode = ad1882_modes;
3475 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
3476 spec->need_dac_fix = 1;
3477 spec->multiout.max_channels = 2;
3478 spec->multiout.num_dacs = 1;
3479 break;
3480 case AD1882_6STACK:
3481 spec->num_mixers = 2;
3482 spec->mixers[1] = ad1882_6stack_mixers;
3483 break;
3485 return 0;
3490 * patch entries
3492 struct hda_codec_preset snd_hda_preset_analog[] = {
3493 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
3494 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
3495 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3496 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
3497 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
3498 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
3499 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
3500 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
3501 {} /* terminator */