xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision b2cb1292b1c7c73abbdc0e07ef3aab056fc2615f)
1c9b443d4STobin Davis /*
2c9b443d4STobin Davis  * HD audio interface patch for Conexant HDA audio codec
3c9b443d4STobin Davis  *
4c9b443d4STobin Davis  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5c9b443d4STobin Davis  * 		      Takashi Iwai <tiwai@suse.de>
6c9b443d4STobin Davis  * 		      Tobin Davis  <tdavis@dsl-only.net>
7c9b443d4STobin Davis  *
8c9b443d4STobin Davis  *  This driver is free software; you can redistribute it and/or modify
9c9b443d4STobin Davis  *  it under the terms of the GNU General Public License as published by
10c9b443d4STobin Davis  *  the Free Software Foundation; either version 2 of the License, or
11c9b443d4STobin Davis  *  (at your option) any later version.
12c9b443d4STobin Davis  *
13c9b443d4STobin Davis  *  This driver is distributed in the hope that it will be useful,
14c9b443d4STobin Davis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9b443d4STobin Davis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9b443d4STobin Davis  *  GNU General Public License for more details.
17c9b443d4STobin Davis  *
18c9b443d4STobin Davis  *  You should have received a copy of the GNU General Public License
19c9b443d4STobin Davis  *  along with this program; if not, write to the Free Software
20c9b443d4STobin Davis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21c9b443d4STobin Davis  */
22c9b443d4STobin Davis 
23c9b443d4STobin Davis #include <linux/init.h>
24c9b443d4STobin Davis #include <linux/delay.h>
25c9b443d4STobin Davis #include <linux/slab.h>
26c9b443d4STobin Davis #include <linux/pci.h>
27c9b443d4STobin Davis #include <sound/core.h>
28bc7a166dSUlrich Dangel #include <sound/jack.h>
29bc7a166dSUlrich Dangel 
30c9b443d4STobin Davis #include "hda_codec.h"
31c9b443d4STobin Davis #include "hda_local.h"
32c0f8faf0SEinar Rünkaru #include "hda_beep.h"
33c9b443d4STobin Davis 
34c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39c9b443d4STobin Davis 
40c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
42c9b443d4STobin Davis 
43bc7a166dSUlrich Dangel /* Conexant 5051 specific */
44c9b443d4STobin Davis 
45ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
48bc7a166dSUlrich Dangel 
49faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
51bc7a166dSUlrich Dangel 
52f2e5731dSTakashi Iwai struct pin_dac_pair {
53f2e5731dSTakashi Iwai 	hda_nid_t pin;
54f2e5731dSTakashi Iwai 	hda_nid_t dac;
55f2e5731dSTakashi Iwai 	int type;
56f2e5731dSTakashi Iwai };
57f2e5731dSTakashi Iwai 
58c9b443d4STobin Davis struct conexant_spec {
59c9b443d4STobin Davis 
60c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
61c9b443d4STobin Davis 	int num_mixers;
62dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
63c9b443d4STobin Davis 
64c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
65c9b443d4STobin Davis 						 * don't forget NULL
66c9b443d4STobin Davis 						 * termination!
67c9b443d4STobin Davis 						 */
68c9b443d4STobin Davis 	unsigned int num_init_verbs;
69c9b443d4STobin Davis 
70c9b443d4STobin Davis 	/* playback */
71c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
72c9b443d4STobin Davis 					 * max_channels, dacs must be set
73c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
74c9b443d4STobin Davis 					 */
75c9b443d4STobin Davis 	unsigned int cur_eapd;
7682f30040STobin Davis 	unsigned int hp_present;
77faddaa5dSTakashi Iwai 	unsigned int auto_mic;
78f2e5731dSTakashi Iwai 	int auto_mic_ext;		/* autocfg.inputs[] index for ext mic */
79c9b443d4STobin Davis 	unsigned int need_dac_fix;
80f6a2491cSAndy Robinson 	hda_nid_t slave_dig_outs[2];
81c9b443d4STobin Davis 
82c9b443d4STobin Davis 	/* capture */
83c9b443d4STobin Davis 	unsigned int num_adc_nids;
84c9b443d4STobin Davis 	hda_nid_t *adc_nids;
85c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
86c9b443d4STobin Davis 
87461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
88461e2c78STakashi Iwai 	hda_nid_t cur_adc;
89461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
90461e2c78STakashi Iwai 	unsigned int cur_adc_format;
91461e2c78STakashi Iwai 
92c9b443d4STobin Davis 	/* capture source */
93c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
94c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
95c9b443d4STobin Davis 	unsigned int cur_mux[3];
96c9b443d4STobin Davis 
97c9b443d4STobin Davis 	/* channel model */
98c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
99c9b443d4STobin Davis 	int num_channel_mode;
100c9b443d4STobin Davis 
101c9b443d4STobin Davis 	/* PCM information */
102c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
103c9b443d4STobin Davis 
104c9b443d4STobin Davis 	unsigned int spdif_route;
105c9b443d4STobin Davis 
106c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
107c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
108c9b443d4STobin Davis 	struct hda_input_mux private_imux;
10941923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
110f2e5731dSTakashi Iwai 	struct pin_dac_pair dac_info[8];
111f2e5731dSTakashi Iwai 	int dac_info_filled;
112c9b443d4STobin Davis 
1130fb67e98SDaniel Drake 	unsigned int port_d_mode;
114f2e5731dSTakashi Iwai 	unsigned int auto_mute:1;	/* used in auto-parser */
115f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
116cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
117cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1187b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
119048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
120a1d6906eSDavid Henningsson 	unsigned int asus:1;
12175f8991dSDaniel Drake 
12275f8991dSDaniel Drake 	unsigned int ext_mic_present;
12375f8991dSDaniel Drake 	unsigned int recording;
12475f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
12575f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
126c4cfe66cSDaniel Drake 
127c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
128c4cfe66cSDaniel Drake 	 * through the microphone jack.
129c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
130c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
131c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
132c4cfe66cSDaniel Drake 	 * control. */
133c4cfe66cSDaniel Drake 	unsigned int dc_enable;
134c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
135c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1363507e2a8STakashi Iwai 
1373507e2a8STakashi Iwai 	unsigned int beep_amp;
138c9b443d4STobin Davis };
139c9b443d4STobin Davis 
140c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
141c9b443d4STobin Davis 				      struct hda_codec *codec,
142c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
143c9b443d4STobin Davis {
144c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1459a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1469a08160bSTakashi Iwai 					     hinfo);
147c9b443d4STobin Davis }
148c9b443d4STobin Davis 
149c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
150c9b443d4STobin Davis 					 struct hda_codec *codec,
151c9b443d4STobin Davis 					 unsigned int stream_tag,
152c9b443d4STobin Davis 					 unsigned int format,
153c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
154c9b443d4STobin Davis {
155c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
156c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
157c9b443d4STobin Davis 						stream_tag,
158c9b443d4STobin Davis 						format, substream);
159c9b443d4STobin Davis }
160c9b443d4STobin Davis 
161c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
162c9b443d4STobin Davis 					 struct hda_codec *codec,
163c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
164c9b443d4STobin Davis {
165c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
166c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
167c9b443d4STobin Davis }
168c9b443d4STobin Davis 
169c9b443d4STobin Davis /*
170c9b443d4STobin Davis  * Digital out
171c9b443d4STobin Davis  */
172c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
173c9b443d4STobin Davis 					  struct hda_codec *codec,
174c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
175c9b443d4STobin Davis {
176c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
177c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
178c9b443d4STobin Davis }
179c9b443d4STobin Davis 
180c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
181c9b443d4STobin Davis 					 struct hda_codec *codec,
182c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
183c9b443d4STobin Davis {
184c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
185c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
186c9b443d4STobin Davis }
187c9b443d4STobin Davis 
1886b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1896b97eb45STakashi Iwai 					 struct hda_codec *codec,
1906b97eb45STakashi Iwai 					 unsigned int stream_tag,
1916b97eb45STakashi Iwai 					 unsigned int format,
1926b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1936b97eb45STakashi Iwai {
1946b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1956b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1966b97eb45STakashi Iwai 					     stream_tag,
1976b97eb45STakashi Iwai 					     format, substream);
1986b97eb45STakashi Iwai }
1996b97eb45STakashi Iwai 
200c9b443d4STobin Davis /*
201c9b443d4STobin Davis  * Analog capture
202c9b443d4STobin Davis  */
203c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
204c9b443d4STobin Davis 				      struct hda_codec *codec,
205c9b443d4STobin Davis 				      unsigned int stream_tag,
206c9b443d4STobin Davis 				      unsigned int format,
207c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
208c9b443d4STobin Davis {
209c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
21075f8991dSDaniel Drake 	if (spec->capture_prepare)
21175f8991dSDaniel Drake 		spec->capture_prepare(codec);
212c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
213c9b443d4STobin Davis 				   stream_tag, 0, format);
214c9b443d4STobin Davis 	return 0;
215c9b443d4STobin Davis }
216c9b443d4STobin Davis 
217c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
218c9b443d4STobin Davis 				      struct hda_codec *codec,
219c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
220c9b443d4STobin Davis {
221c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
222888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
22375f8991dSDaniel Drake 	if (spec->capture_cleanup)
22475f8991dSDaniel Drake 		spec->capture_cleanup(codec);
225c9b443d4STobin Davis 	return 0;
226c9b443d4STobin Davis }
227c9b443d4STobin Davis 
228c9b443d4STobin Davis 
229c9b443d4STobin Davis 
230c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
231c9b443d4STobin Davis 	.substreams = 1,
232c9b443d4STobin Davis 	.channels_min = 2,
233c9b443d4STobin Davis 	.channels_max = 2,
234c9b443d4STobin Davis 	.nid = 0, /* fill later */
235c9b443d4STobin Davis 	.ops = {
236c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
237c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
238c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
239c9b443d4STobin Davis 	},
240c9b443d4STobin Davis };
241c9b443d4STobin Davis 
242c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
243c9b443d4STobin Davis 	.substreams = 1,
244c9b443d4STobin Davis 	.channels_min = 2,
245c9b443d4STobin Davis 	.channels_max = 2,
246c9b443d4STobin Davis 	.nid = 0, /* fill later */
247c9b443d4STobin Davis 	.ops = {
248c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
249c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
250c9b443d4STobin Davis 	},
251c9b443d4STobin Davis };
252c9b443d4STobin Davis 
253c9b443d4STobin Davis 
254c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
255c9b443d4STobin Davis 	.substreams = 1,
256c9b443d4STobin Davis 	.channels_min = 2,
257c9b443d4STobin Davis 	.channels_max = 2,
258c9b443d4STobin Davis 	.nid = 0, /* fill later */
259c9b443d4STobin Davis 	.ops = {
260c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2616b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2626b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
263c9b443d4STobin Davis 	},
264c9b443d4STobin Davis };
265c9b443d4STobin Davis 
266c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
267c9b443d4STobin Davis 	.substreams = 1,
268c9b443d4STobin Davis 	.channels_min = 2,
269c9b443d4STobin Davis 	.channels_max = 2,
270c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
271c9b443d4STobin Davis };
272c9b443d4STobin Davis 
273461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
274461e2c78STakashi Iwai 				      struct hda_codec *codec,
275461e2c78STakashi Iwai 				      unsigned int stream_tag,
276461e2c78STakashi Iwai 				      unsigned int format,
277461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
278461e2c78STakashi Iwai {
279461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
280461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
281461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
282461e2c78STakashi Iwai 	spec->cur_adc_format = format;
283461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
284461e2c78STakashi Iwai 	return 0;
285461e2c78STakashi Iwai }
286461e2c78STakashi Iwai 
287461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
288461e2c78STakashi Iwai 				      struct hda_codec *codec,
289461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
290461e2c78STakashi Iwai {
291461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
292888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
293461e2c78STakashi Iwai 	spec->cur_adc = 0;
294461e2c78STakashi Iwai 	return 0;
295461e2c78STakashi Iwai }
296461e2c78STakashi Iwai 
297461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
298461e2c78STakashi Iwai 	.substreams = 1,
299461e2c78STakashi Iwai 	.channels_min = 2,
300461e2c78STakashi Iwai 	.channels_max = 2,
301461e2c78STakashi Iwai 	.nid = 0, /* fill later */
302461e2c78STakashi Iwai 	.ops = {
303461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
304461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
305461e2c78STakashi Iwai 	},
306461e2c78STakashi Iwai };
307461e2c78STakashi Iwai 
308c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
309c9b443d4STobin Davis {
310c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
311c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
312c9b443d4STobin Davis 
313c9b443d4STobin Davis 	codec->num_pcms = 1;
314c9b443d4STobin Davis 	codec->pcm_info = info;
315c9b443d4STobin Davis 
316c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
317c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
318c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
319c9b443d4STobin Davis 		spec->multiout.max_channels;
320c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
321c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
322461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
323461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
324461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
325461e2c78STakashi Iwai 	else
326461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
327461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
328c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
329c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
330c9b443d4STobin Davis 
331c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
332c9b443d4STobin Davis 		info++;
333c9b443d4STobin Davis 		codec->num_pcms++;
334c9b443d4STobin Davis 		info->name = "Conexant Digital";
3357ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
336c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
337c9b443d4STobin Davis 			conexant_pcm_digital_playback;
338c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
339c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
340c9b443d4STobin Davis 		if (spec->dig_in_nid) {
341c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
342c9b443d4STobin Davis 				conexant_pcm_digital_capture;
343c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
344c9b443d4STobin Davis 				spec->dig_in_nid;
345c9b443d4STobin Davis 		}
346f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
347f6a2491cSAndy Robinson 			codec->slave_dig_outs = spec->slave_dig_outs;
348c9b443d4STobin Davis 	}
349c9b443d4STobin Davis 
350c9b443d4STobin Davis 	return 0;
351c9b443d4STobin Davis }
352c9b443d4STobin Davis 
353c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
354c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
355c9b443d4STobin Davis {
356c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
358c9b443d4STobin Davis 
359c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
360c9b443d4STobin Davis }
361c9b443d4STobin Davis 
362c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
363c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
364c9b443d4STobin Davis {
365c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
367c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
368c9b443d4STobin Davis 
369c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
370c9b443d4STobin Davis 	return 0;
371c9b443d4STobin Davis }
372c9b443d4STobin Davis 
373c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
374c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
375c9b443d4STobin Davis {
376c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
378c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379c9b443d4STobin Davis 
380c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
381c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
382c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
383c9b443d4STobin Davis }
384c9b443d4STobin Davis 
385bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
386bc7a166dSUlrich Dangel {
387cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
388bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
389bc7a166dSUlrich Dangel 	int i;
390bc7a166dSUlrich Dangel 
391bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
392bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
393bc7a166dSUlrich Dangel 
394bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
395bc7a166dSUlrich Dangel 		while (hv->nid) {
396bc7a166dSUlrich Dangel 			int err = 0;
397bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
398bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
399cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
400cd372fb3STakashi Iwai 						SND_JACK_HEADPHONE, NULL);
401cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
402bc7a166dSUlrich Dangel 				break;
403bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
404bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
405cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
406cd372fb3STakashi Iwai 						SND_JACK_MICROPHONE, NULL);
407cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
408bc7a166dSUlrich Dangel 				break;
409bc7a166dSUlrich Dangel 			}
410bc7a166dSUlrich Dangel 			if (err < 0)
411bc7a166dSUlrich Dangel 				return err;
412bc7a166dSUlrich Dangel 			++hv;
413bc7a166dSUlrich Dangel 		}
414bc7a166dSUlrich Dangel 	}
415cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */
4165801f992STakashi Iwai 	return 0;
4175801f992STakashi Iwai }
418bc7a166dSUlrich Dangel 
419c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
420c9b443d4STobin Davis {
421c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
422c9b443d4STobin Davis 	int i;
423c9b443d4STobin Davis 
424c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
425c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
426c9b443d4STobin Davis 	return 0;
427c9b443d4STobin Davis }
428c9b443d4STobin Davis 
429c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
430c9b443d4STobin Davis {
431cd372fb3STakashi Iwai 	snd_hda_input_jack_free(codec);
432c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
433c9b443d4STobin Davis 	kfree(codec->spec);
434c9b443d4STobin Davis }
435c9b443d4STobin Davis 
436b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
437b880c74aSTakashi Iwai 	{
438b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
439b880c74aSTakashi Iwai 		.name = "Capture Source",
440b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
441b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
442b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
443b880c74aSTakashi Iwai 	},
444b880c74aSTakashi Iwai 	{}
445b880c74aSTakashi Iwai };
446b880c74aSTakashi Iwai 
4473507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
4483507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
4493507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = {
4503507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
4513507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
4523507e2a8STakashi Iwai 	{ } /* end */
4533507e2a8STakashi Iwai };
4543507e2a8STakashi Iwai #endif
4553507e2a8STakashi Iwai 
456ea734963STakashi Iwai static const char * const slave_vols[] = {
457dd5746a8STakashi Iwai 	"Headphone Playback Volume",
458dd5746a8STakashi Iwai 	"Speaker Playback Volume",
459dd5746a8STakashi Iwai 	NULL
460dd5746a8STakashi Iwai };
461dd5746a8STakashi Iwai 
462ea734963STakashi Iwai static const char * const slave_sws[] = {
463dd5746a8STakashi Iwai 	"Headphone Playback Switch",
464dd5746a8STakashi Iwai 	"Speaker Playback Switch",
465dd5746a8STakashi Iwai 	NULL
466dd5746a8STakashi Iwai };
467dd5746a8STakashi Iwai 
468c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
469c9b443d4STobin Davis {
470c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
471c9b443d4STobin Davis 	unsigned int i;
472c9b443d4STobin Davis 	int err;
473c9b443d4STobin Davis 
474c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
475c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
476c9b443d4STobin Davis 		if (err < 0)
477c9b443d4STobin Davis 			return err;
478c9b443d4STobin Davis 	}
479c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
480c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
481c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
482c9b443d4STobin Davis 		if (err < 0)
483c9b443d4STobin Davis 			return err;
4849a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
4859a08160bSTakashi Iwai 						    &spec->multiout);
4869a08160bSTakashi Iwai 		if (err < 0)
4879a08160bSTakashi Iwai 			return err;
4889a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
489c9b443d4STobin Davis 	}
490c9b443d4STobin Davis 	if (spec->dig_in_nid) {
491c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
492c9b443d4STobin Davis 		if (err < 0)
493c9b443d4STobin Davis 			return err;
494c9b443d4STobin Davis 	}
495dd5746a8STakashi Iwai 
496dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
497dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
498dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
499dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
500dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
501dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
502dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
503dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
504dd5746a8STakashi Iwai 		if (err < 0)
505dd5746a8STakashi Iwai 			return err;
506dd5746a8STakashi Iwai 	}
507dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
508dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
509dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
510dd5746a8STakashi Iwai 					  NULL, slave_sws);
511dd5746a8STakashi Iwai 		if (err < 0)
512dd5746a8STakashi Iwai 			return err;
513dd5746a8STakashi Iwai 	}
514dd5746a8STakashi Iwai 
515b880c74aSTakashi Iwai 	if (spec->input_mux) {
516b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
517b880c74aSTakashi Iwai 		if (err < 0)
518b880c74aSTakashi Iwai 			return err;
519b880c74aSTakashi Iwai 	}
520b880c74aSTakashi Iwai 
5213507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5223507e2a8STakashi Iwai 	/* create beep controls if needed */
5233507e2a8STakashi Iwai 	if (spec->beep_amp) {
5243507e2a8STakashi Iwai 		struct snd_kcontrol_new *knew;
5253507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
5263507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
5273507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
5283507e2a8STakashi Iwai 			if (!kctl)
5293507e2a8STakashi Iwai 				return -ENOMEM;
5303507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
5313507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
5323507e2a8STakashi Iwai 			if (err < 0)
5333507e2a8STakashi Iwai 				return err;
5343507e2a8STakashi Iwai 		}
5353507e2a8STakashi Iwai 	}
5363507e2a8STakashi Iwai #endif
5373507e2a8STakashi Iwai 
538c9b443d4STobin Davis 	return 0;
539c9b443d4STobin Davis }
540c9b443d4STobin Davis 
541697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
542697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
543697c373eSTakashi Iwai {
544697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
545697c373eSTakashi Iwai 	return 0;
546697c373eSTakashi Iwai }
547697c373eSTakashi Iwai #endif
548697c373eSTakashi Iwai 
549c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
550c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
551c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
552c9b443d4STobin Davis 	.init = conexant_init,
553c9b443d4STobin Davis 	.free = conexant_free,
554697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
555697c373eSTakashi Iwai 	.suspend = conexant_suspend,
556697c373eSTakashi Iwai #endif
557697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
558c9b443d4STobin Davis };
559c9b443d4STobin Davis 
5603507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5613507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
5623507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
5633507e2a8STakashi Iwai #else
5643507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5653507e2a8STakashi Iwai #endif
5663507e2a8STakashi Iwai 
567c9b443d4STobin Davis /*
568c9b443d4STobin Davis  * EAPD control
569c9b443d4STobin Davis  * the private value = nid | (invert << 8)
570c9b443d4STobin Davis  */
571c9b443d4STobin Davis 
572a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
573c9b443d4STobin Davis 
57482f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
575c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
576c9b443d4STobin Davis {
577c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
578c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
579c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
580c9b443d4STobin Davis 	if (invert)
581c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
582c9b443d4STobin Davis 	else
583c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
584c9b443d4STobin Davis 	return 0;
58582f30040STobin Davis 
586c9b443d4STobin Davis }
587c9b443d4STobin Davis 
58882f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
589c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
590c9b443d4STobin Davis {
591c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
592c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
593c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
594c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
595c9b443d4STobin Davis 	unsigned int eapd;
59682f30040STobin Davis 
59768ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
598c9b443d4STobin Davis 	if (invert)
599c9b443d4STobin Davis 		eapd = !eapd;
60082beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
601c9b443d4STobin Davis 		return 0;
60282f30040STobin Davis 
603c9b443d4STobin Davis 	spec->cur_eapd = eapd;
60482beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
605c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
606c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
607c9b443d4STobin Davis 	return 1;
608c9b443d4STobin Davis }
609c9b443d4STobin Davis 
61086d72bdfSTakashi Iwai /* controls for test mode */
61186d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
61286d72bdfSTakashi Iwai 
61382f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
61482f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
61582f30040STobin Davis 	  .info = cxt_eapd_info, \
61682f30040STobin Davis 	  .get = cxt_eapd_get, \
61782f30040STobin Davis 	  .put = cxt_eapd_put, \
61882f30040STobin Davis 	  .private_value = nid | (mask<<16) }
61982f30040STobin Davis 
62082f30040STobin Davis 
62182f30040STobin Davis 
622c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
623c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
624c9b443d4STobin Davis {
625c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
627c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
628c9b443d4STobin Davis 				    spec->num_channel_mode);
629c9b443d4STobin Davis }
630c9b443d4STobin Davis 
631c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
632c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
633c9b443d4STobin Davis {
634c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
636c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
637c9b443d4STobin Davis 				   spec->num_channel_mode,
638c9b443d4STobin Davis 				   spec->multiout.max_channels);
639c9b443d4STobin Davis }
640c9b443d4STobin Davis 
641c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
642c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
643c9b443d4STobin Davis {
644c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
646c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
647c9b443d4STobin Davis 				      spec->num_channel_mode,
648c9b443d4STobin Davis 				      &spec->multiout.max_channels);
649c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
650c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
651c9b443d4STobin Davis 	return err;
652c9b443d4STobin Davis }
653c9b443d4STobin Davis 
654c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
655c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
656c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
657c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
658c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
659c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
660c9b443d4STobin Davis 
66186d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
66286d72bdfSTakashi Iwai 
663c9b443d4STobin Davis /* Conexant 5045 specific */
664c9b443d4STobin Davis 
665c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
666c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
667c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
668cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
669c9b443d4STobin Davis 
6705cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
6715cd57529STobin Davis 	{ 2, NULL },
6725cd57529STobin Davis };
673c9b443d4STobin Davis 
674c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
675c9b443d4STobin Davis 	.num_items = 2,
676c9b443d4STobin Davis 	.items = {
67782f30040STobin Davis 		{ "IntMic", 0x1 },
678f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
679c9b443d4STobin Davis 	}
680c9b443d4STobin Davis };
681c9b443d4STobin Davis 
6825218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
68322e14130SLukasz Marcinowski 	.num_items = 5,
6845218c892SJiang Zhe 	.items = {
6855218c892SJiang Zhe 		{ "IntMic", 0x1 },
6865218c892SJiang Zhe 		{ "ExtMic", 0x2 },
6875218c892SJiang Zhe 		{ "LineIn", 0x3 },
68822e14130SLukasz Marcinowski 		{ "CD",     0x4 },
68922e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
6905218c892SJiang Zhe 	}
6915218c892SJiang Zhe };
6925218c892SJiang Zhe 
6932de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
6942de3c232SJiang zhe 	.num_items = 2,
6952de3c232SJiang zhe 	.items = {
6962de3c232SJiang zhe 		{ "ExtMic", 0x1 },
6972de3c232SJiang zhe 		{ "IntMic", 0x2 },
6982de3c232SJiang zhe 	}
6992de3c232SJiang zhe };
7002de3c232SJiang zhe 
701c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
702c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
703c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
704c9b443d4STobin Davis {
705c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
706c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
70782f30040STobin Davis 	unsigned int bits;
708c9b443d4STobin Davis 
70982f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
710c9b443d4STobin Davis 		return 0;
711c9b443d4STobin Davis 
71282f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
71382f30040STobin Davis 	 * the headphone jack
71482f30040STobin Davis 	 */
71547fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
71647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
71747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7187f29673bSTobin Davis 
71947fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
72047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
72147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
722c9b443d4STobin Davis 	return 1;
723c9b443d4STobin Davis }
724c9b443d4STobin Davis 
725c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
726cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
727cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
728cca3b371STakashi Iwai 	.values = {
729cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
730cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
731cca3b371STakashi Iwai 		0
732cca3b371STakashi Iwai 	},
733cca3b371STakashi Iwai };
734c9b443d4STobin Davis 
7357f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7367f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7377f29673bSTobin Davis {
7387f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
7397f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7407f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7417f29673bSTobin Davis 		{}
7427f29673bSTobin Davis 	};
7437f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
7447f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7457f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7467f29673bSTobin Davis 		{}
7477f29673bSTobin Davis 	};
7487f29673bSTobin Davis 	unsigned int present;
7497f29673bSTobin Davis 
750d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7517f29673bSTobin Davis 	if (present)
7527f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7537f29673bSTobin Davis 	else
7547f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7557f29673bSTobin Davis }
7567f29673bSTobin Davis 
757c9b443d4STobin Davis 
758c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
759c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
760c9b443d4STobin Davis {
76182f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
762dd87da1cSTobin Davis 	unsigned int bits;
763c9b443d4STobin Davis 
764d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
765dd87da1cSTobin Davis 
76647fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
76747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
76847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
769c9b443d4STobin Davis }
770c9b443d4STobin Davis 
771c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
772c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
773c9b443d4STobin Davis 				   unsigned int res)
774c9b443d4STobin Davis {
775c9b443d4STobin Davis 	res >>= 26;
776c9b443d4STobin Davis 	switch (res) {
777c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
778c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
779c9b443d4STobin Davis 		break;
7807f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
7817f29673bSTobin Davis 		cxt5045_hp_automic(codec);
7827f29673bSTobin Davis 		break;
7837f29673bSTobin Davis 
784c9b443d4STobin Davis 	}
785c9b443d4STobin Davis }
786c9b443d4STobin Davis 
787c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
78828c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
78928c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
7908607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
7918607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
792c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
793c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
79428c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
79528c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
7968607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
7978607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
798cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
799c9b443d4STobin Davis 	{
800c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
801c9b443d4STobin Davis 		.name = "Master Playback Switch",
80282f30040STobin Davis 		.info = cxt_eapd_info,
80382f30040STobin Davis 		.get = cxt_eapd_get,
804c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
80582f30040STobin Davis 		.private_value = 0x10,
806c9b443d4STobin Davis 	},
807c9b443d4STobin Davis 
808c9b443d4STobin Davis 	{}
809c9b443d4STobin Davis };
810c9b443d4STobin Davis 
8115218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
81222e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
81322e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
81422e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
81522e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
81622e14130SLukasz Marcinowski 
8175218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8185218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8195218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8205218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8215218c892SJiang Zhe 
82222e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
82322e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
82422e14130SLukasz Marcinowski 
8255218c892SJiang Zhe 	{}
8265218c892SJiang Zhe };
8275218c892SJiang Zhe 
8282de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
82928c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
83028c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8318607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8328607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8332de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8342de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
83528c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
83628c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8378607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8388607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8392de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8402de3c232SJiang zhe 	{
8412de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8422de3c232SJiang zhe 		.name = "Master Playback Switch",
8432de3c232SJiang zhe 		.info = cxt_eapd_info,
8442de3c232SJiang zhe 		.get = cxt_eapd_get,
8452de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8462de3c232SJiang zhe 		.private_value = 0x10,
8472de3c232SJiang zhe 	},
8482de3c232SJiang zhe 
8492de3c232SJiang zhe 	{}
8502de3c232SJiang zhe };
8512de3c232SJiang zhe 
852c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
853c9b443d4STobin Davis 	/* Line in, Mic */
8544090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8557f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
856c9b443d4STobin Davis 	/* HP, Amp  */
857c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
858c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
85982f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
860c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
861c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
862c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
863c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
864c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
865c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
86628c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
8677f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
86882f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
869c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
870c9b443d4STobin Davis 	/* SPDIF route: PCM */
871cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
872c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
873c9b443d4STobin Davis 	/* EAPD */
87482f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
875c9b443d4STobin Davis 	{ } /* end */
876c9b443d4STobin Davis };
877c9b443d4STobin Davis 
8785218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
87928c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
8805218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8815218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8825218c892SJiang Zhe 	/* Line In,HP, Amp  */
8835218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8845218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
8855218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8865218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
8875218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8885218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8895218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8905218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8915218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
89228c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
8935218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
8945218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
8955218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
8965218c892SJiang Zhe 	/* SPDIF route: PCM */
897cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8985218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
8995218c892SJiang Zhe 	/* EAPD */
9005218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9015218c892SJiang Zhe 	{ } /* end */
9025218c892SJiang Zhe };
9037f29673bSTobin Davis 
9047f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9057f29673bSTobin Davis 	/* pin sensing on HP jack */
9067f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
907d3091fadSTakashi Iwai 	{ } /* end */
9087f29673bSTobin Davis };
9097f29673bSTobin Davis 
9107f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9117f29673bSTobin Davis 	/* pin sensing on HP jack */
9127f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
913d3091fadSTakashi Iwai 	{ } /* end */
9147f29673bSTobin Davis };
9157f29673bSTobin Davis 
916c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
917c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
918c9b443d4STobin Davis  * configuration.
919c9b443d4STobin Davis  */
920c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
921c9b443d4STobin Davis 	.num_items = 5,
922c9b443d4STobin Davis 	.items = {
923c9b443d4STobin Davis 		{ "MIXER", 0x0 },
924c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
925c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
926c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
927c9b443d4STobin Davis 		{ "CD pin", 0x4 },
928c9b443d4STobin Davis         },
929c9b443d4STobin Davis };
930c9b443d4STobin Davis 
931c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
932c9b443d4STobin Davis 
933c9b443d4STobin Davis 	/* Output controls */
934c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
935c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9367f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9377f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9387f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9397f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
940c9b443d4STobin Davis 
941c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
942c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
943c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
944c9b443d4STobin Davis 
94582f30040STobin Davis 	/* EAPD Switch Control */
94682f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
94782f30040STobin Davis 
948c9b443d4STobin Davis 	/* Loopback mixer controls */
949c9b443d4STobin Davis 
9507f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9517f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9527f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9537f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9547f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9557f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9567f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9577f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9587f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9597f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
960c9b443d4STobin Davis 	{
961c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
962c9b443d4STobin Davis 		.name = "Input Source",
963c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
964c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
965c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
966c9b443d4STobin Davis 	},
967fb3409e7STobin Davis 	/* Audio input controls */
968fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
969fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
970fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
971fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
972fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
973fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
974fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
975fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
976fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
977fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
978c9b443d4STobin Davis 	{ } /* end */
979c9b443d4STobin Davis };
980c9b443d4STobin Davis 
981c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
9827f29673bSTobin Davis 	/* Set connections */
9837f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9847f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
9857f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
986c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
987c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9887f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
989c9b443d4STobin Davis 
990c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
991c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
992c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
993c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
994c9b443d4STobin Davis 	 * control.
995c9b443d4STobin Davis 	 */
996cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
997cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
998c9b443d4STobin Davis 
999c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1000c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1001c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1002c9b443d4STobin Davis 
1003c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1004c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1005c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1006c9b443d4STobin Davis 	 * input/output buffers as needed.
1007c9b443d4STobin Davis 	 */
1008c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1009c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1010c9b443d4STobin Davis 
1011c9b443d4STobin Davis 	/* Mute capture amp left and right */
1012c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1013c9b443d4STobin Davis 
1014c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1015c9b443d4STobin Davis 	 * pin)
1016c9b443d4STobin Davis 	 */
1017c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10187f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1019c9b443d4STobin Davis 
1020c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1021c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1022c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1023c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1024c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1025c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1026c9b443d4STobin Davis 
1027c9b443d4STobin Davis 	{ }
1028c9b443d4STobin Davis };
1029c9b443d4STobin Davis #endif
1030c9b443d4STobin Davis 
1031c9b443d4STobin Davis 
1032c9b443d4STobin Davis /* initialize jack-sensing, too */
1033c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1034c9b443d4STobin Davis {
1035c9b443d4STobin Davis 	conexant_init(codec);
1036c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1037c9b443d4STobin Davis 	return 0;
1038c9b443d4STobin Davis }
1039c9b443d4STobin Davis 
1040c9b443d4STobin Davis 
1041c9b443d4STobin Davis enum {
104215908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
104315908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
104415908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10455218c892SJiang Zhe 	CXT5045_BENQ,
10462de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1047c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1048c9b443d4STobin Davis 	CXT5045_TEST,
1049c9b443d4STobin Davis #endif
1050f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1051c9b443d4STobin Davis };
1052c9b443d4STobin Davis 
1053ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
105415908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
105515908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
105615908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10575218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10582de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1059c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1060f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1061c9b443d4STobin Davis #endif
1062f5fcc13cSTakashi Iwai };
1063c9b443d4STobin Davis 
1064f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10652de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1066dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1067dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
10686a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10695218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
107015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
107115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10729e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10739e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
107415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
107515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
107615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1077dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1078dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
107915908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1080c9b443d4STobin Davis 	{}
1081c9b443d4STobin Davis };
1082c9b443d4STobin Davis 
1083c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1084c9b443d4STobin Davis {
1085c9b443d4STobin Davis 	struct conexant_spec *spec;
1086c9b443d4STobin Davis 	int board_config;
1087c9b443d4STobin Davis 
1088c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1089c9b443d4STobin Davis 	if (!spec)
1090c9b443d4STobin Davis 		return -ENOMEM;
1091c9b443d4STobin Davis 	codec->spec = spec;
10929421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1093c9b443d4STobin Davis 
1094c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1095c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1096c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1097c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1098c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1099c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1100c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1101c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1102c9b443d4STobin Davis 	spec->num_mixers = 1;
1103c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1104c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1105c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1106c9b443d4STobin Davis 	spec->spdif_route = 0;
11073507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11083507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11095cd57529STobin Davis 
11103507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1111c9b443d4STobin Davis 
1112c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1113c9b443d4STobin Davis 
1114f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1115f5fcc13cSTakashi Iwai 						  cxt5045_models,
1116f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1117c9b443d4STobin Davis 	switch (board_config) {
111815908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11197f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1120c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1121c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11227f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11237f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11247f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11257f29673bSTobin Davis 		break;
112615908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
112786376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11287f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11297f29673bSTobin Davis 		spec->num_init_verbs = 2;
11307f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1131c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1132c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1133c9b443d4STobin Davis 		break;
113415908c36SMarc Boucher 	default:
113515908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
113615908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
113715908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
113815908c36SMarc Boucher 		spec->num_init_verbs = 3;
113915908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
114015908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
114115908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
114215908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
114315908c36SMarc Boucher 		break;
11445218c892SJiang Zhe 	case CXT5045_BENQ:
11455218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11465218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11475218c892SJiang Zhe 		spec->num_init_verbs = 1;
11485218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11495218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11505218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11515218c892SJiang Zhe 		spec->num_mixers = 2;
11525218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11535218c892SJiang Zhe 		break;
11542de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11552de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11562de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11572de3c232SJiang zhe 		spec->num_init_verbs = 2;
11582de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11592de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11602de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11612de3c232SJiang zhe 		break;
1162c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1163c9b443d4STobin Davis 	case CXT5045_TEST:
1164c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1165c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1166c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
116715908c36SMarc Boucher 		break;
116815908c36SMarc Boucher 
1169c9b443d4STobin Davis #endif
1170c9b443d4STobin Davis 	}
117148ecb7e8STakashi Iwai 
1172031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1173031005f7STakashi Iwai 	case 0x103c:
11748f0f5ff6SDaniel T Chen 	case 0x1631:
11750b587fc4SDaniel T Chen 	case 0x1734:
11760ebf9e36SDaniel T Chen 	case 0x17aa:
11770ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
11780ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
11790ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
118048ecb7e8STakashi Iwai 		 */
118148ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
118248ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
118348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
118448ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
118548ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1186031005f7STakashi Iwai 		break;
1187031005f7STakashi Iwai 	}
118848ecb7e8STakashi Iwai 
11893507e2a8STakashi Iwai 	if (spec->beep_amp)
11903507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
11913507e2a8STakashi Iwai 
1192c9b443d4STobin Davis 	return 0;
1193c9b443d4STobin Davis }
1194c9b443d4STobin Davis 
1195c9b443d4STobin Davis 
1196c9b443d4STobin Davis /* Conexant 5047 specific */
119782f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1198c9b443d4STobin Davis 
11995b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1200c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1201c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1202c9b443d4STobin Davis 
12035cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12045cd57529STobin Davis 	{ 2, NULL },
12055cd57529STobin Davis };
1206c9b443d4STobin Davis 
120782f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
120882f30040STobin Davis 	.num_items = 2,
120982f30040STobin Davis 	.items = {
121082f30040STobin Davis 		{ "ExtMic", 0x2 },
121182f30040STobin Davis 		{ "Line-In", 0x1 },
1212c9b443d4STobin Davis 	}
1213c9b443d4STobin Davis };
1214c9b443d4STobin Davis 
1215c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1216c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1217c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1218c9b443d4STobin Davis {
1219c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1220c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
122182f30040STobin Davis 	unsigned int bits;
1222c9b443d4STobin Davis 
122382f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1224c9b443d4STobin Davis 		return 0;
1225c9b443d4STobin Davis 
122682f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
122782f30040STobin Davis 	 * the headphone jack
122882f30040STobin Davis 	 */
122947fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12303b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12313b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12323b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12333b7523fcSTakashi Iwai 	 */
12345d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
123547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
123647fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
123747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
123847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1239c9b443d4STobin Davis 	return 1;
1240c9b443d4STobin Davis }
1241c9b443d4STobin Davis 
1242c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1243c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1244c9b443d4STobin Davis {
124582f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1246dd87da1cSTobin Davis 	unsigned int bits;
1247c9b443d4STobin Davis 
1248d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1249dd87da1cSTobin Davis 
125047fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12513b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12525d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
125347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1254c9b443d4STobin Davis }
1255c9b443d4STobin Davis 
1256c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1257c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1258c9b443d4STobin Davis {
1259c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
12609f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12619f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1262c9b443d4STobin Davis 		{}
1263c9b443d4STobin Davis 	};
1264c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
12659f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12669f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1267c9b443d4STobin Davis 		{}
1268c9b443d4STobin Davis 	};
1269c9b443d4STobin Davis 	unsigned int present;
1270c9b443d4STobin Davis 
1271d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1272c9b443d4STobin Davis 	if (present)
1273c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1274c9b443d4STobin Davis 	else
1275c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1276c9b443d4STobin Davis }
1277c9b443d4STobin Davis 
1278c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1279c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1280c9b443d4STobin Davis 				  unsigned int res)
1281c9b443d4STobin Davis {
12829f113e0eSMarc Boucher 	switch (res >> 26) {
1283c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1284c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1285c9b443d4STobin Davis 		break;
1286c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1287c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1288c9b443d4STobin Davis 		break;
1289c9b443d4STobin Davis 	}
1290c9b443d4STobin Davis }
1291c9b443d4STobin Davis 
1292df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1293df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1294df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
12955f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1296c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1297c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1298c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1299c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
130082f30040STobin Davis 	{
130182f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
130282f30040STobin Davis 		.name = "Master Playback Switch",
130382f30040STobin Davis 		.info = cxt_eapd_info,
130482f30040STobin Davis 		.get = cxt_eapd_get,
1305c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1306c9b443d4STobin Davis 		.private_value = 0x13,
1307c9b443d4STobin Davis 	},
1308c9b443d4STobin Davis 
1309c9b443d4STobin Davis 	{}
1310c9b443d4STobin Davis };
1311c9b443d4STobin Davis 
1312df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13133b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13145d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1315df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1316df481e41STakashi Iwai 	{}
1317df481e41STakashi Iwai };
1318df481e41STakashi Iwai 
1319df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1320c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1321c9b443d4STobin Davis 	{ } /* end */
1322c9b443d4STobin Davis };
1323c9b443d4STobin Davis 
1324c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1325c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1326c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1327c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1328c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13297f29673bSTobin Davis 	/* HP, Speaker  */
1330b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13315b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13325b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13337f29673bSTobin Davis 	/* Record selector: Mic */
13347f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13357f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13367f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13377f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1338c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1339c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1340c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1341c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1342c9b443d4STobin Davis 	/* SPDIF route: PCM */
1343c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
134482f30040STobin Davis 	/* Enable unsolicited events */
134582f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
134682f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1347c9b443d4STobin Davis 	{ } /* end */
1348c9b443d4STobin Davis };
1349c9b443d4STobin Davis 
1350c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1351c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
13523b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1353c9b443d4STobin Davis 	{}
1354c9b443d4STobin Davis };
1355c9b443d4STobin Davis 
1356c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1357c9b443d4STobin Davis  * configuration.
1358c9b443d4STobin Davis  */
1359c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1360c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
136182f30040STobin Davis 	.num_items = 4,
1362c9b443d4STobin Davis 	.items = {
136382f30040STobin Davis 		{ "LINE1 pin", 0x0 },
136482f30040STobin Davis 		{ "MIC1 pin", 0x1 },
136582f30040STobin Davis 		{ "MIC2 pin", 0x2 },
136682f30040STobin Davis 		{ "CD pin", 0x3 },
1367c9b443d4STobin Davis         },
1368c9b443d4STobin Davis };
1369c9b443d4STobin Davis 
1370c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1371c9b443d4STobin Davis 
1372c9b443d4STobin Davis 	/* Output only controls */
137382f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
137482f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
137582f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
137682f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1377c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1378c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1379c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1380c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
138182f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
138282f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
138382f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
138482f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1385c9b443d4STobin Davis 
1386c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1387c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1388c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1389c9b443d4STobin Davis 
139082f30040STobin Davis 	/* EAPD Switch Control */
139182f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
139282f30040STobin Davis 
1393c9b443d4STobin Davis 	/* Loopback mixer controls */
139482f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
139582f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
139682f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
139782f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
139882f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
139982f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
140082f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
140182f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1402c9b443d4STobin Davis 
140382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
140482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
140582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
140682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
140782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
140882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
140982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
141082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1411c9b443d4STobin Davis 	{
1412c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1413c9b443d4STobin Davis 		.name = "Input Source",
1414c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1415c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1416c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1417c9b443d4STobin Davis 	},
1418854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14199f113e0eSMarc Boucher 
1420c9b443d4STobin Davis 	{ } /* end */
1421c9b443d4STobin Davis };
1422c9b443d4STobin Davis 
1423c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1424c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1425c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1427c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1430c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1431c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1432c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1433c9b443d4STobin Davis 	 * control.
1434c9b443d4STobin Davis 	 */
1435c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1436c9b443d4STobin Davis 
1437c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1438c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1439c9b443d4STobin Davis 	 */
1440c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1441c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1442c9b443d4STobin Davis 
1443c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1444c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1445c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1446c9b443d4STobin Davis 
1447c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1448c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1449c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1450c9b443d4STobin Davis 	 * input/output buffers as needed.
1451c9b443d4STobin Davis 	 */
1452c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1454c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1455c9b443d4STobin Davis 
1456c9b443d4STobin Davis 	/* Mute capture amp left and right */
1457c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1458c9b443d4STobin Davis 
1459c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1460c9b443d4STobin Davis 	 * pin)
1461c9b443d4STobin Davis 	 */
1462c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1463c9b443d4STobin Davis 
1464c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1465c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1466c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1467c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1468c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1469c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1470c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1471c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1472c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1473c9b443d4STobin Davis 
1474c9b443d4STobin Davis 	{ }
1475c9b443d4STobin Davis };
1476c9b443d4STobin Davis #endif
1477c9b443d4STobin Davis 
1478c9b443d4STobin Davis 
1479c9b443d4STobin Davis /* initialize jack-sensing, too */
1480c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1481c9b443d4STobin Davis {
1482c9b443d4STobin Davis 	conexant_init(codec);
1483c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1484c9b443d4STobin Davis 	return 0;
1485c9b443d4STobin Davis }
1486c9b443d4STobin Davis 
1487c9b443d4STobin Davis 
1488c9b443d4STobin Davis enum {
1489f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1490f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1491f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1492c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1493c9b443d4STobin Davis 	CXT5047_TEST,
1494c9b443d4STobin Davis #endif
1495f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1496c9b443d4STobin Davis };
1497c9b443d4STobin Davis 
1498ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1499f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1500f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1501f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1502c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1503f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1504c9b443d4STobin Davis #endif
1505f5fcc13cSTakashi Iwai };
1506c9b443d4STobin Davis 
1507f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1508ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1509dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1510dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1511f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1512c9b443d4STobin Davis 	{}
1513c9b443d4STobin Davis };
1514c9b443d4STobin Davis 
1515c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1516c9b443d4STobin Davis {
1517c9b443d4STobin Davis 	struct conexant_spec *spec;
1518c9b443d4STobin Davis 	int board_config;
1519c9b443d4STobin Davis 
1520c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1521c9b443d4STobin Davis 	if (!spec)
1522c9b443d4STobin Davis 		return -ENOMEM;
1523c9b443d4STobin Davis 	codec->spec = spec;
15249421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1525c9b443d4STobin Davis 
1526c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1527c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1528c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1529c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1530c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1531c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1532c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1533c9b443d4STobin Davis 	spec->num_mixers = 1;
1534df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1535c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1536c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1537c9b443d4STobin Davis 	spec->spdif_route = 0;
15385cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15395cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1540c9b443d4STobin Davis 
1541c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1542c9b443d4STobin Davis 
1543f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1544f5fcc13cSTakashi Iwai 						  cxt5047_models,
1545f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1546c9b443d4STobin Davis 	switch (board_config) {
1547c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1548df481e41STakashi Iwai 		spec->num_mixers = 2;
1549df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1550df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1551c9b443d4STobin Davis 		break;
1552c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1553df481e41STakashi Iwai 		spec->num_mixers = 2;
1554df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1555fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1556c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1557c9b443d4STobin Davis 		break;
1558c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
155982f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1560df481e41STakashi Iwai 		spec->num_mixers = 2;
1561df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1562c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1563c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1564fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1565c9b443d4STobin Davis 		break;
1566c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1567c9b443d4STobin Davis 	case CXT5047_TEST:
1568c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1569c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1570c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1571fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1572c9b443d4STobin Davis #endif
1573c9b443d4STobin Davis 	}
1574dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1575025f206cSDaniel T Chen 
1576025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1577025f206cSDaniel T Chen 	case 0x103c:
1578025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1579025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1580025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1581025f206cSDaniel T Chen 		 */
1582025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1583025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1584025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1585025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1586025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1587025f206cSDaniel T Chen 		break;
1588025f206cSDaniel T Chen 	}
1589025f206cSDaniel T Chen 
1590c9b443d4STobin Davis 	return 0;
1591c9b443d4STobin Davis }
1592c9b443d4STobin Davis 
1593461e2c78STakashi Iwai /* Conexant 5051 specific */
1594461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1595461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1596461e2c78STakashi Iwai 
1597461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1598461e2c78STakashi Iwai 	{ 2, NULL },
1599461e2c78STakashi Iwai };
1600461e2c78STakashi Iwai 
1601461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1602461e2c78STakashi Iwai {
1603461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1604461e2c78STakashi Iwai 	unsigned int pinctl;
160523d2df5bSTakashi Iwai 	/* headphone pin */
160623d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
160723d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
160823d2df5bSTakashi Iwai 			    pinctl);
160923d2df5bSTakashi Iwai 	/* speaker pin */
1610461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1611461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1612461e2c78STakashi Iwai 			    pinctl);
1613f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1614f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1615f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1616f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1617f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1618461e2c78STakashi Iwai }
1619461e2c78STakashi Iwai 
1620461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1621461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1622461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1623461e2c78STakashi Iwai {
1624461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1625461e2c78STakashi Iwai 
1626461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1627461e2c78STakashi Iwai 		return 0;
1628461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1629461e2c78STakashi Iwai 	return 1;
1630461e2c78STakashi Iwai }
1631461e2c78STakashi Iwai 
1632461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1633461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1634461e2c78STakashi Iwai {
163579d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1636461e2c78STakashi Iwai 	unsigned int present;
1637461e2c78STakashi Iwai 
1638faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
163979d7d533STakashi Iwai 		return;
1640d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1641461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1642461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1643461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1644461e2c78STakashi Iwai }
1645461e2c78STakashi Iwai 
1646461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1647461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1648461e2c78STakashi Iwai {
1649461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1650461e2c78STakashi Iwai 	unsigned int present;
1651461e2c78STakashi Iwai 	hda_nid_t new_adc;
1652461e2c78STakashi Iwai 
1653faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
165479d7d533STakashi Iwai 		return;
1655d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1656461e2c78STakashi Iwai 	if (present)
1657461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1658461e2c78STakashi Iwai 	else
1659461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1660461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1661461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1662461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1663f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1664461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1665461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1666461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1667461e2c78STakashi Iwai 					   spec->cur_adc_format);
1668461e2c78STakashi Iwai 	}
1669461e2c78STakashi Iwai }
1670461e2c78STakashi Iwai 
1671461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1672461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1673461e2c78STakashi Iwai {
1674461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1675461e2c78STakashi Iwai 
1676d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1677461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1678461e2c78STakashi Iwai }
1679461e2c78STakashi Iwai 
1680461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1681461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1682461e2c78STakashi Iwai 				   unsigned int res)
1683461e2c78STakashi Iwai {
1684acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1685461e2c78STakashi Iwai 	switch (res >> 26) {
1686461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1687461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1688461e2c78STakashi Iwai 		break;
1689461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1690461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1691461e2c78STakashi Iwai 		break;
1692461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1693461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1694461e2c78STakashi Iwai 		break;
1695461e2c78STakashi Iwai 	}
1696cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
1697461e2c78STakashi Iwai }
1698461e2c78STakashi Iwai 
16992c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1700461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1701461e2c78STakashi Iwai 	{
1702461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1703461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1704461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1705461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1706461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1707461e2c78STakashi Iwai 		.private_value = 0x1a,
1708461e2c78STakashi Iwai 	},
17092c7a3fb3STakashi Iwai 	{}
17102c7a3fb3STakashi Iwai };
1711461e2c78STakashi Iwai 
17122c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17132c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17142c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17158607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17168607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
17172c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17182c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1719461e2c78STakashi Iwai 	{}
1720461e2c78STakashi Iwai };
1721461e2c78STakashi Iwai 
1722461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1723461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1724461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17258607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
17268607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1727461e2c78STakashi Iwai 	{}
1728461e2c78STakashi Iwai };
1729461e2c78STakashi Iwai 
173079d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
17314e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
17324e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
173379d7d533STakashi Iwai 	{}
173479d7d533STakashi Iwai };
173579d7d533STakashi Iwai 
1736cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
17375f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
17385f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1739cd9d95a5SKen Prox 	{}
1740cd9d95a5SKen Prox };
1741cd9d95a5SKen Prox 
1742faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1743faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1744faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17458607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17468607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1747faddaa5dSTakashi Iwai 	{}
1748faddaa5dSTakashi Iwai };
1749faddaa5dSTakashi Iwai 
1750461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1751461e2c78STakashi Iwai 	/* Line in, Mic */
1752461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1753461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1754461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1755461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1756461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1757461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1758461e2c78STakashi Iwai 	/* SPK  */
1759461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1760461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1761461e2c78STakashi Iwai 	/* HP, Amp  */
1762461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1763461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1764461e2c78STakashi Iwai 	/* DAC1 */
1765461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
176628c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1767461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1768461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1769461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1770461e2c78STakashi Iwai 	/* SPDIF route: PCM */
17711965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1773461e2c78STakashi Iwai 	/* EAPD */
1774461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1775461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1776461e2c78STakashi Iwai 	{ } /* end */
1777461e2c78STakashi Iwai };
1778461e2c78STakashi Iwai 
177979d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
178079d7d533STakashi Iwai 	/* Line in, Mic */
178179d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
178279d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
178379d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
178479d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
178579d7d533STakashi Iwai 	/* SPK  */
178679d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
178779d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
178879d7d533STakashi Iwai 	/* HP, Amp  */
178979d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
179079d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
179179d7d533STakashi Iwai 	/* DAC1 */
179279d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
179328c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
179479d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
179579d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
179679d7d533STakashi Iwai 	/* SPDIF route: PCM */
179779d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
179879d7d533STakashi Iwai 	/* EAPD */
179979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
180079d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
180179d7d533STakashi Iwai 	{ } /* end */
180279d7d533STakashi Iwai };
180379d7d533STakashi Iwai 
180427e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
180527e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
180627e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
180727e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
180827e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
180927e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
181027e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
181127e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
181227e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
181327e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
181427e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
181527e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
181627e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
181727e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
181827e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
181927e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
182027e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
182127e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
182227e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
182328c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
182427e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
182527e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
182627e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
182727e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
18281965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
182927e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
183027e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
183127e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
183227e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
183327e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
183427e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
183527e08988SAristeu Sergio Rozanski Filho };
183627e08988SAristeu Sergio Rozanski Filho 
1837cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = {
1838cd9d95a5SKen Prox 	/* Line in, Mic */
183930ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1840cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1841cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1842cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1843cd9d95a5SKen Prox 	/* SPK  */
1844cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1845cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1846cd9d95a5SKen Prox 	/* HP, Amp  */
1847cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1848cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1849cd9d95a5SKen Prox 	/* DAC1 */
1850cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
185128c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1852cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1853cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1854cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1855cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1856cd9d95a5SKen Prox 	/* EAPD */
1857cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1858cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1859cd9d95a5SKen Prox 	{ } /* end */
1860cd9d95a5SKen Prox };
1861cd9d95a5SKen Prox 
18626953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
18636953e552STakashi Iwai 				 unsigned int event)
18646953e552STakashi Iwai {
18656953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
18666953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
18676953e552STakashi Iwai 			    AC_USRSP_EN | event);
1868cd372fb3STakashi Iwai 	snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1869cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
18706953e552STakashi Iwai }
18716953e552STakashi Iwai 
1872f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1873f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1874f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1875f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1876f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1877f7154de2SHerton Ronaldo Krzesinski };
1878f7154de2SHerton Ronaldo Krzesinski 
1879461e2c78STakashi Iwai /* initialize jack-sensing, too */
1880461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1881461e2c78STakashi Iwai {
18826953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
18836953e552STakashi Iwai 
1884461e2c78STakashi Iwai 	conexant_init(codec);
1885acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
18866953e552STakashi Iwai 
18876953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
18886953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
18896953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
18906953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
18916953e552STakashi Iwai 
1892461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1893461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1894461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1895461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1896461e2c78STakashi Iwai 	}
1897461e2c78STakashi Iwai 	return 0;
1898461e2c78STakashi Iwai }
1899461e2c78STakashi Iwai 
1900461e2c78STakashi Iwai 
1901461e2c78STakashi Iwai enum {
1902461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1903461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
190479d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19051965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1906cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1907faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1908f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
1909461e2c78STakashi Iwai 	CXT5051_MODELS
1910461e2c78STakashi Iwai };
1911461e2c78STakashi Iwai 
1912ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1913461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1914461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
191579d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
191627e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19175f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1918faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1919f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
1920461e2c78STakashi Iwai };
1921461e2c78STakashi Iwai 
1922461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
192379d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19241812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
19255f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1926faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1927461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1928461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1929461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
193027e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1931f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1932461e2c78STakashi Iwai 	{}
1933461e2c78STakashi Iwai };
1934461e2c78STakashi Iwai 
1935461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1936461e2c78STakashi Iwai {
1937461e2c78STakashi Iwai 	struct conexant_spec *spec;
1938461e2c78STakashi Iwai 	int board_config;
1939461e2c78STakashi Iwai 
1940461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1941461e2c78STakashi Iwai 	if (!spec)
1942461e2c78STakashi Iwai 		return -ENOMEM;
1943461e2c78STakashi Iwai 	codec->spec = spec;
19449421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1945461e2c78STakashi Iwai 
1946461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1947461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1948461e2c78STakashi Iwai 
1949461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1950461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1951461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1952461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1953461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1954461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
19552c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
19562c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
19572c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
1958461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1959461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1960461e2c78STakashi Iwai 	spec->spdif_route = 0;
1961461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1962461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1963461e2c78STakashi Iwai 	spec->cur_adc = 0;
1964461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1965461e2c78STakashi Iwai 
19663507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
19673507e2a8STakashi Iwai 
196879d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
196979d7d533STakashi Iwai 
1970461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1971461e2c78STakashi Iwai 						  cxt5051_models,
1972461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1973faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1974461e2c78STakashi Iwai 	switch (board_config) {
1975461e2c78STakashi Iwai 	case CXT5051_HP:
1976461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1977461e2c78STakashi Iwai 		break;
197879d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
197979d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
198079d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1981faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
198279d7d533STakashi Iwai 		break;
198327e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
198427e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1985607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
1986607bc3e4SJerone Young 		   to use a docking station. */
1987607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
1988607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
1989461e2c78STakashi Iwai 		break;
1990cd9d95a5SKen Prox 	case CXT5051_F700:
1991cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
1992cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
1993faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
1994faddaa5dSTakashi Iwai 		break;
1995faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
1996faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
1997faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
1998cd9d95a5SKen Prox 		break;
1999f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2000f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2001f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2002f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2003f7154de2SHerton Ronaldo Krzesinski 		break;
2004461e2c78STakashi Iwai 	}
2005461e2c78STakashi Iwai 
20063507e2a8STakashi Iwai 	if (spec->beep_amp)
20073507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20083507e2a8STakashi Iwai 
2009461e2c78STakashi Iwai 	return 0;
2010461e2c78STakashi Iwai }
2011461e2c78STakashi Iwai 
20120fb67e98SDaniel Drake /* Conexant 5066 specific */
20130fb67e98SDaniel Drake 
20140fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
20150fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
20160fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
2017f6a2491cSAndy Robinson static hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
20180fb67e98SDaniel Drake 
2019dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2020dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2021dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2022dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2023dbaccc0cSDaniel Drake 
20240fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
20250fb67e98SDaniel Drake 	{ 2, NULL },
20260fb67e98SDaniel Drake };
20270fb67e98SDaniel Drake 
2028a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2029a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2030a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2031a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2032a3de8ab8STakashi Iwai 
20330fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
20340fb67e98SDaniel Drake {
20350fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20360fb67e98SDaniel Drake 	unsigned int pinctl;
20370fb67e98SDaniel Drake 
20383a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
20393a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
20400fb67e98SDaniel Drake 
20410fb67e98SDaniel Drake 	/* Port A (HP) */
2042a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
20430fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20440fb67e98SDaniel Drake 			pinctl);
20450fb67e98SDaniel Drake 
20460fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2047a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2048a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2049a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2050a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
20513a253445SJohn Baboval 			pinctl = 0;
20523a253445SJohn Baboval 	} else {
2053a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2054a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2055a3de8ab8STakashi Iwai 			pinctl = 0;
20563a253445SJohn Baboval 	}
20570fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20580fb67e98SDaniel Drake 			pinctl);
20590fb67e98SDaniel Drake 
20600fb67e98SDaniel Drake 	/* CLASS_D AMP */
20610fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
20620fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20630fb67e98SDaniel Drake 			pinctl);
20640fb67e98SDaniel Drake }
20650fb67e98SDaniel Drake 
20660fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
20670fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
20680fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
20690fb67e98SDaniel Drake {
20700fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
20710fb67e98SDaniel Drake 
20720fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
20730fb67e98SDaniel Drake 		return 0;
20740fb67e98SDaniel Drake 
20750fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
20760fb67e98SDaniel Drake 	return 1;
20770fb67e98SDaniel Drake }
20780fb67e98SDaniel Drake 
2079c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2080c4cfe66cSDaniel Drake 	.num_items = 3,
2081c4cfe66cSDaniel Drake 	.items = {
2082c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2083c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2084c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2085c4cfe66cSDaniel Drake 	},
2086c4cfe66cSDaniel Drake };
2087c4cfe66cSDaniel Drake 
2088c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2089c4cfe66cSDaniel Drake {
2090c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2091c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2092c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2093c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2094c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2095c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2096c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2097c4cfe66cSDaniel Drake }
2098c4cfe66cSDaniel Drake 
209975f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
210075f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
210175f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
210275f8991dSDaniel Drake  * is happening when it is not. */
210375f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21040fb67e98SDaniel Drake {
2105dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
210675f8991dSDaniel Drake 	if (!spec->recording)
210775f8991dSDaniel Drake 		return;
21080fb67e98SDaniel Drake 
2109c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2110c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2111c4cfe66cSDaniel Drake 		 * through our special DC port */
2112c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2113c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2114c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2115c4cfe66cSDaniel Drake 
2116c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2117c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2118c4cfe66cSDaniel Drake 			{},
2119c4cfe66cSDaniel Drake 		};
2120c4cfe66cSDaniel Drake 
2121c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2122c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2123c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2124c4cfe66cSDaniel Drake 		return;
2125c4cfe66cSDaniel Drake 	}
2126c4cfe66cSDaniel Drake 
2127c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2128c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2129c4cfe66cSDaniel Drake 
213075f8991dSDaniel Drake 	/* external mic, port B */
213175f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
213275f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
21330fb67e98SDaniel Drake 
213475f8991dSDaniel Drake 	/* internal mic, port C */
213575f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
213675f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
213775f8991dSDaniel Drake }
21380fb67e98SDaniel Drake 
213975f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
214075f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
214175f8991dSDaniel Drake {
214275f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
21430fb67e98SDaniel Drake 	unsigned int present;
21440fb67e98SDaniel Drake 
2145c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2146c4cfe66cSDaniel Drake 		return;
2147c4cfe66cSDaniel Drake 
214875f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
214975f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
215075f8991dSDaniel Drake 	if (present)
21510fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
215275f8991dSDaniel Drake 	else
21530fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
215475f8991dSDaniel Drake 
215575f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
215675f8991dSDaniel Drake 		present ? 0 : 1);
215775f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
215875f8991dSDaniel Drake 
215975f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
21600fb67e98SDaniel Drake }
21610fb67e98SDaniel Drake 
216295a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
216395a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
216495a618bdSEinar Rünkaru {
216595a618bdSEinar Rünkaru 	unsigned int present;
216695a618bdSEinar Rünkaru 
216795a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
216895a618bdSEinar Rünkaru 		/* enable external mic, port B */
216975f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
217095a618bdSEinar Rünkaru 
217195a618bdSEinar Rünkaru 		/* switch to external mic input */
217295a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
217395a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
217495a618bdSEinar Rünkaru 
217595a618bdSEinar Rünkaru 		/* disable internal digital mic */
217695a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
217795a618bdSEinar Rünkaru 		{}
217895a618bdSEinar Rünkaru 	};
217995a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
218095a618bdSEinar Rünkaru 		/* enable internal mic, port C */
218195a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
218295a618bdSEinar Rünkaru 
218395a618bdSEinar Rünkaru 		/* switch to internal mic input */
218495a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
218595a618bdSEinar Rünkaru 
218695a618bdSEinar Rünkaru 		/* disable external mic, port B */
218795a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
218895a618bdSEinar Rünkaru 		{}
218995a618bdSEinar Rünkaru 	};
219095a618bdSEinar Rünkaru 
219195a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
219295a618bdSEinar Rünkaru 	if (present) {
219395a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
219495a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
219595a618bdSEinar Rünkaru 	} else {
219695a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
219795a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
219895a618bdSEinar Rünkaru 	}
219995a618bdSEinar Rünkaru }
220095a618bdSEinar Rünkaru 
2201cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2202cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2203cfd3d8dcSGreg Alexander {
2204cfd3d8dcSGreg Alexander 	unsigned int present;
2205cfd3d8dcSGreg Alexander 
2206cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2207cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2208cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2209cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2210cfd3d8dcSGreg Alexander 		{}
2211cfd3d8dcSGreg Alexander 	};
2212cfd3d8dcSGreg Alexander 	static struct hda_verb ext_mic_absent[] = {
2213cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2214cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2215cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2216cfd3d8dcSGreg Alexander 		{}
2217cfd3d8dcSGreg Alexander 	};
2218cfd3d8dcSGreg Alexander 
2219cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2220cfd3d8dcSGreg Alexander 	if (present) {
2221cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2222cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2223cfd3d8dcSGreg Alexander 	} else {
2224cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2225cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2226cfd3d8dcSGreg Alexander 	}
2227cfd3d8dcSGreg Alexander }
2228cfd3d8dcSGreg Alexander 
2229a1d6906eSDavid Henningsson 
2230a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2231a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2232a1d6906eSDavid Henningsson {
2233a1d6906eSDavid Henningsson 	unsigned int present;
2234a1d6906eSDavid Henningsson 
2235a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2236a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2237a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2238a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2239a1d6906eSDavid Henningsson }
2240a1d6906eSDavid Henningsson 
2241a1d6906eSDavid Henningsson 
2242048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2243048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2244048e78a5SDavid Henningsson {
2245048e78a5SDavid Henningsson 	unsigned int present;
2246048e78a5SDavid Henningsson 
2247048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2248048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2249048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2250048e78a5SDavid Henningsson 			    present ? 1 : 3);
2251048e78a5SDavid Henningsson }
2252048e78a5SDavid Henningsson 
2253048e78a5SDavid Henningsson 
22547b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
22557b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
22567b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
22577b2bfdbcSJens Taprogge {
22587b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
22597b2bfdbcSJens Taprogge 
22607b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_present[] = {
22617b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
22627b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
22637b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
22647b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22657b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22667b2bfdbcSJens Taprogge 		{}
22677b2bfdbcSJens Taprogge 	};
22687b2bfdbcSJens Taprogge 	static struct hda_verb dock_mic_present[] = {
22697b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
22707b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
22717b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
22727b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22737b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22747b2bfdbcSJens Taprogge 		{}
22757b2bfdbcSJens Taprogge 	};
22767b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_absent[] = {
22777b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
22787b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
22797b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22807b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22817b2bfdbcSJens Taprogge 		{}
22827b2bfdbcSJens Taprogge 	};
22837b2bfdbcSJens Taprogge 
22847b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
22857b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
22867b2bfdbcSJens Taprogge 	if (ext_present) {
22877b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
22887b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
22897b2bfdbcSJens Taprogge 	} else if (dock_present) {
22907b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
22917b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
22927b2bfdbcSJens Taprogge 	} else {
22937b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
22947b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
22957b2bfdbcSJens Taprogge 	}
22967b2bfdbcSJens Taprogge }
22977b2bfdbcSJens Taprogge 
22980fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
22990fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23000fb67e98SDaniel Drake {
23010fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23020fb67e98SDaniel Drake 	unsigned int portA, portD;
23030fb67e98SDaniel Drake 
23040fb67e98SDaniel Drake 	/* Port A */
2305d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23060fb67e98SDaniel Drake 
23070fb67e98SDaniel Drake 	/* Port D */
2308d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23090fb67e98SDaniel Drake 
2310a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2311a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
23120fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23130fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23140fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23150fb67e98SDaniel Drake }
23160fb67e98SDaniel Drake 
231702b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
231802b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
231902b6b5b6SDavid Henningsson {
232002b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
232102b6b5b6SDavid Henningsson 
232202b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
232302b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
232402b6b5b6SDavid Henningsson 	else if (spec->ideapad)
232502b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
232602b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
232702b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
232802b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
232902b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2330a1d6906eSDavid Henningsson 	else if (spec->asus)
2331a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
233202b6b5b6SDavid Henningsson }
233302b6b5b6SDavid Henningsson 
23340fb67e98SDaniel Drake /* unsolicited event for jack sensing */
233575f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23360fb67e98SDaniel Drake {
2337c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23380fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23390fb67e98SDaniel Drake 	switch (res >> 26) {
23400fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
23410fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
23420fb67e98SDaniel Drake 		break;
23430fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2344c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2345c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
234675f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
23470fb67e98SDaniel Drake 		break;
23480fb67e98SDaniel Drake 	}
23490fb67e98SDaniel Drake }
23500fb67e98SDaniel Drake 
235195a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
235202b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
235395a618bdSEinar Rünkaru {
235402b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
235595a618bdSEinar Rünkaru 	switch (res >> 26) {
235695a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
235795a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
235895a618bdSEinar Rünkaru 		break;
235995a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
236002b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
236195a618bdSEinar Rünkaru 		break;
236295a618bdSEinar Rünkaru 	}
236395a618bdSEinar Rünkaru }
236495a618bdSEinar Rünkaru 
23657b2bfdbcSJens Taprogge 
23660fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
23670fb67e98SDaniel Drake 	.num_items = 5,
23680fb67e98SDaniel Drake 	.items = {
23690fb67e98SDaniel Drake 		{ "0dB",  0 },
23700fb67e98SDaniel Drake 		{ "10dB", 1 },
23710fb67e98SDaniel Drake 		{ "20dB", 2 },
23720fb67e98SDaniel Drake 		{ "30dB", 3 },
23730fb67e98SDaniel Drake 		{ "40dB", 4 },
23740fb67e98SDaniel Drake 	},
23750fb67e98SDaniel Drake };
23760fb67e98SDaniel Drake 
2377cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2378c4cfe66cSDaniel Drake {
2379c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2380cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2381c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2382c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2383c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
23847b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2385cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2386cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2387cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2388cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2389cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2390cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2391cfd3d8dcSGreg Alexander 	}
2392c4cfe66cSDaniel Drake }
2393c4cfe66cSDaniel Drake 
23940fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
23950fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
23960fb67e98SDaniel Drake {
23970fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
23980fb67e98SDaniel Drake }
23990fb67e98SDaniel Drake 
24000fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24010fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24020fb67e98SDaniel Drake {
24030fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2404c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2405c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24060fb67e98SDaniel Drake 	return 0;
24070fb67e98SDaniel Drake }
24080fb67e98SDaniel Drake 
24090fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24100fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24110fb67e98SDaniel Drake {
24120fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2413c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24140fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24150fb67e98SDaniel Drake 	unsigned int idx;
24160fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24170fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24180fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24190fb67e98SDaniel Drake 
2420c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2421c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2422c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2423c4cfe66cSDaniel Drake 	return 1;
2424c4cfe66cSDaniel Drake }
24250fb67e98SDaniel Drake 
2426c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2427c4cfe66cSDaniel Drake {
2428c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2429c4cfe66cSDaniel Drake 		/* disable gain */
2430c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2431c4cfe66cSDaniel Drake 
2432c4cfe66cSDaniel Drake 		/* switch to DC input */
2433c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2434c4cfe66cSDaniel Drake 		{}
2435c4cfe66cSDaniel Drake 	};
2436c4cfe66cSDaniel Drake 
2437c4cfe66cSDaniel Drake 	/* configure as input source */
2438c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2439c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2440c4cfe66cSDaniel Drake }
2441c4cfe66cSDaniel Drake 
2442c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2443c4cfe66cSDaniel Drake {
2444c4cfe66cSDaniel Drake 	/* reconfigure input source */
2445c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2446c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2447c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2448c4cfe66cSDaniel Drake }
2449c4cfe66cSDaniel Drake 
2450c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2451c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2452c4cfe66cSDaniel Drake {
2453c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2454c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2455c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2456c4cfe66cSDaniel Drake 	return 0;
2457c4cfe66cSDaniel Drake }
2458c4cfe66cSDaniel Drake 
2459c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2460c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2461c4cfe66cSDaniel Drake {
2462c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2463c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2464c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2465c4cfe66cSDaniel Drake 
2466c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2467c4cfe66cSDaniel Drake 		return 0;
2468c4cfe66cSDaniel Drake 
2469c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2470c4cfe66cSDaniel Drake 	if (dc_enable)
2471c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2472c4cfe66cSDaniel Drake 	else
2473c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2474c4cfe66cSDaniel Drake 
2475c4cfe66cSDaniel Drake 	return 1;
2476c4cfe66cSDaniel Drake }
2477c4cfe66cSDaniel Drake 
2478c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2479c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2480c4cfe66cSDaniel Drake {
2481c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2482c4cfe66cSDaniel Drake }
2483c4cfe66cSDaniel Drake 
2484c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2485c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2486c4cfe66cSDaniel Drake {
2487c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2488c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2489c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2490c4cfe66cSDaniel Drake 	return 0;
2491c4cfe66cSDaniel Drake }
2492c4cfe66cSDaniel Drake 
2493c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2494c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2495c4cfe66cSDaniel Drake {
2496c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2497c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2498c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2499c4cfe66cSDaniel Drake 	unsigned int idx;
2500c4cfe66cSDaniel Drake 
2501c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2502c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2503c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2504c4cfe66cSDaniel Drake 
2505c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2506c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2507c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25080fb67e98SDaniel Drake 	return 1;
25090fb67e98SDaniel Drake }
25100fb67e98SDaniel Drake 
251175f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
251275f8991dSDaniel Drake {
251375f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
251475f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
251575f8991dSDaniel Drake 	 * recording LED comes on. */
251675f8991dSDaniel Drake 	spec->recording = 1;
251775f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
251875f8991dSDaniel Drake }
251975f8991dSDaniel Drake 
252075f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
252175f8991dSDaniel Drake {
252275f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
252375f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
252475f8991dSDaniel Drake 		/* disable external mic, port B */
252575f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
252675f8991dSDaniel Drake 
252775f8991dSDaniel Drake 		/* disble internal mic, port C */
252875f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2529c4cfe66cSDaniel Drake 
2530c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2531c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
253275f8991dSDaniel Drake 		{},
253375f8991dSDaniel Drake 	};
253475f8991dSDaniel Drake 
253575f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
253675f8991dSDaniel Drake 	spec->recording = 0;
253775f8991dSDaniel Drake }
253875f8991dSDaniel Drake 
2539f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
2540f6a2491cSAndy Robinson 				    hda_nid_t *dig_pins,
2541f6a2491cSAndy Robinson 				    int num_pins)
2542f6a2491cSAndy Robinson {
2543f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2544f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2545f6a2491cSAndy Robinson 	int i;
2546f6a2491cSAndy Robinson 
2547f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2548f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2549f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2550f6a2491cSAndy Robinson 			continue;
2551f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2552f6a2491cSAndy Robinson 			continue;
2553f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
2554f6a2491cSAndy Robinson 			nid_loc++;
2555f6a2491cSAndy Robinson 		else
2556f6a2491cSAndy Robinson 			nid_loc = spec->slave_dig_outs;
2557f6a2491cSAndy Robinson 	}
2558f6a2491cSAndy Robinson }
2559f6a2491cSAndy Robinson 
25600fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
25610fb67e98SDaniel Drake 	.num_items = 4,
25620fb67e98SDaniel Drake 	.items = {
25630fb67e98SDaniel Drake 		{ "Mic B", 0 },
25640fb67e98SDaniel Drake 		{ "Mic C", 1 },
25650fb67e98SDaniel Drake 		{ "Mic E", 2 },
25660fb67e98SDaniel Drake 		{ "Mic F", 3 },
25670fb67e98SDaniel Drake 	},
25680fb67e98SDaniel Drake };
25690fb67e98SDaniel Drake 
25700fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
25710fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
25720fb67e98SDaniel Drake 	.values = {
25730fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
25740fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
25750fb67e98SDaniel Drake 		0
25760fb67e98SDaniel Drake 	},
25770fb67e98SDaniel Drake };
25780fb67e98SDaniel Drake 
25790fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
25800fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
25810fb67e98SDaniel Drake 	.values = {
25820fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
25830fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
25840fb67e98SDaniel Drake 		0
25850fb67e98SDaniel Drake 	},
25860fb67e98SDaniel Drake };
25870fb67e98SDaniel Drake 
25880fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
25890fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
25900fb67e98SDaniel Drake 	{}
25910fb67e98SDaniel Drake };
25920fb67e98SDaniel Drake 
25930fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
25940fb67e98SDaniel Drake 	{
25950fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
25960fb67e98SDaniel Drake 		.name = "Master Playback Volume",
25970fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
25980fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
25990fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26005e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26010fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26020fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26030fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26040fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26050fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26060fb67e98SDaniel Drake 		.private_value =
26070fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26080fb67e98SDaniel Drake 	},
26090fb67e98SDaniel Drake 	{}
26100fb67e98SDaniel Drake };
26110fb67e98SDaniel Drake 
2612c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2613c4cfe66cSDaniel Drake 	{
2614c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2615c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2616c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2617c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2618c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2619c4cfe66cSDaniel Drake 	},
2620c4cfe66cSDaniel Drake 	{
2621c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2622c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2623c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2624c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2625c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2626c4cfe66cSDaniel Drake 	},
2627c4cfe66cSDaniel Drake 	{}
2628c4cfe66cSDaniel Drake };
2629c4cfe66cSDaniel Drake 
26300fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
26310fb67e98SDaniel Drake 	{
26320fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26330fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26340fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26350fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26360fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26370fb67e98SDaniel Drake 		.private_value = 0x1d,
26380fb67e98SDaniel Drake 	},
26390fb67e98SDaniel Drake 
26400fb67e98SDaniel Drake 	{
26410fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2642c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
26430fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
26440fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
26450fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
26460fb67e98SDaniel Drake 	},
26470fb67e98SDaniel Drake 
26480fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
26490fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
26500fb67e98SDaniel Drake 	{}
26510fb67e98SDaniel Drake };
26520fb67e98SDaniel Drake 
2653254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2654254bba6aSEinar Rünkaru 	{
2655254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
265628c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2657254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2658254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2659254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2660254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2661254bba6aSEinar Rünkaru 	},
2662254bba6aSEinar Rünkaru 	{}
2663254bba6aSEinar Rünkaru };
2664254bba6aSEinar Rünkaru 
26650fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
26660fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
26670fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
26680fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
26690fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
26700fb67e98SDaniel Drake 
26710fb67e98SDaniel Drake 	/* Speakers  */
26720fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26730fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26740fb67e98SDaniel Drake 
26750fb67e98SDaniel Drake 	/* HP, Amp  */
26760fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
26770fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26780fb67e98SDaniel Drake 
26790fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
26800fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26810fb67e98SDaniel Drake 
26820fb67e98SDaniel Drake 	/* DAC1 */
26830fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
26840fb67e98SDaniel Drake 
26850fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
26860fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
26870fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
26880fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
26890fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
26900fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
26910fb67e98SDaniel Drake 
26920fb67e98SDaniel Drake 	/* no digital microphone support yet */
26930fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26940fb67e98SDaniel Drake 
26950fb67e98SDaniel Drake 	/* Audio input selector */
26960fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
26970fb67e98SDaniel Drake 
26980fb67e98SDaniel Drake 	/* SPDIF route: PCM */
26990fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27000fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27010fb67e98SDaniel Drake 
27020fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27030fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27040fb67e98SDaniel Drake 
27050fb67e98SDaniel Drake 	/* EAPD */
27060fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27070fb67e98SDaniel Drake 
27080fb67e98SDaniel Drake 	/* not handling these yet */
27090fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27100fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27110fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27120fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27130fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27140fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27150fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27160fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27170fb67e98SDaniel Drake 	{ } /* end */
27180fb67e98SDaniel Drake };
27190fb67e98SDaniel Drake 
27200fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
27210fb67e98SDaniel Drake 	/* Port A: headphones */
27220fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27230fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27240fb67e98SDaniel Drake 
27250fb67e98SDaniel Drake 	/* Port B: external microphone */
272675f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27270fb67e98SDaniel Drake 
27280fb67e98SDaniel Drake 	/* Port C: internal microphone */
272975f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27300fb67e98SDaniel Drake 
27310fb67e98SDaniel Drake 	/* Port D: unused */
27320fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27330fb67e98SDaniel Drake 
27340fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27350fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27360fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27370fb67e98SDaniel Drake 
2738c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27390fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27400fb67e98SDaniel Drake 
27410fb67e98SDaniel Drake 	/* Port G: internal speakers */
27420fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27430fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27440fb67e98SDaniel Drake 
27450fb67e98SDaniel Drake 	/* DAC1 */
27460fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27470fb67e98SDaniel Drake 
27480fb67e98SDaniel Drake 	/* DAC2: unused */
27490fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
27500fb67e98SDaniel Drake 
27510fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27520fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27530fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27540fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27550fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27560fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27570fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27580fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27590fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27600fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27610fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27620fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27630fb67e98SDaniel Drake 
27640fb67e98SDaniel Drake 	/* Disable digital microphone port */
27650fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27660fb67e98SDaniel Drake 
27670fb67e98SDaniel Drake 	/* Audio input selectors */
27680fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27690fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
27700fb67e98SDaniel Drake 
27710fb67e98SDaniel Drake 	/* Disable SPDIF */
27720fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27730fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27740fb67e98SDaniel Drake 
27750fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
27760fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
27770fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
27780fb67e98SDaniel Drake 	{ } /* end */
27790fb67e98SDaniel Drake };
27800fb67e98SDaniel Drake 
278195a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
278295a618bdSEinar Rünkaru 	/* Port A: headphones */
278395a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
278495a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
278595a618bdSEinar Rünkaru 
278695a618bdSEinar Rünkaru 	/* Port B: external microphone */
278795a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
278895a618bdSEinar Rünkaru 
278995a618bdSEinar Rünkaru 	/* Port C: unused */
279095a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
279195a618bdSEinar Rünkaru 
279295a618bdSEinar Rünkaru 	/* Port D: unused */
279395a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
279495a618bdSEinar Rünkaru 
279595a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
279695a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
279795a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
279895a618bdSEinar Rünkaru 
279995a618bdSEinar Rünkaru 	/* Port F: unused */
280095a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
280195a618bdSEinar Rünkaru 
280295a618bdSEinar Rünkaru 	/* Port G: internal speakers */
280395a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
280495a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
280595a618bdSEinar Rünkaru 
280695a618bdSEinar Rünkaru 	/* DAC1 */
280795a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
280895a618bdSEinar Rünkaru 
280995a618bdSEinar Rünkaru 	/* DAC2: unused */
281095a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
281195a618bdSEinar Rünkaru 
281295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
281395a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
281495a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
281595a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
281695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
281795a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
281895a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
281995a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
282095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
282195a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
282295a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
282395a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
282495a618bdSEinar Rünkaru 
282595a618bdSEinar Rünkaru 	/* Digital microphone port */
282695a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
282795a618bdSEinar Rünkaru 
282895a618bdSEinar Rünkaru 	/* Audio input selectors */
282995a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
283095a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
283195a618bdSEinar Rünkaru 
283295a618bdSEinar Rünkaru 	/* Disable SPDIF */
283395a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283495a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283595a618bdSEinar Rünkaru 
283695a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
283795a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
283895a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
283995a618bdSEinar Rünkaru 	{ } /* end */
284095a618bdSEinar Rünkaru };
284195a618bdSEinar Rünkaru 
2842cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2843cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2844cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2845cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2846cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2847cfd3d8dcSGreg Alexander 
2848cfd3d8dcSGreg Alexander 	/* Speakers  */
2849cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2850cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2851cfd3d8dcSGreg Alexander 
2852cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2853cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2854cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2855cfd3d8dcSGreg Alexander 
2856cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2857cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2858cfd3d8dcSGreg Alexander 
2859cfd3d8dcSGreg Alexander 	/* DAC1 */
2860cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2861cfd3d8dcSGreg Alexander 
2862cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2863cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2864cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2865cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2866cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2867cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2868cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2869cfd3d8dcSGreg Alexander 
2870cfd3d8dcSGreg Alexander 	/* Audio input selector */
2871cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2872cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2873cfd3d8dcSGreg Alexander 
2874cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2875cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2876cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2877cfd3d8dcSGreg Alexander 
2878cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2879cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2880cfd3d8dcSGreg Alexander 
2881cfd3d8dcSGreg Alexander 	/* internal microphone */
288228c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2883cfd3d8dcSGreg Alexander 
2884cfd3d8dcSGreg Alexander 	/* EAPD */
2885cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2886cfd3d8dcSGreg Alexander 
2887cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2888cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2889cfd3d8dcSGreg Alexander 	{ } /* end */
2890cfd3d8dcSGreg Alexander };
2891cfd3d8dcSGreg Alexander 
28927b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
28937b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
28947b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
28957b2bfdbcSJens Taprogge 
28967b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
28977b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28987b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28997b2bfdbcSJens Taprogge 
29007b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29017b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29027b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29037b2bfdbcSJens Taprogge 
29047b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29057b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29067b2bfdbcSJens Taprogge 
29077b2bfdbcSJens Taprogge 	/* Port C: Mic */
29087b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29097b2bfdbcSJens Taprogge 
29107b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29117b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29127b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29137b2bfdbcSJens Taprogge 
29147b2bfdbcSJens Taprogge 	/* DAC1 */
29157b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29167b2bfdbcSJens Taprogge 
29177b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29187b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29197b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29207b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29217b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29227b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29237b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29247b2bfdbcSJens Taprogge 
29257b2bfdbcSJens Taprogge 	/* Audio input selector */
29267b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29277b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29287b2bfdbcSJens Taprogge 
29297b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29307b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29317b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29327b2bfdbcSJens Taprogge 
29337b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29347b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29357b2bfdbcSJens Taprogge 
29367b2bfdbcSJens Taprogge 	/* internal microphone */
293728c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
29387b2bfdbcSJens Taprogge 
29397b2bfdbcSJens Taprogge 	/* EAPD */
29407b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
29417b2bfdbcSJens Taprogge 
29427b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
29437b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29447b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29457b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29467b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29477b2bfdbcSJens Taprogge 	{ } /* end */
29487b2bfdbcSJens Taprogge };
29497b2bfdbcSJens Taprogge 
29500fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
29510fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29520fb67e98SDaniel Drake 	{ } /* end */
29530fb67e98SDaniel Drake };
29540fb67e98SDaniel Drake 
2955048e78a5SDavid Henningsson 
2956048e78a5SDavid Henningsson static struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2957048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2958048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2959048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2960048e78a5SDavid Henningsson 	{ } /* end */
2961048e78a5SDavid Henningsson };
2962048e78a5SDavid Henningsson 
29630fb67e98SDaniel Drake /* initialize jack-sensing, too */
29640fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
29650fb67e98SDaniel Drake {
29660fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
29670fb67e98SDaniel Drake 	conexant_init(codec);
29680fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
29690fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
297002b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
29710fb67e98SDaniel Drake 	}
2972c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
29730fb67e98SDaniel Drake 	return 0;
29740fb67e98SDaniel Drake }
29750fb67e98SDaniel Drake 
297675f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
297775f8991dSDaniel Drake {
2978c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
297975f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
298075f8991dSDaniel Drake 	conexant_init(codec);
298175f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
2982c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
2983c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
298475f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
2985c4cfe66cSDaniel Drake 	} else {
2986c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2987c4cfe66cSDaniel Drake 	}
298875f8991dSDaniel Drake 	return 0;
298975f8991dSDaniel Drake }
299075f8991dSDaniel Drake 
29910fb67e98SDaniel Drake enum {
29920fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
29930fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
29940fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
29951feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
2996cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
29977b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
2998a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2999048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
30000fb67e98SDaniel Drake 	CXT5066_MODELS
30010fb67e98SDaniel Drake };
30020fb67e98SDaniel Drake 
3003ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
30040fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30050fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30060fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
30071feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3008cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30097b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3010a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3011048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
30120fb67e98SDaniel Drake };
30130fb67e98SDaniel Drake 
30140fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
301500cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
30161feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
30178a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3018ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
30191feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3020231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3021ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3022ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3023048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3024f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3025a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3026f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
30272ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3028c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30294442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30305637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30315637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
30325637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
30334d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3034ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
303519593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
30367b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
303784012657SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3038*b2cb1292SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3039a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
304022f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
30410fb67e98SDaniel Drake 	{}
30420fb67e98SDaniel Drake };
30430fb67e98SDaniel Drake 
30440fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
30450fb67e98SDaniel Drake {
30460fb67e98SDaniel Drake 	struct conexant_spec *spec;
30470fb67e98SDaniel Drake 	int board_config;
30480fb67e98SDaniel Drake 
30490fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
30500fb67e98SDaniel Drake 	if (!spec)
30510fb67e98SDaniel Drake 		return -ENOMEM;
30520fb67e98SDaniel Drake 	codec->spec = spec;
30530fb67e98SDaniel Drake 
30540fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
305575f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
30560fb67e98SDaniel Drake 
30570fb67e98SDaniel Drake 	spec->dell_automute = 0;
30580fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
30590fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
30600fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
3061f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3062f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
30630fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
30640fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
30650fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
30660fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
30670fb67e98SDaniel Drake 
30680fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
30690fb67e98SDaniel Drake 
30700fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
30710fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
30720fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
30730fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
30740fb67e98SDaniel Drake 	spec->cur_adc = 0;
30750fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
30760fb67e98SDaniel Drake 
30773507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
30783507e2a8STakashi Iwai 
30790fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
30800fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
30810fb67e98SDaniel Drake 	switch (board_config) {
30820fb67e98SDaniel Drake 	default:
30830fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
30840fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
30850fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30860fb67e98SDaniel Drake 		break;
30870fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
30880fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
30890fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30900fb67e98SDaniel Drake 
30910fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
30920fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
30930fb67e98SDaniel Drake 		spec->num_init_verbs++;
30940fb67e98SDaniel Drake 		spec->dell_automute = 1;
30950fb67e98SDaniel Drake 		break;
3096a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3097048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3098048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
309902b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3100048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3101048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3102048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3103a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3104a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3105048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3106048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3107048e78a5SDavid Henningsson 		/* no S/PDIF out */
3108f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3109048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3110048e78a5SDavid Henningsson 		/* input source automatically selected */
3111048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3112048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3113048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3114048e78a5SDavid Henningsson 		break;
3115048e78a5SDavid Henningsson 
31160fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
311775f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
311875f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31190fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31200fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3121c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31220fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31230fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3124c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31250fb67e98SDaniel Drake 
31260fb67e98SDaniel Drake 		/* no S/PDIF out */
31270fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31280fb67e98SDaniel Drake 
31290fb67e98SDaniel Drake 		/* input source automatically selected */
31300fb67e98SDaniel Drake 		spec->input_mux = NULL;
313175f8991dSDaniel Drake 
313275f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
313375f8991dSDaniel Drake 		 * at the right time */
313475f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
313575f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
31360fb67e98SDaniel Drake 		break;
31371feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
313875f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
313902b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
314095a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
314195a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
314295a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3143254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
314495a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3145254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3146c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
314795a618bdSEinar Rünkaru 
314895a618bdSEinar Rünkaru 		/* no S/PDIF out */
314995a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
315095a618bdSEinar Rünkaru 
315195a618bdSEinar Rünkaru 		/* input source automatically selected */
315295a618bdSEinar Rünkaru 		spec->input_mux = NULL;
315395a618bdSEinar Rünkaru 		break;
3154cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3155cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
315602b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3157cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3158cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3159cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3160cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3161cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3162cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3163cfd3d8dcSGreg Alexander 
3164cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3165cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3166cfd3d8dcSGreg Alexander 
3167cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3168cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3169cfd3d8dcSGreg Alexander 		break;
31707b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
31717b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
317202b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
31737b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31747b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31757b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
31767b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
31777b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
31787b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
31797b2bfdbcSJens Taprogge 
31807b2bfdbcSJens Taprogge 		/* no S/PDIF out */
31817b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
31827b2bfdbcSJens Taprogge 
31837b2bfdbcSJens Taprogge 		/* input source automatically selected */
31847b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
31857b2bfdbcSJens Taprogge 		break;
31860fb67e98SDaniel Drake 	}
31870fb67e98SDaniel Drake 
31883507e2a8STakashi Iwai 	if (spec->beep_amp)
31893507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
31903507e2a8STakashi Iwai 
31910fb67e98SDaniel Drake 	return 0;
31920fb67e98SDaniel Drake }
3193461e2c78STakashi Iwai 
3194461e2c78STakashi Iwai /*
3195f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3196f2e5731dSTakashi Iwai  */
3197f2e5731dSTakashi Iwai 
3198f2e5731dSTakashi Iwai static hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3199f2e5731dSTakashi Iwai 
3200f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */
3201f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3202f2e5731dSTakashi Iwai 				hda_nid_t nid)
3203f2e5731dSTakashi Iwai {
3204f2e5731dSTakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3205f2e5731dSTakashi Iwai 	int i, nums;
3206f2e5731dSTakashi Iwai 
3207f2e5731dSTakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3208f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++)
3209f2e5731dSTakashi Iwai 		if (conn[i] == nid)
3210f2e5731dSTakashi Iwai 			return i;
3211f2e5731dSTakashi Iwai 	return -1;
3212f2e5731dSTakashi Iwai }
3213f2e5731dSTakashi Iwai 
3214f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3215f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3216f2e5731dSTakashi Iwai  * not found
3217f2e5731dSTakashi Iwai  */
3218f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3219f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3220f2e5731dSTakashi Iwai {
3221f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3222f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3223f2e5731dSTakashi Iwai 
3224f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3225f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3226f2e5731dSTakashi Iwai 			ret = dacs[i];
3227f2e5731dSTakashi Iwai 			break;
3228f2e5731dSTakashi Iwai 		}
3229f2e5731dSTakashi Iwai 	}
3230f2e5731dSTakashi Iwai 	if (!ret)
3231f2e5731dSTakashi Iwai 		return 0;
3232f2e5731dSTakashi Iwai 	if (--nums > 0)
3233f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3234f2e5731dSTakashi Iwai 	*num_dacs = nums;
3235f2e5731dSTakashi Iwai 	return ret;
3236f2e5731dSTakashi Iwai }
3237f2e5731dSTakashi Iwai 
3238f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3239f2e5731dSTakashi Iwai 
3240f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3241f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3242f2e5731dSTakashi Iwai {
3243f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3244f2e5731dSTakashi Iwai 	int nums = 0;
3245f2e5731dSTakashi Iwai 
3246f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3247f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3248f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3249f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3250f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3251f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3252f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3253f2e5731dSTakashi Iwai 				break;
3254f2e5731dSTakashi Iwai 		}
3255f2e5731dSTakashi Iwai 	}
3256f2e5731dSTakashi Iwai 	return nums;
3257f2e5731dSTakashi Iwai }
3258f2e5731dSTakashi Iwai 
3259f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3260f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3261f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3262f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3263f2e5731dSTakashi Iwai {
3264f2e5731dSTakashi Iwai 	int i, nums;
3265f2e5731dSTakashi Iwai 
3266f2e5731dSTakashi Iwai 	nums = 0;
3267f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3268f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3269f2e5731dSTakashi Iwai 		filled[nums].type = type;
3270f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3271f2e5731dSTakashi Iwai 		nums++;
3272f2e5731dSTakashi Iwai 	}
3273f2e5731dSTakashi Iwai 	return nums;
3274f2e5731dSTakashi Iwai }
3275f2e5731dSTakashi Iwai 
3276f2e5731dSTakashi Iwai /* parse analog output paths */
3277f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3278f2e5731dSTakashi Iwai {
3279f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3280f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3281f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3282f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3283f2e5731dSTakashi Iwai 
3284f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3285f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3286f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3287f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3288f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3289f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3290f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3291f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3292f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3293f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3294f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3295f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3296f2e5731dSTakashi Iwai 	/* fill multiout struct */
3297f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3298f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3299f2e5731dSTakashi Iwai 		if (!dac)
3300f2e5731dSTakashi Iwai 			continue;
3301f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3302f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3303f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3304f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3305f2e5731dSTakashi Iwai 			break;
3306f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3307f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3308f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3309f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3310f2e5731dSTakashi Iwai 				break;
3311f2e5731dSTakashi Iwai 			}
3312f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3313f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3314f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3315f2e5731dSTakashi Iwai 					break;
3316f2e5731dSTakashi Iwai 				}
3317f2e5731dSTakashi Iwai 			break;
3318f2e5731dSTakashi Iwai 		}
3319f2e5731dSTakashi Iwai 	}
3320f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
332189724958SDavid Henningsson 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3322f2e5731dSTakashi Iwai 
3323f2e5731dSTakashi Iwai 	if (cfg->hp_outs > 0)
3324f2e5731dSTakashi Iwai 		spec->auto_mute = 1;
3325f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3326f2e5731dSTakashi Iwai }
3327f2e5731dSTakashi Iwai 
3328f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
3329f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3330f2e5731dSTakashi Iwai {
3331f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3332f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3333f2e5731dSTakashi Iwai 	int i, present;
3334f2e5731dSTakashi Iwai 
3335f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3336f2e5731dSTakashi Iwai 		return;
3337f2e5731dSTakashi Iwai 	present = 0;
3338f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
3339f2e5731dSTakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3340f2e5731dSTakashi Iwai 			present = 1;
3341f2e5731dSTakashi Iwai 			break;
3342f2e5731dSTakashi Iwai 		}
3343f2e5731dSTakashi Iwai 	}
3344f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->line_outs; i++) {
3345f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3346f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3347f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3348f2e5731dSTakashi Iwai 	}
3349fbb5bb56STakashi Iwai 	for (i = 0; !present && i < cfg->line_outs; i++)
3350fbb5bb56STakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3351fbb5bb56STakashi Iwai 			present = 1;
3352f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->speaker_outs; i++) {
3353f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3354f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3355f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3356f2e5731dSTakashi Iwai 	}
3357f2e5731dSTakashi Iwai }
3358f2e5731dSTakashi Iwai 
3359f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3360f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3361f2e5731dSTakashi Iwai {
3362f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3363f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3364f2e5731dSTakashi Iwai 	struct hda_input_mux *imux = &spec->private_imux;
3365f2e5731dSTakashi Iwai 	int ext_idx = spec->auto_mic_ext;
3366f2e5731dSTakashi Iwai 
3367f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3368f2e5731dSTakashi Iwai 		return;
3369f2e5731dSTakashi Iwai 	if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin)) {
3370f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3371f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3372f2e5731dSTakashi Iwai 				    imux->items[ext_idx].index);
3373f2e5731dSTakashi Iwai 	} else {
3374f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[0], 0,
3375f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3376f2e5731dSTakashi Iwai 				    imux->items[!ext_idx].index);
3377f2e5731dSTakashi Iwai 	}
3378f2e5731dSTakashi Iwai }
3379f2e5731dSTakashi Iwai 
3380f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3381f2e5731dSTakashi Iwai {
3382f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3383f2e5731dSTakashi Iwai 	switch (res >> 26) {
3384f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3385f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3386cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3387f2e5731dSTakashi Iwai 		break;
3388f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3389f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3390cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3391f2e5731dSTakashi Iwai 		break;
3392f2e5731dSTakashi Iwai 	}
3393f2e5731dSTakashi Iwai }
3394f2e5731dSTakashi Iwai 
3395f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */
3396f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3397f2e5731dSTakashi Iwai {
3398f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3399f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
340099ae28beSTakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3401f2e5731dSTakashi Iwai }
3402f2e5731dSTakashi Iwai 
3403f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */
3404f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3405f2e5731dSTakashi Iwai {
3406f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3407f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3408f68b3b29STakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3409f68b3b29STakashi Iwai 		(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3410f2e5731dSTakashi Iwai }
3411f2e5731dSTakashi Iwai 
3412f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
3413f2e5731dSTakashi Iwai  * auto-mic is enabled only when one int-mic and one-ext mic exist
3414f2e5731dSTakashi Iwai  */
3415f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3416f2e5731dSTakashi Iwai {
3417f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3418f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3419f2e5731dSTakashi Iwai 
3420f2e5731dSTakashi Iwai 	if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3421f2e5731dSTakashi Iwai 	    is_int_mic(codec, cfg->inputs[1].pin)) {
3422f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
3423f2e5731dSTakashi Iwai 		spec->auto_mic_ext = 1;
3424f2e5731dSTakashi Iwai 		return;
3425f2e5731dSTakashi Iwai 	}
3426f2e5731dSTakashi Iwai 	if (is_int_mic(codec, cfg->inputs[1].pin) &&
3427f2e5731dSTakashi Iwai 	    is_ext_mic(codec, cfg->inputs[0].pin)) {
3428f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
3429f2e5731dSTakashi Iwai 		spec->auto_mic_ext = 0;
3430f2e5731dSTakashi Iwai 		return;
3431f2e5731dSTakashi Iwai 	}
3432f2e5731dSTakashi Iwai }
3433f2e5731dSTakashi Iwai 
3434f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3435f2e5731dSTakashi Iwai {
3436f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3437f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3438f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
3439f2e5731dSTakashi Iwai 	int i;
3440f2e5731dSTakashi Iwai 
3441f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3442f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3443f2e5731dSTakashi Iwai 		int idx = get_connection_index(codec, spec->adc_nids[0],
3444f2e5731dSTakashi Iwai 					       cfg->inputs[i].pin);
3445f2e5731dSTakashi Iwai 		if (idx >= 0) {
3446f2e5731dSTakashi Iwai 			const char *label;
3447f2e5731dSTakashi Iwai 			label = hda_get_autocfg_input_label(codec, cfg, i);
3448f2e5731dSTakashi Iwai 			snd_hda_add_imux_item(imux, label, idx, NULL);
3449f2e5731dSTakashi Iwai 		}
3450f2e5731dSTakashi Iwai 	}
3451f2e5731dSTakashi Iwai 	if (imux->num_items == 2 && cfg->num_inputs == 2)
3452f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
3453f2e5731dSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic)
3454f2e5731dSTakashi Iwai 		spec->input_mux = imux;
3455f2e5731dSTakashi Iwai }
3456f2e5731dSTakashi Iwai 
3457f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3458f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3459f2e5731dSTakashi Iwai {
3460f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3461f2e5731dSTakashi Iwai 
3462f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3463f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3464f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3465f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3466f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3467f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3468f2e5731dSTakashi Iwai 				return nid;
3469f2e5731dSTakashi Iwai 		}
3470f2e5731dSTakashi Iwai 	}
3471f2e5731dSTakashi Iwai 	return 0;
3472f2e5731dSTakashi Iwai }
3473f2e5731dSTakashi Iwai 
3474f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3475f2e5731dSTakashi Iwai {
3476f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3477f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3478f2e5731dSTakashi Iwai 	hda_nid_t nid;
3479f2e5731dSTakashi Iwai 
3480f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3481f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3482f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3483f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3484f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3485f2e5731dSTakashi Iwai }
3486f2e5731dSTakashi Iwai 
3487f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3488f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3489f2e5731dSTakashi Iwai {
3490f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3491f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3492f2e5731dSTakashi Iwai 
3493f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3494f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3495f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3496f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3497f2e5731dSTakashi Iwai 			break;
3498f2e5731dSTakashi Iwai 		}
3499f2e5731dSTakashi Iwai }
3500f2e5731dSTakashi Iwai #else
3501f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3502f2e5731dSTakashi Iwai #endif
3503f2e5731dSTakashi Iwai 
3504f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3505f2e5731dSTakashi Iwai {
3506f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3507f2e5731dSTakashi Iwai 	int err;
3508f2e5731dSTakashi Iwai 
3509f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3510f2e5731dSTakashi Iwai 	if (err < 0)
3511f2e5731dSTakashi Iwai 		return err;
3512f2e5731dSTakashi Iwai 
3513f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3514f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3515f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3516f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3517f2e5731dSTakashi Iwai 	return 0;
3518f2e5731dSTakashi Iwai }
3519f2e5731dSTakashi Iwai 
3520f2e5731dSTakashi Iwai static void cx_auto_turn_on_eapd(struct hda_codec *codec, int num_pins,
3521f2e5731dSTakashi Iwai 				 hda_nid_t *pins)
3522f2e5731dSTakashi Iwai {
3523f2e5731dSTakashi Iwai 	int i;
3524f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3525f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3526f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3527f2e5731dSTakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE, 0x02);
3528f2e5731dSTakashi Iwai 	}
3529f2e5731dSTakashi Iwai }
3530f2e5731dSTakashi Iwai 
3531f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3532f2e5731dSTakashi Iwai 			      hda_nid_t src)
3533f2e5731dSTakashi Iwai {
3534f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3535f2e5731dSTakashi Iwai 	if (idx >= 0)
3536f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3537f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3538f2e5731dSTakashi Iwai }
3539f2e5731dSTakashi Iwai 
3540f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
3541f2e5731dSTakashi Iwai {
3542f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3543f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3544f2e5731dSTakashi Iwai 	hda_nid_t nid;
3545f2e5731dSTakashi Iwai 	int i;
3546f2e5731dSTakashi Iwai 
3547f2e5731dSTakashi Iwai 	for (i = 0; i < spec->multiout.num_dacs; i++)
3548f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->multiout.dac_nids[i], 0,
3549f2e5731dSTakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
3550f2e5731dSTakashi Iwai 
3551f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
3552f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3553f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3554f2e5731dSTakashi Iwai 	if (spec->auto_mute) {
3555f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->hp_outs; i++) {
3556f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3557f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3558f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_HP_EVENT);
3559f2e5731dSTakashi Iwai 		}
3560f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3561f2e5731dSTakashi Iwai 	} else {
3562f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++)
3563f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3564f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3565f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->speaker_outs; i++)
3566f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3567f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3568f2e5731dSTakashi Iwai 	}
3569f2e5731dSTakashi Iwai 
3570f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3571f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
3572f2e5731dSTakashi Iwai 		if (!nid)
3573f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
3574f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
3575f2e5731dSTakashi Iwai 	}
3576f2e5731dSTakashi Iwai 
3577f2e5731dSTakashi Iwai 	/* turn on EAPD */
3578f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->line_outs, cfg->line_out_pins);
3579f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->hp_outs, cfg->hp_pins);
3580f2e5731dSTakashi Iwai 	cx_auto_turn_on_eapd(codec, cfg->speaker_outs, cfg->speaker_pins);
3581f2e5731dSTakashi Iwai }
3582f2e5731dSTakashi Iwai 
3583f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
3584f2e5731dSTakashi Iwai {
3585f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3586f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3587f2e5731dSTakashi Iwai 	int i;
3588f2e5731dSTakashi Iwai 
3589f2e5731dSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++)
3590f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3591f2e5731dSTakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0));
3592f2e5731dSTakashi Iwai 
3593f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3594f2e5731dSTakashi Iwai 		unsigned int type;
3595f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
3596f2e5731dSTakashi Iwai 			type = PIN_VREF80;
3597f2e5731dSTakashi Iwai 		else
3598f2e5731dSTakashi Iwai 			type = PIN_IN;
3599f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3600f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3601f2e5731dSTakashi Iwai 	}
3602f2e5731dSTakashi Iwai 
3603f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
3604f2e5731dSTakashi Iwai 		int ext_idx = spec->auto_mic_ext;
3605f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3606f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3607f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_MIC_EVENT);
3608f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3609f2e5731dSTakashi Iwai 	} else {
3610f2e5731dSTakashi Iwai 		for (i = 0; i < spec->num_adc_nids; i++) {
3611f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3612f2e5731dSTakashi Iwai 					    AC_VERB_SET_CONNECT_SEL,
3613f2e5731dSTakashi Iwai 					    spec->private_imux.items[0].index);
3614f2e5731dSTakashi Iwai 		}
3615f2e5731dSTakashi Iwai 	}
3616f2e5731dSTakashi Iwai }
3617f2e5731dSTakashi Iwai 
3618f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
3619f2e5731dSTakashi Iwai {
3620f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3621f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3622f2e5731dSTakashi Iwai 
3623f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
3624f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3625f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3626f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
3627f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3628f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3629f2e5731dSTakashi Iwai }
3630f2e5731dSTakashi Iwai 
3631f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
3632f2e5731dSTakashi Iwai {
3633f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3634f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
3635f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
3636f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
3637f2e5731dSTakashi Iwai 	return 0;
3638f2e5731dSTakashi Iwai }
3639f2e5731dSTakashi Iwai 
3640983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
3641f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
3642983345e5SDavid Henningsson 			      hda_nid_t nid, int hda_dir, int amp_idx)
3643f2e5731dSTakashi Iwai {
3644f2e5731dSTakashi Iwai 	static char name[32];
3645f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
3646f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
3647f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
3648f2e5731dSTakashi Iwai 	};
3649f2e5731dSTakashi Iwai 	static char *sfx[2] = { "Volume", "Switch" };
3650f2e5731dSTakashi Iwai 	int i, err;
3651f2e5731dSTakashi Iwai 
3652f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
3653f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
3654983345e5SDavid Henningsson 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3655983345e5SDavid Henningsson 							    hda_dir);
3656f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3657f2e5731dSTakashi Iwai 		knew[i].index = cidx;
3658f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3659f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
3660f2e5731dSTakashi Iwai 		if (!kctl)
3661f2e5731dSTakashi Iwai 			return -ENOMEM;
3662f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
3663f2e5731dSTakashi Iwai 		if (err < 0)
3664f2e5731dSTakashi Iwai 			return err;
3665f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3666f2e5731dSTakashi Iwai 			break;
3667f2e5731dSTakashi Iwai 	}
3668f2e5731dSTakashi Iwai 	return 0;
3669f2e5731dSTakashi Iwai }
3670f2e5731dSTakashi Iwai 
3671983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\
3672983345e5SDavid Henningsson 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3673983345e5SDavid Henningsson 
3674f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
3675f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3676f2e5731dSTakashi Iwai 
3677f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
3678f2e5731dSTakashi Iwai {
3679f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3680f2e5731dSTakashi Iwai 	int i, err;
3681f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
3682ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3683f2e5731dSTakashi Iwai 
3684f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
3685f2e5731dSTakashi Iwai 		return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3686f2e5731dSTakashi Iwai 					     "Master", 0);
3687f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3688f2e5731dSTakashi Iwai 		const char *label;
3689f2e5731dSTakashi Iwai 		int idx, type;
3690f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
3691f2e5731dSTakashi Iwai 			continue;
3692f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
3693f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
3694f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
3695f2e5731dSTakashi Iwai 		switch (type) {
3696f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3697f2e5731dSTakashi Iwai 		default:
3698f2e5731dSTakashi Iwai 			label = texts[num_line++];
3699f2e5731dSTakashi Iwai 			idx = 0;
3700f2e5731dSTakashi Iwai 			break;
3701f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3702f2e5731dSTakashi Iwai 			label = "Headphone";
3703f2e5731dSTakashi Iwai 			idx = num_hp++;
3704f2e5731dSTakashi Iwai 			break;
3705f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3706f2e5731dSTakashi Iwai 			label = "Speaker";
3707f2e5731dSTakashi Iwai 			idx = num_spk++;
3708f2e5731dSTakashi Iwai 			break;
3709f2e5731dSTakashi Iwai 		}
3710f2e5731dSTakashi Iwai 		err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3711f2e5731dSTakashi Iwai 					    label, idx);
3712f2e5731dSTakashi Iwai 		if (err < 0)
3713f2e5731dSTakashi Iwai 			return err;
3714f2e5731dSTakashi Iwai 	}
3715f2e5731dSTakashi Iwai 	return 0;
3716f2e5731dSTakashi Iwai }
3717f2e5731dSTakashi Iwai 
3718f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
3719f2e5731dSTakashi Iwai {
3720f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3721f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3722f2e5731dSTakashi Iwai 	static const char *prev_label;
3723983345e5SDavid Henningsson 	int i, err, cidx, conn_len;
3724983345e5SDavid Henningsson 	hda_nid_t conn[HDA_MAX_CONNECTIONS];
3725f2e5731dSTakashi Iwai 
3726983345e5SDavid Henningsson 	int multi_adc_volume = 0; /* If the ADC nid has several input volumes */
3727983345e5SDavid Henningsson 	int adc_nid = spec->adc_nids[0];
3728983345e5SDavid Henningsson 
3729983345e5SDavid Henningsson 	conn_len = snd_hda_get_connections(codec, adc_nid, conn,
3730983345e5SDavid Henningsson 					   HDA_MAX_CONNECTIONS);
3731983345e5SDavid Henningsson 	if (conn_len < 0)
3732983345e5SDavid Henningsson 		return conn_len;
3733983345e5SDavid Henningsson 
3734983345e5SDavid Henningsson 	multi_adc_volume = cfg->num_inputs > 1 && conn_len > 1;
3735983345e5SDavid Henningsson 	if (!multi_adc_volume) {
3736983345e5SDavid Henningsson 		err = cx_auto_add_volume(codec, "Capture", "", 0, adc_nid,
3737f2e5731dSTakashi Iwai 					 HDA_INPUT);
3738f2e5731dSTakashi Iwai 		if (err < 0)
3739f2e5731dSTakashi Iwai 			return err;
3740983345e5SDavid Henningsson 	}
3741983345e5SDavid Henningsson 
3742f2e5731dSTakashi Iwai 	prev_label = NULL;
3743f2e5731dSTakashi Iwai 	cidx = 0;
3744f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3745f2e5731dSTakashi Iwai 		hda_nid_t nid = cfg->inputs[i].pin;
3746f2e5731dSTakashi Iwai 		const char *label;
3747983345e5SDavid Henningsson 		int j;
3748983345e5SDavid Henningsson 		int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
3749983345e5SDavid Henningsson 		if (!pin_amp && !multi_adc_volume)
3750f2e5731dSTakashi Iwai 			continue;
3751983345e5SDavid Henningsson 
3752f2e5731dSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, cfg, i);
3753f2e5731dSTakashi Iwai 		if (label == prev_label)
3754f2e5731dSTakashi Iwai 			cidx++;
3755f2e5731dSTakashi Iwai 		else
3756f2e5731dSTakashi Iwai 			cidx = 0;
3757f2e5731dSTakashi Iwai 		prev_label = label;
3758983345e5SDavid Henningsson 
3759983345e5SDavid Henningsson 		if (pin_amp) {
3760983345e5SDavid Henningsson 			err = cx_auto_add_volume(codec, label, " Boost", cidx,
3761f2e5731dSTakashi Iwai 						 nid, HDA_INPUT);
3762f2e5731dSTakashi Iwai 			if (err < 0)
3763f2e5731dSTakashi Iwai 				return err;
3764f2e5731dSTakashi Iwai 		}
3765983345e5SDavid Henningsson 
3766983345e5SDavid Henningsson 		if (!multi_adc_volume)
3767983345e5SDavid Henningsson 			continue;
3768983345e5SDavid Henningsson 		for (j = 0; j < conn_len; j++) {
3769983345e5SDavid Henningsson 			if (conn[j] == nid) {
3770983345e5SDavid Henningsson 				err = cx_auto_add_volume_idx(codec, label,
3771983345e5SDavid Henningsson 				    " Capture", cidx, adc_nid, HDA_INPUT, j);
3772983345e5SDavid Henningsson 				if (err < 0)
3773983345e5SDavid Henningsson 					return err;
3774983345e5SDavid Henningsson 				break;
3775983345e5SDavid Henningsson 			}
3776983345e5SDavid Henningsson 		}
3777983345e5SDavid Henningsson 	}
3778f2e5731dSTakashi Iwai 	return 0;
3779f2e5731dSTakashi Iwai }
3780f2e5731dSTakashi Iwai 
3781f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
3782f2e5731dSTakashi Iwai {
3783f2e5731dSTakashi Iwai 	int err;
3784f2e5731dSTakashi Iwai 
3785f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
3786f2e5731dSTakashi Iwai 	if (err < 0)
3787f2e5731dSTakashi Iwai 		return err;
3788f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
3789f2e5731dSTakashi Iwai 	if (err < 0)
3790f2e5731dSTakashi Iwai 		return err;
3791f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
3792f2e5731dSTakashi Iwai }
3793f2e5731dSTakashi Iwai 
3794f2e5731dSTakashi Iwai static struct hda_codec_ops cx_auto_patch_ops = {
3795f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
3796f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
3797f2e5731dSTakashi Iwai 	.init = cx_auto_init,
3798f2e5731dSTakashi Iwai 	.free = conexant_free,
3799f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
3800f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3801f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
3802f2e5731dSTakashi Iwai #endif
3803f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
3804f2e5731dSTakashi Iwai };
3805f2e5731dSTakashi Iwai 
3806f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3807f2e5731dSTakashi Iwai {
3808f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3809f2e5731dSTakashi Iwai 	int err;
3810f2e5731dSTakashi Iwai 
3811f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3812f2e5731dSTakashi Iwai 	if (!spec)
3813f2e5731dSTakashi Iwai 		return -ENOMEM;
3814f2e5731dSTakashi Iwai 	codec->spec = spec;
3815f2e5731dSTakashi Iwai 	spec->adc_nids = cx_auto_adc_nids;
3816f2e5731dSTakashi Iwai 	spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3817f2e5731dSTakashi Iwai 	spec->capsrc_nids = spec->adc_nids;
3818f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
3819f2e5731dSTakashi Iwai 	if (err < 0) {
3820f2e5731dSTakashi Iwai 		kfree(codec->spec);
3821f2e5731dSTakashi Iwai 		codec->spec = NULL;
3822f2e5731dSTakashi Iwai 		return err;
3823f2e5731dSTakashi Iwai 	}
3824f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
3825f2e5731dSTakashi Iwai 	if (spec->beep_amp)
3826f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
3827f2e5731dSTakashi Iwai 	return 0;
3828f2e5731dSTakashi Iwai }
3829f2e5731dSTakashi Iwai 
3830f2e5731dSTakashi Iwai /*
3831461e2c78STakashi Iwai  */
3832461e2c78STakashi Iwai 
38331289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
383482f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
383582f30040STobin Davis 	  .patch = patch_cxt5045 },
383682f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
383782f30040STobin Davis 	  .patch = patch_cxt5047 },
3838461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3839461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
38400fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
38410fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
384295a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
384395a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3844850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3845850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
38467b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
38477b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
38486da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
38496da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
3850f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
3851f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3852f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
3853f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3854f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
3855f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3856f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
3857f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3858f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
3859f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3860f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
3861f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3862f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
3863f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3864f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
3865f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3866c9b443d4STobin Davis 	{} /* terminator */
3867c9b443d4STobin Davis };
38681289e9e8STakashi Iwai 
38691289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
38701289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
38711289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
38720fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
387395a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3874850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
38757b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
38766da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
3877f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
3878f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
3879f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3880f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3881f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3882f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3883f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3884f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
38851289e9e8STakashi Iwai 
38861289e9e8STakashi Iwai MODULE_LICENSE("GPL");
38871289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
38881289e9e8STakashi Iwai 
38891289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
38901289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
38911289e9e8STakashi Iwai 	.owner = THIS_MODULE,
38921289e9e8STakashi Iwai };
38931289e9e8STakashi Iwai 
38941289e9e8STakashi Iwai static int __init patch_conexant_init(void)
38951289e9e8STakashi Iwai {
38961289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
38971289e9e8STakashi Iwai }
38981289e9e8STakashi Iwai 
38991289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
39001289e9e8STakashi Iwai {
39011289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
39021289e9e8STakashi Iwai }
39031289e9e8STakashi Iwai 
39041289e9e8STakashi Iwai module_init(patch_conexant_init)
39051289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3906