xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 6dcbadef225e52ce487dcf670d4638c197504abd)
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"
36aed523f1STakashi Iwai #include "hda_generic.h"
37c9b443d4STobin Davis 
38bf92d1d5STakashi Iwai #define ENABLE_CXT_STATIC_QUIRKS
39c9b443d4STobin Davis 
40c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
41c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
42c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
43c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
44c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
45c9b443d4STobin Davis 
46c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
47c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
4803697e2aSTakashi Iwai #define CONEXANT_LINE_EVENT	0x39
49c9b443d4STobin Davis 
50bc7a166dSUlrich Dangel /* Conexant 5051 specific */
51c9b443d4STobin Davis 
52ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
53bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
54bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
55bc7a166dSUlrich Dangel 
56faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
57faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
58bc7a166dSUlrich Dangel 
59c9b443d4STobin Davis struct conexant_spec {
6023d30f28STakashi Iwai 	struct hda_gen_spec gen;
61c9b443d4STobin Davis 
62bf92d1d5STakashi Iwai 	unsigned int beep_amp;
63bf92d1d5STakashi Iwai 
64bf92d1d5STakashi Iwai 	/* extra EAPD pins */
65bf92d1d5STakashi Iwai 	unsigned int num_eapds;
66bf92d1d5STakashi Iwai 	hda_nid_t eapds[4];
67ff359b14STakashi Iwai 	bool dynamic_eapd;
68bf92d1d5STakashi Iwai 
69e4c3bce2SDavid Henningsson 	unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
70e4c3bce2SDavid Henningsson 
713a00c660STakashi Iwai 	/* OPLC XO specific */
723a00c660STakashi Iwai 	bool recording;
733a00c660STakashi Iwai 	bool dc_enable;
743a00c660STakashi Iwai 	unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
753a00c660STakashi Iwai 	struct nid_path *dc_mode_path;
763a00c660STakashi Iwai 
77bf92d1d5STakashi Iwai #ifdef ENABLE_CXT_STATIC_QUIRKS
7834cbe3a6STakashi Iwai 	const struct snd_kcontrol_new *mixers[5];
79c9b443d4STobin Davis 	int num_mixers;
80dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
81c9b443d4STobin Davis 
82c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
83c9b443d4STobin Davis 						 * don't forget NULL
84c9b443d4STobin Davis 						 * termination!
85c9b443d4STobin Davis 						 */
86c9b443d4STobin Davis 	unsigned int num_init_verbs;
87c9b443d4STobin Davis 
88c9b443d4STobin Davis 	/* playback */
89c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
90c9b443d4STobin Davis 					 * max_channels, dacs must be set
91c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
92c9b443d4STobin Davis 					 */
93c9b443d4STobin Davis 	unsigned int cur_eapd;
9482f30040STobin Davis 	unsigned int hp_present;
9503697e2aSTakashi Iwai 	unsigned int line_present;
96faddaa5dSTakashi Iwai 	unsigned int auto_mic;
97c9b443d4STobin Davis 
98c9b443d4STobin Davis 	/* capture */
99c9b443d4STobin Davis 	unsigned int num_adc_nids;
10034cbe3a6STakashi Iwai 	const hda_nid_t *adc_nids;
101c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
102c9b443d4STobin Davis 
103461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
104461e2c78STakashi Iwai 	hda_nid_t cur_adc;
105461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
106461e2c78STakashi Iwai 	unsigned int cur_adc_format;
107461e2c78STakashi Iwai 
1086764bcefSTakashi Iwai 	const struct hda_pcm_stream *capture_stream;
1096764bcefSTakashi Iwai 
110c9b443d4STobin Davis 	/* capture source */
111c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
11234cbe3a6STakashi Iwai 	const hda_nid_t *capsrc_nids;
113c9b443d4STobin Davis 	unsigned int cur_mux[3];
114c9b443d4STobin Davis 
115c9b443d4STobin Davis 	/* channel model */
116c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
117c9b443d4STobin Davis 	int num_channel_mode;
118c9b443d4STobin Davis 
119c9b443d4STobin Davis 	/* PCM information */
120c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
121c9b443d4STobin Davis 
122c9b443d4STobin Davis 	unsigned int spdif_route;
123c9b443d4STobin Davis 
1240fb67e98SDaniel Drake 	unsigned int port_d_mode;
125f2e5731dSTakashi Iwai 	unsigned int dell_automute:1;
126cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
127cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1287b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
129048e78a5SDavid Henningsson 	unsigned int hp_laptop:1;
130a1d6906eSDavid Henningsson 	unsigned int asus:1;
1316764bcefSTakashi Iwai 
132c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
133bf92d1d5STakashi Iwai #endif /* ENABLE_CXT_STATIC_QUIRKS */
134c9b443d4STobin Davis };
135c9b443d4STobin Davis 
136bf92d1d5STakashi Iwai 
137bf92d1d5STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
1387504b6cdSTakashi Iwai static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
1397504b6cdSTakashi Iwai 				int idx, int dir)
1407504b6cdSTakashi Iwai {
1417504b6cdSTakashi Iwai 	spec->gen.beep_nid = nid;
1427504b6cdSTakashi Iwai 	spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
1437504b6cdSTakashi Iwai }
144bf92d1d5STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
145bf92d1d5STakashi Iwai static const struct snd_kcontrol_new cxt_beep_mixer[] = {
146bf92d1d5STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
147bf92d1d5STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
148bf92d1d5STakashi Iwai 	{ } /* end */
149bf92d1d5STakashi Iwai };
150bf92d1d5STakashi Iwai 
151bf92d1d5STakashi Iwai /* create beep controls if needed */
152bf92d1d5STakashi Iwai static int add_beep_ctls(struct hda_codec *codec)
153bf92d1d5STakashi Iwai {
154bf92d1d5STakashi Iwai 	struct conexant_spec *spec = codec->spec;
155bf92d1d5STakashi Iwai 	int err;
156bf92d1d5STakashi Iwai 
157bf92d1d5STakashi Iwai 	if (spec->beep_amp) {
158bf92d1d5STakashi Iwai 		const struct snd_kcontrol_new *knew;
159bf92d1d5STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
160bf92d1d5STakashi Iwai 			struct snd_kcontrol *kctl;
161bf92d1d5STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
162bf92d1d5STakashi Iwai 			if (!kctl)
163bf92d1d5STakashi Iwai 				return -ENOMEM;
164bf92d1d5STakashi Iwai 			kctl->private_value = spec->beep_amp;
165bf92d1d5STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
166bf92d1d5STakashi Iwai 			if (err < 0)
167bf92d1d5STakashi Iwai 				return err;
168bf92d1d5STakashi Iwai 		}
169bf92d1d5STakashi Iwai 	}
170bf92d1d5STakashi Iwai 	return 0;
171bf92d1d5STakashi Iwai }
172bf92d1d5STakashi Iwai #else
173bf92d1d5STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
174bf92d1d5STakashi Iwai #define add_beep_ctls(codec)	0
175bf92d1d5STakashi Iwai #endif
176bf92d1d5STakashi Iwai 
177bf92d1d5STakashi Iwai 
178bf92d1d5STakashi Iwai #ifdef ENABLE_CXT_STATIC_QUIRKS
179c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
180c9b443d4STobin Davis 				      struct hda_codec *codec,
181c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
182c9b443d4STobin Davis {
183c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1849a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1859a08160bSTakashi Iwai 					     hinfo);
186c9b443d4STobin Davis }
187c9b443d4STobin Davis 
188c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
189c9b443d4STobin Davis 					 struct hda_codec *codec,
190c9b443d4STobin Davis 					 unsigned int stream_tag,
191c9b443d4STobin Davis 					 unsigned int format,
192c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
193c9b443d4STobin Davis {
194c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
195c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
196c9b443d4STobin Davis 						stream_tag,
197c9b443d4STobin Davis 						format, substream);
198c9b443d4STobin Davis }
199c9b443d4STobin Davis 
200c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
201c9b443d4STobin Davis 					 struct hda_codec *codec,
202c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
203c9b443d4STobin Davis {
204c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
205c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
206c9b443d4STobin Davis }
207c9b443d4STobin Davis 
208c9b443d4STobin Davis /*
209c9b443d4STobin Davis  * Digital out
210c9b443d4STobin Davis  */
211c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
212c9b443d4STobin Davis 					  struct hda_codec *codec,
213c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
214c9b443d4STobin Davis {
215c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
216c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
217c9b443d4STobin Davis }
218c9b443d4STobin Davis 
219c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
220c9b443d4STobin Davis 					 struct hda_codec *codec,
221c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
222c9b443d4STobin Davis {
223c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
224c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
225c9b443d4STobin Davis }
226c9b443d4STobin Davis 
2276b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2286b97eb45STakashi Iwai 					 struct hda_codec *codec,
2296b97eb45STakashi Iwai 					 unsigned int stream_tag,
2306b97eb45STakashi Iwai 					 unsigned int format,
2316b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
2326b97eb45STakashi Iwai {
2336b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2346b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2356b97eb45STakashi Iwai 					     stream_tag,
2366b97eb45STakashi Iwai 					     format, substream);
2376b97eb45STakashi Iwai }
2386b97eb45STakashi Iwai 
239c9b443d4STobin Davis /*
240c9b443d4STobin Davis  * Analog capture
241c9b443d4STobin Davis  */
242c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
243c9b443d4STobin Davis 				      struct hda_codec *codec,
244c9b443d4STobin Davis 				      unsigned int stream_tag,
245c9b443d4STobin Davis 				      unsigned int format,
246c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
247c9b443d4STobin Davis {
248c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
249c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
250c9b443d4STobin Davis 				   stream_tag, 0, format);
251c9b443d4STobin Davis 	return 0;
252c9b443d4STobin Davis }
253c9b443d4STobin Davis 
254c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
255c9b443d4STobin Davis 				      struct hda_codec *codec,
256c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
257c9b443d4STobin Davis {
258c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
259888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
260c9b443d4STobin Davis 	return 0;
261c9b443d4STobin Davis }
262c9b443d4STobin Davis 
263c9b443d4STobin Davis 
264c9b443d4STobin Davis 
26534cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_playback = {
266c9b443d4STobin Davis 	.substreams = 1,
267c9b443d4STobin Davis 	.channels_min = 2,
268c9b443d4STobin Davis 	.channels_max = 2,
269c9b443d4STobin Davis 	.nid = 0, /* fill later */
270c9b443d4STobin Davis 	.ops = {
271c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
272c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
273c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
274c9b443d4STobin Davis 	},
275c9b443d4STobin Davis };
276c9b443d4STobin Davis 
27734cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_analog_capture = {
278c9b443d4STobin Davis 	.substreams = 1,
279c9b443d4STobin Davis 	.channels_min = 2,
280c9b443d4STobin Davis 	.channels_max = 2,
281c9b443d4STobin Davis 	.nid = 0, /* fill later */
282c9b443d4STobin Davis 	.ops = {
283c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
284c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
285c9b443d4STobin Davis 	},
286c9b443d4STobin Davis };
287c9b443d4STobin Davis 
288c9b443d4STobin Davis 
28934cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_playback = {
290c9b443d4STobin Davis 	.substreams = 1,
291c9b443d4STobin Davis 	.channels_min = 2,
292c9b443d4STobin Davis 	.channels_max = 2,
293c9b443d4STobin Davis 	.nid = 0, /* fill later */
294c9b443d4STobin Davis 	.ops = {
295c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2966b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2976b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
298c9b443d4STobin Davis 	},
299c9b443d4STobin Davis };
300c9b443d4STobin Davis 
30134cbe3a6STakashi Iwai static const struct hda_pcm_stream conexant_pcm_digital_capture = {
302c9b443d4STobin Davis 	.substreams = 1,
303c9b443d4STobin Davis 	.channels_min = 2,
304c9b443d4STobin Davis 	.channels_max = 2,
305c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
306c9b443d4STobin Davis };
307c9b443d4STobin Davis 
308461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
309461e2c78STakashi Iwai 				      struct hda_codec *codec,
310461e2c78STakashi Iwai 				      unsigned int stream_tag,
311461e2c78STakashi Iwai 				      unsigned int format,
312461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
313461e2c78STakashi Iwai {
314461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
315461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
316461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
317461e2c78STakashi Iwai 	spec->cur_adc_format = format;
318461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
319461e2c78STakashi Iwai 	return 0;
320461e2c78STakashi Iwai }
321461e2c78STakashi Iwai 
322461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
323461e2c78STakashi Iwai 				      struct hda_codec *codec,
324461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
325461e2c78STakashi Iwai {
326461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
327888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
328461e2c78STakashi Iwai 	spec->cur_adc = 0;
329461e2c78STakashi Iwai 	return 0;
330461e2c78STakashi Iwai }
331461e2c78STakashi Iwai 
33234cbe3a6STakashi Iwai static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
333461e2c78STakashi Iwai 	.substreams = 1,
334461e2c78STakashi Iwai 	.channels_min = 2,
335461e2c78STakashi Iwai 	.channels_max = 2,
336461e2c78STakashi Iwai 	.nid = 0, /* fill later */
337461e2c78STakashi Iwai 	.ops = {
338461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
339461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
340461e2c78STakashi Iwai 	},
341461e2c78STakashi Iwai };
342461e2c78STakashi Iwai 
343c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
344c9b443d4STobin Davis {
345c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
346c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
347c9b443d4STobin Davis 
348c9b443d4STobin Davis 	codec->num_pcms = 1;
349c9b443d4STobin Davis 	codec->pcm_info = info;
350c9b443d4STobin Davis 
351c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
352c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
353c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
354c9b443d4STobin Davis 		spec->multiout.max_channels;
355c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
356c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
3576764bcefSTakashi Iwai 	if (spec->capture_stream)
3586764bcefSTakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
3596764bcefSTakashi Iwai 	else {
360461e2c78STakashi Iwai 		if (codec->vendor_id == 0x14f15051)
361461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
362461e2c78STakashi Iwai 				cx5051_pcm_analog_capture;
3636764bcefSTakashi Iwai 		else {
364461e2c78STakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
365461e2c78STakashi Iwai 				conexant_pcm_analog_capture;
3666764bcefSTakashi Iwai 			info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
3676764bcefSTakashi Iwai 				spec->num_adc_nids;
3686764bcefSTakashi Iwai 		}
3696764bcefSTakashi Iwai 	}
370c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
371c9b443d4STobin Davis 
372c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
373c9b443d4STobin Davis 		info++;
374c9b443d4STobin Davis 		codec->num_pcms++;
375c9b443d4STobin Davis 		info->name = "Conexant Digital";
3767ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
377c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
378c9b443d4STobin Davis 			conexant_pcm_digital_playback;
379c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
380c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
381c9b443d4STobin Davis 		if (spec->dig_in_nid) {
382c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
383c9b443d4STobin Davis 				conexant_pcm_digital_capture;
384c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
385c9b443d4STobin Davis 				spec->dig_in_nid;
386c9b443d4STobin Davis 		}
387c9b443d4STobin Davis 	}
388c9b443d4STobin Davis 
389c9b443d4STobin Davis 	return 0;
390c9b443d4STobin Davis }
391c9b443d4STobin Davis 
392c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
393c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
394c9b443d4STobin Davis {
395c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
397c9b443d4STobin Davis 
398c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
399c9b443d4STobin Davis }
400c9b443d4STobin Davis 
401c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
402c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
403c9b443d4STobin Davis {
404c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
405c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
406c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
407c9b443d4STobin Davis 
408c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
409c9b443d4STobin Davis 	return 0;
410c9b443d4STobin Davis }
411c9b443d4STobin Davis 
412c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
413c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
414c9b443d4STobin Davis {
415c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
416c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
417c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
418c9b443d4STobin Davis 
419c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
420c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
421c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
422c9b443d4STobin Davis }
423c9b443d4STobin Davis 
4244d7fbdbcSTakashi Iwai static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
4254d7fbdbcSTakashi Iwai 			       unsigned int power_state)
4264d7fbdbcSTakashi Iwai {
4274d7fbdbcSTakashi Iwai 	if (power_state == AC_PWRST_D3)
4284d7fbdbcSTakashi Iwai 		msleep(100);
4294d7fbdbcSTakashi Iwai 	snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
4304d7fbdbcSTakashi Iwai 			    power_state);
4314d7fbdbcSTakashi Iwai 	/* partial workaround for "azx_get_response timeout" */
4324d7fbdbcSTakashi Iwai 	if (power_state == AC_PWRST_D0)
4334d7fbdbcSTakashi Iwai 		msleep(10);
4349419ab6bSTakashi Iwai 	snd_hda_codec_set_power_to_all(codec, fg, power_state);
4354d7fbdbcSTakashi Iwai }
4364d7fbdbcSTakashi Iwai 
437c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
438c9b443d4STobin Davis {
439c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
440c9b443d4STobin Davis 	int i;
441c9b443d4STobin Davis 
442c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
443c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
444c9b443d4STobin Davis 	return 0;
445c9b443d4STobin Davis }
446c9b443d4STobin Davis 
447c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
448c9b443d4STobin Davis {
449ee48df57STakashi Iwai 	struct conexant_spec *spec = codec->spec;
450c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
451ee48df57STakashi Iwai 	kfree(spec);
452c9b443d4STobin Davis }
453c9b443d4STobin Davis 
45434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt_capture_mixers[] = {
455b880c74aSTakashi Iwai 	{
456b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
457b880c74aSTakashi Iwai 		.name = "Capture Source",
458b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
459b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
460b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
461b880c74aSTakashi Iwai 	},
462b880c74aSTakashi Iwai 	{}
463b880c74aSTakashi Iwai };
464b880c74aSTakashi Iwai 
4659322ca54STakashi Iwai static const char * const slave_pfxs[] = {
466f37bc7a8STakashi Iwai 	"Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
467dd5746a8STakashi Iwai 	NULL
468dd5746a8STakashi Iwai };
469dd5746a8STakashi Iwai 
470c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
471c9b443d4STobin Davis {
472c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
473c9b443d4STobin Davis 	unsigned int i;
474c9b443d4STobin Davis 	int err;
475c9b443d4STobin Davis 
476c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
477c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
478c9b443d4STobin Davis 		if (err < 0)
479c9b443d4STobin Davis 			return err;
480c9b443d4STobin Davis 	}
481c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
482c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
48374b654c9SStephen Warren 						    spec->multiout.dig_out_nid,
484c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
485c9b443d4STobin Davis 		if (err < 0)
486c9b443d4STobin Davis 			return err;
4879a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
4889a08160bSTakashi Iwai 						    &spec->multiout);
4899a08160bSTakashi Iwai 		if (err < 0)
4909a08160bSTakashi Iwai 			return err;
4919a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
492c9b443d4STobin Davis 	}
493c9b443d4STobin Davis 	if (spec->dig_in_nid) {
494c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
495c9b443d4STobin Davis 		if (err < 0)
496c9b443d4STobin Davis 			return err;
497c9b443d4STobin Davis 	}
498dd5746a8STakashi Iwai 
499dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
500dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
501dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
502dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
503dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
504dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
505dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
5069322ca54STakashi Iwai 					  vmaster_tlv, slave_pfxs,
5079322ca54STakashi Iwai 					  "Playback Volume");
508dd5746a8STakashi Iwai 		if (err < 0)
509dd5746a8STakashi Iwai 			return err;
510dd5746a8STakashi Iwai 	}
511dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
512dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
513aed523f1STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
5149322ca54STakashi Iwai 					  NULL, slave_pfxs,
515aed523f1STakashi Iwai 					  "Playback Switch");
516dd5746a8STakashi Iwai 		if (err < 0)
517dd5746a8STakashi Iwai 			return err;
518dd5746a8STakashi Iwai 	}
519dd5746a8STakashi Iwai 
520b880c74aSTakashi Iwai 	if (spec->input_mux) {
521b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
522b880c74aSTakashi Iwai 		if (err < 0)
523b880c74aSTakashi Iwai 			return err;
524b880c74aSTakashi Iwai 	}
525b880c74aSTakashi Iwai 
526aed523f1STakashi Iwai 	err = add_beep_ctls(codec);
5273507e2a8STakashi Iwai 	if (err < 0)
5283507e2a8STakashi Iwai 		return err;
5293507e2a8STakashi Iwai 
530c9b443d4STobin Davis 	return 0;
531c9b443d4STobin Davis }
532c9b443d4STobin Davis 
53334cbe3a6STakashi Iwai static const struct hda_codec_ops conexant_patch_ops = {
534c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
535c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
536c9b443d4STobin Davis 	.init = conexant_init,
537c9b443d4STobin Davis 	.free = conexant_free,
5384d7fbdbcSTakashi Iwai 	.set_power_state = conexant_set_power,
539c9b443d4STobin Davis };
540c9b443d4STobin Davis 
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),
10145218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
101515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
101615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10179e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10189e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
101915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1022dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1023dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
102415908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1025c9b443d4STobin Davis 	{}
1026c9b443d4STobin Davis };
1027c9b443d4STobin Davis 
1028c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1029c9b443d4STobin Davis {
1030c9b443d4STobin Davis 	struct conexant_spec *spec;
1031c9b443d4STobin Davis 	int board_config;
1032c9b443d4STobin Davis 
10331f8458a2STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
10341f8458a2STakashi Iwai 						  cxt5045_models,
10351f8458a2STakashi Iwai 						  cxt5045_cfg_tbl);
10361f8458a2STakashi Iwai 	if (board_config < 0)
1037c82693dbSTakashi Iwai 		board_config = CXT5045_AUTO; /* model=auto as default */
10381f8458a2STakashi Iwai 	if (board_config == CXT5045_AUTO)
10391f8458a2STakashi Iwai 		return patch_conexant_auto(codec);
10401f8458a2STakashi Iwai 
1041c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1042c9b443d4STobin Davis 	if (!spec)
1043c9b443d4STobin Davis 		return -ENOMEM;
1044c9b443d4STobin Davis 	codec->spec = spec;
10454f32456eSMichael Karcher 	codec->single_adc_amp = 1;
1046c9b443d4STobin Davis 
1047c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1048c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1049c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1050c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1051c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1052c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1053c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1054c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1055c9b443d4STobin Davis 	spec->num_mixers = 1;
1056c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1057c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1058c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1059c9b443d4STobin Davis 	spec->spdif_route = 0;
10603507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
10613507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
10625cd57529STobin Davis 
10633507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1064c9b443d4STobin Davis 
1065c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1066c9b443d4STobin Davis 
1067c9b443d4STobin Davis 	switch (board_config) {
106815908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
10697f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1070c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1071c9b443d4STobin Davis 		spec->num_init_verbs = 2;
10727f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
10737f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
10747f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
10757f29673bSTobin Davis 		break;
107615908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
107786376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10787f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
10797f29673bSTobin Davis 		spec->num_init_verbs = 2;
10807f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1081c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1082c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1083c9b443d4STobin Davis 		break;
108415908c36SMarc Boucher 	default:
108515908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
108615908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
108715908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
108815908c36SMarc Boucher 		spec->num_init_verbs = 3;
108915908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
109015908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
109115908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
109215908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
109315908c36SMarc Boucher 		break;
10945218c892SJiang Zhe 	case CXT5045_BENQ:
10955218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10965218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
10975218c892SJiang Zhe 		spec->num_init_verbs = 1;
10985218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
10995218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11005218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11015218c892SJiang Zhe 		spec->num_mixers = 2;
11025218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11035218c892SJiang Zhe 		break;
11042de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11052de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11062de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11072de3c232SJiang zhe 		spec->num_init_verbs = 2;
11082de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11092de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11102de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11112de3c232SJiang zhe 		break;
1112c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1113c9b443d4STobin Davis 	case CXT5045_TEST:
1114c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1115c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1116c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
111715908c36SMarc Boucher 		break;
111815908c36SMarc Boucher 
1119c9b443d4STobin Davis #endif
1120c9b443d4STobin Davis 	}
112148ecb7e8STakashi Iwai 
1122031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1123031005f7STakashi Iwai 	case 0x103c:
11248f0f5ff6SDaniel T Chen 	case 0x1631:
11250b587fc4SDaniel T Chen 	case 0x1734:
11260ebf9e36SDaniel T Chen 	case 0x17aa:
11270ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
11280ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
11290ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
113048ecb7e8STakashi Iwai 		 */
113148ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
113248ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
113348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
113448ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
113548ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1136031005f7STakashi Iwai 		break;
1137031005f7STakashi Iwai 	}
113848ecb7e8STakashi Iwai 
11393507e2a8STakashi Iwai 	if (spec->beep_amp)
1140a86b1a2cSTakashi Iwai 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
11413507e2a8STakashi Iwai 
1142c9b443d4STobin Davis 	return 0;
1143c9b443d4STobin Davis }
1144c9b443d4STobin Davis 
1145c9b443d4STobin Davis 
1146c9b443d4STobin Davis /* Conexant 5047 specific */
114782f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1148c9b443d4STobin Davis 
114934cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
115034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
115134cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1152c9b443d4STobin Davis 
115334cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
11545cd57529STobin Davis 	{ 2, NULL },
11555cd57529STobin Davis };
1156c9b443d4STobin Davis 
115734cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
115882f30040STobin Davis 	.num_items = 2,
115982f30040STobin Davis 	.items = {
116082f30040STobin Davis 		{ "ExtMic", 0x2 },
116182f30040STobin Davis 		{ "Line-In", 0x1 },
1162c9b443d4STobin Davis 	}
1163c9b443d4STobin Davis };
1164c9b443d4STobin Davis 
1165c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1166c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1167c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1168c9b443d4STobin Davis {
1169c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1170c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
117182f30040STobin Davis 	unsigned int bits;
1172c9b443d4STobin Davis 
117382f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1174c9b443d4STobin Davis 		return 0;
1175c9b443d4STobin Davis 
117682f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
117782f30040STobin Davis 	 * the headphone jack
117882f30040STobin Davis 	 */
117947fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
11803b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
11813b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
11823b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
11833b7523fcSTakashi Iwai 	 */
11845d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
118547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
118647fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
118747fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
118847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1189c9b443d4STobin Davis 	return 1;
1190c9b443d4STobin Davis }
1191c9b443d4STobin Davis 
1192c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1193c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1194c9b443d4STobin Davis {
119582f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1196dd87da1cSTobin Davis 	unsigned int bits;
1197c9b443d4STobin Davis 
1198d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1199dd87da1cSTobin Davis 
120047fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12013b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12025d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
120347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1204c9b443d4STobin Davis }
1205c9b443d4STobin Davis 
1206c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1207c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1208c9b443d4STobin Davis {
120934cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
12109f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12119f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1212c9b443d4STobin Davis 		{}
1213c9b443d4STobin Davis 	};
121434cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
12159f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12169f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1217c9b443d4STobin Davis 		{}
1218c9b443d4STobin Davis 	};
1219c9b443d4STobin Davis 	unsigned int present;
1220c9b443d4STobin Davis 
1221d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1222c9b443d4STobin Davis 	if (present)
1223c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1224c9b443d4STobin Davis 	else
1225c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1226c9b443d4STobin Davis }
1227c9b443d4STobin Davis 
1228c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1229c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1230c9b443d4STobin Davis 				  unsigned int res)
1231c9b443d4STobin Davis {
12329f113e0eSMarc Boucher 	switch (res >> 26) {
1233c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1234c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1235c9b443d4STobin Davis 		break;
1236c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1237c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1238c9b443d4STobin Davis 		break;
1239c9b443d4STobin Davis 	}
1240c9b443d4STobin Davis }
1241c9b443d4STobin Davis 
124234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1243df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1244df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
12455f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1246c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1247c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1248c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1249c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
125082f30040STobin Davis 	{
125182f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
125282f30040STobin Davis 		.name = "Master Playback Switch",
125382f30040STobin Davis 		.info = cxt_eapd_info,
125482f30040STobin Davis 		.get = cxt_eapd_get,
1255c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1256c9b443d4STobin Davis 		.private_value = 0x13,
1257c9b443d4STobin Davis 	},
1258c9b443d4STobin Davis 
1259c9b443d4STobin Davis 	{}
1260c9b443d4STobin Davis };
1261c9b443d4STobin Davis 
126234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
12633b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12645d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1265df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1266df481e41STakashi Iwai 	{}
1267df481e41STakashi Iwai };
1268df481e41STakashi Iwai 
126934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1270c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1271c9b443d4STobin Davis 	{ } /* end */
1272c9b443d4STobin Davis };
1273c9b443d4STobin Davis 
127434cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1275c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1276c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1277c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1278c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
12797f29673bSTobin Davis 	/* HP, Speaker  */
1280b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
12815b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
12825b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
12837f29673bSTobin Davis 	/* Record selector: Mic */
12847f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
12857f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
12867f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
12877f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1288c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1289c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1290c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1291c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1292c9b443d4STobin Davis 	/* SPDIF route: PCM */
1293c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
129482f30040STobin Davis 	/* Enable unsolicited events */
129582f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
129682f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1297c9b443d4STobin Davis 	{ } /* end */
1298c9b443d4STobin Davis };
1299c9b443d4STobin Davis 
1300c9b443d4STobin Davis /* configuration for Toshiba Laptops */
130134cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13023b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1303c9b443d4STobin Davis 	{}
1304c9b443d4STobin Davis };
1305c9b443d4STobin Davis 
1306c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1307c9b443d4STobin Davis  * configuration.
1308c9b443d4STobin Davis  */
1309c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
131034cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
131182f30040STobin Davis 	.num_items = 4,
1312c9b443d4STobin Davis 	.items = {
131382f30040STobin Davis 		{ "LINE1 pin", 0x0 },
131482f30040STobin Davis 		{ "MIC1 pin", 0x1 },
131582f30040STobin Davis 		{ "MIC2 pin", 0x2 },
131682f30040STobin Davis 		{ "CD pin", 0x3 },
1317c9b443d4STobin Davis         },
1318c9b443d4STobin Davis };
1319c9b443d4STobin Davis 
132034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1321c9b443d4STobin Davis 
1322c9b443d4STobin Davis 	/* Output only controls */
132382f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
132482f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
132582f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
132682f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1327c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1328c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1329c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1330c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
133182f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
133282f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
133382f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
133482f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1335c9b443d4STobin Davis 
1336c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1337c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1338c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1339c9b443d4STobin Davis 
134082f30040STobin Davis 	/* EAPD Switch Control */
134182f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
134282f30040STobin Davis 
1343c9b443d4STobin Davis 	/* Loopback mixer controls */
134482f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
134582f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
134682f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
134782f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
134882f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
134982f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
135082f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
135182f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1352c9b443d4STobin Davis 
135382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
135482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
135582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
135682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
135782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
135882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
135982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
136082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1361c9b443d4STobin Davis 	{
1362c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1363c9b443d4STobin Davis 		.name = "Input Source",
1364c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1365c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1366c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1367c9b443d4STobin Davis 	},
1368854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
13699f113e0eSMarc Boucher 
1370c9b443d4STobin Davis 	{ } /* end */
1371c9b443d4STobin Davis };
1372c9b443d4STobin Davis 
137334cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1374c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1375c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1376c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1378c9b443d4STobin Davis 
1379c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1380c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1381c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1382c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1383c9b443d4STobin Davis 	 * control.
1384c9b443d4STobin Davis 	 */
1385c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1386c9b443d4STobin Davis 
1387c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1388c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1389c9b443d4STobin Davis 	 */
1390c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1391c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1392c9b443d4STobin Davis 
1393c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1394c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1395c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1396c9b443d4STobin Davis 
1397c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1398c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1399c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1400c9b443d4STobin Davis 	 * input/output buffers as needed.
1401c9b443d4STobin Davis 	 */
1402c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1403c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1404c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1405c9b443d4STobin Davis 
1406c9b443d4STobin Davis 	/* Mute capture amp left and right */
1407c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1408c9b443d4STobin Davis 
1409c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1410c9b443d4STobin Davis 	 * pin)
1411c9b443d4STobin Davis 	 */
1412c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1413c9b443d4STobin Davis 
1414c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1415c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1416c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1417c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1418c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1419c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1420c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1421c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1422c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1423c9b443d4STobin Davis 
1424c9b443d4STobin Davis 	{ }
1425c9b443d4STobin Davis };
1426c9b443d4STobin Davis #endif
1427c9b443d4STobin Davis 
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis /* initialize jack-sensing, too */
1430c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1431c9b443d4STobin Davis {
1432c9b443d4STobin Davis 	conexant_init(codec);
1433c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1434c9b443d4STobin Davis 	return 0;
1435c9b443d4STobin Davis }
1436c9b443d4STobin Davis 
1437c9b443d4STobin Davis 
1438c9b443d4STobin Davis enum {
1439f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1440f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1441f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1442c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1443c9b443d4STobin Davis 	CXT5047_TEST,
1444c9b443d4STobin Davis #endif
1445fa5dadcbSTakashi Iwai 	CXT5047_AUTO,
1446f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1447c9b443d4STobin Davis };
1448c9b443d4STobin Davis 
1449ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1450f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1451f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1452f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1453c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1454f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1455c9b443d4STobin Davis #endif
1456fa5dadcbSTakashi Iwai 	[CXT5047_AUTO]		= "auto",
1457f5fcc13cSTakashi Iwai };
1458c9b443d4STobin Davis 
145934cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1460ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1461dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1462dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1463f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1464c9b443d4STobin Davis 	{}
1465c9b443d4STobin Davis };
1466c9b443d4STobin Davis 
1467c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1468c9b443d4STobin Davis {
1469c9b443d4STobin Davis 	struct conexant_spec *spec;
1470c9b443d4STobin Davis 	int board_config;
1471c9b443d4STobin Davis 
1472fa5dadcbSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1473fa5dadcbSTakashi Iwai 						  cxt5047_models,
1474fa5dadcbSTakashi Iwai 						  cxt5047_cfg_tbl);
1475fa5dadcbSTakashi Iwai 	if (board_config < 0)
1476c82693dbSTakashi Iwai 		board_config = CXT5047_AUTO; /* model=auto as default */
1477fa5dadcbSTakashi Iwai 	if (board_config == CXT5047_AUTO)
1478fa5dadcbSTakashi Iwai 		return patch_conexant_auto(codec);
1479fa5dadcbSTakashi Iwai 
1480c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1481c9b443d4STobin Davis 	if (!spec)
1482c9b443d4STobin Davis 		return -ENOMEM;
1483c9b443d4STobin Davis 	codec->spec = spec;
14849421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1485c9b443d4STobin Davis 
1486c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1487c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1488c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1489c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1490c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1491c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1492c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1493c9b443d4STobin Davis 	spec->num_mixers = 1;
1494df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1495c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1496c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1497c9b443d4STobin Davis 	spec->spdif_route = 0;
14985cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
14995cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1500c9b443d4STobin Davis 
1501c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1502c9b443d4STobin Davis 
1503c9b443d4STobin Davis 	switch (board_config) {
1504c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1505df481e41STakashi Iwai 		spec->num_mixers = 2;
1506df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1507df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1508c9b443d4STobin Davis 		break;
1509c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1510df481e41STakashi Iwai 		spec->num_mixers = 2;
1511df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1512fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1513c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1514c9b443d4STobin Davis 		break;
1515c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
151682f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1517df481e41STakashi Iwai 		spec->num_mixers = 2;
1518df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1519c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1520c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1521fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1522c9b443d4STobin Davis 		break;
1523c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1524c9b443d4STobin Davis 	case CXT5047_TEST:
1525c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1526c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1527c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1528fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1529c9b443d4STobin Davis #endif
1530c9b443d4STobin Davis 	}
1531dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1532025f206cSDaniel T Chen 
1533025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1534025f206cSDaniel T Chen 	case 0x103c:
1535025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1536025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1537025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1538025f206cSDaniel T Chen 		 */
1539025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1540025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1541025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1542025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1543025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1544025f206cSDaniel T Chen 		break;
1545025f206cSDaniel T Chen 	}
1546025f206cSDaniel T Chen 
1547c9b443d4STobin Davis 	return 0;
1548c9b443d4STobin Davis }
1549c9b443d4STobin Davis 
1550461e2c78STakashi Iwai /* Conexant 5051 specific */
155134cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
155234cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1553461e2c78STakashi Iwai 
155434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1555461e2c78STakashi Iwai 	{ 2, NULL },
1556461e2c78STakashi Iwai };
1557461e2c78STakashi Iwai 
1558461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1559461e2c78STakashi Iwai {
1560461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1561461e2c78STakashi Iwai 	unsigned int pinctl;
156223d2df5bSTakashi Iwai 	/* headphone pin */
156323d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1564cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x16, pinctl);
156523d2df5bSTakashi Iwai 	/* speaker pin */
1566461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1567cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1568a80581d0SJustin P. Mattock 	/* on ideapad there is an additional speaker (subwoofer) to mute */
1569f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1570cdd03cedSTakashi Iwai 		snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1571461e2c78STakashi Iwai }
1572461e2c78STakashi Iwai 
1573461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1574461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1575461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1576461e2c78STakashi Iwai {
1577461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1578461e2c78STakashi Iwai 
1579461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1580461e2c78STakashi Iwai 		return 0;
1581461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1582461e2c78STakashi Iwai 	return 1;
1583461e2c78STakashi Iwai }
1584461e2c78STakashi Iwai 
1585461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1586461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1587461e2c78STakashi Iwai {
158879d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1589461e2c78STakashi Iwai 	unsigned int present;
1590461e2c78STakashi Iwai 
1591faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
159279d7d533STakashi Iwai 		return;
1593d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1594461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1595461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1596461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1597461e2c78STakashi Iwai }
1598461e2c78STakashi Iwai 
1599461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1600461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1601461e2c78STakashi Iwai {
1602461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1603461e2c78STakashi Iwai 	unsigned int present;
1604461e2c78STakashi Iwai 	hda_nid_t new_adc;
1605461e2c78STakashi Iwai 
1606faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
160779d7d533STakashi Iwai 		return;
1608d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1609461e2c78STakashi Iwai 	if (present)
1610461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1611461e2c78STakashi Iwai 	else
1612461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1613461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1614461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1615461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1616f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1617461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1618461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1619461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1620461e2c78STakashi Iwai 					   spec->cur_adc_format);
1621461e2c78STakashi Iwai 	}
1622461e2c78STakashi Iwai }
1623461e2c78STakashi Iwai 
1624461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1625461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1626461e2c78STakashi Iwai {
1627461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1628461e2c78STakashi Iwai 
1629d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1630461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1631461e2c78STakashi Iwai }
1632461e2c78STakashi Iwai 
1633461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1634461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1635461e2c78STakashi Iwai 				   unsigned int res)
1636461e2c78STakashi Iwai {
1637461e2c78STakashi Iwai 	switch (res >> 26) {
1638461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1639461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1640461e2c78STakashi Iwai 		break;
1641461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1642461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1643461e2c78STakashi Iwai 		break;
1644461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1645461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1646461e2c78STakashi Iwai 		break;
1647461e2c78STakashi Iwai 	}
1648461e2c78STakashi Iwai }
1649461e2c78STakashi Iwai 
165034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1651461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1652461e2c78STakashi Iwai 	{
1653461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1654461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1655461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1656461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1657461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1658461e2c78STakashi Iwai 		.private_value = 0x1a,
1659461e2c78STakashi Iwai 	},
16602c7a3fb3STakashi Iwai 	{}
16612c7a3fb3STakashi Iwai };
1662461e2c78STakashi Iwai 
166334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
16642c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
16652c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16668607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
16678607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1668c40bd914SDavid Henningsson 	HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1669c40bd914SDavid Henningsson 	HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1670461e2c78STakashi Iwai 	{}
1671461e2c78STakashi Iwai };
1672461e2c78STakashi Iwai 
167334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1674461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1675461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16768607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
16778607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1678461e2c78STakashi Iwai 	{}
1679461e2c78STakashi Iwai };
1680461e2c78STakashi Iwai 
168134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
16824e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
16834e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
168479d7d533STakashi Iwai 	{}
168579d7d533STakashi Iwai };
168679d7d533STakashi Iwai 
168734cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
16885f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
16895f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1690cd9d95a5SKen Prox 	{}
1691cd9d95a5SKen Prox };
1692cd9d95a5SKen Prox 
169334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1694faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1695faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16968607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
16978607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1698faddaa5dSTakashi Iwai 	{}
1699faddaa5dSTakashi Iwai };
1700faddaa5dSTakashi Iwai 
170134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1702461e2c78STakashi Iwai 	/* Line in, Mic */
1703461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1704461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1705461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1706461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1707461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1708461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1709461e2c78STakashi Iwai 	/* SPK  */
1710461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1711461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1712461e2c78STakashi Iwai 	/* HP, Amp  */
1713461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1714461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1715461e2c78STakashi Iwai 	/* DAC1 */
1716461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
171728c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1718461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1719461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1720461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1721461e2c78STakashi Iwai 	/* SPDIF route: PCM */
17221965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1723461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1724461e2c78STakashi Iwai 	/* EAPD */
1725461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1726461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1727461e2c78STakashi Iwai 	{ } /* end */
1728461e2c78STakashi Iwai };
1729461e2c78STakashi Iwai 
173034cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
173179d7d533STakashi Iwai 	/* Line in, Mic */
173279d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
173379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
173479d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
173579d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
173679d7d533STakashi Iwai 	/* SPK  */
173779d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
173879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
173979d7d533STakashi Iwai 	/* HP, Amp  */
174079d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
174179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
174279d7d533STakashi Iwai 	/* DAC1 */
174379d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
174428c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
174579d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
174679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
174779d7d533STakashi Iwai 	/* SPDIF route: PCM */
174879d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
174979d7d533STakashi Iwai 	/* EAPD */
175079d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
175179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
175279d7d533STakashi Iwai 	{ } /* end */
175379d7d533STakashi Iwai };
175479d7d533STakashi Iwai 
175534cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1756cd9d95a5SKen Prox 	/* Line in, Mic */
175730ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1758cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1759cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1760cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1761cd9d95a5SKen Prox 	/* SPK  */
1762cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1763cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1764cd9d95a5SKen Prox 	/* HP, Amp  */
1765cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1766cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1767cd9d95a5SKen Prox 	/* DAC1 */
1768cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
176928c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1770cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1771cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1772cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1773cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1774cd9d95a5SKen Prox 	/* EAPD */
1775cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1776cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1777cd9d95a5SKen Prox 	{ } /* end */
1778cd9d95a5SKen Prox };
1779cd9d95a5SKen Prox 
17806953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
17816953e552STakashi Iwai 				 unsigned int event)
17826953e552STakashi Iwai {
17836953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
17846953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
17856953e552STakashi Iwai 			    AC_USRSP_EN | event);
17866953e552STakashi Iwai }
17876953e552STakashi Iwai 
178834cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1789f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1790f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1791f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1792f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1793f7154de2SHerton Ronaldo Krzesinski };
1794f7154de2SHerton Ronaldo Krzesinski 
1795461e2c78STakashi Iwai /* initialize jack-sensing, too */
1796461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1797461e2c78STakashi Iwai {
17986953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
17996953e552STakashi Iwai 
1800461e2c78STakashi Iwai 	conexant_init(codec);
18016953e552STakashi Iwai 
18026953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
18036953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
18046953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
18056953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
18066953e552STakashi Iwai 
1807461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1808461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1809461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1810461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1811461e2c78STakashi Iwai 	}
1812461e2c78STakashi Iwai 	return 0;
1813461e2c78STakashi Iwai }
1814461e2c78STakashi Iwai 
1815461e2c78STakashi Iwai 
1816461e2c78STakashi Iwai enum {
1817461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1818461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
181979d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
1820cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1821faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1822f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
18236764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1824461e2c78STakashi Iwai 	CXT5051_MODELS
1825461e2c78STakashi Iwai };
1826461e2c78STakashi Iwai 
1827ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1828461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1829461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
183079d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
18315f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1832faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1833f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
18346764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1835461e2c78STakashi Iwai };
1836461e2c78STakashi Iwai 
183734cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
183879d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
18391812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
18405f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1841faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1842461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1843461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1844461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1845f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1846461e2c78STakashi Iwai 	{}
1847461e2c78STakashi Iwai };
1848461e2c78STakashi Iwai 
1849461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1850461e2c78STakashi Iwai {
1851461e2c78STakashi Iwai 	struct conexant_spec *spec;
1852461e2c78STakashi Iwai 	int board_config;
1853461e2c78STakashi Iwai 
18546764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
18556764bcefSTakashi Iwai 						  cxt5051_models,
18566764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
18576764bcefSTakashi Iwai 	if (board_config < 0)
1858c82693dbSTakashi Iwai 		board_config = CXT5051_AUTO; /* model=auto as default */
18591f8458a2STakashi Iwai 	if (board_config == CXT5051_AUTO)
18606764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
18616764bcefSTakashi Iwai 
1862461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1863461e2c78STakashi Iwai 	if (!spec)
1864461e2c78STakashi Iwai 		return -ENOMEM;
1865461e2c78STakashi Iwai 	codec->spec = spec;
18669421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1867461e2c78STakashi Iwai 
1868461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1869461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1870461e2c78STakashi Iwai 
1871461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1872461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1873461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1874461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1875461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1876461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
18772c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
18782c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
18792c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
1880461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1881461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1882461e2c78STakashi Iwai 	spec->spdif_route = 0;
1883461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1884461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1885461e2c78STakashi Iwai 	spec->cur_adc = 0;
1886461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1887461e2c78STakashi Iwai 
18883507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
18893507e2a8STakashi Iwai 
189079d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
189179d7d533STakashi Iwai 
1892faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1893461e2c78STakashi Iwai 	switch (board_config) {
1894461e2c78STakashi Iwai 	case CXT5051_HP:
1895461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1896461e2c78STakashi Iwai 		break;
189779d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
189879d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
189979d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1900faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
190179d7d533STakashi Iwai 		break;
1902cd9d95a5SKen Prox 	case CXT5051_F700:
1903cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
1904cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
1905faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
1906faddaa5dSTakashi Iwai 		break;
1907faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
1908faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
1909faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
1910cd9d95a5SKen Prox 		break;
1911f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
1912f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
1913f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
1914f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
1915f7154de2SHerton Ronaldo Krzesinski 		break;
1916461e2c78STakashi Iwai 	}
1917461e2c78STakashi Iwai 
19183507e2a8STakashi Iwai 	if (spec->beep_amp)
1919a86b1a2cSTakashi Iwai 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
19203507e2a8STakashi Iwai 
1921461e2c78STakashi Iwai 	return 0;
1922461e2c78STakashi Iwai }
1923461e2c78STakashi Iwai 
19240fb67e98SDaniel Drake /* Conexant 5066 specific */
19250fb67e98SDaniel Drake 
192634cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
192734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
192834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
192934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
19300fb67e98SDaniel Drake 
193134cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
19320fb67e98SDaniel Drake 	{ 2, NULL },
19330fb67e98SDaniel Drake };
19340fb67e98SDaniel Drake 
1935a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
1936a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
1937a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
1938a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
1939a3de8ab8STakashi Iwai 
19400fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
19410fb67e98SDaniel Drake {
19420fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
19430fb67e98SDaniel Drake 	unsigned int pinctl;
19440fb67e98SDaniel Drake 
19453a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
19463a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
19470fb67e98SDaniel Drake 
19480fb67e98SDaniel Drake 	/* Port A (HP) */
1949a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1950cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x19, pinctl);
19510fb67e98SDaniel Drake 
19520fb67e98SDaniel Drake 	/* Port D (HP/LO) */
1953a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1954a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
1955a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
1956a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
19573a253445SJohn Baboval 			pinctl = 0;
19583a253445SJohn Baboval 	} else {
1959a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
1960a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
1961a3de8ab8STakashi Iwai 			pinctl = 0;
19623a253445SJohn Baboval 	}
1963cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
19640fb67e98SDaniel Drake 
19650fb67e98SDaniel Drake 	/* CLASS_D AMP */
19660fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1967cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
19680fb67e98SDaniel Drake }
19690fb67e98SDaniel Drake 
19700fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
19710fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
19720fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
19730fb67e98SDaniel Drake {
19740fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19750fb67e98SDaniel Drake 
19760fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
19770fb67e98SDaniel Drake 		return 0;
19780fb67e98SDaniel Drake 
19790fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
19800fb67e98SDaniel Drake 	return 1;
19810fb67e98SDaniel Drake }
19820fb67e98SDaniel Drake 
198395a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
198495a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
198595a618bdSEinar Rünkaru {
198695a618bdSEinar Rünkaru 	unsigned int present;
198795a618bdSEinar Rünkaru 
198895a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
198995a618bdSEinar Rünkaru 		/* enable external mic, port B */
199075f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
199195a618bdSEinar Rünkaru 
199295a618bdSEinar Rünkaru 		/* switch to external mic input */
199395a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
199495a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
199595a618bdSEinar Rünkaru 
199695a618bdSEinar Rünkaru 		/* disable internal digital mic */
199795a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
199895a618bdSEinar Rünkaru 		{}
199995a618bdSEinar Rünkaru 	};
200034cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
200195a618bdSEinar Rünkaru 		/* enable internal mic, port C */
200295a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
200395a618bdSEinar Rünkaru 
200495a618bdSEinar Rünkaru 		/* switch to internal mic input */
200595a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
200695a618bdSEinar Rünkaru 
200795a618bdSEinar Rünkaru 		/* disable external mic, port B */
200895a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
200995a618bdSEinar Rünkaru 		{}
201095a618bdSEinar Rünkaru 	};
201195a618bdSEinar Rünkaru 
201295a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
201395a618bdSEinar Rünkaru 	if (present) {
201495a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
201595a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
201695a618bdSEinar Rünkaru 	} else {
201795a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
201895a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
201995a618bdSEinar Rünkaru 	}
202095a618bdSEinar Rünkaru }
202195a618bdSEinar Rünkaru 
2022cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2023cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2024cfd3d8dcSGreg Alexander {
2025cfd3d8dcSGreg Alexander 	unsigned int present;
2026cfd3d8dcSGreg Alexander 
2027cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2028cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2029cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2030cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2031cfd3d8dcSGreg Alexander 		{}
2032cfd3d8dcSGreg Alexander 	};
203334cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2034cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2035cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2036cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2037cfd3d8dcSGreg Alexander 		{}
2038cfd3d8dcSGreg Alexander 	};
2039cfd3d8dcSGreg Alexander 
2040cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2041cfd3d8dcSGreg Alexander 	if (present) {
2042cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2043cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2044cfd3d8dcSGreg Alexander 	} else {
2045cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2046cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2047cfd3d8dcSGreg Alexander 	}
2048cfd3d8dcSGreg Alexander }
2049cfd3d8dcSGreg Alexander 
2050a1d6906eSDavid Henningsson 
2051a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2052a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2053a1d6906eSDavid Henningsson {
2054a1d6906eSDavid Henningsson 	unsigned int present;
2055a1d6906eSDavid Henningsson 
2056a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2057a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2058a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2059a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2060a1d6906eSDavid Henningsson }
2061a1d6906eSDavid Henningsson 
2062a1d6906eSDavid Henningsson 
2063048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2064048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2065048e78a5SDavid Henningsson {
2066048e78a5SDavid Henningsson 	unsigned int present;
2067048e78a5SDavid Henningsson 
2068048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2069048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2070048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2071048e78a5SDavid Henningsson 			    present ? 1 : 3);
2072048e78a5SDavid Henningsson }
2073048e78a5SDavid Henningsson 
2074048e78a5SDavid Henningsson 
20757b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
20767b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
20777b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
20787b2bfdbcSJens Taprogge {
20797b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
20807b2bfdbcSJens Taprogge 
208134cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
20827b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
20837b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
20847b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
20857b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20867b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20877b2bfdbcSJens Taprogge 		{}
20887b2bfdbcSJens Taprogge 	};
208934cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
20907b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
20917b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
20927b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
20937b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20947b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20957b2bfdbcSJens Taprogge 		{}
20967b2bfdbcSJens Taprogge 	};
209734cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
20987b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
20997b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
21007b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21017b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21027b2bfdbcSJens Taprogge 		{}
21037b2bfdbcSJens Taprogge 	};
21047b2bfdbcSJens Taprogge 
21057b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
21067b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
21077b2bfdbcSJens Taprogge 	if (ext_present) {
21087b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
21097b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
21107b2bfdbcSJens Taprogge 	} else if (dock_present) {
21117b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
21127b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
21137b2bfdbcSJens Taprogge 	} else {
21147b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
21157b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
21167b2bfdbcSJens Taprogge 	}
21177b2bfdbcSJens Taprogge }
21187b2bfdbcSJens Taprogge 
21190fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
21200fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
21210fb67e98SDaniel Drake {
21220fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
21230fb67e98SDaniel Drake 	unsigned int portA, portD;
21240fb67e98SDaniel Drake 
21250fb67e98SDaniel Drake 	/* Port A */
2126d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
21270fb67e98SDaniel Drake 
21280fb67e98SDaniel Drake 	/* Port D */
2129d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
21300fb67e98SDaniel Drake 
2131a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2132a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
21330fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
21340fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
21350fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21360fb67e98SDaniel Drake }
21370fb67e98SDaniel Drake 
213802b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
213902b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
214002b6b5b6SDavid Henningsson {
214102b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
214202b6b5b6SDavid Henningsson 
214302b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
214402b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
214502b6b5b6SDavid Henningsson 	else if (spec->ideapad)
214602b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
214702b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
214802b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
214902b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
215002b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2151a1d6906eSDavid Henningsson 	else if (spec->asus)
2152a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
215302b6b5b6SDavid Henningsson }
215402b6b5b6SDavid Henningsson 
21550fb67e98SDaniel Drake /* unsolicited event for jack sensing */
215602b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
215795a618bdSEinar Rünkaru {
215802b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
215995a618bdSEinar Rünkaru 	switch (res >> 26) {
216095a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
216195a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
216295a618bdSEinar Rünkaru 		break;
216395a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
216402b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
216595a618bdSEinar Rünkaru 		break;
216695a618bdSEinar Rünkaru 	}
216795a618bdSEinar Rünkaru }
216895a618bdSEinar Rünkaru 
21697b2bfdbcSJens Taprogge 
21700fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
21710fb67e98SDaniel Drake 	.num_items = 5,
21720fb67e98SDaniel Drake 	.items = {
21730fb67e98SDaniel Drake 		{ "0dB",  0 },
21740fb67e98SDaniel Drake 		{ "10dB", 1 },
21750fb67e98SDaniel Drake 		{ "20dB", 2 },
21760fb67e98SDaniel Drake 		{ "30dB", 3 },
21770fb67e98SDaniel Drake 		{ "40dB", 4 },
21780fb67e98SDaniel Drake 	},
21790fb67e98SDaniel Drake };
21800fb67e98SDaniel Drake 
2181cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2182c4cfe66cSDaniel Drake {
2183c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2184cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2185c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2186c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2187c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
21887b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2189cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2190cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2191cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2192cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2193cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2194cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2195cfd3d8dcSGreg Alexander 	}
2196c4cfe66cSDaniel Drake }
2197c4cfe66cSDaniel Drake 
21980fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
21990fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
22000fb67e98SDaniel Drake {
22010fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
22020fb67e98SDaniel Drake }
22030fb67e98SDaniel Drake 
22040fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
22050fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
22060fb67e98SDaniel Drake {
22070fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2208c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2209c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
22100fb67e98SDaniel Drake 	return 0;
22110fb67e98SDaniel Drake }
22120fb67e98SDaniel Drake 
22130fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
22140fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
22150fb67e98SDaniel Drake {
22160fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2217c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22180fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
22190fb67e98SDaniel Drake 	unsigned int idx;
22200fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
22210fb67e98SDaniel Drake 	if (idx >= imux->num_items)
22220fb67e98SDaniel Drake 		idx = imux->num_items - 1;
22230fb67e98SDaniel Drake 
2224c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2225c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2226c4cfe66cSDaniel Drake 	return 1;
2227c4cfe66cSDaniel Drake }
22280fb67e98SDaniel Drake 
2229f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
223034cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2231f6a2491cSAndy Robinson 				    int num_pins)
2232f6a2491cSAndy Robinson {
2233f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2234f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2235f6a2491cSAndy Robinson 	int i;
2236f6a2491cSAndy Robinson 
2237f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2238f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2239f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2240f6a2491cSAndy Robinson 			continue;
2241f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2242f6a2491cSAndy Robinson 			continue;
2243f6a2491cSAndy Robinson 	}
2244f6a2491cSAndy Robinson }
2245f6a2491cSAndy Robinson 
224634cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
22470fb67e98SDaniel Drake 	.num_items = 4,
22480fb67e98SDaniel Drake 	.items = {
22490fb67e98SDaniel Drake 		{ "Mic B", 0 },
22500fb67e98SDaniel Drake 		{ "Mic C", 1 },
22510fb67e98SDaniel Drake 		{ "Mic E", 2 },
22520fb67e98SDaniel Drake 		{ "Mic F", 3 },
22530fb67e98SDaniel Drake 	},
22540fb67e98SDaniel Drake };
22550fb67e98SDaniel Drake 
225634cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
22570fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
22580fb67e98SDaniel Drake 	.values = {
22590fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
22600fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
22610fb67e98SDaniel Drake 		0
22620fb67e98SDaniel Drake 	},
22630fb67e98SDaniel Drake };
22640fb67e98SDaniel Drake 
226534cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
22660fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
22670fb67e98SDaniel Drake 	.values = {
22680fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
22690fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
22700fb67e98SDaniel Drake 		0
22710fb67e98SDaniel Drake 	},
22720fb67e98SDaniel Drake };
22730fb67e98SDaniel Drake 
227434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
22750fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
22760fb67e98SDaniel Drake 	{}
22770fb67e98SDaniel Drake };
22780fb67e98SDaniel Drake 
227934cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
22800fb67e98SDaniel Drake 	{
22810fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
22820fb67e98SDaniel Drake 		.name = "Master Playback Switch",
22830fb67e98SDaniel Drake 		.info = cxt_eapd_info,
22840fb67e98SDaniel Drake 		.get = cxt_eapd_get,
22850fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
22860fb67e98SDaniel Drake 		.private_value = 0x1d,
22870fb67e98SDaniel Drake 	},
22880fb67e98SDaniel Drake 
22890fb67e98SDaniel Drake 	{
22900fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2291c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
22920fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
22930fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
22940fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
22950fb67e98SDaniel Drake 	},
22960fb67e98SDaniel Drake 
22970fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
22980fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
22990fb67e98SDaniel Drake 	{}
23000fb67e98SDaniel Drake };
23010fb67e98SDaniel Drake 
230234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2303254bba6aSEinar Rünkaru 	{
2304254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
230528c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2306254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2307254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2308254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2309254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2310254bba6aSEinar Rünkaru 	},
2311254bba6aSEinar Rünkaru 	{}
2312254bba6aSEinar Rünkaru };
2313254bba6aSEinar Rünkaru 
231434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
23150fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
23160fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
23170fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
23180fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
23190fb67e98SDaniel Drake 
23200fb67e98SDaniel Drake 	/* Speakers  */
23210fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23220fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23230fb67e98SDaniel Drake 
23240fb67e98SDaniel Drake 	/* HP, Amp  */
23250fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23260fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23270fb67e98SDaniel Drake 
23280fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23290fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23300fb67e98SDaniel Drake 
23310fb67e98SDaniel Drake 	/* DAC1 */
23320fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
23330fb67e98SDaniel Drake 
23340fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
23350fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
23360fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
23370fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
23380fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
23390fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
23400fb67e98SDaniel Drake 
23410fb67e98SDaniel Drake 	/* no digital microphone support yet */
23420fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23430fb67e98SDaniel Drake 
23440fb67e98SDaniel Drake 	/* Audio input selector */
23450fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
23460fb67e98SDaniel Drake 
23470fb67e98SDaniel Drake 	/* SPDIF route: PCM */
23480fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
23490fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
23500fb67e98SDaniel Drake 
23510fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23520fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23530fb67e98SDaniel Drake 
23540fb67e98SDaniel Drake 	/* EAPD */
23550fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
23560fb67e98SDaniel Drake 
23570fb67e98SDaniel Drake 	/* not handling these yet */
23580fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23590fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23600fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23610fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23620fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23630fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23640fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23650fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23660fb67e98SDaniel Drake 	{ } /* end */
23670fb67e98SDaniel Drake };
23680fb67e98SDaniel Drake 
236934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
237095a618bdSEinar Rünkaru 	/* Port A: headphones */
237195a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237295a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
237395a618bdSEinar Rünkaru 
237495a618bdSEinar Rünkaru 	/* Port B: external microphone */
237595a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237695a618bdSEinar Rünkaru 
237795a618bdSEinar Rünkaru 	/* Port C: unused */
237895a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237995a618bdSEinar Rünkaru 
238095a618bdSEinar Rünkaru 	/* Port D: unused */
238195a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
238295a618bdSEinar Rünkaru 
238395a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
238495a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
238595a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
238695a618bdSEinar Rünkaru 
238795a618bdSEinar Rünkaru 	/* Port F: unused */
238895a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
238995a618bdSEinar Rünkaru 
239095a618bdSEinar Rünkaru 	/* Port G: internal speakers */
239195a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
239295a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
239395a618bdSEinar Rünkaru 
239495a618bdSEinar Rünkaru 	/* DAC1 */
239595a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
239695a618bdSEinar Rünkaru 
239795a618bdSEinar Rünkaru 	/* DAC2: unused */
239895a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
239995a618bdSEinar Rünkaru 
240095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
240195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
240295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
240395a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
240495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
240595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
240695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
240795a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
240895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
240995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
241095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
241195a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
241295a618bdSEinar Rünkaru 
241395a618bdSEinar Rünkaru 	/* Digital microphone port */
241495a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
241595a618bdSEinar Rünkaru 
241695a618bdSEinar Rünkaru 	/* Audio input selectors */
241795a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
241895a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
241995a618bdSEinar Rünkaru 
242095a618bdSEinar Rünkaru 	/* Disable SPDIF */
242195a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
242295a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
242395a618bdSEinar Rünkaru 
242495a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
242595a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
242695a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
242795a618bdSEinar Rünkaru 	{ } /* end */
242895a618bdSEinar Rünkaru };
242995a618bdSEinar Rünkaru 
243034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2431cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2432cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2433cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2434cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2435cfd3d8dcSGreg Alexander 
2436cfd3d8dcSGreg Alexander 	/* Speakers  */
2437cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2438cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2439cfd3d8dcSGreg Alexander 
2440cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2441cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2442cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2443cfd3d8dcSGreg Alexander 
2444cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2445cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2446cfd3d8dcSGreg Alexander 
2447cfd3d8dcSGreg Alexander 	/* DAC1 */
2448cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2449cfd3d8dcSGreg Alexander 
2450cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2451cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2452cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2453cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2454cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2455cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2456cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2457cfd3d8dcSGreg Alexander 
2458cfd3d8dcSGreg Alexander 	/* Audio input selector */
2459cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2460cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2461cfd3d8dcSGreg Alexander 
2462cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2463cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2464cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2465cfd3d8dcSGreg Alexander 
2466cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2467cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2468cfd3d8dcSGreg Alexander 
2469cfd3d8dcSGreg Alexander 	/* internal microphone */
247028c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2471cfd3d8dcSGreg Alexander 
2472cfd3d8dcSGreg Alexander 	/* EAPD */
2473cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2474cfd3d8dcSGreg Alexander 
2475cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2476cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2477cfd3d8dcSGreg Alexander 	{ } /* end */
2478cfd3d8dcSGreg Alexander };
2479cfd3d8dcSGreg Alexander 
248034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
24817b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
24827b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
24837b2bfdbcSJens Taprogge 
24847b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
24857b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
24867b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
24877b2bfdbcSJens Taprogge 
24887b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
24897b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24907b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
24917b2bfdbcSJens Taprogge 
24927b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
24937b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24947b2bfdbcSJens Taprogge 
24957b2bfdbcSJens Taprogge 	/* Port C: Mic */
24967b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24977b2bfdbcSJens Taprogge 
24987b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
24997b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
25007b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
25017b2bfdbcSJens Taprogge 
25027b2bfdbcSJens Taprogge 	/* DAC1 */
25037b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
25047b2bfdbcSJens Taprogge 
25057b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
25067b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
25077b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
25087b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
25097b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
25107b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
25117b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
25127b2bfdbcSJens Taprogge 
25137b2bfdbcSJens Taprogge 	/* Audio input selector */
25147b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
25157b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
25167b2bfdbcSJens Taprogge 
25177b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
25187b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
25197b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
25207b2bfdbcSJens Taprogge 
25217b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25227b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25237b2bfdbcSJens Taprogge 
25247b2bfdbcSJens Taprogge 	/* internal microphone */
252528c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
25267b2bfdbcSJens Taprogge 
25277b2bfdbcSJens Taprogge 	/* EAPD */
25287b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
25297b2bfdbcSJens Taprogge 
25307b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
25317b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
25327b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
25337b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
25347b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
25357b2bfdbcSJens Taprogge 	{ } /* end */
25367b2bfdbcSJens Taprogge };
25377b2bfdbcSJens Taprogge 
253834cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
25390fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25400fb67e98SDaniel Drake 	{ } /* end */
25410fb67e98SDaniel Drake };
25420fb67e98SDaniel Drake 
2543048e78a5SDavid Henningsson 
254434cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2545048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2546048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2547048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2548048e78a5SDavid Henningsson 	{ } /* end */
2549048e78a5SDavid Henningsson };
2550048e78a5SDavid Henningsson 
25510fb67e98SDaniel Drake /* initialize jack-sensing, too */
25520fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
25530fb67e98SDaniel Drake {
25540fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
25550fb67e98SDaniel Drake 	conexant_init(codec);
25560fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
25570fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
255802b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
25590fb67e98SDaniel Drake 	}
2560c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
25610fb67e98SDaniel Drake 	return 0;
25620fb67e98SDaniel Drake }
25630fb67e98SDaniel Drake 
25640fb67e98SDaniel Drake enum {
25650fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
25660fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
25671feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
2568cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
25697b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
2570a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2571048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
2572fea4a4f9STakashi Iwai 	CXT5066_AUTO,		/* BIOS auto-parser */
25730fb67e98SDaniel Drake 	CXT5066_MODELS
25740fb67e98SDaniel Drake };
25750fb67e98SDaniel Drake 
2576ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
25770fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
25780fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
25791feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
2580cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
25817b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
2582a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
2583048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
2584fea4a4f9STakashi Iwai 	[CXT5066_AUTO]		= "auto",
25850fb67e98SDaniel Drake };
25860fb67e98SDaniel Drake 
258734cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
258800cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
25891feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
25908a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2591ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2592231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2593ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2594048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2595f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2596a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2597f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
25982ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
25995637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
26005637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
26014d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2602ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
260319593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
2604d2859fd4SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2605a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
26060fb67e98SDaniel Drake 	{}
26070fb67e98SDaniel Drake };
26080fb67e98SDaniel Drake 
26090fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
26100fb67e98SDaniel Drake {
26110fb67e98SDaniel Drake 	struct conexant_spec *spec;
26120fb67e98SDaniel Drake 	int board_config;
26130fb67e98SDaniel Drake 
2614fea4a4f9STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2615fea4a4f9STakashi Iwai 						  cxt5066_models, cxt5066_cfg_tbl);
2616fea4a4f9STakashi Iwai 	if (board_config < 0)
2617c82693dbSTakashi Iwai 		board_config = CXT5066_AUTO; /* model=auto as default */
2618fea4a4f9STakashi Iwai 	if (board_config == CXT5066_AUTO)
2619fea4a4f9STakashi Iwai 		return patch_conexant_auto(codec);
2620fea4a4f9STakashi Iwai 
26210fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
26220fb67e98SDaniel Drake 	if (!spec)
26230fb67e98SDaniel Drake 		return -ENOMEM;
26240fb67e98SDaniel Drake 	codec->spec = spec;
26250fb67e98SDaniel Drake 
26260fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
262775f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
26280fb67e98SDaniel Drake 
26290fb67e98SDaniel Drake 	spec->dell_automute = 0;
26300fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
26310fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
26320fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
2633f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2634f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
26350fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
26360fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
26370fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
26380fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
26390fb67e98SDaniel Drake 
26400fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
26410fb67e98SDaniel Drake 
26420fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
26430fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
26440fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
26450fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
26460fb67e98SDaniel Drake 	spec->cur_adc = 0;
26470fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
26480fb67e98SDaniel Drake 
26493507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
26503507e2a8STakashi Iwai 
26510fb67e98SDaniel Drake 	switch (board_config) {
26520fb67e98SDaniel Drake 	default:
26530fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
26540fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
26550fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
26560fb67e98SDaniel Drake 		break;
26570fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
26580fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
26590fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
26600fb67e98SDaniel Drake 
26610fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
26620fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
26630fb67e98SDaniel Drake 		spec->num_init_verbs++;
26640fb67e98SDaniel Drake 		spec->dell_automute = 1;
26650fb67e98SDaniel Drake 		break;
2666a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
2667048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
2668048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
266902b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2670048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
2671048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
2672048e78a5SDavid Henningsson 		spec->num_init_verbs++;
2673a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
2674a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
2675048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2676048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2677048e78a5SDavid Henningsson 		/* no S/PDIF out */
2678f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
2679048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
2680048e78a5SDavid Henningsson 		/* input source automatically selected */
2681048e78a5SDavid Henningsson 		spec->input_mux = NULL;
2682048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
2683048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
2684048e78a5SDavid Henningsson 		break;
2685048e78a5SDavid Henningsson 
26861feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
268775f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
268802b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
268995a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
26903a00c660STakashi Iwai 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
269195a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2692254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
269395a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
2694254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
2695c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
269695a618bdSEinar Rünkaru 
269795a618bdSEinar Rünkaru 		/* no S/PDIF out */
269895a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
269995a618bdSEinar Rünkaru 
270095a618bdSEinar Rünkaru 		/* input source automatically selected */
270195a618bdSEinar Rünkaru 		spec->input_mux = NULL;
270295a618bdSEinar Rünkaru 		break;
2703cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
2704cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
270502b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2706cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2707cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2708cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
2709cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
2710cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
2711cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
2712cfd3d8dcSGreg Alexander 
2713cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
2714cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
2715cfd3d8dcSGreg Alexander 
2716cfd3d8dcSGreg Alexander 		/* input source automatically selected */
2717cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
2718cfd3d8dcSGreg Alexander 		break;
27197b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
27207b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
272102b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
27227b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
27237b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
27247b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
27257b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
27267b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
27277b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
27287b2bfdbcSJens Taprogge 
27297b2bfdbcSJens Taprogge 		/* no S/PDIF out */
27307b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
27317b2bfdbcSJens Taprogge 
27327b2bfdbcSJens Taprogge 		/* input source automatically selected */
27337b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
27347b2bfdbcSJens Taprogge 		break;
27350fb67e98SDaniel Drake 	}
27360fb67e98SDaniel Drake 
27373507e2a8STakashi Iwai 	if (spec->beep_amp)
2738a86b1a2cSTakashi Iwai 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
27393507e2a8STakashi Iwai 
27400fb67e98SDaniel Drake 	return 0;
27410fb67e98SDaniel Drake }
2742461e2c78STakashi Iwai 
2743bf92d1d5STakashi Iwai #endif /* ENABLE_CXT_STATIC_QUIRKS */
2744bf92d1d5STakashi Iwai 
2745bf92d1d5STakashi Iwai 
2746461e2c78STakashi Iwai /*
2747f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
2748f2e5731dSTakashi Iwai  */
2749f2e5731dSTakashi Iwai 
2750f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
2751f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
2752f2e5731dSTakashi Iwai {
2753f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
2754f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
2755f2e5731dSTakashi Iwai 
2756f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
2757f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
2758f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
2759f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
2760f2e5731dSTakashi Iwai 			break;
2761f2e5731dSTakashi Iwai 		}
2762f2e5731dSTakashi Iwai }
2763f2e5731dSTakashi Iwai #else
2764f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
2765f2e5731dSTakashi Iwai #endif
2766f2e5731dSTakashi Iwai 
2767254f2968STakashi Iwai /* parse EAPDs */
276819110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec)
276919110595STakashi Iwai {
277019110595STakashi Iwai 	struct conexant_spec *spec = codec->spec;
277119110595STakashi Iwai 	hda_nid_t nid, end_nid;
277219110595STakashi Iwai 
277319110595STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
277419110595STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
277519110595STakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
277619110595STakashi Iwai 			continue;
277719110595STakashi Iwai 		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
277819110595STakashi Iwai 			continue;
277919110595STakashi Iwai 		spec->eapds[spec->num_eapds++] = nid;
278019110595STakashi Iwai 		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
278119110595STakashi Iwai 			break;
278219110595STakashi Iwai 	}
2783254f2968STakashi Iwai 
2784254f2968STakashi Iwai 	/* NOTE: below is a wild guess; if we have more than two EAPDs,
2785254f2968STakashi Iwai 	 * it's a new chip, where EAPDs are supposed to be associated to
2786254f2968STakashi Iwai 	 * pins, and we can control EAPD per pin.
2787254f2968STakashi Iwai 	 * OTOH, if only one or two EAPDs are found, it's an old chip,
2788254f2968STakashi Iwai 	 * thus it might control over all pins.
2789254f2968STakashi Iwai 	 */
2790aed523f1STakashi Iwai 	if (spec->num_eapds > 2)
2791ff359b14STakashi Iwai 		spec->dynamic_eapd = 1;
2792f2e5731dSTakashi Iwai }
2793f2e5731dSTakashi Iwai 
2794da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
2795da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
2796f2e5731dSTakashi Iwai {
2797f2e5731dSTakashi Iwai 	int i;
2798f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
2799f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
2800f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
2801da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
2802da339866STakashi Iwai 					    on ? 0x02 : 0);
2803f2e5731dSTakashi Iwai 	}
2804f2e5731dSTakashi Iwai }
2805f2e5731dSTakashi Iwai 
2806527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */
2807527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled)
2808527c73baSTakashi Iwai {
2809527c73baSTakashi Iwai 	struct hda_codec *codec = private_data;
2810527c73baSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
2811527c73baSTakashi Iwai 
2812527c73baSTakashi Iwai 	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
2813527c73baSTakashi Iwai }
2814527c73baSTakashi Iwai 
2815f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
2816f2e5731dSTakashi Iwai {
2817f2e5731dSTakashi Iwai 	int err;
2818f2e5731dSTakashi Iwai 
2819aed523f1STakashi Iwai 	err = snd_hda_gen_build_controls(codec);
2820f2e5731dSTakashi Iwai 	if (err < 0)
2821f2e5731dSTakashi Iwai 		return err;
2822f2e5731dSTakashi Iwai 
2823aed523f1STakashi Iwai 	err = add_beep_ctls(codec);
2824aed523f1STakashi Iwai 	if (err < 0)
2825aed523f1STakashi Iwai 		return err;
282622ce5f74STakashi Iwai 
282722ce5f74STakashi Iwai 	return 0;
282822ce5f74STakashi Iwai }
282922ce5f74STakashi Iwai 
2830ff359b14STakashi Iwai static int cx_auto_init(struct hda_codec *codec)
2831ff359b14STakashi Iwai {
2832ff359b14STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2833ff359b14STakashi Iwai 	snd_hda_gen_init(codec);
2834ff359b14STakashi Iwai 	if (!spec->dynamic_eapd)
2835ff359b14STakashi Iwai 		cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
2836e4c3bce2SDavid Henningsson 
2837e4c3bce2SDavid Henningsson 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
2838e4c3bce2SDavid Henningsson 
2839ff359b14STakashi Iwai 	return 0;
2840ff359b14STakashi Iwai }
2841ff359b14STakashi Iwai 
284208cf680cSDavid Henningsson static void cx_auto_free(struct hda_codec *codec)
284308cf680cSDavid Henningsson {
284408cf680cSDavid Henningsson 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
284508cf680cSDavid Henningsson 	snd_hda_gen_free(codec);
284608cf680cSDavid Henningsson }
284708cf680cSDavid Henningsson 
284834cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
2849f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
2850aed523f1STakashi Iwai 	.build_pcms = snd_hda_gen_build_pcms,
2851ff359b14STakashi Iwai 	.init = cx_auto_init,
285208cf680cSDavid Henningsson 	.free = cx_auto_free,
285329adc4b9SDavid Henningsson 	.unsol_event = snd_hda_jack_unsol_event,
2854164a7adaSTakashi Iwai #ifdef CONFIG_PM
2855164a7adaSTakashi Iwai 	.check_power_status = snd_hda_gen_check_power_status,
2856164a7adaSTakashi Iwai #endif
2857f2e5731dSTakashi Iwai };
2858f2e5731dSTakashi Iwai 
2859e92d4b08STakashi Iwai /*
2860e92d4b08STakashi Iwai  * pin fix-up
2861e92d4b08STakashi Iwai  */
286218dcd304SDavid Henningsson enum {
286318dcd304SDavid Henningsson 	CXT_PINCFG_LENOVO_X200,
2864d3980110STakashi Iwai 	CXT_PINCFG_LENOVO_TP410,
2865239fb862SHuacai Chen 	CXT_PINCFG_LEMOTE_A1004,
2866239fb862SHuacai Chen 	CXT_PINCFG_LEMOTE_A1205,
286718dcd304SDavid Henningsson 	CXT_FIXUP_STEREO_DMIC,
2868239fb862SHuacai Chen 	CXT_FIXUP_INC_MIC_BOOST,
2869e4c3bce2SDavid Henningsson 	CXT_FIXUP_HEADPHONE_MIC_PIN,
2870e4c3bce2SDavid Henningsson 	CXT_FIXUP_HEADPHONE_MIC,
28714a437044STakashi Iwai 	CXT_FIXUP_GPIO1,
287208cf680cSDavid Henningsson 	CXT_FIXUP_THINKPAD_ACPI,
28733a00c660STakashi Iwai 	CXT_FIXUP_OLPC_XO,
2874ad7725d3STakashi Iwai 	CXT_FIXUP_CAP_MIX_AMP,
2875*6dcbadefSTakashi Iwai 	CXT_FIXUP_TOSHIBA_P105,
287618dcd304SDavid Henningsson };
287718dcd304SDavid Henningsson 
2878b317b032STakashi Iwai /* for hda_fixup_thinkpad_acpi() */
2879b317b032STakashi Iwai #include "thinkpad_helper.c"
288008cf680cSDavid Henningsson 
288123d30f28STakashi Iwai static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
288223d30f28STakashi Iwai 				  const struct hda_fixup *fix, int action)
2883e92d4b08STakashi Iwai {
288418dcd304SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
2885aed523f1STakashi Iwai 	spec->gen.inv_dmic_split = 1;
2886e92d4b08STakashi Iwai }
2887e92d4b08STakashi Iwai 
2888239fb862SHuacai Chen static void cxt5066_increase_mic_boost(struct hda_codec *codec,
2889239fb862SHuacai Chen 				   const struct hda_fixup *fix, int action)
2890239fb862SHuacai Chen {
2891239fb862SHuacai Chen 	if (action != HDA_FIXUP_ACT_PRE_PROBE)
2892239fb862SHuacai Chen 		return;
2893239fb862SHuacai Chen 
2894239fb862SHuacai Chen 	snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
2895239fb862SHuacai Chen 				  (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
2896239fb862SHuacai Chen 				  (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2897239fb862SHuacai Chen 				  (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2898239fb862SHuacai Chen 				  (0 << AC_AMPCAP_MUTE_SHIFT));
2899239fb862SHuacai Chen }
2900239fb862SHuacai Chen 
2901e4c3bce2SDavid Henningsson static void cxt_update_headset_mode(struct hda_codec *codec)
2902e4c3bce2SDavid Henningsson {
2903e4c3bce2SDavid Henningsson 	/* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
2904e4c3bce2SDavid Henningsson 	int i;
2905e4c3bce2SDavid Henningsson 	bool mic_mode = false;
2906e4c3bce2SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
2907e4c3bce2SDavid Henningsson 	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
2908e4c3bce2SDavid Henningsson 
2909e4c3bce2SDavid Henningsson 	hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
2910e4c3bce2SDavid Henningsson 
2911e4c3bce2SDavid Henningsson 	for (i = 0; i < cfg->num_inputs; i++)
2912e4c3bce2SDavid Henningsson 		if (cfg->inputs[i].pin == mux_pin) {
2913e4c3bce2SDavid Henningsson 			mic_mode = !!cfg->inputs[i].is_headphone_mic;
2914e4c3bce2SDavid Henningsson 			break;
2915e4c3bce2SDavid Henningsson 		}
2916e4c3bce2SDavid Henningsson 
2917e4c3bce2SDavid Henningsson 	if (mic_mode) {
2918e4c3bce2SDavid Henningsson 		snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
2919e4c3bce2SDavid Henningsson 		spec->gen.hp_jack_present = false;
2920e4c3bce2SDavid Henningsson 	} else {
2921e4c3bce2SDavid Henningsson 		snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
2922e4c3bce2SDavid Henningsson 		spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
2923e4c3bce2SDavid Henningsson 	}
2924e4c3bce2SDavid Henningsson 
2925e4c3bce2SDavid Henningsson 	snd_hda_gen_update_outputs(codec);
2926e4c3bce2SDavid Henningsson }
2927e4c3bce2SDavid Henningsson 
2928e4c3bce2SDavid Henningsson static void cxt_update_headset_mode_hook(struct hda_codec *codec,
2929e4c3bce2SDavid Henningsson 			     struct snd_ctl_elem_value *ucontrol)
2930e4c3bce2SDavid Henningsson {
2931e4c3bce2SDavid Henningsson 	cxt_update_headset_mode(codec);
2932e4c3bce2SDavid Henningsson }
2933e4c3bce2SDavid Henningsson 
2934e4c3bce2SDavid Henningsson static void cxt_fixup_headphone_mic(struct hda_codec *codec,
2935e4c3bce2SDavid Henningsson 				    const struct hda_fixup *fix, int action)
2936e4c3bce2SDavid Henningsson {
2937e4c3bce2SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
2938e4c3bce2SDavid Henningsson 
2939e4c3bce2SDavid Henningsson 	switch (action) {
2940e4c3bce2SDavid Henningsson 	case HDA_FIXUP_ACT_PRE_PROBE:
2941e4c3bce2SDavid Henningsson 		spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
2942e4c3bce2SDavid Henningsson 		break;
2943e4c3bce2SDavid Henningsson 	case HDA_FIXUP_ACT_PROBE:
2944e4c3bce2SDavid Henningsson 		spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
2945e4c3bce2SDavid Henningsson 		spec->gen.automute_hook = cxt_update_headset_mode;
2946e4c3bce2SDavid Henningsson 		break;
2947e4c3bce2SDavid Henningsson 	case HDA_FIXUP_ACT_INIT:
2948e4c3bce2SDavid Henningsson 		cxt_update_headset_mode(codec);
2949e4c3bce2SDavid Henningsson 		break;
2950e4c3bce2SDavid Henningsson 	}
2951e4c3bce2SDavid Henningsson }
2952e4c3bce2SDavid Henningsson 
29533a00c660STakashi Iwai /* OPLC XO 1.5 fixup */
29543a00c660STakashi Iwai 
29553a00c660STakashi Iwai /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
29563a00c660STakashi Iwai  * through the microphone jack.
29573a00c660STakashi Iwai  * When the user enables this through a mixer switch, both internal and
29583a00c660STakashi Iwai  * external microphones are disabled. Gain is fixed at 0dB. In this mode,
29593a00c660STakashi Iwai  * we also allow the bias to be configured through a separate mixer
29603a00c660STakashi Iwai  * control. */
29613a00c660STakashi Iwai 
29623a00c660STakashi Iwai #define update_mic_pin(codec, nid, val)					\
29633a00c660STakashi Iwai 	snd_hda_codec_update_cache(codec, nid, 0,			\
29643a00c660STakashi Iwai 				   AC_VERB_SET_PIN_WIDGET_CONTROL, val)
29653a00c660STakashi Iwai 
29663a00c660STakashi Iwai static const struct hda_input_mux olpc_xo_dc_bias = {
29673a00c660STakashi Iwai 	.num_items = 3,
29683a00c660STakashi Iwai 	.items = {
29693a00c660STakashi Iwai 		{ "Off", PIN_IN },
29703a00c660STakashi Iwai 		{ "50%", PIN_VREF50 },
29713a00c660STakashi Iwai 		{ "80%", PIN_VREF80 },
29723a00c660STakashi Iwai 	},
29733a00c660STakashi Iwai };
29743a00c660STakashi Iwai 
29753a00c660STakashi Iwai static void olpc_xo_update_mic_boost(struct hda_codec *codec)
29763a00c660STakashi Iwai {
29773a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
29783a00c660STakashi Iwai 	int ch, val;
29793a00c660STakashi Iwai 
29803a00c660STakashi Iwai 	for (ch = 0; ch < 2; ch++) {
29813a00c660STakashi Iwai 		val = AC_AMP_SET_OUTPUT |
29823a00c660STakashi Iwai 			(ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
29833a00c660STakashi Iwai 		if (!spec->dc_enable)
29843a00c660STakashi Iwai 			val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
29853a00c660STakashi Iwai 		snd_hda_codec_write(codec, 0x17, 0,
29863a00c660STakashi Iwai 				    AC_VERB_SET_AMP_GAIN_MUTE, val);
29873a00c660STakashi Iwai 	}
29883a00c660STakashi Iwai }
29893a00c660STakashi Iwai 
29903a00c660STakashi Iwai static void olpc_xo_update_mic_pins(struct hda_codec *codec)
29913a00c660STakashi Iwai {
29923a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
29933a00c660STakashi Iwai 	int cur_input, val;
29943a00c660STakashi Iwai 	struct nid_path *path;
29953a00c660STakashi Iwai 
29963a00c660STakashi Iwai 	cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
29973a00c660STakashi Iwai 
29983a00c660STakashi Iwai 	/* Set up mic pins for port-B, C and F dynamically as the recording
29993a00c660STakashi Iwai 	 * LED is turned on/off by these pin controls
30003a00c660STakashi Iwai 	 */
30013a00c660STakashi Iwai 	if (!spec->dc_enable) {
30023a00c660STakashi Iwai 		/* disable DC bias path and pin for port F */
30033a00c660STakashi Iwai 		update_mic_pin(codec, 0x1e, 0);
30043a00c660STakashi Iwai 		snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
30053a00c660STakashi Iwai 
30063a00c660STakashi Iwai 		/* update port B (ext mic) and C (int mic) */
30073a00c660STakashi Iwai 		/* OLPC defers mic widget control until when capture is
30083a00c660STakashi Iwai 		 * started because the microphone LED comes on as soon as
30093a00c660STakashi Iwai 		 * these settings are put in place. if we did this before
30103a00c660STakashi Iwai 		 * recording, it would give the false indication that
30113a00c660STakashi Iwai 		 * recording is happening when it is not.
30123a00c660STakashi Iwai 		 */
30133a00c660STakashi Iwai 		update_mic_pin(codec, 0x1a, spec->recording ?
30143a00c660STakashi Iwai 			       snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
30153a00c660STakashi Iwai 		update_mic_pin(codec, 0x1b, spec->recording ?
30163a00c660STakashi Iwai 			       snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
30173a00c660STakashi Iwai 		/* enable normal mic path */
30183a00c660STakashi Iwai 		path = snd_hda_get_path_from_idx(codec, cur_input);
30193a00c660STakashi Iwai 		if (path)
30203a00c660STakashi Iwai 			snd_hda_activate_path(codec, path, true, false);
30213a00c660STakashi Iwai 	} else {
30223a00c660STakashi Iwai 		/* disable normal mic path */
30233a00c660STakashi Iwai 		path = snd_hda_get_path_from_idx(codec, cur_input);
30243a00c660STakashi Iwai 		if (path)
30253a00c660STakashi Iwai 			snd_hda_activate_path(codec, path, false, false);
30263a00c660STakashi Iwai 
30273a00c660STakashi Iwai 		/* Even though port F is the DC input, the bias is controlled
30283a00c660STakashi Iwai 		 * on port B.  We also leave that port as an active input (but
30293a00c660STakashi Iwai 		 * unselected) in DC mode just in case that is necessary to
30303a00c660STakashi Iwai 		 * make the bias setting take effect.
30313a00c660STakashi Iwai 		 */
30323a00c660STakashi Iwai 		if (spec->recording)
30333a00c660STakashi Iwai 			val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
30343a00c660STakashi Iwai 		else
30353a00c660STakashi Iwai 			val = 0;
30363a00c660STakashi Iwai 		update_mic_pin(codec, 0x1a, val);
30373a00c660STakashi Iwai 		update_mic_pin(codec, 0x1b, 0);
30383a00c660STakashi Iwai 		/* enable DC bias path and pin */
30393a00c660STakashi Iwai 		update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
30403a00c660STakashi Iwai 		snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
30413a00c660STakashi Iwai 	}
30423a00c660STakashi Iwai }
30433a00c660STakashi Iwai 
30443a00c660STakashi Iwai /* mic_autoswitch hook */
30453a00c660STakashi Iwai static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
30463a00c660STakashi Iwai {
30473a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
30483a00c660STakashi Iwai 	int saved_cached_write = codec->cached_write;
30493a00c660STakashi Iwai 
30503a00c660STakashi Iwai 	codec->cached_write = 1;
30513a00c660STakashi Iwai 	/* in DC mode, we don't handle automic */
30523a00c660STakashi Iwai 	if (!spec->dc_enable)
30533a00c660STakashi Iwai 		snd_hda_gen_mic_autoswitch(codec, jack);
30543a00c660STakashi Iwai 	olpc_xo_update_mic_pins(codec);
30553a00c660STakashi Iwai 	snd_hda_codec_flush_cache(codec);
30563a00c660STakashi Iwai 	codec->cached_write = saved_cached_write;
30573a00c660STakashi Iwai 	if (spec->dc_enable)
30583a00c660STakashi Iwai 		olpc_xo_update_mic_boost(codec);
30593a00c660STakashi Iwai }
30603a00c660STakashi Iwai 
30613a00c660STakashi Iwai /* pcm_capture hook */
30623a00c660STakashi Iwai static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
30633a00c660STakashi Iwai 				 struct hda_codec *codec,
30643a00c660STakashi Iwai 				 struct snd_pcm_substream *substream,
30653a00c660STakashi Iwai 				 int action)
30663a00c660STakashi Iwai {
30673a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
30683a00c660STakashi Iwai 
30693a00c660STakashi Iwai 	/* toggle spec->recording flag and update mic pins accordingly
30703a00c660STakashi Iwai 	 * for turning on/off LED
30713a00c660STakashi Iwai 	 */
30723a00c660STakashi Iwai 	switch (action) {
30733a00c660STakashi Iwai 	case HDA_GEN_PCM_ACT_PREPARE:
30743a00c660STakashi Iwai 		spec->recording = 1;
30753a00c660STakashi Iwai 		olpc_xo_update_mic_pins(codec);
30763a00c660STakashi Iwai 		break;
30773a00c660STakashi Iwai 	case HDA_GEN_PCM_ACT_CLEANUP:
30783a00c660STakashi Iwai 		spec->recording = 0;
30793a00c660STakashi Iwai 		olpc_xo_update_mic_pins(codec);
30803a00c660STakashi Iwai 		break;
30813a00c660STakashi Iwai 	}
30823a00c660STakashi Iwai }
30833a00c660STakashi Iwai 
30843a00c660STakashi Iwai static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
30853a00c660STakashi Iwai 			       struct snd_ctl_elem_value *ucontrol)
30863a00c660STakashi Iwai {
30873a00c660STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
30883a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
30893a00c660STakashi Iwai 	ucontrol->value.integer.value[0] = spec->dc_enable;
30903a00c660STakashi Iwai 	return 0;
30913a00c660STakashi Iwai }
30923a00c660STakashi Iwai 
30933a00c660STakashi Iwai static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
30943a00c660STakashi Iwai 			       struct snd_ctl_elem_value *ucontrol)
30953a00c660STakashi Iwai {
30963a00c660STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
30973a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
30983a00c660STakashi Iwai 	int dc_enable = !!ucontrol->value.integer.value[0];
30993a00c660STakashi Iwai 
31003a00c660STakashi Iwai 	if (dc_enable == spec->dc_enable)
31013a00c660STakashi Iwai 		return 0;
31023a00c660STakashi Iwai 
31033a00c660STakashi Iwai 	spec->dc_enable = dc_enable;
31043a00c660STakashi Iwai 	olpc_xo_update_mic_pins(codec);
31053a00c660STakashi Iwai 	olpc_xo_update_mic_boost(codec);
31063a00c660STakashi Iwai 	return 1;
31073a00c660STakashi Iwai }
31083a00c660STakashi Iwai 
31093a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
31103a00c660STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
31113a00c660STakashi Iwai {
31123a00c660STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
31133a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
31143a00c660STakashi Iwai 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
31153a00c660STakashi Iwai 	return 0;
31163a00c660STakashi Iwai }
31173a00c660STakashi Iwai 
31183a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
31193a00c660STakashi Iwai 				     struct snd_ctl_elem_info *uinfo)
31203a00c660STakashi Iwai {
31213a00c660STakashi Iwai 	return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
31223a00c660STakashi Iwai }
31233a00c660STakashi Iwai 
31243a00c660STakashi Iwai static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
31253a00c660STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
31263a00c660STakashi Iwai {
31273a00c660STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
31283a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
31293a00c660STakashi Iwai 	const struct hda_input_mux *imux = &olpc_xo_dc_bias;
31303a00c660STakashi Iwai 	unsigned int idx;
31313a00c660STakashi Iwai 
31323a00c660STakashi Iwai 	idx = ucontrol->value.enumerated.item[0];
31333a00c660STakashi Iwai 	if (idx >= imux->num_items)
31343a00c660STakashi Iwai 		idx = imux->num_items - 1;
31353a00c660STakashi Iwai 	if (spec->dc_input_bias == idx)
31363a00c660STakashi Iwai 		return 0;
31373a00c660STakashi Iwai 
31383a00c660STakashi Iwai 	spec->dc_input_bias = idx;
31393a00c660STakashi Iwai 	if (spec->dc_enable)
31403a00c660STakashi Iwai 		olpc_xo_update_mic_pins(codec);
31413a00c660STakashi Iwai 	return 1;
31423a00c660STakashi Iwai }
31433a00c660STakashi Iwai 
31443a00c660STakashi Iwai static const struct snd_kcontrol_new olpc_xo_mixers[] = {
31453a00c660STakashi Iwai 	{
31463a00c660STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
31473a00c660STakashi Iwai 		.name = "DC Mode Enable Switch",
31483a00c660STakashi Iwai 		.info = snd_ctl_boolean_mono_info,
31493a00c660STakashi Iwai 		.get = olpc_xo_dc_mode_get,
31503a00c660STakashi Iwai 		.put = olpc_xo_dc_mode_put,
31513a00c660STakashi Iwai 	},
31523a00c660STakashi Iwai 	{
31533a00c660STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
31543a00c660STakashi Iwai 		.name = "DC Input Bias Enum",
31553a00c660STakashi Iwai 		.info = olpc_xo_dc_bias_enum_info,
31563a00c660STakashi Iwai 		.get = olpc_xo_dc_bias_enum_get,
31573a00c660STakashi Iwai 		.put = olpc_xo_dc_bias_enum_put,
31583a00c660STakashi Iwai 	},
31593a00c660STakashi Iwai 	{}
31603a00c660STakashi Iwai };
31613a00c660STakashi Iwai 
31623a00c660STakashi Iwai /* overriding mic boost put callback; update mic boost volume only when
31633a00c660STakashi Iwai  * DC mode is disabled
31643a00c660STakashi Iwai  */
31653a00c660STakashi Iwai static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
31663a00c660STakashi Iwai 				 struct snd_ctl_elem_value *ucontrol)
31673a00c660STakashi Iwai {
31683a00c660STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
31693a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
31703a00c660STakashi Iwai 	int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
31713a00c660STakashi Iwai 	if (ret > 0 && spec->dc_enable)
31723a00c660STakashi Iwai 		olpc_xo_update_mic_boost(codec);
31733a00c660STakashi Iwai 	return ret;
31743a00c660STakashi Iwai }
31753a00c660STakashi Iwai 
31763a00c660STakashi Iwai static void cxt_fixup_olpc_xo(struct hda_codec *codec,
31773a00c660STakashi Iwai 				    const struct hda_fixup *fix, int action)
31783a00c660STakashi Iwai {
31793a00c660STakashi Iwai 	struct conexant_spec *spec = codec->spec;
31803a00c660STakashi Iwai 	int i;
31813a00c660STakashi Iwai 
31823a00c660STakashi Iwai 	if (action != HDA_FIXUP_ACT_PROBE)
31833a00c660STakashi Iwai 		return;
31843a00c660STakashi Iwai 
31853a00c660STakashi Iwai 	spec->gen.mic_autoswitch_hook = olpc_xo_automic;
31863a00c660STakashi Iwai 	spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
31873a00c660STakashi Iwai 	spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
31883a00c660STakashi Iwai 
31893a00c660STakashi Iwai 	snd_hda_add_new_ctls(codec, olpc_xo_mixers);
31903a00c660STakashi Iwai 
31913a00c660STakashi Iwai 	/* OLPC's microphone port is DC coupled for use with external sensors,
31923a00c660STakashi Iwai 	 * therefore we use a 50% mic bias in order to center the input signal
31933a00c660STakashi Iwai 	 * with the DC input range of the codec.
31943a00c660STakashi Iwai 	 */
31953a00c660STakashi Iwai 	snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
31963a00c660STakashi Iwai 
31973a00c660STakashi Iwai 	/* override mic boost control */
31983a00c660STakashi Iwai 	for (i = 0; i < spec->gen.kctls.used; i++) {
31993a00c660STakashi Iwai 		struct snd_kcontrol_new *kctl =
32003a00c660STakashi Iwai 			snd_array_elem(&spec->gen.kctls, i);
32013a00c660STakashi Iwai 		if (!strcmp(kctl->name, "Mic Boost Volume")) {
32023a00c660STakashi Iwai 			kctl->put = olpc_xo_mic_boost_put;
32033a00c660STakashi Iwai 			break;
32043a00c660STakashi Iwai 		}
32053a00c660STakashi Iwai 	}
32063a00c660STakashi Iwai }
32073a00c660STakashi Iwai 
3208ad7725d3STakashi Iwai /*
3209ad7725d3STakashi Iwai  * Fix max input level on mixer widget to 0dB
3210ad7725d3STakashi Iwai  * (originally it has 0x2b steps with 0dB offset 0x14)
3211ad7725d3STakashi Iwai  */
3212ad7725d3STakashi Iwai static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
3213ad7725d3STakashi Iwai 				  const struct hda_fixup *fix, int action)
3214ad7725d3STakashi Iwai {
3215ad7725d3STakashi Iwai 	snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
3216ad7725d3STakashi Iwai 				  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
3217ad7725d3STakashi Iwai 				  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3218ad7725d3STakashi Iwai 				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3219ad7725d3STakashi Iwai 				  (1 << AC_AMPCAP_MUTE_SHIFT));
3220ad7725d3STakashi Iwai }
3221e4c3bce2SDavid Henningsson 
3222d70f3632STakashi Iwai /* ThinkPad X200 & co with cxt5051 */
322323d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
3224e92d4b08STakashi Iwai 	{ 0x16, 0x042140ff }, /* HP (seq# overridden) */
3225e92d4b08STakashi Iwai 	{ 0x17, 0x21a11000 }, /* dock-mic */
3226e92d4b08STakashi Iwai 	{ 0x19, 0x2121103f }, /* dock-HP */
32273e93f5efSTakashi Iwai 	{ 0x1c, 0x21440100 }, /* dock SPDIF out */
3228e92d4b08STakashi Iwai 	{}
3229e92d4b08STakashi Iwai };
3230e92d4b08STakashi Iwai 
3231d70f3632STakashi Iwai /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
323223d30f28STakashi Iwai static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
3233d70f3632STakashi Iwai 	{ 0x19, 0x042110ff }, /* HP (seq# overridden) */
3234d70f3632STakashi Iwai 	{ 0x1a, 0x21a190f0 }, /* dock-mic */
3235d70f3632STakashi Iwai 	{ 0x1c, 0x212140ff }, /* dock-HP */
3236d70f3632STakashi Iwai 	{}
3237e92d4b08STakashi Iwai };
3238e92d4b08STakashi Iwai 
3239239fb862SHuacai Chen /* Lemote A1004/A1205 with cxt5066 */
3240239fb862SHuacai Chen static const struct hda_pintbl cxt_pincfg_lemote[] = {
3241239fb862SHuacai Chen 	{ 0x1a, 0x90a10020 }, /* Internal mic */
3242239fb862SHuacai Chen 	{ 0x1b, 0x03a11020 }, /* External mic */
3243239fb862SHuacai Chen 	{ 0x1d, 0x400101f0 }, /* Not used */
3244239fb862SHuacai Chen 	{ 0x1e, 0x40a701f0 }, /* Not used */
3245239fb862SHuacai Chen 	{ 0x20, 0x404501f0 }, /* Not used */
3246239fb862SHuacai Chen 	{ 0x22, 0x404401f0 }, /* Not used */
3247239fb862SHuacai Chen 	{ 0x23, 0x40a701f0 }, /* Not used */
3248239fb862SHuacai Chen 	{}
3249239fb862SHuacai Chen };
3250239fb862SHuacai Chen 
325123d30f28STakashi Iwai static const struct hda_fixup cxt_fixups[] = {
325223d30f28STakashi Iwai 	[CXT_PINCFG_LENOVO_X200] = {
325323d30f28STakashi Iwai 		.type = HDA_FIXUP_PINS,
325423d30f28STakashi Iwai 		.v.pins = cxt_pincfg_lenovo_x200,
325523d30f28STakashi Iwai 	},
325623d30f28STakashi Iwai 	[CXT_PINCFG_LENOVO_TP410] = {
325723d30f28STakashi Iwai 		.type = HDA_FIXUP_PINS,
325823d30f28STakashi Iwai 		.v.pins = cxt_pincfg_lenovo_tp410,
325908cf680cSDavid Henningsson 		.chained = true,
326008cf680cSDavid Henningsson 		.chain_id = CXT_FIXUP_THINKPAD_ACPI,
326123d30f28STakashi Iwai 	},
3262239fb862SHuacai Chen 	[CXT_PINCFG_LEMOTE_A1004] = {
3263239fb862SHuacai Chen 		.type = HDA_FIXUP_PINS,
3264239fb862SHuacai Chen 		.chained = true,
3265239fb862SHuacai Chen 		.chain_id = CXT_FIXUP_INC_MIC_BOOST,
3266239fb862SHuacai Chen 		.v.pins = cxt_pincfg_lemote,
3267239fb862SHuacai Chen 	},
3268239fb862SHuacai Chen 	[CXT_PINCFG_LEMOTE_A1205] = {
3269239fb862SHuacai Chen 		.type = HDA_FIXUP_PINS,
3270239fb862SHuacai Chen 		.v.pins = cxt_pincfg_lemote,
3271239fb862SHuacai Chen 	},
327223d30f28STakashi Iwai 	[CXT_FIXUP_STEREO_DMIC] = {
327323d30f28STakashi Iwai 		.type = HDA_FIXUP_FUNC,
327423d30f28STakashi Iwai 		.v.func = cxt_fixup_stereo_dmic,
327523d30f28STakashi Iwai 	},
3276239fb862SHuacai Chen 	[CXT_FIXUP_INC_MIC_BOOST] = {
3277239fb862SHuacai Chen 		.type = HDA_FIXUP_FUNC,
3278239fb862SHuacai Chen 		.v.func = cxt5066_increase_mic_boost,
3279239fb862SHuacai Chen 	},
3280e4c3bce2SDavid Henningsson 	[CXT_FIXUP_HEADPHONE_MIC_PIN] = {
3281e4c3bce2SDavid Henningsson 		.type = HDA_FIXUP_PINS,
3282e4c3bce2SDavid Henningsson 		.chained = true,
3283e4c3bce2SDavid Henningsson 		.chain_id = CXT_FIXUP_HEADPHONE_MIC,
3284e4c3bce2SDavid Henningsson 		.v.pins = (const struct hda_pintbl[]) {
3285e4c3bce2SDavid Henningsson 			{ 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
3286e4c3bce2SDavid Henningsson 			{ }
3287e4c3bce2SDavid Henningsson 		}
3288e4c3bce2SDavid Henningsson 	},
3289e4c3bce2SDavid Henningsson 	[CXT_FIXUP_HEADPHONE_MIC] = {
3290e4c3bce2SDavid Henningsson 		.type = HDA_FIXUP_FUNC,
3291e4c3bce2SDavid Henningsson 		.v.func = cxt_fixup_headphone_mic,
3292e4c3bce2SDavid Henningsson 	},
32934a437044STakashi Iwai 	[CXT_FIXUP_GPIO1] = {
32944a437044STakashi Iwai 		.type = HDA_FIXUP_VERBS,
32954a437044STakashi Iwai 		.v.verbs = (const struct hda_verb[]) {
32964a437044STakashi Iwai 			{ 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
32974a437044STakashi Iwai 			{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
32984a437044STakashi Iwai 			{ 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
32994a437044STakashi Iwai 			{ }
33004a437044STakashi Iwai 		},
33014a437044STakashi Iwai 	},
330208cf680cSDavid Henningsson 	[CXT_FIXUP_THINKPAD_ACPI] = {
330308cf680cSDavid Henningsson 		.type = HDA_FIXUP_FUNC,
3304b317b032STakashi Iwai 		.v.func = hda_fixup_thinkpad_acpi,
330508cf680cSDavid Henningsson 	},
33063a00c660STakashi Iwai 	[CXT_FIXUP_OLPC_XO] = {
33073a00c660STakashi Iwai 		.type = HDA_FIXUP_FUNC,
33083a00c660STakashi Iwai 		.v.func = cxt_fixup_olpc_xo,
33093a00c660STakashi Iwai 	},
3310ad7725d3STakashi Iwai 	[CXT_FIXUP_CAP_MIX_AMP] = {
3311ad7725d3STakashi Iwai 		.type = HDA_FIXUP_FUNC,
3312ad7725d3STakashi Iwai 		.v.func = cxt_fixup_cap_mix_amp,
3313ad7725d3STakashi Iwai 	},
3314*6dcbadefSTakashi Iwai 	[CXT_FIXUP_TOSHIBA_P105] = {
3315*6dcbadefSTakashi Iwai 		.type = HDA_FIXUP_PINS,
3316*6dcbadefSTakashi Iwai 		.v.pins = (const struct hda_pintbl[]) {
3317*6dcbadefSTakashi Iwai 			{ 0x10, 0x961701f0 }, /* speaker/hp */
3318*6dcbadefSTakashi Iwai 			{ 0x12, 0x02a1901e }, /* ext mic */
3319*6dcbadefSTakashi Iwai 			{ 0x14, 0x95a70110 }, /* int mic */
3320*6dcbadefSTakashi Iwai 			{}
3321*6dcbadefSTakashi Iwai 		},
3322*6dcbadefSTakashi Iwai 	},
3323ad7725d3STakashi Iwai };
3324ad7725d3STakashi Iwai 
3325ad7725d3STakashi Iwai static const struct snd_pci_quirk cxt5045_fixups[] = {
3326*6dcbadefSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
3327ad7725d3STakashi Iwai 	/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
3328ad7725d3STakashi Iwai 	 * really bad sound over 0dB on NID 0x17.
3329ad7725d3STakashi Iwai 	 */
3330ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
3331ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
3332ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
3333ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
3334ad7725d3STakashi Iwai 	{}
3335ad7725d3STakashi Iwai };
3336ad7725d3STakashi Iwai 
3337ad7725d3STakashi Iwai static const struct hda_model_fixup cxt5045_fixup_models[] = {
3338ad7725d3STakashi Iwai 	{ .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
3339*6dcbadefSTakashi Iwai 	{ .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
3340ad7725d3STakashi Iwai 	{}
3341e92d4b08STakashi Iwai };
3342e92d4b08STakashi Iwai 
3343d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5051_fixups[] = {
3344e92d4b08STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3345e92d4b08STakashi Iwai 	{}
3346e92d4b08STakashi Iwai };
3347e92d4b08STakashi Iwai 
3348a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5051_fixup_models[] = {
3349a2dd933dSTakashi Iwai 	{ .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
3350a2dd933dSTakashi Iwai 	{}
3351a2dd933dSTakashi Iwai };
3352a2dd933dSTakashi Iwai 
3353d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5066_fixups[] = {
335463a077e2STakashi Iwai 	SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
33554a437044STakashi Iwai 	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
3356e4c3bce2SDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
33573a00c660STakashi Iwai 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
3358d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3359d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3360d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3361d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3362d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
3363a555bb8cSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
336488d57606SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
336518dcd304SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
3366e4db0952SFelix Kaechele 	SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
3367b3c5dce8SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
33682fd3f170SHui Wang 	SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
3369239fb862SHuacai Chen 	SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3370239fb862SHuacai Chen 	SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
3371f2e5731dSTakashi Iwai 	{}
3372f2e5731dSTakashi Iwai };
3373f2e5731dSTakashi Iwai 
3374a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5066_fixup_models[] = {
3375a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
3376a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
3377a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
3378a2dd933dSTakashi Iwai 	{ .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
3379a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
3380a2dd933dSTakashi Iwai 	{ .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
33813a00c660STakashi Iwai 	{ .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
3382a2dd933dSTakashi Iwai 	{}
3383a2dd933dSTakashi Iwai };
3384a2dd933dSTakashi Iwai 
33853868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
33863868137eSTakashi Iwai  * can be created (bko#42825)
33873868137eSTakashi Iwai  */
33883868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec)
33893868137eSTakashi Iwai {
33903868137eSTakashi Iwai 	static hda_nid_t out_nids[] = {
33913868137eSTakashi Iwai 		0x10, 0x11, 0
33923868137eSTakashi Iwai 	};
33933868137eSTakashi Iwai 	hda_nid_t *p;
33943868137eSTakashi Iwai 
33953868137eSTakashi Iwai 	for (p = out_nids; *p; p++)
33963868137eSTakashi Iwai 		snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
33973868137eSTakashi Iwai 					  AC_AMPCAP_MIN_MUTE |
33983868137eSTakashi Iwai 					  query_amp_caps(codec, *p, HDA_OUTPUT));
33993868137eSTakashi Iwai }
34003868137eSTakashi Iwai 
3401f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3402f2e5731dSTakashi Iwai {
3403f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3404f2e5731dSTakashi Iwai 	int err;
3405f2e5731dSTakashi Iwai 
34061f8458a2STakashi Iwai 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
34071f8458a2STakashi Iwai 	       codec->chip_name);
34081f8458a2STakashi Iwai 
3409f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3410f2e5731dSTakashi Iwai 	if (!spec)
3411f2e5731dSTakashi Iwai 		return -ENOMEM;
3412aed523f1STakashi Iwai 	snd_hda_gen_spec_init(&spec->gen);
3413f2e5731dSTakashi Iwai 	codec->spec = spec;
3414e92d4b08STakashi Iwai 
3415aed523f1STakashi Iwai 	cx_auto_parse_beep(codec);
3416aed523f1STakashi Iwai 	cx_auto_parse_eapd(codec);
3417ff359b14STakashi Iwai 	spec->gen.own_eapd_ctl = 1;
3418ff359b14STakashi Iwai 	if (spec->dynamic_eapd)
3419aed523f1STakashi Iwai 		spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
3420e92d4b08STakashi Iwai 
34216b452142STakashi Iwai 	switch (codec->vendor_id) {
34226b452142STakashi Iwai 	case 0x14f15045:
34234f32456eSMichael Karcher 		codec->single_adc_amp = 1;
3424ad7725d3STakashi Iwai 		snd_hda_pick_fixup(codec, cxt5045_fixup_models,
3425ad7725d3STakashi Iwai 				   cxt5045_fixups, cxt_fixups);
34266b452142STakashi Iwai 		break;
3427164a7adaSTakashi Iwai 	case 0x14f15047:
3428164a7adaSTakashi Iwai 		codec->pin_amp_workaround = 1;
3429164a7adaSTakashi Iwai 		spec->gen.mixer_nid = 0x19;
3430164a7adaSTakashi Iwai 		break;
34313868137eSTakashi Iwai 	case 0x14f15051:
34323868137eSTakashi Iwai 		add_cx5051_fake_mutes(codec);
343351969d62SMichael Karcher 		codec->pin_amp_workaround = 1;
3434a2dd933dSTakashi Iwai 		snd_hda_pick_fixup(codec, cxt5051_fixup_models,
3435a2dd933dSTakashi Iwai 				   cxt5051_fixups, cxt_fixups);
34363868137eSTakashi Iwai 		break;
343751969d62SMichael Karcher 	default:
343851969d62SMichael Karcher 		codec->pin_amp_workaround = 1;
3439a2dd933dSTakashi Iwai 		snd_hda_pick_fixup(codec, cxt5066_fixup_models,
3440a2dd933dSTakashi Iwai 				   cxt5066_fixups, cxt_fixups);
344123d30f28STakashi Iwai 		break;
34426b452142STakashi Iwai 	}
34436b452142STakashi Iwai 
3444f29735cbSTakashi Iwai 	/* Show mute-led control only on HP laptops
3445f29735cbSTakashi Iwai 	 * This is a sort of white-list: on HP laptops, EAPD corresponds
3446f29735cbSTakashi Iwai 	 * only to the mute-LED without actualy amp function.  Meanwhile,
3447f29735cbSTakashi Iwai 	 * others may use EAPD really as an amp switch, so it might be
3448f29735cbSTakashi Iwai 	 * not good to expose it blindly.
3449527c73baSTakashi Iwai 	 */
3450f29735cbSTakashi Iwai 	switch (codec->subsystem_id >> 16) {
3451f29735cbSTakashi Iwai 	case 0x103c:
3452aed523f1STakashi Iwai 		spec->gen.vmaster_mute_enum = 1;
3453f29735cbSTakashi Iwai 		break;
3454f29735cbSTakashi Iwai 	}
3455527c73baSTakashi Iwai 
3456aed523f1STakashi Iwai 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3457aed523f1STakashi Iwai 
3458e4c3bce2SDavid Henningsson 	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
3459e4c3bce2SDavid Henningsson 				       spec->parse_flags);
346022ce5f74STakashi Iwai 	if (err < 0)
3461aed523f1STakashi Iwai 		goto error;
3462aed523f1STakashi Iwai 
3463aed523f1STakashi Iwai 	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3464aed523f1STakashi Iwai 	if (err < 0)
3465aed523f1STakashi Iwai 		goto error;
3466aed523f1STakashi Iwai 
3467f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
34684f2864a4STakashi Iwai 
34694f2864a4STakashi Iwai 	/* Some laptops with Conexant chips show stalls in S3 resume,
34704f2864a4STakashi Iwai 	 * which falls into the single-cmd mode.
34714f2864a4STakashi Iwai 	 * Better to make reset, then.
34724f2864a4STakashi Iwai 	 */
34734f2864a4STakashi Iwai 	if (!codec->bus->sync_write) {
34744f2864a4STakashi Iwai 		snd_printd("hda_codec: "
34754f2864a4STakashi Iwai 			   "Enable sync_write for stable communication\n");
34764f2864a4STakashi Iwai 		codec->bus->sync_write = 1;
34774f2864a4STakashi Iwai 		codec->bus->allow_bus_reset = 1;
34784f2864a4STakashi Iwai 	}
34794f2864a4STakashi Iwai 
3480e4c3bce2SDavid Henningsson 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3481e4c3bce2SDavid Henningsson 
3482f2e5731dSTakashi Iwai 	return 0;
3483aed523f1STakashi Iwai 
3484aed523f1STakashi Iwai  error:
348508cf680cSDavid Henningsson 	cx_auto_free(codec);
3486aed523f1STakashi Iwai 	return err;
3487f2e5731dSTakashi Iwai }
3488f2e5731dSTakashi Iwai 
3489bf92d1d5STakashi Iwai #ifndef ENABLE_CXT_STATIC_QUIRKS
3490bf92d1d5STakashi Iwai #define patch_cxt5045	patch_conexant_auto
3491bf92d1d5STakashi Iwai #define patch_cxt5047	patch_conexant_auto
3492bf92d1d5STakashi Iwai #define patch_cxt5051	patch_conexant_auto
3493bf92d1d5STakashi Iwai #define patch_cxt5066	patch_conexant_auto
3494bf92d1d5STakashi Iwai #endif
3495bf92d1d5STakashi Iwai 
3496f2e5731dSTakashi Iwai /*
3497461e2c78STakashi Iwai  */
3498461e2c78STakashi Iwai 
349934cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
350082f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
350182f30040STobin Davis 	  .patch = patch_cxt5045 },
350282f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
350382f30040STobin Davis 	  .patch = patch_cxt5047 },
3504461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3505461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
35060fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
35070fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
350895a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
350995a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3510850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3511850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
35127b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
35137b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
3514f0ca89b0SDavid Henningsson 	{ .id = 0x14f1506c, .name = "CX20588",
3515f0ca89b0SDavid Henningsson 	  .patch = patch_cxt5066 },
35166da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
35176da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
3518f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
3519f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3520f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
3521f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3522f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
3523f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3524f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
3525f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3526f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
3527f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3528f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
3529f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3530f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
3531f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3532f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
3533f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
35342d825fd8STakashi Iwai 	{ .id = 0x14f1510f, .name = "CX20751/2",
35352d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
35362d825fd8STakashi Iwai 	{ .id = 0x14f15110, .name = "CX20751/2",
35372d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
35382d825fd8STakashi Iwai 	{ .id = 0x14f15111, .name = "CX20753/4",
35392d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
354042c364acSTakashi Iwai 	{ .id = 0x14f15113, .name = "CX20755",
354142c364acSTakashi Iwai 	  .patch = patch_conexant_auto },
354242c364acSTakashi Iwai 	{ .id = 0x14f15114, .name = "CX20756",
354342c364acSTakashi Iwai 	  .patch = patch_conexant_auto },
354442c364acSTakashi Iwai 	{ .id = 0x14f15115, .name = "CX20757",
354542c364acSTakashi Iwai 	  .patch = patch_conexant_auto },
35468f42d769STakashi Iwai 	{ .id = 0x14f151d7, .name = "CX20952",
35478f42d769STakashi Iwai 	  .patch = patch_conexant_auto },
3548c9b443d4STobin Davis 	{} /* terminator */
3549c9b443d4STobin Davis };
35501289e9e8STakashi Iwai 
35511289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
35521289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
35531289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
35540fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
355595a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3556850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
35577b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
3558f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c");
35596da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
3560f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
3561f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
3562f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3563f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3564f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3565f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3566f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3567f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
35682d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f1510f");
35692d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15110");
35702d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15111");
357142c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15113");
357242c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15114");
357342c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15115");
35748f42d769STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f151d7");
35751289e9e8STakashi Iwai 
35761289e9e8STakashi Iwai MODULE_LICENSE("GPL");
35771289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
35781289e9e8STakashi Iwai 
35791289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
35801289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
35811289e9e8STakashi Iwai 	.owner = THIS_MODULE,
35821289e9e8STakashi Iwai };
35831289e9e8STakashi Iwai 
35841289e9e8STakashi Iwai static int __init patch_conexant_init(void)
35851289e9e8STakashi Iwai {
35861289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
35871289e9e8STakashi Iwai }
35881289e9e8STakashi Iwai 
35891289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
35901289e9e8STakashi Iwai {
35911289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
35921289e9e8STakashi Iwai }
35931289e9e8STakashi Iwai 
35941289e9e8STakashi Iwai module_init(patch_conexant_init)
35951289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3596