blob: e6d1bdff1b6e56f53778ace479d682eaf385d915 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/slab.h>
25#include <linux/pci.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/core.h>
28#include "hda_codec.h"
29#include "hda_local.h"
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010030#include "hda_beep.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020032struct ad198x_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010033 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010034 int num_mixers;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +010035 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Takashi Iwaid32410b12005-11-24 16:06:23 +010036 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010037 * don't forget NULL termination!
38 */
39 unsigned int num_init_verbs;
40
41 /* playback */
42 struct hda_multi_out multiout; /* playback set-up
43 * max_channels, dacs must be set
44 * dig_out_nid and hp_nid are optional
45 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010046 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020047 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010048
49 /* capture */
50 unsigned int num_adc_nids;
51 hda_nid_t *adc_nids;
52 hda_nid_t dig_in_nid; /* digital-in NID; optional */
53
54 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020055 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010056 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010057 unsigned int cur_mux[3];
58
59 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010060 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010061 int num_channel_mode;
62
63 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020064 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010065
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020066 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010067
68 /* dynamic controls, init_verbs and input_mux */
69 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +020070 struct snd_array kctls;
Takashi Iwaid32410b12005-11-24 16:06:23 +010071 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020072 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +020073
Takashi Iwai8ab78c72007-09-06 14:29:53 +020074 unsigned int jack_present :1;
Takashi Iwaiee6e3652009-12-08 17:23:33 +010075 unsigned int inv_jack_detect:1; /* inverted jack-detection */
76 unsigned int inv_eapd:1; /* inverted EAPD implementation */
Takashi Iwai8ab78c72007-09-06 14:29:53 +020077
Takashi Iwaicb53c622007-08-10 17:21:45 +020078#ifdef CONFIG_SND_HDA_POWER_SAVE
79 struct hda_loopback_check loopback;
80#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +010081 /* for virtual master */
82 hda_nid_t vmaster_nid;
Takashi Iwai2134ea42008-01-10 16:53:55 +010083 const char **slave_vols;
84 const char **slave_sws;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020087/*
88 * input MUX handling (common part)
89 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010090static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020091{
92 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
93 struct ad198x_spec *spec = codec->spec;
94
95 return snd_hda_input_mux_info(spec->input_mux, uinfo);
96}
97
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +010098static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020099{
100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
101 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100102 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200103
Takashi Iwai985be542005-11-02 18:26:49 +0100104 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200105 return 0;
106}
107
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100108static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200109{
110 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
111 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100112 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200113
114 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100115 spec->capsrc_nids[adc_idx],
116 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200117}
118
119/*
120 * initialization (common callbacks)
121 */
122static int ad198x_init(struct hda_codec *codec)
123{
124 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100125 int i;
126
127 for (i = 0; i < spec->num_init_verbs; i++)
128 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200129 return 0;
130}
131
Takashi Iwai2134ea42008-01-10 16:53:55 +0100132static const char *ad_slave_vols[] = {
133 "Front Playback Volume",
134 "Surround Playback Volume",
135 "Center Playback Volume",
136 "LFE Playback Volume",
137 "Side Playback Volume",
138 "Headphone Playback Volume",
139 "Mono Playback Volume",
Takashi Iwai628ed132008-01-25 11:56:57 +0100140 "Speaker Playback Volume",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100141 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100142 NULL
143};
144
145static const char *ad_slave_sws[] = {
146 "Front Playback Switch",
147 "Surround Playback Switch",
148 "Center Playback Switch",
149 "LFE Playback Switch",
150 "Side Playback Switch",
151 "Headphone Playback Switch",
152 "Mono Playback Switch",
Takashi Iwai628ed132008-01-25 11:56:57 +0100153 "Speaker Playback Switch",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100154 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100155 NULL
156};
157
Takashi Iwai603c4012008-07-30 15:01:44 +0200158static void ad198x_free_kctls(struct hda_codec *codec);
159
Takashi Iwai67d634c2009-11-16 15:35:59 +0100160#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100161/* additional beep mixers; the actual parameters are overwritten at build */
162static struct snd_kcontrol_new ad_beep_mixer[] = {
163 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +0200164 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100165 { } /* end */
166};
167
168#define set_beep_amp(spec, nid, idx, dir) \
169 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100170#else
171#define set_beep_amp(spec, nid, idx, dir) /* NOP */
172#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100173
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200174static int ad198x_build_controls(struct hda_codec *codec)
175{
176 struct ad198x_spec *spec = codec->spec;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100177 struct snd_kcontrol *kctl;
Takashi Iwai985be542005-11-02 18:26:49 +0100178 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200179 int err;
180
Takashi Iwai985be542005-11-02 18:26:49 +0100181 for (i = 0; i < spec->num_mixers; i++) {
182 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
183 if (err < 0)
184 return err;
185 }
186 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200187 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100188 if (err < 0)
189 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100190 err = snd_hda_create_spdif_share_sw(codec,
191 &spec->multiout);
192 if (err < 0)
193 return err;
194 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100195 }
196 if (spec->dig_in_nid) {
197 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
198 if (err < 0)
199 return err;
200 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100201
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100202 /* create beep controls if needed */
Takashi Iwai67d634c2009-11-16 15:35:59 +0100203#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100204 if (spec->beep_amp) {
205 struct snd_kcontrol_new *knew;
206 for (knew = ad_beep_mixer; knew->name; knew++) {
207 struct snd_kcontrol *kctl;
208 kctl = snd_ctl_new1(knew, codec);
209 if (!kctl)
210 return -ENOMEM;
211 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100212 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100213 if (err < 0)
214 return err;
215 }
216 }
Takashi Iwai67d634c2009-11-16 15:35:59 +0100217#endif
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100218
Takashi Iwai2134ea42008-01-10 16:53:55 +0100219 /* if we have no master control, let's create it */
220 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100221 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100222 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100223 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100224 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100225 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100226 (spec->slave_vols ?
227 spec->slave_vols : ad_slave_vols));
228 if (err < 0)
229 return err;
230 }
231 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
232 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
233 NULL,
234 (spec->slave_sws ?
235 spec->slave_sws : ad_slave_sws));
236 if (err < 0)
237 return err;
238 }
239
Takashi Iwai603c4012008-07-30 15:01:44 +0200240 ad198x_free_kctls(codec); /* no longer needed */
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100241
242 /* assign Capture Source enums to NID */
243 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
244 if (!kctl)
245 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
246 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai21949f02009-12-23 08:31:59 +0100247 err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100248 if (err < 0)
249 return err;
250 }
251
252 /* assign IEC958 enums to NID */
253 kctl = snd_hda_find_mixer_ctl(codec,
254 SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
255 if (kctl) {
256 err = snd_hda_add_nid(codec, kctl, 0,
257 spec->multiout.dig_out_nid);
258 if (err < 0)
259 return err;
260 }
261
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200262 return 0;
263}
264
Takashi Iwaicb53c622007-08-10 17:21:45 +0200265#ifdef CONFIG_SND_HDA_POWER_SAVE
266static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
267{
268 struct ad198x_spec *spec = codec->spec;
269 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
270}
271#endif
272
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200273/*
274 * Analog playback callbacks
275 */
276static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
277 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100278 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200279{
280 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100281 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
282 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200283}
284
285static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
286 struct hda_codec *codec,
287 unsigned int stream_tag,
288 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100289 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200290{
291 struct ad198x_spec *spec = codec->spec;
292 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
293 format, substream);
294}
295
296static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
297 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100298 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200299{
300 struct ad198x_spec *spec = codec->spec;
301 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
302}
303
304/*
305 * Digital out
306 */
307static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
308 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100309 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200310{
311 struct ad198x_spec *spec = codec->spec;
312 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
313}
314
315static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
316 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100317 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200318{
319 struct ad198x_spec *spec = codec->spec;
320 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
321}
322
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200323static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
324 struct hda_codec *codec,
325 unsigned int stream_tag,
326 unsigned int format,
327 struct snd_pcm_substream *substream)
328{
329 struct ad198x_spec *spec = codec->spec;
330 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
331 format, substream);
332}
333
Takashi Iwai9411e212009-02-13 11:32:28 +0100334static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
335 struct hda_codec *codec,
336 struct snd_pcm_substream *substream)
337{
338 struct ad198x_spec *spec = codec->spec;
339 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
340}
341
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200342/*
343 * Analog capture
344 */
345static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
346 struct hda_codec *codec,
347 unsigned int stream_tag,
348 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100349 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200350{
351 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100352 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
353 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200354 return 0;
355}
356
357static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
358 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100359 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200360{
361 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100362 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200363 return 0;
364}
365
366
367/*
368 */
369static struct hda_pcm_stream ad198x_pcm_analog_playback = {
370 .substreams = 1,
371 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100372 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200373 .nid = 0, /* fill later */
374 .ops = {
375 .open = ad198x_playback_pcm_open,
376 .prepare = ad198x_playback_pcm_prepare,
377 .cleanup = ad198x_playback_pcm_cleanup
378 },
379};
380
381static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100382 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200383 .channels_min = 2,
384 .channels_max = 2,
385 .nid = 0, /* fill later */
386 .ops = {
387 .prepare = ad198x_capture_pcm_prepare,
388 .cleanup = ad198x_capture_pcm_cleanup
389 },
390};
391
392static struct hda_pcm_stream ad198x_pcm_digital_playback = {
393 .substreams = 1,
394 .channels_min = 2,
395 .channels_max = 2,
396 .nid = 0, /* fill later */
397 .ops = {
398 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200399 .close = ad198x_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +0100400 .prepare = ad198x_dig_playback_pcm_prepare,
401 .cleanup = ad198x_dig_playback_pcm_cleanup
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200402 },
403};
404
Takashi Iwai985be542005-11-02 18:26:49 +0100405static struct hda_pcm_stream ad198x_pcm_digital_capture = {
406 .substreams = 1,
407 .channels_min = 2,
408 .channels_max = 2,
409 /* NID is set in alc_build_pcms */
410};
411
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200412static int ad198x_build_pcms(struct hda_codec *codec)
413{
414 struct ad198x_spec *spec = codec->spec;
415 struct hda_pcm *info = spec->pcm_rec;
416
417 codec->num_pcms = 1;
418 codec->pcm_info = info;
419
420 info->name = "AD198x Analog";
421 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
422 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
423 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
424 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100425 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
426 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200427
428 if (spec->multiout.dig_out_nid) {
429 info++;
430 codec->num_pcms++;
431 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100432 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200433 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
434 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100435 if (spec->dig_in_nid) {
436 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
437 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
438 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200439 }
440
441 return 0;
442}
443
Daniel T Chenea52bf22009-12-27 18:48:29 -0500444static inline void ad198x_shutup(struct hda_codec *codec)
445{
446 snd_hda_shutup_pins(codec);
447}
448
Takashi Iwai603c4012008-07-30 15:01:44 +0200449static void ad198x_free_kctls(struct hda_codec *codec)
450{
451 struct ad198x_spec *spec = codec->spec;
452
453 if (spec->kctls.list) {
454 struct snd_kcontrol_new *kctl = spec->kctls.list;
455 int i;
456 for (i = 0; i < spec->kctls.used; i++)
457 kfree(kctl[i].name);
458 }
459 snd_array_free(&spec->kctls);
460}
461
Daniel T Chenea52bf22009-12-27 18:48:29 -0500462static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
463 hda_nid_t hp)
464{
465 struct ad198x_spec *spec = codec->spec;
466 snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
467 !spec->inv_eapd ? 0x00 : 0x02);
468 snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
469 !spec->inv_eapd ? 0x00 : 0x02);
470}
471
472static void ad198x_power_eapd(struct hda_codec *codec)
473{
474 /* We currently only handle front, HP */
475 switch (codec->vendor_id) {
476 case 0x11d41882:
477 case 0x11d4882a:
478 case 0x11d41884:
479 case 0x11d41984:
480 case 0x11d41883:
481 case 0x11d4184a:
482 case 0x11d4194a:
483 case 0x11d4194b:
484 ad198x_power_eapd_write(codec, 0x12, 0x11);
485 break;
486 case 0x11d41981:
487 case 0x11d41983:
488 ad198x_power_eapd_write(codec, 0x05, 0x06);
489 break;
490 case 0x11d41986:
491 ad198x_power_eapd_write(codec, 0x1b, 0x1a);
492 break;
493 case 0x11d41988:
494 case 0x11d4198b:
495 case 0x11d4989a:
496 case 0x11d4989b:
497 ad198x_power_eapd_write(codec, 0x29, 0x22);
498 break;
499 }
500}
501
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200502static void ad198x_free(struct hda_codec *codec)
503{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100504 struct ad198x_spec *spec = codec->spec;
Takashi Iwaid32410b12005-11-24 16:06:23 +0100505
Takashi Iwai603c4012008-07-30 15:01:44 +0200506 if (!spec)
507 return;
508
Daniel T Chenea52bf22009-12-27 18:48:29 -0500509 ad198x_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +0200510 ad198x_free_kctls(codec);
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100511 kfree(spec);
512 snd_hda_detach_beep_device(codec);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200513}
514
Daniel T Chenea52bf22009-12-27 18:48:29 -0500515#ifdef SND_HDA_NEEDS_RESUME
516static int ad198x_suspend(struct hda_codec *codec, pm_message_t state)
517{
518 ad198x_shutup(codec);
519 ad198x_power_eapd(codec);
520 return 0;
521}
522
523static int ad198x_resume(struct hda_codec *codec)
524{
525 ad198x_init(codec);
526 snd_hda_codec_resume_amp(codec);
527 snd_hda_codec_resume_cache(codec);
528 return 0;
529}
530#endif
531
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200532static struct hda_codec_ops ad198x_patch_ops = {
533 .build_controls = ad198x_build_controls,
534 .build_pcms = ad198x_build_pcms,
535 .init = ad198x_init,
536 .free = ad198x_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200537#ifdef CONFIG_SND_HDA_POWER_SAVE
538 .check_power_status = ad198x_check_power_status,
539#endif
Daniel T Chenea52bf22009-12-27 18:48:29 -0500540#ifdef SND_HDA_NEEDS_RESUME
541 .suspend = ad198x_suspend,
542 .resume = ad198x_resume,
543#endif
544 .reboot_notify = ad198x_shutup,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200545};
546
547
548/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100549 * EAPD control
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100550 * the private value = nid
Takashi Iwai18a815d2006-03-01 19:54:39 +0100551 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200552#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100553
554static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
555 struct snd_ctl_elem_value *ucontrol)
556{
557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
558 struct ad198x_spec *spec = codec->spec;
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100559 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100560 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
561 else
562 ucontrol->value.integer.value[0] = spec->cur_eapd;
563 return 0;
564}
565
566static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
568{
569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
570 struct ad198x_spec *spec = codec->spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +0100571 hda_nid_t nid = kcontrol->private_value & 0xff;
572 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100573 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100574 if (spec->inv_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100575 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200576 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100577 return 0;
578 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200579 snd_hda_codec_write_cache(codec, nid,
580 0, AC_VERB_SET_EAPD_BTLENABLE,
581 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100582 return 1;
583}
584
Takashi Iwai9230d212006-03-13 13:49:49 +0100585static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
586 struct snd_ctl_elem_info *uinfo);
587static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
588 struct snd_ctl_elem_value *ucontrol);
589static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
590 struct snd_ctl_elem_value *ucontrol);
591
592
Takashi Iwai18a815d2006-03-01 19:54:39 +0100593/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200594 * AD1986A specific
595 */
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#define AD1986A_SPDIF_OUT 0x02
598#define AD1986A_FRONT_DAC 0x03
599#define AD1986A_SURR_DAC 0x04
600#define AD1986A_CLFE_DAC 0x05
601#define AD1986A_ADC 0x06
602
603static hda_nid_t ad1986a_dac_nids[3] = {
604 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
605};
Takashi Iwai985be542005-11-02 18:26:49 +0100606static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100607static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609static struct hda_input_mux ad1986a_capture_source = {
610 .num_items = 7,
611 .items = {
612 { "Mic", 0x0 },
613 { "CD", 0x1 },
614 { "Aux", 0x3 },
615 { "Line", 0x4 },
616 { "Mix", 0x5 },
617 { "Mono", 0x6 },
618 { "Phone", 0x7 },
619 },
620};
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Takashi Iwai532d5382007-07-27 19:02:40 +0200623static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
624 .ops = &snd_hda_bind_vol,
625 .values = {
626 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
627 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
628 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
629 0
630 },
631};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Takashi Iwai532d5382007-07-27 19:02:40 +0200633static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
634 .ops = &snd_hda_bind_sw,
635 .values = {
636 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
637 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
638 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
639 0
640 },
641};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 * mixers
645 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100646static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200647 /*
648 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
649 */
650 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
651 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
653 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
654 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
655 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
656 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
657 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
658 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
659 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
660 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
661 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
662 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
663 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
664 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
665 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
666 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
667 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
668 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
669 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100670 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
672 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
673 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
674 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
675 {
676 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
677 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200678 .info = ad198x_mux_enum_info,
679 .get = ad198x_mux_enum_get,
680 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 },
682 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
683 { } /* end */
684};
685
Takashi Iwai9230d212006-03-13 13:49:49 +0100686/* additional mixers for 3stack mode */
687static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
688 {
689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
690 .name = "Channel Mode",
691 .info = ad198x_ch_mode_info,
692 .get = ad198x_ch_mode_get,
693 .put = ad198x_ch_mode_put,
694 },
695 { } /* end */
696};
697
698/* laptop model - 2ch only */
699static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
700
Takashi Iwai20a45e82007-08-15 22:20:45 +0200701/* master controls both pins 0x1a and 0x1b */
702static struct hda_bind_ctls ad1986a_laptop_master_vol = {
703 .ops = &snd_hda_bind_vol,
704 .values = {
705 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
706 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
707 0,
708 },
709};
710
711static struct hda_bind_ctls ad1986a_laptop_master_sw = {
712 .ops = &snd_hda_bind_sw,
713 .values = {
714 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
715 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
716 0,
717 },
718};
719
Takashi Iwai9230d212006-03-13 13:49:49 +0100720static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
721 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
722 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200723 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
724 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100725 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
726 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
727 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
728 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
729 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
730 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
731 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
732 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100733 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +0100734 /*
Takashi Iwai9230d212006-03-13 13:49:49 +0100735 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
736 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
737 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
738 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
739 {
740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
741 .name = "Capture Source",
742 .info = ad198x_mux_enum_info,
743 .get = ad198x_mux_enum_get,
744 .put = ad198x_mux_enum_put,
745 },
746 { } /* end */
747};
748
Takashi Iwai825aa972006-03-17 10:50:49 +0100749/* laptop-eapd model - 2ch only */
750
Takashi Iwai825aa972006-03-17 10:50:49 +0100751static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
752 .num_items = 3,
753 .items = {
754 { "Mic", 0x0 },
755 { "Internal Mic", 0x4 },
756 { "Mix", 0x5 },
757 },
758};
759
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100760static struct hda_input_mux ad1986a_automic_capture_source = {
761 .num_items = 2,
762 .items = {
763 { "Mic", 0x0 },
764 { "Mix", 0x5 },
765 },
766};
767
Takashi Iwai16d11a82009-06-24 14:07:53 +0200768static struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200769 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
770 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai16d11a82009-06-24 14:07:53 +0200771 { } /* end */
772};
773
774static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai825aa972006-03-17 10:50:49 +0100775 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
776 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai1725b822008-11-21 02:25:48 +0100777 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
778 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
779 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
780 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
781 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
782 {
783 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
784 .name = "Capture Source",
785 .info = ad198x_mux_enum_info,
786 .get = ad198x_mux_enum_get,
787 .put = ad198x_mux_enum_put,
788 },
789 {
790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
791 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +0100792 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwai1725b822008-11-21 02:25:48 +0100793 .info = ad198x_eapd_info,
794 .get = ad198x_eapd_get,
795 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +0100796 .private_value = 0x1b, /* port-D */
Takashi Iwai1725b822008-11-21 02:25:48 +0100797 },
798 { } /* end */
799};
800
Takashi Iwai16d11a82009-06-24 14:07:53 +0200801static struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
802 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
803 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
Takashi Iwai825aa972006-03-17 10:50:49 +0100804 { } /* end */
805};
806
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100807/* re-connect the mic boost input according to the jack sensing */
808static void ad1986a_automic(struct hda_codec *codec)
809{
810 unsigned int present;
Takashi Iwaid56757a2009-11-18 08:00:14 +0100811 present = snd_hda_jack_detect(codec, 0x1f);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100812 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
813 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
Takashi Iwaid56757a2009-11-18 08:00:14 +0100814 present ? 0 : 2);
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100815}
816
817#define AD1986A_MIC_EVENT 0x36
818
819static void ad1986a_automic_unsol_event(struct hda_codec *codec,
820 unsigned int res)
821{
822 if ((res >> 26) != AD1986A_MIC_EVENT)
823 return;
824 ad1986a_automic(codec);
825}
826
827static int ad1986a_automic_init(struct hda_codec *codec)
828{
829 ad198x_init(codec);
830 ad1986a_automic(codec);
831 return 0;
832}
833
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200834/* laptop-automute - 2ch only */
835
836static void ad1986a_update_hp(struct hda_codec *codec)
837{
838 struct ad198x_spec *spec = codec->spec;
839 unsigned int mute;
840
841 if (spec->jack_present)
842 mute = HDA_AMP_MUTE; /* mute internal speaker */
843 else
844 /* unmute internal speaker if necessary */
845 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
846 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
847 HDA_AMP_MUTE, mute);
848}
849
850static void ad1986a_hp_automute(struct hda_codec *codec)
851{
852 struct ad198x_spec *spec = codec->spec;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200853
Takashi Iwaid56757a2009-11-18 08:00:14 +0100854 spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
Takashi Iwai03c405a2009-06-24 14:10:15 +0200855 if (spec->inv_jack_detect)
856 spec->jack_present = !spec->jack_present;
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200857 ad1986a_update_hp(codec);
858}
859
860#define AD1986A_HP_EVENT 0x37
861
862static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
863{
864 if ((res >> 26) != AD1986A_HP_EVENT)
865 return;
866 ad1986a_hp_automute(codec);
867}
868
869static int ad1986a_hp_init(struct hda_codec *codec)
870{
871 ad198x_init(codec);
872 ad1986a_hp_automute(codec);
873 return 0;
874}
875
876/* bind hp and internal speaker mute (with plug check) */
877static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
878 struct snd_ctl_elem_value *ucontrol)
879{
880 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
881 long *valp = ucontrol->value.integer.value;
882 int change;
883
884 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
885 HDA_AMP_MUTE,
886 valp[0] ? 0 : HDA_AMP_MUTE);
887 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
888 HDA_AMP_MUTE,
889 valp[1] ? 0 : HDA_AMP_MUTE);
890 if (change)
891 ad1986a_update_hp(codec);
892 return change;
893}
894
Takashi Iwai16d11a82009-06-24 14:07:53 +0200895static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200896 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
897 {
898 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
899 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +0100900 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200901 .info = snd_hda_mixer_amp_switch_info,
902 .get = snd_hda_mixer_amp_switch_get,
903 .put = ad1986a_hp_master_sw_put,
904 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
905 },
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200906 { } /* end */
907};
908
Takashi Iwai16d11a82009-06-24 14:07:53 +0200909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910/*
911 * initialization verbs
912 */
913static struct hda_verb ad1986a_init_verbs[] = {
914 /* Front, Surround, CLFE DAC; mute as default */
915 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
916 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
917 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
918 /* Downmix - off */
919 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
920 /* HP, Line-Out, Surround, CLFE selectors */
921 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
922 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
923 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
924 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
925 /* Mono selector */
926 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
927 /* Mic selector: Mic 1/2 pin */
928 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
929 /* Line-in selector: Line-in */
930 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
931 /* Mic 1/2 swap */
932 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
933 /* Record selector: mic */
934 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
935 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
936 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
937 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
938 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
939 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
940 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
941 /* PC beep */
942 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
943 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
944 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
945 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
946 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
947 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
948 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200949 /* HP Pin */
950 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
951 /* Front, Surround, CLFE Pins */
952 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
953 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
954 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
955 /* Mono Pin */
956 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
957 /* Mic Pin */
958 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
959 /* Line, Aux, CD, Beep-In Pin */
960 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
961 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
962 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
963 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
964 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 { } /* end */
966};
967
Takashi Iwai9230d212006-03-13 13:49:49 +0100968static struct hda_verb ad1986a_ch2_init[] = {
969 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200970 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
971 /* Line-in selectors */
972 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100973 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200974 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
975 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
976 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100977 { } /* end */
978};
979
980static struct hda_verb ad1986a_ch4_init[] = {
981 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200982 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
983 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100984 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200985 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
986 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100987 { } /* end */
988};
989
990static struct hda_verb ad1986a_ch6_init[] = {
991 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200992 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
993 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100994 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200995 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
996 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100997 { } /* end */
998};
999
1000static struct hda_channel_mode ad1986a_modes[3] = {
1001 { 2, ad1986a_ch2_init },
1002 { 4, ad1986a_ch4_init },
1003 { 6, ad1986a_ch6_init },
1004};
1005
Takashi Iwai825aa972006-03-17 10:50:49 +01001006/* eapd initialization */
1007static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +01001008 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa972006-03-17 10:50:49 +01001009 {}
1010};
1011
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001012static struct hda_verb ad1986a_automic_verbs[] = {
1013 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1014 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1015 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
1016 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
1017 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
1018 {}
1019};
1020
Tobin Davisf36090f2007-01-08 11:07:12 +01001021/* Ultra initialization */
1022static struct hda_verb ad1986a_ultra_init[] = {
1023 /* eapd initialization */
1024 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
1025 /* CLFE -> Mic in */
1026 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
1027 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1028 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
1029 { } /* end */
1030};
1031
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001032/* pin sensing on HP jack */
1033static struct hda_verb ad1986a_hp_init_verbs[] = {
1034 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
1035 {}
1036};
1037
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001038static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
1039 unsigned int res)
1040{
1041 switch (res >> 26) {
1042 case AD1986A_HP_EVENT:
1043 ad1986a_hp_automute(codec);
1044 break;
1045 case AD1986A_MIC_EVENT:
1046 ad1986a_automic(codec);
1047 break;
1048 }
1049}
1050
1051static int ad1986a_samsung_p50_init(struct hda_codec *codec)
1052{
1053 ad198x_init(codec);
1054 ad1986a_hp_automute(codec);
1055 ad1986a_automic(codec);
1056 return 0;
1057}
1058
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001059
Takashi Iwai9230d212006-03-13 13:49:49 +01001060/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001061enum {
1062 AD1986A_6STACK,
1063 AD1986A_3STACK,
1064 AD1986A_LAPTOP,
1065 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001066 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +01001067 AD1986A_ULTRA,
Takashi Iwai1725b822008-11-21 02:25:48 +01001068 AD1986A_SAMSUNG,
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001069 AD1986A_SAMSUNG_P50,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001070 AD1986A_MODELS
1071};
Takashi Iwai9230d212006-03-13 13:49:49 +01001072
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001073static const char *ad1986a_models[AD1986A_MODELS] = {
1074 [AD1986A_6STACK] = "6stack",
1075 [AD1986A_3STACK] = "3stack",
1076 [AD1986A_LAPTOP] = "laptop",
1077 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001078 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +01001079 [AD1986A_ULTRA] = "ultra",
Takashi Iwai1725b822008-11-21 02:25:48 +01001080 [AD1986A_SAMSUNG] = "samsung",
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001081 [AD1986A_SAMSUNG_P50] = "samsung-p50",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001082};
1083
1084static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1085 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001086 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001087 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001088 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001089 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
1090 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
1091 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
1092 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +01001093 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +02001094 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001095 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
1096 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
1097 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
1098 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
1099 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001100 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Daniel T Chenba579eb2010-02-20 11:16:30 -05001101 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001102 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001103 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001104 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
Tobin Davisf36090f2007-01-08 11:07:12 +01001105 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaidea0a502009-02-09 17:14:52 +01001106 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001107 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +01001108 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001109 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001110 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001111 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +01001112 {}
1113};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
Takashi Iwaicb53c622007-08-10 17:21:45 +02001115#ifdef CONFIG_SND_HDA_POWER_SAVE
1116static struct hda_amp_list ad1986a_loopbacks[] = {
1117 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
1118 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
1119 { 0x15, HDA_OUTPUT, 0 }, /* CD */
1120 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
1121 { 0x17, HDA_OUTPUT, 0 }, /* Line */
1122 { } /* end */
1123};
1124#endif
1125
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001126static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1127{
Takashi Iwai2f334f92009-02-20 14:37:42 +01001128 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001129 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1130}
1131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132static int patch_ad1986a(struct hda_codec *codec)
1133{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001134 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001135 int err, board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001137 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 if (spec == NULL)
1139 return -ENOMEM;
1140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 codec->spec = spec;
1142
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001143 err = snd_hda_attach_beep_device(codec, 0x19);
1144 if (err < 0) {
1145 ad198x_free(codec);
1146 return err;
1147 }
1148 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 spec->multiout.max_channels = 6;
1151 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1152 spec->multiout.dac_nids = ad1986a_dac_nids;
1153 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001154 spec->num_adc_nids = 1;
1155 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001156 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001157 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001158 spec->num_mixers = 1;
1159 spec->mixers[0] = ad1986a_mixers;
1160 spec->num_init_verbs = 1;
1161 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001162#ifdef CONFIG_SND_HDA_POWER_SAVE
1163 spec->loopback.amplist = ad1986a_loopbacks;
1164#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001165 spec->vmaster_nid = 0x1b;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01001166 spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001168 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Takashi Iwai9230d212006-03-13 13:49:49 +01001170 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001171 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1172 ad1986a_models,
1173 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001174 switch (board_config) {
1175 case AD1986A_3STACK:
1176 spec->num_mixers = 2;
1177 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001178 spec->num_init_verbs = 2;
1179 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001180 spec->channel_mode = ad1986a_modes;
1181 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001182 spec->need_dac_fix = 1;
1183 spec->multiout.max_channels = 2;
1184 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001185 break;
1186 case AD1986A_LAPTOP:
1187 spec->mixers[0] = ad1986a_laptop_mixers;
1188 spec->multiout.max_channels = 2;
1189 spec->multiout.num_dacs = 1;
1190 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1191 break;
Takashi Iwai825aa972006-03-17 10:50:49 +01001192 case AD1986A_LAPTOP_EAPD:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001193 spec->num_mixers = 3;
1194 spec->mixers[0] = ad1986a_laptop_master_mixers;
1195 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1196 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai1725b822008-11-21 02:25:48 +01001197 spec->num_init_verbs = 2;
1198 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1199 spec->multiout.max_channels = 2;
1200 spec->multiout.num_dacs = 1;
1201 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1202 if (!is_jack_available(codec, 0x25))
1203 spec->multiout.dig_out_nid = 0;
1204 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1205 break;
1206 case AD1986A_SAMSUNG:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001207 spec->num_mixers = 2;
1208 spec->mixers[0] = ad1986a_laptop_master_mixers;
1209 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001210 spec->num_init_verbs = 3;
Takashi Iwai825aa972006-03-17 10:50:49 +01001211 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001212 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa972006-03-17 10:50:49 +01001213 spec->multiout.max_channels = 2;
1214 spec->multiout.num_dacs = 1;
1215 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001216 if (!is_jack_available(codec, 0x25))
1217 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001218 spec->input_mux = &ad1986a_automic_capture_source;
1219 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1220 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa972006-03-17 10:50:49 +01001221 break;
Takashi Iwaic912e7a2009-06-24 14:14:34 +02001222 case AD1986A_SAMSUNG_P50:
1223 spec->num_mixers = 2;
1224 spec->mixers[0] = ad1986a_automute_master_mixers;
1225 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1226 spec->num_init_verbs = 4;
1227 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1228 spec->init_verbs[2] = ad1986a_automic_verbs;
1229 spec->init_verbs[3] = ad1986a_hp_init_verbs;
1230 spec->multiout.max_channels = 2;
1231 spec->multiout.num_dacs = 1;
1232 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1233 if (!is_jack_available(codec, 0x25))
1234 spec->multiout.dig_out_nid = 0;
1235 spec->input_mux = &ad1986a_automic_capture_source;
1236 codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
1237 codec->patch_ops.init = ad1986a_samsung_p50_init;
1238 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001239 case AD1986A_LAPTOP_AUTOMUTE:
Takashi Iwai16d11a82009-06-24 14:07:53 +02001240 spec->num_mixers = 3;
1241 spec->mixers[0] = ad1986a_automute_master_mixers;
1242 spec->mixers[1] = ad1986a_laptop_eapd_mixers;
1243 spec->mixers[2] = ad1986a_laptop_intmic_mixers;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001244 spec->num_init_verbs = 3;
1245 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1246 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1247 spec->multiout.max_channels = 2;
1248 spec->multiout.num_dacs = 1;
1249 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001250 if (!is_jack_available(codec, 0x25))
1251 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001252 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1253 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1254 codec->patch_ops.init = ad1986a_hp_init;
Takashi Iwai03c405a2009-06-24 14:10:15 +02001255 /* Lenovo N100 seems to report the reversed bit
1256 * for HP jack-sensing
1257 */
1258 spec->inv_jack_detect = 1;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001259 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001260 case AD1986A_ULTRA:
1261 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1262 spec->num_init_verbs = 2;
1263 spec->init_verbs[1] = ad1986a_ultra_init;
1264 spec->multiout.max_channels = 2;
1265 spec->multiout.num_dacs = 1;
1266 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1267 spec->multiout.dig_out_nid = 0;
1268 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001269 }
1270
Takashi Iwaid29240c2007-10-26 12:35:56 +02001271 /* AD1986A has a hardware problem that it can't share a stream
1272 * with multiple output pins. The copy of front to surrounds
1273 * causes noisy or silent outputs at a certain timing, e.g.
1274 * changing the volume.
1275 * So, let's disable the shared stream.
1276 */
1277 spec->multiout.no_share_stream = 1;
1278
Takashi Iwai729d55b2009-12-25 22:49:01 +01001279 codec->no_trigger_sense = 1;
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 return 0;
1282}
1283
1284/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001285 * AD1983 specific
1286 */
1287
1288#define AD1983_SPDIF_OUT 0x02
1289#define AD1983_DAC 0x03
1290#define AD1983_ADC 0x04
1291
1292static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001293static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001294static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001295
1296static struct hda_input_mux ad1983_capture_source = {
1297 .num_items = 4,
1298 .items = {
1299 { "Mic", 0x0 },
1300 { "Line", 0x1 },
1301 { "Mix", 0x2 },
1302 { "Mix Mono", 0x3 },
1303 },
1304};
1305
1306/*
1307 * SPDIF playback route
1308 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001309static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001310{
1311 static char *texts[] = { "PCM", "ADC" };
1312
1313 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1314 uinfo->count = 1;
1315 uinfo->value.enumerated.items = 2;
1316 if (uinfo->value.enumerated.item > 1)
1317 uinfo->value.enumerated.item = 1;
1318 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1319 return 0;
1320}
1321
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001322static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001323{
1324 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1325 struct ad198x_spec *spec = codec->spec;
1326
1327 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1328 return 0;
1329}
1330
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001331static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001332{
1333 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1334 struct ad198x_spec *spec = codec->spec;
1335
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001336 if (ucontrol->value.enumerated.item[0] > 1)
1337 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001338 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1339 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001340 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1341 AC_VERB_SET_CONNECT_SEL,
1342 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001343 return 1;
1344 }
1345 return 0;
1346}
1347
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001348static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001349 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1350 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1351 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1352 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1353 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1354 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1355 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1356 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1357 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1358 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1359 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1360 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001361 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1362 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1363 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1364 {
1365 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1366 .name = "Capture Source",
1367 .info = ad198x_mux_enum_info,
1368 .get = ad198x_mux_enum_get,
1369 .put = ad198x_mux_enum_put,
1370 },
1371 {
1372 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001373 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001374 .info = ad1983_spdif_route_info,
1375 .get = ad1983_spdif_route_get,
1376 .put = ad1983_spdif_route_put,
1377 },
1378 { } /* end */
1379};
1380
1381static struct hda_verb ad1983_init_verbs[] = {
1382 /* Front, HP, Mono; mute as default */
1383 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1384 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1385 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1386 /* Beep, PCM, Mic, Line-In: mute */
1387 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1388 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1389 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1390 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1391 /* Front, HP selectors; from Mix */
1392 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1393 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1394 /* Mono selector; from Mix */
1395 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1396 /* Mic selector; Mic */
1397 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1398 /* Line-in selector: Line-in */
1399 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1400 /* Mic boost: 0dB */
1401 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1402 /* Record selector: mic */
1403 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1404 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1405 /* SPDIF route: PCM */
1406 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1407 /* Front Pin */
1408 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1409 /* HP Pin */
1410 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1411 /* Mono Pin */
1412 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1413 /* Mic Pin */
1414 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1415 /* Line Pin */
1416 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1417 { } /* end */
1418};
1419
Takashi Iwaicb53c622007-08-10 17:21:45 +02001420#ifdef CONFIG_SND_HDA_POWER_SAVE
1421static struct hda_amp_list ad1983_loopbacks[] = {
1422 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1423 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1424 { } /* end */
1425};
1426#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001427
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001428static int patch_ad1983(struct hda_codec *codec)
1429{
1430 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001431 int err;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001432
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001433 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001434 if (spec == NULL)
1435 return -ENOMEM;
1436
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001437 codec->spec = spec;
1438
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001439 err = snd_hda_attach_beep_device(codec, 0x10);
1440 if (err < 0) {
1441 ad198x_free(codec);
1442 return err;
1443 }
1444 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1445
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001446 spec->multiout.max_channels = 2;
1447 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1448 spec->multiout.dac_nids = ad1983_dac_nids;
1449 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001450 spec->num_adc_nids = 1;
1451 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001452 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001453 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001454 spec->num_mixers = 1;
1455 spec->mixers[0] = ad1983_mixers;
1456 spec->num_init_verbs = 1;
1457 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001458 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001459#ifdef CONFIG_SND_HDA_POWER_SAVE
1460 spec->loopback.amplist = ad1983_loopbacks;
1461#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001462 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001463
1464 codec->patch_ops = ad198x_patch_ops;
1465
Takashi Iwai729d55b2009-12-25 22:49:01 +01001466 codec->no_trigger_sense = 1;
1467
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001468 return 0;
1469}
1470
1471
1472/*
1473 * AD1981 HD specific
1474 */
1475
1476#define AD1981_SPDIF_OUT 0x02
1477#define AD1981_DAC 0x03
1478#define AD1981_ADC 0x04
1479
1480static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001481static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001482static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001483
1484/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1485static struct hda_input_mux ad1981_capture_source = {
1486 .num_items = 7,
1487 .items = {
1488 { "Front Mic", 0x0 },
1489 { "Line", 0x1 },
1490 { "Mix", 0x2 },
1491 { "Mix Mono", 0x3 },
1492 { "CD", 0x4 },
1493 { "Mic", 0x6 },
1494 { "Aux", 0x7 },
1495 },
1496};
1497
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001498static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001499 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1500 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1501 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1502 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1503 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1504 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1505 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1506 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1507 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1508 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1509 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1510 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1511 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1512 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1513 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1514 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1515 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1516 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001517 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1518 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1519 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1520 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1521 {
1522 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1523 .name = "Capture Source",
1524 .info = ad198x_mux_enum_info,
1525 .get = ad198x_mux_enum_get,
1526 .put = ad198x_mux_enum_put,
1527 },
1528 /* identical with AD1983 */
1529 {
1530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001531 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001532 .info = ad1983_spdif_route_info,
1533 .get = ad1983_spdif_route_get,
1534 .put = ad1983_spdif_route_put,
1535 },
1536 { } /* end */
1537};
1538
1539static struct hda_verb ad1981_init_verbs[] = {
1540 /* Front, HP, Mono; mute as default */
1541 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1542 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1543 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1544 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1545 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1546 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1547 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1548 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1549 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1550 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1551 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1552 /* Front, HP selectors; from Mix */
1553 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1554 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1555 /* Mono selector; from Mix */
1556 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1557 /* Mic Mixer; select Front Mic */
1558 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1559 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1560 /* Mic boost: 0dB */
Takashi Iwai6d6e17d2009-01-23 12:33:54 +01001561 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1562 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001563 /* Record selector: Front mic */
1564 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1565 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1566 /* SPDIF route: PCM */
1567 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1568 /* Front Pin */
1569 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1570 /* HP Pin */
1571 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1572 /* Mono Pin */
1573 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1574 /* Front & Rear Mic Pins */
1575 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1576 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1577 /* Line Pin */
1578 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1579 /* Digital Beep */
1580 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1581 /* Line-Out as Input: disabled */
1582 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1583 { } /* end */
1584};
1585
Takashi Iwaicb53c622007-08-10 17:21:45 +02001586#ifdef CONFIG_SND_HDA_POWER_SAVE
1587static struct hda_amp_list ad1981_loopbacks[] = {
1588 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1589 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1590 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1591 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1592 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1593 { } /* end */
1594};
1595#endif
1596
Takashi Iwai18a815d2006-03-01 19:54:39 +01001597/*
1598 * Patch for HP nx6320
1599 *
Tobin Davis18768992007-03-12 22:20:51 +01001600 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001601 * speaker output enabled _and_ mute-LED off.
1602 */
1603
1604#define AD1981_HP_EVENT 0x37
1605#define AD1981_MIC_EVENT 0x38
1606
1607static struct hda_verb ad1981_hp_init_verbs[] = {
1608 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1609 /* pin sensing on HP and Mic jacks */
1610 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1611 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1612 {}
1613};
1614
1615/* turn on/off EAPD (+ mute HP) as a master switch */
1616static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1618{
1619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1620 struct ad198x_spec *spec = codec->spec;
1621
1622 if (! ad198x_eapd_put(kcontrol, ucontrol))
1623 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001624 /* change speaker pin appropriately */
1625 snd_hda_codec_write(codec, 0x05, 0,
1626 AC_VERB_SET_PIN_WIDGET_CONTROL,
1627 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001628 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001629 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1630 HDA_AMP_MUTE,
1631 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001632 return 1;
1633}
1634
1635/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001636static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1637 .ops = &snd_hda_bind_vol,
1638 .values = {
1639 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1640 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1641 0
1642 },
1643};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001644
1645/* mute internal speaker if HP is plugged */
1646static void ad1981_hp_automute(struct hda_codec *codec)
1647{
1648 unsigned int present;
1649
Takashi Iwaid56757a2009-11-18 08:00:14 +01001650 present = snd_hda_jack_detect(codec, 0x06);
Takashi Iwai47fd8302007-08-10 17:11:07 +02001651 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1652 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001653}
1654
1655/* toggle input of built-in and mic jack appropriately */
1656static void ad1981_hp_automic(struct hda_codec *codec)
1657{
1658 static struct hda_verb mic_jack_on[] = {
1659 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1660 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1661 {}
1662 };
1663 static struct hda_verb mic_jack_off[] = {
1664 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1665 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1666 {}
1667 };
1668 unsigned int present;
1669
Takashi Iwaid56757a2009-11-18 08:00:14 +01001670 present = snd_hda_jack_detect(codec, 0x08);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001671 if (present)
1672 snd_hda_sequence_write(codec, mic_jack_on);
1673 else
1674 snd_hda_sequence_write(codec, mic_jack_off);
1675}
1676
1677/* unsolicited event for HP jack sensing */
1678static void ad1981_hp_unsol_event(struct hda_codec *codec,
1679 unsigned int res)
1680{
1681 res >>= 26;
1682 switch (res) {
1683 case AD1981_HP_EVENT:
1684 ad1981_hp_automute(codec);
1685 break;
1686 case AD1981_MIC_EVENT:
1687 ad1981_hp_automic(codec);
1688 break;
1689 }
1690}
1691
1692static struct hda_input_mux ad1981_hp_capture_source = {
1693 .num_items = 3,
1694 .items = {
1695 { "Mic", 0x0 },
1696 { "Docking-Station", 0x1 },
1697 { "Mix", 0x2 },
1698 },
1699};
1700
1701static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001702 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001703 {
1704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001705 .subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
Takashi Iwai18a815d2006-03-01 19:54:39 +01001706 .name = "Master Playback Switch",
1707 .info = ad198x_eapd_info,
1708 .get = ad198x_eapd_get,
1709 .put = ad1981_hp_master_sw_put,
1710 .private_value = 0x05,
1711 },
1712 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1713 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1714#if 0
1715 /* FIXME: analog mic/line loopback doesn't work with my tests...
1716 * (although recording is OK)
1717 */
1718 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1719 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1720 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1721 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1722 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1723 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1724 /* FIXME: does this laptop have analog CD connection? */
1725 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1726 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1727#endif
1728 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1729 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1730 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1731 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1732 {
1733 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1734 .name = "Capture Source",
1735 .info = ad198x_mux_enum_info,
1736 .get = ad198x_mux_enum_get,
1737 .put = ad198x_mux_enum_put,
1738 },
1739 { } /* end */
1740};
1741
1742/* initialize jack-sensing, too */
1743static int ad1981_hp_init(struct hda_codec *codec)
1744{
1745 ad198x_init(codec);
1746 ad1981_hp_automute(codec);
1747 ad1981_hp_automic(codec);
1748 return 0;
1749}
1750
Tobin Davis18768992007-03-12 22:20:51 +01001751/* configuration for Toshiba Laptops */
1752static struct hda_verb ad1981_toshiba_init_verbs[] = {
1753 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1754 /* pin sensing on HP and Mic jacks */
1755 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1756 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1757 {}
1758};
1759
1760static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1761 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1762 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1763 { }
1764};
1765
Takashi Iwai01686c52006-04-18 12:54:11 +02001766/* configuration for Lenovo Thinkpad T60 */
1767static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1768 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1769 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1770 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1771 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1772 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1773 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1774 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1775 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1776 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1777 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1778 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1779 {
1780 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1781 .name = "Capture Source",
1782 .info = ad198x_mux_enum_info,
1783 .get = ad198x_mux_enum_get,
1784 .put = ad198x_mux_enum_put,
1785 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001786 /* identical with AD1983 */
1787 {
1788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1789 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1790 .info = ad1983_spdif_route_info,
1791 .get = ad1983_spdif_route_get,
1792 .put = ad1983_spdif_route_put,
1793 },
Takashi Iwai01686c52006-04-18 12:54:11 +02001794 { } /* end */
1795};
1796
1797static struct hda_input_mux ad1981_thinkpad_capture_source = {
1798 .num_items = 3,
1799 .items = {
1800 { "Mic", 0x0 },
1801 { "Mix", 0x2 },
1802 { "CD", 0x4 },
1803 },
1804};
1805
Takashi Iwai18a815d2006-03-01 19:54:39 +01001806/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001807enum {
1808 AD1981_BASIC,
1809 AD1981_HP,
1810 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001811 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001812 AD1981_MODELS
1813};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001814
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001815static const char *ad1981_models[AD1981_MODELS] = {
1816 [AD1981_HP] = "hp",
1817 [AD1981_THINKPAD] = "thinkpad",
1818 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001819 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001820};
1821
1822static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001823 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai470eaf62008-06-30 16:40:10 +02001824 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001825 /* All HP models */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001826 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001827 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c52006-04-18 12:54:11 +02001828 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001829 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001830 /* HP nx6320 (reversed SSID, H/W bug) */
1831 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001832 {}
1833};
1834
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001835static int patch_ad1981(struct hda_codec *codec)
1836{
1837 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001838 int err, board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001839
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001840 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001841 if (spec == NULL)
1842 return -ENOMEM;
1843
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001844 codec->spec = spec;
1845
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01001846 err = snd_hda_attach_beep_device(codec, 0x10);
1847 if (err < 0) {
1848 ad198x_free(codec);
1849 return err;
1850 }
1851 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1852
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001853 spec->multiout.max_channels = 2;
1854 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1855 spec->multiout.dac_nids = ad1981_dac_nids;
1856 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001857 spec->num_adc_nids = 1;
1858 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001859 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001860 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001861 spec->num_mixers = 1;
1862 spec->mixers[0] = ad1981_mixers;
1863 spec->num_init_verbs = 1;
1864 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001865 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001866#ifdef CONFIG_SND_HDA_POWER_SAVE
1867 spec->loopback.amplist = ad1981_loopbacks;
1868#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001869 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001870
1871 codec->patch_ops = ad198x_patch_ops;
1872
Takashi Iwai18a815d2006-03-01 19:54:39 +01001873 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001874 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1875 ad1981_models,
1876 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001877 switch (board_config) {
1878 case AD1981_HP:
1879 spec->mixers[0] = ad1981_hp_mixers;
1880 spec->num_init_verbs = 2;
1881 spec->init_verbs[1] = ad1981_hp_init_verbs;
1882 spec->multiout.dig_out_nid = 0;
1883 spec->input_mux = &ad1981_hp_capture_source;
1884
1885 codec->patch_ops.init = ad1981_hp_init;
1886 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
Daniel T Chen01f59662009-12-13 16:22:58 -05001887 /* set the upper-limit for mixer amp to 0dB for avoiding the
1888 * possible damage by overloading
1889 */
1890 snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
1891 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1892 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1893 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1894 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwai18a815d2006-03-01 19:54:39 +01001895 break;
Takashi Iwai01686c52006-04-18 12:54:11 +02001896 case AD1981_THINKPAD:
1897 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c52006-04-18 12:54:11 +02001898 spec->input_mux = &ad1981_thinkpad_capture_source;
1899 break;
Tobin Davis18768992007-03-12 22:20:51 +01001900 case AD1981_TOSHIBA:
1901 spec->mixers[0] = ad1981_hp_mixers;
1902 spec->mixers[1] = ad1981_toshiba_mixers;
1903 spec->num_init_verbs = 2;
1904 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1905 spec->multiout.dig_out_nid = 0;
1906 spec->input_mux = &ad1981_hp_capture_source;
1907 codec->patch_ops.init = ad1981_hp_init;
1908 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1909 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001910 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01001911
1912 codec->no_trigger_sense = 1;
1913
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001914 return 0;
1915}
1916
1917
1918/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001919 * AD1988
1920 *
1921 * Output pins and routes
1922 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001923 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001924 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1925 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1926 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1927 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1928 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1929 * port-F 0x16 (mute) <- 0x2a <- 06
1930 * port-G 0x24 (mute) <- 0x27 <- 05
1931 * port-H 0x25 (mute) <- 0x28 <- 0a
1932 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1933 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001934 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1935 * (*) 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 +01001936 *
1937 * Input pins and routes
1938 *
1939 * pin boost mix input # / adc input #
1940 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1941 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1942 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1943 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1944 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1945 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1946 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1947 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1948 *
1949 *
1950 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001951 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001952 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001953 *
1954 * Inputs of Analog Mix (0x20)
1955 * 0:Port-B (front mic)
1956 * 1:Port-C/G/H (line-in)
1957 * 2:Port-A
1958 * 3:Port-D (line-in/2)
1959 * 4:Port-E/G/H (mic-in)
1960 * 5:Port-F (mic2-in)
1961 * 6:CD
1962 * 7:Beep
1963 *
1964 * ADC selection
1965 * 0:Port-A
1966 * 1:Port-B (front mic-in)
1967 * 2:Port-C (line-in)
1968 * 3:Port-F (mic2-in)
1969 * 4:Port-E (mic-in)
1970 * 5:CD
1971 * 6:Port-G
1972 * 7:Port-H
1973 * 8:Port-D (line-in/2)
1974 * 9:Mix
1975 *
1976 * Proposed pin assignments by the datasheet
1977 *
1978 * 6-stack
1979 * Port-A front headphone
1980 * B front mic-in
1981 * C rear line-in
1982 * D rear front-out
1983 * E rear mic-in
1984 * F rear surround
1985 * G rear CLFE
1986 * H rear side
1987 *
1988 * 3-stack
1989 * Port-A front headphone
1990 * B front mic
1991 * C rear line-in/surround
1992 * D rear front-out
1993 * E rear mic-in/CLFE
1994 *
1995 * laptop
1996 * Port-A headphone
1997 * B mic-in
1998 * C docking station
1999 * D internal speaker (with EAPD)
2000 * E/F quad mic array
2001 */
2002
2003
2004/* models */
2005enum {
2006 AD1988_6STACK,
2007 AD1988_6STACK_DIG,
2008 AD1988_3STACK,
2009 AD1988_3STACK_DIG,
2010 AD1988_LAPTOP,
2011 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01002012 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002013 AD1988_MODEL_LAST,
2014};
2015
Takashi Iwaid32410b12005-11-24 16:06:23 +01002016/* reivision id to check workarounds */
2017#define AD1988A_REV2 0x100200
2018
Takashi Iwai1a806f42006-07-03 15:58:16 +02002019#define is_rev2(codec) \
2020 ((codec)->vendor_id == 0x11d41988 && \
2021 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002022
2023/*
2024 * mixers
2025 */
2026
Takashi Iwaid32410b12005-11-24 16:06:23 +01002027static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002028 0x04, 0x06, 0x05, 0x0a
2029};
2030
Takashi Iwaid32410b12005-11-24 16:06:23 +01002031static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002032 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002033};
2034
2035/* for AD1988A revision-2, DAC2-4 are swapped */
2036static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
2037 0x04, 0x05, 0x0a, 0x06
2038};
2039
2040static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002041 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002042};
2043
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002044static hda_nid_t ad1988_adc_nids[3] = {
2045 0x08, 0x09, 0x0f
2046};
2047
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002048static hda_nid_t ad1988_capsrc_nids[3] = {
2049 0x0c, 0x0d, 0x0e
2050};
2051
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002052#define AD1988_SPDIF_OUT 0x02
2053#define AD1988_SPDIF_OUT_HDMI 0x0b
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002054#define AD1988_SPDIF_IN 0x07
2055
Takashi Iwai3a08e302009-02-13 11:37:08 +01002056static hda_nid_t ad1989b_slave_dig_outs[] = {
2057 AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002058};
2059
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002060static struct hda_input_mux ad1988_6stack_capture_source = {
2061 .num_items = 5,
2062 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01002063 { "Front Mic", 0x1 }, /* port-B */
2064 { "Line", 0x2 }, /* port-C */
2065 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002066 { "CD", 0x5 },
2067 { "Mix", 0x9 },
2068 },
2069};
2070
2071static struct hda_input_mux ad1988_laptop_capture_source = {
2072 .num_items = 3,
2073 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01002074 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002075 { "CD", 0x5 },
2076 { "Mix", 0x9 },
2077 },
2078};
2079
2080/*
2081 */
2082static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
2083 struct snd_ctl_elem_info *uinfo)
2084{
2085 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2086 struct ad198x_spec *spec = codec->spec;
2087 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
2088 spec->num_channel_mode);
2089}
2090
2091static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
2092 struct snd_ctl_elem_value *ucontrol)
2093{
2094 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2095 struct ad198x_spec *spec = codec->spec;
2096 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
2097 spec->num_channel_mode, spec->multiout.max_channels);
2098}
2099
2100static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2101 struct snd_ctl_elem_value *ucontrol)
2102{
2103 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2104 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002105 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
2106 spec->num_channel_mode,
2107 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02002108 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02002109 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02002110 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002111}
2112
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002113/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002114static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002115 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2116 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2117 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2118 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2119 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002120 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002121};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002122
Takashi Iwaid32410b12005-11-24 16:06:23 +01002123static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2124 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2125 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
2126 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2127 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
2128 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002129 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002130};
2131
2132static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002133 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2134 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2135 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
2136 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
2137 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
2138 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2139 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2140
2141 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2142 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2143 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2144 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2145 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2146 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2147 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2148 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2149
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002150 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002151 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2152
2153 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2154 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2155
2156 { } /* end */
2157};
2158
2159/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002160static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002161 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002162 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002163 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
2164 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002165 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002166};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002167
Takashi Iwaid32410b12005-11-24 16:06:23 +01002168static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2169 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002170 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2171 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
2172 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02002173 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002174};
2175
2176static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002177 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01002178 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2179 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
2180 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002181 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
2182 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2183
2184 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2185 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2186 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2187 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2188 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2189 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2190 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2191 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2192
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002193 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002194 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2195
2196 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2197 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
2198 {
2199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2200 .name = "Channel Mode",
2201 .info = ad198x_ch_mode_info,
2202 .get = ad198x_ch_mode_get,
2203 .put = ad198x_ch_mode_put,
2204 },
2205
2206 { } /* end */
2207};
2208
2209/* laptop mode */
2210static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2211 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2212 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2213 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
2214
2215 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
2216 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
2217 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
2218 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
2219 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2220 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2221
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002222 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002223 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2224
2225 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2226
2227 {
2228 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2229 .name = "External Amplifier",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002230 .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
Takashi Iwai18a815d2006-03-01 19:54:39 +01002231 .info = ad198x_eapd_info,
2232 .get = ad198x_eapd_get,
2233 .put = ad198x_eapd_put,
Takashi Iwaiee6e3652009-12-08 17:23:33 +01002234 .private_value = 0x12, /* port-D */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002235 },
2236
2237 { } /* end */
2238};
2239
2240/* capture */
2241static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2242 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2243 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2244 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2245 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2246 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2247 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2248 {
2249 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2250 /* The multiple "Capture Source" controls confuse alsamixer
2251 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002252 */
2253 /* .name = "Capture Source", */
2254 .name = "Input Source",
2255 .count = 3,
2256 .info = ad198x_mux_enum_info,
2257 .get = ad198x_mux_enum_get,
2258 .put = ad198x_mux_enum_put,
2259 },
2260 { } /* end */
2261};
2262
2263static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2264 struct snd_ctl_elem_info *uinfo)
2265{
2266 static char *texts[] = {
2267 "PCM", "ADC1", "ADC2", "ADC3"
2268 };
2269 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2270 uinfo->count = 1;
2271 uinfo->value.enumerated.items = 4;
2272 if (uinfo->value.enumerated.item >= 4)
2273 uinfo->value.enumerated.item = 3;
2274 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2275 return 0;
2276}
2277
2278static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2279 struct snd_ctl_elem_value *ucontrol)
2280{
2281 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2282 unsigned int sel;
2283
Takashi Iwaibddcf542007-07-24 18:04:05 +02002284 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2285 AC_AMP_GET_INPUT);
2286 if (!(sel & 0x80))
2287 ucontrol->value.enumerated.item[0] = 0;
2288 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002289 sel = snd_hda_codec_read(codec, 0x0b, 0,
2290 AC_VERB_GET_CONNECT_SEL, 0);
2291 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002292 sel++;
2293 else
2294 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002295 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002296 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002297 return 0;
2298}
2299
2300static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2301 struct snd_ctl_elem_value *ucontrol)
2302{
2303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002304 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002305 int change;
2306
Takashi Iwai35b26722007-05-05 12:17:17 +02002307 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002308 if (val > 3)
2309 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002310 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002311 sel = snd_hda_codec_read(codec, 0x1d, 0,
2312 AC_VERB_GET_AMP_GAIN_MUTE,
2313 AC_AMP_GET_INPUT);
2314 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002315 if (change) {
2316 snd_hda_codec_write_cache(codec, 0x1d, 0,
2317 AC_VERB_SET_AMP_GAIN_MUTE,
2318 AMP_IN_UNMUTE(0));
2319 snd_hda_codec_write_cache(codec, 0x1d, 0,
2320 AC_VERB_SET_AMP_GAIN_MUTE,
2321 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002322 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002323 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002324 sel = snd_hda_codec_read(codec, 0x1d, 0,
2325 AC_VERB_GET_AMP_GAIN_MUTE,
2326 AC_AMP_GET_INPUT | 0x01);
2327 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002328 if (change) {
2329 snd_hda_codec_write_cache(codec, 0x1d, 0,
2330 AC_VERB_SET_AMP_GAIN_MUTE,
2331 AMP_IN_MUTE(0));
2332 snd_hda_codec_write_cache(codec, 0x1d, 0,
2333 AC_VERB_SET_AMP_GAIN_MUTE,
2334 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002335 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002336 sel = snd_hda_codec_read(codec, 0x0b, 0,
2337 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2338 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002339 if (change)
2340 snd_hda_codec_write_cache(codec, 0x0b, 0,
2341 AC_VERB_SET_CONNECT_SEL,
2342 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002343 }
2344 return change;
2345}
2346
2347static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2348 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2349 {
2350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2351 .name = "IEC958 Playback Source",
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002352 .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002353 .info = ad1988_spdif_playback_source_info,
2354 .get = ad1988_spdif_playback_source_get,
2355 .put = ad1988_spdif_playback_source_put,
2356 },
2357 { } /* end */
2358};
2359
2360static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2361 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2362 { } /* end */
2363};
2364
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002365static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2366 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07002367 HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002368 { } /* end */
2369};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002370
2371/*
2372 * initialization verbs
2373 */
2374
2375/*
2376 * for 6-stack (+dig)
2377 */
2378static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002379 /* Front, Surround, CLFE, side DAC; unmute as default */
2380 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2381 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2382 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2383 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002384 /* Port-A front headphon path */
2385 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2386 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2387 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2388 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2389 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2390 /* Port-D line-out path */
2391 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2392 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2393 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2394 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2395 /* Port-F surround path */
2396 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2397 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2398 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2399 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2400 /* Port-G CLFE path */
2401 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2402 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2403 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2404 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2405 /* Port-H side path */
2406 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2407 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2408 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2409 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2410 /* Mono out path */
2411 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2412 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2413 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2414 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2415 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2416 /* Port-B front mic-in path */
2417 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2418 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2419 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2420 /* Port-C line-in path */
2421 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2422 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2423 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2424 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2425 /* Port-E mic-in path */
2426 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2427 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2428 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2429 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002430 /* Analog CD Input */
2431 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002432 /* Analog Mix output amp */
2433 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002434
2435 { }
2436};
2437
2438static struct hda_verb ad1988_capture_init_verbs[] = {
2439 /* mute analog mix */
2440 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2441 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2442 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2443 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2444 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2445 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2446 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2447 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2448 /* select ADCs - front-mic */
2449 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2450 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2451 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002452
2453 { }
2454};
2455
2456static struct hda_verb ad1988_spdif_init_verbs[] = {
2457 /* SPDIF out sel */
2458 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2459 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2460 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002461 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002462 /* SPDIF out pin */
2463 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002464
2465 { }
2466};
2467
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01002468static struct hda_verb ad1988_spdif_in_init_verbs[] = {
2469 /* unmute SPDIF input pin */
2470 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2471 { }
2472};
2473
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002474/* AD1989 has no ADC -> SPDIF route */
2475static struct hda_verb ad1989_spdif_init_verbs[] = {
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002476 /* SPDIF-1 out pin */
2477 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002478 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Robin H. Johnsone8bfc6c2008-09-13 16:55:00 -07002479 /* SPDIF-2/HDMI out pin */
2480 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
2481 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02002482 { }
2483};
2484
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002485/*
2486 * verbs for 3stack (+dig)
2487 */
2488static struct hda_verb ad1988_3stack_ch2_init[] = {
2489 /* set port-C to line-in */
2490 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2491 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2492 /* set port-E to mic-in */
2493 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2494 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2495 { } /* end */
2496};
2497
2498static struct hda_verb ad1988_3stack_ch6_init[] = {
2499 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002500 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002501 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002502 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002503 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002504 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002505 { } /* end */
2506};
2507
2508static struct hda_channel_mode ad1988_3stack_modes[2] = {
2509 { 2, ad1988_3stack_ch2_init },
2510 { 6, ad1988_3stack_ch6_init },
2511};
2512
2513static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002514 /* Front, Surround, CLFE, side DAC; unmute as default */
2515 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2516 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2517 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2518 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002519 /* Port-A front headphon path */
2520 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2521 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2522 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2523 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2524 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2525 /* Port-D line-out path */
2526 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2527 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2528 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2529 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2530 /* Mono out path */
2531 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2532 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2533 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2534 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2535 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2536 /* Port-B front mic-in path */
2537 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2538 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2539 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002540 /* Port-C line-in/surround path - 6ch mode as default */
2541 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2542 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002543 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002544 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002545 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002546 /* Port-E mic-in/CLFE path - 6ch mode as default */
2547 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2548 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002549 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002550 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002551 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2552 /* mute analog mix */
2553 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2554 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2555 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2556 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2557 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2558 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2559 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2560 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2561 /* select ADCs - front-mic */
2562 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2563 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2564 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002565 /* Analog Mix output amp */
2566 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002567 { }
2568};
2569
2570/*
2571 * verbs for laptop mode (+dig)
2572 */
2573static struct hda_verb ad1988_laptop_hp_on[] = {
2574 /* unmute port-A and mute port-D */
2575 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2576 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2577 { } /* end */
2578};
2579static struct hda_verb ad1988_laptop_hp_off[] = {
2580 /* mute port-A and unmute port-D */
2581 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2582 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2583 { } /* end */
2584};
2585
2586#define AD1988_HP_EVENT 0x01
2587
2588static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002589 /* Front, Surround, CLFE, side DAC; unmute as default */
2590 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2591 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2592 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2593 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002594 /* Port-A front headphon path */
2595 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2596 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2597 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2598 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2599 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2600 /* unsolicited event for pin-sense */
2601 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2602 /* Port-D line-out path + EAPD */
2603 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2604 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2605 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2606 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2607 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2608 /* Mono out path */
2609 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2610 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2611 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2612 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2613 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2614 /* Port-B mic-in path */
2615 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2616 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2617 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2618 /* Port-C docking station - try to output */
2619 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2620 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2621 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2622 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2623 /* mute analog mix */
2624 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2625 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2626 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2627 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2628 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2629 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2630 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2631 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2632 /* select ADCs - mic */
2633 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2634 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2635 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
Takashi Iwaidb3da6c2008-08-11 18:08:54 +02002636 /* Analog Mix output amp */
2637 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002638 { }
2639};
2640
2641static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2642{
2643 if ((res >> 26) != AD1988_HP_EVENT)
2644 return;
Takashi Iwaid56757a2009-11-18 08:00:14 +01002645 if (snd_hda_jack_detect(codec, 0x11))
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002646 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2647 else
2648 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2649}
2650
Takashi Iwaicb53c622007-08-10 17:21:45 +02002651#ifdef CONFIG_SND_HDA_POWER_SAVE
2652static struct hda_amp_list ad1988_loopbacks[] = {
2653 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2654 { 0x20, HDA_INPUT, 1 }, /* Line */
2655 { 0x20, HDA_INPUT, 4 }, /* Mic */
2656 { 0x20, HDA_INPUT, 6 }, /* CD */
2657 { } /* end */
2658};
2659#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002660
2661/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002662 * Automatic parse of I/O pins from the BIOS configuration
2663 */
2664
Takashi Iwaid32410b12005-11-24 16:06:23 +01002665enum {
2666 AD_CTL_WIDGET_VOL,
2667 AD_CTL_WIDGET_MUTE,
2668 AD_CTL_BIND_MUTE,
2669};
2670static struct snd_kcontrol_new ad1988_control_templates[] = {
2671 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2672 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2673 HDA_BIND_MUTE(NULL, 0, 0, 0),
2674};
2675
2676/* add dynamic controls */
2677static int add_control(struct ad198x_spec *spec, int type, const char *name,
2678 unsigned long val)
2679{
2680 struct snd_kcontrol_new *knew;
2681
Takashi Iwai603c4012008-07-30 15:01:44 +02002682 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2683 knew = snd_array_new(&spec->kctls);
2684 if (!knew)
2685 return -ENOMEM;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002686 *knew = ad1988_control_templates[type];
2687 knew->name = kstrdup(name, GFP_KERNEL);
2688 if (! knew->name)
2689 return -ENOMEM;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002690 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002691 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002692 knew->private_value = val;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002693 return 0;
2694}
2695
2696#define AD1988_PIN_CD_NID 0x18
2697#define AD1988_PIN_BEEP_NID 0x10
2698
2699static hda_nid_t ad1988_mixer_nids[8] = {
2700 /* A B C D E F G H */
2701 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2702};
2703
2704static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2705{
2706 static hda_nid_t idx_to_dac[8] = {
2707 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002708 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002709 };
2710 static hda_nid_t idx_to_dac_rev2[8] = {
2711 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002712 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002713 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002714 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002715 return idx_to_dac_rev2[idx];
2716 else
2717 return idx_to_dac[idx];
2718}
2719
2720static hda_nid_t ad1988_boost_nids[8] = {
2721 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2722};
2723
2724static int ad1988_pin_idx(hda_nid_t nid)
2725{
2726 static hda_nid_t ad1988_io_pins[8] = {
2727 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2728 };
2729 int i;
2730 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2731 if (ad1988_io_pins[i] == nid)
2732 return i;
2733 return 0; /* should be -1 */
2734}
2735
2736static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2737{
2738 static int loopback_idx[8] = {
2739 2, 0, 1, 3, 4, 5, 1, 4
2740 };
2741 switch (nid) {
2742 case AD1988_PIN_CD_NID:
2743 return 6;
2744 default:
2745 return loopback_idx[ad1988_pin_idx(nid)];
2746 }
2747}
2748
2749static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2750{
2751 static int adc_idx[8] = {
2752 0, 1, 2, 8, 4, 3, 6, 7
2753 };
2754 switch (nid) {
2755 case AD1988_PIN_CD_NID:
2756 return 5;
2757 default:
2758 return adc_idx[ad1988_pin_idx(nid)];
2759 }
2760}
2761
2762/* fill in the dac_nids table from the parsed pin configuration */
2763static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2764 const struct auto_pin_cfg *cfg)
2765{
2766 struct ad198x_spec *spec = codec->spec;
2767 int i, idx;
2768
2769 spec->multiout.dac_nids = spec->private_dac_nids;
2770
2771 /* check the pins hardwired to audio widget */
2772 for (i = 0; i < cfg->line_outs; i++) {
2773 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2774 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2775 }
2776 spec->multiout.num_dacs = cfg->line_outs;
2777 return 0;
2778}
2779
2780/* add playback controls from the parsed DAC table */
2781static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2782 const struct auto_pin_cfg *cfg)
2783{
2784 char name[32];
2785 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2786 hda_nid_t nid;
2787 int i, err;
2788
2789 for (i = 0; i < cfg->line_outs; i++) {
2790 hda_nid_t dac = spec->multiout.dac_nids[i];
2791 if (! dac)
2792 continue;
2793 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2794 if (i == 2) {
2795 /* Center/LFE */
2796 err = add_control(spec, AD_CTL_WIDGET_VOL,
2797 "Center Playback Volume",
2798 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2799 if (err < 0)
2800 return err;
2801 err = add_control(spec, AD_CTL_WIDGET_VOL,
2802 "LFE Playback Volume",
2803 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2804 if (err < 0)
2805 return err;
2806 err = add_control(spec, AD_CTL_BIND_MUTE,
2807 "Center Playback Switch",
2808 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2809 if (err < 0)
2810 return err;
2811 err = add_control(spec, AD_CTL_BIND_MUTE,
2812 "LFE Playback Switch",
2813 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2814 if (err < 0)
2815 return err;
2816 } else {
2817 sprintf(name, "%s Playback Volume", chname[i]);
2818 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2819 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2820 if (err < 0)
2821 return err;
2822 sprintf(name, "%s Playback Switch", chname[i]);
2823 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2824 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2825 if (err < 0)
2826 return err;
2827 }
2828 }
2829 return 0;
2830}
2831
2832/* add playback controls for speaker and HP outputs */
2833static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2834 const char *pfx)
2835{
2836 struct ad198x_spec *spec = codec->spec;
2837 hda_nid_t nid;
Takashi Iwai43785ea2008-06-16 15:47:26 +02002838 int i, idx, err;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002839 char name[32];
2840
2841 if (! pin)
2842 return 0;
2843
2844 idx = ad1988_pin_idx(pin);
2845 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai43785ea2008-06-16 15:47:26 +02002846 /* check whether the corresponding DAC was already taken */
2847 for (i = 0; i < spec->autocfg.line_outs; i++) {
2848 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2849 hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
2850 if (dac == nid)
2851 break;
2852 }
2853 if (i >= spec->autocfg.line_outs) {
2854 /* specify the DAC as the extra output */
2855 if (!spec->multiout.hp_nid)
2856 spec->multiout.hp_nid = nid;
2857 else
2858 spec->multiout.extra_out_nid[0] = nid;
2859 /* control HP volume/switch on the output mixer amp */
2860 sprintf(name, "%s Playback Volume", pfx);
2861 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2862 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2863 if (err < 0)
2864 return err;
2865 }
Takashi Iwaid32410b12005-11-24 16:06:23 +01002866 nid = ad1988_mixer_nids[idx];
2867 sprintf(name, "%s Playback Switch", pfx);
2868 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2869 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2870 return err;
2871 return 0;
2872}
2873
2874/* create input playback/capture controls for the given pin */
2875static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2876 const char *ctlname, int boost)
2877{
2878 char name[32];
2879 int err, idx;
2880
2881 sprintf(name, "%s Playback Volume", ctlname);
2882 idx = ad1988_pin_to_loopback_idx(pin);
2883 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2884 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2885 return err;
2886 sprintf(name, "%s Playback Switch", ctlname);
2887 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2888 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2889 return err;
2890 if (boost) {
2891 hda_nid_t bnid;
2892 idx = ad1988_pin_idx(pin);
2893 bnid = ad1988_boost_nids[idx];
2894 if (bnid) {
2895 sprintf(name, "%s Boost", ctlname);
2896 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2897 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2898
2899 }
2900 }
2901 return 0;
2902}
2903
2904/* create playback/capture controls for input pins */
2905static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2906 const struct auto_pin_cfg *cfg)
2907{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002908 struct hda_input_mux *imux = &spec->private_imux;
2909 int i, err;
2910
2911 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002912 err = new_analog_input(spec, cfg->input_pins[i],
2913 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002914 i <= AUTO_PIN_FRONT_MIC);
2915 if (err < 0)
2916 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002917 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002918 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2919 imux->num_items++;
2920 }
2921 imux->items[imux->num_items].label = "Mix";
2922 imux->items[imux->num_items].index = 9;
2923 imux->num_items++;
2924
2925 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2926 "Analog Mix Playback Volume",
2927 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2928 return err;
2929 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2930 "Analog Mix Playback Switch",
2931 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2932 return err;
2933
2934 return 0;
2935}
2936
2937static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2938 hda_nid_t nid, int pin_type,
2939 int dac_idx)
2940{
2941 /* set as output */
2942 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2943 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2944 switch (nid) {
2945 case 0x11: /* port-A - DAC 04 */
2946 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2947 break;
2948 case 0x14: /* port-B - DAC 06 */
2949 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2950 break;
2951 case 0x15: /* port-C - DAC 05 */
2952 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2953 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002954 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002955 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2956 break;
2957 case 0x13: /* mono - DAC 04 */
2958 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2959 break;
2960 }
2961}
2962
2963static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2964{
2965 struct ad198x_spec *spec = codec->spec;
2966 int i;
2967
2968 for (i = 0; i < spec->autocfg.line_outs; i++) {
2969 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2970 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2971 }
2972}
2973
2974static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2975{
2976 struct ad198x_spec *spec = codec->spec;
2977 hda_nid_t pin;
2978
Takashi Iwai82bc9552006-03-21 11:24:42 +01002979 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002980 if (pin) /* connect to front */
2981 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002982 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002983 if (pin) /* connect to front */
2984 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2985}
2986
2987static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2988{
2989 struct ad198x_spec *spec = codec->spec;
2990 int i, idx;
2991
2992 for (i = 0; i < AUTO_PIN_LAST; i++) {
2993 hda_nid_t nid = spec->autocfg.input_pins[i];
2994 if (! nid)
2995 continue;
2996 switch (nid) {
2997 case 0x15: /* port-C */
2998 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2999 break;
3000 case 0x17: /* port-E */
3001 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
3002 break;
3003 }
3004 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3005 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
3006 if (nid != AD1988_PIN_CD_NID)
3007 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3008 AMP_OUT_MUTE);
3009 idx = ad1988_pin_idx(nid);
3010 if (ad1988_boost_nids[idx])
3011 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
3012 AC_VERB_SET_AMP_GAIN_MUTE,
3013 AMP_OUT_ZERO);
3014 }
3015}
3016
3017/* parse the BIOS configuration and set up the alc_spec */
3018/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
3019static int ad1988_parse_auto_config(struct hda_codec *codec)
3020{
3021 struct ad198x_spec *spec = codec->spec;
3022 int err;
3023
Kailang Yangdf694da2005-12-05 19:42:22 +01003024 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003025 return err;
3026 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3027 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003028 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003029 return 0; /* can't find valid BIOS pin config */
3030 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01003031 (err = ad1988_auto_create_extra_out(codec,
3032 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01003033 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003034 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01003035 "Headphone")) < 0 ||
3036 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
3037 return err;
3038
3039 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3040
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003041 if (spec->autocfg.dig_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01003042 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3043 if (spec->autocfg.dig_in_pin)
3044 spec->dig_in_nid = AD1988_SPDIF_IN;
3045
Takashi Iwai603c4012008-07-30 15:01:44 +02003046 if (spec->kctls.list)
3047 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003048
3049 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
3050
3051 spec->input_mux = &spec->private_imux;
3052
3053 return 1;
3054}
3055
3056/* init callback for auto-configuration model -- overriding the default init */
3057static int ad1988_auto_init(struct hda_codec *codec)
3058{
3059 ad198x_init(codec);
3060 ad1988_auto_init_multi_out(codec);
3061 ad1988_auto_init_extra_out(codec);
3062 ad1988_auto_init_analog_input(codec);
3063 return 0;
3064}
3065
3066
3067/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003068 */
3069
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003070static const char *ad1988_models[AD1988_MODEL_LAST] = {
3071 [AD1988_6STACK] = "6stack",
3072 [AD1988_6STACK_DIG] = "6stack-dig",
3073 [AD1988_3STACK] = "3stack",
3074 [AD1988_3STACK_DIG] = "3stack-dig",
3075 [AD1988_LAPTOP] = "laptop",
3076 [AD1988_LAPTOP_DIG] = "laptop-dig",
3077 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003078};
3079
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003080static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01003081 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01003082 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Travis Placeb9e16bc2008-05-21 16:57:20 +02003083 SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
Robin H. Johnsonf51ff992008-09-13 16:55:01 -07003084 SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003085 {}
3086};
3087
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003088static int patch_ad1988(struct hda_codec *codec)
3089{
3090 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003091 int err, board_config;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003092
3093 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3094 if (spec == NULL)
3095 return -ENOMEM;
3096
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003097 codec->spec = spec;
3098
Takashi Iwai1a806f42006-07-03 15:58:16 +02003099 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01003100 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
3101
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003102 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01003103 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003104 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02003105 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3106 codec->chip_name);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003107 board_config = AD1988_AUTO;
3108 }
3109
3110 if (board_config == AD1988_AUTO) {
3111 /* automatic parse from the BIOS config */
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003112 err = ad1988_parse_auto_config(codec);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003113 if (err < 0) {
3114 ad198x_free(codec);
3115 return err;
3116 } else if (! err) {
3117 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
3118 board_config = AD1988_6STACK;
3119 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003120 }
3121
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003122 err = snd_hda_attach_beep_device(codec, 0x10);
3123 if (err < 0) {
3124 ad198x_free(codec);
3125 return err;
3126 }
3127 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3128
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003129 switch (board_config) {
3130 case AD1988_6STACK:
3131 case AD1988_6STACK_DIG:
3132 spec->multiout.max_channels = 8;
3133 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003134 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003135 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
3136 else
3137 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003138 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003139 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003140 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003141 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
3142 else
3143 spec->mixers[0] = ad1988_6stack_mixers1;
3144 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003145 spec->num_init_verbs = 1;
3146 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3147 if (board_config == AD1988_6STACK_DIG) {
3148 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3149 spec->dig_in_nid = AD1988_SPDIF_IN;
3150 }
3151 break;
3152 case AD1988_3STACK:
3153 case AD1988_3STACK_DIG:
3154 spec->multiout.max_channels = 6;
3155 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003156 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003157 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
3158 else
3159 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003160 spec->input_mux = &ad1988_6stack_capture_source;
3161 spec->channel_mode = ad1988_3stack_modes;
3162 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01003163 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02003164 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01003165 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
3166 else
3167 spec->mixers[0] = ad1988_3stack_mixers1;
3168 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003169 spec->num_init_verbs = 1;
3170 spec->init_verbs[0] = ad1988_3stack_init_verbs;
3171 if (board_config == AD1988_3STACK_DIG)
3172 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3173 break;
3174 case AD1988_LAPTOP:
3175 case AD1988_LAPTOP_DIG:
3176 spec->multiout.max_channels = 2;
3177 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01003178 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003179 spec->input_mux = &ad1988_laptop_capture_source;
3180 spec->num_mixers = 1;
3181 spec->mixers[0] = ad1988_laptop_mixers;
Takashi Iwaiee6e3652009-12-08 17:23:33 +01003182 spec->inv_eapd = 1; /* inverted EAPD */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003183 spec->num_init_verbs = 1;
3184 spec->init_verbs[0] = ad1988_laptop_init_verbs;
3185 if (board_config == AD1988_LAPTOP_DIG)
3186 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3187 break;
3188 }
3189
Takashi Iwaid32410b12005-11-24 16:06:23 +01003190 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3191 spec->adc_nids = ad1988_adc_nids;
3192 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003193 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
3194 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
3195 if (spec->multiout.dig_out_nid) {
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003196 if (codec->vendor_id >= 0x11d4989a) {
3197 spec->mixers[spec->num_mixers++] =
3198 ad1989_spdif_out_mixers;
3199 spec->init_verbs[spec->num_init_verbs++] =
3200 ad1989_spdif_init_verbs;
Robin H. Johnson9cae0c62008-09-13 16:54:58 -07003201 codec->slave_dig_outs = ad1989b_slave_dig_outs;
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02003202 } else {
3203 spec->mixers[spec->num_mixers++] =
3204 ad1988_spdif_out_mixers;
3205 spec->init_verbs[spec->num_init_verbs++] =
3206 ad1988_spdif_init_verbs;
3207 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003208 }
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01003209 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003210 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
Jaroslav Kyselafd0b0922010-01-21 14:54:38 +01003211 spec->init_verbs[spec->num_init_verbs++] =
3212 ad1988_spdif_in_init_verbs;
3213 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003214
3215 codec->patch_ops = ad198x_patch_ops;
3216 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01003217 case AD1988_AUTO:
3218 codec->patch_ops.init = ad1988_auto_init;
3219 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003220 case AD1988_LAPTOP:
3221 case AD1988_LAPTOP_DIG:
3222 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
3223 break;
3224 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02003225#ifdef CONFIG_SND_HDA_POWER_SAVE
3226 spec->loopback.amplist = ad1988_loopbacks;
3227#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003228 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003229
Takashi Iwai729d55b2009-12-25 22:49:01 +01003230 codec->no_trigger_sense = 1;
3231
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01003232 return 0;
3233}
3234
3235
3236/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02003237 * AD1884 / AD1984
3238 *
3239 * port-B - front line/mic-in
3240 * port-E - aux in/out
3241 * port-F - aux in/out
3242 * port-C - rear line/mic-in
3243 * port-D - rear line/hp-out
3244 * port-A - front line/hp-out
3245 *
3246 * AD1984 = AD1884 + two digital mic-ins
3247 *
3248 * FIXME:
3249 * For simplicity, we share the single DAC for both HP and line-outs
3250 * right now. The inidividual playbacks could be easily implemented,
3251 * but no build-up framework is given, so far.
3252 */
3253
3254static hda_nid_t ad1884_dac_nids[1] = {
3255 0x04,
3256};
3257
3258static hda_nid_t ad1884_adc_nids[2] = {
3259 0x08, 0x09,
3260};
3261
3262static hda_nid_t ad1884_capsrc_nids[2] = {
3263 0x0c, 0x0d,
3264};
3265
3266#define AD1884_SPDIF_OUT 0x02
3267
3268static struct hda_input_mux ad1884_capture_source = {
3269 .num_items = 4,
3270 .items = {
3271 { "Front Mic", 0x0 },
3272 { "Mic", 0x1 },
3273 { "CD", 0x2 },
3274 { "Mix", 0x3 },
3275 },
3276};
3277
3278static struct snd_kcontrol_new ad1884_base_mixers[] = {
3279 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3280 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3281 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3282 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3283 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3284 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3285 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3286 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3287 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3288 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3289 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3290 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003291 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3292 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3293 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3294 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3295 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3296 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3297 {
3298 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3299 /* The multiple "Capture Source" controls confuse alsamixer
3300 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003301 */
3302 /* .name = "Capture Source", */
3303 .name = "Input Source",
3304 .count = 2,
3305 .info = ad198x_mux_enum_info,
3306 .get = ad198x_mux_enum_get,
3307 .put = ad198x_mux_enum_put,
3308 },
3309 /* SPDIF controls */
3310 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3311 {
3312 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3313 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3314 /* identical with ad1983 */
3315 .info = ad1983_spdif_route_info,
3316 .get = ad1983_spdif_route_get,
3317 .put = ad1983_spdif_route_put,
3318 },
3319 { } /* end */
3320};
3321
3322static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3323 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3324 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3325 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003326 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003327 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003328 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003329 { } /* end */
3330};
3331
3332/*
3333 * initialization verbs
3334 */
3335static struct hda_verb ad1884_init_verbs[] = {
3336 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003337 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3338 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003339 /* Port-A (HP) mixer */
3340 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3341 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3342 /* Port-A pin */
3343 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3344 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3345 /* HP selector - select DAC2 */
3346 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3347 /* Port-D (Line-out) mixer */
3348 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3349 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3350 /* Port-D pin */
3351 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3352 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3353 /* Mono-out mixer */
3354 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3355 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3356 /* Mono-out pin */
3357 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3358 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3359 /* Mono selector */
3360 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3361 /* Port-B (front mic) pin */
3362 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003363 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003364 /* Port-C (rear mic) pin */
3365 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003366 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003367 /* Analog mixer; mute as default */
3368 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3369 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3370 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3371 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3372 /* Analog Mix output amp */
3373 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3374 /* SPDIF output selector */
3375 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3376 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3377 { } /* end */
3378};
3379
Takashi Iwaicb53c622007-08-10 17:21:45 +02003380#ifdef CONFIG_SND_HDA_POWER_SAVE
3381static struct hda_amp_list ad1884_loopbacks[] = {
3382 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3383 { 0x20, HDA_INPUT, 1 }, /* Mic */
3384 { 0x20, HDA_INPUT, 2 }, /* CD */
3385 { 0x20, HDA_INPUT, 4 }, /* Docking */
3386 { } /* end */
3387};
3388#endif
3389
Takashi Iwai2134ea42008-01-10 16:53:55 +01003390static const char *ad1884_slave_vols[] = {
3391 "PCM Playback Volume",
3392 "Mic Playback Volume",
3393 "Mono Playback Volume",
3394 "Front Mic Playback Volume",
3395 "Mic Playback Volume",
3396 "CD Playback Volume",
3397 "Internal Mic Playback Volume",
Akinobu Mitabca68462009-04-06 18:42:42 +09003398 "Docking Mic Playback Volume",
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003399 /* "Beep Playback Volume", */
Takashi Iwai4806ef02008-01-26 09:58:13 +01003400 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003401 NULL
3402};
3403
Takashi Iwai2bac6472007-05-18 18:21:41 +02003404static int patch_ad1884(struct hda_codec *codec)
3405{
3406 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003407 int err;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003408
3409 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3410 if (spec == NULL)
3411 return -ENOMEM;
3412
Takashi Iwai2bac6472007-05-18 18:21:41 +02003413 codec->spec = spec;
3414
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01003415 err = snd_hda_attach_beep_device(codec, 0x10);
3416 if (err < 0) {
3417 ad198x_free(codec);
3418 return err;
3419 }
3420 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3421
Takashi Iwai2bac6472007-05-18 18:21:41 +02003422 spec->multiout.max_channels = 2;
3423 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3424 spec->multiout.dac_nids = ad1884_dac_nids;
3425 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3426 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3427 spec->adc_nids = ad1884_adc_nids;
3428 spec->capsrc_nids = ad1884_capsrc_nids;
3429 spec->input_mux = &ad1884_capture_source;
3430 spec->num_mixers = 1;
3431 spec->mixers[0] = ad1884_base_mixers;
3432 spec->num_init_verbs = 1;
3433 spec->init_verbs[0] = ad1884_init_verbs;
3434 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003435#ifdef CONFIG_SND_HDA_POWER_SAVE
3436 spec->loopback.amplist = ad1884_loopbacks;
3437#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003438 spec->vmaster_nid = 0x04;
3439 /* we need to cover all playback volumes */
3440 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003441
3442 codec->patch_ops = ad198x_patch_ops;
3443
Takashi Iwai729d55b2009-12-25 22:49:01 +01003444 codec->no_trigger_sense = 1;
3445
Takashi Iwai2bac6472007-05-18 18:21:41 +02003446 return 0;
3447}
3448
3449/*
3450 * Lenovo Thinkpad T61/X61
3451 */
3452static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003453 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003454 .items = {
3455 { "Mic", 0x0 },
3456 { "Internal Mic", 0x1 },
3457 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003458 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003459 },
3460};
3461
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003462
3463/*
3464 * Dell Precision T3400
3465 */
3466static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3467 .num_items = 3,
3468 .items = {
3469 { "Front Mic", 0x0 },
3470 { "Line-In", 0x1 },
3471 { "Mix", 0x3 },
3472 },
3473};
3474
3475
Takashi Iwai2bac6472007-05-18 18:21:41 +02003476static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3477 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3478 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3479 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3480 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3481 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3482 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3483 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3484 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3485 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3486 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003487 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3488 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02003489 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003490 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3491 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3492 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3493 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3494 {
3495 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3496 /* The multiple "Capture Source" controls confuse alsamixer
3497 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003498 */
3499 /* .name = "Capture Source", */
3500 .name = "Input Source",
3501 .count = 2,
3502 .info = ad198x_mux_enum_info,
3503 .get = ad198x_mux_enum_get,
3504 .put = ad198x_mux_enum_put,
3505 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003506 /* SPDIF controls */
3507 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3508 {
3509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3510 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3511 /* identical with ad1983 */
3512 .info = ad1983_spdif_route_info,
3513 .get = ad1983_spdif_route_get,
3514 .put = ad1983_spdif_route_put,
3515 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003516 { } /* end */
3517};
3518
3519/* additional verbs */
3520static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3521 /* Port-E (docking station mic) pin */
3522 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3523 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3524 /* docking mic boost */
Takashi Iwai70040c02009-01-23 14:18:11 +01003525 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003526 /* Analog mixer - docking mic; mute as default */
3527 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003528 /* enable EAPD bit */
3529 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003530 { } /* end */
3531};
3532
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003533/*
3534 * Dell Precision T3400
3535 */
3536static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3537 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3538 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3539 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3540 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3541 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3542 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3543 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3544 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3545 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003546 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3547 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3548 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3549 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3550 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3551 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3552 {
3553 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3554 /* The multiple "Capture Source" controls confuse alsamixer
3555 * So call somewhat different..
3556 */
3557 /* .name = "Capture Source", */
3558 .name = "Input Source",
3559 .count = 2,
3560 .info = ad198x_mux_enum_info,
3561 .get = ad198x_mux_enum_get,
3562 .put = ad198x_mux_enum_put,
3563 },
3564 { } /* end */
3565};
3566
Takashi Iwai2bac6472007-05-18 18:21:41 +02003567/* Digial MIC ADC NID 0x05 + 0x06 */
3568static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3569 struct hda_codec *codec,
3570 unsigned int stream_tag,
3571 unsigned int format,
3572 struct snd_pcm_substream *substream)
3573{
3574 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3575 stream_tag, 0, format);
3576 return 0;
3577}
3578
3579static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3580 struct hda_codec *codec,
3581 struct snd_pcm_substream *substream)
3582{
Takashi Iwai888afa12008-03-18 09:57:50 +01003583 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003584 return 0;
3585}
3586
3587static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3588 .substreams = 2,
3589 .channels_min = 2,
3590 .channels_max = 2,
3591 .nid = 0x05,
3592 .ops = {
3593 .prepare = ad1984_pcm_dmic_prepare,
3594 .cleanup = ad1984_pcm_dmic_cleanup
3595 },
3596};
3597
3598static int ad1984_build_pcms(struct hda_codec *codec)
3599{
3600 struct ad198x_spec *spec = codec->spec;
3601 struct hda_pcm *info;
3602 int err;
3603
3604 err = ad198x_build_pcms(codec);
3605 if (err < 0)
3606 return err;
3607
3608 info = spec->pcm_rec + codec->num_pcms;
3609 codec->num_pcms++;
3610 info->name = "AD1984 Digital Mic";
3611 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3612 return 0;
3613}
3614
3615/* models */
3616enum {
3617 AD1984_BASIC,
3618 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003619 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003620 AD1984_MODELS
3621};
3622
3623static const char *ad1984_models[AD1984_MODELS] = {
3624 [AD1984_BASIC] = "basic",
3625 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003626 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003627};
3628
3629static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3630 /* Lenovo Thinkpad T61/X61 */
Takashi Iwaidea0a502009-02-09 17:14:52 +01003631 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003632 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003633 {}
3634};
3635
3636static int patch_ad1984(struct hda_codec *codec)
3637{
3638 struct ad198x_spec *spec;
3639 int board_config, err;
3640
3641 err = patch_ad1884(codec);
3642 if (err < 0)
3643 return err;
3644 spec = codec->spec;
3645 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3646 ad1984_models, ad1984_cfg_tbl);
3647 switch (board_config) {
3648 case AD1984_BASIC:
3649 /* additional digital mics */
3650 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3651 codec->patch_ops.build_pcms = ad1984_build_pcms;
3652 break;
3653 case AD1984_THINKPAD:
Jerone Youngebf00c52008-01-07 12:22:18 +01003654 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003655 spec->input_mux = &ad1984_thinkpad_capture_source;
3656 spec->mixers[0] = ad1984_thinkpad_mixers;
3657 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3658 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003659 case AD1984_DELL_DESKTOP:
3660 spec->multiout.dig_out_nid = 0;
3661 spec->input_mux = &ad1984_dell_desktop_capture_source;
3662 spec->mixers[0] = ad1984_dell_desktop_mixers;
3663 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003664 }
3665 return 0;
3666}
3667
3668
3669/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003670 * AD1883 / AD1884A / AD1984A / AD1984B
3671 *
3672 * port-B (0x14) - front mic-in
3673 * port-E (0x1c) - rear mic-in
3674 * port-F (0x16) - CD / ext out
3675 * port-C (0x15) - rear line-in
3676 * port-D (0x12) - rear line-out
3677 * port-A (0x11) - front hp-out
3678 *
3679 * AD1984A = AD1884A + digital-mic
3680 * AD1883 = equivalent with AD1984A
3681 * AD1984B = AD1984A + extra SPDIF-out
3682 *
3683 * FIXME:
3684 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3685 */
3686
3687static hda_nid_t ad1884a_dac_nids[1] = {
3688 0x03,
3689};
3690
3691#define ad1884a_adc_nids ad1884_adc_nids
3692#define ad1884a_capsrc_nids ad1884_capsrc_nids
3693
3694#define AD1884A_SPDIF_OUT 0x02
3695
3696static struct hda_input_mux ad1884a_capture_source = {
3697 .num_items = 5,
3698 .items = {
3699 { "Front Mic", 0x0 },
3700 { "Mic", 0x4 },
3701 { "Line", 0x1 },
3702 { "CD", 0x2 },
3703 { "Mix", 0x3 },
3704 },
3705};
3706
3707static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3708 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3709 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3710 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3711 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3712 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3713 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3714 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3715 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3716 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3717 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3718 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3719 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3720 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3721 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3722 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3723 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003724 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3725 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3726 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3727 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3728 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3729 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3730 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3731 {
3732 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3733 /* The multiple "Capture Source" controls confuse alsamixer
3734 * So call somewhat different..
3735 */
3736 /* .name = "Capture Source", */
3737 .name = "Input Source",
3738 .count = 2,
3739 .info = ad198x_mux_enum_info,
3740 .get = ad198x_mux_enum_get,
3741 .put = ad198x_mux_enum_put,
3742 },
3743 /* SPDIF controls */
3744 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3745 {
3746 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3747 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3748 /* identical with ad1983 */
3749 .info = ad1983_spdif_route_info,
3750 .get = ad1983_spdif_route_get,
3751 .put = ad1983_spdif_route_put,
3752 },
3753 { } /* end */
3754};
3755
3756/*
3757 * initialization verbs
3758 */
3759static struct hda_verb ad1884a_init_verbs[] = {
3760 /* DACs; unmute as default */
3761 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3762 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3763 /* Port-A (HP) mixer - route only from analog mixer */
3764 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3765 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3766 /* Port-A pin */
3767 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3768 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3769 /* Port-D (Line-out) mixer - route only from analog mixer */
3770 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3771 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3772 /* Port-D pin */
3773 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3774 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3775 /* Mono-out mixer - route only from analog mixer */
3776 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3777 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3778 /* Mono-out pin */
3779 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3780 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3781 /* Port-B (front mic) pin */
3782 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003783 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003784 /* Port-C (rear line-in) pin */
3785 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai60e388e2009-01-23 12:37:09 +01003786 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaic5059252008-02-16 09:43:56 +01003787 /* Port-E (rear mic) pin */
3788 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3789 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3790 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3791 /* Port-F (CD) pin */
3792 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3793 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3794 /* Analog mixer; mute as default */
3795 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3796 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3797 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3798 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3799 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3800 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3801 /* Analog Mix output amp */
3802 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3803 /* capture sources */
3804 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3805 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3806 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3807 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3808 /* SPDIF output amp */
3809 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3810 { } /* end */
3811};
3812
3813#ifdef CONFIG_SND_HDA_POWER_SAVE
3814static struct hda_amp_list ad1884a_loopbacks[] = {
3815 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3816 { 0x20, HDA_INPUT, 1 }, /* Mic */
3817 { 0x20, HDA_INPUT, 2 }, /* CD */
3818 { 0x20, HDA_INPUT, 4 }, /* Docking */
3819 { } /* end */
3820};
3821#endif
3822
3823/*
3824 * Laptop model
3825 *
3826 * Port A: Headphone jack
3827 * Port B: MIC jack
3828 * Port C: Internal MIC
3829 * Port D: Dock Line Out (if enabled)
3830 * Port E: Dock Line In (if enabled)
3831 * Port F: Internal speakers
3832 */
3833
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003834static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
3835 struct snd_ctl_elem_value *ucontrol)
3836{
3837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3838 int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3839 int mute = (!ucontrol->value.integer.value[0] &&
3840 !ucontrol->value.integer.value[1]);
3841 /* toggle GPIO1 according to the mute state */
3842 snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
3843 mute ? 0x02 : 0x0);
3844 return ret;
3845}
Takashi Iwaic5059252008-02-16 09:43:56 +01003846
3847static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3848 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003849 {
3850 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3851 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003852 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003853 .info = snd_hda_mixer_amp_switch_info,
3854 .get = snd_hda_mixer_amp_switch_get,
3855 .put = ad1884a_mobile_master_sw_put,
3856 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3857 },
Takashi Iwaic5059252008-02-16 09:43:56 +01003858 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3859 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3860 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3861 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3862 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3863 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3864 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3865 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3866 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003867 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3868 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3869 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3870 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3871 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaic5059252008-02-16 09:43:56 +01003872 { } /* end */
3873};
3874
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003875static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3876 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwai099db172009-07-02 16:10:23 +02003877 /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
3878 {
3879 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3880 .name = "Master Playback Switch",
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003881 .subdevice = HDA_SUBDEV_AMP_FLAG,
Takashi Iwai099db172009-07-02 16:10:23 +02003882 .info = snd_hda_mixer_amp_switch_info,
3883 .get = snd_hda_mixer_amp_switch_get,
3884 .put = ad1884a_mobile_master_sw_put,
3885 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
3886 },
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003887 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3888 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
Takashi Iwai269ef192008-05-30 15:32:15 +02003889 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3890 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003891 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3892 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003893 { } /* end */
3894};
3895
Takashi Iwaic5059252008-02-16 09:43:56 +01003896/* mute internal speaker if HP is plugged */
3897static void ad1884a_hp_automute(struct hda_codec *codec)
3898{
3899 unsigned int present;
3900
Takashi Iwaid56757a2009-11-18 08:00:14 +01003901 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaic5059252008-02-16 09:43:56 +01003902 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3903 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3904 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3905 present ? 0x00 : 0x02);
3906}
3907
Takashi Iwai269ef192008-05-30 15:32:15 +02003908/* switch to external mic if plugged */
3909static void ad1884a_hp_automic(struct hda_codec *codec)
3910{
3911 unsigned int present;
3912
Takashi Iwaid56757a2009-11-18 08:00:14 +01003913 present = snd_hda_jack_detect(codec, 0x14);
Takashi Iwai269ef192008-05-30 15:32:15 +02003914 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
3915 present ? 0 : 1);
3916}
3917
Takashi Iwaic5059252008-02-16 09:43:56 +01003918#define AD1884A_HP_EVENT 0x37
Takashi Iwai269ef192008-05-30 15:32:15 +02003919#define AD1884A_MIC_EVENT 0x36
Takashi Iwaic5059252008-02-16 09:43:56 +01003920
3921/* unsolicited event for HP jack sensing */
3922static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3923{
Takashi Iwai269ef192008-05-30 15:32:15 +02003924 switch (res >> 26) {
3925 case AD1884A_HP_EVENT:
3926 ad1884a_hp_automute(codec);
3927 break;
3928 case AD1884A_MIC_EVENT:
3929 ad1884a_hp_automic(codec);
3930 break;
3931 }
Takashi Iwaic5059252008-02-16 09:43:56 +01003932}
3933
3934/* initialize jack-sensing, too */
3935static int ad1884a_hp_init(struct hda_codec *codec)
3936{
3937 ad198x_init(codec);
3938 ad1884a_hp_automute(codec);
Takashi Iwai269ef192008-05-30 15:32:15 +02003939 ad1884a_hp_automic(codec);
Takashi Iwaic5059252008-02-16 09:43:56 +01003940 return 0;
3941}
3942
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003943/* mute internal speaker if HP or docking HP is plugged */
3944static void ad1884a_laptop_automute(struct hda_codec *codec)
3945{
3946 unsigned int present;
3947
Takashi Iwaid56757a2009-11-18 08:00:14 +01003948 present = snd_hda_jack_detect(codec, 0x11);
3949 if (!present)
3950 present = snd_hda_jack_detect(codec, 0x12);
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003951 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3952 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3953 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3954 present ? 0x00 : 0x02);
3955}
3956
3957/* switch to external mic if plugged */
3958static void ad1884a_laptop_automic(struct hda_codec *codec)
3959{
3960 unsigned int idx;
3961
Takashi Iwaid56757a2009-11-18 08:00:14 +01003962 if (snd_hda_jack_detect(codec, 0x14))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003963 idx = 0;
Takashi Iwaid56757a2009-11-18 08:00:14 +01003964 else if (snd_hda_jack_detect(codec, 0x1c))
Takashi Iwai17bbaa62009-08-30 12:15:59 +02003965 idx = 4;
3966 else
3967 idx = 1;
3968 snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
3969}
3970
3971/* unsolicited event for HP jack sensing */
3972static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
3973 unsigned int res)
3974{
3975 switch (res >> 26) {
3976 case AD1884A_HP_EVENT:
3977 ad1884a_laptop_automute(codec);
3978 break;
3979 case AD1884A_MIC_EVENT:
3980 ad1884a_laptop_automic(codec);
3981 break;
3982 }
3983}
3984
3985/* initialize jack-sensing, too */
3986static int ad1884a_laptop_init(struct hda_codec *codec)
3987{
3988 ad198x_init(codec);
3989 ad1884a_laptop_automute(codec);
3990 ad1884a_laptop_automic(codec);
3991 return 0;
3992}
3993
Takashi Iwaic5059252008-02-16 09:43:56 +01003994/* additional verbs for laptop model */
3995static struct hda_verb ad1884a_laptop_verbs[] = {
3996 /* Port-A (HP) pin - always unmuted */
3997 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3998 /* Port-F (int speaker) mixer - route only from analog mixer */
3999 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4000 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
Wu Fengguang150fe142009-08-19 16:58:59 +08004001 /* Port-F (int speaker) pin */
4002 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwaic5059252008-02-16 09:43:56 +01004003 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
Wu Fengguang150fe142009-08-19 16:58:59 +08004004 /* required for compaq 6530s/6531s speaker output */
4005 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Takashi Iwai269ef192008-05-30 15:32:15 +02004006 /* Port-C pin - internal mic-in */
4007 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4008 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4009 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
Takashi Iwai2ad81ba2009-09-01 09:09:26 +02004010 /* Port-D (docking line-out) pin - default unmuted */
4011 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaic5059252008-02-16 09:43:56 +01004012 /* analog mix */
4013 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4014 /* unsolicited event for pin-sense */
4015 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004016 {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
Takashi Iwai269ef192008-05-30 15:32:15 +02004017 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004018 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwaife7e5682009-08-31 08:37:46 +02004019 /* allow to touch GPIO1 (for mute control) */
4020 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4021 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4022 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwaic5059252008-02-16 09:43:56 +01004023 { } /* end */
4024};
4025
Takashi Iwai73156132009-04-23 08:24:48 +02004026static struct hda_verb ad1884a_mobile_verbs[] = {
4027 /* DACs; unmute as default */
4028 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4029 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4030 /* Port-A (HP) mixer - route only from analog mixer */
4031 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4032 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4033 /* Port-A pin */
4034 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4035 /* Port-A (HP) pin - always unmuted */
4036 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4037 /* Port-B (mic jack) pin */
4038 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4039 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4040 /* Port-C (int mic) pin */
4041 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4042 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
4043 /* Port-F (int speaker) mixer - route only from analog mixer */
4044 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4045 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4046 /* Port-F pin */
4047 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4048 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4049 /* Analog mixer; mute as default */
4050 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4051 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4052 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4053 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4054 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4055 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4056 /* Analog Mix output amp */
4057 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4058 /* capture sources */
4059 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4060 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4061 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4062 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4063 /* unsolicited event for pin-sense */
4064 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4065 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
Takashi Iwai099db172009-07-02 16:10:23 +02004066 /* allow to touch GPIO1 (for mute control) */
4067 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4068 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4069 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
Takashi Iwai73156132009-04-23 08:24:48 +02004070 { } /* end */
4071};
4072
Takashi Iwaic5059252008-02-16 09:43:56 +01004073/*
Takashi Iwaif0813742008-03-18 12:13:03 +01004074 * Thinkpad X300
4075 * 0x11 - HP
4076 * 0x12 - speaker
4077 * 0x14 - mic-in
4078 * 0x17 - built-in mic
4079 */
4080
4081static struct hda_verb ad1984a_thinkpad_verbs[] = {
4082 /* HP unmute */
4083 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4084 /* analog mix */
4085 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4086 /* turn on EAPD */
4087 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
4088 /* unsolicited event for pin-sense */
4089 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4090 /* internal mic - dmic */
4091 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwai05808ec2008-04-23 13:50:08 +02004092 /* set magic COEFs for dmic */
4093 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4094 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
Takashi Iwaif0813742008-03-18 12:13:03 +01004095 { } /* end */
4096};
4097
4098static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
4099 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4100 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
4101 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4102 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4103 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4104 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
Takashi Iwaif0813742008-03-18 12:13:03 +01004105 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
4106 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4107 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4108 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4109 {
4110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4111 .name = "Capture Source",
4112 .info = ad198x_mux_enum_info,
4113 .get = ad198x_mux_enum_get,
4114 .put = ad198x_mux_enum_put,
4115 },
4116 { } /* end */
4117};
4118
4119static struct hda_input_mux ad1984a_thinkpad_capture_source = {
4120 .num_items = 3,
4121 .items = {
4122 { "Mic", 0x0 },
4123 { "Internal Mic", 0x5 },
4124 { "Mix", 0x3 },
4125 },
4126};
4127
4128/* mute internal speaker if HP is plugged */
4129static void ad1984a_thinkpad_automute(struct hda_codec *codec)
4130{
4131 unsigned int present;
4132
Takashi Iwaid56757a2009-11-18 08:00:14 +01004133 present = snd_hda_jack_detect(codec, 0x11);
Takashi Iwaif0813742008-03-18 12:13:03 +01004134 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
4135 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
4136}
4137
4138/* unsolicited event for HP jack sensing */
4139static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
4140 unsigned int res)
4141{
4142 if ((res >> 26) != AD1884A_HP_EVENT)
4143 return;
4144 ad1984a_thinkpad_automute(codec);
4145}
4146
4147/* initialize jack-sensing, too */
4148static int ad1984a_thinkpad_init(struct hda_codec *codec)
4149{
4150 ad198x_init(codec);
4151 ad1984a_thinkpad_automute(codec);
4152 return 0;
4153}
4154
4155/*
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004156 * HP Touchsmart
4157 * port-A (0x11) - front hp-out
4158 * port-B (0x14) - unused
4159 * port-C (0x15) - unused
4160 * port-D (0x12) - rear line out
4161 * port-E (0x1c) - front mic-in
4162 * port-F (0x16) - Internal speakers
4163 * digital-mic (0x17) - Internal mic
4164 */
4165
4166static struct hda_verb ad1984a_touchsmart_verbs[] = {
4167 /* DACs; unmute as default */
4168 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4169 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
4170 /* Port-A (HP) mixer - route only from analog mixer */
4171 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4172 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4173 /* Port-A pin */
4174 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4175 /* Port-A (HP) pin - always unmuted */
4176 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4177 /* Port-E (int speaker) mixer - route only from analog mixer */
4178 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
4179 /* Port-E pin */
4180 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4181 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
4182 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4183 /* Port-F (int speaker) mixer - route only from analog mixer */
4184 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4185 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4186 /* Port-F pin */
4187 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4188 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4189 /* Analog mixer; mute as default */
4190 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4191 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4192 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4193 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4194 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4195 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4196 /* Analog Mix output amp */
4197 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4198 /* capture sources */
4199 /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
4200 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4201 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
4202 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4203 /* unsolicited event for pin-sense */
4204 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
4205 {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
4206 /* allow to touch GPIO1 (for mute control) */
4207 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
4208 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
4209 {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
4210 /* internal mic - dmic */
4211 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4212 /* set magic COEFs for dmic */
4213 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
4214 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
4215 { } /* end */
4216};
4217
4218static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
4219 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
4220/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
4221 {
4222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01004223 .subdevice = HDA_SUBDEV_AMP_FLAG,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004224 .name = "Master Playback Switch",
4225 .info = snd_hda_mixer_amp_switch_info,
4226 .get = snd_hda_mixer_amp_switch_get,
4227 .put = ad1884a_mobile_master_sw_put,
4228 .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
4229 },
4230 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
4231 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
4232 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4233 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4234 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
4235 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
4236 { } /* end */
4237};
4238
4239/* switch to external mic if plugged */
4240static void ad1984a_touchsmart_automic(struct hda_codec *codec)
4241{
Takashi Iwaid56757a2009-11-18 08:00:14 +01004242 if (snd_hda_jack_detect(codec, 0x1c))
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004243 snd_hda_codec_write(codec, 0x0c, 0,
4244 AC_VERB_SET_CONNECT_SEL, 0x4);
Takashi Iwaid56757a2009-11-18 08:00:14 +01004245 else
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004246 snd_hda_codec_write(codec, 0x0c, 0,
4247 AC_VERB_SET_CONNECT_SEL, 0x5);
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004248}
4249
4250
4251/* unsolicited event for HP jack sensing */
4252static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
4253 unsigned int res)
4254{
4255 switch (res >> 26) {
4256 case AD1884A_HP_EVENT:
4257 ad1884a_hp_automute(codec);
4258 break;
4259 case AD1884A_MIC_EVENT:
4260 ad1984a_touchsmart_automic(codec);
4261 break;
4262 }
4263}
4264
4265/* initialize jack-sensing, too */
4266static int ad1984a_touchsmart_init(struct hda_codec *codec)
4267{
4268 ad198x_init(codec);
4269 ad1884a_hp_automute(codec);
4270 ad1984a_touchsmart_automic(codec);
4271 return 0;
4272}
4273
4274
4275/*
Takashi Iwaic5059252008-02-16 09:43:56 +01004276 */
4277
4278enum {
4279 AD1884A_DESKTOP,
4280 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004281 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01004282 AD1884A_THINKPAD,
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004283 AD1984A_TOUCHSMART,
Takashi Iwaic5059252008-02-16 09:43:56 +01004284 AD1884A_MODELS
4285};
4286
4287static const char *ad1884a_models[AD1884A_MODELS] = {
4288 [AD1884A_DESKTOP] = "desktop",
4289 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004290 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01004291 [AD1884A_THINKPAD] = "thinkpad",
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004292 [AD1984A_TOUCHSMART] = "touchsmart",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004293};
4294
4295static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
4296 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaid5337de2009-01-07 11:41:57 +01004297 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
Takashi Iwai5695ff42008-10-28 15:39:26 +01004298 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
Takashi Iwaic2312752009-02-16 15:20:41 +01004299 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
Takashi Iwaiff848472009-07-01 18:08:01 +02004300 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai873dc782009-02-25 18:12:13 +01004301 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
4302 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
Takashi Iwai286f5872009-08-27 14:37:51 +02004303 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01004304 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004305 SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004306 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01004307};
4308
4309static int patch_ad1884a(struct hda_codec *codec)
4310{
4311 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004312 int err, board_config;
Takashi Iwaic5059252008-02-16 09:43:56 +01004313
4314 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4315 if (spec == NULL)
4316 return -ENOMEM;
4317
Takashi Iwaic5059252008-02-16 09:43:56 +01004318 codec->spec = spec;
4319
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004320 err = snd_hda_attach_beep_device(codec, 0x10);
4321 if (err < 0) {
4322 ad198x_free(codec);
4323 return err;
4324 }
4325 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4326
Takashi Iwaic5059252008-02-16 09:43:56 +01004327 spec->multiout.max_channels = 2;
4328 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
4329 spec->multiout.dac_nids = ad1884a_dac_nids;
4330 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
4331 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
4332 spec->adc_nids = ad1884a_adc_nids;
4333 spec->capsrc_nids = ad1884a_capsrc_nids;
4334 spec->input_mux = &ad1884a_capture_source;
4335 spec->num_mixers = 1;
4336 spec->mixers[0] = ad1884a_base_mixers;
4337 spec->num_init_verbs = 1;
4338 spec->init_verbs[0] = ad1884a_init_verbs;
4339 spec->spdif_route = 0;
4340#ifdef CONFIG_SND_HDA_POWER_SAVE
4341 spec->loopback.amplist = ad1884a_loopbacks;
4342#endif
4343 codec->patch_ops = ad198x_patch_ops;
4344
4345 /* override some parameters */
4346 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004347 ad1884a_models,
4348 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01004349 switch (board_config) {
4350 case AD1884A_LAPTOP:
4351 spec->mixers[0] = ad1884a_laptop_mixers;
4352 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
4353 spec->multiout.dig_out_nid = 0;
Takashi Iwai17bbaa62009-08-30 12:15:59 +02004354 codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
4355 codec->patch_ops.init = ad1884a_laptop_init;
Takashi Iwai4dc1f872009-04-16 14:19:19 +02004356 /* set the upper-limit for mixer amp to 0dB for avoiding the
4357 * possible damage by overloading
4358 */
4359 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4360 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4361 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4362 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4363 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaic5059252008-02-16 09:43:56 +01004364 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004365 case AD1884A_MOBILE:
4366 spec->mixers[0] = ad1884a_mobile_mixers;
Takashi Iwai73156132009-04-23 08:24:48 +02004367 spec->init_verbs[0] = ad1884a_mobile_verbs;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004368 spec->multiout.dig_out_nid = 0;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004369 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
4370 codec->patch_ops.init = ad1884a_hp_init;
Takashi Iwai13c989b2009-02-23 11:33:34 +01004371 /* set the upper-limit for mixer amp to 0dB for avoiding the
4372 * possible damage by overloading
4373 */
4374 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4375 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4376 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4377 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4378 (1 << AC_AMPCAP_MUTE_SHIFT));
Takashi Iwaib40b04a2008-02-16 09:44:56 +01004379 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01004380 case AD1884A_THINKPAD:
4381 spec->mixers[0] = ad1984a_thinkpad_mixers;
4382 spec->init_verbs[spec->num_init_verbs++] =
4383 ad1984a_thinkpad_verbs;
4384 spec->multiout.dig_out_nid = 0;
4385 spec->input_mux = &ad1984a_thinkpad_capture_source;
4386 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
4387 codec->patch_ops.init = ad1984a_thinkpad_init;
4388 break;
Miguel de Barrosa72cb4b2009-09-27 22:11:21 +02004389 case AD1984A_TOUCHSMART:
4390 spec->mixers[0] = ad1984a_touchsmart_mixers;
4391 spec->init_verbs[0] = ad1984a_touchsmart_verbs;
4392 spec->multiout.dig_out_nid = 0;
4393 codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
4394 codec->patch_ops.init = ad1984a_touchsmart_init;
4395 /* set the upper-limit for mixer amp to 0dB for avoiding the
4396 * possible damage by overloading
4397 */
4398 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
4399 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
4400 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4401 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4402 (1 << AC_AMPCAP_MUTE_SHIFT));
4403 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01004404 }
4405
Takashi Iwai729d55b2009-12-25 22:49:01 +01004406 codec->no_trigger_sense = 1;
4407
Takashi Iwaic5059252008-02-16 09:43:56 +01004408 return 0;
4409}
4410
4411
4412/*
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004413 * AD1882 / AD1882A
Takashi Iwai0ac85512007-06-20 15:46:13 +02004414 *
4415 * port-A - front hp-out
4416 * port-B - front mic-in
4417 * port-C - rear line-in, shared surr-out (3stack)
4418 * port-D - rear line-out
4419 * port-E - rear mic-in, shared clfe-out (3stack)
4420 * port-F - rear surr-out (6stack)
4421 * port-G - rear clfe-out (6stack)
4422 */
4423
4424static hda_nid_t ad1882_dac_nids[3] = {
4425 0x04, 0x03, 0x05
4426};
4427
4428static hda_nid_t ad1882_adc_nids[2] = {
4429 0x08, 0x09,
4430};
4431
4432static hda_nid_t ad1882_capsrc_nids[2] = {
4433 0x0c, 0x0d,
4434};
4435
4436#define AD1882_SPDIF_OUT 0x02
4437
4438/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
4439static struct hda_input_mux ad1882_capture_source = {
4440 .num_items = 5,
4441 .items = {
4442 { "Front Mic", 0x1 },
4443 { "Mic", 0x4 },
4444 { "Line", 0x2 },
4445 { "CD", 0x3 },
4446 { "Mix", 0x7 },
4447 },
4448};
4449
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004450/* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
4451static struct hda_input_mux ad1882a_capture_source = {
4452 .num_items = 5,
4453 .items = {
4454 { "Front Mic", 0x1 },
4455 { "Mic", 0x4},
4456 { "Line", 0x2 },
4457 { "Digital Mic", 0x06 },
4458 { "Mix", 0x7 },
4459 },
4460};
4461
Takashi Iwai0ac85512007-06-20 15:46:13 +02004462static struct snd_kcontrol_new ad1882_base_mixers[] = {
4463 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
4464 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
4465 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
4466 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
4467 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
4468 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
4469 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
4470 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004471
Takashi Iwai0ac85512007-06-20 15:46:13 +02004472 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
4473 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
4474 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
4475 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
4476 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
4477 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
4478 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
4479 {
4480 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4481 /* The multiple "Capture Source" controls confuse alsamixer
4482 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02004483 */
4484 /* .name = "Capture Source", */
4485 .name = "Input Source",
4486 .count = 2,
4487 .info = ad198x_mux_enum_info,
4488 .get = ad198x_mux_enum_get,
4489 .put = ad198x_mux_enum_put,
4490 },
4491 /* SPDIF controls */
4492 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
4493 {
4494 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4495 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4496 /* identical with ad1983 */
4497 .info = ad1983_spdif_route_info,
4498 .get = ad1983_spdif_route_get,
4499 .put = ad1983_spdif_route_put,
4500 },
4501 { } /* end */
4502};
4503
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004504static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4505 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4506 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4507 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
4508 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
4509 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
4510 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4511 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4512 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004513 { } /* end */
4514};
4515
4516static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4517 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
4518 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
4519 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
4520 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
4521 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
4522 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4523 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4524 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004525 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4526 { } /* end */
4527};
4528
Takashi Iwai0ac85512007-06-20 15:46:13 +02004529static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
4530 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
4531 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
4532 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
4533 {
4534 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4535 .name = "Channel Mode",
4536 .info = ad198x_ch_mode_info,
4537 .get = ad198x_ch_mode_get,
4538 .put = ad198x_ch_mode_put,
4539 },
4540 { } /* end */
4541};
4542
4543static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
4544 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
4545 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
4546 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
4547 { } /* end */
4548};
4549
4550static struct hda_verb ad1882_ch2_init[] = {
4551 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4552 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4553 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4554 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4555 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4556 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4557 { } /* end */
4558};
4559
4560static struct hda_verb ad1882_ch4_init[] = {
4561 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4562 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4563 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4564 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4565 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4566 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4567 { } /* end */
4568};
4569
4570static struct hda_verb ad1882_ch6_init[] = {
4571 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4572 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4573 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4574 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4575 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4576 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4577 { } /* end */
4578};
4579
4580static struct hda_channel_mode ad1882_modes[3] = {
4581 { 2, ad1882_ch2_init },
4582 { 4, ad1882_ch4_init },
4583 { 6, ad1882_ch6_init },
4584};
4585
4586/*
4587 * initialization verbs
4588 */
4589static struct hda_verb ad1882_init_verbs[] = {
4590 /* DACs; mute as default */
4591 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4592 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4593 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4594 /* Port-A (HP) mixer */
4595 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4596 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4597 /* Port-A pin */
4598 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4599 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4600 /* HP selector - select DAC2 */
4601 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4602 /* Port-D (Line-out) mixer */
4603 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4604 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4605 /* Port-D pin */
4606 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4607 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4608 /* Mono-out mixer */
4609 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4610 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4611 /* Mono-out pin */
4612 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4613 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4614 /* Port-B (front mic) pin */
4615 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4616 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4617 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4618 /* Port-C (line-in) pin */
4619 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4620 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4621 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4622 /* Port-C mixer - mute as input */
4623 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4624 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4625 /* Port-E (mic-in) pin */
4626 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4627 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4628 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4629 /* Port-E mixer - mute as input */
4630 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4631 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4632 /* Port-F (surround) */
4633 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4634 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4635 /* Port-G (CLFE) */
4636 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4637 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4638 /* Analog mixer; mute as default */
4639 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4640 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4641 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4642 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4643 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4644 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4645 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4646 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4647 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4648 /* Analog Mix output amp */
4649 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4650 /* SPDIF output selector */
4651 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4652 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4653 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4654 { } /* end */
4655};
4656
Takashi Iwaicb53c622007-08-10 17:21:45 +02004657#ifdef CONFIG_SND_HDA_POWER_SAVE
4658static struct hda_amp_list ad1882_loopbacks[] = {
4659 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4660 { 0x20, HDA_INPUT, 1 }, /* Mic */
4661 { 0x20, HDA_INPUT, 4 }, /* Line */
4662 { 0x20, HDA_INPUT, 6 }, /* CD */
4663 { } /* end */
4664};
4665#endif
4666
Takashi Iwai0ac85512007-06-20 15:46:13 +02004667/* models */
4668enum {
4669 AD1882_3STACK,
4670 AD1882_6STACK,
4671 AD1882_MODELS
4672};
4673
4674static const char *ad1882_models[AD1986A_MODELS] = {
4675 [AD1882_3STACK] = "3stack",
4676 [AD1882_6STACK] = "6stack",
4677};
4678
4679
4680static int patch_ad1882(struct hda_codec *codec)
4681{
4682 struct ad198x_spec *spec;
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004683 int err, board_config;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004684
4685 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4686 if (spec == NULL)
4687 return -ENOMEM;
4688
Takashi Iwai0ac85512007-06-20 15:46:13 +02004689 codec->spec = spec;
4690
Takashi Iwaic5a4bcd2009-02-06 17:22:05 +01004691 err = snd_hda_attach_beep_device(codec, 0x10);
4692 if (err < 0) {
4693 ad198x_free(codec);
4694 return err;
4695 }
4696 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4697
Takashi Iwai0ac85512007-06-20 15:46:13 +02004698 spec->multiout.max_channels = 6;
4699 spec->multiout.num_dacs = 3;
4700 spec->multiout.dac_nids = ad1882_dac_nids;
4701 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4702 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4703 spec->adc_nids = ad1882_adc_nids;
4704 spec->capsrc_nids = ad1882_capsrc_nids;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004705 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004706 spec->input_mux = &ad1882_capture_source;
4707 else
4708 spec->input_mux = &ad1882a_capture_source;
4709 spec->num_mixers = 2;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004710 spec->mixers[0] = ad1882_base_mixers;
Clemens Fruhwirthc247ed62009-01-07 11:43:48 +01004711 if (codec->vendor_id == 0x11d41882)
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004712 spec->mixers[1] = ad1882_loopback_mixers;
4713 else
4714 spec->mixers[1] = ad1882a_loopback_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004715 spec->num_init_verbs = 1;
4716 spec->init_verbs[0] = ad1882_init_verbs;
4717 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004718#ifdef CONFIG_SND_HDA_POWER_SAVE
4719 spec->loopback.amplist = ad1882_loopbacks;
4720#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004721 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004722
4723 codec->patch_ops = ad198x_patch_ops;
4724
4725 /* override some parameters */
4726 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4727 ad1882_models, NULL);
4728 switch (board_config) {
4729 default:
4730 case AD1882_3STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004731 spec->num_mixers = 3;
4732 spec->mixers[2] = ad1882_3stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004733 spec->channel_mode = ad1882_modes;
4734 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4735 spec->need_dac_fix = 1;
4736 spec->multiout.max_channels = 2;
4737 spec->multiout.num_dacs = 1;
4738 break;
4739 case AD1882_6STACK:
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004740 spec->num_mixers = 3;
4741 spec->mixers[2] = ad1882_6stack_mixers;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004742 break;
4743 }
Takashi Iwai729d55b2009-12-25 22:49:01 +01004744
4745 codec->no_trigger_sense = 1;
4746
Takashi Iwai0ac85512007-06-20 15:46:13 +02004747 return 0;
4748}
4749
4750
4751/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 * patch entries
4753 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004754static struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004755 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004756 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004757 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004758 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004759 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4760 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004761 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4762 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004763 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004765 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004766 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Takashi Iwai9e44c6e2008-08-18 13:53:07 +02004767 { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
Takashi Iwai3adb8ab2008-04-15 18:46:42 +02004768 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4769 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 {} /* terminator */
4771};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01004772
4773MODULE_ALIAS("snd-hda-codec-id:11d4*");
4774
4775MODULE_LICENSE("GPL");
4776MODULE_DESCRIPTION("Analog Devices HD-audio codec");
4777
4778static struct hda_codec_preset_list analog_list = {
4779 .preset = snd_hda_preset_analog,
4780 .owner = THIS_MODULE,
4781};
4782
4783static int __init patch_analog_init(void)
4784{
4785 return snd_hda_add_codec_preset(&analog_list);
4786}
4787
4788static void __exit patch_analog_exit(void)
4789{
4790 snd_hda_delete_codec_preset(&analog_list);
4791}
4792
4793module_init(patch_analog_init)
4794module_exit(patch_analog_exit)