blob: 2befeebd909e6679d342cbea7e1c8aa6d8523810 [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#include <linux/mutex.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <sound/core.h>
29#include "hda_codec.h"
30#include "hda_local.h"
Harvey Harrison3c9a3202008-02-29 11:59:26 +010031#include "hda_patch.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020033struct ad198x_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010034 struct snd_kcontrol_new *mixers[5];
Takashi Iwai985be542005-11-02 18:26:49 +010035 int num_mixers;
36
Takashi Iwaid32410b12005-11-24 16:06:23 +010037 const struct hda_verb *init_verbs[5]; /* initialization verbs
Takashi Iwai985be542005-11-02 18:26:49 +010038 * don't forget NULL termination!
39 */
40 unsigned int num_init_verbs;
41
42 /* playback */
43 struct hda_multi_out multiout; /* playback set-up
44 * max_channels, dacs must be set
45 * dig_out_nid and hp_nid are optional
46 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +010047 unsigned int cur_eapd;
Takashi Iwai2125cad2006-03-27 12:52:22 +020048 unsigned int need_dac_fix;
Takashi Iwai985be542005-11-02 18:26:49 +010049
50 /* capture */
51 unsigned int num_adc_nids;
52 hda_nid_t *adc_nids;
53 hda_nid_t dig_in_nid; /* digital-in NID; optional */
54
55 /* capture source */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020056 const struct hda_input_mux *input_mux;
Takashi Iwai2e5b9562005-11-21 16:36:15 +010057 hda_nid_t *capsrc_nids;
Takashi Iwai985be542005-11-02 18:26:49 +010058 unsigned int cur_mux[3];
59
60 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +010061 const struct hda_channel_mode *channel_mode;
Takashi Iwai985be542005-11-02 18:26:49 +010062 int num_channel_mode;
63
64 /* PCM information */
Takashi Iwai2bac6472007-05-18 18:21:41 +020065 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai985be542005-11-02 18:26:49 +010066
Ingo Molnar62932df2006-01-16 16:34:20 +010067 struct mutex amp_mutex; /* PCM volume/mute control mutex */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020068 unsigned int spdif_route;
Takashi Iwaid32410b12005-11-24 16:06:23 +010069
70 /* dynamic controls, init_verbs and input_mux */
71 struct auto_pin_cfg autocfg;
72 unsigned int num_kctl_alloc, num_kctl_used;
73 struct snd_kcontrol_new *kctl_alloc;
74 struct hda_input_mux private_imux;
Takashi Iwai41923e42007-10-22 17:20:10 +020075 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwaicb53c622007-08-10 17:21:45 +020076
Takashi Iwai8ab78c72007-09-06 14:29:53 +020077 unsigned int jack_present :1;
78
Takashi Iwaicb53c622007-08-10 17:21:45 +020079#ifdef CONFIG_SND_HDA_POWER_SAVE
80 struct hda_loopback_check loopback;
81#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +010082 /* for virtual master */
83 hda_nid_t vmaster_nid;
Takashi Iwai2134ea42008-01-10 16:53:55 +010084 const char **slave_vols;
85 const char **slave_sws;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020088/*
89 * input MUX handling (common part)
90 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010091static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +020092{
93 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
94 struct ad198x_spec *spec = codec->spec;
95
96 return snd_hda_input_mux_info(spec->input_mux, uinfo);
97}
98
Takashi Iwaic8b6bf92005-11-17 14:57:47 +010099static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200100{
101 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
102 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100103 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200104
Takashi Iwai985be542005-11-02 18:26:49 +0100105 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200106 return 0;
107}
108
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100109static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200110{
111 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
112 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100113 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200114
115 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Takashi Iwai2e5b9562005-11-21 16:36:15 +0100116 spec->capsrc_nids[adc_idx],
117 &spec->cur_mux[adc_idx]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200118}
119
120/*
121 * initialization (common callbacks)
122 */
123static int ad198x_init(struct hda_codec *codec)
124{
125 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100126 int i;
127
128 for (i = 0; i < spec->num_init_verbs; i++)
129 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200130 return 0;
131}
132
Takashi Iwai2134ea42008-01-10 16:53:55 +0100133static const char *ad_slave_vols[] = {
134 "Front Playback Volume",
135 "Surround Playback Volume",
136 "Center Playback Volume",
137 "LFE Playback Volume",
138 "Side Playback Volume",
139 "Headphone Playback Volume",
140 "Mono Playback Volume",
Takashi Iwai628ed132008-01-25 11:56:57 +0100141 "Speaker Playback Volume",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100142 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100143 NULL
144};
145
146static const char *ad_slave_sws[] = {
147 "Front Playback Switch",
148 "Surround Playback Switch",
149 "Center Playback Switch",
150 "LFE Playback Switch",
151 "Side Playback Switch",
152 "Headphone Playback Switch",
153 "Mono Playback Switch",
Takashi Iwai628ed132008-01-25 11:56:57 +0100154 "Speaker Playback Switch",
Takashi Iwai4806ef02008-01-26 09:58:13 +0100155 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100156 NULL
157};
158
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200159static int ad198x_build_controls(struct hda_codec *codec)
160{
161 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100162 unsigned int i;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200163 int err;
164
Takashi Iwai985be542005-11-02 18:26:49 +0100165 for (i = 0; i < spec->num_mixers; i++) {
166 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
167 if (err < 0)
168 return err;
169 }
170 if (spec->multiout.dig_out_nid) {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
Takashi Iwai985be542005-11-02 18:26:49 +0100172 if (err < 0)
173 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100174 err = snd_hda_create_spdif_share_sw(codec,
175 &spec->multiout);
176 if (err < 0)
177 return err;
178 spec->multiout.share_spdif = 1;
Takashi Iwai985be542005-11-02 18:26:49 +0100179 }
180 if (spec->dig_in_nid) {
181 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
182 if (err < 0)
183 return err;
184 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100185
186 /* if we have no master control, let's create it */
187 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100188 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100189 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100190 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100191 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100192 vmaster_tlv,
Takashi Iwai2134ea42008-01-10 16:53:55 +0100193 (spec->slave_vols ?
194 spec->slave_vols : ad_slave_vols));
195 if (err < 0)
196 return err;
197 }
198 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
199 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
200 NULL,
201 (spec->slave_sws ?
202 spec->slave_sws : ad_slave_sws));
203 if (err < 0)
204 return err;
205 }
206
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200207 return 0;
208}
209
Takashi Iwaicb53c622007-08-10 17:21:45 +0200210#ifdef CONFIG_SND_HDA_POWER_SAVE
211static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
212{
213 struct ad198x_spec *spec = codec->spec;
214 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
215}
216#endif
217
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200218/*
219 * Analog playback callbacks
220 */
221static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
222 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100223 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200224{
225 struct ad198x_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +0100226 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
227 hinfo);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200228}
229
230static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
231 struct hda_codec *codec,
232 unsigned int stream_tag,
233 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100234 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200235{
236 struct ad198x_spec *spec = codec->spec;
237 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
238 format, substream);
239}
240
241static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
242 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100243 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200244{
245 struct ad198x_spec *spec = codec->spec;
246 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
247}
248
249/*
250 * Digital out
251 */
252static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
253 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100254 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200255{
256 struct ad198x_spec *spec = codec->spec;
257 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
258}
259
260static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
261 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100262 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200263{
264 struct ad198x_spec *spec = codec->spec;
265 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
266}
267
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200268static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
269 struct hda_codec *codec,
270 unsigned int stream_tag,
271 unsigned int format,
272 struct snd_pcm_substream *substream)
273{
274 struct ad198x_spec *spec = codec->spec;
275 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
276 format, substream);
277}
278
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200279/*
280 * Analog capture
281 */
282static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
283 struct hda_codec *codec,
284 unsigned int stream_tag,
285 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100286 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200287{
288 struct ad198x_spec *spec = codec->spec;
Takashi Iwai985be542005-11-02 18:26:49 +0100289 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
290 stream_tag, 0, format);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200291 return 0;
292}
293
294static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
295 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100296 struct snd_pcm_substream *substream)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200297{
298 struct ad198x_spec *spec = codec->spec;
Takashi Iwai888afa12008-03-18 09:57:50 +0100299 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200300 return 0;
301}
302
303
304/*
305 */
306static struct hda_pcm_stream ad198x_pcm_analog_playback = {
307 .substreams = 1,
308 .channels_min = 2,
Takashi Iwai985be542005-11-02 18:26:49 +0100309 .channels_max = 6, /* changed later */
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200310 .nid = 0, /* fill later */
311 .ops = {
312 .open = ad198x_playback_pcm_open,
313 .prepare = ad198x_playback_pcm_prepare,
314 .cleanup = ad198x_playback_pcm_cleanup
315 },
316};
317
318static struct hda_pcm_stream ad198x_pcm_analog_capture = {
Takashi Iwai985be542005-11-02 18:26:49 +0100319 .substreams = 1,
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200320 .channels_min = 2,
321 .channels_max = 2,
322 .nid = 0, /* fill later */
323 .ops = {
324 .prepare = ad198x_capture_pcm_prepare,
325 .cleanup = ad198x_capture_pcm_cleanup
326 },
327};
328
329static struct hda_pcm_stream ad198x_pcm_digital_playback = {
330 .substreams = 1,
331 .channels_min = 2,
332 .channels_max = 2,
333 .nid = 0, /* fill later */
334 .ops = {
335 .open = ad198x_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +0200336 .close = ad198x_dig_playback_pcm_close,
337 .prepare = ad198x_dig_playback_pcm_prepare
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200338 },
339};
340
Takashi Iwai985be542005-11-02 18:26:49 +0100341static struct hda_pcm_stream ad198x_pcm_digital_capture = {
342 .substreams = 1,
343 .channels_min = 2,
344 .channels_max = 2,
345 /* NID is set in alc_build_pcms */
346};
347
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200348static int ad198x_build_pcms(struct hda_codec *codec)
349{
350 struct ad198x_spec *spec = codec->spec;
351 struct hda_pcm *info = spec->pcm_rec;
352
353 codec->num_pcms = 1;
354 codec->pcm_info = info;
355
356 info->name = "AD198x Analog";
357 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
358 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
360 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
Takashi Iwai985be542005-11-02 18:26:49 +0100361 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
362 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200363
364 if (spec->multiout.dig_out_nid) {
365 info++;
366 codec->num_pcms++;
367 info->name = "AD198x Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +0100368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
Takashi Iwai985be542005-11-02 18:26:49 +0100371 if (spec->dig_in_nid) {
372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
374 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200375 }
376
377 return 0;
378}
379
380static void ad198x_free(struct hda_codec *codec)
381{
Takashi Iwaid32410b12005-11-24 16:06:23 +0100382 struct ad198x_spec *spec = codec->spec;
383 unsigned int i;
384
385 if (spec->kctl_alloc) {
386 for (i = 0; i < spec->num_kctl_used; i++)
387 kfree(spec->kctl_alloc[i].name);
388 kfree(spec->kctl_alloc);
389 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200390 kfree(codec->spec);
391}
392
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200393static struct hda_codec_ops ad198x_patch_ops = {
394 .build_controls = ad198x_build_controls,
395 .build_pcms = ad198x_build_pcms,
396 .init = ad198x_init,
397 .free = ad198x_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +0200398#ifdef CONFIG_SND_HDA_POWER_SAVE
399 .check_power_status = ad198x_check_power_status,
400#endif
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200401};
402
403
404/*
Takashi Iwai18a815d2006-03-01 19:54:39 +0100405 * EAPD control
406 * the private value = nid | (invert << 8)
407 */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200408#define ad198x_eapd_info snd_ctl_boolean_mono_info
Takashi Iwai18a815d2006-03-01 19:54:39 +0100409
410static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
411 struct snd_ctl_elem_value *ucontrol)
412{
413 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
414 struct ad198x_spec *spec = codec->spec;
415 int invert = (kcontrol->private_value >> 8) & 1;
416 if (invert)
417 ucontrol->value.integer.value[0] = ! spec->cur_eapd;
418 else
419 ucontrol->value.integer.value[0] = spec->cur_eapd;
420 return 0;
421}
422
423static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
424 struct snd_ctl_elem_value *ucontrol)
425{
426 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
427 struct ad198x_spec *spec = codec->spec;
428 int invert = (kcontrol->private_value >> 8) & 1;
429 hda_nid_t nid = kcontrol->private_value & 0xff;
430 unsigned int eapd;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100431 eapd = !!ucontrol->value.integer.value[0];
Takashi Iwai18a815d2006-03-01 19:54:39 +0100432 if (invert)
433 eapd = !eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200434 if (eapd == spec->cur_eapd)
Takashi Iwai18a815d2006-03-01 19:54:39 +0100435 return 0;
436 spec->cur_eapd = eapd;
Takashi Iwai82beb8f2007-08-10 17:09:26 +0200437 snd_hda_codec_write_cache(codec, nid,
438 0, AC_VERB_SET_EAPD_BTLENABLE,
439 eapd ? 0x02 : 0x00);
Takashi Iwai18a815d2006-03-01 19:54:39 +0100440 return 1;
441}
442
Takashi Iwai9230d212006-03-13 13:49:49 +0100443static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
444 struct snd_ctl_elem_info *uinfo);
445static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
446 struct snd_ctl_elem_value *ucontrol);
447static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
448 struct snd_ctl_elem_value *ucontrol);
449
450
Takashi Iwai18a815d2006-03-01 19:54:39 +0100451/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200452 * AD1986A specific
453 */
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define AD1986A_SPDIF_OUT 0x02
456#define AD1986A_FRONT_DAC 0x03
457#define AD1986A_SURR_DAC 0x04
458#define AD1986A_CLFE_DAC 0x05
459#define AD1986A_ADC 0x06
460
461static hda_nid_t ad1986a_dac_nids[3] = {
462 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
463};
Takashi Iwai985be542005-11-02 18:26:49 +0100464static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100465static hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467static struct hda_input_mux ad1986a_capture_source = {
468 .num_items = 7,
469 .items = {
470 { "Mic", 0x0 },
471 { "CD", 0x1 },
472 { "Aux", 0x3 },
473 { "Line", 0x4 },
474 { "Mix", 0x5 },
475 { "Mono", 0x6 },
476 { "Phone", 0x7 },
477 },
478};
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Takashi Iwai532d5382007-07-27 19:02:40 +0200481static struct hda_bind_ctls ad1986a_bind_pcm_vol = {
482 .ops = &snd_hda_bind_vol,
483 .values = {
484 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
485 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
486 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
487 0
488 },
489};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Takashi Iwai532d5382007-07-27 19:02:40 +0200491static struct hda_bind_ctls ad1986a_bind_pcm_sw = {
492 .ops = &snd_hda_bind_sw,
493 .values = {
494 HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
495 HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
496 HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
497 0
498 },
499};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 * mixers
503 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100504static struct snd_kcontrol_new ad1986a_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200505 /*
506 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
507 */
508 HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
509 HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
511 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
512 HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
513 HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
514 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
515 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
516 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
517 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
518 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
521 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
522 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
524 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
525 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
526 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
527 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100528 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
530 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
532 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
533 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
534 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
535 {
536 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
537 .name = "Capture Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200538 .info = ad198x_mux_enum_info,
539 .get = ad198x_mux_enum_get,
540 .put = ad198x_mux_enum_put,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 },
542 HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
543 { } /* end */
544};
545
Takashi Iwai9230d212006-03-13 13:49:49 +0100546/* additional mixers for 3stack mode */
547static struct snd_kcontrol_new ad1986a_3st_mixers[] = {
548 {
549 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
550 .name = "Channel Mode",
551 .info = ad198x_ch_mode_info,
552 .get = ad198x_ch_mode_get,
553 .put = ad198x_ch_mode_put,
554 },
555 { } /* end */
556};
557
558/* laptop model - 2ch only */
559static hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
560
Takashi Iwai20a45e82007-08-15 22:20:45 +0200561/* master controls both pins 0x1a and 0x1b */
562static struct hda_bind_ctls ad1986a_laptop_master_vol = {
563 .ops = &snd_hda_bind_vol,
564 .values = {
565 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
566 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
567 0,
568 },
569};
570
571static struct hda_bind_ctls ad1986a_laptop_master_sw = {
572 .ops = &snd_hda_bind_sw,
573 .values = {
574 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
575 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
576 0,
577 },
578};
579
Takashi Iwai9230d212006-03-13 13:49:49 +0100580static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
581 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
582 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai20a45e82007-08-15 22:20:45 +0200583 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
584 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai9230d212006-03-13 13:49:49 +0100585 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
586 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
587 HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
588 HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
589 HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
590 HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
591 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
592 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100593 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai9230d212006-03-13 13:49:49 +0100594 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
595 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
596 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
597 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
598 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
599 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
600 {
601 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
602 .name = "Capture Source",
603 .info = ad198x_mux_enum_info,
604 .get = ad198x_mux_enum_get,
605 .put = ad198x_mux_enum_put,
606 },
607 { } /* end */
608};
609
Takashi Iwai825aa9722006-03-17 10:50:49 +0100610/* laptop-eapd model - 2ch only */
611
Takashi Iwai825aa9722006-03-17 10:50:49 +0100612static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
613 .num_items = 3,
614 .items = {
615 { "Mic", 0x0 },
616 { "Internal Mic", 0x4 },
617 { "Mix", 0x5 },
618 },
619};
620
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100621static struct hda_input_mux ad1986a_automic_capture_source = {
622 .num_items = 2,
623 .items = {
624 { "Mic", 0x0 },
625 { "Mix", 0x5 },
626 },
627};
628
Takashi Iwai825aa9722006-03-17 10:50:49 +0100629static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
Takashi Iwai532d5382007-07-27 19:02:40 +0200630 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
631 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
Takashi Iwai825aa9722006-03-17 10:50:49 +0100632 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
633 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
Takashi Iwai825aa9722006-03-17 10:50:49 +0100634 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
635 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Takashi Iwaife8970b2007-02-26 16:00:34 +0100636 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
Takashi Iwai825aa9722006-03-17 10:50:49 +0100637 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
638 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
639 {
640 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
641 .name = "Capture Source",
642 .info = ad198x_mux_enum_info,
643 .get = ad198x_mux_enum_get,
644 .put = ad198x_mux_enum_put,
645 },
646 {
647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
648 .name = "External Amplifier",
649 .info = ad198x_eapd_info,
650 .get = ad198x_eapd_get,
651 .put = ad198x_eapd_put,
652 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
653 },
654 { } /* end */
655};
656
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100657/* re-connect the mic boost input according to the jack sensing */
658static void ad1986a_automic(struct hda_codec *codec)
659{
660 unsigned int present;
661 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
662 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
663 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
664 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
665}
666
667#define AD1986A_MIC_EVENT 0x36
668
669static void ad1986a_automic_unsol_event(struct hda_codec *codec,
670 unsigned int res)
671{
672 if ((res >> 26) != AD1986A_MIC_EVENT)
673 return;
674 ad1986a_automic(codec);
675}
676
677static int ad1986a_automic_init(struct hda_codec *codec)
678{
679 ad198x_init(codec);
680 ad1986a_automic(codec);
681 return 0;
682}
683
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200684/* laptop-automute - 2ch only */
685
686static void ad1986a_update_hp(struct hda_codec *codec)
687{
688 struct ad198x_spec *spec = codec->spec;
689 unsigned int mute;
690
691 if (spec->jack_present)
692 mute = HDA_AMP_MUTE; /* mute internal speaker */
693 else
694 /* unmute internal speaker if necessary */
695 mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
696 snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
697 HDA_AMP_MUTE, mute);
698}
699
700static void ad1986a_hp_automute(struct hda_codec *codec)
701{
702 struct ad198x_spec *spec = codec->spec;
703 unsigned int present;
704
705 present = snd_hda_codec_read(codec, 0x1a, 0, AC_VERB_GET_PIN_SENSE, 0);
Takashi Iwai53eb1b82007-10-17 10:09:32 +0200706 /* Lenovo N100 seems to report the reversed bit for HP jack-sensing */
707 spec->jack_present = !(present & 0x80000000);
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200708 ad1986a_update_hp(codec);
709}
710
711#define AD1986A_HP_EVENT 0x37
712
713static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
714{
715 if ((res >> 26) != AD1986A_HP_EVENT)
716 return;
717 ad1986a_hp_automute(codec);
718}
719
720static int ad1986a_hp_init(struct hda_codec *codec)
721{
722 ad198x_init(codec);
723 ad1986a_hp_automute(codec);
724 return 0;
725}
726
727/* bind hp and internal speaker mute (with plug check) */
728static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
730{
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732 long *valp = ucontrol->value.integer.value;
733 int change;
734
735 change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
736 HDA_AMP_MUTE,
737 valp[0] ? 0 : HDA_AMP_MUTE);
738 change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
739 HDA_AMP_MUTE,
740 valp[1] ? 0 : HDA_AMP_MUTE);
741 if (change)
742 ad1986a_update_hp(codec);
743 return change;
744}
745
746static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
747 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
748 {
749 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
750 .name = "Master Playback Switch",
751 .info = snd_hda_mixer_amp_switch_info,
752 .get = snd_hda_mixer_amp_switch_get,
753 .put = ad1986a_hp_master_sw_put,
754 .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
755 },
756 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
757 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
758 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
759 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
760 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
761 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
762 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
763 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
764 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
765 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
766 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
767 {
768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
769 .name = "Capture Source",
770 .info = ad198x_mux_enum_info,
771 .get = ad198x_mux_enum_get,
772 .put = ad198x_mux_enum_put,
773 },
774 {
775 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
776 .name = "External Amplifier",
777 .info = ad198x_eapd_info,
778 .get = ad198x_eapd_get,
779 .put = ad198x_eapd_put,
780 .private_value = 0x1b | (1 << 8), /* port-D, inversed */
781 },
782 { } /* end */
783};
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785/*
786 * initialization verbs
787 */
788static struct hda_verb ad1986a_init_verbs[] = {
789 /* Front, Surround, CLFE DAC; mute as default */
790 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
791 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
792 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
793 /* Downmix - off */
794 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
795 /* HP, Line-Out, Surround, CLFE selectors */
796 {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
797 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
798 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
799 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
800 /* Mono selector */
801 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
802 /* Mic selector: Mic 1/2 pin */
803 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
804 /* Line-in selector: Line-in */
805 {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
806 /* Mic 1/2 swap */
807 {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
808 /* Record selector: mic */
809 {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
810 /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
811 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
812 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
813 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
814 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
815 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
816 /* PC beep */
817 {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
818 /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
819 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
820 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
821 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
822 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
823 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200824 /* HP Pin */
825 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
826 /* Front, Surround, CLFE Pins */
827 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
828 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
829 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
830 /* Mono Pin */
831 {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
832 /* Mic Pin */
833 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
834 /* Line, Aux, CD, Beep-In Pin */
835 {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
836 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
837 {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
838 {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
839 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 { } /* end */
841};
842
Takashi Iwai9230d212006-03-13 13:49:49 +0100843static struct hda_verb ad1986a_ch2_init[] = {
844 /* Surround out -> Line In */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200845 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
846 /* Line-in selectors */
847 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100848 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200849 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
850 /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
851 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100852 { } /* end */
853};
854
855static struct hda_verb ad1986a_ch4_init[] = {
856 /* Surround out -> Surround */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200857 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
858 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100859 /* CLFE -> Mic in */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200860 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
861 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100862 { } /* end */
863};
864
865static struct hda_verb ad1986a_ch6_init[] = {
866 /* Surround out -> Surround out */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200867 { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
868 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100869 /* CLFE -> CLFE */
Takashi Iwaifb956c12007-04-18 23:03:56 +0200870 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
871 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
Takashi Iwai9230d212006-03-13 13:49:49 +0100872 { } /* end */
873};
874
875static struct hda_channel_mode ad1986a_modes[3] = {
876 { 2, ad1986a_ch2_init },
877 { 4, ad1986a_ch4_init },
878 { 6, ad1986a_ch6_init },
879};
880
Takashi Iwai825aa9722006-03-17 10:50:49 +0100881/* eapd initialization */
882static struct hda_verb ad1986a_eapd_init_verbs[] = {
Tobin Davisf36090f2007-01-08 11:07:12 +0100883 {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
Takashi Iwai825aa9722006-03-17 10:50:49 +0100884 {}
885};
886
Takashi Iwai5d5d5f42008-02-12 12:11:36 +0100887static struct hda_verb ad1986a_automic_verbs[] = {
888 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
889 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
890 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
891 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
892 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
893 {}
894};
895
Tobin Davisf36090f2007-01-08 11:07:12 +0100896/* Ultra initialization */
897static struct hda_verb ad1986a_ultra_init[] = {
898 /* eapd initialization */
899 { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
900 /* CLFE -> Mic in */
901 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
902 { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
903 { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
904 { } /* end */
905};
906
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200907/* pin sensing on HP jack */
908static struct hda_verb ad1986a_hp_init_verbs[] = {
909 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
910 {}
911};
912
913
Takashi Iwai9230d212006-03-13 13:49:49 +0100914/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100915enum {
916 AD1986A_6STACK,
917 AD1986A_3STACK,
918 AD1986A_LAPTOP,
919 AD1986A_LAPTOP_EAPD,
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200920 AD1986A_LAPTOP_AUTOMUTE,
Tobin Davisf36090f2007-01-08 11:07:12 +0100921 AD1986A_ULTRA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100922 AD1986A_MODELS
923};
Takashi Iwai9230d212006-03-13 13:49:49 +0100924
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100925static const char *ad1986a_models[AD1986A_MODELS] = {
926 [AD1986A_6STACK] = "6stack",
927 [AD1986A_3STACK] = "3stack",
928 [AD1986A_LAPTOP] = "laptop",
929 [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200930 [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
Tobin Davisf36090f2007-01-08 11:07:12 +0100931 [AD1986A_ULTRA] = "ultra",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100932};
933
934static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
935 SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100936 SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100937 SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +0100938 SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100939 SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
940 SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
941 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
942 SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
Tobin Davisd9f9b8b2007-11-05 15:13:51 +0100943 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
Tobin Davis658fba02007-04-23 16:41:12 +0200944 SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100945 SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
946 SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
947 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
948 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
949 SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
Takashi Iwaiac3e3742007-12-17 17:14:18 +0100950 SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
Takashi Iwai7db756f2007-12-24 14:36:09 +0100951 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
Tobin Davis18768992007-03-12 22:20:51 +0100952 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100953 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
954 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
955 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
956 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
Tobin Davisf36090f2007-01-08 11:07:12 +0100957 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
Takashi Iwaiac3e3742007-12-17 17:14:18 +0100958 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
Tobin Davis18768992007-03-12 22:20:51 +0100959 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100960 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
Takashi Iwai8ab78c72007-09-06 14:29:53 +0200961 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100962 SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
Takashi Iwai9230d212006-03-13 13:49:49 +0100963 {}
964};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Takashi Iwaicb53c622007-08-10 17:21:45 +0200966#ifdef CONFIG_SND_HDA_POWER_SAVE
967static struct hda_amp_list ad1986a_loopbacks[] = {
968 { 0x13, HDA_OUTPUT, 0 }, /* Mic */
969 { 0x14, HDA_OUTPUT, 0 }, /* Phone */
970 { 0x15, HDA_OUTPUT, 0 }, /* CD */
971 { 0x16, HDA_OUTPUT, 0 }, /* Aux */
972 { 0x17, HDA_OUTPUT, 0 }, /* Line */
973 { } /* end */
974};
975#endif
976
Takashi Iwai8c0d9642008-01-28 12:30:17 +0100977static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
978{
979 unsigned int conf = snd_hda_codec_read(codec, nid, 0,
980 AC_VERB_GET_CONFIG_DEFAULT, 0);
981 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
982}
983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984static int patch_ad1986a(struct hda_codec *codec)
985{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200986 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100987 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200989 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 if (spec == NULL)
991 return -ENOMEM;
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 codec->spec = spec;
994
995 spec->multiout.max_channels = 6;
996 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
997 spec->multiout.dac_nids = ad1986a_dac_nids;
998 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100999 spec->num_adc_nids = 1;
1000 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +01001001 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001002 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001003 spec->num_mixers = 1;
1004 spec->mixers[0] = ad1986a_mixers;
1005 spec->num_init_verbs = 1;
1006 spec->init_verbs[0] = ad1986a_init_verbs;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001007#ifdef CONFIG_SND_HDA_POWER_SAVE
1008 spec->loopback.amplist = ad1986a_loopbacks;
1009#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001010 spec->vmaster_nid = 0x1b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001012 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Takashi Iwai9230d212006-03-13 13:49:49 +01001014 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001015 board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
1016 ad1986a_models,
1017 ad1986a_cfg_tbl);
Takashi Iwai9230d212006-03-13 13:49:49 +01001018 switch (board_config) {
1019 case AD1986A_3STACK:
1020 spec->num_mixers = 2;
1021 spec->mixers[1] = ad1986a_3st_mixers;
Takashi Iwaifb956c12007-04-18 23:03:56 +02001022 spec->num_init_verbs = 2;
1023 spec->init_verbs[1] = ad1986a_ch2_init;
Takashi Iwai9230d212006-03-13 13:49:49 +01001024 spec->channel_mode = ad1986a_modes;
1025 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
Takashi Iwai2125cad2006-03-27 12:52:22 +02001026 spec->need_dac_fix = 1;
1027 spec->multiout.max_channels = 2;
1028 spec->multiout.num_dacs = 1;
Takashi Iwai9230d212006-03-13 13:49:49 +01001029 break;
1030 case AD1986A_LAPTOP:
1031 spec->mixers[0] = ad1986a_laptop_mixers;
1032 spec->multiout.max_channels = 2;
1033 spec->multiout.num_dacs = 1;
1034 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1035 break;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001036 case AD1986A_LAPTOP_EAPD:
1037 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001038 spec->num_init_verbs = 3;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001039 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001040 spec->init_verbs[2] = ad1986a_automic_verbs;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001041 spec->multiout.max_channels = 2;
1042 spec->multiout.num_dacs = 1;
1043 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001044 if (!is_jack_available(codec, 0x25))
1045 spec->multiout.dig_out_nid = 0;
Takashi Iwai5d5d5f42008-02-12 12:11:36 +01001046 spec->input_mux = &ad1986a_automic_capture_source;
1047 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1048 codec->patch_ops.init = ad1986a_automic_init;
Takashi Iwai825aa9722006-03-17 10:50:49 +01001049 break;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001050 case AD1986A_LAPTOP_AUTOMUTE:
1051 spec->mixers[0] = ad1986a_laptop_automute_mixers;
1052 spec->num_init_verbs = 3;
1053 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1054 spec->init_verbs[2] = ad1986a_hp_init_verbs;
1055 spec->multiout.max_channels = 2;
1056 spec->multiout.num_dacs = 1;
1057 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
Takashi Iwai8c0d9642008-01-28 12:30:17 +01001058 if (!is_jack_available(codec, 0x25))
1059 spec->multiout.dig_out_nid = 0;
Takashi Iwai8ab78c72007-09-06 14:29:53 +02001060 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1061 codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
1062 codec->patch_ops.init = ad1986a_hp_init;
1063 break;
Tobin Davisf36090f2007-01-08 11:07:12 +01001064 case AD1986A_ULTRA:
1065 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1066 spec->num_init_verbs = 2;
1067 spec->init_verbs[1] = ad1986a_ultra_init;
1068 spec->multiout.max_channels = 2;
1069 spec->multiout.num_dacs = 1;
1070 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1071 spec->multiout.dig_out_nid = 0;
1072 break;
Takashi Iwai9230d212006-03-13 13:49:49 +01001073 }
1074
Takashi Iwaid29240c2007-10-26 12:35:56 +02001075 /* AD1986A has a hardware problem that it can't share a stream
1076 * with multiple output pins. The copy of front to surrounds
1077 * causes noisy or silent outputs at a certain timing, e.g.
1078 * changing the volume.
1079 * So, let's disable the shared stream.
1080 */
1081 spec->multiout.no_share_stream = 1;
1082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return 0;
1084}
1085
1086/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001087 * AD1983 specific
1088 */
1089
1090#define AD1983_SPDIF_OUT 0x02
1091#define AD1983_DAC 0x03
1092#define AD1983_ADC 0x04
1093
1094static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001095static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001096static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001097
1098static struct hda_input_mux ad1983_capture_source = {
1099 .num_items = 4,
1100 .items = {
1101 { "Mic", 0x0 },
1102 { "Line", 0x1 },
1103 { "Mix", 0x2 },
1104 { "Mix Mono", 0x3 },
1105 },
1106};
1107
1108/*
1109 * SPDIF playback route
1110 */
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001111static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001112{
1113 static char *texts[] = { "PCM", "ADC" };
1114
1115 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1116 uinfo->count = 1;
1117 uinfo->value.enumerated.items = 2;
1118 if (uinfo->value.enumerated.item > 1)
1119 uinfo->value.enumerated.item = 1;
1120 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1121 return 0;
1122}
1123
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001124static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001125{
1126 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1127 struct ad198x_spec *spec = codec->spec;
1128
1129 ucontrol->value.enumerated.item[0] = spec->spdif_route;
1130 return 0;
1131}
1132
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001133static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001134{
1135 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1136 struct ad198x_spec *spec = codec->spec;
1137
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001138 if (ucontrol->value.enumerated.item[0] > 1)
1139 return -EINVAL;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001140 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
1141 spec->spdif_route = ucontrol->value.enumerated.item[0];
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001142 snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
1143 AC_VERB_SET_CONNECT_SEL,
1144 spec->spdif_route);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001145 return 1;
1146 }
1147 return 0;
1148}
1149
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001150static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001151 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1152 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1153 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1154 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1155 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1156 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1157 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1158 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1159 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1160 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1161 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1162 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1163 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1164 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1165 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1166 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1167 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1168 {
1169 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1170 .name = "Capture Source",
1171 .info = ad198x_mux_enum_info,
1172 .get = ad198x_mux_enum_get,
1173 .put = ad198x_mux_enum_put,
1174 },
1175 {
1176 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001177 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001178 .info = ad1983_spdif_route_info,
1179 .get = ad1983_spdif_route_get,
1180 .put = ad1983_spdif_route_put,
1181 },
1182 { } /* end */
1183};
1184
1185static struct hda_verb ad1983_init_verbs[] = {
1186 /* Front, HP, Mono; mute as default */
1187 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1188 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1189 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1190 /* Beep, PCM, Mic, Line-In: mute */
1191 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1192 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1193 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1194 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1195 /* Front, HP selectors; from Mix */
1196 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1197 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1198 /* Mono selector; from Mix */
1199 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1200 /* Mic selector; Mic */
1201 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
1202 /* Line-in selector: Line-in */
1203 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
1204 /* Mic boost: 0dB */
1205 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1206 /* Record selector: mic */
1207 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1208 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1209 /* SPDIF route: PCM */
1210 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1211 /* Front Pin */
1212 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1213 /* HP Pin */
1214 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1215 /* Mono Pin */
1216 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1217 /* Mic Pin */
1218 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1219 /* Line Pin */
1220 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1221 { } /* end */
1222};
1223
Takashi Iwaicb53c622007-08-10 17:21:45 +02001224#ifdef CONFIG_SND_HDA_POWER_SAVE
1225static struct hda_amp_list ad1983_loopbacks[] = {
1226 { 0x12, HDA_OUTPUT, 0 }, /* Mic */
1227 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1228 { } /* end */
1229};
1230#endif
Takashi Iwai985be542005-11-02 18:26:49 +01001231
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001232static int patch_ad1983(struct hda_codec *codec)
1233{
1234 struct ad198x_spec *spec;
1235
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001236 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001237 if (spec == NULL)
1238 return -ENOMEM;
1239
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001240 codec->spec = spec;
1241
1242 spec->multiout.max_channels = 2;
1243 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1244 spec->multiout.dac_nids = ad1983_dac_nids;
1245 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001246 spec->num_adc_nids = 1;
1247 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001248 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001249 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001250 spec->num_mixers = 1;
1251 spec->mixers[0] = ad1983_mixers;
1252 spec->num_init_verbs = 1;
1253 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001254 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001255#ifdef CONFIG_SND_HDA_POWER_SAVE
1256 spec->loopback.amplist = ad1983_loopbacks;
1257#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001258 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001259
1260 codec->patch_ops = ad198x_patch_ops;
1261
1262 return 0;
1263}
1264
1265
1266/*
1267 * AD1981 HD specific
1268 */
1269
1270#define AD1981_SPDIF_OUT 0x02
1271#define AD1981_DAC 0x03
1272#define AD1981_ADC 0x04
1273
1274static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001275static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001276static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001277
1278/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1279static struct hda_input_mux ad1981_capture_source = {
1280 .num_items = 7,
1281 .items = {
1282 { "Front Mic", 0x0 },
1283 { "Line", 0x1 },
1284 { "Mix", 0x2 },
1285 { "Mix Mono", 0x3 },
1286 { "CD", 0x4 },
1287 { "Mic", 0x6 },
1288 { "Aux", 0x7 },
1289 },
1290};
1291
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001292static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001293 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1295 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1296 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1297 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1298 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1299 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1300 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1301 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1302 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1303 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1304 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1305 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1306 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1307 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1308 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1309 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1310 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1311 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1312 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1313 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1314 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1317 {
1318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1319 .name = "Capture Source",
1320 .info = ad198x_mux_enum_info,
1321 .get = ad198x_mux_enum_get,
1322 .put = ad198x_mux_enum_put,
1323 },
1324 /* identical with AD1983 */
1325 {
1326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Takashi Iwai6540dff2006-06-13 11:57:22 +02001327 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001328 .info = ad1983_spdif_route_info,
1329 .get = ad1983_spdif_route_get,
1330 .put = ad1983_spdif_route_put,
1331 },
1332 { } /* end */
1333};
1334
1335static struct hda_verb ad1981_init_verbs[] = {
1336 /* Front, HP, Mono; mute as default */
1337 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1338 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1339 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1340 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1341 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1342 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1343 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1344 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1345 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1346 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1347 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1348 /* Front, HP selectors; from Mix */
1349 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1350 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1351 /* Mono selector; from Mix */
1352 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1353 /* Mic Mixer; select Front Mic */
1354 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1355 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1356 /* Mic boost: 0dB */
1357 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1358 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1359 /* Record selector: Front mic */
1360 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1361 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1362 /* SPDIF route: PCM */
1363 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1364 /* Front Pin */
1365 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1366 /* HP Pin */
1367 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1368 /* Mono Pin */
1369 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1370 /* Front & Rear Mic Pins */
1371 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1372 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1373 /* Line Pin */
1374 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1375 /* Digital Beep */
1376 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1377 /* Line-Out as Input: disabled */
1378 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1379 { } /* end */
1380};
1381
Takashi Iwaicb53c622007-08-10 17:21:45 +02001382#ifdef CONFIG_SND_HDA_POWER_SAVE
1383static struct hda_amp_list ad1981_loopbacks[] = {
1384 { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
1385 { 0x13, HDA_OUTPUT, 0 }, /* Line */
1386 { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
1387 { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
1388 { 0x1d, HDA_OUTPUT, 0 }, /* CD */
1389 { } /* end */
1390};
1391#endif
1392
Takashi Iwai18a815d2006-03-01 19:54:39 +01001393/*
1394 * Patch for HP nx6320
1395 *
Tobin Davis18768992007-03-12 22:20:51 +01001396 * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
Takashi Iwai18a815d2006-03-01 19:54:39 +01001397 * speaker output enabled _and_ mute-LED off.
1398 */
1399
1400#define AD1981_HP_EVENT 0x37
1401#define AD1981_MIC_EVENT 0x38
1402
1403static struct hda_verb ad1981_hp_init_verbs[] = {
1404 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1405 /* pin sensing on HP and Mic jacks */
1406 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1407 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1408 {}
1409};
1410
1411/* turn on/off EAPD (+ mute HP) as a master switch */
1412static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1413 struct snd_ctl_elem_value *ucontrol)
1414{
1415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1416 struct ad198x_spec *spec = codec->spec;
1417
1418 if (! ad198x_eapd_put(kcontrol, ucontrol))
1419 return 0;
Takashi Iwaif0824812008-02-11 15:54:34 +01001420 /* change speaker pin appropriately */
1421 snd_hda_codec_write(codec, 0x05, 0,
1422 AC_VERB_SET_PIN_WIDGET_CONTROL,
1423 spec->cur_eapd ? PIN_OUT : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001424 /* toggle HP mute appropriately */
Takashi Iwai47fd8302007-08-10 17:11:07 +02001425 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1426 HDA_AMP_MUTE,
1427 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001428 return 1;
1429}
1430
1431/* bind volumes of both NID 0x05 and 0x06 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02001432static struct hda_bind_ctls ad1981_hp_bind_master_vol = {
1433 .ops = &snd_hda_bind_vol,
1434 .values = {
1435 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1436 HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
1437 0
1438 },
1439};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001440
1441/* mute internal speaker if HP is plugged */
1442static void ad1981_hp_automute(struct hda_codec *codec)
1443{
1444 unsigned int present;
1445
1446 present = snd_hda_codec_read(codec, 0x06, 0,
1447 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
Takashi Iwai47fd8302007-08-10 17:11:07 +02001448 snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
1449 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001450}
1451
1452/* toggle input of built-in and mic jack appropriately */
1453static void ad1981_hp_automic(struct hda_codec *codec)
1454{
1455 static struct hda_verb mic_jack_on[] = {
1456 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1457 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1458 {}
1459 };
1460 static struct hda_verb mic_jack_off[] = {
1461 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1462 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1463 {}
1464 };
1465 unsigned int present;
1466
1467 present = snd_hda_codec_read(codec, 0x08, 0,
1468 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1469 if (present)
1470 snd_hda_sequence_write(codec, mic_jack_on);
1471 else
1472 snd_hda_sequence_write(codec, mic_jack_off);
1473}
1474
1475/* unsolicited event for HP jack sensing */
1476static void ad1981_hp_unsol_event(struct hda_codec *codec,
1477 unsigned int res)
1478{
1479 res >>= 26;
1480 switch (res) {
1481 case AD1981_HP_EVENT:
1482 ad1981_hp_automute(codec);
1483 break;
1484 case AD1981_MIC_EVENT:
1485 ad1981_hp_automic(codec);
1486 break;
1487 }
1488}
1489
1490static struct hda_input_mux ad1981_hp_capture_source = {
1491 .num_items = 3,
1492 .items = {
1493 { "Mic", 0x0 },
1494 { "Docking-Station", 0x1 },
1495 { "Mix", 0x2 },
1496 },
1497};
1498
1499static struct snd_kcontrol_new ad1981_hp_mixers[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02001500 HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001501 {
1502 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1503 .name = "Master Playback Switch",
1504 .info = ad198x_eapd_info,
1505 .get = ad198x_eapd_get,
1506 .put = ad1981_hp_master_sw_put,
1507 .private_value = 0x05,
1508 },
1509 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1510 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1511#if 0
1512 /* FIXME: analog mic/line loopback doesn't work with my tests...
1513 * (although recording is OK)
1514 */
1515 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1516 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1517 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1518 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1519 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1520 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1521 /* FIXME: does this laptop have analog CD connection? */
1522 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1523 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1524#endif
1525 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1526 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1527 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1528 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1529 {
1530 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1531 .name = "Capture Source",
1532 .info = ad198x_mux_enum_info,
1533 .get = ad198x_mux_enum_get,
1534 .put = ad198x_mux_enum_put,
1535 },
1536 { } /* end */
1537};
1538
1539/* initialize jack-sensing, too */
1540static int ad1981_hp_init(struct hda_codec *codec)
1541{
1542 ad198x_init(codec);
1543 ad1981_hp_automute(codec);
1544 ad1981_hp_automic(codec);
1545 return 0;
1546}
1547
Tobin Davis18768992007-03-12 22:20:51 +01001548/* configuration for Toshiba Laptops */
1549static struct hda_verb ad1981_toshiba_init_verbs[] = {
1550 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
1551 /* pin sensing on HP and Mic jacks */
1552 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1553 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1554 {}
1555};
1556
1557static struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
1558 HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
1559 HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
1560 { }
1561};
1562
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001563/* configuration for Lenovo Thinkpad T60 */
1564static struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
1565 HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1566 HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1567 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1568 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1569 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1570 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1571 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1572 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1573 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1574 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1575 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1576 {
1577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1578 .name = "Capture Source",
1579 .info = ad198x_mux_enum_info,
1580 .get = ad198x_mux_enum_get,
1581 .put = ad198x_mux_enum_put,
1582 },
Takashi Iwai6540dff2006-06-13 11:57:22 +02001583 /* identical with AD1983 */
1584 {
1585 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1586 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
1587 .info = ad1983_spdif_route_info,
1588 .get = ad1983_spdif_route_get,
1589 .put = ad1983_spdif_route_put,
1590 },
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001591 { } /* end */
1592};
1593
1594static struct hda_input_mux ad1981_thinkpad_capture_source = {
1595 .num_items = 3,
1596 .items = {
1597 { "Mic", 0x0 },
1598 { "Mix", 0x2 },
1599 { "CD", 0x4 },
1600 },
1601};
1602
Takashi Iwai18a815d2006-03-01 19:54:39 +01001603/* models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001604enum {
1605 AD1981_BASIC,
1606 AD1981_HP,
1607 AD1981_THINKPAD,
Tobin Davis18768992007-03-12 22:20:51 +01001608 AD1981_TOSHIBA,
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001609 AD1981_MODELS
1610};
Takashi Iwai18a815d2006-03-01 19:54:39 +01001611
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001612static const char *ad1981_models[AD1981_MODELS] = {
1613 [AD1981_HP] = "hp",
1614 [AD1981_THINKPAD] = "thinkpad",
1615 [AD1981_BASIC] = "basic",
Tobin Davis18768992007-03-12 22:20:51 +01001616 [AD1981_TOSHIBA] = "toshiba"
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001617};
1618
1619static struct snd_pci_quirk ad1981_cfg_tbl[] = {
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001620 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
Takashi Iwai8970ccd2006-04-18 12:50:40 +02001621 /* All HP models */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001622 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001623 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001624 /* Lenovo Thinkpad T60/X60/Z6xx */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001625 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01001626 /* HP nx6320 (reversed SSID, H/W bug) */
1627 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
Takashi Iwai18a815d2006-03-01 19:54:39 +01001628 {}
1629};
1630
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001631static int patch_ad1981(struct hda_codec *codec)
1632{
1633 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001634 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001635
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001636 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001637 if (spec == NULL)
1638 return -ENOMEM;
1639
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001640 codec->spec = spec;
1641
1642 spec->multiout.max_channels = 2;
1643 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1644 spec->multiout.dac_nids = ad1981_dac_nids;
1645 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001646 spec->num_adc_nids = 1;
1647 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001648 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001649 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001650 spec->num_mixers = 1;
1651 spec->mixers[0] = ad1981_mixers;
1652 spec->num_init_verbs = 1;
1653 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001654 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02001655#ifdef CONFIG_SND_HDA_POWER_SAVE
1656 spec->loopback.amplist = ad1981_loopbacks;
1657#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01001658 spec->vmaster_nid = 0x05;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001659
1660 codec->patch_ops = ad198x_patch_ops;
1661
Takashi Iwai18a815d2006-03-01 19:54:39 +01001662 /* override some parameters */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001663 board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
1664 ad1981_models,
1665 ad1981_cfg_tbl);
Takashi Iwai18a815d2006-03-01 19:54:39 +01001666 switch (board_config) {
1667 case AD1981_HP:
1668 spec->mixers[0] = ad1981_hp_mixers;
1669 spec->num_init_verbs = 2;
1670 spec->init_verbs[1] = ad1981_hp_init_verbs;
1671 spec->multiout.dig_out_nid = 0;
1672 spec->input_mux = &ad1981_hp_capture_source;
1673
1674 codec->patch_ops.init = ad1981_hp_init;
1675 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1676 break;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001677 case AD1981_THINKPAD:
1678 spec->mixers[0] = ad1981_thinkpad_mixers;
Takashi Iwai01686c5f2006-04-18 12:54:11 +02001679 spec->input_mux = &ad1981_thinkpad_capture_source;
1680 break;
Tobin Davis18768992007-03-12 22:20:51 +01001681 case AD1981_TOSHIBA:
1682 spec->mixers[0] = ad1981_hp_mixers;
1683 spec->mixers[1] = ad1981_toshiba_mixers;
1684 spec->num_init_verbs = 2;
1685 spec->init_verbs[1] = ad1981_toshiba_init_verbs;
1686 spec->multiout.dig_out_nid = 0;
1687 spec->input_mux = &ad1981_hp_capture_source;
1688 codec->patch_ops.init = ad1981_hp_init;
1689 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1690 break;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001691 }
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001692 return 0;
1693}
1694
1695
1696/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001697 * AD1988
1698 *
1699 * Output pins and routes
1700 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001701 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001702 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1703 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1704 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1705 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1706 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1707 * port-F 0x16 (mute) <- 0x2a <- 06
1708 * port-G 0x24 (mute) <- 0x27 <- 05
1709 * port-H 0x25 (mute) <- 0x28 <- 0a
1710 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1711 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001712 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1713 * (*) 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 +01001714 *
1715 * Input pins and routes
1716 *
1717 * pin boost mix input # / adc input #
1718 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1719 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1720 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1721 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1722 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1723 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1724 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1725 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1726 *
1727 *
1728 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001729 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001730 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001731 *
1732 * Inputs of Analog Mix (0x20)
1733 * 0:Port-B (front mic)
1734 * 1:Port-C/G/H (line-in)
1735 * 2:Port-A
1736 * 3:Port-D (line-in/2)
1737 * 4:Port-E/G/H (mic-in)
1738 * 5:Port-F (mic2-in)
1739 * 6:CD
1740 * 7:Beep
1741 *
1742 * ADC selection
1743 * 0:Port-A
1744 * 1:Port-B (front mic-in)
1745 * 2:Port-C (line-in)
1746 * 3:Port-F (mic2-in)
1747 * 4:Port-E (mic-in)
1748 * 5:CD
1749 * 6:Port-G
1750 * 7:Port-H
1751 * 8:Port-D (line-in/2)
1752 * 9:Mix
1753 *
1754 * Proposed pin assignments by the datasheet
1755 *
1756 * 6-stack
1757 * Port-A front headphone
1758 * B front mic-in
1759 * C rear line-in
1760 * D rear front-out
1761 * E rear mic-in
1762 * F rear surround
1763 * G rear CLFE
1764 * H rear side
1765 *
1766 * 3-stack
1767 * Port-A front headphone
1768 * B front mic
1769 * C rear line-in/surround
1770 * D rear front-out
1771 * E rear mic-in/CLFE
1772 *
1773 * laptop
1774 * Port-A headphone
1775 * B mic-in
1776 * C docking station
1777 * D internal speaker (with EAPD)
1778 * E/F quad mic array
1779 */
1780
1781
1782/* models */
1783enum {
1784 AD1988_6STACK,
1785 AD1988_6STACK_DIG,
1786 AD1988_3STACK,
1787 AD1988_3STACK_DIG,
1788 AD1988_LAPTOP,
1789 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001790 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001791 AD1988_MODEL_LAST,
1792};
1793
Takashi Iwaid32410b12005-11-24 16:06:23 +01001794/* reivision id to check workarounds */
1795#define AD1988A_REV2 0x100200
1796
Takashi Iwai1a806f42006-07-03 15:58:16 +02001797#define is_rev2(codec) \
1798 ((codec)->vendor_id == 0x11d41988 && \
1799 (codec)->revision_id == AD1988A_REV2)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001800
1801/*
1802 * mixers
1803 */
1804
Takashi Iwaid32410b12005-11-24 16:06:23 +01001805static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001806 0x04, 0x06, 0x05, 0x0a
1807};
1808
Takashi Iwaid32410b12005-11-24 16:06:23 +01001809static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001810 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001811};
1812
1813/* for AD1988A revision-2, DAC2-4 are swapped */
1814static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1815 0x04, 0x05, 0x0a, 0x06
1816};
1817
1818static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001819 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001820};
1821
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001822static hda_nid_t ad1988_adc_nids[3] = {
1823 0x08, 0x09, 0x0f
1824};
1825
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001826static hda_nid_t ad1988_capsrc_nids[3] = {
1827 0x0c, 0x0d, 0x0e
1828};
1829
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001830#define AD1988_SPDIF_OUT 0x02
1831#define AD1988_SPDIF_IN 0x07
1832
1833static struct hda_input_mux ad1988_6stack_capture_source = {
1834 .num_items = 5,
1835 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001836 { "Front Mic", 0x1 }, /* port-B */
1837 { "Line", 0x2 }, /* port-C */
1838 { "Mic", 0x4 }, /* port-E */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001839 { "CD", 0x5 },
1840 { "Mix", 0x9 },
1841 },
1842};
1843
1844static struct hda_input_mux ad1988_laptop_capture_source = {
1845 .num_items = 3,
1846 .items = {
Takashi Iwaifb304ce2008-02-25 15:32:01 +01001847 { "Mic/Line", 0x1 }, /* port-B */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001848 { "CD", 0x5 },
1849 { "Mix", 0x9 },
1850 },
1851};
1852
1853/*
1854 */
1855static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1856 struct snd_ctl_elem_info *uinfo)
1857{
1858 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1859 struct ad198x_spec *spec = codec->spec;
1860 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1861 spec->num_channel_mode);
1862}
1863
1864static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1865 struct snd_ctl_elem_value *ucontrol)
1866{
1867 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1868 struct ad198x_spec *spec = codec->spec;
1869 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1870 spec->num_channel_mode, spec->multiout.max_channels);
1871}
1872
1873static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1874 struct snd_ctl_elem_value *ucontrol)
1875{
1876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1877 struct ad198x_spec *spec = codec->spec;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001878 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1879 spec->num_channel_mode,
1880 &spec->multiout.max_channels);
Takashi Iwaibd2033f2006-10-10 19:49:31 +02001881 if (err >= 0 && spec->need_dac_fix)
Takashi Iwai2125cad2006-03-27 12:52:22 +02001882 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwai4e195a72006-07-28 14:47:34 +02001883 return err;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001884}
1885
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001886/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001887static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001888 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1889 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1890 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1891 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1892 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001893 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001894};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001895
Takashi Iwaid32410b12005-11-24 16:06:23 +01001896static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1897 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1898 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1899 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1900 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1901 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001902 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001903};
1904
1905static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001906 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1907 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1908 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1909 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1910 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1911 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1912 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1913
1914 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1915 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1916 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1917 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1918 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1919 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1920 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1921 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1922
1923 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1924 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1925
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001926 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001927 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1928
1929 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1930 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1931
1932 { } /* end */
1933};
1934
1935/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001936static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001937 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001938 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001939 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1940 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001941 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001942};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001943
Takashi Iwaid32410b12005-11-24 16:06:23 +01001944static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1945 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001946 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1947 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1948 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwai2ece5f422006-07-06 19:16:40 +02001949 { } /* end */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001950};
1951
1952static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001953 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001954 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1955 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1956 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001957 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1958 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1959
1960 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1961 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1962 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1963 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1964 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1965 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1966 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1967 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1968
1969 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1970 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1971
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001972 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001973 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1974
1975 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1976 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1977 {
1978 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1979 .name = "Channel Mode",
1980 .info = ad198x_ch_mode_info,
1981 .get = ad198x_ch_mode_get,
1982 .put = ad198x_ch_mode_put,
1983 },
1984
1985 { } /* end */
1986};
1987
1988/* laptop mode */
1989static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1990 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1991 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1992 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1993
1994 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1995 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1996 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1997 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1998 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1999 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2000
2001 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2002 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2003
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002004 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002005 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2006
2007 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
2008
2009 {
2010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2011 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01002012 .info = ad198x_eapd_info,
2013 .get = ad198x_eapd_get,
2014 .put = ad198x_eapd_put,
2015 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002016 },
2017
2018 { } /* end */
2019};
2020
2021/* capture */
2022static struct snd_kcontrol_new ad1988_capture_mixers[] = {
2023 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
2024 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
2025 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
2026 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
2027 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
2028 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
2029 {
2030 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2031 /* The multiple "Capture Source" controls confuse alsamixer
2032 * So call somewhat different..
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002033 */
2034 /* .name = "Capture Source", */
2035 .name = "Input Source",
2036 .count = 3,
2037 .info = ad198x_mux_enum_info,
2038 .get = ad198x_mux_enum_get,
2039 .put = ad198x_mux_enum_put,
2040 },
2041 { } /* end */
2042};
2043
2044static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
2045 struct snd_ctl_elem_info *uinfo)
2046{
2047 static char *texts[] = {
2048 "PCM", "ADC1", "ADC2", "ADC3"
2049 };
2050 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2051 uinfo->count = 1;
2052 uinfo->value.enumerated.items = 4;
2053 if (uinfo->value.enumerated.item >= 4)
2054 uinfo->value.enumerated.item = 3;
2055 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2056 return 0;
2057}
2058
2059static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
2060 struct snd_ctl_elem_value *ucontrol)
2061{
2062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2063 unsigned int sel;
2064
Takashi Iwaibddcf542007-07-24 18:04:05 +02002065 sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
2066 AC_AMP_GET_INPUT);
2067 if (!(sel & 0x80))
2068 ucontrol->value.enumerated.item[0] = 0;
2069 else {
Takashi Iwai35b26722007-05-05 12:17:17 +02002070 sel = snd_hda_codec_read(codec, 0x0b, 0,
2071 AC_VERB_GET_CONNECT_SEL, 0);
2072 if (sel < 3)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002073 sel++;
2074 else
2075 sel = 0;
Takashi Iwaibddcf542007-07-24 18:04:05 +02002076 ucontrol->value.enumerated.item[0] = sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002077 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002078 return 0;
2079}
2080
2081static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
2082 struct snd_ctl_elem_value *ucontrol)
2083{
2084 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Takashi Iwai35b26722007-05-05 12:17:17 +02002085 unsigned int val, sel;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002086 int change;
2087
Takashi Iwai35b26722007-05-05 12:17:17 +02002088 val = ucontrol->value.enumerated.item[0];
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002089 if (val > 3)
2090 return -EINVAL;
Takashi Iwai35b26722007-05-05 12:17:17 +02002091 if (!val) {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002092 sel = snd_hda_codec_read(codec, 0x1d, 0,
2093 AC_VERB_GET_AMP_GAIN_MUTE,
2094 AC_AMP_GET_INPUT);
2095 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002096 if (change) {
2097 snd_hda_codec_write_cache(codec, 0x1d, 0,
2098 AC_VERB_SET_AMP_GAIN_MUTE,
2099 AMP_IN_UNMUTE(0));
2100 snd_hda_codec_write_cache(codec, 0x1d, 0,
2101 AC_VERB_SET_AMP_GAIN_MUTE,
2102 AMP_IN_MUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002103 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002104 } else {
Takashi Iwaibddcf542007-07-24 18:04:05 +02002105 sel = snd_hda_codec_read(codec, 0x1d, 0,
2106 AC_VERB_GET_AMP_GAIN_MUTE,
2107 AC_AMP_GET_INPUT | 0x01);
2108 change = sel & 0x80;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002109 if (change) {
2110 snd_hda_codec_write_cache(codec, 0x1d, 0,
2111 AC_VERB_SET_AMP_GAIN_MUTE,
2112 AMP_IN_MUTE(0));
2113 snd_hda_codec_write_cache(codec, 0x1d, 0,
2114 AC_VERB_SET_AMP_GAIN_MUTE,
2115 AMP_IN_UNMUTE(1));
Takashi Iwaibddcf542007-07-24 18:04:05 +02002116 }
Takashi Iwai35b26722007-05-05 12:17:17 +02002117 sel = snd_hda_codec_read(codec, 0x0b, 0,
2118 AC_VERB_GET_CONNECT_SEL, 0) + 1;
2119 change |= sel != val;
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002120 if (change)
2121 snd_hda_codec_write_cache(codec, 0x0b, 0,
2122 AC_VERB_SET_CONNECT_SEL,
2123 val - 1);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002124 }
2125 return change;
2126}
2127
2128static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
2129 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2130 {
2131 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2132 .name = "IEC958 Playback Source",
2133 .info = ad1988_spdif_playback_source_info,
2134 .get = ad1988_spdif_playback_source_get,
2135 .put = ad1988_spdif_playback_source_put,
2136 },
2137 { } /* end */
2138};
2139
2140static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2141 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
2142 { } /* end */
2143};
2144
2145
2146/*
2147 * initialization verbs
2148 */
2149
2150/*
2151 * for 6-stack (+dig)
2152 */
2153static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002154 /* Front, Surround, CLFE, side DAC; unmute as default */
2155 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2156 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2157 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2158 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002159 /* Port-A front headphon path */
2160 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2161 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2162 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2163 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2164 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2165 /* Port-D line-out path */
2166 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2167 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2168 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2169 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2170 /* Port-F surround path */
2171 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2172 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2173 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2174 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2175 /* Port-G CLFE path */
2176 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2177 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2178 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2179 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2180 /* Port-H side path */
2181 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2182 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2183 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2184 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2185 /* Mono out path */
2186 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2187 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2188 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2189 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2190 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2191 /* Port-B front mic-in path */
2192 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2193 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2194 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2195 /* Port-C line-in path */
2196 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2197 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2198 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2199 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2200 /* Port-E mic-in path */
2201 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2202 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2203 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2204 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
Johannes Stezenbach695005c2007-12-13 17:51:00 +01002205 /* Analog CD Input */
2206 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002207
2208 { }
2209};
2210
2211static struct hda_verb ad1988_capture_init_verbs[] = {
2212 /* mute analog mix */
2213 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2214 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2215 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2216 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2217 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2218 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2219 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2220 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2221 /* select ADCs - front-mic */
2222 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2223 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2224 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2225 /* ADCs; muted */
2226 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2227 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2228 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2229
2230 { }
2231};
2232
2233static struct hda_verb ad1988_spdif_init_verbs[] = {
2234 /* SPDIF out sel */
2235 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
2236 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
2237 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Takashi Iwaibddcf542007-07-24 18:04:05 +02002238 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002239 /* SPDIF out pin */
2240 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002241
2242 { }
2243};
2244
2245/*
2246 * verbs for 3stack (+dig)
2247 */
2248static struct hda_verb ad1988_3stack_ch2_init[] = {
2249 /* set port-C to line-in */
2250 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2251 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
2252 /* set port-E to mic-in */
2253 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2254 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
2255 { } /* end */
2256};
2257
2258static struct hda_verb ad1988_3stack_ch6_init[] = {
2259 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002260 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002261 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002262 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002263 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002264 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002265 { } /* end */
2266};
2267
2268static struct hda_channel_mode ad1988_3stack_modes[2] = {
2269 { 2, ad1988_3stack_ch2_init },
2270 { 6, ad1988_3stack_ch6_init },
2271};
2272
2273static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002274 /* Front, Surround, CLFE, side DAC; unmute as default */
2275 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2276 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2277 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2278 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002279 /* Port-A front headphon path */
2280 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2281 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2282 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2283 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2284 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2285 /* Port-D line-out path */
2286 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2287 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2288 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2289 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2290 /* Mono out path */
2291 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2292 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2293 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2294 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2295 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2296 /* Port-B front mic-in path */
2297 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2298 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2299 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002300 /* Port-C line-in/surround path - 6ch mode as default */
2301 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2302 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002303 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002304 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002305 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01002306 /* Port-E mic-in/CLFE path - 6ch mode as default */
2307 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2308 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002309 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002310 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002311 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
2312 /* mute analog mix */
2313 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2314 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2315 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2316 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2317 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2318 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2319 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2320 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2321 /* select ADCs - front-mic */
2322 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2323 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2324 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2325 /* ADCs; muted */
2326 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2327 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2328 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2329 { }
2330};
2331
2332/*
2333 * verbs for laptop mode (+dig)
2334 */
2335static struct hda_verb ad1988_laptop_hp_on[] = {
2336 /* unmute port-A and mute port-D */
2337 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2338 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2339 { } /* end */
2340};
2341static struct hda_verb ad1988_laptop_hp_off[] = {
2342 /* mute port-A and unmute port-D */
2343 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
2344 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
2345 { } /* end */
2346};
2347
2348#define AD1988_HP_EVENT 0x01
2349
2350static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01002351 /* Front, Surround, CLFE, side DAC; unmute as default */
2352 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2353 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2354 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2355 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002356 /* Port-A front headphon path */
2357 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2358 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2359 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2360 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2361 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2362 /* unsolicited event for pin-sense */
2363 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2364 /* Port-D line-out path + EAPD */
2365 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2366 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2367 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2368 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2369 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2370 /* Mono out path */
2371 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2372 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2373 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2374 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2375 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2376 /* Port-B mic-in path */
2377 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2378 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2379 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2380 /* Port-C docking station - try to output */
2381 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2382 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2383 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2384 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2385 /* mute analog mix */
2386 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2387 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2388 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2389 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2390 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2391 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2392 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2393 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2394 /* select ADCs - mic */
2395 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2396 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2397 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2398 /* ADCs; muted */
2399 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2400 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2401 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2402 { }
2403};
2404
2405static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2406{
2407 if ((res >> 26) != AD1988_HP_EVENT)
2408 return;
2409 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2410 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2411 else
2412 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2413}
2414
Takashi Iwaicb53c622007-08-10 17:21:45 +02002415#ifdef CONFIG_SND_HDA_POWER_SAVE
2416static struct hda_amp_list ad1988_loopbacks[] = {
2417 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
2418 { 0x20, HDA_INPUT, 1 }, /* Line */
2419 { 0x20, HDA_INPUT, 4 }, /* Mic */
2420 { 0x20, HDA_INPUT, 6 }, /* CD */
2421 { } /* end */
2422};
2423#endif
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002424
2425/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002426 * Automatic parse of I/O pins from the BIOS configuration
2427 */
2428
2429#define NUM_CONTROL_ALLOC 32
2430#define NUM_VERB_ALLOC 32
2431
2432enum {
2433 AD_CTL_WIDGET_VOL,
2434 AD_CTL_WIDGET_MUTE,
2435 AD_CTL_BIND_MUTE,
2436};
2437static struct snd_kcontrol_new ad1988_control_templates[] = {
2438 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2439 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2440 HDA_BIND_MUTE(NULL, 0, 0, 0),
2441};
2442
2443/* add dynamic controls */
2444static int add_control(struct ad198x_spec *spec, int type, const char *name,
2445 unsigned long val)
2446{
2447 struct snd_kcontrol_new *knew;
2448
2449 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2450 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2451
2452 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2453 if (! knew)
2454 return -ENOMEM;
2455 if (spec->kctl_alloc) {
2456 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2457 kfree(spec->kctl_alloc);
2458 }
2459 spec->kctl_alloc = knew;
2460 spec->num_kctl_alloc = num;
2461 }
2462
2463 knew = &spec->kctl_alloc[spec->num_kctl_used];
2464 *knew = ad1988_control_templates[type];
2465 knew->name = kstrdup(name, GFP_KERNEL);
2466 if (! knew->name)
2467 return -ENOMEM;
2468 knew->private_value = val;
2469 spec->num_kctl_used++;
2470 return 0;
2471}
2472
2473#define AD1988_PIN_CD_NID 0x18
2474#define AD1988_PIN_BEEP_NID 0x10
2475
2476static hda_nid_t ad1988_mixer_nids[8] = {
2477 /* A B C D E F G H */
2478 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2479};
2480
2481static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2482{
2483 static hda_nid_t idx_to_dac[8] = {
2484 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002485 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002486 };
2487 static hda_nid_t idx_to_dac_rev2[8] = {
2488 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002489 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002490 };
Takashi Iwai1a806f42006-07-03 15:58:16 +02002491 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002492 return idx_to_dac_rev2[idx];
2493 else
2494 return idx_to_dac[idx];
2495}
2496
2497static hda_nid_t ad1988_boost_nids[8] = {
2498 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2499};
2500
2501static int ad1988_pin_idx(hda_nid_t nid)
2502{
2503 static hda_nid_t ad1988_io_pins[8] = {
2504 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2505 };
2506 int i;
2507 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2508 if (ad1988_io_pins[i] == nid)
2509 return i;
2510 return 0; /* should be -1 */
2511}
2512
2513static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2514{
2515 static int loopback_idx[8] = {
2516 2, 0, 1, 3, 4, 5, 1, 4
2517 };
2518 switch (nid) {
2519 case AD1988_PIN_CD_NID:
2520 return 6;
2521 default:
2522 return loopback_idx[ad1988_pin_idx(nid)];
2523 }
2524}
2525
2526static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2527{
2528 static int adc_idx[8] = {
2529 0, 1, 2, 8, 4, 3, 6, 7
2530 };
2531 switch (nid) {
2532 case AD1988_PIN_CD_NID:
2533 return 5;
2534 default:
2535 return adc_idx[ad1988_pin_idx(nid)];
2536 }
2537}
2538
2539/* fill in the dac_nids table from the parsed pin configuration */
2540static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2541 const struct auto_pin_cfg *cfg)
2542{
2543 struct ad198x_spec *spec = codec->spec;
2544 int i, idx;
2545
2546 spec->multiout.dac_nids = spec->private_dac_nids;
2547
2548 /* check the pins hardwired to audio widget */
2549 for (i = 0; i < cfg->line_outs; i++) {
2550 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2551 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2552 }
2553 spec->multiout.num_dacs = cfg->line_outs;
2554 return 0;
2555}
2556
2557/* add playback controls from the parsed DAC table */
2558static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2559 const struct auto_pin_cfg *cfg)
2560{
2561 char name[32];
2562 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2563 hda_nid_t nid;
2564 int i, err;
2565
2566 for (i = 0; i < cfg->line_outs; i++) {
2567 hda_nid_t dac = spec->multiout.dac_nids[i];
2568 if (! dac)
2569 continue;
2570 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2571 if (i == 2) {
2572 /* Center/LFE */
2573 err = add_control(spec, AD_CTL_WIDGET_VOL,
2574 "Center Playback Volume",
2575 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2576 if (err < 0)
2577 return err;
2578 err = add_control(spec, AD_CTL_WIDGET_VOL,
2579 "LFE Playback Volume",
2580 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2581 if (err < 0)
2582 return err;
2583 err = add_control(spec, AD_CTL_BIND_MUTE,
2584 "Center Playback Switch",
2585 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2586 if (err < 0)
2587 return err;
2588 err = add_control(spec, AD_CTL_BIND_MUTE,
2589 "LFE Playback Switch",
2590 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2591 if (err < 0)
2592 return err;
2593 } else {
2594 sprintf(name, "%s Playback Volume", chname[i]);
2595 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2596 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2597 if (err < 0)
2598 return err;
2599 sprintf(name, "%s Playback Switch", chname[i]);
2600 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2601 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2602 if (err < 0)
2603 return err;
2604 }
2605 }
2606 return 0;
2607}
2608
2609/* add playback controls for speaker and HP outputs */
2610static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2611 const char *pfx)
2612{
2613 struct ad198x_spec *spec = codec->spec;
2614 hda_nid_t nid;
2615 int idx, err;
2616 char name[32];
2617
2618 if (! pin)
2619 return 0;
2620
2621 idx = ad1988_pin_idx(pin);
2622 nid = ad1988_idx_to_dac(codec, idx);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002623 /* specify the DAC as the extra output */
2624 if (! spec->multiout.hp_nid)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002625 spec->multiout.hp_nid = nid;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002626 else
2627 spec->multiout.extra_out_nid[0] = nid;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002628 /* control HP volume/switch on the output mixer amp */
2629 sprintf(name, "%s Playback Volume", pfx);
2630 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2631 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2632 return err;
2633 nid = ad1988_mixer_nids[idx];
2634 sprintf(name, "%s Playback Switch", pfx);
2635 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2636 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2637 return err;
2638 return 0;
2639}
2640
2641/* create input playback/capture controls for the given pin */
2642static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2643 const char *ctlname, int boost)
2644{
2645 char name[32];
2646 int err, idx;
2647
2648 sprintf(name, "%s Playback Volume", ctlname);
2649 idx = ad1988_pin_to_loopback_idx(pin);
2650 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2651 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2652 return err;
2653 sprintf(name, "%s Playback Switch", ctlname);
2654 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2655 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2656 return err;
2657 if (boost) {
2658 hda_nid_t bnid;
2659 idx = ad1988_pin_idx(pin);
2660 bnid = ad1988_boost_nids[idx];
2661 if (bnid) {
2662 sprintf(name, "%s Boost", ctlname);
2663 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2664 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2665
2666 }
2667 }
2668 return 0;
2669}
2670
2671/* create playback/capture controls for input pins */
2672static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2673 const struct auto_pin_cfg *cfg)
2674{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002675 struct hda_input_mux *imux = &spec->private_imux;
2676 int i, err;
2677
2678 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002679 err = new_analog_input(spec, cfg->input_pins[i],
2680 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002681 i <= AUTO_PIN_FRONT_MIC);
2682 if (err < 0)
2683 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002684 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002685 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2686 imux->num_items++;
2687 }
2688 imux->items[imux->num_items].label = "Mix";
2689 imux->items[imux->num_items].index = 9;
2690 imux->num_items++;
2691
2692 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2693 "Analog Mix Playback Volume",
2694 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2695 return err;
2696 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2697 "Analog Mix Playback Switch",
2698 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2699 return err;
2700
2701 return 0;
2702}
2703
2704static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2705 hda_nid_t nid, int pin_type,
2706 int dac_idx)
2707{
2708 /* set as output */
2709 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2710 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2711 switch (nid) {
2712 case 0x11: /* port-A - DAC 04 */
2713 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2714 break;
2715 case 0x14: /* port-B - DAC 06 */
2716 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2717 break;
2718 case 0x15: /* port-C - DAC 05 */
2719 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2720 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002721 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002722 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2723 break;
2724 case 0x13: /* mono - DAC 04 */
2725 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2726 break;
2727 }
2728}
2729
2730static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2731{
2732 struct ad198x_spec *spec = codec->spec;
2733 int i;
2734
2735 for (i = 0; i < spec->autocfg.line_outs; i++) {
2736 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2737 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2738 }
2739}
2740
2741static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2742{
2743 struct ad198x_spec *spec = codec->spec;
2744 hda_nid_t pin;
2745
Takashi Iwai82bc9552006-03-21 11:24:42 +01002746 pin = spec->autocfg.speaker_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002747 if (pin) /* connect to front */
2748 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002749 pin = spec->autocfg.hp_pins[0];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002750 if (pin) /* connect to front */
2751 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2752}
2753
2754static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2755{
2756 struct ad198x_spec *spec = codec->spec;
2757 int i, idx;
2758
2759 for (i = 0; i < AUTO_PIN_LAST; i++) {
2760 hda_nid_t nid = spec->autocfg.input_pins[i];
2761 if (! nid)
2762 continue;
2763 switch (nid) {
2764 case 0x15: /* port-C */
2765 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2766 break;
2767 case 0x17: /* port-E */
2768 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2769 break;
2770 }
2771 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2772 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2773 if (nid != AD1988_PIN_CD_NID)
2774 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2775 AMP_OUT_MUTE);
2776 idx = ad1988_pin_idx(nid);
2777 if (ad1988_boost_nids[idx])
2778 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2779 AC_VERB_SET_AMP_GAIN_MUTE,
2780 AMP_OUT_ZERO);
2781 }
2782}
2783
2784/* parse the BIOS configuration and set up the alc_spec */
2785/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2786static int ad1988_parse_auto_config(struct hda_codec *codec)
2787{
2788 struct ad198x_spec *spec = codec->spec;
2789 int err;
2790
Kailang Yangdf694da2005-12-05 19:42:22 +01002791 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002792 return err;
2793 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2794 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002795 if (! spec->autocfg.line_outs)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002796 return 0; /* can't find valid BIOS pin config */
2797 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
Takashi Iwai82bc9552006-03-21 11:24:42 +01002798 (err = ad1988_auto_create_extra_out(codec,
2799 spec->autocfg.speaker_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002800 "Speaker")) < 0 ||
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002801 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002802 "Headphone")) < 0 ||
2803 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2804 return err;
2805
2806 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2807
2808 if (spec->autocfg.dig_out_pin)
2809 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2810 if (spec->autocfg.dig_in_pin)
2811 spec->dig_in_nid = AD1988_SPDIF_IN;
2812
2813 if (spec->kctl_alloc)
2814 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2815
2816 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2817
2818 spec->input_mux = &spec->private_imux;
2819
2820 return 1;
2821}
2822
2823/* init callback for auto-configuration model -- overriding the default init */
2824static int ad1988_auto_init(struct hda_codec *codec)
2825{
2826 ad198x_init(codec);
2827 ad1988_auto_init_multi_out(codec);
2828 ad1988_auto_init_extra_out(codec);
2829 ad1988_auto_init_analog_input(codec);
2830 return 0;
2831}
2832
2833
2834/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002835 */
2836
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002837static const char *ad1988_models[AD1988_MODEL_LAST] = {
2838 [AD1988_6STACK] = "6stack",
2839 [AD1988_6STACK_DIG] = "6stack-dig",
2840 [AD1988_3STACK] = "3stack",
2841 [AD1988_3STACK_DIG] = "3stack-dig",
2842 [AD1988_LAPTOP] = "laptop",
2843 [AD1988_LAPTOP_DIG] = "laptop-dig",
2844 [AD1988_AUTO] = "auto",
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002845};
2846
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002847static struct snd_pci_quirk ad1988_cfg_tbl[] = {
Tobin Davis18768992007-03-12 22:20:51 +01002848 SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
Takashi Iwaiac3e3742007-12-17 17:14:18 +01002849 SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002850 {}
2851};
2852
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002853static int patch_ad1988(struct hda_codec *codec)
2854{
2855 struct ad198x_spec *spec;
2856 int board_config;
2857
2858 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2859 if (spec == NULL)
2860 return -ENOMEM;
2861
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002862 codec->spec = spec;
2863
Takashi Iwai1a806f42006-07-03 15:58:16 +02002864 if (is_rev2(codec))
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002865 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2866
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002867 board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
Tobin Davisa64c8cd2007-03-12 11:36:00 +01002868 ad1988_models, ad1988_cfg_tbl);
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002869 if (board_config < 0) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002870 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2871 board_config = AD1988_AUTO;
2872 }
2873
2874 if (board_config == AD1988_AUTO) {
2875 /* automatic parse from the BIOS config */
2876 int err = ad1988_parse_auto_config(codec);
2877 if (err < 0) {
2878 ad198x_free(codec);
2879 return err;
2880 } else if (! err) {
2881 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2882 board_config = AD1988_6STACK;
2883 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002884 }
2885
2886 switch (board_config) {
2887 case AD1988_6STACK:
2888 case AD1988_6STACK_DIG:
2889 spec->multiout.max_channels = 8;
2890 spec->multiout.num_dacs = 4;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002891 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002892 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2893 else
2894 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002895 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002896 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002897 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002898 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2899 else
2900 spec->mixers[0] = ad1988_6stack_mixers1;
2901 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002902 spec->num_init_verbs = 1;
2903 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2904 if (board_config == AD1988_6STACK_DIG) {
2905 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2906 spec->dig_in_nid = AD1988_SPDIF_IN;
2907 }
2908 break;
2909 case AD1988_3STACK:
2910 case AD1988_3STACK_DIG:
2911 spec->multiout.max_channels = 6;
2912 spec->multiout.num_dacs = 3;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002913 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002914 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2915 else
2916 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002917 spec->input_mux = &ad1988_6stack_capture_source;
2918 spec->channel_mode = ad1988_3stack_modes;
2919 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002920 spec->num_mixers = 2;
Takashi Iwai1a806f42006-07-03 15:58:16 +02002921 if (is_rev2(codec))
Takashi Iwaid32410b12005-11-24 16:06:23 +01002922 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2923 else
2924 spec->mixers[0] = ad1988_3stack_mixers1;
2925 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002926 spec->num_init_verbs = 1;
2927 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2928 if (board_config == AD1988_3STACK_DIG)
2929 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2930 break;
2931 case AD1988_LAPTOP:
2932 case AD1988_LAPTOP_DIG:
2933 spec->multiout.max_channels = 2;
2934 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002935 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002936 spec->input_mux = &ad1988_laptop_capture_source;
2937 spec->num_mixers = 1;
2938 spec->mixers[0] = ad1988_laptop_mixers;
2939 spec->num_init_verbs = 1;
2940 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2941 if (board_config == AD1988_LAPTOP_DIG)
2942 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2943 break;
2944 }
2945
Takashi Iwaid32410b12005-11-24 16:06:23 +01002946 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2947 spec->adc_nids = ad1988_adc_nids;
2948 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002949 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2950 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2951 if (spec->multiout.dig_out_nid) {
2952 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2953 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2954 }
2955 if (spec->dig_in_nid)
2956 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2957
2958 codec->patch_ops = ad198x_patch_ops;
2959 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002960 case AD1988_AUTO:
2961 codec->patch_ops.init = ad1988_auto_init;
2962 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002963 case AD1988_LAPTOP:
2964 case AD1988_LAPTOP_DIG:
2965 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2966 break;
2967 }
Takashi Iwaicb53c622007-08-10 17:21:45 +02002968#ifdef CONFIG_SND_HDA_POWER_SAVE
2969 spec->loopback.amplist = ad1988_loopbacks;
2970#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01002971 spec->vmaster_nid = 0x04;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002972
2973 return 0;
2974}
2975
2976
2977/*
Takashi Iwai2bac6472007-05-18 18:21:41 +02002978 * AD1884 / AD1984
2979 *
2980 * port-B - front line/mic-in
2981 * port-E - aux in/out
2982 * port-F - aux in/out
2983 * port-C - rear line/mic-in
2984 * port-D - rear line/hp-out
2985 * port-A - front line/hp-out
2986 *
2987 * AD1984 = AD1884 + two digital mic-ins
2988 *
2989 * FIXME:
2990 * For simplicity, we share the single DAC for both HP and line-outs
2991 * right now. The inidividual playbacks could be easily implemented,
2992 * but no build-up framework is given, so far.
2993 */
2994
2995static hda_nid_t ad1884_dac_nids[1] = {
2996 0x04,
2997};
2998
2999static hda_nid_t ad1884_adc_nids[2] = {
3000 0x08, 0x09,
3001};
3002
3003static hda_nid_t ad1884_capsrc_nids[2] = {
3004 0x0c, 0x0d,
3005};
3006
3007#define AD1884_SPDIF_OUT 0x02
3008
3009static struct hda_input_mux ad1884_capture_source = {
3010 .num_items = 4,
3011 .items = {
3012 { "Front Mic", 0x0 },
3013 { "Mic", 0x1 },
3014 { "CD", 0x2 },
3015 { "Mix", 0x3 },
3016 },
3017};
3018
3019static struct snd_kcontrol_new ad1884_base_mixers[] = {
3020 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3021 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3022 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3023 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3024 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3025 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3026 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3027 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3028 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3029 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3030 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3031 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3032 /*
3033 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3034 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3035 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
3036 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3037 */
3038 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3039 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3040 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3041 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3042 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3043 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3044 {
3045 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3046 /* The multiple "Capture Source" controls confuse alsamixer
3047 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003048 */
3049 /* .name = "Capture Source", */
3050 .name = "Input Source",
3051 .count = 2,
3052 .info = ad198x_mux_enum_info,
3053 .get = ad198x_mux_enum_get,
3054 .put = ad198x_mux_enum_put,
3055 },
3056 /* SPDIF controls */
3057 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3058 {
3059 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3060 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3061 /* identical with ad1983 */
3062 .info = ad1983_spdif_route_info,
3063 .get = ad1983_spdif_route_get,
3064 .put = ad1983_spdif_route_put,
3065 },
3066 { } /* end */
3067};
3068
3069static struct snd_kcontrol_new ad1984_dmic_mixers[] = {
3070 HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
3071 HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
3072 HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003073 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003074 HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
Takashi Iwai538c49c2007-06-05 12:13:34 +02003075 HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003076 { } /* end */
3077};
3078
3079/*
3080 * initialization verbs
3081 */
3082static struct hda_verb ad1884_init_verbs[] = {
3083 /* DACs; mute as default */
Takashi Iwai3b194402007-06-04 18:32:23 +02003084 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3085 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003086 /* Port-A (HP) mixer */
3087 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3088 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3089 /* Port-A pin */
3090 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3091 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3092 /* HP selector - select DAC2 */
3093 {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
3094 /* Port-D (Line-out) mixer */
3095 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3096 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3097 /* Port-D pin */
3098 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3099 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3100 /* Mono-out mixer */
3101 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3102 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3103 /* Mono-out pin */
3104 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3105 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3106 /* Mono selector */
3107 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3108 /* Port-B (front mic) pin */
3109 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3110 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3111 /* Port-C (rear mic) pin */
3112 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3113 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3114 /* Analog mixer; mute as default */
3115 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3116 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3117 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3118 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3119 /* Analog Mix output amp */
3120 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
3121 /* SPDIF output selector */
3122 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
3123 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3124 { } /* end */
3125};
3126
Takashi Iwaicb53c622007-08-10 17:21:45 +02003127#ifdef CONFIG_SND_HDA_POWER_SAVE
3128static struct hda_amp_list ad1884_loopbacks[] = {
3129 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3130 { 0x20, HDA_INPUT, 1 }, /* Mic */
3131 { 0x20, HDA_INPUT, 2 }, /* CD */
3132 { 0x20, HDA_INPUT, 4 }, /* Docking */
3133 { } /* end */
3134};
3135#endif
3136
Takashi Iwai2134ea42008-01-10 16:53:55 +01003137static const char *ad1884_slave_vols[] = {
3138 "PCM Playback Volume",
3139 "Mic Playback Volume",
3140 "Mono Playback Volume",
3141 "Front Mic Playback Volume",
3142 "Mic Playback Volume",
3143 "CD Playback Volume",
3144 "Internal Mic Playback Volume",
3145 "Docking Mic Playback Volume"
3146 "Beep Playback Volume",
Takashi Iwai4806ef02008-01-26 09:58:13 +01003147 "IEC958 Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01003148 NULL
3149};
3150
Takashi Iwai2bac6472007-05-18 18:21:41 +02003151static int patch_ad1884(struct hda_codec *codec)
3152{
3153 struct ad198x_spec *spec;
3154
3155 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3156 if (spec == NULL)
3157 return -ENOMEM;
3158
3159 mutex_init(&spec->amp_mutex);
3160 codec->spec = spec;
3161
3162 spec->multiout.max_channels = 2;
3163 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3164 spec->multiout.dac_nids = ad1884_dac_nids;
3165 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
3166 spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
3167 spec->adc_nids = ad1884_adc_nids;
3168 spec->capsrc_nids = ad1884_capsrc_nids;
3169 spec->input_mux = &ad1884_capture_source;
3170 spec->num_mixers = 1;
3171 spec->mixers[0] = ad1884_base_mixers;
3172 spec->num_init_verbs = 1;
3173 spec->init_verbs[0] = ad1884_init_verbs;
3174 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02003175#ifdef CONFIG_SND_HDA_POWER_SAVE
3176 spec->loopback.amplist = ad1884_loopbacks;
3177#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01003178 spec->vmaster_nid = 0x04;
3179 /* we need to cover all playback volumes */
3180 spec->slave_vols = ad1884_slave_vols;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003181
3182 codec->patch_ops = ad198x_patch_ops;
3183
3184 return 0;
3185}
3186
3187/*
3188 * Lenovo Thinkpad T61/X61
3189 */
3190static struct hda_input_mux ad1984_thinkpad_capture_source = {
Takashi Iwaib26451c2008-02-26 11:56:35 +01003191 .num_items = 4,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003192 .items = {
3193 { "Mic", 0x0 },
3194 { "Internal Mic", 0x1 },
3195 { "Mix", 0x3 },
Takashi Iwaib26451c2008-02-26 11:56:35 +01003196 { "Docking-Station", 0x4 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003197 },
3198};
3199
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003200
3201/*
3202 * Dell Precision T3400
3203 */
3204static struct hda_input_mux ad1984_dell_desktop_capture_source = {
3205 .num_items = 3,
3206 .items = {
3207 { "Front Mic", 0x0 },
3208 { "Line-In", 0x1 },
3209 { "Mix", 0x3 },
3210 },
3211};
3212
3213
Takashi Iwai2bac6472007-05-18 18:21:41 +02003214static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3215 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3216 /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
3217 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3218 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3219 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3220 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3221 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3222 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3223 HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3224 HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003225 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3226 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
Takashi Iwai0ba79622007-05-23 16:27:32 +02003227 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003228 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3229 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003230 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3231 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3232 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3233 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3234 {
3235 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3236 /* The multiple "Capture Source" controls confuse alsamixer
3237 * So call somewhat different..
Takashi Iwai2bac6472007-05-18 18:21:41 +02003238 */
3239 /* .name = "Capture Source", */
3240 .name = "Input Source",
3241 .count = 2,
3242 .info = ad198x_mux_enum_info,
3243 .get = ad198x_mux_enum_get,
3244 .put = ad198x_mux_enum_put,
3245 },
Jerone Youngebf00c52008-01-07 12:22:18 +01003246 /* SPDIF controls */
3247 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3248 {
3249 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3250 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3251 /* identical with ad1983 */
3252 .info = ad1983_spdif_route_info,
3253 .get = ad1983_spdif_route_get,
3254 .put = ad1983_spdif_route_put,
3255 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02003256 { } /* end */
3257};
3258
3259/* additional verbs */
3260static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3261 /* Port-E (docking station mic) pin */
3262 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3263 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3264 /* docking mic boost */
3265 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3266 /* Analog mixer - docking mic; mute as default */
3267 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
Takashi Iwaib959d1f2007-06-08 12:25:25 +02003268 /* enable EAPD bit */
3269 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
Takashi Iwai2bac6472007-05-18 18:21:41 +02003270 { } /* end */
3271};
3272
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003273/*
3274 * Dell Precision T3400
3275 */
3276static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3277 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3278 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3279 HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3280 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3281 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3282 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3283 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3284 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3285 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3286 /*
3287 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3288 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3289 */
3290 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3291 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3292 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3293 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3294 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3295 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3296 {
3297 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3298 /* The multiple "Capture Source" controls confuse alsamixer
3299 * So call somewhat different..
3300 */
3301 /* .name = "Capture Source", */
3302 .name = "Input Source",
3303 .count = 2,
3304 .info = ad198x_mux_enum_info,
3305 .get = ad198x_mux_enum_get,
3306 .put = ad198x_mux_enum_put,
3307 },
3308 { } /* end */
3309};
3310
Takashi Iwai2bac6472007-05-18 18:21:41 +02003311/* Digial MIC ADC NID 0x05 + 0x06 */
3312static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
3313 struct hda_codec *codec,
3314 unsigned int stream_tag,
3315 unsigned int format,
3316 struct snd_pcm_substream *substream)
3317{
3318 snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
3319 stream_tag, 0, format);
3320 return 0;
3321}
3322
3323static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3324 struct hda_codec *codec,
3325 struct snd_pcm_substream *substream)
3326{
Takashi Iwai888afa12008-03-18 09:57:50 +01003327 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
Takashi Iwai2bac6472007-05-18 18:21:41 +02003328 return 0;
3329}
3330
3331static struct hda_pcm_stream ad1984_pcm_dmic_capture = {
3332 .substreams = 2,
3333 .channels_min = 2,
3334 .channels_max = 2,
3335 .nid = 0x05,
3336 .ops = {
3337 .prepare = ad1984_pcm_dmic_prepare,
3338 .cleanup = ad1984_pcm_dmic_cleanup
3339 },
3340};
3341
3342static int ad1984_build_pcms(struct hda_codec *codec)
3343{
3344 struct ad198x_spec *spec = codec->spec;
3345 struct hda_pcm *info;
3346 int err;
3347
3348 err = ad198x_build_pcms(codec);
3349 if (err < 0)
3350 return err;
3351
3352 info = spec->pcm_rec + codec->num_pcms;
3353 codec->num_pcms++;
3354 info->name = "AD1984 Digital Mic";
3355 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
3356 return 0;
3357}
3358
3359/* models */
3360enum {
3361 AD1984_BASIC,
3362 AD1984_THINKPAD,
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003363 AD1984_DELL_DESKTOP,
Takashi Iwai2bac6472007-05-18 18:21:41 +02003364 AD1984_MODELS
3365};
3366
3367static const char *ad1984_models[AD1984_MODELS] = {
3368 [AD1984_BASIC] = "basic",
3369 [AD1984_THINKPAD] = "thinkpad",
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003370 [AD1984_DELL_DESKTOP] = "dell_desktop",
Takashi Iwai2bac6472007-05-18 18:21:41 +02003371};
3372
3373static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3374 /* Lenovo Thinkpad T61/X61 */
3375 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD),
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003376 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
Takashi Iwai2bac6472007-05-18 18:21:41 +02003377 {}
3378};
3379
3380static int patch_ad1984(struct hda_codec *codec)
3381{
3382 struct ad198x_spec *spec;
3383 int board_config, err;
3384
3385 err = patch_ad1884(codec);
3386 if (err < 0)
3387 return err;
3388 spec = codec->spec;
3389 board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
3390 ad1984_models, ad1984_cfg_tbl);
3391 switch (board_config) {
3392 case AD1984_BASIC:
3393 /* additional digital mics */
3394 spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
3395 codec->patch_ops.build_pcms = ad1984_build_pcms;
3396 break;
3397 case AD1984_THINKPAD:
Jerone Youngebf00c52008-01-07 12:22:18 +01003398 spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003399 spec->input_mux = &ad1984_thinkpad_capture_source;
3400 spec->mixers[0] = ad1984_thinkpad_mixers;
3401 spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
3402 break;
Douglas Kosovic0aaa22e2008-01-29 15:02:50 +01003403 case AD1984_DELL_DESKTOP:
3404 spec->multiout.dig_out_nid = 0;
3405 spec->input_mux = &ad1984_dell_desktop_capture_source;
3406 spec->mixers[0] = ad1984_dell_desktop_mixers;
3407 break;
Takashi Iwai2bac6472007-05-18 18:21:41 +02003408 }
3409 return 0;
3410}
3411
3412
3413/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003414 * AD1883 / AD1884A / AD1984A / AD1984B
3415 *
3416 * port-B (0x14) - front mic-in
3417 * port-E (0x1c) - rear mic-in
3418 * port-F (0x16) - CD / ext out
3419 * port-C (0x15) - rear line-in
3420 * port-D (0x12) - rear line-out
3421 * port-A (0x11) - front hp-out
3422 *
3423 * AD1984A = AD1884A + digital-mic
3424 * AD1883 = equivalent with AD1984A
3425 * AD1984B = AD1984A + extra SPDIF-out
3426 *
3427 * FIXME:
3428 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3429 */
3430
3431static hda_nid_t ad1884a_dac_nids[1] = {
3432 0x03,
3433};
3434
3435#define ad1884a_adc_nids ad1884_adc_nids
3436#define ad1884a_capsrc_nids ad1884_capsrc_nids
3437
3438#define AD1884A_SPDIF_OUT 0x02
3439
3440static struct hda_input_mux ad1884a_capture_source = {
3441 .num_items = 5,
3442 .items = {
3443 { "Front Mic", 0x0 },
3444 { "Mic", 0x4 },
3445 { "Line", 0x1 },
3446 { "CD", 0x2 },
3447 { "Mix", 0x3 },
3448 },
3449};
3450
3451static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3452 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3453 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3454 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3455 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3456 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3457 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3458 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3459 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3460 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3461 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3462 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3463 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3464 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3465 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3466 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3467 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3468 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3469 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3470 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3471 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3472 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3473 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3474 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3475 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3476 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3477 {
3478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3479 /* The multiple "Capture Source" controls confuse alsamixer
3480 * So call somewhat different..
3481 */
3482 /* .name = "Capture Source", */
3483 .name = "Input Source",
3484 .count = 2,
3485 .info = ad198x_mux_enum_info,
3486 .get = ad198x_mux_enum_get,
3487 .put = ad198x_mux_enum_put,
3488 },
3489 /* SPDIF controls */
3490 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3491 {
3492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3493 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3494 /* identical with ad1983 */
3495 .info = ad1983_spdif_route_info,
3496 .get = ad1983_spdif_route_get,
3497 .put = ad1983_spdif_route_put,
3498 },
3499 { } /* end */
3500};
3501
3502/*
3503 * initialization verbs
3504 */
3505static struct hda_verb ad1884a_init_verbs[] = {
3506 /* DACs; unmute as default */
3507 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3508 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3509 /* Port-A (HP) mixer - route only from analog mixer */
3510 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3511 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3512 /* Port-A pin */
3513 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3514 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3515 /* Port-D (Line-out) mixer - route only from analog mixer */
3516 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3517 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3518 /* Port-D pin */
3519 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3520 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3521 /* Mono-out mixer - route only from analog mixer */
3522 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3523 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3524 /* Mono-out pin */
3525 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3526 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3527 /* Port-B (front mic) pin */
3528 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3529 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3530 /* Port-C (rear line-in) pin */
3531 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3532 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3533 /* Port-E (rear mic) pin */
3534 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3535 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3536 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3537 /* Port-F (CD) pin */
3538 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3539 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3540 /* Analog mixer; mute as default */
3541 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3542 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3543 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3544 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3545 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3546 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3547 /* Analog Mix output amp */
3548 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3549 /* capture sources */
3550 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3551 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3552 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3553 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3554 /* SPDIF output amp */
3555 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3556 { } /* end */
3557};
3558
3559#ifdef CONFIG_SND_HDA_POWER_SAVE
3560static struct hda_amp_list ad1884a_loopbacks[] = {
3561 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3562 { 0x20, HDA_INPUT, 1 }, /* Mic */
3563 { 0x20, HDA_INPUT, 2 }, /* CD */
3564 { 0x20, HDA_INPUT, 4 }, /* Docking */
3565 { } /* end */
3566};
3567#endif
3568
3569/*
3570 * Laptop model
3571 *
3572 * Port A: Headphone jack
3573 * Port B: MIC jack
3574 * Port C: Internal MIC
3575 * Port D: Dock Line Out (if enabled)
3576 * Port E: Dock Line In (if enabled)
3577 * Port F: Internal speakers
3578 */
3579
3580static struct hda_input_mux ad1884a_laptop_capture_source = {
3581 .num_items = 4,
3582 .items = {
3583 { "Mic", 0x0 }, /* port-B */
3584 { "Internal Mic", 0x1 }, /* port-C */
3585 { "Dock Mic", 0x4 }, /* port-E */
3586 { "Mix", 0x3 },
3587 },
3588};
3589
3590static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3591 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3592 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3593 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3594 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3595 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3596 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3597 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3598 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3599 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3600 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3601 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3602 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3603 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3604 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3605 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3606 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3607 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3608 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3609 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3610 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3611 {
3612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3613 /* The multiple "Capture Source" controls confuse alsamixer
3614 * So call somewhat different..
3615 */
3616 /* .name = "Capture Source", */
3617 .name = "Input Source",
3618 .count = 2,
3619 .info = ad198x_mux_enum_info,
3620 .get = ad198x_mux_enum_get,
3621 .put = ad198x_mux_enum_put,
3622 },
3623 { } /* end */
3624};
3625
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003626static struct hda_input_mux ad1884a_mobile_capture_source = {
3627 .num_items = 2,
3628 .items = {
3629 { "Mic", 0x1 }, /* port-C */
3630 { "Mix", 0x3 },
3631 },
3632};
3633
3634static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3635 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3636 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3637 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3638 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3639 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3640 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3641 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3642 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3643 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3644 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3645 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3646 {
3647 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3648 .name = "Capture Source",
3649 .info = ad198x_mux_enum_info,
3650 .get = ad198x_mux_enum_get,
3651 .put = ad198x_mux_enum_put,
3652 },
3653 { } /* end */
3654};
3655
Takashi Iwaic5059252008-02-16 09:43:56 +01003656/* mute internal speaker if HP is plugged */
3657static void ad1884a_hp_automute(struct hda_codec *codec)
3658{
3659 unsigned int present;
3660
3661 present = snd_hda_codec_read(codec, 0x11, 0,
3662 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3663 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3664 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3665 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3666 present ? 0x00 : 0x02);
3667}
3668
3669#define AD1884A_HP_EVENT 0x37
3670
3671/* unsolicited event for HP jack sensing */
3672static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3673{
3674 if ((res >> 26) != AD1884A_HP_EVENT)
3675 return;
3676 ad1884a_hp_automute(codec);
3677}
3678
3679/* initialize jack-sensing, too */
3680static int ad1884a_hp_init(struct hda_codec *codec)
3681{
3682 ad198x_init(codec);
3683 ad1884a_hp_automute(codec);
3684 return 0;
3685}
3686
3687/* additional verbs for laptop model */
3688static struct hda_verb ad1884a_laptop_verbs[] = {
3689 /* Port-A (HP) pin - always unmuted */
3690 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3691 /* Port-F (int speaker) mixer - route only from analog mixer */
3692 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3693 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3694 /* Port-F pin */
3695 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3696 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3697 /* analog mix */
3698 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3699 /* unsolicited event for pin-sense */
3700 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3701 { } /* end */
3702};
3703
3704/*
Takashi Iwaif0813742008-03-18 12:13:03 +01003705 * Thinkpad X300
3706 * 0x11 - HP
3707 * 0x12 - speaker
3708 * 0x14 - mic-in
3709 * 0x17 - built-in mic
3710 */
3711
3712static struct hda_verb ad1984a_thinkpad_verbs[] = {
3713 /* HP unmute */
3714 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3715 /* analog mix */
3716 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3717 /* turn on EAPD */
3718 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3719 /* unsolicited event for pin-sense */
3720 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3721 /* internal mic - dmic */
3722 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3723 { } /* end */
3724};
3725
3726static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3727 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3728 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3729 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3730 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3731 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3732 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3733 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3734 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3735 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3736 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3737 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3738 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3739 {
3740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3741 .name = "Capture Source",
3742 .info = ad198x_mux_enum_info,
3743 .get = ad198x_mux_enum_get,
3744 .put = ad198x_mux_enum_put,
3745 },
3746 { } /* end */
3747};
3748
3749static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3750 .num_items = 3,
3751 .items = {
3752 { "Mic", 0x0 },
3753 { "Internal Mic", 0x5 },
3754 { "Mix", 0x3 },
3755 },
3756};
3757
3758/* mute internal speaker if HP is plugged */
3759static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3760{
3761 unsigned int present;
3762
3763 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3764 & AC_PINSENSE_PRESENCE;
3765 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3766 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3767}
3768
3769/* unsolicited event for HP jack sensing */
3770static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3771 unsigned int res)
3772{
3773 if ((res >> 26) != AD1884A_HP_EVENT)
3774 return;
3775 ad1984a_thinkpad_automute(codec);
3776}
3777
3778/* initialize jack-sensing, too */
3779static int ad1984a_thinkpad_init(struct hda_codec *codec)
3780{
3781 ad198x_init(codec);
3782 ad1984a_thinkpad_automute(codec);
3783 return 0;
3784}
3785
3786/*
Takashi Iwaic5059252008-02-16 09:43:56 +01003787 */
3788
3789enum {
3790 AD1884A_DESKTOP,
3791 AD1884A_LAPTOP,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003792 AD1884A_MOBILE,
Takashi Iwaif0813742008-03-18 12:13:03 +01003793 AD1884A_THINKPAD,
Takashi Iwaic5059252008-02-16 09:43:56 +01003794 AD1884A_MODELS
3795};
3796
3797static const char *ad1884a_models[AD1884A_MODELS] = {
3798 [AD1884A_DESKTOP] = "desktop",
3799 [AD1884A_LAPTOP] = "laptop",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003800 [AD1884A_MOBILE] = "mobile",
Takashi Iwaif0813742008-03-18 12:13:03 +01003801 [AD1884A_THINKPAD] = "thinkpad",
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003802};
3803
3804static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3805 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
Takashi Iwaif0813742008-03-18 12:13:03 +01003806 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003807 {}
Takashi Iwaic5059252008-02-16 09:43:56 +01003808};
3809
3810static int patch_ad1884a(struct hda_codec *codec)
3811{
3812 struct ad198x_spec *spec;
3813 int board_config;
3814
3815 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3816 if (spec == NULL)
3817 return -ENOMEM;
3818
3819 mutex_init(&spec->amp_mutex);
3820 codec->spec = spec;
3821
3822 spec->multiout.max_channels = 2;
3823 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3824 spec->multiout.dac_nids = ad1884a_dac_nids;
3825 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3826 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3827 spec->adc_nids = ad1884a_adc_nids;
3828 spec->capsrc_nids = ad1884a_capsrc_nids;
3829 spec->input_mux = &ad1884a_capture_source;
3830 spec->num_mixers = 1;
3831 spec->mixers[0] = ad1884a_base_mixers;
3832 spec->num_init_verbs = 1;
3833 spec->init_verbs[0] = ad1884a_init_verbs;
3834 spec->spdif_route = 0;
3835#ifdef CONFIG_SND_HDA_POWER_SAVE
3836 spec->loopback.amplist = ad1884a_loopbacks;
3837#endif
3838 codec->patch_ops = ad198x_patch_ops;
3839
3840 /* override some parameters */
3841 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003842 ad1884a_models,
3843 ad1884a_cfg_tbl);
Takashi Iwaic5059252008-02-16 09:43:56 +01003844 switch (board_config) {
3845 case AD1884A_LAPTOP:
3846 spec->mixers[0] = ad1884a_laptop_mixers;
3847 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3848 spec->multiout.dig_out_nid = 0;
3849 spec->input_mux = &ad1884a_laptop_capture_source;
3850 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3851 codec->patch_ops.init = ad1884a_hp_init;
3852 break;
Takashi Iwaib40b04a2008-02-16 09:44:56 +01003853 case AD1884A_MOBILE:
3854 spec->mixers[0] = ad1884a_mobile_mixers;
3855 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3856 spec->multiout.dig_out_nid = 0;
3857 spec->input_mux = &ad1884a_mobile_capture_source;
3858 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3859 codec->patch_ops.init = ad1884a_hp_init;
3860 break;
Takashi Iwaif0813742008-03-18 12:13:03 +01003861 case AD1884A_THINKPAD:
3862 spec->mixers[0] = ad1984a_thinkpad_mixers;
3863 spec->init_verbs[spec->num_init_verbs++] =
3864 ad1984a_thinkpad_verbs;
3865 spec->multiout.dig_out_nid = 0;
3866 spec->input_mux = &ad1984a_thinkpad_capture_source;
3867 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3868 codec->patch_ops.init = ad1984a_thinkpad_init;
3869 break;
Takashi Iwaic5059252008-02-16 09:43:56 +01003870 }
3871
3872 return 0;
3873}
3874
3875
3876/*
Takashi Iwai0ac85512007-06-20 15:46:13 +02003877 * AD1882
3878 *
3879 * port-A - front hp-out
3880 * port-B - front mic-in
3881 * port-C - rear line-in, shared surr-out (3stack)
3882 * port-D - rear line-out
3883 * port-E - rear mic-in, shared clfe-out (3stack)
3884 * port-F - rear surr-out (6stack)
3885 * port-G - rear clfe-out (6stack)
3886 */
3887
3888static hda_nid_t ad1882_dac_nids[3] = {
3889 0x04, 0x03, 0x05
3890};
3891
3892static hda_nid_t ad1882_adc_nids[2] = {
3893 0x08, 0x09,
3894};
3895
3896static hda_nid_t ad1882_capsrc_nids[2] = {
3897 0x0c, 0x0d,
3898};
3899
3900#define AD1882_SPDIF_OUT 0x02
3901
3902/* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
3903static struct hda_input_mux ad1882_capture_source = {
3904 .num_items = 5,
3905 .items = {
3906 { "Front Mic", 0x1 },
3907 { "Mic", 0x4 },
3908 { "Line", 0x2 },
3909 { "CD", 0x3 },
3910 { "Mix", 0x7 },
3911 },
3912};
3913
3914static struct snd_kcontrol_new ad1882_base_mixers[] = {
3915 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
3916 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
3917 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
3918 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
3919 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3920 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3921 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3922 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3923 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3924 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3925 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3926 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3927 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
3928 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
3929 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
3930 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
3931 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
3932 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
3933 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
3934 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
3935 HDA_CODEC_VOLUME("Line-In Boost", 0x3a, 0x0, HDA_OUTPUT),
3936 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3937 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3938 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3939 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3940 {
3941 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3942 /* The multiple "Capture Source" controls confuse alsamixer
3943 * So call somewhat different..
Takashi Iwai0ac85512007-06-20 15:46:13 +02003944 */
3945 /* .name = "Capture Source", */
3946 .name = "Input Source",
3947 .count = 2,
3948 .info = ad198x_mux_enum_info,
3949 .get = ad198x_mux_enum_get,
3950 .put = ad198x_mux_enum_put,
3951 },
3952 /* SPDIF controls */
3953 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3954 {
3955 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3956 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3957 /* identical with ad1983 */
3958 .info = ad1983_spdif_route_info,
3959 .get = ad1983_spdif_route_get,
3960 .put = ad1983_spdif_route_put,
3961 },
3962 { } /* end */
3963};
3964
3965static struct snd_kcontrol_new ad1882_3stack_mixers[] = {
3966 HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
3967 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
3968 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
3969 {
3970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3971 .name = "Channel Mode",
3972 .info = ad198x_ch_mode_info,
3973 .get = ad198x_ch_mode_get,
3974 .put = ad198x_ch_mode_put,
3975 },
3976 { } /* end */
3977};
3978
3979static struct snd_kcontrol_new ad1882_6stack_mixers[] = {
3980 HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
3981 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
3982 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
3983 { } /* end */
3984};
3985
3986static struct hda_verb ad1882_ch2_init[] = {
3987 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3988 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3989 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3990 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3991 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3992 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3993 { } /* end */
3994};
3995
3996static struct hda_verb ad1882_ch4_init[] = {
3997 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
3998 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3999 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4000 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4001 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4002 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4003 { } /* end */
4004};
4005
4006static struct hda_verb ad1882_ch6_init[] = {
4007 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4008 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4009 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4010 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4011 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4012 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4013 { } /* end */
4014};
4015
4016static struct hda_channel_mode ad1882_modes[3] = {
4017 { 2, ad1882_ch2_init },
4018 { 4, ad1882_ch4_init },
4019 { 6, ad1882_ch6_init },
4020};
4021
4022/*
4023 * initialization verbs
4024 */
4025static struct hda_verb ad1882_init_verbs[] = {
4026 /* DACs; mute as default */
4027 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4028 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4029 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
4030 /* Port-A (HP) mixer */
4031 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4032 {0x22, 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 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4036 /* HP selector - select DAC2 */
4037 {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
4038 /* Port-D (Line-out) mixer */
4039 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4040 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4041 /* Port-D pin */
4042 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4043 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4044 /* Mono-out mixer */
4045 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4046 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
4047 /* Mono-out pin */
4048 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
4049 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4050 /* Port-B (front mic) pin */
4051 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4052 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4053 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4054 /* Port-C (line-in) pin */
4055 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
4056 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4057 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4058 /* Port-C mixer - mute as input */
4059 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4060 {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4061 /* Port-E (mic-in) pin */
4062 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
4063 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4064 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
4065 /* Port-E mixer - mute as input */
4066 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4067 {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4068 /* Port-F (surround) */
4069 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4070 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4071 /* Port-G (CLFE) */
4072 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
4073 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
4074 /* Analog mixer; mute as default */
4075 /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
4076 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
4077 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4078 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
4079 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
4080 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
4081 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
4082 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
4083 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
4084 /* Analog Mix output amp */
4085 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
4086 /* SPDIF output selector */
4087 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4088 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
4089 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
4090 { } /* end */
4091};
4092
Takashi Iwaicb53c622007-08-10 17:21:45 +02004093#ifdef CONFIG_SND_HDA_POWER_SAVE
4094static struct hda_amp_list ad1882_loopbacks[] = {
4095 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
4096 { 0x20, HDA_INPUT, 1 }, /* Mic */
4097 { 0x20, HDA_INPUT, 4 }, /* Line */
4098 { 0x20, HDA_INPUT, 6 }, /* CD */
4099 { } /* end */
4100};
4101#endif
4102
Takashi Iwai0ac85512007-06-20 15:46:13 +02004103/* models */
4104enum {
4105 AD1882_3STACK,
4106 AD1882_6STACK,
4107 AD1882_MODELS
4108};
4109
4110static const char *ad1882_models[AD1986A_MODELS] = {
4111 [AD1882_3STACK] = "3stack",
4112 [AD1882_6STACK] = "6stack",
4113};
4114
4115
4116static int patch_ad1882(struct hda_codec *codec)
4117{
4118 struct ad198x_spec *spec;
4119 int board_config;
4120
4121 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4122 if (spec == NULL)
4123 return -ENOMEM;
4124
4125 mutex_init(&spec->amp_mutex);
4126 codec->spec = spec;
4127
4128 spec->multiout.max_channels = 6;
4129 spec->multiout.num_dacs = 3;
4130 spec->multiout.dac_nids = ad1882_dac_nids;
4131 spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
4132 spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
4133 spec->adc_nids = ad1882_adc_nids;
4134 spec->capsrc_nids = ad1882_capsrc_nids;
4135 spec->input_mux = &ad1882_capture_source;
4136 spec->num_mixers = 1;
4137 spec->mixers[0] = ad1882_base_mixers;
4138 spec->num_init_verbs = 1;
4139 spec->init_verbs[0] = ad1882_init_verbs;
4140 spec->spdif_route = 0;
Takashi Iwaicb53c622007-08-10 17:21:45 +02004141#ifdef CONFIG_SND_HDA_POWER_SAVE
4142 spec->loopback.amplist = ad1882_loopbacks;
4143#endif
Takashi Iwai2134ea42008-01-10 16:53:55 +01004144 spec->vmaster_nid = 0x04;
Takashi Iwai0ac85512007-06-20 15:46:13 +02004145
4146 codec->patch_ops = ad198x_patch_ops;
4147
4148 /* override some parameters */
4149 board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
4150 ad1882_models, NULL);
4151 switch (board_config) {
4152 default:
4153 case AD1882_3STACK:
4154 spec->num_mixers = 2;
4155 spec->mixers[1] = ad1882_3stack_mixers;
4156 spec->channel_mode = ad1882_modes;
4157 spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
4158 spec->need_dac_fix = 1;
4159 spec->multiout.max_channels = 2;
4160 spec->multiout.num_dacs = 1;
4161 break;
4162 case AD1882_6STACK:
4163 spec->num_mixers = 2;
4164 spec->mixers[1] = ad1882_6stack_mixers;
4165 break;
4166 }
4167 return 0;
4168}
4169
4170
4171/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 * patch entries
4173 */
4174struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwaic5059252008-02-16 09:43:56 +01004175 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
Takashi Iwai0ac85512007-06-20 15:46:13 +02004176 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004177 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004178 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
Takashi Iwaic5059252008-02-16 09:43:56 +01004179 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4180 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02004181 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
4182 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Takashi Iwai2bac6472007-05-18 18:21:41 +02004183 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01004185 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Takashi Iwai71b2ccc2006-04-21 16:09:31 +02004186 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 {} /* terminator */
4188};