xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision a3a85d3983f7e18c46fba9f92c21d8a713de9791)
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 
5847ad1f4eSTakashi Iwai struct imux_info {
5947ad1f4eSTakashi Iwai 	hda_nid_t pin;		/* input pin NID */
6047ad1f4eSTakashi Iwai 	hda_nid_t adc;		/* connected ADC NID */
6147ad1f4eSTakashi Iwai 	hda_nid_t boost;	/* optional boost volume NID */
6247ad1f4eSTakashi Iwai 	int index;		/* corresponding to autocfg.input */
6347ad1f4eSTakashi Iwai };
6447ad1f4eSTakashi Iwai 
65c9b443d4STobin Davis struct conexant_spec {
66c9b443d4STobin Davis 
6734cbe3a6STakashi Iwai 	const struct snd_kcontrol_new *mixers[5];
68c9b443d4STobin Davis 	int num_mixers;
69dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
70c9b443d4STobin Davis 
71c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
72c9b443d4STobin Davis 						 * don't forget NULL
73c9b443d4STobin Davis 						 * termination!
74c9b443d4STobin Davis 						 */
75c9b443d4STobin Davis 	unsigned int num_init_verbs;
76c9b443d4STobin Davis 
77c9b443d4STobin Davis 	/* playback */
78c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
79c9b443d4STobin Davis 					 * max_channels, dacs must be set
80c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
81c9b443d4STobin Davis 					 */
82c9b443d4STobin Davis 	unsigned int cur_eapd;
8382f30040STobin Davis 	unsigned int hp_present;
84faddaa5dSTakashi Iwai 	unsigned int auto_mic;
85f6100bb4STakashi Iwai 	int auto_mic_ext;		/* imux_pins[] index for ext mic */
86c9b443d4STobin Davis 	unsigned int need_dac_fix;
87f6a2491cSAndy Robinson 	hda_nid_t slave_dig_outs[2];
88c9b443d4STobin Davis 
89c9b443d4STobin Davis 	/* capture */
90c9b443d4STobin Davis 	unsigned int num_adc_nids;
9134cbe3a6STakashi Iwai 	const hda_nid_t *adc_nids;
92c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
93c9b443d4STobin Davis 
94461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
95461e2c78STakashi Iwai 	hda_nid_t cur_adc;
96461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
97461e2c78STakashi Iwai 	unsigned int cur_adc_format;
98461e2c78STakashi Iwai 
996764bcefSTakashi Iwai 	const struct hda_pcm_stream *capture_stream;
1006764bcefSTakashi Iwai 
101c9b443d4STobin Davis 	/* capture source */
102c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
10334cbe3a6STakashi Iwai 	const hda_nid_t *capsrc_nids;
104c9b443d4STobin Davis 	unsigned int cur_mux[3];
105c9b443d4STobin Davis 
106c9b443d4STobin Davis 	/* channel model */
107c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
108c9b443d4STobin Davis 	int num_channel_mode;
109c9b443d4STobin Davis 
110c9b443d4STobin Davis 	/* PCM information */
111c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
112c9b443d4STobin Davis 
113c9b443d4STobin Davis 	unsigned int spdif_route;
114c9b443d4STobin Davis 
115c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
116c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
117c9b443d4STobin Davis 	struct hda_input_mux private_imux;
11847ad1f4eSTakashi Iwai 	struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
11922ce5f74STakashi Iwai 	hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
12041923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
121f2e5731dSTakashi Iwai 	struct pin_dac_pair dac_info[8];
122f2e5731dSTakashi Iwai 	int dac_info_filled;
123c9b443d4STobin Davis 
1240fb67e98SDaniel Drake 	unsigned int port_d_mode;
125f2e5731dSTakashi Iwai 	unsigned int auto_mute:1;	/* used in auto-parser */
126f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
127cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
128cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1297b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
130048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
131a1d6906eSDavid Henningsson 	unsigned int asus:1;
13275f8991dSDaniel Drake 
1336764bcefSTakashi Iwai 	unsigned int adc_switching:1;
1346764bcefSTakashi Iwai 
13575f8991dSDaniel Drake 	unsigned int ext_mic_present;
13675f8991dSDaniel Drake 	unsigned int recording;
13775f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
13875f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
139c4cfe66cSDaniel Drake 
140c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
141c4cfe66cSDaniel Drake 	 * through the microphone jack.
142c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
143c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
144c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
145c4cfe66cSDaniel Drake 	 * control. */
146c4cfe66cSDaniel Drake 	unsigned int dc_enable;
147c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
148c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1493507e2a8STakashi Iwai 
1503507e2a8STakashi Iwai 	unsigned int beep_amp;
151c9b443d4STobin Davis };
152c9b443d4STobin Davis 
153c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
154c9b443d4STobin Davis 				      struct hda_codec *codec,
155c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
156c9b443d4STobin Davis {
157c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1589a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1599a08160bSTakashi Iwai 					     hinfo);
160c9b443d4STobin Davis }
161c9b443d4STobin Davis 
162c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
163c9b443d4STobin Davis 					 struct hda_codec *codec,
164c9b443d4STobin Davis 					 unsigned int stream_tag,
165c9b443d4STobin Davis 					 unsigned int format,
166c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
167c9b443d4STobin Davis {
168c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
169c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
170c9b443d4STobin Davis 						stream_tag,
171c9b443d4STobin Davis 						format, substream);
172c9b443d4STobin Davis }
173c9b443d4STobin Davis 
174c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
175c9b443d4STobin Davis 					 struct hda_codec *codec,
176c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
177c9b443d4STobin Davis {
178c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
179c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
180c9b443d4STobin Davis }
181c9b443d4STobin Davis 
182c9b443d4STobin Davis /*
183c9b443d4STobin Davis  * Digital out
184c9b443d4STobin Davis  */
185c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
186c9b443d4STobin Davis 					  struct hda_codec *codec,
187c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
188c9b443d4STobin Davis {
189c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
190c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
191c9b443d4STobin Davis }
192c9b443d4STobin Davis 
193c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
194c9b443d4STobin Davis 					 struct hda_codec *codec,
195c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
196c9b443d4STobin Davis {
197c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
198c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
199c9b443d4STobin Davis }
200c9b443d4STobin Davis 
2016b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2026b97eb45STakashi Iwai 					 struct hda_codec *codec,
2036b97eb45STakashi Iwai 					 unsigned int stream_tag,
2046b97eb45STakashi Iwai 					 unsigned int format,
2056b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
2066b97eb45STakashi Iwai {
2076b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2086b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2096b97eb45STakashi Iwai 					     stream_tag,
2106b97eb45STakashi Iwai 					     format, substream);
2116b97eb45STakashi Iwai }
2126b97eb45STakashi Iwai 
213c9b443d4STobin Davis /*
214c9b443d4STobin Davis  * Analog capture
215c9b443d4STobin Davis  */
216c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
217c9b443d4STobin Davis 				      struct hda_codec *codec,
218c9b443d4STobin Davis 				      unsigned int stream_tag,
219c9b443d4STobin Davis 				      unsigned int format,
220c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
221c9b443d4STobin Davis {
222c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
22375f8991dSDaniel Drake 	if (spec->capture_prepare)
22475f8991dSDaniel Drake 		spec->capture_prepare(codec);
225c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
226c9b443d4STobin Davis 				   stream_tag, 0, format);
227c9b443d4STobin Davis 	return 0;
228c9b443d4STobin Davis }
229c9b443d4STobin Davis 
230c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
231c9b443d4STobin Davis 				      struct hda_codec *codec,
232c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
233c9b443d4STobin Davis {
234c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
235888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
23675f8991dSDaniel Drake 	if (spec->capture_cleanup)
23775f8991dSDaniel Drake 		spec->capture_cleanup(codec);
238c9b443d4STobin Davis 	return 0;
239c9b443d4STobin Davis }
240c9b443d4STobin Davis 
241c9b443d4STobin Davis 
242c9b443d4STobin Davis 
24334cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = {
244c9b443d4STobin Davis 	.substreams = 1,
245c9b443d4STobin Davis 	.channels_min = 2,
246c9b443d4STobin Davis 	.channels_max = 2,
247c9b443d4STobin Davis 	.nid = 0, /* fill later */
248c9b443d4STobin Davis 	.ops = {
249c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
250c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
251c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
252c9b443d4STobin Davis 	},
253c9b443d4STobin Davis };
254c9b443d4STobin Davis 
25534cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = {
256c9b443d4STobin Davis 	.substreams = 1,
257c9b443d4STobin Davis 	.channels_min = 2,
258c9b443d4STobin Davis 	.channels_max = 2,
259c9b443d4STobin Davis 	.nid = 0, /* fill later */
260c9b443d4STobin Davis 	.ops = {
261c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
262c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
263c9b443d4STobin Davis 	},
264c9b443d4STobin Davis };
265c9b443d4STobin Davis 
266c9b443d4STobin Davis 
26734cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = {
268c9b443d4STobin Davis 	.substreams = 1,
269c9b443d4STobin Davis 	.channels_min = 2,
270c9b443d4STobin Davis 	.channels_max = 2,
271c9b443d4STobin Davis 	.nid = 0, /* fill later */
272c9b443d4STobin Davis 	.ops = {
273c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2746b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2756b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
276c9b443d4STobin Davis 	},
277c9b443d4STobin Davis };
278c9b443d4STobin Davis 
27934cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = {
280c9b443d4STobin Davis 	.substreams = 1,
281c9b443d4STobin Davis 	.channels_min = 2,
282c9b443d4STobin Davis 	.channels_max = 2,
283c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
284c9b443d4STobin Davis };
285c9b443d4STobin Davis 
286461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
287461e2c78STakashi Iwai 				      struct hda_codec *codec,
288461e2c78STakashi Iwai 				      unsigned int stream_tag,
289461e2c78STakashi Iwai 				      unsigned int format,
290461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
291461e2c78STakashi Iwai {
292461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
293461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
294461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
295461e2c78STakashi Iwai 	spec->cur_adc_format = format;
296461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
297461e2c78STakashi Iwai 	return 0;
298461e2c78STakashi Iwai }
299461e2c78STakashi Iwai 
300461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
301461e2c78STakashi Iwai 				      struct hda_codec *codec,
302461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
303461e2c78STakashi Iwai {
304461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
305888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
306461e2c78STakashi Iwai 	spec->cur_adc = 0;
307461e2c78STakashi Iwai 	return 0;
308461e2c78STakashi Iwai }
309461e2c78STakashi Iwai 
31034cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
311461e2c78STakashi Iwai 	.substreams = 1,
312461e2c78STakashi Iwai 	.channels_min = 2,
313461e2c78STakashi Iwai 	.channels_max = 2,
314461e2c78STakashi Iwai 	.nid = 0, /* fill later */
315461e2c78STakashi Iwai 	.ops = {
316461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
317461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
318461e2c78STakashi Iwai 	},
319461e2c78STakashi Iwai };
320461e2c78STakashi Iwai 
321c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
322c9b443d4STobin Davis {
323c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
324c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
325c9b443d4STobin Davis 
326c9b443d4STobin Davis 	codec->num_pcms = 1;
327c9b443d4STobin Davis 	codec->pcm_info = info;
328c9b443d4STobin Davis 
329c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
330c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
331c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
332c9b443d4STobin Davis 		spec->multiout.max_channels;
333c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
334c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
3356764bcefSTakashi Iwai 	if (spec->capture_stream)
3366764bcefSTakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
3376764bcefSTakashi Iwai 	else {
338461e2c78STakashi Iwai 		if (codec->vendor_id == 0x14f15051)
339461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
340461e2c78STakashi Iwai 				cx5051_pcm_analog_capture;
3416764bcefSTakashi Iwai 		else {
342461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
343461e2c78STakashi Iwai 				conexant_pcm_analog_capture;
3446764bcefSTakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3456764bcefSTakashi Iwai 				spec->num_adc_nids;
3466764bcefSTakashi Iwai 		}
3476764bcefSTakashi Iwai 	}
348c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
349c9b443d4STobin Davis 
350c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
351c9b443d4STobin Davis 		info++;
352c9b443d4STobin Davis 		codec->num_pcms++;
353c9b443d4STobin Davis 		info->name = "Conexant Digital";
3547ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
355c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
356c9b443d4STobin Davis 			conexant_pcm_digital_playback;
357c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
358c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
359c9b443d4STobin Davis 		if (spec->dig_in_nid) {
360c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
361c9b443d4STobin Davis 				conexant_pcm_digital_capture;
362c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
363c9b443d4STobin Davis 				spec->dig_in_nid;
364c9b443d4STobin Davis 		}
365f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
366f6a2491cSAndy Robinson 			codec->slave_dig_outs = spec->slave_dig_outs;
367c9b443d4STobin Davis 	}
368c9b443d4STobin Davis 
369c9b443d4STobin Davis 	return 0;
370c9b443d4STobin Davis }
371c9b443d4STobin Davis 
372c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
373c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
374c9b443d4STobin Davis {
375c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
376c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
377c9b443d4STobin Davis 
378c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
379c9b443d4STobin Davis }
380c9b443d4STobin Davis 
381c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
382c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
383c9b443d4STobin Davis {
384c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
385c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
386c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
387c9b443d4STobin Davis 
388c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
389c9b443d4STobin Davis 	return 0;
390c9b443d4STobin Davis }
391c9b443d4STobin Davis 
392c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
393c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
394c9b443d4STobin Davis {
395c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
397c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
398c9b443d4STobin Davis 
399c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
400c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
401c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
402c9b443d4STobin Davis }
403c9b443d4STobin Davis 
404bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
405bc7a166dSUlrich Dangel {
406cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
407bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
408bc7a166dSUlrich Dangel 	int i;
409bc7a166dSUlrich Dangel 
410bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
411bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
412bc7a166dSUlrich Dangel 
413bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
414bc7a166dSUlrich Dangel 		while (hv->nid) {
415bc7a166dSUlrich Dangel 			int err = 0;
416bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
417bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
418cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
419cd372fb3STakashi Iwai 						SND_JACK_HEADPHONE, NULL);
420cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
421bc7a166dSUlrich Dangel 				break;
422bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
423bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
424cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
425cd372fb3STakashi Iwai 						SND_JACK_MICROPHONE, NULL);
426cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
427bc7a166dSUlrich Dangel 				break;
428bc7a166dSUlrich Dangel 			}
429bc7a166dSUlrich Dangel 			if (err < 0)
430bc7a166dSUlrich Dangel 				return err;
431bc7a166dSUlrich Dangel 			++hv;
432bc7a166dSUlrich Dangel 		}
433bc7a166dSUlrich Dangel 	}
434cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */
4355801f992STakashi Iwai 	return 0;
4365801f992STakashi Iwai }
437bc7a166dSUlrich Dangel 
438c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
439c9b443d4STobin Davis {
440c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
441c9b443d4STobin Davis 	int i;
442c9b443d4STobin Davis 
443c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
444c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
445c9b443d4STobin Davis 	return 0;
446c9b443d4STobin Davis }
447c9b443d4STobin Davis 
448c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
449c9b443d4STobin Davis {
450cd372fb3STakashi Iwai 	snd_hda_input_jack_free(codec);
451c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
452c9b443d4STobin Davis 	kfree(codec->spec);
453c9b443d4STobin Davis }
454c9b443d4STobin Davis 
45534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = {
456b880c74aSTakashi Iwai 	{
457b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
458b880c74aSTakashi Iwai 		.name = "Capture Source",
459b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
460b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
461b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
462b880c74aSTakashi Iwai 	},
463b880c74aSTakashi Iwai 	{}
464b880c74aSTakashi Iwai };
465b880c74aSTakashi Iwai 
4663507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
4673507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
46834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = {
4693507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
4703507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
4713507e2a8STakashi Iwai 	{ } /* end */
4723507e2a8STakashi Iwai };
4733507e2a8STakashi Iwai #endif
4743507e2a8STakashi Iwai 
475ea734963STakashi Iwai static const char * const slave_vols[] = {
476dd5746a8STakashi Iwai 	"Headphone Playback Volume",
477dd5746a8STakashi Iwai 	"Speaker Playback Volume",
478*a3a85d39STakashi Iwai 	"Front Playback Volume",
479*a3a85d39STakashi Iwai 	"Surround Playback Volume",
480*a3a85d39STakashi Iwai 	"CLFE Playback Volume",
481dd5746a8STakashi Iwai 	NULL
482dd5746a8STakashi Iwai };
483dd5746a8STakashi Iwai 
484ea734963STakashi Iwai static const char * const slave_sws[] = {
485dd5746a8STakashi Iwai 	"Headphone Playback Switch",
486dd5746a8STakashi Iwai 	"Speaker Playback Switch",
487*a3a85d39STakashi Iwai 	"Front Playback Switch",
488*a3a85d39STakashi Iwai 	"Surround Playback Switch",
489*a3a85d39STakashi Iwai 	"CLFE Playback Switch",
490dd5746a8STakashi Iwai 	NULL
491dd5746a8STakashi Iwai };
492dd5746a8STakashi Iwai 
493c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
494c9b443d4STobin Davis {
495c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
496c9b443d4STobin Davis 	unsigned int i;
497c9b443d4STobin Davis 	int err;
498c9b443d4STobin Davis 
499c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
500c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
501c9b443d4STobin Davis 		if (err < 0)
502c9b443d4STobin Davis 			return err;
503c9b443d4STobin Davis 	}
504c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
505c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
506c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
507c9b443d4STobin Davis 		if (err < 0)
508c9b443d4STobin Davis 			return err;
5099a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5109a08160bSTakashi Iwai 						    &spec->multiout);
5119a08160bSTakashi Iwai 		if (err < 0)
5129a08160bSTakashi Iwai 			return err;
5139a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
514c9b443d4STobin Davis 	}
515c9b443d4STobin Davis 	if (spec->dig_in_nid) {
516c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
517c9b443d4STobin Davis 		if (err < 0)
518c9b443d4STobin Davis 			return err;
519c9b443d4STobin Davis 	}
520dd5746a8STakashi Iwai 
521dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
522dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
523dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
524dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
525dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
526dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
527dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
528dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
529dd5746a8STakashi Iwai 		if (err < 0)
530dd5746a8STakashi Iwai 			return err;
531dd5746a8STakashi Iwai 	}
532dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
533dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
534dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
535dd5746a8STakashi Iwai 					  NULL, slave_sws);
536dd5746a8STakashi Iwai 		if (err < 0)
537dd5746a8STakashi Iwai 			return err;
538dd5746a8STakashi Iwai 	}
539dd5746a8STakashi Iwai 
540b880c74aSTakashi Iwai 	if (spec->input_mux) {
541b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
542b880c74aSTakashi Iwai 		if (err < 0)
543b880c74aSTakashi Iwai 			return err;
544b880c74aSTakashi Iwai 	}
545b880c74aSTakashi Iwai 
5463507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5473507e2a8STakashi Iwai 	/* create beep controls if needed */
5483507e2a8STakashi Iwai 	if (spec->beep_amp) {
54934cbe3a6STakashi Iwai 		const struct snd_kcontrol_new *knew;
5503507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
5513507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
5523507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
5533507e2a8STakashi Iwai 			if (!kctl)
5543507e2a8STakashi Iwai 				return -ENOMEM;
5553507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
5563507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
5573507e2a8STakashi Iwai 			if (err < 0)
5583507e2a8STakashi Iwai 				return err;
5593507e2a8STakashi Iwai 		}
5603507e2a8STakashi Iwai 	}
5613507e2a8STakashi Iwai #endif
5623507e2a8STakashi Iwai 
563c9b443d4STobin Davis 	return 0;
564c9b443d4STobin Davis }
565c9b443d4STobin Davis 
566697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
567697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
568697c373eSTakashi Iwai {
569697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
570697c373eSTakashi Iwai 	return 0;
571697c373eSTakashi Iwai }
572697c373eSTakashi Iwai #endif
573697c373eSTakashi Iwai 
57434cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = {
575c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
576c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
577c9b443d4STobin Davis 	.init = conexant_init,
578c9b443d4STobin Davis 	.free = conexant_free,
579697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
580697c373eSTakashi Iwai 	.suspend = conexant_suspend,
581697c373eSTakashi Iwai #endif
582697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
583c9b443d4STobin Davis };
584c9b443d4STobin Davis 
5853507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5863507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
5873507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
5883507e2a8STakashi Iwai #else
5893507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5903507e2a8STakashi Iwai #endif
5913507e2a8STakashi Iwai 
5926764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec);
593c9b443d4STobin Davis /*
594c9b443d4STobin Davis  * EAPD control
595c9b443d4STobin Davis  * the private value = nid | (invert << 8)
596c9b443d4STobin Davis  */
597c9b443d4STobin Davis 
598a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
599c9b443d4STobin Davis 
60082f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
601c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
602c9b443d4STobin Davis {
603c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
605c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
606c9b443d4STobin Davis 	if (invert)
607c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
608c9b443d4STobin Davis 	else
609c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
610c9b443d4STobin Davis 	return 0;
61182f30040STobin Davis 
612c9b443d4STobin Davis }
613c9b443d4STobin Davis 
61482f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
615c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
616c9b443d4STobin Davis {
617c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
619c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
620c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
621c9b443d4STobin Davis 	unsigned int eapd;
62282f30040STobin Davis 
62368ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
624c9b443d4STobin Davis 	if (invert)
625c9b443d4STobin Davis 		eapd = !eapd;
62682beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
627c9b443d4STobin Davis 		return 0;
62882f30040STobin Davis 
629c9b443d4STobin Davis 	spec->cur_eapd = eapd;
63082beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
631c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
632c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
633c9b443d4STobin Davis 	return 1;
634c9b443d4STobin Davis }
635c9b443d4STobin Davis 
63686d72bdfSTakashi Iwai /* controls for test mode */
63786d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
63886d72bdfSTakashi Iwai 
63982f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
64082f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
64182f30040STobin Davis 	  .info = cxt_eapd_info, \
64282f30040STobin Davis 	  .get = cxt_eapd_get, \
64382f30040STobin Davis 	  .put = cxt_eapd_put, \
64482f30040STobin Davis 	  .private_value = nid | (mask<<16) }
64582f30040STobin Davis 
64682f30040STobin Davis 
64782f30040STobin Davis 
648c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
649c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
650c9b443d4STobin Davis {
651c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
653c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
654c9b443d4STobin Davis 				    spec->num_channel_mode);
655c9b443d4STobin Davis }
656c9b443d4STobin Davis 
657c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
658c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
659c9b443d4STobin Davis {
660c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
662c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
663c9b443d4STobin Davis 				   spec->num_channel_mode,
664c9b443d4STobin Davis 				   spec->multiout.max_channels);
665c9b443d4STobin Davis }
666c9b443d4STobin Davis 
667c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
668c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
669c9b443d4STobin Davis {
670c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
672c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
673c9b443d4STobin Davis 				      spec->num_channel_mode,
674c9b443d4STobin Davis 				      &spec->multiout.max_channels);
675c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
676c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
677c9b443d4STobin Davis 	return err;
678c9b443d4STobin Davis }
679c9b443d4STobin Davis 
680c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
681c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
682c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
683c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
684c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
685c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
686c9b443d4STobin Davis 
68786d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
68886d72bdfSTakashi Iwai 
689c9b443d4STobin Davis /* Conexant 5045 specific */
690c9b443d4STobin Davis 
69134cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
69234cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
69334cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
694cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
695c9b443d4STobin Davis 
69634cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = {
6975cd57529STobin Davis 	{ 2, NULL },
6985cd57529STobin Davis };
699c9b443d4STobin Davis 
70034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = {
701c9b443d4STobin Davis 	.num_items = 2,
702c9b443d4STobin Davis 	.items = {
70382f30040STobin Davis 		{ "IntMic", 0x1 },
704f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
705c9b443d4STobin Davis 	}
706c9b443d4STobin Davis };
707c9b443d4STobin Davis 
70834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = {
70922e14130SLukasz Marcinowski 	.num_items = 5,
7105218c892SJiang Zhe 	.items = {
7115218c892SJiang Zhe 		{ "IntMic", 0x1 },
7125218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7135218c892SJiang Zhe 		{ "LineIn", 0x3 },
71422e14130SLukasz Marcinowski 		{ "CD",     0x4 },
71522e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7165218c892SJiang Zhe 	}
7175218c892SJiang Zhe };
7185218c892SJiang Zhe 
71934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = {
7202de3c232SJiang zhe 	.num_items = 2,
7212de3c232SJiang zhe 	.items = {
7222de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7232de3c232SJiang zhe 		{ "IntMic", 0x2 },
7242de3c232SJiang zhe 	}
7252de3c232SJiang zhe };
7262de3c232SJiang zhe 
727c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
728c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
730c9b443d4STobin Davis {
731c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
73382f30040STobin Davis 	unsigned int bits;
734c9b443d4STobin Davis 
73582f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
736c9b443d4STobin Davis 		return 0;
737c9b443d4STobin Davis 
73882f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
73982f30040STobin Davis 	 * the headphone jack
74082f30040STobin Davis 	 */
74147fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
74247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
74347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7447f29673bSTobin Davis 
74547fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
74647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
74747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
748c9b443d4STobin Davis 	return 1;
749c9b443d4STobin Davis }
750c9b443d4STobin Davis 
751c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
75234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
753cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
754cca3b371STakashi Iwai 	.values = {
755cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
756cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
757cca3b371STakashi Iwai 		0
758cca3b371STakashi Iwai 	},
759cca3b371STakashi Iwai };
760c9b443d4STobin Davis 
7617f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7627f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7637f29673bSTobin Davis {
76434cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
7657f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7667f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7677f29673bSTobin Davis 		{}
7687f29673bSTobin Davis 	};
76934cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
7707f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7717f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7727f29673bSTobin Davis 		{}
7737f29673bSTobin Davis 	};
7747f29673bSTobin Davis 	unsigned int present;
7757f29673bSTobin Davis 
776d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7777f29673bSTobin Davis 	if (present)
7787f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7797f29673bSTobin Davis 	else
7807f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7817f29673bSTobin Davis }
7827f29673bSTobin Davis 
783c9b443d4STobin Davis 
784c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
785c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
786c9b443d4STobin Davis {
78782f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
788dd87da1cSTobin Davis 	unsigned int bits;
789c9b443d4STobin Davis 
790d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
791dd87da1cSTobin Davis 
79247fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
79347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
79447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
795c9b443d4STobin Davis }
796c9b443d4STobin Davis 
797c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
798c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
799c9b443d4STobin Davis 				   unsigned int res)
800c9b443d4STobin Davis {
801c9b443d4STobin Davis 	res >>= 26;
802c9b443d4STobin Davis 	switch (res) {
803c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
804c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
805c9b443d4STobin Davis 		break;
8067f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8077f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8087f29673bSTobin Davis 		break;
8097f29673bSTobin Davis 
810c9b443d4STobin Davis 	}
811c9b443d4STobin Davis }
812c9b443d4STobin Davis 
81334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = {
81428c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
81528c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8168607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8178607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
818c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
819c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
82028c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
82128c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8228607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8238607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
824cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
825c9b443d4STobin Davis 	{
826c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
827c9b443d4STobin Davis 		.name = "Master Playback Switch",
82882f30040STobin Davis 		.info = cxt_eapd_info,
82982f30040STobin Davis 		.get = cxt_eapd_get,
830c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
83182f30040STobin Davis 		.private_value = 0x10,
832c9b443d4STobin Davis 	},
833c9b443d4STobin Davis 
834c9b443d4STobin Davis 	{}
835c9b443d4STobin Davis };
836c9b443d4STobin Davis 
83734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
83822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
83922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
84022e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
84122e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
84222e14130SLukasz Marcinowski 
8435218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8445218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8455218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8465218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8475218c892SJiang Zhe 
84822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
84922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
85022e14130SLukasz Marcinowski 
8515218c892SJiang Zhe 	{}
8525218c892SJiang Zhe };
8535218c892SJiang Zhe 
85434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
85528c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
85628c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8578607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8588607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8592de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8602de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
86128c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
86228c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8638607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8648607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8652de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8662de3c232SJiang zhe 	{
8672de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8682de3c232SJiang zhe 		.name = "Master Playback Switch",
8692de3c232SJiang zhe 		.info = cxt_eapd_info,
8702de3c232SJiang zhe 		.get = cxt_eapd_get,
8712de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8722de3c232SJiang zhe 		.private_value = 0x10,
8732de3c232SJiang zhe 	},
8742de3c232SJiang zhe 
8752de3c232SJiang zhe 	{}
8762de3c232SJiang zhe };
8772de3c232SJiang zhe 
87834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = {
879c9b443d4STobin Davis 	/* Line in, Mic */
8804090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8817f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
882c9b443d4STobin Davis 	/* HP, Amp  */
883c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
88582f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
886c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
887c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
888c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
889c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
890c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
891c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
89228c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
8937f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
89482f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
895c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
896c9b443d4STobin Davis 	/* SPDIF route: PCM */
897cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
898c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
899c9b443d4STobin Davis 	/* EAPD */
90082f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
901c9b443d4STobin Davis 	{ } /* end */
902c9b443d4STobin Davis };
903c9b443d4STobin Davis 
90434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = {
90528c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
9065218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9075218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9085218c892SJiang Zhe 	/* Line In,HP, Amp  */
9095218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9105218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9115218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9125218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9135218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9145218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9155218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9165218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9175218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
91828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9195218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9205218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9215218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9225218c892SJiang Zhe 	/* SPDIF route: PCM */
923cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9245218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9255218c892SJiang Zhe 	/* EAPD */
9265218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9275218c892SJiang Zhe 	{ } /* end */
9285218c892SJiang Zhe };
9297f29673bSTobin Davis 
93034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9317f29673bSTobin Davis 	/* pin sensing on HP jack */
9327f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
933d3091fadSTakashi Iwai 	{ } /* end */
9347f29673bSTobin Davis };
9357f29673bSTobin Davis 
93634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9377f29673bSTobin Davis 	/* pin sensing on HP jack */
9387f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
939d3091fadSTakashi Iwai 	{ } /* end */
9407f29673bSTobin Davis };
9417f29673bSTobin Davis 
942c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
943c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
944c9b443d4STobin Davis  * configuration.
945c9b443d4STobin Davis  */
94634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = {
947c9b443d4STobin Davis 	.num_items = 5,
948c9b443d4STobin Davis 	.items = {
949c9b443d4STobin Davis 		{ "MIXER", 0x0 },
950c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
951c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
952c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
953c9b443d4STobin Davis 		{ "CD pin", 0x4 },
954c9b443d4STobin Davis         },
955c9b443d4STobin Davis };
956c9b443d4STobin Davis 
95734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
958c9b443d4STobin Davis 
959c9b443d4STobin Davis 	/* Output controls */
960c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
961c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9627f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9637f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9647f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9657f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
966c9b443d4STobin Davis 
967c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
968c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
969c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
970c9b443d4STobin Davis 
97182f30040STobin Davis 	/* EAPD Switch Control */
97282f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
97382f30040STobin Davis 
974c9b443d4STobin Davis 	/* Loopback mixer controls */
975c9b443d4STobin Davis 
9767f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9777f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9787f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9797f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9807f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9817f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9827f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9837f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9847f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9857f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
986c9b443d4STobin Davis 	{
987c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
988c9b443d4STobin Davis 		.name = "Input Source",
989c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
990c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
991c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
992c9b443d4STobin Davis 	},
993fb3409e7STobin Davis 	/* Audio input controls */
994fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
995fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
996fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
997fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
998fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
999fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1000fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1001fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1002fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1003fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1004c9b443d4STobin Davis 	{ } /* end */
1005c9b443d4STobin Davis };
1006c9b443d4STobin Davis 
100734cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = {
10087f29673bSTobin Davis 	/* Set connections */
10097f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10107f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10117f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1012c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1013c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10147f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1015c9b443d4STobin Davis 
1016c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1017c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1018c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1019c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1020c9b443d4STobin Davis 	 * control.
1021c9b443d4STobin Davis 	 */
1022cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1023cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1024c9b443d4STobin Davis 
1025c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1026c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1027c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1028c9b443d4STobin Davis 
1029c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1030c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1031c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1032c9b443d4STobin Davis 	 * input/output buffers as needed.
1033c9b443d4STobin Davis 	 */
1034c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1036c9b443d4STobin Davis 
1037c9b443d4STobin Davis 	/* Mute capture amp left and right */
1038c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1039c9b443d4STobin Davis 
1040c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1041c9b443d4STobin Davis 	 * pin)
1042c9b443d4STobin Davis 	 */
1043c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10447f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1045c9b443d4STobin Davis 
1046c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1047c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1048c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1049c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1050c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1051c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1052c9b443d4STobin Davis 
1053c9b443d4STobin Davis 	{ }
1054c9b443d4STobin Davis };
1055c9b443d4STobin Davis #endif
1056c9b443d4STobin Davis 
1057c9b443d4STobin Davis 
1058c9b443d4STobin Davis /* initialize jack-sensing, too */
1059c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1060c9b443d4STobin Davis {
1061c9b443d4STobin Davis 	conexant_init(codec);
1062c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1063c9b443d4STobin Davis 	return 0;
1064c9b443d4STobin Davis }
1065c9b443d4STobin Davis 
1066c9b443d4STobin Davis 
1067c9b443d4STobin Davis enum {
106815908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
106915908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
107015908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10715218c892SJiang Zhe 	CXT5045_BENQ,
10722de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1073c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1074c9b443d4STobin Davis 	CXT5045_TEST,
1075c9b443d4STobin Davis #endif
10761f8458a2STakashi Iwai 	CXT5045_AUTO,
1077f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1078c9b443d4STobin Davis };
1079c9b443d4STobin Davis 
1080ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
108115908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
108215908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
108315908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10845218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10852de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1086c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1087f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1088c9b443d4STobin Davis #endif
10891f8458a2STakashi Iwai 	[CXT5045_AUTO]			= "auto",
1090f5fcc13cSTakashi Iwai };
1091c9b443d4STobin Davis 
109234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10932de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1094dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1095dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
10966a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10975218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
109815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
109915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
11009e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
11019e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
110215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
110315908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
110415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1105dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1106dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
110715908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1108c9b443d4STobin Davis 	{}
1109c9b443d4STobin Davis };
1110c9b443d4STobin Davis 
1111c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1112c9b443d4STobin Davis {
1113c9b443d4STobin Davis 	struct conexant_spec *spec;
1114c9b443d4STobin Davis 	int board_config;
1115c9b443d4STobin Davis 
11161f8458a2STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
11171f8458a2STakashi Iwai 						  cxt5045_models,
11181f8458a2STakashi Iwai 						  cxt5045_cfg_tbl);
11199b842cd8STakashi Iwai #if 0 /* use the old method just for safety */
11201f8458a2STakashi Iwai 	if (board_config < 0)
11211f8458a2STakashi Iwai 		board_config = CXT5045_AUTO;
11229b842cd8STakashi Iwai #endif
11231f8458a2STakashi Iwai 	if (board_config == CXT5045_AUTO)
11241f8458a2STakashi Iwai 		return patch_conexant_auto(codec);
11251f8458a2STakashi Iwai 
1126c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1127c9b443d4STobin Davis 	if (!spec)
1128c9b443d4STobin Davis 		return -ENOMEM;
1129c9b443d4STobin Davis 	codec->spec = spec;
11309421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1131c9b443d4STobin Davis 
1132c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1133c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1134c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1135c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1136c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1137c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1138c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1139c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1140c9b443d4STobin Davis 	spec->num_mixers = 1;
1141c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1142c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1143c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1144c9b443d4STobin Davis 	spec->spdif_route = 0;
11453507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11463507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11475cd57529STobin Davis 
11483507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1149c9b443d4STobin Davis 
1150c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1151c9b443d4STobin Davis 
1152c9b443d4STobin Davis 	switch (board_config) {
115315908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11547f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1155c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1156c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11577f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11587f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11597f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11607f29673bSTobin Davis 		break;
116115908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
116286376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11637f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11647f29673bSTobin Davis 		spec->num_init_verbs = 2;
11657f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1166c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1167c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1168c9b443d4STobin Davis 		break;
116915908c36SMarc Boucher 	default:
117015908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
117115908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
117215908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
117315908c36SMarc Boucher 		spec->num_init_verbs = 3;
117415908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
117515908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
117615908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
117715908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
117815908c36SMarc Boucher 		break;
11795218c892SJiang Zhe 	case CXT5045_BENQ:
11805218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11815218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11825218c892SJiang Zhe 		spec->num_init_verbs = 1;
11835218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11845218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11855218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11865218c892SJiang Zhe 		spec->num_mixers = 2;
11875218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11885218c892SJiang Zhe 		break;
11892de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11902de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11912de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11922de3c232SJiang zhe 		spec->num_init_verbs = 2;
11932de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11942de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11952de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11962de3c232SJiang zhe 		break;
1197c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1198c9b443d4STobin Davis 	case CXT5045_TEST:
1199c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1200c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1201c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
120215908c36SMarc Boucher 		break;
120315908c36SMarc Boucher 
1204c9b443d4STobin Davis #endif
1205c9b443d4STobin Davis 	}
120648ecb7e8STakashi Iwai 
1207031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1208031005f7STakashi Iwai 	case 0x103c:
12098f0f5ff6SDaniel T Chen 	case 0x1631:
12100b587fc4SDaniel T Chen 	case 0x1734:
12110ebf9e36SDaniel T Chen 	case 0x17aa:
12120ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12130ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12140ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
121548ecb7e8STakashi Iwai 		 */
121648ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
121748ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
121848ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
121948ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
122048ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1221031005f7STakashi Iwai 		break;
1222031005f7STakashi Iwai 	}
122348ecb7e8STakashi Iwai 
12243507e2a8STakashi Iwai 	if (spec->beep_amp)
12253507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12263507e2a8STakashi Iwai 
1227c9b443d4STobin Davis 	return 0;
1228c9b443d4STobin Davis }
1229c9b443d4STobin Davis 
1230c9b443d4STobin Davis 
1231c9b443d4STobin Davis /* Conexant 5047 specific */
123282f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1233c9b443d4STobin Davis 
123434cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
123534cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
123634cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1237c9b443d4STobin Davis 
123834cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
12395cd57529STobin Davis 	{ 2, NULL },
12405cd57529STobin Davis };
1241c9b443d4STobin Davis 
124234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
124382f30040STobin Davis 	.num_items = 2,
124482f30040STobin Davis 	.items = {
124582f30040STobin Davis 		{ "ExtMic", 0x2 },
124682f30040STobin Davis 		{ "Line-In", 0x1 },
1247c9b443d4STobin Davis 	}
1248c9b443d4STobin Davis };
1249c9b443d4STobin Davis 
1250c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1251c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1252c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1253c9b443d4STobin Davis {
1254c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1255c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
125682f30040STobin Davis 	unsigned int bits;
1257c9b443d4STobin Davis 
125882f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1259c9b443d4STobin Davis 		return 0;
1260c9b443d4STobin Davis 
126182f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
126282f30040STobin Davis 	 * the headphone jack
126382f30040STobin Davis 	 */
126447fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12653b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12663b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12673b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12683b7523fcSTakashi Iwai 	 */
12695d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
127047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
127147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
127247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
127347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1274c9b443d4STobin Davis 	return 1;
1275c9b443d4STobin Davis }
1276c9b443d4STobin Davis 
1277c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1278c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1279c9b443d4STobin Davis {
128082f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1281dd87da1cSTobin Davis 	unsigned int bits;
1282c9b443d4STobin Davis 
1283d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1284dd87da1cSTobin Davis 
128547fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12863b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12875d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
128847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1289c9b443d4STobin Davis }
1290c9b443d4STobin Davis 
1291c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1292c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1293c9b443d4STobin Davis {
129434cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
12959f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12969f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1297c9b443d4STobin Davis 		{}
1298c9b443d4STobin Davis 	};
129934cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
13009f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13019f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1302c9b443d4STobin Davis 		{}
1303c9b443d4STobin Davis 	};
1304c9b443d4STobin Davis 	unsigned int present;
1305c9b443d4STobin Davis 
1306d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1307c9b443d4STobin Davis 	if (present)
1308c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1309c9b443d4STobin Davis 	else
1310c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1311c9b443d4STobin Davis }
1312c9b443d4STobin Davis 
1313c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1314c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1315c9b443d4STobin Davis 				  unsigned int res)
1316c9b443d4STobin Davis {
13179f113e0eSMarc Boucher 	switch (res >> 26) {
1318c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1319c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1320c9b443d4STobin Davis 		break;
1321c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1322c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1323c9b443d4STobin Davis 		break;
1324c9b443d4STobin Davis 	}
1325c9b443d4STobin Davis }
1326c9b443d4STobin Davis 
132734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1328df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1329df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
13305f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1331c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1332c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1333c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1334c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
133582f30040STobin Davis 	{
133682f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
133782f30040STobin Davis 		.name = "Master Playback Switch",
133882f30040STobin Davis 		.info = cxt_eapd_info,
133982f30040STobin Davis 		.get = cxt_eapd_get,
1340c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1341c9b443d4STobin Davis 		.private_value = 0x13,
1342c9b443d4STobin Davis 	},
1343c9b443d4STobin Davis 
1344c9b443d4STobin Davis 	{}
1345c9b443d4STobin Davis };
1346c9b443d4STobin Davis 
134734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13483b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13495d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1350df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1351df481e41STakashi Iwai 	{}
1352df481e41STakashi Iwai };
1353df481e41STakashi Iwai 
135434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1355c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1356c9b443d4STobin Davis 	{ } /* end */
1357c9b443d4STobin Davis };
1358c9b443d4STobin Davis 
135934cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1360c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1361c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1362c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1363c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13647f29673bSTobin Davis 	/* HP, Speaker  */
1365b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13665b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13675b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13687f29673bSTobin Davis 	/* Record selector: Mic */
13697f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13707f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13717f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13727f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1373c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1374c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1375c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1376c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1377c9b443d4STobin Davis 	/* SPDIF route: PCM */
1378c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
137982f30040STobin Davis 	/* Enable unsolicited events */
138082f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
138182f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1382c9b443d4STobin Davis 	{ } /* end */
1383c9b443d4STobin Davis };
1384c9b443d4STobin Davis 
1385c9b443d4STobin Davis /* configuration for Toshiba Laptops */
138634cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13873b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1388c9b443d4STobin Davis 	{}
1389c9b443d4STobin Davis };
1390c9b443d4STobin Davis 
1391c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1392c9b443d4STobin Davis  * configuration.
1393c9b443d4STobin Davis  */
1394c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
139534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
139682f30040STobin Davis 	.num_items = 4,
1397c9b443d4STobin Davis 	.items = {
139882f30040STobin Davis 		{ "LINE1 pin", 0x0 },
139982f30040STobin Davis 		{ "MIC1 pin", 0x1 },
140082f30040STobin Davis 		{ "MIC2 pin", 0x2 },
140182f30040STobin Davis 		{ "CD pin", 0x3 },
1402c9b443d4STobin Davis         },
1403c9b443d4STobin Davis };
1404c9b443d4STobin Davis 
140534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1406c9b443d4STobin Davis 
1407c9b443d4STobin Davis 	/* Output only controls */
140882f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
140982f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
141082f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
141182f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1412c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1413c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1414c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1415c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
141682f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
141782f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
141882f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
141982f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1420c9b443d4STobin Davis 
1421c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1422c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1423c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1424c9b443d4STobin Davis 
142582f30040STobin Davis 	/* EAPD Switch Control */
142682f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
142782f30040STobin Davis 
1428c9b443d4STobin Davis 	/* Loopback mixer controls */
142982f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
143082f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
143182f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
143282f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
143382f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
143482f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
143582f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
143682f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1437c9b443d4STobin Davis 
143882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
143982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
144082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
144182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
144282f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
144382f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
144482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
144582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1446c9b443d4STobin Davis 	{
1447c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1448c9b443d4STobin Davis 		.name = "Input Source",
1449c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1450c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1451c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1452c9b443d4STobin Davis 	},
1453854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14549f113e0eSMarc Boucher 
1455c9b443d4STobin Davis 	{ } /* end */
1456c9b443d4STobin Davis };
1457c9b443d4STobin Davis 
145834cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1459c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1460c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1461c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1462c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1463c9b443d4STobin Davis 
1464c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1465c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1466c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1467c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1468c9b443d4STobin Davis 	 * control.
1469c9b443d4STobin Davis 	 */
1470c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1471c9b443d4STobin Davis 
1472c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1473c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1474c9b443d4STobin Davis 	 */
1475c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1476c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1477c9b443d4STobin Davis 
1478c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1479c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1480c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1481c9b443d4STobin Davis 
1482c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1483c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1484c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1485c9b443d4STobin Davis 	 * input/output buffers as needed.
1486c9b443d4STobin Davis 	 */
1487c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1488c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1489c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1490c9b443d4STobin Davis 
1491c9b443d4STobin Davis 	/* Mute capture amp left and right */
1492c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1493c9b443d4STobin Davis 
1494c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1495c9b443d4STobin Davis 	 * pin)
1496c9b443d4STobin Davis 	 */
1497c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1498c9b443d4STobin Davis 
1499c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1500c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1501c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1502c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1503c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1504c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1505c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1506c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1507c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1508c9b443d4STobin Davis 
1509c9b443d4STobin Davis 	{ }
1510c9b443d4STobin Davis };
1511c9b443d4STobin Davis #endif
1512c9b443d4STobin Davis 
1513c9b443d4STobin Davis 
1514c9b443d4STobin Davis /* initialize jack-sensing, too */
1515c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1516c9b443d4STobin Davis {
1517c9b443d4STobin Davis 	conexant_init(codec);
1518c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1519c9b443d4STobin Davis 	return 0;
1520c9b443d4STobin Davis }
1521c9b443d4STobin Davis 
1522c9b443d4STobin Davis 
1523c9b443d4STobin Davis enum {
1524f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1525f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1526f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1527c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1528c9b443d4STobin Davis 	CXT5047_TEST,
1529c9b443d4STobin Davis #endif
1530fa5dadcbSTakashi Iwai 	CXT5047_AUTO,
1531f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1532c9b443d4STobin Davis };
1533c9b443d4STobin Davis 
1534ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1535f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1536f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1537f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1538c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1539f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1540c9b443d4STobin Davis #endif
1541fa5dadcbSTakashi Iwai 	[CXT5047_AUTO]		= "auto",
1542f5fcc13cSTakashi Iwai };
1543c9b443d4STobin Davis 
154434cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1545ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1546dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1547dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1548f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1549c9b443d4STobin Davis 	{}
1550c9b443d4STobin Davis };
1551c9b443d4STobin Davis 
1552c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1553c9b443d4STobin Davis {
1554c9b443d4STobin Davis 	struct conexant_spec *spec;
1555c9b443d4STobin Davis 	int board_config;
1556c9b443d4STobin Davis 
1557fa5dadcbSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1558fa5dadcbSTakashi Iwai 						  cxt5047_models,
1559fa5dadcbSTakashi Iwai 						  cxt5047_cfg_tbl);
1560fa5dadcbSTakashi Iwai #if 0 /* not enabled as default, as BIOS often broken for this codec */
1561fa5dadcbSTakashi Iwai 	if (board_config < 0)
1562fa5dadcbSTakashi Iwai 		board_config = CXT5047_AUTO;
1563fa5dadcbSTakashi Iwai #endif
1564fa5dadcbSTakashi Iwai 	if (board_config == CXT5047_AUTO)
1565fa5dadcbSTakashi Iwai 		return patch_conexant_auto(codec);
1566fa5dadcbSTakashi Iwai 
1567c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1568c9b443d4STobin Davis 	if (!spec)
1569c9b443d4STobin Davis 		return -ENOMEM;
1570c9b443d4STobin Davis 	codec->spec = spec;
15719421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1572c9b443d4STobin Davis 
1573c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1574c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1575c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1576c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1577c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1578c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1579c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1580c9b443d4STobin Davis 	spec->num_mixers = 1;
1581df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1582c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1583c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1584c9b443d4STobin Davis 	spec->spdif_route = 0;
15855cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15865cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1587c9b443d4STobin Davis 
1588c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1589c9b443d4STobin Davis 
1590c9b443d4STobin Davis 	switch (board_config) {
1591c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1592df481e41STakashi Iwai 		spec->num_mixers = 2;
1593df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1594df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1595c9b443d4STobin Davis 		break;
1596c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1597df481e41STakashi Iwai 		spec->num_mixers = 2;
1598df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1599fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1600c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1601c9b443d4STobin Davis 		break;
1602c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
160382f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1604df481e41STakashi Iwai 		spec->num_mixers = 2;
1605df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1606c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1607c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1608fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1609c9b443d4STobin Davis 		break;
1610c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1611c9b443d4STobin Davis 	case CXT5047_TEST:
1612c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1613c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1614c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1615fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1616c9b443d4STobin Davis #endif
1617c9b443d4STobin Davis 	}
1618dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1619025f206cSDaniel T Chen 
1620025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1621025f206cSDaniel T Chen 	case 0x103c:
1622025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1623025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1624025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1625025f206cSDaniel T Chen 		 */
1626025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1627025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1628025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1629025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1630025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1631025f206cSDaniel T Chen 		break;
1632025f206cSDaniel T Chen 	}
1633025f206cSDaniel T Chen 
1634c9b443d4STobin Davis 	return 0;
1635c9b443d4STobin Davis }
1636c9b443d4STobin Davis 
1637461e2c78STakashi Iwai /* Conexant 5051 specific */
163834cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
163934cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1640461e2c78STakashi Iwai 
164134cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1642461e2c78STakashi Iwai 	{ 2, NULL },
1643461e2c78STakashi Iwai };
1644461e2c78STakashi Iwai 
1645461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1646461e2c78STakashi Iwai {
1647461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1648461e2c78STakashi Iwai 	unsigned int pinctl;
164923d2df5bSTakashi Iwai 	/* headphone pin */
165023d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
165123d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
165223d2df5bSTakashi Iwai 			    pinctl);
165323d2df5bSTakashi Iwai 	/* speaker pin */
1654461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1655461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1656461e2c78STakashi Iwai 			    pinctl);
1657f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1658f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1659f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1660f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1661f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1662461e2c78STakashi Iwai }
1663461e2c78STakashi Iwai 
1664461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1665461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1666461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1667461e2c78STakashi Iwai {
1668461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1669461e2c78STakashi Iwai 
1670461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1671461e2c78STakashi Iwai 		return 0;
1672461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1673461e2c78STakashi Iwai 	return 1;
1674461e2c78STakashi Iwai }
1675461e2c78STakashi Iwai 
1676461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1677461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1678461e2c78STakashi Iwai {
167979d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1680461e2c78STakashi Iwai 	unsigned int present;
1681461e2c78STakashi Iwai 
1682faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
168379d7d533STakashi Iwai 		return;
1684d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1685461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1686461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1687461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1688461e2c78STakashi Iwai }
1689461e2c78STakashi Iwai 
1690461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1691461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1692461e2c78STakashi Iwai {
1693461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1694461e2c78STakashi Iwai 	unsigned int present;
1695461e2c78STakashi Iwai 	hda_nid_t new_adc;
1696461e2c78STakashi Iwai 
1697faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
169879d7d533STakashi Iwai 		return;
1699d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1700461e2c78STakashi Iwai 	if (present)
1701461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1702461e2c78STakashi Iwai 	else
1703461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1704461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1705461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1706461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1707f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1708461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1709461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1710461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1711461e2c78STakashi Iwai 					   spec->cur_adc_format);
1712461e2c78STakashi Iwai 	}
1713461e2c78STakashi Iwai }
1714461e2c78STakashi Iwai 
1715461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1716461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1717461e2c78STakashi Iwai {
1718461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1719461e2c78STakashi Iwai 
1720d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1721461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1722461e2c78STakashi Iwai }
1723461e2c78STakashi Iwai 
1724461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1725461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1726461e2c78STakashi Iwai 				   unsigned int res)
1727461e2c78STakashi Iwai {
1728acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1729461e2c78STakashi Iwai 	switch (res >> 26) {
1730461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1731461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1732461e2c78STakashi Iwai 		break;
1733461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1734461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1735461e2c78STakashi Iwai 		break;
1736461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1737461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1738461e2c78STakashi Iwai 		break;
1739461e2c78STakashi Iwai 	}
1740cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
1741461e2c78STakashi Iwai }
1742461e2c78STakashi Iwai 
174334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1744461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1745461e2c78STakashi Iwai 	{
1746461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1747461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1748461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1749461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1750461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1751461e2c78STakashi Iwai 		.private_value = 0x1a,
1752461e2c78STakashi Iwai 	},
17532c7a3fb3STakashi Iwai 	{}
17542c7a3fb3STakashi Iwai };
1755461e2c78STakashi Iwai 
175634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17572c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17582c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17598607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17608607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
17612c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17622c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1763461e2c78STakashi Iwai 	{}
1764461e2c78STakashi Iwai };
1765461e2c78STakashi Iwai 
176634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1767461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1768461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17698607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
17708607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1771461e2c78STakashi Iwai 	{}
1772461e2c78STakashi Iwai };
1773461e2c78STakashi Iwai 
177434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
17754e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
17764e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
177779d7d533STakashi Iwai 	{}
177879d7d533STakashi Iwai };
177979d7d533STakashi Iwai 
178034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
17815f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
17825f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1783cd9d95a5SKen Prox 	{}
1784cd9d95a5SKen Prox };
1785cd9d95a5SKen Prox 
178634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1787faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1788faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17898607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17908607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1791faddaa5dSTakashi Iwai 	{}
1792faddaa5dSTakashi Iwai };
1793faddaa5dSTakashi Iwai 
179434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1795461e2c78STakashi Iwai 	/* Line in, Mic */
1796461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1797461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1798461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1799461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1800461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1801461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1802461e2c78STakashi Iwai 	/* SPK  */
1803461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1804461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1805461e2c78STakashi Iwai 	/* HP, Amp  */
1806461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1807461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1808461e2c78STakashi Iwai 	/* DAC1 */
1809461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
181028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1811461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1812461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1813461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1814461e2c78STakashi Iwai 	/* SPDIF route: PCM */
18151965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1816461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1817461e2c78STakashi Iwai 	/* EAPD */
1818461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1819461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1820461e2c78STakashi Iwai 	{ } /* end */
1821461e2c78STakashi Iwai };
1822461e2c78STakashi Iwai 
182334cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
182479d7d533STakashi Iwai 	/* Line in, Mic */
182579d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
182679d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
182779d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
182879d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
182979d7d533STakashi Iwai 	/* SPK  */
183079d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
183179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
183279d7d533STakashi Iwai 	/* HP, Amp  */
183379d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
183479d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
183579d7d533STakashi Iwai 	/* DAC1 */
183679d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
183728c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
183879d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
183979d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
184079d7d533STakashi Iwai 	/* SPDIF route: PCM */
184179d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
184279d7d533STakashi Iwai 	/* EAPD */
184379d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
184479d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
184579d7d533STakashi Iwai 	{ } /* end */
184679d7d533STakashi Iwai };
184779d7d533STakashi Iwai 
184834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
184927e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
185027e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185127e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
185227e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185327e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
185427e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
185527e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185627e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
185727e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
185827e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
185927e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
186027e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186127e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
186227e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
186327e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186427e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
186527e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
186627e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
186728c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
186827e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
186927e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
187027e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
187127e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
18721965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
187327e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
187427e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
187527e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
187627e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
187727e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
187827e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
187927e08988SAristeu Sergio Rozanski Filho };
188027e08988SAristeu Sergio Rozanski Filho 
188134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1882cd9d95a5SKen Prox 	/* Line in, Mic */
188330ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1884cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1885cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1886cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1887cd9d95a5SKen Prox 	/* SPK  */
1888cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1889cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1890cd9d95a5SKen Prox 	/* HP, Amp  */
1891cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1892cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1893cd9d95a5SKen Prox 	/* DAC1 */
1894cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
189528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1896cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1897cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1898cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1899cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1900cd9d95a5SKen Prox 	/* EAPD */
1901cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1902cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1903cd9d95a5SKen Prox 	{ } /* end */
1904cd9d95a5SKen Prox };
1905cd9d95a5SKen Prox 
19066953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
19076953e552STakashi Iwai 				 unsigned int event)
19086953e552STakashi Iwai {
19096953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
19106953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
19116953e552STakashi Iwai 			    AC_USRSP_EN | event);
1912cd372fb3STakashi Iwai 	snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1913cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
19146953e552STakashi Iwai }
19156953e552STakashi Iwai 
191634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1917f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1918f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1919f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1920f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1921f7154de2SHerton Ronaldo Krzesinski };
1922f7154de2SHerton Ronaldo Krzesinski 
1923461e2c78STakashi Iwai /* initialize jack-sensing, too */
1924461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1925461e2c78STakashi Iwai {
19266953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19276953e552STakashi Iwai 
1928461e2c78STakashi Iwai 	conexant_init(codec);
1929acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19306953e552STakashi Iwai 
19316953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19326953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19336953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19346953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19356953e552STakashi Iwai 
1936461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1937461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1938461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1939461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1940461e2c78STakashi Iwai 	}
1941461e2c78STakashi Iwai 	return 0;
1942461e2c78STakashi Iwai }
1943461e2c78STakashi Iwai 
1944461e2c78STakashi Iwai 
1945461e2c78STakashi Iwai enum {
1946461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1947461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
194879d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19491965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1950cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1951faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1952f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
19536764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1954461e2c78STakashi Iwai 	CXT5051_MODELS
1955461e2c78STakashi Iwai };
1956461e2c78STakashi Iwai 
1957ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1958461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1959461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
196079d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
196127e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19625f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1963faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1964f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
19656764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1966461e2c78STakashi Iwai };
1967461e2c78STakashi Iwai 
196834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
196979d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19701812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
19715f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1972faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1973461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1974461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1975461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
197627e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1977f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1978461e2c78STakashi Iwai 	{}
1979461e2c78STakashi Iwai };
1980461e2c78STakashi Iwai 
1981461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1982461e2c78STakashi Iwai {
1983461e2c78STakashi Iwai 	struct conexant_spec *spec;
1984461e2c78STakashi Iwai 	int board_config;
1985461e2c78STakashi Iwai 
19866764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
19876764bcefSTakashi Iwai 						  cxt5051_models,
19886764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
19899b842cd8STakashi Iwai #if 0 /* use the old method just for safety */
19906764bcefSTakashi Iwai 	if (board_config < 0)
19916764bcefSTakashi Iwai 		board_config = CXT5051_AUTO;
19929b842cd8STakashi Iwai #endif
19931f8458a2STakashi Iwai 	if (board_config == CXT5051_AUTO)
19946764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
19956764bcefSTakashi Iwai 
1996461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1997461e2c78STakashi Iwai 	if (!spec)
1998461e2c78STakashi Iwai 		return -ENOMEM;
1999461e2c78STakashi Iwai 	codec->spec = spec;
20009421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
2001461e2c78STakashi Iwai 
2002461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
2003461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
2004461e2c78STakashi Iwai 
2005461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
2006461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2007461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
2008461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2009461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2010461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
20112c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
20122c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
20132c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
2014461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
2015461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
2016461e2c78STakashi Iwai 	spec->spdif_route = 0;
2017461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2018461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
2019461e2c78STakashi Iwai 	spec->cur_adc = 0;
2020461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
2021461e2c78STakashi Iwai 
20223507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
20233507e2a8STakashi Iwai 
202479d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
202579d7d533STakashi Iwai 
2026faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2027461e2c78STakashi Iwai 	switch (board_config) {
2028461e2c78STakashi Iwai 	case CXT5051_HP:
2029461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
2030461e2c78STakashi Iwai 		break;
203179d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
203279d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
203379d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2034faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
203579d7d533STakashi Iwai 		break;
203627e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
203727e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2038607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2039607bc3e4SJerone Young 		   to use a docking station. */
2040607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2041607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2042461e2c78STakashi Iwai 		break;
2043cd9d95a5SKen Prox 	case CXT5051_F700:
2044cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2045cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2046faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2047faddaa5dSTakashi Iwai 		break;
2048faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2049faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2050faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2051cd9d95a5SKen Prox 		break;
2052f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2053f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2054f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2055f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2056f7154de2SHerton Ronaldo Krzesinski 		break;
2057461e2c78STakashi Iwai 	}
2058461e2c78STakashi Iwai 
20593507e2a8STakashi Iwai 	if (spec->beep_amp)
20603507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20613507e2a8STakashi Iwai 
2062461e2c78STakashi Iwai 	return 0;
2063461e2c78STakashi Iwai }
2064461e2c78STakashi Iwai 
20650fb67e98SDaniel Drake /* Conexant 5066 specific */
20660fb67e98SDaniel Drake 
206734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
206834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
206934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
207034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
20710fb67e98SDaniel Drake 
2072dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2073dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2074dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2075dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2076dbaccc0cSDaniel Drake 
207734cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
20780fb67e98SDaniel Drake 	{ 2, NULL },
20790fb67e98SDaniel Drake };
20800fb67e98SDaniel Drake 
2081a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2082a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2083a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2084a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2085a3de8ab8STakashi Iwai 
20860fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
20870fb67e98SDaniel Drake {
20880fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20890fb67e98SDaniel Drake 	unsigned int pinctl;
20900fb67e98SDaniel Drake 
20913a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
20923a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
20930fb67e98SDaniel Drake 
20940fb67e98SDaniel Drake 	/* Port A (HP) */
2095a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
20960fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20970fb67e98SDaniel Drake 			pinctl);
20980fb67e98SDaniel Drake 
20990fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2100a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2101a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2102a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2103a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
21043a253445SJohn Baboval 			pinctl = 0;
21053a253445SJohn Baboval 	} else {
2106a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2107a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2108a3de8ab8STakashi Iwai 			pinctl = 0;
21093a253445SJohn Baboval 	}
21100fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21110fb67e98SDaniel Drake 			pinctl);
21120fb67e98SDaniel Drake 
21130fb67e98SDaniel Drake 	/* CLASS_D AMP */
21140fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
21150fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21160fb67e98SDaniel Drake 			pinctl);
21170fb67e98SDaniel Drake }
21180fb67e98SDaniel Drake 
21190fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
21200fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
21210fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
21220fb67e98SDaniel Drake {
21230fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21240fb67e98SDaniel Drake 
21250fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
21260fb67e98SDaniel Drake 		return 0;
21270fb67e98SDaniel Drake 
21280fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21290fb67e98SDaniel Drake 	return 1;
21300fb67e98SDaniel Drake }
21310fb67e98SDaniel Drake 
2132c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2133c4cfe66cSDaniel Drake 	.num_items = 3,
2134c4cfe66cSDaniel Drake 	.items = {
2135c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2136c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2137c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2138c4cfe66cSDaniel Drake 	},
2139c4cfe66cSDaniel Drake };
2140c4cfe66cSDaniel Drake 
2141c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2142c4cfe66cSDaniel Drake {
2143c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2144c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2145c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2146c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2147c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2148c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2149c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2150c4cfe66cSDaniel Drake }
2151c4cfe66cSDaniel Drake 
215275f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
215375f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
215475f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
215575f8991dSDaniel Drake  * is happening when it is not. */
215675f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21570fb67e98SDaniel Drake {
2158dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
215975f8991dSDaniel Drake 	if (!spec->recording)
216075f8991dSDaniel Drake 		return;
21610fb67e98SDaniel Drake 
2162c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2163c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2164c4cfe66cSDaniel Drake 		 * through our special DC port */
2165c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2166c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2167c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2168c4cfe66cSDaniel Drake 
2169c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2170c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2171c4cfe66cSDaniel Drake 			{},
2172c4cfe66cSDaniel Drake 		};
2173c4cfe66cSDaniel Drake 
2174c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2175c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2176c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2177c4cfe66cSDaniel Drake 		return;
2178c4cfe66cSDaniel Drake 	}
2179c4cfe66cSDaniel Drake 
2180c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2181c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2182c4cfe66cSDaniel Drake 
218375f8991dSDaniel Drake 	/* external mic, port B */
218475f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
218575f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
21860fb67e98SDaniel Drake 
218775f8991dSDaniel Drake 	/* internal mic, port C */
218875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
218975f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
219075f8991dSDaniel Drake }
21910fb67e98SDaniel Drake 
219275f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
219375f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
219475f8991dSDaniel Drake {
219575f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
21960fb67e98SDaniel Drake 	unsigned int present;
21970fb67e98SDaniel Drake 
2198c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2199c4cfe66cSDaniel Drake 		return;
2200c4cfe66cSDaniel Drake 
220175f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
220275f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
220375f8991dSDaniel Drake 	if (present)
22040fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
220575f8991dSDaniel Drake 	else
22060fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
220775f8991dSDaniel Drake 
220875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
220975f8991dSDaniel Drake 		present ? 0 : 1);
221075f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
221175f8991dSDaniel Drake 
221275f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
22130fb67e98SDaniel Drake }
22140fb67e98SDaniel Drake 
221595a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
221695a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
221795a618bdSEinar Rünkaru {
221895a618bdSEinar Rünkaru 	unsigned int present;
221995a618bdSEinar Rünkaru 
222095a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
222195a618bdSEinar Rünkaru 		/* enable external mic, port B */
222275f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
222395a618bdSEinar Rünkaru 
222495a618bdSEinar Rünkaru 		/* switch to external mic input */
222595a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
222695a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
222795a618bdSEinar Rünkaru 
222895a618bdSEinar Rünkaru 		/* disable internal digital mic */
222995a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
223095a618bdSEinar Rünkaru 		{}
223195a618bdSEinar Rünkaru 	};
223234cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
223395a618bdSEinar Rünkaru 		/* enable internal mic, port C */
223495a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
223595a618bdSEinar Rünkaru 
223695a618bdSEinar Rünkaru 		/* switch to internal mic input */
223795a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
223895a618bdSEinar Rünkaru 
223995a618bdSEinar Rünkaru 		/* disable external mic, port B */
224095a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
224195a618bdSEinar Rünkaru 		{}
224295a618bdSEinar Rünkaru 	};
224395a618bdSEinar Rünkaru 
224495a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
224595a618bdSEinar Rünkaru 	if (present) {
224695a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
224795a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
224895a618bdSEinar Rünkaru 	} else {
224995a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
225095a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
225195a618bdSEinar Rünkaru 	}
225295a618bdSEinar Rünkaru }
225395a618bdSEinar Rünkaru 
2254cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2255cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2256cfd3d8dcSGreg Alexander {
2257cfd3d8dcSGreg Alexander 	unsigned int present;
2258cfd3d8dcSGreg Alexander 
2259cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2260cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2261cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2262cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2263cfd3d8dcSGreg Alexander 		{}
2264cfd3d8dcSGreg Alexander 	};
226534cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2266cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2267cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2268cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2269cfd3d8dcSGreg Alexander 		{}
2270cfd3d8dcSGreg Alexander 	};
2271cfd3d8dcSGreg Alexander 
2272cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2273cfd3d8dcSGreg Alexander 	if (present) {
2274cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2275cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2276cfd3d8dcSGreg Alexander 	} else {
2277cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2278cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2279cfd3d8dcSGreg Alexander 	}
2280cfd3d8dcSGreg Alexander }
2281cfd3d8dcSGreg Alexander 
2282a1d6906eSDavid Henningsson 
2283a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2284a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2285a1d6906eSDavid Henningsson {
2286a1d6906eSDavid Henningsson 	unsigned int present;
2287a1d6906eSDavid Henningsson 
2288a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2289a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2290a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2291a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2292a1d6906eSDavid Henningsson }
2293a1d6906eSDavid Henningsson 
2294a1d6906eSDavid Henningsson 
2295048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2296048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2297048e78a5SDavid Henningsson {
2298048e78a5SDavid Henningsson 	unsigned int present;
2299048e78a5SDavid Henningsson 
2300048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2301048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2302048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2303048e78a5SDavid Henningsson 			    present ? 1 : 3);
2304048e78a5SDavid Henningsson }
2305048e78a5SDavid Henningsson 
2306048e78a5SDavid Henningsson 
23077b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
23087b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
23097b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
23107b2bfdbcSJens Taprogge {
23117b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
23127b2bfdbcSJens Taprogge 
231334cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
23147b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23157b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
23167b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23177b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23187b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23197b2bfdbcSJens Taprogge 		{}
23207b2bfdbcSJens Taprogge 	};
232134cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
23227b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23237b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
23247b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23257b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23267b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23277b2bfdbcSJens Taprogge 		{}
23287b2bfdbcSJens Taprogge 	};
232934cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
23307b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23317b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23327b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23337b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23347b2bfdbcSJens Taprogge 		{}
23357b2bfdbcSJens Taprogge 	};
23367b2bfdbcSJens Taprogge 
23377b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23387b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23397b2bfdbcSJens Taprogge 	if (ext_present) {
23407b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23417b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23427b2bfdbcSJens Taprogge 	} else if (dock_present) {
23437b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23447b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23457b2bfdbcSJens Taprogge 	} else {
23467b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23477b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23487b2bfdbcSJens Taprogge 	}
23497b2bfdbcSJens Taprogge }
23507b2bfdbcSJens Taprogge 
23510fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23520fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23530fb67e98SDaniel Drake {
23540fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23550fb67e98SDaniel Drake 	unsigned int portA, portD;
23560fb67e98SDaniel Drake 
23570fb67e98SDaniel Drake 	/* Port A */
2358d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23590fb67e98SDaniel Drake 
23600fb67e98SDaniel Drake 	/* Port D */
2361d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23620fb67e98SDaniel Drake 
2363a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2364a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
23650fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23660fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23670fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23680fb67e98SDaniel Drake }
23690fb67e98SDaniel Drake 
237002b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
237102b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
237202b6b5b6SDavid Henningsson {
237302b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
237402b6b5b6SDavid Henningsson 
237502b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
237602b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
237702b6b5b6SDavid Henningsson 	else if (spec->ideapad)
237802b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
237902b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
238002b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
238102b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
238202b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2383a1d6906eSDavid Henningsson 	else if (spec->asus)
2384a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
238502b6b5b6SDavid Henningsson }
238602b6b5b6SDavid Henningsson 
23870fb67e98SDaniel Drake /* unsolicited event for jack sensing */
238875f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23890fb67e98SDaniel Drake {
2390c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23910fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23920fb67e98SDaniel Drake 	switch (res >> 26) {
23930fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
23940fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
23950fb67e98SDaniel Drake 		break;
23960fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2397c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2398c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
239975f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
24000fb67e98SDaniel Drake 		break;
24010fb67e98SDaniel Drake 	}
24020fb67e98SDaniel Drake }
24030fb67e98SDaniel Drake 
240495a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
240502b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
240695a618bdSEinar Rünkaru {
240702b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
240895a618bdSEinar Rünkaru 	switch (res >> 26) {
240995a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
241095a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
241195a618bdSEinar Rünkaru 		break;
241295a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
241302b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
241495a618bdSEinar Rünkaru 		break;
241595a618bdSEinar Rünkaru 	}
241695a618bdSEinar Rünkaru }
241795a618bdSEinar Rünkaru 
24187b2bfdbcSJens Taprogge 
24190fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
24200fb67e98SDaniel Drake 	.num_items = 5,
24210fb67e98SDaniel Drake 	.items = {
24220fb67e98SDaniel Drake 		{ "0dB",  0 },
24230fb67e98SDaniel Drake 		{ "10dB", 1 },
24240fb67e98SDaniel Drake 		{ "20dB", 2 },
24250fb67e98SDaniel Drake 		{ "30dB", 3 },
24260fb67e98SDaniel Drake 		{ "40dB", 4 },
24270fb67e98SDaniel Drake 	},
24280fb67e98SDaniel Drake };
24290fb67e98SDaniel Drake 
2430cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2431c4cfe66cSDaniel Drake {
2432c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2433cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2434c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2435c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2436c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24377b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2438cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2439cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2440cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2441cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2442cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2443cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2444cfd3d8dcSGreg Alexander 	}
2445c4cfe66cSDaniel Drake }
2446c4cfe66cSDaniel Drake 
24470fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24480fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24490fb67e98SDaniel Drake {
24500fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24510fb67e98SDaniel Drake }
24520fb67e98SDaniel Drake 
24530fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24540fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24550fb67e98SDaniel Drake {
24560fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2457c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2458c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24590fb67e98SDaniel Drake 	return 0;
24600fb67e98SDaniel Drake }
24610fb67e98SDaniel Drake 
24620fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24630fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24640fb67e98SDaniel Drake {
24650fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2466c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24670fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24680fb67e98SDaniel Drake 	unsigned int idx;
24690fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24700fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24710fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24720fb67e98SDaniel Drake 
2473c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2474c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2475c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2476c4cfe66cSDaniel Drake 	return 1;
2477c4cfe66cSDaniel Drake }
24780fb67e98SDaniel Drake 
2479c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2480c4cfe66cSDaniel Drake {
2481c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2482c4cfe66cSDaniel Drake 		/* disable gain */
2483c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2484c4cfe66cSDaniel Drake 
2485c4cfe66cSDaniel Drake 		/* switch to DC input */
2486c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2487c4cfe66cSDaniel Drake 		{}
2488c4cfe66cSDaniel Drake 	};
2489c4cfe66cSDaniel Drake 
2490c4cfe66cSDaniel Drake 	/* configure as input source */
2491c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2492c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2493c4cfe66cSDaniel Drake }
2494c4cfe66cSDaniel Drake 
2495c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2496c4cfe66cSDaniel Drake {
2497c4cfe66cSDaniel Drake 	/* reconfigure input source */
2498c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2499c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2500c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2501c4cfe66cSDaniel Drake }
2502c4cfe66cSDaniel Drake 
2503c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2504c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2505c4cfe66cSDaniel Drake {
2506c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2507c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2508c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2509c4cfe66cSDaniel Drake 	return 0;
2510c4cfe66cSDaniel Drake }
2511c4cfe66cSDaniel Drake 
2512c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2513c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2514c4cfe66cSDaniel Drake {
2515c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2516c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2517c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2518c4cfe66cSDaniel Drake 
2519c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2520c4cfe66cSDaniel Drake 		return 0;
2521c4cfe66cSDaniel Drake 
2522c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2523c4cfe66cSDaniel Drake 	if (dc_enable)
2524c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2525c4cfe66cSDaniel Drake 	else
2526c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2527c4cfe66cSDaniel Drake 
2528c4cfe66cSDaniel Drake 	return 1;
2529c4cfe66cSDaniel Drake }
2530c4cfe66cSDaniel Drake 
2531c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2532c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2533c4cfe66cSDaniel Drake {
2534c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2535c4cfe66cSDaniel Drake }
2536c4cfe66cSDaniel Drake 
2537c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2538c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2539c4cfe66cSDaniel Drake {
2540c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2541c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2542c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2543c4cfe66cSDaniel Drake 	return 0;
2544c4cfe66cSDaniel Drake }
2545c4cfe66cSDaniel Drake 
2546c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2547c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2548c4cfe66cSDaniel Drake {
2549c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2551c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2552c4cfe66cSDaniel Drake 	unsigned int idx;
2553c4cfe66cSDaniel Drake 
2554c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2555c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2556c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2557c4cfe66cSDaniel Drake 
2558c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2559c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2560c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25610fb67e98SDaniel Drake 	return 1;
25620fb67e98SDaniel Drake }
25630fb67e98SDaniel Drake 
256475f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
256575f8991dSDaniel Drake {
256675f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
256775f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
256875f8991dSDaniel Drake 	 * recording LED comes on. */
256975f8991dSDaniel Drake 	spec->recording = 1;
257075f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
257175f8991dSDaniel Drake }
257275f8991dSDaniel Drake 
257375f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
257475f8991dSDaniel Drake {
257575f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
257675f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
257775f8991dSDaniel Drake 		/* disable external mic, port B */
257875f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
257975f8991dSDaniel Drake 
258075f8991dSDaniel Drake 		/* disble internal mic, port C */
258175f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2582c4cfe66cSDaniel Drake 
2583c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2584c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
258575f8991dSDaniel Drake 		{},
258675f8991dSDaniel Drake 	};
258775f8991dSDaniel Drake 
258875f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
258975f8991dSDaniel Drake 	spec->recording = 0;
259075f8991dSDaniel Drake }
259175f8991dSDaniel Drake 
2592f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
259334cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2594f6a2491cSAndy Robinson 				    int num_pins)
2595f6a2491cSAndy Robinson {
2596f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2597f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2598f6a2491cSAndy Robinson 	int i;
2599f6a2491cSAndy Robinson 
2600f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2601f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2602f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2603f6a2491cSAndy Robinson 			continue;
2604f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2605f6a2491cSAndy Robinson 			continue;
2606f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
2607f6a2491cSAndy Robinson 			nid_loc++;
2608f6a2491cSAndy Robinson 		else
2609f6a2491cSAndy Robinson 			nid_loc = spec->slave_dig_outs;
2610f6a2491cSAndy Robinson 	}
2611f6a2491cSAndy Robinson }
2612f6a2491cSAndy Robinson 
261334cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
26140fb67e98SDaniel Drake 	.num_items = 4,
26150fb67e98SDaniel Drake 	.items = {
26160fb67e98SDaniel Drake 		{ "Mic B", 0 },
26170fb67e98SDaniel Drake 		{ "Mic C", 1 },
26180fb67e98SDaniel Drake 		{ "Mic E", 2 },
26190fb67e98SDaniel Drake 		{ "Mic F", 3 },
26200fb67e98SDaniel Drake 	},
26210fb67e98SDaniel Drake };
26220fb67e98SDaniel Drake 
262334cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
26240fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
26250fb67e98SDaniel Drake 	.values = {
26260fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26270fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26280fb67e98SDaniel Drake 		0
26290fb67e98SDaniel Drake 	},
26300fb67e98SDaniel Drake };
26310fb67e98SDaniel Drake 
263234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26330fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26340fb67e98SDaniel Drake 	.values = {
26350fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26360fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26370fb67e98SDaniel Drake 		0
26380fb67e98SDaniel Drake 	},
26390fb67e98SDaniel Drake };
26400fb67e98SDaniel Drake 
264134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
26420fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26430fb67e98SDaniel Drake 	{}
26440fb67e98SDaniel Drake };
26450fb67e98SDaniel Drake 
264634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26470fb67e98SDaniel Drake 	{
26480fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26490fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26500fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26510fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26520fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26535e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26540fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26550fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26560fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26570fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26580fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26590fb67e98SDaniel Drake 		.private_value =
26600fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26610fb67e98SDaniel Drake 	},
26620fb67e98SDaniel Drake 	{}
26630fb67e98SDaniel Drake };
26640fb67e98SDaniel Drake 
266534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2666c4cfe66cSDaniel Drake 	{
2667c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2668c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2669c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2670c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2671c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2672c4cfe66cSDaniel Drake 	},
2673c4cfe66cSDaniel Drake 	{
2674c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2675c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2676c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2677c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2678c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2679c4cfe66cSDaniel Drake 	},
2680c4cfe66cSDaniel Drake 	{}
2681c4cfe66cSDaniel Drake };
2682c4cfe66cSDaniel Drake 
268334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
26840fb67e98SDaniel Drake 	{
26850fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26860fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26870fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26880fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26890fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26900fb67e98SDaniel Drake 		.private_value = 0x1d,
26910fb67e98SDaniel Drake 	},
26920fb67e98SDaniel Drake 
26930fb67e98SDaniel Drake 	{
26940fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2695c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
26960fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
26970fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
26980fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
26990fb67e98SDaniel Drake 	},
27000fb67e98SDaniel Drake 
27010fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
27020fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
27030fb67e98SDaniel Drake 	{}
27040fb67e98SDaniel Drake };
27050fb67e98SDaniel Drake 
270634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2707254bba6aSEinar Rünkaru 	{
2708254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
270928c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2710254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2711254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2712254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2713254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2714254bba6aSEinar Rünkaru 	},
2715254bba6aSEinar Rünkaru 	{}
2716254bba6aSEinar Rünkaru };
2717254bba6aSEinar Rünkaru 
271834cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
27190fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
27200fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
27210fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27220fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
27230fb67e98SDaniel Drake 
27240fb67e98SDaniel Drake 	/* Speakers  */
27250fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27260fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27270fb67e98SDaniel Drake 
27280fb67e98SDaniel Drake 	/* HP, Amp  */
27290fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27300fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27310fb67e98SDaniel Drake 
27320fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27330fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27340fb67e98SDaniel Drake 
27350fb67e98SDaniel Drake 	/* DAC1 */
27360fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27370fb67e98SDaniel Drake 
27380fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27390fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27400fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27410fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27420fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27430fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27440fb67e98SDaniel Drake 
27450fb67e98SDaniel Drake 	/* no digital microphone support yet */
27460fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27470fb67e98SDaniel Drake 
27480fb67e98SDaniel Drake 	/* Audio input selector */
27490fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27500fb67e98SDaniel Drake 
27510fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27520fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27530fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27540fb67e98SDaniel Drake 
27550fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27560fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27570fb67e98SDaniel Drake 
27580fb67e98SDaniel Drake 	/* EAPD */
27590fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27600fb67e98SDaniel Drake 
27610fb67e98SDaniel Drake 	/* not handling these yet */
27620fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27630fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27640fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27650fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27660fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27670fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27680fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27690fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27700fb67e98SDaniel Drake 	{ } /* end */
27710fb67e98SDaniel Drake };
27720fb67e98SDaniel Drake 
277334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = {
27740fb67e98SDaniel Drake 	/* Port A: headphones */
27750fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27760fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27770fb67e98SDaniel Drake 
27780fb67e98SDaniel Drake 	/* Port B: external microphone */
277975f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27800fb67e98SDaniel Drake 
27810fb67e98SDaniel Drake 	/* Port C: internal microphone */
278275f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27830fb67e98SDaniel Drake 
27840fb67e98SDaniel Drake 	/* Port D: unused */
27850fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27860fb67e98SDaniel Drake 
27870fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27880fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27890fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27900fb67e98SDaniel Drake 
2791c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27920fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27930fb67e98SDaniel Drake 
27940fb67e98SDaniel Drake 	/* Port G: internal speakers */
27950fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27960fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27970fb67e98SDaniel Drake 
27980fb67e98SDaniel Drake 	/* DAC1 */
27990fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28000fb67e98SDaniel Drake 
28010fb67e98SDaniel Drake 	/* DAC2: unused */
28020fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
28030fb67e98SDaniel Drake 
28040fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28050fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28060fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28070fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28080fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28090fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28100fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28110fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28120fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28130fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28140fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28150fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28160fb67e98SDaniel Drake 
28170fb67e98SDaniel Drake 	/* Disable digital microphone port */
28180fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28190fb67e98SDaniel Drake 
28200fb67e98SDaniel Drake 	/* Audio input selectors */
28210fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
28220fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
28230fb67e98SDaniel Drake 
28240fb67e98SDaniel Drake 	/* Disable SPDIF */
28250fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28260fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28270fb67e98SDaniel Drake 
28280fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
28290fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28300fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28310fb67e98SDaniel Drake 	{ } /* end */
28320fb67e98SDaniel Drake };
28330fb67e98SDaniel Drake 
283434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
283595a618bdSEinar Rünkaru 	/* Port A: headphones */
283695a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283795a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
283895a618bdSEinar Rünkaru 
283995a618bdSEinar Rünkaru 	/* Port B: external microphone */
284095a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284195a618bdSEinar Rünkaru 
284295a618bdSEinar Rünkaru 	/* Port C: unused */
284395a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284495a618bdSEinar Rünkaru 
284595a618bdSEinar Rünkaru 	/* Port D: unused */
284695a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284795a618bdSEinar Rünkaru 
284895a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
284995a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285095a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
285195a618bdSEinar Rünkaru 
285295a618bdSEinar Rünkaru 	/* Port F: unused */
285395a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285495a618bdSEinar Rünkaru 
285595a618bdSEinar Rünkaru 	/* Port G: internal speakers */
285695a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
285795a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
285895a618bdSEinar Rünkaru 
285995a618bdSEinar Rünkaru 	/* DAC1 */
286095a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
286195a618bdSEinar Rünkaru 
286295a618bdSEinar Rünkaru 	/* DAC2: unused */
286395a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
286495a618bdSEinar Rünkaru 
286595a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
286695a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
286795a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
286895a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
286995a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287095a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
287195a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287295a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287395a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287495a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
287595a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287695a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287795a618bdSEinar Rünkaru 
287895a618bdSEinar Rünkaru 	/* Digital microphone port */
287995a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
288095a618bdSEinar Rünkaru 
288195a618bdSEinar Rünkaru 	/* Audio input selectors */
288295a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
288395a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
288495a618bdSEinar Rünkaru 
288595a618bdSEinar Rünkaru 	/* Disable SPDIF */
288695a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
288795a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
288895a618bdSEinar Rünkaru 
288995a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
289095a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
289195a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
289295a618bdSEinar Rünkaru 	{ } /* end */
289395a618bdSEinar Rünkaru };
289495a618bdSEinar Rünkaru 
289534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2896cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2897cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2898cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2899cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2900cfd3d8dcSGreg Alexander 
2901cfd3d8dcSGreg Alexander 	/* Speakers  */
2902cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2903cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2904cfd3d8dcSGreg Alexander 
2905cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2906cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2907cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2908cfd3d8dcSGreg Alexander 
2909cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2910cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2911cfd3d8dcSGreg Alexander 
2912cfd3d8dcSGreg Alexander 	/* DAC1 */
2913cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2914cfd3d8dcSGreg Alexander 
2915cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2916cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2917cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2918cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2919cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2920cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2921cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2922cfd3d8dcSGreg Alexander 
2923cfd3d8dcSGreg Alexander 	/* Audio input selector */
2924cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2925cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2926cfd3d8dcSGreg Alexander 
2927cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2928cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2929cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2930cfd3d8dcSGreg Alexander 
2931cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2932cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2933cfd3d8dcSGreg Alexander 
2934cfd3d8dcSGreg Alexander 	/* internal microphone */
293528c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2936cfd3d8dcSGreg Alexander 
2937cfd3d8dcSGreg Alexander 	/* EAPD */
2938cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2939cfd3d8dcSGreg Alexander 
2940cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2941cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2942cfd3d8dcSGreg Alexander 	{ } /* end */
2943cfd3d8dcSGreg Alexander };
2944cfd3d8dcSGreg Alexander 
294534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29467b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29477b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29487b2bfdbcSJens Taprogge 
29497b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29507b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29517b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29527b2bfdbcSJens Taprogge 
29537b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29547b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29557b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29567b2bfdbcSJens Taprogge 
29577b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29587b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29597b2bfdbcSJens Taprogge 
29607b2bfdbcSJens Taprogge 	/* Port C: Mic */
29617b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29627b2bfdbcSJens Taprogge 
29637b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29647b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29657b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29667b2bfdbcSJens Taprogge 
29677b2bfdbcSJens Taprogge 	/* DAC1 */
29687b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29697b2bfdbcSJens Taprogge 
29707b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29717b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29727b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29737b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29747b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29757b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29767b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29777b2bfdbcSJens Taprogge 
29787b2bfdbcSJens Taprogge 	/* Audio input selector */
29797b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29807b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29817b2bfdbcSJens Taprogge 
29827b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29837b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29847b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29857b2bfdbcSJens Taprogge 
29867b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29877b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29887b2bfdbcSJens Taprogge 
29897b2bfdbcSJens Taprogge 	/* internal microphone */
299028c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
29917b2bfdbcSJens Taprogge 
29927b2bfdbcSJens Taprogge 	/* EAPD */
29937b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
29947b2bfdbcSJens Taprogge 
29957b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
29967b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29977b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29987b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29997b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30007b2bfdbcSJens Taprogge 	{ } /* end */
30017b2bfdbcSJens Taprogge };
30027b2bfdbcSJens Taprogge 
300334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
30040fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30050fb67e98SDaniel Drake 	{ } /* end */
30060fb67e98SDaniel Drake };
30070fb67e98SDaniel Drake 
3008048e78a5SDavid Henningsson 
300934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3010048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3011048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3012048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3013048e78a5SDavid Henningsson 	{ } /* end */
3014048e78a5SDavid Henningsson };
3015048e78a5SDavid Henningsson 
30160fb67e98SDaniel Drake /* initialize jack-sensing, too */
30170fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
30180fb67e98SDaniel Drake {
30190fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
30200fb67e98SDaniel Drake 	conexant_init(codec);
30210fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
30220fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
302302b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
30240fb67e98SDaniel Drake 	}
3025c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
30260fb67e98SDaniel Drake 	return 0;
30270fb67e98SDaniel Drake }
30280fb67e98SDaniel Drake 
302975f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
303075f8991dSDaniel Drake {
3031c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
303275f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
303375f8991dSDaniel Drake 	conexant_init(codec);
303475f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3035c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3036c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
303775f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3038c4cfe66cSDaniel Drake 	} else {
3039c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3040c4cfe66cSDaniel Drake 	}
304175f8991dSDaniel Drake 	return 0;
304275f8991dSDaniel Drake }
304375f8991dSDaniel Drake 
30440fb67e98SDaniel Drake enum {
30450fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30460fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30470fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
30481feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
3049cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30507b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
3051a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3052048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
3053fea4a4f9STakashi Iwai 	CXT5066_AUTO,		/* BIOS auto-parser */
30540fb67e98SDaniel Drake 	CXT5066_MODELS
30550fb67e98SDaniel Drake };
30560fb67e98SDaniel Drake 
3057ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
30580fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30590fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30600fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
30611feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3062cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30637b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3064a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3065048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
3066fea4a4f9STakashi Iwai 	[CXT5066_AUTO]		= "auto",
30670fb67e98SDaniel Drake };
30680fb67e98SDaniel Drake 
306934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
307000cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
30711feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
30728a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3073ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
30741feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3075231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3076ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3077ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3078048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3079f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3080a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3081f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
30822ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3083c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30844442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30855637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30865637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
30875637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
30884d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3089ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
309019593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
30917b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
309284012657SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3093b2cb1292SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3094a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
309522f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
30960fb67e98SDaniel Drake 	{}
30970fb67e98SDaniel Drake };
30980fb67e98SDaniel Drake 
30990fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
31000fb67e98SDaniel Drake {
31010fb67e98SDaniel Drake 	struct conexant_spec *spec;
31020fb67e98SDaniel Drake 	int board_config;
31030fb67e98SDaniel Drake 
3104fea4a4f9STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3105fea4a4f9STakashi Iwai 						  cxt5066_models, cxt5066_cfg_tbl);
3106fea4a4f9STakashi Iwai #if 0 /* use the old method just for safety */
3107fea4a4f9STakashi Iwai 	if (board_config < 0)
3108fea4a4f9STakashi Iwai 		board_config = CXT5066_AUTO;
3109fea4a4f9STakashi Iwai #endif
3110fea4a4f9STakashi Iwai 	if (board_config == CXT5066_AUTO)
3111fea4a4f9STakashi Iwai 		return patch_conexant_auto(codec);
3112fea4a4f9STakashi Iwai 
31130fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
31140fb67e98SDaniel Drake 	if (!spec)
31150fb67e98SDaniel Drake 		return -ENOMEM;
31160fb67e98SDaniel Drake 	codec->spec = spec;
31170fb67e98SDaniel Drake 
31180fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
311975f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
31200fb67e98SDaniel Drake 
31210fb67e98SDaniel Drake 	spec->dell_automute = 0;
31220fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
31230fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
31240fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
3125f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3126f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
31270fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
31280fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
31290fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
31300fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
31310fb67e98SDaniel Drake 
31320fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
31330fb67e98SDaniel Drake 
31340fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
31350fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
31360fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
31370fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
31380fb67e98SDaniel Drake 	spec->cur_adc = 0;
31390fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
31400fb67e98SDaniel Drake 
31413507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31423507e2a8STakashi Iwai 
31430fb67e98SDaniel Drake 	switch (board_config) {
31440fb67e98SDaniel Drake 	default:
31450fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31460fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31470fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31480fb67e98SDaniel Drake 		break;
31490fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31500fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31510fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31520fb67e98SDaniel Drake 
31530fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31540fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31550fb67e98SDaniel Drake 		spec->num_init_verbs++;
31560fb67e98SDaniel Drake 		spec->dell_automute = 1;
31570fb67e98SDaniel Drake 		break;
3158a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3159048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3160048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
316102b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3162048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3163048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3164048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3165a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3166a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3167048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3168048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3169048e78a5SDavid Henningsson 		/* no S/PDIF out */
3170f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3171048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3172048e78a5SDavid Henningsson 		/* input source automatically selected */
3173048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3174048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3175048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3176048e78a5SDavid Henningsson 		break;
3177048e78a5SDavid Henningsson 
31780fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
317975f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
318075f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31810fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31820fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3183c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31840fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31850fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3186c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31870fb67e98SDaniel Drake 
31880fb67e98SDaniel Drake 		/* no S/PDIF out */
31890fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31900fb67e98SDaniel Drake 
31910fb67e98SDaniel Drake 		/* input source automatically selected */
31920fb67e98SDaniel Drake 		spec->input_mux = NULL;
319375f8991dSDaniel Drake 
319475f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
319575f8991dSDaniel Drake 		 * at the right time */
319675f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
319775f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
31980fb67e98SDaniel Drake 		break;
31991feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
320075f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
320102b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
320295a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
320395a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
320495a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3205254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
320695a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3207254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3208c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
320995a618bdSEinar Rünkaru 
321095a618bdSEinar Rünkaru 		/* no S/PDIF out */
321195a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
321295a618bdSEinar Rünkaru 
321395a618bdSEinar Rünkaru 		/* input source automatically selected */
321495a618bdSEinar Rünkaru 		spec->input_mux = NULL;
321595a618bdSEinar Rünkaru 		break;
3216cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3217cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
321802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3219cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3220cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3221cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3222cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3223cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3224cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3225cfd3d8dcSGreg Alexander 
3226cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3227cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3228cfd3d8dcSGreg Alexander 
3229cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3230cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3231cfd3d8dcSGreg Alexander 		break;
32327b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
32337b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
323402b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
32357b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
32367b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
32377b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
32387b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
32397b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
32407b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
32417b2bfdbcSJens Taprogge 
32427b2bfdbcSJens Taprogge 		/* no S/PDIF out */
32437b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
32447b2bfdbcSJens Taprogge 
32457b2bfdbcSJens Taprogge 		/* input source automatically selected */
32467b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
32477b2bfdbcSJens Taprogge 		break;
32480fb67e98SDaniel Drake 	}
32490fb67e98SDaniel Drake 
32503507e2a8STakashi Iwai 	if (spec->beep_amp)
32513507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
32523507e2a8STakashi Iwai 
32530fb67e98SDaniel Drake 	return 0;
32540fb67e98SDaniel Drake }
3255461e2c78STakashi Iwai 
3256461e2c78STakashi Iwai /*
3257f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3258f2e5731dSTakashi Iwai  */
3259f2e5731dSTakashi Iwai 
32606764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
32616764bcefSTakashi Iwai 				       struct hda_codec *codec,
32626764bcefSTakashi Iwai 				       unsigned int stream_tag,
32636764bcefSTakashi Iwai 				       unsigned int format,
32646764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
32656764bcefSTakashi Iwai {
32666764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
326747ad1f4eSTakashi Iwai 	hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
32686764bcefSTakashi Iwai 	if (spec->adc_switching) {
32696764bcefSTakashi Iwai 		spec->cur_adc = adc;
32706764bcefSTakashi Iwai 		spec->cur_adc_stream_tag = stream_tag;
32716764bcefSTakashi Iwai 		spec->cur_adc_format = format;
32726764bcefSTakashi Iwai 	}
32736764bcefSTakashi Iwai 	snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
32746764bcefSTakashi Iwai 	return 0;
32756764bcefSTakashi Iwai }
32766764bcefSTakashi Iwai 
32776764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
32786764bcefSTakashi Iwai 				       struct hda_codec *codec,
32796764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
32806764bcefSTakashi Iwai {
32816764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
32826764bcefSTakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
32836764bcefSTakashi Iwai 	spec->cur_adc = 0;
32846764bcefSTakashi Iwai 	return 0;
32856764bcefSTakashi Iwai }
32866764bcefSTakashi Iwai 
32876764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
32886764bcefSTakashi Iwai 	.substreams = 1,
32896764bcefSTakashi Iwai 	.channels_min = 2,
32906764bcefSTakashi Iwai 	.channels_max = 2,
32916764bcefSTakashi Iwai 	.nid = 0, /* fill later */
32926764bcefSTakashi Iwai 	.ops = {
32936764bcefSTakashi Iwai 		.prepare = cx_auto_capture_pcm_prepare,
32946764bcefSTakashi Iwai 		.cleanup = cx_auto_capture_pcm_cleanup
32956764bcefSTakashi Iwai 	},
32966764bcefSTakashi Iwai };
32976764bcefSTakashi Iwai 
329834cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3299f2e5731dSTakashi Iwai 
3300f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */
3301f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3302f2e5731dSTakashi Iwai 				hda_nid_t nid)
3303f2e5731dSTakashi Iwai {
3304f2e5731dSTakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3305f2e5731dSTakashi Iwai 	int i, nums;
3306f2e5731dSTakashi Iwai 
3307f2e5731dSTakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3308f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++)
3309f2e5731dSTakashi Iwai 		if (conn[i] == nid)
3310f2e5731dSTakashi Iwai 			return i;
3311f2e5731dSTakashi Iwai 	return -1;
3312f2e5731dSTakashi Iwai }
3313f2e5731dSTakashi Iwai 
3314f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3315f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3316f2e5731dSTakashi Iwai  * not found
3317f2e5731dSTakashi Iwai  */
3318f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3319f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3320f2e5731dSTakashi Iwai {
3321f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3322f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3323f2e5731dSTakashi Iwai 
3324f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3325f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3326f2e5731dSTakashi Iwai 			ret = dacs[i];
3327f2e5731dSTakashi Iwai 			break;
3328f2e5731dSTakashi Iwai 		}
3329f2e5731dSTakashi Iwai 	}
3330f2e5731dSTakashi Iwai 	if (!ret)
3331f2e5731dSTakashi Iwai 		return 0;
3332f2e5731dSTakashi Iwai 	if (--nums > 0)
3333f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3334f2e5731dSTakashi Iwai 	*num_dacs = nums;
3335f2e5731dSTakashi Iwai 	return ret;
3336f2e5731dSTakashi Iwai }
3337f2e5731dSTakashi Iwai 
3338f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3339f2e5731dSTakashi Iwai 
3340f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3341f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3342f2e5731dSTakashi Iwai {
3343f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3344f2e5731dSTakashi Iwai 	int nums = 0;
3345f2e5731dSTakashi Iwai 
3346f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3347f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3348f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3349f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3350f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3351f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3352f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3353f2e5731dSTakashi Iwai 				break;
3354f2e5731dSTakashi Iwai 		}
3355f2e5731dSTakashi Iwai 	}
3356f2e5731dSTakashi Iwai 	return nums;
3357f2e5731dSTakashi Iwai }
3358f2e5731dSTakashi Iwai 
3359f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3360f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3361f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3362f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3363f2e5731dSTakashi Iwai {
3364f2e5731dSTakashi Iwai 	int i, nums;
3365f2e5731dSTakashi Iwai 
3366f2e5731dSTakashi Iwai 	nums = 0;
3367f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3368f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3369f2e5731dSTakashi Iwai 		filled[nums].type = type;
3370f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3371f2e5731dSTakashi Iwai 		nums++;
3372f2e5731dSTakashi Iwai 	}
3373f2e5731dSTakashi Iwai 	return nums;
3374f2e5731dSTakashi Iwai }
3375f2e5731dSTakashi Iwai 
3376f2e5731dSTakashi Iwai /* parse analog output paths */
3377f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3378f2e5731dSTakashi Iwai {
3379f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3380f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3381f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3382f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3383f2e5731dSTakashi Iwai 
3384f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3385f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3386f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3387f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3388f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3389f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3390f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3391f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3392f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3393f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3394f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3395f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3396f2e5731dSTakashi Iwai 	/* fill multiout struct */
3397f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3398f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3399f2e5731dSTakashi Iwai 		if (!dac)
3400f2e5731dSTakashi Iwai 			continue;
3401f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3402f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3403f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3404f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3405f2e5731dSTakashi Iwai 			break;
3406f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3407f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3408f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3409f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3410f2e5731dSTakashi Iwai 				break;
3411f2e5731dSTakashi Iwai 			}
3412f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3413f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3414f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3415f2e5731dSTakashi Iwai 					break;
3416f2e5731dSTakashi Iwai 				}
3417f2e5731dSTakashi Iwai 			break;
3418f2e5731dSTakashi Iwai 		}
3419f2e5731dSTakashi Iwai 	}
3420f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
342189724958SDavid Henningsson 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3422f2e5731dSTakashi Iwai 
3423f2e5731dSTakashi Iwai 	if (cfg->hp_outs > 0)
3424f2e5731dSTakashi Iwai 		spec->auto_mute = 1;
3425f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3426f2e5731dSTakashi Iwai }
3427f2e5731dSTakashi Iwai 
3428da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3429da339866STakashi Iwai 			      hda_nid_t *pins, bool on);
3430da339866STakashi Iwai 
3431f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
3432f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3433f2e5731dSTakashi Iwai {
3434f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3435f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3436f2e5731dSTakashi Iwai 	int i, present;
3437f2e5731dSTakashi Iwai 
3438f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3439f2e5731dSTakashi Iwai 		return;
3440f2e5731dSTakashi Iwai 	present = 0;
3441f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
3442f2e5731dSTakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3443f2e5731dSTakashi Iwai 			present = 1;
3444f2e5731dSTakashi Iwai 			break;
3445f2e5731dSTakashi Iwai 		}
3446f2e5731dSTakashi Iwai 	}
3447da339866STakashi Iwai 	cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
3448f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->line_outs; i++) {
3449f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3450f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3451f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3452f2e5731dSTakashi Iwai 	}
3453da339866STakashi Iwai 	cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
3454fbb5bb56STakashi Iwai 	for (i = 0; !present && i < cfg->line_outs; i++)
3455fbb5bb56STakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3456fbb5bb56STakashi Iwai 			present = 1;
3457f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->speaker_outs; i++) {
3458f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3459f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3460f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3461f2e5731dSTakashi Iwai 	}
3462da339866STakashi Iwai 	cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
3463f2e5731dSTakashi Iwai }
3464f2e5731dSTakashi Iwai 
34656764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
34666764bcefSTakashi Iwai 				 struct snd_ctl_elem_info *uinfo)
34676764bcefSTakashi Iwai {
34686764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
34696764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
34706764bcefSTakashi Iwai 
34716764bcefSTakashi Iwai 	return snd_hda_input_mux_info(&spec->private_imux, uinfo);
34726764bcefSTakashi Iwai }
34736764bcefSTakashi Iwai 
34746764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
34756764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
34766764bcefSTakashi Iwai {
34776764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
34786764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
34796764bcefSTakashi Iwai 
34806764bcefSTakashi Iwai 	ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
34816764bcefSTakashi Iwai 	return 0;
34826764bcefSTakashi Iwai }
34836764bcefSTakashi Iwai 
34845c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index;
34855c9887e0STakashi Iwai  * if do_select is set, actually select the route.
34865c9887e0STakashi Iwai  */
34875c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3488cf27f29aSTakashi Iwai 				     hda_nid_t pin, hda_nid_t *srcp,
3489cf27f29aSTakashi Iwai 				     bool do_select, int depth)
34905c9887e0STakashi Iwai {
34915c9887e0STakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
34925c9887e0STakashi Iwai 	int i, nums;
34935c9887e0STakashi Iwai 
3494cf27f29aSTakashi Iwai 	switch (get_wcaps_type(get_wcaps(codec, mux))) {
3495cf27f29aSTakashi Iwai 	case AC_WID_AUD_IN:
3496cf27f29aSTakashi Iwai 	case AC_WID_AUD_SEL:
3497cf27f29aSTakashi Iwai 	case AC_WID_AUD_MIX:
3498cf27f29aSTakashi Iwai 		break;
3499cf27f29aSTakashi Iwai 	default:
3500cf27f29aSTakashi Iwai 		return -1;
3501cf27f29aSTakashi Iwai 	}
3502cf27f29aSTakashi Iwai 
35035c9887e0STakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
35045c9887e0STakashi Iwai 	for (i = 0; i < nums; i++)
35055c9887e0STakashi Iwai 		if (conn[i] == pin) {
35065c9887e0STakashi Iwai 			if (do_select)
35075c9887e0STakashi Iwai 				snd_hda_codec_write(codec, mux, 0,
35085c9887e0STakashi Iwai 						    AC_VERB_SET_CONNECT_SEL, i);
3509cf27f29aSTakashi Iwai 			if (srcp)
3510cf27f29aSTakashi Iwai 				*srcp = mux;
35115c9887e0STakashi Iwai 			return i;
35125c9887e0STakashi Iwai 		}
35135c9887e0STakashi Iwai 	depth++;
35145c9887e0STakashi Iwai 	if (depth == 2)
35155c9887e0STakashi Iwai 		return -1;
35165c9887e0STakashi Iwai 	for (i = 0; i < nums; i++) {
3517cf27f29aSTakashi Iwai 		int ret  = __select_input_connection(codec, conn[i], pin, srcp,
35185c9887e0STakashi Iwai 						     do_select, depth);
35195c9887e0STakashi Iwai 		if (ret >= 0) {
35205c9887e0STakashi Iwai 			if (do_select)
35215c9887e0STakashi Iwai 				snd_hda_codec_write(codec, mux, 0,
35225c9887e0STakashi Iwai 						    AC_VERB_SET_CONNECT_SEL, i);
3523cf27f29aSTakashi Iwai 			return i;
35245c9887e0STakashi Iwai 		}
35255c9887e0STakashi Iwai 	}
35265c9887e0STakashi Iwai 	return -1;
35275c9887e0STakashi Iwai }
35285c9887e0STakashi Iwai 
35295c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
35305c9887e0STakashi Iwai 				   hda_nid_t pin)
35315c9887e0STakashi Iwai {
3532cf27f29aSTakashi Iwai 	__select_input_connection(codec, mux, pin, NULL, true, 0);
35335c9887e0STakashi Iwai }
35345c9887e0STakashi Iwai 
35355c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
35365c9887e0STakashi Iwai 				hda_nid_t pin)
35375c9887e0STakashi Iwai {
3538cf27f29aSTakashi Iwai 	return __select_input_connection(codec, mux, pin, NULL, false, 0);
35395c9887e0STakashi Iwai }
35405c9887e0STakashi Iwai 
35416764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec,
35426764bcefSTakashi Iwai 				   const struct hda_input_mux *imux,
35436764bcefSTakashi Iwai 				   unsigned int idx)
35446764bcefSTakashi Iwai {
35456764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
35466764bcefSTakashi Iwai 	hda_nid_t adc;
35476764bcefSTakashi Iwai 
35486764bcefSTakashi Iwai 	if (!imux->num_items)
35496764bcefSTakashi Iwai 		return 0;
35506764bcefSTakashi Iwai 	if (idx >= imux->num_items)
35516764bcefSTakashi Iwai 		idx = imux->num_items - 1;
35526764bcefSTakashi Iwai 	if (spec->cur_mux[0] == idx)
35536764bcefSTakashi Iwai 		return 0;
355447ad1f4eSTakashi Iwai 	adc = spec->imux_info[idx].adc;
355547ad1f4eSTakashi Iwai 	select_input_connection(codec, spec->imux_info[idx].adc,
355647ad1f4eSTakashi Iwai 				spec->imux_info[idx].pin);
35576764bcefSTakashi Iwai 	if (spec->cur_adc && spec->cur_adc != adc) {
35586764bcefSTakashi Iwai 		/* stream is running, let's swap the current ADC */
35596764bcefSTakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
35606764bcefSTakashi Iwai 		spec->cur_adc = adc;
35616764bcefSTakashi Iwai 		snd_hda_codec_setup_stream(codec, adc,
35626764bcefSTakashi Iwai 					   spec->cur_adc_stream_tag, 0,
35636764bcefSTakashi Iwai 					   spec->cur_adc_format);
35646764bcefSTakashi Iwai 	}
35656764bcefSTakashi Iwai 	spec->cur_mux[0] = idx;
35666764bcefSTakashi Iwai 	return 1;
35676764bcefSTakashi Iwai }
35686764bcefSTakashi Iwai 
35696764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
35706764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
35716764bcefSTakashi Iwai {
35726764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
35736764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
35746764bcefSTakashi Iwai 
35756764bcefSTakashi Iwai 	return cx_auto_mux_enum_update(codec, &spec->private_imux,
35766764bcefSTakashi Iwai 				       ucontrol->value.enumerated.item[0]);
35776764bcefSTakashi Iwai }
35786764bcefSTakashi Iwai 
35796764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
35806764bcefSTakashi Iwai 	{
35816764bcefSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
35826764bcefSTakashi Iwai 		.name = "Capture Source",
35836764bcefSTakashi Iwai 		.info = cx_auto_mux_enum_info,
35846764bcefSTakashi Iwai 		.get = cx_auto_mux_enum_get,
35856764bcefSTakashi Iwai 		.put = cx_auto_mux_enum_put
35866764bcefSTakashi Iwai 	},
35876764bcefSTakashi Iwai 	{}
35886764bcefSTakashi Iwai };
35896764bcefSTakashi Iwai 
3590f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3591f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3592f2e5731dSTakashi Iwai {
3593f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3594f2e5731dSTakashi Iwai 	int ext_idx = spec->auto_mic_ext;
3595f2e5731dSTakashi Iwai 
3596f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3597f2e5731dSTakashi Iwai 		return;
359847ad1f4eSTakashi Iwai 	if (snd_hda_jack_detect(codec, spec->imux_info[ext_idx].pin))
35996764bcefSTakashi Iwai 		cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
36006764bcefSTakashi Iwai 	else
36016764bcefSTakashi Iwai 		cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
3602f2e5731dSTakashi Iwai }
3603f2e5731dSTakashi Iwai 
3604f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3605f2e5731dSTakashi Iwai {
3606f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3607f2e5731dSTakashi Iwai 	switch (res >> 26) {
3608f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3609f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3610cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3611f2e5731dSTakashi Iwai 		break;
3612f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3613f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3614cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3615f2e5731dSTakashi Iwai 		break;
3616f2e5731dSTakashi Iwai 	}
3617f2e5731dSTakashi Iwai }
3618f2e5731dSTakashi Iwai 
3619f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */
3620f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3621f2e5731dSTakashi Iwai {
3622f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3623f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
362499ae28beSTakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3625f2e5731dSTakashi Iwai }
3626f2e5731dSTakashi Iwai 
3627f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */
3628f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3629f2e5731dSTakashi Iwai {
3630f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3631f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3632f68b3b29STakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3633f68b3b29STakashi Iwai 		(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3634f2e5731dSTakashi Iwai }
3635f2e5731dSTakashi Iwai 
3636f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
3637f2e5731dSTakashi Iwai  * auto-mic is enabled only when one int-mic and one-ext mic exist
3638f2e5731dSTakashi Iwai  */
3639f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3640f2e5731dSTakashi Iwai {
3641f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3642f2e5731dSTakashi Iwai 
364347ad1f4eSTakashi Iwai 	if (is_ext_mic(codec, spec->imux_info[0].pin) &&
364447ad1f4eSTakashi Iwai 	    is_int_mic(codec, spec->imux_info[1].pin)) {
3645f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
36462557f742STakashi Iwai 		spec->auto_mic_ext = 0;
3647f2e5731dSTakashi Iwai 		return;
3648f2e5731dSTakashi Iwai 	}
364947ad1f4eSTakashi Iwai 	if (is_int_mic(codec, spec->imux_info[0].pin) &&
365047ad1f4eSTakashi Iwai 	    is_ext_mic(codec, spec->imux_info[1].pin)) {
3651f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
36522557f742STakashi Iwai 		spec->auto_mic_ext = 1;
3653f2e5731dSTakashi Iwai 		return;
3654f2e5731dSTakashi Iwai 	}
3655f2e5731dSTakashi Iwai }
3656f2e5731dSTakashi Iwai 
3657f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3658f2e5731dSTakashi Iwai {
3659f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3660f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3661f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
36626764bcefSTakashi Iwai 	int i, j;
3663f2e5731dSTakashi Iwai 
3664f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3665f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
36666764bcefSTakashi Iwai 		for (j = 0; j < spec->num_adc_nids; j++) {
36676764bcefSTakashi Iwai 			hda_nid_t adc = spec->adc_nids[j];
36685c9887e0STakashi Iwai 			int idx = get_input_connection(codec, adc,
3669f2e5731dSTakashi Iwai 						       cfg->inputs[i].pin);
3670f2e5731dSTakashi Iwai 			if (idx >= 0) {
3671f2e5731dSTakashi Iwai 				const char *label;
3672f2e5731dSTakashi Iwai 				label = hda_get_autocfg_input_label(codec, cfg, i);
367347ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].index = i;
367447ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].boost = 0;
367547ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].adc = adc;
367647ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].pin =
3677f6100bb4STakashi Iwai 					cfg->inputs[i].pin;
3678f2e5731dSTakashi Iwai 				snd_hda_add_imux_item(imux, label, idx, NULL);
36796764bcefSTakashi Iwai 				break;
36806764bcefSTakashi Iwai 			}
3681f2e5731dSTakashi Iwai 		}
3682f2e5731dSTakashi Iwai 	}
3683f2e5731dSTakashi Iwai 	if (imux->num_items == 2 && cfg->num_inputs == 2)
3684f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
36856764bcefSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic) {
36866764bcefSTakashi Iwai 		for (i = 1; i < imux->num_items; i++) {
368747ad1f4eSTakashi Iwai 			if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
36886764bcefSTakashi Iwai 				spec->adc_switching = 1;
36896764bcefSTakashi Iwai 				break;
36906764bcefSTakashi Iwai 			}
36916764bcefSTakashi Iwai 		}
36926764bcefSTakashi Iwai 	}
3693f2e5731dSTakashi Iwai }
3694f2e5731dSTakashi Iwai 
3695f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3696f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3697f2e5731dSTakashi Iwai {
3698f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3699f2e5731dSTakashi Iwai 
3700f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3701f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3702f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3703f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3704f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3705f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3706f2e5731dSTakashi Iwai 				return nid;
3707f2e5731dSTakashi Iwai 		}
3708f2e5731dSTakashi Iwai 	}
3709f2e5731dSTakashi Iwai 	return 0;
3710f2e5731dSTakashi Iwai }
3711f2e5731dSTakashi Iwai 
3712f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3713f2e5731dSTakashi Iwai {
3714f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3715f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3716f2e5731dSTakashi Iwai 	hda_nid_t nid;
3717f2e5731dSTakashi Iwai 
3718f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3719f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3720f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3721f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3722f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3723f2e5731dSTakashi Iwai }
3724f2e5731dSTakashi Iwai 
3725f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3726f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3727f2e5731dSTakashi Iwai {
3728f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3729f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3730f2e5731dSTakashi Iwai 
3731f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3732f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3733f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3734f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3735f2e5731dSTakashi Iwai 			break;
3736f2e5731dSTakashi Iwai 		}
3737f2e5731dSTakashi Iwai }
3738f2e5731dSTakashi Iwai #else
3739f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3740f2e5731dSTakashi Iwai #endif
3741f2e5731dSTakashi Iwai 
3742f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3743f2e5731dSTakashi Iwai {
3744f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3745f2e5731dSTakashi Iwai 	int err;
3746f2e5731dSTakashi Iwai 
3747f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3748f2e5731dSTakashi Iwai 	if (err < 0)
3749f2e5731dSTakashi Iwai 		return err;
3750f2e5731dSTakashi Iwai 
3751f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3752f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3753f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3754f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3755f2e5731dSTakashi Iwai 	return 0;
3756f2e5731dSTakashi Iwai }
3757f2e5731dSTakashi Iwai 
3758da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3759da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
3760f2e5731dSTakashi Iwai {
3761f2e5731dSTakashi Iwai 	int i;
3762f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3763f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3764f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3765da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
3766da339866STakashi Iwai 					    on ? 0x02 : 0);
3767f2e5731dSTakashi Iwai 	}
3768f2e5731dSTakashi Iwai }
3769f2e5731dSTakashi Iwai 
3770f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3771f2e5731dSTakashi Iwai 			      hda_nid_t src)
3772f2e5731dSTakashi Iwai {
3773f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3774f2e5731dSTakashi Iwai 	if (idx >= 0)
3775f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3776f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3777f2e5731dSTakashi Iwai }
3778f2e5731dSTakashi Iwai 
37791f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids,
37801f8458a2STakashi Iwai 			 const hda_nid_t *nids)
3781f2e5731dSTakashi Iwai {
37820ad1b5b6STakashi Iwai 	int i, val;
3783f2e5731dSTakashi Iwai 
37841f8458a2STakashi Iwai 	for (i = 0; i < num_nids; i++) {
37851f8458a2STakashi Iwai 		hda_nid_t nid = nids[i];
37861f8458a2STakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
37871f8458a2STakashi Iwai 			continue;
37880ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
37890ad1b5b6STakashi Iwai 			val = AMP_OUT_MUTE;
37900ad1b5b6STakashi Iwai 		else
37910ad1b5b6STakashi Iwai 			val = AMP_OUT_ZERO;
37920ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0,
37930ad1b5b6STakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, val);
37940ad1b5b6STakashi Iwai 	}
37951f8458a2STakashi Iwai }
3796f2e5731dSTakashi Iwai 
37971f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
37981f8458a2STakashi Iwai {
37991f8458a2STakashi Iwai 	struct conexant_spec *spec = codec->spec;
38001f8458a2STakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
38011f8458a2STakashi Iwai 	hda_nid_t nid;
38021f8458a2STakashi Iwai 	int i;
38031f8458a2STakashi Iwai 
38041f8458a2STakashi Iwai 	mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3805f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
3806f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3807f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
38081f8458a2STakashi Iwai 	mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
38091f8458a2STakashi Iwai 	mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
38101f8458a2STakashi Iwai 	mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3811f2e5731dSTakashi Iwai 	if (spec->auto_mute) {
3812f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->hp_outs; i++) {
3813f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3814f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3815f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_HP_EVENT);
3816f2e5731dSTakashi Iwai 		}
3817f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3818f2e5731dSTakashi Iwai 	} else {
3819f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++)
3820f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3821f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3822f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->speaker_outs; i++)
3823f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3824f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3825da339866STakashi Iwai 		/* turn on EAPD */
3826da339866STakashi Iwai 		cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3827da339866STakashi Iwai 				  true);
3828da339866STakashi Iwai 		cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3829da339866STakashi Iwai 				  true);
3830da339866STakashi Iwai 		cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3831da339866STakashi Iwai 				  true);
3832f2e5731dSTakashi Iwai 	}
3833f2e5731dSTakashi Iwai 
3834f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3835f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
3836f2e5731dSTakashi Iwai 		if (!nid)
3837f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
3838f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
3839f2e5731dSTakashi Iwai 	}
3840f2e5731dSTakashi Iwai }
3841f2e5731dSTakashi Iwai 
3842f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
3843f2e5731dSTakashi Iwai {
3844f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3845f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
38460ad1b5b6STakashi Iwai 	int i, val;
3847f2e5731dSTakashi Iwai 
38480ad1b5b6STakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
38490ad1b5b6STakashi Iwai 		hda_nid_t nid = spec->adc_nids[i];
38501f8458a2STakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
38511f8458a2STakashi Iwai 			continue;
38520ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
38530ad1b5b6STakashi Iwai 			val = AMP_IN_MUTE(0);
38540ad1b5b6STakashi Iwai 		else
38550ad1b5b6STakashi Iwai 			val = AMP_IN_UNMUTE(0);
38560ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
38570ad1b5b6STakashi Iwai 				    val);
38580ad1b5b6STakashi Iwai 	}
3859f2e5731dSTakashi Iwai 
3860f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3861f2e5731dSTakashi Iwai 		unsigned int type;
3862f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
3863f2e5731dSTakashi Iwai 			type = PIN_VREF80;
3864f2e5731dSTakashi Iwai 		else
3865f2e5731dSTakashi Iwai 			type = PIN_IN;
3866f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3867f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3868f2e5731dSTakashi Iwai 	}
3869f2e5731dSTakashi Iwai 
3870f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
3871f2e5731dSTakashi Iwai 		int ext_idx = spec->auto_mic_ext;
3872f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3873f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3874f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_MIC_EVENT);
3875f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3876f2e5731dSTakashi Iwai 	} else {
387747ad1f4eSTakashi Iwai 		select_input_connection(codec, spec->imux_info[0].adc,
387847ad1f4eSTakashi Iwai 					spec->imux_info[0].pin);
3879f2e5731dSTakashi Iwai 	}
3880f2e5731dSTakashi Iwai }
3881f2e5731dSTakashi Iwai 
3882f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
3883f2e5731dSTakashi Iwai {
3884f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3885f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3886f2e5731dSTakashi Iwai 
3887f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
3888f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3889f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3890f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
3891f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3892f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3893f2e5731dSTakashi Iwai }
3894f2e5731dSTakashi Iwai 
3895f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
3896f2e5731dSTakashi Iwai {
3897f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3898f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
3899f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
3900f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
3901f2e5731dSTakashi Iwai 	return 0;
3902f2e5731dSTakashi Iwai }
3903f2e5731dSTakashi Iwai 
3904983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
3905f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
3906983345e5SDavid Henningsson 			      hda_nid_t nid, int hda_dir, int amp_idx)
3907f2e5731dSTakashi Iwai {
3908f2e5731dSTakashi Iwai 	static char name[32];
3909f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
3910f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
3911f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
3912f2e5731dSTakashi Iwai 	};
391334cbe3a6STakashi Iwai 	static const char * const sfx[2] = { "Volume", "Switch" };
3914f2e5731dSTakashi Iwai 	int i, err;
3915f2e5731dSTakashi Iwai 
3916f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
3917f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
3918983345e5SDavid Henningsson 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3919983345e5SDavid Henningsson 							    hda_dir);
3920f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3921f2e5731dSTakashi Iwai 		knew[i].index = cidx;
3922f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3923f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
3924f2e5731dSTakashi Iwai 		if (!kctl)
3925f2e5731dSTakashi Iwai 			return -ENOMEM;
3926f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
3927f2e5731dSTakashi Iwai 		if (err < 0)
3928f2e5731dSTakashi Iwai 			return err;
3929f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3930f2e5731dSTakashi Iwai 			break;
3931f2e5731dSTakashi Iwai 	}
3932f2e5731dSTakashi Iwai 	return 0;
3933f2e5731dSTakashi Iwai }
3934f2e5731dSTakashi Iwai 
3935983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\
3936983345e5SDavid Henningsson 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3937983345e5SDavid Henningsson 
3938f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
3939f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3940f2e5731dSTakashi Iwai 
39411f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
39421f8458a2STakashi Iwai 			     hda_nid_t pin, const char *name, int idx)
39431f8458a2STakashi Iwai {
39441f8458a2STakashi Iwai 	unsigned int caps;
39451f8458a2STakashi Iwai 	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
39461f8458a2STakashi Iwai 	if (caps & AC_AMPCAP_NUM_STEPS)
39471f8458a2STakashi Iwai 		return cx_auto_add_pb_volume(codec, dac, name, idx);
39481f8458a2STakashi Iwai 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
39491f8458a2STakashi Iwai 	if (caps & AC_AMPCAP_NUM_STEPS)
39501f8458a2STakashi Iwai 		return cx_auto_add_pb_volume(codec, pin, name, idx);
39511f8458a2STakashi Iwai 	return 0;
39521f8458a2STakashi Iwai }
39531f8458a2STakashi Iwai 
3954f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
3955f2e5731dSTakashi Iwai {
3956f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3957f2e5731dSTakashi Iwai 	int i, err;
3958f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
3959ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3960f2e5731dSTakashi Iwai 
3961f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
39621f8458a2STakashi Iwai 		return try_add_pb_volume(codec, spec->dac_info[0].dac,
39631f8458a2STakashi Iwai 					 spec->dac_info[0].pin,
3964f2e5731dSTakashi Iwai 					 "Master", 0);
39651f8458a2STakashi Iwai 
3966f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3967f2e5731dSTakashi Iwai 		const char *label;
3968f2e5731dSTakashi Iwai 		int idx, type;
3969f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
3970f2e5731dSTakashi Iwai 			continue;
3971f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
3972f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
3973f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
3974f2e5731dSTakashi Iwai 		switch (type) {
3975f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3976f2e5731dSTakashi Iwai 		default:
3977f2e5731dSTakashi Iwai 			label = texts[num_line++];
3978f2e5731dSTakashi Iwai 			idx = 0;
3979f2e5731dSTakashi Iwai 			break;
3980f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3981f2e5731dSTakashi Iwai 			label = "Headphone";
3982f2e5731dSTakashi Iwai 			idx = num_hp++;
3983f2e5731dSTakashi Iwai 			break;
3984f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3985f2e5731dSTakashi Iwai 			label = "Speaker";
3986f2e5731dSTakashi Iwai 			idx = num_spk++;
3987f2e5731dSTakashi Iwai 			break;
3988f2e5731dSTakashi Iwai 		}
39891f8458a2STakashi Iwai 		err = try_add_pb_volume(codec, spec->dac_info[i].dac,
39901f8458a2STakashi Iwai 					spec->dac_info[i].pin,
3991f2e5731dSTakashi Iwai 					label, idx);
3992f2e5731dSTakashi Iwai 		if (err < 0)
3993f2e5731dSTakashi Iwai 			return err;
3994f2e5731dSTakashi Iwai 	}
3995f2e5731dSTakashi Iwai 	return 0;
3996f2e5731dSTakashi Iwai }
3997f2e5731dSTakashi Iwai 
39986764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
39996764bcefSTakashi Iwai 				      const char *label, const char *pfx,
40006764bcefSTakashi Iwai 				      int cidx)
40016764bcefSTakashi Iwai {
40026764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
40036764bcefSTakashi Iwai 	int i;
40046764bcefSTakashi Iwai 
40056764bcefSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
40066764bcefSTakashi Iwai 		hda_nid_t adc_nid = spec->adc_nids[i];
40075c9887e0STakashi Iwai 		int idx = get_input_connection(codec, adc_nid, nid);
40086764bcefSTakashi Iwai 		if (idx < 0)
40096764bcefSTakashi Iwai 			continue;
40106764bcefSTakashi Iwai 		return cx_auto_add_volume_idx(codec, label, pfx,
40116764bcefSTakashi Iwai 					      cidx, adc_nid, HDA_INPUT, idx);
40126764bcefSTakashi Iwai 	}
40136764bcefSTakashi Iwai 	return 0;
40146764bcefSTakashi Iwai }
40156764bcefSTakashi Iwai 
4016cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4017cf27f29aSTakashi Iwai 				    const char *label, int cidx)
4018cf27f29aSTakashi Iwai {
4019cf27f29aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4020cf27f29aSTakashi Iwai 	hda_nid_t mux, nid;
4021f9759301STakashi Iwai 	int i, con;
4022cf27f29aSTakashi Iwai 
402347ad1f4eSTakashi Iwai 	nid = spec->imux_info[idx].pin;
4024cf27f29aSTakashi Iwai 	if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4025cf27f29aSTakashi Iwai 		return cx_auto_add_volume(codec, label, " Boost", cidx,
4026cf27f29aSTakashi Iwai 					  nid, HDA_INPUT);
402747ad1f4eSTakashi Iwai 	con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
402847ad1f4eSTakashi Iwai 					&mux, false, 0);
4029cf27f29aSTakashi Iwai 	if (con < 0)
4030cf27f29aSTakashi Iwai 		return 0;
4031f9759301STakashi Iwai 	for (i = 0; i < idx; i++) {
403247ad1f4eSTakashi Iwai 		if (spec->imux_info[i].boost == mux)
4033f9759301STakashi Iwai 			return 0; /* already present */
4034f9759301STakashi Iwai 	}
4035f9759301STakashi Iwai 
4036f9759301STakashi Iwai 	if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
403747ad1f4eSTakashi Iwai 		spec->imux_info[idx].boost = mux;
4038cf27f29aSTakashi Iwai 		return cx_auto_add_volume(codec, label, " Boost", 0,
4039cf27f29aSTakashi Iwai 					  mux, HDA_OUTPUT);
4040f9759301STakashi Iwai 	}
4041cf27f29aSTakashi Iwai 	return 0;
4042cf27f29aSTakashi Iwai }
4043cf27f29aSTakashi Iwai 
4044f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
4045f2e5731dSTakashi Iwai {
4046f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4047cf27f29aSTakashi Iwai 	struct hda_input_mux *imux = &spec->private_imux;
4048cf27f29aSTakashi Iwai 	const char *prev_label;
4049cf27f29aSTakashi Iwai 	int input_conn[HDA_MAX_NUM_INPUTS];
40506764bcefSTakashi Iwai 	int i, err, cidx;
4051cf27f29aSTakashi Iwai 	int multi_connection;
4052cf27f29aSTakashi Iwai 
4053cf27f29aSTakashi Iwai 	multi_connection = 0;
4054cf27f29aSTakashi Iwai 	for (i = 0; i < imux->num_items; i++) {
405547ad1f4eSTakashi Iwai 		cidx = get_input_connection(codec, spec->imux_info[i].adc,
405647ad1f4eSTakashi Iwai 					    spec->imux_info[i].pin);
405747ad1f4eSTakashi Iwai 		input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
4058cf27f29aSTakashi Iwai 		if (i > 0 && input_conn[i] != input_conn[0])
4059cf27f29aSTakashi Iwai 			multi_connection = 1;
4060cf27f29aSTakashi Iwai 	}
4061983345e5SDavid Henningsson 
4062f2e5731dSTakashi Iwai 	prev_label = NULL;
4063f2e5731dSTakashi Iwai 	cidx = 0;
4064cf27f29aSTakashi Iwai 	for (i = 0; i < imux->num_items; i++) {
406547ad1f4eSTakashi Iwai 		hda_nid_t nid = spec->imux_info[i].pin;
4066f2e5731dSTakashi Iwai 		const char *label;
4067983345e5SDavid Henningsson 
4068cf27f29aSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, &spec->autocfg,
406947ad1f4eSTakashi Iwai 						    spec->imux_info[i].index);
4070f2e5731dSTakashi Iwai 		if (label == prev_label)
4071f2e5731dSTakashi Iwai 			cidx++;
4072f2e5731dSTakashi Iwai 		else
4073f2e5731dSTakashi Iwai 			cidx = 0;
4074f2e5731dSTakashi Iwai 		prev_label = label;
4075983345e5SDavid Henningsson 
4076cf27f29aSTakashi Iwai 		err = cx_auto_add_boost_volume(codec, i, label, cidx);
4077f2e5731dSTakashi Iwai 		if (err < 0)
4078f2e5731dSTakashi Iwai 			return err;
4079983345e5SDavid Henningsson 
4080cf27f29aSTakashi Iwai 		if (!multi_connection) {
4081f9759301STakashi Iwai 			if (i > 0)
4082f9759301STakashi Iwai 				continue;
40836764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
40846764bcefSTakashi Iwai 							 "Capture", "", cidx);
40856764bcefSTakashi Iwai 		} else {
40866764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
40876764bcefSTakashi Iwai 							 label, " Capture", cidx);
40886764bcefSTakashi Iwai 		}
4089983345e5SDavid Henningsson 		if (err < 0)
4090983345e5SDavid Henningsson 			return err;
4091983345e5SDavid Henningsson 	}
40926764bcefSTakashi Iwai 
40936764bcefSTakashi Iwai 	if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
40946764bcefSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
40956764bcefSTakashi Iwai 		if (err < 0)
40966764bcefSTakashi Iwai 			return err;
4097983345e5SDavid Henningsson 	}
40986764bcefSTakashi Iwai 
4099f2e5731dSTakashi Iwai 	return 0;
4100f2e5731dSTakashi Iwai }
4101f2e5731dSTakashi Iwai 
4102f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
4103f2e5731dSTakashi Iwai {
4104f2e5731dSTakashi Iwai 	int err;
4105f2e5731dSTakashi Iwai 
4106f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
4107f2e5731dSTakashi Iwai 	if (err < 0)
4108f2e5731dSTakashi Iwai 		return err;
4109f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
4110f2e5731dSTakashi Iwai 	if (err < 0)
4111f2e5731dSTakashi Iwai 		return err;
4112f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
4113f2e5731dSTakashi Iwai }
4114f2e5731dSTakashi Iwai 
411522ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec)
411622ce5f74STakashi Iwai {
411722ce5f74STakashi Iwai 	struct conexant_spec *spec = codec->spec;
411822ce5f74STakashi Iwai 	hda_nid_t nid, end_nid;
411922ce5f74STakashi Iwai 
412022ce5f74STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
412122ce5f74STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
412222ce5f74STakashi Iwai 		unsigned int caps = get_wcaps(codec, nid);
412322ce5f74STakashi Iwai 		if (get_wcaps_type(caps) != AC_WID_AUD_IN)
412422ce5f74STakashi Iwai 			continue;
412522ce5f74STakashi Iwai 		if (caps & AC_WCAP_DIGITAL)
412622ce5f74STakashi Iwai 			continue;
412722ce5f74STakashi Iwai 		if (snd_BUG_ON(spec->num_adc_nids >=
412822ce5f74STakashi Iwai 			       ARRAY_SIZE(spec->private_adc_nids)))
412922ce5f74STakashi Iwai 			break;
413022ce5f74STakashi Iwai 		spec->private_adc_nids[spec->num_adc_nids++] = nid;
413122ce5f74STakashi Iwai 	}
413222ce5f74STakashi Iwai 	spec->adc_nids = spec->private_adc_nids;
413322ce5f74STakashi Iwai 	return 0;
413422ce5f74STakashi Iwai }
413522ce5f74STakashi Iwai 
413622ce5f74STakashi Iwai 
413734cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
4138f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
4139f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
4140f2e5731dSTakashi Iwai 	.init = cx_auto_init,
4141f2e5731dSTakashi Iwai 	.free = conexant_free,
4142f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
4143f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
4144f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
4145f2e5731dSTakashi Iwai #endif
4146f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
4147f2e5731dSTakashi Iwai };
4148f2e5731dSTakashi Iwai 
4149f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
4150f2e5731dSTakashi Iwai {
4151f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
4152f2e5731dSTakashi Iwai 	int err;
4153f2e5731dSTakashi Iwai 
41541f8458a2STakashi Iwai 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
41551f8458a2STakashi Iwai 	       codec->chip_name);
41561f8458a2STakashi Iwai 
4157f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4158f2e5731dSTakashi Iwai 	if (!spec)
4159f2e5731dSTakashi Iwai 		return -ENOMEM;
4160f2e5731dSTakashi Iwai 	codec->spec = spec;
41611387cde5STakashi Iwai 	codec->pin_amp_workaround = 1;
416222ce5f74STakashi Iwai 	err = cx_auto_search_adcs(codec);
416322ce5f74STakashi Iwai 	if (err < 0)
416422ce5f74STakashi Iwai 		return err;
4165f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
4166f2e5731dSTakashi Iwai 	if (err < 0) {
4167f2e5731dSTakashi Iwai 		kfree(codec->spec);
4168f2e5731dSTakashi Iwai 		codec->spec = NULL;
4169f2e5731dSTakashi Iwai 		return err;
4170f2e5731dSTakashi Iwai 	}
41716764bcefSTakashi Iwai 	spec->capture_stream = &cx_auto_pcm_analog_capture;
4172f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
4173f2e5731dSTakashi Iwai 	if (spec->beep_amp)
4174f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
4175f2e5731dSTakashi Iwai 	return 0;
4176f2e5731dSTakashi Iwai }
4177f2e5731dSTakashi Iwai 
4178f2e5731dSTakashi Iwai /*
4179461e2c78STakashi Iwai  */
4180461e2c78STakashi Iwai 
418134cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
418282f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
418382f30040STobin Davis 	  .patch = patch_cxt5045 },
418482f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
418582f30040STobin Davis 	  .patch = patch_cxt5047 },
4186461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4187461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
41880fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
41890fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
419095a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
419195a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
4192850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
4193850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
41947b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
41957b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
41966da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
41976da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
4198f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
4199f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4200f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
4201f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4202f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
4203f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4204f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
4205f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4206f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
4207f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4208f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
4209f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4210f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
4211f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4212f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
4213f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4214c9b443d4STobin Davis 	{} /* terminator */
4215c9b443d4STobin Davis };
42161289e9e8STakashi Iwai 
42171289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
42181289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
42191289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
42200fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
422195a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
4222850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
42237b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
42246da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4225f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
4226f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
4227f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4228f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4229f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4230f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4231f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4232f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
42331289e9e8STakashi Iwai 
42341289e9e8STakashi Iwai MODULE_LICENSE("GPL");
42351289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
42361289e9e8STakashi Iwai 
42371289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
42381289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
42391289e9e8STakashi Iwai 	.owner = THIS_MODULE,
42401289e9e8STakashi Iwai };
42411289e9e8STakashi Iwai 
42421289e9e8STakashi Iwai static int __init patch_conexant_init(void)
42431289e9e8STakashi Iwai {
42441289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
42451289e9e8STakashi Iwai }
42461289e9e8STakashi Iwai 
42471289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
42481289e9e8STakashi Iwai {
42491289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
42501289e9e8STakashi Iwai }
42511289e9e8STakashi Iwai 
42521289e9e8STakashi Iwai module_init(patch_conexant_init)
42531289e9e8STakashi Iwai module_exit(patch_conexant_exit)
4254