xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 19110595c89b2d606883b7cb99260c7e47fd2143)
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;
158*19110595STakashi Iwai 
159*19110595STakashi Iwai 	/* extra EAPD pins */
160*19110595STakashi Iwai 	unsigned int num_eapds;
161*19110595STakashi Iwai 	hda_nid_t eapds[4];
162c9b443d4STobin Davis };
163c9b443d4STobin Davis 
164c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
165c9b443d4STobin Davis 				      struct hda_codec *codec,
166c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
167c9b443d4STobin Davis {
168c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1699a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1709a08160bSTakashi Iwai 					     hinfo);
171c9b443d4STobin Davis }
172c9b443d4STobin Davis 
173c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
174c9b443d4STobin Davis 					 struct hda_codec *codec,
175c9b443d4STobin Davis 					 unsigned int stream_tag,
176c9b443d4STobin Davis 					 unsigned int format,
177c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
178c9b443d4STobin Davis {
179c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
180c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
181c9b443d4STobin Davis 						stream_tag,
182c9b443d4STobin Davis 						format, substream);
183c9b443d4STobin Davis }
184c9b443d4STobin Davis 
185c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
186c9b443d4STobin Davis 					 struct hda_codec *codec,
187c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
188c9b443d4STobin Davis {
189c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
190c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
191c9b443d4STobin Davis }
192c9b443d4STobin Davis 
193c9b443d4STobin Davis /*
194c9b443d4STobin Davis  * Digital out
195c9b443d4STobin Davis  */
196c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
197c9b443d4STobin Davis 					  struct hda_codec *codec,
198c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
199c9b443d4STobin Davis {
200c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
201c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
202c9b443d4STobin Davis }
203c9b443d4STobin Davis 
204c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
205c9b443d4STobin Davis 					 struct hda_codec *codec,
206c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
207c9b443d4STobin Davis {
208c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
209c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
210c9b443d4STobin Davis }
211c9b443d4STobin Davis 
2126b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2136b97eb45STakashi Iwai 					 struct hda_codec *codec,
2146b97eb45STakashi Iwai 					 unsigned int stream_tag,
2156b97eb45STakashi Iwai 					 unsigned int format,
2166b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
2176b97eb45STakashi Iwai {
2186b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2196b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2206b97eb45STakashi Iwai 					     stream_tag,
2216b97eb45STakashi Iwai 					     format, substream);
2226b97eb45STakashi Iwai }
2236b97eb45STakashi Iwai 
224c9b443d4STobin Davis /*
225c9b443d4STobin Davis  * Analog capture
226c9b443d4STobin Davis  */
227c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
228c9b443d4STobin Davis 				      struct hda_codec *codec,
229c9b443d4STobin Davis 				      unsigned int stream_tag,
230c9b443d4STobin Davis 				      unsigned int format,
231c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
232c9b443d4STobin Davis {
233c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
23475f8991dSDaniel Drake 	if (spec->capture_prepare)
23575f8991dSDaniel Drake 		spec->capture_prepare(codec);
236c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
237c9b443d4STobin Davis 				   stream_tag, 0, format);
238c9b443d4STobin Davis 	return 0;
239c9b443d4STobin Davis }
240c9b443d4STobin Davis 
241c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
242c9b443d4STobin Davis 				      struct hda_codec *codec,
243c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
244c9b443d4STobin Davis {
245c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
246888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
24775f8991dSDaniel Drake 	if (spec->capture_cleanup)
24875f8991dSDaniel Drake 		spec->capture_cleanup(codec);
249c9b443d4STobin Davis 	return 0;
250c9b443d4STobin Davis }
251c9b443d4STobin Davis 
252c9b443d4STobin Davis 
253c9b443d4STobin Davis 
25434cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = {
255c9b443d4STobin Davis 	.substreams = 1,
256c9b443d4STobin Davis 	.channels_min = 2,
257c9b443d4STobin Davis 	.channels_max = 2,
258c9b443d4STobin Davis 	.nid = 0, /* fill later */
259c9b443d4STobin Davis 	.ops = {
260c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
261c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
262c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
263c9b443d4STobin Davis 	},
264c9b443d4STobin Davis };
265c9b443d4STobin Davis 
26634cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = {
267c9b443d4STobin Davis 	.substreams = 1,
268c9b443d4STobin Davis 	.channels_min = 2,
269c9b443d4STobin Davis 	.channels_max = 2,
270c9b443d4STobin Davis 	.nid = 0, /* fill later */
271c9b443d4STobin Davis 	.ops = {
272c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
273c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
274c9b443d4STobin Davis 	},
275c9b443d4STobin Davis };
276c9b443d4STobin Davis 
277c9b443d4STobin Davis 
27834cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = {
279c9b443d4STobin Davis 	.substreams = 1,
280c9b443d4STobin Davis 	.channels_min = 2,
281c9b443d4STobin Davis 	.channels_max = 2,
282c9b443d4STobin Davis 	.nid = 0, /* fill later */
283c9b443d4STobin Davis 	.ops = {
284c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2856b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2866b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
287c9b443d4STobin Davis 	},
288c9b443d4STobin Davis };
289c9b443d4STobin Davis 
29034cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = {
291c9b443d4STobin Davis 	.substreams = 1,
292c9b443d4STobin Davis 	.channels_min = 2,
293c9b443d4STobin Davis 	.channels_max = 2,
294c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
295c9b443d4STobin Davis };
296c9b443d4STobin Davis 
297461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
298461e2c78STakashi Iwai 				      struct hda_codec *codec,
299461e2c78STakashi Iwai 				      unsigned int stream_tag,
300461e2c78STakashi Iwai 				      unsigned int format,
301461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
302461e2c78STakashi Iwai {
303461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
304461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
305461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
306461e2c78STakashi Iwai 	spec->cur_adc_format = format;
307461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
308461e2c78STakashi Iwai 	return 0;
309461e2c78STakashi Iwai }
310461e2c78STakashi Iwai 
311461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
312461e2c78STakashi Iwai 				      struct hda_codec *codec,
313461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
314461e2c78STakashi Iwai {
315461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
316888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
317461e2c78STakashi Iwai 	spec->cur_adc = 0;
318461e2c78STakashi Iwai 	return 0;
319461e2c78STakashi Iwai }
320461e2c78STakashi Iwai 
32134cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
322461e2c78STakashi Iwai 	.substreams = 1,
323461e2c78STakashi Iwai 	.channels_min = 2,
324461e2c78STakashi Iwai 	.channels_max = 2,
325461e2c78STakashi Iwai 	.nid = 0, /* fill later */
326461e2c78STakashi Iwai 	.ops = {
327461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
328461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
329461e2c78STakashi Iwai 	},
330461e2c78STakashi Iwai };
331461e2c78STakashi Iwai 
332c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
333c9b443d4STobin Davis {
334c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
335c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
336c9b443d4STobin Davis 
337c9b443d4STobin Davis 	codec->num_pcms = 1;
338c9b443d4STobin Davis 	codec->pcm_info = info;
339c9b443d4STobin Davis 
340c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
341c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
342c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
343c9b443d4STobin Davis 		spec->multiout.max_channels;
344c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
345c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
3466764bcefSTakashi Iwai 	if (spec->capture_stream)
3476764bcefSTakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
3486764bcefSTakashi Iwai 	else {
349461e2c78STakashi Iwai 		if (codec->vendor_id == 0x14f15051)
350461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
351461e2c78STakashi Iwai 				cx5051_pcm_analog_capture;
3526764bcefSTakashi Iwai 		else {
353461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
354461e2c78STakashi Iwai 				conexant_pcm_analog_capture;
3556764bcefSTakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3566764bcefSTakashi Iwai 				spec->num_adc_nids;
3576764bcefSTakashi Iwai 		}
3586764bcefSTakashi Iwai 	}
359c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
360c9b443d4STobin Davis 
361c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
362c9b443d4STobin Davis 		info++;
363c9b443d4STobin Davis 		codec->num_pcms++;
364c9b443d4STobin Davis 		info->name = "Conexant Digital";
3657ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
366c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
367c9b443d4STobin Davis 			conexant_pcm_digital_playback;
368c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
369c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
370c9b443d4STobin Davis 		if (spec->dig_in_nid) {
371c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
372c9b443d4STobin Davis 				conexant_pcm_digital_capture;
373c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
374c9b443d4STobin Davis 				spec->dig_in_nid;
375c9b443d4STobin Davis 		}
376f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
377f6a2491cSAndy Robinson 			codec->slave_dig_outs = spec->slave_dig_outs;
378c9b443d4STobin Davis 	}
379c9b443d4STobin Davis 
380c9b443d4STobin Davis 	return 0;
381c9b443d4STobin Davis }
382c9b443d4STobin Davis 
383c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
384c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
385c9b443d4STobin Davis {
386c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
387c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
388c9b443d4STobin Davis 
389c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
390c9b443d4STobin Davis }
391c9b443d4STobin Davis 
392c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
393c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
394c9b443d4STobin Davis {
395c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
397c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
398c9b443d4STobin Davis 
399c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
400c9b443d4STobin Davis 	return 0;
401c9b443d4STobin Davis }
402c9b443d4STobin Davis 
403c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
404c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
405c9b443d4STobin Davis {
406c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
408c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
409c9b443d4STobin Davis 
410c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
411c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
412c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
413c9b443d4STobin Davis }
414c9b443d4STobin Davis 
415bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
416bc7a166dSUlrich Dangel {
417cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
418bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
419bc7a166dSUlrich Dangel 	int i;
420bc7a166dSUlrich Dangel 
421bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
422bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
423bc7a166dSUlrich Dangel 
424bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
425bc7a166dSUlrich Dangel 		while (hv->nid) {
426bc7a166dSUlrich Dangel 			int err = 0;
427bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
428bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
429cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
430cd372fb3STakashi Iwai 						SND_JACK_HEADPHONE, NULL);
431cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
432bc7a166dSUlrich Dangel 				break;
433bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
434bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
435cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
436cd372fb3STakashi Iwai 						SND_JACK_MICROPHONE, NULL);
437cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
438bc7a166dSUlrich Dangel 				break;
439bc7a166dSUlrich Dangel 			}
440bc7a166dSUlrich Dangel 			if (err < 0)
441bc7a166dSUlrich Dangel 				return err;
442bc7a166dSUlrich Dangel 			++hv;
443bc7a166dSUlrich Dangel 		}
444bc7a166dSUlrich Dangel 	}
445cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */
4465801f992STakashi Iwai 	return 0;
4475801f992STakashi Iwai }
448bc7a166dSUlrich Dangel 
449c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
450c9b443d4STobin Davis {
451c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
452c9b443d4STobin Davis 	int i;
453c9b443d4STobin Davis 
454c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
455c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
456c9b443d4STobin Davis 	return 0;
457c9b443d4STobin Davis }
458c9b443d4STobin Davis 
459c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
460c9b443d4STobin Davis {
461cd372fb3STakashi Iwai 	snd_hda_input_jack_free(codec);
462c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
463c9b443d4STobin Davis 	kfree(codec->spec);
464c9b443d4STobin Davis }
465c9b443d4STobin Davis 
46634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = {
467b880c74aSTakashi Iwai 	{
468b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469b880c74aSTakashi Iwai 		.name = "Capture Source",
470b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
471b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
472b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
473b880c74aSTakashi Iwai 	},
474b880c74aSTakashi Iwai 	{}
475b880c74aSTakashi Iwai };
476b880c74aSTakashi Iwai 
4773507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
4783507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
47934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = {
4803507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
4813507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
4823507e2a8STakashi Iwai 	{ } /* end */
4833507e2a8STakashi Iwai };
4843507e2a8STakashi Iwai #endif
4853507e2a8STakashi Iwai 
486ea734963STakashi Iwai static const char * const slave_vols[] = {
487dd5746a8STakashi Iwai 	"Headphone Playback Volume",
488dd5746a8STakashi Iwai 	"Speaker Playback Volume",
489a3a85d39STakashi Iwai 	"Front Playback Volume",
490a3a85d39STakashi Iwai 	"Surround Playback Volume",
491a3a85d39STakashi Iwai 	"CLFE Playback Volume",
492dd5746a8STakashi Iwai 	NULL
493dd5746a8STakashi Iwai };
494dd5746a8STakashi Iwai 
495ea734963STakashi Iwai static const char * const slave_sws[] = {
496dd5746a8STakashi Iwai 	"Headphone Playback Switch",
497dd5746a8STakashi Iwai 	"Speaker Playback Switch",
498a3a85d39STakashi Iwai 	"Front Playback Switch",
499a3a85d39STakashi Iwai 	"Surround Playback Switch",
500a3a85d39STakashi Iwai 	"CLFE Playback Switch",
501dd5746a8STakashi Iwai 	NULL
502dd5746a8STakashi Iwai };
503dd5746a8STakashi Iwai 
504c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
505c9b443d4STobin Davis {
506c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
507c9b443d4STobin Davis 	unsigned int i;
508c9b443d4STobin Davis 	int err;
509c9b443d4STobin Davis 
510c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
511c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
512c9b443d4STobin Davis 		if (err < 0)
513c9b443d4STobin Davis 			return err;
514c9b443d4STobin Davis 	}
515c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
516c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
51774b654c9SStephen Warren 						    spec->multiout.dig_out_nid,
518c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
519c9b443d4STobin Davis 		if (err < 0)
520c9b443d4STobin Davis 			return err;
5219a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5229a08160bSTakashi Iwai 						    &spec->multiout);
5239a08160bSTakashi Iwai 		if (err < 0)
5249a08160bSTakashi Iwai 			return err;
5259a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
526c9b443d4STobin Davis 	}
527c9b443d4STobin Davis 	if (spec->dig_in_nid) {
528c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
529c9b443d4STobin Davis 		if (err < 0)
530c9b443d4STobin Davis 			return err;
531c9b443d4STobin Davis 	}
532dd5746a8STakashi Iwai 
533dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
534dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
535dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
536dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
537dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
538dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
539dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
540dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
541dd5746a8STakashi Iwai 		if (err < 0)
542dd5746a8STakashi Iwai 			return err;
543dd5746a8STakashi Iwai 	}
544dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
545dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
546dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
547dd5746a8STakashi Iwai 					  NULL, slave_sws);
548dd5746a8STakashi Iwai 		if (err < 0)
549dd5746a8STakashi Iwai 			return err;
550dd5746a8STakashi Iwai 	}
551dd5746a8STakashi Iwai 
552b880c74aSTakashi Iwai 	if (spec->input_mux) {
553b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
554b880c74aSTakashi Iwai 		if (err < 0)
555b880c74aSTakashi Iwai 			return err;
556b880c74aSTakashi Iwai 	}
557b880c74aSTakashi Iwai 
5583507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5593507e2a8STakashi Iwai 	/* create beep controls if needed */
5603507e2a8STakashi Iwai 	if (spec->beep_amp) {
56134cbe3a6STakashi Iwai 		const struct snd_kcontrol_new *knew;
5623507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
5633507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
5643507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
5653507e2a8STakashi Iwai 			if (!kctl)
5663507e2a8STakashi Iwai 				return -ENOMEM;
5673507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
5683507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
5693507e2a8STakashi Iwai 			if (err < 0)
5703507e2a8STakashi Iwai 				return err;
5713507e2a8STakashi Iwai 		}
5723507e2a8STakashi Iwai 	}
5733507e2a8STakashi Iwai #endif
5743507e2a8STakashi Iwai 
575c9b443d4STobin Davis 	return 0;
576c9b443d4STobin Davis }
577c9b443d4STobin Davis 
578697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
579697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
580697c373eSTakashi Iwai {
581697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
582697c373eSTakashi Iwai 	return 0;
583697c373eSTakashi Iwai }
584697c373eSTakashi Iwai #endif
585697c373eSTakashi Iwai 
58634cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = {
587c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
588c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
589c9b443d4STobin Davis 	.init = conexant_init,
590c9b443d4STobin Davis 	.free = conexant_free,
591697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
592697c373eSTakashi Iwai 	.suspend = conexant_suspend,
593697c373eSTakashi Iwai #endif
594697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
595c9b443d4STobin Davis };
596c9b443d4STobin Davis 
5973507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5983507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
5993507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
6003507e2a8STakashi Iwai #else
6013507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
6023507e2a8STakashi Iwai #endif
6033507e2a8STakashi Iwai 
6046764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec);
605c9b443d4STobin Davis /*
606c9b443d4STobin Davis  * EAPD control
607c9b443d4STobin Davis  * the private value = nid | (invert << 8)
608c9b443d4STobin Davis  */
609c9b443d4STobin Davis 
610a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
611c9b443d4STobin Davis 
61282f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
613c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
614c9b443d4STobin Davis {
615c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
616c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
617c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
618c9b443d4STobin Davis 	if (invert)
619c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
620c9b443d4STobin Davis 	else
621c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
622c9b443d4STobin Davis 	return 0;
62382f30040STobin Davis 
624c9b443d4STobin Davis }
625c9b443d4STobin Davis 
62682f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
627c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
628c9b443d4STobin Davis {
629c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
631c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
632c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
633c9b443d4STobin Davis 	unsigned int eapd;
63482f30040STobin Davis 
63568ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
636c9b443d4STobin Davis 	if (invert)
637c9b443d4STobin Davis 		eapd = !eapd;
63882beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
639c9b443d4STobin Davis 		return 0;
64082f30040STobin Davis 
641c9b443d4STobin Davis 	spec->cur_eapd = eapd;
64282beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
643c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
644c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
645c9b443d4STobin Davis 	return 1;
646c9b443d4STobin Davis }
647c9b443d4STobin Davis 
64886d72bdfSTakashi Iwai /* controls for test mode */
64986d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
65086d72bdfSTakashi Iwai 
65182f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
65282f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
65382f30040STobin Davis 	  .info = cxt_eapd_info, \
65482f30040STobin Davis 	  .get = cxt_eapd_get, \
65582f30040STobin Davis 	  .put = cxt_eapd_put, \
65682f30040STobin Davis 	  .private_value = nid | (mask<<16) }
65782f30040STobin Davis 
65882f30040STobin Davis 
65982f30040STobin Davis 
660c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
661c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
662c9b443d4STobin Davis {
663c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
664c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
665c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
666c9b443d4STobin Davis 				    spec->num_channel_mode);
667c9b443d4STobin Davis }
668c9b443d4STobin Davis 
669c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
670c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
671c9b443d4STobin Davis {
672c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
673c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
674c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
675c9b443d4STobin Davis 				   spec->num_channel_mode,
676c9b443d4STobin Davis 				   spec->multiout.max_channels);
677c9b443d4STobin Davis }
678c9b443d4STobin Davis 
679c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
680c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
681c9b443d4STobin Davis {
682c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
683c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
684c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
685c9b443d4STobin Davis 				      spec->num_channel_mode,
686c9b443d4STobin Davis 				      &spec->multiout.max_channels);
687c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
688c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
689c9b443d4STobin Davis 	return err;
690c9b443d4STobin Davis }
691c9b443d4STobin Davis 
692c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
693c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
694c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
695c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
696c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
697c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
698c9b443d4STobin Davis 
69986d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
70086d72bdfSTakashi Iwai 
701c9b443d4STobin Davis /* Conexant 5045 specific */
702c9b443d4STobin Davis 
70334cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
70434cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
70534cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
706cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
707c9b443d4STobin Davis 
70834cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = {
7095cd57529STobin Davis 	{ 2, NULL },
7105cd57529STobin Davis };
711c9b443d4STobin Davis 
71234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = {
713c9b443d4STobin Davis 	.num_items = 2,
714c9b443d4STobin Davis 	.items = {
71582f30040STobin Davis 		{ "IntMic", 0x1 },
716f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
717c9b443d4STobin Davis 	}
718c9b443d4STobin Davis };
719c9b443d4STobin Davis 
72034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = {
72122e14130SLukasz Marcinowski 	.num_items = 5,
7225218c892SJiang Zhe 	.items = {
7235218c892SJiang Zhe 		{ "IntMic", 0x1 },
7245218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7255218c892SJiang Zhe 		{ "LineIn", 0x3 },
72622e14130SLukasz Marcinowski 		{ "CD",     0x4 },
72722e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7285218c892SJiang Zhe 	}
7295218c892SJiang Zhe };
7305218c892SJiang Zhe 
73134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = {
7322de3c232SJiang zhe 	.num_items = 2,
7332de3c232SJiang zhe 	.items = {
7342de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7352de3c232SJiang zhe 		{ "IntMic", 0x2 },
7362de3c232SJiang zhe 	}
7372de3c232SJiang zhe };
7382de3c232SJiang zhe 
739c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
740c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
741c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
742c9b443d4STobin Davis {
743c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
74582f30040STobin Davis 	unsigned int bits;
746c9b443d4STobin Davis 
74782f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
748c9b443d4STobin Davis 		return 0;
749c9b443d4STobin Davis 
75082f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
75182f30040STobin Davis 	 * the headphone jack
75282f30040STobin Davis 	 */
75347fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
75447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
75547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7567f29673bSTobin Davis 
75747fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
75847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
75947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
760c9b443d4STobin Davis 	return 1;
761c9b443d4STobin Davis }
762c9b443d4STobin Davis 
763c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
76434cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
765cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
766cca3b371STakashi Iwai 	.values = {
767cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
768cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
769cca3b371STakashi Iwai 		0
770cca3b371STakashi Iwai 	},
771cca3b371STakashi Iwai };
772c9b443d4STobin Davis 
7737f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7747f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7757f29673bSTobin Davis {
77634cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
7777f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7787f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7797f29673bSTobin Davis 		{}
7807f29673bSTobin Davis 	};
78134cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
7827f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7837f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7847f29673bSTobin Davis 		{}
7857f29673bSTobin Davis 	};
7867f29673bSTobin Davis 	unsigned int present;
7877f29673bSTobin Davis 
788d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7897f29673bSTobin Davis 	if (present)
7907f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7917f29673bSTobin Davis 	else
7927f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7937f29673bSTobin Davis }
7947f29673bSTobin Davis 
795c9b443d4STobin Davis 
796c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
797c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
798c9b443d4STobin Davis {
79982f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
800dd87da1cSTobin Davis 	unsigned int bits;
801c9b443d4STobin Davis 
802d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
803dd87da1cSTobin Davis 
80447fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
80547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
80647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
807c9b443d4STobin Davis }
808c9b443d4STobin Davis 
809c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
810c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
811c9b443d4STobin Davis 				   unsigned int res)
812c9b443d4STobin Davis {
813c9b443d4STobin Davis 	res >>= 26;
814c9b443d4STobin Davis 	switch (res) {
815c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
816c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
817c9b443d4STobin Davis 		break;
8187f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8197f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8207f29673bSTobin Davis 		break;
8217f29673bSTobin Davis 
822c9b443d4STobin Davis 	}
823c9b443d4STobin Davis }
824c9b443d4STobin Davis 
82534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = {
82628c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
82728c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8288607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8298607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
830c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
831c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
83228c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
83328c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8348607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8358607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
836cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
837c9b443d4STobin Davis 	{
838c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
839c9b443d4STobin Davis 		.name = "Master Playback Switch",
84082f30040STobin Davis 		.info = cxt_eapd_info,
84182f30040STobin Davis 		.get = cxt_eapd_get,
842c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
84382f30040STobin Davis 		.private_value = 0x10,
844c9b443d4STobin Davis 	},
845c9b443d4STobin Davis 
846c9b443d4STobin Davis 	{}
847c9b443d4STobin Davis };
848c9b443d4STobin Davis 
84934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
85022e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
85122e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
85222e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
85322e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
85422e14130SLukasz Marcinowski 
8555218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8565218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8575218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8585218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8595218c892SJiang Zhe 
86022e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
86122e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
86222e14130SLukasz Marcinowski 
8635218c892SJiang Zhe 	{}
8645218c892SJiang Zhe };
8655218c892SJiang Zhe 
86634cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
86728c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
86828c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8698607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8708607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8712de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8722de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
87328c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
87428c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8758607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8768607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8772de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8782de3c232SJiang zhe 	{
8792de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8802de3c232SJiang zhe 		.name = "Master Playback Switch",
8812de3c232SJiang zhe 		.info = cxt_eapd_info,
8822de3c232SJiang zhe 		.get = cxt_eapd_get,
8832de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8842de3c232SJiang zhe 		.private_value = 0x10,
8852de3c232SJiang zhe 	},
8862de3c232SJiang zhe 
8872de3c232SJiang zhe 	{}
8882de3c232SJiang zhe };
8892de3c232SJiang zhe 
89034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = {
891c9b443d4STobin Davis 	/* Line in, Mic */
8924090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8937f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
894c9b443d4STobin Davis 	/* HP, Amp  */
895c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
896c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
89782f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
898c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
899c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
900c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
901c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
902c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
903c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
90428c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9057f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
90682f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
907c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
908c9b443d4STobin Davis 	/* SPDIF route: PCM */
909cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
910c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
911c9b443d4STobin Davis 	/* EAPD */
91282f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
913c9b443d4STobin Davis 	{ } /* end */
914c9b443d4STobin Davis };
915c9b443d4STobin Davis 
91634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = {
91728c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
9185218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9195218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9205218c892SJiang Zhe 	/* Line In,HP, Amp  */
9215218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9225218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9235218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9245218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9255218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9265218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9275218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9285218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9295218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
93028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9315218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9325218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9335218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9345218c892SJiang Zhe 	/* SPDIF route: PCM */
935cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9365218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9375218c892SJiang Zhe 	/* EAPD */
9385218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9395218c892SJiang Zhe 	{ } /* end */
9405218c892SJiang Zhe };
9417f29673bSTobin Davis 
94234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9437f29673bSTobin Davis 	/* pin sensing on HP jack */
9447f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
945d3091fadSTakashi Iwai 	{ } /* end */
9467f29673bSTobin Davis };
9477f29673bSTobin Davis 
94834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9497f29673bSTobin Davis 	/* pin sensing on HP jack */
9507f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
951d3091fadSTakashi Iwai 	{ } /* end */
9527f29673bSTobin Davis };
9537f29673bSTobin Davis 
954c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
955c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
956c9b443d4STobin Davis  * configuration.
957c9b443d4STobin Davis  */
95834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = {
959c9b443d4STobin Davis 	.num_items = 5,
960c9b443d4STobin Davis 	.items = {
961c9b443d4STobin Davis 		{ "MIXER", 0x0 },
962c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
963c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
964c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
965c9b443d4STobin Davis 		{ "CD pin", 0x4 },
966c9b443d4STobin Davis         },
967c9b443d4STobin Davis };
968c9b443d4STobin Davis 
96934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
970c9b443d4STobin Davis 
971c9b443d4STobin Davis 	/* Output controls */
972c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
973c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9747f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9757f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9767f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9777f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
978c9b443d4STobin Davis 
979c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
980c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
981c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
982c9b443d4STobin Davis 
98382f30040STobin Davis 	/* EAPD Switch Control */
98482f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
98582f30040STobin Davis 
986c9b443d4STobin Davis 	/* Loopback mixer controls */
987c9b443d4STobin Davis 
9887f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9897f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9907f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9917f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9927f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9937f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9947f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9957f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9967f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9977f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
998c9b443d4STobin Davis 	{
999c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1000c9b443d4STobin Davis 		.name = "Input Source",
1001c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1002c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1003c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1004c9b443d4STobin Davis 	},
1005fb3409e7STobin Davis 	/* Audio input controls */
1006fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1007fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1008fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1009fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1010fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1011fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1012fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1013fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1014fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1015fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1016c9b443d4STobin Davis 	{ } /* end */
1017c9b443d4STobin Davis };
1018c9b443d4STobin Davis 
101934cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = {
10207f29673bSTobin Davis 	/* Set connections */
10217f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10227f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10237f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1024c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1025c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10267f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1027c9b443d4STobin Davis 
1028c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1029c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1030c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1031c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1032c9b443d4STobin Davis 	 * control.
1033c9b443d4STobin Davis 	 */
1034cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1035cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1036c9b443d4STobin Davis 
1037c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1038c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1039c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1040c9b443d4STobin Davis 
1041c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1042c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1043c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1044c9b443d4STobin Davis 	 * input/output buffers as needed.
1045c9b443d4STobin Davis 	 */
1046c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1047c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1048c9b443d4STobin Davis 
1049c9b443d4STobin Davis 	/* Mute capture amp left and right */
1050c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1051c9b443d4STobin Davis 
1052c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1053c9b443d4STobin Davis 	 * pin)
1054c9b443d4STobin Davis 	 */
1055c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10567f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1057c9b443d4STobin Davis 
1058c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1059c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1060c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1061c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1062c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1063c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1064c9b443d4STobin Davis 
1065c9b443d4STobin Davis 	{ }
1066c9b443d4STobin Davis };
1067c9b443d4STobin Davis #endif
1068c9b443d4STobin Davis 
1069c9b443d4STobin Davis 
1070c9b443d4STobin Davis /* initialize jack-sensing, too */
1071c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1072c9b443d4STobin Davis {
1073c9b443d4STobin Davis 	conexant_init(codec);
1074c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1075c9b443d4STobin Davis 	return 0;
1076c9b443d4STobin Davis }
1077c9b443d4STobin Davis 
1078c9b443d4STobin Davis 
1079c9b443d4STobin Davis enum {
108015908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
108115908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
108215908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10835218c892SJiang Zhe 	CXT5045_BENQ,
10842de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1085c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1086c9b443d4STobin Davis 	CXT5045_TEST,
1087c9b443d4STobin Davis #endif
10881f8458a2STakashi Iwai 	CXT5045_AUTO,
1089f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1090c9b443d4STobin Davis };
1091c9b443d4STobin Davis 
1092ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
109315908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
109415908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
109515908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10965218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10972de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1098c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1099f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1100c9b443d4STobin Davis #endif
11011f8458a2STakashi Iwai 	[CXT5045_AUTO]			= "auto",
1102f5fcc13cSTakashi Iwai };
1103c9b443d4STobin Davis 
110434cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
11052de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1106dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1107dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
11086a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
11095218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
111015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
111115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
11129e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
11139e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
111415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
111515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
111615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1117dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1118dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
111915908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1120c9b443d4STobin Davis 	{}
1121c9b443d4STobin Davis };
1122c9b443d4STobin Davis 
1123c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1124c9b443d4STobin Davis {
1125c9b443d4STobin Davis 	struct conexant_spec *spec;
1126c9b443d4STobin Davis 	int board_config;
1127c9b443d4STobin Davis 
11281f8458a2STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
11291f8458a2STakashi Iwai 						  cxt5045_models,
11301f8458a2STakashi Iwai 						  cxt5045_cfg_tbl);
11311f8458a2STakashi Iwai 	if (board_config < 0)
1132c82693dbSTakashi Iwai 		board_config = CXT5045_AUTO; /* model=auto as default */
11331f8458a2STakashi Iwai 	if (board_config == CXT5045_AUTO)
11341f8458a2STakashi Iwai 		return patch_conexant_auto(codec);
11351f8458a2STakashi Iwai 
1136c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1137c9b443d4STobin Davis 	if (!spec)
1138c9b443d4STobin Davis 		return -ENOMEM;
1139c9b443d4STobin Davis 	codec->spec = spec;
11409421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1141c9b443d4STobin Davis 
1142c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1143c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1144c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1145c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1146c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1147c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1148c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1149c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1150c9b443d4STobin Davis 	spec->num_mixers = 1;
1151c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1152c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1153c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1154c9b443d4STobin Davis 	spec->spdif_route = 0;
11553507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11563507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11575cd57529STobin Davis 
11583507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1159c9b443d4STobin Davis 
1160c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1161c9b443d4STobin Davis 
1162c9b443d4STobin Davis 	switch (board_config) {
116315908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11647f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1165c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1166c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11677f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11687f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11697f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11707f29673bSTobin Davis 		break;
117115908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
117286376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11737f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11747f29673bSTobin Davis 		spec->num_init_verbs = 2;
11757f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1176c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1177c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1178c9b443d4STobin Davis 		break;
117915908c36SMarc Boucher 	default:
118015908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
118115908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
118215908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
118315908c36SMarc Boucher 		spec->num_init_verbs = 3;
118415908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
118515908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
118615908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
118715908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
118815908c36SMarc Boucher 		break;
11895218c892SJiang Zhe 	case CXT5045_BENQ:
11905218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11915218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11925218c892SJiang Zhe 		spec->num_init_verbs = 1;
11935218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11945218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11955218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11965218c892SJiang Zhe 		spec->num_mixers = 2;
11975218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11985218c892SJiang Zhe 		break;
11992de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
12002de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12012de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
12022de3c232SJiang zhe 		spec->num_init_verbs = 2;
12032de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12042de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
12052de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
12062de3c232SJiang zhe 		break;
1207c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1208c9b443d4STobin Davis 	case CXT5045_TEST:
1209c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1210c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1211c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
121215908c36SMarc Boucher 		break;
121315908c36SMarc Boucher 
1214c9b443d4STobin Davis #endif
1215c9b443d4STobin Davis 	}
121648ecb7e8STakashi Iwai 
1217031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1218031005f7STakashi Iwai 	case 0x103c:
12198f0f5ff6SDaniel T Chen 	case 0x1631:
12200b587fc4SDaniel T Chen 	case 0x1734:
12210ebf9e36SDaniel T Chen 	case 0x17aa:
12220ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12230ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12240ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
122548ecb7e8STakashi Iwai 		 */
122648ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
122748ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
122848ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
122948ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
123048ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1231031005f7STakashi Iwai 		break;
1232031005f7STakashi Iwai 	}
123348ecb7e8STakashi Iwai 
12343507e2a8STakashi Iwai 	if (spec->beep_amp)
12353507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12363507e2a8STakashi Iwai 
1237c9b443d4STobin Davis 	return 0;
1238c9b443d4STobin Davis }
1239c9b443d4STobin Davis 
1240c9b443d4STobin Davis 
1241c9b443d4STobin Davis /* Conexant 5047 specific */
124282f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1243c9b443d4STobin Davis 
124434cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
124534cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
124634cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1247c9b443d4STobin Davis 
124834cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
12495cd57529STobin Davis 	{ 2, NULL },
12505cd57529STobin Davis };
1251c9b443d4STobin Davis 
125234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
125382f30040STobin Davis 	.num_items = 2,
125482f30040STobin Davis 	.items = {
125582f30040STobin Davis 		{ "ExtMic", 0x2 },
125682f30040STobin Davis 		{ "Line-In", 0x1 },
1257c9b443d4STobin Davis 	}
1258c9b443d4STobin Davis };
1259c9b443d4STobin Davis 
1260c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1261c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1262c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1263c9b443d4STobin Davis {
1264c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1265c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
126682f30040STobin Davis 	unsigned int bits;
1267c9b443d4STobin Davis 
126882f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1269c9b443d4STobin Davis 		return 0;
1270c9b443d4STobin Davis 
127182f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
127282f30040STobin Davis 	 * the headphone jack
127382f30040STobin Davis 	 */
127447fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12753b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12763b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12773b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12783b7523fcSTakashi Iwai 	 */
12795d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
128047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
128147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
128247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
128347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1284c9b443d4STobin Davis 	return 1;
1285c9b443d4STobin Davis }
1286c9b443d4STobin Davis 
1287c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1288c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1289c9b443d4STobin Davis {
129082f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1291dd87da1cSTobin Davis 	unsigned int bits;
1292c9b443d4STobin Davis 
1293d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1294dd87da1cSTobin Davis 
129547fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12963b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12975d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
129847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1299c9b443d4STobin Davis }
1300c9b443d4STobin Davis 
1301c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1302c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1303c9b443d4STobin Davis {
130434cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
13059f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13069f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1307c9b443d4STobin Davis 		{}
1308c9b443d4STobin Davis 	};
130934cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
13109f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13119f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1312c9b443d4STobin Davis 		{}
1313c9b443d4STobin Davis 	};
1314c9b443d4STobin Davis 	unsigned int present;
1315c9b443d4STobin Davis 
1316d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1317c9b443d4STobin Davis 	if (present)
1318c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1319c9b443d4STobin Davis 	else
1320c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1321c9b443d4STobin Davis }
1322c9b443d4STobin Davis 
1323c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1324c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1325c9b443d4STobin Davis 				  unsigned int res)
1326c9b443d4STobin Davis {
13279f113e0eSMarc Boucher 	switch (res >> 26) {
1328c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1329c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1330c9b443d4STobin Davis 		break;
1331c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1332c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1333c9b443d4STobin Davis 		break;
1334c9b443d4STobin Davis 	}
1335c9b443d4STobin Davis }
1336c9b443d4STobin Davis 
133734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1338df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1339df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
13405f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1341c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1342c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1343c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1344c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
134582f30040STobin Davis 	{
134682f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
134782f30040STobin Davis 		.name = "Master Playback Switch",
134882f30040STobin Davis 		.info = cxt_eapd_info,
134982f30040STobin Davis 		.get = cxt_eapd_get,
1350c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1351c9b443d4STobin Davis 		.private_value = 0x13,
1352c9b443d4STobin Davis 	},
1353c9b443d4STobin Davis 
1354c9b443d4STobin Davis 	{}
1355c9b443d4STobin Davis };
1356c9b443d4STobin Davis 
135734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13583b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13595d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1360df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1361df481e41STakashi Iwai 	{}
1362df481e41STakashi Iwai };
1363df481e41STakashi Iwai 
136434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1365c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1366c9b443d4STobin Davis 	{ } /* end */
1367c9b443d4STobin Davis };
1368c9b443d4STobin Davis 
136934cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1370c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1371c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1372c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1373c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13747f29673bSTobin Davis 	/* HP, Speaker  */
1375b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13765b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13775b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13787f29673bSTobin Davis 	/* Record selector: Mic */
13797f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13807f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13817f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13827f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1383c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1384c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1385c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1386c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1387c9b443d4STobin Davis 	/* SPDIF route: PCM */
1388c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
138982f30040STobin Davis 	/* Enable unsolicited events */
139082f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
139182f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1392c9b443d4STobin Davis 	{ } /* end */
1393c9b443d4STobin Davis };
1394c9b443d4STobin Davis 
1395c9b443d4STobin Davis /* configuration for Toshiba Laptops */
139634cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13973b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1398c9b443d4STobin Davis 	{}
1399c9b443d4STobin Davis };
1400c9b443d4STobin Davis 
1401c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1402c9b443d4STobin Davis  * configuration.
1403c9b443d4STobin Davis  */
1404c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
140534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
140682f30040STobin Davis 	.num_items = 4,
1407c9b443d4STobin Davis 	.items = {
140882f30040STobin Davis 		{ "LINE1 pin", 0x0 },
140982f30040STobin Davis 		{ "MIC1 pin", 0x1 },
141082f30040STobin Davis 		{ "MIC2 pin", 0x2 },
141182f30040STobin Davis 		{ "CD pin", 0x3 },
1412c9b443d4STobin Davis         },
1413c9b443d4STobin Davis };
1414c9b443d4STobin Davis 
141534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1416c9b443d4STobin Davis 
1417c9b443d4STobin Davis 	/* Output only controls */
141882f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
141982f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
142082f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
142182f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1422c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1423c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1424c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1425c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
142682f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
142782f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
142882f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
142982f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1430c9b443d4STobin Davis 
1431c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1432c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1433c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1434c9b443d4STobin Davis 
143582f30040STobin Davis 	/* EAPD Switch Control */
143682f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
143782f30040STobin Davis 
1438c9b443d4STobin Davis 	/* Loopback mixer controls */
143982f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
144082f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
144182f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
144282f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
144382f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
144482f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
144582f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
144682f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1447c9b443d4STobin Davis 
144882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
144982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
145082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
145182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
145282f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
145382f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
145482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
145582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1456c9b443d4STobin Davis 	{
1457c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1458c9b443d4STobin Davis 		.name = "Input Source",
1459c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1460c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1461c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1462c9b443d4STobin Davis 	},
1463854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14649f113e0eSMarc Boucher 
1465c9b443d4STobin Davis 	{ } /* end */
1466c9b443d4STobin Davis };
1467c9b443d4STobin Davis 
146834cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1469c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1470c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1471c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1472c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1473c9b443d4STobin Davis 
1474c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1475c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1476c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1477c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1478c9b443d4STobin Davis 	 * control.
1479c9b443d4STobin Davis 	 */
1480c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1481c9b443d4STobin Davis 
1482c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1483c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1484c9b443d4STobin Davis 	 */
1485c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1486c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1487c9b443d4STobin Davis 
1488c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1489c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1490c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1491c9b443d4STobin Davis 
1492c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1493c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1494c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1495c9b443d4STobin Davis 	 * input/output buffers as needed.
1496c9b443d4STobin Davis 	 */
1497c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1498c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1499c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1500c9b443d4STobin Davis 
1501c9b443d4STobin Davis 	/* Mute capture amp left and right */
1502c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1503c9b443d4STobin Davis 
1504c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1505c9b443d4STobin Davis 	 * pin)
1506c9b443d4STobin Davis 	 */
1507c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1508c9b443d4STobin Davis 
1509c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1510c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1511c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1512c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1513c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1514c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1515c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1516c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1517c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1518c9b443d4STobin Davis 
1519c9b443d4STobin Davis 	{ }
1520c9b443d4STobin Davis };
1521c9b443d4STobin Davis #endif
1522c9b443d4STobin Davis 
1523c9b443d4STobin Davis 
1524c9b443d4STobin Davis /* initialize jack-sensing, too */
1525c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1526c9b443d4STobin Davis {
1527c9b443d4STobin Davis 	conexant_init(codec);
1528c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1529c9b443d4STobin Davis 	return 0;
1530c9b443d4STobin Davis }
1531c9b443d4STobin Davis 
1532c9b443d4STobin Davis 
1533c9b443d4STobin Davis enum {
1534f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1535f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1536f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1537c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1538c9b443d4STobin Davis 	CXT5047_TEST,
1539c9b443d4STobin Davis #endif
1540fa5dadcbSTakashi Iwai 	CXT5047_AUTO,
1541f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1542c9b443d4STobin Davis };
1543c9b443d4STobin Davis 
1544ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1545f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1546f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1547f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1548c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1549f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1550c9b443d4STobin Davis #endif
1551fa5dadcbSTakashi Iwai 	[CXT5047_AUTO]		= "auto",
1552f5fcc13cSTakashi Iwai };
1553c9b443d4STobin Davis 
155434cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1555ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1556dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1557dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1558f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1559c9b443d4STobin Davis 	{}
1560c9b443d4STobin Davis };
1561c9b443d4STobin Davis 
1562c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1563c9b443d4STobin Davis {
1564c9b443d4STobin Davis 	struct conexant_spec *spec;
1565c9b443d4STobin Davis 	int board_config;
1566c9b443d4STobin Davis 
1567fa5dadcbSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1568fa5dadcbSTakashi Iwai 						  cxt5047_models,
1569fa5dadcbSTakashi Iwai 						  cxt5047_cfg_tbl);
1570fa5dadcbSTakashi Iwai 	if (board_config < 0)
1571c82693dbSTakashi Iwai 		board_config = CXT5047_AUTO; /* model=auto as default */
1572fa5dadcbSTakashi Iwai 	if (board_config == CXT5047_AUTO)
1573fa5dadcbSTakashi Iwai 		return patch_conexant_auto(codec);
1574fa5dadcbSTakashi Iwai 
1575c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1576c9b443d4STobin Davis 	if (!spec)
1577c9b443d4STobin Davis 		return -ENOMEM;
1578c9b443d4STobin Davis 	codec->spec = spec;
15799421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1580c9b443d4STobin Davis 
1581c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1582c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1583c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1584c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1585c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1586c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1587c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1588c9b443d4STobin Davis 	spec->num_mixers = 1;
1589df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1590c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1591c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1592c9b443d4STobin Davis 	spec->spdif_route = 0;
15935cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15945cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1595c9b443d4STobin Davis 
1596c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1597c9b443d4STobin Davis 
1598c9b443d4STobin Davis 	switch (board_config) {
1599c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1600df481e41STakashi Iwai 		spec->num_mixers = 2;
1601df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1602df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1603c9b443d4STobin Davis 		break;
1604c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1605df481e41STakashi Iwai 		spec->num_mixers = 2;
1606df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1607fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1608c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1609c9b443d4STobin Davis 		break;
1610c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
161182f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1612df481e41STakashi Iwai 		spec->num_mixers = 2;
1613df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1614c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1615c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1616fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1617c9b443d4STobin Davis 		break;
1618c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1619c9b443d4STobin Davis 	case CXT5047_TEST:
1620c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1621c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1622c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1623fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1624c9b443d4STobin Davis #endif
1625c9b443d4STobin Davis 	}
1626dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1627025f206cSDaniel T Chen 
1628025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1629025f206cSDaniel T Chen 	case 0x103c:
1630025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1631025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1632025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1633025f206cSDaniel T Chen 		 */
1634025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1635025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1636025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1637025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1638025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1639025f206cSDaniel T Chen 		break;
1640025f206cSDaniel T Chen 	}
1641025f206cSDaniel T Chen 
1642c9b443d4STobin Davis 	return 0;
1643c9b443d4STobin Davis }
1644c9b443d4STobin Davis 
1645461e2c78STakashi Iwai /* Conexant 5051 specific */
164634cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
164734cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1648461e2c78STakashi Iwai 
164934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1650461e2c78STakashi Iwai 	{ 2, NULL },
1651461e2c78STakashi Iwai };
1652461e2c78STakashi Iwai 
1653461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1654461e2c78STakashi Iwai {
1655461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1656461e2c78STakashi Iwai 	unsigned int pinctl;
165723d2df5bSTakashi Iwai 	/* headphone pin */
165823d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
165923d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
166023d2df5bSTakashi Iwai 			    pinctl);
166123d2df5bSTakashi Iwai 	/* speaker pin */
1662461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1663461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1664461e2c78STakashi Iwai 			    pinctl);
1665f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1666f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1667f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1668f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1669f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1670461e2c78STakashi Iwai }
1671461e2c78STakashi Iwai 
1672461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1673461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1674461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1675461e2c78STakashi Iwai {
1676461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1677461e2c78STakashi Iwai 
1678461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1679461e2c78STakashi Iwai 		return 0;
1680461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1681461e2c78STakashi Iwai 	return 1;
1682461e2c78STakashi Iwai }
1683461e2c78STakashi Iwai 
1684461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1685461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1686461e2c78STakashi Iwai {
168779d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1688461e2c78STakashi Iwai 	unsigned int present;
1689461e2c78STakashi Iwai 
1690faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
169179d7d533STakashi Iwai 		return;
1692d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1693461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1694461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1695461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1696461e2c78STakashi Iwai }
1697461e2c78STakashi Iwai 
1698461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1699461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1700461e2c78STakashi Iwai {
1701461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1702461e2c78STakashi Iwai 	unsigned int present;
1703461e2c78STakashi Iwai 	hda_nid_t new_adc;
1704461e2c78STakashi Iwai 
1705faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
170679d7d533STakashi Iwai 		return;
1707d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1708461e2c78STakashi Iwai 	if (present)
1709461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1710461e2c78STakashi Iwai 	else
1711461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1712461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1713461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1714461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1715f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1716461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1717461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1718461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1719461e2c78STakashi Iwai 					   spec->cur_adc_format);
1720461e2c78STakashi Iwai 	}
1721461e2c78STakashi Iwai }
1722461e2c78STakashi Iwai 
1723461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1724461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1725461e2c78STakashi Iwai {
1726461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1727461e2c78STakashi Iwai 
1728d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1729461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1730461e2c78STakashi Iwai }
1731461e2c78STakashi Iwai 
1732461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1733461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1734461e2c78STakashi Iwai 				   unsigned int res)
1735461e2c78STakashi Iwai {
1736acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1737461e2c78STakashi Iwai 	switch (res >> 26) {
1738461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1739461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1740461e2c78STakashi Iwai 		break;
1741461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1742461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1743461e2c78STakashi Iwai 		break;
1744461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1745461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1746461e2c78STakashi Iwai 		break;
1747461e2c78STakashi Iwai 	}
1748cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
1749461e2c78STakashi Iwai }
1750461e2c78STakashi Iwai 
175134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1752461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1753461e2c78STakashi Iwai 	{
1754461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1755461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1756461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1757461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1758461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1759461e2c78STakashi Iwai 		.private_value = 0x1a,
1760461e2c78STakashi Iwai 	},
17612c7a3fb3STakashi Iwai 	{}
17622c7a3fb3STakashi Iwai };
1763461e2c78STakashi Iwai 
176434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17652c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17662c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17678607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17688607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
17692c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17702c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1771461e2c78STakashi Iwai 	{}
1772461e2c78STakashi Iwai };
1773461e2c78STakashi Iwai 
177434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1775461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1776461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17778607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
17788607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1779461e2c78STakashi Iwai 	{}
1780461e2c78STakashi Iwai };
1781461e2c78STakashi Iwai 
178234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
17834e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
17844e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
178579d7d533STakashi Iwai 	{}
178679d7d533STakashi Iwai };
178779d7d533STakashi Iwai 
178834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
17895f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
17905f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1791cd9d95a5SKen Prox 	{}
1792cd9d95a5SKen Prox };
1793cd9d95a5SKen Prox 
179434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1795faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1796faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17978607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17988607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1799faddaa5dSTakashi Iwai 	{}
1800faddaa5dSTakashi Iwai };
1801faddaa5dSTakashi Iwai 
180234cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1803461e2c78STakashi Iwai 	/* Line in, Mic */
1804461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1805461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1806461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1807461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1808461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1809461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1810461e2c78STakashi Iwai 	/* SPK  */
1811461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1812461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1813461e2c78STakashi Iwai 	/* HP, Amp  */
1814461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1815461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1816461e2c78STakashi Iwai 	/* DAC1 */
1817461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
181828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1819461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1820461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1821461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1822461e2c78STakashi Iwai 	/* SPDIF route: PCM */
18231965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1824461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1825461e2c78STakashi Iwai 	/* EAPD */
1826461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1827461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1828461e2c78STakashi Iwai 	{ } /* end */
1829461e2c78STakashi Iwai };
1830461e2c78STakashi Iwai 
183134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
183279d7d533STakashi Iwai 	/* Line in, Mic */
183379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
183479d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
183579d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
183679d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
183779d7d533STakashi Iwai 	/* SPK  */
183879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
183979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
184079d7d533STakashi Iwai 	/* HP, Amp  */
184179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
184279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
184379d7d533STakashi Iwai 	/* DAC1 */
184479d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
184528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
184679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
184779d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
184879d7d533STakashi Iwai 	/* SPDIF route: PCM */
184979d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
185079d7d533STakashi Iwai 	/* EAPD */
185179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
185279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
185379d7d533STakashi Iwai 	{ } /* end */
185479d7d533STakashi Iwai };
185579d7d533STakashi Iwai 
185634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
185727e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
185827e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185927e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
186027e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
186127e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
186227e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
186327e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
186427e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
186527e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
186627e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
186727e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
186827e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186927e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
187027e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
187127e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
187227e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
187327e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
187427e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
187528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
187627e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
187727e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
187827e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
187927e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
18801965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
188127e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
188227e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
188327e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
188427e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
188527e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
188627e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
188727e08988SAristeu Sergio Rozanski Filho };
188827e08988SAristeu Sergio Rozanski Filho 
188934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1890cd9d95a5SKen Prox 	/* Line in, Mic */
189130ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1892cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1893cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1894cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1895cd9d95a5SKen Prox 	/* SPK  */
1896cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1897cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1898cd9d95a5SKen Prox 	/* HP, Amp  */
1899cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1900cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1901cd9d95a5SKen Prox 	/* DAC1 */
1902cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
190328c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1904cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1905cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1906cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1907cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1908cd9d95a5SKen Prox 	/* EAPD */
1909cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1910cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1911cd9d95a5SKen Prox 	{ } /* end */
1912cd9d95a5SKen Prox };
1913cd9d95a5SKen Prox 
19146953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
19156953e552STakashi Iwai 				 unsigned int event)
19166953e552STakashi Iwai {
19176953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
19186953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
19196953e552STakashi Iwai 			    AC_USRSP_EN | event);
1920cd372fb3STakashi Iwai 	snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1921cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
19226953e552STakashi Iwai }
19236953e552STakashi Iwai 
192434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1925f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1926f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1927f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1928f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1929f7154de2SHerton Ronaldo Krzesinski };
1930f7154de2SHerton Ronaldo Krzesinski 
1931461e2c78STakashi Iwai /* initialize jack-sensing, too */
1932461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1933461e2c78STakashi Iwai {
19346953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19356953e552STakashi Iwai 
1936461e2c78STakashi Iwai 	conexant_init(codec);
1937acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19386953e552STakashi Iwai 
19396953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19406953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19416953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19426953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19436953e552STakashi Iwai 
1944461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1945461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1946461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1947461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1948461e2c78STakashi Iwai 	}
1949461e2c78STakashi Iwai 	return 0;
1950461e2c78STakashi Iwai }
1951461e2c78STakashi Iwai 
1952461e2c78STakashi Iwai 
1953461e2c78STakashi Iwai enum {
1954461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1955461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
195679d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19571965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1958cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1959faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1960f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
19616764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1962461e2c78STakashi Iwai 	CXT5051_MODELS
1963461e2c78STakashi Iwai };
1964461e2c78STakashi Iwai 
1965ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1966461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1967461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
196879d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
196927e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19705f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1971faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1972f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
19736764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1974461e2c78STakashi Iwai };
1975461e2c78STakashi Iwai 
197634cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
197779d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19781812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
19795f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1980faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1981461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1982461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1983461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
198427e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1985f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1986461e2c78STakashi Iwai 	{}
1987461e2c78STakashi Iwai };
1988461e2c78STakashi Iwai 
1989461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1990461e2c78STakashi Iwai {
1991461e2c78STakashi Iwai 	struct conexant_spec *spec;
1992461e2c78STakashi Iwai 	int board_config;
1993461e2c78STakashi Iwai 
19946764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
19956764bcefSTakashi Iwai 						  cxt5051_models,
19966764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
19976764bcefSTakashi Iwai 	if (board_config < 0)
1998c82693dbSTakashi Iwai 		board_config = CXT5051_AUTO; /* model=auto as default */
19991f8458a2STakashi Iwai 	if (board_config == CXT5051_AUTO)
20006764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
20016764bcefSTakashi Iwai 
2002461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2003461e2c78STakashi Iwai 	if (!spec)
2004461e2c78STakashi Iwai 		return -ENOMEM;
2005461e2c78STakashi Iwai 	codec->spec = spec;
20069421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
2007461e2c78STakashi Iwai 
2008461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
2009461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
2010461e2c78STakashi Iwai 
2011461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
2012461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2013461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
2014461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2015461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2016461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
20172c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
20182c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
20192c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
2020461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
2021461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
2022461e2c78STakashi Iwai 	spec->spdif_route = 0;
2023461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2024461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
2025461e2c78STakashi Iwai 	spec->cur_adc = 0;
2026461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
2027461e2c78STakashi Iwai 
20283507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
20293507e2a8STakashi Iwai 
203079d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
203179d7d533STakashi Iwai 
2032faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2033461e2c78STakashi Iwai 	switch (board_config) {
2034461e2c78STakashi Iwai 	case CXT5051_HP:
2035461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
2036461e2c78STakashi Iwai 		break;
203779d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
203879d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
203979d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2040faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
204179d7d533STakashi Iwai 		break;
204227e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
204327e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2044607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2045607bc3e4SJerone Young 		   to use a docking station. */
2046607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2047607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2048461e2c78STakashi Iwai 		break;
2049cd9d95a5SKen Prox 	case CXT5051_F700:
2050cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2051cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2052faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2053faddaa5dSTakashi Iwai 		break;
2054faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2055faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2056faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2057cd9d95a5SKen Prox 		break;
2058f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2059f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2060f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2061f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2062f7154de2SHerton Ronaldo Krzesinski 		break;
2063461e2c78STakashi Iwai 	}
2064461e2c78STakashi Iwai 
20653507e2a8STakashi Iwai 	if (spec->beep_amp)
20663507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20673507e2a8STakashi Iwai 
2068461e2c78STakashi Iwai 	return 0;
2069461e2c78STakashi Iwai }
2070461e2c78STakashi Iwai 
20710fb67e98SDaniel Drake /* Conexant 5066 specific */
20720fb67e98SDaniel Drake 
207334cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
207434cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
207534cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
207634cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
20770fb67e98SDaniel Drake 
2078dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2079dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2080dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2081dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2082dbaccc0cSDaniel Drake 
208334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
20840fb67e98SDaniel Drake 	{ 2, NULL },
20850fb67e98SDaniel Drake };
20860fb67e98SDaniel Drake 
2087a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2088a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2089a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2090a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2091a3de8ab8STakashi Iwai 
20920fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
20930fb67e98SDaniel Drake {
20940fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20950fb67e98SDaniel Drake 	unsigned int pinctl;
20960fb67e98SDaniel Drake 
20973a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
20983a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
20990fb67e98SDaniel Drake 
21000fb67e98SDaniel Drake 	/* Port A (HP) */
2101a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
21020fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21030fb67e98SDaniel Drake 			pinctl);
21040fb67e98SDaniel Drake 
21050fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2106a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2107a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2108a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2109a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
21103a253445SJohn Baboval 			pinctl = 0;
21113a253445SJohn Baboval 	} else {
2112a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2113a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2114a3de8ab8STakashi Iwai 			pinctl = 0;
21153a253445SJohn Baboval 	}
21160fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21170fb67e98SDaniel Drake 			pinctl);
21180fb67e98SDaniel Drake 
21190fb67e98SDaniel Drake 	/* CLASS_D AMP */
21200fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
21210fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21220fb67e98SDaniel Drake 			pinctl);
21230fb67e98SDaniel Drake }
21240fb67e98SDaniel Drake 
21250fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
21260fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
21270fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
21280fb67e98SDaniel Drake {
21290fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21300fb67e98SDaniel Drake 
21310fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
21320fb67e98SDaniel Drake 		return 0;
21330fb67e98SDaniel Drake 
21340fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21350fb67e98SDaniel Drake 	return 1;
21360fb67e98SDaniel Drake }
21370fb67e98SDaniel Drake 
2138c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2139c4cfe66cSDaniel Drake 	.num_items = 3,
2140c4cfe66cSDaniel Drake 	.items = {
2141c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2142c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2143c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2144c4cfe66cSDaniel Drake 	},
2145c4cfe66cSDaniel Drake };
2146c4cfe66cSDaniel Drake 
2147c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2148c4cfe66cSDaniel Drake {
2149c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2150c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2151c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2152c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2153c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2154c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2155c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2156c4cfe66cSDaniel Drake }
2157c4cfe66cSDaniel Drake 
215875f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
215975f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
216075f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
216175f8991dSDaniel Drake  * is happening when it is not. */
216275f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21630fb67e98SDaniel Drake {
2164dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
216575f8991dSDaniel Drake 	if (!spec->recording)
216675f8991dSDaniel Drake 		return;
21670fb67e98SDaniel Drake 
2168c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2169c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2170c4cfe66cSDaniel Drake 		 * through our special DC port */
2171c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2172c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2173c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2174c4cfe66cSDaniel Drake 
2175c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2176c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2177c4cfe66cSDaniel Drake 			{},
2178c4cfe66cSDaniel Drake 		};
2179c4cfe66cSDaniel Drake 
2180c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2181c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2182c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2183c4cfe66cSDaniel Drake 		return;
2184c4cfe66cSDaniel Drake 	}
2185c4cfe66cSDaniel Drake 
2186c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2187c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2188c4cfe66cSDaniel Drake 
218975f8991dSDaniel Drake 	/* external mic, port B */
219075f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
219175f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
21920fb67e98SDaniel Drake 
219375f8991dSDaniel Drake 	/* internal mic, port C */
219475f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
219575f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
219675f8991dSDaniel Drake }
21970fb67e98SDaniel Drake 
219875f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
219975f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
220075f8991dSDaniel Drake {
220175f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22020fb67e98SDaniel Drake 	unsigned int present;
22030fb67e98SDaniel Drake 
2204c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2205c4cfe66cSDaniel Drake 		return;
2206c4cfe66cSDaniel Drake 
220775f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
220875f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
220975f8991dSDaniel Drake 	if (present)
22100fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
221175f8991dSDaniel Drake 	else
22120fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
221375f8991dSDaniel Drake 
221475f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
221575f8991dSDaniel Drake 		present ? 0 : 1);
221675f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
221775f8991dSDaniel Drake 
221875f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
22190fb67e98SDaniel Drake }
22200fb67e98SDaniel Drake 
222195a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
222295a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
222395a618bdSEinar Rünkaru {
222495a618bdSEinar Rünkaru 	unsigned int present;
222595a618bdSEinar Rünkaru 
222695a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
222795a618bdSEinar Rünkaru 		/* enable external mic, port B */
222875f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
222995a618bdSEinar Rünkaru 
223095a618bdSEinar Rünkaru 		/* switch to external mic input */
223195a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
223295a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
223395a618bdSEinar Rünkaru 
223495a618bdSEinar Rünkaru 		/* disable internal digital mic */
223595a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
223695a618bdSEinar Rünkaru 		{}
223795a618bdSEinar Rünkaru 	};
223834cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
223995a618bdSEinar Rünkaru 		/* enable internal mic, port C */
224095a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
224195a618bdSEinar Rünkaru 
224295a618bdSEinar Rünkaru 		/* switch to internal mic input */
224395a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
224495a618bdSEinar Rünkaru 
224595a618bdSEinar Rünkaru 		/* disable external mic, port B */
224695a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
224795a618bdSEinar Rünkaru 		{}
224895a618bdSEinar Rünkaru 	};
224995a618bdSEinar Rünkaru 
225095a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
225195a618bdSEinar Rünkaru 	if (present) {
225295a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
225395a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
225495a618bdSEinar Rünkaru 	} else {
225595a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
225695a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
225795a618bdSEinar Rünkaru 	}
225895a618bdSEinar Rünkaru }
225995a618bdSEinar Rünkaru 
2260cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2261cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2262cfd3d8dcSGreg Alexander {
2263cfd3d8dcSGreg Alexander 	unsigned int present;
2264cfd3d8dcSGreg Alexander 
2265cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2266cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2267cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2268cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2269cfd3d8dcSGreg Alexander 		{}
2270cfd3d8dcSGreg Alexander 	};
227134cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2272cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2273cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2274cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2275cfd3d8dcSGreg Alexander 		{}
2276cfd3d8dcSGreg Alexander 	};
2277cfd3d8dcSGreg Alexander 
2278cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2279cfd3d8dcSGreg Alexander 	if (present) {
2280cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2281cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2282cfd3d8dcSGreg Alexander 	} else {
2283cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2284cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2285cfd3d8dcSGreg Alexander 	}
2286cfd3d8dcSGreg Alexander }
2287cfd3d8dcSGreg Alexander 
2288a1d6906eSDavid Henningsson 
2289a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2290a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2291a1d6906eSDavid Henningsson {
2292a1d6906eSDavid Henningsson 	unsigned int present;
2293a1d6906eSDavid Henningsson 
2294a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2295a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2296a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2297a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2298a1d6906eSDavid Henningsson }
2299a1d6906eSDavid Henningsson 
2300a1d6906eSDavid Henningsson 
2301048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2302048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2303048e78a5SDavid Henningsson {
2304048e78a5SDavid Henningsson 	unsigned int present;
2305048e78a5SDavid Henningsson 
2306048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2307048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2308048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2309048e78a5SDavid Henningsson 			    present ? 1 : 3);
2310048e78a5SDavid Henningsson }
2311048e78a5SDavid Henningsson 
2312048e78a5SDavid Henningsson 
23137b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
23147b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
23157b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
23167b2bfdbcSJens Taprogge {
23177b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
23187b2bfdbcSJens Taprogge 
231934cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
23207b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23217b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
23227b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23237b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23247b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23257b2bfdbcSJens Taprogge 		{}
23267b2bfdbcSJens Taprogge 	};
232734cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
23287b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23297b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
23307b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23317b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23327b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23337b2bfdbcSJens Taprogge 		{}
23347b2bfdbcSJens Taprogge 	};
233534cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
23367b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23377b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23387b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23397b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23407b2bfdbcSJens Taprogge 		{}
23417b2bfdbcSJens Taprogge 	};
23427b2bfdbcSJens Taprogge 
23437b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23447b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23457b2bfdbcSJens Taprogge 	if (ext_present) {
23467b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23477b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23487b2bfdbcSJens Taprogge 	} else if (dock_present) {
23497b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23507b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23517b2bfdbcSJens Taprogge 	} else {
23527b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23537b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23547b2bfdbcSJens Taprogge 	}
23557b2bfdbcSJens Taprogge }
23567b2bfdbcSJens Taprogge 
23570fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23580fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23590fb67e98SDaniel Drake {
23600fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23610fb67e98SDaniel Drake 	unsigned int portA, portD;
23620fb67e98SDaniel Drake 
23630fb67e98SDaniel Drake 	/* Port A */
2364d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23650fb67e98SDaniel Drake 
23660fb67e98SDaniel Drake 	/* Port D */
2367d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23680fb67e98SDaniel Drake 
2369a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2370a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
23710fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23720fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23730fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23740fb67e98SDaniel Drake }
23750fb67e98SDaniel Drake 
237602b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
237702b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
237802b6b5b6SDavid Henningsson {
237902b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
238002b6b5b6SDavid Henningsson 
238102b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
238202b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
238302b6b5b6SDavid Henningsson 	else if (spec->ideapad)
238402b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
238502b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
238602b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
238702b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
238802b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2389a1d6906eSDavid Henningsson 	else if (spec->asus)
2390a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
239102b6b5b6SDavid Henningsson }
239202b6b5b6SDavid Henningsson 
23930fb67e98SDaniel Drake /* unsolicited event for jack sensing */
239475f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23950fb67e98SDaniel Drake {
2396c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23970fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23980fb67e98SDaniel Drake 	switch (res >> 26) {
23990fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
24000fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
24010fb67e98SDaniel Drake 		break;
24020fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2403c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2404c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
240575f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
24060fb67e98SDaniel Drake 		break;
24070fb67e98SDaniel Drake 	}
24080fb67e98SDaniel Drake }
24090fb67e98SDaniel Drake 
241095a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
241102b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
241295a618bdSEinar Rünkaru {
241302b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
241495a618bdSEinar Rünkaru 	switch (res >> 26) {
241595a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
241695a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
241795a618bdSEinar Rünkaru 		break;
241895a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
241902b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
242095a618bdSEinar Rünkaru 		break;
242195a618bdSEinar Rünkaru 	}
242295a618bdSEinar Rünkaru }
242395a618bdSEinar Rünkaru 
24247b2bfdbcSJens Taprogge 
24250fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
24260fb67e98SDaniel Drake 	.num_items = 5,
24270fb67e98SDaniel Drake 	.items = {
24280fb67e98SDaniel Drake 		{ "0dB",  0 },
24290fb67e98SDaniel Drake 		{ "10dB", 1 },
24300fb67e98SDaniel Drake 		{ "20dB", 2 },
24310fb67e98SDaniel Drake 		{ "30dB", 3 },
24320fb67e98SDaniel Drake 		{ "40dB", 4 },
24330fb67e98SDaniel Drake 	},
24340fb67e98SDaniel Drake };
24350fb67e98SDaniel Drake 
2436cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2437c4cfe66cSDaniel Drake {
2438c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2439cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2440c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2441c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2442c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24437b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2444cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2445cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2446cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2447cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2448cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2449cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2450cfd3d8dcSGreg Alexander 	}
2451c4cfe66cSDaniel Drake }
2452c4cfe66cSDaniel Drake 
24530fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24540fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24550fb67e98SDaniel Drake {
24560fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24570fb67e98SDaniel Drake }
24580fb67e98SDaniel Drake 
24590fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24600fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24610fb67e98SDaniel Drake {
24620fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2463c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2464c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24650fb67e98SDaniel Drake 	return 0;
24660fb67e98SDaniel Drake }
24670fb67e98SDaniel Drake 
24680fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24690fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24700fb67e98SDaniel Drake {
24710fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2472c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24730fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24740fb67e98SDaniel Drake 	unsigned int idx;
24750fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24760fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24770fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24780fb67e98SDaniel Drake 
2479c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2480c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2481c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2482c4cfe66cSDaniel Drake 	return 1;
2483c4cfe66cSDaniel Drake }
24840fb67e98SDaniel Drake 
2485c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2486c4cfe66cSDaniel Drake {
2487c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2488c4cfe66cSDaniel Drake 		/* disable gain */
2489c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2490c4cfe66cSDaniel Drake 
2491c4cfe66cSDaniel Drake 		/* switch to DC input */
2492c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2493c4cfe66cSDaniel Drake 		{}
2494c4cfe66cSDaniel Drake 	};
2495c4cfe66cSDaniel Drake 
2496c4cfe66cSDaniel Drake 	/* configure as input source */
2497c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2498c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2499c4cfe66cSDaniel Drake }
2500c4cfe66cSDaniel Drake 
2501c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2502c4cfe66cSDaniel Drake {
2503c4cfe66cSDaniel Drake 	/* reconfigure input source */
2504c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2505c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2506c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2507c4cfe66cSDaniel Drake }
2508c4cfe66cSDaniel Drake 
2509c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2510c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2511c4cfe66cSDaniel Drake {
2512c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2513c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2514c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2515c4cfe66cSDaniel Drake 	return 0;
2516c4cfe66cSDaniel Drake }
2517c4cfe66cSDaniel Drake 
2518c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2519c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2520c4cfe66cSDaniel Drake {
2521c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2522c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2523c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2524c4cfe66cSDaniel Drake 
2525c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2526c4cfe66cSDaniel Drake 		return 0;
2527c4cfe66cSDaniel Drake 
2528c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2529c4cfe66cSDaniel Drake 	if (dc_enable)
2530c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2531c4cfe66cSDaniel Drake 	else
2532c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2533c4cfe66cSDaniel Drake 
2534c4cfe66cSDaniel Drake 	return 1;
2535c4cfe66cSDaniel Drake }
2536c4cfe66cSDaniel Drake 
2537c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2538c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2539c4cfe66cSDaniel Drake {
2540c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2541c4cfe66cSDaniel Drake }
2542c4cfe66cSDaniel Drake 
2543c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2544c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2545c4cfe66cSDaniel Drake {
2546c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2547c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2548c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2549c4cfe66cSDaniel Drake 	return 0;
2550c4cfe66cSDaniel Drake }
2551c4cfe66cSDaniel Drake 
2552c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2553c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2554c4cfe66cSDaniel Drake {
2555c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2556c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2557c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2558c4cfe66cSDaniel Drake 	unsigned int idx;
2559c4cfe66cSDaniel Drake 
2560c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2561c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2562c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2563c4cfe66cSDaniel Drake 
2564c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2565c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2566c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25670fb67e98SDaniel Drake 	return 1;
25680fb67e98SDaniel Drake }
25690fb67e98SDaniel Drake 
257075f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
257175f8991dSDaniel Drake {
257275f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
257375f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
257475f8991dSDaniel Drake 	 * recording LED comes on. */
257575f8991dSDaniel Drake 	spec->recording = 1;
257675f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
257775f8991dSDaniel Drake }
257875f8991dSDaniel Drake 
257975f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
258075f8991dSDaniel Drake {
258175f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
258275f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
258375f8991dSDaniel Drake 		/* disable external mic, port B */
258475f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
258575f8991dSDaniel Drake 
258675f8991dSDaniel Drake 		/* disble internal mic, port C */
258775f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2588c4cfe66cSDaniel Drake 
2589c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2590c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
259175f8991dSDaniel Drake 		{},
259275f8991dSDaniel Drake 	};
259375f8991dSDaniel Drake 
259475f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
259575f8991dSDaniel Drake 	spec->recording = 0;
259675f8991dSDaniel Drake }
259775f8991dSDaniel Drake 
2598f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
259934cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2600f6a2491cSAndy Robinson 				    int num_pins)
2601f6a2491cSAndy Robinson {
2602f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2603f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2604f6a2491cSAndy Robinson 	int i;
2605f6a2491cSAndy Robinson 
2606f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2607f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2608f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2609f6a2491cSAndy Robinson 			continue;
2610f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2611f6a2491cSAndy Robinson 			continue;
2612f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
2613f6a2491cSAndy Robinson 			nid_loc++;
2614f6a2491cSAndy Robinson 		else
2615f6a2491cSAndy Robinson 			nid_loc = spec->slave_dig_outs;
2616f6a2491cSAndy Robinson 	}
2617f6a2491cSAndy Robinson }
2618f6a2491cSAndy Robinson 
261934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
26200fb67e98SDaniel Drake 	.num_items = 4,
26210fb67e98SDaniel Drake 	.items = {
26220fb67e98SDaniel Drake 		{ "Mic B", 0 },
26230fb67e98SDaniel Drake 		{ "Mic C", 1 },
26240fb67e98SDaniel Drake 		{ "Mic E", 2 },
26250fb67e98SDaniel Drake 		{ "Mic F", 3 },
26260fb67e98SDaniel Drake 	},
26270fb67e98SDaniel Drake };
26280fb67e98SDaniel Drake 
262934cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
26300fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
26310fb67e98SDaniel Drake 	.values = {
26320fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26330fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26340fb67e98SDaniel Drake 		0
26350fb67e98SDaniel Drake 	},
26360fb67e98SDaniel Drake };
26370fb67e98SDaniel Drake 
263834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26390fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26400fb67e98SDaniel Drake 	.values = {
26410fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26420fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26430fb67e98SDaniel Drake 		0
26440fb67e98SDaniel Drake 	},
26450fb67e98SDaniel Drake };
26460fb67e98SDaniel Drake 
264734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
26480fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26490fb67e98SDaniel Drake 	{}
26500fb67e98SDaniel Drake };
26510fb67e98SDaniel Drake 
265234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26530fb67e98SDaniel Drake 	{
26540fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26550fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26560fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26570fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26580fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26595e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26600fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26610fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26620fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26630fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26640fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26650fb67e98SDaniel Drake 		.private_value =
26660fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26670fb67e98SDaniel Drake 	},
26680fb67e98SDaniel Drake 	{}
26690fb67e98SDaniel Drake };
26700fb67e98SDaniel Drake 
267134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2672c4cfe66cSDaniel Drake 	{
2673c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2674c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2675c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2676c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2677c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2678c4cfe66cSDaniel Drake 	},
2679c4cfe66cSDaniel Drake 	{
2680c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2681c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2682c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2683c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2684c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2685c4cfe66cSDaniel Drake 	},
2686c4cfe66cSDaniel Drake 	{}
2687c4cfe66cSDaniel Drake };
2688c4cfe66cSDaniel Drake 
268934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
26900fb67e98SDaniel Drake 	{
26910fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26920fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26930fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26940fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26950fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26960fb67e98SDaniel Drake 		.private_value = 0x1d,
26970fb67e98SDaniel Drake 	},
26980fb67e98SDaniel Drake 
26990fb67e98SDaniel Drake 	{
27000fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2701c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
27020fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
27030fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
27040fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
27050fb67e98SDaniel Drake 	},
27060fb67e98SDaniel Drake 
27070fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
27080fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
27090fb67e98SDaniel Drake 	{}
27100fb67e98SDaniel Drake };
27110fb67e98SDaniel Drake 
271234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2713254bba6aSEinar Rünkaru 	{
2714254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
271528c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2716254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2717254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2718254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2719254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2720254bba6aSEinar Rünkaru 	},
2721254bba6aSEinar Rünkaru 	{}
2722254bba6aSEinar Rünkaru };
2723254bba6aSEinar Rünkaru 
272434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
27250fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
27260fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
27270fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27280fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
27290fb67e98SDaniel Drake 
27300fb67e98SDaniel Drake 	/* Speakers  */
27310fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27320fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27330fb67e98SDaniel Drake 
27340fb67e98SDaniel Drake 	/* HP, Amp  */
27350fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27360fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27370fb67e98SDaniel Drake 
27380fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27390fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27400fb67e98SDaniel Drake 
27410fb67e98SDaniel Drake 	/* DAC1 */
27420fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27430fb67e98SDaniel Drake 
27440fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27450fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27460fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27470fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27480fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27490fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27500fb67e98SDaniel Drake 
27510fb67e98SDaniel Drake 	/* no digital microphone support yet */
27520fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27530fb67e98SDaniel Drake 
27540fb67e98SDaniel Drake 	/* Audio input selector */
27550fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27560fb67e98SDaniel Drake 
27570fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27580fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27590fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27600fb67e98SDaniel Drake 
27610fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27620fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27630fb67e98SDaniel Drake 
27640fb67e98SDaniel Drake 	/* EAPD */
27650fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27660fb67e98SDaniel Drake 
27670fb67e98SDaniel Drake 	/* not handling these yet */
27680fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27690fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27700fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27710fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27720fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27730fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27740fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27750fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27760fb67e98SDaniel Drake 	{ } /* end */
27770fb67e98SDaniel Drake };
27780fb67e98SDaniel Drake 
277934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = {
27800fb67e98SDaniel Drake 	/* Port A: headphones */
27810fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27820fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27830fb67e98SDaniel Drake 
27840fb67e98SDaniel Drake 	/* Port B: external microphone */
278575f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27860fb67e98SDaniel Drake 
27870fb67e98SDaniel Drake 	/* Port C: internal microphone */
278875f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27890fb67e98SDaniel Drake 
27900fb67e98SDaniel Drake 	/* Port D: unused */
27910fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27920fb67e98SDaniel Drake 
27930fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27940fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27950fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27960fb67e98SDaniel Drake 
2797c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27980fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27990fb67e98SDaniel Drake 
28000fb67e98SDaniel Drake 	/* Port G: internal speakers */
28010fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28020fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28030fb67e98SDaniel Drake 
28040fb67e98SDaniel Drake 	/* DAC1 */
28050fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28060fb67e98SDaniel Drake 
28070fb67e98SDaniel Drake 	/* DAC2: unused */
28080fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
28090fb67e98SDaniel Drake 
28100fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28110fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28120fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28130fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28140fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28150fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28160fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28170fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28180fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
28190fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28200fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
28210fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28220fb67e98SDaniel Drake 
28230fb67e98SDaniel Drake 	/* Disable digital microphone port */
28240fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28250fb67e98SDaniel Drake 
28260fb67e98SDaniel Drake 	/* Audio input selectors */
28270fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
28280fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
28290fb67e98SDaniel Drake 
28300fb67e98SDaniel Drake 	/* Disable SPDIF */
28310fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28320fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28330fb67e98SDaniel Drake 
28340fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
28350fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28360fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28370fb67e98SDaniel Drake 	{ } /* end */
28380fb67e98SDaniel Drake };
28390fb67e98SDaniel Drake 
284034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
284195a618bdSEinar Rünkaru 	/* Port A: headphones */
284295a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284395a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
284495a618bdSEinar Rünkaru 
284595a618bdSEinar Rünkaru 	/* Port B: external microphone */
284695a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
284795a618bdSEinar Rünkaru 
284895a618bdSEinar Rünkaru 	/* Port C: unused */
284995a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285095a618bdSEinar Rünkaru 
285195a618bdSEinar Rünkaru 	/* Port D: unused */
285295a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285395a618bdSEinar Rünkaru 
285495a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
285595a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285695a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
285795a618bdSEinar Rünkaru 
285895a618bdSEinar Rünkaru 	/* Port F: unused */
285995a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
286095a618bdSEinar Rünkaru 
286195a618bdSEinar Rünkaru 	/* Port G: internal speakers */
286295a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
286395a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
286495a618bdSEinar Rünkaru 
286595a618bdSEinar Rünkaru 	/* DAC1 */
286695a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
286795a618bdSEinar Rünkaru 
286895a618bdSEinar Rünkaru 	/* DAC2: unused */
286995a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
287095a618bdSEinar Rünkaru 
287195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
287395a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287495a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
287695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
287795a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
287895a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
287995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
288095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
288195a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
288295a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
288395a618bdSEinar Rünkaru 
288495a618bdSEinar Rünkaru 	/* Digital microphone port */
288595a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
288695a618bdSEinar Rünkaru 
288795a618bdSEinar Rünkaru 	/* Audio input selectors */
288895a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
288995a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
289095a618bdSEinar Rünkaru 
289195a618bdSEinar Rünkaru 	/* Disable SPDIF */
289295a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
289395a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
289495a618bdSEinar Rünkaru 
289595a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
289695a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
289795a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
289895a618bdSEinar Rünkaru 	{ } /* end */
289995a618bdSEinar Rünkaru };
290095a618bdSEinar Rünkaru 
290134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2902cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2903cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2904cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2905cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2906cfd3d8dcSGreg Alexander 
2907cfd3d8dcSGreg Alexander 	/* Speakers  */
2908cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2909cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2910cfd3d8dcSGreg Alexander 
2911cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2912cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2913cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2914cfd3d8dcSGreg Alexander 
2915cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2916cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2917cfd3d8dcSGreg Alexander 
2918cfd3d8dcSGreg Alexander 	/* DAC1 */
2919cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2920cfd3d8dcSGreg Alexander 
2921cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2922cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2923cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2924cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2925cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2926cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2927cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2928cfd3d8dcSGreg Alexander 
2929cfd3d8dcSGreg Alexander 	/* Audio input selector */
2930cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2931cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2932cfd3d8dcSGreg Alexander 
2933cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2934cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2935cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2936cfd3d8dcSGreg Alexander 
2937cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2938cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2939cfd3d8dcSGreg Alexander 
2940cfd3d8dcSGreg Alexander 	/* internal microphone */
294128c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2942cfd3d8dcSGreg Alexander 
2943cfd3d8dcSGreg Alexander 	/* EAPD */
2944cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2945cfd3d8dcSGreg Alexander 
2946cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2947cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2948cfd3d8dcSGreg Alexander 	{ } /* end */
2949cfd3d8dcSGreg Alexander };
2950cfd3d8dcSGreg Alexander 
295134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29527b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29537b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29547b2bfdbcSJens Taprogge 
29557b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29567b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29577b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29587b2bfdbcSJens Taprogge 
29597b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29607b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29617b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29627b2bfdbcSJens Taprogge 
29637b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29647b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29657b2bfdbcSJens Taprogge 
29667b2bfdbcSJens Taprogge 	/* Port C: Mic */
29677b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29687b2bfdbcSJens Taprogge 
29697b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29707b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29717b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29727b2bfdbcSJens Taprogge 
29737b2bfdbcSJens Taprogge 	/* DAC1 */
29747b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29757b2bfdbcSJens Taprogge 
29767b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29777b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29787b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29797b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29807b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29817b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29827b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29837b2bfdbcSJens Taprogge 
29847b2bfdbcSJens Taprogge 	/* Audio input selector */
29857b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29867b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29877b2bfdbcSJens Taprogge 
29887b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29897b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29907b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29917b2bfdbcSJens Taprogge 
29927b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29937b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29947b2bfdbcSJens Taprogge 
29957b2bfdbcSJens Taprogge 	/* internal microphone */
299628c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
29977b2bfdbcSJens Taprogge 
29987b2bfdbcSJens Taprogge 	/* EAPD */
29997b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
30007b2bfdbcSJens Taprogge 
30017b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
30027b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30037b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
30047b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30057b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
30067b2bfdbcSJens Taprogge 	{ } /* end */
30077b2bfdbcSJens Taprogge };
30087b2bfdbcSJens Taprogge 
300934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
30100fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
30110fb67e98SDaniel Drake 	{ } /* end */
30120fb67e98SDaniel Drake };
30130fb67e98SDaniel Drake 
3014048e78a5SDavid Henningsson 
301534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
3016048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
3017048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
3018048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
3019048e78a5SDavid Henningsson 	{ } /* end */
3020048e78a5SDavid Henningsson };
3021048e78a5SDavid Henningsson 
30220fb67e98SDaniel Drake /* initialize jack-sensing, too */
30230fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
30240fb67e98SDaniel Drake {
30250fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
30260fb67e98SDaniel Drake 	conexant_init(codec);
30270fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
30280fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
302902b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
30300fb67e98SDaniel Drake 	}
3031c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
30320fb67e98SDaniel Drake 	return 0;
30330fb67e98SDaniel Drake }
30340fb67e98SDaniel Drake 
303575f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
303675f8991dSDaniel Drake {
3037c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
303875f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
303975f8991dSDaniel Drake 	conexant_init(codec);
304075f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3041c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3042c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
304375f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3044c4cfe66cSDaniel Drake 	} else {
3045c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3046c4cfe66cSDaniel Drake 	}
304775f8991dSDaniel Drake 	return 0;
304875f8991dSDaniel Drake }
304975f8991dSDaniel Drake 
30500fb67e98SDaniel Drake enum {
30510fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30520fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30530fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
30541feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
3055cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30567b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
3057a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3058048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
3059fea4a4f9STakashi Iwai 	CXT5066_AUTO,		/* BIOS auto-parser */
30600fb67e98SDaniel Drake 	CXT5066_MODELS
30610fb67e98SDaniel Drake };
30620fb67e98SDaniel Drake 
3063ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
30640fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30650fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30660fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
30671feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3068cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30697b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3070a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3071048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
3072fea4a4f9STakashi Iwai 	[CXT5066_AUTO]		= "auto",
30730fb67e98SDaniel Drake };
30740fb67e98SDaniel Drake 
307534cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
30769966db22SDavid Henningsson 	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
307700cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
30781feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
30798a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3080ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
30811feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3082231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3083ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3084ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3085048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3086f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3087a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3088f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
30892ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3090c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30914442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30925637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30935637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
30945637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
30954d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3096ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
309719593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
30987b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
309984012657SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3100b2cb1292SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3101d2859fd4SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
3102a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
3103af4ccf4fSTakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
310422f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
31057ab1fc0aSDaniel T Chen 	SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
31060fb67e98SDaniel Drake 	{}
31070fb67e98SDaniel Drake };
31080fb67e98SDaniel Drake 
31090fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
31100fb67e98SDaniel Drake {
31110fb67e98SDaniel Drake 	struct conexant_spec *spec;
31120fb67e98SDaniel Drake 	int board_config;
31130fb67e98SDaniel Drake 
3114fea4a4f9STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
3115fea4a4f9STakashi Iwai 						  cxt5066_models, cxt5066_cfg_tbl);
3116fea4a4f9STakashi Iwai 	if (board_config < 0)
3117c82693dbSTakashi Iwai 		board_config = CXT5066_AUTO; /* model=auto as default */
3118fea4a4f9STakashi Iwai 	if (board_config == CXT5066_AUTO)
3119fea4a4f9STakashi Iwai 		return patch_conexant_auto(codec);
3120fea4a4f9STakashi Iwai 
31210fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
31220fb67e98SDaniel Drake 	if (!spec)
31230fb67e98SDaniel Drake 		return -ENOMEM;
31240fb67e98SDaniel Drake 	codec->spec = spec;
31250fb67e98SDaniel Drake 
31260fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
312775f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
31280fb67e98SDaniel Drake 
31290fb67e98SDaniel Drake 	spec->dell_automute = 0;
31300fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
31310fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
31320fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
3133f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3134f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
31350fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
31360fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
31370fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
31380fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
31390fb67e98SDaniel Drake 
31400fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
31410fb67e98SDaniel Drake 
31420fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
31430fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
31440fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
31450fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
31460fb67e98SDaniel Drake 	spec->cur_adc = 0;
31470fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
31480fb67e98SDaniel Drake 
31493507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31503507e2a8STakashi Iwai 
31510fb67e98SDaniel Drake 	switch (board_config) {
31520fb67e98SDaniel Drake 	default:
31530fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31540fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31550fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31560fb67e98SDaniel Drake 		break;
31570fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31580fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31590fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31600fb67e98SDaniel Drake 
31610fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31620fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31630fb67e98SDaniel Drake 		spec->num_init_verbs++;
31640fb67e98SDaniel Drake 		spec->dell_automute = 1;
31650fb67e98SDaniel Drake 		break;
3166a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3167048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3168048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
316902b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3170048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3171048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3172048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3173a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3174a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3175048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3176048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3177048e78a5SDavid Henningsson 		/* no S/PDIF out */
3178f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3179048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3180048e78a5SDavid Henningsson 		/* input source automatically selected */
3181048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3182048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3183048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3184048e78a5SDavid Henningsson 		break;
3185048e78a5SDavid Henningsson 
31860fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
318775f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
318875f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31890fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31900fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3191c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31920fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31930fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3194c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31950fb67e98SDaniel Drake 
31960fb67e98SDaniel Drake 		/* no S/PDIF out */
31970fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31980fb67e98SDaniel Drake 
31990fb67e98SDaniel Drake 		/* input source automatically selected */
32000fb67e98SDaniel Drake 		spec->input_mux = NULL;
320175f8991dSDaniel Drake 
320275f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
320375f8991dSDaniel Drake 		 * at the right time */
320475f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
320575f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
32060fb67e98SDaniel Drake 		break;
32071feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
320875f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
320902b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
321095a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
321195a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
321295a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3213254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
321495a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3215254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3216c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
321795a618bdSEinar Rünkaru 
321895a618bdSEinar Rünkaru 		/* no S/PDIF out */
321995a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
322095a618bdSEinar Rünkaru 
322195a618bdSEinar Rünkaru 		/* input source automatically selected */
322295a618bdSEinar Rünkaru 		spec->input_mux = NULL;
322395a618bdSEinar Rünkaru 		break;
3224cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3225cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
322602b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3227cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3228cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3229cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3230cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3231cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3232cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3233cfd3d8dcSGreg Alexander 
3234cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3235cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3236cfd3d8dcSGreg Alexander 
3237cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3238cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3239cfd3d8dcSGreg Alexander 		break;
32407b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
32417b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
324202b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
32437b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
32447b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
32457b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
32467b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
32477b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
32487b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
32497b2bfdbcSJens Taprogge 
32507b2bfdbcSJens Taprogge 		/* no S/PDIF out */
32517b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
32527b2bfdbcSJens Taprogge 
32537b2bfdbcSJens Taprogge 		/* input source automatically selected */
32547b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
32557b2bfdbcSJens Taprogge 		break;
32560fb67e98SDaniel Drake 	}
32570fb67e98SDaniel Drake 
32583507e2a8STakashi Iwai 	if (spec->beep_amp)
32593507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
32603507e2a8STakashi Iwai 
32610fb67e98SDaniel Drake 	return 0;
32620fb67e98SDaniel Drake }
3263461e2c78STakashi Iwai 
3264461e2c78STakashi Iwai /*
3265f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3266f2e5731dSTakashi Iwai  */
3267f2e5731dSTakashi Iwai 
32686764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
32696764bcefSTakashi Iwai 				       struct hda_codec *codec,
32706764bcefSTakashi Iwai 				       unsigned int stream_tag,
32716764bcefSTakashi Iwai 				       unsigned int format,
32726764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
32736764bcefSTakashi Iwai {
32746764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
327547ad1f4eSTakashi Iwai 	hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
32766764bcefSTakashi Iwai 	if (spec->adc_switching) {
32776764bcefSTakashi Iwai 		spec->cur_adc = adc;
32786764bcefSTakashi Iwai 		spec->cur_adc_stream_tag = stream_tag;
32796764bcefSTakashi Iwai 		spec->cur_adc_format = format;
32806764bcefSTakashi Iwai 	}
32816764bcefSTakashi Iwai 	snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
32826764bcefSTakashi Iwai 	return 0;
32836764bcefSTakashi Iwai }
32846764bcefSTakashi Iwai 
32856764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
32866764bcefSTakashi Iwai 				       struct hda_codec *codec,
32876764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
32886764bcefSTakashi Iwai {
32896764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
32906764bcefSTakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
32916764bcefSTakashi Iwai 	spec->cur_adc = 0;
32926764bcefSTakashi Iwai 	return 0;
32936764bcefSTakashi Iwai }
32946764bcefSTakashi Iwai 
32956764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
32966764bcefSTakashi Iwai 	.substreams = 1,
32976764bcefSTakashi Iwai 	.channels_min = 2,
32986764bcefSTakashi Iwai 	.channels_max = 2,
32996764bcefSTakashi Iwai 	.nid = 0, /* fill later */
33006764bcefSTakashi Iwai 	.ops = {
33016764bcefSTakashi Iwai 		.prepare = cx_auto_capture_pcm_prepare,
33026764bcefSTakashi Iwai 		.cleanup = cx_auto_capture_pcm_cleanup
33036764bcefSTakashi Iwai 	},
33046764bcefSTakashi Iwai };
33056764bcefSTakashi Iwai 
330634cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3307f2e5731dSTakashi Iwai 
33088d087c76STakashi Iwai #define get_connection_index(codec, mux, nid)\
33098d087c76STakashi Iwai 	snd_hda_get_conn_index(codec, mux, nid, 0)
3310f2e5731dSTakashi Iwai 
3311f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3312f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3313f2e5731dSTakashi Iwai  * not found
3314f2e5731dSTakashi Iwai  */
3315f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3316f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3317f2e5731dSTakashi Iwai {
3318f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3319f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3320f2e5731dSTakashi Iwai 
3321f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3322f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3323f2e5731dSTakashi Iwai 			ret = dacs[i];
3324f2e5731dSTakashi Iwai 			break;
3325f2e5731dSTakashi Iwai 		}
3326f2e5731dSTakashi Iwai 	}
3327f2e5731dSTakashi Iwai 	if (!ret)
3328f2e5731dSTakashi Iwai 		return 0;
3329f2e5731dSTakashi Iwai 	if (--nums > 0)
3330f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3331f2e5731dSTakashi Iwai 	*num_dacs = nums;
3332f2e5731dSTakashi Iwai 	return ret;
3333f2e5731dSTakashi Iwai }
3334f2e5731dSTakashi Iwai 
3335f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3336f2e5731dSTakashi Iwai 
3337f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3338f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3339f2e5731dSTakashi Iwai {
3340f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3341f2e5731dSTakashi Iwai 	int nums = 0;
3342f2e5731dSTakashi Iwai 
3343f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3344f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3345f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3346f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3347f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3348f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3349f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3350f2e5731dSTakashi Iwai 				break;
3351f2e5731dSTakashi Iwai 		}
3352f2e5731dSTakashi Iwai 	}
3353f2e5731dSTakashi Iwai 	return nums;
3354f2e5731dSTakashi Iwai }
3355f2e5731dSTakashi Iwai 
3356f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3357f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3358f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3359f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3360f2e5731dSTakashi Iwai {
3361f2e5731dSTakashi Iwai 	int i, nums;
3362f2e5731dSTakashi Iwai 
3363f2e5731dSTakashi Iwai 	nums = 0;
3364f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3365f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3366f2e5731dSTakashi Iwai 		filled[nums].type = type;
3367f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3368f2e5731dSTakashi Iwai 		nums++;
3369f2e5731dSTakashi Iwai 	}
3370f2e5731dSTakashi Iwai 	return nums;
3371f2e5731dSTakashi Iwai }
3372f2e5731dSTakashi Iwai 
3373f2e5731dSTakashi Iwai /* parse analog output paths */
3374f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3375f2e5731dSTakashi Iwai {
3376f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3377f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3378f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3379f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3380f2e5731dSTakashi Iwai 
3381f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3382f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3383f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3384f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3385f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3386f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3387f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3388f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3389f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3390f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3391f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3392f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3393f2e5731dSTakashi Iwai 	/* fill multiout struct */
3394f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3395f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3396f2e5731dSTakashi Iwai 		if (!dac)
3397f2e5731dSTakashi Iwai 			continue;
3398f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3399f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3400f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3401f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3402f2e5731dSTakashi Iwai 			break;
3403f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3404f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3405f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3406f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3407f2e5731dSTakashi Iwai 				break;
3408f2e5731dSTakashi Iwai 			}
3409f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3410f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3411f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3412f2e5731dSTakashi Iwai 					break;
3413f2e5731dSTakashi Iwai 				}
3414f2e5731dSTakashi Iwai 			break;
3415f2e5731dSTakashi Iwai 		}
3416f2e5731dSTakashi Iwai 	}
3417f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
341889724958SDavid Henningsson 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3419f2e5731dSTakashi Iwai 
342003697e2aSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
342103697e2aSTakashi Iwai 		if (is_jack_detectable(codec, cfg->hp_pins[i])) {
3422f2e5731dSTakashi Iwai 			spec->auto_mute = 1;
342303697e2aSTakashi Iwai 			break;
342403697e2aSTakashi Iwai 		}
342503697e2aSTakashi Iwai 	}
3426e2df82ffSTakashi Iwai 	if (spec->auto_mute &&
3427e2df82ffSTakashi Iwai 	    cfg->line_out_pins[0] &&
3428e2df82ffSTakashi Iwai 	    cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
342903697e2aSTakashi Iwai 	    cfg->line_out_pins[0] != cfg->hp_pins[0] &&
343003697e2aSTakashi Iwai 	    cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
343103697e2aSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++) {
343203697e2aSTakashi Iwai 			if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
343303697e2aSTakashi Iwai 				spec->detect_line = 1;
343403697e2aSTakashi Iwai 				break;
343503697e2aSTakashi Iwai 			}
343603697e2aSTakashi Iwai 		}
343703697e2aSTakashi Iwai 		spec->automute_lines = spec->detect_line;
343803697e2aSTakashi Iwai 	}
343903697e2aSTakashi Iwai 
3440f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3441f2e5731dSTakashi Iwai }
3442f2e5731dSTakashi Iwai 
3443da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3444da339866STakashi Iwai 			      hda_nid_t *pins, bool on);
3445da339866STakashi Iwai 
344603697e2aSTakashi Iwai static void do_automute(struct hda_codec *codec, int num_pins,
344703697e2aSTakashi Iwai 			hda_nid_t *pins, bool on)
344803697e2aSTakashi Iwai {
344903697e2aSTakashi Iwai 	int i;
345003697e2aSTakashi Iwai 	for (i = 0; i < num_pins; i++)
345103697e2aSTakashi Iwai 		snd_hda_codec_write(codec, pins[i], 0,
345203697e2aSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
345303697e2aSTakashi Iwai 				    on ? PIN_OUT : 0);
345403697e2aSTakashi Iwai 	cx_auto_turn_eapd(codec, num_pins, pins, on);
345503697e2aSTakashi Iwai }
345603697e2aSTakashi Iwai 
345703697e2aSTakashi Iwai static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
345803697e2aSTakashi Iwai {
345903697e2aSTakashi Iwai 	int i, present = 0;
346003697e2aSTakashi Iwai 
346103697e2aSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
346203697e2aSTakashi Iwai 		hda_nid_t nid = pins[i];
346303697e2aSTakashi Iwai 		if (!nid || !is_jack_detectable(codec, nid))
346403697e2aSTakashi Iwai 			break;
346503697e2aSTakashi Iwai 		snd_hda_input_jack_report(codec, nid);
346603697e2aSTakashi Iwai 		present |= snd_hda_jack_detect(codec, nid);
346703697e2aSTakashi Iwai 	}
346803697e2aSTakashi Iwai 	return present;
346903697e2aSTakashi Iwai }
347003697e2aSTakashi Iwai 
3471f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
347203697e2aSTakashi Iwai static void cx_auto_update_speakers(struct hda_codec *codec)
347303697e2aSTakashi Iwai {
347403697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
347503697e2aSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3476e2df82ffSTakashi Iwai 	int on = 1;
347703697e2aSTakashi Iwai 
3478e2df82ffSTakashi Iwai 	/* turn on HP EAPD when HP jacks are present */
3479e2df82ffSTakashi Iwai 	if (spec->auto_mute)
3480e2df82ffSTakashi Iwai 		on = spec->hp_present;
348103697e2aSTakashi Iwai 	cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3482e2df82ffSTakashi Iwai 	/* mute speakers in auto-mode if HP or LO jacks are plugged */
3483e2df82ffSTakashi Iwai 	if (spec->auto_mute)
3484e2df82ffSTakashi Iwai 		on = !(spec->hp_present ||
3485e2df82ffSTakashi Iwai 		       (spec->detect_line && spec->line_present));
3486e2df82ffSTakashi Iwai 	do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
348703697e2aSTakashi Iwai 
348803697e2aSTakashi Iwai 	/* toggle line-out mutes if needed, too */
348903697e2aSTakashi Iwai 	/* if LO is a copy of either HP or Speaker, don't need to handle it */
349003697e2aSTakashi Iwai 	if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
349103697e2aSTakashi Iwai 	    cfg->line_out_pins[0] == cfg->speaker_pins[0])
349203697e2aSTakashi Iwai 		return;
3493e2df82ffSTakashi Iwai 	if (spec->auto_mute) {
3494e2df82ffSTakashi Iwai 		/* mute LO in auto-mode when HP jack is present */
3495e2df82ffSTakashi Iwai 		if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
3496e2df82ffSTakashi Iwai 		    spec->automute_lines)
3497e2df82ffSTakashi Iwai 			on = !spec->hp_present;
349803697e2aSTakashi Iwai 		else
3499e2df82ffSTakashi Iwai 			on = 1;
3500e2df82ffSTakashi Iwai 	}
3501e2df82ffSTakashi Iwai 	do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
350203697e2aSTakashi Iwai }
350303697e2aSTakashi Iwai 
3504f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3505f2e5731dSTakashi Iwai {
3506f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3507f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3508f2e5731dSTakashi Iwai 
3509f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3510f2e5731dSTakashi Iwai 		return;
351103697e2aSTakashi Iwai 	spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
351203697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
351303697e2aSTakashi Iwai }
351403697e2aSTakashi Iwai 
351503697e2aSTakashi Iwai static void cx_auto_line_automute(struct hda_codec *codec)
351603697e2aSTakashi Iwai {
351703697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
351803697e2aSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
351903697e2aSTakashi Iwai 
352003697e2aSTakashi Iwai 	if (!spec->auto_mute || !spec->detect_line)
352103697e2aSTakashi Iwai 		return;
352203697e2aSTakashi Iwai 	spec->line_present = detect_jacks(codec, cfg->line_outs,
352303697e2aSTakashi Iwai 					  cfg->line_out_pins);
352403697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
352503697e2aSTakashi Iwai }
352603697e2aSTakashi Iwai 
352703697e2aSTakashi Iwai static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
352803697e2aSTakashi Iwai 				 struct snd_ctl_elem_info *uinfo)
352903697e2aSTakashi Iwai {
353003697e2aSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353103697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
353203697e2aSTakashi Iwai 	static const char * const texts2[] = {
353303697e2aSTakashi Iwai 		"Disabled", "Enabled"
353403697e2aSTakashi Iwai 	};
353503697e2aSTakashi Iwai 	static const char * const texts3[] = {
353603697e2aSTakashi Iwai 		"Disabled", "Speaker Only", "Line-Out+Speaker"
353703697e2aSTakashi Iwai 	};
353803697e2aSTakashi Iwai 	const char * const *texts;
353903697e2aSTakashi Iwai 
354003697e2aSTakashi Iwai 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
354103697e2aSTakashi Iwai 	uinfo->count = 1;
354203697e2aSTakashi Iwai 	if (spec->automute_hp_lo) {
354303697e2aSTakashi Iwai 		uinfo->value.enumerated.items = 3;
354403697e2aSTakashi Iwai 		texts = texts3;
354503697e2aSTakashi Iwai 	} else {
354603697e2aSTakashi Iwai 		uinfo->value.enumerated.items = 2;
354703697e2aSTakashi Iwai 		texts = texts2;
354803697e2aSTakashi Iwai 	}
354903697e2aSTakashi Iwai 	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
355003697e2aSTakashi Iwai 		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
355103697e2aSTakashi Iwai 	strcpy(uinfo->value.enumerated.name,
355203697e2aSTakashi Iwai 	       texts[uinfo->value.enumerated.item]);
355303697e2aSTakashi Iwai 	return 0;
355403697e2aSTakashi Iwai }
355503697e2aSTakashi Iwai 
355603697e2aSTakashi Iwai static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
355703697e2aSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
355803697e2aSTakashi Iwai {
355903697e2aSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
356003697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
356103697e2aSTakashi Iwai 	unsigned int val;
356203697e2aSTakashi Iwai 	if (!spec->auto_mute)
356303697e2aSTakashi Iwai 		val = 0;
356403697e2aSTakashi Iwai 	else if (!spec->automute_lines)
356503697e2aSTakashi Iwai 		val = 1;
356603697e2aSTakashi Iwai 	else
356703697e2aSTakashi Iwai 		val = 2;
356803697e2aSTakashi Iwai 	ucontrol->value.enumerated.item[0] = val;
356903697e2aSTakashi Iwai 	return 0;
357003697e2aSTakashi Iwai }
357103697e2aSTakashi Iwai 
357203697e2aSTakashi Iwai static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
357303697e2aSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
357403697e2aSTakashi Iwai {
357503697e2aSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357603697e2aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
357703697e2aSTakashi Iwai 
357803697e2aSTakashi Iwai 	switch (ucontrol->value.enumerated.item[0]) {
357903697e2aSTakashi Iwai 	case 0:
358003697e2aSTakashi Iwai 		if (!spec->auto_mute)
358103697e2aSTakashi Iwai 			return 0;
358203697e2aSTakashi Iwai 		spec->auto_mute = 0;
3583f2e5731dSTakashi Iwai 		break;
358403697e2aSTakashi Iwai 	case 1:
358503697e2aSTakashi Iwai 		if (spec->auto_mute && !spec->automute_lines)
358603697e2aSTakashi Iwai 			return 0;
358703697e2aSTakashi Iwai 		spec->auto_mute = 1;
358803697e2aSTakashi Iwai 		spec->automute_lines = 0;
358903697e2aSTakashi Iwai 		break;
359003697e2aSTakashi Iwai 	case 2:
359103697e2aSTakashi Iwai 		if (!spec->automute_hp_lo)
359203697e2aSTakashi Iwai 			return -EINVAL;
359303697e2aSTakashi Iwai 		if (spec->auto_mute && spec->automute_lines)
359403697e2aSTakashi Iwai 			return 0;
359503697e2aSTakashi Iwai 		spec->auto_mute = 1;
359603697e2aSTakashi Iwai 		spec->automute_lines = 1;
359703697e2aSTakashi Iwai 		break;
359803697e2aSTakashi Iwai 	default:
359903697e2aSTakashi Iwai 		return -EINVAL;
3600f2e5731dSTakashi Iwai 	}
360103697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
360203697e2aSTakashi Iwai 	return 1;
3603f2e5731dSTakashi Iwai }
360403697e2aSTakashi Iwai 
360503697e2aSTakashi Iwai static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
360603697e2aSTakashi Iwai 	{
360703697e2aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
360803697e2aSTakashi Iwai 		.name = "Auto-Mute Mode",
360903697e2aSTakashi Iwai 		.info = cx_automute_mode_info,
361003697e2aSTakashi Iwai 		.get = cx_automute_mode_get,
361103697e2aSTakashi Iwai 		.put = cx_automute_mode_put,
361203697e2aSTakashi Iwai 	},
361303697e2aSTakashi Iwai 	{ }
361403697e2aSTakashi Iwai };
3615f2e5731dSTakashi Iwai 
36166764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
36176764bcefSTakashi Iwai 				 struct snd_ctl_elem_info *uinfo)
36186764bcefSTakashi Iwai {
36196764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
36206764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
36216764bcefSTakashi Iwai 
36226764bcefSTakashi Iwai 	return snd_hda_input_mux_info(&spec->private_imux, uinfo);
36236764bcefSTakashi Iwai }
36246764bcefSTakashi Iwai 
36256764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
36266764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
36276764bcefSTakashi Iwai {
36286764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
36296764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
36306764bcefSTakashi Iwai 
36316764bcefSTakashi Iwai 	ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
36326764bcefSTakashi Iwai 	return 0;
36336764bcefSTakashi Iwai }
36346764bcefSTakashi Iwai 
36355c9887e0STakashi Iwai /* look for the route the given pin from mux and return the index;
36365c9887e0STakashi Iwai  * if do_select is set, actually select the route.
36375c9887e0STakashi Iwai  */
36385c9887e0STakashi Iwai static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
3639cf27f29aSTakashi Iwai 				     hda_nid_t pin, hda_nid_t *srcp,
3640cf27f29aSTakashi Iwai 				     bool do_select, int depth)
36415c9887e0STakashi Iwai {
36425c9887e0STakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
36435c9887e0STakashi Iwai 	int i, nums;
36445c9887e0STakashi Iwai 
3645cf27f29aSTakashi Iwai 	switch (get_wcaps_type(get_wcaps(codec, mux))) {
3646cf27f29aSTakashi Iwai 	case AC_WID_AUD_IN:
3647cf27f29aSTakashi Iwai 	case AC_WID_AUD_SEL:
3648cf27f29aSTakashi Iwai 	case AC_WID_AUD_MIX:
3649cf27f29aSTakashi Iwai 		break;
3650cf27f29aSTakashi Iwai 	default:
3651cf27f29aSTakashi Iwai 		return -1;
3652cf27f29aSTakashi Iwai 	}
3653cf27f29aSTakashi Iwai 
36545c9887e0STakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
36555c9887e0STakashi Iwai 	for (i = 0; i < nums; i++)
36565c9887e0STakashi Iwai 		if (conn[i] == pin) {
36575c9887e0STakashi Iwai 			if (do_select)
36585c9887e0STakashi Iwai 				snd_hda_codec_write(codec, mux, 0,
36595c9887e0STakashi Iwai 						    AC_VERB_SET_CONNECT_SEL, i);
3660cf27f29aSTakashi Iwai 			if (srcp)
3661cf27f29aSTakashi Iwai 				*srcp = mux;
36625c9887e0STakashi Iwai 			return i;
36635c9887e0STakashi Iwai 		}
36645c9887e0STakashi Iwai 	depth++;
36655c9887e0STakashi Iwai 	if (depth == 2)
36665c9887e0STakashi Iwai 		return -1;
36675c9887e0STakashi Iwai 	for (i = 0; i < nums; i++) {
3668cf27f29aSTakashi Iwai 		int ret  = __select_input_connection(codec, conn[i], pin, srcp,
36695c9887e0STakashi Iwai 						     do_select, depth);
36705c9887e0STakashi Iwai 		if (ret >= 0) {
36715c9887e0STakashi Iwai 			if (do_select)
36725c9887e0STakashi Iwai 				snd_hda_codec_write(codec, mux, 0,
36735c9887e0STakashi Iwai 						    AC_VERB_SET_CONNECT_SEL, i);
3674cf27f29aSTakashi Iwai 			return i;
36755c9887e0STakashi Iwai 		}
36765c9887e0STakashi Iwai 	}
36775c9887e0STakashi Iwai 	return -1;
36785c9887e0STakashi Iwai }
36795c9887e0STakashi Iwai 
36805c9887e0STakashi Iwai static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
36815c9887e0STakashi Iwai 				   hda_nid_t pin)
36825c9887e0STakashi Iwai {
3683cf27f29aSTakashi Iwai 	__select_input_connection(codec, mux, pin, NULL, true, 0);
36845c9887e0STakashi Iwai }
36855c9887e0STakashi Iwai 
36865c9887e0STakashi Iwai static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
36875c9887e0STakashi Iwai 				hda_nid_t pin)
36885c9887e0STakashi Iwai {
3689cf27f29aSTakashi Iwai 	return __select_input_connection(codec, mux, pin, NULL, false, 0);
36905c9887e0STakashi Iwai }
36915c9887e0STakashi Iwai 
36926764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec,
36936764bcefSTakashi Iwai 				   const struct hda_input_mux *imux,
36946764bcefSTakashi Iwai 				   unsigned int idx)
36956764bcefSTakashi Iwai {
36966764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
36976764bcefSTakashi Iwai 	hda_nid_t adc;
3698313d2c06STakashi Iwai 	int changed = 1;
36996764bcefSTakashi Iwai 
37006764bcefSTakashi Iwai 	if (!imux->num_items)
37016764bcefSTakashi Iwai 		return 0;
37026764bcefSTakashi Iwai 	if (idx >= imux->num_items)
37036764bcefSTakashi Iwai 		idx = imux->num_items - 1;
37046764bcefSTakashi Iwai 	if (spec->cur_mux[0] == idx)
3705313d2c06STakashi Iwai 		changed = 0;
370647ad1f4eSTakashi Iwai 	adc = spec->imux_info[idx].adc;
370747ad1f4eSTakashi Iwai 	select_input_connection(codec, spec->imux_info[idx].adc,
370847ad1f4eSTakashi Iwai 				spec->imux_info[idx].pin);
37096764bcefSTakashi Iwai 	if (spec->cur_adc && spec->cur_adc != adc) {
37106764bcefSTakashi Iwai 		/* stream is running, let's swap the current ADC */
37116764bcefSTakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
37126764bcefSTakashi Iwai 		spec->cur_adc = adc;
37136764bcefSTakashi Iwai 		snd_hda_codec_setup_stream(codec, adc,
37146764bcefSTakashi Iwai 					   spec->cur_adc_stream_tag, 0,
37156764bcefSTakashi Iwai 					   spec->cur_adc_format);
37166764bcefSTakashi Iwai 	}
37176764bcefSTakashi Iwai 	spec->cur_mux[0] = idx;
3718313d2c06STakashi Iwai 	return changed;
37196764bcefSTakashi Iwai }
37206764bcefSTakashi Iwai 
37216764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
37226764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
37236764bcefSTakashi Iwai {
37246764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
37256764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
37266764bcefSTakashi Iwai 
37276764bcefSTakashi Iwai 	return cx_auto_mux_enum_update(codec, &spec->private_imux,
37286764bcefSTakashi Iwai 				       ucontrol->value.enumerated.item[0]);
37296764bcefSTakashi Iwai }
37306764bcefSTakashi Iwai 
37316764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
37326764bcefSTakashi Iwai 	{
37336764bcefSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
37346764bcefSTakashi Iwai 		.name = "Capture Source",
37356764bcefSTakashi Iwai 		.info = cx_auto_mux_enum_info,
37366764bcefSTakashi Iwai 		.get = cx_auto_mux_enum_get,
37376764bcefSTakashi Iwai 		.put = cx_auto_mux_enum_put
37386764bcefSTakashi Iwai 	},
37396764bcefSTakashi Iwai 	{}
37406764bcefSTakashi Iwai };
37416764bcefSTakashi Iwai 
374243c1b2e9STakashi Iwai static bool select_automic(struct hda_codec *codec, int idx, bool detect)
374343c1b2e9STakashi Iwai {
374443c1b2e9STakashi Iwai 	struct conexant_spec *spec = codec->spec;
374543c1b2e9STakashi Iwai 	if (idx < 0)
374643c1b2e9STakashi Iwai 		return false;
374743c1b2e9STakashi Iwai 	if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
374843c1b2e9STakashi Iwai 		return false;
374943c1b2e9STakashi Iwai 	cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
375043c1b2e9STakashi Iwai 	return true;
375143c1b2e9STakashi Iwai }
375243c1b2e9STakashi Iwai 
3753f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3754f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3755f2e5731dSTakashi Iwai {
3756f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3757f2e5731dSTakashi Iwai 
3758f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3759f2e5731dSTakashi Iwai 		return;
376043c1b2e9STakashi Iwai 	if (!select_automic(codec, spec->auto_mic_ext, true))
376143c1b2e9STakashi Iwai 		if (!select_automic(codec, spec->auto_mic_dock, true))
376243c1b2e9STakashi Iwai 			select_automic(codec, spec->auto_mic_int, false);
3763f2e5731dSTakashi Iwai }
3764f2e5731dSTakashi Iwai 
3765f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3766f2e5731dSTakashi Iwai {
3767f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3768f2e5731dSTakashi Iwai 	switch (res >> 26) {
3769f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3770f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
377103697e2aSTakashi Iwai 		break;
377203697e2aSTakashi Iwai 	case CONEXANT_LINE_EVENT:
377303697e2aSTakashi Iwai 		cx_auto_line_automute(codec);
3774f2e5731dSTakashi Iwai 		break;
3775f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3776f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3777cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3778f2e5731dSTakashi Iwai 		break;
3779f2e5731dSTakashi Iwai 	}
3780f2e5731dSTakashi Iwai }
3781f2e5731dSTakashi Iwai 
3782f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
378343c1b2e9STakashi Iwai  * auto-mic is enabled only when one int-mic and one ext- and/or
378443c1b2e9STakashi Iwai  * one dock-mic exist
3785f2e5731dSTakashi Iwai  */
3786f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3787f2e5731dSTakashi Iwai {
3788f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
378943c1b2e9STakashi Iwai 	int pset[INPUT_PIN_ATTR_NORMAL + 1];
379043c1b2e9STakashi Iwai 	int i;
3791f2e5731dSTakashi Iwai 
3792506a4196STakashi Iwai 	for (i = 0; i < ARRAY_SIZE(pset); i++)
379343c1b2e9STakashi Iwai 		pset[i] = -1;
379443c1b2e9STakashi Iwai 	for (i = 0; i < spec->private_imux.num_items; i++) {
379543c1b2e9STakashi Iwai 		hda_nid_t pin = spec->imux_info[i].pin;
379643c1b2e9STakashi Iwai 		unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3797b55fcb50STakashi Iwai 		int type, attr;
379843c1b2e9STakashi Iwai 		attr = snd_hda_get_input_pin_attr(def_conf);
379943c1b2e9STakashi Iwai 		if (attr == INPUT_PIN_ATTR_UNUSED)
3800b55fcb50STakashi Iwai 			return; /* invalid entry */
380143c1b2e9STakashi Iwai 		if (attr > INPUT_PIN_ATTR_NORMAL)
380243c1b2e9STakashi Iwai 			attr = INPUT_PIN_ATTR_NORMAL;
380343c1b2e9STakashi Iwai 		if (attr != INPUT_PIN_ATTR_INT &&
380443c1b2e9STakashi Iwai 		    !is_jack_detectable(codec, pin))
3805b55fcb50STakashi Iwai 			return; /* non-detectable pin */
3806b55fcb50STakashi Iwai 		type = get_defcfg_device(def_conf);
3807b55fcb50STakashi Iwai 		if (type != AC_JACK_MIC_IN &&
3808b55fcb50STakashi Iwai 		    (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
3809b55fcb50STakashi Iwai 			return; /* no valid input type */
381043c1b2e9STakashi Iwai 		if (pset[attr] >= 0)
381143c1b2e9STakashi Iwai 			return; /* already occupied */
381243c1b2e9STakashi Iwai 		pset[attr] = i;
3813f2e5731dSTakashi Iwai 	}
381443c1b2e9STakashi Iwai 	if (pset[INPUT_PIN_ATTR_INT] < 0 ||
381543c1b2e9STakashi Iwai 	    (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
381643c1b2e9STakashi Iwai 		return; /* no input to switch*/
3817f2e5731dSTakashi Iwai 	spec->auto_mic = 1;
381843c1b2e9STakashi Iwai 	spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
381943c1b2e9STakashi Iwai 	spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
382043c1b2e9STakashi Iwai 	spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
3821f2e5731dSTakashi Iwai }
3822f2e5731dSTakashi Iwai 
3823f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3824f2e5731dSTakashi Iwai {
3825f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3826f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3827f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
38286764bcefSTakashi Iwai 	int i, j;
3829f2e5731dSTakashi Iwai 
3830f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3831f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
38326764bcefSTakashi Iwai 		for (j = 0; j < spec->num_adc_nids; j++) {
38336764bcefSTakashi Iwai 			hda_nid_t adc = spec->adc_nids[j];
38345c9887e0STakashi Iwai 			int idx = get_input_connection(codec, adc,
3835f2e5731dSTakashi Iwai 						       cfg->inputs[i].pin);
3836f2e5731dSTakashi Iwai 			if (idx >= 0) {
3837f2e5731dSTakashi Iwai 				const char *label;
3838f2e5731dSTakashi Iwai 				label = hda_get_autocfg_input_label(codec, cfg, i);
383947ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].index = i;
384047ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].boost = 0;
384147ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].adc = adc;
384247ad1f4eSTakashi Iwai 				spec->imux_info[imux->num_items].pin =
3843f6100bb4STakashi Iwai 					cfg->inputs[i].pin;
3844f2e5731dSTakashi Iwai 				snd_hda_add_imux_item(imux, label, idx, NULL);
38456764bcefSTakashi Iwai 				break;
38466764bcefSTakashi Iwai 			}
3847f2e5731dSTakashi Iwai 		}
3848f2e5731dSTakashi Iwai 	}
384943c1b2e9STakashi Iwai 	if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3850f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
38516764bcefSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic) {
38526764bcefSTakashi Iwai 		for (i = 1; i < imux->num_items; i++) {
385347ad1f4eSTakashi Iwai 			if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
38546764bcefSTakashi Iwai 				spec->adc_switching = 1;
38556764bcefSTakashi Iwai 				break;
38566764bcefSTakashi Iwai 			}
38576764bcefSTakashi Iwai 		}
38586764bcefSTakashi Iwai 	}
3859f2e5731dSTakashi Iwai }
3860f2e5731dSTakashi Iwai 
3861f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3862f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3863f2e5731dSTakashi Iwai {
3864f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3865f2e5731dSTakashi Iwai 
3866f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3867f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3868f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3869f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3870f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3871f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3872f2e5731dSTakashi Iwai 				return nid;
3873f2e5731dSTakashi Iwai 		}
3874f2e5731dSTakashi Iwai 	}
3875f2e5731dSTakashi Iwai 	return 0;
3876f2e5731dSTakashi Iwai }
3877f2e5731dSTakashi Iwai 
3878f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3879f2e5731dSTakashi Iwai {
3880f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3881f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3882f2e5731dSTakashi Iwai 	hda_nid_t nid;
3883f2e5731dSTakashi Iwai 
3884f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3885f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3886f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3887f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3888f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3889f2e5731dSTakashi Iwai }
3890f2e5731dSTakashi Iwai 
3891f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3892f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3893f2e5731dSTakashi Iwai {
3894f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3895f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3896f2e5731dSTakashi Iwai 
3897f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3898f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3899f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3900f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3901f2e5731dSTakashi Iwai 			break;
3902f2e5731dSTakashi Iwai 		}
3903f2e5731dSTakashi Iwai }
3904f2e5731dSTakashi Iwai #else
3905f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3906f2e5731dSTakashi Iwai #endif
3907f2e5731dSTakashi Iwai 
3908*19110595STakashi Iwai static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
3909*19110595STakashi Iwai {
3910*19110595STakashi Iwai 	int i;
3911*19110595STakashi Iwai 	for (i = 0; i < nums; i++)
3912*19110595STakashi Iwai 		if (list[i] == nid)
3913*19110595STakashi Iwai 			return true;
3914*19110595STakashi Iwai 	return false;
3915*19110595STakashi Iwai }
3916*19110595STakashi Iwai 
3917*19110595STakashi Iwai /* parse extra-EAPD that aren't assigned to any pins */
3918*19110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec)
3919*19110595STakashi Iwai {
3920*19110595STakashi Iwai 	struct conexant_spec *spec = codec->spec;
3921*19110595STakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3922*19110595STakashi Iwai 	hda_nid_t nid, end_nid;
3923*19110595STakashi Iwai 
3924*19110595STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3925*19110595STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3926*19110595STakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3927*19110595STakashi Iwai 			continue;
3928*19110595STakashi Iwai 		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3929*19110595STakashi Iwai 			continue;
3930*19110595STakashi Iwai 		if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3931*19110595STakashi Iwai 		    found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3932*19110595STakashi Iwai 		    found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs))
3933*19110595STakashi Iwai 			continue;
3934*19110595STakashi Iwai 		spec->eapds[spec->num_eapds++] = nid;
3935*19110595STakashi Iwai 		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3936*19110595STakashi Iwai 			break;
3937*19110595STakashi Iwai 	}
3938*19110595STakashi Iwai }
3939*19110595STakashi Iwai 
3940f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3941f2e5731dSTakashi Iwai {
3942f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3943f2e5731dSTakashi Iwai 	int err;
3944f2e5731dSTakashi Iwai 
3945f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3946f2e5731dSTakashi Iwai 	if (err < 0)
3947f2e5731dSTakashi Iwai 		return err;
3948f2e5731dSTakashi Iwai 
3949f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3950f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3951f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3952f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3953*19110595STakashi Iwai 	cx_auto_parse_eapd(codec);
3954f2e5731dSTakashi Iwai 	return 0;
3955f2e5731dSTakashi Iwai }
3956f2e5731dSTakashi Iwai 
3957da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3958da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
3959f2e5731dSTakashi Iwai {
3960f2e5731dSTakashi Iwai 	int i;
3961f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3962f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3963f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3964da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
3965da339866STakashi Iwai 					    on ? 0x02 : 0);
3966f2e5731dSTakashi Iwai 	}
3967f2e5731dSTakashi Iwai }
3968f2e5731dSTakashi Iwai 
3969f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3970f2e5731dSTakashi Iwai 			      hda_nid_t src)
3971f2e5731dSTakashi Iwai {
3972f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3973f2e5731dSTakashi Iwai 	if (idx >= 0)
3974f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3975f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3976f2e5731dSTakashi Iwai }
3977f2e5731dSTakashi Iwai 
39781f8458a2STakashi Iwai static void mute_outputs(struct hda_codec *codec, int num_nids,
39791f8458a2STakashi Iwai 			 const hda_nid_t *nids)
3980f2e5731dSTakashi Iwai {
39810ad1b5b6STakashi Iwai 	int i, val;
3982f2e5731dSTakashi Iwai 
39831f8458a2STakashi Iwai 	for (i = 0; i < num_nids; i++) {
39841f8458a2STakashi Iwai 		hda_nid_t nid = nids[i];
39851f8458a2STakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
39861f8458a2STakashi Iwai 			continue;
39870ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
39880ad1b5b6STakashi Iwai 			val = AMP_OUT_MUTE;
39890ad1b5b6STakashi Iwai 		else
39900ad1b5b6STakashi Iwai 			val = AMP_OUT_ZERO;
39910ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0,
39920ad1b5b6STakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, val);
39930ad1b5b6STakashi Iwai 	}
39941f8458a2STakashi Iwai }
3995f2e5731dSTakashi Iwai 
399603697e2aSTakashi Iwai static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
399703697e2aSTakashi Iwai 			      hda_nid_t *pins, unsigned int tag)
399803697e2aSTakashi Iwai {
399903697e2aSTakashi Iwai 	int i;
400003697e2aSTakashi Iwai 	for (i = 0; i < num_pins; i++)
400103697e2aSTakashi Iwai 		snd_hda_codec_write(codec, pins[i], 0,
400203697e2aSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
400303697e2aSTakashi Iwai 				    AC_USRSP_EN | tag);
400403697e2aSTakashi Iwai }
400503697e2aSTakashi Iwai 
40061f8458a2STakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
40071f8458a2STakashi Iwai {
40081f8458a2STakashi Iwai 	struct conexant_spec *spec = codec->spec;
40091f8458a2STakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
40101f8458a2STakashi Iwai 	hda_nid_t nid;
40111f8458a2STakashi Iwai 	int i;
40121f8458a2STakashi Iwai 
40131f8458a2STakashi Iwai 	mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
4014f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
4015f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
4016f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
40171f8458a2STakashi Iwai 	mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
40181f8458a2STakashi Iwai 	mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
40191f8458a2STakashi Iwai 	mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
4020f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
4021f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
4022f2e5731dSTakashi Iwai 		if (!nid)
4023f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
4024f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
4025f2e5731dSTakashi Iwai 	}
402603697e2aSTakashi Iwai 	if (spec->auto_mute) {
402703697e2aSTakashi Iwai 		enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
402803697e2aSTakashi Iwai 				  CONEXANT_HP_EVENT);
402903697e2aSTakashi Iwai 		spec->hp_present = detect_jacks(codec, cfg->hp_outs,
403003697e2aSTakashi Iwai 						cfg->hp_pins);
403103697e2aSTakashi Iwai 		if (spec->detect_line) {
403203697e2aSTakashi Iwai 			enable_unsol_pins(codec, cfg->line_outs,
403303697e2aSTakashi Iwai 					  cfg->line_out_pins,
403403697e2aSTakashi Iwai 					  CONEXANT_LINE_EVENT);
403503697e2aSTakashi Iwai 			spec->line_present =
403603697e2aSTakashi Iwai 				detect_jacks(codec, cfg->line_outs,
403703697e2aSTakashi Iwai 					     cfg->line_out_pins);
403803697e2aSTakashi Iwai 		}
403903697e2aSTakashi Iwai 	}
404003697e2aSTakashi Iwai 	cx_auto_update_speakers(codec);
4041*19110595STakashi Iwai 	/* turn on/off extra EAPDs, too */
4042*19110595STakashi Iwai 	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
4043f2e5731dSTakashi Iwai }
4044f2e5731dSTakashi Iwai 
4045f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
4046f2e5731dSTakashi Iwai {
4047f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4048f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
40490ad1b5b6STakashi Iwai 	int i, val;
4050f2e5731dSTakashi Iwai 
40510ad1b5b6STakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
40520ad1b5b6STakashi Iwai 		hda_nid_t nid = spec->adc_nids[i];
40531f8458a2STakashi Iwai 		if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
40541f8458a2STakashi Iwai 			continue;
40550ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
40560ad1b5b6STakashi Iwai 			val = AMP_IN_MUTE(0);
40570ad1b5b6STakashi Iwai 		else
40580ad1b5b6STakashi Iwai 			val = AMP_IN_UNMUTE(0);
40590ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
40600ad1b5b6STakashi Iwai 				    val);
40610ad1b5b6STakashi Iwai 	}
4062f2e5731dSTakashi Iwai 
4063f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
4064f2e5731dSTakashi Iwai 		unsigned int type;
4065f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
4066f2e5731dSTakashi Iwai 			type = PIN_VREF80;
4067f2e5731dSTakashi Iwai 		else
4068f2e5731dSTakashi Iwai 			type = PIN_IN;
4069f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
4070f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
4071f2e5731dSTakashi Iwai 	}
4072f2e5731dSTakashi Iwai 
4073f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
407443c1b2e9STakashi Iwai 		if (spec->auto_mic_ext >= 0) {
407543c1b2e9STakashi Iwai 			snd_hda_codec_write(codec,
407643c1b2e9STakashi Iwai 				cfg->inputs[spec->auto_mic_ext].pin, 0,
4077f2e5731dSTakashi Iwai 				AC_VERB_SET_UNSOLICITED_ENABLE,
4078f2e5731dSTakashi Iwai 				AC_USRSP_EN | CONEXANT_MIC_EVENT);
407943c1b2e9STakashi Iwai 		}
408043c1b2e9STakashi Iwai 		if (spec->auto_mic_dock >= 0) {
408143c1b2e9STakashi Iwai 			snd_hda_codec_write(codec,
408243c1b2e9STakashi Iwai 				cfg->inputs[spec->auto_mic_dock].pin, 0,
408343c1b2e9STakashi Iwai 				AC_VERB_SET_UNSOLICITED_ENABLE,
408443c1b2e9STakashi Iwai 				AC_USRSP_EN | CONEXANT_MIC_EVENT);
408543c1b2e9STakashi Iwai 		}
4086f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
4087f2e5731dSTakashi Iwai 	} else {
408847ad1f4eSTakashi Iwai 		select_input_connection(codec, spec->imux_info[0].adc,
408947ad1f4eSTakashi Iwai 					spec->imux_info[0].pin);
4090f2e5731dSTakashi Iwai 	}
4091f2e5731dSTakashi Iwai }
4092f2e5731dSTakashi Iwai 
4093f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
4094f2e5731dSTakashi Iwai {
4095f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4096f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
4097f2e5731dSTakashi Iwai 
4098f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
4099f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
4100f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
4101f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
4102f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
4103f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
4104f2e5731dSTakashi Iwai }
4105f2e5731dSTakashi Iwai 
4106f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
4107f2e5731dSTakashi Iwai {
4108f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
4109f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
4110f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
4111f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
4112f2e5731dSTakashi Iwai 	return 0;
4113f2e5731dSTakashi Iwai }
4114f2e5731dSTakashi Iwai 
4115983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
4116f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
4117983345e5SDavid Henningsson 			      hda_nid_t nid, int hda_dir, int amp_idx)
4118f2e5731dSTakashi Iwai {
4119f2e5731dSTakashi Iwai 	static char name[32];
4120f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
4121f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
4122f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
4123f2e5731dSTakashi Iwai 	};
412434cbe3a6STakashi Iwai 	static const char * const sfx[2] = { "Volume", "Switch" };
4125f2e5731dSTakashi Iwai 	int i, err;
4126f2e5731dSTakashi Iwai 
4127f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
4128f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
4129983345e5SDavid Henningsson 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
4130983345e5SDavid Henningsson 							    hda_dir);
4131f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
4132f2e5731dSTakashi Iwai 		knew[i].index = cidx;
4133f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
4134f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
4135f2e5731dSTakashi Iwai 		if (!kctl)
4136f2e5731dSTakashi Iwai 			return -ENOMEM;
4137f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
4138f2e5731dSTakashi Iwai 		if (err < 0)
4139f2e5731dSTakashi Iwai 			return err;
4140f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
4141f2e5731dSTakashi Iwai 			break;
4142f2e5731dSTakashi Iwai 	}
4143f2e5731dSTakashi Iwai 	return 0;
4144f2e5731dSTakashi Iwai }
4145f2e5731dSTakashi Iwai 
4146983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\
4147983345e5SDavid Henningsson 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
4148983345e5SDavid Henningsson 
4149f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
4150f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
4151f2e5731dSTakashi Iwai 
41521f8458a2STakashi Iwai static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
41531f8458a2STakashi Iwai 			     hda_nid_t pin, const char *name, int idx)
41541f8458a2STakashi Iwai {
41551f8458a2STakashi Iwai 	unsigned int caps;
41561f8458a2STakashi Iwai 	caps = query_amp_caps(codec, dac, HDA_OUTPUT);
41571f8458a2STakashi Iwai 	if (caps & AC_AMPCAP_NUM_STEPS)
41581f8458a2STakashi Iwai 		return cx_auto_add_pb_volume(codec, dac, name, idx);
41591f8458a2STakashi Iwai 	caps = query_amp_caps(codec, pin, HDA_OUTPUT);
41601f8458a2STakashi Iwai 	if (caps & AC_AMPCAP_NUM_STEPS)
41611f8458a2STakashi Iwai 		return cx_auto_add_pb_volume(codec, pin, name, idx);
41621f8458a2STakashi Iwai 	return 0;
41631f8458a2STakashi Iwai }
41641f8458a2STakashi Iwai 
4165f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
4166f2e5731dSTakashi Iwai {
4167f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4168f2e5731dSTakashi Iwai 	int i, err;
4169f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
4170ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
4171f2e5731dSTakashi Iwai 
4172f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
41731f8458a2STakashi Iwai 		return try_add_pb_volume(codec, spec->dac_info[0].dac,
41741f8458a2STakashi Iwai 					 spec->dac_info[0].pin,
4175f2e5731dSTakashi Iwai 					 "Master", 0);
41761f8458a2STakashi Iwai 
4177f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
4178f2e5731dSTakashi Iwai 		const char *label;
4179f2e5731dSTakashi Iwai 		int idx, type;
4180f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
4181f2e5731dSTakashi Iwai 			continue;
4182f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
4183f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
4184f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
4185f2e5731dSTakashi Iwai 		switch (type) {
4186f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
4187f2e5731dSTakashi Iwai 		default:
4188f2e5731dSTakashi Iwai 			label = texts[num_line++];
4189f2e5731dSTakashi Iwai 			idx = 0;
4190f2e5731dSTakashi Iwai 			break;
4191f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
4192f2e5731dSTakashi Iwai 			label = "Headphone";
4193f2e5731dSTakashi Iwai 			idx = num_hp++;
4194f2e5731dSTakashi Iwai 			break;
4195f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
4196f2e5731dSTakashi Iwai 			label = "Speaker";
4197f2e5731dSTakashi Iwai 			idx = num_spk++;
4198f2e5731dSTakashi Iwai 			break;
4199f2e5731dSTakashi Iwai 		}
42001f8458a2STakashi Iwai 		err = try_add_pb_volume(codec, spec->dac_info[i].dac,
42011f8458a2STakashi Iwai 					spec->dac_info[i].pin,
4202f2e5731dSTakashi Iwai 					label, idx);
4203f2e5731dSTakashi Iwai 		if (err < 0)
4204f2e5731dSTakashi Iwai 			return err;
4205f2e5731dSTakashi Iwai 	}
420603697e2aSTakashi Iwai 
420703697e2aSTakashi Iwai 	if (spec->auto_mute) {
420803697e2aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
420903697e2aSTakashi Iwai 		if (err < 0)
421003697e2aSTakashi Iwai 			return err;
421103697e2aSTakashi Iwai 	}
421203697e2aSTakashi Iwai 
4213f2e5731dSTakashi Iwai 	return 0;
4214f2e5731dSTakashi Iwai }
4215f2e5731dSTakashi Iwai 
42166764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
42176764bcefSTakashi Iwai 				      const char *label, const char *pfx,
42186764bcefSTakashi Iwai 				      int cidx)
42196764bcefSTakashi Iwai {
42206764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
42216764bcefSTakashi Iwai 	int i;
42226764bcefSTakashi Iwai 
42236764bcefSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
42246764bcefSTakashi Iwai 		hda_nid_t adc_nid = spec->adc_nids[i];
42255c9887e0STakashi Iwai 		int idx = get_input_connection(codec, adc_nid, nid);
42266764bcefSTakashi Iwai 		if (idx < 0)
42276764bcefSTakashi Iwai 			continue;
42286764bcefSTakashi Iwai 		return cx_auto_add_volume_idx(codec, label, pfx,
42296764bcefSTakashi Iwai 					      cidx, adc_nid, HDA_INPUT, idx);
42306764bcefSTakashi Iwai 	}
42316764bcefSTakashi Iwai 	return 0;
42326764bcefSTakashi Iwai }
42336764bcefSTakashi Iwai 
4234cf27f29aSTakashi Iwai static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
4235cf27f29aSTakashi Iwai 				    const char *label, int cidx)
4236cf27f29aSTakashi Iwai {
4237cf27f29aSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4238cf27f29aSTakashi Iwai 	hda_nid_t mux, nid;
4239f9759301STakashi Iwai 	int i, con;
4240cf27f29aSTakashi Iwai 
424147ad1f4eSTakashi Iwai 	nid = spec->imux_info[idx].pin;
4242cf27f29aSTakashi Iwai 	if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
4243cf27f29aSTakashi Iwai 		return cx_auto_add_volume(codec, label, " Boost", cidx,
4244cf27f29aSTakashi Iwai 					  nid, HDA_INPUT);
424547ad1f4eSTakashi Iwai 	con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
424647ad1f4eSTakashi Iwai 					&mux, false, 0);
4247cf27f29aSTakashi Iwai 	if (con < 0)
4248cf27f29aSTakashi Iwai 		return 0;
4249f9759301STakashi Iwai 	for (i = 0; i < idx; i++) {
425047ad1f4eSTakashi Iwai 		if (spec->imux_info[i].boost == mux)
4251f9759301STakashi Iwai 			return 0; /* already present */
4252f9759301STakashi Iwai 	}
4253f9759301STakashi Iwai 
4254f9759301STakashi Iwai 	if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
425547ad1f4eSTakashi Iwai 		spec->imux_info[idx].boost = mux;
4256cf27f29aSTakashi Iwai 		return cx_auto_add_volume(codec, label, " Boost", 0,
4257cf27f29aSTakashi Iwai 					  mux, HDA_OUTPUT);
4258f9759301STakashi Iwai 	}
4259cf27f29aSTakashi Iwai 	return 0;
4260cf27f29aSTakashi Iwai }
4261cf27f29aSTakashi Iwai 
4262f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
4263f2e5731dSTakashi Iwai {
4264f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
4265cf27f29aSTakashi Iwai 	struct hda_input_mux *imux = &spec->private_imux;
4266cf27f29aSTakashi Iwai 	const char *prev_label;
4267cf27f29aSTakashi Iwai 	int input_conn[HDA_MAX_NUM_INPUTS];
42686764bcefSTakashi Iwai 	int i, err, cidx;
4269cf27f29aSTakashi Iwai 	int multi_connection;
4270cf27f29aSTakashi Iwai 
4271cf27f29aSTakashi Iwai 	multi_connection = 0;
4272cf27f29aSTakashi Iwai 	for (i = 0; i < imux->num_items; i++) {
427347ad1f4eSTakashi Iwai 		cidx = get_input_connection(codec, spec->imux_info[i].adc,
427447ad1f4eSTakashi Iwai 					    spec->imux_info[i].pin);
427547ad1f4eSTakashi Iwai 		input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
4276cf27f29aSTakashi Iwai 		if (i > 0 && input_conn[i] != input_conn[0])
4277cf27f29aSTakashi Iwai 			multi_connection = 1;
4278cf27f29aSTakashi Iwai 	}
4279983345e5SDavid Henningsson 
4280f2e5731dSTakashi Iwai 	prev_label = NULL;
4281f2e5731dSTakashi Iwai 	cidx = 0;
4282cf27f29aSTakashi Iwai 	for (i = 0; i < imux->num_items; i++) {
428347ad1f4eSTakashi Iwai 		hda_nid_t nid = spec->imux_info[i].pin;
4284f2e5731dSTakashi Iwai 		const char *label;
4285983345e5SDavid Henningsson 
4286cf27f29aSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, &spec->autocfg,
428747ad1f4eSTakashi Iwai 						    spec->imux_info[i].index);
4288f2e5731dSTakashi Iwai 		if (label == prev_label)
4289f2e5731dSTakashi Iwai 			cidx++;
4290f2e5731dSTakashi Iwai 		else
4291f2e5731dSTakashi Iwai 			cidx = 0;
4292f2e5731dSTakashi Iwai 		prev_label = label;
4293983345e5SDavid Henningsson 
4294cf27f29aSTakashi Iwai 		err = cx_auto_add_boost_volume(codec, i, label, cidx);
4295f2e5731dSTakashi Iwai 		if (err < 0)
4296f2e5731dSTakashi Iwai 			return err;
4297983345e5SDavid Henningsson 
4298cf27f29aSTakashi Iwai 		if (!multi_connection) {
4299f9759301STakashi Iwai 			if (i > 0)
4300f9759301STakashi Iwai 				continue;
43016764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
43026764bcefSTakashi Iwai 							 "Capture", "", cidx);
43036764bcefSTakashi Iwai 		} else {
43046764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
43056764bcefSTakashi Iwai 							 label, " Capture", cidx);
43066764bcefSTakashi Iwai 		}
4307983345e5SDavid Henningsson 		if (err < 0)
4308983345e5SDavid Henningsson 			return err;
4309983345e5SDavid Henningsson 	}
43106764bcefSTakashi Iwai 
43116764bcefSTakashi Iwai 	if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
43126764bcefSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
43136764bcefSTakashi Iwai 		if (err < 0)
43146764bcefSTakashi Iwai 			return err;
4315983345e5SDavid Henningsson 	}
43166764bcefSTakashi Iwai 
4317f2e5731dSTakashi Iwai 	return 0;
4318f2e5731dSTakashi Iwai }
4319f2e5731dSTakashi Iwai 
4320f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
4321f2e5731dSTakashi Iwai {
4322f2e5731dSTakashi Iwai 	int err;
4323f2e5731dSTakashi Iwai 
4324f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
4325f2e5731dSTakashi Iwai 	if (err < 0)
4326f2e5731dSTakashi Iwai 		return err;
4327f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
4328f2e5731dSTakashi Iwai 	if (err < 0)
4329f2e5731dSTakashi Iwai 		return err;
4330f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
4331f2e5731dSTakashi Iwai }
4332f2e5731dSTakashi Iwai 
433322ce5f74STakashi Iwai static int cx_auto_search_adcs(struct hda_codec *codec)
433422ce5f74STakashi Iwai {
433522ce5f74STakashi Iwai 	struct conexant_spec *spec = codec->spec;
433622ce5f74STakashi Iwai 	hda_nid_t nid, end_nid;
433722ce5f74STakashi Iwai 
433822ce5f74STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
433922ce5f74STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
434022ce5f74STakashi Iwai 		unsigned int caps = get_wcaps(codec, nid);
434122ce5f74STakashi Iwai 		if (get_wcaps_type(caps) != AC_WID_AUD_IN)
434222ce5f74STakashi Iwai 			continue;
434322ce5f74STakashi Iwai 		if (caps & AC_WCAP_DIGITAL)
434422ce5f74STakashi Iwai 			continue;
434522ce5f74STakashi Iwai 		if (snd_BUG_ON(spec->num_adc_nids >=
434622ce5f74STakashi Iwai 			       ARRAY_SIZE(spec->private_adc_nids)))
434722ce5f74STakashi Iwai 			break;
434822ce5f74STakashi Iwai 		spec->private_adc_nids[spec->num_adc_nids++] = nid;
434922ce5f74STakashi Iwai 	}
435022ce5f74STakashi Iwai 	spec->adc_nids = spec->private_adc_nids;
435122ce5f74STakashi Iwai 	return 0;
435222ce5f74STakashi Iwai }
435322ce5f74STakashi Iwai 
435422ce5f74STakashi Iwai 
435534cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
4356f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
4357f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
4358f2e5731dSTakashi Iwai 	.init = cx_auto_init,
4359f2e5731dSTakashi Iwai 	.free = conexant_free,
4360f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
4361f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
4362f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
4363f2e5731dSTakashi Iwai #endif
4364f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
4365f2e5731dSTakashi Iwai };
4366f2e5731dSTakashi Iwai 
4367f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
4368f2e5731dSTakashi Iwai {
4369f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
4370f2e5731dSTakashi Iwai 	int err;
4371f2e5731dSTakashi Iwai 
43721f8458a2STakashi Iwai 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
43731f8458a2STakashi Iwai 	       codec->chip_name);
43741f8458a2STakashi Iwai 
4375f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4376f2e5731dSTakashi Iwai 	if (!spec)
4377f2e5731dSTakashi Iwai 		return -ENOMEM;
4378f2e5731dSTakashi Iwai 	codec->spec = spec;
43791387cde5STakashi Iwai 	codec->pin_amp_workaround = 1;
438022ce5f74STakashi Iwai 	err = cx_auto_search_adcs(codec);
438122ce5f74STakashi Iwai 	if (err < 0)
438222ce5f74STakashi Iwai 		return err;
4383f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
4384f2e5731dSTakashi Iwai 	if (err < 0) {
4385f2e5731dSTakashi Iwai 		kfree(codec->spec);
4386f2e5731dSTakashi Iwai 		codec->spec = NULL;
4387f2e5731dSTakashi Iwai 		return err;
4388f2e5731dSTakashi Iwai 	}
43896764bcefSTakashi Iwai 	spec->capture_stream = &cx_auto_pcm_analog_capture;
4390f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
4391f2e5731dSTakashi Iwai 	if (spec->beep_amp)
4392f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
4393f2e5731dSTakashi Iwai 	return 0;
4394f2e5731dSTakashi Iwai }
4395f2e5731dSTakashi Iwai 
4396f2e5731dSTakashi Iwai /*
4397461e2c78STakashi Iwai  */
4398461e2c78STakashi Iwai 
439934cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
440082f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
440182f30040STobin Davis 	  .patch = patch_cxt5045 },
440282f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
440382f30040STobin Davis 	  .patch = patch_cxt5047 },
4404461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4405461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
44060fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
44070fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
440895a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
440995a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
4410850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
4411850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
44127b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
44137b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
4414f0ca89b0SDavid Henningsson 	{ .id = 0x14f1506c, .name = "CX20588",
4415f0ca89b0SDavid Henningsson 	  .patch = patch_cxt5066 },
44166da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
44176da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
4418f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
4419f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4420f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
4421f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4422f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
4423f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4424f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
4425f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4426f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
4427f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4428f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
4429f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4430f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
4431f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4432f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
4433f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4434c9b443d4STobin Davis 	{} /* terminator */
4435c9b443d4STobin Davis };
44361289e9e8STakashi Iwai 
44371289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
44381289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
44391289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
44400fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
444195a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
4442850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
44437b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
4444f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c");
44456da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4446f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
4447f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
4448f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4449f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4450f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4451f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4452f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4453f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
44541289e9e8STakashi Iwai 
44551289e9e8STakashi Iwai MODULE_LICENSE("GPL");
44561289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
44571289e9e8STakashi Iwai 
44581289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
44591289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
44601289e9e8STakashi Iwai 	.owner = THIS_MODULE,
44611289e9e8STakashi Iwai };
44621289e9e8STakashi Iwai 
44631289e9e8STakashi Iwai static int __init patch_conexant_init(void)
44641289e9e8STakashi Iwai {
44651289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
44661289e9e8STakashi Iwai }
44671289e9e8STakashi Iwai 
44681289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
44691289e9e8STakashi Iwai {
44701289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
44711289e9e8STakashi Iwai }
44721289e9e8STakashi Iwai 
44731289e9e8STakashi Iwai module_init(patch_conexant_init)
44741289e9e8STakashi Iwai module_exit(patch_conexant_exit)
4475