blob: 2b14fa74a8fd01d7d4fadc978a261a36cee13c8f [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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 },
789 { .modelname = "laptop", .config = AD1986A_LAPTOP },
790 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc01e,
791 .config = AD1986A_LAPTOP }, /* FSC V2060 */
792 { .pci_subvendor = 0x17c0, .pci_subdevice = 0x2017,
793 .config = AD1986A_LAPTOP }, /* Samsung M50 */
Takashi Iwai825aa972006-03-17 10:50:49 +0100794 { .pci_subvendor = 0x1043, .pci_subdevice = 0x818f,
795 .config = AD1986A_LAPTOP }, /* ASUS P5GV-MX */
796 { .modelname = "laptop-eapd", .config = AD1986A_LAPTOP_EAPD },
797 { .pci_subvendor = 0x144d, .pci_subdevice = 0xc024,
798 .config = AD1986A_LAPTOP_EAPD }, /* Samsung R65-T2300 Charis */
799 { .pci_subvendor = 0x1043, .pci_subdevice = 0x1213,
800 .config = AD1986A_LAPTOP_EAPD }, /* ASUS A6J */
Takashi Iwai9230d212006-03-13 13:49:49 +0100801 {}
802};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804static int patch_ad1986a(struct hda_codec *codec)
805{
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200806 struct ad198x_spec *spec;
Takashi Iwai9230d212006-03-13 13:49:49 +0100807 int board_config;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Takashi Iwaie560d8d2005-09-09 14:21:46 +0200809 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 if (spec == NULL)
811 return -ENOMEM;
812
Ingo Molnar62932df2006-01-16 16:34:20 +0100813 mutex_init(&spec->amp_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 codec->spec = spec;
815
816 spec->multiout.max_channels = 6;
817 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
818 spec->multiout.dac_nids = ad1986a_dac_nids;
819 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +0100820 spec->num_adc_nids = 1;
821 spec->adc_nids = ad1986a_adc_nids;
Takashi Iwaia7ee8202006-03-01 20:05:39 +0100822 spec->capsrc_nids = ad1986a_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200823 spec->input_mux = &ad1986a_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +0100824 spec->num_mixers = 1;
825 spec->mixers[0] = ad1986a_mixers;
826 spec->num_init_verbs = 1;
827 spec->init_verbs[0] = ad1986a_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200829 codec->patch_ops = ad198x_patch_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Takashi Iwai9230d212006-03-13 13:49:49 +0100831 /* override some parameters */
832 board_config = snd_hda_check_board_config(codec, ad1986a_cfg_tbl);
833 switch (board_config) {
834 case AD1986A_3STACK:
835 spec->num_mixers = 2;
836 spec->mixers[1] = ad1986a_3st_mixers;
837 spec->num_init_verbs = 2;
838 spec->init_verbs[1] = ad1986a_3st_init_verbs;
839 spec->channel_mode = ad1986a_modes;
840 spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
841 break;
842 case AD1986A_LAPTOP:
843 spec->mixers[0] = ad1986a_laptop_mixers;
844 spec->multiout.max_channels = 2;
845 spec->multiout.num_dacs = 1;
846 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
847 break;
Takashi Iwai825aa972006-03-17 10:50:49 +0100848 case AD1986A_LAPTOP_EAPD:
849 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
850 spec->num_init_verbs = 2;
851 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
852 spec->multiout.max_channels = 2;
853 spec->multiout.num_dacs = 1;
854 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
855 spec->multiout.dig_out_nid = 0;
856 spec->input_mux = &ad1986a_laptop_eapd_capture_source;
857 break;
Takashi Iwai9230d212006-03-13 13:49:49 +0100858 }
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 return 0;
861}
862
863/*
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200864 * AD1983 specific
865 */
866
867#define AD1983_SPDIF_OUT 0x02
868#define AD1983_DAC 0x03
869#define AD1983_ADC 0x04
870
871static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +0100872static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +0100873static hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200874
875static struct hda_input_mux ad1983_capture_source = {
876 .num_items = 4,
877 .items = {
878 { "Mic", 0x0 },
879 { "Line", 0x1 },
880 { "Mix", 0x2 },
881 { "Mix Mono", 0x3 },
882 },
883};
884
885/*
886 * SPDIF playback route
887 */
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100888static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200889{
890 static char *texts[] = { "PCM", "ADC" };
891
892 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
893 uinfo->count = 1;
894 uinfo->value.enumerated.items = 2;
895 if (uinfo->value.enumerated.item > 1)
896 uinfo->value.enumerated.item = 1;
897 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
898 return 0;
899}
900
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100901static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200902{
903 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
904 struct ad198x_spec *spec = codec->spec;
905
906 ucontrol->value.enumerated.item[0] = spec->spdif_route;
907 return 0;
908}
909
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100910static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200911{
912 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
913 struct ad198x_spec *spec = codec->spec;
914
915 if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
916 spec->spdif_route = ucontrol->value.enumerated.item[0];
917 snd_hda_codec_write(codec, spec->multiout.dig_out_nid, 0,
918 AC_VERB_SET_CONNECT_SEL, spec->spdif_route);
919 return 1;
920 }
921 return 0;
922}
923
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100924static struct snd_kcontrol_new ad1983_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200925 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
926 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
927 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
928 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
929 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
930 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
931 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
932 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
933 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
934 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
935 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
936 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
937 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
938 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
939 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
940 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
941 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
942 {
943 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
944 .name = "Capture Source",
945 .info = ad198x_mux_enum_info,
946 .get = ad198x_mux_enum_get,
947 .put = ad198x_mux_enum_put,
948 },
949 {
950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clemens Ladisch10e8d782005-08-03 13:40:08 +0200951 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200952 .info = ad1983_spdif_route_info,
953 .get = ad1983_spdif_route_get,
954 .put = ad1983_spdif_route_put,
955 },
956 { } /* end */
957};
958
959static struct hda_verb ad1983_init_verbs[] = {
960 /* Front, HP, Mono; mute as default */
961 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
962 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
963 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
964 /* Beep, PCM, Mic, Line-In: mute */
965 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
966 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
967 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
968 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
969 /* Front, HP selectors; from Mix */
970 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
971 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
972 /* Mono selector; from Mix */
973 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
974 /* Mic selector; Mic */
975 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
976 /* Line-in selector: Line-in */
977 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
978 /* Mic boost: 0dB */
979 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
980 /* Record selector: mic */
981 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
982 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
983 /* SPDIF route: PCM */
984 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
985 /* Front Pin */
986 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
987 /* HP Pin */
988 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
989 /* Mono Pin */
990 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
991 /* Mic Pin */
992 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
993 /* Line Pin */
994 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
995 { } /* end */
996};
997
Takashi Iwai985be542005-11-02 18:26:49 +0100998
Takashi Iwai4a3fdf32005-04-14 13:35:51 +0200999static int patch_ad1983(struct hda_codec *codec)
1000{
1001 struct ad198x_spec *spec;
1002
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001003 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001004 if (spec == NULL)
1005 return -ENOMEM;
1006
Ingo Molnar62932df2006-01-16 16:34:20 +01001007 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001008 codec->spec = spec;
1009
1010 spec->multiout.max_channels = 2;
1011 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1012 spec->multiout.dac_nids = ad1983_dac_nids;
1013 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001014 spec->num_adc_nids = 1;
1015 spec->adc_nids = ad1983_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001016 spec->capsrc_nids = ad1983_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001017 spec->input_mux = &ad1983_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001018 spec->num_mixers = 1;
1019 spec->mixers[0] = ad1983_mixers;
1020 spec->num_init_verbs = 1;
1021 spec->init_verbs[0] = ad1983_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001022 spec->spdif_route = 0;
1023
1024 codec->patch_ops = ad198x_patch_ops;
1025
1026 return 0;
1027}
1028
1029
1030/*
1031 * AD1981 HD specific
1032 */
1033
1034#define AD1981_SPDIF_OUT 0x02
1035#define AD1981_DAC 0x03
1036#define AD1981_ADC 0x04
1037
1038static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
Takashi Iwai985be542005-11-02 18:26:49 +01001039static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
Takashi Iwai18a815d2006-03-01 19:54:39 +01001040static hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001041
1042/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
1043static struct hda_input_mux ad1981_capture_source = {
1044 .num_items = 7,
1045 .items = {
1046 { "Front Mic", 0x0 },
1047 { "Line", 0x1 },
1048 { "Mix", 0x2 },
1049 { "Mix Mono", 0x3 },
1050 { "CD", 0x4 },
1051 { "Mic", 0x6 },
1052 { "Aux", 0x7 },
1053 },
1054};
1055
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01001056static struct snd_kcontrol_new ad1981_mixers[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001057 HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1058 HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
1059 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1060 HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
1061 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
1062 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
1063 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1064 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1065 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1066 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1067 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1068 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1069 HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1070 HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
1071 HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1072 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1073 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1074 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1075 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1076 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1077 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1078 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1079 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1080 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1081 {
1082 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1083 .name = "Capture Source",
1084 .info = ad198x_mux_enum_info,
1085 .get = ad198x_mux_enum_get,
1086 .put = ad198x_mux_enum_put,
1087 },
1088 /* identical with AD1983 */
1089 {
1090 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Clemens Ladisch10e8d782005-08-03 13:40:08 +02001091 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Route",
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001092 .info = ad1983_spdif_route_info,
1093 .get = ad1983_spdif_route_get,
1094 .put = ad1983_spdif_route_put,
1095 },
1096 { } /* end */
1097};
1098
1099static struct hda_verb ad1981_init_verbs[] = {
1100 /* Front, HP, Mono; mute as default */
1101 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1102 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1103 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1104 /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
1105 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1106 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1107 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1108 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1109 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1110 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1111 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1112 /* Front, HP selectors; from Mix */
1113 {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
1114 {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
1115 /* Mono selector; from Mix */
1116 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
1117 /* Mic Mixer; select Front Mic */
1118 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1119 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1120 /* Mic boost: 0dB */
1121 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1122 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1123 /* Record selector: Front mic */
1124 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1125 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1126 /* SPDIF route: PCM */
1127 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
1128 /* Front Pin */
1129 {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1130 /* HP Pin */
1131 {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
1132 /* Mono Pin */
1133 {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
1134 /* Front & Rear Mic Pins */
1135 {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1136 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
1137 /* Line Pin */
1138 {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1139 /* Digital Beep */
1140 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
1141 /* Line-Out as Input: disabled */
1142 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1143 { } /* end */
1144};
1145
Takashi Iwai18a815d2006-03-01 19:54:39 +01001146/*
1147 * Patch for HP nx6320
1148 *
1149 * nx6320 uses EAPD in the reserve way - EAPD-on means the internal
1150 * speaker output enabled _and_ mute-LED off.
1151 */
1152
1153#define AD1981_HP_EVENT 0x37
1154#define AD1981_MIC_EVENT 0x38
1155
1156static struct hda_verb ad1981_hp_init_verbs[] = {
1157 {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
1158 /* pin sensing on HP and Mic jacks */
1159 {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
1160 {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
1161 {}
1162};
1163
1164/* turn on/off EAPD (+ mute HP) as a master switch */
1165static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1166 struct snd_ctl_elem_value *ucontrol)
1167{
1168 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1169 struct ad198x_spec *spec = codec->spec;
1170
1171 if (! ad198x_eapd_put(kcontrol, ucontrol))
1172 return 0;
1173
1174 /* toggle HP mute appropriately */
1175 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1176 0x80, spec->cur_eapd ? 0 : 0x80);
1177 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1178 0x80, spec->cur_eapd ? 0 : 0x80);
1179 return 1;
1180}
1181
1182/* bind volumes of both NID 0x05 and 0x06 */
1183static int ad1981_hp_master_vol_put(struct snd_kcontrol *kcontrol,
1184 struct snd_ctl_elem_value *ucontrol)
1185{
1186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1187 long *valp = ucontrol->value.integer.value;
1188 int change;
1189
1190 change = snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1191 0x7f, valp[0] & 0x7f);
1192 change |= snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1193 0x7f, valp[1] & 0x7f);
1194 snd_hda_codec_amp_update(codec, 0x06, 0, HDA_OUTPUT, 0,
1195 0x7f, valp[0] & 0x7f);
1196 snd_hda_codec_amp_update(codec, 0x06, 1, HDA_OUTPUT, 0,
1197 0x7f, valp[1] & 0x7f);
1198 return change;
1199}
1200
1201/* mute internal speaker if HP is plugged */
1202static void ad1981_hp_automute(struct hda_codec *codec)
1203{
1204 unsigned int present;
1205
1206 present = snd_hda_codec_read(codec, 0x06, 0,
1207 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1208 snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
1209 0x80, present ? 0x80 : 0);
1210 snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
1211 0x80, present ? 0x80 : 0);
1212}
1213
1214/* toggle input of built-in and mic jack appropriately */
1215static void ad1981_hp_automic(struct hda_codec *codec)
1216{
1217 static struct hda_verb mic_jack_on[] = {
1218 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1219 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1220 {}
1221 };
1222 static struct hda_verb mic_jack_off[] = {
1223 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1224 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1225 {}
1226 };
1227 unsigned int present;
1228
1229 present = snd_hda_codec_read(codec, 0x08, 0,
1230 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1231 if (present)
1232 snd_hda_sequence_write(codec, mic_jack_on);
1233 else
1234 snd_hda_sequence_write(codec, mic_jack_off);
1235}
1236
1237/* unsolicited event for HP jack sensing */
1238static void ad1981_hp_unsol_event(struct hda_codec *codec,
1239 unsigned int res)
1240{
1241 res >>= 26;
1242 switch (res) {
1243 case AD1981_HP_EVENT:
1244 ad1981_hp_automute(codec);
1245 break;
1246 case AD1981_MIC_EVENT:
1247 ad1981_hp_automic(codec);
1248 break;
1249 }
1250}
1251
1252static struct hda_input_mux ad1981_hp_capture_source = {
1253 .num_items = 3,
1254 .items = {
1255 { "Mic", 0x0 },
1256 { "Docking-Station", 0x1 },
1257 { "Mix", 0x2 },
1258 },
1259};
1260
1261static struct snd_kcontrol_new ad1981_hp_mixers[] = {
1262 {
1263 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1264 .name = "Master Playback Volume",
1265 .info = snd_hda_mixer_amp_volume_info,
1266 .get = snd_hda_mixer_amp_volume_get,
1267 .put = ad1981_hp_master_vol_put,
1268 .private_value = HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
1269 },
1270 {
1271 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1272 .name = "Master Playback Switch",
1273 .info = ad198x_eapd_info,
1274 .get = ad198x_eapd_get,
1275 .put = ad1981_hp_master_sw_put,
1276 .private_value = 0x05,
1277 },
1278 HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
1279 HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
1280#if 0
1281 /* FIXME: analog mic/line loopback doesn't work with my tests...
1282 * (although recording is OK)
1283 */
1284 HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
1285 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1286 HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1287 HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1288 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
1289 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1290 /* FIXME: does this laptop have analog CD connection? */
1291 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1292 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1293#endif
1294 HDA_CODEC_VOLUME("Mic Boost", 0x08, 0x0, HDA_INPUT),
1295 HDA_CODEC_VOLUME("Internal Mic Boost", 0x18, 0x0, HDA_INPUT),
1296 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1297 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
1298 {
1299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1300 .name = "Capture Source",
1301 .info = ad198x_mux_enum_info,
1302 .get = ad198x_mux_enum_get,
1303 .put = ad198x_mux_enum_put,
1304 },
1305 { } /* end */
1306};
1307
1308/* initialize jack-sensing, too */
1309static int ad1981_hp_init(struct hda_codec *codec)
1310{
1311 ad198x_init(codec);
1312 ad1981_hp_automute(codec);
1313 ad1981_hp_automic(codec);
1314 return 0;
1315}
1316
1317/* models */
1318enum { AD1981_BASIC, AD1981_HP };
1319
1320static struct hda_board_config ad1981_cfg_tbl[] = {
1321 { .modelname = "hp", .config = AD1981_HP },
1322 { .pci_subvendor = 0x103c, .pci_subdevice = 0x30aa,
1323 .config = AD1981_HP },
1324 { .modelname = "basic", .config = AD1981_BASIC },
1325 {}
1326};
1327
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001328static int patch_ad1981(struct hda_codec *codec)
1329{
1330 struct ad198x_spec *spec;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001331 int board_config;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001332
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001333 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001334 if (spec == NULL)
1335 return -ENOMEM;
1336
Ingo Molnar62932df2006-01-16 16:34:20 +01001337 mutex_init(&spec->amp_mutex);
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001338 codec->spec = spec;
1339
1340 spec->multiout.max_channels = 2;
1341 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1342 spec->multiout.dac_nids = ad1981_dac_nids;
1343 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
Takashi Iwai985be542005-11-02 18:26:49 +01001344 spec->num_adc_nids = 1;
1345 spec->adc_nids = ad1981_adc_nids;
Takashi Iwai18a815d2006-03-01 19:54:39 +01001346 spec->capsrc_nids = ad1981_capsrc_nids;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001347 spec->input_mux = &ad1981_capture_source;
Takashi Iwai985be542005-11-02 18:26:49 +01001348 spec->num_mixers = 1;
1349 spec->mixers[0] = ad1981_mixers;
1350 spec->num_init_verbs = 1;
1351 spec->init_verbs[0] = ad1981_init_verbs;
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001352 spec->spdif_route = 0;
1353
1354 codec->patch_ops = ad198x_patch_ops;
1355
Takashi Iwai18a815d2006-03-01 19:54:39 +01001356 /* override some parameters */
1357 board_config = snd_hda_check_board_config(codec, ad1981_cfg_tbl);
1358 switch (board_config) {
1359 case AD1981_HP:
1360 spec->mixers[0] = ad1981_hp_mixers;
1361 spec->num_init_verbs = 2;
1362 spec->init_verbs[1] = ad1981_hp_init_verbs;
1363 spec->multiout.dig_out_nid = 0;
1364 spec->input_mux = &ad1981_hp_capture_source;
1365
1366 codec->patch_ops.init = ad1981_hp_init;
1367 codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
1368 break;
1369 }
1370
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02001371 return 0;
1372}
1373
1374
1375/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001376 * AD1988
1377 *
1378 * Output pins and routes
1379 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001380 * Pin Mix Sel DAC (*)
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001381 * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
1382 * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
1383 * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
1384 * port-D 0x12 (mute/hp) <- 0x29 <- 04
1385 * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
1386 * port-F 0x16 (mute) <- 0x2a <- 06
1387 * port-G 0x24 (mute) <- 0x27 <- 05
1388 * port-H 0x25 (mute) <- 0x28 <- 0a
1389 * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
1390 *
Takashi Iwaid32410b12005-11-24 16:06:23 +01001391 * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
1392 * (*) 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 +01001393 *
1394 * Input pins and routes
1395 *
1396 * pin boost mix input # / adc input #
1397 * port-A 0x11 -> 0x38 -> mix 2, ADC 0
1398 * port-B 0x14 -> 0x39 -> mix 0, ADC 1
1399 * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
1400 * port-D 0x12 -> 0x3d -> mix 3, ADC 8
1401 * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
1402 * port-F 0x16 -> 0x3b -> mix 5, ADC 3
1403 * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
1404 * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
1405 *
1406 *
1407 * DAC assignment
Takashi Iwaid32410b12005-11-24 16:06:23 +01001408 * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001409 * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001410 *
1411 * Inputs of Analog Mix (0x20)
1412 * 0:Port-B (front mic)
1413 * 1:Port-C/G/H (line-in)
1414 * 2:Port-A
1415 * 3:Port-D (line-in/2)
1416 * 4:Port-E/G/H (mic-in)
1417 * 5:Port-F (mic2-in)
1418 * 6:CD
1419 * 7:Beep
1420 *
1421 * ADC selection
1422 * 0:Port-A
1423 * 1:Port-B (front mic-in)
1424 * 2:Port-C (line-in)
1425 * 3:Port-F (mic2-in)
1426 * 4:Port-E (mic-in)
1427 * 5:CD
1428 * 6:Port-G
1429 * 7:Port-H
1430 * 8:Port-D (line-in/2)
1431 * 9:Mix
1432 *
1433 * Proposed pin assignments by the datasheet
1434 *
1435 * 6-stack
1436 * Port-A front headphone
1437 * B front mic-in
1438 * C rear line-in
1439 * D rear front-out
1440 * E rear mic-in
1441 * F rear surround
1442 * G rear CLFE
1443 * H rear side
1444 *
1445 * 3-stack
1446 * Port-A front headphone
1447 * B front mic
1448 * C rear line-in/surround
1449 * D rear front-out
1450 * E rear mic-in/CLFE
1451 *
1452 * laptop
1453 * Port-A headphone
1454 * B mic-in
1455 * C docking station
1456 * D internal speaker (with EAPD)
1457 * E/F quad mic array
1458 */
1459
1460
1461/* models */
1462enum {
1463 AD1988_6STACK,
1464 AD1988_6STACK_DIG,
1465 AD1988_3STACK,
1466 AD1988_3STACK_DIG,
1467 AD1988_LAPTOP,
1468 AD1988_LAPTOP_DIG,
Takashi Iwaid32410b12005-11-24 16:06:23 +01001469 AD1988_AUTO,
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001470 AD1988_MODEL_LAST,
1471};
1472
Takashi Iwaid32410b12005-11-24 16:06:23 +01001473/* reivision id to check workarounds */
1474#define AD1988A_REV2 0x100200
1475
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001476
1477/*
1478 * mixers
1479 */
1480
Takashi Iwaid32410b12005-11-24 16:06:23 +01001481static hda_nid_t ad1988_6stack_dac_nids[4] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001482 0x04, 0x06, 0x05, 0x0a
1483};
1484
Takashi Iwaid32410b12005-11-24 16:06:23 +01001485static hda_nid_t ad1988_3stack_dac_nids[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001486 0x04, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01001487};
1488
1489/* for AD1988A revision-2, DAC2-4 are swapped */
1490static hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
1491 0x04, 0x05, 0x0a, 0x06
1492};
1493
1494static hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001495 0x04, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01001496};
1497
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001498static hda_nid_t ad1988_adc_nids[3] = {
1499 0x08, 0x09, 0x0f
1500};
1501
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001502static hda_nid_t ad1988_capsrc_nids[3] = {
1503 0x0c, 0x0d, 0x0e
1504};
1505
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001506#define AD1988_SPDIF_OUT 0x02
1507#define AD1988_SPDIF_IN 0x07
1508
1509static struct hda_input_mux ad1988_6stack_capture_source = {
1510 .num_items = 5,
1511 .items = {
1512 { "Front Mic", 0x0 },
1513 { "Line", 0x1 },
1514 { "Mic", 0x4 },
1515 { "CD", 0x5 },
1516 { "Mix", 0x9 },
1517 },
1518};
1519
1520static struct hda_input_mux ad1988_laptop_capture_source = {
1521 .num_items = 3,
1522 .items = {
1523 { "Mic/Line", 0x0 },
1524 { "CD", 0x5 },
1525 { "Mix", 0x9 },
1526 },
1527};
1528
1529/*
1530 */
1531static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
1532 struct snd_ctl_elem_info *uinfo)
1533{
1534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1535 struct ad198x_spec *spec = codec->spec;
1536 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
1537 spec->num_channel_mode);
1538}
1539
1540static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
1541 struct snd_ctl_elem_value *ucontrol)
1542{
1543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1544 struct ad198x_spec *spec = codec->spec;
1545 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
1546 spec->num_channel_mode, spec->multiout.max_channels);
1547}
1548
1549static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
1550 struct snd_ctl_elem_value *ucontrol)
1551{
1552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1553 struct ad198x_spec *spec = codec->spec;
1554 return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
1555 spec->num_channel_mode, &spec->multiout.max_channels);
1556}
1557
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001558/* 6-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001559static struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001560 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1561 HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1562 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1563 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
1564 HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001565};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001566
Takashi Iwaid32410b12005-11-24 16:06:23 +01001567static struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
1568 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1569 HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
1570 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
1571 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
1572 HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
1573};
1574
1575static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001576 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
1577 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
1578 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
1579 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
1580 HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
1581 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1582 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1583
1584 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1585 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1586 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1587 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1588 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1589 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1590 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1591 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1592
1593 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1594 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1595
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001596 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001597 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1598
1599 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1600 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1601
1602 { } /* end */
1603};
1604
1605/* 3-stack mode */
Takashi Iwaid32410b12005-11-24 16:06:23 +01001606static struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001607 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001608 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001609 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
1610 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001611};
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001612
Takashi Iwaid32410b12005-11-24 16:06:23 +01001613static struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
1614 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001615 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
1616 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
1617 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001618};
1619
1620static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001621 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
Takashi Iwaid32410b12005-11-24 16:06:23 +01001622 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
1623 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
1624 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001625 HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
1626 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1627
1628 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1629 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1630 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1631 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1632 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1633 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1634 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1635 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1636
1637 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1638 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1639
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001640 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001641 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1642
1643 HDA_CODEC_VOLUME("Front Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1644 HDA_CODEC_VOLUME("Mic Boost", 0x3c, 0x0, HDA_OUTPUT),
1645 {
1646 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1647 .name = "Channel Mode",
1648 .info = ad198x_ch_mode_info,
1649 .get = ad198x_ch_mode_get,
1650 .put = ad198x_ch_mode_put,
1651 },
1652
1653 { } /* end */
1654};
1655
1656/* laptop mode */
1657static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
1658 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
1659 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
1660 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
1661
1662 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
1663 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
1664 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
1665 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
1666 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
1667 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
1668
1669 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1670 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1671
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001672 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001673 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1674
1675 HDA_CODEC_VOLUME("Mic Boost", 0x39, 0x0, HDA_OUTPUT),
1676
1677 {
1678 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1679 .name = "External Amplifier",
Takashi Iwai18a815d2006-03-01 19:54:39 +01001680 .info = ad198x_eapd_info,
1681 .get = ad198x_eapd_get,
1682 .put = ad198x_eapd_put,
1683 .private_value = 0x12 | (1 << 8), /* port-D, inversed */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001684 },
1685
1686 { } /* end */
1687};
1688
1689/* capture */
1690static struct snd_kcontrol_new ad1988_capture_mixers[] = {
1691 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
1692 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
1693 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
1694 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
1695 HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
1696 HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
1697 {
1698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1699 /* The multiple "Capture Source" controls confuse alsamixer
1700 * So call somewhat different..
1701 * FIXME: the controls appear in the "playback" view!
1702 */
1703 /* .name = "Capture Source", */
1704 .name = "Input Source",
1705 .count = 3,
1706 .info = ad198x_mux_enum_info,
1707 .get = ad198x_mux_enum_get,
1708 .put = ad198x_mux_enum_put,
1709 },
1710 { } /* end */
1711};
1712
1713static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
1714 struct snd_ctl_elem_info *uinfo)
1715{
1716 static char *texts[] = {
1717 "PCM", "ADC1", "ADC2", "ADC3"
1718 };
1719 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1720 uinfo->count = 1;
1721 uinfo->value.enumerated.items = 4;
1722 if (uinfo->value.enumerated.item >= 4)
1723 uinfo->value.enumerated.item = 3;
1724 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1725 return 0;
1726}
1727
1728static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol)
1730{
1731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1732 unsigned int sel;
1733
1734 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1735 if (sel > 0) {
1736 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0);
1737 if (sel <= 3)
1738 sel++;
1739 else
1740 sel = 0;
1741 }
1742 ucontrol->value.enumerated.item[0] = sel;
1743 return 0;
1744}
1745
1746static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
1748{
1749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1750 unsigned int sel;
1751 int change;
1752
1753 sel = snd_hda_codec_read(codec, 0x02, 0, AC_VERB_GET_CONNECT_SEL, 0);
1754 if (! ucontrol->value.enumerated.item[0]) {
1755 change = sel != 0;
1756 if (change)
1757 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 0);
1758 } else {
1759 change = sel == 0;
1760 if (change)
1761 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL, 1);
1762 sel = snd_hda_codec_read(codec, 0x0b, 0, AC_VERB_GET_CONNECT_SEL, 0) + 1;
1763 change |= sel == ucontrol->value.enumerated.item[0];
1764 if (change)
1765 snd_hda_codec_write(codec, 0x02, 0, AC_VERB_SET_CONNECT_SEL,
1766 ucontrol->value.enumerated.item[0] - 1);
1767 }
1768 return change;
1769}
1770
1771static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
1772 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
1773 {
1774 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1775 .name = "IEC958 Playback Source",
1776 .info = ad1988_spdif_playback_source_info,
1777 .get = ad1988_spdif_playback_source_get,
1778 .put = ad1988_spdif_playback_source_put,
1779 },
1780 { } /* end */
1781};
1782
1783static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
1784 HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
1785 { } /* end */
1786};
1787
1788
1789/*
1790 * initialization verbs
1791 */
1792
1793/*
1794 * for 6-stack (+dig)
1795 */
1796static struct hda_verb ad1988_6stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001797 /* Front, Surround, CLFE, side DAC; unmute as default */
1798 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1799 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1800 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1801 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001802 /* Port-A front headphon path */
1803 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1804 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1805 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1806 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1807 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1808 /* Port-D line-out path */
1809 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1810 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1811 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1812 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1813 /* Port-F surround path */
1814 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1815 {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1816 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1817 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1818 /* Port-G CLFE path */
1819 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1820 {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1821 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1822 {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1823 /* Port-H side path */
1824 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1825 {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1826 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1827 {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1828 /* Mono out path */
1829 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1830 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1831 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1832 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1833 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1834 /* Port-B front mic-in path */
1835 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1836 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1837 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1838 /* Port-C line-in path */
1839 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1840 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1841 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1842 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
1843 /* Port-E mic-in path */
1844 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1845 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1846 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
1847 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1848
1849 { }
1850};
1851
1852static struct hda_verb ad1988_capture_init_verbs[] = {
1853 /* mute analog mix */
1854 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1855 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1856 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1857 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1858 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1859 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1860 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1861 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1862 /* select ADCs - front-mic */
1863 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1864 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1865 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1866 /* ADCs; muted */
1867 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1868 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1869 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1870
1871 { }
1872};
1873
1874static struct hda_verb ad1988_spdif_init_verbs[] = {
1875 /* SPDIF out sel */
1876 {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
1877 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
1878 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1879 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
1880 /* SPDIF out pin */
1881 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
1882 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x17}, /* 0dB */
1883
1884 { }
1885};
1886
1887/*
1888 * verbs for 3stack (+dig)
1889 */
1890static struct hda_verb ad1988_3stack_ch2_init[] = {
1891 /* set port-C to line-in */
1892 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1893 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1894 /* set port-E to mic-in */
1895 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1896 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
1897 { } /* end */
1898};
1899
1900static struct hda_verb ad1988_3stack_ch6_init[] = {
1901 /* set port-C to surround out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001902 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001903 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001904 /* set port-E to CLFE out */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001905 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
Takashi Iwaid32410b12005-11-24 16:06:23 +01001906 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001907 { } /* end */
1908};
1909
1910static struct hda_channel_mode ad1988_3stack_modes[2] = {
1911 { 2, ad1988_3stack_ch2_init },
1912 { 6, ad1988_3stack_ch6_init },
1913};
1914
1915static struct hda_verb ad1988_3stack_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001916 /* Front, Surround, CLFE, side DAC; unmute as default */
1917 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1918 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1919 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1920 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001921 /* Port-A front headphon path */
1922 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
1923 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1924 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1925 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1926 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1927 /* Port-D line-out path */
1928 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1929 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1930 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1931 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1932 /* Mono out path */
1933 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
1934 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1935 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1936 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1937 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
1938 /* Port-B front mic-in path */
1939 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1940 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1941 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01001942 /* Port-C line-in/surround path - 6ch mode as default */
1943 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1944 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001945 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaid32410b12005-11-24 16:06:23 +01001946 {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001947 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
Takashi Iwaid32410b12005-11-24 16:06:23 +01001948 /* Port-E mic-in/CLFE path - 6ch mode as default */
1949 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1950 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001951 {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01001952 {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001953 {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
1954 /* mute analog mix */
1955 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1956 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1957 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
1958 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
1959 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
1960 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
1961 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
1962 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
1963 /* select ADCs - front-mic */
1964 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
1965 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
1966 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
1967 /* ADCs; muted */
1968 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1969 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1970 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1971 { }
1972};
1973
1974/*
1975 * verbs for laptop mode (+dig)
1976 */
1977static struct hda_verb ad1988_laptop_hp_on[] = {
1978 /* unmute port-A and mute port-D */
1979 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1980 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1981 { } /* end */
1982};
1983static struct hda_verb ad1988_laptop_hp_off[] = {
1984 /* mute port-A and unmute port-D */
1985 { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
1986 { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
1987 { } /* end */
1988};
1989
1990#define AD1988_HP_EVENT 0x01
1991
1992static struct hda_verb ad1988_laptop_init_verbs[] = {
Takashi Iwai2e5b9562005-11-21 16:36:15 +01001993 /* Front, Surround, CLFE, side DAC; unmute as default */
1994 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1995 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1996 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1997 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01001998 /* Port-A front headphon path */
1999 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */
2000 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2001 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2002 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2003 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2004 /* unsolicited event for pin-sense */
2005 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
2006 /* Port-D line-out path + EAPD */
2007 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2008 {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2009 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2010 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2011 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
2012 /* Mono out path */
2013 {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
2014 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2015 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2016 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2017 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
2018 /* Port-B mic-in path */
2019 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2020 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2021 {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2022 /* Port-C docking station - try to output */
2023 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2024 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2025 {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2026 {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
2027 /* mute analog mix */
2028 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2029 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2030 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
2031 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2032 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2033 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
2034 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
2035 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
2036 /* select ADCs - mic */
2037 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2038 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2039 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2040 /* ADCs; muted */
2041 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2042 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2043 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2044 { }
2045};
2046
2047static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
2048{
2049 if ((res >> 26) != AD1988_HP_EVENT)
2050 return;
2051 if (snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0) & (1 << 31))
2052 snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
2053 else
2054 snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
2055}
2056
2057
2058/*
Takashi Iwaid32410b12005-11-24 16:06:23 +01002059 * Automatic parse of I/O pins from the BIOS configuration
2060 */
2061
2062#define NUM_CONTROL_ALLOC 32
2063#define NUM_VERB_ALLOC 32
2064
2065enum {
2066 AD_CTL_WIDGET_VOL,
2067 AD_CTL_WIDGET_MUTE,
2068 AD_CTL_BIND_MUTE,
2069};
2070static struct snd_kcontrol_new ad1988_control_templates[] = {
2071 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2072 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2073 HDA_BIND_MUTE(NULL, 0, 0, 0),
2074};
2075
2076/* add dynamic controls */
2077static int add_control(struct ad198x_spec *spec, int type, const char *name,
2078 unsigned long val)
2079{
2080 struct snd_kcontrol_new *knew;
2081
2082 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2083 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2084
2085 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2086 if (! knew)
2087 return -ENOMEM;
2088 if (spec->kctl_alloc) {
2089 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2090 kfree(spec->kctl_alloc);
2091 }
2092 spec->kctl_alloc = knew;
2093 spec->num_kctl_alloc = num;
2094 }
2095
2096 knew = &spec->kctl_alloc[spec->num_kctl_used];
2097 *knew = ad1988_control_templates[type];
2098 knew->name = kstrdup(name, GFP_KERNEL);
2099 if (! knew->name)
2100 return -ENOMEM;
2101 knew->private_value = val;
2102 spec->num_kctl_used++;
2103 return 0;
2104}
2105
2106#define AD1988_PIN_CD_NID 0x18
2107#define AD1988_PIN_BEEP_NID 0x10
2108
2109static hda_nid_t ad1988_mixer_nids[8] = {
2110 /* A B C D E F G H */
2111 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
2112};
2113
2114static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2115{
2116 static hda_nid_t idx_to_dac[8] = {
2117 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002118 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
Takashi Iwaid32410b12005-11-24 16:06:23 +01002119 };
2120 static hda_nid_t idx_to_dac_rev2[8] = {
2121 /* A B C D E F G H */
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002122 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
Takashi Iwaid32410b12005-11-24 16:06:23 +01002123 };
2124 if (codec->revision_id == AD1988A_REV2)
2125 return idx_to_dac_rev2[idx];
2126 else
2127 return idx_to_dac[idx];
2128}
2129
2130static hda_nid_t ad1988_boost_nids[8] = {
2131 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
2132};
2133
2134static int ad1988_pin_idx(hda_nid_t nid)
2135{
2136 static hda_nid_t ad1988_io_pins[8] = {
2137 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
2138 };
2139 int i;
2140 for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
2141 if (ad1988_io_pins[i] == nid)
2142 return i;
2143 return 0; /* should be -1 */
2144}
2145
2146static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
2147{
2148 static int loopback_idx[8] = {
2149 2, 0, 1, 3, 4, 5, 1, 4
2150 };
2151 switch (nid) {
2152 case AD1988_PIN_CD_NID:
2153 return 6;
2154 default:
2155 return loopback_idx[ad1988_pin_idx(nid)];
2156 }
2157}
2158
2159static int ad1988_pin_to_adc_idx(hda_nid_t nid)
2160{
2161 static int adc_idx[8] = {
2162 0, 1, 2, 8, 4, 3, 6, 7
2163 };
2164 switch (nid) {
2165 case AD1988_PIN_CD_NID:
2166 return 5;
2167 default:
2168 return adc_idx[ad1988_pin_idx(nid)];
2169 }
2170}
2171
2172/* fill in the dac_nids table from the parsed pin configuration */
2173static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
2174 const struct auto_pin_cfg *cfg)
2175{
2176 struct ad198x_spec *spec = codec->spec;
2177 int i, idx;
2178
2179 spec->multiout.dac_nids = spec->private_dac_nids;
2180
2181 /* check the pins hardwired to audio widget */
2182 for (i = 0; i < cfg->line_outs; i++) {
2183 idx = ad1988_pin_idx(cfg->line_out_pins[i]);
2184 spec->multiout.dac_nids[i] = ad1988_idx_to_dac(codec, idx);
2185 }
2186 spec->multiout.num_dacs = cfg->line_outs;
2187 return 0;
2188}
2189
2190/* add playback controls from the parsed DAC table */
2191static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
2192 const struct auto_pin_cfg *cfg)
2193{
2194 char name[32];
2195 static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
2196 hda_nid_t nid;
2197 int i, err;
2198
2199 for (i = 0; i < cfg->line_outs; i++) {
2200 hda_nid_t dac = spec->multiout.dac_nids[i];
2201 if (! dac)
2202 continue;
2203 nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
2204 if (i == 2) {
2205 /* Center/LFE */
2206 err = add_control(spec, AD_CTL_WIDGET_VOL,
2207 "Center Playback Volume",
2208 HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
2209 if (err < 0)
2210 return err;
2211 err = add_control(spec, AD_CTL_WIDGET_VOL,
2212 "LFE Playback Volume",
2213 HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
2214 if (err < 0)
2215 return err;
2216 err = add_control(spec, AD_CTL_BIND_MUTE,
2217 "Center Playback Switch",
2218 HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
2219 if (err < 0)
2220 return err;
2221 err = add_control(spec, AD_CTL_BIND_MUTE,
2222 "LFE Playback Switch",
2223 HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
2224 if (err < 0)
2225 return err;
2226 } else {
2227 sprintf(name, "%s Playback Volume", chname[i]);
2228 err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2229 HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
2230 if (err < 0)
2231 return err;
2232 sprintf(name, "%s Playback Switch", chname[i]);
2233 err = add_control(spec, AD_CTL_BIND_MUTE, name,
2234 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
2235 if (err < 0)
2236 return err;
2237 }
2238 }
2239 return 0;
2240}
2241
2242/* add playback controls for speaker and HP outputs */
2243static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2244 const char *pfx)
2245{
2246 struct ad198x_spec *spec = codec->spec;
2247 hda_nid_t nid;
2248 int idx, err;
2249 char name[32];
2250
2251 if (! pin)
2252 return 0;
2253
2254 idx = ad1988_pin_idx(pin);
2255 nid = ad1988_idx_to_dac(codec, idx);
2256 if (! spec->multiout.dac_nids[0]) {
2257 /* use this as the primary output */
2258 spec->multiout.dac_nids[0] = nid;
2259 if (! spec->multiout.num_dacs)
2260 spec->multiout.num_dacs = 1;
2261 } else
2262 /* specify the DAC as the extra output */
2263 spec->multiout.hp_nid = nid;
2264 /* control HP volume/switch on the output mixer amp */
2265 sprintf(name, "%s Playback Volume", pfx);
2266 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2267 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
2268 return err;
2269 nid = ad1988_mixer_nids[idx];
2270 sprintf(name, "%s Playback Switch", pfx);
2271 if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
2272 HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
2273 return err;
2274 return 0;
2275}
2276
2277/* create input playback/capture controls for the given pin */
2278static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
2279 const char *ctlname, int boost)
2280{
2281 char name[32];
2282 int err, idx;
2283
2284 sprintf(name, "%s Playback Volume", ctlname);
2285 idx = ad1988_pin_to_loopback_idx(pin);
2286 if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
2287 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2288 return err;
2289 sprintf(name, "%s Playback Switch", ctlname);
2290 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
2291 HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
2292 return err;
2293 if (boost) {
2294 hda_nid_t bnid;
2295 idx = ad1988_pin_idx(pin);
2296 bnid = ad1988_boost_nids[idx];
2297 if (bnid) {
2298 sprintf(name, "%s Boost", ctlname);
2299 return add_control(spec, AD_CTL_WIDGET_VOL, name,
2300 HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
2301
2302 }
2303 }
2304 return 0;
2305}
2306
2307/* create playback/capture controls for input pins */
2308static int ad1988_auto_create_analog_input_ctls(struct ad198x_spec *spec,
2309 const struct auto_pin_cfg *cfg)
2310{
Takashi Iwaid32410b12005-11-24 16:06:23 +01002311 struct hda_input_mux *imux = &spec->private_imux;
2312 int i, err;
2313
2314 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai4a471b72005-12-07 13:56:29 +01002315 err = new_analog_input(spec, cfg->input_pins[i],
2316 auto_pin_cfg_labels[i],
Takashi Iwaid32410b12005-11-24 16:06:23 +01002317 i <= AUTO_PIN_FRONT_MIC);
2318 if (err < 0)
2319 return err;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002320 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
Takashi Iwaid32410b12005-11-24 16:06:23 +01002321 imux->items[imux->num_items].index = ad1988_pin_to_adc_idx(cfg->input_pins[i]);
2322 imux->num_items++;
2323 }
2324 imux->items[imux->num_items].label = "Mix";
2325 imux->items[imux->num_items].index = 9;
2326 imux->num_items++;
2327
2328 if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
2329 "Analog Mix Playback Volume",
2330 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2331 return err;
2332 if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
2333 "Analog Mix Playback Switch",
2334 HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
2335 return err;
2336
2337 return 0;
2338}
2339
2340static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
2341 hda_nid_t nid, int pin_type,
2342 int dac_idx)
2343{
2344 /* set as output */
2345 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
2346 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
2347 switch (nid) {
2348 case 0x11: /* port-A - DAC 04 */
2349 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2350 break;
2351 case 0x14: /* port-B - DAC 06 */
2352 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
2353 break;
2354 case 0x15: /* port-C - DAC 05 */
2355 snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
2356 break;
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002357 case 0x17: /* port-E - DAC 0a */
Takashi Iwaid32410b12005-11-24 16:06:23 +01002358 snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2359 break;
2360 case 0x13: /* mono - DAC 04 */
2361 snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
2362 break;
2363 }
2364}
2365
2366static void ad1988_auto_init_multi_out(struct hda_codec *codec)
2367{
2368 struct ad198x_spec *spec = codec->spec;
2369 int i;
2370
2371 for (i = 0; i < spec->autocfg.line_outs; i++) {
2372 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2373 ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
2374 }
2375}
2376
2377static void ad1988_auto_init_extra_out(struct hda_codec *codec)
2378{
2379 struct ad198x_spec *spec = codec->spec;
2380 hda_nid_t pin;
2381
2382 pin = spec->autocfg.speaker_pin;
2383 if (pin) /* connect to front */
2384 ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
2385 pin = spec->autocfg.hp_pin;
2386 if (pin) /* connect to front */
2387 ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
2388}
2389
2390static void ad1988_auto_init_analog_input(struct hda_codec *codec)
2391{
2392 struct ad198x_spec *spec = codec->spec;
2393 int i, idx;
2394
2395 for (i = 0; i < AUTO_PIN_LAST; i++) {
2396 hda_nid_t nid = spec->autocfg.input_pins[i];
2397 if (! nid)
2398 continue;
2399 switch (nid) {
2400 case 0x15: /* port-C */
2401 snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2402 break;
2403 case 0x17: /* port-E */
2404 snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
2405 break;
2406 }
2407 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2408 i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
2409 if (nid != AD1988_PIN_CD_NID)
2410 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
2411 AMP_OUT_MUTE);
2412 idx = ad1988_pin_idx(nid);
2413 if (ad1988_boost_nids[idx])
2414 snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
2415 AC_VERB_SET_AMP_GAIN_MUTE,
2416 AMP_OUT_ZERO);
2417 }
2418}
2419
2420/* parse the BIOS configuration and set up the alc_spec */
2421/* return 1 if successful, 0 if the proper config is not found, or a negative error code */
2422static int ad1988_parse_auto_config(struct hda_codec *codec)
2423{
2424 struct ad198x_spec *spec = codec->spec;
2425 int err;
2426
Kailang Yangdf694da2005-12-05 19:42:22 +01002427 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Takashi Iwaid32410b12005-11-24 16:06:23 +01002428 return err;
2429 if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2430 return err;
2431 if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
2432 ! spec->autocfg.hp_pin)
2433 return 0; /* can't find valid BIOS pin config */
2434 if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
2435 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2436 "Speaker")) < 0 ||
2437 (err = ad1988_auto_create_extra_out(codec, spec->autocfg.speaker_pin,
2438 "Headphone")) < 0 ||
2439 (err = ad1988_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
2440 return err;
2441
2442 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2443
2444 if (spec->autocfg.dig_out_pin)
2445 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2446 if (spec->autocfg.dig_in_pin)
2447 spec->dig_in_nid = AD1988_SPDIF_IN;
2448
2449 if (spec->kctl_alloc)
2450 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2451
2452 spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
2453
2454 spec->input_mux = &spec->private_imux;
2455
2456 return 1;
2457}
2458
2459/* init callback for auto-configuration model -- overriding the default init */
2460static int ad1988_auto_init(struct hda_codec *codec)
2461{
2462 ad198x_init(codec);
2463 ad1988_auto_init_multi_out(codec);
2464 ad1988_auto_init_extra_out(codec);
2465 ad1988_auto_init_analog_input(codec);
2466 return 0;
2467}
2468
2469
2470/*
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002471 */
2472
2473static struct hda_board_config ad1988_cfg_tbl[] = {
2474 { .modelname = "6stack", .config = AD1988_6STACK },
2475 { .modelname = "6stack-dig", .config = AD1988_6STACK_DIG },
2476 { .modelname = "3stack", .config = AD1988_3STACK },
2477 { .modelname = "3stack-dig", .config = AD1988_3STACK_DIG },
2478 { .modelname = "laptop", .config = AD1988_LAPTOP },
2479 { .modelname = "laptop-dig", .config = AD1988_LAPTOP_DIG },
Takashi Iwaid32410b12005-11-24 16:06:23 +01002480 { .modelname = "auto", .config = AD1988_AUTO },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002481 {}
2482};
2483
2484static int patch_ad1988(struct hda_codec *codec)
2485{
2486 struct ad198x_spec *spec;
2487 int board_config;
2488
2489 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2490 if (spec == NULL)
2491 return -ENOMEM;
2492
Ingo Molnar62932df2006-01-16 16:34:20 +01002493 mutex_init(&spec->amp_mutex);
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002494 codec->spec = spec;
2495
Takashi Iwaif8c7c7b2005-11-24 16:17:20 +01002496 if (codec->revision_id == AD1988A_REV2)
2497 snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
2498
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002499 board_config = snd_hda_check_board_config(codec, ad1988_cfg_tbl);
2500 if (board_config < 0 || board_config >= AD1988_MODEL_LAST) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002501 printk(KERN_INFO "hda_codec: Unknown model for AD1988, trying auto-probe from BIOS...\n");
2502 board_config = AD1988_AUTO;
2503 }
2504
2505 if (board_config == AD1988_AUTO) {
2506 /* automatic parse from the BIOS config */
2507 int err = ad1988_parse_auto_config(codec);
2508 if (err < 0) {
2509 ad198x_free(codec);
2510 return err;
2511 } else if (! err) {
2512 printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
2513 board_config = AD1988_6STACK;
2514 }
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002515 }
2516
2517 switch (board_config) {
2518 case AD1988_6STACK:
2519 case AD1988_6STACK_DIG:
2520 spec->multiout.max_channels = 8;
2521 spec->multiout.num_dacs = 4;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002522 if (codec->revision_id == AD1988A_REV2)
2523 spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
2524 else
2525 spec->multiout.dac_nids = ad1988_6stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002526 spec->input_mux = &ad1988_6stack_capture_source;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002527 spec->num_mixers = 2;
2528 if (codec->revision_id == AD1988A_REV2)
2529 spec->mixers[0] = ad1988_6stack_mixers1_rev2;
2530 else
2531 spec->mixers[0] = ad1988_6stack_mixers1;
2532 spec->mixers[1] = ad1988_6stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002533 spec->num_init_verbs = 1;
2534 spec->init_verbs[0] = ad1988_6stack_init_verbs;
2535 if (board_config == AD1988_6STACK_DIG) {
2536 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2537 spec->dig_in_nid = AD1988_SPDIF_IN;
2538 }
2539 break;
2540 case AD1988_3STACK:
2541 case AD1988_3STACK_DIG:
2542 spec->multiout.max_channels = 6;
2543 spec->multiout.num_dacs = 3;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002544 if (codec->revision_id == AD1988A_REV2)
2545 spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
2546 else
2547 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002548 spec->input_mux = &ad1988_6stack_capture_source;
2549 spec->channel_mode = ad1988_3stack_modes;
2550 spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
Takashi Iwaid32410b12005-11-24 16:06:23 +01002551 spec->num_mixers = 2;
2552 if (codec->revision_id == AD1988A_REV2)
2553 spec->mixers[0] = ad1988_3stack_mixers1_rev2;
2554 else
2555 spec->mixers[0] = ad1988_3stack_mixers1;
2556 spec->mixers[1] = ad1988_3stack_mixers2;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002557 spec->num_init_verbs = 1;
2558 spec->init_verbs[0] = ad1988_3stack_init_verbs;
2559 if (board_config == AD1988_3STACK_DIG)
2560 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2561 break;
2562 case AD1988_LAPTOP:
2563 case AD1988_LAPTOP_DIG:
2564 spec->multiout.max_channels = 2;
2565 spec->multiout.num_dacs = 1;
Takashi Iwaid32410b12005-11-24 16:06:23 +01002566 spec->multiout.dac_nids = ad1988_3stack_dac_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002567 spec->input_mux = &ad1988_laptop_capture_source;
2568 spec->num_mixers = 1;
2569 spec->mixers[0] = ad1988_laptop_mixers;
2570 spec->num_init_verbs = 1;
2571 spec->init_verbs[0] = ad1988_laptop_init_verbs;
2572 if (board_config == AD1988_LAPTOP_DIG)
2573 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2574 break;
2575 }
2576
Takashi Iwaid32410b12005-11-24 16:06:23 +01002577 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
2578 spec->adc_nids = ad1988_adc_nids;
2579 spec->capsrc_nids = ad1988_capsrc_nids;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002580 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2581 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2582 if (spec->multiout.dig_out_nid) {
2583 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers;
2584 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs;
2585 }
2586 if (spec->dig_in_nid)
2587 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2588
2589 codec->patch_ops = ad198x_patch_ops;
2590 switch (board_config) {
Takashi Iwaid32410b12005-11-24 16:06:23 +01002591 case AD1988_AUTO:
2592 codec->patch_ops.init = ad1988_auto_init;
2593 break;
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002594 case AD1988_LAPTOP:
2595 case AD1988_LAPTOP_DIG:
2596 codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
2597 break;
2598 }
2599
2600 return 0;
2601}
2602
2603
2604/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 * patch entries
2606 */
2607struct hda_codec_preset snd_hda_preset_analog[] = {
Takashi Iwai4a3fdf32005-04-14 13:35:51 +02002608 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
2609 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
Takashi Iwaifd66e0d2005-11-17 15:31:34 +01002611 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 {} /* terminator */
2613};