xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision c82693db52beced0419cecf09a3c81adfe95a544)
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
4203697e2aSTakashi Iwai #define CONEXANT_LINE_EVENT	0x39
43c9b443d4STobin Davis 
44bc7a166dSUlrich Dangel /* Conexant 5051 specific */
45c9b443d4STobin Davis 
46ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
47bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
48bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
49bc7a166dSUlrich Dangel 
50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
51faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
52bc7a166dSUlrich Dangel 
53f2e5731dSTakashi Iwai struct pin_dac_pair {
54f2e5731dSTakashi Iwai 	hda_nid_t pin;
55f2e5731dSTakashi Iwai 	hda_nid_t dac;
56f2e5731dSTakashi Iwai 	int type;
57f2e5731dSTakashi Iwai };
58f2e5731dSTakashi Iwai 
5947ad1f4eSTakashi Iwai struct imux_info {
6047ad1f4eSTakashi Iwai 	hda_nid_t pin;		/* input pin NID */
6147ad1f4eSTakashi Iwai 	hda_nid_t adc;		/* connected ADC NID */
6247ad1f4eSTakashi Iwai 	hda_nid_t boost;	/* optional boost volume NID */
6347ad1f4eSTakashi Iwai 	int index;		/* corresponding to autocfg.input */
6447ad1f4eSTakashi Iwai };
6547ad1f4eSTakashi Iwai 
66c9b443d4STobin Davis struct conexant_spec {
67c9b443d4STobin Davis 
6834cbe3a6STakashi Iwai 	const struct snd_kcontrol_new *mixers[5];
69c9b443d4STobin Davis 	int num_mixers;
70dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
71c9b443d4STobin Davis 
72c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
73c9b443d4STobin Davis 						 * don't forget NULL
74c9b443d4STobin Davis 						 * termination!
75c9b443d4STobin Davis 						 */
76c9b443d4STobin Davis 	unsigned int num_init_verbs;
77c9b443d4STobin Davis 
78c9b443d4STobin Davis 	/* playback */
79c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
80c9b443d4STobin Davis 					 * max_channels, dacs must be set
81c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
82c9b443d4STobin Davis 					 */
83c9b443d4STobin Davis 	unsigned int cur_eapd;
8482f30040STobin Davis 	unsigned int hp_present;
8503697e2aSTakashi Iwai 	unsigned int line_present;
86faddaa5dSTakashi Iwai 	unsigned int auto_mic;
87f6100bb4STakashi Iwai 	int auto_mic_ext;		/* imux_pins[] index for ext mic */
8843c1b2e9STakashi Iwai 	int auto_mic_dock;		/* imux_pins[] index for dock mic */
8943c1b2e9STakashi Iwai 	int auto_mic_int;		/* imux_pins[] index for int mic */
90c9b443d4STobin Davis 	unsigned int need_dac_fix;
91f6a2491cSAndy Robinson 	hda_nid_t slave_dig_outs[2];
92c9b443d4STobin Davis 
93c9b443d4STobin Davis 	/* capture */
94c9b443d4STobin Davis 	unsigned int num_adc_nids;
9534cbe3a6STakashi Iwai 	const hda_nid_t *adc_nids;
96c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
97c9b443d4STobin Davis 
98461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
99461e2c78STakashi Iwai 	hda_nid_t cur_adc;
100461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
101461e2c78STakashi Iwai 	unsigned int cur_adc_format;
102461e2c78STakashi Iwai 
1036764bcefSTakashi Iwai 	const struct hda_pcm_stream *capture_stream;
1046764bcefSTakashi Iwai 
105c9b443d4STobin Davis 	/* capture source */
106c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
10734cbe3a6STakashi Iwai 	const hda_nid_t *capsrc_nids;
108c9b443d4STobin Davis 	unsigned int cur_mux[3];
109c9b443d4STobin Davis 
110c9b443d4STobin Davis 	/* channel model */
111c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
112c9b443d4STobin Davis 	int num_channel_mode;
113c9b443d4STobin Davis 
114c9b443d4STobin Davis 	/* PCM information */
115c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
116c9b443d4STobin Davis 
117c9b443d4STobin Davis 	unsigned int spdif_route;
118c9b443d4STobin Davis 
119c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
120c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
121c9b443d4STobin Davis 	struct hda_input_mux private_imux;
12247ad1f4eSTakashi Iwai 	struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
12322ce5f74STakashi Iwai 	hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
12441923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
125f2e5731dSTakashi Iwai 	struct pin_dac_pair dac_info[8];
126f2e5731dSTakashi Iwai 	int dac_info_filled;
127c9b443d4STobin Davis 
1280fb67e98SDaniel Drake 	unsigned int port_d_mode;
129f2e5731dSTakashi Iwai 	unsigned int auto_mute:1;	/* used in auto-parser */
13003697e2aSTakashi Iwai 	unsigned int detect_line:1;	/* Line-out detection enabled */
13103697e2aSTakashi Iwai 	unsigned int automute_lines:1;	/* automute line-out as well */
13203697e2aSTakashi Iwai 	unsigned int automute_hp_lo:1;	/* both HP and LO available */
133f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
134cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
135cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1367b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
137048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
138a1d6906eSDavid Henningsson 	unsigned int asus:1;
13975f8991dSDaniel Drake 
1406764bcefSTakashi Iwai 	unsigned int adc_switching:1;
1416764bcefSTakashi Iwai 
14275f8991dSDaniel Drake 	unsigned int ext_mic_present;
14375f8991dSDaniel Drake 	unsigned int recording;
14475f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
14575f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
146c4cfe66cSDaniel Drake 
147c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
148c4cfe66cSDaniel Drake 	 * through the microphone jack.
149c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
150c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
151c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
152c4cfe66cSDaniel Drake 	 * control. */
153c4cfe66cSDaniel Drake 	unsigned int dc_enable;
154c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
155c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1563507e2a8STakashi Iwai 
1573507e2a8STakashi Iwai 	unsigned int beep_amp;
158c9b443d4STobin Davis };
159c9b443d4STobin Davis 
160c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
161c9b443d4STobin Davis 				      struct hda_codec *codec,
162c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
163c9b443d4STobin Davis {
164c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1659a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1669a08160bSTakashi Iwai 					     hinfo);
167c9b443d4STobin Davis }
168c9b443d4STobin Davis 
169c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
170c9b443d4STobin Davis 					 struct hda_codec *codec,
171c9b443d4STobin Davis 					 unsigned int stream_tag,
172c9b443d4STobin Davis 					 unsigned int format,
173c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
174c9b443d4STobin Davis {
175c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
176c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
177c9b443d4STobin Davis 						stream_tag,
178c9b443d4STobin Davis 						format, substream);
179c9b443d4STobin Davis }
180c9b443d4STobin Davis 
181c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
182c9b443d4STobin Davis 					 struct hda_codec *codec,
183c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
184c9b443d4STobin Davis {
185c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
186c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
187c9b443d4STobin Davis }
188c9b443d4STobin Davis 
189c9b443d4STobin Davis /*
190c9b443d4STobin Davis  * Digital out
191c9b443d4STobin Davis  */
192c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
193c9b443d4STobin Davis 					  struct hda_codec *codec,
194c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
195c9b443d4STobin Davis {
196c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
197c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
198c9b443d4STobin Davis }
199c9b443d4STobin Davis 
200c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
201c9b443d4STobin Davis 					 struct hda_codec *codec,
202c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
203c9b443d4STobin Davis {
204c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
205c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
206c9b443d4STobin Davis }
207c9b443d4STobin Davis 
2086b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2096b97eb45STakashi Iwai 					 struct hda_codec *codec,
2106b97eb45STakashi Iwai 					 unsigned int stream_tag,
2116b97eb45STakashi Iwai 					 unsigned int format,
2126b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
2136b97eb45STakashi Iwai {
2146b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2156b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2166b97eb45STakashi Iwai 					     stream_tag,
2176b97eb45STakashi Iwai 					     format, substream);
2186b97eb45STakashi Iwai }
2196b97eb45STakashi Iwai 
220c9b443d4STobin Davis /*
221c9b443d4STobin Davis  * Analog capture
222c9b443d4STobin Davis  */
223c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
224c9b443d4STobin Davis 				      struct hda_codec *codec,
225c9b443d4STobin Davis 				      unsigned int stream_tag,
226c9b443d4STobin Davis 				      unsigned int format,
227c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
228c9b443d4STobin Davis {
229c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
23075f8991dSDaniel Drake 	if (spec->capture_prepare)
23175f8991dSDaniel Drake 		spec->capture_prepare(codec);
232c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
233c9b443d4STobin Davis 				   stream_tag, 0, format);
234c9b443d4STobin Davis 	return 0;
235c9b443d4STobin Davis }
236c9b443d4STobin Davis 
237c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
238c9b443d4STobin Davis 				      struct hda_codec *codec,
239c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
240c9b443d4STobin Davis {
241c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
242888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
24375f8991dSDaniel Drake 	if (spec->capture_cleanup)
24475f8991dSDaniel Drake 		spec->capture_cleanup(codec);
245c9b443d4STobin Davis 	return 0;
246c9b443d4STobin Davis }
247c9b443d4STobin Davis 
248c9b443d4STobin Davis 
249c9b443d4STobin Davis 
25034cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = {
251c9b443d4STobin Davis 	.substreams = 1,
252c9b443d4STobin Davis 	.channels_min = 2,
253c9b443d4STobin Davis 	.channels_max = 2,
254c9b443d4STobin Davis 	.nid = 0, /* fill later */
255c9b443d4STobin Davis 	.ops = {
256c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
257c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
258c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
259c9b443d4STobin Davis 	},
260c9b443d4STobin Davis };
261c9b443d4STobin Davis 
26234cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = {
263c9b443d4STobin Davis 	.substreams = 1,
264c9b443d4STobin Davis 	.channels_min = 2,
265c9b443d4STobin Davis 	.channels_max = 2,
266c9b443d4STobin Davis 	.nid = 0, /* fill later */
267c9b443d4STobin Davis 	.ops = {
268c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
269c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
270c9b443d4STobin Davis 	},
271c9b443d4STobin Davis };
272c9b443d4STobin Davis 
273c9b443d4STobin Davis 
27434cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = {
275c9b443d4STobin Davis 	.substreams = 1,
276c9b443d4STobin Davis 	.channels_min = 2,
277c9b443d4STobin Davis 	.channels_max = 2,
278c9b443d4STobin Davis 	.nid = 0, /* fill later */
279c9b443d4STobin Davis 	.ops = {
280c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2816b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2826b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
283c9b443d4STobin Davis 	},
284c9b443d4STobin Davis };
285c9b443d4STobin Davis 
28634cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = {
287c9b443d4STobin Davis 	.substreams = 1,
288c9b443d4STobin Davis 	.channels_min = 2,
289c9b443d4STobin Davis 	.channels_max = 2,
290c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
291c9b443d4STobin Davis };
292c9b443d4STobin Davis 
293461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
294461e2c78STakashi Iwai 				      struct hda_codec *codec,
295461e2c78STakashi Iwai 				      unsigned int stream_tag,
296461e2c78STakashi Iwai 				      unsigned int format,
297461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
298461e2c78STakashi Iwai {
299461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
300461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
301461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
302461e2c78STakashi Iwai 	spec->cur_adc_format = format;
303461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
304461e2c78STakashi Iwai 	return 0;
305461e2c78STakashi Iwai }
306461e2c78STakashi Iwai 
307461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
308461e2c78STakashi Iwai 				      struct hda_codec *codec,
309461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
310461e2c78STakashi Iwai {
311461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
312888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
313461e2c78STakashi Iwai 	spec->cur_adc = 0;
314461e2c78STakashi Iwai 	return 0;
315461e2c78STakashi Iwai }
316461e2c78STakashi Iwai 
31734cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
318461e2c78STakashi Iwai 	.substreams = 1,
319461e2c78STakashi Iwai 	.channels_min = 2,
320461e2c78STakashi Iwai 	.channels_max = 2,
321461e2c78STakashi Iwai 	.nid = 0, /* fill later */
322461e2c78STakashi Iwai 	.ops = {
323461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
324461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
325461e2c78STakashi Iwai 	},
326461e2c78STakashi Iwai };
327461e2c78STakashi Iwai 
328c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
329c9b443d4STobin Davis {
330c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
331c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
332c9b443d4STobin Davis 
333c9b443d4STobin Davis 	codec->num_pcms = 1;
334c9b443d4STobin Davis 	codec->pcm_info = info;
335c9b443d4STobin Davis 
336c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
337c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
338c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
339c9b443d4STobin Davis 		spec->multiout.max_channels;
340c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
341c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
3426764bcefSTakashi Iwai 	if (spec->capture_stream)
3436764bcefSTakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
3446764bcefSTakashi Iwai 	else {
345461e2c78STakashi Iwai 		if (codec->vendor_id == 0x14f15051)
346461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
347461e2c78STakashi Iwai 				cx5051_pcm_analog_capture;
3486764bcefSTakashi Iwai 		else {
349461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
350461e2c78STakashi Iwai 				conexant_pcm_analog_capture;
3516764bcefSTakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3526764bcefSTakashi Iwai 				spec->num_adc_nids;
3536764bcefSTakashi Iwai 		}
3546764bcefSTakashi Iwai 	}
355c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
356c9b443d4STobin Davis 
357c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
358c9b443d4STobin Davis 		info++;
359c9b443d4STobin Davis 		codec->num_pcms++;
360c9b443d4STobin Davis 		info->name = "Conexant Digital";
3617ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
362c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
363c9b443d4STobin Davis 			conexant_pcm_digital_playback;
364c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
365c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
366c9b443d4STobin Davis 		if (spec->dig_in_nid) {
367c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
368c9b443d4STobin Davis 				conexant_pcm_digital_capture;
369c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
370c9b443d4STobin Davis 				spec->dig_in_nid;
371c9b443d4STobin Davis 		}
372f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
373f6a2491cSAndy Robinson 			codec->slave_dig_outs = spec->slave_dig_outs;
374c9b443d4STobin Davis 	}
375c9b443d4STobin Davis 
376c9b443d4STobin Davis 	return 0;
377c9b443d4STobin Davis }
378c9b443d4STobin Davis 
379c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
380c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
381c9b443d4STobin Davis {
382c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
383c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
384c9b443d4STobin Davis 
385c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
386c9b443d4STobin Davis }
387c9b443d4STobin Davis 
388c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
389c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
390c9b443d4STobin Davis {
391c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
392c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
393c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
394c9b443d4STobin Davis 
395c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
396c9b443d4STobin Davis 	return 0;
397c9b443d4STobin Davis }
398c9b443d4STobin Davis 
399c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
400c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
401c9b443d4STobin Davis {
402c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
403c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
404c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
405c9b443d4STobin Davis 
406c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
407c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
408c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
409c9b443d4STobin Davis }
410c9b443d4STobin Davis 
411bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
412bc7a166dSUlrich Dangel {
413cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
414bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
415bc7a166dSUlrich Dangel 	int i;
416bc7a166dSUlrich Dangel 
417bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
418bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
419bc7a166dSUlrich Dangel 
420bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
421bc7a166dSUlrich Dangel 		while (hv->nid) {
422bc7a166dSUlrich Dangel 			int err = 0;
423bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
424bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
425cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
426cd372fb3STakashi Iwai 						SND_JACK_HEADPHONE, NULL);
427cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
428bc7a166dSUlrich Dangel 				break;
429bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
430bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
431cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
432cd372fb3STakashi Iwai 						SND_JACK_MICROPHONE, NULL);
433cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
434bc7a166dSUlrich Dangel 				break;
435bc7a166dSUlrich Dangel 			}
436bc7a166dSUlrich Dangel 			if (err < 0)
437bc7a166dSUlrich Dangel 				return err;
438bc7a166dSUlrich Dangel 			++hv;
439bc7a166dSUlrich Dangel 		}
440bc7a166dSUlrich Dangel 	}
441cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */
4425801f992STakashi Iwai 	return 0;
4435801f992STakashi Iwai }
444bc7a166dSUlrich Dangel 
445c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
446c9b443d4STobin Davis {
447c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
448c9b443d4STobin Davis 	int i;
449c9b443d4STobin Davis 
450c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
451c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
452c9b443d4STobin Davis 	return 0;
453c9b443d4STobin Davis }
454c9b443d4STobin Davis 
455c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
456c9b443d4STobin Davis {
457cd372fb3STakashi Iwai 	snd_hda_input_jack_free(codec);
458c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
459c9b443d4STobin Davis 	kfree(codec->spec);
460c9b443d4STobin Davis }
461c9b443d4STobin Davis 
46234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = {
463b880c74aSTakashi Iwai 	{
464b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
465b880c74aSTakashi Iwai 		.name = "Capture Source",
466b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
467b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
468b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
469b880c74aSTakashi Iwai 	},
470b880c74aSTakashi Iwai 	{}
471b880c74aSTakashi Iwai };
472b880c74aSTakashi Iwai 
4733507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
4743507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
47534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = {
4763507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
4773507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
4783507e2a8STakashi Iwai 	{ } /* end */
4793507e2a8STakashi Iwai };
4803507e2a8STakashi Iwai #endif
4813507e2a8STakashi Iwai 
482ea734963STakashi Iwai static const char * const slave_vols[] = {
483dd5746a8STakashi Iwai 	"Headphone Playback Volume",
484dd5746a8STakashi Iwai 	"Speaker Playback Volume",
485a3a85d39STakashi Iwai 	"Front Playback Volume",
486a3a85d39STakashi Iwai 	"Surround Playback Volume",
487a3a85d39STakashi Iwai 	"CLFE Playback Volume",
488dd5746a8STakashi Iwai 	NULL
489dd5746a8STakashi Iwai };
490dd5746a8STakashi Iwai 
491ea734963STakashi Iwai static const char * const slave_sws[] = {
492dd5746a8STakashi Iwai 	"Headphone Playback Switch",
493dd5746a8STakashi Iwai 	"Speaker Playback Switch",
494a3a85d39STakashi Iwai 	"Front Playback Switch",
495a3a85d39STakashi Iwai 	"Surround Playback Switch",
496a3a85d39STakashi Iwai 	"CLFE Playback Switch",
497dd5746a8STakashi Iwai 	NULL
498dd5746a8STakashi Iwai };
499dd5746a8STakashi Iwai 
500c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
501c9b443d4STobin Davis {
502c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
503c9b443d4STobin Davis 	unsigned int i;
504c9b443d4STobin Davis 	int err;
505c9b443d4STobin Davis 
506c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
507c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
508c9b443d4STobin Davis 		if (err < 0)
509c9b443d4STobin Davis 			return err;
510c9b443d4STobin Davis 	}
511c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
512c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
51374b654c9SStephen Warren 						    spec->multiout.dig_out_nid,
514c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
515c9b443d4STobin Davis 		if (err < 0)
516c9b443d4STobin Davis 			return err;
5179a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5189a08160bSTakashi Iwai 						    &spec->multiout);
5199a08160bSTakashi Iwai 		if (err < 0)
5209a08160bSTakashi Iwai 			return err;
5219a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
522c9b443d4STobin Davis 	}
523c9b443d4STobin Davis 	if (spec->dig_in_nid) {
524c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
525c9b443d4STobin Davis 		if (err < 0)
526c9b443d4STobin Davis 			return err;
527c9b443d4STobin Davis 	}
528dd5746a8STakashi Iwai 
529dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
530dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
531dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
532dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
533dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
534dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
535dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
536dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
537dd5746a8STakashi Iwai 		if (err < 0)
538dd5746a8STakashi Iwai 			return err;
539dd5746a8STakashi Iwai 	}
540dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
541dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
542dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
543dd5746a8STakashi Iwai 					  NULL, slave_sws);
544dd5746a8STakashi Iwai 		if (err < 0)
545dd5746a8STakashi Iwai 			return err;
546dd5746a8STakashi Iwai 	}
547dd5746a8STakashi Iwai 
548b880c74aSTakashi Iwai 	if (spec->input_mux) {
549b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
550b880c74aSTakashi Iwai 		if (err < 0)
551b880c74aSTakashi Iwai 			return err;
552b880c74aSTakashi Iwai 	}
553b880c74aSTakashi Iwai 
5543507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5553507e2a8STakashi Iwai 	/* create beep controls if needed */
5563507e2a8STakashi Iwai 	if (spec->beep_amp) {
55734cbe3a6STakashi Iwai 		const struct snd_kcontrol_new *knew;
5583507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
5593507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
5603507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
5613507e2a8STakashi Iwai 			if (!kctl)
5623507e2a8STakashi Iwai 				return -ENOMEM;
5633507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
5643507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
5653507e2a8STakashi Iwai 			if (err < 0)
5663507e2a8STakashi Iwai 				return err;
5673507e2a8STakashi Iwai 		}
5683507e2a8STakashi Iwai 	}
5693507e2a8STakashi Iwai #endif
5703507e2a8STakashi Iwai 
571c9b443d4STobin Davis 	return 0;
572c9b443d4STobin Davis }
573c9b443d4STobin Davis 
574697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
575697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
576697c373eSTakashi Iwai {
577697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
578697c373eSTakashi Iwai 	return 0;
579697c373eSTakashi Iwai }
580697c373eSTakashi Iwai #endif
581697c373eSTakashi Iwai 
58234cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = {
583c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
584c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
585c9b443d4STobin Davis 	.init = conexant_init,
586c9b443d4STobin Davis 	.free = conexant_free,
587697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
588697c373eSTakashi Iwai 	.suspend = conexant_suspend,
589697c373eSTakashi Iwai #endif
590697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
591c9b443d4STobin Davis };
592c9b443d4STobin Davis 
5933507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5943507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
5953507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
5963507e2a8STakashi Iwai #else
5973507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5983507e2a8STakashi Iwai #endif
5993507e2a8STakashi Iwai 
6006764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec);
601c9b443d4STobin Davis /*
602c9b443d4STobin Davis  * EAPD control
603c9b443d4STobin Davis  * the private value = nid | (invert << 8)
604c9b443d4STobin Davis  */
605c9b443d4STobin Davis 
606a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
607c9b443d4STobin Davis 
60882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
609c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
610c9b443d4STobin Davis {
611c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
613c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
614c9b443d4STobin Davis 	if (invert)
615c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
616c9b443d4STobin Davis 	else
617c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
618c9b443d4STobin Davis 	return 0;
61982f30040STobin Davis 
620c9b443d4STobin Davis }
621c9b443d4STobin Davis 
62282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
623c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
624c9b443d4STobin Davis {
625c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
627c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
628c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
629c9b443d4STobin Davis 	unsigned int eapd;
63082f30040STobin Davis 
63168ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
632c9b443d4STobin Davis 	if (invert)
633c9b443d4STobin Davis 		eapd = !eapd;
63482beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
635c9b443d4STobin Davis 		return 0;
63682f30040STobin Davis 
637c9b443d4STobin Davis 	spec->cur_eapd = eapd;
63882beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
639c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
640c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
641c9b443d4STobin Davis 	return 1;
642c9b443d4STobin Davis }
643c9b443d4STobin Davis 
64486d72bdfSTakashi Iwai /* controls for test mode */
64586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
64686d72bdfSTakashi Iwai 
64782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
64882f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
64982f30040STobin Davis 	  .info = cxt_eapd_info, \
65082f30040STobin Davis 	  .get = cxt_eapd_get, \
65182f30040STobin Davis 	  .put = cxt_eapd_put, \
65282f30040STobin Davis 	  .private_value = nid | (mask<<16) }
65382f30040STobin Davis 
65482f30040STobin Davis 
65582f30040STobin Davis 
656c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
657c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
658c9b443d4STobin Davis {
659c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
661c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
662c9b443d4STobin Davis 				    spec->num_channel_mode);
663c9b443d4STobin Davis }
664c9b443d4STobin Davis 
665c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
666c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
667c9b443d4STobin Davis {
668c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
669c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
670c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
671c9b443d4STobin Davis 				   spec->num_channel_mode,
672c9b443d4STobin Davis 				   spec->multiout.max_channels);
673c9b443d4STobin Davis }
674c9b443d4STobin Davis 
675c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
676c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
677c9b443d4STobin Davis {
678c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
680c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
681c9b443d4STobin Davis 				      spec->num_channel_mode,
682c9b443d4STobin Davis 				      &spec->multiout.max_channels);
683c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
684c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
685c9b443d4STobin Davis 	return err;
686c9b443d4STobin Davis }
687c9b443d4STobin Davis 
688c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
689c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
690c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
691c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
692c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
693c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
694c9b443d4STobin Davis 
69586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
69686d72bdfSTakashi Iwai 
697c9b443d4STobin Davis /* Conexant 5045 specific */
698c9b443d4STobin Davis 
69934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
70034cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
70134cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
702cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
703c9b443d4STobin Davis 
70434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = {
7055cd57529STobin Davis 	{ 2, NULL },
7065cd57529STobin Davis };
707c9b443d4STobin Davis 
70834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = {
709c9b443d4STobin Davis 	.num_items = 2,
710c9b443d4STobin Davis 	.items = {
71182f30040STobin Davis 		{ "IntMic", 0x1 },
712f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
713c9b443d4STobin Davis 	}
714c9b443d4STobin Davis };
715c9b443d4STobin Davis 
71634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = {
71722e14130SLukasz Marcinowski 	.num_items = 5,
7185218c892SJiang Zhe 	.items = {
7195218c892SJiang Zhe 		{ "IntMic", 0x1 },
7205218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7215218c892SJiang Zhe 		{ "LineIn", 0x3 },
72222e14130SLukasz Marcinowski 		{ "CD",     0x4 },
72322e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7245218c892SJiang Zhe 	}
7255218c892SJiang Zhe };
7265218c892SJiang Zhe 
72734cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = {
7282de3c232SJiang zhe 	.num_items = 2,
7292de3c232SJiang zhe 	.items = {
7302de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7312de3c232SJiang zhe 		{ "IntMic", 0x2 },
7322de3c232SJiang zhe 	}
7332de3c232SJiang zhe };
7342de3c232SJiang zhe 
735c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
736c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
737c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
738c9b443d4STobin Davis {
739c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
740c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
74182f30040STobin Davis 	unsigned int bits;
742c9b443d4STobin Davis 
74382f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
744c9b443d4STobin Davis 		return 0;
745c9b443d4STobin Davis 
74682f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
74782f30040STobin Davis 	 * the headphone jack
74882f30040STobin Davis 	 */
74947fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
75047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
75147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7527f29673bSTobin Davis 
75347fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
75447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
75547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
756c9b443d4STobin Davis 	return 1;
757c9b443d4STobin Davis }
758c9b443d4STobin Davis 
759c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
76034cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
761cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
762cca3b371STakashi Iwai 	.values = {
763cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
764cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
765cca3b371STakashi Iwai 		0
766cca3b371STakashi Iwai 	},
767cca3b371STakashi Iwai };
768c9b443d4STobin Davis 
7697f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7707f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7717f29673bSTobin Davis {
77234cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
7737f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7747f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7757f29673bSTobin Davis 		{}
7767f29673bSTobin Davis 	};
77734cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
7787f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7797f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7807f29673bSTobin Davis 		{}
7817f29673bSTobin Davis 	};
7827f29673bSTobin Davis 	unsigned int present;
7837f29673bSTobin Davis 
784d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7857f29673bSTobin Davis 	if (present)
7867f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7877f29673bSTobin Davis 	else
7887f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7897f29673bSTobin Davis }
7907f29673bSTobin Davis 
791c9b443d4STobin Davis 
792c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
793c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
794c9b443d4STobin Davis {
79582f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
796dd87da1cSTobin Davis 	unsigned int bits;
797c9b443d4STobin Davis 
798d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
799dd87da1cSTobin Davis 
80047fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
80147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
80247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
803c9b443d4STobin Davis }
804c9b443d4STobin Davis 
805c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
806c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
807c9b443d4STobin Davis 				   unsigned int res)
808c9b443d4STobin Davis {
809c9b443d4STobin Davis 	res >>= 26;
810c9b443d4STobin Davis 	switch (res) {
811c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
812c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
813c9b443d4STobin Davis 		break;
8147f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8157f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8167f29673bSTobin Davis 		break;
8177f29673bSTobin Davis 
818c9b443d4STobin Davis 	}
819c9b443d4STobin Davis }
820c9b443d4STobin Davis 
82134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = {
82228c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
82328c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8248607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8258607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
826c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
827c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
82828c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
82928c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8308607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8318607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
832cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
833c9b443d4STobin Davis 	{
834c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
835c9b443d4STobin Davis 		.name = "Master Playback Switch",
83682f30040STobin Davis 		.info = cxt_eapd_info,
83782f30040STobin Davis 		.get = cxt_eapd_get,
838c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
83982f30040STobin Davis 		.private_value = 0x10,
840c9b443d4STobin Davis 	},
841c9b443d4STobin Davis 
842c9b443d4STobin Davis 	{}
843c9b443d4STobin Davis };
844c9b443d4STobin Davis 
84534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
84622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
84722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
84822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
84922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
85022e14130SLukasz Marcinowski 
8515218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8525218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8535218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8545218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8555218c892SJiang Zhe 
85622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
85722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
85822e14130SLukasz Marcinowski 
8595218c892SJiang Zhe 	{}
8605218c892SJiang Zhe };
8615218c892SJiang Zhe 
86234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
86328c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
86428c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8658607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8668607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8672de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8682de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
86928c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
87028c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8718607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8728607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8732de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8742de3c232SJiang zhe 	{
8752de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8762de3c232SJiang zhe 		.name = "Master Playback Switch",
8772de3c232SJiang zhe 		.info = cxt_eapd_info,
8782de3c232SJiang zhe 		.get = cxt_eapd_get,
8792de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8802de3c232SJiang zhe 		.private_value = 0x10,
8812de3c232SJiang zhe 	},
8822de3c232SJiang zhe 
8832de3c232SJiang zhe 	{}
8842de3c232SJiang zhe };
8852de3c232SJiang zhe 
88634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = {
887c9b443d4STobin Davis 	/* Line in, Mic */
8884090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8897f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
890c9b443d4STobin Davis 	/* HP, Amp  */
891c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
892c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
89382f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
894c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
895c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
896c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
897c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
898c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
899c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
90028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9017f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
90282f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
903c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
904c9b443d4STobin Davis 	/* SPDIF route: PCM */
905cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
906c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
907c9b443d4STobin Davis 	/* EAPD */
90882f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
909c9b443d4STobin Davis 	{ } /* end */
910c9b443d4STobin Davis };
911c9b443d4STobin Davis 
91234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = {
91328c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
9145218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9155218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9165218c892SJiang Zhe 	/* Line In,HP, Amp  */
9175218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9185218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9195218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9205218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9215218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9225218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9235218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9245218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9255218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
92628c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9275218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9285218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9295218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9305218c892SJiang Zhe 	/* SPDIF route: PCM */
931cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9325218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9335218c892SJiang Zhe 	/* EAPD */
9345218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9355218c892SJiang Zhe 	{ } /* end */
9365218c892SJiang Zhe };
9377f29673bSTobin Davis 
93834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9397f29673bSTobin Davis 	/* pin sensing on HP jack */
9407f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
941d3091fadSTakashi Iwai 	{ } /* end */
9427f29673bSTobin Davis };
9437f29673bSTobin Davis 
94434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9457f29673bSTobin Davis 	/* pin sensing on HP jack */
9467f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
947d3091fadSTakashi Iwai 	{ } /* end */
9487f29673bSTobin Davis };
9497f29673bSTobin Davis 
950c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
951c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
952c9b443d4STobin Davis  * configuration.
953c9b443d4STobin Davis  */
95434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = {
955c9b443d4STobin Davis 	.num_items = 5,
956c9b443d4STobin Davis 	.items = {
957c9b443d4STobin Davis 		{ "MIXER", 0x0 },
958c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
959c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
960c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
961c9b443d4STobin Davis 		{ "CD pin", 0x4 },
962c9b443d4STobin Davis         },
963c9b443d4STobin Davis };
964c9b443d4STobin Davis 
96534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
966c9b443d4STobin Davis 
967c9b443d4STobin Davis 	/* Output controls */
968c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
969c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9707f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9717f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9727f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9737f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
974c9b443d4STobin Davis 
975c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
976c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
977c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
978c9b443d4STobin Davis 
97982f30040STobin Davis 	/* EAPD Switch Control */
98082f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
98182f30040STobin Davis 
982c9b443d4STobin Davis 	/* Loopback mixer controls */
983c9b443d4STobin Davis 
9847f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9857f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9867f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9877f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9887f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9897f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9907f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9917f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9927f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9937f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
994c9b443d4STobin Davis 	{
995c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
996c9b443d4STobin Davis 		.name = "Input Source",
997c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
998c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
999c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1000c9b443d4STobin Davis 	},
1001fb3409e7STobin Davis 	/* Audio input controls */
1002fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1003fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1004fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1005fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1006fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1007fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1008fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1009fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1010fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1011fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1012c9b443d4STobin Davis 	{ } /* end */
1013c9b443d4STobin Davis };
1014c9b443d4STobin Davis 
101534cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = {
10167f29673bSTobin Davis 	/* Set connections */
10177f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10187f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10197f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1020c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1021c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10227f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1023c9b443d4STobin Davis 
1024c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1025c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1026c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1027c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1028c9b443d4STobin Davis 	 * control.
1029c9b443d4STobin Davis 	 */
1030cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1031cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1032c9b443d4STobin Davis 
1033c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1034c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1035c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1036c9b443d4STobin Davis 
1037c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1038c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1039c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1040c9b443d4STobin Davis 	 * input/output buffers as needed.
1041c9b443d4STobin Davis 	 */
1042c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1043c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1044c9b443d4STobin Davis 
1045c9b443d4STobin Davis 	/* Mute capture amp left and right */
1046c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1047c9b443d4STobin Davis 
1048c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1049c9b443d4STobin Davis 	 * pin)
1050c9b443d4STobin Davis 	 */
1051c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10527f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1053c9b443d4STobin Davis 
1054c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1055c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1056c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1057c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1058c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1059c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1060c9b443d4STobin Davis 
1061c9b443d4STobin Davis 	{ }
1062c9b443d4STobin Davis };
1063c9b443d4STobin Davis #endif
1064c9b443d4STobin Davis 
1065c9b443d4STobin Davis 
1066c9b443d4STobin Davis /* initialize jack-sensing, too */
1067c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1068c9b443d4STobin Davis {
1069c9b443d4STobin Davis 	conexant_init(codec);
1070c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1071c9b443d4STobin Davis 	return 0;
1072c9b443d4STobin Davis }
1073c9b443d4STobin Davis 
1074c9b443d4STobin Davis 
1075c9b443d4STobin Davis enum {
107615908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
107715908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
107815908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10795218c892SJiang Zhe 	CXT5045_BENQ,
10802de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1081c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1082c9b443d4STobin Davis 	CXT5045_TEST,
1083c9b443d4STobin Davis #endif
10841f8458a2STakashi Iwai 	CXT5045_AUTO,
1085f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1086c9b443d4STobin Davis };
1087c9b443d4STobin Davis 
1088ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
108915908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
109015908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
109115908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10925218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10932de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1094c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1095f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1096c9b443d4STobin Davis #endif
10971f8458a2STakashi Iwai 	[CXT5045_AUTO]			= "auto",
1098f5fcc13cSTakashi Iwai };
1099c9b443d4STobin Davis 
110034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
11012de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1102dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1103dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
11046a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
11055218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
110615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
110715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
11089e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
11099e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
111015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
111115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
111215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1113dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1114dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
111515908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1116c9b443d4STobin Davis 	{}
1117c9b443d4STobin Davis };
1118c9b443d4STobin Davis 
1119c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1120c9b443d4STobin Davis {
1121c9b443d4STobin Davis 	struct conexant_spec *spec;
1122c9b443d4STobin Davis 	int board_config;
1123c9b443d4STobin Davis 
11241f8458a2STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
11251f8458a2STakashi Iwai 						  cxt5045_models,
11261f8458a2STakashi Iwai 						  cxt5045_cfg_tbl);
11271f8458a2STakashi Iwai 	if (board_config < 0)
1128*c82693dbSTakashi Iwai 		board_config = CXT5045_AUTO; /* model=auto as default */
11291f8458a2STakashi Iwai 	if (board_config == CXT5045_AUTO)
11301f8458a2STakashi Iwai 		return patch_conexant_auto(codec);
11311f8458a2STakashi Iwai 
1132c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1133c9b443d4STobin Davis 	if (!spec)
1134c9b443d4STobin Davis 		return -ENOMEM;
1135c9b443d4STobin Davis 	codec->spec = spec;
11369421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1137c9b443d4STobin Davis 
1138c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1139c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1140c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1141c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1142c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1143c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1144c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1145c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1146c9b443d4STobin Davis 	spec->num_mixers = 1;
1147c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1148c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1149c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1150c9b443d4STobin Davis 	spec->spdif_route = 0;
11513507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11523507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11535cd57529STobin Davis 
11543507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1155c9b443d4STobin Davis 
1156c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1157c9b443d4STobin Davis 
1158c9b443d4STobin Davis 	switch (board_config) {
115915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11607f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1161c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1162c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11637f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11647f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11657f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11667f29673bSTobin Davis 		break;
116715908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
116886376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11697f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11707f29673bSTobin Davis 		spec->num_init_verbs = 2;
11717f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1172c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1173c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1174c9b443d4STobin Davis 		break;
117515908c36SMarc Boucher 	default:
117615908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
117715908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
117815908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
117915908c36SMarc Boucher 		spec->num_init_verbs = 3;
118015908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
118115908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
118215908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
118315908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
118415908c36SMarc Boucher 		break;
11855218c892SJiang Zhe 	case CXT5045_BENQ:
11865218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11875218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11885218c892SJiang Zhe 		spec->num_init_verbs = 1;
11895218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11905218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11915218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11925218c892SJiang Zhe 		spec->num_mixers = 2;
11935218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11945218c892SJiang Zhe 		break;
11952de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11962de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11972de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11982de3c232SJiang zhe 		spec->num_init_verbs = 2;
11992de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12002de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
12012de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
12022de3c232SJiang zhe 		break;
1203c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1204c9b443d4STobin Davis 	case CXT5045_TEST:
1205c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1206c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1207c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
120815908c36SMarc Boucher 		break;
120915908c36SMarc Boucher 
1210c9b443d4STobin Davis #endif
1211c9b443d4STobin Davis 	}
121248ecb7e8STakashi Iwai 
1213031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1214031005f7STakashi Iwai 	case 0x103c:
12158f0f5ff6SDaniel T Chen 	case 0x1631:
12160b587fc4SDaniel T Chen 	case 0x1734:
12170ebf9e36SDaniel T Chen 	case 0x17aa:
12180ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12190ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12200ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
122148ecb7e8STakashi Iwai 		 */
122248ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
122348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
122448ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
122548ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
122648ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1227031005f7STakashi Iwai 		break;
1228031005f7STakashi Iwai 	}
122948ecb7e8STakashi Iwai 
12303507e2a8STakashi Iwai 	if (spec->beep_amp)
12313507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12323507e2a8STakashi Iwai 
1233c9b443d4STobin Davis 	return 0;
1234c9b443d4STobin Davis }
1235c9b443d4STobin Davis 
1236c9b443d4STobin Davis 
1237c9b443d4STobin Davis /* Conexant 5047 specific */
123882f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1239c9b443d4STobin Davis 
124034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
124134cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
124234cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1243c9b443d4STobin Davis 
124434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
12455cd57529STobin Davis 	{ 2, NULL },
12465cd57529STobin Davis };
1247c9b443d4STobin Davis 
124834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
124982f30040STobin Davis 	.num_items = 2,
125082f30040STobin Davis 	.items = {
125182f30040STobin Davis 		{ "ExtMic", 0x2 },
125282f30040STobin Davis 		{ "Line-In", 0x1 },
1253c9b443d4STobin Davis 	}
1254c9b443d4STobin Davis };
1255c9b443d4STobin Davis 
1256c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1257c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1258c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1259c9b443d4STobin Davis {
1260c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1261c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
126282f30040STobin Davis 	unsigned int bits;
1263c9b443d4STobin Davis 
126482f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1265c9b443d4STobin Davis 		return 0;
1266c9b443d4STobin Davis 
126782f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
126882f30040STobin Davis 	 * the headphone jack
126982f30040STobin Davis 	 */
127047fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12713b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12723b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12733b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12743b7523fcSTakashi Iwai 	 */
12755d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
127647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
127747fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
127847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
127947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1280c9b443d4STobin Davis 	return 1;
1281c9b443d4STobin Davis }
1282c9b443d4STobin Davis 
1283c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1284c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1285c9b443d4STobin Davis {
128682f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1287dd87da1cSTobin Davis 	unsigned int bits;
1288c9b443d4STobin Davis 
1289d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1290dd87da1cSTobin Davis 
129147fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12923b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12935d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
129447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1295c9b443d4STobin Davis }
1296c9b443d4STobin Davis 
1297c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1298c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1299c9b443d4STobin Davis {
130034cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
13019f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13029f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1303c9b443d4STobin Davis 		{}
1304c9b443d4STobin Davis 	};
130534cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
13069f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13079f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1308c9b443d4STobin Davis 		{}
1309c9b443d4STobin Davis 	};
1310c9b443d4STobin Davis 	unsigned int present;
1311c9b443d4STobin Davis 
1312d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1313c9b443d4STobin Davis 	if (present)
1314c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1315c9b443d4STobin Davis 	else
1316c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1317c9b443d4STobin Davis }
1318c9b443d4STobin Davis 
1319c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1320c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1321c9b443d4STobin Davis 				  unsigned int res)
1322c9b443d4STobin Davis {
13239f113e0eSMarc Boucher 	switch (res >> 26) {
1324c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1325c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1326c9b443d4STobin Davis 		break;
1327c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1328c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1329c9b443d4STobin Davis 		break;
1330c9b443d4STobin Davis 	}
1331c9b443d4STobin Davis }
1332c9b443d4STobin Davis 
133334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1334df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1335df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
13365f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1337c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1338c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1339c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1340c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
134182f30040STobin Davis 	{
134282f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
134382f30040STobin Davis 		.name = "Master Playback Switch",
134482f30040STobin Davis 		.info = cxt_eapd_info,
134582f30040STobin Davis 		.get = cxt_eapd_get,
1346c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1347c9b443d4STobin Davis 		.private_value = 0x13,
1348c9b443d4STobin Davis 	},
1349c9b443d4STobin Davis 
1350c9b443d4STobin Davis 	{}
1351c9b443d4STobin Davis };
1352c9b443d4STobin Davis 
135334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13543b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13555d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1356df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1357df481e41STakashi Iwai 	{}
1358df481e41STakashi Iwai };
1359df481e41STakashi Iwai 
136034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1361c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1362c9b443d4STobin Davis 	{ } /* end */
1363c9b443d4STobin Davis };
1364c9b443d4STobin Davis 
136534cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1366c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1367c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1368c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1369c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13707f29673bSTobin Davis 	/* HP, Speaker  */
1371b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13725b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13735b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13747f29673bSTobin Davis 	/* Record selector: Mic */
13757f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13767f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13777f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13787f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1379c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1380c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1381c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1382c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1383c9b443d4STobin Davis 	/* SPDIF route: PCM */
1384c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
138582f30040STobin Davis 	/* Enable unsolicited events */
138682f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
138782f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1388c9b443d4STobin Davis 	{ } /* end */
1389c9b443d4STobin Davis };
1390c9b443d4STobin Davis 
1391c9b443d4STobin Davis /* configuration for Toshiba Laptops */
139234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13933b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1394c9b443d4STobin Davis 	{}
1395c9b443d4STobin Davis };
1396c9b443d4STobin Davis 
1397c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1398c9b443d4STobin Davis  * configuration.
1399c9b443d4STobin Davis  */
1400c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
140134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
140282f30040STobin Davis 	.num_items = 4,
1403c9b443d4STobin Davis 	.items = {
140482f30040STobin Davis 		{ "LINE1 pin", 0x0 },
140582f30040STobin Davis 		{ "MIC1 pin", 0x1 },
140682f30040STobin Davis 		{ "MIC2 pin", 0x2 },
140782f30040STobin Davis 		{ "CD pin", 0x3 },
1408c9b443d4STobin Davis         },
1409c9b443d4STobin Davis };
1410c9b443d4STobin Davis 
141134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1412c9b443d4STobin Davis 
1413c9b443d4STobin Davis 	/* Output only controls */
141482f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
141582f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
141682f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
141782f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1418c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1419c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1420c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1421c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
142282f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
142382f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
142482f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
142582f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1426c9b443d4STobin Davis 
1427c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1428c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1429c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1430c9b443d4STobin Davis 
143182f30040STobin Davis 	/* EAPD Switch Control */
143282f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
143382f30040STobin Davis 
1434c9b443d4STobin Davis 	/* Loopback mixer controls */
143582f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
143682f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
143782f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
143882f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
143982f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
144082f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
144182f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
144282f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1443c9b443d4STobin Davis 
144482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
144582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
144682f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
144782f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
144882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
144982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
145082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
145182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1452c9b443d4STobin Davis 	{
1453c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1454c9b443d4STobin Davis 		.name = "Input Source",
1455c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1456c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1457c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1458c9b443d4STobin Davis 	},
1459854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14609f113e0eSMarc Boucher 
1461c9b443d4STobin Davis 	{ } /* end */
1462c9b443d4STobin Davis };
1463c9b443d4STobin Davis 
146434cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1465c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1466c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1467c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1468c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1469c9b443d4STobin Davis 
1470c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1471c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1472c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1473c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1474c9b443d4STobin Davis 	 * control.
1475c9b443d4STobin Davis 	 */
1476c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1477c9b443d4STobin Davis 
1478c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1479c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1480c9b443d4STobin Davis 	 */
1481c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1482c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1483c9b443d4STobin Davis 
1484c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1485c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1486c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1487c9b443d4STobin Davis 
1488c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1489c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1490c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1491c9b443d4STobin Davis 	 * input/output buffers as needed.
1492c9b443d4STobin Davis 	 */
1493c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1494c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1495c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1496c9b443d4STobin Davis 
1497c9b443d4STobin Davis 	/* Mute capture amp left and right */
1498c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1499c9b443d4STobin Davis 
1500c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1501c9b443d4STobin Davis 	 * pin)
1502c9b443d4STobin Davis 	 */
1503c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1504c9b443d4STobin Davis 
1505c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1506c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1507c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1508c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1509c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1510c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1511c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1512c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1513c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1514c9b443d4STobin Davis 
1515c9b443d4STobin Davis 	{ }
1516c9b443d4STobin Davis };
1517c9b443d4STobin Davis #endif
1518c9b443d4STobin Davis 
1519c9b443d4STobin Davis 
1520c9b443d4STobin Davis /* initialize jack-sensing, too */
1521c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1522c9b443d4STobin Davis {
1523c9b443d4STobin Davis 	conexant_init(codec);
1524c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1525c9b443d4STobin Davis 	return 0;
1526c9b443d4STobin Davis }
1527c9b443d4STobin Davis 
1528c9b443d4STobin Davis 
1529c9b443d4STobin Davis enum {
1530f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1531f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1532f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1533c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1534c9b443d4STobin Davis 	CXT5047_TEST,
1535c9b443d4STobin Davis #endif
1536fa5dadcbSTakashi Iwai 	CXT5047_AUTO,
1537f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1538c9b443d4STobin Davis };
1539c9b443d4STobin Davis 
1540ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1541f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1542f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1543f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1544c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1545f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1546c9b443d4STobin Davis #endif
1547fa5dadcbSTakashi Iwai 	[CXT5047_AUTO]		= "auto",
1548f5fcc13cSTakashi Iwai };
1549c9b443d4STobin Davis 
155034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1551ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1552dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1553dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1554f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1555c9b443d4STobin Davis 	{}
1556c9b443d4STobin Davis };
1557c9b443d4STobin Davis 
1558c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1559c9b443d4STobin Davis {
1560c9b443d4STobin Davis 	struct conexant_spec *spec;
1561c9b443d4STobin Davis 	int board_config;
1562c9b443d4STobin Davis 
1563fa5dadcbSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1564fa5dadcbSTakashi Iwai 						  cxt5047_models,
1565fa5dadcbSTakashi Iwai 						  cxt5047_cfg_tbl);
1566fa5dadcbSTakashi Iwai 	if (board_config < 0)
1567*c82693dbSTakashi Iwai 		board_config = CXT5047_AUTO; /* model=auto as default */
1568fa5dadcbSTakashi Iwai 	if (board_config == CXT5047_AUTO)
1569fa5dadcbSTakashi Iwai 		return patch_conexant_auto(codec);
1570fa5dadcbSTakashi Iwai 
1571c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1572c9b443d4STobin Davis 	if (!spec)
1573c9b443d4STobin Davis 		return -ENOMEM;
1574c9b443d4STobin Davis 	codec->spec = spec;
15759421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1576c9b443d4STobin Davis 
1577c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1578c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1579c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1580c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1581c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1582c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1583c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1584c9b443d4STobin Davis 	spec->num_mixers = 1;
1585df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1586c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1587c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1588c9b443d4STobin Davis 	spec->spdif_route = 0;
15895cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15905cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1591c9b443d4STobin Davis 
1592c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1593c9b443d4STobin Davis 
1594c9b443d4STobin Davis 	switch (board_config) {
1595c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1596df481e41STakashi Iwai 		spec->num_mixers = 2;
1597df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1598df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1599c9b443d4STobin Davis 		break;
1600c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1601df481e41STakashi Iwai 		spec->num_mixers = 2;
1602df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1603fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1604c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1605c9b443d4STobin Davis 		break;
1606c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
160782f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1608df481e41STakashi Iwai 		spec->num_mixers = 2;
1609df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1610c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1611c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1612fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1613c9b443d4STobin Davis 		break;
1614c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1615c9b443d4STobin Davis 	case CXT5047_TEST:
1616c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1617c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1618c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1619fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1620c9b443d4STobin Davis #endif
1621c9b443d4STobin Davis 	}
1622dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1623025f206cSDaniel T Chen 
1624025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1625025f206cSDaniel T Chen 	case 0x103c:
1626025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1627025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1628025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1629025f206cSDaniel T Chen 		 */
1630025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1631025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1632025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1633025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1634025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1635025f206cSDaniel T Chen 		break;
1636025f206cSDaniel T Chen 	}
1637025f206cSDaniel T Chen 
1638c9b443d4STobin Davis 	return 0;
1639c9b443d4STobin Davis }
1640c9b443d4STobin Davis 
1641461e2c78STakashi Iwai /* Conexant 5051 specific */
164234cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
164334cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1644461e2c78STakashi Iwai 
164534cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1646461e2c78STakashi Iwai 	{ 2, NULL },
1647461e2c78STakashi Iwai };
1648461e2c78STakashi Iwai 
1649461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1650461e2c78STakashi Iwai {
1651461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1652461e2c78STakashi Iwai 	unsigned int pinctl;
165323d2df5bSTakashi Iwai 	/* headphone pin */
165423d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
165523d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
165623d2df5bSTakashi Iwai 			    pinctl);
165723d2df5bSTakashi Iwai 	/* speaker pin */
1658461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1659461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1660461e2c78STakashi Iwai 			    pinctl);
1661f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1662f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1663f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1664f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1665f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1666461e2c78STakashi Iwai }
1667461e2c78STakashi Iwai 
1668461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1669461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1670461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1671461e2c78STakashi Iwai {
1672461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1673461e2c78STakashi Iwai 
1674461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1675461e2c78STakashi Iwai 		return 0;
1676461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1677461e2c78STakashi Iwai 	return 1;
1678461e2c78STakashi Iwai }
1679461e2c78STakashi Iwai 
1680461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1681461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1682461e2c78STakashi Iwai {
168379d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1684461e2c78STakashi Iwai 	unsigned int present;
1685461e2c78STakashi Iwai 
1686faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
168779d7d533STakashi Iwai 		return;
1688d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1689461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1690461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1691461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1692461e2c78STakashi Iwai }
1693461e2c78STakashi Iwai 
1694461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1695461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1696461e2c78STakashi Iwai {
1697461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1698461e2c78STakashi Iwai 	unsigned int present;
1699461e2c78STakashi Iwai 	hda_nid_t new_adc;
1700461e2c78STakashi Iwai 
1701faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
170279d7d533STakashi Iwai 		return;
1703d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1704461e2c78STakashi Iwai 	if (present)
1705461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1706461e2c78STakashi Iwai 	else
1707461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1708461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1709461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1710461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1711f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1712461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1713461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1714461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1715461e2c78STakashi Iwai 					   spec->cur_adc_format);
1716461e2c78STakashi Iwai 	}
1717461e2c78STakashi Iwai }
1718461e2c78STakashi Iwai 
1719461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1720461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1721461e2c78STakashi Iwai {
1722461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1723461e2c78STakashi Iwai 
1724d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1725461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1726461e2c78STakashi Iwai }
1727461e2c78STakashi Iwai 
1728461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1729461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1730461e2c78STakashi Iwai 				   unsigned int res)
1731461e2c78STakashi Iwai {
1732acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1733461e2c78STakashi Iwai 	switch (res >> 26) {
1734461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1735461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1736461e2c78STakashi Iwai 		break;
1737461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1738461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1739461e2c78STakashi Iwai 		break;
1740461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1741461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1742461e2c78STakashi Iwai 		break;
1743461e2c78STakashi Iwai 	}
1744cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
1745461e2c78STakashi Iwai }
1746461e2c78STakashi Iwai 
174734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1748461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1749461e2c78STakashi Iwai 	{
1750461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1751461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1752461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1753461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1754461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1755461e2c78STakashi Iwai 		.private_value = 0x1a,
1756461e2c78STakashi Iwai 	},
17572c7a3fb3STakashi Iwai 	{}
17582c7a3fb3STakashi Iwai };
1759461e2c78STakashi Iwai 
176034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17612c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17622c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17638607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17648607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
17652c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17662c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1767461e2c78STakashi Iwai 	{}
1768461e2c78STakashi Iwai };
1769461e2c78STakashi Iwai 
177034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1771461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1772461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17738607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
17748607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1775461e2c78STakashi Iwai 	{}
1776461e2c78STakashi Iwai };
1777461e2c78STakashi Iwai 
177834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
17794e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
17804e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
178179d7d533STakashi Iwai 	{}
178279d7d533STakashi Iwai };
178379d7d533STakashi Iwai 
178434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
17855f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
17865f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1787cd9d95a5SKen Prox 	{}
1788cd9d95a5SKen Prox };
1789cd9d95a5SKen Prox 
179034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1791faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1792faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17938607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17948607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1795faddaa5dSTakashi Iwai 	{}
1796faddaa5dSTakashi Iwai };
1797faddaa5dSTakashi Iwai 
179834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1799461e2c78STakashi Iwai 	/* Line in, Mic */
1800461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1801461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1802461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1803461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1804461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1805461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1806461e2c78STakashi Iwai 	/* SPK  */
1807461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1808461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1809461e2c78STakashi Iwai 	/* HP, Amp  */
1810461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1811461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1812461e2c78STakashi Iwai 	/* DAC1 */
1813461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
181428c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1815461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1816461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1817461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1818461e2c78STakashi Iwai 	/* SPDIF route: PCM */
18191965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1820461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1821461e2c78STakashi Iwai 	/* EAPD */
1822461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1823461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1824461e2c78STakashi Iwai 	{ } /* end */
1825461e2c78STakashi Iwai };
1826461e2c78STakashi Iwai 
182734cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
182879d7d533STakashi Iwai 	/* Line in, Mic */
182979d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
183079d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
183179d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
183279d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
183379d7d533STakashi Iwai 	/* SPK  */
183479d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
183579d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
183679d7d533STakashi Iwai 	/* HP, Amp  */
183779d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
183879d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
183979d7d533STakashi Iwai 	/* DAC1 */
184079d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
184128c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
184279d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
184379d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
184479d7d533STakashi Iwai 	/* SPDIF route: PCM */
184579d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
184679d7d533STakashi Iwai 	/* EAPD */
184779d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
184879d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
184979d7d533STakashi Iwai 	{ } /* end */
185079d7d533STakashi Iwai };
185179d7d533STakashi Iwai 
185234cbe3a6STakashi Iwai static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
185327e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
185427e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185527e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
185627e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185727e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
185827e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
185927e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
186027e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
186127e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
186227e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
186327e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
186427e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186527e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
186627e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
186727e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186827e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
186927e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
187027e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
187128c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
187227e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
187327e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
187427e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
187527e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
18761965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
187727e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
187827e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
187927e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
188027e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
188127e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
188227e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
188327e08988SAristeu Sergio Rozanski Filho };
188427e08988SAristeu Sergio Rozanski Filho 
188534cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1886cd9d95a5SKen Prox 	/* Line in, Mic */
188730ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1888cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1889cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1890cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1891cd9d95a5SKen Prox 	/* SPK  */
1892cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1893cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1894cd9d95a5SKen Prox 	/* HP, Amp  */
1895cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1896cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1897cd9d95a5SKen Prox 	/* DAC1 */
1898cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
189928c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1900cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1901cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1902cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1903cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1904cd9d95a5SKen Prox 	/* EAPD */
1905cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1906cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1907cd9d95a5SKen Prox 	{ } /* end */
1908cd9d95a5SKen Prox };
1909cd9d95a5SKen Prox 
19106953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
19116953e552STakashi Iwai 				 unsigned int event)
19126953e552STakashi Iwai {
19136953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
19146953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
19156953e552STakashi Iwai 			    AC_USRSP_EN | event);
1916cd372fb3STakashi Iwai 	snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1917cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
19186953e552STakashi Iwai }
19196953e552STakashi Iwai 
192034cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1921f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1922f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1923f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1924f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1925f7154de2SHerton Ronaldo Krzesinski };
1926f7154de2SHerton Ronaldo Krzesinski 
1927461e2c78STakashi Iwai /* initialize jack-sensing, too */
1928461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1929461e2c78STakashi Iwai {
19306953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19316953e552STakashi Iwai 
1932461e2c78STakashi Iwai 	conexant_init(codec);
1933acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19346953e552STakashi Iwai 
19356953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19366953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19376953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19386953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19396953e552STakashi Iwai 
1940461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1941461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1942461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1943461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1944461e2c78STakashi Iwai 	}
1945461e2c78STakashi Iwai 	return 0;
1946461e2c78STakashi Iwai }
1947461e2c78STakashi Iwai 
1948461e2c78STakashi Iwai 
1949461e2c78STakashi Iwai enum {
1950461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1951461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
195279d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19531965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1954cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1955faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1956f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
19576764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1958461e2c78STakashi Iwai 	CXT5051_MODELS
1959461e2c78STakashi Iwai };
1960461e2c78STakashi Iwai 
1961ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1962461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1963461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
196479d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
196527e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19665f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1967faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1968f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
19696764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1970461e2c78STakashi Iwai };
1971461e2c78STakashi Iwai 
197234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
197379d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19741812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
19755f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1976faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1977461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1978461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1979461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
198027e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1981f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1982461e2c78STakashi Iwai 	{}
1983461e2c78STakashi Iwai };
1984461e2c78STakashi Iwai 
1985461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1986461e2c78STakashi Iwai {
1987461e2c78STakashi Iwai 	struct conexant_spec *spec;
1988461e2c78STakashi Iwai 	int board_config;
1989461e2c78STakashi Iwai 
19906764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
19916764bcefSTakashi Iwai 						  cxt5051_models,
19926764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
19936764bcefSTakashi Iwai 	if (board_config < 0)
1994*c82693dbSTakashi Iwai 		board_config = CXT5051_AUTO; /* model=auto as default */
19951f8458a2STakashi Iwai 	if (board_config == CXT5051_AUTO)
19966764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
19976764bcefSTakashi Iwai 
1998461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1999461e2c78STakashi Iwai 	if (!spec)
2000461e2c78STakashi Iwai 		return -ENOMEM;
2001461e2c78STakashi Iwai 	codec->spec = spec;
20029421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
2003461e2c78STakashi Iwai 
2004461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
2005461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
2006461e2c78STakashi Iwai 
2007461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
2008461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2009461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
2010461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2011461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2012461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
20132c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
20142c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
20152c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
2016461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
2017461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
2018461e2c78STakashi Iwai 	spec->spdif_route = 0;
2019461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2020461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
2021461e2c78STakashi Iwai 	spec->cur_adc = 0;
2022461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
2023461e2c78STakashi Iwai 
20243507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
20253507e2a8STakashi Iwai 
202679d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
202779d7d533STakashi Iwai 
2028faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2029461e2c78STakashi Iwai 	switch (board_config) {
2030461e2c78STakashi Iwai 	case CXT5051_HP:
2031461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
2032461e2c78STakashi Iwai 		break;
203379d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
203479d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
203579d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2036faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
203779d7d533STakashi Iwai 		break;
203827e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
203927e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2040607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2041607bc3e4SJerone Young 		   to use a docking station. */
2042607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2043607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2044461e2c78STakashi Iwai 		break;
2045cd9d95a5SKen Prox 	case CXT5051_F700:
2046cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2047cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2048faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2049faddaa5dSTakashi Iwai 		break;
2050faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2051faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2052faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2053cd9d95a5SKen Prox 		break;
2054f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2055f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2056f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2057f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2058f7154de2SHerton Ronaldo Krzesinski 		break;
2059461e2c78STakashi Iwai 	}
2060461e2c78STakashi Iwai 
20613507e2a8STakashi Iwai 	if (spec->beep_amp)
20623507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20633507e2a8STakashi Iwai 
2064461e2c78STakashi Iwai 	return 0;
2065461e2c78STakashi Iwai }
2066461e2c78STakashi Iwai 
20670fb67e98SDaniel Drake /* Conexant 5066 specific */
20680fb67e98SDaniel Drake 
206934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
207034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
207134cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
207234cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
20730fb67e98SDaniel Drake 
2074dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2075dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2076dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2077dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2078dbaccc0cSDaniel Drake 
207934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
20800fb67e98SDaniel Drake 	{ 2, NULL },
20810fb67e98SDaniel Drake };
20820fb67e98SDaniel Drake 
2083a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2084a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2085a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2086a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2087a3de8ab8STakashi Iwai 
20880fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
20890fb67e98SDaniel Drake {
20900fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20910fb67e98SDaniel Drake 	unsigned int pinctl;
20920fb67e98SDaniel Drake 
20933a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
20943a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
20950fb67e98SDaniel Drake 
20960fb67e98SDaniel Drake 	/* Port A (HP) */
2097a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
20980fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20990fb67e98SDaniel Drake 			pinctl);
21000fb67e98SDaniel Drake 
21010fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2102a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2103a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2104a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2105a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
21063a253445SJohn Baboval 			pinctl = 0;
21073a253445SJohn Baboval 	} else {
2108a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2109a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2110a3de8ab8STakashi Iwai 			pinctl = 0;
21113a253445SJohn Baboval 	}
21120fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21130fb67e98SDaniel Drake 			pinctl);
21140fb67e98SDaniel Drake 
21150fb67e98SDaniel Drake 	/* CLASS_D AMP */
21160fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
21170fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21180fb67e98SDaniel Drake 			pinctl);
21190fb67e98SDaniel Drake }
21200fb67e98SDaniel Drake 
21210fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
21220fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
21230fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
21240fb67e98SDaniel Drake {
21250fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21260fb67e98SDaniel Drake 
21270fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
21280fb67e98SDaniel Drake 		return 0;
21290fb67e98SDaniel Drake 
21300fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21310fb67e98SDaniel Drake 	return 1;
21320fb67e98SDaniel Drake }
21330fb67e98SDaniel Drake 
2134c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2135c4cfe66cSDaniel Drake 	.num_items = 3,
2136c4cfe66cSDaniel Drake 	.items = {
2137c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2138c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2139c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2140c4cfe66cSDaniel Drake 	},
2141c4cfe66cSDaniel Drake };
2142c4cfe66cSDaniel Drake 
2143c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2144c4cfe66cSDaniel Drake {
2145c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2146c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2147c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2148c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2149c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2150c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2151c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2152c4cfe66cSDaniel Drake }
2153c4cfe66cSDaniel Drake 
215475f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
215575f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
215675f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
215775f8991dSDaniel Drake  * is happening when it is not. */
215875f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21590fb67e98SDaniel Drake {
2160dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
216175f8991dSDaniel Drake 	if (!spec->recording)
216275f8991dSDaniel Drake 		return;
21630fb67e98SDaniel Drake 
2164c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2165c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2166c4cfe66cSDaniel Drake 		 * through our special DC port */
2167c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2168c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2169c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2170c4cfe66cSDaniel Drake 
2171c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2172c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2173c4cfe66cSDaniel Drake 			{},
2174c4cfe66cSDaniel Drake 		};
2175c4cfe66cSDaniel Drake 
2176c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2177c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2178c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2179c4cfe66cSDaniel Drake 		return;
2180c4cfe66cSDaniel Drake 	}
2181c4cfe66cSDaniel Drake 
2182c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2183c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2184c4cfe66cSDaniel Drake 
218575f8991dSDaniel Drake 	/* external mic, port B */
218675f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
218775f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
21880fb67e98SDaniel Drake 
218975f8991dSDaniel Drake 	/* internal mic, port C */
219075f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
219175f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
219275f8991dSDaniel Drake }
21930fb67e98SDaniel Drake 
219475f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
219575f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
219675f8991dSDaniel Drake {
219775f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
21980fb67e98SDaniel Drake 	unsigned int present;
21990fb67e98SDaniel Drake 
2200c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2201c4cfe66cSDaniel Drake 		return;
2202c4cfe66cSDaniel Drake 
220375f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
220475f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
220575f8991dSDaniel Drake 	if (present)
22060fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
220775f8991dSDaniel Drake 	else
22080fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
220975f8991dSDaniel Drake 
221075f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
221175f8991dSDaniel Drake 		present ? 0 : 1);
221275f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
221375f8991dSDaniel Drake 
221475f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
22150fb67e98SDaniel Drake }
22160fb67e98SDaniel Drake 
221795a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
221895a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
221995a618bdSEinar Rünkaru {
222095a618bdSEinar Rünkaru 	unsigned int present;
222195a618bdSEinar Rünkaru 
222295a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
222395a618bdSEinar Rünkaru 		/* enable external mic, port B */
222475f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
222595a618bdSEinar Rünkaru 
222695a618bdSEinar Rünkaru 		/* switch to external mic input */
222795a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
222895a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
222995a618bdSEinar Rünkaru 
223095a618bdSEinar Rünkaru 		/* disable internal digital mic */
223195a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
223295a618bdSEinar Rünkaru 		{}
223395a618bdSEinar Rünkaru 	};
223434cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
223595a618bdSEinar Rünkaru 		/* enable internal mic, port C */
223695a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
223795a618bdSEinar Rünkaru 
223895a618bdSEinar Rünkaru 		/* switch to internal mic input */
223995a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
224095a618bdSEinar Rünkaru 
224195a618bdSEinar Rünkaru 		/* disable external mic, port B */
224295a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
224395a618bdSEinar Rünkaru 		{}
224495a618bdSEinar Rünkaru 	};
224595a618bdSEinar Rünkaru 
224695a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
224795a618bdSEinar Rünkaru 	if (present) {
224895a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
224995a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
225095a618bdSEinar Rünkaru 	} else {
225195a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
225295a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
225395a618bdSEinar Rünkaru 	}
225495a618bdSEinar Rünkaru }
225595a618bdSEinar Rünkaru 
2256cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2257cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2258cfd3d8dcSGreg Alexander {
2259cfd3d8dcSGreg Alexander 	unsigned int present;
2260cfd3d8dcSGreg Alexander 
2261cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2262cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2263cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2264cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2265cfd3d8dcSGreg Alexander 		{}
2266cfd3d8dcSGreg Alexander 	};
226734cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2268cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2269cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2270cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2271cfd3d8dcSGreg Alexander 		{}
2272cfd3d8dcSGreg Alexander 	};
2273cfd3d8dcSGreg Alexander 
2274cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2275cfd3d8dcSGreg Alexander 	if (present) {
2276cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2277cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2278cfd3d8dcSGreg Alexander 	} else {
2279cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2280cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2281cfd3d8dcSGreg Alexander 	}
2282cfd3d8dcSGreg Alexander }
2283cfd3d8dcSGreg Alexander 
2284a1d6906eSDavid Henningsson 
2285a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2286a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2287a1d6906eSDavid Henningsson {
2288a1d6906eSDavid Henningsson 	unsigned int present;
2289a1d6906eSDavid Henningsson 
2290a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2291a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2292a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2293a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2294a1d6906eSDavid Henningsson }
2295a1d6906eSDavid Henningsson 
2296a1d6906eSDavid Henningsson 
2297048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2298048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2299048e78a5SDavid Henningsson {
2300048e78a5SDavid Henningsson 	unsigned int present;
2301048e78a5SDavid Henningsson 
2302048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2303048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2304048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2305048e78a5SDavid Henningsson 			    present ? 1 : 3);
2306048e78a5SDavid Henningsson }
2307048e78a5SDavid Henningsson 
2308048e78a5SDavid Henningsson 
23097b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
23107b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
23117b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
23127b2bfdbcSJens Taprogge {
23137b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
23147b2bfdbcSJens Taprogge 
231534cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
23167b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23177b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
23187b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23197b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23207b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23217b2bfdbcSJens Taprogge 		{}
23227b2bfdbcSJens Taprogge 	};
232334cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
23247b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23257b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
23267b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23277b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23287b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23297b2bfdbcSJens Taprogge 		{}
23307b2bfdbcSJens Taprogge 	};
233134cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
23327b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23337b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23347b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23357b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23367b2bfdbcSJens Taprogge 		{}
23377b2bfdbcSJens Taprogge 	};
23387b2bfdbcSJens Taprogge 
23397b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23407b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23417b2bfdbcSJens Taprogge 	if (ext_present) {
23427b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23437b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23447b2bfdbcSJens Taprogge 	} else if (dock_present) {
23457b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23467b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23477b2bfdbcSJens Taprogge 	} else {
23487b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23497b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23507b2bfdbcSJens Taprogge 	}
23517b2bfdbcSJens Taprogge }
23527b2bfdbcSJens Taprogge 
23530fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23540fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23550fb67e98SDaniel Drake {
23560fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23570fb67e98SDaniel Drake 	unsigned int portA, portD;
23580fb67e98SDaniel Drake 
23590fb67e98SDaniel Drake 	/* Port A */
2360d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23610fb67e98SDaniel Drake 
23620fb67e98SDaniel Drake 	/* Port D */
2363d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23640fb67e98SDaniel Drake 
2365a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2366a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
23670fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23680fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23690fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23700fb67e98SDaniel Drake }
23710fb67e98SDaniel Drake 
237202b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
237302b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
237402b6b5b6SDavid Henningsson {
237502b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
237602b6b5b6SDavid Henningsson 
237702b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
237802b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
237902b6b5b6SDavid Henningsson 	else if (spec->ideapad)
238002b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
238102b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
238202b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
238302b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
238402b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2385a1d6906eSDavid Henningsson 	else if (spec->asus)
2386a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
238702b6b5b6SDavid Henningsson }
238802b6b5b6SDavid Henningsson 
23890fb67e98SDaniel Drake /* unsolicited event for jack sensing */
239075f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23910fb67e98SDaniel Drake {
2392c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23930fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23940fb67e98SDaniel Drake 	switch (res >> 26) {
23950fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
23960fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
23970fb67e98SDaniel Drake 		break;
23980fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2399c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2400c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
240175f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
24020fb67e98SDaniel Drake 		break;
24030fb67e98SDaniel Drake 	}
24040fb67e98SDaniel Drake }
24050fb67e98SDaniel Drake 
240695a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
240702b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
240895a618bdSEinar Rünkaru {
240902b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
241095a618bdSEinar Rünkaru 	switch (res >> 26) {
241195a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
241295a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
241395a618bdSEinar Rünkaru 		break;
241495a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
241502b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
241695a618bdSEinar Rünkaru 		break;
241795a618bdSEinar Rünkaru 	}
241895a618bdSEinar Rünkaru }
241995a618bdSEinar Rünkaru 
24207b2bfdbcSJens Taprogge 
24210fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
24220fb67e98SDaniel Drake 	.num_items = 5,
24230fb67e98SDaniel Drake 	.items = {
24240fb67e98SDaniel Drake 		{ "0dB",  0 },
24250fb67e98SDaniel Drake 		{ "10dB", 1 },
24260fb67e98SDaniel Drake 		{ "20dB", 2 },
24270fb67e98SDaniel Drake 		{ "30dB", 3 },
24280fb67e98SDaniel Drake 		{ "40dB", 4 },
24290fb67e98SDaniel Drake 	},
24300fb67e98SDaniel Drake };
24310fb67e98SDaniel Drake 
2432cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2433c4cfe66cSDaniel Drake {
2434c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2435cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2436c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2437c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2438c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24397b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2440cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2441cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2442cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2443cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2444cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2445cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2446cfd3d8dcSGreg Alexander 	}
2447c4cfe66cSDaniel Drake }
2448c4cfe66cSDaniel Drake 
24490fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24500fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24510fb67e98SDaniel Drake {
24520fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24530fb67e98SDaniel Drake }
24540fb67e98SDaniel Drake 
24550fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24560fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24570fb67e98SDaniel Drake {
24580fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2459c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2460c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24610fb67e98SDaniel Drake 	return 0;
24620fb67e98SDaniel Drake }
24630fb67e98SDaniel Drake 
24640fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24650fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24660fb67e98SDaniel Drake {
24670fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2468c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24690fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24700fb67e98SDaniel Drake 	unsigned int idx;
24710fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24720fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24730fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24740fb67e98SDaniel Drake 
2475c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2476c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2477c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2478c4cfe66cSDaniel Drake 	return 1;
2479c4cfe66cSDaniel Drake }
24800fb67e98SDaniel Drake 
2481c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2482c4cfe66cSDaniel Drake {
2483c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2484c4cfe66cSDaniel Drake 		/* disable gain */
2485c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2486c4cfe66cSDaniel Drake 
2487c4cfe66cSDaniel Drake 		/* switch to DC input */
2488c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2489c4cfe66cSDaniel Drake 		{}
2490c4cfe66cSDaniel Drake 	};
2491c4cfe66cSDaniel Drake 
2492c4cfe66cSDaniel Drake 	/* configure as input source */
2493c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2494c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2495c4cfe66cSDaniel Drake }
2496c4cfe66cSDaniel Drake 
2497c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2498c4cfe66cSDaniel Drake {
2499c4cfe66cSDaniel Drake 	/* reconfigure input source */
2500c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2501c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2502c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2503c4cfe66cSDaniel Drake }
2504c4cfe66cSDaniel Drake 
2505c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2506c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2507c4cfe66cSDaniel Drake {
2508c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2509c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2510c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2511c4cfe66cSDaniel Drake 	return 0;
2512c4cfe66cSDaniel Drake }
2513c4cfe66cSDaniel Drake 
2514c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2515c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2516c4cfe66cSDaniel Drake {
2517c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2518c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2519c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2520c4cfe66cSDaniel Drake 
2521c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2522c4cfe66cSDaniel Drake 		return 0;
2523c4cfe66cSDaniel Drake 
2524c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2525c4cfe66cSDaniel Drake 	if (dc_enable)
2526c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2527c4cfe66cSDaniel Drake 	else
2528c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2529c4cfe66cSDaniel Drake 
2530c4cfe66cSDaniel Drake 	return 1;
2531c4cfe66cSDaniel Drake }
2532c4cfe66cSDaniel Drake 
2533c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2534c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2535c4cfe66cSDaniel Drake {
2536c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2537c4cfe66cSDaniel Drake }
2538c4cfe66cSDaniel Drake 
2539c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2540c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2541c4cfe66cSDaniel Drake {
2542c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2543c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2544c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2545c4cfe66cSDaniel Drake 	return 0;
2546c4cfe66cSDaniel Drake }
2547c4cfe66cSDaniel Drake 
2548c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2549c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2550c4cfe66cSDaniel Drake {
2551c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2552c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2553c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2554c4cfe66cSDaniel Drake 	unsigned int idx;
2555c4cfe66cSDaniel Drake 
2556c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2557c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2558c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2559c4cfe66cSDaniel Drake 
2560c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2561c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2562c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25630fb67e98SDaniel Drake 	return 1;
25640fb67e98SDaniel Drake }
25650fb67e98SDaniel Drake 
256675f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
256775f8991dSDaniel Drake {
256875f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
256975f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
257075f8991dSDaniel Drake 	 * recording LED comes on. */
257175f8991dSDaniel Drake 	spec->recording = 1;
257275f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
257375f8991dSDaniel Drake }
257475f8991dSDaniel Drake 
257575f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
257675f8991dSDaniel Drake {
257775f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
257875f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
257975f8991dSDaniel Drake 		/* disable external mic, port B */
258075f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
258175f8991dSDaniel Drake 
258275f8991dSDaniel Drake 		/* disble internal mic, port C */
258375f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2584c4cfe66cSDaniel Drake 
2585c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2586c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
258775f8991dSDaniel Drake 		{},
258875f8991dSDaniel Drake 	};
258975f8991dSDaniel Drake 
259075f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
259175f8991dSDaniel Drake 	spec->recording = 0;
259275f8991dSDaniel Drake }
259375f8991dSDaniel Drake 
2594f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
259534cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2596f6a2491cSAndy Robinson 				    int num_pins)
2597f6a2491cSAndy Robinson {
2598f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2599f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2600f6a2491cSAndy Robinson 	int i;
2601f6a2491cSAndy Robinson 
2602f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2603f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2604f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2605f6a2491cSAndy Robinson 			continue;
2606f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2607f6a2491cSAndy Robinson 			continue;
2608f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
2609f6a2491cSAndy Robinson 			nid_loc++;
2610f6a2491cSAndy Robinson 		else
2611f6a2491cSAndy Robinson 			nid_loc = spec->slave_dig_outs;
2612f6a2491cSAndy Robinson 	}
2613f6a2491cSAndy Robinson }
2614f6a2491cSAndy Robinson 
261534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
26160fb67e98SDaniel Drake 	.num_items = 4,
26170fb67e98SDaniel Drake 	.items = {
26180fb67e98SDaniel Drake 		{ "Mic B", 0 },
26190fb67e98SDaniel Drake 		{ "Mic C", 1 },
26200fb67e98SDaniel Drake 		{ "Mic E", 2 },
26210fb67e98SDaniel Drake 		{ "Mic F", 3 },
26220fb67e98SDaniel Drake 	},
26230fb67e98SDaniel Drake };
26240fb67e98SDaniel Drake 
262534cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
26260fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
26270fb67e98SDaniel Drake 	.values = {
26280fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26290fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26300fb67e98SDaniel Drake 		0
26310fb67e98SDaniel Drake 	},
26320fb67e98SDaniel Drake };
26330fb67e98SDaniel Drake 
263434cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26350fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26360fb67e98SDaniel Drake 	.values = {
26370fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26380fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26390fb67e98SDaniel Drake 		0
26400fb67e98SDaniel Drake 	},
26410fb67e98SDaniel Drake };
26420fb67e98SDaniel Drake 
264334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
26440fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26450fb67e98SDaniel Drake 	{}
26460fb67e98SDaniel Drake };
26470fb67e98SDaniel Drake 
264834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26490fb67e98SDaniel Drake 	{
26500fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26510fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26520fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26530fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26540fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26555e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26560fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26570fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26580fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26590fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26600fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26610fb67e98SDaniel Drake 		.private_value =
26620fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26630fb67e98SDaniel Drake 	},
26640fb67e98SDaniel Drake 	{}
26650fb67e98SDaniel Drake };
26660fb67e98SDaniel Drake 
266734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2668c4cfe66cSDaniel Drake 	{
2669c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2670c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2671c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2672c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2673c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2674c4cfe66cSDaniel Drake 	},
2675c4cfe66cSDaniel Drake 	{
2676c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2677c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2678c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2679c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2680c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2681c4cfe66cSDaniel Drake 	},
2682c4cfe66cSDaniel Drake 	{}
2683c4cfe66cSDaniel Drake };
2684c4cfe66cSDaniel Drake 
268534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
26860fb67e98SDaniel Drake 	{
26870fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26880fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26890fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26900fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26910fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26920fb67e98SDaniel Drake 		.private_value = 0x1d,
26930fb67e98SDaniel Drake 	},
26940fb67e98SDaniel Drake 
26950fb67e98SDaniel Drake 	{
26960fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2697c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
26980fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
26990fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
27000fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
27010fb67e98SDaniel Drake 	},
27020fb67e98SDaniel Drake 
27030fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
27040fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
27050fb67e98SDaniel Drake 	{}
27060fb67e98SDaniel Drake };
27070fb67e98SDaniel Drake 
270834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2709254bba6aSEinar Rünkaru 	{
2710254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
271128c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2712254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2713254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2714254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2715254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2716254bba6aSEinar Rünkaru 	},
2717254bba6aSEinar Rünkaru 	{}
2718254bba6aSEinar Rünkaru };
2719254bba6aSEinar Rünkaru 
272034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
27210fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
27220fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
27230fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27240fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
27250fb67e98SDaniel Drake 
27260fb67e98SDaniel Drake 	/* Speakers  */
27270fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27280fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27290fb67e98SDaniel Drake 
27300fb67e98SDaniel Drake 	/* HP, Amp  */
27310fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27320fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27330fb67e98SDaniel Drake 
27340fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27350fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27360fb67e98SDaniel Drake 
27370fb67e98SDaniel Drake 	/* DAC1 */
27380fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27390fb67e98SDaniel Drake 
27400fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27410fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27420fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27430fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27440fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27450fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27460fb67e98SDaniel Drake 
27470fb67e98SDaniel Drake 	/* no digital microphone support yet */
27480fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27490fb67e98SDaniel Drake 
27500fb67e98SDaniel Drake 	/* Audio input selector */
27510fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27520fb67e98SDaniel Drake 
27530fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27540fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27550fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27560fb67e98SDaniel Drake 
27570fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27580fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27590fb67e98SDaniel Drake 
27600fb67e98SDaniel Drake 	/* EAPD */
27610fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27620fb67e98SDaniel Drake 
27630fb67e98SDaniel Drake 	/* not handling these yet */
27640fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27650fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27660fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27670fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27680fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27690fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27700fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27710fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27720fb67e98SDaniel Drake 	{ } /* end */
27730fb67e98SDaniel Drake };
27740fb67e98SDaniel Drake 
277534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = {
27760fb67e98SDaniel Drake 	/* Port A: headphones */
27770fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27780fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27790fb67e98SDaniel Drake 
27800fb67e98SDaniel Drake 	/* Port B: external microphone */
278175f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27820fb67e98SDaniel Drake 
27830fb67e98SDaniel Drake 	/* Port C: internal microphone */
278475f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27850fb67e98SDaniel Drake 
27860fb67e98SDaniel Drake 	/* Port D: unused */
27870fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27880fb67e98SDaniel Drake 
27890fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27900fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27910fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27920fb67e98SDaniel Drake 
2793c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27940fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27950fb67e98SDaniel Drake 
27960fb67e98SDaniel Drake 	/* Port G: internal speakers */
27970fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27980fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27990fb67e98SDaniel Drake 
28000fb67e98SDaniel Drake 	/* DAC1 */
28010fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28020fb67e98SDaniel Drake 
28030fb67e98SDaniel Drake 	/* DAC2: unused */
28040fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
28050fb67e98SDaniel Drake 
28060fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28070fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28080fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28090fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28100fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28110fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28120fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28130fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28140fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28150fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28160fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28170fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28180fb67e98SDaniel Drake 
28190fb67e98SDaniel Drake 	/* Disable digital microphone port */
28200fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28210fb67e98SDaniel Drake 
28220fb67e98SDaniel Drake 	/* Audio input selectors */
28230fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
28240fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
28250fb67e98SDaniel Drake 
28260fb67e98SDaniel Drake 	/* Disable SPDIF */
28270fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28280fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28290fb67e98SDaniel Drake 
28300fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
28310fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28320fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28330fb67e98SDaniel Drake 	{ } /* end */
28340fb67e98SDaniel Drake };
28350fb67e98SDaniel Drake 
283634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
283795a618bdSEinar Rünkaru 	/* Port A: headphones */
283895a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283995a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
284095a618bdSEinar Rünkaru 
284195a618bdSEinar Rünkaru 	/* Port B: external microphone */
284295a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284395a618bdSEinar Rünkaru 
284495a618bdSEinar Rünkaru 	/* Port C: unused */
284595a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284695a618bdSEinar Rünkaru 
284795a618bdSEinar Rünkaru 	/* Port D: unused */
284895a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284995a618bdSEinar Rünkaru 
285095a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
285195a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285295a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
285395a618bdSEinar Rünkaru 
285495a618bdSEinar Rünkaru 	/* Port F: unused */
285595a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285695a618bdSEinar Rünkaru 
285795a618bdSEinar Rünkaru 	/* Port G: internal speakers */
285895a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
285995a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
286095a618bdSEinar Rünkaru 
286195a618bdSEinar Rünkaru 	/* DAC1 */
286295a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
286395a618bdSEinar Rünkaru 
286495a618bdSEinar Rünkaru 	/* DAC2: unused */
286595a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
286695a618bdSEinar Rünkaru 
286795a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
286895a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
286995a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287195a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287295a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
287395a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287595a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287695a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
287795a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287995a618bdSEinar Rünkaru 
288095a618bdSEinar Rünkaru 	/* Digital microphone port */
288195a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
288295a618bdSEinar Rünkaru 
288395a618bdSEinar Rünkaru 	/* Audio input selectors */
288495a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
288595a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
288695a618bdSEinar Rünkaru 
288795a618bdSEinar Rünkaru 	/* Disable SPDIF */
288895a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
288995a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
289095a618bdSEinar Rünkaru 
289195a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
289295a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
289395a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
289495a618bdSEinar Rünkaru 	{ } /* end */
289595a618bdSEinar Rünkaru };
289695a618bdSEinar Rünkaru 
289734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2898cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2899cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2900cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2901cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2902cfd3d8dcSGreg Alexander 
2903cfd3d8dcSGreg Alexander 	/* Speakers  */
2904cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2905cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2906cfd3d8dcSGreg Alexander 
2907cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2908cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2909cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2910cfd3d8dcSGreg Alexander 
2911cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2912cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2913cfd3d8dcSGreg Alexander 
2914cfd3d8dcSGreg Alexander 	/* DAC1 */
2915cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2916cfd3d8dcSGreg Alexander 
2917cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2918cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2919cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2920cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2921cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2922cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2923cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2924cfd3d8dcSGreg Alexander 
2925cfd3d8dcSGreg Alexander 	/* Audio input selector */
2926cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2927cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2928cfd3d8dcSGreg Alexander 
2929cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2930cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2931cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2932cfd3d8dcSGreg Alexander 
2933cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2934cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2935cfd3d8dcSGreg Alexander 
2936cfd3d8dcSGreg Alexander 	/* internal microphone */
293728c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2938cfd3d8dcSGreg Alexander 
2939cfd3d8dcSGreg Alexander 	/* EAPD */
2940cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2941cfd3d8dcSGreg Alexander 
2942cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2943cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2944cfd3d8dcSGreg Alexander 	{ } /* end */
2945cfd3d8dcSGreg Alexander };
2946cfd3d8dcSGreg Alexander 
294734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29487b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29497b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29507b2bfdbcSJens Taprogge 
29517b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29527b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29537b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29547b2bfdbcSJens Taprogge 
29557b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29567b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29577b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29587b2bfdbcSJens Taprogge 
29597b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29607b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29617b2bfdbcSJens Taprogge 
29627b2bfdbcSJens Taprogge 	/* Port C: Mic */
29637b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29647b2bfdbcSJens Taprogge 
29657b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29667b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29677b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29687b2bfdbcSJens Taprogge 
29697b2bfdbcSJens Taprogge 	/* DAC1 */
29707b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29717b2bfdbcSJens Taprogge 
29727b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29737b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29747b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29757b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29767b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29777b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29787b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29797b2bfdbcSJens Taprogge 
29807b2bfdbcSJens Taprogge 	/* Audio input selector */
29817b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29827b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29837b2bfdbcSJens Taprogge 
29847b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29857b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29867b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29877b2bfdbcSJens Taprogge 
29887b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29897b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29907b2bfdbcSJens Taprogge 
29917b2bfdbcSJens Taprogge 	/* internal microphone */
299228c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
29937b2bfdbcSJens Taprogge 
29947b2bfdbcSJens Taprogge 	/* EAPD */
29957b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
29967b2bfdbcSJens Taprogge 
29977b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
29987b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29997b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30007b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30017b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30027b2bfdbcSJens Taprogge 	{ } /* end */
30037b2bfdbcSJens Taprogge };
30047b2bfdbcSJens Taprogge 
300534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
30060fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30070fb67e98SDaniel Drake 	{ } /* end */
30080fb67e98SDaniel Drake };
30090fb67e98SDaniel Drake 
3010048e78a5SDavid Henningsson 
301134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3012048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3013048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3014048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3015048e78a5SDavid Henningsson 	{ } /* end */
3016048e78a5SDavid Henningsson };
3017048e78a5SDavid Henningsson 
30180fb67e98SDaniel Drake /* initialize jack-sensing, too */
30190fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
30200fb67e98SDaniel Drake {
30210fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
30220fb67e98SDaniel Drake 	conexant_init(codec);
30230fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
30240fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
302502b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
30260fb67e98SDaniel Drake 	}
3027c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
30280fb67e98SDaniel Drake 	return 0;
30290fb67e98SDaniel Drake }
30300fb67e98SDaniel Drake 
303175f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
303275f8991dSDaniel Drake {
3033c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
303475f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
303575f8991dSDaniel Drake 	conexant_init(codec);
303675f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3037c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3038c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
303975f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3040c4cfe66cSDaniel Drake 	} else {
3041c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3042c4cfe66cSDaniel Drake 	}
304375f8991dSDaniel Drake 	return 0;
304475f8991dSDaniel Drake }
304575f8991dSDaniel Drake 
30460fb67e98SDaniel Drake enum {
30470fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30480fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30490fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
30501feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
3051cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30527b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
3053a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3054048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
3055fea4a4f9STakashi Iwai 	CXT5066_AUTO,		/* BIOS auto-parser */
30560fb67e98SDaniel Drake 	CXT5066_MODELS
30570fb67e98SDaniel Drake };
30580fb67e98SDaniel Drake 
3059ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
30600fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30610fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30620fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
30631feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3064cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30657b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3066a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3067048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
3068fea4a4f9STakashi Iwai 	[CXT5066_AUTO]		= "auto",
30690fb67e98SDaniel Drake };
30700fb67e98SDaniel Drake 
307134cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
30729966db22SDavid Henningsson 	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
307300cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
30741feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
30758a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3076ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
30771feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3078231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3079ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3080ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3081048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3082f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3083a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3084f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
30852ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3086c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30874442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30885637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30895637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
30905637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
30914d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3092ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
309319593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
30947b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
309584012657SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3096b2cb1292SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3097d2859fd4SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
3098a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3099af4ccf4fSTakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
310022f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
31017ab1fc0aSDaniel T Chen 	SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
31020fb67e98SDaniel Drake 	{}
31030fb67e98SDaniel Drake };
31040fb67e98SDaniel Drake 
31050fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
31060fb67e98SDaniel Drake {
31070fb67e98SDaniel Drake 	struct conexant_spec *spec;
31080fb67e98SDaniel Drake 	int board_config;
31090fb67e98SDaniel Drake 
3110fea4a4f9STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3111fea4a4f9STakashi Iwai 						  cxt5066_models, cxt5066_cfg_tbl);
3112fea4a4f9STakashi Iwai 	if (board_config < 0)
3113*c82693dbSTakashi Iwai 		board_config = CXT5066_AUTO; /* model=auto as default */
3114fea4a4f9STakashi Iwai 	if (board_config == CXT5066_AUTO)
3115fea4a4f9STakashi Iwai 		return patch_conexant_auto(codec);
3116fea4a4f9STakashi Iwai 
31170fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
31180fb67e98SDaniel Drake 	if (!spec)
31190fb67e98SDaniel Drake 		return -ENOMEM;
31200fb67e98SDaniel Drake 	codec->spec = spec;
31210fb67e98SDaniel Drake 
31220fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
312375f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
31240fb67e98SDaniel Drake 
31250fb67e98SDaniel Drake 	spec->dell_automute = 0;
31260fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
31270fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
31280fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
3129f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3130f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
31310fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
31320fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
31330fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
31340fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
31350fb67e98SDaniel Drake 
31360fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
31370fb67e98SDaniel Drake 
31380fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
31390fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
31400fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
31410fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
31420fb67e98SDaniel Drake 	spec->cur_adc = 0;
31430fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
31440fb67e98SDaniel Drake 
31453507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31463507e2a8STakashi Iwai 
31470fb67e98SDaniel Drake 	switch (board_config) {
31480fb67e98SDaniel Drake 	default:
31490fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31500fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31510fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31520fb67e98SDaniel Drake 		break;
31530fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31540fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31550fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31560fb67e98SDaniel Drake 
31570fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31580fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31590fb67e98SDaniel Drake 		spec->num_init_verbs++;
31600fb67e98SDaniel Drake 		spec->dell_automute = 1;
31610fb67e98SDaniel Drake 		break;
3162a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3163048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3164048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
316502b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3166048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3167048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3168048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3169a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3170a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3171048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3172048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3173048e78a5SDavid Henningsson 		/* no S/PDIF out */
3174f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3175048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3176048e78a5SDavid Henningsson 		/* input source automatically selected */
3177048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3178048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3179048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3180048e78a5SDavid Henningsson 		break;
3181048e78a5SDavid Henningsson 
31820fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
318375f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
318475f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31850fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31860fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3187c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31880fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31890fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3190c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31910fb67e98SDaniel Drake 
31920fb67e98SDaniel Drake 		/* no S/PDIF out */
31930fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31940fb67e98SDaniel Drake 
31950fb67e98SDaniel Drake 		/* input source automatically selected */
31960fb67e98SDaniel Drake 		spec->input_mux = NULL;
319775f8991dSDaniel Drake 
319875f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
319975f8991dSDaniel Drake 		 * at the right time */
320075f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
320175f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
32020fb67e98SDaniel Drake 		break;
32031feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
320475f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
320502b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
320695a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
320795a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
320895a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3209254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
321095a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3211254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3212c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
321395a618bdSEinar Rünkaru 
321495a618bdSEinar Rünkaru 		/* no S/PDIF out */
321595a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
321695a618bdSEinar Rünkaru 
321795a618bdSEinar Rünkaru 		/* input source automatically selected */
321895a618bdSEinar Rünkaru 		spec->input_mux = NULL;
321995a618bdSEinar Rünkaru 		break;
3220cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3221cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
322202b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3223cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3224cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3225cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3226cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3227cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3228cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3229cfd3d8dcSGreg Alexander 
3230cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3231cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3232cfd3d8dcSGreg Alexander 
3233cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3234cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3235cfd3d8dcSGreg Alexander 		break;
32367b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
32377b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
323802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
32397b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
32407b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
32417b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
32427b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
32437b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
32447b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
32457b2bfdbcSJens Taprogge 
32467b2bfdbcSJens Taprogge 		/* no S/PDIF out */
32477b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
32487b2bfdbcSJens Taprogge 
32497b2bfdbcSJens Taprogge 		/* input source automatically selected */
32507b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
32517b2bfdbcSJens Taprogge 		break;
32520fb67e98SDaniel Drake 	}
32530fb67e98SDaniel Drake 
32543507e2a8STakashi Iwai 	if (spec->beep_amp)
32553507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
32563507e2a8STakashi Iwai 
32570fb67e98SDaniel Drake 	return 0;
32580fb67e98SDaniel Drake }
3259461e2c78STakashi Iwai 
3260461e2c78STakashi Iwai /*
3261f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3262f2e5731dSTakashi Iwai  */
3263f2e5731dSTakashi Iwai 
32646764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
32656764bcefSTakashi Iwai 				       struct hda_codec *codec,
32666764bcefSTakashi Iwai 				       unsigned int stream_tag,
32676764bcefSTakashi Iwai 				       unsigned int format,
32686764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
32696764bcefSTakashi Iwai {
32706764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
327147ad1f4eSTakashi Iwai 	hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
32726764bcefSTakashi Iwai 	if (spec->adc_switching) {
32736764bcefSTakashi Iwai 		spec->cur_adc = adc;
32746764bcefSTakashi Iwai 		spec->cur_adc_stream_tag = stream_tag;
32756764bcefSTakashi Iwai 		spec->cur_adc_format = format;
32766764bcefSTakashi Iwai 	}
32776764bcefSTakashi Iwai 	snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
32786764bcefSTakashi Iwai 	return 0;
32796764bcefSTakashi Iwai }
32806764bcefSTakashi Iwai 
32816764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
32826764bcefSTakashi Iwai 				       struct hda_codec *codec,
32836764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
32846764bcefSTakashi Iwai {
32856764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
32866764bcefSTakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
32876764bcefSTakashi Iwai 	spec->cur_adc = 0;
32886764bcefSTakashi Iwai 	return 0;
32896764bcefSTakashi Iwai }
32906764bcefSTakashi Iwai 
32916764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
32926764bcefSTakashi Iwai 	.substreams = 1,
32936764bcefSTakashi Iwai 	.channels_min = 2,
32946764bcefSTakashi Iwai 	.channels_max = 2,
32956764bcefSTakashi Iwai 	.nid = 0, /* fill later */
32966764bcefSTakashi Iwai 	.ops = {
32976764bcefSTakashi Iwai 		.prepare = cx_auto_capture_pcm_prepare,
32986764bcefSTakashi Iwai 		.cleanup = cx_auto_capture_pcm_cleanup
32996764bcefSTakashi Iwai 	},
33006764bcefSTakashi Iwai };
33016764bcefSTakashi Iwai 
330234cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3303f2e5731dSTakashi Iwai 
33048d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\
33058d087c76STakashi Iwai 	snd_hda_get_conn_index(codec, mux, nid, 0)
3306f2e5731dSTakashi Iwai 
3307f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3308f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3309f2e5731dSTakashi Iwai  * not found
3310f2e5731dSTakashi Iwai  */
3311f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3312f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3313f2e5731dSTakashi Iwai {
3314f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3315f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3316f2e5731dSTakashi Iwai 
3317f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3318f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3319f2e5731dSTakashi Iwai 			ret = dacs[i];
3320f2e5731dSTakashi Iwai 			break;
3321f2e5731dSTakashi Iwai 		}
3322f2e5731dSTakashi Iwai 	}
3323f2e5731dSTakashi Iwai 	if (!ret)
3324f2e5731dSTakashi Iwai 		return 0;
3325f2e5731dSTakashi Iwai 	if (--nums > 0)
3326f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3327f2e5731dSTakashi Iwai 	*num_dacs = nums;
3328f2e5731dSTakashi Iwai 	return ret;
3329f2e5731dSTakashi Iwai }
3330f2e5731dSTakashi Iwai 
3331f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3332f2e5731dSTakashi Iwai 
3333f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3334f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3335f2e5731dSTakashi Iwai {
3336f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3337f2e5731dSTakashi Iwai 	int nums = 0;
3338f2e5731dSTakashi Iwai 
3339f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3340f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3341f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3342f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3343f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3344f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3345f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3346f2e5731dSTakashi Iwai 				break;
3347f2e5731dSTakashi Iwai 		}
3348f2e5731dSTakashi Iwai 	}
3349f2e5731dSTakashi Iwai 	return nums;
3350f2e5731dSTakashi Iwai }
3351f2e5731dSTakashi Iwai 
3352f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3353f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3354f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3355f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3356f2e5731dSTakashi Iwai {
3357f2e5731dSTakashi Iwai 	int i, nums;
3358f2e5731dSTakashi Iwai 
3359f2e5731dSTakashi Iwai 	nums = 0;
3360f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3361f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3362f2e5731dSTakashi Iwai 		filled[nums].type = type;
3363f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3364f2e5731dSTakashi Iwai 		nums++;
3365f2e5731dSTakashi Iwai 	}
3366f2e5731dSTakashi Iwai 	return nums;
3367f2e5731dSTakashi Iwai }
3368f2e5731dSTakashi Iwai 
3369f2e5731dSTakashi Iwai /* parse analog output paths */
3370f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3371f2e5731dSTakashi Iwai {
3372f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3373f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3374f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3375f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3376f2e5731dSTakashi Iwai 
3377f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3378f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3379f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3380f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3381f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3382f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3383f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3384f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3385f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3386f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3387f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3388f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3389f2e5731dSTakashi Iwai 	/* fill multiout struct */
3390f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3391f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3392f2e5731dSTakashi Iwai 		if (!dac)
3393f2e5731dSTakashi Iwai 			continue;
3394f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3395f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3396f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3397f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3398f2e5731dSTakashi Iwai 			break;
3399f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3400f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3401f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3402f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3403f2e5731dSTakashi Iwai 				break;
3404f2e5731dSTakashi Iwai 			}
3405f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3406f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3407f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3408f2e5731dSTakashi Iwai 					break;
3409f2e5731dSTakashi Iwai 				}
3410f2e5731dSTakashi Iwai 			break;
3411f2e5731dSTakashi Iwai 		}
3412f2e5731dSTakashi Iwai 	}
3413f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
341489724958SDavid Henningsson 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3415f2e5731dSTakashi Iwai 
341603697e2aSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
341703697e2aSTakashi Iwai 		if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3418f2e5731dSTakashi Iwai 			spec->auto_mute = 1;
341903697e2aSTakashi Iwai 			break;
342003697e2aSTakashi Iwai 		}
342103697e2aSTakashi Iwai 	}
3422e2df82ffSTakashi Iwai 	if (spec->auto_mute &&
3423e2df82ffSTakashi Iwai 	    cfg->line_out_pins[0] &&
3424e2df82ffSTakashi Iwai 	    cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
342503697e2aSTakashi Iwai 	    cfg->line_out_pins[0] != cfg->hp_pins[0] &&
342603697e2aSTakashi Iwai 	    cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
342703697e2aSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++) {
342803697e2aSTakashi Iwai 			if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
342903697e2aSTakashi Iwai 				spec->detect_line = 1;
343003697e2aSTakashi Iwai 				break;
343103697e2aSTakashi Iwai 			}
343203697e2aSTakashi Iwai 		}
343303697e2aSTakashi Iwai 		spec->automute_lines = spec->detect_line;
343403697e2aSTakashi Iwai 	}
343503697e2aSTakashi Iwai 
3436f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3437f2e5731dSTakashi Iwai }
3438f2e5731dSTakashi Iwai 
3439da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3440da339866STakashi Iwai 			      hda_nid_t *pins, bool on);
3441da339866STakashi Iwai 
344203697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins,
344303697e2aSTakashi Iwai 			hda_nid_t *pins, bool on)
344403697e2aSTakashi Iwai {
344503697e2aSTakashi Iwai 	int i;
344603697e2aSTakashi Iwai 	for (i = 0; i < num_pins; i++)
344703697e2aSTakashi Iwai 		snd_hda_codec_write(codec, pins[i], 0,
344803697e2aSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
344903697e2aSTakashi Iwai 				    on ? PIN_OUT : 0);
345003697e2aSTakashi Iwai 	cx_auto_turn_eapd(codec, num_pins, pins, on);
345103697e2aSTakashi Iwai }
345203697e2aSTakashi Iwai 
345303697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
345403697e2aSTakashi Iwai {
345503697e2aSTakashi Iwai 	int i, present = 0;
345603697e2aSTakashi Iwai 
345703697e2aSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
345803697e2aSTakashi Iwai 		hda_nid_t nid = pins[i];
345903697e2aSTakashi Iwai 		if (!nid || !is_jack_detectable(codec, nid))
346003697e2aSTakashi Iwai 			break;
346103697e2aSTakashi Iwai 		snd_hda_input_jack_report(codec, nid);
346203697e2aSTakashi Iwai 		present |= snd_hda_jack_detect(codec, nid);
346303697e2aSTakashi Iwai 	}
346403697e2aSTakashi Iwai 	return present;
346503697e2aSTakashi Iwai }
346603697e2aSTakashi Iwai 
3467f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
346803697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec)
346903697e2aSTakashi Iwai {
347003697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
347103697e2aSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3472e2df82ffSTakashi Iwai 	int on = 1;
347303697e2aSTakashi Iwai 
3474e2df82ffSTakashi Iwai 	/* turn on HP EAPD when HP jacks are present */
3475e2df82ffSTakashi Iwai 	if (spec->auto_mute)
3476e2df82ffSTakashi Iwai 		on = spec->hp_present;
347703697e2aSTakashi Iwai 	cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3478e2df82ffSTakashi Iwai 	/* mute speakers in auto-mode if HP or LO jacks are plugged */
3479e2df82ffSTakashi Iwai 	if (spec->auto_mute)
3480e2df82ffSTakashi Iwai 		on = !(spec->hp_present ||
3481e2df82ffSTakashi Iwai 		       (spec->detect_line && spec->line_present));
3482e2df82ffSTakashi Iwai 	do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
348303697e2aSTakashi Iwai 
348403697e2aSTakashi Iwai 	/* toggle line-out mutes if needed, too */
348503697e2aSTakashi Iwai 	/* if LO is a copy of either HP or Speaker, don't need to handle it */
348603697e2aSTakashi Iwai 	if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
348703697e2aSTakashi Iwai 	    cfg->line_out_pins[0] == cfg->speaker_pins[0])
348803697e2aSTakashi Iwai 		return;
3489e2df82ffSTakashi Iwai 	if (spec->auto_mute) {
3490e2df82ffSTakashi Iwai 		/* mute LO in auto-mode when HP jack is present */
3491e2df82ffSTakashi Iwai 		if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3492e2df82ffSTakashi Iwai 		    spec->automute_lines)
3493e2df82ffSTakashi Iwai 			on = !spec->hp_present;
349403697e2aSTakashi Iwai 		else
3495e2df82ffSTakashi Iwai 			on = 1;
3496e2df82ffSTakashi Iwai 	}
3497e2df82ffSTakashi Iwai 	do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
349803697e2aSTakashi Iwai }
349903697e2aSTakashi Iwai 
3500f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3501f2e5731dSTakashi Iwai {
3502f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3503f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3504f2e5731dSTakashi Iwai 
3505f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3506f2e5731dSTakashi Iwai 		return;
350703697e2aSTakashi Iwai 	spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
350803697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
350903697e2aSTakashi Iwai }
351003697e2aSTakashi Iwai 
351103697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec)
351203697e2aSTakashi Iwai {
351303697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
351403697e2aSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
351503697e2aSTakashi Iwai 
351603697e2aSTakashi Iwai 	if (!spec->auto_mute || !spec->detect_line)
351703697e2aSTakashi Iwai 		return;
351803697e2aSTakashi Iwai 	spec->line_present = detect_jacks(codec, cfg->line_outs,
351903697e2aSTakashi Iwai 					  cfg->line_out_pins);
352003697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
352103697e2aSTakashi Iwai }
352203697e2aSTakashi Iwai 
352303697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
352403697e2aSTakashi Iwai 				 struct snd_ctl_elem_info *uinfo)
352503697e2aSTakashi Iwai {
352603697e2aSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
352703697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
352803697e2aSTakashi Iwai 	static const char * const texts2[] = {
352903697e2aSTakashi Iwai 		"Disabled", "Enabled"
353003697e2aSTakashi Iwai 	};
353103697e2aSTakashi Iwai 	static const char * const texts3[] = {
353203697e2aSTakashi Iwai 		"Disabled", "Speaker Only", "Line-Out+Speaker"
353303697e2aSTakashi Iwai 	};
353403697e2aSTakashi Iwai 	const char * const *texts;
353503697e2aSTakashi Iwai 
353603697e2aSTakashi Iwai 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
353703697e2aSTakashi Iwai 	uinfo->count = 1;
353803697e2aSTakashi Iwai 	if (spec->automute_hp_lo) {
353903697e2aSTakashi Iwai 		uinfo->value.enumerated.items = 3;
354003697e2aSTakashi Iwai 		texts = texts3;
354103697e2aSTakashi Iwai 	} else {
354203697e2aSTakashi Iwai 		uinfo->value.enumerated.items = 2;
354303697e2aSTakashi Iwai 		texts = texts2;
354403697e2aSTakashi Iwai 	}
354503697e2aSTakashi Iwai 	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
354603697e2aSTakashi Iwai 		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
354703697e2aSTakashi Iwai 	strcpy(uinfo->value.enumerated.name,
354803697e2aSTakashi Iwai 	       texts[uinfo->value.enumerated.item]);
354903697e2aSTakashi Iwai 	return 0;
355003697e2aSTakashi Iwai }
355103697e2aSTakashi Iwai 
355203697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
355303697e2aSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
355403697e2aSTakashi Iwai {
355503697e2aSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
355603697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
355703697e2aSTakashi Iwai 	unsigned int val;
355803697e2aSTakashi Iwai 	if (!spec->auto_mute)
355903697e2aSTakashi Iwai 		val = 0;
356003697e2aSTakashi Iwai 	else if (!spec->automute_lines)
356103697e2aSTakashi Iwai 		val = 1;
356203697e2aSTakashi Iwai 	else
356303697e2aSTakashi Iwai 		val = 2;
356403697e2aSTakashi Iwai 	ucontrol->value.enumerated.item[0] = val;
356503697e2aSTakashi Iwai 	return 0;
356603697e2aSTakashi Iwai }
356703697e2aSTakashi Iwai 
356803697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
356903697e2aSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
357003697e2aSTakashi Iwai {
357103697e2aSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357203697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
357303697e2aSTakashi Iwai 
357403697e2aSTakashi Iwai 	switch (ucontrol->value.enumerated.item[0]) {
357503697e2aSTakashi Iwai 	case 0:
357603697e2aSTakashi Iwai 		if (!spec->auto_mute)
357703697e2aSTakashi Iwai 			return 0;
357803697e2aSTakashi Iwai 		spec->auto_mute = 0;
3579f2e5731dSTakashi Iwai 		break;
358003697e2aSTakashi Iwai 	case 1:
358103697e2aSTakashi Iwai 		if (spec->auto_mute && !spec->automute_lines)
358203697e2aSTakashi Iwai 			return 0;
358303697e2aSTakashi Iwai 		spec->auto_mute = 1;
358403697e2aSTakashi Iwai 		spec->automute_lines = 0;
358503697e2aSTakashi Iwai 		break;
358603697e2aSTakashi Iwai 	case 2:
358703697e2aSTakashi Iwai 		if (!spec->automute_hp_lo)
358803697e2aSTakashi Iwai 			return -EINVAL;
358903697e2aSTakashi Iwai 		if (spec->auto_mute && spec->automute_lines)
359003697e2aSTakashi Iwai 			return 0;
359103697e2aSTakashi Iwai 		spec->auto_mute = 1;
359203697e2aSTakashi Iwai 		spec->automute_lines = 1;
359303697e2aSTakashi Iwai 		break;
359403697e2aSTakashi Iwai 	default:
359503697e2aSTakashi Iwai 		return -EINVAL;
3596f2e5731dSTakashi Iwai 	}
359703697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
359803697e2aSTakashi Iwai 	return 1;
3599f2e5731dSTakashi Iwai }
360003697e2aSTakashi Iwai 
360103697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
360203697e2aSTakashi Iwai 	{
360303697e2aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
360403697e2aSTakashi Iwai 		.name = "Auto-Mute Mode",
360503697e2aSTakashi Iwai 		.info = cx_automute_mode_info,
360603697e2aSTakashi Iwai 		.get = cx_automute_mode_get,
360703697e2aSTakashi Iwai 		.put = cx_automute_mode_put,
360803697e2aSTakashi Iwai 	},
360903697e2aSTakashi Iwai 	{ }
361003697e2aSTakashi Iwai };
3611f2e5731dSTakashi Iwai 
36126764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
36136764bcefSTakashi Iwai 				 struct snd_ctl_elem_info *uinfo)
36146764bcefSTakashi Iwai {
36156764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
36166764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
36176764bcefSTakashi Iwai 
36186764bcefSTakashi Iwai 	return snd_hda_input_mux_info(&spec->private_imux, uinfo);
36196764bcefSTakashi Iwai }
36206764bcefSTakashi Iwai 
36216764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
36226764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
36236764bcefSTakashi Iwai {
36246764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
36256764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
36266764bcefSTakashi Iwai 
36276764bcefSTakashi Iwai 	ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
36286764bcefSTakashi Iwai 	return 0;
36296764bcefSTakashi Iwai }
36306764bcefSTakashi Iwai 
36315c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index;
36325c9887e0STakashi Iwai  * if do_select is set, actually select the route.
36335c9887e0STakashi Iwai  */
36345c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3635cf27f29aSTakashi Iwai 				     hda_nid_t pin, hda_nid_t *srcp,
3636cf27f29aSTakashi Iwai 				     bool do_select, int depth)
36375c9887e0STakashi Iwai {
36385c9887e0STakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
36395c9887e0STakashi Iwai 	int i, nums;
36405c9887e0STakashi Iwai 
3641cf27f29aSTakashi Iwai 	switch (get_wcaps_type(get_wcaps(codec, mux))) {
3642cf27f29aSTakashi Iwai 	case AC_WID_AUD_IN:
3643cf27f29aSTakashi Iwai 	case AC_WID_AUD_SEL:
3644cf27f29aSTakashi Iwai 	case AC_WID_AUD_MIX:
3645cf27f29aSTakashi Iwai 		break;
3646cf27f29aSTakashi Iwai 	default:
3647cf27f29aSTakashi Iwai 		return -1;
3648cf27f29aSTakashi Iwai 	}
3649cf27f29aSTakashi Iwai 
36505c9887e0STakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
36515c9887e0STakashi Iwai 	for (i = 0; i < nums; i++)
36525c9887e0STakashi Iwai 		if (conn[i] == pin) {
36535c9887e0STakashi Iwai 			if (do_select)
36545c9887e0STakashi Iwai 				snd_hda_codec_write(codec, mux, 0,
36555c9887e0STakashi Iwai 						    AC_VERB_SET_CONNECT_SEL, i);
3656cf27f29aSTakashi Iwai 			if (srcp)
3657cf27f29aSTakashi Iwai 				*srcp = mux;
36585c9887e0STakashi Iwai 			return i;
36595c9887e0STakashi Iwai 		}
36605c9887e0STakashi Iwai 	depth++;
36615c9887e0STakashi Iwai 	if (depth == 2)
36625c9887e0STakashi Iwai 		return -1;
36635c9887e0STakashi Iwai 	for (i = 0; i < nums; i++) {
3664cf27f29aSTakashi Iwai 		int ret  = __select_input_connection(codec, conn[i], pin, srcp,
36655c9887e0STakashi Iwai 						     do_select, depth);
36665c9887e0STakashi Iwai 		if (ret >= 0) {
36675c9887e0STakashi Iwai 			if (do_select)
36685c9887e0STakashi Iwai 				snd_hda_codec_write(codec, mux, 0,
36695c9887e0STakashi Iwai 						    AC_VERB_SET_CONNECT_SEL, i);
3670cf27f29aSTakashi Iwai 			return i;
36715c9887e0STakashi Iwai 		}
36725c9887e0STakashi Iwai 	}
36735c9887e0STakashi Iwai 	return -1;
36745c9887e0STakashi Iwai }
36755c9887e0STakashi Iwai 
36765c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
36775c9887e0STakashi Iwai 				   hda_nid_t pin)
36785c9887e0STakashi Iwai {
3679cf27f29aSTakashi Iwai 	__select_input_connection(codec, mux, pin, NULL, true, 0);
36805c9887e0STakashi Iwai }
36815c9887e0STakashi Iwai 
36825c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
36835c9887e0STakashi Iwai 				hda_nid_t pin)
36845c9887e0STakashi Iwai {
3685cf27f29aSTakashi Iwai 	return __select_input_connection(codec, mux, pin, NULL, false, 0);
36865c9887e0STakashi Iwai }
36875c9887e0STakashi Iwai 
36886764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec,
36896764bcefSTakashi Iwai 				   const struct hda_input_mux *imux,
36906764bcefSTakashi Iwai 				   unsigned int idx)
36916764bcefSTakashi Iwai {
36926764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
36936764bcefSTakashi Iwai 	hda_nid_t adc;
3694313d2c06STakashi Iwai 	int changed = 1;
36956764bcefSTakashi Iwai 
36966764bcefSTakashi Iwai 	if (!imux->num_items)
36976764bcefSTakashi Iwai 		return 0;
36986764bcefSTakashi Iwai 	if (idx >= imux->num_items)
36996764bcefSTakashi Iwai 		idx = imux->num_items - 1;
37006764bcefSTakashi Iwai 	if (spec->cur_mux[0] == idx)
3701313d2c06STakashi Iwai 		changed = 0;
370247ad1f4eSTakashi Iwai 	adc = spec->imux_info[idx].adc;
370347ad1f4eSTakashi Iwai 	select_input_connection(codec, spec->imux_info[idx].adc,
370447ad1f4eSTakashi Iwai 				spec->imux_info[idx].pin);
37056764bcefSTakashi Iwai 	if (spec->cur_adc && spec->cur_adc != adc) {
37066764bcefSTakashi Iwai 		/* stream is running, let's swap the current ADC */
37076764bcefSTakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
37086764bcefSTakashi Iwai 		spec->cur_adc = adc;
37096764bcefSTakashi Iwai 		snd_hda_codec_setup_stream(codec, adc,
37106764bcefSTakashi Iwai 					   spec->cur_adc_stream_tag, 0,
37116764bcefSTakashi Iwai 					   spec->cur_adc_format);
37126764bcefSTakashi Iwai 	}
37136764bcefSTakashi Iwai 	spec->cur_mux[0] = idx;
3714313d2c06STakashi Iwai 	return changed;
37156764bcefSTakashi Iwai }
37166764bcefSTakashi Iwai 
37176764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
37186764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
37196764bcefSTakashi Iwai {
37206764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
37216764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
37226764bcefSTakashi Iwai 
37236764bcefSTakashi Iwai 	return cx_auto_mux_enum_update(codec, &spec->private_imux,
37246764bcefSTakashi Iwai 				       ucontrol->value.enumerated.item[0]);
37256764bcefSTakashi Iwai }
37266764bcefSTakashi Iwai 
37276764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
37286764bcefSTakashi Iwai 	{
37296764bcefSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
37306764bcefSTakashi Iwai 		.name = "Capture Source",
37316764bcefSTakashi Iwai 		.info = cx_auto_mux_enum_info,
37326764bcefSTakashi Iwai 		.get = cx_auto_mux_enum_get,
37336764bcefSTakashi Iwai 		.put = cx_auto_mux_enum_put
37346764bcefSTakashi Iwai 	},
37356764bcefSTakashi Iwai 	{}
37366764bcefSTakashi Iwai };
37376764bcefSTakashi Iwai 
373843c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect)
373943c1b2e9STakashi Iwai {
374043c1b2e9STakashi Iwai 	struct conexant_spec *spec = codec->spec;
374143c1b2e9STakashi Iwai 	if (idx < 0)
374243c1b2e9STakashi Iwai 		return false;
374343c1b2e9STakashi Iwai 	if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
374443c1b2e9STakashi Iwai 		return false;
374543c1b2e9STakashi Iwai 	cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
374643c1b2e9STakashi Iwai 	return true;
374743c1b2e9STakashi Iwai }
374843c1b2e9STakashi Iwai 
3749f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3750f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3751f2e5731dSTakashi Iwai {
3752f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3753f2e5731dSTakashi Iwai 
3754f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3755f2e5731dSTakashi Iwai 		return;
375643c1b2e9STakashi Iwai 	if (!select_automic(codec, spec->auto_mic_ext, true))
375743c1b2e9STakashi Iwai 		if (!select_automic(codec, spec->auto_mic_dock, true))
375843c1b2e9STakashi Iwai 			select_automic(codec, spec->auto_mic_int, false);
3759f2e5731dSTakashi Iwai }
3760f2e5731dSTakashi Iwai 
3761f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3762f2e5731dSTakashi Iwai {
3763f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3764f2e5731dSTakashi Iwai 	switch (res >> 26) {
3765f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3766f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
376703697e2aSTakashi Iwai 		break;
376803697e2aSTakashi Iwai 	case CONEXANT_LINE_EVENT:
376903697e2aSTakashi Iwai 		cx_auto_line_automute(codec);
3770f2e5731dSTakashi Iwai 		break;
3771f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3772f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3773cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3774f2e5731dSTakashi Iwai 		break;
3775f2e5731dSTakashi Iwai 	}
3776f2e5731dSTakashi Iwai }
3777f2e5731dSTakashi Iwai 
3778f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
377943c1b2e9STakashi Iwai  * auto-mic is enabled only when one int-mic and one ext- and/or
378043c1b2e9STakashi Iwai  * one dock-mic exist
3781f2e5731dSTakashi Iwai  */
3782f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3783f2e5731dSTakashi Iwai {
3784f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
378543c1b2e9STakashi Iwai 	int pset[INPUT_PIN_ATTR_NORMAL + 1];
378643c1b2e9STakashi Iwai 	int i;
3787f2e5731dSTakashi Iwai 
3788506a4196STakashi Iwai 	for (i = 0; i < ARRAY_SIZE(pset); i++)
378943c1b2e9STakashi Iwai 		pset[i] = -1;
379043c1b2e9STakashi Iwai 	for (i = 0; i < spec->private_imux.num_items; i++) {
379143c1b2e9STakashi Iwai 		hda_nid_t pin = spec->imux_info[i].pin;
379243c1b2e9STakashi Iwai 		unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3793b55fcb50STakashi Iwai 		int type, attr;
379443c1b2e9STakashi Iwai 		attr = snd_hda_get_input_pin_attr(def_conf);
379543c1b2e9STakashi Iwai 		if (attr == INPUT_PIN_ATTR_UNUSED)
3796b55fcb50STakashi Iwai 			return; /* invalid entry */
379743c1b2e9STakashi Iwai 		if (attr > INPUT_PIN_ATTR_NORMAL)
379843c1b2e9STakashi Iwai 			attr = INPUT_PIN_ATTR_NORMAL;
379943c1b2e9STakashi Iwai 		if (attr != INPUT_PIN_ATTR_INT &&
380043c1b2e9STakashi Iwai 		    !is_jack_detectable(codec, pin))
3801b55fcb50STakashi Iwai 			return; /* non-detectable pin */
3802b55fcb50STakashi Iwai 		type = get_defcfg_device(def_conf);
3803b55fcb50STakashi Iwai 		if (type != AC_JACK_MIC_IN &&
3804b55fcb50STakashi Iwai 		    (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3805b55fcb50STakashi Iwai 			return; /* no valid input type */
380643c1b2e9STakashi Iwai 		if (pset[attr] >= 0)
380743c1b2e9STakashi Iwai 			return; /* already occupied */
380843c1b2e9STakashi Iwai 		pset[attr] = i;
3809f2e5731dSTakashi Iwai 	}
381043c1b2e9STakashi Iwai 	if (pset[INPUT_PIN_ATTR_INT] < 0 ||
381143c1b2e9STakashi Iwai 	    (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
381243c1b2e9STakashi Iwai 		return; /* no input to switch*/
3813f2e5731dSTakashi Iwai 	spec->auto_mic = 1;
381443c1b2e9STakashi Iwai 	spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
381543c1b2e9STakashi Iwai 	spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
381643c1b2e9STakashi Iwai 	spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3817f2e5731dSTakashi Iwai }
3818f2e5731dSTakashi Iwai 
3819f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3820f2e5731dSTakashi Iwai {
3821f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3822f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3823f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
38246764bcefSTakashi Iwai 	int i, j;
3825f2e5731dSTakashi Iwai 
3826f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3827f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
38286764bcefSTakashi Iwai 		for (j = 0; j < spec->num_adc_nids; j++) {
38296764bcefSTakashi Iwai 			hda_nid_t adc = spec->adc_nids[j];
38305c9887e0STakashi Iwai 			int idx = get_input_connection(codec, adc,
3831f2e5731dSTakashi Iwai 						       cfg->inputs[i].pin);
3832f2e5731dSTakashi Iwai 			if (idx >= 0) {
3833f2e5731dSTakashi Iwai 				const char *label;
3834f2e5731dSTakashi Iwai 				label = hda_get_autocfg_input_label(codec, cfg, i);
383547ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].index = i;
383647ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].boost = 0;
383747ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].adc = adc;
383847ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].pin =
3839f6100bb4STakashi Iwai 					cfg->inputs[i].pin;
3840f2e5731dSTakashi Iwai 				snd_hda_add_imux_item(imux, label, idx, NULL);
38416764bcefSTakashi Iwai 				break;
38426764bcefSTakashi Iwai 			}
3843f2e5731dSTakashi Iwai 		}
3844f2e5731dSTakashi Iwai 	}
384543c1b2e9STakashi Iwai 	if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3846f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
38476764bcefSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic) {
38486764bcefSTakashi Iwai 		for (i = 1; i < imux->num_items; i++) {
384947ad1f4eSTakashi Iwai 			if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
38506764bcefSTakashi Iwai 				spec->adc_switching = 1;
38516764bcefSTakashi Iwai 				break;
38526764bcefSTakashi Iwai 			}
38536764bcefSTakashi Iwai 		}
38546764bcefSTakashi Iwai 	}
3855f2e5731dSTakashi Iwai }
3856f2e5731dSTakashi Iwai 
3857f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3858f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3859f2e5731dSTakashi Iwai {
3860f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3861f2e5731dSTakashi Iwai 
3862f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3863f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3864f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3865f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3866f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3867f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3868f2e5731dSTakashi Iwai 				return nid;
3869f2e5731dSTakashi Iwai 		}
3870f2e5731dSTakashi Iwai 	}
3871f2e5731dSTakashi Iwai 	return 0;
3872f2e5731dSTakashi Iwai }
3873f2e5731dSTakashi Iwai 
3874f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3875f2e5731dSTakashi Iwai {
3876f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3877f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3878f2e5731dSTakashi Iwai 	hda_nid_t nid;
3879f2e5731dSTakashi Iwai 
3880f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3881f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3882f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3883f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3884f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3885f2e5731dSTakashi Iwai }
3886f2e5731dSTakashi Iwai 
3887f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3888f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3889f2e5731dSTakashi Iwai {
3890f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3891f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3892f2e5731dSTakashi Iwai 
3893f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3894f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3895f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3896f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3897f2e5731dSTakashi Iwai 			break;
3898f2e5731dSTakashi Iwai 		}
3899f2e5731dSTakashi Iwai }
3900f2e5731dSTakashi Iwai #else
3901f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3902f2e5731dSTakashi Iwai #endif
3903f2e5731dSTakashi Iwai 
3904f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3905f2e5731dSTakashi Iwai {
3906f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3907f2e5731dSTakashi Iwai 	int err;
3908f2e5731dSTakashi Iwai 
3909f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3910f2e5731dSTakashi Iwai 	if (err < 0)
3911f2e5731dSTakashi Iwai 		return err;
3912f2e5731dSTakashi Iwai 
3913f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3914f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3915f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3916f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3917f2e5731dSTakashi Iwai 	return 0;
3918f2e5731dSTakashi Iwai }
3919f2e5731dSTakashi Iwai 
3920da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3921da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
3922f2e5731dSTakashi Iwai {
3923f2e5731dSTakashi Iwai 	int i;
3924f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3925f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3926f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3927da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
3928da339866STakashi Iwai 					    on ? 0x02 : 0);
3929f2e5731dSTakashi Iwai 	}
3930f2e5731dSTakashi Iwai }
3931f2e5731dSTakashi Iwai 
3932f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3933f2e5731dSTakashi Iwai 			      hda_nid_t src)
3934f2e5731dSTakashi Iwai {
3935f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3936f2e5731dSTakashi Iwai 	if (idx >= 0)
3937f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3938f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3939f2e5731dSTakashi Iwai }
3940f2e5731dSTakashi Iwai 
39411f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids,
39421f8458a2STakashi Iwai 			 const hda_nid_t *nids)
3943f2e5731dSTakashi Iwai {
39440ad1b5b6STakashi Iwai 	int i, val;
3945f2e5731dSTakashi Iwai 
39461f8458a2STakashi Iwai 	for (i = 0; i < num_nids; i++) {
39471f8458a2STakashi Iwai 		hda_nid_t nid = nids[i];
39481f8458a2STakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
39491f8458a2STakashi Iwai 			continue;
39500ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
39510ad1b5b6STakashi Iwai 			val = AMP_OUT_MUTE;
39520ad1b5b6STakashi Iwai 		else
39530ad1b5b6STakashi Iwai 			val = AMP_OUT_ZERO;
39540ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0,
39550ad1b5b6STakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, val);
39560ad1b5b6STakashi Iwai 	}
39571f8458a2STakashi Iwai }
3958f2e5731dSTakashi Iwai 
395903697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
396003697e2aSTakashi Iwai 			      hda_nid_t *pins, unsigned int tag)
396103697e2aSTakashi Iwai {
396203697e2aSTakashi Iwai 	int i;
396303697e2aSTakashi Iwai 	for (i = 0; i < num_pins; i++)
396403697e2aSTakashi Iwai 		snd_hda_codec_write(codec, pins[i], 0,
396503697e2aSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
396603697e2aSTakashi Iwai 				    AC_USRSP_EN | tag);
396703697e2aSTakashi Iwai }
396803697e2aSTakashi Iwai 
39691f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
39701f8458a2STakashi Iwai {
39711f8458a2STakashi Iwai 	struct conexant_spec *spec = codec->spec;
39721f8458a2STakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
39731f8458a2STakashi Iwai 	hda_nid_t nid;
39741f8458a2STakashi Iwai 	int i;
39751f8458a2STakashi Iwai 
39761f8458a2STakashi Iwai 	mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
3977f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
3978f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3979f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
39801f8458a2STakashi Iwai 	mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
39811f8458a2STakashi Iwai 	mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
39821f8458a2STakashi Iwai 	mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
3983f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3984f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
3985f2e5731dSTakashi Iwai 		if (!nid)
3986f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
3987f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
3988f2e5731dSTakashi Iwai 	}
398903697e2aSTakashi Iwai 	if (spec->auto_mute) {
399003697e2aSTakashi Iwai 		enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
399103697e2aSTakashi Iwai 				  CONEXANT_HP_EVENT);
399203697e2aSTakashi Iwai 		spec->hp_present = detect_jacks(codec, cfg->hp_outs,
399303697e2aSTakashi Iwai 						cfg->hp_pins);
399403697e2aSTakashi Iwai 		if (spec->detect_line) {
399503697e2aSTakashi Iwai 			enable_unsol_pins(codec, cfg->line_outs,
399603697e2aSTakashi Iwai 					  cfg->line_out_pins,
399703697e2aSTakashi Iwai 					  CONEXANT_LINE_EVENT);
399803697e2aSTakashi Iwai 			spec->line_present =
399903697e2aSTakashi Iwai 				detect_jacks(codec, cfg->line_outs,
400003697e2aSTakashi Iwai 					     cfg->line_out_pins);
400103697e2aSTakashi Iwai 		}
400203697e2aSTakashi Iwai 	}
400303697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
4004f2e5731dSTakashi Iwai }
4005f2e5731dSTakashi Iwai 
4006f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
4007f2e5731dSTakashi Iwai {
4008f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4009f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
40100ad1b5b6STakashi Iwai 	int i, val;
4011f2e5731dSTakashi Iwai 
40120ad1b5b6STakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
40130ad1b5b6STakashi Iwai 		hda_nid_t nid = spec->adc_nids[i];
40141f8458a2STakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
40151f8458a2STakashi Iwai 			continue;
40160ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
40170ad1b5b6STakashi Iwai 			val = AMP_IN_MUTE(0);
40180ad1b5b6STakashi Iwai 		else
40190ad1b5b6STakashi Iwai 			val = AMP_IN_UNMUTE(0);
40200ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
40210ad1b5b6STakashi Iwai 				    val);
40220ad1b5b6STakashi Iwai 	}
4023f2e5731dSTakashi Iwai 
4024f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
4025f2e5731dSTakashi Iwai 		unsigned int type;
4026f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
4027f2e5731dSTakashi Iwai 			type = PIN_VREF80;
4028f2e5731dSTakashi Iwai 		else
4029f2e5731dSTakashi Iwai 			type = PIN_IN;
4030f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4031f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4032f2e5731dSTakashi Iwai 	}
4033f2e5731dSTakashi Iwai 
4034f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
403543c1b2e9STakashi Iwai 		if (spec->auto_mic_ext >= 0) {
403643c1b2e9STakashi Iwai 			snd_hda_codec_write(codec,
403743c1b2e9STakashi Iwai 				cfg->inputs[spec->auto_mic_ext].pin, 0,
4038f2e5731dSTakashi Iwai 				AC_VERB_SET_UNSOLICITED_ENABLE,
4039f2e5731dSTakashi Iwai 				AC_USRSP_EN | CONEXANT_MIC_EVENT);
404043c1b2e9STakashi Iwai 		}
404143c1b2e9STakashi Iwai 		if (spec->auto_mic_dock >= 0) {
404243c1b2e9STakashi Iwai 			snd_hda_codec_write(codec,
404343c1b2e9STakashi Iwai 				cfg->inputs[spec->auto_mic_dock].pin, 0,
404443c1b2e9STakashi Iwai 				AC_VERB_SET_UNSOLICITED_ENABLE,
404543c1b2e9STakashi Iwai 				AC_USRSP_EN | CONEXANT_MIC_EVENT);
404643c1b2e9STakashi Iwai 		}
4047f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
4048f2e5731dSTakashi Iwai 	} else {
404947ad1f4eSTakashi Iwai 		select_input_connection(codec, spec->imux_info[0].adc,
405047ad1f4eSTakashi Iwai 					spec->imux_info[0].pin);
4051f2e5731dSTakashi Iwai 	}
4052f2e5731dSTakashi Iwai }
4053f2e5731dSTakashi Iwai 
4054f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
4055f2e5731dSTakashi Iwai {
4056f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4057f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
4058f2e5731dSTakashi Iwai 
4059f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
4060f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4061f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4062f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
4063f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4064f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4065f2e5731dSTakashi Iwai }
4066f2e5731dSTakashi Iwai 
4067f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
4068f2e5731dSTakashi Iwai {
4069f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4070f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
4071f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
4072f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
4073f2e5731dSTakashi Iwai 	return 0;
4074f2e5731dSTakashi Iwai }
4075f2e5731dSTakashi Iwai 
4076983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4077f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
4078983345e5SDavid Henningsson 			      hda_nid_t nid, int hda_dir, int amp_idx)
4079f2e5731dSTakashi Iwai {
4080f2e5731dSTakashi Iwai 	static char name[32];
4081f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
4082f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
4083f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
4084f2e5731dSTakashi Iwai 	};
408534cbe3a6STakashi Iwai 	static const char * const sfx[2] = { "Volume", "Switch" };
4086f2e5731dSTakashi Iwai 	int i, err;
4087f2e5731dSTakashi Iwai 
4088f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
4089f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
4090983345e5SDavid Henningsson 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4091983345e5SDavid Henningsson 							    hda_dir);
4092f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4093f2e5731dSTakashi Iwai 		knew[i].index = cidx;
4094f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4095f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
4096f2e5731dSTakashi Iwai 		if (!kctl)
4097f2e5731dSTakashi Iwai 			return -ENOMEM;
4098f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
4099f2e5731dSTakashi Iwai 		if (err < 0)
4100f2e5731dSTakashi Iwai 			return err;
4101f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4102f2e5731dSTakashi Iwai 			break;
4103f2e5731dSTakashi Iwai 	}
4104f2e5731dSTakashi Iwai 	return 0;
4105f2e5731dSTakashi Iwai }
4106f2e5731dSTakashi Iwai 
4107983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\
4108983345e5SDavid Henningsson 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4109983345e5SDavid Henningsson 
4110f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
4111f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4112f2e5731dSTakashi Iwai 
41131f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
41141f8458a2STakashi Iwai 			     hda_nid_t pin, const char *name, int idx)
41151f8458a2STakashi Iwai {
41161f8458a2STakashi Iwai 	unsigned int caps;
41171f8458a2STakashi Iwai 	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
41181f8458a2STakashi Iwai 	if (caps & AC_AMPCAP_NUM_STEPS)
41191f8458a2STakashi Iwai 		return cx_auto_add_pb_volume(codec, dac, name, idx);
41201f8458a2STakashi Iwai 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
41211f8458a2STakashi Iwai 	if (caps & AC_AMPCAP_NUM_STEPS)
41221f8458a2STakashi Iwai 		return cx_auto_add_pb_volume(codec, pin, name, idx);
41231f8458a2STakashi Iwai 	return 0;
41241f8458a2STakashi Iwai }
41251f8458a2STakashi Iwai 
4126f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
4127f2e5731dSTakashi Iwai {
4128f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4129f2e5731dSTakashi Iwai 	int i, err;
4130f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
4131ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4132f2e5731dSTakashi Iwai 
4133f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
41341f8458a2STakashi Iwai 		return try_add_pb_volume(codec, spec->dac_info[0].dac,
41351f8458a2STakashi Iwai 					 spec->dac_info[0].pin,
4136f2e5731dSTakashi Iwai 					 "Master", 0);
41371f8458a2STakashi Iwai 
4138f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
4139f2e5731dSTakashi Iwai 		const char *label;
4140f2e5731dSTakashi Iwai 		int idx, type;
4141f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
4142f2e5731dSTakashi Iwai 			continue;
4143f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
4144f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
4145f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
4146f2e5731dSTakashi Iwai 		switch (type) {
4147f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
4148f2e5731dSTakashi Iwai 		default:
4149f2e5731dSTakashi Iwai 			label = texts[num_line++];
4150f2e5731dSTakashi Iwai 			idx = 0;
4151f2e5731dSTakashi Iwai 			break;
4152f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
4153f2e5731dSTakashi Iwai 			label = "Headphone";
4154f2e5731dSTakashi Iwai 			idx = num_hp++;
4155f2e5731dSTakashi Iwai 			break;
4156f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
4157f2e5731dSTakashi Iwai 			label = "Speaker";
4158f2e5731dSTakashi Iwai 			idx = num_spk++;
4159f2e5731dSTakashi Iwai 			break;
4160f2e5731dSTakashi Iwai 		}
41611f8458a2STakashi Iwai 		err = try_add_pb_volume(codec, spec->dac_info[i].dac,
41621f8458a2STakashi Iwai 					spec->dac_info[i].pin,
4163f2e5731dSTakashi Iwai 					label, idx);
4164f2e5731dSTakashi Iwai 		if (err < 0)
4165f2e5731dSTakashi Iwai 			return err;
4166f2e5731dSTakashi Iwai 	}
416703697e2aSTakashi Iwai 
416803697e2aSTakashi Iwai 	if (spec->auto_mute) {
416903697e2aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
417003697e2aSTakashi Iwai 		if (err < 0)
417103697e2aSTakashi Iwai 			return err;
417203697e2aSTakashi Iwai 	}
417303697e2aSTakashi Iwai 
4174f2e5731dSTakashi Iwai 	return 0;
4175f2e5731dSTakashi Iwai }
4176f2e5731dSTakashi Iwai 
41776764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
41786764bcefSTakashi Iwai 				      const char *label, const char *pfx,
41796764bcefSTakashi Iwai 				      int cidx)
41806764bcefSTakashi Iwai {
41816764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
41826764bcefSTakashi Iwai 	int i;
41836764bcefSTakashi Iwai 
41846764bcefSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
41856764bcefSTakashi Iwai 		hda_nid_t adc_nid = spec->adc_nids[i];
41865c9887e0STakashi Iwai 		int idx = get_input_connection(codec, adc_nid, nid);
41876764bcefSTakashi Iwai 		if (idx < 0)
41886764bcefSTakashi Iwai 			continue;
41896764bcefSTakashi Iwai 		return cx_auto_add_volume_idx(codec, label, pfx,
41906764bcefSTakashi Iwai 					      cidx, adc_nid, HDA_INPUT, idx);
41916764bcefSTakashi Iwai 	}
41926764bcefSTakashi Iwai 	return 0;
41936764bcefSTakashi Iwai }
41946764bcefSTakashi Iwai 
4195cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4196cf27f29aSTakashi Iwai 				    const char *label, int cidx)
4197cf27f29aSTakashi Iwai {
4198cf27f29aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4199cf27f29aSTakashi Iwai 	hda_nid_t mux, nid;
4200f9759301STakashi Iwai 	int i, con;
4201cf27f29aSTakashi Iwai 
420247ad1f4eSTakashi Iwai 	nid = spec->imux_info[idx].pin;
4203cf27f29aSTakashi Iwai 	if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4204cf27f29aSTakashi Iwai 		return cx_auto_add_volume(codec, label, " Boost", cidx,
4205cf27f29aSTakashi Iwai 					  nid, HDA_INPUT);
420647ad1f4eSTakashi Iwai 	con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
420747ad1f4eSTakashi Iwai 					&mux, false, 0);
4208cf27f29aSTakashi Iwai 	if (con < 0)
4209cf27f29aSTakashi Iwai 		return 0;
4210f9759301STakashi Iwai 	for (i = 0; i < idx; i++) {
421147ad1f4eSTakashi Iwai 		if (spec->imux_info[i].boost == mux)
4212f9759301STakashi Iwai 			return 0; /* already present */
4213f9759301STakashi Iwai 	}
4214f9759301STakashi Iwai 
4215f9759301STakashi Iwai 	if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
421647ad1f4eSTakashi Iwai 		spec->imux_info[idx].boost = mux;
4217cf27f29aSTakashi Iwai 		return cx_auto_add_volume(codec, label, " Boost", 0,
4218cf27f29aSTakashi Iwai 					  mux, HDA_OUTPUT);
4219f9759301STakashi Iwai 	}
4220cf27f29aSTakashi Iwai 	return 0;
4221cf27f29aSTakashi Iwai }
4222cf27f29aSTakashi Iwai 
4223f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
4224f2e5731dSTakashi Iwai {
4225f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4226cf27f29aSTakashi Iwai 	struct hda_input_mux *imux = &spec->private_imux;
4227cf27f29aSTakashi Iwai 	const char *prev_label;
4228cf27f29aSTakashi Iwai 	int input_conn[HDA_MAX_NUM_INPUTS];
42296764bcefSTakashi Iwai 	int i, err, cidx;
4230cf27f29aSTakashi Iwai 	int multi_connection;
4231cf27f29aSTakashi Iwai 
4232cf27f29aSTakashi Iwai 	multi_connection = 0;
4233cf27f29aSTakashi Iwai 	for (i = 0; i < imux->num_items; i++) {
423447ad1f4eSTakashi Iwai 		cidx = get_input_connection(codec, spec->imux_info[i].adc,
423547ad1f4eSTakashi Iwai 					    spec->imux_info[i].pin);
423647ad1f4eSTakashi Iwai 		input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
4237cf27f29aSTakashi Iwai 		if (i > 0 && input_conn[i] != input_conn[0])
4238cf27f29aSTakashi Iwai 			multi_connection = 1;
4239cf27f29aSTakashi Iwai 	}
4240983345e5SDavid Henningsson 
4241f2e5731dSTakashi Iwai 	prev_label = NULL;
4242f2e5731dSTakashi Iwai 	cidx = 0;
4243cf27f29aSTakashi Iwai 	for (i = 0; i < imux->num_items; i++) {
424447ad1f4eSTakashi Iwai 		hda_nid_t nid = spec->imux_info[i].pin;
4245f2e5731dSTakashi Iwai 		const char *label;
4246983345e5SDavid Henningsson 
4247cf27f29aSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, &spec->autocfg,
424847ad1f4eSTakashi Iwai 						    spec->imux_info[i].index);
4249f2e5731dSTakashi Iwai 		if (label == prev_label)
4250f2e5731dSTakashi Iwai 			cidx++;
4251f2e5731dSTakashi Iwai 		else
4252f2e5731dSTakashi Iwai 			cidx = 0;
4253f2e5731dSTakashi Iwai 		prev_label = label;
4254983345e5SDavid Henningsson 
4255cf27f29aSTakashi Iwai 		err = cx_auto_add_boost_volume(codec, i, label, cidx);
4256f2e5731dSTakashi Iwai 		if (err < 0)
4257f2e5731dSTakashi Iwai 			return err;
4258983345e5SDavid Henningsson 
4259cf27f29aSTakashi Iwai 		if (!multi_connection) {
4260f9759301STakashi Iwai 			if (i > 0)
4261f9759301STakashi Iwai 				continue;
42626764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
42636764bcefSTakashi Iwai 							 "Capture", "", cidx);
42646764bcefSTakashi Iwai 		} else {
42656764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
42666764bcefSTakashi Iwai 							 label, " Capture", cidx);
42676764bcefSTakashi Iwai 		}
4268983345e5SDavid Henningsson 		if (err < 0)
4269983345e5SDavid Henningsson 			return err;
4270983345e5SDavid Henningsson 	}
42716764bcefSTakashi Iwai 
42726764bcefSTakashi Iwai 	if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
42736764bcefSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
42746764bcefSTakashi Iwai 		if (err < 0)
42756764bcefSTakashi Iwai 			return err;
4276983345e5SDavid Henningsson 	}
42776764bcefSTakashi Iwai 
4278f2e5731dSTakashi Iwai 	return 0;
4279f2e5731dSTakashi Iwai }
4280f2e5731dSTakashi Iwai 
4281f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
4282f2e5731dSTakashi Iwai {
4283f2e5731dSTakashi Iwai 	int err;
4284f2e5731dSTakashi Iwai 
4285f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
4286f2e5731dSTakashi Iwai 	if (err < 0)
4287f2e5731dSTakashi Iwai 		return err;
4288f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
4289f2e5731dSTakashi Iwai 	if (err < 0)
4290f2e5731dSTakashi Iwai 		return err;
4291f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
4292f2e5731dSTakashi Iwai }
4293f2e5731dSTakashi Iwai 
429422ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec)
429522ce5f74STakashi Iwai {
429622ce5f74STakashi Iwai 	struct conexant_spec *spec = codec->spec;
429722ce5f74STakashi Iwai 	hda_nid_t nid, end_nid;
429822ce5f74STakashi Iwai 
429922ce5f74STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
430022ce5f74STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
430122ce5f74STakashi Iwai 		unsigned int caps = get_wcaps(codec, nid);
430222ce5f74STakashi Iwai 		if (get_wcaps_type(caps) != AC_WID_AUD_IN)
430322ce5f74STakashi Iwai 			continue;
430422ce5f74STakashi Iwai 		if (caps & AC_WCAP_DIGITAL)
430522ce5f74STakashi Iwai 			continue;
430622ce5f74STakashi Iwai 		if (snd_BUG_ON(spec->num_adc_nids >=
430722ce5f74STakashi Iwai 			       ARRAY_SIZE(spec->private_adc_nids)))
430822ce5f74STakashi Iwai 			break;
430922ce5f74STakashi Iwai 		spec->private_adc_nids[spec->num_adc_nids++] = nid;
431022ce5f74STakashi Iwai 	}
431122ce5f74STakashi Iwai 	spec->adc_nids = spec->private_adc_nids;
431222ce5f74STakashi Iwai 	return 0;
431322ce5f74STakashi Iwai }
431422ce5f74STakashi Iwai 
431522ce5f74STakashi Iwai 
431634cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
4317f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
4318f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
4319f2e5731dSTakashi Iwai 	.init = cx_auto_init,
4320f2e5731dSTakashi Iwai 	.free = conexant_free,
4321f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
4322f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
4323f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
4324f2e5731dSTakashi Iwai #endif
4325f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
4326f2e5731dSTakashi Iwai };
4327f2e5731dSTakashi Iwai 
4328f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
4329f2e5731dSTakashi Iwai {
4330f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
4331f2e5731dSTakashi Iwai 	int err;
4332f2e5731dSTakashi Iwai 
43331f8458a2STakashi Iwai 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
43341f8458a2STakashi Iwai 	       codec->chip_name);
43351f8458a2STakashi Iwai 
4336f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4337f2e5731dSTakashi Iwai 	if (!spec)
4338f2e5731dSTakashi Iwai 		return -ENOMEM;
4339f2e5731dSTakashi Iwai 	codec->spec = spec;
43401387cde5STakashi Iwai 	codec->pin_amp_workaround = 1;
434122ce5f74STakashi Iwai 	err = cx_auto_search_adcs(codec);
434222ce5f74STakashi Iwai 	if (err < 0)
434322ce5f74STakashi Iwai 		return err;
4344f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
4345f2e5731dSTakashi Iwai 	if (err < 0) {
4346f2e5731dSTakashi Iwai 		kfree(codec->spec);
4347f2e5731dSTakashi Iwai 		codec->spec = NULL;
4348f2e5731dSTakashi Iwai 		return err;
4349f2e5731dSTakashi Iwai 	}
43506764bcefSTakashi Iwai 	spec->capture_stream = &cx_auto_pcm_analog_capture;
4351f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
4352f2e5731dSTakashi Iwai 	if (spec->beep_amp)
4353f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
4354f2e5731dSTakashi Iwai 	return 0;
4355f2e5731dSTakashi Iwai }
4356f2e5731dSTakashi Iwai 
4357f2e5731dSTakashi Iwai /*
4358461e2c78STakashi Iwai  */
4359461e2c78STakashi Iwai 
436034cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
436182f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
436282f30040STobin Davis 	  .patch = patch_cxt5045 },
436382f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
436482f30040STobin Davis 	  .patch = patch_cxt5047 },
4365461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4366461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
43670fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
43680fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
436995a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
437095a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
4371850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
4372850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
43737b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
43747b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
4375f0ca89b0SDavid Henningsson 	{ .id = 0x14f1506c, .name = "CX20588",
4376f0ca89b0SDavid Henningsson 	  .patch = patch_cxt5066 },
43776da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
43786da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
4379f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
4380f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4381f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
4382f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4383f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
4384f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4385f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
4386f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4387f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
4388f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4389f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
4390f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4391f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
4392f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4393f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
4394f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4395c9b443d4STobin Davis 	{} /* terminator */
4396c9b443d4STobin Davis };
43971289e9e8STakashi Iwai 
43981289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
43991289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
44001289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
44010fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
440295a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
4403850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
44047b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
4405f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c");
44066da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4407f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
4408f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
4409f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4410f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4411f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4412f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4413f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4414f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
44151289e9e8STakashi Iwai 
44161289e9e8STakashi Iwai MODULE_LICENSE("GPL");
44171289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
44181289e9e8STakashi Iwai 
44191289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
44201289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
44211289e9e8STakashi Iwai 	.owner = THIS_MODULE,
44221289e9e8STakashi Iwai };
44231289e9e8STakashi Iwai 
44241289e9e8STakashi Iwai static int __init patch_conexant_init(void)
44251289e9e8STakashi Iwai {
44261289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
44271289e9e8STakashi Iwai }
44281289e9e8STakashi Iwai 
44291289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
44301289e9e8STakashi Iwai {
44311289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
44321289e9e8STakashi Iwai }
44331289e9e8STakashi Iwai 
44341289e9e8STakashi Iwai module_init(patch_conexant_init)
44351289e9e8STakashi Iwai module_exit(patch_conexant_exit)
4436