xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 6764bcef4cb964456615565ff974ed917de3c12d)
1c9b443d4STobin Davis /*
2c9b443d4STobin Davis  * HD audio interface patch for Conexant HDA audio codec
3c9b443d4STobin Davis  *
4c9b443d4STobin Davis  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5c9b443d4STobin Davis  * 		      Takashi Iwai <tiwai@suse.de>
6c9b443d4STobin Davis  * 		      Tobin Davis  <tdavis@dsl-only.net>
7c9b443d4STobin Davis  *
8c9b443d4STobin Davis  *  This driver is free software; you can redistribute it and/or modify
9c9b443d4STobin Davis  *  it under the terms of the GNU General Public License as published by
10c9b443d4STobin Davis  *  the Free Software Foundation; either version 2 of the License, or
11c9b443d4STobin Davis  *  (at your option) any later version.
12c9b443d4STobin Davis  *
13c9b443d4STobin Davis  *  This driver is distributed in the hope that it will be useful,
14c9b443d4STobin Davis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9b443d4STobin Davis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9b443d4STobin Davis  *  GNU General Public License for more details.
17c9b443d4STobin Davis  *
18c9b443d4STobin Davis  *  You should have received a copy of the GNU General Public License
19c9b443d4STobin Davis  *  along with this program; if not, write to the Free Software
20c9b443d4STobin Davis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21c9b443d4STobin Davis  */
22c9b443d4STobin Davis 
23c9b443d4STobin Davis #include <linux/init.h>
24c9b443d4STobin Davis #include <linux/delay.h>
25c9b443d4STobin Davis #include <linux/slab.h>
26c9b443d4STobin Davis #include <linux/pci.h>
27c9b443d4STobin Davis #include <sound/core.h>
28bc7a166dSUlrich Dangel #include <sound/jack.h>
29bc7a166dSUlrich Dangel 
30c9b443d4STobin Davis #include "hda_codec.h"
31c9b443d4STobin Davis #include "hda_local.h"
32c0f8faf0SEinar Rünkaru #include "hda_beep.h"
33c9b443d4STobin Davis 
34c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39c9b443d4STobin Davis 
40c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
42c9b443d4STobin Davis 
43bc7a166dSUlrich Dangel /* Conexant 5051 specific */
44c9b443d4STobin Davis 
45ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
48bc7a166dSUlrich Dangel 
49faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
51bc7a166dSUlrich Dangel 
52f2e5731dSTakashi Iwai struct pin_dac_pair {
53f2e5731dSTakashi Iwai 	hda_nid_t pin;
54f2e5731dSTakashi Iwai 	hda_nid_t dac;
55f2e5731dSTakashi Iwai 	int type;
56f2e5731dSTakashi Iwai };
57f2e5731dSTakashi Iwai 
58c9b443d4STobin Davis struct conexant_spec {
59c9b443d4STobin Davis 
6034cbe3a6STakashi Iwai 	const struct snd_kcontrol_new *mixers[5];
61c9b443d4STobin Davis 	int num_mixers;
62dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
63c9b443d4STobin Davis 
64c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
65c9b443d4STobin Davis 						 * don't forget NULL
66c9b443d4STobin Davis 						 * termination!
67c9b443d4STobin Davis 						 */
68c9b443d4STobin Davis 	unsigned int num_init_verbs;
69c9b443d4STobin Davis 
70c9b443d4STobin Davis 	/* playback */
71c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
72c9b443d4STobin Davis 					 * max_channels, dacs must be set
73c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
74c9b443d4STobin Davis 					 */
75c9b443d4STobin Davis 	unsigned int cur_eapd;
7682f30040STobin Davis 	unsigned int hp_present;
77faddaa5dSTakashi Iwai 	unsigned int auto_mic;
78f2e5731dSTakashi Iwai 	int auto_mic_ext;		/* autocfg.inputs[] index for ext mic */
79c9b443d4STobin Davis 	unsigned int need_dac_fix;
80f6a2491cSAndy Robinson 	hda_nid_t slave_dig_outs[2];
81c9b443d4STobin Davis 
82c9b443d4STobin Davis 	/* capture */
83c9b443d4STobin Davis 	unsigned int num_adc_nids;
8434cbe3a6STakashi Iwai 	const hda_nid_t *adc_nids;
85c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
86c9b443d4STobin Davis 
87461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
88461e2c78STakashi Iwai 	hda_nid_t cur_adc;
89461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
90461e2c78STakashi Iwai 	unsigned int cur_adc_format;
91461e2c78STakashi Iwai 
92*6764bcefSTakashi Iwai 	const struct hda_pcm_stream *capture_stream;
93*6764bcefSTakashi Iwai 
94c9b443d4STobin Davis 	/* capture source */
95c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
9634cbe3a6STakashi Iwai 	const hda_nid_t *capsrc_nids;
97c9b443d4STobin Davis 	unsigned int cur_mux[3];
98c9b443d4STobin Davis 
99c9b443d4STobin Davis 	/* channel model */
100c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
101c9b443d4STobin Davis 	int num_channel_mode;
102c9b443d4STobin Davis 
103c9b443d4STobin Davis 	/* PCM information */
104c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
105c9b443d4STobin Davis 
106c9b443d4STobin Davis 	unsigned int spdif_route;
107c9b443d4STobin Davis 
108c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
109c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
110c9b443d4STobin Davis 	struct hda_input_mux private_imux;
111*6764bcefSTakashi Iwai 	hda_nid_t imux_adcs[HDA_MAX_NUM_INPUTS];
11241923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
113f2e5731dSTakashi Iwai 	struct pin_dac_pair dac_info[8];
114f2e5731dSTakashi Iwai 	int dac_info_filled;
115c9b443d4STobin Davis 
1160fb67e98SDaniel Drake 	unsigned int port_d_mode;
117f2e5731dSTakashi Iwai 	unsigned int auto_mute:1;	/* used in auto-parser */
118f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
119cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
120cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1217b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
122048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
123a1d6906eSDavid Henningsson 	unsigned int asus:1;
12475f8991dSDaniel Drake 
125*6764bcefSTakashi Iwai 	unsigned int adc_switching:1;
126*6764bcefSTakashi Iwai 
12775f8991dSDaniel Drake 	unsigned int ext_mic_present;
12875f8991dSDaniel Drake 	unsigned int recording;
12975f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
13075f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
131c4cfe66cSDaniel Drake 
132c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
133c4cfe66cSDaniel Drake 	 * through the microphone jack.
134c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
135c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
136c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
137c4cfe66cSDaniel Drake 	 * control. */
138c4cfe66cSDaniel Drake 	unsigned int dc_enable;
139c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
140c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1413507e2a8STakashi Iwai 
1423507e2a8STakashi Iwai 	unsigned int beep_amp;
143c9b443d4STobin Davis };
144c9b443d4STobin Davis 
145c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
146c9b443d4STobin Davis 				      struct hda_codec *codec,
147c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
148c9b443d4STobin Davis {
149c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1509a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1519a08160bSTakashi Iwai 					     hinfo);
152c9b443d4STobin Davis }
153c9b443d4STobin Davis 
154c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
155c9b443d4STobin Davis 					 struct hda_codec *codec,
156c9b443d4STobin Davis 					 unsigned int stream_tag,
157c9b443d4STobin Davis 					 unsigned int format,
158c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
159c9b443d4STobin Davis {
160c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
161c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
162c9b443d4STobin Davis 						stream_tag,
163c9b443d4STobin Davis 						format, substream);
164c9b443d4STobin Davis }
165c9b443d4STobin Davis 
166c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
167c9b443d4STobin Davis 					 struct hda_codec *codec,
168c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
169c9b443d4STobin Davis {
170c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
171c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
172c9b443d4STobin Davis }
173c9b443d4STobin Davis 
174c9b443d4STobin Davis /*
175c9b443d4STobin Davis  * Digital out
176c9b443d4STobin Davis  */
177c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
178c9b443d4STobin Davis 					  struct hda_codec *codec,
179c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
180c9b443d4STobin Davis {
181c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
182c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
183c9b443d4STobin Davis }
184c9b443d4STobin Davis 
185c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
186c9b443d4STobin Davis 					 struct hda_codec *codec,
187c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
188c9b443d4STobin Davis {
189c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
190c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
191c9b443d4STobin Davis }
192c9b443d4STobin Davis 
1936b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1946b97eb45STakashi Iwai 					 struct hda_codec *codec,
1956b97eb45STakashi Iwai 					 unsigned int stream_tag,
1966b97eb45STakashi Iwai 					 unsigned int format,
1976b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1986b97eb45STakashi Iwai {
1996b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2006b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2016b97eb45STakashi Iwai 					     stream_tag,
2026b97eb45STakashi Iwai 					     format, substream);
2036b97eb45STakashi Iwai }
2046b97eb45STakashi Iwai 
205c9b443d4STobin Davis /*
206c9b443d4STobin Davis  * Analog capture
207c9b443d4STobin Davis  */
208c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
209c9b443d4STobin Davis 				      struct hda_codec *codec,
210c9b443d4STobin Davis 				      unsigned int stream_tag,
211c9b443d4STobin Davis 				      unsigned int format,
212c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
213c9b443d4STobin Davis {
214c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
21575f8991dSDaniel Drake 	if (spec->capture_prepare)
21675f8991dSDaniel Drake 		spec->capture_prepare(codec);
217c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
218c9b443d4STobin Davis 				   stream_tag, 0, format);
219c9b443d4STobin Davis 	return 0;
220c9b443d4STobin Davis }
221c9b443d4STobin Davis 
222c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
223c9b443d4STobin Davis 				      struct hda_codec *codec,
224c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
225c9b443d4STobin Davis {
226c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
227888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
22875f8991dSDaniel Drake 	if (spec->capture_cleanup)
22975f8991dSDaniel Drake 		spec->capture_cleanup(codec);
230c9b443d4STobin Davis 	return 0;
231c9b443d4STobin Davis }
232c9b443d4STobin Davis 
233c9b443d4STobin Davis 
234c9b443d4STobin Davis 
23534cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = {
236c9b443d4STobin Davis 	.substreams = 1,
237c9b443d4STobin Davis 	.channels_min = 2,
238c9b443d4STobin Davis 	.channels_max = 2,
239c9b443d4STobin Davis 	.nid = 0, /* fill later */
240c9b443d4STobin Davis 	.ops = {
241c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
242c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
243c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
244c9b443d4STobin Davis 	},
245c9b443d4STobin Davis };
246c9b443d4STobin Davis 
24734cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = {
248c9b443d4STobin Davis 	.substreams = 1,
249c9b443d4STobin Davis 	.channels_min = 2,
250c9b443d4STobin Davis 	.channels_max = 2,
251c9b443d4STobin Davis 	.nid = 0, /* fill later */
252c9b443d4STobin Davis 	.ops = {
253c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
254c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
255c9b443d4STobin Davis 	},
256c9b443d4STobin Davis };
257c9b443d4STobin Davis 
258c9b443d4STobin Davis 
25934cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = {
260c9b443d4STobin Davis 	.substreams = 1,
261c9b443d4STobin Davis 	.channels_min = 2,
262c9b443d4STobin Davis 	.channels_max = 2,
263c9b443d4STobin Davis 	.nid = 0, /* fill later */
264c9b443d4STobin Davis 	.ops = {
265c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2666b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2676b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
268c9b443d4STobin Davis 	},
269c9b443d4STobin Davis };
270c9b443d4STobin Davis 
27134cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = {
272c9b443d4STobin Davis 	.substreams = 1,
273c9b443d4STobin Davis 	.channels_min = 2,
274c9b443d4STobin Davis 	.channels_max = 2,
275c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
276c9b443d4STobin Davis };
277c9b443d4STobin Davis 
278461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
279461e2c78STakashi Iwai 				      struct hda_codec *codec,
280461e2c78STakashi Iwai 				      unsigned int stream_tag,
281461e2c78STakashi Iwai 				      unsigned int format,
282461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
283461e2c78STakashi Iwai {
284461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
285461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
286461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
287461e2c78STakashi Iwai 	spec->cur_adc_format = format;
288461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
289461e2c78STakashi Iwai 	return 0;
290461e2c78STakashi Iwai }
291461e2c78STakashi Iwai 
292461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
293461e2c78STakashi Iwai 				      struct hda_codec *codec,
294461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
295461e2c78STakashi Iwai {
296461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
297888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
298461e2c78STakashi Iwai 	spec->cur_adc = 0;
299461e2c78STakashi Iwai 	return 0;
300461e2c78STakashi Iwai }
301461e2c78STakashi Iwai 
30234cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
303461e2c78STakashi Iwai 	.substreams = 1,
304461e2c78STakashi Iwai 	.channels_min = 2,
305461e2c78STakashi Iwai 	.channels_max = 2,
306461e2c78STakashi Iwai 	.nid = 0, /* fill later */
307461e2c78STakashi Iwai 	.ops = {
308461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
309461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
310461e2c78STakashi Iwai 	},
311461e2c78STakashi Iwai };
312461e2c78STakashi Iwai 
313c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
314c9b443d4STobin Davis {
315c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
316c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
317c9b443d4STobin Davis 
318c9b443d4STobin Davis 	codec->num_pcms = 1;
319c9b443d4STobin Davis 	codec->pcm_info = info;
320c9b443d4STobin Davis 
321c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
322c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
323c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
324c9b443d4STobin Davis 		spec->multiout.max_channels;
325c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
326c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
327*6764bcefSTakashi Iwai 	if (spec->capture_stream)
328*6764bcefSTakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
329*6764bcefSTakashi Iwai 	else {
330461e2c78STakashi Iwai 		if (codec->vendor_id == 0x14f15051)
331461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
332461e2c78STakashi Iwai 				cx5051_pcm_analog_capture;
333*6764bcefSTakashi Iwai 		else {
334461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
335461e2c78STakashi Iwai 				conexant_pcm_analog_capture;
336*6764bcefSTakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
337*6764bcefSTakashi Iwai 				spec->num_adc_nids;
338*6764bcefSTakashi Iwai 		}
339*6764bcefSTakashi Iwai 	}
340c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
341c9b443d4STobin Davis 
342c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
343c9b443d4STobin Davis 		info++;
344c9b443d4STobin Davis 		codec->num_pcms++;
345c9b443d4STobin Davis 		info->name = "Conexant Digital";
3467ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
347c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
348c9b443d4STobin Davis 			conexant_pcm_digital_playback;
349c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
350c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
351c9b443d4STobin Davis 		if (spec->dig_in_nid) {
352c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
353c9b443d4STobin Davis 				conexant_pcm_digital_capture;
354c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
355c9b443d4STobin Davis 				spec->dig_in_nid;
356c9b443d4STobin Davis 		}
357f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
358f6a2491cSAndy Robinson 			codec->slave_dig_outs = spec->slave_dig_outs;
359c9b443d4STobin Davis 	}
360c9b443d4STobin Davis 
361c9b443d4STobin Davis 	return 0;
362c9b443d4STobin Davis }
363c9b443d4STobin Davis 
364c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
365c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
366c9b443d4STobin Davis {
367c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
369c9b443d4STobin Davis 
370c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
371c9b443d4STobin Davis }
372c9b443d4STobin Davis 
373c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
374c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
375c9b443d4STobin Davis {
376c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
378c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379c9b443d4STobin Davis 
380c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
381c9b443d4STobin Davis 	return 0;
382c9b443d4STobin Davis }
383c9b443d4STobin Davis 
384c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
385c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
386c9b443d4STobin Davis {
387c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
388c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
389c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
390c9b443d4STobin Davis 
391c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
392c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
393c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
394c9b443d4STobin Davis }
395c9b443d4STobin Davis 
396bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
397bc7a166dSUlrich Dangel {
398cd372fb3STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
399bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
400bc7a166dSUlrich Dangel 	int i;
401bc7a166dSUlrich Dangel 
402bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
403bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
404bc7a166dSUlrich Dangel 
405bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
406bc7a166dSUlrich Dangel 		while (hv->nid) {
407bc7a166dSUlrich Dangel 			int err = 0;
408bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
409bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
410cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
411cd372fb3STakashi Iwai 						SND_JACK_HEADPHONE, NULL);
412cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
413bc7a166dSUlrich Dangel 				break;
414bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
415bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
416cd372fb3STakashi Iwai 				err = snd_hda_input_jack_add(codec, hv->nid,
417cd372fb3STakashi Iwai 						SND_JACK_MICROPHONE, NULL);
418cd372fb3STakashi Iwai 				snd_hda_input_jack_report(codec, hv->nid);
419bc7a166dSUlrich Dangel 				break;
420bc7a166dSUlrich Dangel 			}
421bc7a166dSUlrich Dangel 			if (err < 0)
422bc7a166dSUlrich Dangel 				return err;
423bc7a166dSUlrich Dangel 			++hv;
424bc7a166dSUlrich Dangel 		}
425bc7a166dSUlrich Dangel 	}
426cd372fb3STakashi Iwai #endif /* CONFIG_SND_HDA_INPUT_JACK */
4275801f992STakashi Iwai 	return 0;
4285801f992STakashi Iwai }
429bc7a166dSUlrich Dangel 
430c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
431c9b443d4STobin Davis {
432c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
433c9b443d4STobin Davis 	int i;
434c9b443d4STobin Davis 
435c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
436c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
437c9b443d4STobin Davis 	return 0;
438c9b443d4STobin Davis }
439c9b443d4STobin Davis 
440c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
441c9b443d4STobin Davis {
442cd372fb3STakashi Iwai 	snd_hda_input_jack_free(codec);
443c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
444c9b443d4STobin Davis 	kfree(codec->spec);
445c9b443d4STobin Davis }
446c9b443d4STobin Davis 
44734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = {
448b880c74aSTakashi Iwai 	{
449b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
450b880c74aSTakashi Iwai 		.name = "Capture Source",
451b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
452b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
453b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
454b880c74aSTakashi Iwai 	},
455b880c74aSTakashi Iwai 	{}
456b880c74aSTakashi Iwai };
457b880c74aSTakashi Iwai 
4583507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
4593507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
46034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = {
4613507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
4623507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
4633507e2a8STakashi Iwai 	{ } /* end */
4643507e2a8STakashi Iwai };
4653507e2a8STakashi Iwai #endif
4663507e2a8STakashi Iwai 
467ea734963STakashi Iwai static const char * const slave_vols[] = {
468dd5746a8STakashi Iwai 	"Headphone Playback Volume",
469dd5746a8STakashi Iwai 	"Speaker Playback Volume",
470dd5746a8STakashi Iwai 	NULL
471dd5746a8STakashi Iwai };
472dd5746a8STakashi Iwai 
473ea734963STakashi Iwai static const char * const slave_sws[] = {
474dd5746a8STakashi Iwai 	"Headphone Playback Switch",
475dd5746a8STakashi Iwai 	"Speaker Playback Switch",
476dd5746a8STakashi Iwai 	NULL
477dd5746a8STakashi Iwai };
478dd5746a8STakashi Iwai 
479c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
480c9b443d4STobin Davis {
481c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
482c9b443d4STobin Davis 	unsigned int i;
483c9b443d4STobin Davis 	int err;
484c9b443d4STobin Davis 
485c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
486c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
487c9b443d4STobin Davis 		if (err < 0)
488c9b443d4STobin Davis 			return err;
489c9b443d4STobin Davis 	}
490c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
491c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
492c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
493c9b443d4STobin Davis 		if (err < 0)
494c9b443d4STobin Davis 			return err;
4959a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
4969a08160bSTakashi Iwai 						    &spec->multiout);
4979a08160bSTakashi Iwai 		if (err < 0)
4989a08160bSTakashi Iwai 			return err;
4999a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
500c9b443d4STobin Davis 	}
501c9b443d4STobin Davis 	if (spec->dig_in_nid) {
502c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
503c9b443d4STobin Davis 		if (err < 0)
504c9b443d4STobin Davis 			return err;
505c9b443d4STobin Davis 	}
506dd5746a8STakashi Iwai 
507dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
508dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
509dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
510dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
511dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
512dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
513dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
514dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
515dd5746a8STakashi Iwai 		if (err < 0)
516dd5746a8STakashi Iwai 			return err;
517dd5746a8STakashi Iwai 	}
518dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
519dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
520dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
521dd5746a8STakashi Iwai 					  NULL, slave_sws);
522dd5746a8STakashi Iwai 		if (err < 0)
523dd5746a8STakashi Iwai 			return err;
524dd5746a8STakashi Iwai 	}
525dd5746a8STakashi Iwai 
526b880c74aSTakashi Iwai 	if (spec->input_mux) {
527b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
528b880c74aSTakashi Iwai 		if (err < 0)
529b880c74aSTakashi Iwai 			return err;
530b880c74aSTakashi Iwai 	}
531b880c74aSTakashi Iwai 
5323507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5333507e2a8STakashi Iwai 	/* create beep controls if needed */
5343507e2a8STakashi Iwai 	if (spec->beep_amp) {
53534cbe3a6STakashi Iwai 		const struct snd_kcontrol_new *knew;
5363507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
5373507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
5383507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
5393507e2a8STakashi Iwai 			if (!kctl)
5403507e2a8STakashi Iwai 				return -ENOMEM;
5413507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
5423507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
5433507e2a8STakashi Iwai 			if (err < 0)
5443507e2a8STakashi Iwai 				return err;
5453507e2a8STakashi Iwai 		}
5463507e2a8STakashi Iwai 	}
5473507e2a8STakashi Iwai #endif
5483507e2a8STakashi Iwai 
549c9b443d4STobin Davis 	return 0;
550c9b443d4STobin Davis }
551c9b443d4STobin Davis 
552697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
553697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
554697c373eSTakashi Iwai {
555697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
556697c373eSTakashi Iwai 	return 0;
557697c373eSTakashi Iwai }
558697c373eSTakashi Iwai #endif
559697c373eSTakashi Iwai 
56034cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = {
561c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
562c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
563c9b443d4STobin Davis 	.init = conexant_init,
564c9b443d4STobin Davis 	.free = conexant_free,
565697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
566697c373eSTakashi Iwai 	.suspend = conexant_suspend,
567697c373eSTakashi Iwai #endif
568697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
569c9b443d4STobin Davis };
570c9b443d4STobin Davis 
5713507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5723507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
5733507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
5743507e2a8STakashi Iwai #else
5753507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5763507e2a8STakashi Iwai #endif
5773507e2a8STakashi Iwai 
578*6764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec);
579c9b443d4STobin Davis /*
580c9b443d4STobin Davis  * EAPD control
581c9b443d4STobin Davis  * the private value = nid | (invert << 8)
582c9b443d4STobin Davis  */
583c9b443d4STobin Davis 
584a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
585c9b443d4STobin Davis 
58682f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
587c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
588c9b443d4STobin Davis {
589c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
591c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
592c9b443d4STobin Davis 	if (invert)
593c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
594c9b443d4STobin Davis 	else
595c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
596c9b443d4STobin Davis 	return 0;
59782f30040STobin Davis 
598c9b443d4STobin Davis }
599c9b443d4STobin Davis 
60082f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
601c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
602c9b443d4STobin Davis {
603c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
605c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
606c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
607c9b443d4STobin Davis 	unsigned int eapd;
60882f30040STobin Davis 
60968ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
610c9b443d4STobin Davis 	if (invert)
611c9b443d4STobin Davis 		eapd = !eapd;
61282beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
613c9b443d4STobin Davis 		return 0;
61482f30040STobin Davis 
615c9b443d4STobin Davis 	spec->cur_eapd = eapd;
61682beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
617c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
618c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
619c9b443d4STobin Davis 	return 1;
620c9b443d4STobin Davis }
621c9b443d4STobin Davis 
62286d72bdfSTakashi Iwai /* controls for test mode */
62386d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
62486d72bdfSTakashi Iwai 
62582f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
62682f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
62782f30040STobin Davis 	  .info = cxt_eapd_info, \
62882f30040STobin Davis 	  .get = cxt_eapd_get, \
62982f30040STobin Davis 	  .put = cxt_eapd_put, \
63082f30040STobin Davis 	  .private_value = nid | (mask<<16) }
63182f30040STobin Davis 
63282f30040STobin Davis 
63382f30040STobin Davis 
634c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
635c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
636c9b443d4STobin Davis {
637c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
639c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
640c9b443d4STobin Davis 				    spec->num_channel_mode);
641c9b443d4STobin Davis }
642c9b443d4STobin Davis 
643c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
644c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
645c9b443d4STobin Davis {
646c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
648c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
649c9b443d4STobin Davis 				   spec->num_channel_mode,
650c9b443d4STobin Davis 				   spec->multiout.max_channels);
651c9b443d4STobin Davis }
652c9b443d4STobin Davis 
653c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
654c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
655c9b443d4STobin Davis {
656c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
658c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
659c9b443d4STobin Davis 				      spec->num_channel_mode,
660c9b443d4STobin Davis 				      &spec->multiout.max_channels);
661c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
662c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
663c9b443d4STobin Davis 	return err;
664c9b443d4STobin Davis }
665c9b443d4STobin Davis 
666c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
667c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
668c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
669c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
670c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
671c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
672c9b443d4STobin Davis 
67386d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
67486d72bdfSTakashi Iwai 
675c9b443d4STobin Davis /* Conexant 5045 specific */
676c9b443d4STobin Davis 
67734cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
67834cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
67934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
680cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
681c9b443d4STobin Davis 
68234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = {
6835cd57529STobin Davis 	{ 2, NULL },
6845cd57529STobin Davis };
685c9b443d4STobin Davis 
68634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = {
687c9b443d4STobin Davis 	.num_items = 2,
688c9b443d4STobin Davis 	.items = {
68982f30040STobin Davis 		{ "IntMic", 0x1 },
690f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
691c9b443d4STobin Davis 	}
692c9b443d4STobin Davis };
693c9b443d4STobin Davis 
69434cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = {
69522e14130SLukasz Marcinowski 	.num_items = 5,
6965218c892SJiang Zhe 	.items = {
6975218c892SJiang Zhe 		{ "IntMic", 0x1 },
6985218c892SJiang Zhe 		{ "ExtMic", 0x2 },
6995218c892SJiang Zhe 		{ "LineIn", 0x3 },
70022e14130SLukasz Marcinowski 		{ "CD",     0x4 },
70122e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7025218c892SJiang Zhe 	}
7035218c892SJiang Zhe };
7045218c892SJiang Zhe 
70534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = {
7062de3c232SJiang zhe 	.num_items = 2,
7072de3c232SJiang zhe 	.items = {
7082de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7092de3c232SJiang zhe 		{ "IntMic", 0x2 },
7102de3c232SJiang zhe 	}
7112de3c232SJiang zhe };
7122de3c232SJiang zhe 
713c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
714c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
715c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
716c9b443d4STobin Davis {
717c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
71982f30040STobin Davis 	unsigned int bits;
720c9b443d4STobin Davis 
72182f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
722c9b443d4STobin Davis 		return 0;
723c9b443d4STobin Davis 
72482f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
72582f30040STobin Davis 	 * the headphone jack
72682f30040STobin Davis 	 */
72747fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
72847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
72947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7307f29673bSTobin Davis 
73147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
73247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
73347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
734c9b443d4STobin Davis 	return 1;
735c9b443d4STobin Davis }
736c9b443d4STobin Davis 
737c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
73834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
739cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
740cca3b371STakashi Iwai 	.values = {
741cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
742cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
743cca3b371STakashi Iwai 		0
744cca3b371STakashi Iwai 	},
745cca3b371STakashi Iwai };
746c9b443d4STobin Davis 
7477f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7487f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7497f29673bSTobin Davis {
75034cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
7517f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7527f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7537f29673bSTobin Davis 		{}
7547f29673bSTobin Davis 	};
75534cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
7567f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7577f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7587f29673bSTobin Davis 		{}
7597f29673bSTobin Davis 	};
7607f29673bSTobin Davis 	unsigned int present;
7617f29673bSTobin Davis 
762d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7637f29673bSTobin Davis 	if (present)
7647f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7657f29673bSTobin Davis 	else
7667f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7677f29673bSTobin Davis }
7687f29673bSTobin Davis 
769c9b443d4STobin Davis 
770c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
771c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
772c9b443d4STobin Davis {
77382f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
774dd87da1cSTobin Davis 	unsigned int bits;
775c9b443d4STobin Davis 
776d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
777dd87da1cSTobin Davis 
77847fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
77947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
78047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
781c9b443d4STobin Davis }
782c9b443d4STobin Davis 
783c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
784c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
785c9b443d4STobin Davis 				   unsigned int res)
786c9b443d4STobin Davis {
787c9b443d4STobin Davis 	res >>= 26;
788c9b443d4STobin Davis 	switch (res) {
789c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
790c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
791c9b443d4STobin Davis 		break;
7927f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
7937f29673bSTobin Davis 		cxt5045_hp_automic(codec);
7947f29673bSTobin Davis 		break;
7957f29673bSTobin Davis 
796c9b443d4STobin Davis 	}
797c9b443d4STobin Davis }
798c9b443d4STobin Davis 
79934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = {
80028c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
80128c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8028607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8038607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
804c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
805c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
80628c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
80728c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8088607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8098607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
810cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
811c9b443d4STobin Davis 	{
812c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
813c9b443d4STobin Davis 		.name = "Master Playback Switch",
81482f30040STobin Davis 		.info = cxt_eapd_info,
81582f30040STobin Davis 		.get = cxt_eapd_get,
816c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
81782f30040STobin Davis 		.private_value = 0x10,
818c9b443d4STobin Davis 	},
819c9b443d4STobin Davis 
820c9b443d4STobin Davis 	{}
821c9b443d4STobin Davis };
822c9b443d4STobin Davis 
82334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
82422e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
82522e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
82622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
82722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
82822e14130SLukasz Marcinowski 
8295218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8305218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8315218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8325218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8335218c892SJiang Zhe 
83422e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
83522e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
83622e14130SLukasz Marcinowski 
8375218c892SJiang Zhe 	{}
8385218c892SJiang Zhe };
8395218c892SJiang Zhe 
84034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
84128c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
84228c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8438607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8448607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8452de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8462de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
84728c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
84828c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8498607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8508607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8512de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8522de3c232SJiang zhe 	{
8532de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8542de3c232SJiang zhe 		.name = "Master Playback Switch",
8552de3c232SJiang zhe 		.info = cxt_eapd_info,
8562de3c232SJiang zhe 		.get = cxt_eapd_get,
8572de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8582de3c232SJiang zhe 		.private_value = 0x10,
8592de3c232SJiang zhe 	},
8602de3c232SJiang zhe 
8612de3c232SJiang zhe 	{}
8622de3c232SJiang zhe };
8632de3c232SJiang zhe 
86434cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = {
865c9b443d4STobin Davis 	/* Line in, Mic */
8664090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8677f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
868c9b443d4STobin Davis 	/* HP, Amp  */
869c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
870c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
87182f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
872c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
873c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
874c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
875c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
876c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
877c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
87828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
8797f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
88082f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
881c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
882c9b443d4STobin Davis 	/* SPDIF route: PCM */
883cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
885c9b443d4STobin Davis 	/* EAPD */
88682f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
887c9b443d4STobin Davis 	{ } /* end */
888c9b443d4STobin Davis };
889c9b443d4STobin Davis 
89034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = {
89128c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
8925218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8935218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8945218c892SJiang Zhe 	/* Line In,HP, Amp  */
8955218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8965218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
8975218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8985218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
8995218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9005218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9015218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9025218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9035218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
90428c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
9055218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9065218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9075218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9085218c892SJiang Zhe 	/* SPDIF route: PCM */
909cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9105218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9115218c892SJiang Zhe 	/* EAPD */
9125218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9135218c892SJiang Zhe 	{ } /* end */
9145218c892SJiang Zhe };
9157f29673bSTobin Davis 
91634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9177f29673bSTobin Davis 	/* pin sensing on HP jack */
9187f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
919d3091fadSTakashi Iwai 	{ } /* end */
9207f29673bSTobin Davis };
9217f29673bSTobin Davis 
92234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9237f29673bSTobin Davis 	/* pin sensing on HP jack */
9247f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
925d3091fadSTakashi Iwai 	{ } /* end */
9267f29673bSTobin Davis };
9277f29673bSTobin Davis 
928c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
929c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
930c9b443d4STobin Davis  * configuration.
931c9b443d4STobin Davis  */
93234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = {
933c9b443d4STobin Davis 	.num_items = 5,
934c9b443d4STobin Davis 	.items = {
935c9b443d4STobin Davis 		{ "MIXER", 0x0 },
936c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
937c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
938c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
939c9b443d4STobin Davis 		{ "CD pin", 0x4 },
940c9b443d4STobin Davis         },
941c9b443d4STobin Davis };
942c9b443d4STobin Davis 
94334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
944c9b443d4STobin Davis 
945c9b443d4STobin Davis 	/* Output controls */
946c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
947c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9487f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9497f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9507f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9517f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
952c9b443d4STobin Davis 
953c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
954c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
955c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
956c9b443d4STobin Davis 
95782f30040STobin Davis 	/* EAPD Switch Control */
95882f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
95982f30040STobin Davis 
960c9b443d4STobin Davis 	/* Loopback mixer controls */
961c9b443d4STobin Davis 
9627f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9637f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9647f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9657f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9667f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9677f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9687f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9697f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9707f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9717f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
972c9b443d4STobin Davis 	{
973c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
974c9b443d4STobin Davis 		.name = "Input Source",
975c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
976c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
977c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
978c9b443d4STobin Davis 	},
979fb3409e7STobin Davis 	/* Audio input controls */
980fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
981fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
982fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
983fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
984fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
985fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
986fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
987fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
988fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
989fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
990c9b443d4STobin Davis 	{ } /* end */
991c9b443d4STobin Davis };
992c9b443d4STobin Davis 
99334cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = {
9947f29673bSTobin Davis 	/* Set connections */
9957f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9967f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
9977f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
998c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
999c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10007f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1001c9b443d4STobin Davis 
1002c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1003c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1004c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1005c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1006c9b443d4STobin Davis 	 * control.
1007c9b443d4STobin Davis 	 */
1008cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1009cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1010c9b443d4STobin Davis 
1011c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1012c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1013c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1014c9b443d4STobin Davis 
1015c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1016c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1017c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1018c9b443d4STobin Davis 	 * input/output buffers as needed.
1019c9b443d4STobin Davis 	 */
1020c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1021c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1022c9b443d4STobin Davis 
1023c9b443d4STobin Davis 	/* Mute capture amp left and right */
1024c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1025c9b443d4STobin Davis 
1026c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1027c9b443d4STobin Davis 	 * pin)
1028c9b443d4STobin Davis 	 */
1029c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10307f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1031c9b443d4STobin Davis 
1032c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1033c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1034c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1035c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1036c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1037c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1038c9b443d4STobin Davis 
1039c9b443d4STobin Davis 	{ }
1040c9b443d4STobin Davis };
1041c9b443d4STobin Davis #endif
1042c9b443d4STobin Davis 
1043c9b443d4STobin Davis 
1044c9b443d4STobin Davis /* initialize jack-sensing, too */
1045c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1046c9b443d4STobin Davis {
1047c9b443d4STobin Davis 	conexant_init(codec);
1048c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1049c9b443d4STobin Davis 	return 0;
1050c9b443d4STobin Davis }
1051c9b443d4STobin Davis 
1052c9b443d4STobin Davis 
1053c9b443d4STobin Davis enum {
105415908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
105515908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
105615908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10575218c892SJiang Zhe 	CXT5045_BENQ,
10582de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1059c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1060c9b443d4STobin Davis 	CXT5045_TEST,
1061c9b443d4STobin Davis #endif
1062f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1063c9b443d4STobin Davis };
1064c9b443d4STobin Davis 
1065ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
106615908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
106715908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
106815908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10695218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10702de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1071c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1072f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1073c9b443d4STobin Davis #endif
1074f5fcc13cSTakashi Iwai };
1075c9b443d4STobin Davis 
107634cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10772de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1078dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1079dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
10806a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10815218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
108215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
108315908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10849e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10859e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
108615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
108715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
108815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1089dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1090dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
109115908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1092c9b443d4STobin Davis 	{}
1093c9b443d4STobin Davis };
1094c9b443d4STobin Davis 
1095c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1096c9b443d4STobin Davis {
1097c9b443d4STobin Davis 	struct conexant_spec *spec;
1098c9b443d4STobin Davis 	int board_config;
1099c9b443d4STobin Davis 
1100c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1101c9b443d4STobin Davis 	if (!spec)
1102c9b443d4STobin Davis 		return -ENOMEM;
1103c9b443d4STobin Davis 	codec->spec = spec;
11049421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1105c9b443d4STobin Davis 
1106c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1107c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1108c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1109c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1110c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1111c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1112c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1113c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1114c9b443d4STobin Davis 	spec->num_mixers = 1;
1115c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1116c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1117c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1118c9b443d4STobin Davis 	spec->spdif_route = 0;
11193507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11203507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11215cd57529STobin Davis 
11223507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1123c9b443d4STobin Davis 
1124c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1125c9b443d4STobin Davis 
1126f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1127f5fcc13cSTakashi Iwai 						  cxt5045_models,
1128f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1129c9b443d4STobin Davis 	switch (board_config) {
113015908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11317f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1132c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1133c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11347f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11357f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11367f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11377f29673bSTobin Davis 		break;
113815908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
113986376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11407f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11417f29673bSTobin Davis 		spec->num_init_verbs = 2;
11427f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1143c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1144c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1145c9b443d4STobin Davis 		break;
114615908c36SMarc Boucher 	default:
114715908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
114815908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
114915908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
115015908c36SMarc Boucher 		spec->num_init_verbs = 3;
115115908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
115215908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
115315908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
115415908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
115515908c36SMarc Boucher 		break;
11565218c892SJiang Zhe 	case CXT5045_BENQ:
11575218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11585218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11595218c892SJiang Zhe 		spec->num_init_verbs = 1;
11605218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11615218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11625218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11635218c892SJiang Zhe 		spec->num_mixers = 2;
11645218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11655218c892SJiang Zhe 		break;
11662de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11672de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11682de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11692de3c232SJiang zhe 		spec->num_init_verbs = 2;
11702de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11712de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11722de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11732de3c232SJiang zhe 		break;
1174c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1175c9b443d4STobin Davis 	case CXT5045_TEST:
1176c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1177c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1178c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
117915908c36SMarc Boucher 		break;
118015908c36SMarc Boucher 
1181c9b443d4STobin Davis #endif
1182c9b443d4STobin Davis 	}
118348ecb7e8STakashi Iwai 
1184031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1185031005f7STakashi Iwai 	case 0x103c:
11868f0f5ff6SDaniel T Chen 	case 0x1631:
11870b587fc4SDaniel T Chen 	case 0x1734:
11880ebf9e36SDaniel T Chen 	case 0x17aa:
11890ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
11900ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
11910ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
119248ecb7e8STakashi Iwai 		 */
119348ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
119448ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
119548ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
119648ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
119748ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1198031005f7STakashi Iwai 		break;
1199031005f7STakashi Iwai 	}
120048ecb7e8STakashi Iwai 
12013507e2a8STakashi Iwai 	if (spec->beep_amp)
12023507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12033507e2a8STakashi Iwai 
1204c9b443d4STobin Davis 	return 0;
1205c9b443d4STobin Davis }
1206c9b443d4STobin Davis 
1207c9b443d4STobin Davis 
1208c9b443d4STobin Davis /* Conexant 5047 specific */
120982f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1210c9b443d4STobin Davis 
121134cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
121234cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
121334cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1214c9b443d4STobin Davis 
121534cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
12165cd57529STobin Davis 	{ 2, NULL },
12175cd57529STobin Davis };
1218c9b443d4STobin Davis 
121934cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
122082f30040STobin Davis 	.num_items = 2,
122182f30040STobin Davis 	.items = {
122282f30040STobin Davis 		{ "ExtMic", 0x2 },
122382f30040STobin Davis 		{ "Line-In", 0x1 },
1224c9b443d4STobin Davis 	}
1225c9b443d4STobin Davis };
1226c9b443d4STobin Davis 
1227c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1228c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1229c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1230c9b443d4STobin Davis {
1231c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1232c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
123382f30040STobin Davis 	unsigned int bits;
1234c9b443d4STobin Davis 
123582f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1236c9b443d4STobin Davis 		return 0;
1237c9b443d4STobin Davis 
123882f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
123982f30040STobin Davis 	 * the headphone jack
124082f30040STobin Davis 	 */
124147fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12423b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12433b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12443b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12453b7523fcSTakashi Iwai 	 */
12465d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
124747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
124847fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
124947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
125047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1251c9b443d4STobin Davis 	return 1;
1252c9b443d4STobin Davis }
1253c9b443d4STobin Davis 
1254c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1255c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1256c9b443d4STobin Davis {
125782f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1258dd87da1cSTobin Davis 	unsigned int bits;
1259c9b443d4STobin Davis 
1260d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1261dd87da1cSTobin Davis 
126247fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12633b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12645d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
126547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1266c9b443d4STobin Davis }
1267c9b443d4STobin Davis 
1268c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1269c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1270c9b443d4STobin Davis {
127134cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
12729f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12739f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1274c9b443d4STobin Davis 		{}
1275c9b443d4STobin Davis 	};
127634cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
12779f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12789f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1279c9b443d4STobin Davis 		{}
1280c9b443d4STobin Davis 	};
1281c9b443d4STobin Davis 	unsigned int present;
1282c9b443d4STobin Davis 
1283d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1284c9b443d4STobin Davis 	if (present)
1285c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1286c9b443d4STobin Davis 	else
1287c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1288c9b443d4STobin Davis }
1289c9b443d4STobin Davis 
1290c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1291c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1292c9b443d4STobin Davis 				  unsigned int res)
1293c9b443d4STobin Davis {
12949f113e0eSMarc Boucher 	switch (res >> 26) {
1295c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1296c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1297c9b443d4STobin Davis 		break;
1298c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1299c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1300c9b443d4STobin Davis 		break;
1301c9b443d4STobin Davis 	}
1302c9b443d4STobin Davis }
1303c9b443d4STobin Davis 
130434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1305df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1306df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
13075f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1308c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1309c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1310c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1311c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
131282f30040STobin Davis 	{
131382f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
131482f30040STobin Davis 		.name = "Master Playback Switch",
131582f30040STobin Davis 		.info = cxt_eapd_info,
131682f30040STobin Davis 		.get = cxt_eapd_get,
1317c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1318c9b443d4STobin Davis 		.private_value = 0x13,
1319c9b443d4STobin Davis 	},
1320c9b443d4STobin Davis 
1321c9b443d4STobin Davis 	{}
1322c9b443d4STobin Davis };
1323c9b443d4STobin Davis 
132434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13253b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13265d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1327df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1328df481e41STakashi Iwai 	{}
1329df481e41STakashi Iwai };
1330df481e41STakashi Iwai 
133134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1332c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1333c9b443d4STobin Davis 	{ } /* end */
1334c9b443d4STobin Davis };
1335c9b443d4STobin Davis 
133634cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1337c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1338c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1339c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1340c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13417f29673bSTobin Davis 	/* HP, Speaker  */
1342b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13435b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13445b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13457f29673bSTobin Davis 	/* Record selector: Mic */
13467f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13477f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13487f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13497f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1350c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1351c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1352c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1353c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1354c9b443d4STobin Davis 	/* SPDIF route: PCM */
1355c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
135682f30040STobin Davis 	/* Enable unsolicited events */
135782f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
135882f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1359c9b443d4STobin Davis 	{ } /* end */
1360c9b443d4STobin Davis };
1361c9b443d4STobin Davis 
1362c9b443d4STobin Davis /* configuration for Toshiba Laptops */
136334cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13643b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1365c9b443d4STobin Davis 	{}
1366c9b443d4STobin Davis };
1367c9b443d4STobin Davis 
1368c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1369c9b443d4STobin Davis  * configuration.
1370c9b443d4STobin Davis  */
1371c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
137234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
137382f30040STobin Davis 	.num_items = 4,
1374c9b443d4STobin Davis 	.items = {
137582f30040STobin Davis 		{ "LINE1 pin", 0x0 },
137682f30040STobin Davis 		{ "MIC1 pin", 0x1 },
137782f30040STobin Davis 		{ "MIC2 pin", 0x2 },
137882f30040STobin Davis 		{ "CD pin", 0x3 },
1379c9b443d4STobin Davis         },
1380c9b443d4STobin Davis };
1381c9b443d4STobin Davis 
138234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1383c9b443d4STobin Davis 
1384c9b443d4STobin Davis 	/* Output only controls */
138582f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
138682f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
138782f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
138882f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1389c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1390c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1391c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1392c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
139382f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
139482f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
139582f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
139682f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1397c9b443d4STobin Davis 
1398c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1399c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1400c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1401c9b443d4STobin Davis 
140282f30040STobin Davis 	/* EAPD Switch Control */
140382f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
140482f30040STobin Davis 
1405c9b443d4STobin Davis 	/* Loopback mixer controls */
140682f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
140782f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
140882f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
140982f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
141082f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
141182f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
141282f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
141382f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1414c9b443d4STobin Davis 
141582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
141682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
141782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
141882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
141982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
142082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
142182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
142282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1423c9b443d4STobin Davis 	{
1424c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1425c9b443d4STobin Davis 		.name = "Input Source",
1426c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1427c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1428c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1429c9b443d4STobin Davis 	},
1430854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14319f113e0eSMarc Boucher 
1432c9b443d4STobin Davis 	{ } /* end */
1433c9b443d4STobin Davis };
1434c9b443d4STobin Davis 
143534cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1436c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1437c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1438c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1439c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1440c9b443d4STobin Davis 
1441c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1442c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1443c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1444c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1445c9b443d4STobin Davis 	 * control.
1446c9b443d4STobin Davis 	 */
1447c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1448c9b443d4STobin Davis 
1449c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1450c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1451c9b443d4STobin Davis 	 */
1452c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1453c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1454c9b443d4STobin Davis 
1455c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1456c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1457c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1458c9b443d4STobin Davis 
1459c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1460c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1461c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1462c9b443d4STobin Davis 	 * input/output buffers as needed.
1463c9b443d4STobin Davis 	 */
1464c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1465c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1466c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1467c9b443d4STobin Davis 
1468c9b443d4STobin Davis 	/* Mute capture amp left and right */
1469c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1470c9b443d4STobin Davis 
1471c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1472c9b443d4STobin Davis 	 * pin)
1473c9b443d4STobin Davis 	 */
1474c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1475c9b443d4STobin Davis 
1476c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1477c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1478c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1479c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1480c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1481c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1482c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1483c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1484c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1485c9b443d4STobin Davis 
1486c9b443d4STobin Davis 	{ }
1487c9b443d4STobin Davis };
1488c9b443d4STobin Davis #endif
1489c9b443d4STobin Davis 
1490c9b443d4STobin Davis 
1491c9b443d4STobin Davis /* initialize jack-sensing, too */
1492c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1493c9b443d4STobin Davis {
1494c9b443d4STobin Davis 	conexant_init(codec);
1495c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1496c9b443d4STobin Davis 	return 0;
1497c9b443d4STobin Davis }
1498c9b443d4STobin Davis 
1499c9b443d4STobin Davis 
1500c9b443d4STobin Davis enum {
1501f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1502f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1503f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1504c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1505c9b443d4STobin Davis 	CXT5047_TEST,
1506c9b443d4STobin Davis #endif
1507f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1508c9b443d4STobin Davis };
1509c9b443d4STobin Davis 
1510ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1511f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1512f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1513f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1514c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1515f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1516c9b443d4STobin Davis #endif
1517f5fcc13cSTakashi Iwai };
1518c9b443d4STobin Davis 
151934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1520ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1521dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1522dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1523f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1524c9b443d4STobin Davis 	{}
1525c9b443d4STobin Davis };
1526c9b443d4STobin Davis 
1527c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1528c9b443d4STobin Davis {
1529c9b443d4STobin Davis 	struct conexant_spec *spec;
1530c9b443d4STobin Davis 	int board_config;
1531c9b443d4STobin Davis 
1532c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1533c9b443d4STobin Davis 	if (!spec)
1534c9b443d4STobin Davis 		return -ENOMEM;
1535c9b443d4STobin Davis 	codec->spec = spec;
15369421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1537c9b443d4STobin Davis 
1538c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1539c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1540c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1541c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1542c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1543c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1544c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1545c9b443d4STobin Davis 	spec->num_mixers = 1;
1546df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1547c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1548c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1549c9b443d4STobin Davis 	spec->spdif_route = 0;
15505cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15515cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1552c9b443d4STobin Davis 
1553c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1554c9b443d4STobin Davis 
1555f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1556f5fcc13cSTakashi Iwai 						  cxt5047_models,
1557f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1558c9b443d4STobin Davis 	switch (board_config) {
1559c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1560df481e41STakashi Iwai 		spec->num_mixers = 2;
1561df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1562df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1563c9b443d4STobin Davis 		break;
1564c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1565df481e41STakashi Iwai 		spec->num_mixers = 2;
1566df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1567fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1568c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1569c9b443d4STobin Davis 		break;
1570c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
157182f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1572df481e41STakashi Iwai 		spec->num_mixers = 2;
1573df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1574c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1575c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1576fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1577c9b443d4STobin Davis 		break;
1578c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1579c9b443d4STobin Davis 	case CXT5047_TEST:
1580c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1581c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1582c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1583fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1584c9b443d4STobin Davis #endif
1585c9b443d4STobin Davis 	}
1586dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1587025f206cSDaniel T Chen 
1588025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1589025f206cSDaniel T Chen 	case 0x103c:
1590025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1591025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1592025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1593025f206cSDaniel T Chen 		 */
1594025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1595025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1596025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1597025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1598025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1599025f206cSDaniel T Chen 		break;
1600025f206cSDaniel T Chen 	}
1601025f206cSDaniel T Chen 
1602c9b443d4STobin Davis 	return 0;
1603c9b443d4STobin Davis }
1604c9b443d4STobin Davis 
1605461e2c78STakashi Iwai /* Conexant 5051 specific */
160634cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
160734cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1608461e2c78STakashi Iwai 
160934cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1610461e2c78STakashi Iwai 	{ 2, NULL },
1611461e2c78STakashi Iwai };
1612461e2c78STakashi Iwai 
1613461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1614461e2c78STakashi Iwai {
1615461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1616461e2c78STakashi Iwai 	unsigned int pinctl;
161723d2df5bSTakashi Iwai 	/* headphone pin */
161823d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
161923d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
162023d2df5bSTakashi Iwai 			    pinctl);
162123d2df5bSTakashi Iwai 	/* speaker pin */
1622461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1623461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1624461e2c78STakashi Iwai 			    pinctl);
1625f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1626f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1627f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1628f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1629f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1630461e2c78STakashi Iwai }
1631461e2c78STakashi Iwai 
1632461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1633461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1634461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1635461e2c78STakashi Iwai {
1636461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1637461e2c78STakashi Iwai 
1638461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1639461e2c78STakashi Iwai 		return 0;
1640461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1641461e2c78STakashi Iwai 	return 1;
1642461e2c78STakashi Iwai }
1643461e2c78STakashi Iwai 
1644461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1645461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1646461e2c78STakashi Iwai {
164779d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1648461e2c78STakashi Iwai 	unsigned int present;
1649461e2c78STakashi Iwai 
1650faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
165179d7d533STakashi Iwai 		return;
1652d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1653461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1654461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1655461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1656461e2c78STakashi Iwai }
1657461e2c78STakashi Iwai 
1658461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1659461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1660461e2c78STakashi Iwai {
1661461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1662461e2c78STakashi Iwai 	unsigned int present;
1663461e2c78STakashi Iwai 	hda_nid_t new_adc;
1664461e2c78STakashi Iwai 
1665faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
166679d7d533STakashi Iwai 		return;
1667d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1668461e2c78STakashi Iwai 	if (present)
1669461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1670461e2c78STakashi Iwai 	else
1671461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1672461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1673461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1674461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1675f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1676461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1677461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1678461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1679461e2c78STakashi Iwai 					   spec->cur_adc_format);
1680461e2c78STakashi Iwai 	}
1681461e2c78STakashi Iwai }
1682461e2c78STakashi Iwai 
1683461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1684461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1685461e2c78STakashi Iwai {
1686461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1687461e2c78STakashi Iwai 
1688d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1689461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1690461e2c78STakashi Iwai }
1691461e2c78STakashi Iwai 
1692461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1693461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1694461e2c78STakashi Iwai 				   unsigned int res)
1695461e2c78STakashi Iwai {
1696acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1697461e2c78STakashi Iwai 	switch (res >> 26) {
1698461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1699461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1700461e2c78STakashi Iwai 		break;
1701461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1702461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1703461e2c78STakashi Iwai 		break;
1704461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1705461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1706461e2c78STakashi Iwai 		break;
1707461e2c78STakashi Iwai 	}
1708cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
1709461e2c78STakashi Iwai }
1710461e2c78STakashi Iwai 
171134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1712461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1713461e2c78STakashi Iwai 	{
1714461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1715461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1716461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1717461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1718461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1719461e2c78STakashi Iwai 		.private_value = 0x1a,
1720461e2c78STakashi Iwai 	},
17212c7a3fb3STakashi Iwai 	{}
17222c7a3fb3STakashi Iwai };
1723461e2c78STakashi Iwai 
172434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17252c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17262c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17278607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17288607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
17292c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17302c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1731461e2c78STakashi Iwai 	{}
1732461e2c78STakashi Iwai };
1733461e2c78STakashi Iwai 
173434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1735461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1736461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17378607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
17388607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1739461e2c78STakashi Iwai 	{}
1740461e2c78STakashi Iwai };
1741461e2c78STakashi Iwai 
174234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
17434e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
17444e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
174579d7d533STakashi Iwai 	{}
174679d7d533STakashi Iwai };
174779d7d533STakashi Iwai 
174834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
17495f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
17505f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1751cd9d95a5SKen Prox 	{}
1752cd9d95a5SKen Prox };
1753cd9d95a5SKen Prox 
175434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1755faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1756faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17578607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
17588607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1759faddaa5dSTakashi Iwai 	{}
1760faddaa5dSTakashi Iwai };
1761faddaa5dSTakashi Iwai 
176234cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1763461e2c78STakashi Iwai 	/* Line in, Mic */
1764461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1765461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1766461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1767461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1768461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1769461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1770461e2c78STakashi Iwai 	/* SPK  */
1771461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1772461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1773461e2c78STakashi Iwai 	/* HP, Amp  */
1774461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1775461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1776461e2c78STakashi Iwai 	/* DAC1 */
1777461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
177828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1779461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1780461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1781461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1782461e2c78STakashi Iwai 	/* SPDIF route: PCM */
17831965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1784461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1785461e2c78STakashi Iwai 	/* EAPD */
1786461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1787461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1788461e2c78STakashi Iwai 	{ } /* end */
1789461e2c78STakashi Iwai };
1790461e2c78STakashi Iwai 
179134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
179279d7d533STakashi Iwai 	/* Line in, Mic */
179379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
179479d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
179579d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
179679d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
179779d7d533STakashi Iwai 	/* SPK  */
179879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
179979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
180079d7d533STakashi Iwai 	/* HP, Amp  */
180179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
180279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
180379d7d533STakashi Iwai 	/* DAC1 */
180479d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
180528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
180679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
180779d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
180879d7d533STakashi Iwai 	/* SPDIF route: PCM */
180979d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
181079d7d533STakashi Iwai 	/* EAPD */
181179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
181279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
181379d7d533STakashi Iwai 	{ } /* end */
181479d7d533STakashi Iwai };
181579d7d533STakashi Iwai 
181634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
181727e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
181827e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
181927e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
182027e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
182127e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
182227e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
182327e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
182427e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
182527e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
182627e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
182727e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
182827e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
182927e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
183027e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
183127e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
183227e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
183327e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
183427e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
183528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
183627e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
183727e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
183827e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
183927e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
18401965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
184127e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
184227e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
184327e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
184427e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
184527e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
184627e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
184727e08988SAristeu Sergio Rozanski Filho };
184827e08988SAristeu Sergio Rozanski Filho 
184934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1850cd9d95a5SKen Prox 	/* Line in, Mic */
185130ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1852cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1853cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1854cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1855cd9d95a5SKen Prox 	/* SPK  */
1856cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1857cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1858cd9d95a5SKen Prox 	/* HP, Amp  */
1859cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1860cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1861cd9d95a5SKen Prox 	/* DAC1 */
1862cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
186328c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1864cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1865cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1866cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1867cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1868cd9d95a5SKen Prox 	/* EAPD */
1869cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1870cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1871cd9d95a5SKen Prox 	{ } /* end */
1872cd9d95a5SKen Prox };
1873cd9d95a5SKen Prox 
18746953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
18756953e552STakashi Iwai 				 unsigned int event)
18766953e552STakashi Iwai {
18776953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
18786953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
18796953e552STakashi Iwai 			    AC_USRSP_EN | event);
1880cd372fb3STakashi Iwai 	snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
1881cd372fb3STakashi Iwai 	snd_hda_input_jack_report(codec, nid);
18826953e552STakashi Iwai }
18836953e552STakashi Iwai 
188434cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1885f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1886f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1887f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1888f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1889f7154de2SHerton Ronaldo Krzesinski };
1890f7154de2SHerton Ronaldo Krzesinski 
1891461e2c78STakashi Iwai /* initialize jack-sensing, too */
1892461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1893461e2c78STakashi Iwai {
18946953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
18956953e552STakashi Iwai 
1896461e2c78STakashi Iwai 	conexant_init(codec);
1897acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
18986953e552STakashi Iwai 
18996953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19006953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19016953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19026953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19036953e552STakashi Iwai 
1904461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1905461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1906461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1907461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1908461e2c78STakashi Iwai 	}
1909461e2c78STakashi Iwai 	return 0;
1910461e2c78STakashi Iwai }
1911461e2c78STakashi Iwai 
1912461e2c78STakashi Iwai 
1913461e2c78STakashi Iwai enum {
1914461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1915461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
191679d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19171965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1918cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1919faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1920f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
1921*6764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1922461e2c78STakashi Iwai 	CXT5051_MODELS
1923461e2c78STakashi Iwai };
1924461e2c78STakashi Iwai 
1925ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1926461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1927461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
192879d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
192927e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19305f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1931faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1932f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
1933*6764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1934461e2c78STakashi Iwai };
1935461e2c78STakashi Iwai 
193634cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
193779d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19381812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
19395f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1940faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1941461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1942461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1943461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
194427e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1945f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1946461e2c78STakashi Iwai 	{}
1947461e2c78STakashi Iwai };
1948461e2c78STakashi Iwai 
1949461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1950461e2c78STakashi Iwai {
1951461e2c78STakashi Iwai 	struct conexant_spec *spec;
1952461e2c78STakashi Iwai 	int board_config;
1953461e2c78STakashi Iwai 
1954*6764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1955*6764bcefSTakashi Iwai 						  cxt5051_models,
1956*6764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
1957*6764bcefSTakashi Iwai 	if (board_config < 0)
1958*6764bcefSTakashi Iwai 		board_config = CXT5051_AUTO;
1959*6764bcefSTakashi Iwai 	if (board_config == CXT5051_AUTO) {
1960*6764bcefSTakashi Iwai 		printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
1961*6764bcefSTakashi Iwai 		       codec->chip_name);
1962*6764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
1963*6764bcefSTakashi Iwai 	}
1964*6764bcefSTakashi Iwai 
1965461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1966461e2c78STakashi Iwai 	if (!spec)
1967461e2c78STakashi Iwai 		return -ENOMEM;
1968461e2c78STakashi Iwai 	codec->spec = spec;
19699421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1970461e2c78STakashi Iwai 
1971461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1972461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1973461e2c78STakashi Iwai 
1974461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1975461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1976461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1977461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1978461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1979461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
19802c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
19812c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
19822c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
1983461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1984461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1985461e2c78STakashi Iwai 	spec->spdif_route = 0;
1986461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1987461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1988461e2c78STakashi Iwai 	spec->cur_adc = 0;
1989461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1990461e2c78STakashi Iwai 
19913507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
19923507e2a8STakashi Iwai 
199379d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
199479d7d533STakashi Iwai 
1995faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1996461e2c78STakashi Iwai 	switch (board_config) {
1997461e2c78STakashi Iwai 	case CXT5051_HP:
1998461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1999461e2c78STakashi Iwai 		break;
200079d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
200179d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
200279d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2003faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
200479d7d533STakashi Iwai 		break;
200527e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
200627e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2007607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2008607bc3e4SJerone Young 		   to use a docking station. */
2009607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2010607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2011461e2c78STakashi Iwai 		break;
2012cd9d95a5SKen Prox 	case CXT5051_F700:
2013cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2014cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2015faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2016faddaa5dSTakashi Iwai 		break;
2017faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2018faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2019faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2020cd9d95a5SKen Prox 		break;
2021f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2022f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2023f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2024f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2025f7154de2SHerton Ronaldo Krzesinski 		break;
2026461e2c78STakashi Iwai 	}
2027461e2c78STakashi Iwai 
20283507e2a8STakashi Iwai 	if (spec->beep_amp)
20293507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20303507e2a8STakashi Iwai 
2031461e2c78STakashi Iwai 	return 0;
2032461e2c78STakashi Iwai }
2033461e2c78STakashi Iwai 
20340fb67e98SDaniel Drake /* Conexant 5066 specific */
20350fb67e98SDaniel Drake 
203634cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
203734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
203834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
203934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
20400fb67e98SDaniel Drake 
2041dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2042dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2043dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2044dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2045dbaccc0cSDaniel Drake 
204634cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
20470fb67e98SDaniel Drake 	{ 2, NULL },
20480fb67e98SDaniel Drake };
20490fb67e98SDaniel Drake 
2050a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
2051a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
2052a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
2053a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
2054a3de8ab8STakashi Iwai 
20550fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
20560fb67e98SDaniel Drake {
20570fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20580fb67e98SDaniel Drake 	unsigned int pinctl;
20590fb67e98SDaniel Drake 
20603a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
20613a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
20620fb67e98SDaniel Drake 
20630fb67e98SDaniel Drake 	/* Port A (HP) */
2064a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
20650fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20660fb67e98SDaniel Drake 			pinctl);
20670fb67e98SDaniel Drake 
20680fb67e98SDaniel Drake 	/* Port D (HP/LO) */
2069a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
2070a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
2071a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
2072a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
20733a253445SJohn Baboval 			pinctl = 0;
20743a253445SJohn Baboval 	} else {
2075a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
2076a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
2077a3de8ab8STakashi Iwai 			pinctl = 0;
20783a253445SJohn Baboval 	}
20790fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20800fb67e98SDaniel Drake 			pinctl);
20810fb67e98SDaniel Drake 
20820fb67e98SDaniel Drake 	/* CLASS_D AMP */
20830fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
20840fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20850fb67e98SDaniel Drake 			pinctl);
20860fb67e98SDaniel Drake }
20870fb67e98SDaniel Drake 
20880fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
20890fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
20900fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
20910fb67e98SDaniel Drake {
20920fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
20930fb67e98SDaniel Drake 
20940fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
20950fb67e98SDaniel Drake 		return 0;
20960fb67e98SDaniel Drake 
20970fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
20980fb67e98SDaniel Drake 	return 1;
20990fb67e98SDaniel Drake }
21000fb67e98SDaniel Drake 
2101c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2102c4cfe66cSDaniel Drake 	.num_items = 3,
2103c4cfe66cSDaniel Drake 	.items = {
2104c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2105c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2106c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2107c4cfe66cSDaniel Drake 	},
2108c4cfe66cSDaniel Drake };
2109c4cfe66cSDaniel Drake 
2110c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2111c4cfe66cSDaniel Drake {
2112c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2113c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2114c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2115c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2116c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2117c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2118c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2119c4cfe66cSDaniel Drake }
2120c4cfe66cSDaniel Drake 
212175f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
212275f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
212375f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
212475f8991dSDaniel Drake  * is happening when it is not. */
212575f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21260fb67e98SDaniel Drake {
2127dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
212875f8991dSDaniel Drake 	if (!spec->recording)
212975f8991dSDaniel Drake 		return;
21300fb67e98SDaniel Drake 
2131c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2132c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2133c4cfe66cSDaniel Drake 		 * through our special DC port */
2134c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2135c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2136c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2137c4cfe66cSDaniel Drake 
2138c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2139c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2140c4cfe66cSDaniel Drake 			{},
2141c4cfe66cSDaniel Drake 		};
2142c4cfe66cSDaniel Drake 
2143c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2144c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2145c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2146c4cfe66cSDaniel Drake 		return;
2147c4cfe66cSDaniel Drake 	}
2148c4cfe66cSDaniel Drake 
2149c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2150c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2151c4cfe66cSDaniel Drake 
215275f8991dSDaniel Drake 	/* external mic, port B */
215375f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
215475f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
21550fb67e98SDaniel Drake 
215675f8991dSDaniel Drake 	/* internal mic, port C */
215775f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
215875f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
215975f8991dSDaniel Drake }
21600fb67e98SDaniel Drake 
216175f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
216275f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
216375f8991dSDaniel Drake {
216475f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
21650fb67e98SDaniel Drake 	unsigned int present;
21660fb67e98SDaniel Drake 
2167c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2168c4cfe66cSDaniel Drake 		return;
2169c4cfe66cSDaniel Drake 
217075f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
217175f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
217275f8991dSDaniel Drake 	if (present)
21730fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
217475f8991dSDaniel Drake 	else
21750fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
217675f8991dSDaniel Drake 
217775f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
217875f8991dSDaniel Drake 		present ? 0 : 1);
217975f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
218075f8991dSDaniel Drake 
218175f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
21820fb67e98SDaniel Drake }
21830fb67e98SDaniel Drake 
218495a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
218595a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
218695a618bdSEinar Rünkaru {
218795a618bdSEinar Rünkaru 	unsigned int present;
218895a618bdSEinar Rünkaru 
218995a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
219095a618bdSEinar Rünkaru 		/* enable external mic, port B */
219175f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
219295a618bdSEinar Rünkaru 
219395a618bdSEinar Rünkaru 		/* switch to external mic input */
219495a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
219595a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
219695a618bdSEinar Rünkaru 
219795a618bdSEinar Rünkaru 		/* disable internal digital mic */
219895a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
219995a618bdSEinar Rünkaru 		{}
220095a618bdSEinar Rünkaru 	};
220134cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
220295a618bdSEinar Rünkaru 		/* enable internal mic, port C */
220395a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
220495a618bdSEinar Rünkaru 
220595a618bdSEinar Rünkaru 		/* switch to internal mic input */
220695a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
220795a618bdSEinar Rünkaru 
220895a618bdSEinar Rünkaru 		/* disable external mic, port B */
220995a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
221095a618bdSEinar Rünkaru 		{}
221195a618bdSEinar Rünkaru 	};
221295a618bdSEinar Rünkaru 
221395a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
221495a618bdSEinar Rünkaru 	if (present) {
221595a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
221695a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
221795a618bdSEinar Rünkaru 	} else {
221895a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
221995a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
222095a618bdSEinar Rünkaru 	}
222195a618bdSEinar Rünkaru }
222295a618bdSEinar Rünkaru 
2223cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2224cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2225cfd3d8dcSGreg Alexander {
2226cfd3d8dcSGreg Alexander 	unsigned int present;
2227cfd3d8dcSGreg Alexander 
2228cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2229cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2230cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2231cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2232cfd3d8dcSGreg Alexander 		{}
2233cfd3d8dcSGreg Alexander 	};
223434cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2235cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2236cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2237cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2238cfd3d8dcSGreg Alexander 		{}
2239cfd3d8dcSGreg Alexander 	};
2240cfd3d8dcSGreg Alexander 
2241cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2242cfd3d8dcSGreg Alexander 	if (present) {
2243cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2244cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2245cfd3d8dcSGreg Alexander 	} else {
2246cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2247cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2248cfd3d8dcSGreg Alexander 	}
2249cfd3d8dcSGreg Alexander }
2250cfd3d8dcSGreg Alexander 
2251a1d6906eSDavid Henningsson 
2252a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2253a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2254a1d6906eSDavid Henningsson {
2255a1d6906eSDavid Henningsson 	unsigned int present;
2256a1d6906eSDavid Henningsson 
2257a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2258a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2259a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2260a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2261a1d6906eSDavid Henningsson }
2262a1d6906eSDavid Henningsson 
2263a1d6906eSDavid Henningsson 
2264048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2265048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2266048e78a5SDavid Henningsson {
2267048e78a5SDavid Henningsson 	unsigned int present;
2268048e78a5SDavid Henningsson 
2269048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2270048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2271048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2272048e78a5SDavid Henningsson 			    present ? 1 : 3);
2273048e78a5SDavid Henningsson }
2274048e78a5SDavid Henningsson 
2275048e78a5SDavid Henningsson 
22767b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
22777b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
22787b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
22797b2bfdbcSJens Taprogge {
22807b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
22817b2bfdbcSJens Taprogge 
228234cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
22837b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
22847b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
22857b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
22867b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22877b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22887b2bfdbcSJens Taprogge 		{}
22897b2bfdbcSJens Taprogge 	};
229034cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
22917b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
22927b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
22937b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
22947b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22957b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22967b2bfdbcSJens Taprogge 		{}
22977b2bfdbcSJens Taprogge 	};
229834cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
22997b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23007b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23017b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23027b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23037b2bfdbcSJens Taprogge 		{}
23047b2bfdbcSJens Taprogge 	};
23057b2bfdbcSJens Taprogge 
23067b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23077b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23087b2bfdbcSJens Taprogge 	if (ext_present) {
23097b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23107b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23117b2bfdbcSJens Taprogge 	} else if (dock_present) {
23127b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23137b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23147b2bfdbcSJens Taprogge 	} else {
23157b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23167b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23177b2bfdbcSJens Taprogge 	}
23187b2bfdbcSJens Taprogge }
23197b2bfdbcSJens Taprogge 
23200fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23210fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23220fb67e98SDaniel Drake {
23230fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23240fb67e98SDaniel Drake 	unsigned int portA, portD;
23250fb67e98SDaniel Drake 
23260fb67e98SDaniel Drake 	/* Port A */
2327d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23280fb67e98SDaniel Drake 
23290fb67e98SDaniel Drake 	/* Port D */
2330d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23310fb67e98SDaniel Drake 
2332a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2333a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
23340fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23350fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23360fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23370fb67e98SDaniel Drake }
23380fb67e98SDaniel Drake 
233902b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
234002b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
234102b6b5b6SDavid Henningsson {
234202b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
234302b6b5b6SDavid Henningsson 
234402b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
234502b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
234602b6b5b6SDavid Henningsson 	else if (spec->ideapad)
234702b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
234802b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
234902b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
235002b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
235102b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2352a1d6906eSDavid Henningsson 	else if (spec->asus)
2353a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
235402b6b5b6SDavid Henningsson }
235502b6b5b6SDavid Henningsson 
23560fb67e98SDaniel Drake /* unsolicited event for jack sensing */
235775f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23580fb67e98SDaniel Drake {
2359c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23600fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23610fb67e98SDaniel Drake 	switch (res >> 26) {
23620fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
23630fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
23640fb67e98SDaniel Drake 		break;
23650fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2366c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2367c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
236875f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
23690fb67e98SDaniel Drake 		break;
23700fb67e98SDaniel Drake 	}
23710fb67e98SDaniel Drake }
23720fb67e98SDaniel Drake 
237395a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
237402b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
237595a618bdSEinar Rünkaru {
237602b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
237795a618bdSEinar Rünkaru 	switch (res >> 26) {
237895a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
237995a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
238095a618bdSEinar Rünkaru 		break;
238195a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
238202b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
238395a618bdSEinar Rünkaru 		break;
238495a618bdSEinar Rünkaru 	}
238595a618bdSEinar Rünkaru }
238695a618bdSEinar Rünkaru 
23877b2bfdbcSJens Taprogge 
23880fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
23890fb67e98SDaniel Drake 	.num_items = 5,
23900fb67e98SDaniel Drake 	.items = {
23910fb67e98SDaniel Drake 		{ "0dB",  0 },
23920fb67e98SDaniel Drake 		{ "10dB", 1 },
23930fb67e98SDaniel Drake 		{ "20dB", 2 },
23940fb67e98SDaniel Drake 		{ "30dB", 3 },
23950fb67e98SDaniel Drake 		{ "40dB", 4 },
23960fb67e98SDaniel Drake 	},
23970fb67e98SDaniel Drake };
23980fb67e98SDaniel Drake 
2399cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2400c4cfe66cSDaniel Drake {
2401c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2402cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2403c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2404c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2405c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24067b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2407cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2408cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2409cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2410cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2411cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2412cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2413cfd3d8dcSGreg Alexander 	}
2414c4cfe66cSDaniel Drake }
2415c4cfe66cSDaniel Drake 
24160fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24170fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24180fb67e98SDaniel Drake {
24190fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24200fb67e98SDaniel Drake }
24210fb67e98SDaniel Drake 
24220fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24230fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24240fb67e98SDaniel Drake {
24250fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2426c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2427c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24280fb67e98SDaniel Drake 	return 0;
24290fb67e98SDaniel Drake }
24300fb67e98SDaniel Drake 
24310fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24320fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24330fb67e98SDaniel Drake {
24340fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2435c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24360fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24370fb67e98SDaniel Drake 	unsigned int idx;
24380fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24390fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24400fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24410fb67e98SDaniel Drake 
2442c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2443c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2444c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2445c4cfe66cSDaniel Drake 	return 1;
2446c4cfe66cSDaniel Drake }
24470fb67e98SDaniel Drake 
2448c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2449c4cfe66cSDaniel Drake {
2450c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2451c4cfe66cSDaniel Drake 		/* disable gain */
2452c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2453c4cfe66cSDaniel Drake 
2454c4cfe66cSDaniel Drake 		/* switch to DC input */
2455c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2456c4cfe66cSDaniel Drake 		{}
2457c4cfe66cSDaniel Drake 	};
2458c4cfe66cSDaniel Drake 
2459c4cfe66cSDaniel Drake 	/* configure as input source */
2460c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2461c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2462c4cfe66cSDaniel Drake }
2463c4cfe66cSDaniel Drake 
2464c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2465c4cfe66cSDaniel Drake {
2466c4cfe66cSDaniel Drake 	/* reconfigure input source */
2467c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2468c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2469c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2470c4cfe66cSDaniel Drake }
2471c4cfe66cSDaniel Drake 
2472c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2473c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2474c4cfe66cSDaniel Drake {
2475c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2476c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2477c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2478c4cfe66cSDaniel Drake 	return 0;
2479c4cfe66cSDaniel Drake }
2480c4cfe66cSDaniel Drake 
2481c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2482c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2483c4cfe66cSDaniel Drake {
2484c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2485c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2486c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2487c4cfe66cSDaniel Drake 
2488c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2489c4cfe66cSDaniel Drake 		return 0;
2490c4cfe66cSDaniel Drake 
2491c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2492c4cfe66cSDaniel Drake 	if (dc_enable)
2493c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2494c4cfe66cSDaniel Drake 	else
2495c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2496c4cfe66cSDaniel Drake 
2497c4cfe66cSDaniel Drake 	return 1;
2498c4cfe66cSDaniel Drake }
2499c4cfe66cSDaniel Drake 
2500c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2501c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2502c4cfe66cSDaniel Drake {
2503c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2504c4cfe66cSDaniel Drake }
2505c4cfe66cSDaniel Drake 
2506c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2507c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2508c4cfe66cSDaniel Drake {
2509c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2510c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2511c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2512c4cfe66cSDaniel Drake 	return 0;
2513c4cfe66cSDaniel Drake }
2514c4cfe66cSDaniel Drake 
2515c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2516c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2517c4cfe66cSDaniel Drake {
2518c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2519c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2520c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2521c4cfe66cSDaniel Drake 	unsigned int idx;
2522c4cfe66cSDaniel Drake 
2523c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2524c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2525c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2526c4cfe66cSDaniel Drake 
2527c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2528c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2529c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25300fb67e98SDaniel Drake 	return 1;
25310fb67e98SDaniel Drake }
25320fb67e98SDaniel Drake 
253375f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
253475f8991dSDaniel Drake {
253575f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
253675f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
253775f8991dSDaniel Drake 	 * recording LED comes on. */
253875f8991dSDaniel Drake 	spec->recording = 1;
253975f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
254075f8991dSDaniel Drake }
254175f8991dSDaniel Drake 
254275f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
254375f8991dSDaniel Drake {
254475f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
254575f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
254675f8991dSDaniel Drake 		/* disable external mic, port B */
254775f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
254875f8991dSDaniel Drake 
254975f8991dSDaniel Drake 		/* disble internal mic, port C */
255075f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2551c4cfe66cSDaniel Drake 
2552c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2553c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
255475f8991dSDaniel Drake 		{},
255575f8991dSDaniel Drake 	};
255675f8991dSDaniel Drake 
255775f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
255875f8991dSDaniel Drake 	spec->recording = 0;
255975f8991dSDaniel Drake }
256075f8991dSDaniel Drake 
2561f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
256234cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2563f6a2491cSAndy Robinson 				    int num_pins)
2564f6a2491cSAndy Robinson {
2565f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2566f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2567f6a2491cSAndy Robinson 	int i;
2568f6a2491cSAndy Robinson 
2569f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2570f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2571f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2572f6a2491cSAndy Robinson 			continue;
2573f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2574f6a2491cSAndy Robinson 			continue;
2575f6a2491cSAndy Robinson 		if (spec->slave_dig_outs[0])
2576f6a2491cSAndy Robinson 			nid_loc++;
2577f6a2491cSAndy Robinson 		else
2578f6a2491cSAndy Robinson 			nid_loc = spec->slave_dig_outs;
2579f6a2491cSAndy Robinson 	}
2580f6a2491cSAndy Robinson }
2581f6a2491cSAndy Robinson 
258234cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
25830fb67e98SDaniel Drake 	.num_items = 4,
25840fb67e98SDaniel Drake 	.items = {
25850fb67e98SDaniel Drake 		{ "Mic B", 0 },
25860fb67e98SDaniel Drake 		{ "Mic C", 1 },
25870fb67e98SDaniel Drake 		{ "Mic E", 2 },
25880fb67e98SDaniel Drake 		{ "Mic F", 3 },
25890fb67e98SDaniel Drake 	},
25900fb67e98SDaniel Drake };
25910fb67e98SDaniel Drake 
259234cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
25930fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
25940fb67e98SDaniel Drake 	.values = {
25950fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
25960fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
25970fb67e98SDaniel Drake 		0
25980fb67e98SDaniel Drake 	},
25990fb67e98SDaniel Drake };
26000fb67e98SDaniel Drake 
260134cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26020fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26030fb67e98SDaniel Drake 	.values = {
26040fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26050fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26060fb67e98SDaniel Drake 		0
26070fb67e98SDaniel Drake 	},
26080fb67e98SDaniel Drake };
26090fb67e98SDaniel Drake 
261034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
26110fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26120fb67e98SDaniel Drake 	{}
26130fb67e98SDaniel Drake };
26140fb67e98SDaniel Drake 
261534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26160fb67e98SDaniel Drake 	{
26170fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26180fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26190fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26200fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26210fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26225e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26230fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26240fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26250fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26260fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26270fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26280fb67e98SDaniel Drake 		.private_value =
26290fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26300fb67e98SDaniel Drake 	},
26310fb67e98SDaniel Drake 	{}
26320fb67e98SDaniel Drake };
26330fb67e98SDaniel Drake 
263434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2635c4cfe66cSDaniel Drake 	{
2636c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2637c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2638c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2639c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2640c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2641c4cfe66cSDaniel Drake 	},
2642c4cfe66cSDaniel Drake 	{
2643c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2644c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2645c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2646c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2647c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2648c4cfe66cSDaniel Drake 	},
2649c4cfe66cSDaniel Drake 	{}
2650c4cfe66cSDaniel Drake };
2651c4cfe66cSDaniel Drake 
265234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
26530fb67e98SDaniel Drake 	{
26540fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26550fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26560fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26570fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26580fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26590fb67e98SDaniel Drake 		.private_value = 0x1d,
26600fb67e98SDaniel Drake 	},
26610fb67e98SDaniel Drake 
26620fb67e98SDaniel Drake 	{
26630fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2664c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
26650fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
26660fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
26670fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
26680fb67e98SDaniel Drake 	},
26690fb67e98SDaniel Drake 
26700fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
26710fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
26720fb67e98SDaniel Drake 	{}
26730fb67e98SDaniel Drake };
26740fb67e98SDaniel Drake 
267534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2676254bba6aSEinar Rünkaru 	{
2677254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
267828c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2679254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2680254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2681254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2682254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2683254bba6aSEinar Rünkaru 	},
2684254bba6aSEinar Rünkaru 	{}
2685254bba6aSEinar Rünkaru };
2686254bba6aSEinar Rünkaru 
268734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
26880fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
26890fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
26900fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
26910fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
26920fb67e98SDaniel Drake 
26930fb67e98SDaniel Drake 	/* Speakers  */
26940fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26950fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26960fb67e98SDaniel Drake 
26970fb67e98SDaniel Drake 	/* HP, Amp  */
26980fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
26990fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27000fb67e98SDaniel Drake 
27010fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27020fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27030fb67e98SDaniel Drake 
27040fb67e98SDaniel Drake 	/* DAC1 */
27050fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27060fb67e98SDaniel Drake 
27070fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27080fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27090fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27100fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27110fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27120fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27130fb67e98SDaniel Drake 
27140fb67e98SDaniel Drake 	/* no digital microphone support yet */
27150fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27160fb67e98SDaniel Drake 
27170fb67e98SDaniel Drake 	/* Audio input selector */
27180fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27190fb67e98SDaniel Drake 
27200fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27210fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27220fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27230fb67e98SDaniel Drake 
27240fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27250fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27260fb67e98SDaniel Drake 
27270fb67e98SDaniel Drake 	/* EAPD */
27280fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27290fb67e98SDaniel Drake 
27300fb67e98SDaniel Drake 	/* not handling these yet */
27310fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27320fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27330fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27340fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27350fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27360fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27370fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27380fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27390fb67e98SDaniel Drake 	{ } /* end */
27400fb67e98SDaniel Drake };
27410fb67e98SDaniel Drake 
274234cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = {
27430fb67e98SDaniel Drake 	/* Port A: headphones */
27440fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27450fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27460fb67e98SDaniel Drake 
27470fb67e98SDaniel Drake 	/* Port B: external microphone */
274875f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27490fb67e98SDaniel Drake 
27500fb67e98SDaniel Drake 	/* Port C: internal microphone */
275175f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27520fb67e98SDaniel Drake 
27530fb67e98SDaniel Drake 	/* Port D: unused */
27540fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27550fb67e98SDaniel Drake 
27560fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27570fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27580fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27590fb67e98SDaniel Drake 
2760c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27610fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27620fb67e98SDaniel Drake 
27630fb67e98SDaniel Drake 	/* Port G: internal speakers */
27640fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27650fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27660fb67e98SDaniel Drake 
27670fb67e98SDaniel Drake 	/* DAC1 */
27680fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27690fb67e98SDaniel Drake 
27700fb67e98SDaniel Drake 	/* DAC2: unused */
27710fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
27720fb67e98SDaniel Drake 
27730fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27740fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27750fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27760fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27770fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27780fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27790fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27800fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27810fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27820fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27830fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27840fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27850fb67e98SDaniel Drake 
27860fb67e98SDaniel Drake 	/* Disable digital microphone port */
27870fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27880fb67e98SDaniel Drake 
27890fb67e98SDaniel Drake 	/* Audio input selectors */
27900fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27910fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
27920fb67e98SDaniel Drake 
27930fb67e98SDaniel Drake 	/* Disable SPDIF */
27940fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27950fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27960fb67e98SDaniel Drake 
27970fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
27980fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
27990fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28000fb67e98SDaniel Drake 	{ } /* end */
28010fb67e98SDaniel Drake };
28020fb67e98SDaniel Drake 
280334cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
280495a618bdSEinar Rünkaru 	/* Port A: headphones */
280595a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
280695a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
280795a618bdSEinar Rünkaru 
280895a618bdSEinar Rünkaru 	/* Port B: external microphone */
280995a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
281095a618bdSEinar Rünkaru 
281195a618bdSEinar Rünkaru 	/* Port C: unused */
281295a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
281395a618bdSEinar Rünkaru 
281495a618bdSEinar Rünkaru 	/* Port D: unused */
281595a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
281695a618bdSEinar Rünkaru 
281795a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
281895a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
281995a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
282095a618bdSEinar Rünkaru 
282195a618bdSEinar Rünkaru 	/* Port F: unused */
282295a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
282395a618bdSEinar Rünkaru 
282495a618bdSEinar Rünkaru 	/* Port G: internal speakers */
282595a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
282695a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
282795a618bdSEinar Rünkaru 
282895a618bdSEinar Rünkaru 	/* DAC1 */
282995a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
283095a618bdSEinar Rünkaru 
283195a618bdSEinar Rünkaru 	/* DAC2: unused */
283295a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
283395a618bdSEinar Rünkaru 
283495a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
283595a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
283695a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
283795a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
283895a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
283995a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
284095a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
284195a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
284295a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
284395a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
284495a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
284595a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
284695a618bdSEinar Rünkaru 
284795a618bdSEinar Rünkaru 	/* Digital microphone port */
284895a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
284995a618bdSEinar Rünkaru 
285095a618bdSEinar Rünkaru 	/* Audio input selectors */
285195a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
285295a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
285395a618bdSEinar Rünkaru 
285495a618bdSEinar Rünkaru 	/* Disable SPDIF */
285595a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285695a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
285795a618bdSEinar Rünkaru 
285895a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
285995a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
286095a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
286195a618bdSEinar Rünkaru 	{ } /* end */
286295a618bdSEinar Rünkaru };
286395a618bdSEinar Rünkaru 
286434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2865cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2866cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2867cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2868cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2869cfd3d8dcSGreg Alexander 
2870cfd3d8dcSGreg Alexander 	/* Speakers  */
2871cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2872cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2873cfd3d8dcSGreg Alexander 
2874cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2875cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2876cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2877cfd3d8dcSGreg Alexander 
2878cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2879cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2880cfd3d8dcSGreg Alexander 
2881cfd3d8dcSGreg Alexander 	/* DAC1 */
2882cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2883cfd3d8dcSGreg Alexander 
2884cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2885cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2886cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2887cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2888cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2889cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2890cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2891cfd3d8dcSGreg Alexander 
2892cfd3d8dcSGreg Alexander 	/* Audio input selector */
2893cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2894cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2895cfd3d8dcSGreg Alexander 
2896cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2897cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2898cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2899cfd3d8dcSGreg Alexander 
2900cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2901cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2902cfd3d8dcSGreg Alexander 
2903cfd3d8dcSGreg Alexander 	/* internal microphone */
290428c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2905cfd3d8dcSGreg Alexander 
2906cfd3d8dcSGreg Alexander 	/* EAPD */
2907cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2908cfd3d8dcSGreg Alexander 
2909cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2910cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2911cfd3d8dcSGreg Alexander 	{ } /* end */
2912cfd3d8dcSGreg Alexander };
2913cfd3d8dcSGreg Alexander 
291434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29157b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29167b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29177b2bfdbcSJens Taprogge 
29187b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29197b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29207b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29217b2bfdbcSJens Taprogge 
29227b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29237b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29247b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29257b2bfdbcSJens Taprogge 
29267b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29277b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29287b2bfdbcSJens Taprogge 
29297b2bfdbcSJens Taprogge 	/* Port C: Mic */
29307b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29317b2bfdbcSJens Taprogge 
29327b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29337b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29347b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29357b2bfdbcSJens Taprogge 
29367b2bfdbcSJens Taprogge 	/* DAC1 */
29377b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29387b2bfdbcSJens Taprogge 
29397b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29407b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29417b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29427b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29437b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29447b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29457b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29467b2bfdbcSJens Taprogge 
29477b2bfdbcSJens Taprogge 	/* Audio input selector */
29487b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29497b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29507b2bfdbcSJens Taprogge 
29517b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29527b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29537b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29547b2bfdbcSJens Taprogge 
29557b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29567b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29577b2bfdbcSJens Taprogge 
29587b2bfdbcSJens Taprogge 	/* internal microphone */
295928c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
29607b2bfdbcSJens Taprogge 
29617b2bfdbcSJens Taprogge 	/* EAPD */
29627b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
29637b2bfdbcSJens Taprogge 
29647b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
29657b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29667b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29677b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29687b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29697b2bfdbcSJens Taprogge 	{ } /* end */
29707b2bfdbcSJens Taprogge };
29717b2bfdbcSJens Taprogge 
297234cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
29730fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29740fb67e98SDaniel Drake 	{ } /* end */
29750fb67e98SDaniel Drake };
29760fb67e98SDaniel Drake 
2977048e78a5SDavid Henningsson 
297834cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2979048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2980048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2981048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2982048e78a5SDavid Henningsson 	{ } /* end */
2983048e78a5SDavid Henningsson };
2984048e78a5SDavid Henningsson 
29850fb67e98SDaniel Drake /* initialize jack-sensing, too */
29860fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
29870fb67e98SDaniel Drake {
29880fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
29890fb67e98SDaniel Drake 	conexant_init(codec);
29900fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
29910fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
299202b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
29930fb67e98SDaniel Drake 	}
2994c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
29950fb67e98SDaniel Drake 	return 0;
29960fb67e98SDaniel Drake }
29970fb67e98SDaniel Drake 
299875f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
299975f8991dSDaniel Drake {
3000c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
300175f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
300275f8991dSDaniel Drake 	conexant_init(codec);
300375f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3004c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3005c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
300675f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3007c4cfe66cSDaniel Drake 	} else {
3008c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3009c4cfe66cSDaniel Drake 	}
301075f8991dSDaniel Drake 	return 0;
301175f8991dSDaniel Drake }
301275f8991dSDaniel Drake 
30130fb67e98SDaniel Drake enum {
30140fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30150fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30160fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
30171feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
3018cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30197b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
3020a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
3021048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
30220fb67e98SDaniel Drake 	CXT5066_MODELS
30230fb67e98SDaniel Drake };
30240fb67e98SDaniel Drake 
3025ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
30260fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30270fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30280fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
30291feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
3030cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30317b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
3032a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
3033048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
30340fb67e98SDaniel Drake };
30350fb67e98SDaniel Drake 
303634cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
303700cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
30381feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
30398a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
3040ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
30411feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
3042231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3043ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
3044ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
3045048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
3046f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
3047a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
3048f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
30492ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
3050c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30514442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30525637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30535637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
30545637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
30554d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
3056ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
305719593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
30587b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
305984012657SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3060b2cb1292SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3061a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
306222f21d51SDavid Henningsson 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
30630fb67e98SDaniel Drake 	{}
30640fb67e98SDaniel Drake };
30650fb67e98SDaniel Drake 
30660fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
30670fb67e98SDaniel Drake {
30680fb67e98SDaniel Drake 	struct conexant_spec *spec;
30690fb67e98SDaniel Drake 	int board_config;
30700fb67e98SDaniel Drake 
30710fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
30720fb67e98SDaniel Drake 	if (!spec)
30730fb67e98SDaniel Drake 		return -ENOMEM;
30740fb67e98SDaniel Drake 	codec->spec = spec;
30750fb67e98SDaniel Drake 
30760fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
307775f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
30780fb67e98SDaniel Drake 
30790fb67e98SDaniel Drake 	spec->dell_automute = 0;
30800fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
30810fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
30820fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
3083f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
3084f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
30850fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
30860fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
30870fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
30880fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
30890fb67e98SDaniel Drake 
30900fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
30910fb67e98SDaniel Drake 
30920fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
30930fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
30940fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
30950fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
30960fb67e98SDaniel Drake 	spec->cur_adc = 0;
30970fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
30980fb67e98SDaniel Drake 
30993507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31003507e2a8STakashi Iwai 
31010fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
31020fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
31030fb67e98SDaniel Drake 	switch (board_config) {
31040fb67e98SDaniel Drake 	default:
31050fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31060fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31070fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31080fb67e98SDaniel Drake 		break;
31090fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31100fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31110fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31120fb67e98SDaniel Drake 
31130fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31140fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31150fb67e98SDaniel Drake 		spec->num_init_verbs++;
31160fb67e98SDaniel Drake 		spec->dell_automute = 1;
31170fb67e98SDaniel Drake 		break;
3118a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3119048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3120048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
312102b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3122048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3123048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3124048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3125a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3126a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3127048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3128048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3129048e78a5SDavid Henningsson 		/* no S/PDIF out */
3130f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3131048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3132048e78a5SDavid Henningsson 		/* input source automatically selected */
3133048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3134048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3135048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3136048e78a5SDavid Henningsson 		break;
3137048e78a5SDavid Henningsson 
31380fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
313975f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
314075f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31410fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31420fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3143c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31440fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31450fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3146c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31470fb67e98SDaniel Drake 
31480fb67e98SDaniel Drake 		/* no S/PDIF out */
31490fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31500fb67e98SDaniel Drake 
31510fb67e98SDaniel Drake 		/* input source automatically selected */
31520fb67e98SDaniel Drake 		spec->input_mux = NULL;
315375f8991dSDaniel Drake 
315475f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
315575f8991dSDaniel Drake 		 * at the right time */
315675f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
315775f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
31580fb67e98SDaniel Drake 		break;
31591feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
316075f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
316102b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
316295a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
316395a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
316495a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3165254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
316695a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3167254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3168c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
316995a618bdSEinar Rünkaru 
317095a618bdSEinar Rünkaru 		/* no S/PDIF out */
317195a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
317295a618bdSEinar Rünkaru 
317395a618bdSEinar Rünkaru 		/* input source automatically selected */
317495a618bdSEinar Rünkaru 		spec->input_mux = NULL;
317595a618bdSEinar Rünkaru 		break;
3176cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3177cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
317802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3179cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3180cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3181cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3182cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3183cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3184cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3185cfd3d8dcSGreg Alexander 
3186cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3187cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3188cfd3d8dcSGreg Alexander 
3189cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3190cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3191cfd3d8dcSGreg Alexander 		break;
31927b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
31937b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
319402b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
31957b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31967b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31977b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
31987b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
31997b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
32007b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
32017b2bfdbcSJens Taprogge 
32027b2bfdbcSJens Taprogge 		/* no S/PDIF out */
32037b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
32047b2bfdbcSJens Taprogge 
32057b2bfdbcSJens Taprogge 		/* input source automatically selected */
32067b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
32077b2bfdbcSJens Taprogge 		break;
32080fb67e98SDaniel Drake 	}
32090fb67e98SDaniel Drake 
32103507e2a8STakashi Iwai 	if (spec->beep_amp)
32113507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
32123507e2a8STakashi Iwai 
32130fb67e98SDaniel Drake 	return 0;
32140fb67e98SDaniel Drake }
3215461e2c78STakashi Iwai 
3216461e2c78STakashi Iwai /*
3217f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3218f2e5731dSTakashi Iwai  */
3219f2e5731dSTakashi Iwai 
3220*6764bcefSTakashi Iwai static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
3221*6764bcefSTakashi Iwai 				       struct hda_codec *codec,
3222*6764bcefSTakashi Iwai 				       unsigned int stream_tag,
3223*6764bcefSTakashi Iwai 				       unsigned int format,
3224*6764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
3225*6764bcefSTakashi Iwai {
3226*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3227*6764bcefSTakashi Iwai 	hda_nid_t adc = spec->imux_adcs[spec->cur_mux[0]];
3228*6764bcefSTakashi Iwai 	if (spec->adc_switching) {
3229*6764bcefSTakashi Iwai 		spec->cur_adc = adc;
3230*6764bcefSTakashi Iwai 		spec->cur_adc_stream_tag = stream_tag;
3231*6764bcefSTakashi Iwai 		spec->cur_adc_format = format;
3232*6764bcefSTakashi Iwai 	}
3233*6764bcefSTakashi Iwai 	snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
3234*6764bcefSTakashi Iwai 	return 0;
3235*6764bcefSTakashi Iwai }
3236*6764bcefSTakashi Iwai 
3237*6764bcefSTakashi Iwai static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
3238*6764bcefSTakashi Iwai 				       struct hda_codec *codec,
3239*6764bcefSTakashi Iwai 				       struct snd_pcm_substream *substream)
3240*6764bcefSTakashi Iwai {
3241*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3242*6764bcefSTakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
3243*6764bcefSTakashi Iwai 	spec->cur_adc = 0;
3244*6764bcefSTakashi Iwai 	return 0;
3245*6764bcefSTakashi Iwai }
3246*6764bcefSTakashi Iwai 
3247*6764bcefSTakashi Iwai static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
3248*6764bcefSTakashi Iwai 	.substreams = 1,
3249*6764bcefSTakashi Iwai 	.channels_min = 2,
3250*6764bcefSTakashi Iwai 	.channels_max = 2,
3251*6764bcefSTakashi Iwai 	.nid = 0, /* fill later */
3252*6764bcefSTakashi Iwai 	.ops = {
3253*6764bcefSTakashi Iwai 		.prepare = cx_auto_capture_pcm_prepare,
3254*6764bcefSTakashi Iwai 		.cleanup = cx_auto_capture_pcm_cleanup
3255*6764bcefSTakashi Iwai 	},
3256*6764bcefSTakashi Iwai };
3257*6764bcefSTakashi Iwai 
325834cbe3a6STakashi Iwai static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
3259f2e5731dSTakashi Iwai 
3260f2e5731dSTakashi Iwai /* get the connection index of @nid in the widget @mux */
3261f2e5731dSTakashi Iwai static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3262f2e5731dSTakashi Iwai 				hda_nid_t nid)
3263f2e5731dSTakashi Iwai {
3264f2e5731dSTakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3265f2e5731dSTakashi Iwai 	int i, nums;
3266f2e5731dSTakashi Iwai 
3267f2e5731dSTakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3268f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++)
3269f2e5731dSTakashi Iwai 		if (conn[i] == nid)
3270f2e5731dSTakashi Iwai 			return i;
3271f2e5731dSTakashi Iwai 	return -1;
3272f2e5731dSTakashi Iwai }
3273f2e5731dSTakashi Iwai 
3274*6764bcefSTakashi Iwai static int has_multi_connection(struct hda_codec *codec, hda_nid_t mux)
3275*6764bcefSTakashi Iwai {
3276*6764bcefSTakashi Iwai 	hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3277*6764bcefSTakashi Iwai 	int nums;
3278*6764bcefSTakashi Iwai 
3279*6764bcefSTakashi Iwai 	nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3280*6764bcefSTakashi Iwai 	return nums > 1;
3281*6764bcefSTakashi Iwai }
3282*6764bcefSTakashi Iwai 
3283f2e5731dSTakashi Iwai /* get an unassigned DAC from the given list.
3284f2e5731dSTakashi Iwai  * Return the nid if found and reduce the DAC list, or return zero if
3285f2e5731dSTakashi Iwai  * not found
3286f2e5731dSTakashi Iwai  */
3287f2e5731dSTakashi Iwai static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3288f2e5731dSTakashi Iwai 				    hda_nid_t *dacs, int *num_dacs)
3289f2e5731dSTakashi Iwai {
3290f2e5731dSTakashi Iwai 	int i, nums = *num_dacs;
3291f2e5731dSTakashi Iwai 	hda_nid_t ret = 0;
3292f2e5731dSTakashi Iwai 
3293f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3294f2e5731dSTakashi Iwai 		if (get_connection_index(codec, pin, dacs[i]) >= 0) {
3295f2e5731dSTakashi Iwai 			ret = dacs[i];
3296f2e5731dSTakashi Iwai 			break;
3297f2e5731dSTakashi Iwai 		}
3298f2e5731dSTakashi Iwai 	}
3299f2e5731dSTakashi Iwai 	if (!ret)
3300f2e5731dSTakashi Iwai 		return 0;
3301f2e5731dSTakashi Iwai 	if (--nums > 0)
3302f2e5731dSTakashi Iwai 		memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
3303f2e5731dSTakashi Iwai 	*num_dacs = nums;
3304f2e5731dSTakashi Iwai 	return ret;
3305f2e5731dSTakashi Iwai }
3306f2e5731dSTakashi Iwai 
3307f2e5731dSTakashi Iwai #define MAX_AUTO_DACS	5
3308f2e5731dSTakashi Iwai 
3309f2e5731dSTakashi Iwai /* fill analog DAC list from the widget tree */
3310f2e5731dSTakashi Iwai static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3311f2e5731dSTakashi Iwai {
3312f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3313f2e5731dSTakashi Iwai 	int nums = 0;
3314f2e5731dSTakashi Iwai 
3315f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3316f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3317f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3318f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3319f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
3320f2e5731dSTakashi Iwai 			dacs[nums++] = nid;
3321f2e5731dSTakashi Iwai 			if (nums >= MAX_AUTO_DACS)
3322f2e5731dSTakashi Iwai 				break;
3323f2e5731dSTakashi Iwai 		}
3324f2e5731dSTakashi Iwai 	}
3325f2e5731dSTakashi Iwai 	return nums;
3326f2e5731dSTakashi Iwai }
3327f2e5731dSTakashi Iwai 
3328f2e5731dSTakashi Iwai /* fill pin_dac_pair list from the pin and dac list */
3329f2e5731dSTakashi Iwai static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3330f2e5731dSTakashi Iwai 			      int num_pins, hda_nid_t *dacs, int *rest,
3331f2e5731dSTakashi Iwai 			      struct pin_dac_pair *filled, int type)
3332f2e5731dSTakashi Iwai {
3333f2e5731dSTakashi Iwai 	int i, nums;
3334f2e5731dSTakashi Iwai 
3335f2e5731dSTakashi Iwai 	nums = 0;
3336f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3337f2e5731dSTakashi Iwai 		filled[nums].pin = pins[i];
3338f2e5731dSTakashi Iwai 		filled[nums].type = type;
3339f2e5731dSTakashi Iwai 		filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3340f2e5731dSTakashi Iwai 		nums++;
3341f2e5731dSTakashi Iwai 	}
3342f2e5731dSTakashi Iwai 	return nums;
3343f2e5731dSTakashi Iwai }
3344f2e5731dSTakashi Iwai 
3345f2e5731dSTakashi Iwai /* parse analog output paths */
3346f2e5731dSTakashi Iwai static void cx_auto_parse_output(struct hda_codec *codec)
3347f2e5731dSTakashi Iwai {
3348f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3349f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3350f2e5731dSTakashi Iwai 	hda_nid_t dacs[MAX_AUTO_DACS];
3351f2e5731dSTakashi Iwai 	int i, j, nums, rest;
3352f2e5731dSTakashi Iwai 
3353f2e5731dSTakashi Iwai 	rest = fill_cx_auto_dacs(codec, dacs);
3354f2e5731dSTakashi Iwai 	/* parse all analog output pins */
3355f2e5731dSTakashi Iwai 	nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3356f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info,
3357f2e5731dSTakashi Iwai 				  AUTO_PIN_LINE_OUT);
3358f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3359f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3360f2e5731dSTakashi Iwai 				  AUTO_PIN_HP_OUT);
3361f2e5731dSTakashi Iwai 	nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3362f2e5731dSTakashi Iwai 				  dacs, &rest, spec->dac_info + nums,
3363f2e5731dSTakashi Iwai 				  AUTO_PIN_SPEAKER_OUT);
3364f2e5731dSTakashi Iwai 	spec->dac_info_filled = nums;
3365f2e5731dSTakashi Iwai 	/* fill multiout struct */
3366f2e5731dSTakashi Iwai 	for (i = 0; i < nums; i++) {
3367f2e5731dSTakashi Iwai 		hda_nid_t dac = spec->dac_info[i].dac;
3368f2e5731dSTakashi Iwai 		if (!dac)
3369f2e5731dSTakashi Iwai 			continue;
3370f2e5731dSTakashi Iwai 		switch (spec->dac_info[i].type) {
3371f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3372f2e5731dSTakashi Iwai 			spec->private_dac_nids[spec->multiout.num_dacs] = dac;
3373f2e5731dSTakashi Iwai 			spec->multiout.num_dacs++;
3374f2e5731dSTakashi Iwai 			break;
3375f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3376f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3377f2e5731dSTakashi Iwai 			if (!spec->multiout.hp_nid) {
3378f2e5731dSTakashi Iwai 				spec->multiout.hp_nid = dac;
3379f2e5731dSTakashi Iwai 				break;
3380f2e5731dSTakashi Iwai 			}
3381f2e5731dSTakashi Iwai 			for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
3382f2e5731dSTakashi Iwai 				if (!spec->multiout.extra_out_nid[j]) {
3383f2e5731dSTakashi Iwai 					spec->multiout.extra_out_nid[j] = dac;
3384f2e5731dSTakashi Iwai 					break;
3385f2e5731dSTakashi Iwai 				}
3386f2e5731dSTakashi Iwai 			break;
3387f2e5731dSTakashi Iwai 		}
3388f2e5731dSTakashi Iwai 	}
3389f2e5731dSTakashi Iwai 	spec->multiout.dac_nids = spec->private_dac_nids;
339089724958SDavid Henningsson 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3391f2e5731dSTakashi Iwai 
3392f2e5731dSTakashi Iwai 	if (cfg->hp_outs > 0)
3393f2e5731dSTakashi Iwai 		spec->auto_mute = 1;
3394f2e5731dSTakashi Iwai 	spec->vmaster_nid = spec->private_dac_nids[0];
3395f2e5731dSTakashi Iwai }
3396f2e5731dSTakashi Iwai 
3397da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3398da339866STakashi Iwai 			      hda_nid_t *pins, bool on);
3399da339866STakashi Iwai 
3400f2e5731dSTakashi Iwai /* auto-mute/unmute speaker and line outs according to headphone jack */
3401f2e5731dSTakashi Iwai static void cx_auto_hp_automute(struct hda_codec *codec)
3402f2e5731dSTakashi Iwai {
3403f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3404f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3405f2e5731dSTakashi Iwai 	int i, present;
3406f2e5731dSTakashi Iwai 
3407f2e5731dSTakashi Iwai 	if (!spec->auto_mute)
3408f2e5731dSTakashi Iwai 		return;
3409f2e5731dSTakashi Iwai 	present = 0;
3410f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++) {
3411f2e5731dSTakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
3412f2e5731dSTakashi Iwai 			present = 1;
3413f2e5731dSTakashi Iwai 			break;
3414f2e5731dSTakashi Iwai 		}
3415f2e5731dSTakashi Iwai 	}
3416da339866STakashi Iwai 	cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
3417f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->line_outs; i++) {
3418f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3419f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3420f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3421f2e5731dSTakashi Iwai 	}
3422da339866STakashi Iwai 	cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
3423fbb5bb56STakashi Iwai 	for (i = 0; !present && i < cfg->line_outs; i++)
3424fbb5bb56STakashi Iwai 		if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
3425fbb5bb56STakashi Iwai 			present = 1;
3426f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->speaker_outs; i++) {
3427f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3428f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
3429f2e5731dSTakashi Iwai 				    present ? 0 : PIN_OUT);
3430f2e5731dSTakashi Iwai 	}
3431da339866STakashi Iwai 	cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
3432f2e5731dSTakashi Iwai }
3433f2e5731dSTakashi Iwai 
3434*6764bcefSTakashi Iwai static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
3435*6764bcefSTakashi Iwai 				 struct snd_ctl_elem_info *uinfo)
3436*6764bcefSTakashi Iwai {
3437*6764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3438*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3439*6764bcefSTakashi Iwai 
3440*6764bcefSTakashi Iwai 	return snd_hda_input_mux_info(&spec->private_imux, uinfo);
3441*6764bcefSTakashi Iwai }
3442*6764bcefSTakashi Iwai 
3443*6764bcefSTakashi Iwai static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
3444*6764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
3445*6764bcefSTakashi Iwai {
3446*6764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3447*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3448*6764bcefSTakashi Iwai 
3449*6764bcefSTakashi Iwai 	ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
3450*6764bcefSTakashi Iwai 	return 0;
3451*6764bcefSTakashi Iwai }
3452*6764bcefSTakashi Iwai 
3453*6764bcefSTakashi Iwai static int cx_auto_mux_enum_update(struct hda_codec *codec,
3454*6764bcefSTakashi Iwai 				   const struct hda_input_mux *imux,
3455*6764bcefSTakashi Iwai 				   unsigned int idx)
3456*6764bcefSTakashi Iwai {
3457*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3458*6764bcefSTakashi Iwai 	hda_nid_t adc;
3459*6764bcefSTakashi Iwai 
3460*6764bcefSTakashi Iwai 	if (!imux->num_items)
3461*6764bcefSTakashi Iwai 		return 0;
3462*6764bcefSTakashi Iwai 	if (idx >= imux->num_items)
3463*6764bcefSTakashi Iwai 		idx = imux->num_items - 1;
3464*6764bcefSTakashi Iwai 	if (spec->cur_mux[0] == idx)
3465*6764bcefSTakashi Iwai 		return 0;
3466*6764bcefSTakashi Iwai 	adc = spec->imux_adcs[idx];
3467*6764bcefSTakashi Iwai 	if (has_multi_connection(codec, adc))
3468*6764bcefSTakashi Iwai 		snd_hda_codec_write(codec, adc, 0,
3469*6764bcefSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL,
3470*6764bcefSTakashi Iwai 				    imux->items[idx].index);
3471*6764bcefSTakashi Iwai 	if (spec->cur_adc && spec->cur_adc != adc) {
3472*6764bcefSTakashi Iwai 		/* stream is running, let's swap the current ADC */
3473*6764bcefSTakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
3474*6764bcefSTakashi Iwai 		spec->cur_adc = adc;
3475*6764bcefSTakashi Iwai 		snd_hda_codec_setup_stream(codec, adc,
3476*6764bcefSTakashi Iwai 					   spec->cur_adc_stream_tag, 0,
3477*6764bcefSTakashi Iwai 					   spec->cur_adc_format);
3478*6764bcefSTakashi Iwai 	}
3479*6764bcefSTakashi Iwai 	spec->cur_mux[0] = idx;
3480*6764bcefSTakashi Iwai 	return 1;
3481*6764bcefSTakashi Iwai }
3482*6764bcefSTakashi Iwai 
3483*6764bcefSTakashi Iwai static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
3484*6764bcefSTakashi Iwai 				struct snd_ctl_elem_value *ucontrol)
3485*6764bcefSTakashi Iwai {
3486*6764bcefSTakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3487*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3488*6764bcefSTakashi Iwai 
3489*6764bcefSTakashi Iwai 	return cx_auto_mux_enum_update(codec, &spec->private_imux,
3490*6764bcefSTakashi Iwai 				       ucontrol->value.enumerated.item[0]);
3491*6764bcefSTakashi Iwai }
3492*6764bcefSTakashi Iwai 
3493*6764bcefSTakashi Iwai static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
3494*6764bcefSTakashi Iwai 	{
3495*6764bcefSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3496*6764bcefSTakashi Iwai 		.name = "Capture Source",
3497*6764bcefSTakashi Iwai 		.info = cx_auto_mux_enum_info,
3498*6764bcefSTakashi Iwai 		.get = cx_auto_mux_enum_get,
3499*6764bcefSTakashi Iwai 		.put = cx_auto_mux_enum_put
3500*6764bcefSTakashi Iwai 	},
3501*6764bcefSTakashi Iwai 	{}
3502*6764bcefSTakashi Iwai };
3503*6764bcefSTakashi Iwai 
3504f2e5731dSTakashi Iwai /* automatic switch internal and external mic */
3505f2e5731dSTakashi Iwai static void cx_auto_automic(struct hda_codec *codec)
3506f2e5731dSTakashi Iwai {
3507f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3508f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3509f2e5731dSTakashi Iwai 	int ext_idx = spec->auto_mic_ext;
3510f2e5731dSTakashi Iwai 
3511f2e5731dSTakashi Iwai 	if (!spec->auto_mic)
3512f2e5731dSTakashi Iwai 		return;
3513*6764bcefSTakashi Iwai 	if (snd_hda_jack_detect(codec, cfg->inputs[ext_idx].pin))
3514*6764bcefSTakashi Iwai 		cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
3515*6764bcefSTakashi Iwai 	else
3516*6764bcefSTakashi Iwai 		cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
3517f2e5731dSTakashi Iwai }
3518f2e5731dSTakashi Iwai 
3519f2e5731dSTakashi Iwai static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3520f2e5731dSTakashi Iwai {
3521f2e5731dSTakashi Iwai 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
3522f2e5731dSTakashi Iwai 	switch (res >> 26) {
3523f2e5731dSTakashi Iwai 	case CONEXANT_HP_EVENT:
3524f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3525cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3526f2e5731dSTakashi Iwai 		break;
3527f2e5731dSTakashi Iwai 	case CONEXANT_MIC_EVENT:
3528f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3529cd372fb3STakashi Iwai 		snd_hda_input_jack_report(codec, nid);
3530f2e5731dSTakashi Iwai 		break;
3531f2e5731dSTakashi Iwai 	}
3532f2e5731dSTakashi Iwai }
3533f2e5731dSTakashi Iwai 
3534f2e5731dSTakashi Iwai /* return true if it's an internal-mic pin */
3535f2e5731dSTakashi Iwai static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3536f2e5731dSTakashi Iwai {
3537f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3538f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
353999ae28beSTakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3540f2e5731dSTakashi Iwai }
3541f2e5731dSTakashi Iwai 
3542f2e5731dSTakashi Iwai /* return true if it's an external-mic pin */
3543f2e5731dSTakashi Iwai static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3544f2e5731dSTakashi Iwai {
3545f2e5731dSTakashi Iwai 	unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3546f2e5731dSTakashi Iwai 	return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3547f68b3b29STakashi Iwai 		snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
3548f68b3b29STakashi Iwai 		(snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
3549f2e5731dSTakashi Iwai }
3550f2e5731dSTakashi Iwai 
3551f2e5731dSTakashi Iwai /* check whether the pin config is suitable for auto-mic switching;
3552f2e5731dSTakashi Iwai  * auto-mic is enabled only when one int-mic and one-ext mic exist
3553f2e5731dSTakashi Iwai  */
3554f2e5731dSTakashi Iwai static void cx_auto_check_auto_mic(struct hda_codec *codec)
3555f2e5731dSTakashi Iwai {
3556f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3557f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3558f2e5731dSTakashi Iwai 
3559f2e5731dSTakashi Iwai 	if (is_ext_mic(codec, cfg->inputs[0].pin) &&
3560f2e5731dSTakashi Iwai 	    is_int_mic(codec, cfg->inputs[1].pin)) {
3561f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
35622557f742STakashi Iwai 		spec->auto_mic_ext = 0;
3563f2e5731dSTakashi Iwai 		return;
3564f2e5731dSTakashi Iwai 	}
35652557f742STakashi Iwai 	if (is_int_mic(codec, cfg->inputs[0].pin) &&
35662557f742STakashi Iwai 	    is_ext_mic(codec, cfg->inputs[1].pin)) {
3567f2e5731dSTakashi Iwai 		spec->auto_mic = 1;
35682557f742STakashi Iwai 		spec->auto_mic_ext = 1;
3569f2e5731dSTakashi Iwai 		return;
3570f2e5731dSTakashi Iwai 	}
3571f2e5731dSTakashi Iwai }
3572f2e5731dSTakashi Iwai 
3573f2e5731dSTakashi Iwai static void cx_auto_parse_input(struct hda_codec *codec)
3574f2e5731dSTakashi Iwai {
3575f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3576f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3577f2e5731dSTakashi Iwai 	struct hda_input_mux *imux;
3578*6764bcefSTakashi Iwai 	int i, j;
3579f2e5731dSTakashi Iwai 
3580f2e5731dSTakashi Iwai 	imux = &spec->private_imux;
3581f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3582*6764bcefSTakashi Iwai 		for (j = 0; j < spec->num_adc_nids; j++) {
3583*6764bcefSTakashi Iwai 			hda_nid_t adc = spec->adc_nids[j];
3584*6764bcefSTakashi Iwai 			int idx = get_connection_index(codec, adc,
3585f2e5731dSTakashi Iwai 					       cfg->inputs[i].pin);
3586f2e5731dSTakashi Iwai 			if (idx >= 0) {
3587f2e5731dSTakashi Iwai 				const char *label;
3588f2e5731dSTakashi Iwai 				label = hda_get_autocfg_input_label(codec, cfg, i);
3589f2e5731dSTakashi Iwai 				snd_hda_add_imux_item(imux, label, idx, NULL);
3590*6764bcefSTakashi Iwai 				spec->imux_adcs[i] = adc;
3591*6764bcefSTakashi Iwai 				break;
3592*6764bcefSTakashi Iwai 			}
3593f2e5731dSTakashi Iwai 		}
3594f2e5731dSTakashi Iwai 	}
3595f2e5731dSTakashi Iwai 	if (imux->num_items == 2 && cfg->num_inputs == 2)
3596f2e5731dSTakashi Iwai 		cx_auto_check_auto_mic(codec);
3597*6764bcefSTakashi Iwai 	if (imux->num_items > 1 && !spec->auto_mic) {
3598*6764bcefSTakashi Iwai 		for (i = 1; i < imux->num_items; i++) {
3599*6764bcefSTakashi Iwai 			if (spec->imux_adcs[i] != spec->imux_adcs[0]) {
3600*6764bcefSTakashi Iwai 				spec->adc_switching = 1;
3601*6764bcefSTakashi Iwai 				break;
3602*6764bcefSTakashi Iwai 			}
3603*6764bcefSTakashi Iwai 		}
3604*6764bcefSTakashi Iwai 	}
3605f2e5731dSTakashi Iwai }
3606f2e5731dSTakashi Iwai 
3607f2e5731dSTakashi Iwai /* get digital-input audio widget corresponding to the given pin */
3608f2e5731dSTakashi Iwai static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
3609f2e5731dSTakashi Iwai {
3610f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3611f2e5731dSTakashi Iwai 
3612f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3613f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
3614f2e5731dSTakashi Iwai 		unsigned int wcaps = get_wcaps(codec, nid);
3615f2e5731dSTakashi Iwai 		unsigned int type = get_wcaps_type(wcaps);
3616f2e5731dSTakashi Iwai 		if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
3617f2e5731dSTakashi Iwai 			if (get_connection_index(codec, nid, pin) >= 0)
3618f2e5731dSTakashi Iwai 				return nid;
3619f2e5731dSTakashi Iwai 		}
3620f2e5731dSTakashi Iwai 	}
3621f2e5731dSTakashi Iwai 	return 0;
3622f2e5731dSTakashi Iwai }
3623f2e5731dSTakashi Iwai 
3624f2e5731dSTakashi Iwai static void cx_auto_parse_digital(struct hda_codec *codec)
3625f2e5731dSTakashi Iwai {
3626f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3627f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3628f2e5731dSTakashi Iwai 	hda_nid_t nid;
3629f2e5731dSTakashi Iwai 
3630f2e5731dSTakashi Iwai 	if (cfg->dig_outs &&
3631f2e5731dSTakashi Iwai 	    snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
3632f2e5731dSTakashi Iwai 		spec->multiout.dig_out_nid = nid;
3633f2e5731dSTakashi Iwai 	if (cfg->dig_in_pin)
3634f2e5731dSTakashi Iwai 		spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
3635f2e5731dSTakashi Iwai }
3636f2e5731dSTakashi Iwai 
3637f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3638f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3639f2e5731dSTakashi Iwai {
3640f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3641f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3642f2e5731dSTakashi Iwai 
3643f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3644f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3645f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3646f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3647f2e5731dSTakashi Iwai 			break;
3648f2e5731dSTakashi Iwai 		}
3649f2e5731dSTakashi Iwai }
3650f2e5731dSTakashi Iwai #else
3651f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3652f2e5731dSTakashi Iwai #endif
3653f2e5731dSTakashi Iwai 
3654f2e5731dSTakashi Iwai static int cx_auto_parse_auto_config(struct hda_codec *codec)
3655f2e5731dSTakashi Iwai {
3656f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3657f2e5731dSTakashi Iwai 	int err;
3658f2e5731dSTakashi Iwai 
3659f2e5731dSTakashi Iwai 	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
3660f2e5731dSTakashi Iwai 	if (err < 0)
3661f2e5731dSTakashi Iwai 		return err;
3662f2e5731dSTakashi Iwai 
3663f2e5731dSTakashi Iwai 	cx_auto_parse_output(codec);
3664f2e5731dSTakashi Iwai 	cx_auto_parse_input(codec);
3665f2e5731dSTakashi Iwai 	cx_auto_parse_digital(codec);
3666f2e5731dSTakashi Iwai 	cx_auto_parse_beep(codec);
3667f2e5731dSTakashi Iwai 	return 0;
3668f2e5731dSTakashi Iwai }
3669f2e5731dSTakashi Iwai 
3670da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3671da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
3672f2e5731dSTakashi Iwai {
3673f2e5731dSTakashi Iwai 	int i;
3674f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3675f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3676f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3677da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
3678da339866STakashi Iwai 					    on ? 0x02 : 0);
3679f2e5731dSTakashi Iwai 	}
3680f2e5731dSTakashi Iwai }
3681f2e5731dSTakashi Iwai 
3682f2e5731dSTakashi Iwai static void select_connection(struct hda_codec *codec, hda_nid_t pin,
3683f2e5731dSTakashi Iwai 			      hda_nid_t src)
3684f2e5731dSTakashi Iwai {
3685f2e5731dSTakashi Iwai 	int idx = get_connection_index(codec, pin, src);
3686f2e5731dSTakashi Iwai 	if (idx >= 0)
3687f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, pin, 0,
3688f2e5731dSTakashi Iwai 				    AC_VERB_SET_CONNECT_SEL, idx);
3689f2e5731dSTakashi Iwai }
3690f2e5731dSTakashi Iwai 
3691f2e5731dSTakashi Iwai static void cx_auto_init_output(struct hda_codec *codec)
3692f2e5731dSTakashi Iwai {
3693f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3694f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3695f2e5731dSTakashi Iwai 	hda_nid_t nid;
36960ad1b5b6STakashi Iwai 	int i, val;
3697f2e5731dSTakashi Iwai 
36980ad1b5b6STakashi Iwai 	for (i = 0; i < spec->multiout.num_dacs; i++) {
36990ad1b5b6STakashi Iwai 		nid = spec->multiout.dac_nids[i];
37000ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
37010ad1b5b6STakashi Iwai 			val = AMP_OUT_MUTE;
37020ad1b5b6STakashi Iwai 		else
37030ad1b5b6STakashi Iwai 			val = AMP_OUT_ZERO;
37040ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0,
37050ad1b5b6STakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, val);
37060ad1b5b6STakashi Iwai 	}
3707f2e5731dSTakashi Iwai 
3708f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->hp_outs; i++)
3709f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3710f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
3711f2e5731dSTakashi Iwai 	if (spec->auto_mute) {
3712f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->hp_outs; i++) {
3713f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
3714f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3715f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_HP_EVENT);
3716f2e5731dSTakashi Iwai 		}
3717f2e5731dSTakashi Iwai 		cx_auto_hp_automute(codec);
3718f2e5731dSTakashi Iwai 	} else {
3719f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->line_outs; i++)
3720f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
3721f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3722f2e5731dSTakashi Iwai 		for (i = 0; i < cfg->speaker_outs; i++)
3723f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
3724f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3725da339866STakashi Iwai 		/* turn on EAPD */
3726da339866STakashi Iwai 		cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
3727da339866STakashi Iwai 				  true);
3728da339866STakashi Iwai 		cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
3729da339866STakashi Iwai 				  true);
3730da339866STakashi Iwai 		cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
3731da339866STakashi Iwai 				  true);
3732f2e5731dSTakashi Iwai 	}
3733f2e5731dSTakashi Iwai 
3734f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3735f2e5731dSTakashi Iwai 		nid = spec->dac_info[i].dac;
3736f2e5731dSTakashi Iwai 		if (!nid)
3737f2e5731dSTakashi Iwai 			nid = spec->multiout.dac_nids[0];
3738f2e5731dSTakashi Iwai 		select_connection(codec, spec->dac_info[i].pin, nid);
3739f2e5731dSTakashi Iwai 	}
3740f2e5731dSTakashi Iwai }
3741f2e5731dSTakashi Iwai 
3742f2e5731dSTakashi Iwai static void cx_auto_init_input(struct hda_codec *codec)
3743f2e5731dSTakashi Iwai {
3744f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3745f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
37460ad1b5b6STakashi Iwai 	int i, val;
3747f2e5731dSTakashi Iwai 
37480ad1b5b6STakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
37490ad1b5b6STakashi Iwai 		hda_nid_t nid = spec->adc_nids[i];
37500ad1b5b6STakashi Iwai 		if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
37510ad1b5b6STakashi Iwai 			val = AMP_IN_MUTE(0);
37520ad1b5b6STakashi Iwai 		else
37530ad1b5b6STakashi Iwai 			val = AMP_IN_UNMUTE(0);
37540ad1b5b6STakashi Iwai 		snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
37550ad1b5b6STakashi Iwai 				    val);
37560ad1b5b6STakashi Iwai 	}
3757f2e5731dSTakashi Iwai 
3758f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3759f2e5731dSTakashi Iwai 		unsigned int type;
3760f2e5731dSTakashi Iwai 		if (cfg->inputs[i].type == AUTO_PIN_MIC)
3761f2e5731dSTakashi Iwai 			type = PIN_VREF80;
3762f2e5731dSTakashi Iwai 		else
3763f2e5731dSTakashi Iwai 			type = PIN_IN;
3764f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
3765f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, type);
3766f2e5731dSTakashi Iwai 	}
3767f2e5731dSTakashi Iwai 
3768f2e5731dSTakashi Iwai 	if (spec->auto_mic) {
3769f2e5731dSTakashi Iwai 		int ext_idx = spec->auto_mic_ext;
3770f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
3771f2e5731dSTakashi Iwai 				    AC_VERB_SET_UNSOLICITED_ENABLE,
3772f2e5731dSTakashi Iwai 				    AC_USRSP_EN | CONEXANT_MIC_EVENT);
3773f2e5731dSTakashi Iwai 		cx_auto_automic(codec);
3774f2e5731dSTakashi Iwai 	} else {
3775f2e5731dSTakashi Iwai 		for (i = 0; i < spec->num_adc_nids; i++) {
3776f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, spec->adc_nids[i], 0,
3777f2e5731dSTakashi Iwai 					    AC_VERB_SET_CONNECT_SEL,
3778f2e5731dSTakashi Iwai 					    spec->private_imux.items[0].index);
3779f2e5731dSTakashi Iwai 		}
3780f2e5731dSTakashi Iwai 	}
3781f2e5731dSTakashi Iwai }
3782f2e5731dSTakashi Iwai 
3783f2e5731dSTakashi Iwai static void cx_auto_init_digital(struct hda_codec *codec)
3784f2e5731dSTakashi Iwai {
3785f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3786f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3787f2e5731dSTakashi Iwai 
3788f2e5731dSTakashi Iwai 	if (spec->multiout.dig_out_nid)
3789f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
3790f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
3791f2e5731dSTakashi Iwai 	if (spec->dig_in_nid)
3792f2e5731dSTakashi Iwai 		snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
3793f2e5731dSTakashi Iwai 				    AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
3794f2e5731dSTakashi Iwai }
3795f2e5731dSTakashi Iwai 
3796f2e5731dSTakashi Iwai static int cx_auto_init(struct hda_codec *codec)
3797f2e5731dSTakashi Iwai {
3798f2e5731dSTakashi Iwai 	/*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
3799f2e5731dSTakashi Iwai 	cx_auto_init_output(codec);
3800f2e5731dSTakashi Iwai 	cx_auto_init_input(codec);
3801f2e5731dSTakashi Iwai 	cx_auto_init_digital(codec);
3802f2e5731dSTakashi Iwai 	return 0;
3803f2e5731dSTakashi Iwai }
3804f2e5731dSTakashi Iwai 
3805983345e5SDavid Henningsson static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
3806f2e5731dSTakashi Iwai 			      const char *dir, int cidx,
3807983345e5SDavid Henningsson 			      hda_nid_t nid, int hda_dir, int amp_idx)
3808f2e5731dSTakashi Iwai {
3809f2e5731dSTakashi Iwai 	static char name[32];
3810f2e5731dSTakashi Iwai 	static struct snd_kcontrol_new knew[] = {
3811f2e5731dSTakashi Iwai 		HDA_CODEC_VOLUME(name, 0, 0, 0),
3812f2e5731dSTakashi Iwai 		HDA_CODEC_MUTE(name, 0, 0, 0),
3813f2e5731dSTakashi Iwai 	};
381434cbe3a6STakashi Iwai 	static const char * const sfx[2] = { "Volume", "Switch" };
3815f2e5731dSTakashi Iwai 	int i, err;
3816f2e5731dSTakashi Iwai 
3817f2e5731dSTakashi Iwai 	for (i = 0; i < 2; i++) {
3818f2e5731dSTakashi Iwai 		struct snd_kcontrol *kctl;
3819983345e5SDavid Henningsson 		knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
3820983345e5SDavid Henningsson 							    hda_dir);
3821f2e5731dSTakashi Iwai 		knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
3822f2e5731dSTakashi Iwai 		knew[i].index = cidx;
3823f2e5731dSTakashi Iwai 		snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
3824f2e5731dSTakashi Iwai 		kctl = snd_ctl_new1(&knew[i], codec);
3825f2e5731dSTakashi Iwai 		if (!kctl)
3826f2e5731dSTakashi Iwai 			return -ENOMEM;
3827f2e5731dSTakashi Iwai 		err = snd_hda_ctl_add(codec, nid, kctl);
3828f2e5731dSTakashi Iwai 		if (err < 0)
3829f2e5731dSTakashi Iwai 			return err;
3830f2e5731dSTakashi Iwai 		if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
3831f2e5731dSTakashi Iwai 			break;
3832f2e5731dSTakashi Iwai 	}
3833f2e5731dSTakashi Iwai 	return 0;
3834f2e5731dSTakashi Iwai }
3835f2e5731dSTakashi Iwai 
3836983345e5SDavid Henningsson #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir)		\
3837983345e5SDavid Henningsson 	cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
3838983345e5SDavid Henningsson 
3839f2e5731dSTakashi Iwai #define cx_auto_add_pb_volume(codec, nid, str, idx)			\
3840f2e5731dSTakashi Iwai 	cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
3841f2e5731dSTakashi Iwai 
3842f2e5731dSTakashi Iwai static int cx_auto_build_output_controls(struct hda_codec *codec)
3843f2e5731dSTakashi Iwai {
3844f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3845f2e5731dSTakashi Iwai 	int i, err;
3846f2e5731dSTakashi Iwai 	int num_line = 0, num_hp = 0, num_spk = 0;
3847ea734963STakashi Iwai 	static const char * const texts[3] = { "Front", "Surround", "CLFE" };
3848f2e5731dSTakashi Iwai 
3849f2e5731dSTakashi Iwai 	if (spec->dac_info_filled == 1)
3850f2e5731dSTakashi Iwai 		return cx_auto_add_pb_volume(codec, spec->dac_info[0].dac,
3851f2e5731dSTakashi Iwai 					     "Master", 0);
3852f2e5731dSTakashi Iwai 	for (i = 0; i < spec->dac_info_filled; i++) {
3853f2e5731dSTakashi Iwai 		const char *label;
3854f2e5731dSTakashi Iwai 		int idx, type;
3855f2e5731dSTakashi Iwai 		if (!spec->dac_info[i].dac)
3856f2e5731dSTakashi Iwai 			continue;
3857f2e5731dSTakashi Iwai 		type = spec->dac_info[i].type;
3858f2e5731dSTakashi Iwai 		if (type == AUTO_PIN_LINE_OUT)
3859f2e5731dSTakashi Iwai 			type = spec->autocfg.line_out_type;
3860f2e5731dSTakashi Iwai 		switch (type) {
3861f2e5731dSTakashi Iwai 		case AUTO_PIN_LINE_OUT:
3862f2e5731dSTakashi Iwai 		default:
3863f2e5731dSTakashi Iwai 			label = texts[num_line++];
3864f2e5731dSTakashi Iwai 			idx = 0;
3865f2e5731dSTakashi Iwai 			break;
3866f2e5731dSTakashi Iwai 		case AUTO_PIN_HP_OUT:
3867f2e5731dSTakashi Iwai 			label = "Headphone";
3868f2e5731dSTakashi Iwai 			idx = num_hp++;
3869f2e5731dSTakashi Iwai 			break;
3870f2e5731dSTakashi Iwai 		case AUTO_PIN_SPEAKER_OUT:
3871f2e5731dSTakashi Iwai 			label = "Speaker";
3872f2e5731dSTakashi Iwai 			idx = num_spk++;
3873f2e5731dSTakashi Iwai 			break;
3874f2e5731dSTakashi Iwai 		}
3875f2e5731dSTakashi Iwai 		err = cx_auto_add_pb_volume(codec, spec->dac_info[i].dac,
3876f2e5731dSTakashi Iwai 					    label, idx);
3877f2e5731dSTakashi Iwai 		if (err < 0)
3878f2e5731dSTakashi Iwai 			return err;
3879f2e5731dSTakashi Iwai 	}
3880f2e5731dSTakashi Iwai 	return 0;
3881f2e5731dSTakashi Iwai }
3882f2e5731dSTakashi Iwai 
3883*6764bcefSTakashi Iwai static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
3884*6764bcefSTakashi Iwai 				      const char *label, const char *pfx,
3885*6764bcefSTakashi Iwai 				      int cidx)
3886*6764bcefSTakashi Iwai {
3887*6764bcefSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3888*6764bcefSTakashi Iwai 	int i;
3889*6764bcefSTakashi Iwai 
3890*6764bcefSTakashi Iwai 	for (i = 0; i < spec->num_adc_nids; i++) {
3891*6764bcefSTakashi Iwai 		hda_nid_t adc_nid = spec->adc_nids[i];
3892*6764bcefSTakashi Iwai 		int idx = get_connection_index(codec, adc_nid, nid);
3893*6764bcefSTakashi Iwai 		if (idx < 0)
3894*6764bcefSTakashi Iwai 			continue;
3895*6764bcefSTakashi Iwai 		return cx_auto_add_volume_idx(codec, label, pfx,
3896*6764bcefSTakashi Iwai 					      cidx, adc_nid, HDA_INPUT, idx);
3897*6764bcefSTakashi Iwai 	}
3898*6764bcefSTakashi Iwai 	return 0;
3899*6764bcefSTakashi Iwai }
3900*6764bcefSTakashi Iwai 
3901f2e5731dSTakashi Iwai static int cx_auto_build_input_controls(struct hda_codec *codec)
3902f2e5731dSTakashi Iwai {
3903f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3904f2e5731dSTakashi Iwai 	struct auto_pin_cfg *cfg = &spec->autocfg;
3905f2e5731dSTakashi Iwai 	static const char *prev_label;
3906*6764bcefSTakashi Iwai 	int i, err, cidx;
3907983345e5SDavid Henningsson 
3908f2e5731dSTakashi Iwai 	prev_label = NULL;
3909f2e5731dSTakashi Iwai 	cidx = 0;
3910f2e5731dSTakashi Iwai 	for (i = 0; i < cfg->num_inputs; i++) {
3911f2e5731dSTakashi Iwai 		hda_nid_t nid = cfg->inputs[i].pin;
3912f2e5731dSTakashi Iwai 		const char *label;
3913983345e5SDavid Henningsson 		int pin_amp = get_wcaps(codec, nid) & AC_WCAP_IN_AMP;
3914983345e5SDavid Henningsson 
3915f2e5731dSTakashi Iwai 		label = hda_get_autocfg_input_label(codec, cfg, i);
3916f2e5731dSTakashi Iwai 		if (label == prev_label)
3917f2e5731dSTakashi Iwai 			cidx++;
3918f2e5731dSTakashi Iwai 		else
3919f2e5731dSTakashi Iwai 			cidx = 0;
3920f2e5731dSTakashi Iwai 		prev_label = label;
3921983345e5SDavid Henningsson 
3922983345e5SDavid Henningsson 		if (pin_amp) {
3923983345e5SDavid Henningsson 			err = cx_auto_add_volume(codec, label, " Boost", cidx,
3924f2e5731dSTakashi Iwai 						 nid, HDA_INPUT);
3925f2e5731dSTakashi Iwai 			if (err < 0)
3926f2e5731dSTakashi Iwai 				return err;
3927f2e5731dSTakashi Iwai 		}
3928983345e5SDavid Henningsson 
3929*6764bcefSTakashi Iwai 		if (cfg->num_inputs == 1) {
3930*6764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
3931*6764bcefSTakashi Iwai 							 "Capture", "", cidx);
3932*6764bcefSTakashi Iwai 		} else {
3933*6764bcefSTakashi Iwai 			err = cx_auto_add_capture_volume(codec, nid,
3934*6764bcefSTakashi Iwai 							 label, " Capture", cidx);
3935*6764bcefSTakashi Iwai 		}
3936983345e5SDavid Henningsson 		if (err < 0)
3937983345e5SDavid Henningsson 			return err;
3938983345e5SDavid Henningsson 	}
3939*6764bcefSTakashi Iwai 
3940*6764bcefSTakashi Iwai 	if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
3941*6764bcefSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
3942*6764bcefSTakashi Iwai 		if (err < 0)
3943*6764bcefSTakashi Iwai 			return err;
3944983345e5SDavid Henningsson 	}
3945*6764bcefSTakashi Iwai 
3946f2e5731dSTakashi Iwai 	return 0;
3947f2e5731dSTakashi Iwai }
3948f2e5731dSTakashi Iwai 
3949f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
3950f2e5731dSTakashi Iwai {
3951f2e5731dSTakashi Iwai 	int err;
3952f2e5731dSTakashi Iwai 
3953f2e5731dSTakashi Iwai 	err = cx_auto_build_output_controls(codec);
3954f2e5731dSTakashi Iwai 	if (err < 0)
3955f2e5731dSTakashi Iwai 		return err;
3956f2e5731dSTakashi Iwai 	err = cx_auto_build_input_controls(codec);
3957f2e5731dSTakashi Iwai 	if (err < 0)
3958f2e5731dSTakashi Iwai 		return err;
3959f2e5731dSTakashi Iwai 	return conexant_build_controls(codec);
3960f2e5731dSTakashi Iwai }
3961f2e5731dSTakashi Iwai 
396234cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
3963f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
3964f2e5731dSTakashi Iwai 	.build_pcms = conexant_build_pcms,
3965f2e5731dSTakashi Iwai 	.init = cx_auto_init,
3966f2e5731dSTakashi Iwai 	.free = conexant_free,
3967f2e5731dSTakashi Iwai 	.unsol_event = cx_auto_unsol_event,
3968f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
3969f2e5731dSTakashi Iwai 	.suspend = conexant_suspend,
3970f2e5731dSTakashi Iwai #endif
3971f2e5731dSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
3972f2e5731dSTakashi Iwai };
3973f2e5731dSTakashi Iwai 
3974f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3975f2e5731dSTakashi Iwai {
3976f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3977f2e5731dSTakashi Iwai 	int err;
3978f2e5731dSTakashi Iwai 
3979f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3980f2e5731dSTakashi Iwai 	if (!spec)
3981f2e5731dSTakashi Iwai 		return -ENOMEM;
3982f2e5731dSTakashi Iwai 	codec->spec = spec;
3983*6764bcefSTakashi Iwai 	if (codec->vendor_id == 0x14f15051) {
3984*6764bcefSTakashi Iwai 		codec->pin_amp_workaround = 1;
3985*6764bcefSTakashi Iwai 		spec->adc_nids = cxt5051_adc_nids;
3986*6764bcefSTakashi Iwai 		spec->num_adc_nids = ARRAY_SIZE(cxt5051_adc_nids);
3987*6764bcefSTakashi Iwai 		spec->capsrc_nids = spec->adc_nids;
3988*6764bcefSTakashi Iwai 	} else {
3989f2e5731dSTakashi Iwai 		spec->adc_nids = cx_auto_adc_nids;
3990f2e5731dSTakashi Iwai 		spec->num_adc_nids = ARRAY_SIZE(cx_auto_adc_nids);
3991f2e5731dSTakashi Iwai 		spec->capsrc_nids = spec->adc_nids;
3992*6764bcefSTakashi Iwai 	}
3993f2e5731dSTakashi Iwai 	err = cx_auto_parse_auto_config(codec);
3994f2e5731dSTakashi Iwai 	if (err < 0) {
3995f2e5731dSTakashi Iwai 		kfree(codec->spec);
3996f2e5731dSTakashi Iwai 		codec->spec = NULL;
3997f2e5731dSTakashi Iwai 		return err;
3998f2e5731dSTakashi Iwai 	}
3999*6764bcefSTakashi Iwai 	spec->capture_stream = &cx_auto_pcm_analog_capture;
4000f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
4001f2e5731dSTakashi Iwai 	if (spec->beep_amp)
4002f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
4003f2e5731dSTakashi Iwai 	return 0;
4004f2e5731dSTakashi Iwai }
4005f2e5731dSTakashi Iwai 
4006f2e5731dSTakashi Iwai /*
4007461e2c78STakashi Iwai  */
4008461e2c78STakashi Iwai 
400934cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
401082f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
401182f30040STobin Davis 	  .patch = patch_cxt5045 },
401282f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
401382f30040STobin Davis 	  .patch = patch_cxt5047 },
4014461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
4015461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
40160fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
40170fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
401895a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
401995a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
4020850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
4021850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
40227b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
40237b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
40246da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
40256da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
4026f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
4027f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4028f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
4029f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4030f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
4031f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4032f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
4033f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4034f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
4035f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4036f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
4037f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4038f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
4039f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4040f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
4041f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
4042c9b443d4STobin Davis 	{} /* terminator */
4043c9b443d4STobin Davis };
40441289e9e8STakashi Iwai 
40451289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
40461289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
40471289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
40480fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
404995a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
4050850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
40517b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
40526da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
4053f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
4054f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
4055f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
4056f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
4057f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
4058f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
4059f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
4060f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
40611289e9e8STakashi Iwai 
40621289e9e8STakashi Iwai MODULE_LICENSE("GPL");
40631289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
40641289e9e8STakashi Iwai 
40651289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
40661289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
40671289e9e8STakashi Iwai 	.owner = THIS_MODULE,
40681289e9e8STakashi Iwai };
40691289e9e8STakashi Iwai 
40701289e9e8STakashi Iwai static int __init patch_conexant_init(void)
40711289e9e8STakashi Iwai {
40721289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
40731289e9e8STakashi Iwai }
40741289e9e8STakashi Iwai 
40751289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
40761289e9e8STakashi Iwai {
40771289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
40781289e9e8STakashi Iwai }
40791289e9e8STakashi Iwai 
40801289e9e8STakashi Iwai module_init(patch_conexant_init)
40811289e9e8STakashi Iwai module_exit(patch_conexant_exit)
4082