blob: febc2053f08e9e4ba7afc6d5a1de70a272c8b92c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02002 * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
3 * AD1986A, AD1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Takashi Iwai2bac6472007-05-18 18:21:41 +02005 * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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.
11 *
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.
16 *
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
20 */
21
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>
Ingo Molnar62932df2006-01-16 16:34:20 +010027#include <linux/mutex.h>
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <sound/core.h>
30#include "hda_codec.h"
31#include "hda_local.h"
32
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020033struct ad198x_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010034 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010035 int num_mixers;
36
Takashi Iwaid32410b12005-11-24 16:06:23 +010037 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010038 * don't forget NULL termination!
39 */
40 unsigned int num_init_verbs;
41
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
46 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010047 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020048 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010049
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 */
54
55 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020056 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010057 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010058 unsigned int cur_mux[3];
59
60 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010061 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010062 int num_channel_mode;
63
64 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020065 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010066
Ingo Molnar62932df2006-01-16 16:34:20 +010067 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020068 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010069
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[4];
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020078/*
79 * input MUX handling (common part)
80 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010081static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020082{
83 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
84 struct ad198x_spec *spec = codec->spec;
85
86 return snd_hda_input_mux_info(spec->input_mux, uinfo);
87}
88
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010089static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020090{
91 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
92 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +010093 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020094
Takashi Iwai985be542005-11-02 18:26:49 +010095 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020096 return 0;
97}
98
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010099static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200100{
101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
102 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100103 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200104
105 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100106 spec->capsrc_nids[adc_idx],
107 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200108}
109
110/*
111 * initialization (common callbacks)
112 */
113static int ad198x_init(struct hda_codec *codec)
114{
115 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100116 int i;
117
118 for (i = 0; i < spec->num_init_verbs; i++)
119 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200120 return 0;
121}
122
123static int ad198x_build_controls(struct hda_codec *codec)
124{
125 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100126 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200127 int err;
128
Takashi Iwai985be542005-11-02 18:26:49 +0100129 for (i = 0; i < spec->num_mixers; i++) {
130 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
131 if (err < 0)
132 return err;
133 }
134 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200135 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100136 if (err < 0)
137 return err;
138 }
139 if (spec->dig_in_nid) {
140 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
141 if (err < 0)
142 return err;
143 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200144 return 0;
145}
146
147/*
148 * Analog playback callbacks
149 */
150static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
151 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100152 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200153{
154 struct ad198x_spec *spec = codec->spec;
155 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
156}
157
158static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
159 struct hda_codec *codec,
160 unsigned int stream_tag,
161 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100162 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200163{
164 struct ad198x_spec *spec = codec->spec;
165 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
166 format, substream);
167}
168
169static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
170 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100171 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200172{
173 struct ad198x_spec *spec = codec->spec;
174 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
175}
176
177/*
178 * Digital out
179 */
180static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
181 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100182 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200183{
184 struct ad198x_spec *spec = codec->spec;
185 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
186}
187
188static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
189 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100190 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200191{
192 struct ad198x_spec *spec = codec->spec;
193 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
194}
195
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200196static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
197 struct hda_codec *codec,
198 unsigned int stream_tag,
199 unsigned int format,
200 struct snd_pcm_substream *substream)
201{
202 struct ad198x_spec *spec = codec->spec;
203 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
204 format, substream);
205}
206
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200207/*
208 * Analog capture
209 */
210static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
211 struct hda_codec *codec,
212 unsigned int stream_tag,
213 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100214 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200215{
216 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100217 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
218 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200219 return 0;
220}
221
222static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
223 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100224 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200225{
226 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100227 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
228 0, 0, 0);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200229 return 0;
230}
231
232
233/*
234 */
235static struct hda_pcm_stream ad198x_pcm_analog_playback = {
236 .substreams = 1,
237 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100238 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200239 .nid = 0, /* fill later */
240 .ops = {
241 .open = ad198x_playback_pcm_open,
242 .prepare = ad198x_playback_pcm_prepare,
243 .cleanup = ad198x_playback_pcm_cleanup
244 },
245};
246
247static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100248 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200249 .channels_min = 2,
250 .channels_max = 2,
251 .nid = 0, /* fill later */
252 .ops = {
253 .prepare = ad198x_capture_pcm_prepare,
254 .cleanup = ad198x_capture_pcm_cleanup
255 },
256};
257
258static struct hda_pcm_stream ad198x_pcm_digital_playback = {
259 .substreams = 1,
260 .channels_min = 2,
261 .channels_max = 2,
262 .nid = 0, /* fill later */
263 .ops = {
264 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200265 .close = ad198x_dig_playback_pcm_close,
266 .prepare = ad198x_dig_playback_pcm_prepare
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200267 },
268};
269
Takashi Iwai985be542005-11-02 18:26:49 +0100270static struct hda_pcm_stream ad198x_pcm_digital_capture = {
271 .substreams = 1,
272 .channels_min = 2,
273 .channels_max = 2,
274 /* NID is set in alc_build_pcms */
275};
276
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200277static int ad198x_build_pcms(struct hda_codec *codec)
278{
279 struct ad198x_spec *spec = codec->spec;
280 struct hda_pcm *info = spec->pcm_rec;
281
282 codec->num_pcms = 1;
283 codec->pcm_info = info;
284
285 info->name = "AD198x Analog";
286 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
289 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100290 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
291 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200292
293 if (spec->multiout.dig_out_nid) {
294 info++;
295 codec->num_pcms++;
296 info->name = "AD198x Digital";
297 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
298 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100299 if (spec->dig_in_nid) {
300 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
301 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
302 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200303 }
304
305 return 0;
306}
307
308static void ad198x_free(struct hda_codec *codec)
309{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100310 struct ad198x_spec *spec = codec->spec;
311 unsigned int i;
312
313 if (spec->kctl_alloc) {
314 for (i = 0; i < spec->num_kctl_used; i++)
315 kfree(spec->kctl_alloc[i].name);
316 kfree(spec->kctl_alloc);
317 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200318 kfree(codec->spec);
319}
320
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200321static struct hda_codec_ops ad198x_patch_ops = {
322 .build_controls = ad198x_build_controls,
323 .build_pcms = ad198x_build_pcms,
324 .init = ad198x_init,
325 .free = ad198x_free,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200326};
327
328
329/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100330 * EAPD control
331 * the private value = nid | (invert << 8)
332 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200333#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100334
335static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_value *ucontrol)
337{
338 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
339 struct ad198x_spec *spec = codec->spec;
340 int invert = (kcontrol->private_value >> 8) & 1;
341 if (invert)
342 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
343 else
344 ucontrol->value.integer.value[0] = spec->cur_eapd;
345 return 0;
346}
347
348static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol)
350{
351 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
352 struct ad198x_spec *spec = codec->spec;
353 int invert = (kcontrol->private_value >> 8) & 1;
354 hda_nid_t nid = kcontrol->private_value & 0xff;
355 unsigned int eapd;
356 eapd = ucontrol->value.integer.value[0];
357 if (invert)
358 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200359 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100360 return 0;
361 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200362 snd_hda_codec_write_cache(codec, nid,
363 0, AC_VERB_SET_EAPD_BTLENABLE,
364 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100365 return 1;
366}
367
Takashi Iwai9230d212006-03-13 13:49:49 +0100368static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
369 struct snd_ctl_elem_info *uinfo);
370static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
371 struct snd_ctl_elem_value *ucontrol);
372static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
373 struct snd_ctl_elem_value *ucontrol);
374
375
Takashi Iwai18a815d2006-03-01 19:54:39 +0100376/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200377 * AD1986A specific
378 */
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#define AD1986A_SPDIF_OUT 0x02
381#define AD1986A_FRONT_DAC 0x03
382#define AD1986A_SURR_DAC 0x04
383#define AD1986A_CLFE_DAC 0x05
384#define AD1986A_ADC 0x06
385
386static hda_nid_t ad1986a_dac_nids[3] = {
387 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
388};
Takashi Iwai985be542005-11-02 18:26:49 +0100389static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100390static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392static struct hda_input_mux ad1986a_capture_source = {
393 .num_items = 7,
394 .items = {
395 { "Mic", 0x0 },
396 { "CD", 0x1 },
397 { "Aux", 0x3 },
398 { "Line", 0x4 },
399 { "Mix", 0x5 },
400 { "Mono", 0x6 },
401 { "Phone", 0x7 },
402 },
403};
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Takashi Iwai532d5382007-07-27 19:02:40 +0200406static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
407 .ops = &snd_hda_bind_vol,
408 .values = {
409 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
410 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
411 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
412 0
413 },
414};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Takashi Iwai532d5382007-07-27 19:02:40 +0200416static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
417 .ops = &snd_hda_bind_sw,
418 .values = {
419 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
420 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
421 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
422 0
423 },
424};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 * mixers
428 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100429static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200430 /*
431 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
432 */
433 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
434 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
436 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
437 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
438 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
439 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
440 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
441 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
442 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
443 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
444 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
445 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
446 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
447 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
448 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
449 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
450 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
451 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
452 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100453 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
455 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
456 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
457 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
458 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
459 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
460 {
461 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
462 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200463 .info = ad198x_mux_enum_info,
464 .get = ad198x_mux_enum_get,
465 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 },
467 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
468 { } /* end */
469};
470
Takashi Iwai9230d212006-03-13 13:49:49 +0100471/* additional mixers for 3stack mode */
472static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
473 {
474 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
475 .name = "Channel Mode",
476 .info = ad198x_ch_mode_info,
477 .get = ad198x_ch_mode_get,
478 .put = ad198x_ch_mode_put,
479 },
480 { } /* end */
481};
482
483/* laptop model - 2ch only */
484static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
485
486static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
487 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
488 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
489 HDA_CODEC_VOLUME("Master Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
490 HDA_CODEC_MUTE("Master Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
491 /* HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
492 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT), */
493 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
494 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
495 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
496 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
497 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
498 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
499 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
500 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100501 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai9230d212006-03-13 13:49:49 +0100502 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
503 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
504 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
505 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
506 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
507 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
508 {
509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
510 .name = "Capture Source",
511 .info = ad198x_mux_enum_info,
512 .get = ad198x_mux_enum_get,
513 .put = ad198x_mux_enum_put,
514 },
515 { } /* end */
516};
517
Takashi Iwai825aa972006-03-17 10:50:49 +0100518/* laptop-eapd model - 2ch only */
519
520/* master controls both pins 0x1a and 0x1b */
Takashi Iwai532d5382007-07-27 19:02:40 +0200521static struct hda_bind_ctls ad1986a_laptop_master_vol = {
522 .ops = &snd_hda_bind_vol,
523 .values = {
524 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
525 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
526 0,
527 },
528};
Takashi Iwai825aa972006-03-17 10:50:49 +0100529
Takashi Iwai532d5382007-07-27 19:02:40 +0200530static struct hda_bind_ctls ad1986a_laptop_master_sw = {
531 .ops = &snd_hda_bind_sw,
532 .values = {
533 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
534 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
535 0,
536 },
537};
Takashi Iwai825aa972006-03-17 10:50:49 +0100538
539static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
540 .num_items = 3,
541 .items = {
542 { "Mic", 0x0 },
543 { "Internal Mic", 0x4 },
544 { "Mix", 0x5 },
545 },
546};
547
548static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200549 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
550 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai825aa972006-03-17 10:50:49 +0100551 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
552 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
553 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
554 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
555 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
556 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100557 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100558 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
559 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
560 {
561 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
562 .name = "Capture Source",
563 .info = ad198x_mux_enum_info,
564 .get = ad198x_mux_enum_get,
565 .put = ad198x_mux_enum_put,
566 },
567 {
568 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
569 .name = "External Amplifier",
570 .info = ad198x_eapd_info,
571 .get = ad198x_eapd_get,
572 .put = ad198x_eapd_put,
573 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
574 },
575 { } /* end */
576};
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578/*
579 * initialization verbs
580 */
581static struct hda_verb ad1986a_init_verbs[] = {
582 /* Front, Surround, CLFE DAC; mute as default */
583 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
584 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
585 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
586 /* Downmix - off */
587 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
588 /* HP, Line-Out, Surround, CLFE selectors */
589 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
590 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
591 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
592 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
593 /* Mono selector */
594 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
595 /* Mic selector: Mic 1/2 pin */
596 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
597 /* Line-in selector: Line-in */
598 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
599 /* Mic 1/2 swap */
600 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
601 /* Record selector: mic */
602 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
603 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
604 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
605 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
606 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
607 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
608 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
609 /* PC beep */
610 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
611 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
612 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
613 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
614 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
615 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
616 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200617 /* HP Pin */
618 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
619 /* Front, Surround, CLFE Pins */
620 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
621 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
622 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
623 /* Mono Pin */
624 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
625 /* Mic Pin */
626 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
627 /* Line, Aux, CD, Beep-In Pin */
628 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
629 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
630 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
631 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
632 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 { } /* end */
634};
635
Takashi Iwai9230d212006-03-13 13:49:49 +0100636static struct hda_verb ad1986a_ch2_init[] = {
637 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200638 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
639 /* Line-in selectors */
640 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100641 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200642 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
643 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
644 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100645 { } /* end */
646};
647
648static struct hda_verb ad1986a_ch4_init[] = {
649 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200650 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
651 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100652 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200653 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
654 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100655 { } /* end */
656};
657
658static struct hda_verb ad1986a_ch6_init[] = {
659 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200660 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
661 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100662 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200663 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
664 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100665 { } /* end */
666};
667
668static struct hda_channel_mode ad1986a_modes[3] = {
669 { 2, ad1986a_ch2_init },
670 { 4, ad1986a_ch4_init },
671 { 6, ad1986a_ch6_init },
672};
673
Takashi Iwai825aa972006-03-17 10:50:49 +0100674/* eapd initialization */
675static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100676 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +0100677 {}
678};
679
Tobin Davisf36090f2007-01-08 11:07:12 +0100680/* Ultra initialization */
681static struct hda_verb ad1986a_ultra_init[] = {
682 /* eapd initialization */
683 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
684 /* CLFE -> Mic in */
685 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
686 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
687 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
688 { } /* end */
689};
690
Takashi Iwai9230d212006-03-13 13:49:49 +0100691/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100692enum {
693 AD1986A_6STACK,
694 AD1986A_3STACK,
695 AD1986A_LAPTOP,
696 AD1986A_LAPTOP_EAPD,
Tobin Davisf36090f2007-01-08 11:07:12 +0100697 AD1986A_ULTRA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100698 AD1986A_MODELS
699};
Takashi Iwai9230d212006-03-13 13:49:49 +0100700
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100701static const char *ad1986a_models[AD1986A_MODELS] = {
702 [AD1986A_6STACK] = "6stack",
703 [AD1986A_3STACK] = "3stack",
704 [AD1986A_LAPTOP] = "laptop",
705 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Tobin Davisf36090f2007-01-08 11:07:12 +0100706 [AD1986A_ULTRA] = "ultra",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100707};
708
709static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
710 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
711 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
712 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
713 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
714 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
715 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
716 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
717 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
718 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davis658fba02007-04-23 16:41:12 +0200719 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100720 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
721 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
722 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
723 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
724 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +0100725 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100726 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
727 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
728 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
729 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
Tobin Davisf36090f2007-01-08 11:07:12 +0100730 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
731 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Tobin Davis18768992007-03-12 22:20:51 +0100732 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100733 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
734 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_EAPD),
735 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +0100736 {}
737};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739static int patch_ad1986a(struct hda_codec *codec)
740{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200741 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100742 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200744 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 if (spec == NULL)
746 return -ENOMEM;
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 codec->spec = spec;
749
750 spec->multiout.max_channels = 6;
751 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
752 spec->multiout.dac_nids = ad1986a_dac_nids;
753 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100754 spec->num_adc_nids = 1;
755 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100756 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200757 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100758 spec->num_mixers = 1;
759 spec->mixers[0] = ad1986a_mixers;
760 spec->num_init_verbs = 1;
761 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200763 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Takashi Iwai9230d212006-03-13 13:49:49 +0100765 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100766 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
767 ad1986a_models,
768 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +0100769 switch (board_config) {
770 case AD1986A_3STACK:
771 spec->num_mixers = 2;
772 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +0200773 spec->num_init_verbs = 2;
774 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +0100775 spec->channel_mode = ad1986a_modes;
776 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +0200777 spec->need_dac_fix = 1;
778 spec->multiout.max_channels = 2;
779 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +0100780 break;
781 case AD1986A_LAPTOP:
782 spec->mixers[0] = ad1986a_laptop_mixers;
783 spec->multiout.max_channels = 2;
784 spec->multiout.num_dacs = 1;
785 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
786 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100787 case AD1986A_LAPTOP_EAPD:
788 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
789 spec->num_init_verbs = 2;
790 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
791 spec->multiout.max_channels = 2;
792 spec->multiout.num_dacs = 1;
793 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
794 spec->multiout.dig_out_nid = 0;
795 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
796 break;
Tobin Davisf36090f2007-01-08 11:07:12 +0100797 case AD1986A_ULTRA:
798 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
799 spec->num_init_verbs = 2;
800 spec->init_verbs[1] = ad1986a_ultra_init;
801 spec->multiout.max_channels = 2;
802 spec->multiout.num_dacs = 1;
803 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
804 spec->multiout.dig_out_nid = 0;
805 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100806 }
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return 0;
809}
810
811/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200812 * AD1983 specific
813 */
814
815#define AD1983_SPDIF_OUT 0x02
816#define AD1983_DAC 0x03
817#define AD1983_ADC 0x04
818
819static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100820static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100821static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200822
823static struct hda_input_mux ad1983_capture_source = {
824 .num_items = 4,
825 .items = {
826 { "Mic", 0x0 },
827 { "Line", 0x1 },
828 { "Mix", 0x2 },
829 { "Mix Mono", 0x3 },
830 },
831};
832
833/*
834 * SPDIF playback route
835 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100836static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200837{
838 static char *texts[] = { "PCM", "ADC" };
839
840 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
841 uinfo->count = 1;
842 uinfo->value.enumerated.items = 2;
843 if (uinfo->value.enumerated.item > 1)
844 uinfo->value.enumerated.item = 1;
845 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
846 return 0;
847}
848
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100849static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200850{
851 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
852 struct ad198x_spec *spec = codec->spec;
853
854 ucontrol->value.enumerated.item[0] = spec->spdif_route;
855 return 0;
856}
857
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100858static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200859{
860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
861 struct ad198x_spec *spec = codec->spec;
862
863 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
864 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200865 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
866 AC_VERB_SET_CONNECT_SEL,
867 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200868 return 1;
869 }
870 return 0;
871}
872
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100873static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200874 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
875 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
876 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
877 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
878 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
879 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
880 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
881 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
882 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
883 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
884 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
885 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
886 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
887 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
888 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
889 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
890 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
891 {
892 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
893 .name = "Capture Source",
894 .info = ad198x_mux_enum_info,
895 .get = ad198x_mux_enum_get,
896 .put = ad198x_mux_enum_put,
897 },
898 {
899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +0200900 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200901 .info = ad1983_spdif_route_info,
902 .get = ad1983_spdif_route_get,
903 .put = ad1983_spdif_route_put,
904 },
905 { } /* end */
906};
907
908static struct hda_verb ad1983_init_verbs[] = {
909 /* Front, HP, Mono; mute as default */
910 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
911 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
912 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
913 /* Beep, PCM, Mic, Line-In: mute */
914 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
915 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
916 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
917 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
918 /* Front, HP selectors; from Mix */
919 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
920 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
921 /* Mono selector; from Mix */
922 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
923 /* Mic selector; Mic */
924 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
925 /* Line-in selector: Line-in */
926 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
927 /* Mic boost: 0dB */
928 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
929 /* Record selector: mic */
930 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
931 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
932 /* SPDIF route: PCM */
933 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
934 /* Front Pin */
935 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
936 /* HP Pin */
937 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
938 /* Mono Pin */
939 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
940 /* Mic Pin */
941 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
942 /* Line Pin */
943 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
944 { } /* end */
945};
946
Takashi Iwai985be542005-11-02 18:26:49 +0100947
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200948static int patch_ad1983(struct hda_codec *codec)
949{
950 struct ad198x_spec *spec;
951
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200952 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200953 if (spec == NULL)
954 return -ENOMEM;
955
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200956 codec->spec = spec;
957
958 spec->multiout.max_channels = 2;
959 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
960 spec->multiout.dac_nids = ad1983_dac_nids;
961 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100962 spec->num_adc_nids = 1;
963 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100964 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200965 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100966 spec->num_mixers = 1;
967 spec->mixers[0] = ad1983_mixers;
968 spec->num_init_verbs = 1;
969 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200970 spec->spdif_route = 0;
971
972 codec->patch_ops = ad198x_patch_ops;
973
974 return 0;
975}
976
977
978/*
979 * AD1981 HD specific
980 */
981
982#define AD1981_SPDIF_OUT 0x02
983#define AD1981_DAC 0x03
984#define AD1981_ADC 0x04
985
986static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100987static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100988static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200989
990/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
991static struct hda_input_mux ad1981_capture_source = {
992 .num_items = 7,
993 .items = {
994 { "Front Mic", 0x0 },
995 { "Line", 0x1 },
996 { "Mix", 0x2 },
997 { "Mix Mono", 0x3 },
998 { "CD", 0x4 },
999 { "Mic", 0x6 },
1000 { "Aux", 0x7 },
1001 },
1002};
1003
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001004static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001005 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1006 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1007 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1008 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1009 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1010 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1011 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1012 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1013 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1014 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1015 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1016 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1017 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1018 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1019 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1020 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1021 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1022 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1023 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1024 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1026 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1027 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1028 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1029 {
1030 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1031 .name = "Capture Source",
1032 .info = ad198x_mux_enum_info,
1033 .get = ad198x_mux_enum_get,
1034 .put = ad198x_mux_enum_put,
1035 },
1036 /* identical with AD1983 */
1037 {
1038 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001039 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001040 .info = ad1983_spdif_route_info,
1041 .get = ad1983_spdif_route_get,
1042 .put = ad1983_spdif_route_put,
1043 },
1044 { } /* end */
1045};
1046
1047static struct hda_verb ad1981_init_verbs[] = {
1048 /* Front, HP, Mono; mute as default */
1049 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1050 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1051 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1052 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1053 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1054 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1055 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1056 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1057 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1058 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1059 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1060 /* Front, HP selectors; from Mix */
1061 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1062 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1063 /* Mono selector; from Mix */
1064 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1065 /* Mic Mixer; select Front Mic */
1066 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1067 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1068 /* Mic boost: 0dB */
1069 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1070 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1071 /* Record selector: Front mic */
1072 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1073 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1074 /* SPDIF route: PCM */
1075 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1076 /* Front Pin */
1077 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1078 /* HP Pin */
1079 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1080 /* Mono Pin */
1081 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1082 /* Front & Rear Mic Pins */
1083 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1084 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1085 /* Line Pin */
1086 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1087 /* Digital Beep */
1088 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1089 /* Line-Out as Input: disabled */
1090 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1091 { } /* end */
1092};
1093
Takashi Iwai18a815d2006-03-01 19:54:39 +01001094/*
1095 * Patch for HP nx6320
1096 *
Tobin Davis18768992007-03-12 22:20:51 +01001097 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001098 * speaker output enabled _and_ mute-LED off.
1099 */
1100
1101#define AD1981_HP_EVENT 0x37
1102#define AD1981_MIC_EVENT 0x38
1103
1104static struct hda_verb ad1981_hp_init_verbs[] = {
1105 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1106 /* pin sensing on HP and Mic jacks */
1107 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1108 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1109 {}
1110};
1111
1112/* turn on/off EAPD (+ mute HP) as a master switch */
1113static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1114 struct snd_ctl_elem_value *ucontrol)
1115{
1116 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1117 struct ad198x_spec *spec = codec->spec;
1118
1119 if (! ad198x_eapd_put(kcontrol, ucontrol))
1120 return 0;
1121
1122 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001123 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1124 HDA_AMP_MUTE,
1125 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001126 return 1;
1127}
1128
1129/* bind volumes of both NID 0x05 and 0x06 */
1130static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1131 struct snd_ctl_elem_value *ucontrol)
1132{
1133 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1134 long *valp = ucontrol->value.integer.value;
1135 int change;
1136
1137 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001138 HDA_AMP_VOLMASK, valp[0]);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001139 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001140 HDA_AMP_VOLMASK, valp[1]);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001141 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001142 HDA_AMP_VOLMASK, valp[0]);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001143 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
Takashi Iwai47fd8302007-08-10 17:11:07 +02001144 HDA_AMP_VOLMASK, valp[1]);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001145 return change;
1146}
1147
1148/* mute internal speaker if HP is plugged */
1149static void ad1981_hp_automute(struct hda_codec *codec)
1150{
1151 unsigned int present;
1152
1153 present = snd_hda_codec_read(codec, 0x06, 0,
1154 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Takashi Iwai47fd8302007-08-10 17:11:07 +02001155 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1156 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001157}
1158
1159/* toggle input of built-in and mic jack appropriately */
1160static void ad1981_hp_automic(struct hda_codec *codec)
1161{
1162 static struct hda_verb mic_jack_on[] = {
1163 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1164 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1165 {}
1166 };
1167 static struct hda_verb mic_jack_off[] = {
1168 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1169 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1170 {}
1171 };
1172 unsigned int present;
1173
1174 present = snd_hda_codec_read(codec, 0x08, 0,
1175 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1176 if (present)
1177 snd_hda_sequence_write(codec, mic_jack_on);
1178 else
1179 snd_hda_sequence_write(codec, mic_jack_off);
1180}
1181
1182/* unsolicited event for HP jack sensing */
1183static void ad1981_hp_unsol_event(struct hda_codec *codec,
1184 unsigned int res)
1185{
1186 res >>= 26;
1187 switch (res) {
1188 case AD1981_HP_EVENT:
1189 ad1981_hp_automute(codec);
1190 break;
1191 case AD1981_MIC_EVENT:
1192 ad1981_hp_automic(codec);
1193 break;
1194 }
1195}
1196
1197static struct hda_input_mux ad1981_hp_capture_source = {
1198 .num_items = 3,
1199 .items = {
1200 { "Mic", 0x0 },
1201 { "Docking-Station", 0x1 },
1202 { "Mix", 0x2 },
1203 },
1204};
1205
1206static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1207 {
1208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1209 .name = "Master Playback Volume",
1210 .info = snd_hda_mixer_amp_volume_info,
1211 .get = snd_hda_mixer_amp_volume_get,
1212 .put = ad1981_hp_master_vol_put,
1213 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1214 },
1215 {
1216 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1217 .name = "Master Playback Switch",
1218 .info = ad198x_eapd_info,
1219 .get = ad198x_eapd_get,
1220 .put = ad1981_hp_master_sw_put,
1221 .private_value = 0x05,
1222 },
1223 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1224 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1225#if 0
1226 /* FIXME: analog mic/line loopback doesn't work with my tests...
1227 * (although recording is OK)
1228 */
1229 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1230 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1231 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1232 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1233 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1234 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1235 /* FIXME: does this laptop have analog CD connection? */
1236 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1237 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1238#endif
1239 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1240 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1241 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1242 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1243 {
1244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1245 .name = "Capture Source",
1246 .info = ad198x_mux_enum_info,
1247 .get = ad198x_mux_enum_get,
1248 .put = ad198x_mux_enum_put,
1249 },
1250 { } /* end */
1251};
1252
1253/* initialize jack-sensing, too */
1254static int ad1981_hp_init(struct hda_codec *codec)
1255{
1256 ad198x_init(codec);
1257 ad1981_hp_automute(codec);
1258 ad1981_hp_automic(codec);
1259 return 0;
1260}
1261
Tobin Davis18768992007-03-12 22:20:51 +01001262/* configuration for Toshiba Laptops */
1263static struct hda_verb ad1981_toshiba_init_verbs[] = {
1264 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1265 /* pin sensing on HP and Mic jacks */
1266 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1267 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1268 {}
1269};
1270
1271static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1272 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1273 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1274 { }
1275};
1276
Takashi Iwai01686c52006-04-18 12:54:11 +02001277/* configuration for Lenovo Thinkpad T60 */
1278static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1279 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1280 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1281 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1282 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1283 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1284 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1285 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1286 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1287 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1288 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1289 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1290 {
1291 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1292 .name = "Capture Source",
1293 .info = ad198x_mux_enum_info,
1294 .get = ad198x_mux_enum_get,
1295 .put = ad198x_mux_enum_put,
1296 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001297 /* identical with AD1983 */
1298 {
1299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1300 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1301 .info = ad1983_spdif_route_info,
1302 .get = ad1983_spdif_route_get,
1303 .put = ad1983_spdif_route_put,
1304 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001305 { } /* end */
1306};
1307
1308static struct hda_input_mux ad1981_thinkpad_capture_source = {
1309 .num_items = 3,
1310 .items = {
1311 { "Mic", 0x0 },
1312 { "Mix", 0x2 },
1313 { "CD", 0x4 },
1314 },
1315};
1316
Takashi Iwai18a815d2006-03-01 19:54:39 +01001317/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001318enum {
1319 AD1981_BASIC,
1320 AD1981_HP,
1321 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001322 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001323 AD1981_MODELS
1324};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001325
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001326static const char *ad1981_models[AD1981_MODELS] = {
1327 [AD1981_HP] = "hp",
1328 [AD1981_THINKPAD] = "thinkpad",
1329 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001330 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001331};
1332
1333static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001334 /* All HP models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001335 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
1336 /* HP nx6320 (reversed SSID, H/W bug) */
1337 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai01686c52006-04-18 12:54:11 +02001338 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001339 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
1340 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Tobin Davis18768992007-03-12 22:20:51 +01001341 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001342 {}
1343};
1344
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001345static int patch_ad1981(struct hda_codec *codec)
1346{
1347 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001348 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001349
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001350 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001351 if (spec == NULL)
1352 return -ENOMEM;
1353
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001354 codec->spec = spec;
1355
1356 spec->multiout.max_channels = 2;
1357 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1358 spec->multiout.dac_nids = ad1981_dac_nids;
1359 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001360 spec->num_adc_nids = 1;
1361 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001362 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001363 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001364 spec->num_mixers = 1;
1365 spec->mixers[0] = ad1981_mixers;
1366 spec->num_init_verbs = 1;
1367 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001368 spec->spdif_route = 0;
1369
1370 codec->patch_ops = ad198x_patch_ops;
1371
Takashi Iwai18a815d2006-03-01 19:54:39 +01001372 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001373 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1374 ad1981_models,
1375 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001376 switch (board_config) {
1377 case AD1981_HP:
1378 spec->mixers[0] = ad1981_hp_mixers;
1379 spec->num_init_verbs = 2;
1380 spec->init_verbs[1] = ad1981_hp_init_verbs;
1381 spec->multiout.dig_out_nid = 0;
1382 spec->input_mux = &ad1981_hp_capture_source;
1383
1384 codec->patch_ops.init = ad1981_hp_init;
1385 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1386 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001387 case AD1981_THINKPAD:
1388 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001389 spec->input_mux = &ad1981_thinkpad_capture_source;
1390 break;
Tobin Davis18768992007-03-12 22:20:51 +01001391 case AD1981_TOSHIBA:
1392 spec->mixers[0] = ad1981_hp_mixers;
1393 spec->mixers[1] = ad1981_toshiba_mixers;
1394 spec->num_init_verbs = 2;
1395 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1396 spec->multiout.dig_out_nid = 0;
1397 spec->input_mux = &ad1981_hp_capture_source;
1398 codec->patch_ops.init = ad1981_hp_init;
1399 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1400 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001401 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001402 return 0;
1403}
1404
1405
1406/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001407 * AD1988
1408 *
1409 * Output pins and routes
1410 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001411 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001412 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1413 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1414 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1415 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1416 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1417 * port-F 0x16 (mute) <- 0x2a <- 06
1418 * port-G 0x24 (mute) <- 0x27 <- 05
1419 * port-H 0x25 (mute) <- 0x28 <- 0a
1420 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1421 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001422 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1423 * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001424 *
1425 * Input pins and routes
1426 *
1427 * pin boost mix input # / adc input #
1428 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1429 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1430 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1431 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1432 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1433 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1434 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1435 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1436 *
1437 *
1438 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001439 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001440 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001441 *
1442 * Inputs of Analog Mix (0x20)
1443 * 0:Port-B (front mic)
1444 * 1:Port-C/G/H (line-in)
1445 * 2:Port-A
1446 * 3:Port-D (line-in/2)
1447 * 4:Port-E/G/H (mic-in)
1448 * 5:Port-F (mic2-in)
1449 * 6:CD
1450 * 7:Beep
1451 *
1452 * ADC selection
1453 * 0:Port-A
1454 * 1:Port-B (front mic-in)
1455 * 2:Port-C (line-in)
1456 * 3:Port-F (mic2-in)
1457 * 4:Port-E (mic-in)
1458 * 5:CD
1459 * 6:Port-G
1460 * 7:Port-H
1461 * 8:Port-D (line-in/2)
1462 * 9:Mix
1463 *
1464 * Proposed pin assignments by the datasheet
1465 *
1466 * 6-stack
1467 * Port-A front headphone
1468 * B front mic-in
1469 * C rear line-in
1470 * D rear front-out
1471 * E rear mic-in
1472 * F rear surround
1473 * G rear CLFE
1474 * H rear side
1475 *
1476 * 3-stack
1477 * Port-A front headphone
1478 * B front mic
1479 * C rear line-in/surround
1480 * D rear front-out
1481 * E rear mic-in/CLFE
1482 *
1483 * laptop
1484 * Port-A headphone
1485 * B mic-in
1486 * C docking station
1487 * D internal speaker (with EAPD)
1488 * E/F quad mic array
1489 */
1490
1491
1492/* models */
1493enum {
1494 AD1988_6STACK,
1495 AD1988_6STACK_DIG,
1496 AD1988_3STACK,
1497 AD1988_3STACK_DIG,
1498 AD1988_LAPTOP,
1499 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001500 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001501 AD1988_MODEL_LAST,
1502};
1503
Takashi Iwaid32410b12005-11-24 16:06:23 +01001504/* reivision id to check workarounds */
1505#define AD1988A_REV2 0x100200
1506
Takashi Iwai1a806f42006-07-03 15:58:16 +02001507#define is_rev2(codec) \
1508 ((codec)->vendor_id == 0x11d41988 && \
1509 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001510
1511/*
1512 * mixers
1513 */
1514
Takashi Iwaid32410b12005-11-24 16:06:23 +01001515static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001516 0x04, 0x06, 0x05, 0x0a
1517};
1518
Takashi Iwaid32410b12005-11-24 16:06:23 +01001519static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001520 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001521};
1522
1523/* for AD1988A revision-2, DAC2-4 are swapped */
1524static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1525 0x04, 0x05, 0x0a, 0x06
1526};
1527
1528static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001529 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001530};
1531
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001532static hda_nid_t ad1988_adc_nids[3] = {
1533 0x08, 0x09, 0x0f
1534};
1535
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001536static hda_nid_t ad1988_capsrc_nids[3] = {
1537 0x0c, 0x0d, 0x0e
1538};
1539
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001540#define AD1988_SPDIF_OUT 0x02
1541#define AD1988_SPDIF_IN 0x07
1542
1543static struct hda_input_mux ad1988_6stack_capture_source = {
1544 .num_items = 5,
1545 .items = {
1546 { "Front Mic", 0x0 },
1547 { "Line", 0x1 },
1548 { "Mic", 0x4 },
1549 { "CD", 0x5 },
1550 { "Mix", 0x9 },
1551 },
1552};
1553
1554static struct hda_input_mux ad1988_laptop_capture_source = {
1555 .num_items = 3,
1556 .items = {
1557 { "Mic/Line", 0x0 },
1558 { "CD", 0x5 },
1559 { "Mix", 0x9 },
1560 },
1561};
1562
1563/*
1564 */
1565static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1566 struct snd_ctl_elem_info *uinfo)
1567{
1568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1569 struct ad198x_spec *spec = codec->spec;
1570 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1571 spec->num_channel_mode);
1572}
1573
1574static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1575 struct snd_ctl_elem_value *ucontrol)
1576{
1577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1578 struct ad198x_spec *spec = codec->spec;
1579 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1580 spec->num_channel_mode, spec->multiout.max_channels);
1581}
1582
1583static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1584 struct snd_ctl_elem_value *ucontrol)
1585{
1586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1587 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001588 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1589 spec->num_channel_mode,
1590 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001591 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001592 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001593 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001594}
1595
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001596/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001597static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001598 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1599 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1600 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1601 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1602 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001603 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001604};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001605
Takashi Iwaid32410b12005-11-24 16:06:23 +01001606static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1607 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1608 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1609 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1610 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1611 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001612 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001613};
1614
1615static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001616 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1617 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1618 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1619 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1620 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1621 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1622 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1623
1624 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1625 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1626 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1627 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1628 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1629 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1630 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1631 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1632
1633 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1634 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1635
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001636 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001637 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1638
1639 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1640 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1641
1642 { } /* end */
1643};
1644
1645/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001646static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001647 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001648 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001649 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1650 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001651 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001652};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001653
Takashi Iwaid32410b12005-11-24 16:06:23 +01001654static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1655 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001656 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1657 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1658 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001659 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001660};
1661
1662static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001663 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001664 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1665 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1666 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001667 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1668 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1669
1670 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1671 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1672 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1673 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1674 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1675 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1676 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1677 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1678
1679 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1680 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1681
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001682 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001683 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1684
1685 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1686 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1687 {
1688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1689 .name = "Channel Mode",
1690 .info = ad198x_ch_mode_info,
1691 .get = ad198x_ch_mode_get,
1692 .put = ad198x_ch_mode_put,
1693 },
1694
1695 { } /* end */
1696};
1697
1698/* laptop mode */
1699static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1700 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1701 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1702 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1703
1704 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1705 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1706 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1707 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1708 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1709 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1710
1711 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1712 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1713
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001714 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001715 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1716
1717 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1718
1719 {
1720 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1721 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001722 .info = ad198x_eapd_info,
1723 .get = ad198x_eapd_get,
1724 .put = ad198x_eapd_put,
1725 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001726 },
1727
1728 { } /* end */
1729};
1730
1731/* capture */
1732static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1733 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1734 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1735 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1736 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1737 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1738 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1739 {
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1741 /* The multiple "Capture Source" controls confuse alsamixer
1742 * So call somewhat different..
1743 * FIXME: the controls appear in the "playback" view!
1744 */
1745 /* .name = "Capture Source", */
1746 .name = "Input Source",
1747 .count = 3,
1748 .info = ad198x_mux_enum_info,
1749 .get = ad198x_mux_enum_get,
1750 .put = ad198x_mux_enum_put,
1751 },
1752 { } /* end */
1753};
1754
1755static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_info *uinfo)
1757{
1758 static char *texts[] = {
1759 "PCM", "ADC1", "ADC2", "ADC3"
1760 };
1761 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1762 uinfo->count = 1;
1763 uinfo->value.enumerated.items = 4;
1764 if (uinfo->value.enumerated.item >= 4)
1765 uinfo->value.enumerated.item = 3;
1766 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1767 return 0;
1768}
1769
1770static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1772{
1773 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1774 unsigned int sel;
1775
Takashi Iwaibddcf542007-07-24 18:04:05 +02001776 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
1777 AC_AMP_GET_INPUT);
1778 if (!(sel & 0x80))
1779 ucontrol->value.enumerated.item[0] = 0;
1780 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02001781 sel = snd_hda_codec_read(codec, 0x0b, 0,
1782 AC_VERB_GET_CONNECT_SEL, 0);
1783 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001784 sel++;
1785 else
1786 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02001787 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001788 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001789 return 0;
1790}
1791
1792static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1793 struct snd_ctl_elem_value *ucontrol)
1794{
1795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02001796 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001797 int change;
1798
Takashi Iwai35b26722007-05-05 12:17:17 +02001799 val = ucontrol->value.enumerated.item[0];
Takashi Iwai35b26722007-05-05 12:17:17 +02001800 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02001801 sel = snd_hda_codec_read(codec, 0x1d, 0,
1802 AC_VERB_GET_AMP_GAIN_MUTE,
1803 AC_AMP_GET_INPUT);
1804 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001805 if (change) {
1806 snd_hda_codec_write_cache(codec, 0x1d, 0,
1807 AC_VERB_SET_AMP_GAIN_MUTE,
1808 AMP_IN_UNMUTE(0));
1809 snd_hda_codec_write_cache(codec, 0x1d, 0,
1810 AC_VERB_SET_AMP_GAIN_MUTE,
1811 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02001812 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001813 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02001814 sel = snd_hda_codec_read(codec, 0x1d, 0,
1815 AC_VERB_GET_AMP_GAIN_MUTE,
1816 AC_AMP_GET_INPUT | 0x01);
1817 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001818 if (change) {
1819 snd_hda_codec_write_cache(codec, 0x1d, 0,
1820 AC_VERB_SET_AMP_GAIN_MUTE,
1821 AMP_IN_MUTE(0));
1822 snd_hda_codec_write_cache(codec, 0x1d, 0,
1823 AC_VERB_SET_AMP_GAIN_MUTE,
1824 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02001825 }
Takashi Iwai35b26722007-05-05 12:17:17 +02001826 sel = snd_hda_codec_read(codec, 0x0b, 0,
1827 AC_VERB_GET_CONNECT_SEL, 0) + 1;
1828 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001829 if (change)
1830 snd_hda_codec_write_cache(codec, 0x0b, 0,
1831 AC_VERB_SET_CONNECT_SEL,
1832 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001833 }
1834 return change;
1835}
1836
1837static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1838 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1839 {
1840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1841 .name = "IEC958 Playback Source",
1842 .info = ad1988_spdif_playback_source_info,
1843 .get = ad1988_spdif_playback_source_get,
1844 .put = ad1988_spdif_playback_source_put,
1845 },
1846 { } /* end */
1847};
1848
1849static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1850 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1851 { } /* end */
1852};
1853
1854
1855/*
1856 * initialization verbs
1857 */
1858
1859/*
1860 * for 6-stack (+dig)
1861 */
1862static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001863 /* Front, Surround, CLFE, side DAC; unmute as default */
1864 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1865 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1866 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1867 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001868 /* Port-A front headphon path */
1869 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1870 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1871 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1872 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1873 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1874 /* Port-D line-out path */
1875 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1876 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1877 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1878 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1879 /* Port-F surround path */
1880 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1881 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1882 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1883 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1884 /* Port-G CLFE path */
1885 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1886 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1887 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1888 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1889 /* Port-H side path */
1890 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1891 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1892 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1893 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1894 /* Mono out path */
1895 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1896 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1897 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1898 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1899 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1900 /* Port-B front mic-in path */
1901 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1902 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1903 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1904 /* Port-C line-in path */
1905 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1906 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1907 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1908 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1909 /* Port-E mic-in path */
1910 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1911 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1912 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1913 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1914
1915 { }
1916};
1917
1918static struct hda_verb ad1988_capture_init_verbs[] = {
1919 /* mute analog mix */
1920 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1921 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1922 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1923 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1924 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1925 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1926 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1927 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1928 /* select ADCs - front-mic */
1929 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1930 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1931 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1932 /* ADCs; muted */
1933 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1934 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1935 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1936
1937 { }
1938};
1939
1940static struct hda_verb ad1988_spdif_init_verbs[] = {
1941 /* SPDIF out sel */
1942 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1943 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1944 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02001945 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001946 /* SPDIF out pin */
1947 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001948
1949 { }
1950};
1951
1952/*
1953 * verbs for 3stack (+dig)
1954 */
1955static struct hda_verb ad1988_3stack_ch2_init[] = {
1956 /* set port-C to line-in */
1957 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1958 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1959 /* set port-E to mic-in */
1960 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1961 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1962 { } /* end */
1963};
1964
1965static struct hda_verb ad1988_3stack_ch6_init[] = {
1966 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001967 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001968 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001969 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001970 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001971 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001972 { } /* end */
1973};
1974
1975static struct hda_channel_mode ad1988_3stack_modes[2] = {
1976 { 2, ad1988_3stack_ch2_init },
1977 { 6, ad1988_3stack_ch6_init },
1978};
1979
1980static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001981 /* Front, Surround, CLFE, side DAC; unmute as default */
1982 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1983 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1984 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1985 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001986 /* Port-A front headphon path */
1987 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1988 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1989 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1990 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1991 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1992 /* Port-D line-out path */
1993 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1994 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1995 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1996 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1997 /* Mono out path */
1998 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1999 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2000 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2001 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2002 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2003 /* Port-B front mic-in path */
2004 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2005 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2006 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002007 /* Port-C line-in/surround path - 6ch mode as default */
2008 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2009 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002010 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002011 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002012 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002013 /* Port-E mic-in/CLFE path - 6ch mode as default */
2014 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2015 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002016 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002017 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002018 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2019 /* mute analog mix */
2020 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2021 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2022 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2023 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2024 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2025 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2026 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2027 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2028 /* select ADCs - front-mic */
2029 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2030 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2031 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2032 /* ADCs; muted */
2033 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2034 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2035 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2036 { }
2037};
2038
2039/*
2040 * verbs for laptop mode (+dig)
2041 */
2042static struct hda_verb ad1988_laptop_hp_on[] = {
2043 /* unmute port-A and mute port-D */
2044 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2045 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2046 { } /* end */
2047};
2048static struct hda_verb ad1988_laptop_hp_off[] = {
2049 /* mute port-A and unmute port-D */
2050 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2051 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2052 { } /* end */
2053};
2054
2055#define AD1988_HP_EVENT 0x01
2056
2057static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002058 /* Front, Surround, CLFE, side DAC; unmute as default */
2059 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2060 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2061 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2062 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002063 /* Port-A front headphon path */
2064 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2065 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2066 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2067 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2068 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2069 /* unsolicited event for pin-sense */
2070 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2071 /* Port-D line-out path + EAPD */
2072 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2073 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2074 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2075 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2076 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2077 /* Mono out path */
2078 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2079 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2080 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2081 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2082 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2083 /* Port-B mic-in path */
2084 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2085 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2086 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2087 /* Port-C docking station - try to output */
2088 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2089 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2090 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2091 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2092 /* mute analog mix */
2093 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2094 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2095 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2096 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2097 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2098 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2099 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2100 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2101 /* select ADCs - mic */
2102 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2103 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2104 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2105 /* ADCs; muted */
2106 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2107 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2108 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2109 { }
2110};
2111
2112static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2113{
2114 if ((res >> 26) != AD1988_HP_EVENT)
2115 return;
2116 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2117 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2118 else
2119 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2120}
2121
2122
2123/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002124 * Automatic parse of I/O pins from the BIOS configuration
2125 */
2126
2127#define NUM_CONTROL_ALLOC 32
2128#define NUM_VERB_ALLOC 32
2129
2130enum {
2131 AD_CTL_WIDGET_VOL,
2132 AD_CTL_WIDGET_MUTE,
2133 AD_CTL_BIND_MUTE,
2134};
2135static struct snd_kcontrol_new ad1988_control_templates[] = {
2136 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2137 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2138 HDA_BIND_MUTE(NULL, 0, 0, 0),
2139};
2140
2141/* add dynamic controls */
2142static int add_control(struct ad198x_spec *spec, int type, const char *name,
2143 unsigned long val)
2144{
2145 struct snd_kcontrol_new *knew;
2146
2147 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2148 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2149
2150 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2151 if (! knew)
2152 return -ENOMEM;
2153 if (spec->kctl_alloc) {
2154 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2155 kfree(spec->kctl_alloc);
2156 }
2157 spec->kctl_alloc = knew;
2158 spec->num_kctl_alloc = num;
2159 }
2160
2161 knew = &spec->kctl_alloc[spec->num_kctl_used];
2162 *knew = ad1988_control_templates[type];
2163 knew->name = kstrdup(name, GFP_KERNEL);
2164 if (! knew->name)
2165 return -ENOMEM;
2166 knew->private_value = val;
2167 spec->num_kctl_used++;
2168 return 0;
2169}
2170
2171#define AD1988_PIN_CD_NID 0x18
2172#define AD1988_PIN_BEEP_NID 0x10
2173
2174static hda_nid_t ad1988_mixer_nids[8] = {
2175 /* A B C D E F G H */
2176 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2177};
2178
2179static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2180{
2181 static hda_nid_t idx_to_dac[8] = {
2182 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002183 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002184 };
2185 static hda_nid_t idx_to_dac_rev2[8] = {
2186 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002187 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002188 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002189 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002190 return idx_to_dac_rev2[idx];
2191 else
2192 return idx_to_dac[idx];
2193}
2194
2195static hda_nid_t ad1988_boost_nids[8] = {
2196 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2197};
2198
2199static int ad1988_pin_idx(hda_nid_t nid)
2200{
2201 static hda_nid_t ad1988_io_pins[8] = {
2202 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2203 };
2204 int i;
2205 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2206 if (ad1988_io_pins[i] == nid)
2207 return i;
2208 return 0; /* should be -1 */
2209}
2210
2211static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2212{
2213 static int loopback_idx[8] = {
2214 2, 0, 1, 3, 4, 5, 1, 4
2215 };
2216 switch (nid) {
2217 case AD1988_PIN_CD_NID:
2218 return 6;
2219 default:
2220 return loopback_idx[ad1988_pin_idx(nid)];
2221 }
2222}
2223
2224static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2225{
2226 static int adc_idx[8] = {
2227 0, 1, 2, 8, 4, 3, 6, 7
2228 };
2229 switch (nid) {
2230 case AD1988_PIN_CD_NID:
2231 return 5;
2232 default:
2233 return adc_idx[ad1988_pin_idx(nid)];
2234 }
2235}
2236
2237/* fill in the dac_nids table from the parsed pin configuration */
2238static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2239 const struct auto_pin_cfg *cfg)
2240{
2241 struct ad198x_spec *spec = codec->spec;
2242 int i, idx;
2243
2244 spec->multiout.dac_nids = spec->private_dac_nids;
2245
2246 /* check the pins hardwired to audio widget */
2247 for (i = 0; i < cfg->line_outs; i++) {
2248 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2249 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2250 }
2251 spec->multiout.num_dacs = cfg->line_outs;
2252 return 0;
2253}
2254
2255/* add playback controls from the parsed DAC table */
2256static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2257 const struct auto_pin_cfg *cfg)
2258{
2259 char name[32];
2260 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2261 hda_nid_t nid;
2262 int i, err;
2263
2264 for (i = 0; i < cfg->line_outs; i++) {
2265 hda_nid_t dac = spec->multiout.dac_nids[i];
2266 if (! dac)
2267 continue;
2268 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2269 if (i == 2) {
2270 /* Center/LFE */
2271 err = add_control(spec, AD_CTL_WIDGET_VOL,
2272 "Center Playback Volume",
2273 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2274 if (err < 0)
2275 return err;
2276 err = add_control(spec, AD_CTL_WIDGET_VOL,
2277 "LFE Playback Volume",
2278 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2279 if (err < 0)
2280 return err;
2281 err = add_control(spec, AD_CTL_BIND_MUTE,
2282 "Center Playback Switch",
2283 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2284 if (err < 0)
2285 return err;
2286 err = add_control(spec, AD_CTL_BIND_MUTE,
2287 "LFE Playback Switch",
2288 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2289 if (err < 0)
2290 return err;
2291 } else {
2292 sprintf(name, "%s Playback Volume", chname[i]);
2293 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2294 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2295 if (err < 0)
2296 return err;
2297 sprintf(name, "%s Playback Switch", chname[i]);
2298 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2299 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2300 if (err < 0)
2301 return err;
2302 }
2303 }
2304 return 0;
2305}
2306
2307/* add playback controls for speaker and HP outputs */
2308static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2309 const char *pfx)
2310{
2311 struct ad198x_spec *spec = codec->spec;
2312 hda_nid_t nid;
2313 int idx, err;
2314 char name[32];
2315
2316 if (! pin)
2317 return 0;
2318
2319 idx = ad1988_pin_idx(pin);
2320 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002321 /* specify the DAC as the extra output */
2322 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002323 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002324 else
2325 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002326 /* control HP volume/switch on the output mixer amp */
2327 sprintf(name, "%s Playback Volume", pfx);
2328 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2329 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2330 return err;
2331 nid = ad1988_mixer_nids[idx];
2332 sprintf(name, "%s Playback Switch", pfx);
2333 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2334 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2335 return err;
2336 return 0;
2337}
2338
2339/* create input playback/capture controls for the given pin */
2340static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2341 const char *ctlname, int boost)
2342{
2343 char name[32];
2344 int err, idx;
2345
2346 sprintf(name, "%s Playback Volume", ctlname);
2347 idx = ad1988_pin_to_loopback_idx(pin);
2348 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2349 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2350 return err;
2351 sprintf(name, "%s Playback Switch", ctlname);
2352 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2353 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2354 return err;
2355 if (boost) {
2356 hda_nid_t bnid;
2357 idx = ad1988_pin_idx(pin);
2358 bnid = ad1988_boost_nids[idx];
2359 if (bnid) {
2360 sprintf(name, "%s Boost", ctlname);
2361 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2362 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2363
2364 }
2365 }
2366 return 0;
2367}
2368
2369/* create playback/capture controls for input pins */
2370static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2371 const struct auto_pin_cfg *cfg)
2372{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002373 struct hda_input_mux *imux = &spec->private_imux;
2374 int i, err;
2375
2376 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002377 err = new_analog_input(spec, cfg->input_pins[i],
2378 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002379 i <= AUTO_PIN_FRONT_MIC);
2380 if (err < 0)
2381 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002382 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002383 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2384 imux->num_items++;
2385 }
2386 imux->items[imux->num_items].label = "Mix";
2387 imux->items[imux->num_items].index = 9;
2388 imux->num_items++;
2389
2390 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2391 "Analog Mix Playback Volume",
2392 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2393 return err;
2394 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2395 "Analog Mix Playback Switch",
2396 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2397 return err;
2398
2399 return 0;
2400}
2401
2402static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2403 hda_nid_t nid, int pin_type,
2404 int dac_idx)
2405{
2406 /* set as output */
2407 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2408 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2409 switch (nid) {
2410 case 0x11: /* port-A - DAC 04 */
2411 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2412 break;
2413 case 0x14: /* port-B - DAC 06 */
2414 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2415 break;
2416 case 0x15: /* port-C - DAC 05 */
2417 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2418 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002419 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002420 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2421 break;
2422 case 0x13: /* mono - DAC 04 */
2423 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2424 break;
2425 }
2426}
2427
2428static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2429{
2430 struct ad198x_spec *spec = codec->spec;
2431 int i;
2432
2433 for (i = 0; i < spec->autocfg.line_outs; i++) {
2434 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2435 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2436 }
2437}
2438
2439static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2440{
2441 struct ad198x_spec *spec = codec->spec;
2442 hda_nid_t pin;
2443
Takashi Iwai82bc9552006-03-21 11:24:42 +01002444 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002445 if (pin) /* connect to front */
2446 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002447 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002448 if (pin) /* connect to front */
2449 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2450}
2451
2452static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2453{
2454 struct ad198x_spec *spec = codec->spec;
2455 int i, idx;
2456
2457 for (i = 0; i < AUTO_PIN_LAST; i++) {
2458 hda_nid_t nid = spec->autocfg.input_pins[i];
2459 if (! nid)
2460 continue;
2461 switch (nid) {
2462 case 0x15: /* port-C */
2463 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2464 break;
2465 case 0x17: /* port-E */
2466 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2467 break;
2468 }
2469 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2470 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2471 if (nid != AD1988_PIN_CD_NID)
2472 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2473 AMP_OUT_MUTE);
2474 idx = ad1988_pin_idx(nid);
2475 if (ad1988_boost_nids[idx])
2476 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2477 AC_VERB_SET_AMP_GAIN_MUTE,
2478 AMP_OUT_ZERO);
2479 }
2480}
2481
2482/* parse the BIOS configuration and set up the alc_spec */
2483/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2484static int ad1988_parse_auto_config(struct hda_codec *codec)
2485{
2486 struct ad198x_spec *spec = codec->spec;
2487 int err;
2488
Kailang Yangdf694da2005-12-05 19:42:22 +01002489 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002490 return err;
2491 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2492 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002493 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002494 return 0; /* can't find valid BIOS pin config */
2495 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002496 (err = ad1988_auto_create_extra_out(codec,
2497 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002498 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002499 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002500 "Headphone")) < 0 ||
2501 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2502 return err;
2503
2504 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2505
2506 if (spec->autocfg.dig_out_pin)
2507 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2508 if (spec->autocfg.dig_in_pin)
2509 spec->dig_in_nid = AD1988_SPDIF_IN;
2510
2511 if (spec->kctl_alloc)
2512 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2513
2514 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2515
2516 spec->input_mux = &spec->private_imux;
2517
2518 return 1;
2519}
2520
2521/* init callback for auto-configuration model -- overriding the default init */
2522static int ad1988_auto_init(struct hda_codec *codec)
2523{
2524 ad198x_init(codec);
2525 ad1988_auto_init_multi_out(codec);
2526 ad1988_auto_init_extra_out(codec);
2527 ad1988_auto_init_analog_input(codec);
2528 return 0;
2529}
2530
2531
2532/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002533 */
2534
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002535static const char *ad1988_models[AD1988_MODEL_LAST] = {
2536 [AD1988_6STACK] = "6stack",
2537 [AD1988_6STACK_DIG] = "6stack-dig",
2538 [AD1988_3STACK] = "3stack",
2539 [AD1988_3STACK_DIG] = "3stack-dig",
2540 [AD1988_LAPTOP] = "laptop",
2541 [AD1988_LAPTOP_DIG] = "laptop-dig",
2542 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002543};
2544
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002545static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2546 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Tobin Davis18768992007-03-12 22:20:51 +01002547 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002548 {}
2549};
2550
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002551static int patch_ad1988(struct hda_codec *codec)
2552{
2553 struct ad198x_spec *spec;
2554 int board_config;
2555
2556 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2557 if (spec == NULL)
2558 return -ENOMEM;
2559
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002560 codec->spec = spec;
2561
Takashi Iwai1a806f42006-07-03 15:58:16 +02002562 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002563 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2564
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002565 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002566 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002567 if (board_config < 0) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002568 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2569 board_config = AD1988_AUTO;
2570 }
2571
2572 if (board_config == AD1988_AUTO) {
2573 /* automatic parse from the BIOS config */
2574 int err = ad1988_parse_auto_config(codec);
2575 if (err < 0) {
2576 ad198x_free(codec);
2577 return err;
2578 } else if (! err) {
2579 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2580 board_config = AD1988_6STACK;
2581 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002582 }
2583
2584 switch (board_config) {
2585 case AD1988_6STACK:
2586 case AD1988_6STACK_DIG:
2587 spec->multiout.max_channels = 8;
2588 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002589 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002590 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2591 else
2592 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002593 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002594 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002595 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002596 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2597 else
2598 spec->mixers[0] = ad1988_6stack_mixers1;
2599 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002600 spec->num_init_verbs = 1;
2601 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2602 if (board_config == AD1988_6STACK_DIG) {
2603 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2604 spec->dig_in_nid = AD1988_SPDIF_IN;
2605 }
2606 break;
2607 case AD1988_3STACK:
2608 case AD1988_3STACK_DIG:
2609 spec->multiout.max_channels = 6;
2610 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002611 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002612 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2613 else
2614 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002615 spec->input_mux = &ad1988_6stack_capture_source;
2616 spec->channel_mode = ad1988_3stack_modes;
2617 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002618 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002619 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002620 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2621 else
2622 spec->mixers[0] = ad1988_3stack_mixers1;
2623 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002624 spec->num_init_verbs = 1;
2625 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2626 if (board_config == AD1988_3STACK_DIG)
2627 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2628 break;
2629 case AD1988_LAPTOP:
2630 case AD1988_LAPTOP_DIG:
2631 spec->multiout.max_channels = 2;
2632 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002633 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002634 spec->input_mux = &ad1988_laptop_capture_source;
2635 spec->num_mixers = 1;
2636 spec->mixers[0] = ad1988_laptop_mixers;
2637 spec->num_init_verbs = 1;
2638 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2639 if (board_config == AD1988_LAPTOP_DIG)
2640 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2641 break;
2642 }
2643
Takashi Iwaid32410b12005-11-24 16:06:23 +01002644 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2645 spec->adc_nids = ad1988_adc_nids;
2646 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002647 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2648 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2649 if (spec->multiout.dig_out_nid) {
2650 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2651 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2652 }
2653 if (spec->dig_in_nid)
2654 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2655
2656 codec->patch_ops = ad198x_patch_ops;
2657 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002658 case AD1988_AUTO:
2659 codec->patch_ops.init = ad1988_auto_init;
2660 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002661 case AD1988_LAPTOP:
2662 case AD1988_LAPTOP_DIG:
2663 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2664 break;
2665 }
2666
2667 return 0;
2668}
2669
2670
2671/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02002672 * AD1884 / AD1984
2673 *
2674 * port-B - front line/mic-in
2675 * port-E - aux in/out
2676 * port-F - aux in/out
2677 * port-C - rear line/mic-in
2678 * port-D - rear line/hp-out
2679 * port-A - front line/hp-out
2680 *
2681 * AD1984 = AD1884 + two digital mic-ins
2682 *
2683 * FIXME:
2684 * For simplicity, we share the single DAC for both HP and line-outs
2685 * right now. The inidividual playbacks could be easily implemented,
2686 * but no build-up framework is given, so far.
2687 */
2688
2689static hda_nid_t ad1884_dac_nids[1] = {
2690 0x04,
2691};
2692
2693static hda_nid_t ad1884_adc_nids[2] = {
2694 0x08, 0x09,
2695};
2696
2697static hda_nid_t ad1884_capsrc_nids[2] = {
2698 0x0c, 0x0d,
2699};
2700
2701#define AD1884_SPDIF_OUT 0x02
2702
2703static struct hda_input_mux ad1884_capture_source = {
2704 .num_items = 4,
2705 .items = {
2706 { "Front Mic", 0x0 },
2707 { "Mic", 0x1 },
2708 { "CD", 0x2 },
2709 { "Mix", 0x3 },
2710 },
2711};
2712
2713static struct snd_kcontrol_new ad1884_base_mixers[] = {
2714 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2715 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2716 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2717 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2718 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2719 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
2720 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2721 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2722 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2723 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2724 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
2725 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
2726 /*
2727 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
2728 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
2729 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2730 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2731 */
2732 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
2733 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
2734 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2735 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2736 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2737 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2738 {
2739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2740 /* The multiple "Capture Source" controls confuse alsamixer
2741 * So call somewhat different..
2742 * FIXME: the controls appear in the "playback" view!
2743 */
2744 /* .name = "Capture Source", */
2745 .name = "Input Source",
2746 .count = 2,
2747 .info = ad198x_mux_enum_info,
2748 .get = ad198x_mux_enum_get,
2749 .put = ad198x_mux_enum_put,
2750 },
2751 /* SPDIF controls */
2752 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2753 {
2754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2755 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
2756 /* identical with ad1983 */
2757 .info = ad1983_spdif_route_info,
2758 .get = ad1983_spdif_route_get,
2759 .put = ad1983_spdif_route_put,
2760 },
2761 { } /* end */
2762};
2763
2764static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
2765 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
2766 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
2767 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02002768 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002769 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02002770 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002771 { } /* end */
2772};
2773
2774/*
2775 * initialization verbs
2776 */
2777static struct hda_verb ad1884_init_verbs[] = {
2778 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02002779 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2780 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02002781 /* Port-A (HP) mixer */
2782 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2783 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2784 /* Port-A pin */
2785 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2786 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2787 /* HP selector - select DAC2 */
2788 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
2789 /* Port-D (Line-out) mixer */
2790 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2791 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2792 /* Port-D pin */
2793 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2794 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2795 /* Mono-out mixer */
2796 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2797 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
2798 /* Mono-out pin */
2799 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2800 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2801 /* Mono selector */
2802 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2803 /* Port-B (front mic) pin */
2804 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2805 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2806 /* Port-C (rear mic) pin */
2807 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2808 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2809 /* Analog mixer; mute as default */
2810 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2811 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2812 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2813 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2814 /* Analog Mix output amp */
2815 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2816 /* SPDIF output selector */
2817 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2818 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2819 { } /* end */
2820};
2821
2822static int patch_ad1884(struct hda_codec *codec)
2823{
2824 struct ad198x_spec *spec;
2825
2826 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2827 if (spec == NULL)
2828 return -ENOMEM;
2829
2830 mutex_init(&spec->amp_mutex);
2831 codec->spec = spec;
2832
2833 spec->multiout.max_channels = 2;
2834 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
2835 spec->multiout.dac_nids = ad1884_dac_nids;
2836 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
2837 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
2838 spec->adc_nids = ad1884_adc_nids;
2839 spec->capsrc_nids = ad1884_capsrc_nids;
2840 spec->input_mux = &ad1884_capture_source;
2841 spec->num_mixers = 1;
2842 spec->mixers[0] = ad1884_base_mixers;
2843 spec->num_init_verbs = 1;
2844 spec->init_verbs[0] = ad1884_init_verbs;
2845 spec->spdif_route = 0;
2846
2847 codec->patch_ops = ad198x_patch_ops;
2848
2849 return 0;
2850}
2851
2852/*
2853 * Lenovo Thinkpad T61/X61
2854 */
2855static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwai3b194402007-06-04 18:32:23 +02002856 .num_items = 3,
Takashi Iwai2bac6472007-05-18 18:21:41 +02002857 .items = {
2858 { "Mic", 0x0 },
2859 { "Internal Mic", 0x1 },
2860 { "Mix", 0x3 },
2861 },
2862};
2863
2864static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
2865 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2866 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
2867 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
2868 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
2869 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
2870 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
2871 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
2872 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
2873 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
2874 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002875 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
2876 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02002877 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaib959d1f2007-06-08 12:25:25 +02002878 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
2879 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02002880 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2881 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2882 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2883 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2884 {
2885 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2886 /* The multiple "Capture Source" controls confuse alsamixer
2887 * So call somewhat different..
2888 * FIXME: the controls appear in the "playback" view!
2889 */
2890 /* .name = "Capture Source", */
2891 .name = "Input Source",
2892 .count = 2,
2893 .info = ad198x_mux_enum_info,
2894 .get = ad198x_mux_enum_get,
2895 .put = ad198x_mux_enum_put,
2896 },
2897 { } /* end */
2898};
2899
2900/* additional verbs */
2901static struct hda_verb ad1984_thinkpad_init_verbs[] = {
2902 /* Port-E (docking station mic) pin */
2903 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2904 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2905 /* docking mic boost */
2906 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2907 /* Analog mixer - docking mic; mute as default */
2908 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02002909 /* enable EAPD bit */
2910 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02002911 { } /* end */
2912};
2913
2914/* Digial MIC ADC NID 0x05 + 0x06 */
2915static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
2916 struct hda_codec *codec,
2917 unsigned int stream_tag,
2918 unsigned int format,
2919 struct snd_pcm_substream *substream)
2920{
2921 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
2922 stream_tag, 0, format);
2923 return 0;
2924}
2925
2926static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
2927 struct hda_codec *codec,
2928 struct snd_pcm_substream *substream)
2929{
2930 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
2931 0, 0, 0);
2932 return 0;
2933}
2934
2935static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
2936 .substreams = 2,
2937 .channels_min = 2,
2938 .channels_max = 2,
2939 .nid = 0x05,
2940 .ops = {
2941 .prepare = ad1984_pcm_dmic_prepare,
2942 .cleanup = ad1984_pcm_dmic_cleanup
2943 },
2944};
2945
2946static int ad1984_build_pcms(struct hda_codec *codec)
2947{
2948 struct ad198x_spec *spec = codec->spec;
2949 struct hda_pcm *info;
2950 int err;
2951
2952 err = ad198x_build_pcms(codec);
2953 if (err < 0)
2954 return err;
2955
2956 info = spec->pcm_rec + codec->num_pcms;
2957 codec->num_pcms++;
2958 info->name = "AD1984 Digital Mic";
2959 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
2960 return 0;
2961}
2962
2963/* models */
2964enum {
2965 AD1984_BASIC,
2966 AD1984_THINKPAD,
2967 AD1984_MODELS
2968};
2969
2970static const char *ad1984_models[AD1984_MODELS] = {
2971 [AD1984_BASIC] = "basic",
2972 [AD1984_THINKPAD] = "thinkpad",
2973};
2974
2975static struct snd_pci_quirk ad1984_cfg_tbl[] = {
2976 /* Lenovo Thinkpad T61/X61 */
2977 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
2978 {}
2979};
2980
2981static int patch_ad1984(struct hda_codec *codec)
2982{
2983 struct ad198x_spec *spec;
2984 int board_config, err;
2985
2986 err = patch_ad1884(codec);
2987 if (err < 0)
2988 return err;
2989 spec = codec->spec;
2990 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
2991 ad1984_models, ad1984_cfg_tbl);
2992 switch (board_config) {
2993 case AD1984_BASIC:
2994 /* additional digital mics */
2995 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
2996 codec->patch_ops.build_pcms = ad1984_build_pcms;
2997 break;
2998 case AD1984_THINKPAD:
2999 spec->multiout.dig_out_nid = 0;
3000 spec->input_mux = &ad1984_thinkpad_capture_source;
3001 spec->mixers[0] = ad1984_thinkpad_mixers;
3002 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3003 break;
3004 }
3005 return 0;
3006}
3007
3008
3009/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02003010 * AD1882
3011 *
3012 * port-A - front hp-out
3013 * port-B - front mic-in
3014 * port-C - rear line-in, shared surr-out (3stack)
3015 * port-D - rear line-out
3016 * port-E - rear mic-in, shared clfe-out (3stack)
3017 * port-F - rear surr-out (6stack)
3018 * port-G - rear clfe-out (6stack)
3019 */
3020
3021static hda_nid_t ad1882_dac_nids[3] = {
3022 0x04, 0x03, 0x05
3023};
3024
3025static hda_nid_t ad1882_adc_nids[2] = {
3026 0x08, 0x09,
3027};
3028
3029static hda_nid_t ad1882_capsrc_nids[2] = {
3030 0x0c, 0x0d,
3031};
3032
3033#define AD1882_SPDIF_OUT 0x02
3034
3035/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3036static struct hda_input_mux ad1882_capture_source = {
3037 .num_items = 5,
3038 .items = {
3039 { "Front Mic", 0x1 },
3040 { "Mic", 0x4 },
3041 { "Line", 0x2 },
3042 { "CD", 0x3 },
3043 { "Mix", 0x7 },
3044 },
3045};
3046
3047static struct snd_kcontrol_new ad1882_base_mixers[] = {
3048 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3049 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3050 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3051 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3052 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3053 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3054 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3055 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3056 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3057 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3058 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3059 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3060 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3061 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3062 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3063 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3064 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3065 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3066 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3067 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3068 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3069 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3070 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3071 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3072 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3073 {
3074 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3075 /* The multiple "Capture Source" controls confuse alsamixer
3076 * So call somewhat different..
3077 * FIXME: the controls appear in the "playback" view!
3078 */
3079 /* .name = "Capture Source", */
3080 .name = "Input Source",
3081 .count = 2,
3082 .info = ad198x_mux_enum_info,
3083 .get = ad198x_mux_enum_get,
3084 .put = ad198x_mux_enum_put,
3085 },
3086 /* SPDIF controls */
3087 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3088 {
3089 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3090 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3091 /* identical with ad1983 */
3092 .info = ad1983_spdif_route_info,
3093 .get = ad1983_spdif_route_get,
3094 .put = ad1983_spdif_route_put,
3095 },
3096 { } /* end */
3097};
3098
3099static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3100 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3101 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3102 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3103 {
3104 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3105 .name = "Channel Mode",
3106 .info = ad198x_ch_mode_info,
3107 .get = ad198x_ch_mode_get,
3108 .put = ad198x_ch_mode_put,
3109 },
3110 { } /* end */
3111};
3112
3113static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
3114 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
3115 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
3116 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
3117 { } /* end */
3118};
3119
3120static struct hda_verb ad1882_ch2_init[] = {
3121 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3122 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3123 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3124 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3125 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3126 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3127 { } /* end */
3128};
3129
3130static struct hda_verb ad1882_ch4_init[] = {
3131 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3132 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3133 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3134 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3135 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3136 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3137 { } /* end */
3138};
3139
3140static struct hda_verb ad1882_ch6_init[] = {
3141 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3142 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3143 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3144 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3145 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3146 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3147 { } /* end */
3148};
3149
3150static struct hda_channel_mode ad1882_modes[3] = {
3151 { 2, ad1882_ch2_init },
3152 { 4, ad1882_ch4_init },
3153 { 6, ad1882_ch6_init },
3154};
3155
3156/*
3157 * initialization verbs
3158 */
3159static struct hda_verb ad1882_init_verbs[] = {
3160 /* DACs; mute as default */
3161 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3162 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3163 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3164 /* Port-A (HP) mixer */
3165 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3166 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3167 /* Port-A pin */
3168 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3169 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3170 /* HP selector - select DAC2 */
3171 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
3172 /* Port-D (Line-out) mixer */
3173 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3174 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3175 /* Port-D pin */
3176 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3177 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3178 /* Mono-out mixer */
3179 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3180 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3181 /* Mono-out pin */
3182 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3183 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3184 /* Port-B (front mic) pin */
3185 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3186 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3187 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3188 /* Port-C (line-in) pin */
3189 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3190 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3191 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3192 /* Port-C mixer - mute as input */
3193 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3194 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3195 /* Port-E (mic-in) pin */
3196 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3197 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3198 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
3199 /* Port-E mixer - mute as input */
3200 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3201 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3202 /* Port-F (surround) */
3203 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3204 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3205 /* Port-G (CLFE) */
3206 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3207 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3208 /* Analog mixer; mute as default */
3209 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
3210 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3211 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3212 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3213 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3214 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3215 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3216 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
3217 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
3218 /* Analog Mix output amp */
3219 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3220 /* SPDIF output selector */
3221 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3222 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3223 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3224 { } /* end */
3225};
3226
3227/* models */
3228enum {
3229 AD1882_3STACK,
3230 AD1882_6STACK,
3231 AD1882_MODELS
3232};
3233
3234static const char *ad1882_models[AD1986A_MODELS] = {
3235 [AD1882_3STACK] = "3stack",
3236 [AD1882_6STACK] = "6stack",
3237};
3238
3239
3240static int patch_ad1882(struct hda_codec *codec)
3241{
3242 struct ad198x_spec *spec;
3243 int board_config;
3244
3245 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3246 if (spec == NULL)
3247 return -ENOMEM;
3248
3249 mutex_init(&spec->amp_mutex);
3250 codec->spec = spec;
3251
3252 spec->multiout.max_channels = 6;
3253 spec->multiout.num_dacs = 3;
3254 spec->multiout.dac_nids = ad1882_dac_nids;
3255 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
3256 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
3257 spec->adc_nids = ad1882_adc_nids;
3258 spec->capsrc_nids = ad1882_capsrc_nids;
3259 spec->input_mux = &ad1882_capture_source;
3260 spec->num_mixers = 1;
3261 spec->mixers[0] = ad1882_base_mixers;
3262 spec->num_init_verbs = 1;
3263 spec->init_verbs[0] = ad1882_init_verbs;
3264 spec->spdif_route = 0;
3265
3266 codec->patch_ops = ad198x_patch_ops;
3267
3268 /* override some parameters */
3269 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
3270 ad1882_models, NULL);
3271 switch (board_config) {
3272 default:
3273 case AD1882_3STACK:
3274 spec->num_mixers = 2;
3275 spec->mixers[1] = ad1882_3stack_mixers;
3276 spec->channel_mode = ad1882_modes;
3277 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
3278 spec->need_dac_fix = 1;
3279 spec->multiout.max_channels = 2;
3280 spec->multiout.num_dacs = 1;
3281 break;
3282 case AD1882_6STACK:
3283 spec->num_mixers = 2;
3284 spec->mixers[1] = ad1882_6stack_mixers;
3285 break;
3286 }
3287 return 0;
3288}
3289
3290
3291/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 * patch entries
3293 */
3294struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai0ac85512007-06-20 15:46:13 +02003295 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003296 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02003297 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3298 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003299 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003301 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02003302 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 {} /* terminator */
3304};