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