Blame view

sound/pci/hda/patch_analog.c 159 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
2
3
   * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
   *   AD1986A, AD1988
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
5
   * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   *
   *  This driver is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This driver is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
23
24
  #include <linux/init.h>
  #include <linux/delay.h>
  #include <linux/slab.h>
  #include <linux/pci.h>
da155d5b4   Paul Gortmaker   sound: Add module...
25
  #include <linux/module.h>
62932df8f   Ingo Molnar   [ALSA] semaphore ...
26

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
29
  #include <sound/core.h>
  #include "hda_codec.h"
  #include "hda_local.h"
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
30
  #include "hda_beep.h"
1835a0f9a   Takashi Iwai   ALSA: hda - Cache...
31
  #include "hda_jack.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
33
  struct ad198x_spec {
498f5b175   Takashi Iwai   ALSA: hda - Const...
34
  	const struct snd_kcontrol_new *mixers[6];
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
35
  	int num_mixers;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
36
  	unsigned int beep_amp;	/* beep amp value, set via set_beep_amp() */
282208460   Raymond Yau   ALSA: hda - simpl...
37
  	const struct hda_verb *init_verbs[6];	/* initialization verbs
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
38
39
40
41
42
43
44
45
46
  						 * don't forget NULL termination!
  						 */
  	unsigned int num_init_verbs;
  
  	/* playback */
  	struct hda_multi_out multiout;	/* playback set-up
  					 * max_channels, dacs must be set
  					 * dig_out_nid and hp_nid are optional
  					 */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
47
  	unsigned int cur_eapd;
2125cad29   Takashi Iwai   [ALSA] hda-codec ...
48
  	unsigned int need_dac_fix;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
49

498f5b175   Takashi Iwai   ALSA: hda - Const...
50
51
  	const hda_nid_t *alt_dac_nid;
  	const struct hda_pcm_stream *stream_analog_alt_playback;
34588709a   Raymond Yau   ALSA: HDA - Add I...
52
53
  	int independent_hp;
  	int num_active_streams;
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
54

985be54ba   Takashi Iwai   [ALSA] hda-codec ...
55
56
  	/* capture */
  	unsigned int num_adc_nids;
498f5b175   Takashi Iwai   ALSA: hda - Const...
57
  	const hda_nid_t *adc_nids;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
58
59
60
  	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
  
  	/* capture source */
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
61
  	const struct hda_input_mux *input_mux;
498f5b175   Takashi Iwai   ALSA: hda - Const...
62
  	const hda_nid_t *capsrc_nids;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
63
64
65
  	unsigned int cur_mux[3];
  
  	/* channel model */
d2a6d7dc7   Takashi Iwai   [ALSA] hda-codec ...
66
  	const struct hda_channel_mode *channel_mode;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
67
68
69
  	int num_channel_mode;
  
  	/* PCM information */
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
70
  	struct hda_pcm pcm_rec[3];	/* used in alc_build_pcms() */
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
71

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
72
  	unsigned int spdif_route;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
73
74
75
  
  	/* dynamic controls, init_verbs and input_mux */
  	struct auto_pin_cfg autocfg;
603c40199   Takashi Iwai   ALSA: hda - Use g...
76
  	struct snd_array kctls;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
77
  	struct hda_input_mux private_imux;
41923e441   Takashi Iwai   [ALSA] hda-codec ...
78
  	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
79

0bf0e5a6f   Jaroslav Kysela   ALSA: hda-intel -...
80
81
82
83
  	unsigned int jack_present: 1;
  	unsigned int inv_jack_detect: 1;/* inverted jack-detection */
  	unsigned int inv_eapd: 1;	/* inverted EAPD implementation */
  	unsigned int analog_beep: 1;	/* analog beep input present */
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
84

cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
85
86
87
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	struct hda_loopback_check loopback;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
88
89
  	/* for virtual master */
  	hda_nid_t vmaster_nid;
ea7349632   Takashi Iwai   ALSA: hda - consi...
90
91
  	const char * const *slave_vols;
  	const char * const *slave_sws;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
  };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
93
94
95
  /*
   * input MUX handling (common part)
   */
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
96
  static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
97
98
99
100
101
102
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
  
  	return snd_hda_input_mux_info(spec->input_mux, uinfo);
  }
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
103
  static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
104
105
106
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
107
  	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
108

985be54ba   Takashi Iwai   [ALSA] hda-codec ...
109
  	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
110
111
  	return 0;
  }
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
112
  static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
113
114
115
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
116
  	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
117
118
  
  	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
119
120
  				     spec->capsrc_nids[adc_idx],
  				     &spec->cur_mux[adc_idx]);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
121
122
123
124
125
126
127
128
  }
  
  /*
   * initialization (common callbacks)
   */
  static int ad198x_init(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
129
130
131
132
  	int i;
  
  	for (i = 0; i < spec->num_init_verbs; i++)
  		snd_hda_sequence_write(codec, spec->init_verbs[i]);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
133
134
  	return 0;
  }
ea7349632   Takashi Iwai   ALSA: hda - consi...
135
  static const char * const ad_slave_vols[] = {
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
136
137
138
139
140
141
142
  	"Front Playback Volume",
  	"Surround Playback Volume",
  	"Center Playback Volume",
  	"LFE Playback Volume",
  	"Side Playback Volume",
  	"Headphone Playback Volume",
  	"Mono Playback Volume",
628ed1333   Takashi Iwai   [ALSA] hda-codec ...
143
  	"Speaker Playback Volume",
4806ef0cf   Takashi Iwai   [ALSA] hda-codec ...
144
  	"IEC958 Playback Volume",
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
145
146
  	NULL
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
147
  static const char * const ad_slave_sws[] = {
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
148
149
150
151
152
153
154
  	"Front Playback Switch",
  	"Surround Playback Switch",
  	"Center Playback Switch",
  	"LFE Playback Switch",
  	"Side Playback Switch",
  	"Headphone Playback Switch",
  	"Mono Playback Switch",
628ed1333   Takashi Iwai   [ALSA] hda-codec ...
155
  	"Speaker Playback Switch",
4806ef0cf   Takashi Iwai   [ALSA] hda-codec ...
156
  	"IEC958 Playback Switch",
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
157
158
  	NULL
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
159
  static const char * const ad1988_6stack_fp_slave_vols[] = {
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
160
161
162
163
164
165
166
167
  	"Front Playback Volume",
  	"Surround Playback Volume",
  	"Center Playback Volume",
  	"LFE Playback Volume",
  	"Side Playback Volume",
  	"IEC958 Playback Volume",
  	NULL
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
168
  static const char * const ad1988_6stack_fp_slave_sws[] = {
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
169
170
171
172
173
174
175
176
  	"Front Playback Switch",
  	"Surround Playback Switch",
  	"Center Playback Switch",
  	"LFE Playback Switch",
  	"Side Playback Switch",
  	"IEC958 Playback Switch",
  	NULL
  };
603c40199   Takashi Iwai   ALSA: hda - Use g...
177
  static void ad198x_free_kctls(struct hda_codec *codec);
67d634c07   Takashi Iwai   ALSA: hda - Fix b...
178
  #ifdef CONFIG_SND_HDA_INPUT_BEEP
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
179
  /* additional beep mixers; the actual parameters are overwritten at build */
498f5b175   Takashi Iwai   ALSA: hda - Const...
180
  static const struct snd_kcontrol_new ad_beep_mixer[] = {
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
181
  	HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
123c07aed   Jaroslav Kysela   ALSA: hda_intel: ...
182
  	HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
183
184
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
185
  static const struct snd_kcontrol_new ad_beep2_mixer[] = {
0bf0e5a6f   Jaroslav Kysela   ALSA: hda-intel -...
186
187
188
189
  	HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
  	{ } /* end */
  };
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
190
191
  #define set_beep_amp(spec, nid, idx, dir) \
  	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
67d634c07   Takashi Iwai   ALSA: hda - Fix b...
192
193
194
  #else
  #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  #endif
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
195

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
196
197
198
  static int ad198x_build_controls(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
199
  	struct snd_kcontrol *kctl;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
200
  	unsigned int i;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
201
  	int err;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
202
203
204
205
206
207
  	for (i = 0; i < spec->num_mixers; i++) {
  		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  		if (err < 0)
  			return err;
  	}
  	if (spec->multiout.dig_out_nid) {
74b654c95   Stephen Warren   ALSA: hda: Virtua...
208
209
210
  		err = snd_hda_create_spdif_out_ctls(codec,
  						    spec->multiout.dig_out_nid,
  						    spec->multiout.dig_out_nid);
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
211
212
  		if (err < 0)
  			return err;
9a08160bd   Takashi Iwai   [ALSA] hda-codec ...
213
214
215
216
217
  		err = snd_hda_create_spdif_share_sw(codec,
  						    &spec->multiout);
  		if (err < 0)
  			return err;
  		spec->multiout.share_spdif = 1;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
218
219
220
221
222
223
  	} 
  	if (spec->dig_in_nid) {
  		err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  		if (err < 0)
  			return err;
  	}
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
224

c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
225
  	/* create beep controls if needed */
67d634c07   Takashi Iwai   ALSA: hda - Fix b...
226
  #ifdef CONFIG_SND_HDA_INPUT_BEEP
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
227
  	if (spec->beep_amp) {
498f5b175   Takashi Iwai   ALSA: hda - Const...
228
  		const struct snd_kcontrol_new *knew;
0bf0e5a6f   Jaroslav Kysela   ALSA: hda-intel -...
229
230
  		knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
  		for ( ; knew->name; knew++) {
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
231
232
233
234
235
  			struct snd_kcontrol *kctl;
  			kctl = snd_ctl_new1(knew, codec);
  			if (!kctl)
  				return -ENOMEM;
  			kctl->private_value = spec->beep_amp;
5e26dfd06   Jaroslav Kysela   ALSA: hda - simpl...
236
  			err = snd_hda_ctl_add(codec, 0, kctl);
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
237
238
239
240
  			if (err < 0)
  				return err;
  		}
  	}
67d634c07   Takashi Iwai   ALSA: hda - Fix b...
241
  #endif
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
242

2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
243
244
  	/* if we have no master control, let's create it */
  	if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1c82ed1bc   Takashi Iwai   [ALSA] Keep priva...
245
  		unsigned int vmaster_tlv[4];
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
246
  		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1c82ed1bc   Takashi Iwai   [ALSA] Keep priva...
247
  					HDA_OUTPUT, vmaster_tlv);
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
248
  		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1c82ed1bc   Takashi Iwai   [ALSA] Keep priva...
249
  					  vmaster_tlv,
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
250
251
252
253
254
255
256
257
258
259
260
261
262
  					  (spec->slave_vols ?
  					   spec->slave_vols : ad_slave_vols));
  		if (err < 0)
  			return err;
  	}
  	if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  					  NULL,
  					  (spec->slave_sws ?
  					   spec->slave_sws : ad_slave_sws));
  		if (err < 0)
  			return err;
  	}
603c40199   Takashi Iwai   ALSA: hda - Use g...
263
  	ad198x_free_kctls(codec); /* no longer needed */
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
264
265
266
267
268
269
  
  	/* assign Capture Source enums to NID */
  	kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  	if (!kctl)
  		kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  	for (i = 0; kctl && i < kctl->count; i++) {
21949f00a   Takashi Iwai   ALSA: hda - Fix N...
270
  		err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
271
272
273
274
275
276
277
278
279
280
281
282
283
  		if (err < 0)
  			return err;
  	}
  
  	/* assign IEC958 enums to NID */
  	kctl = snd_hda_find_mixer_ctl(codec,
  			SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
  	if (kctl) {
  		err = snd_hda_add_nid(codec, kctl, 0,
  				      spec->multiout.dig_out_nid);
  		if (err < 0)
  			return err;
  	}
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
284
285
  	return 0;
  }
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
286
287
288
289
290
291
292
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  }
  #endif
34588709a   Raymond Yau   ALSA: HDA - Add I...
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
  static void activate_ctl(struct hda_codec *codec, const char *name, int active)
  {
  	struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
  	if (ctl) {
  		ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  		ctl->vd[0].access |= active ? 0 :
  			SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  		ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
  		ctl->vd[0].access |= active ?
  			SNDRV_CTL_ELEM_ACCESS_WRITE : 0;
  		snd_ctl_notify(codec->bus->card,
  			       SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
  	}
  }
  
  static void set_stream_active(struct hda_codec *codec, bool active)
  {
  	struct ad198x_spec *spec = codec->spec;
  	if (active)
  		spec->num_active_streams++;
  	else
  		spec->num_active_streams--;
  	activate_ctl(codec, "Independent HP", spec->num_active_streams == 0);
  }
  
  static int ad1988_independent_hp_info(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_info *uinfo)
  {
  	static const char * const texts[] = { "OFF", "ON", NULL};
  	int index;
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  	uinfo->count = 1;
  	uinfo->value.enumerated.items = 2;
  	index = uinfo->value.enumerated.item;
  	if (index >= 2)
  		index = 1;
  	strcpy(uinfo->value.enumerated.name, texts[index]);
  	return 0;
  }
  
  static int ad1988_independent_hp_get(struct snd_kcontrol *kcontrol,
  				  struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
  	ucontrol->value.enumerated.item[0] = spec->independent_hp;
  	return 0;
  }
  
  static int ad1988_independent_hp_put(struct snd_kcontrol *kcontrol,
  				  struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
  	unsigned int select = ucontrol->value.enumerated.item[0];
  	if (spec->independent_hp != select) {
  		spec->independent_hp = select;
  		if (spec->independent_hp)
  			spec->multiout.hp_nid = 0;
  		else
  			spec->multiout.hp_nid = spec->alt_dac_nid[0];
  		return 1;
  	}
  	return 0;
  }
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
358
359
360
361
362
  /*
   * Analog playback callbacks
   */
  static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
  				    struct hda_codec *codec,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
363
  				    struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
364
365
  {
  	struct ad198x_spec *spec = codec->spec;
34588709a   Raymond Yau   ALSA: HDA - Add I...
366
367
368
  	int err;
  	set_stream_active(codec, true);
  	err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
9a08160bd   Takashi Iwai   [ALSA] hda-codec ...
369
  					     hinfo);
34588709a   Raymond Yau   ALSA: HDA - Add I...
370
371
372
373
374
  	if (err < 0) {
  		set_stream_active(codec, false);
  		return err;
  	}
  	return 0;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
375
376
377
378
379
380
  }
  
  static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  				       struct hda_codec *codec,
  				       unsigned int stream_tag,
  				       unsigned int format,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
381
  				       struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
382
383
384
385
386
387
388
389
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  						format, substream);
  }
  
  static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  				       struct hda_codec *codec,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
390
  				       struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
391
392
393
394
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  }
34588709a   Raymond Yau   ALSA: HDA - Add I...
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
  static int ad198x_playback_pcm_close(struct hda_pcm_stream *hinfo,
  				 struct hda_codec *codec,
  				 struct snd_pcm_substream *substream)
  {
  	set_stream_active(codec, false);
  	return 0;
  }
  
  static int ad1988_alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
  				 struct hda_codec *codec,
  				 struct snd_pcm_substream *substream)
  {
  	struct ad198x_spec *spec = codec->spec;
  	if (!spec->independent_hp)
  		return -EBUSY;
  	set_stream_active(codec, true);
  	return 0;
  }
  
  static int ad1988_alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
  				 struct hda_codec *codec,
  				 struct snd_pcm_substream *substream)
  {
  	set_stream_active(codec, false);
  	return 0;
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
421
  static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
422
423
424
  	.substreams = 1,
  	.channels_min = 2,
  	.channels_max = 2,
34588709a   Raymond Yau   ALSA: HDA - Add I...
425
426
427
428
  	.ops = {
  		.open  = ad1988_alt_playback_pcm_open,
  		.close = ad1988_alt_playback_pcm_close
  	},
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
429
  };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
430
431
432
433
434
  /*
   * Digital out
   */
  static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  					struct hda_codec *codec,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
435
  					struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
436
437
438
439
440
441
442
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  }
  
  static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  					 struct hda_codec *codec,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
443
  					 struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
444
445
446
447
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  }
6b97eb45f   Takashi Iwai   [ALSA] hda-codec ...
448
449
450
451
452
453
454
455
456
457
  static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  					   struct hda_codec *codec,
  					   unsigned int stream_tag,
  					   unsigned int format,
  					   struct snd_pcm_substream *substream)
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  					     format, substream);
  }
9411e21cd   Takashi Iwai   ALSA: hda - Add s...
458
459
460
461
462
463
464
  static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  					   struct hda_codec *codec,
  					   struct snd_pcm_substream *substream)
  {
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  }
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
465
466
467
468
469
470
471
  /*
   * Analog capture
   */
  static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  				      struct hda_codec *codec,
  				      unsigned int stream_tag,
  				      unsigned int format,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
472
  				      struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
473
474
  {
  	struct ad198x_spec *spec = codec->spec;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
475
476
  	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  				   stream_tag, 0, format);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
477
478
479
480
481
  	return 0;
  }
  
  static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  				      struct hda_codec *codec,
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
482
  				      struct snd_pcm_substream *substream)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
483
484
  {
  	struct ad198x_spec *spec = codec->spec;
888afa154   Takashi Iwai   [ALSA] hda-codec ...
485
  	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
486
487
  	return 0;
  }
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
488
489
  /*
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
490
  static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
491
492
  	.substreams = 1,
  	.channels_min = 2,
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
493
  	.channels_max = 6, /* changed later */
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
494
495
496
497
  	.nid = 0, /* fill later */
  	.ops = {
  		.open = ad198x_playback_pcm_open,
  		.prepare = ad198x_playback_pcm_prepare,
34588709a   Raymond Yau   ALSA: HDA - Add I...
498
499
  		.cleanup = ad198x_playback_pcm_cleanup,
  		.close = ad198x_playback_pcm_close
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
500
501
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
502
  static const struct hda_pcm_stream ad198x_pcm_analog_capture = {
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
503
  	.substreams = 1,
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
504
505
506
507
508
509
510
511
  	.channels_min = 2,
  	.channels_max = 2,
  	.nid = 0, /* fill later */
  	.ops = {
  		.prepare = ad198x_capture_pcm_prepare,
  		.cleanup = ad198x_capture_pcm_cleanup
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
512
  static const struct hda_pcm_stream ad198x_pcm_digital_playback = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
513
514
515
516
517
518
  	.substreams = 1,
  	.channels_min = 2,
  	.channels_max = 2,
  	.nid = 0, /* fill later */
  	.ops = {
  		.open = ad198x_dig_playback_pcm_open,
6b97eb45f   Takashi Iwai   [ALSA] hda-codec ...
519
  		.close = ad198x_dig_playback_pcm_close,
9411e21cd   Takashi Iwai   ALSA: hda - Add s...
520
521
  		.prepare = ad198x_dig_playback_pcm_prepare,
  		.cleanup = ad198x_dig_playback_pcm_cleanup
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
522
523
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
524
  static const struct hda_pcm_stream ad198x_pcm_digital_capture = {
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
525
526
527
528
529
  	.substreams = 1,
  	.channels_min = 2,
  	.channels_max = 2,
  	/* NID is set in alc_build_pcms */
  };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
530
531
532
533
534
535
536
537
538
539
540
541
542
  static int ad198x_build_pcms(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  	struct hda_pcm *info = spec->pcm_rec;
  
  	codec->num_pcms = 1;
  	codec->pcm_info = info;
  
  	info->name = "AD198x Analog";
  	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
  	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
  	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  	info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
543
544
  	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
545
546
547
548
549
  
  	if (spec->multiout.dig_out_nid) {
  		info++;
  		codec->num_pcms++;
  		info->name = "AD198x Digital";
7ba72ba1f   Takashi Iwai   [ALSA] hda-intel ...
550
  		info->pcm_type = HDA_PCM_TYPE_SPDIF;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
551
552
  		info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
  		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
553
554
555
556
  		if (spec->dig_in_nid) {
  			info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
  			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  		}
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
557
  	}
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
558
559
560
561
562
563
564
565
566
567
  	if (spec->alt_dac_nid && spec->stream_analog_alt_playback) {
  		codec->num_pcms++;
  		info = spec->pcm_rec + 2;
  		info->name = "AD198x Headphone";
  		info->pcm_type = HDA_PCM_TYPE_AUDIO;
  		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  			*spec->stream_analog_alt_playback;
  		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  			spec->alt_dac_nid[0];
  	}
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
568
569
  	return 0;
  }
603c40199   Takashi Iwai   ALSA: hda - Use g...
570
  static void ad198x_free_kctls(struct hda_codec *codec)
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
571
  {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
572
  	struct ad198x_spec *spec = codec->spec;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
573

603c40199   Takashi Iwai   ALSA: hda - Use g...
574
575
576
577
578
  	if (spec->kctls.list) {
  		struct snd_kcontrol_new *kctl = spec->kctls.list;
  		int i;
  		for (i = 0; i < spec->kctls.used; i++)
  			kfree(kctl[i].name);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
579
  	}
603c40199   Takashi Iwai   ALSA: hda - Use g...
580
581
  	snd_array_free(&spec->kctls);
  }
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
582
583
584
585
  static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
  				hda_nid_t hp)
  {
  	struct ad198x_spec *spec = codec->spec;
a01ef051d   Raymond Yau   ALSA: hda - Check...
586
587
  	if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
  		snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
588
  			    !spec->inv_eapd ? 0x00 : 0x02);
a01ef051d   Raymond Yau   ALSA: hda - Check...
589
590
  	if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
  		snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
  			    !spec->inv_eapd ? 0x00 : 0x02);
  }
  
  static void ad198x_power_eapd(struct hda_codec *codec)
  {
  	/* We currently only handle front, HP */
  	switch (codec->vendor_id) {
  	case 0x11d41882:
  	case 0x11d4882a:
  	case 0x11d41884:
  	case 0x11d41984:
  	case 0x11d41883:
  	case 0x11d4184a:
  	case 0x11d4194a:
  	case 0x11d4194b:
4dffbe03d   Takashi Iwai   ALSA: hda - Fix H...
606
607
608
609
  	case 0x11d41988:
  	case 0x11d4198b:
  	case 0x11d4989a:
  	case 0x11d4989b:
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
610
611
612
613
614
615
616
617
618
  		ad198x_power_eapd_write(codec, 0x12, 0x11);
  		break;
  	case 0x11d41981:
  	case 0x11d41983:
  		ad198x_power_eapd_write(codec, 0x05, 0x06);
  		break;
  	case 0x11d41986:
  		ad198x_power_eapd_write(codec, 0x1b, 0x1a);
  		break;
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
619
620
  	}
  }
0da269225   Takashi Iwai   ALSA: hda - Move ...
621
622
623
624
625
  static void ad198x_shutup(struct hda_codec *codec)
  {
  	snd_hda_shutup_pins(codec);
  	ad198x_power_eapd(codec);
  }
603c40199   Takashi Iwai   ALSA: hda - Use g...
626
627
628
629
630
631
  static void ad198x_free(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  
  	if (!spec)
  		return;
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
632
  	ad198x_shutup(codec);
603c40199   Takashi Iwai   ALSA: hda - Use g...
633
  	ad198x_free_kctls(codec);
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
634
635
  	kfree(spec);
  	snd_hda_detach_beep_device(codec);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
636
  }
2a43952a9   Takashi Iwai   ALSA: hda - Make ...
637
  #ifdef CONFIG_PM
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
638
639
640
  static int ad198x_suspend(struct hda_codec *codec, pm_message_t state)
  {
  	ad198x_shutup(codec);
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
641
642
  	return 0;
  }
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
643
  #endif
498f5b175   Takashi Iwai   ALSA: hda - Const...
644
  static const struct hda_codec_ops ad198x_patch_ops = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
645
646
647
648
  	.build_controls = ad198x_build_controls,
  	.build_pcms = ad198x_build_pcms,
  	.init = ad198x_init,
  	.free = ad198x_free,
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
649
650
651
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	.check_power_status = ad198x_check_power_status,
  #endif
2a43952a9   Takashi Iwai   ALSA: hda - Make ...
652
  #ifdef CONFIG_PM
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
653
  	.suspend = ad198x_suspend,
ea52bf260   Daniel T Chen   ALSA: hda: Add po...
654
655
  #endif
  	.reboot_notify = ad198x_shutup,
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
656
657
658
659
  };
  
  
  /*
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
660
   * EAPD control
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
661
   * the private value = nid
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
662
   */
a5ce88909   Takashi Iwai   [ALSA] Clean up w...
663
  #define ad198x_eapd_info	snd_ctl_boolean_mono_info
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
664
665
666
667
668
669
  
  static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
  			   struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
670
  	if (spec->inv_eapd)
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
671
672
673
674
675
676
677
678
679
680
681
  		ucontrol->value.integer.value[0] = ! spec->cur_eapd;
  	else
  		ucontrol->value.integer.value[0] = spec->cur_eapd;
  	return 0;
  }
  
  static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
  			   struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
682
683
  	hda_nid_t nid = kcontrol->private_value & 0xff;
  	unsigned int eapd;
68ea7b2f2   Takashi Iwai   [ALSA] hda-codec ...
684
  	eapd = !!ucontrol->value.integer.value[0];
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
685
  	if (spec->inv_eapd)
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
686
  		eapd = !eapd;
82beb8fd3   Takashi Iwai   [ALSA] hda-codec ...
687
  	if (eapd == spec->cur_eapd)
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
688
689
  		return 0;
  	spec->cur_eapd = eapd;
82beb8fd3   Takashi Iwai   [ALSA] hda-codec ...
690
691
692
  	snd_hda_codec_write_cache(codec, nid,
  				  0, AC_VERB_SET_EAPD_BTLENABLE,
  				  eapd ? 0x02 : 0x00);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
693
694
  	return 1;
  }
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
695
696
697
698
699
700
  static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_info *uinfo);
  static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  			      struct snd_ctl_elem_value *ucontrol);
  static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  			      struct snd_ctl_elem_value *ucontrol);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
701
  /*
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
702
703
   * AD1986A specific
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
706
707
708
  #define AD1986A_SPDIF_OUT	0x02
  #define AD1986A_FRONT_DAC	0x03
  #define AD1986A_SURR_DAC	0x04
  #define AD1986A_CLFE_DAC	0x05
  #define AD1986A_ADC		0x06
498f5b175   Takashi Iwai   ALSA: hda - Const...
709
  static const hda_nid_t ad1986a_dac_nids[3] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
710
711
  	AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
712
713
  static const hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
  static const hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
714

498f5b175   Takashi Iwai   ALSA: hda - Const...
715
  static const struct hda_input_mux ad1986a_capture_source = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
716
717
718
719
720
721
722
723
724
725
726
  	.num_items = 7,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "CD", 0x1 },
  		{ "Aux", 0x3 },
  		{ "Line", 0x4 },
  		{ "Mix", 0x5 },
  		{ "Mono", 0x6 },
  		{ "Phone", 0x7 },
  	},
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
727

498f5b175   Takashi Iwai   ALSA: hda - Const...
728
  static const struct hda_bind_ctls ad1986a_bind_pcm_vol = {
532d53817   Takashi Iwai   [ALSA] hda-codec ...
729
730
731
732
733
734
735
736
  	.ops = &snd_hda_bind_vol,
  	.values = {
  		HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  		0
  	},
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737

498f5b175   Takashi Iwai   ALSA: hda - Const...
738
  static const struct hda_bind_ctls ad1986a_bind_pcm_sw = {
532d53817   Takashi Iwai   [ALSA] hda-codec ...
739
740
741
742
743
744
745
746
  	.ops = &snd_hda_bind_sw,
  	.values = {
  		HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  		0
  	},
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
747
748
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
749
750
   * mixers
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
751
  static const struct snd_kcontrol_new ad1986a_mixers[] = {
532d53817   Takashi Iwai   [ALSA] hda-codec ...
752
753
754
755
756
  	/*
  	 * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
  	 */
  	HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
  	HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
775
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
776
777
778
779
780
781
782
  	HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
783
784
785
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
786
787
788
789
  	},
  	HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
  	{ } /* end */
  };
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
790
  /* additional mixers for 3stack mode */
498f5b175   Takashi Iwai   ALSA: hda - Const...
791
  static const struct snd_kcontrol_new ad1986a_3st_mixers[] = {
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
792
793
794
795
796
797
798
799
800
801
802
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Channel Mode",
  		.info = ad198x_ch_mode_info,
  		.get = ad198x_ch_mode_get,
  		.put = ad198x_ch_mode_put,
  	},
  	{ } /* end */
  };
  
  /* laptop model - 2ch only */
498f5b175   Takashi Iwai   ALSA: hda - Const...
803
  static const hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
804

20a45e864   Takashi Iwai   [ALSA] hda-codec ...
805
  /* master controls both pins 0x1a and 0x1b */
498f5b175   Takashi Iwai   ALSA: hda - Const...
806
  static const struct hda_bind_ctls ad1986a_laptop_master_vol = {
20a45e864   Takashi Iwai   [ALSA] hda-codec ...
807
808
809
810
811
812
813
  	.ops = &snd_hda_bind_vol,
  	.values = {
  		HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  		0,
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
814
  static const struct hda_bind_ctls ad1986a_laptop_master_sw = {
20a45e864   Takashi Iwai   [ALSA] hda-codec ...
815
816
817
818
819
820
821
  	.ops = &snd_hda_bind_sw,
  	.values = {
  		HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  		0,
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
822
  static const struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
823
824
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
20a45e864   Takashi Iwai   [ALSA] hda-codec ...
825
826
  	HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  	HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
827
828
829
830
831
832
833
834
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
835
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
836
  	/* 
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
837
838
839
840
841
842
843
844
845
846
847
848
849
  	   HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  	   HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
  	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	{ } /* end */
  };
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
850
  /* laptop-eapd model - 2ch only */
498f5b175   Takashi Iwai   ALSA: hda - Const...
851
  static const struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
852
853
854
855
856
857
858
  	.num_items = 3,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Internal Mic", 0x4 },
  		{ "Mix", 0x5 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
859
  static const struct hda_input_mux ad1986a_automic_capture_source = {
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
860
861
862
863
864
865
  	.num_items = 2,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Mix", 0x5 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
866
  static const struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
532d53817   Takashi Iwai   [ALSA] hda-codec ...
867
868
  	HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  	HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
1725b82a6   Takashi Iwai   ALSA: hda - make ...
869
870
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
871
  static const struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
1725b82a6   Takashi Iwai   ALSA: hda - make ...
872
873
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
874
875
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
876
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
877
878
879
880
881
882
883
884
885
886
887
888
  	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "External Amplifier",
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
889
  		.subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
890
891
892
  		.info = ad198x_eapd_info,
  		.get = ad198x_eapd_get,
  		.put = ad198x_eapd_put,
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
893
  		.private_value = 0x1b, /* port-D */
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
894
895
896
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
897
  static const struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
16d11a829   Takashi Iwai   ALSA: hda - Simpl...
898
899
900
901
  	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
  	{ } /* end */
  };
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
902
903
904
905
  /* re-connect the mic boost input according to the jack sensing */
  static void ad1986a_automic(struct hda_codec *codec)
  {
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
906
  	present = snd_hda_jack_detect(codec, 0x1f);
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
907
908
  	/* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
  	snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
d56757abc   Takashi Iwai   ALSA: hda - Repla...
909
  			    present ? 0 : 2);
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
  }
  
  #define AD1986A_MIC_EVENT		0x36
  
  static void ad1986a_automic_unsol_event(struct hda_codec *codec,
  					    unsigned int res)
  {
  	if ((res >> 26) != AD1986A_MIC_EVENT)
  		return;
  	ad1986a_automic(codec);
  }
  
  static int ad1986a_automic_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1986a_automic(codec);
  	return 0;
  }
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
  /* laptop-automute - 2ch only */
  
  static void ad1986a_update_hp(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  	unsigned int mute;
  
  	if (spec->jack_present)
  		mute = HDA_AMP_MUTE; /* mute internal speaker */
  	else
  		/* unmute internal speaker if necessary */
  		mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
  	snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE, mute);
  }
  
  static void ad1986a_hp_automute(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
947

d56757abc   Takashi Iwai   ALSA: hda - Repla...
948
  	spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
03c405ad3   Takashi Iwai   ALSA: hda - Gener...
949
950
  	if (spec->inv_jack_detect)
  		spec->jack_present = !spec->jack_present;
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
  	ad1986a_update_hp(codec);
  }
  
  #define AD1986A_HP_EVENT		0x37
  
  static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  {
  	if ((res >> 26) != AD1986A_HP_EVENT)
  		return;
  	ad1986a_hp_automute(codec);
  }
  
  static int ad1986a_hp_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1986a_hp_automute(codec);
  	return 0;
  }
  
  /* bind hp and internal speaker mute (with plug check) */
  static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  				    struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	long *valp = ucontrol->value.integer.value;
  	int change;
  
  	change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
  					  HDA_AMP_MUTE,
  					  valp[0] ? 0 : HDA_AMP_MUTE);
  	change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
  					   HDA_AMP_MUTE,
  					   valp[1] ? 0 : HDA_AMP_MUTE);
  	if (change)
  		ad1986a_update_hp(codec);
  	return change;
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
988
  static const struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
989
990
991
992
  	HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Master Playback Switch",
5e26dfd06   Jaroslav Kysela   ALSA: hda - simpl...
993
  		.subdevice = HDA_SUBDEV_AMP_FLAG,
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
994
995
996
997
998
  		.info = snd_hda_mixer_amp_switch_info,
  		.get = snd_hda_mixer_amp_switch_get,
  		.put = ad1986a_hp_master_sw_put,
  		.private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  	},
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
999
1000
  	{ } /* end */
  };
16d11a829   Takashi Iwai   ALSA: hda - Simpl...
1001

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1002
1003
1004
  /*
   * initialization verbs
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1005
  static const struct hda_verb ad1986a_init_verbs[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
  	/* Front, Surround, CLFE DAC; mute as default */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* Downmix - off */
  	{0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* HP, Line-Out, Surround, CLFE selectors */
  	{0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Mono selector */
  	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Mic selector: Mic 1/2 pin */
  	{0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Line-in selector: Line-in */
  	{0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Mic 1/2 swap */
  	{0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Record selector: mic */
  	{0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Mic, Phone, CD, Aux, Line-In amp; mute as default */
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* PC beep */
  	{0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
  	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
  	/* HP Pin */
  	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  	/* Front, Surround, CLFE Pins */
  	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	/* Mono Pin */
  	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	/* Mic Pin */
  	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  	/* Line, Aux, CD, Beep-In Pin */
  	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1057
1058
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1059
  static const struct hda_verb ad1986a_ch2_init[] = {
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1060
  	/* Surround out -> Line In */
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1061
1062
1063
  	{ 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
   	/* Line-in selectors */
  	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1064
  	/* CLFE -> Mic in */
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1065
1066
1067
  	{ 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  	/* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
  	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1068
1069
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1070
  static const struct hda_verb ad1986a_ch4_init[] = {
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1071
  	/* Surround out -> Surround */
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1072
1073
  	{ 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1074
  	/* CLFE -> Mic in */
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1075
1076
  	{ 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1077
1078
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1079
  static const struct hda_verb ad1986a_ch6_init[] = {
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1080
  	/* Surround out -> Surround out */
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1081
1082
  	{ 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1083
  	/* CLFE -> CLFE */
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1084
1085
  	{ 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1086
1087
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1088
  static const struct hda_channel_mode ad1986a_modes[3] = {
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1089
1090
1091
1092
  	{ 2, ad1986a_ch2_init },
  	{ 4, ad1986a_ch4_init },
  	{ 6, ad1986a_ch6_init },
  };
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
1093
  /* eapd initialization */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1094
  static const struct hda_verb ad1986a_eapd_init_verbs[] = {
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1095
  	{0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
1096
1097
  	{}
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1098
  static const struct hda_verb ad1986a_automic_verbs[] = {
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
1099
1100
1101
1102
1103
1104
1105
  	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	/*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
  	{0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
  	{}
  };
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1106
  /* Ultra initialization */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1107
  static const struct hda_verb ad1986a_ultra_init[] = {
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1108
1109
1110
1111
1112
1113
1114
1115
  	/* eapd initialization */
  	{ 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  	/* CLFE -> Mic in */
  	{ 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
  	{ 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  	{ 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
  	{ } /* end */
  };
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1116
  /* pin sensing on HP jack */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1117
  static const struct hda_verb ad1986a_hp_init_verbs[] = {
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1118
1119
1120
  	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
  	{}
  };
c912e7a58   Takashi Iwai   ALSA: hda - Fix s...
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
  static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
  					    unsigned int res)
  {
  	switch (res >> 26) {
  	case AD1986A_HP_EVENT:
  		ad1986a_hp_automute(codec);
  		break;
  	case AD1986A_MIC_EVENT:
  		ad1986a_automic(codec);
  		break;
  	}
  }
  
  static int ad1986a_samsung_p50_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1986a_hp_automute(codec);
  	ad1986a_automic(codec);
  	return 0;
  }
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1141

9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1142
  /* models */
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1143
1144
1145
1146
1147
  enum {
  	AD1986A_6STACK,
  	AD1986A_3STACK,
  	AD1986A_LAPTOP,
  	AD1986A_LAPTOP_EAPD,
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1148
  	AD1986A_LAPTOP_AUTOMUTE,
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1149
  	AD1986A_ULTRA,
1725b82a6   Takashi Iwai   ALSA: hda - make ...
1150
  	AD1986A_SAMSUNG,
c912e7a58   Takashi Iwai   ALSA: hda - Fix s...
1151
  	AD1986A_SAMSUNG_P50,
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1152
1153
  	AD1986A_MODELS
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
1154
  static const char * const ad1986a_models[AD1986A_MODELS] = {
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1155
1156
1157
1158
  	[AD1986A_6STACK]	= "6stack",
  	[AD1986A_3STACK]	= "3stack",
  	[AD1986A_LAPTOP]	= "laptop",
  	[AD1986A_LAPTOP_EAPD]	= "laptop-eapd",
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1159
  	[AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1160
  	[AD1986A_ULTRA]		= "ultra",
1725b82a6   Takashi Iwai   ALSA: hda - make ...
1161
  	[AD1986A_SAMSUNG]	= "samsung",
c912e7a58   Takashi Iwai   ALSA: hda - Fix s...
1162
  	[AD1986A_SAMSUNG_P50]	= "samsung-p50",
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1163
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1164
  static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1165
  	SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1166
  	SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1167
  	SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
1168
  	SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1169
1170
1171
1172
  	SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
  	SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
  	SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
  	SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
d9f9b8baa   Tobin Davis   [ALSA] HDA: Add A...
1173
  	SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
658fba0ef   Tobin Davis   [ALSA] hda-codec ...
1174
  	SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1175
1176
1177
1178
1179
  	SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
  	SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
  	SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
  	SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
  	SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
1180
  	SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
ba579eb7b   Daniel T Chen   ALSA: hda: Use 3s...
1181
  	SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
187689913   Tobin Davis   [ALSA] hda-codec ...
1182
  	SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1183
  	SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
c912e7a58   Takashi Iwai   ALSA: hda - Fix s...
1184
  	SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1185
  	SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
dea0a5095   Takashi Iwai   ALSA: hda - Clean...
1186
  	SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
1187
  	SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
187689913   Tobin Davis   [ALSA] hda-codec ...
1188
  	SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1189
  	SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1190
  	SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1191
  	SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1192
1193
  	{}
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1194

cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1195
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
1196
  static const struct hda_amp_list ad1986a_loopbacks[] = {
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1197
1198
1199
1200
1201
1202
1203
1204
  	{ 0x13, HDA_OUTPUT, 0 }, /* Mic */
  	{ 0x14, HDA_OUTPUT, 0 }, /* Phone */
  	{ 0x15, HDA_OUTPUT, 0 }, /* CD */
  	{ 0x16, HDA_OUTPUT, 0 }, /* Aux */
  	{ 0x17, HDA_OUTPUT, 0 }, /* Line */
  	{ } /* end */
  };
  #endif
8c0d9649b   Takashi Iwai   [ALSA] hda-codec ...
1205
1206
  static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
  {
2f334f92c   Takashi Iwai   ALSA: hda - Remov...
1207
  	unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
8c0d9649b   Takashi Iwai   [ALSA] hda-codec ...
1208
1209
  	return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
  }
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1210
  static int patch_ad1986a(struct hda_codec *codec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1211
  {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1212
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
1213
  	int err, board_config;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1214

e560d8d83   Takashi Iwai   [ALSA] Replace wi...
1215
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1216
1217
  	if (spec == NULL)
  		return -ENOMEM;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1218
  	codec->spec = spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
1219
1220
1221
1222
1223
1224
  	err = snd_hda_attach_beep_device(codec, 0x19);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1225
1226
1227
1228
  	spec->multiout.max_channels = 6;
  	spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  	spec->multiout.dac_nids = ad1986a_dac_nids;
  	spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1229
1230
  	spec->num_adc_nids = 1;
  	spec->adc_nids = ad1986a_adc_nids;
a7ee8201a   Takashi Iwai   [ALSA] Fix missin...
1231
  	spec->capsrc_nids = ad1986a_capsrc_nids;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1232
  	spec->input_mux = &ad1986a_capture_source;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1233
1234
1235
1236
  	spec->num_mixers = 1;
  	spec->mixers[0] = ad1986a_mixers;
  	spec->num_init_verbs = 1;
  	spec->init_verbs[0] = ad1986a_init_verbs;
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1237
1238
1239
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1986a_loopbacks;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
1240
  	spec->vmaster_nid = 0x1b;
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
1241
  	spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1242
1243
  
  	codec->patch_ops = ad198x_patch_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1244

9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1245
  	/* override some parameters */
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1246
1247
1248
  	board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
  						  ad1986a_models,
  						  ad1986a_cfg_tbl);
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1249
1250
1251
1252
  	switch (board_config) {
  	case AD1986A_3STACK:
  		spec->num_mixers = 2;
  		spec->mixers[1] = ad1986a_3st_mixers;
fb956c16d   Takashi Iwai   [ALSA] hda-codec ...
1253
1254
  		spec->num_init_verbs = 2;
  		spec->init_verbs[1] = ad1986a_ch2_init;
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1255
1256
  		spec->channel_mode = ad1986a_modes;
  		spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
2125cad29   Takashi Iwai   [ALSA] hda-codec ...
1257
1258
1259
  		spec->need_dac_fix = 1;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1260
1261
1262
1263
1264
1265
1266
  		break;
  	case AD1986A_LAPTOP:
  		spec->mixers[0] = ad1986a_laptop_mixers;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  		break;
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
1267
  	case AD1986A_LAPTOP_EAPD:
16d11a829   Takashi Iwai   ALSA: hda - Simpl...
1268
1269
1270
1271
  		spec->num_mixers = 3;
  		spec->mixers[0] = ad1986a_laptop_master_mixers;
  		spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  		spec->mixers[2] = ad1986a_laptop_intmic_mixers;
1725b82a6   Takashi Iwai   ALSA: hda - make ...
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
  		spec->num_init_verbs = 2;
  		spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  		if (!is_jack_available(codec, 0x25))
  			spec->multiout.dig_out_nid = 0;
  		spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  		break;
  	case AD1986A_SAMSUNG:
16d11a829   Takashi Iwai   ALSA: hda - Simpl...
1282
1283
1284
  		spec->num_mixers = 2;
  		spec->mixers[0] = ad1986a_laptop_master_mixers;
  		spec->mixers[1] = ad1986a_laptop_eapd_mixers;
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
1285
  		spec->num_init_verbs = 3;
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
1286
  		spec->init_verbs[1] = ad1986a_eapd_init_verbs;
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
1287
  		spec->init_verbs[2] = ad1986a_automic_verbs;
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
1288
1289
1290
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
8c0d9649b   Takashi Iwai   [ALSA] hda-codec ...
1291
1292
  		if (!is_jack_available(codec, 0x25))
  			spec->multiout.dig_out_nid = 0;
5d5d5f43f   Takashi Iwai   [ALSA] hda-codec ...
1293
1294
1295
  		spec->input_mux = &ad1986a_automic_capture_source;
  		codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
  		codec->patch_ops.init = ad1986a_automic_init;
825aa9724   Takashi Iwai   [ALSA] hda-codec ...
1296
  		break;
c912e7a58   Takashi Iwai   ALSA: hda - Fix s...
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
  	case AD1986A_SAMSUNG_P50:
  		spec->num_mixers = 2;
  		spec->mixers[0] = ad1986a_automute_master_mixers;
  		spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  		spec->num_init_verbs = 4;
  		spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  		spec->init_verbs[2] = ad1986a_automic_verbs;
  		spec->init_verbs[3] = ad1986a_hp_init_verbs;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  		if (!is_jack_available(codec, 0x25))
  			spec->multiout.dig_out_nid = 0;
  		spec->input_mux = &ad1986a_automic_capture_source;
  		codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
  		codec->patch_ops.init = ad1986a_samsung_p50_init;
  		break;
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1314
  	case AD1986A_LAPTOP_AUTOMUTE:
16d11a829   Takashi Iwai   ALSA: hda - Simpl...
1315
1316
1317
1318
  		spec->num_mixers = 3;
  		spec->mixers[0] = ad1986a_automute_master_mixers;
  		spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  		spec->mixers[2] = ad1986a_laptop_intmic_mixers;
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1319
1320
1321
1322
1323
1324
  		spec->num_init_verbs = 3;
  		spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  		spec->init_verbs[2] = ad1986a_hp_init_verbs;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
8c0d9649b   Takashi Iwai   [ALSA] hda-codec ...
1325
1326
  		if (!is_jack_available(codec, 0x25))
  			spec->multiout.dig_out_nid = 0;
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1327
1328
1329
  		spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  		codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
  		codec->patch_ops.init = ad1986a_hp_init;
03c405ad3   Takashi Iwai   ALSA: hda - Gener...
1330
1331
1332
1333
  		/* Lenovo N100 seems to report the reversed bit
  		 * for HP jack-sensing
  		 */
  		spec->inv_jack_detect = 1;
8ab78c742   Takashi Iwai   [ALSA] hda-codec ...
1334
  		break;
f36090fe0   Tobin Davis   [ALSA] hda-codec ...
1335
1336
1337
1338
1339
1340
1341
1342
1343
  	case AD1986A_ULTRA:
  		spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  		spec->num_init_verbs = 2;
  		spec->init_verbs[1] = ad1986a_ultra_init;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  		spec->multiout.dig_out_nid = 0;
  		break;
9230d2148   Takashi Iwai   [ALSA] hda-codec ...
1344
  	}
d29240ce5   Takashi Iwai   [ALSA] hda-codec ...
1345
1346
1347
1348
1349
1350
1351
  	/* AD1986A has a hardware problem that it can't share a stream
  	 * with multiple output pins.  The copy of front to surrounds
  	 * causes noisy or silent outputs at a certain timing, e.g.
  	 * changing the volume.
  	 * So, let's disable the shared stream.
  	 */
  	spec->multiout.no_share_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
1352
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
1353
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
1354

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1355
1356
1357
1358
  	return 0;
  }
  
  /*
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1359
   * AD1983 specific
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1360
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1361

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1362
1363
1364
  #define AD1983_SPDIF_OUT	0x02
  #define AD1983_DAC		0x03
  #define AD1983_ADC		0x04
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1365

498f5b175   Takashi Iwai   ALSA: hda - Const...
1366
1367
1368
  static const hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
  static const hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
  static const hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1369

498f5b175   Takashi Iwai   ALSA: hda - Const...
1370
  static const struct hda_input_mux ad1983_capture_source = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1371
1372
1373
1374
1375
1376
1377
1378
  	.num_items = 4,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Line", 0x1 },
  		{ "Mix", 0x2 },
  		{ "Mix Mono", 0x3 },
  	},
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1379
1380
  
  /*
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1381
   * SPDIF playback route
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1382
   */
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
1383
  static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1384
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
1385
  	static const char * const texts[] = { "PCM", "ADC" };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1386
1387
1388
1389
1390
1391
1392
1393
  
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  	uinfo->count = 1;
  	uinfo->value.enumerated.items = 2;
  	if (uinfo->value.enumerated.item > 1)
  		uinfo->value.enumerated.item = 1;
  	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1394
  }
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
1395
  static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1396
  {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1397
1398
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1399

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1400
  	ucontrol->value.enumerated.item[0] = spec->spdif_route;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1401
1402
  	return 0;
  }
c8b6bf9b5   Takashi Iwai   [ALSA] Remove xxx...
1403
  static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1404
  {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1405
1406
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
68ea7b2f2   Takashi Iwai   [ALSA] hda-codec ...
1407
1408
  	if (ucontrol->value.enumerated.item[0] > 1)
  		return -EINVAL;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1409
1410
  	if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
  		spec->spdif_route = ucontrol->value.enumerated.item[0];
82beb8fd3   Takashi Iwai   [ALSA] hda-codec ...
1411
1412
1413
  		snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
  					  AC_VERB_SET_CONNECT_SEL,
  					  spec->spdif_route);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1414
1415
  		return 1;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1416
1417
  	return 0;
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
1418
  static const struct snd_kcontrol_new ad1983_mixers[] = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
1431
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x0c, 0x0, HDA_OUTPUT),
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1432
1433
1434
1435
1436
1437
1438
1439
  	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1440
  	},
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1441
1442
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6540dffa6   Takashi Iwai   [ALSA] hda-codec ...
1443
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1444
1445
1446
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1447
  	},
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1448
  	{ } /* end */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1449
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1450
  static const struct hda_verb ad1983_init_verbs[] = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
  	/* Front, HP, Mono; mute as default */
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* Beep, PCM, Mic, Line-In: mute */
  	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* Front, HP selectors; from Mix */
  	{0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  	{0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  	/* Mono selector; from Mix */
  	{0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  	/* Mic selector; Mic */
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Line-in selector: Line-in */
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Mic boost: 0dB */
  	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  	/* Record selector: mic */
  	{0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* SPDIF route: PCM */
  	{0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Front Pin */
  	{0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	/* HP Pin */
  	{0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  	/* Mono Pin */
  	{0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	/* Mic Pin */
  	{0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  	/* Line Pin */
  	{0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  	{ } /* end */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1487
  };
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1488
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
1489
  static const struct hda_amp_list ad1983_loopbacks[] = {
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1490
1491
1492
1493
1494
  	{ 0x12, HDA_OUTPUT, 0 }, /* Mic */
  	{ 0x13, HDA_OUTPUT, 0 }, /* Line */
  	{ } /* end */
  };
  #endif
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1495

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1496
  static int patch_ad1983(struct hda_codec *codec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1497
  {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1498
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
1499
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1500

e560d8d83   Takashi Iwai   [ALSA] Replace wi...
1501
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1502
1503
  	if (spec == NULL)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1504

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1505
  	codec->spec = spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
1506
1507
1508
1509
1510
1511
  	err = snd_hda_attach_beep_device(codec, 0x10);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1512
1513
1514
1515
  	spec->multiout.max_channels = 2;
  	spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
  	spec->multiout.dac_nids = ad1983_dac_nids;
  	spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1516
1517
  	spec->num_adc_nids = 1;
  	spec->adc_nids = ad1983_adc_nids;
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1518
  	spec->capsrc_nids = ad1983_capsrc_nids;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1519
  	spec->input_mux = &ad1983_capture_source;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1520
1521
1522
1523
  	spec->num_mixers = 1;
  	spec->mixers[0] = ad1983_mixers;
  	spec->num_init_verbs = 1;
  	spec->init_verbs[0] = ad1983_init_verbs;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1524
  	spec->spdif_route = 0;
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1525
1526
1527
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1983_loopbacks;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
1528
  	spec->vmaster_nid = 0x05;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1529

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1530
  	codec->patch_ops = ad198x_patch_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1531

729d55ba9   Takashi Iwai   ALSA: hda - Disab...
1532
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
1533
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
1534

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1535
1536
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1537

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1538
1539
1540
  /*
   * AD1981 HD specific
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1541

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1542
1543
1544
  #define AD1981_SPDIF_OUT	0x02
  #define AD1981_DAC		0x03
  #define AD1981_ADC		0x04
498f5b175   Takashi Iwai   ALSA: hda - Const...
1545
1546
1547
  static const hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
  static const hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
  static const hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1548
1549
  
  /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1550
  static const struct hda_input_mux ad1981_capture_source = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
  	.num_items = 7,
  	.items = {
  		{ "Front Mic", 0x0 },
  		{ "Line", 0x1 },
  		{ "Mix", 0x2 },
  		{ "Mix Mono", 0x3 },
  		{ "CD", 0x4 },
  		{ "Mic", 0x6 },
  		{ "Aux", 0x7 },
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1561
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1562
  static const struct snd_kcontrol_new ad1981_mixers[] = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
1581
1582
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
  	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	/* identical with AD1983 */
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6540dffa6   Takashi Iwai   [ALSA] hda-codec ...
1595
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1596
1597
1598
1599
1600
1601
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1602
  static const struct hda_verb ad1981_init_verbs[] = {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
  	/* Front, HP, Mono; mute as default */
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
  	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* Front, HP selectors; from Mix */
  	{0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  	{0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  	/* Mono selector; from Mix */
  	{0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  	/* Mic Mixer; select Front Mic */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  	{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* Mic boost: 0dB */
6d6e17de4   Takashi Iwai   ALSA: hda - Fix i...
1624
1625
  	{0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
  	/* Record selector: Front mic */
  	{0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	/* SPDIF route: PCM */
  	{0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Front Pin */
  	{0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	/* HP Pin */
  	{0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  	/* Mono Pin */
  	{0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  	/* Front & Rear Mic Pins */
  	{0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  	/* Line Pin */
  	{0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  	/* Digital Beep */
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
  	/* Line-Out as Input: disabled */
  	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  	{ } /* end */
  };
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1648
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
1649
  static const struct hda_amp_list ad1981_loopbacks[] = {
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1650
1651
1652
1653
1654
1655
1656
1657
  	{ 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
  	{ 0x13, HDA_OUTPUT, 0 }, /* Line */
  	{ 0x1b, HDA_OUTPUT, 0 }, /* Aux */
  	{ 0x1c, HDA_OUTPUT, 0 }, /* Mic */
  	{ 0x1d, HDA_OUTPUT, 0 }, /* CD */
  	{ } /* end */
  };
  #endif
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1658
1659
1660
  /*
   * Patch for HP nx6320
   *
187689913   Tobin Davis   [ALSA] hda-codec ...
1661
   * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1662
1663
1664
1665
1666
   * speaker output enabled _and_ mute-LED off.
   */
  
  #define AD1981_HP_EVENT		0x37
  #define AD1981_MIC_EVENT	0x38
498f5b175   Takashi Iwai   ALSA: hda - Const...
1667
  static const struct hda_verb ad1981_hp_init_verbs[] = {
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
  	{0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
  	/* pin sensing on HP and Mic jacks */
  	{0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  	{0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  	{}
  };
  
  /* turn on/off EAPD (+ mute HP) as a master switch */
  static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  				   struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
  
  	if (! ad198x_eapd_put(kcontrol, ucontrol))
  		return 0;
f0824812a   Takashi Iwai   [ALSA] hda-codec ...
1684
1685
1686
1687
  	/* change speaker pin appropriately */
  	snd_hda_codec_write(codec, 0x05, 0,
  			    AC_VERB_SET_PIN_WIDGET_CONTROL,
  			    spec->cur_eapd ? PIN_OUT : 0);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1688
  	/* toggle HP mute appropriately */
47fd830ac   Takashi Iwai   [ALSA] hda-codec ...
1689
1690
1691
  	snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE,
  				 spec->cur_eapd ? 0 : HDA_AMP_MUTE);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1692
1693
1694
1695
  	return 1;
  }
  
  /* bind volumes of both NID 0x05 and 0x06 */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1696
  static const struct hda_bind_ctls ad1981_hp_bind_master_vol = {
cca3b3718   Takashi Iwai   [ALSA] hda-codec ...
1697
1698
1699
1700
1701
1702
1703
  	.ops = &snd_hda_bind_vol,
  	.values = {
  		HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  		HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
  		0
  	},
  };
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1704
1705
1706
1707
1708
  
  /* mute internal speaker if HP is plugged */
  static void ad1981_hp_automute(struct hda_codec *codec)
  {
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
1709
  	present = snd_hda_jack_detect(codec, 0x06);
47fd830ac   Takashi Iwai   [ALSA] hda-codec ...
1710
1711
  	snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1712
1713
1714
1715
1716
  }
  
  /* toggle input of built-in and mic jack appropriately */
  static void ad1981_hp_automic(struct hda_codec *codec)
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
1717
  	static const struct hda_verb mic_jack_on[] = {
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1718
1719
1720
1721
  		{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  		{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  		{}
  	};
498f5b175   Takashi Iwai   ALSA: hda - Const...
1722
  	static const struct hda_verb mic_jack_off[] = {
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1723
1724
1725
1726
1727
  		{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  		{0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  		{}
  	};
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
1728
  	present = snd_hda_jack_detect(codec, 0x08);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
  	if (present)
  		snd_hda_sequence_write(codec, mic_jack_on);
  	else
  		snd_hda_sequence_write(codec, mic_jack_off);
  }
  
  /* unsolicited event for HP jack sensing */
  static void ad1981_hp_unsol_event(struct hda_codec *codec,
  				  unsigned int res)
  {
  	res >>= 26;
  	switch (res) {
  	case AD1981_HP_EVENT:
  		ad1981_hp_automute(codec);
  		break;
  	case AD1981_MIC_EVENT:
  		ad1981_hp_automic(codec);
  		break;
  	}
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
1749
  static const struct hda_input_mux ad1981_hp_capture_source = {
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1750
1751
1752
1753
1754
1755
1756
  	.num_items = 3,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Docking-Station", 0x1 },
  		{ "Mix", 0x2 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1757
  static const struct snd_kcontrol_new ad1981_hp_mixers[] = {
cca3b3718   Takashi Iwai   [ALSA] hda-codec ...
1758
  	HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1759
1760
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
1761
  		.subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
  		.name = "Master Playback Switch",
  		.info = ad198x_eapd_info,
  		.get = ad198x_eapd_get,
  		.put = ad1981_hp_master_sw_put,
  		.private_value = 0x05,
  	},
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  #if 0
  	/* FIXME: analog mic/line loopback doesn't work with my tests...
  	 *        (although recording is OK)
  	 */
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  	/* FIXME: does this laptop have analog CD connection? */
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  #endif
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
1784
1785
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
  	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	{ } /* end */
  };
  
  /* initialize jack-sensing, too */
  static int ad1981_hp_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1981_hp_automute(codec);
  	ad1981_hp_automic(codec);
  	return 0;
  }
187689913   Tobin Davis   [ALSA] hda-codec ...
1806
  /* configuration for Toshiba Laptops */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1807
  static const struct hda_verb ad1981_toshiba_init_verbs[] = {
187689913   Tobin Davis   [ALSA] hda-codec ...
1808
1809
1810
1811
1812
1813
  	{0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
  	/* pin sensing on HP and Mic jacks */
  	{0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  	{0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  	{}
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1814
  static const struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
187689913   Tobin Davis   [ALSA] hda-codec ...
1815
1816
1817
1818
  	HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
  	{ }
  };
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1819
  /* configuration for Lenovo Thinkpad T60 */
498f5b175   Takashi Iwai   ALSA: hda - Const...
1820
  static const struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1821
1822
1823
1824
1825
1826
1827
1828
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
1829
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1830
1831
1832
1833
1834
1835
1836
1837
1838
  	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
6540dffa6   Takashi Iwai   [ALSA] hda-codec ...
1839
1840
1841
1842
1843
1844
1845
1846
  	/* identical with AD1983 */
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
  	},
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1847
1848
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1849
  static const struct hda_input_mux ad1981_thinkpad_capture_source = {
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1850
1851
1852
1853
1854
1855
1856
  	.num_items = 3,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Mix", 0x2 },
  		{ "CD", 0x4 },
  	},
  };
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1857
  /* models */
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1858
1859
1860
1861
  enum {
  	AD1981_BASIC,
  	AD1981_HP,
  	AD1981_THINKPAD,
187689913   Tobin Davis   [ALSA] hda-codec ...
1862
  	AD1981_TOSHIBA,
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1863
1864
  	AD1981_MODELS
  };
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1865

ea7349632   Takashi Iwai   ALSA: hda - consi...
1866
  static const char * const ad1981_models[AD1981_MODELS] = {
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1867
1868
1869
  	[AD1981_HP]		= "hp",
  	[AD1981_THINKPAD]	= "thinkpad",
  	[AD1981_BASIC]		= "basic",
187689913   Tobin Davis   [ALSA] hda-codec ...
1870
  	[AD1981_TOSHIBA]	= "toshiba"
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1871
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
1872
  static const struct snd_pci_quirk ad1981_cfg_tbl[] = {
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
1873
  	SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
470eaf6be   Takashi Iwai   ALSA: hda - Add m...
1874
  	SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
8970ccda1   Takashi Iwai   [ALSA] hda-codec ...
1875
  	/* All HP models */
dea0a5095   Takashi Iwai   ALSA: hda - Clean...
1876
  	SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
1877
  	SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1878
  	/* Lenovo Thinkpad T60/X60/Z6xx */
dea0a5095   Takashi Iwai   ALSA: hda - Clean...
1879
  	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
1880
1881
  	/* HP nx6320 (reversed SSID, H/W bug) */
  	SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1882
1883
  	{}
  };
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1884
  static int patch_ad1981(struct hda_codec *codec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1885
  {
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1886
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
1887
  	int err, board_config;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1888

e560d8d83   Takashi Iwai   [ALSA] Replace wi...
1889
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1890
1891
  	if (spec == NULL)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1892
  	codec->spec = spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
1893
1894
1895
1896
1897
1898
  	err = snd_hda_attach_beep_device(codec, 0x10);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1899
1900
1901
1902
  	spec->multiout.max_channels = 2;
  	spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
  	spec->multiout.dac_nids = ad1981_dac_nids;
  	spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1903
1904
  	spec->num_adc_nids = 1;
  	spec->adc_nids = ad1981_adc_nids;
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1905
  	spec->capsrc_nids = ad1981_capsrc_nids;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1906
  	spec->input_mux = &ad1981_capture_source;
985be54ba   Takashi Iwai   [ALSA] hda-codec ...
1907
1908
1909
1910
  	spec->num_mixers = 1;
  	spec->mixers[0] = ad1981_mixers;
  	spec->num_init_verbs = 1;
  	spec->init_verbs[0] = ad1981_init_verbs;
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1911
  	spec->spdif_route = 0;
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
1912
1913
1914
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1981_loopbacks;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
1915
  	spec->vmaster_nid = 0x05;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1916

4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1917
  	codec->patch_ops = ad198x_patch_ops;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1918

18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1919
  	/* override some parameters */
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
1920
1921
1922
  	board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
  						  ad1981_models,
  						  ad1981_cfg_tbl);
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1923
1924
1925
1926
1927
  	switch (board_config) {
  	case AD1981_HP:
  		spec->mixers[0] = ad1981_hp_mixers;
  		spec->num_init_verbs = 2;
  		spec->init_verbs[1] = ad1981_hp_init_verbs;
695cd4a34   Takashi Iwai   ALSA: hda - Disab...
1928
1929
  		if (!is_jack_available(codec, 0x0a))
  			spec->multiout.dig_out_nid = 0;
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1930
1931
1932
1933
  		spec->input_mux = &ad1981_hp_capture_source;
  
  		codec->patch_ops.init = ad1981_hp_init;
  		codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
01f5966d2   Daniel T Chen   ALSA: hda: Fix ma...
1934
1935
1936
1937
1938
1939
1940
1941
  		/* set the upper-limit for mixer amp to 0dB for avoiding the
  		 * possible damage by overloading
  		 */
  		snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  					  (1 << AC_AMPCAP_MUTE_SHIFT));
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1942
  		break;
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1943
1944
  	case AD1981_THINKPAD:
  		spec->mixers[0] = ad1981_thinkpad_mixers;
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1945
  		spec->input_mux = &ad1981_thinkpad_capture_source;
b8e80cf38   Daniel T Chen   ALSA: hda: Fix 0 ...
1946
1947
1948
1949
1950
1951
1952
1953
  		/* set the upper-limit for mixer amp to 0dB for avoiding the
  		 * possible damage by overloading
  		 */
  		snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  					  (1 << AC_AMPCAP_MUTE_SHIFT));
01686c5fc   Takashi Iwai   [ALSA] hda-codec ...
1954
  		break;
187689913   Tobin Davis   [ALSA] hda-codec ...
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
  	case AD1981_TOSHIBA:
  		spec->mixers[0] = ad1981_hp_mixers;
  		spec->mixers[1] = ad1981_toshiba_mixers;
  		spec->num_init_verbs = 2;
  		spec->init_verbs[1] = ad1981_toshiba_init_verbs;
  		spec->multiout.dig_out_nid = 0;
  		spec->input_mux = &ad1981_hp_capture_source;
  		codec->patch_ops.init = ad1981_hp_init;
  		codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  		break;
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
1965
  	}
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
1966
1967
  
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
1968
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
1969

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1970
1971
  	return 0;
  }
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
1972

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1973
  /*
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
1974
1975
1976
1977
   * AD1988
   *
   * Output pins and routes
   *
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
1978
   *        Pin               Mix     Sel     DAC (*)
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
   * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
   * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
   * port-C 0x15 (mute)    <- 0x2c <- 0x31 <- 05/0a
   * port-D 0x12 (mute/hp) <- 0x29         <- 04
   * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
   * port-F 0x16 (mute)    <- 0x2a         <- 06
   * port-G 0x24 (mute)    <- 0x27         <- 05
   * port-H 0x25 (mute)    <- 0x28         <- 0a
   * mono   0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
   *
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
1989
1990
   * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
   * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
   *
   * Input pins and routes
   *
   *        pin     boost   mix input # / adc input #
   * port-A 0x11 -> 0x38 -> mix 2, ADC 0
   * port-B 0x14 -> 0x39 -> mix 0, ADC 1
   * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
   * port-D 0x12 -> 0x3d -> mix 3, ADC 8
   * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
   * port-F 0x16 -> 0x3b -> mix 5, ADC 3
   * port-G 0x24 -> N/A  -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
   * port-H 0x25 -> N/A  -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
   *
   *
   * DAC assignment
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2006
   *   6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
2007
   *   3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
   *
   * Inputs of Analog Mix (0x20)
   *   0:Port-B (front mic)
   *   1:Port-C/G/H (line-in)
   *   2:Port-A
   *   3:Port-D (line-in/2)
   *   4:Port-E/G/H (mic-in)
   *   5:Port-F (mic2-in)
   *   6:CD
   *   7:Beep
   *
   * ADC selection
   *   0:Port-A
   *   1:Port-B (front mic-in)
   *   2:Port-C (line-in)
   *   3:Port-F (mic2-in)
   *   4:Port-E (mic-in)
   *   5:CD
   *   6:Port-G
   *   7:Port-H
   *   8:Port-D (line-in/2)
   *   9:Mix
   *
   * Proposed pin assignments by the datasheet
   *
   * 6-stack
   * Port-A front headphone
   *      B front mic-in
   *      C rear line-in
   *      D rear front-out
   *      E rear mic-in
   *      F rear surround
   *      G rear CLFE
   *      H rear side
   *
   * 3-stack
   * Port-A front headphone
   *      B front mic
   *      C rear line-in/surround
   *      D rear front-out
   *      E rear mic-in/CLFE
   *
   * laptop
   * Port-A headphone
   *      B mic-in
   *      C docking station
   *      D internal speaker (with EAPD)
   *      E/F quad mic array
   */
  
  
  /* models */
  enum {
  	AD1988_6STACK,
  	AD1988_6STACK_DIG,
  	AD1988_3STACK,
  	AD1988_3STACK_DIG,
  	AD1988_LAPTOP,
  	AD1988_LAPTOP_DIG,
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2067
  	AD1988_AUTO,
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2068
2069
  	AD1988_MODEL_LAST,
  };
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2070
2071
  /* reivision id to check workarounds */
  #define AD1988A_REV2		0x100200
1a806f487   Takashi Iwai   [ALSA] Fix workar...
2072
2073
2074
  #define is_rev2(codec) \
  	((codec)->vendor_id == 0x11d41988 && \
  	 (codec)->revision_id == AD1988A_REV2)
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2075
2076
2077
2078
  
  /*
   * mixers
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2079
  static const hda_nid_t ad1988_6stack_dac_nids[4] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2080
2081
  	0x04, 0x06, 0x05, 0x0a
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2082
  static const hda_nid_t ad1988_3stack_dac_nids[3] = {
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
2083
  	0x04, 0x05, 0x0a
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2084
2085
2086
  };
  
  /* for AD1988A revision-2, DAC2-4 are swapped */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2087
  static const hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2088
2089
  	0x04, 0x05, 0x0a, 0x06
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2090
  static const hda_nid_t ad1988_alt_dac_nid[1] = {
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
2091
2092
  	0x03
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2093
  static const hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
2094
  	0x04, 0x0a, 0x06
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2095
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2096
  static const hda_nid_t ad1988_adc_nids[3] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2097
2098
  	0x08, 0x09, 0x0f
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2099
  static const hda_nid_t ad1988_capsrc_nids[3] = {
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2100
2101
  	0x0c, 0x0d, 0x0e
  };
9cae0c637   Robin H. Johnson   ALSA: HDA: patch_...
2102
2103
  #define AD1988_SPDIF_OUT		0x02
  #define AD1988_SPDIF_OUT_HDMI	0x0b
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2104
  #define AD1988_SPDIF_IN		0x07
498f5b175   Takashi Iwai   ALSA: hda - Const...
2105
  static const hda_nid_t ad1989b_slave_dig_outs[] = {
3a08e30de   Takashi Iwai   ALSA: hda - Add m...
2106
  	AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
9cae0c637   Robin H. Johnson   ALSA: HDA: patch_...
2107
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2108
  static const struct hda_input_mux ad1988_6stack_capture_source = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2109
2110
  	.num_items = 5,
  	.items = {
fb304ce53   Takashi Iwai   [ALSA] hda-codec ...
2111
2112
2113
  		{ "Front Mic", 0x1 },	/* port-B */
  		{ "Line", 0x2 },	/* port-C */
  		{ "Mic", 0x4 },		/* port-E */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2114
2115
2116
2117
  		{ "CD", 0x5 },
  		{ "Mix", 0x9 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2118
  static const struct hda_input_mux ad1988_laptop_capture_source = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2119
2120
  	.num_items = 3,
  	.items = {
fb304ce53   Takashi Iwai   [ALSA] hda-codec ...
2121
  		{ "Mic/Line", 0x1 },	/* port-B */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
  		{ "CD", 0x5 },
  		{ "Mix", 0x9 },
  	},
  };
  
  /*
   */
  static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_info *uinfo)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  				    spec->num_channel_mode);
  }
  
  static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  			      struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
  	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  				   spec->num_channel_mode, spec->multiout.max_channels);
  }
  
  static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  			      struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	struct ad198x_spec *spec = codec->spec;
4e195a7b7   Takashi Iwai   [ALSA] Fix noisy ...
2152
2153
2154
  	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  				      spec->num_channel_mode,
  				      &spec->multiout.max_channels);
bd2033f27   Takashi Iwai   [ALSA] hda-codec ...
2155
  	if (err >= 0 && spec->need_dac_fix)
2125cad29   Takashi Iwai   [ALSA] hda-codec ...
2156
  		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
4e195a7b7   Takashi Iwai   [ALSA] Fix noisy ...
2157
  	return err;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2158
  }
34588709a   Raymond Yau   ALSA: HDA - Add I...
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
  static const struct snd_kcontrol_new ad1988_hp_mixers[] = {
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Independent HP",
  		.info = ad1988_independent_hp_info,
  		.get = ad1988_independent_hp_get,
  		.put = ad1988_independent_hp_put,
  	},
  	{ } /* end */
  };
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2169
  /* 6-stack mode */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2170
  static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2171
2172
2173
2174
2175
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
2ece5f42a   Takashi Iwai   [ALSA] hda-codec ...
2176
  	{ } /* end */
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2177
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2178
  static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2179
2180
2181
2182
2183
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
2ece5f42a   Takashi Iwai   [ALSA] hda-codec ...
2184
  	{ } /* end */
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2185
  };
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2186

498f5b175   Takashi Iwai   ALSA: hda - Const...
2187
  static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2188
  	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
  	HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  	HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
  	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
  	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
  	HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
  	HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  	HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2205
  	HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2206
  	HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
2207
2208
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2209
2210
2211
2212
  	{ } /* end */
  };
  
  /* 3-stack mode */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2213
  static const struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2214
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2215
  	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2216
2217
  	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
2ece5f42a   Takashi Iwai   [ALSA] hda-codec ...
2218
  	{ } /* end */
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2219
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2220
  static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2221
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
2222
2223
2224
  	HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
2ece5f42a   Takashi Iwai   [ALSA] hda-codec ...
2225
  	{ } /* end */
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2226
  };
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2227

498f5b175   Takashi Iwai   ALSA: hda - Const...
2228
  static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2229
  	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2230
  	HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2231
2232
2233
  	HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
  	HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
  	HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
  	HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  	HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2245
  	HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2246
  	HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
2247
2248
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Channel Mode",
  		.info = ad198x_ch_mode_info,
  		.get = ad198x_ch_mode_get,
  		.put = ad198x_ch_mode_put,
  	},
  
  	{ } /* end */
  };
  
  /* laptop mode */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2261
  static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2262
  	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
  	HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2273
  	HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2274
  	HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
2275
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2276
2277
2278
2279
  
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "External Amplifier",
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
2280
  		.subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
18a815d74   Takashi Iwai   [ALSA] hda-codec ...
2281
2282
2283
  		.info = ad198x_eapd_info,
  		.get = ad198x_eapd_get,
  		.put = ad198x_eapd_put,
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
2284
  		.private_value = 0x12, /* port-D */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2285
2286
2287
2288
2289
2290
  	},
  
  	{ } /* end */
  };
  
  /* capture */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2291
  static const struct snd_kcontrol_new ad1988_capture_mixers[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		/* The multiple "Capture Source" controls confuse alsamixer
  		 * So call somewhat different..
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
  		 */
  		/* .name = "Capture Source", */
  		.name = "Input Source",
  		.count = 3,
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	{ } /* end */
  };
  
  static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
  					     struct snd_ctl_elem_info *uinfo)
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
2316
  	static const char * const texts[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
  		"PCM", "ADC1", "ADC2", "ADC3"
  	};
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  	uinfo->count = 1;
  	uinfo->value.enumerated.items = 4;
  	if (uinfo->value.enumerated.item >= 4)
  		uinfo->value.enumerated.item = 3;
  	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  	return 0;
  }
  
  static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
  					    struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	unsigned int sel;
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2333
2334
2335
2336
2337
  	sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
  				 AC_AMP_GET_INPUT);
  	if (!(sel & 0x80))
  		ucontrol->value.enumerated.item[0] = 0;
  	else {
35b26722a   Takashi Iwai   [ALSA] hda-codec ...
2338
2339
2340
  		sel = snd_hda_codec_read(codec, 0x0b, 0,
  					 AC_VERB_GET_CONNECT_SEL, 0);
  		if (sel < 3)
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2341
2342
2343
  			sel++;
  		else
  			sel = 0;
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2344
  		ucontrol->value.enumerated.item[0] = sel;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2345
  	}
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2346
2347
2348
2349
2350
2351
2352
  	return 0;
  }
  
  static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
  					    struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
35b26722a   Takashi Iwai   [ALSA] hda-codec ...
2353
  	unsigned int val, sel;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2354
  	int change;
35b26722a   Takashi Iwai   [ALSA] hda-codec ...
2355
  	val = ucontrol->value.enumerated.item[0];
68ea7b2f2   Takashi Iwai   [ALSA] hda-codec ...
2356
2357
  	if (val > 3)
  		return -EINVAL;
35b26722a   Takashi Iwai   [ALSA] hda-codec ...
2358
  	if (!val) {
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2359
2360
2361
2362
  		sel = snd_hda_codec_read(codec, 0x1d, 0,
  					 AC_VERB_GET_AMP_GAIN_MUTE,
  					 AC_AMP_GET_INPUT);
  		change = sel & 0x80;
82beb8fd3   Takashi Iwai   [ALSA] hda-codec ...
2363
2364
2365
2366
2367
2368
2369
  		if (change) {
  			snd_hda_codec_write_cache(codec, 0x1d, 0,
  						  AC_VERB_SET_AMP_GAIN_MUTE,
  						  AMP_IN_UNMUTE(0));
  			snd_hda_codec_write_cache(codec, 0x1d, 0,
  						  AC_VERB_SET_AMP_GAIN_MUTE,
  						  AMP_IN_MUTE(1));
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2370
  		}
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2371
  	} else {
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2372
2373
2374
2375
  		sel = snd_hda_codec_read(codec, 0x1d, 0,
  					 AC_VERB_GET_AMP_GAIN_MUTE,
  					 AC_AMP_GET_INPUT | 0x01);
  		change = sel & 0x80;
82beb8fd3   Takashi Iwai   [ALSA] hda-codec ...
2376
2377
2378
2379
2380
2381
2382
  		if (change) {
  			snd_hda_codec_write_cache(codec, 0x1d, 0,
  						  AC_VERB_SET_AMP_GAIN_MUTE,
  						  AMP_IN_MUTE(0));
  			snd_hda_codec_write_cache(codec, 0x1d, 0,
  						  AC_VERB_SET_AMP_GAIN_MUTE,
  						  AMP_IN_UNMUTE(1));
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2383
  		}
35b26722a   Takashi Iwai   [ALSA] hda-codec ...
2384
2385
2386
  		sel = snd_hda_codec_read(codec, 0x0b, 0,
  					 AC_VERB_GET_CONNECT_SEL, 0) + 1;
  		change |= sel != val;
82beb8fd3   Takashi Iwai   [ALSA] hda-codec ...
2387
2388
2389
2390
  		if (change)
  			snd_hda_codec_write_cache(codec, 0x0b, 0,
  						  AC_VERB_SET_CONNECT_SEL,
  						  val - 1);
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2391
2392
2393
  	}
  	return change;
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
2394
  static const struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2395
2396
2397
2398
  	HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "IEC958 Playback Source",
5b0cb1d85   Jaroslav Kysela   ALSA: hda - add m...
2399
  		.subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2400
2401
2402
2403
2404
2405
  		.info = ad1988_spdif_playback_source_info,
  		.get = ad1988_spdif_playback_source_get,
  		.put = ad1988_spdif_playback_source_put,
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2406
  static const struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2407
2408
2409
  	HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2410
  static const struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
2411
  	HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
9cae0c637   Robin H. Johnson   ALSA: HDA: patch_...
2412
  	HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
2413
2414
  	{ } /* end */
  };
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2415
2416
2417
2418
2419
2420
2421
2422
  
  /*
   * initialization verbs
   */
  
  /*
   * for 6-stack (+dig)
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2423
  static const struct hda_verb ad1988_6stack_init_verbs[] = {
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2424
2425
2426
2427
2428
  	/* Front, Surround, CLFE, side DAC; unmute as default */
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2429
  	/* Port-A front headphon path */
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2430
  	{0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	/* Port-D line-out path */
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	/* Port-F surround path */
  	{0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	/* Port-G CLFE path */
  	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	/* Port-H side path */
  	{0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	/* Mono out path */
  	{0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  	/* Port-B front mic-in path */
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	/* Port-C line-in path */
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  	{0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	{0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* Port-E mic-in path */
  	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	{0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
695005cfe   Johannes Stezenbach   [ALSA] hda-intel:...
2475
2476
  	/* Analog CD Input */
  	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
db3da6c13   Takashi Iwai   ALSA: hda - initi...
2477
2478
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2479
2480
2481
  
  	{ }
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2482
  static const struct hda_verb ad1988_6stack_fp_init_verbs[] = {
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
2483
2484
2485
2486
2487
2488
2489
2490
  	/* Headphone; unmute as default */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	/* Port-A front headphon path */
  	{0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
c66ddf32d   Raymond Yau   ALSA: hda - Add a...
2491
2492
2493
  
  	{ }
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2494
  static const struct hda_verb ad1988_capture_init_verbs[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
  	/* mute analog mix */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  	/* select ADCs - front-mic */
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2508
2509
2510
  
  	{ }
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2511
  static const struct hda_verb ad1988_spdif_init_verbs[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2512
2513
2514
2515
  	/* SPDIF out sel */
  	{0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  	{0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
  	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
bddcf5411   Takashi Iwai   [ALSA] hda-codec ...
2516
  	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2517
2518
  	/* SPDIF out pin */
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2519
2520
2521
  
  	{ }
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2522
  static const struct hda_verb ad1988_spdif_in_init_verbs[] = {
fd0b092a7   Jaroslav Kysela   ALSA: hda - AD198...
2523
2524
2525
2526
  	/* unmute SPDIF input pin */
  	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{ }
  };
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
2527
  /* AD1989 has no ADC -> SPDIF route */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2528
  static const struct hda_verb ad1989_spdif_init_verbs[] = {
e8bfc6c1d   Robin H. Johnson   ALSA: HDA: patch_...
2529
2530
  	/* SPDIF-1 out pin */
  	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
2531
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
e8bfc6c1d   Robin H. Johnson   ALSA: HDA: patch_...
2532
2533
2534
  	/* SPDIF-2/HDMI out pin */
  	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
2535
2536
  	{ }
  };
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2537
2538
2539
  /*
   * verbs for 3stack (+dig)
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2540
  static const struct hda_verb ad1988_3stack_ch2_init[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2541
2542
2543
2544
2545
2546
2547
2548
  	/* set port-C to line-in */
  	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  	/* set port-E to mic-in */
  	{ 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2549
  static const struct hda_verb ad1988_3stack_ch6_init[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2550
  	/* set port-C to surround out */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2551
  	{ 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2552
  	{ 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2553
  	/* set port-E to CLFE out */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2554
  	{ 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2555
  	{ 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2556
2557
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2558
  static const struct hda_channel_mode ad1988_3stack_modes[2] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2559
2560
2561
  	{ 2, ad1988_3stack_ch2_init },
  	{ 6, ad1988_3stack_ch6_init },
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2562
  static const struct hda_verb ad1988_3stack_init_verbs[] = {
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2563
2564
2565
2566
2567
  	/* Front, Surround, CLFE, side DAC; unmute as default */
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2568
  	/* Port-A front headphon path */
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2569
  	{0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	/* Port-D line-out path */
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	/* Mono out path */
  	{0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  	/* Port-B front mic-in path */
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2589
2590
2591
  	/* Port-C line-in/surround path - 6ch mode as default */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2592
  	{0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2593
  	{0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2594
  	{0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2595
2596
2597
  	/* Port-E mic-in/CLFE path - 6ch mode as default */
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2598
  	{0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
2599
  	{0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
  	{0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* mute analog mix */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  	/* select ADCs - front-mic */
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
db3da6c13   Takashi Iwai   ALSA: hda - initi...
2614
2615
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2616
2617
2618
2619
2620
2621
  	{ }
  };
  
  /*
   * verbs for laptop mode (+dig)
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
2622
  static const struct hda_verb ad1988_laptop_hp_on[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2623
2624
2625
2626
2627
  	/* unmute port-A and mute port-D */
  	{ 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  	{ 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2628
  static const struct hda_verb ad1988_laptop_hp_off[] = {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2629
2630
2631
2632
2633
2634
2635
  	/* mute port-A and unmute port-D */
  	{ 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  	{ 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  	{ } /* end */
  };
  
  #define AD1988_HP_EVENT	0x01
498f5b175   Takashi Iwai   ALSA: hda - Const...
2636
  static const struct hda_verb ad1988_laptop_init_verbs[] = {
2e5b9567f   Takashi Iwai   [ALSA] hda-codec ...
2637
2638
2639
2640
2641
  	/* Front, Surround, CLFE, side DAC; unmute as default */
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2642
  	/* Port-A front headphon path */
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2643
  	{0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	/* unsolicited event for pin-sense */
  	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
  	/* Port-D line-out path + EAPD */
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
  	/* Mono out path */
  	{0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  	/* Port-B mic-in path */
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	/* Port-C docking station - try to output */
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	{0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  	/* mute analog mix */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  	/* select ADCs - mic */
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
db3da6c13   Takashi Iwai   ALSA: hda - initi...
2684
2685
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2686
2687
2688
2689
2690
2691
2692
  	{ }
  };
  
  static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
  {
  	if ((res >> 26) != AD1988_HP_EVENT)
  		return;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
2693
  	if (snd_hda_jack_detect(codec, 0x11))
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2694
2695
2696
2697
  		snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
  	else
  		snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
  } 
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
2698
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
2699
  static const struct hda_amp_list ad1988_loopbacks[] = {
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
2700
2701
2702
2703
2704
2705
2706
  	{ 0x20, HDA_INPUT, 0 }, /* Front Mic */
  	{ 0x20, HDA_INPUT, 1 }, /* Line */
  	{ 0x20, HDA_INPUT, 4 }, /* Mic */
  	{ 0x20, HDA_INPUT, 6 }, /* CD */
  	{ } /* end */
  };
  #endif
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
2707
2708
  
  /*
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2709
2710
   * Automatic parse of I/O pins from the BIOS configuration
   */
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2711
2712
2713
2714
2715
  enum {
  	AD_CTL_WIDGET_VOL,
  	AD_CTL_WIDGET_MUTE,
  	AD_CTL_BIND_MUTE,
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
2716
  static const struct snd_kcontrol_new ad1988_control_templates[] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
  	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  	HDA_CODEC_MUTE(NULL, 0, 0, 0),
  	HDA_BIND_MUTE(NULL, 0, 0, 0),
  };
  
  /* add dynamic controls */
  static int add_control(struct ad198x_spec *spec, int type, const char *name,
  		       unsigned long val)
  {
  	struct snd_kcontrol_new *knew;
603c40199   Takashi Iwai   ALSA: hda - Use g...
2727
2728
2729
2730
  	snd_array_init(&spec->kctls, sizeof(*knew), 32);
  	knew = snd_array_new(&spec->kctls);
  	if (!knew)
  		return -ENOMEM;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2731
2732
2733
2734
  	*knew = ad1988_control_templates[type];
  	knew->name = kstrdup(name, GFP_KERNEL);
  	if (! knew->name)
  		return -ENOMEM;
4d02d1b63   Jaroslav Kysela   ALSA: hda - proc ...
2735
  	if (get_amp_nid_(val))
5e26dfd06   Jaroslav Kysela   ALSA: hda - simpl...
2736
  		knew->subdevice = HDA_SUBDEV_AMP_FLAG;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2737
  	knew->private_value = val;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2738
2739
2740
2741
2742
  	return 0;
  }
  
  #define AD1988_PIN_CD_NID		0x18
  #define AD1988_PIN_BEEP_NID		0x10
498f5b175   Takashi Iwai   ALSA: hda - Const...
2743
  static const hda_nid_t ad1988_mixer_nids[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2744
2745
2746
2747
2748
2749
  	/* A     B     C     D     E     F     G     H */
  	0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
  };
  
  static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
2750
  	static const hda_nid_t idx_to_dac[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2751
  		/* A     B     C     D     E     F     G     H */
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2752
  		0x03, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2753
  	};
498f5b175   Takashi Iwai   ALSA: hda - Const...
2754
  	static const hda_nid_t idx_to_dac_rev2[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2755
  		/* A     B     C     D     E     F     G     H */
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2756
  		0x03, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2757
  	};
1a806f487   Takashi Iwai   [ALSA] Fix workar...
2758
  	if (is_rev2(codec))
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2759
2760
2761
2762
  		return idx_to_dac_rev2[idx];
  	else
  		return idx_to_dac[idx];
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
2763
  static const hda_nid_t ad1988_boost_nids[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2764
2765
2766
2767
2768
  	0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
  };
  
  static int ad1988_pin_idx(hda_nid_t nid)
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
2769
  	static const hda_nid_t ad1988_io_pins[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
  		0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
  	};
  	int i;
  	for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
  		if (ad1988_io_pins[i] == nid)
  			return i;
  	return 0; /* should be -1 */
  }
  
  static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
2781
  	static const int loopback_idx[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
  		2, 0, 1, 3, 4, 5, 1, 4
  	};
  	switch (nid) {
  	case AD1988_PIN_CD_NID:
  		return 6;
  	default:
  		return loopback_idx[ad1988_pin_idx(nid)];
  	}
  }
  
  static int ad1988_pin_to_adc_idx(hda_nid_t nid)
  {
498f5b175   Takashi Iwai   ALSA: hda - Const...
2794
  	static const int adc_idx[8] = {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
  		0, 1, 2, 8, 4, 3, 6, 7
  	};
  	switch (nid) {
  	case AD1988_PIN_CD_NID:
  		return 5;
  	default:
  		return adc_idx[ad1988_pin_idx(nid)];
  	}
  }
  
  /* fill in the dac_nids table from the parsed pin configuration */
  static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
  				     const struct auto_pin_cfg *cfg)
  {
  	struct ad198x_spec *spec = codec->spec;
  	int i, idx;
  
  	spec->multiout.dac_nids = spec->private_dac_nids;
  
  	/* check the pins hardwired to audio widget */
  	for (i = 0; i < cfg->line_outs; i++) {
  		idx = ad1988_pin_idx(cfg->line_out_pins[i]);
dda144103   Takashi Iwai   ALSA: hda - Const...
2817
  		spec->private_dac_nids[i] = ad1988_idx_to_dac(codec, idx);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
  	}
  	spec->multiout.num_dacs = cfg->line_outs;
  	return 0;
  }
  
  /* add playback controls from the parsed DAC table */
  static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
  					     const struct auto_pin_cfg *cfg)
  {
  	char name[32];
ea7349632   Takashi Iwai   ALSA: hda - consi...
2828
2829
2830
  	static const char * const chname[4] = {
  		"Front", "Surround", NULL /*CLFE*/, "Side"
  	};
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
  	hda_nid_t nid;
  	int i, err;
  
  	for (i = 0; i < cfg->line_outs; i++) {
  		hda_nid_t dac = spec->multiout.dac_nids[i];
  		if (! dac)
  			continue;
  		nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
  		if (i == 2) {
  			/* Center/LFE */
  			err = add_control(spec, AD_CTL_WIDGET_VOL,
  					  "Center Playback Volume",
  					  HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
  			if (err < 0)
  				return err;
  			err = add_control(spec, AD_CTL_WIDGET_VOL,
  					  "LFE Playback Volume",
  					  HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
  			if (err < 0)
  				return err;
  			err = add_control(spec, AD_CTL_BIND_MUTE,
  					  "Center Playback Switch",
  					  HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
  			if (err < 0)
  				return err;
  			err = add_control(spec, AD_CTL_BIND_MUTE,
  					  "LFE Playback Switch",
  					  HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
  			if (err < 0)
  				return err;
  		} else {
  			sprintf(name, "%s Playback Volume", chname[i]);
  			err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  					  HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
  			if (err < 0)
  				return err;
  			sprintf(name, "%s Playback Switch", chname[i]);
  			err = add_control(spec, AD_CTL_BIND_MUTE, name,
  					  HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
  			if (err < 0)
  				return err;
  		}
  	}
  	return 0;
  }
  
  /* add playback controls for speaker and HP outputs */
  static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  					const char *pfx)
  {
  	struct ad198x_spec *spec = codec->spec;
  	hda_nid_t nid;
43785eaeb   Takashi Iwai   ALSA: hda - Fix w...
2883
  	int i, idx, err;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2884
2885
2886
2887
2888
2889
2890
  	char name[32];
  
  	if (! pin)
  		return 0;
  
  	idx = ad1988_pin_idx(pin);
  	nid = ad1988_idx_to_dac(codec, idx);
43785eaeb   Takashi Iwai   ALSA: hda - Fix w...
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
  	/* check whether the corresponding DAC was already taken */
  	for (i = 0; i < spec->autocfg.line_outs; i++) {
  		hda_nid_t pin = spec->autocfg.line_out_pins[i];
  		hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
  		if (dac == nid)
  			break;
  	}
  	if (i >= spec->autocfg.line_outs) {
  		/* specify the DAC as the extra output */
  		if (!spec->multiout.hp_nid)
  			spec->multiout.hp_nid = nid;
  		else
  			spec->multiout.extra_out_nid[0] = nid;
  		/* control HP volume/switch on the output mixer amp */
  		sprintf(name, "%s Playback Volume", pfx);
  		err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  				  HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
  		if (err < 0)
  			return err;
  	}
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
  	nid = ad1988_mixer_nids[idx];
  	sprintf(name, "%s Playback Switch", pfx);
  	if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
  			       HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  		return err;
  	return 0;
  }
  
  /* create input playback/capture controls for the given pin */
  static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
9e042e713   Takashi Iwai   ALSA: hda - Use n...
2921
  			    const char *ctlname, int ctlidx, int boost)
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
  {
  	char name[32];
  	int err, idx;
  
  	sprintf(name, "%s Playback Volume", ctlname);
  	idx = ad1988_pin_to_loopback_idx(pin);
  	if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  			       HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  		return err;
  	sprintf(name, "%s Playback Switch", ctlname);
  	if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
  			       HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  		return err;
  	if (boost) {
  		hda_nid_t bnid;
  		idx = ad1988_pin_idx(pin);
  		bnid = ad1988_boost_nids[idx];
  		if (bnid) {
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
2940
  			sprintf(name, "%s Boost Volume", ctlname);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2941
2942
2943
2944
2945
2946
2947
2948
2949
  			return add_control(spec, AD_CTL_WIDGET_VOL, name,
  					   HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
  
  		}
  	}
  	return 0;
  }
  
  /* create playback/capture controls for input pins */
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2950
  static int ad1988_auto_create_analog_input_ctls(struct hda_codec *codec,
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2951
2952
  						const struct auto_pin_cfg *cfg)
  {
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2953
  	struct ad198x_spec *spec = codec->spec;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2954
  	struct hda_input_mux *imux = &spec->private_imux;
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2955
  	int i, err, type, type_idx;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2956

9e042e713   Takashi Iwai   ALSA: hda - Use n...
2957
  	for (i = 0; i < cfg->num_inputs; i++) {
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2958
  		const char *label;
9e042e713   Takashi Iwai   ALSA: hda - Use n...
2959
  		type = cfg->inputs[i].type;
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2960
2961
2962
2963
  		label = hda_get_autocfg_input_label(codec, cfg, i);
  		snd_hda_add_imux_item(imux, label,
  				      ad1988_pin_to_adc_idx(cfg->inputs[i].pin),
  				      &type_idx);
9e042e713   Takashi Iwai   ALSA: hda - Use n...
2964
  		err = new_analog_input(spec, cfg->inputs[i].pin,
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2965
  				       label, type_idx,
86e2959a1   Takashi Iwai   ALSA: hda - Remov...
2966
  				       type == AUTO_PIN_MIC);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2967
2968
  		if (err < 0)
  			return err;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2969
  	}
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
2970
  	snd_hda_add_imux_item(imux, "Mix", 9, NULL);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
  
  	if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
  			       "Analog Mix Playback Volume",
  			       HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  		return err;
  	if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
  			       "Analog Mix Playback Switch",
  			       HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  		return err;
  
  	return 0;
  }
  
  static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
  					      hda_nid_t nid, int pin_type,
  					      int dac_idx)
  {
  	/* set as output */
  	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  	switch (nid) {
356aab7d4   Raymond Yau   ALSA: hda - Add H...
2992
2993
  	case 0x11: /* port-A - DAC 03 */
  		snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
2994
2995
2996
2997
2998
2999
3000
  		break;
  	case 0x14: /* port-B - DAC 06 */
  		snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
  		break;
  	case 0x15: /* port-C - DAC 05 */
  		snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
  		break;
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
3001
  	case 0x17: /* port-E - DAC 0a */
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
  		snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  		break;
  	case 0x13: /* mono - DAC 04 */
  		snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  		break;
  	}
  }
  
  static void ad1988_auto_init_multi_out(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  	int i;
  
  	for (i = 0; i < spec->autocfg.line_outs; i++) {
  		hda_nid_t nid = spec->autocfg.line_out_pins[i];
  		ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  	}
  }
  
  static void ad1988_auto_init_extra_out(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  	hda_nid_t pin;
82bc955f6   Takashi Iwai   [ALSA] hda-codec ...
3025
  	pin = spec->autocfg.speaker_pins[0];
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3026
3027
  	if (pin) /* connect to front */
  		ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
eb06ed8f4   Takashi Iwai   [ALSA] hda-codec ...
3028
  	pin = spec->autocfg.hp_pins[0];
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3029
3030
3031
3032
3033
3034
3035
  	if (pin) /* connect to front */
  		ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  }
  
  static void ad1988_auto_init_analog_input(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
9e042e713   Takashi Iwai   ALSA: hda - Use n...
3036
  	const struct auto_pin_cfg *cfg = &spec->autocfg;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3037
  	int i, idx;
9e042e713   Takashi Iwai   ALSA: hda - Use n...
3038
3039
  	for (i = 0; i < cfg->num_inputs; i++) {
  		hda_nid_t nid = cfg->inputs[i].pin;
5a2d227fd   Adrian Wilkins   ALSA: hda - Fix i...
3040
  		int type = cfg->inputs[i].type;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3041
3042
3043
3044
3045
3046
3047
3048
3049
  		switch (nid) {
  		case 0x15: /* port-C */
  			snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  			break;
  		case 0x17: /* port-E */
  			snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  			break;
  		}
  		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5a2d227fd   Adrian Wilkins   ALSA: hda - Fix i...
3050
  				    type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
  		if (nid != AD1988_PIN_CD_NID)
  			snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  					    AMP_OUT_MUTE);
  		idx = ad1988_pin_idx(nid);
  		if (ad1988_boost_nids[idx])
  			snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
  					    AC_VERB_SET_AMP_GAIN_MUTE,
  					    AMP_OUT_ZERO);
  	}
  }
  
  /* parse the BIOS configuration and set up the alc_spec */
  /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  static int ad1988_parse_auto_config(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  	int err;
df694daa3   Kailang Yang   [ALSA] hda-codec ...
3068
  	if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3069
3070
3071
  		return err;
  	if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  		return err;
82bc955f6   Takashi Iwai   [ALSA] hda-codec ...
3072
  	if (! spec->autocfg.line_outs)
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3073
3074
  		return 0; /* can't find valid BIOS pin config */
  	if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
82bc955f6   Takashi Iwai   [ALSA] hda-codec ...
3075
3076
  	    (err = ad1988_auto_create_extra_out(codec,
  						spec->autocfg.speaker_pins[0],
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3077
  						"Speaker")) < 0 ||
eb06ed8f4   Takashi Iwai   [ALSA] hda-codec ...
3078
  	    (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3079
  						"Headphone")) < 0 ||
10a20af7c   Takashi Iwai   ALSA: hda - Impro...
3080
  	    (err = ad1988_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3081
3082
3083
  		return err;
  
  	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
0852d7a65   Takashi Iwai   ALSA: hda - Detec...
3084
  	if (spec->autocfg.dig_outs)
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3085
3086
3087
  		spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  	if (spec->autocfg.dig_in_pin)
  		spec->dig_in_nid = AD1988_SPDIF_IN;
603c40199   Takashi Iwai   ALSA: hda - Use g...
3088
3089
  	if (spec->kctls.list)
  		spec->mixers[spec->num_mixers++] = spec->kctls.list;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
  
  	spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
  
  	spec->input_mux = &spec->private_imux;
  
  	return 1;
  }
  
  /* init callback for auto-configuration model -- overriding the default init */
  static int ad1988_auto_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1988_auto_init_multi_out(codec);
  	ad1988_auto_init_extra_out(codec);
  	ad1988_auto_init_analog_input(codec);
  	return 0;
  }
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3107
  /*
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3108
   */
ea7349632   Takashi Iwai   ALSA: hda - consi...
3109
  static const char * const ad1988_models[AD1988_MODEL_LAST] = {
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
3110
3111
3112
3113
3114
3115
3116
  	[AD1988_6STACK]		= "6stack",
  	[AD1988_6STACK_DIG]	= "6stack-dig",
  	[AD1988_3STACK]		= "3stack",
  	[AD1988_3STACK_DIG]	= "3stack-dig",
  	[AD1988_LAPTOP]		= "laptop",
  	[AD1988_LAPTOP_DIG]	= "laptop-dig",
  	[AD1988_AUTO]		= "auto",
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3117
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3118
  static const struct snd_pci_quirk ad1988_cfg_tbl[] = {
187689913   Tobin Davis   [ALSA] hda-codec ...
3119
  	SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
ac3e37412   Takashi Iwai   [ALSA] hda-codec ...
3120
  	SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
b9e16bc54   Travis Place   [ALSA] hda - Add ...
3121
  	SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
4e60b4f83   Tony Vroon   ALSA: hda - Force...
3122
  	SND_PCI_QUIRK(0x1043, 0x82c0, "Asus M3N-HT Deluxe", AD1988_6STACK_DIG),
f51ff9937   Robin H. Johnson   ALSA: HDA: patch_...
3123
  	SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
a64c8cd6e   Tobin Davis   [ALSA] hda-codec ...
3124
3125
  	{}
  };
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3126
3127
3128
  static int patch_ad1988(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
3129
  	int err, board_config;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3130
3131
3132
3133
  
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  	if (spec == NULL)
  		return -ENOMEM;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3134
  	codec->spec = spec;
1a806f487   Takashi Iwai   [ALSA] Fix workar...
3135
  	if (is_rev2(codec))
f8c7c7b8d   Takashi Iwai   [ALSA] hda-codec ...
3136
3137
  		snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds
  ");
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
3138
  	board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
a64c8cd6e   Tobin Davis   [ALSA] hda-codec ...
3139
  						  ad1988_models, ad1988_cfg_tbl);
f5fcc13c2   Takashi Iwai   [ALSA] hda-codec ...
3140
  	if (board_config < 0) {
9a11f1aa8   Takashi Iwai   ALSA: hda - Rewor...
3141
3142
3143
  		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.
  ",
  		       codec->chip_name);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3144
3145
3146
3147
3148
  		board_config = AD1988_AUTO;
  	}
  
  	if (board_config == AD1988_AUTO) {
  		/* automatic parse from the BIOS config */
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
3149
  		err = ad1988_parse_auto_config(codec);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3150
3151
3152
3153
3154
3155
3156
3157
  		if (err < 0) {
  			ad198x_free(codec);
  			return err;
  		} else if (! err) {
  			printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS.  Using 6-stack mode...
  ");
  			board_config = AD1988_6STACK;
  		}
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3158
  	}
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
3159
3160
3161
3162
3163
3164
  	err = snd_hda_attach_beep_device(codec, 0x10);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
356aab7d4   Raymond Yau   ALSA: hda - Add H...
3165
  	if (!spec->multiout.hp_nid)
34588709a   Raymond Yau   ALSA: HDA - Add I...
3166
  		spec->multiout.hp_nid = ad1988_alt_dac_nid[0];
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3167
3168
3169
3170
3171
  	switch (board_config) {
  	case AD1988_6STACK:
  	case AD1988_6STACK_DIG:
  		spec->multiout.max_channels = 8;
  		spec->multiout.num_dacs = 4;
1a806f487   Takashi Iwai   [ALSA] Fix workar...
3172
  		if (is_rev2(codec))
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3173
3174
3175
  			spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
  		else
  			spec->multiout.dac_nids = ad1988_6stack_dac_nids;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3176
  		spec->input_mux = &ad1988_6stack_capture_source;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3177
  		spec->num_mixers = 2;
1a806f487   Takashi Iwai   [ALSA] Fix workar...
3178
  		if (is_rev2(codec))
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3179
3180
3181
  			spec->mixers[0] = ad1988_6stack_mixers1_rev2;
  		else
  			spec->mixers[0] = ad1988_6stack_mixers1;
282208460   Raymond Yau   ALSA: hda - simpl...
3182
3183
3184
  		spec->mixers[1] = ad1988_6stack_mixers2;
  		spec->num_init_verbs = 1;
  		spec->init_verbs[0] = ad1988_6stack_init_verbs;
34588709a   Raymond Yau   ALSA: HDA - Add I...
3185
  		if (board_config == AD1988_6STACK_DIG) {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3186
3187
3188
3189
3190
3191
3192
3193
  			spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  			spec->dig_in_nid = AD1988_SPDIF_IN;
  		}
  		break;
  	case AD1988_3STACK:
  	case AD1988_3STACK_DIG:
  		spec->multiout.max_channels = 6;
  		spec->multiout.num_dacs = 3;
1a806f487   Takashi Iwai   [ALSA] Fix workar...
3194
  		if (is_rev2(codec))
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3195
3196
3197
  			spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
  		else
  			spec->multiout.dac_nids = ad1988_3stack_dac_nids;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3198
3199
3200
  		spec->input_mux = &ad1988_6stack_capture_source;
  		spec->channel_mode = ad1988_3stack_modes;
  		spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3201
  		spec->num_mixers = 2;
1a806f487   Takashi Iwai   [ALSA] Fix workar...
3202
  		if (is_rev2(codec))
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3203
3204
3205
3206
  			spec->mixers[0] = ad1988_3stack_mixers1_rev2;
  		else
  			spec->mixers[0] = ad1988_3stack_mixers1;
  		spec->mixers[1] = ad1988_3stack_mixers2;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3207
3208
3209
3210
3211
3212
3213
3214
3215
  		spec->num_init_verbs = 1;
  		spec->init_verbs[0] = ad1988_3stack_init_verbs;
  		if (board_config == AD1988_3STACK_DIG)
  			spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  		break;
  	case AD1988_LAPTOP:
  	case AD1988_LAPTOP_DIG:
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3216
  		spec->multiout.dac_nids = ad1988_3stack_dac_nids;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3217
3218
3219
  		spec->input_mux = &ad1988_laptop_capture_source;
  		spec->num_mixers = 1;
  		spec->mixers[0] = ad1988_laptop_mixers;
ee6e365e3   Takashi Iwai   ALSA: hda - Gener...
3220
  		spec->inv_eapd = 1; /* inverted EAPD */
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3221
3222
3223
3224
3225
3226
  		spec->num_init_verbs = 1;
  		spec->init_verbs[0] = ad1988_laptop_init_verbs;
  		if (board_config == AD1988_LAPTOP_DIG)
  			spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  		break;
  	}
34588709a   Raymond Yau   ALSA: HDA - Add I...
3227
3228
3229
3230
3231
3232
3233
3234
  	if (spec->autocfg.hp_pins[0]) {
  		spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
  		spec->slave_vols = ad1988_6stack_fp_slave_vols;
  		spec->slave_sws = ad1988_6stack_fp_slave_sws;
  		spec->alt_dac_nid = ad1988_alt_dac_nid;
  		spec->stream_analog_alt_playback =
  			&ad198x_pcm_analog_alt_playback;
  	}
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3235
3236
3237
  	spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
  	spec->adc_nids = ad1988_adc_nids;
  	spec->capsrc_nids = ad1988_capsrc_nids;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3238
3239
3240
  	spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
  	spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
  	if (spec->multiout.dig_out_nid) {
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
3241
3242
3243
3244
3245
  		if (codec->vendor_id >= 0x11d4989a) {
  			spec->mixers[spec->num_mixers++] =
  				ad1989_spdif_out_mixers;
  			spec->init_verbs[spec->num_init_verbs++] =
  				ad1989_spdif_init_verbs;
9cae0c637   Robin H. Johnson   ALSA: HDA: patch_...
3246
  			codec->slave_dig_outs = ad1989b_slave_dig_outs;
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
3247
3248
3249
3250
3251
3252
  		} else {
  			spec->mixers[spec->num_mixers++] =
  				ad1988_spdif_out_mixers;
  			spec->init_verbs[spec->num_init_verbs++] =
  				ad1988_spdif_init_verbs;
  		}
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3253
  	}
fd0b092a7   Jaroslav Kysela   ALSA: hda - AD198...
3254
  	if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3255
  		spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
fd0b092a7   Jaroslav Kysela   ALSA: hda - AD198...
3256
3257
3258
  		spec->init_verbs[spec->num_init_verbs++] =
  			ad1988_spdif_in_init_verbs;
  	}
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3259
3260
3261
  
  	codec->patch_ops = ad198x_patch_ops;
  	switch (board_config) {
d32410b10   Takashi Iwai   [ALSA] hda-codec ...
3262
3263
3264
  	case AD1988_AUTO:
  		codec->patch_ops.init = ad1988_auto_init;
  		break;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3265
3266
3267
3268
3269
  	case AD1988_LAPTOP:
  	case AD1988_LAPTOP_DIG:
  		codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
  		break;
  	}
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
3270
3271
3272
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1988_loopbacks;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
3273
  	spec->vmaster_nid = 0x04;
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3274

729d55ba9   Takashi Iwai   ALSA: hda - Disab...
3275
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
3276
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
3277

fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
3278
3279
3280
3281
3282
  	return 0;
  }
  
  
  /*
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
   * AD1884 / AD1984
   *
   * port-B - front line/mic-in
   * port-E - aux in/out
   * port-F - aux in/out
   * port-C - rear line/mic-in
   * port-D - rear line/hp-out
   * port-A - front line/hp-out
   *
   * AD1984 = AD1884 + two digital mic-ins
   *
   * FIXME:
   * For simplicity, we share the single DAC for both HP and line-outs
   * right now.  The inidividual playbacks could be easily implemented,
   * but no build-up framework is given, so far.
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3299
  static const hda_nid_t ad1884_dac_nids[1] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3300
3301
  	0x04,
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3302
  static const hda_nid_t ad1884_adc_nids[2] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3303
3304
  	0x08, 0x09,
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3305
  static const hda_nid_t ad1884_capsrc_nids[2] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3306
3307
3308
3309
  	0x0c, 0x0d,
  };
  
  #define AD1884_SPDIF_OUT	0x02
498f5b175   Takashi Iwai   ALSA: hda - Const...
3310
  static const struct hda_input_mux ad1884_capture_source = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3311
3312
3313
3314
3315
3316
3317
3318
  	.num_items = 4,
  	.items = {
  		{ "Front Mic", 0x0 },
  		{ "Mic", 0x1 },
  		{ "CD", 0x2 },
  		{ "Mix", 0x3 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3319
  static const struct snd_kcontrol_new ad1884_base_mixers[] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	/* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
3332
3333
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3334
3335
3336
3337
3338
3339
3340
3341
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		/* The multiple "Capture Source" controls confuse alsamixer
  		 * So call somewhat different..
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
  		 */
  		/* .name = "Capture Source", */
  		.name = "Input Source",
  		.count = 2,
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	/* SPDIF controls */
  	HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  		/* identical with ad1983 */
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3362
  static const struct snd_kcontrol_new ad1984_dmic_mixers[] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3363
3364
3365
  	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
  	HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
538c49c41   Takashi Iwai   [ALSA] hda-codec ...
3366
  			     HDA_INPUT),
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3367
  	HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
538c49c41   Takashi Iwai   [ALSA] hda-codec ...
3368
  			   HDA_INPUT),
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3369
3370
3371
3372
3373
3374
  	{ } /* end */
  };
  
  /*
   * initialization verbs
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3375
  static const struct hda_verb ad1884_init_verbs[] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3376
  	/* DACs; mute as default */
3b194401a   Takashi Iwai   [ALSA] hda-codec ...
3377
3378
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
  	/* Port-A (HP) mixer */
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-A pin */
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* HP selector - select DAC2 */
  	{0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
  	/* Port-D (Line-out) mixer */
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-D pin */
  	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Mono-out mixer */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Mono-out pin */
  	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Mono selector */
  	{0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  	/* Port-B (front mic) pin */
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
60e388e89   Takashi Iwai   ALSA: hda - Fix i...
3403
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3404
3405
  	/* Port-C (rear mic) pin */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
60e388e89   Takashi Iwai   ALSA: hda - Fix i...
3406
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
  	/* Analog mixer; mute as default */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  	/* SPDIF output selector */
  	{0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  	{ } /* end */
  };
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
3419
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
3420
  static const struct hda_amp_list ad1884_loopbacks[] = {
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
3421
3422
3423
3424
3425
3426
3427
  	{ 0x20, HDA_INPUT, 0 }, /* Front Mic */
  	{ 0x20, HDA_INPUT, 1 }, /* Mic */
  	{ 0x20, HDA_INPUT, 2 }, /* CD */
  	{ 0x20, HDA_INPUT, 4 }, /* Docking */
  	{ } /* end */
  };
  #endif
ea7349632   Takashi Iwai   ALSA: hda - consi...
3428
  static const char * const ad1884_slave_vols[] = {
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
3429
3430
3431
3432
3433
3434
3435
  	"PCM Playback Volume",
  	"Mic Playback Volume",
  	"Mono Playback Volume",
  	"Front Mic Playback Volume",
  	"Mic Playback Volume",
  	"CD Playback Volume",
  	"Internal Mic Playback Volume",
bca68467b   Akinobu Mita   ALSA: hda - add m...
3436
  	"Docking Mic Playback Volume",
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
3437
  	/* "Beep Playback Volume", */
4806ef0cf   Takashi Iwai   [ALSA] hda-codec ...
3438
  	"IEC958 Playback Volume",
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
3439
3440
  	NULL
  };
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3441
3442
3443
  static int patch_ad1884(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
3444
  	int err;
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3445
3446
3447
3448
  
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  	if (spec == NULL)
  		return -ENOMEM;
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3449
  	codec->spec = spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
3450
3451
3452
3453
3454
3455
  	err = snd_hda_attach_beep_device(codec, 0x10);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
  	spec->multiout.max_channels = 2;
  	spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
  	spec->multiout.dac_nids = ad1884_dac_nids;
  	spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
  	spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
  	spec->adc_nids = ad1884_adc_nids;
  	spec->capsrc_nids = ad1884_capsrc_nids;
  	spec->input_mux = &ad1884_capture_source;
  	spec->num_mixers = 1;
  	spec->mixers[0] = ad1884_base_mixers;
  	spec->num_init_verbs = 1;
  	spec->init_verbs[0] = ad1884_init_verbs;
  	spec->spdif_route = 0;
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
3469
3470
3471
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1884_loopbacks;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
3472
3473
3474
  	spec->vmaster_nid = 0x04;
  	/* we need to cover all playback volumes */
  	spec->slave_vols = ad1884_slave_vols;
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3475
3476
  
  	codec->patch_ops = ad198x_patch_ops;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
3477
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
3478
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
3479

2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3480
3481
3482
3483
3484
3485
  	return 0;
  }
  
  /*
   * Lenovo Thinkpad T61/X61
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3486
  static const struct hda_input_mux ad1984_thinkpad_capture_source = {
b26451c05   Takashi Iwai   [ALSA] hda-codec ...
3487
  	.num_items = 4,
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3488
3489
3490
3491
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Internal Mic", 0x1 },
  		{ "Mix", 0x3 },
b26451c05   Takashi Iwai   [ALSA] hda-codec ...
3492
  		{ "Docking-Station", 0x4 },
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3493
3494
  	},
  };
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3495
3496
3497
3498
  
  /*
   * Dell Precision T3400
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3499
  static const struct hda_input_mux ad1984_dell_desktop_capture_source = {
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3500
3501
3502
3503
3504
3505
3506
  	.num_items = 3,
  	.items = {
  		{ "Front Mic", 0x0 },
  		{ "Line-In", 0x1 },
  		{ "Mix", 0x3 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3507
  static const struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3508
3509
3510
3511
3512
3513
3514
3515
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	/* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
0bf0e5a6f   Jaroslav Kysela   ALSA: hda-intel -...
3516
3517
  	HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
  	HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3518
3519
  	HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
3520
3521
3522
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3523
3524
3525
3526
3527
3528
3529
3530
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		/* The multiple "Capture Source" controls confuse alsamixer
  		 * So call somewhat different..
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3531
3532
3533
3534
3535
3536
3537
3538
  		 */
  		/* .name = "Capture Source", */
  		.name = "Input Source",
  		.count = 2,
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
ebf00c54a   Jerone Young   [ALSA] hda-codec ...
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
  	/* SPDIF controls */
  	HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  		/* identical with ad1983 */
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
  	},
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3549
3550
3551
3552
  	{ } /* end */
  };
  
  /* additional verbs */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3553
  static const struct hda_verb ad1984_thinkpad_init_verbs[] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3554
3555
3556
3557
  	/* Port-E (docking station mic) pin */
  	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* docking mic boost */
70040c074   Takashi Iwai   ALSA: hda - Fix w...
3558
  	{0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
0bf0e5a6f   Jaroslav Kysela   ALSA: hda-intel -...
3559
3560
  	/* Analog PC Beeper - allow firmware/ACPI beeps */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3) | 0x1a},
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3561
3562
  	/* Analog mixer - docking mic; mute as default */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
b959d1f83   Takashi Iwai   [ALSA] hda-codec ...
3563
3564
  	/* enable EAPD bit */
  	{0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3565
3566
  	{ } /* end */
  };
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3567
3568
3569
  /*
   * Dell Precision T3400
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3570
  static const struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3571
3572
3573
3574
3575
3576
3577
3578
3579
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
3580
3581
  	HDA_CODEC_VOLUME("Line-In Boost Volume", 0x15, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		/* The multiple "Capture Source" controls confuse alsamixer
  		 * So call somewhat different..
  		 */
  		/* .name = "Capture Source", */
  		.name = "Input Source",
  		.count = 2,
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	{ } /* end */
  };
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
  /* Digial MIC ADC NID 0x05 + 0x06 */
  static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
  				   struct hda_codec *codec,
  				   unsigned int stream_tag,
  				   unsigned int format,
  				   struct snd_pcm_substream *substream)
  {
  	snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
  				   stream_tag, 0, format);
  	return 0;
  }
  
  static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
  				   struct hda_codec *codec,
  				   struct snd_pcm_substream *substream)
  {
888afa154   Takashi Iwai   [ALSA] hda-codec ...
3616
  	snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3617
3618
  	return 0;
  }
498f5b175   Takashi Iwai   ALSA: hda - Const...
3619
  static const struct hda_pcm_stream ad1984_pcm_dmic_capture = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
  	.substreams = 2,
  	.channels_min = 2,
  	.channels_max = 2,
  	.nid = 0x05,
  	.ops = {
  		.prepare = ad1984_pcm_dmic_prepare,
  		.cleanup = ad1984_pcm_dmic_cleanup
  	},
  };
  
  static int ad1984_build_pcms(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec = codec->spec;
  	struct hda_pcm *info;
  	int err;
  
  	err = ad198x_build_pcms(codec);
  	if (err < 0)
  		return err;
  
  	info = spec->pcm_rec + codec->num_pcms;
  	codec->num_pcms++;
  	info->name = "AD1984 Digital Mic";
  	info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
  	return 0;
  }
  
  /* models */
  enum {
  	AD1984_BASIC,
  	AD1984_THINKPAD,
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3651
  	AD1984_DELL_DESKTOP,
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3652
3653
  	AD1984_MODELS
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
3654
  static const char * const ad1984_models[AD1984_MODELS] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3655
3656
  	[AD1984_BASIC]		= "basic",
  	[AD1984_THINKPAD]	= "thinkpad",
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3657
  	[AD1984_DELL_DESKTOP]	= "dell_desktop",
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3658
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3659
  static const struct snd_pci_quirk ad1984_cfg_tbl[] = {
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3660
  	/* Lenovo Thinkpad T61/X61 */
dea0a5095   Takashi Iwai   ALSA: hda - Clean...
3661
  	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3662
  	SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
0f9f1ee9d   Luke Yelavich   ALSA: hda - Add D...
3663
  	SND_PCI_QUIRK(0x1028, 0x0233, "Dell Latitude E6400", AD1984_DELL_DESKTOP),
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
  	{}
  };
  
  static int patch_ad1984(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec;
  	int board_config, err;
  
  	err = patch_ad1884(codec);
  	if (err < 0)
  		return err;
  	spec = codec->spec;
  	board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
  						  ad1984_models, ad1984_cfg_tbl);
  	switch (board_config) {
  	case AD1984_BASIC:
  		/* additional digital mics */
  		spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
  		codec->patch_ops.build_pcms = ad1984_build_pcms;
  		break;
  	case AD1984_THINKPAD:
68c186979   Jerone Young   ALSA: hda - Fix T...
3685
3686
3687
3688
3689
3690
  		if (codec->subsystem_id == 0x17aa20fb) {
  			/* Thinpad X300 does not have the ability to do SPDIF,
  			   or attach to docking station to use SPDIF */
  			spec->multiout.dig_out_nid = 0;
  		} else
  			spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3691
3692
3693
  		spec->input_mux = &ad1984_thinkpad_capture_source;
  		spec->mixers[0] = ad1984_thinkpad_mixers;
  		spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
0bf0e5a6f   Jaroslav Kysela   ALSA: hda-intel -...
3694
  		spec->analog_beep = 1;
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3695
  		break;
0aaa22e55   Douglas Kosovic   [ALSA] hda-codec ...
3696
3697
3698
3699
3700
  	case AD1984_DELL_DESKTOP:
  		spec->multiout.dig_out_nid = 0;
  		spec->input_mux = &ad1984_dell_desktop_capture_source;
  		spec->mixers[0] = ad1984_dell_desktop_mixers;
  		break;
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
3701
3702
3703
3704
3705
3706
  	}
  	return 0;
  }
  
  
  /*
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
   * AD1883 / AD1884A / AD1984A / AD1984B
   *
   * port-B (0x14) - front mic-in
   * port-E (0x1c) - rear mic-in
   * port-F (0x16) - CD / ext out
   * port-C (0x15) - rear line-in
   * port-D (0x12) - rear line-out
   * port-A (0x11) - front hp-out
   *
   * AD1984A = AD1884A + digital-mic
   * AD1883 = equivalent with AD1984A
   * AD1984B = AD1984A + extra SPDIF-out
   *
   * FIXME:
   * We share the single DAC for both HP and line-outs (see AD1884/1984).
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3723
  static const hda_nid_t ad1884a_dac_nids[1] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3724
3725
3726
3727
3728
3729
3730
  	0x03,
  };
  
  #define ad1884a_adc_nids	ad1884_adc_nids
  #define ad1884a_capsrc_nids	ad1884_capsrc_nids
  
  #define AD1884A_SPDIF_OUT	0x02
498f5b175   Takashi Iwai   ALSA: hda - Const...
3731
  static const struct hda_input_mux ad1884a_capture_source = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3732
3733
3734
3735
3736
3737
3738
3739
3740
  	.num_items = 5,
  	.items = {
  		{ "Front Mic", 0x0 },
  		{ "Mic", 0x4 },
  		{ "Line", 0x1 },
  		{ "CD", 0x2 },
  		{ "Mix", 0x3 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3741
  static const struct snd_kcontrol_new ad1884a_base_mixers[] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
3758
3759
3760
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		/* The multiple "Capture Source" controls confuse alsamixer
  		 * So call somewhat different..
  		 */
  		/* .name = "Capture Source", */
  		.name = "Input Source",
  		.count = 2,
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	/* SPDIF controls */
  	HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  		/* identical with ad1983 */
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
  	},
  	{ } /* end */
  };
  
  /*
   * initialization verbs
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
3793
  static const struct hda_verb ad1884a_init_verbs[] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
  	/* DACs; unmute as default */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	/* Port-A (HP) mixer - route only from analog mixer */
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-A pin */
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Port-D (Line-out) mixer - route only from analog mixer */
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-D pin */
  	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Mono-out mixer - route only from analog mixer */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Mono-out pin */
  	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Port-B (front mic) pin */
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
60e388e89   Takashi Iwai   ALSA: hda - Fix i...
3817
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3818
3819
  	/* Port-C (rear line-in) pin */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
60e388e89   Takashi Iwai   ALSA: hda - Fix i...
3820
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
  	/* Port-E (rear mic) pin */
  	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
  	/* Port-F (CD) pin */
  	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Analog mixer; mute as default */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* capture sources */
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* SPDIF output amp */
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  	{ } /* end */
  };
  
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
3848
  static const struct hda_amp_list ad1884a_loopbacks[] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
  	{ 0x20, HDA_INPUT, 0 }, /* Front Mic */
  	{ 0x20, HDA_INPUT, 1 }, /* Mic */
  	{ 0x20, HDA_INPUT, 2 }, /* CD */
  	{ 0x20, HDA_INPUT, 4 }, /* Docking */
  	{ } /* end */
  };
  #endif
  
  /*
   * Laptop model
   *
   * Port A: Headphone jack
   * Port B: MIC jack
   * Port C: Internal MIC
   * Port D: Dock Line Out (if enabled)
   * Port E: Dock Line In (if enabled)
   * Port F: Internal speakers
   */
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
  static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_value *ucontrol)
  {
  	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  	int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  	int mute = (!ucontrol->value.integer.value[0] &&
  		    !ucontrol->value.integer.value[1]);
  	/* toggle GPIO1 according to the mute state */
  	snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  			    mute ? 0x02 : 0x0);
  	return ret;
  }
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3879

498f5b175   Takashi Iwai   ALSA: hda - Const...
3880
  static const struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3881
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3882
3883
3884
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Master Playback Switch",
5e26dfd06   Jaroslav Kysela   ALSA: hda - simpl...
3885
  		.subdevice = HDA_SUBDEV_AMP_FLAG,
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3886
3887
3888
3889
3890
  		.info = snd_hda_mixer_amp_switch_info,
  		.get = snd_hda_mixer_amp_switch_get,
  		.put = ad1884a_mobile_master_sw_put,
  		.private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  	},
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3891
3892
3893
3894
3895
3896
3897
3898
3899
  	HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
3900
3901
3902
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3903
3904
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3905
3906
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
3907
  static const struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
3908
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
099db17e6   Takashi Iwai   ALSA: hda - Add G...
3909
3910
3911
3912
  	/*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Master Playback Switch",
5e26dfd06   Jaroslav Kysela   ALSA: hda - simpl...
3913
  		.subdevice = HDA_SUBDEV_AMP_FLAG,
099db17e6   Takashi Iwai   ALSA: hda - Add G...
3914
3915
3916
3917
3918
  		.info = snd_hda_mixer_amp_switch_info,
  		.get = snd_hda_mixer_amp_switch_get,
  		.put = ad1884a_mobile_master_sw_put,
  		.private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  	},
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
3919
3920
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
3921
3922
  	HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
3923
3924
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
3925
3926
  	{ } /* end */
  };
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3927
3928
3929
3930
  /* mute internal speaker if HP is plugged */
  static void ad1884a_hp_automute(struct hda_codec *codec)
  {
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
3931
  	present = snd_hda_jack_detect(codec, 0x11);
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3932
3933
3934
3935
3936
  	snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
  			    present ? 0x00 : 0x02);
  }
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
3937
3938
3939
3940
  /* switch to external mic if plugged */
  static void ad1884a_hp_automic(struct hda_codec *codec)
  {
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
3941
  	present = snd_hda_jack_detect(codec, 0x14);
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
3942
3943
3944
  	snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
  			    present ? 0 : 1);
  }
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3945
  #define AD1884A_HP_EVENT		0x37
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
3946
  #define AD1884A_MIC_EVENT		0x36
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3947
3948
3949
3950
  
  /* unsolicited event for HP jack sensing */
  static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  {
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
3951
3952
3953
3954
3955
3956
3957
3958
  	switch (res >> 26) {
  	case AD1884A_HP_EVENT:
  		ad1884a_hp_automute(codec);
  		break;
  	case AD1884A_MIC_EVENT:
  		ad1884a_hp_automic(codec);
  		break;
  	}
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3959
3960
3961
3962
3963
3964
3965
  }
  
  /* initialize jack-sensing, too */
  static int ad1884a_hp_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1884a_hp_automute(codec);
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
3966
  	ad1884a_hp_automic(codec);
c50592596   Takashi Iwai   [ALSA] hda-codec ...
3967
3968
  	return 0;
  }
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3969
3970
3971
3972
  /* mute internal speaker if HP or docking HP is plugged */
  static void ad1884a_laptop_automute(struct hda_codec *codec)
  {
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
3973
3974
3975
  	present = snd_hda_jack_detect(codec, 0x11);
  	if (!present)
  		present = snd_hda_jack_detect(codec, 0x12);
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
  	snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
  			    present ? 0x00 : 0x02);
  }
  
  /* switch to external mic if plugged */
  static void ad1884a_laptop_automic(struct hda_codec *codec)
  {
  	unsigned int idx;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
3986
  	if (snd_hda_jack_detect(codec, 0x14))
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3987
  		idx = 0;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
3988
  	else if (snd_hda_jack_detect(codec, 0x1c))
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
  		idx = 4;
  	else
  		idx = 1;
  	snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
  }
  
  /* unsolicited event for HP jack sensing */
  static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
  				       unsigned int res)
  {
  	switch (res >> 26) {
  	case AD1884A_HP_EVENT:
  		ad1884a_laptop_automute(codec);
  		break;
  	case AD1884A_MIC_EVENT:
  		ad1884a_laptop_automic(codec);
  		break;
  	}
  }
  
  /* initialize jack-sensing, too */
  static int ad1884a_laptop_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1884a_laptop_automute(codec);
  	ad1884a_laptop_automic(codec);
  	return 0;
  }
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4017
  /* additional verbs for laptop model */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4018
  static const struct hda_verb ad1884a_laptop_verbs[] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4019
4020
4021
4022
4023
  	/* Port-A (HP) pin - always unmuted */
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	/* Port-F (int speaker) mixer - route only from analog mixer */
  	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
150fe14c1   Wu Fengguang   ALSA: hda: enable...
4024
4025
  	/* Port-F (int speaker) pin */
  	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4026
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
150fe14c1   Wu Fengguang   ALSA: hda: enable...
4027
4028
  	/* required for compaq 6530s/6531s speaker output */
  	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
4029
4030
4031
4032
  	/* Port-C pin - internal mic-in */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
2ad81ba01   Takashi Iwai   ALSA: hda - Unmut...
4033
4034
  	/* Port-D (docking line-out) pin - default unmuted */
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4035
4036
4037
4038
  	/* analog mix */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	/* unsolicited event for pin-sense */
  	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
4039
  	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
269ef19ca   Takashi Iwai   [ALSA] hda - Fix ...
4040
  	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
4041
  	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
fe7e56814   Takashi Iwai   ALSA: hda - Add m...
4042
4043
4044
4045
  	/* allow to touch GPIO1 (for mute control) */
  	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  	{0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4046
4047
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4048
  static const struct hda_verb ad1884a_mobile_verbs[] = {
7315613f8   Takashi Iwai   ALSA: hda - Fix i...
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
  	/* DACs; unmute as default */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	/* Port-A (HP) mixer - route only from analog mixer */
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-A pin */
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	/* Port-A (HP) pin - always unmuted */
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	/* Port-B (mic jack) pin */
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  	/* Port-C (int mic) pin */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  	/* Port-F (int speaker) mixer - route only from analog mixer */
  	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-F pin */
  	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Analog mixer; mute as default */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* capture sources */
  	/* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
  	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* unsolicited event for pin-sense */
  	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
099db17e6   Takashi Iwai   ALSA: hda - Add G...
4088
4089
4090
4091
  	/* allow to touch GPIO1 (for mute control) */
  	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  	{0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
7315613f8   Takashi Iwai   ALSA: hda - Fix i...
4092
4093
  	{ } /* end */
  };
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4094
  /*
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4095
4096
4097
4098
4099
4100
   * Thinkpad X300
   * 0x11 - HP
   * 0x12 - speaker
   * 0x14 - mic-in
   * 0x17 - built-in mic
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4101
  static const struct hda_verb ad1984a_thinkpad_verbs[] = {
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
  	/* HP unmute */
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	/* analog mix */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	/* turn on EAPD */
  	{0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  	/* unsolicited event for pin-sense */
  	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  	/* internal mic - dmic */
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
05808ecc4   Takashi Iwai   [ALSA] hda - Fix ...
4112
4113
4114
  	/* set magic COEFs for dmic */
  	{0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  	{0x01, AC_VERB_SET_PROC_COEF, 0x08},
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4115
4116
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4117
  static const struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4118
4119
4120
4121
4122
4123
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
4124
4125
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  	HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Capture Source",
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4137
  static const struct hda_input_mux ad1984a_thinkpad_capture_source = {
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
  	.num_items = 3,
  	.items = {
  		{ "Mic", 0x0 },
  		{ "Internal Mic", 0x5 },
  		{ "Mix", 0x3 },
  	},
  };
  
  /* mute internal speaker if HP is plugged */
  static void ad1984a_thinkpad_automute(struct hda_codec *codec)
  {
  	unsigned int present;
d56757abc   Takashi Iwai   ALSA: hda - Repla...
4150
  	present = snd_hda_jack_detect(codec, 0x11);
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
  	snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  }
  
  /* unsolicited event for HP jack sensing */
  static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
  					 unsigned int res)
  {
  	if ((res >> 26) != AD1884A_HP_EVENT)
  		return;
  	ad1984a_thinkpad_automute(codec);
  }
  
  /* initialize jack-sensing, too */
  static int ad1984a_thinkpad_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1984a_thinkpad_automute(codec);
  	return 0;
  }
  
  /*
677cd904a   David Henningsson   ALSA: HDA: New AD...
4173
4174
4175
4176
4177
   * Precision R5500
   * 0x12 - HP/line-out
   * 0x13 - speaker (mono)
   * 0x15 - mic-in
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4178
  static const struct hda_verb ad1984a_precision_verbs[] = {
677cd904a   David Henningsson   ALSA: HDA: New AD...
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
  	/* Unmute main output path */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x1f}, /* 0dB */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) + 0x17}, /* 0dB */
  	/* Analog mixer; mute as default */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	/* Select mic as input */
  	{0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x27}, /* 0dB */
  	/* Configure as mic */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  	/* HP unmute */
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	/* turn on EAPD */
  	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  	/* unsolicited event for pin-sense */
  	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4203
  static const struct snd_kcontrol_new ad1984a_precision_mixers[] = {
677cd904a   David Henningsson   ALSA: HDA: New AD...
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	{ } /* end */
  };
  
  
  /* mute internal speaker if HP is plugged */
  static void ad1984a_precision_automute(struct hda_codec *codec)
  {
  	unsigned int present;
  
  	present = snd_hda_jack_detect(codec, 0x12);
  	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  				 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  }
  
  
  /* unsolicited event for HP jack sensing */
  static void ad1984a_precision_unsol_event(struct hda_codec *codec,
  					 unsigned int res)
  {
  	if ((res >> 26) != AD1884A_HP_EVENT)
  		return;
  	ad1984a_precision_automute(codec);
  }
  
  /* initialize jack-sensing, too */
  static int ad1984a_precision_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1984a_precision_automute(codec);
  	return 0;
  }
  
  
  /*
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4249
4250
4251
4252
4253
4254
4255
4256
4257
   * HP Touchsmart
   * port-A (0x11)      - front hp-out
   * port-B (0x14)      - unused
   * port-C (0x15)      - unused
   * port-D (0x12)      - rear line out
   * port-E (0x1c)      - front mic-in
   * port-F (0x16)      - Internal speakers
   * digital-mic (0x17) - Internal mic
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4258
  static const struct hda_verb ad1984a_touchsmart_verbs[] = {
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
  	/* DACs; unmute as default */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  	/* Port-A (HP) mixer - route only from analog mixer */
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-A pin */
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	/* Port-A (HP) pin - always unmuted */
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	/* Port-E (int speaker) mixer - route only from analog mixer */
  	{0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
  	/* Port-E pin */
  	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	/* Port-F (int speaker) mixer - route only from analog mixer */
  	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-F pin */
  	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Analog mixer; mute as default */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* capture sources */
  	/* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
  	{0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  	{0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* unsolicited event for pin-sense */
  	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  	/* allow to touch GPIO1 (for mute control) */
  	{0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  	{0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  	{0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  	/* internal mic - dmic */
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  	/* set magic COEFs for dmic */
  	{0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  	{0x01, AC_VERB_SET_PROC_COEF, 0x08},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4309
  static const struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4310
4311
4312
4313
  	HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  /*	HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5e26dfd06   Jaroslav Kysela   ALSA: hda - simpl...
4314
  		.subdevice = HDA_SUBDEV_AMP_FLAG,
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
  		.name = "Master Playback Switch",
  		.info = snd_hda_mixer_amp_switch_info,
  		.get = snd_hda_mixer_amp_switch_get,
  		.put = ad1884a_mobile_master_sw_put,
  		.private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  	},
  	HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
4325
4326
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4327
4328
4329
4330
4331
4332
  	{ } /* end */
  };
  
  /* switch to external mic if plugged */
  static void ad1984a_touchsmart_automic(struct hda_codec *codec)
  {
d56757abc   Takashi Iwai   ALSA: hda - Repla...
4333
  	if (snd_hda_jack_detect(codec, 0x1c))
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4334
4335
  		snd_hda_codec_write(codec, 0x0c, 0,
  				     AC_VERB_SET_CONNECT_SEL, 0x4);
d56757abc   Takashi Iwai   ALSA: hda - Repla...
4336
  	else
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4337
4338
  		snd_hda_codec_write(codec, 0x0c, 0,
  				     AC_VERB_SET_CONNECT_SEL, 0x5);
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
  }
  
  
  /* unsolicited event for HP jack sensing */
  static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
  	unsigned int res)
  {
  	switch (res >> 26) {
  	case AD1884A_HP_EVENT:
  		ad1884a_hp_automute(codec);
  		break;
  	case AD1884A_MIC_EVENT:
  		ad1984a_touchsmart_automic(codec);
  		break;
  	}
  }
  
  /* initialize jack-sensing, too */
  static int ad1984a_touchsmart_init(struct hda_codec *codec)
  {
  	ad198x_init(codec);
  	ad1884a_hp_automute(codec);
  	ad1984a_touchsmart_automic(codec);
  	return 0;
  }
  
  
  /*
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4367
4368
4369
4370
4371
   */
  
  enum {
  	AD1884A_DESKTOP,
  	AD1884A_LAPTOP,
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4372
  	AD1884A_MOBILE,
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4373
  	AD1884A_THINKPAD,
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4374
  	AD1984A_TOUCHSMART,
677cd904a   David Henningsson   ALSA: HDA: New AD...
4375
  	AD1984A_PRECISION,
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4376
4377
  	AD1884A_MODELS
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
4378
  static const char * const ad1884a_models[AD1884A_MODELS] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4379
4380
  	[AD1884A_DESKTOP]	= "desktop",
  	[AD1884A_LAPTOP]	= "laptop",
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4381
  	[AD1884A_MOBILE]	= "mobile",
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4382
  	[AD1884A_THINKPAD]	= "thinkpad",
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4383
  	[AD1984A_TOUCHSMART]	= "touchsmart",
677cd904a   David Henningsson   ALSA: HDA: New AD...
4384
  	[AD1984A_PRECISION]	= "precision",
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4385
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4386
  static const struct snd_pci_quirk ad1884a_cfg_tbl[] = {
677cd904a   David Henningsson   ALSA: HDA: New AD...
4387
  	SND_PCI_QUIRK(0x1028, 0x04ac, "Precision R5500", AD1984A_PRECISION),
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4388
  	SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
d5337deba   Takashi Iwai   ALSA: hda - Add q...
4389
  	SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
5695ff441   Takashi Iwai   ALSA: hda - Add a...
4390
  	SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
c23127566   Takashi Iwai   ALSA: hda - Clean...
4391
  	SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
ff8484717   Takashi Iwai   ALSA: hda - Add q...
4392
  	SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
873dc78a8   Takashi Iwai   ALSA: hda - Clean...
4393
4394
  	SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
  	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
286f5875c   Takashi Iwai   ALSA: hda - Add m...
4395
  	SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4396
  	SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4397
  	SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4398
  	{}
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4399
4400
4401
4402
4403
  };
  
  static int patch_ad1884a(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
4404
  	int err, board_config;
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4405
4406
4407
4408
  
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  	if (spec == NULL)
  		return -ENOMEM;
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4409
  	codec->spec = spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
4410
4411
4412
4413
4414
4415
  	err = snd_hda_attach_beep_device(codec, 0x10);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
  	spec->multiout.max_channels = 2;
  	spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
  	spec->multiout.dac_nids = ad1884a_dac_nids;
  	spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
  	spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
  	spec->adc_nids = ad1884a_adc_nids;
  	spec->capsrc_nids = ad1884a_capsrc_nids;
  	spec->input_mux = &ad1884a_capture_source;
  	spec->num_mixers = 1;
  	spec->mixers[0] = ad1884a_base_mixers;
  	spec->num_init_verbs = 1;
  	spec->init_verbs[0] = ad1884a_init_verbs;
  	spec->spdif_route = 0;
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1884a_loopbacks;
  #endif
  	codec->patch_ops = ad198x_patch_ops;
  
  	/* override some parameters */
  	board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4436
4437
  						  ad1884a_models,
  						  ad1884a_cfg_tbl);
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4438
4439
4440
4441
4442
  	switch (board_config) {
  	case AD1884A_LAPTOP:
  		spec->mixers[0] = ad1884a_laptop_mixers;
  		spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
  		spec->multiout.dig_out_nid = 0;
17bbaa6f6   Takashi Iwai   ALSA: hda - Add s...
4443
4444
  		codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
  		codec->patch_ops.init = ad1884a_laptop_init;
4dc1f87f0   Takashi Iwai   ALSA: hda - Add u...
4445
4446
4447
4448
4449
4450
4451
4452
  		/* set the upper-limit for mixer amp to 0dB for avoiding the
  		 * possible damage by overloading
  		 */
  		snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  					  (1 << AC_AMPCAP_MUTE_SHIFT));
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4453
  		break;
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4454
4455
  	case AD1884A_MOBILE:
  		spec->mixers[0] = ad1884a_mobile_mixers;
7315613f8   Takashi Iwai   ALSA: hda - Fix i...
4456
  		spec->init_verbs[0] = ad1884a_mobile_verbs;
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4457
  		spec->multiout.dig_out_nid = 0;
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4458
4459
  		codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
  		codec->patch_ops.init = ad1884a_hp_init;
13c989beb   Takashi Iwai   ALSA: hda - Don't...
4460
4461
4462
4463
4464
4465
4466
4467
  		/* set the upper-limit for mixer amp to 0dB for avoiding the
  		 * possible damage by overloading
  		 */
  		snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  					  (1 << AC_AMPCAP_MUTE_SHIFT));
b40b04ad3   Takashi Iwai   [ALSA] hda-codec ...
4468
  		break;
f081374b6   Takashi Iwai   [ALSA] hda-codec ...
4469
4470
4471
4472
4473
4474
4475
4476
4477
  	case AD1884A_THINKPAD:
  		spec->mixers[0] = ad1984a_thinkpad_mixers;
  		spec->init_verbs[spec->num_init_verbs++] =
  			ad1984a_thinkpad_verbs;
  		spec->multiout.dig_out_nid = 0;
  		spec->input_mux = &ad1984a_thinkpad_capture_source;
  		codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
  		codec->patch_ops.init = ad1984a_thinkpad_init;
  		break;
677cd904a   David Henningsson   ALSA: HDA: New AD...
4478
4479
4480
4481
4482
4483
4484
4485
  	case AD1984A_PRECISION:
  		spec->mixers[0] = ad1984a_precision_mixers;
  		spec->init_verbs[spec->num_init_verbs++] =
  			ad1984a_precision_verbs;
  		spec->multiout.dig_out_nid = 0;
  		codec->patch_ops.unsol_event = ad1984a_precision_unsol_event;
  		codec->patch_ops.init = ad1984a_precision_init;
  		break;
a72cb4bc8   Miguel de Barros   ALSA: hda - Analo...
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
  	case AD1984A_TOUCHSMART:
  		spec->mixers[0] = ad1984a_touchsmart_mixers;
  		spec->init_verbs[0] = ad1984a_touchsmart_verbs;
  		spec->multiout.dig_out_nid = 0;
  		codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
  		codec->patch_ops.init = ad1984a_touchsmart_init;
  		/* set the upper-limit for mixer amp to 0dB for avoiding the
  		 * possible damage by overloading
  		 */
  		snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  					  (1 << AC_AMPCAP_MUTE_SHIFT));
  		break;
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4501
  	}
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
4502
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
4503
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
4504

c50592596   Takashi Iwai   [ALSA] hda-codec ...
4505
4506
4507
4508
4509
  	return 0;
  }
  
  
  /*
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4510
   * AD1882 / AD1882A
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4511
4512
4513
4514
4515
4516
4517
4518
4519
   *
   * port-A - front hp-out
   * port-B - front mic-in
   * port-C - rear line-in, shared surr-out (3stack)
   * port-D - rear line-out
   * port-E - rear mic-in, shared clfe-out (3stack)
   * port-F - rear surr-out (6stack)
   * port-G - rear clfe-out (6stack)
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4520
  static const hda_nid_t ad1882_dac_nids[3] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4521
4522
  	0x04, 0x03, 0x05
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4523
  static const hda_nid_t ad1882_adc_nids[2] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4524
4525
  	0x08, 0x09,
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4526
  static const hda_nid_t ad1882_capsrc_nids[2] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4527
4528
4529
4530
4531
4532
  	0x0c, 0x0d,
  };
  
  #define AD1882_SPDIF_OUT	0x02
  
  /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4533
  static const struct hda_input_mux ad1882_capture_source = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4534
4535
4536
4537
4538
4539
4540
4541
4542
  	.num_items = 5,
  	.items = {
  		{ "Front Mic", 0x1 },
  		{ "Mic", 0x4 },
  		{ "Line", 0x2 },
  		{ "CD", 0x3 },
  		{ "Mix", 0x7 },
  	},
  };
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4543
  /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4544
  static const struct hda_input_mux ad1882a_capture_source = {
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4545
4546
4547
4548
4549
4550
4551
4552
4553
  	.num_items = 5,
  	.items = {
  		{ "Front Mic", 0x1 },
  		{ "Mic", 0x4},
  		{ "Line", 0x2 },
  		{ "Digital Mic", 0x06 },
  		{ "Mix", 0x7 },
  	},
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4554
  static const struct snd_kcontrol_new ad1882_base_mixers[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4555
4556
4557
4558
4559
4560
4561
4562
  	HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4563

5f99f86a8   David Henningsson   ALSA: HDA: Rename...
4564
4565
4566
  	HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME("Line-In Boost Volume", 0x3a, 0x0, HDA_OUTPUT),
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4567
4568
4569
4570
4571
4572
4573
4574
  	HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		/* The multiple "Capture Source" controls confuse alsamixer
  		 * So call somewhat different..
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
  		 */
  		/* .name = "Capture Source", */
  		.name = "Input Source",
  		.count = 2,
  		.info = ad198x_mux_enum_info,
  		.get = ad198x_mux_enum_get,
  		.put = ad198x_mux_enum_put,
  	},
  	/* SPDIF controls */
  	HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  		/* identical with ad1983 */
  		.info = ad1983_spdif_route_info,
  		.get = ad1983_spdif_route_get,
  		.put = ad1983_spdif_route_put,
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4595
  static const struct snd_kcontrol_new ad1882_loopback_mixers[] = {
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4596
4597
4598
4599
4600
4601
4602
4603
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4604
4605
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4606
  static const struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4607
4608
4609
4610
4611
4612
4613
4614
  	HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  	HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  	HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
  	HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
  	HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
5f99f86a8   David Henningsson   ALSA: HDA: Rename...
4615
  	HDA_CODEC_VOLUME("Digital Mic Boost Volume", 0x1f, 0x0, HDA_INPUT),
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4616
4617
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4618
  static const struct snd_kcontrol_new ad1882_3stack_mixers[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
  	HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name = "Channel Mode",
  		.info = ad198x_ch_mode_info,
  		.get = ad198x_ch_mode_get,
  		.put = ad198x_ch_mode_put,
  	},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4631
  static const struct snd_kcontrol_new ad1882_6stack_mixers[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4632
4633
4634
4635
4636
  	HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
  	HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4637
  static const struct hda_verb ad1882_ch2_init[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4638
4639
4640
4641
4642
4643
4644
4645
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4646
  static const struct hda_verb ad1882_ch4_init[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4647
4648
4649
4650
4651
4652
4653
4654
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4655
  static const struct hda_verb ad1882_ch6_init[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4656
4657
4658
4659
4660
4661
4662
4663
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	{ } /* end */
  };
498f5b175   Takashi Iwai   ALSA: hda - Const...
4664
  static const struct hda_channel_mode ad1882_modes[3] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4665
4666
4667
4668
4669
4670
4671
4672
  	{ 2, ad1882_ch2_init },
  	{ 4, ad1882_ch4_init },
  	{ 6, ad1882_ch6_init },
  };
  
  /*
   * initialization verbs
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4673
  static const struct hda_verb ad1882_init_verbs[] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
  	/* DACs; mute as default */
  	{0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	{0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	{0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  	/* Port-A (HP) mixer */
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-A pin */
  	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* HP selector - select DAC2 */
  	{0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
  	/* Port-D (Line-out) mixer */
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Port-D pin */
  	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Mono-out mixer */
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  	{0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  	/* Mono-out pin */
  	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Port-B (front mic) pin */
  	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  	/* Port-C (line-in) pin */
  	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  	/* Port-C mixer - mute as input */
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	/* Port-E (mic-in) pin */
  	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	{0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  	/* Port-E mixer - mute as input */
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	/* Port-F (surround) */
  	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Port-G (CLFE) */
  	{0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  	{0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  	/* Analog mixer; mute as default */
  	/* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  	{0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  	/* Analog Mix output amp */
  	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  	/* SPDIF output selector */
  	{0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  	{0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  	{ } /* end */
  };
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
4740
  #ifdef CONFIG_SND_HDA_POWER_SAVE
498f5b175   Takashi Iwai   ALSA: hda - Const...
4741
  static const struct hda_amp_list ad1882_loopbacks[] = {
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
4742
4743
4744
4745
4746
4747
4748
  	{ 0x20, HDA_INPUT, 0 }, /* Front Mic */
  	{ 0x20, HDA_INPUT, 1 }, /* Mic */
  	{ 0x20, HDA_INPUT, 4 }, /* Line */
  	{ 0x20, HDA_INPUT, 6 }, /* CD */
  	{ } /* end */
  };
  #endif
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4749
4750
4751
4752
4753
4754
  /* models */
  enum {
  	AD1882_3STACK,
  	AD1882_6STACK,
  	AD1882_MODELS
  };
ea7349632   Takashi Iwai   ALSA: hda - consi...
4755
  static const char * const ad1882_models[AD1986A_MODELS] = {
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4756
4757
4758
4759
4760
4761
4762
4763
  	[AD1882_3STACK]		= "3stack",
  	[AD1882_6STACK]		= "6stack",
  };
  
  
  static int patch_ad1882(struct hda_codec *codec)
  {
  	struct ad198x_spec *spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
4764
  	int err, board_config;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4765
4766
4767
4768
  
  	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  	if (spec == NULL)
  		return -ENOMEM;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4769
  	codec->spec = spec;
c5a4bcd0c   Takashi Iwai   ALSA: hda - Use d...
4770
4771
4772
4773
4774
4775
  	err = snd_hda_attach_beep_device(codec, 0x10);
  	if (err < 0) {
  		ad198x_free(codec);
  		return err;
  	}
  	set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4776
4777
4778
4779
4780
4781
4782
  	spec->multiout.max_channels = 6;
  	spec->multiout.num_dacs = 3;
  	spec->multiout.dac_nids = ad1882_dac_nids;
  	spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
  	spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
  	spec->adc_nids = ad1882_adc_nids;
  	spec->capsrc_nids = ad1882_capsrc_nids;
c247ed6f5   Clemens Fruhwirth   ALSA: hda - Fix t...
4783
  	if (codec->vendor_id == 0x11d41882)
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4784
4785
4786
4787
  		spec->input_mux = &ad1882_capture_source;
  	else
  		spec->input_mux = &ad1882a_capture_source;
  	spec->num_mixers = 2;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4788
  	spec->mixers[0] = ad1882_base_mixers;
c247ed6f5   Clemens Fruhwirth   ALSA: hda - Fix t...
4789
  	if (codec->vendor_id == 0x11d41882)
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4790
4791
4792
  		spec->mixers[1] = ad1882_loopback_mixers;
  	else
  		spec->mixers[1] = ad1882a_loopback_mixers;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4793
4794
4795
  	spec->num_init_verbs = 1;
  	spec->init_verbs[0] = ad1882_init_verbs;
  	spec->spdif_route = 0;
cb53c626e   Takashi Iwai   [ALSA] hda-intel ...
4796
4797
4798
  #ifdef CONFIG_SND_HDA_POWER_SAVE
  	spec->loopback.amplist = ad1882_loopbacks;
  #endif
2134ea4f3   Takashi Iwai   [ALSA] hda-codec ...
4799
  	spec->vmaster_nid = 0x04;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4800
4801
4802
4803
4804
4805
4806
4807
4808
  
  	codec->patch_ops = ad198x_patch_ops;
  
  	/* override some parameters */
  	board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
  						  ad1882_models, NULL);
  	switch (board_config) {
  	default:
  	case AD1882_3STACK:
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4809
4810
  		spec->num_mixers = 3;
  		spec->mixers[2] = ad1882_3stack_mixers;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4811
4812
4813
4814
4815
4816
4817
  		spec->channel_mode = ad1882_modes;
  		spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
  		spec->need_dac_fix = 1;
  		spec->multiout.max_channels = 2;
  		spec->multiout.num_dacs = 1;
  		break;
  	case AD1882_6STACK:
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4818
4819
  		spec->num_mixers = 3;
  		spec->mixers[2] = ad1882_6stack_mixers;
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4820
4821
  		break;
  	}
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
4822
4823
  
  	codec->no_trigger_sense = 1;
0e7adbe26   Takashi Iwai   ALSA: hda - Disab...
4824
  	codec->no_sticky_stream = 1;
729d55ba9   Takashi Iwai   ALSA: hda - Disab...
4825

0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4826
4827
4828
4829
4830
  	return 0;
  }
  
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4831
4832
   * patch entries
   */
498f5b175   Takashi Iwai   ALSA: hda - Const...
4833
  static const struct hda_codec_preset snd_hda_preset_analog[] = {
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4834
  	{ .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
0ac8551ea   Takashi Iwai   [ALSA] hda-codec ...
4835
  	{ .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4836
  	{ .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
4837
  	{ .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
c50592596   Takashi Iwai   [ALSA] hda-codec ...
4838
4839
  	{ .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
  	{ .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
4a3fdf3db   Takashi Iwai   [ALSA] Add AD1981...
4840
4841
  	{ .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  	{ .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
2bac647c4   Takashi Iwai   [ALSA] hda-codec ...
4842
  	{ .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4843
  	{ .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
fd66e0d05   Takashi Iwai   [ALSA] hda-codec ...
4844
  	{ .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
71b2ccc3a   Takashi Iwai   [ALSA] hda-codec ...
4845
  	{ .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
9e44c6e40   Takashi Iwai   ALSA: hda - Add A...
4846
  	{ .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
3adb8abc7   Takashi Iwai   [ALSA] hda - Add ...
4847
4848
  	{ .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
  	{ .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4849
4850
  	{} /* terminator */
  };
1289e9e8b   Takashi Iwai   ALSA: hda - Modul...
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
  
  MODULE_ALIAS("snd-hda-codec-id:11d4*");
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  
  static struct hda_codec_preset_list analog_list = {
  	.preset = snd_hda_preset_analog,
  	.owner = THIS_MODULE,
  };
  
  static int __init patch_analog_init(void)
  {
  	return snd_hda_add_codec_preset(&analog_list);
  }
  
  static void __exit patch_analog_exit(void)
  {
  	snd_hda_delete_codec_preset(&analog_list);
  }
  
  module_init(patch_analog_init)
  module_exit(patch_analog_exit)