xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision aed523f193ed0a208d93c764e5372ac645cc0402)
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>
27da155d5bSPaul Gortmaker #include <linux/module.h>
28c9b443d4STobin Davis #include <sound/core.h>
29bc7a166dSUlrich Dangel #include <sound/jack.h>
30bc7a166dSUlrich Dangel 
31c9b443d4STobin Davis #include "hda_codec.h"
32c9b443d4STobin Davis #include "hda_local.h"
3323d30f28STakashi Iwai #include "hda_auto_parser.h"
34c0f8faf0SEinar Rünkaru #include "hda_beep.h"
351835a0f9STakashi Iwai #include "hda_jack.h"
36*aed523f1STakashi Iwai #include "hda_generic.h"
37c9b443d4STobin Davis 
38c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
39c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
40c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
41c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
42c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
43c9b443d4STobin Davis 
44c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
45c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
4603697e2aSTakashi Iwai #define CONEXANT_LINE_EVENT	0x39
47c9b443d4STobin Davis 
48bc7a166dSUlrich Dangel /* Conexant 5051 specific */
49c9b443d4STobin Davis 
50ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
51bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
52bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
53bc7a166dSUlrich Dangel 
54faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
55faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
56bc7a166dSUlrich Dangel 
57c9b443d4STobin Davis struct conexant_spec {
58*aed523f1STakashi Iwai 	struct hda_gen_spec gen;
59*aed523f1STakashi Iwai 
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;
7703697e2aSTakashi Iwai 	unsigned int line_present;
78faddaa5dSTakashi Iwai 	unsigned int auto_mic;
79c9b443d4STobin Davis 
80c9b443d4STobin Davis 	/* capture */
81c9b443d4STobin Davis 	unsigned int num_adc_nids;
8234cbe3a6STakashi Iwai 	const hda_nid_t *adc_nids;
83c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
84c9b443d4STobin Davis 
85461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
86461e2c78STakashi Iwai 	hda_nid_t cur_adc;
87461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
88461e2c78STakashi Iwai 	unsigned int cur_adc_format;
89461e2c78STakashi Iwai 
906764bcefSTakashi Iwai 	const struct hda_pcm_stream *capture_stream;
916764bcefSTakashi Iwai 
92c9b443d4STobin Davis 	/* capture source */
93c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
9434cbe3a6STakashi Iwai 	const hda_nid_t *capsrc_nids;
95c9b443d4STobin Davis 	unsigned int cur_mux[3];
96c9b443d4STobin Davis 
97c9b443d4STobin Davis 	/* channel model */
98c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
99c9b443d4STobin Davis 	int num_channel_mode;
100c9b443d4STobin Davis 
101c9b443d4STobin Davis 	/* PCM information */
102c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
103c9b443d4STobin Davis 
104c9b443d4STobin Davis 	unsigned int spdif_route;
105c9b443d4STobin Davis 
1060fb67e98SDaniel Drake 	unsigned int port_d_mode;
107f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
108cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
109cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1107b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
111048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
112a1d6906eSDavid Henningsson 	unsigned int asus:1;
1136764bcefSTakashi Iwai 
11475f8991dSDaniel Drake 	unsigned int ext_mic_present;
11575f8991dSDaniel Drake 	unsigned int recording;
11675f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
11775f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
118c4cfe66cSDaniel Drake 
119c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
120c4cfe66cSDaniel Drake 	 * through the microphone jack.
121c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
122c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
123c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
124c4cfe66cSDaniel Drake 	 * control. */
125c4cfe66cSDaniel Drake 	unsigned int dc_enable;
126c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
127c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
1283507e2a8STakashi Iwai 
1293507e2a8STakashi Iwai 	unsigned int beep_amp;
13019110595STakashi Iwai 
13119110595STakashi Iwai 	/* extra EAPD pins */
13219110595STakashi Iwai 	unsigned int num_eapds;
13319110595STakashi Iwai 	hda_nid_t eapds[4];
134c9b443d4STobin Davis };
135c9b443d4STobin Davis 
136c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
137c9b443d4STobin Davis 				      struct hda_codec *codec,
138c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
139c9b443d4STobin Davis {
140c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1419a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1429a08160bSTakashi Iwai 					     hinfo);
143c9b443d4STobin Davis }
144c9b443d4STobin Davis 
145c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
146c9b443d4STobin Davis 					 struct hda_codec *codec,
147c9b443d4STobin Davis 					 unsigned int stream_tag,
148c9b443d4STobin Davis 					 unsigned int format,
149c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
150c9b443d4STobin Davis {
151c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
152c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
153c9b443d4STobin Davis 						stream_tag,
154c9b443d4STobin Davis 						format, substream);
155c9b443d4STobin Davis }
156c9b443d4STobin Davis 
157c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
158c9b443d4STobin Davis 					 struct hda_codec *codec,
159c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
160c9b443d4STobin Davis {
161c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
162c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
163c9b443d4STobin Davis }
164c9b443d4STobin Davis 
165c9b443d4STobin Davis /*
166c9b443d4STobin Davis  * Digital out
167c9b443d4STobin Davis  */
168c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
169c9b443d4STobin Davis 					  struct hda_codec *codec,
170c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
171c9b443d4STobin Davis {
172c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
173c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
174c9b443d4STobin Davis }
175c9b443d4STobin Davis 
176c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
177c9b443d4STobin Davis 					 struct hda_codec *codec,
178c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
179c9b443d4STobin Davis {
180c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
181c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
182c9b443d4STobin Davis }
183c9b443d4STobin Davis 
1846b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1856b97eb45STakashi Iwai 					 struct hda_codec *codec,
1866b97eb45STakashi Iwai 					 unsigned int stream_tag,
1876b97eb45STakashi Iwai 					 unsigned int format,
1886b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1896b97eb45STakashi Iwai {
1906b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1916b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1926b97eb45STakashi Iwai 					     stream_tag,
1936b97eb45STakashi Iwai 					     format, substream);
1946b97eb45STakashi Iwai }
1956b97eb45STakashi Iwai 
196c9b443d4STobin Davis /*
197c9b443d4STobin Davis  * Analog capture
198c9b443d4STobin Davis  */
199c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
200c9b443d4STobin Davis 				      struct hda_codec *codec,
201c9b443d4STobin Davis 				      unsigned int stream_tag,
202c9b443d4STobin Davis 				      unsigned int format,
203c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
204c9b443d4STobin Davis {
205c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
20675f8991dSDaniel Drake 	if (spec->capture_prepare)
20775f8991dSDaniel Drake 		spec->capture_prepare(codec);
208c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
209c9b443d4STobin Davis 				   stream_tag, 0, format);
210c9b443d4STobin Davis 	return 0;
211c9b443d4STobin Davis }
212c9b443d4STobin Davis 
213c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
214c9b443d4STobin Davis 				      struct hda_codec *codec,
215c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
216c9b443d4STobin Davis {
217c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
218888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
21975f8991dSDaniel Drake 	if (spec->capture_cleanup)
22075f8991dSDaniel Drake 		spec->capture_cleanup(codec);
221c9b443d4STobin Davis 	return 0;
222c9b443d4STobin Davis }
223c9b443d4STobin Davis 
224c9b443d4STobin Davis 
225c9b443d4STobin Davis 
22634cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = {
227c9b443d4STobin Davis 	.substreams = 1,
228c9b443d4STobin Davis 	.channels_min = 2,
229c9b443d4STobin Davis 	.channels_max = 2,
230c9b443d4STobin Davis 	.nid = 0, /* fill later */
231c9b443d4STobin Davis 	.ops = {
232c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
233c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
234c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
235c9b443d4STobin Davis 	},
236c9b443d4STobin Davis };
237c9b443d4STobin Davis 
23834cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = {
239c9b443d4STobin Davis 	.substreams = 1,
240c9b443d4STobin Davis 	.channels_min = 2,
241c9b443d4STobin Davis 	.channels_max = 2,
242c9b443d4STobin Davis 	.nid = 0, /* fill later */
243c9b443d4STobin Davis 	.ops = {
244c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
245c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
246c9b443d4STobin Davis 	},
247c9b443d4STobin Davis };
248c9b443d4STobin Davis 
249c9b443d4STobin Davis 
25034cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = {
251c9b443d4STobin Davis 	.substreams = 1,
252c9b443d4STobin Davis 	.channels_min = 2,
253c9b443d4STobin Davis 	.channels_max = 2,
254c9b443d4STobin Davis 	.nid = 0, /* fill later */
255c9b443d4STobin Davis 	.ops = {
256c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2576b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2586b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
259c9b443d4STobin Davis 	},
260c9b443d4STobin Davis };
261c9b443d4STobin Davis 
26234cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = {
263c9b443d4STobin Davis 	.substreams = 1,
264c9b443d4STobin Davis 	.channels_min = 2,
265c9b443d4STobin Davis 	.channels_max = 2,
266c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
267c9b443d4STobin Davis };
268c9b443d4STobin Davis 
269461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
270461e2c78STakashi Iwai 				      struct hda_codec *codec,
271461e2c78STakashi Iwai 				      unsigned int stream_tag,
272461e2c78STakashi Iwai 				      unsigned int format,
273461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
274461e2c78STakashi Iwai {
275461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
276461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
277461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
278461e2c78STakashi Iwai 	spec->cur_adc_format = format;
279461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
280461e2c78STakashi Iwai 	return 0;
281461e2c78STakashi Iwai }
282461e2c78STakashi Iwai 
283461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
284461e2c78STakashi Iwai 				      struct hda_codec *codec,
285461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
286461e2c78STakashi Iwai {
287461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
288888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
289461e2c78STakashi Iwai 	spec->cur_adc = 0;
290461e2c78STakashi Iwai 	return 0;
291461e2c78STakashi Iwai }
292461e2c78STakashi Iwai 
29334cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
294461e2c78STakashi Iwai 	.substreams = 1,
295461e2c78STakashi Iwai 	.channels_min = 2,
296461e2c78STakashi Iwai 	.channels_max = 2,
297461e2c78STakashi Iwai 	.nid = 0, /* fill later */
298461e2c78STakashi Iwai 	.ops = {
299461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
300461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
301461e2c78STakashi Iwai 	},
302461e2c78STakashi Iwai };
303461e2c78STakashi Iwai 
304c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
305c9b443d4STobin Davis {
306c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
307c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
308c9b443d4STobin Davis 
309c9b443d4STobin Davis 	codec->num_pcms = 1;
310c9b443d4STobin Davis 	codec->pcm_info = info;
311c9b443d4STobin Davis 
312c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
313c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
314c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
315c9b443d4STobin Davis 		spec->multiout.max_channels;
316c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
317c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
3186764bcefSTakashi Iwai 	if (spec->capture_stream)
3196764bcefSTakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
3206764bcefSTakashi Iwai 	else {
321461e2c78STakashi Iwai 		if (codec->vendor_id == 0x14f15051)
322461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
323461e2c78STakashi Iwai 				cx5051_pcm_analog_capture;
3246764bcefSTakashi Iwai 		else {
325461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
326461e2c78STakashi Iwai 				conexant_pcm_analog_capture;
3276764bcefSTakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3286764bcefSTakashi Iwai 				spec->num_adc_nids;
3296764bcefSTakashi Iwai 		}
3306764bcefSTakashi Iwai 	}
331c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
332c9b443d4STobin Davis 
333c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
334c9b443d4STobin Davis 		info++;
335c9b443d4STobin Davis 		codec->num_pcms++;
336c9b443d4STobin Davis 		info->name = "Conexant Digital";
3377ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
338c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
339c9b443d4STobin Davis 			conexant_pcm_digital_playback;
340c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
341c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
342c9b443d4STobin Davis 		if (spec->dig_in_nid) {
343c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
344c9b443d4STobin Davis 				conexant_pcm_digital_capture;
345c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
346c9b443d4STobin Davis 				spec->dig_in_nid;
347c9b443d4STobin Davis 		}
348c9b443d4STobin Davis 	}
349c9b443d4STobin Davis 
350c9b443d4STobin Davis 	return 0;
351c9b443d4STobin Davis }
352c9b443d4STobin Davis 
353c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
354c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
355c9b443d4STobin Davis {
356c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
357c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
358c9b443d4STobin Davis 
359c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
360c9b443d4STobin Davis }
361c9b443d4STobin Davis 
362c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
363c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
364c9b443d4STobin Davis {
365c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
367c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
368c9b443d4STobin Davis 
369c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
370c9b443d4STobin Davis 	return 0;
371c9b443d4STobin Davis }
372c9b443d4STobin Davis 
373c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
374c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
375c9b443d4STobin Davis {
376c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
377c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
378c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379c9b443d4STobin Davis 
380c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
381c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
382c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
383c9b443d4STobin Davis }
384c9b443d4STobin Davis 
3854d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
3864d7fbdbcSTakashi Iwai 			       unsigned int power_state)
3874d7fbdbcSTakashi Iwai {
3884d7fbdbcSTakashi Iwai 	if (power_state == AC_PWRST_D3)
3894d7fbdbcSTakashi Iwai 		msleep(100);
3904d7fbdbcSTakashi Iwai 	snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
3914d7fbdbcSTakashi Iwai 			    power_state);
3924d7fbdbcSTakashi Iwai 	/* partial workaround for "azx_get_response timeout" */
3934d7fbdbcSTakashi Iwai 	if (power_state == AC_PWRST_D0)
3944d7fbdbcSTakashi Iwai 		msleep(10);
3954d7fbdbcSTakashi Iwai 	snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
3964d7fbdbcSTakashi Iwai }
3974d7fbdbcSTakashi Iwai 
398c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
399c9b443d4STobin Davis {
400c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
401c9b443d4STobin Davis 	int i;
402c9b443d4STobin Davis 
403c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
404c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
405c9b443d4STobin Davis 	return 0;
406c9b443d4STobin Davis }
407c9b443d4STobin Davis 
408c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
409c9b443d4STobin Davis {
410ee48df57STakashi Iwai 	struct conexant_spec *spec = codec->spec;
411c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
412ee48df57STakashi Iwai 	kfree(spec);
413c9b443d4STobin Davis }
414c9b443d4STobin Davis 
41534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = {
416b880c74aSTakashi Iwai 	{
417b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
418b880c74aSTakashi Iwai 		.name = "Capture Source",
419b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
420b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
421b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
422b880c74aSTakashi Iwai 	},
423b880c74aSTakashi Iwai 	{}
424b880c74aSTakashi Iwai };
425b880c74aSTakashi Iwai 
4263507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
4273507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
42834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = {
4293507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
4303507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
4313507e2a8STakashi Iwai 	{ } /* end */
4323507e2a8STakashi Iwai };
433*aed523f1STakashi Iwai /* create beep controls if needed */
434*aed523f1STakashi Iwai static int add_beep_ctls(struct hda_codec *codec)
435*aed523f1STakashi Iwai {
436*aed523f1STakashi Iwai 	struct conexant_spec *spec = codec->spec;
437*aed523f1STakashi Iwai 	int err;
438*aed523f1STakashi Iwai 
439*aed523f1STakashi Iwai 	if (spec->beep_amp) {
440*aed523f1STakashi Iwai 		const struct snd_kcontrol_new *knew;
441*aed523f1STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
442*aed523f1STakashi Iwai 			struct snd_kcontrol *kctl;
443*aed523f1STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
444*aed523f1STakashi Iwai 			if (!kctl)
445*aed523f1STakashi Iwai 				return -ENOMEM;
446*aed523f1STakashi Iwai 			kctl->private_value = spec->beep_amp;
447*aed523f1STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
448*aed523f1STakashi Iwai 			if (err < 0)
449*aed523f1STakashi Iwai 				return err;
450*aed523f1STakashi Iwai 		}
451*aed523f1STakashi Iwai 	}
452*aed523f1STakashi Iwai 	return 0;
453*aed523f1STakashi Iwai }
454*aed523f1STakashi Iwai #else
455*aed523f1STakashi Iwai #define add_beep_ctls(codec)	0
4563507e2a8STakashi Iwai #endif
4573507e2a8STakashi Iwai 
4589322ca54STakashi Iwai static const char * const slave_pfxs[] = {
459f37bc7a8STakashi Iwai 	"Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
460dd5746a8STakashi Iwai 	NULL
461dd5746a8STakashi Iwai };
462dd5746a8STakashi Iwai 
463c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
464c9b443d4STobin Davis {
465c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
466c9b443d4STobin Davis 	unsigned int i;
467c9b443d4STobin Davis 	int err;
468c9b443d4STobin Davis 
469c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
470c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
471c9b443d4STobin Davis 		if (err < 0)
472c9b443d4STobin Davis 			return err;
473c9b443d4STobin Davis 	}
474c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
475c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
47674b654c9SStephen Warren 						    spec->multiout.dig_out_nid,
477c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
478c9b443d4STobin Davis 		if (err < 0)
479c9b443d4STobin Davis 			return err;
4809a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
4819a08160bSTakashi Iwai 						    &spec->multiout);
4829a08160bSTakashi Iwai 		if (err < 0)
4839a08160bSTakashi Iwai 			return err;
4849a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
485c9b443d4STobin Davis 	}
486c9b443d4STobin Davis 	if (spec->dig_in_nid) {
487c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
488c9b443d4STobin Davis 		if (err < 0)
489c9b443d4STobin Davis 			return err;
490c9b443d4STobin Davis 	}
491dd5746a8STakashi Iwai 
492dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
493dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
494dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
495dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
496dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
497dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
498dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
4999322ca54STakashi Iwai 					  vmaster_tlv, slave_pfxs,
5009322ca54STakashi Iwai 					  "Playback Volume");
501dd5746a8STakashi Iwai 		if (err < 0)
502dd5746a8STakashi Iwai 			return err;
503dd5746a8STakashi Iwai 	}
504dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
505dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
506*aed523f1STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
5079322ca54STakashi Iwai 					  NULL, slave_pfxs,
508*aed523f1STakashi Iwai 					  "Playback Switch");
509dd5746a8STakashi Iwai 		if (err < 0)
510dd5746a8STakashi Iwai 			return err;
511dd5746a8STakashi Iwai 	}
512dd5746a8STakashi Iwai 
513b880c74aSTakashi Iwai 	if (spec->input_mux) {
514b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
515b880c74aSTakashi Iwai 		if (err < 0)
516b880c74aSTakashi Iwai 			return err;
517b880c74aSTakashi Iwai 	}
518b880c74aSTakashi Iwai 
519*aed523f1STakashi Iwai 	err = add_beep_ctls(codec);
5203507e2a8STakashi Iwai 	if (err < 0)
5213507e2a8STakashi Iwai 		return err;
5223507e2a8STakashi Iwai 
523c9b443d4STobin Davis 	return 0;
524c9b443d4STobin Davis }
525c9b443d4STobin Davis 
52634cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = {
527c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
528c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
529c9b443d4STobin Davis 	.init = conexant_init,
530c9b443d4STobin Davis 	.free = conexant_free,
5314d7fbdbcSTakashi Iwai 	.set_power_state = conexant_set_power,
532c9b443d4STobin Davis };
533c9b443d4STobin Davis 
5343507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5353507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
5363507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
5373507e2a8STakashi Iwai #else
5383507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
5393507e2a8STakashi Iwai #endif
5403507e2a8STakashi Iwai 
5416764bcefSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec);
542c9b443d4STobin Davis /*
543c9b443d4STobin Davis  * EAPD control
544c9b443d4STobin Davis  * the private value = nid | (invert << 8)
545c9b443d4STobin Davis  */
546c9b443d4STobin Davis 
547a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
548c9b443d4STobin Davis 
54982f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
550c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
551c9b443d4STobin Davis {
552c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
553c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
554c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
555c9b443d4STobin Davis 	if (invert)
556c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
557c9b443d4STobin Davis 	else
558c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
559c9b443d4STobin Davis 	return 0;
56082f30040STobin Davis 
561c9b443d4STobin Davis }
562c9b443d4STobin Davis 
56382f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
564c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
565c9b443d4STobin Davis {
566c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
567c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
568c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
569c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
570c9b443d4STobin Davis 	unsigned int eapd;
57182f30040STobin Davis 
57268ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
573c9b443d4STobin Davis 	if (invert)
574c9b443d4STobin Davis 		eapd = !eapd;
57582beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
576c9b443d4STobin Davis 		return 0;
57782f30040STobin Davis 
578c9b443d4STobin Davis 	spec->cur_eapd = eapd;
57982beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
580c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
581c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
582c9b443d4STobin Davis 	return 1;
583c9b443d4STobin Davis }
584c9b443d4STobin Davis 
58586d72bdfSTakashi Iwai /* controls for test mode */
58686d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
58786d72bdfSTakashi Iwai 
58882f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
58982f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
59082f30040STobin Davis 	  .info = cxt_eapd_info, \
59182f30040STobin Davis 	  .get = cxt_eapd_get, \
59282f30040STobin Davis 	  .put = cxt_eapd_put, \
59382f30040STobin Davis 	  .private_value = nid | (mask<<16) }
59482f30040STobin Davis 
59582f30040STobin Davis 
59682f30040STobin Davis 
597c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
598c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
599c9b443d4STobin Davis {
600c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
601c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
602c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
603c9b443d4STobin Davis 				    spec->num_channel_mode);
604c9b443d4STobin Davis }
605c9b443d4STobin Davis 
606c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
607c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
608c9b443d4STobin Davis {
609c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
611c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
612c9b443d4STobin Davis 				   spec->num_channel_mode,
613c9b443d4STobin Davis 				   spec->multiout.max_channels);
614c9b443d4STobin Davis }
615c9b443d4STobin Davis 
616c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
617c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
618c9b443d4STobin Davis {
619c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
621c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
622c9b443d4STobin Davis 				      spec->num_channel_mode,
623c9b443d4STobin Davis 				      &spec->multiout.max_channels);
624c9b443d4STobin Davis 	return err;
625c9b443d4STobin Davis }
626c9b443d4STobin Davis 
627c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
628c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
629c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
630c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
631c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
632c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
633c9b443d4STobin Davis 
63486d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
63586d72bdfSTakashi Iwai 
636c9b443d4STobin Davis /* Conexant 5045 specific */
637c9b443d4STobin Davis 
63834cbe3a6STakashi Iwai static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
63934cbe3a6STakashi Iwai static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
64034cbe3a6STakashi Iwai static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
641cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
642c9b443d4STobin Davis 
64334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5045_modes[1] = {
6445cd57529STobin Davis 	{ 2, NULL },
6455cd57529STobin Davis };
646c9b443d4STobin Davis 
64734cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source = {
648c9b443d4STobin Davis 	.num_items = 2,
649c9b443d4STobin Davis 	.items = {
6503edbbb9eSMichael Karcher 		{ "Internal Mic", 0x1 },
6513edbbb9eSMichael Karcher 		{ "Mic",          0x2 },
652c9b443d4STobin Davis 	}
653c9b443d4STobin Davis };
654c9b443d4STobin Davis 
65534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_benq = {
656e6e03daeSMichael Karcher 	.num_items = 4,
6575218c892SJiang Zhe 	.items = {
6583edbbb9eSMichael Karcher 		{ "Internal Mic", 0x1 },
6593edbbb9eSMichael Karcher 		{ "Mic",          0x2 },
6603edbbb9eSMichael Karcher 		{ "Line",         0x3 },
66122e14130SLukasz Marcinowski 		{ "Mixer",        0x0 },
6625218c892SJiang Zhe 	}
6635218c892SJiang Zhe };
6645218c892SJiang Zhe 
66534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_capture_source_hp530 = {
6662de3c232SJiang zhe 	.num_items = 2,
6672de3c232SJiang zhe 	.items = {
6683edbbb9eSMichael Karcher 		{ "Mic",          0x1 },
6693edbbb9eSMichael Karcher 		{ "Internal Mic", 0x2 },
6702de3c232SJiang zhe 	}
6712de3c232SJiang zhe };
6722de3c232SJiang zhe 
673c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
674c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
675c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
676c9b443d4STobin Davis {
677c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
678c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
67982f30040STobin Davis 	unsigned int bits;
680c9b443d4STobin Davis 
68182f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
682c9b443d4STobin Davis 		return 0;
683c9b443d4STobin Davis 
68482f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
68582f30040STobin Davis 	 * the headphone jack
68682f30040STobin Davis 	 */
68747fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
68847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
68947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
6907f29673bSTobin Davis 
69147fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
69247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
69347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
694c9b443d4STobin Davis 	return 1;
695c9b443d4STobin Davis }
696c9b443d4STobin Davis 
697c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
69834cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
699cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
700cca3b371STakashi Iwai 	.values = {
701cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
702cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
703cca3b371STakashi Iwai 		0
704cca3b371STakashi Iwai 	},
705cca3b371STakashi Iwai };
706c9b443d4STobin Davis 
7077f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7087f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7097f29673bSTobin Davis {
71034cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
7117f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7127f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7137f29673bSTobin Davis 		{}
7147f29673bSTobin Davis 	};
71534cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
7167f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7177f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7187f29673bSTobin Davis 		{}
7197f29673bSTobin Davis 	};
7207f29673bSTobin Davis 	unsigned int present;
7217f29673bSTobin Davis 
722d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7237f29673bSTobin Davis 	if (present)
7247f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7257f29673bSTobin Davis 	else
7267f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7277f29673bSTobin Davis }
7287f29673bSTobin Davis 
729c9b443d4STobin Davis 
730c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
731c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
732c9b443d4STobin Davis {
73382f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
734dd87da1cSTobin Davis 	unsigned int bits;
735c9b443d4STobin Davis 
736d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
737dd87da1cSTobin Davis 
73847fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
73947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
74047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
741c9b443d4STobin Davis }
742c9b443d4STobin Davis 
743c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
744c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
745c9b443d4STobin Davis 				   unsigned int res)
746c9b443d4STobin Davis {
747c9b443d4STobin Davis 	res >>= 26;
748c9b443d4STobin Davis 	switch (res) {
749c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
750c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
751c9b443d4STobin Davis 		break;
7527f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
7537f29673bSTobin Davis 		cxt5045_hp_automic(codec);
7547f29673bSTobin Davis 		break;
7557f29673bSTobin Davis 
756c9b443d4STobin Davis 	}
757c9b443d4STobin Davis }
758c9b443d4STobin Davis 
75934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers[] = {
760cbf2d28eSMichael Karcher 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
761cbf2d28eSMichael Karcher 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
762c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
763c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
76428c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
76528c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
7668607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
7678607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
768cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
769c9b443d4STobin Davis 	{
770c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
771c9b443d4STobin Davis 		.name = "Master Playback Switch",
77282f30040STobin Davis 		.info = cxt_eapd_info,
77382f30040STobin Davis 		.get = cxt_eapd_get,
774c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
77582f30040STobin Davis 		.private_value = 0x10,
776c9b443d4STobin Davis 	},
777c9b443d4STobin Davis 
778c9b443d4STobin Davis 	{}
779c9b443d4STobin Davis };
780c9b443d4STobin Davis 
78134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
7823edbbb9eSMichael Karcher 	HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
7833edbbb9eSMichael Karcher 	HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
78422e14130SLukasz Marcinowski 
7855218c892SJiang Zhe 	{}
7865218c892SJiang Zhe };
7875218c892SJiang Zhe 
78834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
789cbf2d28eSMichael Karcher 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
790cbf2d28eSMichael Karcher 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
7912de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
7922de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
79328c4edb7SDavid Henningsson 	HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
79428c4edb7SDavid Henningsson 	HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
7958607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
7968607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
7972de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
7982de3c232SJiang zhe 	{
7992de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8002de3c232SJiang zhe 		.name = "Master Playback Switch",
8012de3c232SJiang zhe 		.info = cxt_eapd_info,
8022de3c232SJiang zhe 		.get = cxt_eapd_get,
8032de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8042de3c232SJiang zhe 		.private_value = 0x10,
8052de3c232SJiang zhe 	},
8062de3c232SJiang zhe 
8072de3c232SJiang zhe 	{}
8082de3c232SJiang zhe };
8092de3c232SJiang zhe 
81034cbe3a6STakashi Iwai static const struct hda_verb cxt5045_init_verbs[] = {
811c9b443d4STobin Davis 	/* Line in, Mic */
8124090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8137f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
814c9b443d4STobin Davis 	/* HP, Amp  */
815c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
816c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
81782f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
818c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
819c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
820c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
821c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
822c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
823c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
82428c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
8257f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
82682f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
827c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
828c9b443d4STobin Davis 	/* SPDIF route: PCM */
829cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
830c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
831c9b443d4STobin Davis 	/* EAPD */
83282f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
833c9b443d4STobin Davis 	{ } /* end */
834c9b443d4STobin Davis };
835c9b443d4STobin Davis 
83634cbe3a6STakashi Iwai static const struct hda_verb cxt5045_benq_init_verbs[] = {
83728c4edb7SDavid Henningsson 	/* Internal Mic, Mic */
8385218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8395218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8405218c892SJiang Zhe 	/* Line In,HP, Amp  */
8415218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8425218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
8435218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8445218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
8455218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8465218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8475218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8485218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8495218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
85028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
8515218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
8525218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
8535218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
8545218c892SJiang Zhe 	/* SPDIF route: PCM */
855cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8565218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
8575218c892SJiang Zhe 	/* EAPD */
8585218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
8595218c892SJiang Zhe 	{ } /* end */
8605218c892SJiang Zhe };
8617f29673bSTobin Davis 
86234cbe3a6STakashi Iwai static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
8637f29673bSTobin Davis 	/* pin sensing on HP jack */
8647f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
865d3091fadSTakashi Iwai 	{ } /* end */
8667f29673bSTobin Davis };
8677f29673bSTobin Davis 
86834cbe3a6STakashi Iwai static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
8697f29673bSTobin Davis 	/* pin sensing on HP jack */
8707f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
871d3091fadSTakashi Iwai 	{ } /* end */
8727f29673bSTobin Davis };
8737f29673bSTobin Davis 
874c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
875c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
876c9b443d4STobin Davis  * configuration.
877c9b443d4STobin Davis  */
87834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5045_test_capture_source = {
879c9b443d4STobin Davis 	.num_items = 5,
880c9b443d4STobin Davis 	.items = {
881c9b443d4STobin Davis 		{ "MIXER", 0x0 },
882c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
883c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
884c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
885c9b443d4STobin Davis 		{ "CD pin", 0x4 },
886c9b443d4STobin Davis         },
887c9b443d4STobin Davis };
888c9b443d4STobin Davis 
88934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
890c9b443d4STobin Davis 
891c9b443d4STobin Davis 	/* Output controls */
892c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
893c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
894250f3274SMichael Karcher 	HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
895250f3274SMichael Karcher 	HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
896250f3274SMichael Karcher 	HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
897250f3274SMichael Karcher 	HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
898c9b443d4STobin Davis 
899c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
900c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
901c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
902c9b443d4STobin Davis 
90382f30040STobin Davis 	/* EAPD Switch Control */
90482f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
90582f30040STobin Davis 
906c9b443d4STobin Davis 	/* Loopback mixer controls */
907c9b443d4STobin Davis 
908250f3274SMichael Karcher 	HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
909250f3274SMichael Karcher 	HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
910250f3274SMichael Karcher 	HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
911250f3274SMichael Karcher 	HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
912250f3274SMichael Karcher 	HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
913250f3274SMichael Karcher 	HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
914250f3274SMichael Karcher 	HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
915250f3274SMichael Karcher 	HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
916250f3274SMichael Karcher 	HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
917250f3274SMichael Karcher 	HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
918c9b443d4STobin Davis 	{
919c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
920c9b443d4STobin Davis 		.name = "Input Source",
921c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
922c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
923c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
924c9b443d4STobin Davis 	},
925fb3409e7STobin Davis 	/* Audio input controls */
926cbf2d28eSMichael Karcher 	HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
927cbf2d28eSMichael Karcher 	HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
928c9b443d4STobin Davis 	{ } /* end */
929c9b443d4STobin Davis };
930c9b443d4STobin Davis 
93134cbe3a6STakashi Iwai static const struct hda_verb cxt5045_test_init_verbs[] = {
9327f29673bSTobin Davis 	/* Set connections */
9337f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9347f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
9357f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
936c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
937c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9387f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
939c9b443d4STobin Davis 
940c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
941c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
942c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
943c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
944c9b443d4STobin Davis 	 * control.
945c9b443d4STobin Davis 	 */
946cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
947cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
948c9b443d4STobin Davis 
949c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
950c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
951c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
952c9b443d4STobin Davis 	 * input/output buffers as needed.
953c9b443d4STobin Davis 	 */
954c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
955c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
956c9b443d4STobin Davis 
957c9b443d4STobin Davis 	/* Mute capture amp left and right */
958c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
959c9b443d4STobin Davis 
960c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
961c9b443d4STobin Davis 	 * pin)
962c9b443d4STobin Davis 	 */
963250f3274SMichael Karcher 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
964250f3274SMichael Karcher 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
965c9b443d4STobin Davis 
966c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
967250f3274SMichael Karcher 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
968c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
969c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
970c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
971c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
972c9b443d4STobin Davis 
973c9b443d4STobin Davis 	{ }
974c9b443d4STobin Davis };
975c9b443d4STobin Davis #endif
976c9b443d4STobin Davis 
977c9b443d4STobin Davis 
978c9b443d4STobin Davis /* initialize jack-sensing, too */
979c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
980c9b443d4STobin Davis {
981c9b443d4STobin Davis 	conexant_init(codec);
982c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
983c9b443d4STobin Davis 	return 0;
984c9b443d4STobin Davis }
985c9b443d4STobin Davis 
986c9b443d4STobin Davis 
987c9b443d4STobin Davis enum {
98815908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
98915908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
99015908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
9915218c892SJiang Zhe 	CXT5045_BENQ,
9922de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
993c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
994c9b443d4STobin Davis 	CXT5045_TEST,
995c9b443d4STobin Davis #endif
9961f8458a2STakashi Iwai 	CXT5045_AUTO,
997f5fcc13cSTakashi Iwai 	CXT5045_MODELS
998c9b443d4STobin Davis };
999c9b443d4STobin Davis 
1000ea734963STakashi Iwai static const char * const cxt5045_models[CXT5045_MODELS] = {
100115908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
100215908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
100315908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10045218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10052de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1006c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1007f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1008c9b443d4STobin Davis #endif
10091f8458a2STakashi Iwai 	[CXT5045_AUTO]			= "auto",
1010f5fcc13cSTakashi Iwai };
1011c9b443d4STobin Davis 
101234cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10132de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
10146a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10155218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
101615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
101715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10189e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10199e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
102015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1023dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1024dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
102515908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1026c9b443d4STobin Davis 	{}
1027c9b443d4STobin Davis };
1028c9b443d4STobin Davis 
1029c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1030c9b443d4STobin Davis {
1031c9b443d4STobin Davis 	struct conexant_spec *spec;
1032c9b443d4STobin Davis 	int board_config;
1033c9b443d4STobin Davis 
10341f8458a2STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
10351f8458a2STakashi Iwai 						  cxt5045_models,
10361f8458a2STakashi Iwai 						  cxt5045_cfg_tbl);
10371f8458a2STakashi Iwai 	if (board_config < 0)
1038c82693dbSTakashi Iwai 		board_config = CXT5045_AUTO; /* model=auto as default */
10391f8458a2STakashi Iwai 	if (board_config == CXT5045_AUTO)
10401f8458a2STakashi Iwai 		return patch_conexant_auto(codec);
10411f8458a2STakashi Iwai 
1042c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1043c9b443d4STobin Davis 	if (!spec)
1044c9b443d4STobin Davis 		return -ENOMEM;
1045c9b443d4STobin Davis 	codec->spec = spec;
10464f32456eSMichael Karcher 	codec->single_adc_amp = 1;
1047c9b443d4STobin Davis 
1048c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1049c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1050c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1051c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1052c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1053c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1054c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1055c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1056c9b443d4STobin Davis 	spec->num_mixers = 1;
1057c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1058c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1059c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1060c9b443d4STobin Davis 	spec->spdif_route = 0;
10613507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
10623507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
10635cd57529STobin Davis 
10643507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1065c9b443d4STobin Davis 
1066c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1067c9b443d4STobin Davis 
1068c9b443d4STobin Davis 	switch (board_config) {
106915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
10707f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1071c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1072c9b443d4STobin Davis 		spec->num_init_verbs = 2;
10737f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
10747f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
10757f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
10767f29673bSTobin Davis 		break;
107715908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
107886376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10797f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
10807f29673bSTobin Davis 		spec->num_init_verbs = 2;
10817f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1082c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1083c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1084c9b443d4STobin Davis 		break;
108515908c36SMarc Boucher 	default:
108615908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
108715908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
108815908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
108915908c36SMarc Boucher 		spec->num_init_verbs = 3;
109015908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
109115908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
109215908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
109315908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
109415908c36SMarc Boucher 		break;
10955218c892SJiang Zhe 	case CXT5045_BENQ:
10965218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10975218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
10985218c892SJiang Zhe 		spec->num_init_verbs = 1;
10995218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11005218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11015218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11025218c892SJiang Zhe 		spec->num_mixers = 2;
11035218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11045218c892SJiang Zhe 		break;
11052de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11062de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11072de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11082de3c232SJiang zhe 		spec->num_init_verbs = 2;
11092de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11102de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11112de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11122de3c232SJiang zhe 		break;
1113c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1114c9b443d4STobin Davis 	case CXT5045_TEST:
1115c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1116c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1117c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
111815908c36SMarc Boucher 		break;
111915908c36SMarc Boucher 
1120c9b443d4STobin Davis #endif
1121c9b443d4STobin Davis 	}
112248ecb7e8STakashi Iwai 
1123031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1124031005f7STakashi Iwai 	case 0x103c:
11258f0f5ff6SDaniel T Chen 	case 0x1631:
11260b587fc4SDaniel T Chen 	case 0x1734:
11270ebf9e36SDaniel T Chen 	case 0x17aa:
11280ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
11290ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
11300ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
113148ecb7e8STakashi Iwai 		 */
113248ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
113348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
113448ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
113548ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
113648ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1137031005f7STakashi Iwai 		break;
1138031005f7STakashi Iwai 	}
113948ecb7e8STakashi Iwai 
11403507e2a8STakashi Iwai 	if (spec->beep_amp)
11413507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
11423507e2a8STakashi Iwai 
1143c9b443d4STobin Davis 	return 0;
1144c9b443d4STobin Davis }
1145c9b443d4STobin Davis 
1146c9b443d4STobin Davis 
1147c9b443d4STobin Davis /* Conexant 5047 specific */
114882f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1149c9b443d4STobin Davis 
115034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
115134cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
115234cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1153c9b443d4STobin Davis 
115434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
11555cd57529STobin Davis 	{ 2, NULL },
11565cd57529STobin Davis };
1157c9b443d4STobin Davis 
115834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
115982f30040STobin Davis 	.num_items = 2,
116082f30040STobin Davis 	.items = {
116182f30040STobin Davis 		{ "ExtMic", 0x2 },
116282f30040STobin Davis 		{ "Line-In", 0x1 },
1163c9b443d4STobin Davis 	}
1164c9b443d4STobin Davis };
1165c9b443d4STobin Davis 
1166c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1167c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1168c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1169c9b443d4STobin Davis {
1170c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1171c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
117282f30040STobin Davis 	unsigned int bits;
1173c9b443d4STobin Davis 
117482f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1175c9b443d4STobin Davis 		return 0;
1176c9b443d4STobin Davis 
117782f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
117882f30040STobin Davis 	 * the headphone jack
117982f30040STobin Davis 	 */
118047fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
11813b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
11823b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
11833b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
11843b7523fcSTakashi Iwai 	 */
11855d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
118647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
118747fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
118847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
118947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1190c9b443d4STobin Davis 	return 1;
1191c9b443d4STobin Davis }
1192c9b443d4STobin Davis 
1193c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1194c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1195c9b443d4STobin Davis {
119682f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1197dd87da1cSTobin Davis 	unsigned int bits;
1198c9b443d4STobin Davis 
1199d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1200dd87da1cSTobin Davis 
120147fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12023b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12035d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
120447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1205c9b443d4STobin Davis }
1206c9b443d4STobin Davis 
1207c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1208c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1209c9b443d4STobin Davis {
121034cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
12119f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12129f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1213c9b443d4STobin Davis 		{}
1214c9b443d4STobin Davis 	};
121534cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
12169f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12179f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1218c9b443d4STobin Davis 		{}
1219c9b443d4STobin Davis 	};
1220c9b443d4STobin Davis 	unsigned int present;
1221c9b443d4STobin Davis 
1222d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1223c9b443d4STobin Davis 	if (present)
1224c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1225c9b443d4STobin Davis 	else
1226c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1227c9b443d4STobin Davis }
1228c9b443d4STobin Davis 
1229c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1230c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1231c9b443d4STobin Davis 				  unsigned int res)
1232c9b443d4STobin Davis {
12339f113e0eSMarc Boucher 	switch (res >> 26) {
1234c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1235c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1236c9b443d4STobin Davis 		break;
1237c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1238c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1239c9b443d4STobin Davis 		break;
1240c9b443d4STobin Davis 	}
1241c9b443d4STobin Davis }
1242c9b443d4STobin Davis 
124334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1244df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1245df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
12465f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1247c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1248c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1249c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1250c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
125182f30040STobin Davis 	{
125282f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
125382f30040STobin Davis 		.name = "Master Playback Switch",
125482f30040STobin Davis 		.info = cxt_eapd_info,
125582f30040STobin Davis 		.get = cxt_eapd_get,
1256c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1257c9b443d4STobin Davis 		.private_value = 0x13,
1258c9b443d4STobin Davis 	},
1259c9b443d4STobin Davis 
1260c9b443d4STobin Davis 	{}
1261c9b443d4STobin Davis };
1262c9b443d4STobin Davis 
126334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
12643b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12655d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1266df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1267df481e41STakashi Iwai 	{}
1268df481e41STakashi Iwai };
1269df481e41STakashi Iwai 
127034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1271c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1272c9b443d4STobin Davis 	{ } /* end */
1273c9b443d4STobin Davis };
1274c9b443d4STobin Davis 
127534cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1276c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1277c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1278c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1279c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
12807f29673bSTobin Davis 	/* HP, Speaker  */
1281b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
12825b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
12835b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
12847f29673bSTobin Davis 	/* Record selector: Mic */
12857f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
12867f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
12877f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
12887f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1289c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1290c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1291c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1292c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1293c9b443d4STobin Davis 	/* SPDIF route: PCM */
1294c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
129582f30040STobin Davis 	/* Enable unsolicited events */
129682f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
129782f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1298c9b443d4STobin Davis 	{ } /* end */
1299c9b443d4STobin Davis };
1300c9b443d4STobin Davis 
1301c9b443d4STobin Davis /* configuration for Toshiba Laptops */
130234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13033b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1304c9b443d4STobin Davis 	{}
1305c9b443d4STobin Davis };
1306c9b443d4STobin Davis 
1307c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1308c9b443d4STobin Davis  * configuration.
1309c9b443d4STobin Davis  */
1310c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
131134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
131282f30040STobin Davis 	.num_items = 4,
1313c9b443d4STobin Davis 	.items = {
131482f30040STobin Davis 		{ "LINE1 pin", 0x0 },
131582f30040STobin Davis 		{ "MIC1 pin", 0x1 },
131682f30040STobin Davis 		{ "MIC2 pin", 0x2 },
131782f30040STobin Davis 		{ "CD pin", 0x3 },
1318c9b443d4STobin Davis         },
1319c9b443d4STobin Davis };
1320c9b443d4STobin Davis 
132134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1322c9b443d4STobin Davis 
1323c9b443d4STobin Davis 	/* Output only controls */
132482f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
132582f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
132682f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
132782f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1328c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1329c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1330c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1331c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
133282f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
133382f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
133482f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
133582f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1336c9b443d4STobin Davis 
1337c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1338c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1339c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1340c9b443d4STobin Davis 
134182f30040STobin Davis 	/* EAPD Switch Control */
134282f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
134382f30040STobin Davis 
1344c9b443d4STobin Davis 	/* Loopback mixer controls */
134582f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
134682f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
134782f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
134882f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
134982f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
135082f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
135182f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
135282f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1353c9b443d4STobin Davis 
135482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
135582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
135682f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
135782f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
135882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
135982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
136082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
136182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1362c9b443d4STobin Davis 	{
1363c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1364c9b443d4STobin Davis 		.name = "Input Source",
1365c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1366c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1367c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1368c9b443d4STobin Davis 	},
1369854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
13709f113e0eSMarc Boucher 
1371c9b443d4STobin Davis 	{ } /* end */
1372c9b443d4STobin Davis };
1373c9b443d4STobin Davis 
137434cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1375c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1376c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1378c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1379c9b443d4STobin Davis 
1380c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1381c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1382c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1383c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1384c9b443d4STobin Davis 	 * control.
1385c9b443d4STobin Davis 	 */
1386c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1387c9b443d4STobin Davis 
1388c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1389c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1390c9b443d4STobin Davis 	 */
1391c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1392c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1393c9b443d4STobin Davis 
1394c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1395c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1396c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1397c9b443d4STobin Davis 
1398c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1399c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1400c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1401c9b443d4STobin Davis 	 * input/output buffers as needed.
1402c9b443d4STobin Davis 	 */
1403c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1404c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1405c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1406c9b443d4STobin Davis 
1407c9b443d4STobin Davis 	/* Mute capture amp left and right */
1408c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1409c9b443d4STobin Davis 
1410c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1411c9b443d4STobin Davis 	 * pin)
1412c9b443d4STobin Davis 	 */
1413c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1414c9b443d4STobin Davis 
1415c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1416c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1417c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1418c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1419c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1420c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1421c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1422c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1423c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1424c9b443d4STobin Davis 
1425c9b443d4STobin Davis 	{ }
1426c9b443d4STobin Davis };
1427c9b443d4STobin Davis #endif
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis 
1430c9b443d4STobin Davis /* initialize jack-sensing, too */
1431c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1432c9b443d4STobin Davis {
1433c9b443d4STobin Davis 	conexant_init(codec);
1434c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1435c9b443d4STobin Davis 	return 0;
1436c9b443d4STobin Davis }
1437c9b443d4STobin Davis 
1438c9b443d4STobin Davis 
1439c9b443d4STobin Davis enum {
1440f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1441f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1442f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1443c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1444c9b443d4STobin Davis 	CXT5047_TEST,
1445c9b443d4STobin Davis #endif
1446fa5dadcbSTakashi Iwai 	CXT5047_AUTO,
1447f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1448c9b443d4STobin Davis };
1449c9b443d4STobin Davis 
1450ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1451f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1452f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1453f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1454c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1455f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1456c9b443d4STobin Davis #endif
1457fa5dadcbSTakashi Iwai 	[CXT5047_AUTO]		= "auto",
1458f5fcc13cSTakashi Iwai };
1459c9b443d4STobin Davis 
146034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1461ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1462dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1463dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1464f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1465c9b443d4STobin Davis 	{}
1466c9b443d4STobin Davis };
1467c9b443d4STobin Davis 
1468c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1469c9b443d4STobin Davis {
1470c9b443d4STobin Davis 	struct conexant_spec *spec;
1471c9b443d4STobin Davis 	int board_config;
1472c9b443d4STobin Davis 
1473fa5dadcbSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1474fa5dadcbSTakashi Iwai 						  cxt5047_models,
1475fa5dadcbSTakashi Iwai 						  cxt5047_cfg_tbl);
1476fa5dadcbSTakashi Iwai 	if (board_config < 0)
1477c82693dbSTakashi Iwai 		board_config = CXT5047_AUTO; /* model=auto as default */
1478fa5dadcbSTakashi Iwai 	if (board_config == CXT5047_AUTO)
1479fa5dadcbSTakashi Iwai 		return patch_conexant_auto(codec);
1480fa5dadcbSTakashi Iwai 
1481c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1482c9b443d4STobin Davis 	if (!spec)
1483c9b443d4STobin Davis 		return -ENOMEM;
1484c9b443d4STobin Davis 	codec->spec = spec;
14859421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1486c9b443d4STobin Davis 
1487c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1488c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1489c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1490c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1491c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1492c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1493c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1494c9b443d4STobin Davis 	spec->num_mixers = 1;
1495df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1496c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1497c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1498c9b443d4STobin Davis 	spec->spdif_route = 0;
14995cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15005cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1501c9b443d4STobin Davis 
1502c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1503c9b443d4STobin Davis 
1504c9b443d4STobin Davis 	switch (board_config) {
1505c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1506df481e41STakashi Iwai 		spec->num_mixers = 2;
1507df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1508df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1509c9b443d4STobin Davis 		break;
1510c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1511df481e41STakashi Iwai 		spec->num_mixers = 2;
1512df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1513fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1514c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1515c9b443d4STobin Davis 		break;
1516c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
151782f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1518df481e41STakashi Iwai 		spec->num_mixers = 2;
1519df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1520c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1521c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1522fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1523c9b443d4STobin Davis 		break;
1524c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1525c9b443d4STobin Davis 	case CXT5047_TEST:
1526c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1527c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1528c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1529fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1530c9b443d4STobin Davis #endif
1531c9b443d4STobin Davis 	}
1532dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1533025f206cSDaniel T Chen 
1534025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1535025f206cSDaniel T Chen 	case 0x103c:
1536025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1537025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1538025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1539025f206cSDaniel T Chen 		 */
1540025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1541025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1542025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1543025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1544025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1545025f206cSDaniel T Chen 		break;
1546025f206cSDaniel T Chen 	}
1547025f206cSDaniel T Chen 
1548c9b443d4STobin Davis 	return 0;
1549c9b443d4STobin Davis }
1550c9b443d4STobin Davis 
1551461e2c78STakashi Iwai /* Conexant 5051 specific */
155234cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
155334cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1554461e2c78STakashi Iwai 
155534cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1556461e2c78STakashi Iwai 	{ 2, NULL },
1557461e2c78STakashi Iwai };
1558461e2c78STakashi Iwai 
1559461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1560461e2c78STakashi Iwai {
1561461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1562461e2c78STakashi Iwai 	unsigned int pinctl;
156323d2df5bSTakashi Iwai 	/* headphone pin */
156423d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1565cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x16, pinctl);
156623d2df5bSTakashi Iwai 	/* speaker pin */
1567461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1568cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1569a80581d0SJustin P. Mattock 	/* on ideapad there is an additional speaker (subwoofer) to mute */
1570f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1571cdd03cedSTakashi Iwai 		snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1572461e2c78STakashi Iwai }
1573461e2c78STakashi Iwai 
1574461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1575461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1576461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1577461e2c78STakashi Iwai {
1578461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1579461e2c78STakashi Iwai 
1580461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1581461e2c78STakashi Iwai 		return 0;
1582461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1583461e2c78STakashi Iwai 	return 1;
1584461e2c78STakashi Iwai }
1585461e2c78STakashi Iwai 
1586461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1587461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1588461e2c78STakashi Iwai {
158979d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1590461e2c78STakashi Iwai 	unsigned int present;
1591461e2c78STakashi Iwai 
1592faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
159379d7d533STakashi Iwai 		return;
1594d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1595461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1596461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1597461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1598461e2c78STakashi Iwai }
1599461e2c78STakashi Iwai 
1600461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1601461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1602461e2c78STakashi Iwai {
1603461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1604461e2c78STakashi Iwai 	unsigned int present;
1605461e2c78STakashi Iwai 	hda_nid_t new_adc;
1606461e2c78STakashi Iwai 
1607faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
160879d7d533STakashi Iwai 		return;
1609d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1610461e2c78STakashi Iwai 	if (present)
1611461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1612461e2c78STakashi Iwai 	else
1613461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1614461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1615461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1616461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1617f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1618461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1619461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1620461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1621461e2c78STakashi Iwai 					   spec->cur_adc_format);
1622461e2c78STakashi Iwai 	}
1623461e2c78STakashi Iwai }
1624461e2c78STakashi Iwai 
1625461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1626461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1627461e2c78STakashi Iwai {
1628461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1629461e2c78STakashi Iwai 
1630d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1631461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1632461e2c78STakashi Iwai }
1633461e2c78STakashi Iwai 
1634461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1635461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1636461e2c78STakashi Iwai 				   unsigned int res)
1637461e2c78STakashi Iwai {
1638461e2c78STakashi Iwai 	switch (res >> 26) {
1639461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1640461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1641461e2c78STakashi Iwai 		break;
1642461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1643461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1644461e2c78STakashi Iwai 		break;
1645461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1646461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1647461e2c78STakashi Iwai 		break;
1648461e2c78STakashi Iwai 	}
1649461e2c78STakashi Iwai }
1650461e2c78STakashi Iwai 
165134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1652461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1653461e2c78STakashi Iwai 	{
1654461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1655461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1656461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1657461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1658461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1659461e2c78STakashi Iwai 		.private_value = 0x1a,
1660461e2c78STakashi Iwai 	},
16612c7a3fb3STakashi Iwai 	{}
16622c7a3fb3STakashi Iwai };
1663461e2c78STakashi Iwai 
166434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
16652c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
16662c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16678607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
16688607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1669c40bd914SDavid Henningsson 	HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1670c40bd914SDavid Henningsson 	HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1671461e2c78STakashi Iwai 	{}
1672461e2c78STakashi Iwai };
1673461e2c78STakashi Iwai 
167434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1675461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1676461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16778607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
16788607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1679461e2c78STakashi Iwai 	{}
1680461e2c78STakashi Iwai };
1681461e2c78STakashi Iwai 
168234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
16834e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
16844e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
168579d7d533STakashi Iwai 	{}
168679d7d533STakashi Iwai };
168779d7d533STakashi Iwai 
168834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
16895f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
16905f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1691cd9d95a5SKen Prox 	{}
1692cd9d95a5SKen Prox };
1693cd9d95a5SKen Prox 
169434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1695faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1696faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16978607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
16988607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1699faddaa5dSTakashi Iwai 	{}
1700faddaa5dSTakashi Iwai };
1701faddaa5dSTakashi Iwai 
170234cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1703461e2c78STakashi Iwai 	/* Line in, Mic */
1704461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1705461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1706461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1707461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1708461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1709461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1710461e2c78STakashi Iwai 	/* SPK  */
1711461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1712461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1713461e2c78STakashi Iwai 	/* HP, Amp  */
1714461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1715461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1716461e2c78STakashi Iwai 	/* DAC1 */
1717461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
171828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1719461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1720461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1721461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1722461e2c78STakashi Iwai 	/* SPDIF route: PCM */
17231965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1724461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1725461e2c78STakashi Iwai 	/* EAPD */
1726461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1727461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1728461e2c78STakashi Iwai 	{ } /* end */
1729461e2c78STakashi Iwai };
1730461e2c78STakashi Iwai 
173134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
173279d7d533STakashi Iwai 	/* Line in, Mic */
173379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
173479d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
173579d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
173679d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
173779d7d533STakashi Iwai 	/* SPK  */
173879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
173979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
174079d7d533STakashi Iwai 	/* HP, Amp  */
174179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
174279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
174379d7d533STakashi Iwai 	/* DAC1 */
174479d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
174528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
174679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
174779d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
174879d7d533STakashi Iwai 	/* SPDIF route: PCM */
174979d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
175079d7d533STakashi Iwai 	/* EAPD */
175179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
175279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
175379d7d533STakashi Iwai 	{ } /* end */
175479d7d533STakashi Iwai };
175579d7d533STakashi Iwai 
175634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1757cd9d95a5SKen Prox 	/* Line in, Mic */
175830ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1759cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1761cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1762cd9d95a5SKen Prox 	/* SPK  */
1763cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1764cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1765cd9d95a5SKen Prox 	/* HP, Amp  */
1766cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1767cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1768cd9d95a5SKen Prox 	/* DAC1 */
1769cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
177028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1771cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1772cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1773cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1774cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1775cd9d95a5SKen Prox 	/* EAPD */
1776cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1777cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1778cd9d95a5SKen Prox 	{ } /* end */
1779cd9d95a5SKen Prox };
1780cd9d95a5SKen Prox 
17816953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
17826953e552STakashi Iwai 				 unsigned int event)
17836953e552STakashi Iwai {
17846953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
17856953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
17866953e552STakashi Iwai 			    AC_USRSP_EN | event);
17876953e552STakashi Iwai }
17886953e552STakashi Iwai 
178934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1790f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1791f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1792f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1793f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1794f7154de2SHerton Ronaldo Krzesinski };
1795f7154de2SHerton Ronaldo Krzesinski 
1796461e2c78STakashi Iwai /* initialize jack-sensing, too */
1797461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1798461e2c78STakashi Iwai {
17996953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
18006953e552STakashi Iwai 
1801461e2c78STakashi Iwai 	conexant_init(codec);
18026953e552STakashi Iwai 
18036953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
18046953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
18056953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
18066953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
18076953e552STakashi Iwai 
1808461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1809461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1810461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1811461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1812461e2c78STakashi Iwai 	}
1813461e2c78STakashi Iwai 	return 0;
1814461e2c78STakashi Iwai }
1815461e2c78STakashi Iwai 
1816461e2c78STakashi Iwai 
1817461e2c78STakashi Iwai enum {
1818461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1819461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
182079d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
1821cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1822faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1823f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
18246764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1825461e2c78STakashi Iwai 	CXT5051_MODELS
1826461e2c78STakashi Iwai };
1827461e2c78STakashi Iwai 
1828ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1829461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1830461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
183179d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
18325f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1833faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1834f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
18356764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1836461e2c78STakashi Iwai };
1837461e2c78STakashi Iwai 
183834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
183979d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
18401812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
18415f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1842faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1843461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1844461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1845461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1846f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1847461e2c78STakashi Iwai 	{}
1848461e2c78STakashi Iwai };
1849461e2c78STakashi Iwai 
1850461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1851461e2c78STakashi Iwai {
1852461e2c78STakashi Iwai 	struct conexant_spec *spec;
1853461e2c78STakashi Iwai 	int board_config;
1854461e2c78STakashi Iwai 
18556764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
18566764bcefSTakashi Iwai 						  cxt5051_models,
18576764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
18586764bcefSTakashi Iwai 	if (board_config < 0)
1859c82693dbSTakashi Iwai 		board_config = CXT5051_AUTO; /* model=auto as default */
18601f8458a2STakashi Iwai 	if (board_config == CXT5051_AUTO)
18616764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
18626764bcefSTakashi Iwai 
1863461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1864461e2c78STakashi Iwai 	if (!spec)
1865461e2c78STakashi Iwai 		return -ENOMEM;
1866461e2c78STakashi Iwai 	codec->spec = spec;
18679421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1868461e2c78STakashi Iwai 
1869461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1870461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1871461e2c78STakashi Iwai 
1872461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1873461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1874461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1875461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1876461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1877461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
18782c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
18792c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
18802c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
1881461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1882461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1883461e2c78STakashi Iwai 	spec->spdif_route = 0;
1884461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1885461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1886461e2c78STakashi Iwai 	spec->cur_adc = 0;
1887461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1888461e2c78STakashi Iwai 
18893507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
18903507e2a8STakashi Iwai 
189179d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
189279d7d533STakashi Iwai 
1893faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1894461e2c78STakashi Iwai 	switch (board_config) {
1895461e2c78STakashi Iwai 	case CXT5051_HP:
1896461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1897461e2c78STakashi Iwai 		break;
189879d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
189979d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
190079d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1901faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
190279d7d533STakashi Iwai 		break;
1903cd9d95a5SKen Prox 	case CXT5051_F700:
1904cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
1905cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
1906faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
1907faddaa5dSTakashi Iwai 		break;
1908faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
1909faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
1910faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
1911cd9d95a5SKen Prox 		break;
1912f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
1913f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
1914f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
1915f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
1916f7154de2SHerton Ronaldo Krzesinski 		break;
1917461e2c78STakashi Iwai 	}
1918461e2c78STakashi Iwai 
19193507e2a8STakashi Iwai 	if (spec->beep_amp)
19203507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
19213507e2a8STakashi Iwai 
1922461e2c78STakashi Iwai 	return 0;
1923461e2c78STakashi Iwai }
1924461e2c78STakashi Iwai 
19250fb67e98SDaniel Drake /* Conexant 5066 specific */
19260fb67e98SDaniel Drake 
192734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
192834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
192934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
193034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
19310fb67e98SDaniel Drake 
1932dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
1933dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
1934dbaccc0cSDaniel Drake  * the DC input range of the codec. */
1935dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1936dbaccc0cSDaniel Drake 
193734cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
19380fb67e98SDaniel Drake 	{ 2, NULL },
19390fb67e98SDaniel Drake };
19400fb67e98SDaniel Drake 
1941a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
1942a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
1943a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
1944a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
1945a3de8ab8STakashi Iwai 
19460fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
19470fb67e98SDaniel Drake {
19480fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
19490fb67e98SDaniel Drake 	unsigned int pinctl;
19500fb67e98SDaniel Drake 
19513a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
19523a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
19530fb67e98SDaniel Drake 
19540fb67e98SDaniel Drake 	/* Port A (HP) */
1955a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1956cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x19, pinctl);
19570fb67e98SDaniel Drake 
19580fb67e98SDaniel Drake 	/* Port D (HP/LO) */
1959a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1960a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
1961a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
1962a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
19633a253445SJohn Baboval 			pinctl = 0;
19643a253445SJohn Baboval 	} else {
1965a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
1966a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
1967a3de8ab8STakashi Iwai 			pinctl = 0;
19683a253445SJohn Baboval 	}
1969cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
19700fb67e98SDaniel Drake 
19710fb67e98SDaniel Drake 	/* CLASS_D AMP */
19720fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1973cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
19740fb67e98SDaniel Drake }
19750fb67e98SDaniel Drake 
19760fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
19770fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
19780fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
19790fb67e98SDaniel Drake {
19800fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19810fb67e98SDaniel Drake 
19820fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
19830fb67e98SDaniel Drake 		return 0;
19840fb67e98SDaniel Drake 
19850fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
19860fb67e98SDaniel Drake 	return 1;
19870fb67e98SDaniel Drake }
19880fb67e98SDaniel Drake 
1989c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
1990c4cfe66cSDaniel Drake 	.num_items = 3,
1991c4cfe66cSDaniel Drake 	.items = {
1992c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
1993c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
1994c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
1995c4cfe66cSDaniel Drake 	},
1996c4cfe66cSDaniel Drake };
1997c4cfe66cSDaniel Drake 
1998c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
1999c4cfe66cSDaniel Drake {
2000c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2001c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2002c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2003c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2004cdd03cedSTakashi Iwai 	return snd_hda_set_pin_ctl_cache(codec, 0x1a,
2005c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2006c4cfe66cSDaniel Drake }
2007c4cfe66cSDaniel Drake 
200875f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
200975f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
201075f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
201175f8991dSDaniel Drake  * is happening when it is not. */
201275f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
20130fb67e98SDaniel Drake {
2014dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
201575f8991dSDaniel Drake 	if (!spec->recording)
201675f8991dSDaniel Drake 		return;
20170fb67e98SDaniel Drake 
2018c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2019c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2020c4cfe66cSDaniel Drake 		 * through our special DC port */
2021c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2022c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2023c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2024c4cfe66cSDaniel Drake 
2025c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2026c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2027c4cfe66cSDaniel Drake 			{},
2028c4cfe66cSDaniel Drake 		};
2029c4cfe66cSDaniel Drake 
2030c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2031c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2032c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2033c4cfe66cSDaniel Drake 		return;
2034c4cfe66cSDaniel Drake 	}
2035c4cfe66cSDaniel Drake 
2036c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2037cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1e, 0);
2038c4cfe66cSDaniel Drake 
203975f8991dSDaniel Drake 	/* external mic, port B */
2040cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1a,
204175f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
20420fb67e98SDaniel Drake 
204375f8991dSDaniel Drake 	/* internal mic, port C */
2044cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1b,
204575f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
204675f8991dSDaniel Drake }
20470fb67e98SDaniel Drake 
204875f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
204975f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
205075f8991dSDaniel Drake {
205175f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
20520fb67e98SDaniel Drake 	unsigned int present;
20530fb67e98SDaniel Drake 
2054c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2055c4cfe66cSDaniel Drake 		return;
2056c4cfe66cSDaniel Drake 
205775f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
205875f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
205975f8991dSDaniel Drake 	if (present)
20600fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
206175f8991dSDaniel Drake 	else
20620fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
206375f8991dSDaniel Drake 
206475f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
206575f8991dSDaniel Drake 		present ? 0 : 1);
206675f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
206775f8991dSDaniel Drake 
206875f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
20690fb67e98SDaniel Drake }
20700fb67e98SDaniel Drake 
207195a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
207295a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
207395a618bdSEinar Rünkaru {
207495a618bdSEinar Rünkaru 	unsigned int present;
207595a618bdSEinar Rünkaru 
207695a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
207795a618bdSEinar Rünkaru 		/* enable external mic, port B */
207875f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
207995a618bdSEinar Rünkaru 
208095a618bdSEinar Rünkaru 		/* switch to external mic input */
208195a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
208295a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
208395a618bdSEinar Rünkaru 
208495a618bdSEinar Rünkaru 		/* disable internal digital mic */
208595a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
208695a618bdSEinar Rünkaru 		{}
208795a618bdSEinar Rünkaru 	};
208834cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
208995a618bdSEinar Rünkaru 		/* enable internal mic, port C */
209095a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
209195a618bdSEinar Rünkaru 
209295a618bdSEinar Rünkaru 		/* switch to internal mic input */
209395a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
209495a618bdSEinar Rünkaru 
209595a618bdSEinar Rünkaru 		/* disable external mic, port B */
209695a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
209795a618bdSEinar Rünkaru 		{}
209895a618bdSEinar Rünkaru 	};
209995a618bdSEinar Rünkaru 
210095a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
210195a618bdSEinar Rünkaru 	if (present) {
210295a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
210395a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
210495a618bdSEinar Rünkaru 	} else {
210595a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
210695a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
210795a618bdSEinar Rünkaru 	}
210895a618bdSEinar Rünkaru }
210995a618bdSEinar Rünkaru 
2110cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2111cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2112cfd3d8dcSGreg Alexander {
2113cfd3d8dcSGreg Alexander 	unsigned int present;
2114cfd3d8dcSGreg Alexander 
2115cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2116cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2117cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2118cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2119cfd3d8dcSGreg Alexander 		{}
2120cfd3d8dcSGreg Alexander 	};
212134cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2122cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2123cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2124cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2125cfd3d8dcSGreg Alexander 		{}
2126cfd3d8dcSGreg Alexander 	};
2127cfd3d8dcSGreg Alexander 
2128cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2129cfd3d8dcSGreg Alexander 	if (present) {
2130cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2131cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2132cfd3d8dcSGreg Alexander 	} else {
2133cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2134cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2135cfd3d8dcSGreg Alexander 	}
2136cfd3d8dcSGreg Alexander }
2137cfd3d8dcSGreg Alexander 
2138a1d6906eSDavid Henningsson 
2139a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2140a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2141a1d6906eSDavid Henningsson {
2142a1d6906eSDavid Henningsson 	unsigned int present;
2143a1d6906eSDavid Henningsson 
2144a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2145a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2146a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2147a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2148a1d6906eSDavid Henningsson }
2149a1d6906eSDavid Henningsson 
2150a1d6906eSDavid Henningsson 
2151048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2152048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2153048e78a5SDavid Henningsson {
2154048e78a5SDavid Henningsson 	unsigned int present;
2155048e78a5SDavid Henningsson 
2156048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2157048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2158048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2159048e78a5SDavid Henningsson 			    present ? 1 : 3);
2160048e78a5SDavid Henningsson }
2161048e78a5SDavid Henningsson 
2162048e78a5SDavid Henningsson 
21637b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
21647b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
21657b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
21667b2bfdbcSJens Taprogge {
21677b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
21687b2bfdbcSJens Taprogge 
216934cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
21707b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
21717b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
21727b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
21737b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21747b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21757b2bfdbcSJens Taprogge 		{}
21767b2bfdbcSJens Taprogge 	};
217734cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
21787b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
21797b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
21807b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
21817b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21827b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21837b2bfdbcSJens Taprogge 		{}
21847b2bfdbcSJens Taprogge 	};
218534cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
21867b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
21877b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
21887b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21897b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21907b2bfdbcSJens Taprogge 		{}
21917b2bfdbcSJens Taprogge 	};
21927b2bfdbcSJens Taprogge 
21937b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
21947b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
21957b2bfdbcSJens Taprogge 	if (ext_present) {
21967b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
21977b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
21987b2bfdbcSJens Taprogge 	} else if (dock_present) {
21997b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
22007b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
22017b2bfdbcSJens Taprogge 	} else {
22027b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
22037b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
22047b2bfdbcSJens Taprogge 	}
22057b2bfdbcSJens Taprogge }
22067b2bfdbcSJens Taprogge 
22070fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
22080fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
22090fb67e98SDaniel Drake {
22100fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
22110fb67e98SDaniel Drake 	unsigned int portA, portD;
22120fb67e98SDaniel Drake 
22130fb67e98SDaniel Drake 	/* Port A */
2214d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
22150fb67e98SDaniel Drake 
22160fb67e98SDaniel Drake 	/* Port D */
2217d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
22180fb67e98SDaniel Drake 
2219a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2220a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
22210fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
22220fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
22230fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
22240fb67e98SDaniel Drake }
22250fb67e98SDaniel Drake 
222602b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
222702b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
222802b6b5b6SDavid Henningsson {
222902b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
223002b6b5b6SDavid Henningsson 
223102b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
223202b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
223302b6b5b6SDavid Henningsson 	else if (spec->ideapad)
223402b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
223502b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
223602b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
223702b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
223802b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2239a1d6906eSDavid Henningsson 	else if (spec->asus)
2240a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
224102b6b5b6SDavid Henningsson }
224202b6b5b6SDavid Henningsson 
22430fb67e98SDaniel Drake /* unsolicited event for jack sensing */
224475f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
22450fb67e98SDaniel Drake {
2246c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22470fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
22480fb67e98SDaniel Drake 	switch (res >> 26) {
22490fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
22500fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
22510fb67e98SDaniel Drake 		break;
22520fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2253c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2254c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
225575f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
22560fb67e98SDaniel Drake 		break;
22570fb67e98SDaniel Drake 	}
22580fb67e98SDaniel Drake }
22590fb67e98SDaniel Drake 
226095a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
226102b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
226295a618bdSEinar Rünkaru {
226302b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
226495a618bdSEinar Rünkaru 	switch (res >> 26) {
226595a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
226695a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
226795a618bdSEinar Rünkaru 		break;
226895a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
226902b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
227095a618bdSEinar Rünkaru 		break;
227195a618bdSEinar Rünkaru 	}
227295a618bdSEinar Rünkaru }
227395a618bdSEinar Rünkaru 
22747b2bfdbcSJens Taprogge 
22750fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
22760fb67e98SDaniel Drake 	.num_items = 5,
22770fb67e98SDaniel Drake 	.items = {
22780fb67e98SDaniel Drake 		{ "0dB",  0 },
22790fb67e98SDaniel Drake 		{ "10dB", 1 },
22800fb67e98SDaniel Drake 		{ "20dB", 2 },
22810fb67e98SDaniel Drake 		{ "30dB", 3 },
22820fb67e98SDaniel Drake 		{ "40dB", 4 },
22830fb67e98SDaniel Drake 	},
22840fb67e98SDaniel Drake };
22850fb67e98SDaniel Drake 
2286cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2287c4cfe66cSDaniel Drake {
2288c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2289cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2290c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2291c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2292c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
22937b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2294cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2295cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2296cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2297cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2298cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2299cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2300cfd3d8dcSGreg Alexander 	}
2301c4cfe66cSDaniel Drake }
2302c4cfe66cSDaniel Drake 
23030fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
23040fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
23050fb67e98SDaniel Drake {
23060fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
23070fb67e98SDaniel Drake }
23080fb67e98SDaniel Drake 
23090fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
23100fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
23110fb67e98SDaniel Drake {
23120fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2313c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2314c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
23150fb67e98SDaniel Drake 	return 0;
23160fb67e98SDaniel Drake }
23170fb67e98SDaniel Drake 
23180fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
23190fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
23200fb67e98SDaniel Drake {
23210fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2322c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23230fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
23240fb67e98SDaniel Drake 	unsigned int idx;
23250fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
23260fb67e98SDaniel Drake 	if (idx >= imux->num_items)
23270fb67e98SDaniel Drake 		idx = imux->num_items - 1;
23280fb67e98SDaniel Drake 
2329c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2330c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2331c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2332c4cfe66cSDaniel Drake 	return 1;
2333c4cfe66cSDaniel Drake }
23340fb67e98SDaniel Drake 
2335c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2336c4cfe66cSDaniel Drake {
2337c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2338c4cfe66cSDaniel Drake 		/* disable gain */
2339c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2340c4cfe66cSDaniel Drake 
2341c4cfe66cSDaniel Drake 		/* switch to DC input */
2342c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2343c4cfe66cSDaniel Drake 		{}
2344c4cfe66cSDaniel Drake 	};
2345c4cfe66cSDaniel Drake 
2346c4cfe66cSDaniel Drake 	/* configure as input source */
2347c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2348c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2349c4cfe66cSDaniel Drake }
2350c4cfe66cSDaniel Drake 
2351c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2352c4cfe66cSDaniel Drake {
2353c4cfe66cSDaniel Drake 	/* reconfigure input source */
2354c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2355c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2356c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2357c4cfe66cSDaniel Drake }
2358c4cfe66cSDaniel Drake 
2359c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2360c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2361c4cfe66cSDaniel Drake {
2362c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2363c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2364c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2365c4cfe66cSDaniel Drake 	return 0;
2366c4cfe66cSDaniel Drake }
2367c4cfe66cSDaniel Drake 
2368c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2369c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2370c4cfe66cSDaniel Drake {
2371c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2372c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2373c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2374c4cfe66cSDaniel Drake 
2375c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2376c4cfe66cSDaniel Drake 		return 0;
2377c4cfe66cSDaniel Drake 
2378c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2379c4cfe66cSDaniel Drake 	if (dc_enable)
2380c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2381c4cfe66cSDaniel Drake 	else
2382c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2383c4cfe66cSDaniel Drake 
2384c4cfe66cSDaniel Drake 	return 1;
2385c4cfe66cSDaniel Drake }
2386c4cfe66cSDaniel Drake 
2387c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2388c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2389c4cfe66cSDaniel Drake {
2390c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2391c4cfe66cSDaniel Drake }
2392c4cfe66cSDaniel Drake 
2393c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2394c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2395c4cfe66cSDaniel Drake {
2396c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2397c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2398c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2399c4cfe66cSDaniel Drake 	return 0;
2400c4cfe66cSDaniel Drake }
2401c4cfe66cSDaniel Drake 
2402c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2403c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2404c4cfe66cSDaniel Drake {
2405c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2406c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2407c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2408c4cfe66cSDaniel Drake 	unsigned int idx;
2409c4cfe66cSDaniel Drake 
2410c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2411c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2412c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2413c4cfe66cSDaniel Drake 
2414c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2415c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2416c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
24170fb67e98SDaniel Drake 	return 1;
24180fb67e98SDaniel Drake }
24190fb67e98SDaniel Drake 
242075f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
242175f8991dSDaniel Drake {
242275f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
242375f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
242475f8991dSDaniel Drake 	 * recording LED comes on. */
242575f8991dSDaniel Drake 	spec->recording = 1;
242675f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
242775f8991dSDaniel Drake }
242875f8991dSDaniel Drake 
242975f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
243075f8991dSDaniel Drake {
243175f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
243275f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
243375f8991dSDaniel Drake 		/* disable external mic, port B */
243475f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
243575f8991dSDaniel Drake 
243675f8991dSDaniel Drake 		/* disble internal mic, port C */
243775f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2438c4cfe66cSDaniel Drake 
2439c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2440c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
244175f8991dSDaniel Drake 		{},
244275f8991dSDaniel Drake 	};
244375f8991dSDaniel Drake 
244475f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
244575f8991dSDaniel Drake 	spec->recording = 0;
244675f8991dSDaniel Drake }
244775f8991dSDaniel Drake 
2448f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
244934cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2450f6a2491cSAndy Robinson 				    int num_pins)
2451f6a2491cSAndy Robinson {
2452f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2453f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2454f6a2491cSAndy Robinson 	int i;
2455f6a2491cSAndy Robinson 
2456f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2457f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2458f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2459f6a2491cSAndy Robinson 			continue;
2460f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2461f6a2491cSAndy Robinson 			continue;
2462f6a2491cSAndy Robinson 	}
2463f6a2491cSAndy Robinson }
2464f6a2491cSAndy Robinson 
246534cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
24660fb67e98SDaniel Drake 	.num_items = 4,
24670fb67e98SDaniel Drake 	.items = {
24680fb67e98SDaniel Drake 		{ "Mic B", 0 },
24690fb67e98SDaniel Drake 		{ "Mic C", 1 },
24700fb67e98SDaniel Drake 		{ "Mic E", 2 },
24710fb67e98SDaniel Drake 		{ "Mic F", 3 },
24720fb67e98SDaniel Drake 	},
24730fb67e98SDaniel Drake };
24740fb67e98SDaniel Drake 
247534cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
24760fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
24770fb67e98SDaniel Drake 	.values = {
24780fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
24790fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
24800fb67e98SDaniel Drake 		0
24810fb67e98SDaniel Drake 	},
24820fb67e98SDaniel Drake };
24830fb67e98SDaniel Drake 
248434cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
24850fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
24860fb67e98SDaniel Drake 	.values = {
24870fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
24880fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
24890fb67e98SDaniel Drake 		0
24900fb67e98SDaniel Drake 	},
24910fb67e98SDaniel Drake };
24920fb67e98SDaniel Drake 
249334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
24940fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
24950fb67e98SDaniel Drake 	{}
24960fb67e98SDaniel Drake };
24970fb67e98SDaniel Drake 
249834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
24990fb67e98SDaniel Drake 	{
25000fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
25010fb67e98SDaniel Drake 		.name = "Master Playback Volume",
25020fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
25030fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
25040fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
25055e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
25060fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
25070fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
25080fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
25090fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
25100fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
25110fb67e98SDaniel Drake 		.private_value =
25120fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
25130fb67e98SDaniel Drake 	},
25140fb67e98SDaniel Drake 	{}
25150fb67e98SDaniel Drake };
25160fb67e98SDaniel Drake 
251734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2518c4cfe66cSDaniel Drake 	{
2519c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2520c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2521c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2522c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2523c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2524c4cfe66cSDaniel Drake 	},
2525c4cfe66cSDaniel Drake 	{
2526c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2527c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2528c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2529c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2530c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2531c4cfe66cSDaniel Drake 	},
2532c4cfe66cSDaniel Drake 	{}
2533c4cfe66cSDaniel Drake };
2534c4cfe66cSDaniel Drake 
253534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
25360fb67e98SDaniel Drake 	{
25370fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
25380fb67e98SDaniel Drake 		.name = "Master Playback Switch",
25390fb67e98SDaniel Drake 		.info = cxt_eapd_info,
25400fb67e98SDaniel Drake 		.get = cxt_eapd_get,
25410fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
25420fb67e98SDaniel Drake 		.private_value = 0x1d,
25430fb67e98SDaniel Drake 	},
25440fb67e98SDaniel Drake 
25450fb67e98SDaniel Drake 	{
25460fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2547c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
25480fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
25490fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
25500fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
25510fb67e98SDaniel Drake 	},
25520fb67e98SDaniel Drake 
25530fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
25540fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
25550fb67e98SDaniel Drake 	{}
25560fb67e98SDaniel Drake };
25570fb67e98SDaniel Drake 
255834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2559254bba6aSEinar Rünkaru 	{
2560254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
256128c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2562254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2563254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2564254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2565254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2566254bba6aSEinar Rünkaru 	},
2567254bba6aSEinar Rünkaru 	{}
2568254bba6aSEinar Rünkaru };
2569254bba6aSEinar Rünkaru 
257034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
25710fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
25720fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
25730fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
25740fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
25750fb67e98SDaniel Drake 
25760fb67e98SDaniel Drake 	/* Speakers  */
25770fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25780fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
25790fb67e98SDaniel Drake 
25800fb67e98SDaniel Drake 	/* HP, Amp  */
25810fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
25820fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
25830fb67e98SDaniel Drake 
25840fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
25850fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
25860fb67e98SDaniel Drake 
25870fb67e98SDaniel Drake 	/* DAC1 */
25880fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
25890fb67e98SDaniel Drake 
25900fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
25910fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
25920fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
25930fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
25940fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
25950fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
25960fb67e98SDaniel Drake 
25970fb67e98SDaniel Drake 	/* no digital microphone support yet */
25980fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
25990fb67e98SDaniel Drake 
26000fb67e98SDaniel Drake 	/* Audio input selector */
26010fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
26020fb67e98SDaniel Drake 
26030fb67e98SDaniel Drake 	/* SPDIF route: PCM */
26040fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
26050fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
26060fb67e98SDaniel Drake 
26070fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26080fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26090fb67e98SDaniel Drake 
26100fb67e98SDaniel Drake 	/* EAPD */
26110fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
26120fb67e98SDaniel Drake 
26130fb67e98SDaniel Drake 	/* not handling these yet */
26140fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26150fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26160fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26170fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26180fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26190fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26200fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26210fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26220fb67e98SDaniel Drake 	{ } /* end */
26230fb67e98SDaniel Drake };
26240fb67e98SDaniel Drake 
262534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_olpc[] = {
26260fb67e98SDaniel Drake 	/* Port A: headphones */
26270fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
26280fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26290fb67e98SDaniel Drake 
26300fb67e98SDaniel Drake 	/* Port B: external microphone */
263175f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26320fb67e98SDaniel Drake 
26330fb67e98SDaniel Drake 	/* Port C: internal microphone */
263475f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26350fb67e98SDaniel Drake 
26360fb67e98SDaniel Drake 	/* Port D: unused */
26370fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26380fb67e98SDaniel Drake 
26390fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
26400fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26410fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
26420fb67e98SDaniel Drake 
2643c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
26440fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26450fb67e98SDaniel Drake 
26460fb67e98SDaniel Drake 	/* Port G: internal speakers */
26470fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26480fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26490fb67e98SDaniel Drake 
26500fb67e98SDaniel Drake 	/* DAC1 */
26510fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
26520fb67e98SDaniel Drake 
26530fb67e98SDaniel Drake 	/* DAC2: unused */
26540fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
26550fb67e98SDaniel Drake 
26560fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
26570fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
26580fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
26590fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
26600fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
26610fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
26620fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
26630fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
26640fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
26650fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
26660fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
26670fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
26680fb67e98SDaniel Drake 
26690fb67e98SDaniel Drake 	/* Disable digital microphone port */
26700fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26710fb67e98SDaniel Drake 
26720fb67e98SDaniel Drake 	/* Audio input selectors */
26730fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
26740fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
26750fb67e98SDaniel Drake 
26760fb67e98SDaniel Drake 	/* Disable SPDIF */
26770fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26780fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26790fb67e98SDaniel Drake 
26800fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
26810fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
26820fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
26830fb67e98SDaniel Drake 	{ } /* end */
26840fb67e98SDaniel Drake };
26850fb67e98SDaniel Drake 
268634cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
268795a618bdSEinar Rünkaru 	/* Port A: headphones */
268895a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
268995a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
269095a618bdSEinar Rünkaru 
269195a618bdSEinar Rünkaru 	/* Port B: external microphone */
269295a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
269395a618bdSEinar Rünkaru 
269495a618bdSEinar Rünkaru 	/* Port C: unused */
269595a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
269695a618bdSEinar Rünkaru 
269795a618bdSEinar Rünkaru 	/* Port D: unused */
269895a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
269995a618bdSEinar Rünkaru 
270095a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
270195a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
270295a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
270395a618bdSEinar Rünkaru 
270495a618bdSEinar Rünkaru 	/* Port F: unused */
270595a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
270695a618bdSEinar Rünkaru 
270795a618bdSEinar Rünkaru 	/* Port G: internal speakers */
270895a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
270995a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
271095a618bdSEinar Rünkaru 
271195a618bdSEinar Rünkaru 	/* DAC1 */
271295a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
271395a618bdSEinar Rünkaru 
271495a618bdSEinar Rünkaru 	/* DAC2: unused */
271595a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
271695a618bdSEinar Rünkaru 
271795a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
271895a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
271995a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
272095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
272195a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
272295a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
272395a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
272495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
272595a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
272695a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
272795a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
272895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
272995a618bdSEinar Rünkaru 
273095a618bdSEinar Rünkaru 	/* Digital microphone port */
273195a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
273295a618bdSEinar Rünkaru 
273395a618bdSEinar Rünkaru 	/* Audio input selectors */
273495a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
273595a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
273695a618bdSEinar Rünkaru 
273795a618bdSEinar Rünkaru 	/* Disable SPDIF */
273895a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
273995a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
274095a618bdSEinar Rünkaru 
274195a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
274295a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
274395a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
274495a618bdSEinar Rünkaru 	{ } /* end */
274595a618bdSEinar Rünkaru };
274695a618bdSEinar Rünkaru 
274734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2748cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2749cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2750cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2751cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2752cfd3d8dcSGreg Alexander 
2753cfd3d8dcSGreg Alexander 	/* Speakers  */
2754cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2755cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2756cfd3d8dcSGreg Alexander 
2757cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2758cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2759cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2760cfd3d8dcSGreg Alexander 
2761cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2762cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2763cfd3d8dcSGreg Alexander 
2764cfd3d8dcSGreg Alexander 	/* DAC1 */
2765cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2766cfd3d8dcSGreg Alexander 
2767cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2768cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2769cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2770cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2771cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2772cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2773cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2774cfd3d8dcSGreg Alexander 
2775cfd3d8dcSGreg Alexander 	/* Audio input selector */
2776cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2777cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2778cfd3d8dcSGreg Alexander 
2779cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2780cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2781cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2782cfd3d8dcSGreg Alexander 
2783cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2784cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2785cfd3d8dcSGreg Alexander 
2786cfd3d8dcSGreg Alexander 	/* internal microphone */
278728c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2788cfd3d8dcSGreg Alexander 
2789cfd3d8dcSGreg Alexander 	/* EAPD */
2790cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2791cfd3d8dcSGreg Alexander 
2792cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2793cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2794cfd3d8dcSGreg Alexander 	{ } /* end */
2795cfd3d8dcSGreg Alexander };
2796cfd3d8dcSGreg Alexander 
279734cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
27987b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27997b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
28007b2bfdbcSJens Taprogge 
28017b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
28027b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28037b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28047b2bfdbcSJens Taprogge 
28057b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
28067b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28077b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28087b2bfdbcSJens Taprogge 
28097b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
28107b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28117b2bfdbcSJens Taprogge 
28127b2bfdbcSJens Taprogge 	/* Port C: Mic */
28137b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28147b2bfdbcSJens Taprogge 
28157b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
28167b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28177b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28187b2bfdbcSJens Taprogge 
28197b2bfdbcSJens Taprogge 	/* DAC1 */
28207b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28217b2bfdbcSJens Taprogge 
28227b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
28237b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28247b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28257b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
28267b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28277b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
28287b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
28297b2bfdbcSJens Taprogge 
28307b2bfdbcSJens Taprogge 	/* Audio input selector */
28317b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
28327b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
28337b2bfdbcSJens Taprogge 
28347b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
28357b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
28367b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
28377b2bfdbcSJens Taprogge 
28387b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28397b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28407b2bfdbcSJens Taprogge 
28417b2bfdbcSJens Taprogge 	/* internal microphone */
284228c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
28437b2bfdbcSJens Taprogge 
28447b2bfdbcSJens Taprogge 	/* EAPD */
28457b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
28467b2bfdbcSJens Taprogge 
28477b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
28487b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28497b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28507b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28517b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28527b2bfdbcSJens Taprogge 	{ } /* end */
28537b2bfdbcSJens Taprogge };
28547b2bfdbcSJens Taprogge 
285534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
28560fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28570fb67e98SDaniel Drake 	{ } /* end */
28580fb67e98SDaniel Drake };
28590fb67e98SDaniel Drake 
2860048e78a5SDavid Henningsson 
286134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2862048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2863048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2864048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2865048e78a5SDavid Henningsson 	{ } /* end */
2866048e78a5SDavid Henningsson };
2867048e78a5SDavid Henningsson 
28680fb67e98SDaniel Drake /* initialize jack-sensing, too */
28690fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
28700fb67e98SDaniel Drake {
28710fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
28720fb67e98SDaniel Drake 	conexant_init(codec);
28730fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
28740fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
287502b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
28760fb67e98SDaniel Drake 	}
2877c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
28780fb67e98SDaniel Drake 	return 0;
28790fb67e98SDaniel Drake }
28800fb67e98SDaniel Drake 
288175f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
288275f8991dSDaniel Drake {
2883c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
288475f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
288575f8991dSDaniel Drake 	conexant_init(codec);
288675f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
2887c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
2888c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
288975f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
2890c4cfe66cSDaniel Drake 	} else {
2891c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2892c4cfe66cSDaniel Drake 	}
289375f8991dSDaniel Drake 	return 0;
289475f8991dSDaniel Drake }
289575f8991dSDaniel Drake 
28960fb67e98SDaniel Drake enum {
28970fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
28980fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
28990fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
29001feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
2901cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
29027b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
2903a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2904048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
2905fea4a4f9STakashi Iwai 	CXT5066_AUTO,		/* BIOS auto-parser */
29060fb67e98SDaniel Drake 	CXT5066_MODELS
29070fb67e98SDaniel Drake };
29080fb67e98SDaniel Drake 
2909ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
29100fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
29110fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
29120fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
29131feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
2914cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
29157b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
2916a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
2917048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
2918fea4a4f9STakashi Iwai 	[CXT5066_AUTO]		= "auto",
29190fb67e98SDaniel Drake };
29200fb67e98SDaniel Drake 
292134cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
292200cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
29231feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
29248a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2925ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2926231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2927ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2928ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
2929048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2930f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2931a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2932f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
29332ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
2934c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
29355637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
29365637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
29375637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
29384d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2939ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
294019593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
294184012657SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
2942b2cb1292SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
2943d2859fd4SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2944a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
29450fb67e98SDaniel Drake 	{}
29460fb67e98SDaniel Drake };
29470fb67e98SDaniel Drake 
29480fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
29490fb67e98SDaniel Drake {
29500fb67e98SDaniel Drake 	struct conexant_spec *spec;
29510fb67e98SDaniel Drake 	int board_config;
29520fb67e98SDaniel Drake 
2953fea4a4f9STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2954fea4a4f9STakashi Iwai 						  cxt5066_models, cxt5066_cfg_tbl);
2955fea4a4f9STakashi Iwai 	if (board_config < 0)
2956c82693dbSTakashi Iwai 		board_config = CXT5066_AUTO; /* model=auto as default */
2957fea4a4f9STakashi Iwai 	if (board_config == CXT5066_AUTO)
2958fea4a4f9STakashi Iwai 		return patch_conexant_auto(codec);
2959fea4a4f9STakashi Iwai 
29600fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
29610fb67e98SDaniel Drake 	if (!spec)
29620fb67e98SDaniel Drake 		return -ENOMEM;
29630fb67e98SDaniel Drake 	codec->spec = spec;
29640fb67e98SDaniel Drake 
29650fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
296675f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
29670fb67e98SDaniel Drake 
29680fb67e98SDaniel Drake 	spec->dell_automute = 0;
29690fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
29700fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
29710fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
2972f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2973f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
29740fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
29750fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
29760fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
29770fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
29780fb67e98SDaniel Drake 
29790fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
29800fb67e98SDaniel Drake 
29810fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
29820fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
29830fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
29840fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
29850fb67e98SDaniel Drake 	spec->cur_adc = 0;
29860fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
29870fb67e98SDaniel Drake 
29883507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
29893507e2a8STakashi Iwai 
29900fb67e98SDaniel Drake 	switch (board_config) {
29910fb67e98SDaniel Drake 	default:
29920fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
29930fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
29940fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
29950fb67e98SDaniel Drake 		break;
29960fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
29970fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
29980fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
29990fb67e98SDaniel Drake 
30000fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
30010fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
30020fb67e98SDaniel Drake 		spec->num_init_verbs++;
30030fb67e98SDaniel Drake 		spec->dell_automute = 1;
30040fb67e98SDaniel Drake 		break;
3005a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
3006048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
3007048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
300802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3009048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
3010048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
3011048e78a5SDavid Henningsson 		spec->num_init_verbs++;
3012a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
3013a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
3014048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3015048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3016048e78a5SDavid Henningsson 		/* no S/PDIF out */
3017f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
3018048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
3019048e78a5SDavid Henningsson 		/* input source automatically selected */
3020048e78a5SDavid Henningsson 		spec->input_mux = NULL;
3021048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
3022048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
3023048e78a5SDavid Henningsson 		break;
3024048e78a5SDavid Henningsson 
30250fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
302675f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
302775f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
30280fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
30290fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3030c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
30310fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30320fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3033c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
30340fb67e98SDaniel Drake 
30350fb67e98SDaniel Drake 		/* no S/PDIF out */
30360fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
30370fb67e98SDaniel Drake 
30380fb67e98SDaniel Drake 		/* input source automatically selected */
30390fb67e98SDaniel Drake 		spec->input_mux = NULL;
304075f8991dSDaniel Drake 
304175f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
304275f8991dSDaniel Drake 		 * at the right time */
304375f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
304475f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
30450fb67e98SDaniel Drake 		break;
30461feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
304775f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
304802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
304995a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
305095a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
305195a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3052254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
305395a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3054254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3055c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
305695a618bdSEinar Rünkaru 
305795a618bdSEinar Rünkaru 		/* no S/PDIF out */
305895a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
305995a618bdSEinar Rünkaru 
306095a618bdSEinar Rünkaru 		/* input source automatically selected */
306195a618bdSEinar Rünkaru 		spec->input_mux = NULL;
306295a618bdSEinar Rünkaru 		break;
3063cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3064cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
306502b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
3066cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3067cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3068cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3069cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3070cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3071cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3072cfd3d8dcSGreg Alexander 
3073cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3074cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3075cfd3d8dcSGreg Alexander 
3076cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3077cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3078cfd3d8dcSGreg Alexander 		break;
30797b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
30807b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
308102b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
30827b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
30837b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30847b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
30857b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
30867b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
30877b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
30887b2bfdbcSJens Taprogge 
30897b2bfdbcSJens Taprogge 		/* no S/PDIF out */
30907b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
30917b2bfdbcSJens Taprogge 
30927b2bfdbcSJens Taprogge 		/* input source automatically selected */
30937b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
30947b2bfdbcSJens Taprogge 		break;
30950fb67e98SDaniel Drake 	}
30960fb67e98SDaniel Drake 
30973507e2a8STakashi Iwai 	if (spec->beep_amp)
30983507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
30993507e2a8STakashi Iwai 
31000fb67e98SDaniel Drake 	return 0;
31010fb67e98SDaniel Drake }
3102461e2c78STakashi Iwai 
3103461e2c78STakashi Iwai /*
3104f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
3105f2e5731dSTakashi Iwai  */
3106f2e5731dSTakashi Iwai 
3107f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
3108f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
3109f2e5731dSTakashi Iwai {
3110f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3111f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
3112f2e5731dSTakashi Iwai 
3113f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
3114f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
3115f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
3116f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
3117f2e5731dSTakashi Iwai 			break;
3118f2e5731dSTakashi Iwai 		}
3119f2e5731dSTakashi Iwai }
3120f2e5731dSTakashi Iwai #else
3121f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
3122f2e5731dSTakashi Iwai #endif
3123f2e5731dSTakashi Iwai 
3124254f2968STakashi Iwai /* parse EAPDs */
312519110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec)
312619110595STakashi Iwai {
312719110595STakashi Iwai 	struct conexant_spec *spec = codec->spec;
312819110595STakashi Iwai 	hda_nid_t nid, end_nid;
312919110595STakashi Iwai 
313019110595STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
313119110595STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
313219110595STakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
313319110595STakashi Iwai 			continue;
313419110595STakashi Iwai 		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
313519110595STakashi Iwai 			continue;
313619110595STakashi Iwai 		spec->eapds[spec->num_eapds++] = nid;
313719110595STakashi Iwai 		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
313819110595STakashi Iwai 			break;
313919110595STakashi Iwai 	}
3140254f2968STakashi Iwai 
3141254f2968STakashi Iwai 	/* NOTE: below is a wild guess; if we have more than two EAPDs,
3142254f2968STakashi Iwai 	 * it's a new chip, where EAPDs are supposed to be associated to
3143254f2968STakashi Iwai 	 * pins, and we can control EAPD per pin.
3144254f2968STakashi Iwai 	 * OTOH, if only one or two EAPDs are found, it's an old chip,
3145254f2968STakashi Iwai 	 * thus it might control over all pins.
3146254f2968STakashi Iwai 	 */
3147*aed523f1STakashi Iwai 	if (spec->num_eapds > 2)
3148*aed523f1STakashi Iwai 		spec->gen.own_eapd_ctl = 1;
3149f2e5731dSTakashi Iwai }
3150f2e5731dSTakashi Iwai 
3151da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3152da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
3153f2e5731dSTakashi Iwai {
3154f2e5731dSTakashi Iwai 	int i;
3155f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
3156f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
3157f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
3158da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
3159da339866STakashi Iwai 					    on ? 0x02 : 0);
3160f2e5731dSTakashi Iwai 	}
3161f2e5731dSTakashi Iwai }
3162f2e5731dSTakashi Iwai 
3163527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */
3164527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled)
3165527c73baSTakashi Iwai {
3166527c73baSTakashi Iwai 	struct hda_codec *codec = private_data;
3167527c73baSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
3168527c73baSTakashi Iwai 
3169527c73baSTakashi Iwai 	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
3170527c73baSTakashi Iwai }
3171527c73baSTakashi Iwai 
3172f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
3173f2e5731dSTakashi Iwai {
3174f2e5731dSTakashi Iwai 	int err;
3175f2e5731dSTakashi Iwai 
3176*aed523f1STakashi Iwai 	err = snd_hda_gen_build_controls(codec);
3177f2e5731dSTakashi Iwai 	if (err < 0)
3178f2e5731dSTakashi Iwai 		return err;
3179f2e5731dSTakashi Iwai 
3180*aed523f1STakashi Iwai 	err = add_beep_ctls(codec);
3181*aed523f1STakashi Iwai 	if (err < 0)
3182*aed523f1STakashi Iwai 		return err;
318322ce5f74STakashi Iwai 
318422ce5f74STakashi Iwai 	return 0;
318522ce5f74STakashi Iwai }
318622ce5f74STakashi Iwai 
318734cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
3188f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
3189*aed523f1STakashi Iwai 	.build_pcms = snd_hda_gen_build_pcms,
3190*aed523f1STakashi Iwai 	.init = snd_hda_gen_init,
3191*aed523f1STakashi Iwai 	.free = snd_hda_gen_free,
319229adc4b9SDavid Henningsson 	.unsol_event = snd_hda_jack_unsol_event,
3193f2e5731dSTakashi Iwai };
3194f2e5731dSTakashi Iwai 
3195e92d4b08STakashi Iwai /*
3196e92d4b08STakashi Iwai  * pin fix-up
3197e92d4b08STakashi Iwai  */
319818dcd304SDavid Henningsson enum {
319918dcd304SDavid Henningsson 	CXT_PINCFG_LENOVO_X200,
3200d3980110STakashi Iwai 	CXT_PINCFG_LENOVO_TP410,
3201239fb862SHuacai Chen 	CXT_PINCFG_LEMOTE_A1004,
3202239fb862SHuacai Chen 	CXT_PINCFG_LEMOTE_A1205,
320318dcd304SDavid Henningsson 	CXT_FIXUP_STEREO_DMIC,
3204239fb862SHuacai Chen 	CXT_FIXUP_INC_MIC_BOOST,
320518dcd304SDavid Henningsson };
320618dcd304SDavid Henningsson 
320723d30f28STakashi Iwai static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
320823d30f28STakashi Iwai 				  const struct hda_fixup *fix, int action)
3209e92d4b08STakashi Iwai {
321018dcd304SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
3211*aed523f1STakashi Iwai 	spec->gen.inv_dmic_split = 1;
3212e92d4b08STakashi Iwai }
3213e92d4b08STakashi Iwai 
3214239fb862SHuacai Chen static void cxt5066_increase_mic_boost(struct hda_codec *codec,
3215239fb862SHuacai Chen 				   const struct hda_fixup *fix, int action)
3216239fb862SHuacai Chen {
3217239fb862SHuacai Chen 	if (action != HDA_FIXUP_ACT_PRE_PROBE)
3218239fb862SHuacai Chen 		return;
3219239fb862SHuacai Chen 
3220239fb862SHuacai Chen 	snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
3221239fb862SHuacai Chen 				  (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
3222239fb862SHuacai Chen 				  (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3223239fb862SHuacai Chen 				  (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3224239fb862SHuacai Chen 				  (0 << AC_AMPCAP_MUTE_SHIFT));
3225239fb862SHuacai Chen }
3226239fb862SHuacai Chen 
3227d70f3632STakashi Iwai /* ThinkPad X200 & co with cxt5051 */
322823d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
3229e92d4b08STakashi Iwai 	{ 0x16, 0x042140ff }, /* HP (seq# overridden) */
3230e92d4b08STakashi Iwai 	{ 0x17, 0x21a11000 }, /* dock-mic */
3231e92d4b08STakashi Iwai 	{ 0x19, 0x2121103f }, /* dock-HP */
32323e93f5efSTakashi Iwai 	{ 0x1c, 0x21440100 }, /* dock SPDIF out */
3233e92d4b08STakashi Iwai 	{}
3234e92d4b08STakashi Iwai };
3235e92d4b08STakashi Iwai 
3236d70f3632STakashi Iwai /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
323723d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
3238d70f3632STakashi Iwai 	{ 0x19, 0x042110ff }, /* HP (seq# overridden) */
3239d70f3632STakashi Iwai 	{ 0x1a, 0x21a190f0 }, /* dock-mic */
3240d70f3632STakashi Iwai 	{ 0x1c, 0x212140ff }, /* dock-HP */
3241d70f3632STakashi Iwai 	{}
3242e92d4b08STakashi Iwai };
3243e92d4b08STakashi Iwai 
3244239fb862SHuacai Chen /* Lemote A1004/A1205 with cxt5066 */
3245239fb862SHuacai Chen static const struct hda_pintbl cxt_pincfg_lemote[] = {
3246239fb862SHuacai Chen 	{ 0x1a, 0x90a10020 }, /* Internal mic */
3247239fb862SHuacai Chen 	{ 0x1b, 0x03a11020 }, /* External mic */
3248239fb862SHuacai Chen 	{ 0x1d, 0x400101f0 }, /* Not used */
3249239fb862SHuacai Chen 	{ 0x1e, 0x40a701f0 }, /* Not used */
3250239fb862SHuacai Chen 	{ 0x20, 0x404501f0 }, /* Not used */
3251239fb862SHuacai Chen 	{ 0x22, 0x404401f0 }, /* Not used */
3252239fb862SHuacai Chen 	{ 0x23, 0x40a701f0 }, /* Not used */
3253239fb862SHuacai Chen 	{}
3254239fb862SHuacai Chen };
3255239fb862SHuacai Chen 
325623d30f28STakashi Iwai static const struct hda_fixup cxt_fixups[] = {
325723d30f28STakashi Iwai 	[CXT_PINCFG_LENOVO_X200] = {
325823d30f28STakashi Iwai 		.type = HDA_FIXUP_PINS,
325923d30f28STakashi Iwai 		.v.pins = cxt_pincfg_lenovo_x200,
326023d30f28STakashi Iwai 	},
326123d30f28STakashi Iwai 	[CXT_PINCFG_LENOVO_TP410] = {
326223d30f28STakashi Iwai 		.type = HDA_FIXUP_PINS,
326323d30f28STakashi Iwai 		.v.pins = cxt_pincfg_lenovo_tp410,
326423d30f28STakashi Iwai 	},
3265239fb862SHuacai Chen 	[CXT_PINCFG_LEMOTE_A1004] = {
3266239fb862SHuacai Chen 		.type = HDA_FIXUP_PINS,
3267239fb862SHuacai Chen 		.chained = true,
3268239fb862SHuacai Chen 		.chain_id = CXT_FIXUP_INC_MIC_BOOST,
3269239fb862SHuacai Chen 		.v.pins = cxt_pincfg_lemote,
3270239fb862SHuacai Chen 	},
3271239fb862SHuacai Chen 	[CXT_PINCFG_LEMOTE_A1205] = {
3272239fb862SHuacai Chen 		.type = HDA_FIXUP_PINS,
3273239fb862SHuacai Chen 		.v.pins = cxt_pincfg_lemote,
3274239fb862SHuacai Chen 	},
327523d30f28STakashi Iwai 	[CXT_FIXUP_STEREO_DMIC] = {
327623d30f28STakashi Iwai 		.type = HDA_FIXUP_FUNC,
327723d30f28STakashi Iwai 		.v.func = cxt_fixup_stereo_dmic,
327823d30f28STakashi Iwai 	},
3279239fb862SHuacai Chen 	[CXT_FIXUP_INC_MIC_BOOST] = {
3280239fb862SHuacai Chen 		.type = HDA_FIXUP_FUNC,
3281239fb862SHuacai Chen 		.v.func = cxt5066_increase_mic_boost,
3282239fb862SHuacai Chen 	},
3283e92d4b08STakashi Iwai };
3284e92d4b08STakashi Iwai 
3285d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5051_fixups[] = {
3286e92d4b08STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3287e92d4b08STakashi Iwai 	{}
3288e92d4b08STakashi Iwai };
3289e92d4b08STakashi Iwai 
3290d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5066_fixups[] = {
329163a077e2STakashi Iwai 	SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
3292d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3293d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3294d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3295d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3296d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
329718dcd304SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
3298e4db0952SFelix Kaechele 	SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
3299b3c5dce8SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
3300239fb862SHuacai Chen 	SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3301239fb862SHuacai Chen 	SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
3302f2e5731dSTakashi Iwai 	{}
3303f2e5731dSTakashi Iwai };
3304f2e5731dSTakashi Iwai 
33053868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
33063868137eSTakashi Iwai  * can be created (bko#42825)
33073868137eSTakashi Iwai  */
33083868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec)
33093868137eSTakashi Iwai {
33103868137eSTakashi Iwai 	static hda_nid_t out_nids[] = {
33113868137eSTakashi Iwai 		0x10, 0x11, 0
33123868137eSTakashi Iwai 	};
33133868137eSTakashi Iwai 	hda_nid_t *p;
33143868137eSTakashi Iwai 
33153868137eSTakashi Iwai 	for (p = out_nids; *p; p++)
33163868137eSTakashi Iwai 		snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
33173868137eSTakashi Iwai 					  AC_AMPCAP_MIN_MUTE |
33183868137eSTakashi Iwai 					  query_amp_caps(codec, *p, HDA_OUTPUT));
33193868137eSTakashi Iwai }
33203868137eSTakashi Iwai 
3321f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3322f2e5731dSTakashi Iwai {
3323f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3324f2e5731dSTakashi Iwai 	int err;
3325f2e5731dSTakashi Iwai 
33261f8458a2STakashi Iwai 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
33271f8458a2STakashi Iwai 	       codec->chip_name);
33281f8458a2STakashi Iwai 
3329f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3330f2e5731dSTakashi Iwai 	if (!spec)
3331f2e5731dSTakashi Iwai 		return -ENOMEM;
3332*aed523f1STakashi Iwai 	snd_hda_gen_spec_init(&spec->gen);
3333f2e5731dSTakashi Iwai 	codec->spec = spec;
3334e92d4b08STakashi Iwai 
3335*aed523f1STakashi Iwai 	cx_auto_parse_beep(codec);
3336*aed523f1STakashi Iwai 	cx_auto_parse_eapd(codec);
3337*aed523f1STakashi Iwai 	if (spec->gen.own_eapd_ctl)
3338*aed523f1STakashi Iwai 		spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
3339*aed523f1STakashi Iwai 
33406b452142STakashi Iwai 	switch (codec->vendor_id) {
33416b452142STakashi Iwai 	case 0x14f15045:
33424f32456eSMichael Karcher 		codec->single_adc_amp = 1;
33436b452142STakashi Iwai 		break;
33443868137eSTakashi Iwai 	case 0x14f15051:
33453868137eSTakashi Iwai 		add_cx5051_fake_mutes(codec);
334651969d62SMichael Karcher 		codec->pin_amp_workaround = 1;
334723d30f28STakashi Iwai 		snd_hda_pick_fixup(codec, NULL, cxt5051_fixups, cxt_fixups);
33483868137eSTakashi Iwai 		break;
334951969d62SMichael Karcher 	default:
335051969d62SMichael Karcher 		codec->pin_amp_workaround = 1;
335123d30f28STakashi Iwai 		snd_hda_pick_fixup(codec, NULL, cxt5066_fixups, cxt_fixups);
335223d30f28STakashi Iwai 		break;
33536b452142STakashi Iwai 	}
33546b452142STakashi Iwai 
3355f29735cbSTakashi Iwai 	/* Show mute-led control only on HP laptops
3356f29735cbSTakashi Iwai 	 * This is a sort of white-list: on HP laptops, EAPD corresponds
3357f29735cbSTakashi Iwai 	 * only to the mute-LED without actualy amp function.  Meanwhile,
3358f29735cbSTakashi Iwai 	 * others may use EAPD really as an amp switch, so it might be
3359f29735cbSTakashi Iwai 	 * not good to expose it blindly.
3360527c73baSTakashi Iwai 	 */
3361f29735cbSTakashi Iwai 	switch (codec->subsystem_id >> 16) {
3362f29735cbSTakashi Iwai 	case 0x103c:
3363*aed523f1STakashi Iwai 		spec->gen.vmaster_mute_enum = 1;
3364f29735cbSTakashi Iwai 		break;
3365f29735cbSTakashi Iwai 	}
3366527c73baSTakashi Iwai 
3367*aed523f1STakashi Iwai 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3368*aed523f1STakashi Iwai 
3369*aed523f1STakashi Iwai 	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
337022ce5f74STakashi Iwai 	if (err < 0)
3371*aed523f1STakashi Iwai 		goto error;
3372*aed523f1STakashi Iwai 
3373*aed523f1STakashi Iwai 	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3374*aed523f1STakashi Iwai 	if (err < 0)
3375*aed523f1STakashi Iwai 		goto error;
3376*aed523f1STakashi Iwai 
3377f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
3378f2e5731dSTakashi Iwai 	if (spec->beep_amp)
3379f2e5731dSTakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
33804f2864a4STakashi Iwai 
33814f2864a4STakashi Iwai 	/* Some laptops with Conexant chips show stalls in S3 resume,
33824f2864a4STakashi Iwai 	 * which falls into the single-cmd mode.
33834f2864a4STakashi Iwai 	 * Better to make reset, then.
33844f2864a4STakashi Iwai 	 */
33854f2864a4STakashi Iwai 	if (!codec->bus->sync_write) {
33864f2864a4STakashi Iwai 		snd_printd("hda_codec: "
33874f2864a4STakashi Iwai 			   "Enable sync_write for stable communication\n");
33884f2864a4STakashi Iwai 		codec->bus->sync_write = 1;
33894f2864a4STakashi Iwai 		codec->bus->allow_bus_reset = 1;
33904f2864a4STakashi Iwai 	}
33914f2864a4STakashi Iwai 
3392f2e5731dSTakashi Iwai 	return 0;
3393*aed523f1STakashi Iwai 
3394*aed523f1STakashi Iwai  error:
3395*aed523f1STakashi Iwai 	snd_hda_gen_free(codec);
3396*aed523f1STakashi Iwai 	return err;
3397f2e5731dSTakashi Iwai }
3398f2e5731dSTakashi Iwai 
3399f2e5731dSTakashi Iwai /*
3400461e2c78STakashi Iwai  */
3401461e2c78STakashi Iwai 
340234cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
340382f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
340482f30040STobin Davis 	  .patch = patch_cxt5045 },
340582f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
340682f30040STobin Davis 	  .patch = patch_cxt5047 },
3407461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3408461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
34090fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
34100fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
341195a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
341295a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3413850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3414850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
34157b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
34167b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
3417f0ca89b0SDavid Henningsson 	{ .id = 0x14f1506c, .name = "CX20588",
3418f0ca89b0SDavid Henningsson 	  .patch = patch_cxt5066 },
34196da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
34206da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
3421f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
3422f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3423f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
3424f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3425f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
3426f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3427f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
3428f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3429f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
3430f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3431f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
3432f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3433f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
3434f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3435f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
3436f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
34372d825fd8STakashi Iwai 	{ .id = 0x14f1510f, .name = "CX20751/2",
34382d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
34392d825fd8STakashi Iwai 	{ .id = 0x14f15110, .name = "CX20751/2",
34402d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
34412d825fd8STakashi Iwai 	{ .id = 0x14f15111, .name = "CX20753/4",
34422d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
3443c9b443d4STobin Davis 	{} /* terminator */
3444c9b443d4STobin Davis };
34451289e9e8STakashi Iwai 
34461289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
34471289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
34481289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
34490fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
345095a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3451850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
34527b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
3453f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c");
34546da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
3455f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
3456f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
3457f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3458f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3459f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3460f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3461f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3462f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
34632d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f1510f");
34642d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15110");
34652d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15111");
34661289e9e8STakashi Iwai 
34671289e9e8STakashi Iwai MODULE_LICENSE("GPL");
34681289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
34691289e9e8STakashi Iwai 
34701289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
34711289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
34721289e9e8STakashi Iwai 	.owner = THIS_MODULE,
34731289e9e8STakashi Iwai };
34741289e9e8STakashi Iwai 
34751289e9e8STakashi Iwai static int __init patch_conexant_init(void)
34761289e9e8STakashi Iwai {
34771289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
34781289e9e8STakashi Iwai }
34791289e9e8STakashi Iwai 
34801289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
34811289e9e8STakashi Iwai {
34821289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
34831289e9e8STakashi Iwai }
34841289e9e8STakashi Iwai 
34851289e9e8STakashi Iwai module_init(patch_conexant_init)
34861289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3487