xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision ad7725d31becb0abf0758adac7f08c754f231574)
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),
10146a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10155218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
101615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
101715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10189e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10199e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
102015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
102215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1023dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1024dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
102515908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1026c9b443d4STobin Davis 	{}
1027c9b443d4STobin Davis };
1028c9b443d4STobin Davis 
1029c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1030c9b443d4STobin Davis {
1031c9b443d4STobin Davis 	struct conexant_spec *spec;
1032c9b443d4STobin Davis 	int board_config;
1033c9b443d4STobin Davis 
10341f8458a2STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
10351f8458a2STakashi Iwai 						  cxt5045_models,
10361f8458a2STakashi Iwai 						  cxt5045_cfg_tbl);
10371f8458a2STakashi Iwai 	if (board_config < 0)
1038c82693dbSTakashi Iwai 		board_config = CXT5045_AUTO; /* model=auto as default */
10391f8458a2STakashi Iwai 	if (board_config == CXT5045_AUTO)
10401f8458a2STakashi Iwai 		return patch_conexant_auto(codec);
10411f8458a2STakashi Iwai 
1042c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1043c9b443d4STobin Davis 	if (!spec)
1044c9b443d4STobin Davis 		return -ENOMEM;
1045c9b443d4STobin Davis 	codec->spec = spec;
10464f32456eSMichael Karcher 	codec->single_adc_amp = 1;
1047c9b443d4STobin Davis 
1048c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1049c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1050c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1051c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1052c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1053c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1054c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1055c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1056c9b443d4STobin Davis 	spec->num_mixers = 1;
1057c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1058c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1059c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1060c9b443d4STobin Davis 	spec->spdif_route = 0;
10613507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
10623507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
10635cd57529STobin Davis 
10643507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1065c9b443d4STobin Davis 
1066c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1067c9b443d4STobin Davis 
1068c9b443d4STobin Davis 	switch (board_config) {
106915908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
10707f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1071c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1072c9b443d4STobin Davis 		spec->num_init_verbs = 2;
10737f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
10747f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
10757f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
10767f29673bSTobin Davis 		break;
107715908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
107886376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10797f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
10807f29673bSTobin Davis 		spec->num_init_verbs = 2;
10817f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1082c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1083c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1084c9b443d4STobin Davis 		break;
108515908c36SMarc Boucher 	default:
108615908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
108715908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
108815908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
108915908c36SMarc Boucher 		spec->num_init_verbs = 3;
109015908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
109115908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
109215908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
109315908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
109415908c36SMarc Boucher 		break;
10955218c892SJiang Zhe 	case CXT5045_BENQ:
10965218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
10975218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
10985218c892SJiang Zhe 		spec->num_init_verbs = 1;
10995218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11005218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11015218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11025218c892SJiang Zhe 		spec->num_mixers = 2;
11035218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11045218c892SJiang Zhe 		break;
11052de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11062de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11072de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11082de3c232SJiang zhe 		spec->num_init_verbs = 2;
11092de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11102de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11112de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11122de3c232SJiang zhe 		break;
1113c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1114c9b443d4STobin Davis 	case CXT5045_TEST:
1115c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1116c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1117c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
111815908c36SMarc Boucher 		break;
111915908c36SMarc Boucher 
1120c9b443d4STobin Davis #endif
1121c9b443d4STobin Davis 	}
112248ecb7e8STakashi Iwai 
1123031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1124031005f7STakashi Iwai 	case 0x103c:
11258f0f5ff6SDaniel T Chen 	case 0x1631:
11260b587fc4SDaniel T Chen 	case 0x1734:
11270ebf9e36SDaniel T Chen 	case 0x17aa:
11280ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
11290ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
11300ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
113148ecb7e8STakashi Iwai 		 */
113248ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
113348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
113448ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
113548ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
113648ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1137031005f7STakashi Iwai 		break;
1138031005f7STakashi Iwai 	}
113948ecb7e8STakashi Iwai 
11403507e2a8STakashi Iwai 	if (spec->beep_amp)
1141a86b1a2cSTakashi Iwai 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
11423507e2a8STakashi Iwai 
1143c9b443d4STobin Davis 	return 0;
1144c9b443d4STobin Davis }
1145c9b443d4STobin Davis 
1146c9b443d4STobin Davis 
1147c9b443d4STobin Davis /* Conexant 5047 specific */
114882f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1149c9b443d4STobin Davis 
115034cbe3a6STakashi Iwai static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
115134cbe3a6STakashi Iwai static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
115234cbe3a6STakashi Iwai static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1153c9b443d4STobin Davis 
115434cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5047_modes[1] = {
11555cd57529STobin Davis 	{ 2, NULL },
11565cd57529STobin Davis };
1157c9b443d4STobin Davis 
115834cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_toshiba_capture_source = {
115982f30040STobin Davis 	.num_items = 2,
116082f30040STobin Davis 	.items = {
116182f30040STobin Davis 		{ "ExtMic", 0x2 },
116282f30040STobin Davis 		{ "Line-In", 0x1 },
1163c9b443d4STobin Davis 	}
1164c9b443d4STobin Davis };
1165c9b443d4STobin Davis 
1166c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1167c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1168c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1169c9b443d4STobin Davis {
1170c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1171c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
117282f30040STobin Davis 	unsigned int bits;
1173c9b443d4STobin Davis 
117482f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1175c9b443d4STobin Davis 		return 0;
1176c9b443d4STobin Davis 
117782f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
117882f30040STobin Davis 	 * the headphone jack
117982f30040STobin Davis 	 */
118047fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
11813b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
11823b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
11833b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
11843b7523fcSTakashi Iwai 	 */
11855d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
118647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
118747fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
118847fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
118947fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1190c9b443d4STobin Davis 	return 1;
1191c9b443d4STobin Davis }
1192c9b443d4STobin Davis 
1193c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1194c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1195c9b443d4STobin Davis {
119682f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1197dd87da1cSTobin Davis 	unsigned int bits;
1198c9b443d4STobin Davis 
1199d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1200dd87da1cSTobin Davis 
120147fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12023b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12035d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
120447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1205c9b443d4STobin Davis }
1206c9b443d4STobin Davis 
1207c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1208c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1209c9b443d4STobin Davis {
121034cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_on[] = {
12119f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12129f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1213c9b443d4STobin Davis 		{}
1214c9b443d4STobin Davis 	};
121534cbe3a6STakashi Iwai 	static const struct hda_verb mic_jack_off[] = {
12169f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12179f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1218c9b443d4STobin Davis 		{}
1219c9b443d4STobin Davis 	};
1220c9b443d4STobin Davis 	unsigned int present;
1221c9b443d4STobin Davis 
1222d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1223c9b443d4STobin Davis 	if (present)
1224c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1225c9b443d4STobin Davis 	else
1226c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1227c9b443d4STobin Davis }
1228c9b443d4STobin Davis 
1229c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1230c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1231c9b443d4STobin Davis 				  unsigned int res)
1232c9b443d4STobin Davis {
12339f113e0eSMarc Boucher 	switch (res >> 26) {
1234c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1235c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1236c9b443d4STobin Davis 		break;
1237c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1238c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1239c9b443d4STobin Davis 		break;
1240c9b443d4STobin Davis 	}
1241c9b443d4STobin Davis }
1242c9b443d4STobin Davis 
124334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
1244df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1245df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
12465f99f86aSDavid Henningsson 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
1247c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1248c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1249c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1250c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
125182f30040STobin Davis 	{
125282f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
125382f30040STobin Davis 		.name = "Master Playback Switch",
125482f30040STobin Davis 		.info = cxt_eapd_info,
125582f30040STobin Davis 		.get = cxt_eapd_get,
1256c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1257c9b443d4STobin Davis 		.private_value = 0x13,
1258c9b443d4STobin Davis 	},
1259c9b443d4STobin Davis 
1260c9b443d4STobin Davis 	{}
1261c9b443d4STobin Davis };
1262c9b443d4STobin Davis 
126334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
12643b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12655d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1266df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1267df481e41STakashi Iwai 	{}
1268df481e41STakashi Iwai };
1269df481e41STakashi Iwai 
127034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1271c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1272c9b443d4STobin Davis 	{ } /* end */
1273c9b443d4STobin Davis };
1274c9b443d4STobin Davis 
127534cbe3a6STakashi Iwai static const struct hda_verb cxt5047_init_verbs[] = {
1276c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1277c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1278c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1279c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
12807f29673bSTobin Davis 	/* HP, Speaker  */
1281b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
12825b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
12835b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
12847f29673bSTobin Davis 	/* Record selector: Mic */
12857f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
12867f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
12877f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
12887f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1289c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1290c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1291c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1292c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1293c9b443d4STobin Davis 	/* SPDIF route: PCM */
1294c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
129582f30040STobin Davis 	/* Enable unsolicited events */
129682f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
129782f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1298c9b443d4STobin Davis 	{ } /* end */
1299c9b443d4STobin Davis };
1300c9b443d4STobin Davis 
1301c9b443d4STobin Davis /* configuration for Toshiba Laptops */
130234cbe3a6STakashi Iwai static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
13033b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1304c9b443d4STobin Davis 	{}
1305c9b443d4STobin Davis };
1306c9b443d4STobin Davis 
1307c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1308c9b443d4STobin Davis  * configuration.
1309c9b443d4STobin Davis  */
1310c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
131134cbe3a6STakashi Iwai static const struct hda_input_mux cxt5047_test_capture_source = {
131282f30040STobin Davis 	.num_items = 4,
1313c9b443d4STobin Davis 	.items = {
131482f30040STobin Davis 		{ "LINE1 pin", 0x0 },
131582f30040STobin Davis 		{ "MIC1 pin", 0x1 },
131682f30040STobin Davis 		{ "MIC2 pin", 0x2 },
131782f30040STobin Davis 		{ "CD pin", 0x3 },
1318c9b443d4STobin Davis         },
1319c9b443d4STobin Davis };
1320c9b443d4STobin Davis 
132134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
1322c9b443d4STobin Davis 
1323c9b443d4STobin Davis 	/* Output only controls */
132482f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
132582f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
132682f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
132782f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1328c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1329c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1330c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1331c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
133282f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
133382f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
133482f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
133582f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1336c9b443d4STobin Davis 
1337c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1338c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1339c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1340c9b443d4STobin Davis 
134182f30040STobin Davis 	/* EAPD Switch Control */
134282f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
134382f30040STobin Davis 
1344c9b443d4STobin Davis 	/* Loopback mixer controls */
134582f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
134682f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
134782f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
134882f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
134982f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
135082f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
135182f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
135282f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1353c9b443d4STobin Davis 
135482f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
135582f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
135682f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
135782f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
135882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
135982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
136082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
136182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1362c9b443d4STobin Davis 	{
1363c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1364c9b443d4STobin Davis 		.name = "Input Source",
1365c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1366c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1367c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1368c9b443d4STobin Davis 	},
1369854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
13709f113e0eSMarc Boucher 
1371c9b443d4STobin Davis 	{ } /* end */
1372c9b443d4STobin Davis };
1373c9b443d4STobin Davis 
137434cbe3a6STakashi Iwai static const struct hda_verb cxt5047_test_init_verbs[] = {
1375c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1376c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1377c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1378c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1379c9b443d4STobin Davis 
1380c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1381c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1382c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1383c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1384c9b443d4STobin Davis 	 * control.
1385c9b443d4STobin Davis 	 */
1386c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1387c9b443d4STobin Davis 
1388c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1389c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1390c9b443d4STobin Davis 	 */
1391c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1392c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1393c9b443d4STobin Davis 
1394c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1395c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1396c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1397c9b443d4STobin Davis 
1398c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1399c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1400c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1401c9b443d4STobin Davis 	 * input/output buffers as needed.
1402c9b443d4STobin Davis 	 */
1403c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1404c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1405c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1406c9b443d4STobin Davis 
1407c9b443d4STobin Davis 	/* Mute capture amp left and right */
1408c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1409c9b443d4STobin Davis 
1410c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1411c9b443d4STobin Davis 	 * pin)
1412c9b443d4STobin Davis 	 */
1413c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1414c9b443d4STobin Davis 
1415c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1416c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1417c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1418c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1419c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1420c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1421c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1422c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1423c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1424c9b443d4STobin Davis 
1425c9b443d4STobin Davis 	{ }
1426c9b443d4STobin Davis };
1427c9b443d4STobin Davis #endif
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis 
1430c9b443d4STobin Davis /* initialize jack-sensing, too */
1431c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1432c9b443d4STobin Davis {
1433c9b443d4STobin Davis 	conexant_init(codec);
1434c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1435c9b443d4STobin Davis 	return 0;
1436c9b443d4STobin Davis }
1437c9b443d4STobin Davis 
1438c9b443d4STobin Davis 
1439c9b443d4STobin Davis enum {
1440f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1441f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1442f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1443c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1444c9b443d4STobin Davis 	CXT5047_TEST,
1445c9b443d4STobin Davis #endif
1446fa5dadcbSTakashi Iwai 	CXT5047_AUTO,
1447f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1448c9b443d4STobin Davis };
1449c9b443d4STobin Davis 
1450ea734963STakashi Iwai static const char * const cxt5047_models[CXT5047_MODELS] = {
1451f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1452f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1453f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1454c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1455f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1456c9b443d4STobin Davis #endif
1457fa5dadcbSTakashi Iwai 	[CXT5047_AUTO]		= "auto",
1458f5fcc13cSTakashi Iwai };
1459c9b443d4STobin Davis 
146034cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1461ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1462dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1463dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1464f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1465c9b443d4STobin Davis 	{}
1466c9b443d4STobin Davis };
1467c9b443d4STobin Davis 
1468c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1469c9b443d4STobin Davis {
1470c9b443d4STobin Davis 	struct conexant_spec *spec;
1471c9b443d4STobin Davis 	int board_config;
1472c9b443d4STobin Davis 
1473fa5dadcbSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1474fa5dadcbSTakashi Iwai 						  cxt5047_models,
1475fa5dadcbSTakashi Iwai 						  cxt5047_cfg_tbl);
1476fa5dadcbSTakashi Iwai 	if (board_config < 0)
1477c82693dbSTakashi Iwai 		board_config = CXT5047_AUTO; /* model=auto as default */
1478fa5dadcbSTakashi Iwai 	if (board_config == CXT5047_AUTO)
1479fa5dadcbSTakashi Iwai 		return patch_conexant_auto(codec);
1480fa5dadcbSTakashi Iwai 
1481c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1482c9b443d4STobin Davis 	if (!spec)
1483c9b443d4STobin Davis 		return -ENOMEM;
1484c9b443d4STobin Davis 	codec->spec = spec;
14859421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1486c9b443d4STobin Davis 
1487c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1488c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1489c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1490c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1491c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1492c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1493c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1494c9b443d4STobin Davis 	spec->num_mixers = 1;
1495df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1496c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1497c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1498c9b443d4STobin Davis 	spec->spdif_route = 0;
14995cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15005cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1501c9b443d4STobin Davis 
1502c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1503c9b443d4STobin Davis 
1504c9b443d4STobin Davis 	switch (board_config) {
1505c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1506df481e41STakashi Iwai 		spec->num_mixers = 2;
1507df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1508df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1509c9b443d4STobin Davis 		break;
1510c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1511df481e41STakashi Iwai 		spec->num_mixers = 2;
1512df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1513fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1514c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1515c9b443d4STobin Davis 		break;
1516c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
151782f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1518df481e41STakashi Iwai 		spec->num_mixers = 2;
1519df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1520c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1521c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1522fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1523c9b443d4STobin Davis 		break;
1524c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1525c9b443d4STobin Davis 	case CXT5047_TEST:
1526c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1527c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1528c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1529fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1530c9b443d4STobin Davis #endif
1531c9b443d4STobin Davis 	}
1532dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1533025f206cSDaniel T Chen 
1534025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1535025f206cSDaniel T Chen 	case 0x103c:
1536025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1537025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1538025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1539025f206cSDaniel T Chen 		 */
1540025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1541025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1542025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1543025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1544025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1545025f206cSDaniel T Chen 		break;
1546025f206cSDaniel T Chen 	}
1547025f206cSDaniel T Chen 
1548c9b443d4STobin Davis 	return 0;
1549c9b443d4STobin Davis }
1550c9b443d4STobin Davis 
1551461e2c78STakashi Iwai /* Conexant 5051 specific */
155234cbe3a6STakashi Iwai static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
155334cbe3a6STakashi Iwai static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1554461e2c78STakashi Iwai 
155534cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5051_modes[1] = {
1556461e2c78STakashi Iwai 	{ 2, NULL },
1557461e2c78STakashi Iwai };
1558461e2c78STakashi Iwai 
1559461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1560461e2c78STakashi Iwai {
1561461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1562461e2c78STakashi Iwai 	unsigned int pinctl;
156323d2df5bSTakashi Iwai 	/* headphone pin */
156423d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
1565cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x16, pinctl);
156623d2df5bSTakashi Iwai 	/* speaker pin */
1567461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1568cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
1569a80581d0SJustin P. Mattock 	/* on ideapad there is an additional speaker (subwoofer) to mute */
1570f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1571cdd03cedSTakashi Iwai 		snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
1572461e2c78STakashi Iwai }
1573461e2c78STakashi Iwai 
1574461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1575461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1576461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1577461e2c78STakashi Iwai {
1578461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1579461e2c78STakashi Iwai 
1580461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1581461e2c78STakashi Iwai 		return 0;
1582461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1583461e2c78STakashi Iwai 	return 1;
1584461e2c78STakashi Iwai }
1585461e2c78STakashi Iwai 
1586461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1587461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1588461e2c78STakashi Iwai {
158979d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1590461e2c78STakashi Iwai 	unsigned int present;
1591461e2c78STakashi Iwai 
1592faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
159379d7d533STakashi Iwai 		return;
1594d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1595461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1596461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1597461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1598461e2c78STakashi Iwai }
1599461e2c78STakashi Iwai 
1600461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1601461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1602461e2c78STakashi Iwai {
1603461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1604461e2c78STakashi Iwai 	unsigned int present;
1605461e2c78STakashi Iwai 	hda_nid_t new_adc;
1606461e2c78STakashi Iwai 
1607faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
160879d7d533STakashi Iwai 		return;
1609d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1610461e2c78STakashi Iwai 	if (present)
1611461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1612461e2c78STakashi Iwai 	else
1613461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1614461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1615461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1616461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1617f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1618461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1619461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1620461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1621461e2c78STakashi Iwai 					   spec->cur_adc_format);
1622461e2c78STakashi Iwai 	}
1623461e2c78STakashi Iwai }
1624461e2c78STakashi Iwai 
1625461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1626461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1627461e2c78STakashi Iwai {
1628461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1629461e2c78STakashi Iwai 
1630d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1631461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1632461e2c78STakashi Iwai }
1633461e2c78STakashi Iwai 
1634461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1635461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1636461e2c78STakashi Iwai 				   unsigned int res)
1637461e2c78STakashi Iwai {
1638461e2c78STakashi Iwai 	switch (res >> 26) {
1639461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1640461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1641461e2c78STakashi Iwai 		break;
1642461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1643461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1644461e2c78STakashi Iwai 		break;
1645461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1646461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1647461e2c78STakashi Iwai 		break;
1648461e2c78STakashi Iwai 	}
1649461e2c78STakashi Iwai }
1650461e2c78STakashi Iwai 
165134cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1652461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1653461e2c78STakashi Iwai 	{
1654461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1655461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1656461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1657461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1658461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1659461e2c78STakashi Iwai 		.private_value = 0x1a,
1660461e2c78STakashi Iwai 	},
16612c7a3fb3STakashi Iwai 	{}
16622c7a3fb3STakashi Iwai };
1663461e2c78STakashi Iwai 
166434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
16652c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
16662c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16678607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
16688607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1669c40bd914SDavid Henningsson 	HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
1670c40bd914SDavid Henningsson 	HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
1671461e2c78STakashi Iwai 	{}
1672461e2c78STakashi Iwai };
1673461e2c78STakashi Iwai 
167434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1675461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1676461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16778607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
16788607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
1679461e2c78STakashi Iwai 	{}
1680461e2c78STakashi Iwai };
1681461e2c78STakashi Iwai 
168234cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
16834e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
16844e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
168579d7d533STakashi Iwai 	{}
168679d7d533STakashi Iwai };
168779d7d533STakashi Iwai 
168834cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
16895f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
16905f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1691cd9d95a5SKen Prox 	{}
1692cd9d95a5SKen Prox };
1693cd9d95a5SKen Prox 
169434cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1695faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1696faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
16978607f7c4SDavid Henningsson 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
16988607f7c4SDavid Henningsson 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
1699faddaa5dSTakashi Iwai 	{}
1700faddaa5dSTakashi Iwai };
1701faddaa5dSTakashi Iwai 
170234cbe3a6STakashi Iwai static const struct hda_verb cxt5051_init_verbs[] = {
1703461e2c78STakashi Iwai 	/* Line in, Mic */
1704461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1705461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1706461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1707461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1708461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1709461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1710461e2c78STakashi Iwai 	/* SPK  */
1711461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1712461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1713461e2c78STakashi Iwai 	/* HP, Amp  */
1714461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1715461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1716461e2c78STakashi Iwai 	/* DAC1 */
1717461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
171828c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1719461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1720461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1721461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1722461e2c78STakashi Iwai 	/* SPDIF route: PCM */
17231965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1724461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1725461e2c78STakashi Iwai 	/* EAPD */
1726461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1727461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1728461e2c78STakashi Iwai 	{ } /* end */
1729461e2c78STakashi Iwai };
1730461e2c78STakashi Iwai 
173134cbe3a6STakashi Iwai static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
173279d7d533STakashi Iwai 	/* Line in, Mic */
173379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
173479d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
173579d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
173679d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
173779d7d533STakashi Iwai 	/* SPK  */
173879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
173979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
174079d7d533STakashi Iwai 	/* HP, Amp  */
174179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
174279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
174379d7d533STakashi Iwai 	/* DAC1 */
174479d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
174528c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
174679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
174779d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
174879d7d533STakashi Iwai 	/* SPDIF route: PCM */
174979d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
175079d7d533STakashi Iwai 	/* EAPD */
175179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
175279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
175379d7d533STakashi Iwai 	{ } /* end */
175479d7d533STakashi Iwai };
175579d7d533STakashi Iwai 
175634cbe3a6STakashi Iwai static const struct hda_verb cxt5051_f700_init_verbs[] = {
1757cd9d95a5SKen Prox 	/* Line in, Mic */
175830ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1759cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1760cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1761cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1762cd9d95a5SKen Prox 	/* SPK  */
1763cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1764cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1765cd9d95a5SKen Prox 	/* HP, Amp  */
1766cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1767cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1768cd9d95a5SKen Prox 	/* DAC1 */
1769cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
177028c4edb7SDavid Henningsson 	/* Record selector: Internal mic */
1771cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1772cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1773cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1774cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1775cd9d95a5SKen Prox 	/* EAPD */
1776cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1777cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1778cd9d95a5SKen Prox 	{ } /* end */
1779cd9d95a5SKen Prox };
1780cd9d95a5SKen Prox 
17816953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
17826953e552STakashi Iwai 				 unsigned int event)
17836953e552STakashi Iwai {
17846953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
17856953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
17866953e552STakashi Iwai 			    AC_USRSP_EN | event);
17876953e552STakashi Iwai }
17886953e552STakashi Iwai 
178934cbe3a6STakashi Iwai static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
1790f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1791f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1792f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1793f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1794f7154de2SHerton Ronaldo Krzesinski };
1795f7154de2SHerton Ronaldo Krzesinski 
1796461e2c78STakashi Iwai /* initialize jack-sensing, too */
1797461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1798461e2c78STakashi Iwai {
17996953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
18006953e552STakashi Iwai 
1801461e2c78STakashi Iwai 	conexant_init(codec);
18026953e552STakashi Iwai 
18036953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
18046953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
18056953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
18066953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
18076953e552STakashi Iwai 
1808461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1809461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1810461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1811461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1812461e2c78STakashi Iwai 	}
1813461e2c78STakashi Iwai 	return 0;
1814461e2c78STakashi Iwai }
1815461e2c78STakashi Iwai 
1816461e2c78STakashi Iwai 
1817461e2c78STakashi Iwai enum {
1818461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1819461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
182079d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
1821cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1822faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1823f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
18246764bcefSTakashi Iwai 	CXT5051_AUTO,		/* auto-parser */
1825461e2c78STakashi Iwai 	CXT5051_MODELS
1826461e2c78STakashi Iwai };
1827461e2c78STakashi Iwai 
1828ea734963STakashi Iwai static const char *const cxt5051_models[CXT5051_MODELS] = {
1829461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1830461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
183179d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
18325f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1833faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1834f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
18356764bcefSTakashi Iwai 	[CXT5051_AUTO]		= "auto",
1836461e2c78STakashi Iwai };
1837461e2c78STakashi Iwai 
183834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
183979d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
18401812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
18415f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1842faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1843461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1844461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1845461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1846f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1847461e2c78STakashi Iwai 	{}
1848461e2c78STakashi Iwai };
1849461e2c78STakashi Iwai 
1850461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1851461e2c78STakashi Iwai {
1852461e2c78STakashi Iwai 	struct conexant_spec *spec;
1853461e2c78STakashi Iwai 	int board_config;
1854461e2c78STakashi Iwai 
18556764bcefSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
18566764bcefSTakashi Iwai 						  cxt5051_models,
18576764bcefSTakashi Iwai 						  cxt5051_cfg_tbl);
18586764bcefSTakashi Iwai 	if (board_config < 0)
1859c82693dbSTakashi Iwai 		board_config = CXT5051_AUTO; /* model=auto as default */
18601f8458a2STakashi Iwai 	if (board_config == CXT5051_AUTO)
18616764bcefSTakashi Iwai 		return patch_conexant_auto(codec);
18626764bcefSTakashi Iwai 
1863461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1864461e2c78STakashi Iwai 	if (!spec)
1865461e2c78STakashi Iwai 		return -ENOMEM;
1866461e2c78STakashi Iwai 	codec->spec = spec;
18679421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1868461e2c78STakashi Iwai 
1869461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1870461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1871461e2c78STakashi Iwai 
1872461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1873461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1874461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1875461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1876461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1877461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
18782c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
18792c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
18802c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
1881461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1882461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1883461e2c78STakashi Iwai 	spec->spdif_route = 0;
1884461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1885461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1886461e2c78STakashi Iwai 	spec->cur_adc = 0;
1887461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1888461e2c78STakashi Iwai 
18893507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
18903507e2a8STakashi Iwai 
189179d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
189279d7d533STakashi Iwai 
1893faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1894461e2c78STakashi Iwai 	switch (board_config) {
1895461e2c78STakashi Iwai 	case CXT5051_HP:
1896461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1897461e2c78STakashi Iwai 		break;
189879d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
189979d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
190079d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1901faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
190279d7d533STakashi Iwai 		break;
1903cd9d95a5SKen Prox 	case CXT5051_F700:
1904cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
1905cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
1906faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
1907faddaa5dSTakashi Iwai 		break;
1908faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
1909faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
1910faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
1911cd9d95a5SKen Prox 		break;
1912f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
1913f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
1914f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
1915f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
1916f7154de2SHerton Ronaldo Krzesinski 		break;
1917461e2c78STakashi Iwai 	}
1918461e2c78STakashi Iwai 
19193507e2a8STakashi Iwai 	if (spec->beep_amp)
1920a86b1a2cSTakashi Iwai 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
19213507e2a8STakashi Iwai 
1922461e2c78STakashi Iwai 	return 0;
1923461e2c78STakashi Iwai }
1924461e2c78STakashi Iwai 
19250fb67e98SDaniel Drake /* Conexant 5066 specific */
19260fb67e98SDaniel Drake 
192734cbe3a6STakashi Iwai static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
192834cbe3a6STakashi Iwai static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
192934cbe3a6STakashi Iwai static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
193034cbe3a6STakashi Iwai static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
19310fb67e98SDaniel Drake 
193234cbe3a6STakashi Iwai static const struct hda_channel_mode cxt5066_modes[1] = {
19330fb67e98SDaniel Drake 	{ 2, NULL },
19340fb67e98SDaniel Drake };
19350fb67e98SDaniel Drake 
1936a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_A	(1 << 0)
1937a3de8ab8STakashi Iwai #define HP_PRESENT_PORT_D	(1 << 1)
1938a3de8ab8STakashi Iwai #define hp_port_a_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_A)
1939a3de8ab8STakashi Iwai #define hp_port_d_present(spec)	((spec)->hp_present & HP_PRESENT_PORT_D)
1940a3de8ab8STakashi Iwai 
19410fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
19420fb67e98SDaniel Drake {
19430fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
19440fb67e98SDaniel Drake 	unsigned int pinctl;
19450fb67e98SDaniel Drake 
19463a253445SJohn Baboval 	snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
19473a253445SJohn Baboval 		    spec->hp_present, spec->cur_eapd);
19480fb67e98SDaniel Drake 
19490fb67e98SDaniel Drake 	/* Port A (HP) */
1950a3de8ab8STakashi Iwai 	pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
1951cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x19, pinctl);
19520fb67e98SDaniel Drake 
19530fb67e98SDaniel Drake 	/* Port D (HP/LO) */
1954a3de8ab8STakashi Iwai 	pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
1955a3de8ab8STakashi Iwai 	if (spec->dell_automute || spec->thinkpad) {
1956a3de8ab8STakashi Iwai 		/* Mute if Port A is connected */
1957a3de8ab8STakashi Iwai 		if (hp_port_a_present(spec))
19583a253445SJohn Baboval 			pinctl = 0;
19593a253445SJohn Baboval 	} else {
1960a3de8ab8STakashi Iwai 		/* Thinkpad/Dell doesn't give pin-D status */
1961a3de8ab8STakashi Iwai 		if (!hp_port_d_present(spec))
1962a3de8ab8STakashi Iwai 			pinctl = 0;
19633a253445SJohn Baboval 	}
1964cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
19650fb67e98SDaniel Drake 
19660fb67e98SDaniel Drake 	/* CLASS_D AMP */
19670fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1968cdd03cedSTakashi Iwai 	snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
19690fb67e98SDaniel Drake }
19700fb67e98SDaniel Drake 
19710fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
19720fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
19730fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
19740fb67e98SDaniel Drake {
19750fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19760fb67e98SDaniel Drake 
19770fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
19780fb67e98SDaniel Drake 		return 0;
19790fb67e98SDaniel Drake 
19800fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
19810fb67e98SDaniel Drake 	return 1;
19820fb67e98SDaniel Drake }
19830fb67e98SDaniel Drake 
198495a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
198595a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
198695a618bdSEinar Rünkaru {
198795a618bdSEinar Rünkaru 	unsigned int present;
198895a618bdSEinar Rünkaru 
198995a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
199095a618bdSEinar Rünkaru 		/* enable external mic, port B */
199175f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
199295a618bdSEinar Rünkaru 
199395a618bdSEinar Rünkaru 		/* switch to external mic input */
199495a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
199595a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
199695a618bdSEinar Rünkaru 
199795a618bdSEinar Rünkaru 		/* disable internal digital mic */
199895a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
199995a618bdSEinar Rünkaru 		{}
200095a618bdSEinar Rünkaru 	};
200134cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
200295a618bdSEinar Rünkaru 		/* enable internal mic, port C */
200395a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
200495a618bdSEinar Rünkaru 
200595a618bdSEinar Rünkaru 		/* switch to internal mic input */
200695a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
200795a618bdSEinar Rünkaru 
200895a618bdSEinar Rünkaru 		/* disable external mic, port B */
200995a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
201095a618bdSEinar Rünkaru 		{}
201195a618bdSEinar Rünkaru 	};
201295a618bdSEinar Rünkaru 
201395a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
201495a618bdSEinar Rünkaru 	if (present) {
201595a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
201695a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
201795a618bdSEinar Rünkaru 	} else {
201895a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
201995a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
202095a618bdSEinar Rünkaru 	}
202195a618bdSEinar Rünkaru }
202295a618bdSEinar Rünkaru 
2023cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2024cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2025cfd3d8dcSGreg Alexander {
2026cfd3d8dcSGreg Alexander 	unsigned int present;
2027cfd3d8dcSGreg Alexander 
2028cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2029cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2030cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2031cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2032cfd3d8dcSGreg Alexander 		{}
2033cfd3d8dcSGreg Alexander 	};
203434cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
2035cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2036cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2037cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2038cfd3d8dcSGreg Alexander 		{}
2039cfd3d8dcSGreg Alexander 	};
2040cfd3d8dcSGreg Alexander 
2041cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2042cfd3d8dcSGreg Alexander 	if (present) {
2043cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2044cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2045cfd3d8dcSGreg Alexander 	} else {
2046cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2047cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2048cfd3d8dcSGreg Alexander 	}
2049cfd3d8dcSGreg Alexander }
2050cfd3d8dcSGreg Alexander 
2051a1d6906eSDavid Henningsson 
2052a1d6906eSDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2053a1d6906eSDavid Henningsson static void cxt5066_asus_automic(struct hda_codec *codec)
2054a1d6906eSDavid Henningsson {
2055a1d6906eSDavid Henningsson 	unsigned int present;
2056a1d6906eSDavid Henningsson 
2057a1d6906eSDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2058a1d6906eSDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2059a1d6906eSDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2060a1d6906eSDavid Henningsson 			    present ? 1 : 0);
2061a1d6906eSDavid Henningsson }
2062a1d6906eSDavid Henningsson 
2063a1d6906eSDavid Henningsson 
2064048e78a5SDavid Henningsson /* toggle input of built-in digital mic and mic jack appropriately */
2065048e78a5SDavid Henningsson static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
2066048e78a5SDavid Henningsson {
2067048e78a5SDavid Henningsson 	unsigned int present;
2068048e78a5SDavid Henningsson 
2069048e78a5SDavid Henningsson 	present = snd_hda_jack_detect(codec, 0x1b);
2070048e78a5SDavid Henningsson 	snd_printdd("CXT5066: external microphone present=%d\n", present);
2071048e78a5SDavid Henningsson 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
2072048e78a5SDavid Henningsson 			    present ? 1 : 3);
2073048e78a5SDavid Henningsson }
2074048e78a5SDavid Henningsson 
2075048e78a5SDavid Henningsson 
20767b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
20777b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
20787b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
20797b2bfdbcSJens Taprogge {
20807b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
20817b2bfdbcSJens Taprogge 
208234cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_present[] = {
20837b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
20847b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
20857b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
20867b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20877b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20887b2bfdbcSJens Taprogge 		{}
20897b2bfdbcSJens Taprogge 	};
209034cbe3a6STakashi Iwai 	static const struct hda_verb dock_mic_present[] = {
20917b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
20927b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
20937b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
20947b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20957b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
20967b2bfdbcSJens Taprogge 		{}
20977b2bfdbcSJens Taprogge 	};
209834cbe3a6STakashi Iwai 	static const struct hda_verb ext_mic_absent[] = {
20997b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
21007b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
21017b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21027b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
21037b2bfdbcSJens Taprogge 		{}
21047b2bfdbcSJens Taprogge 	};
21057b2bfdbcSJens Taprogge 
21067b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
21077b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
21087b2bfdbcSJens Taprogge 	if (ext_present) {
21097b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
21107b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
21117b2bfdbcSJens Taprogge 	} else if (dock_present) {
21127b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
21137b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
21147b2bfdbcSJens Taprogge 	} else {
21157b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
21167b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
21177b2bfdbcSJens Taprogge 	}
21187b2bfdbcSJens Taprogge }
21197b2bfdbcSJens Taprogge 
21200fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
21210fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
21220fb67e98SDaniel Drake {
21230fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
21240fb67e98SDaniel Drake 	unsigned int portA, portD;
21250fb67e98SDaniel Drake 
21260fb67e98SDaniel Drake 	/* Port A */
2127d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
21280fb67e98SDaniel Drake 
21290fb67e98SDaniel Drake 	/* Port D */
2130d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
21310fb67e98SDaniel Drake 
2132a3de8ab8STakashi Iwai 	spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
2133a3de8ab8STakashi Iwai 	spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
21340fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
21350fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
21360fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21370fb67e98SDaniel Drake }
21380fb67e98SDaniel Drake 
213902b6b5b6SDavid Henningsson /* Dispatch the right mic autoswitch function */
214002b6b5b6SDavid Henningsson static void cxt5066_automic(struct hda_codec *codec)
214102b6b5b6SDavid Henningsson {
214202b6b5b6SDavid Henningsson 	struct conexant_spec *spec = codec->spec;
214302b6b5b6SDavid Henningsson 
214402b6b5b6SDavid Henningsson 	if (spec->dell_vostro)
214502b6b5b6SDavid Henningsson 		cxt5066_vostro_automic(codec);
214602b6b5b6SDavid Henningsson 	else if (spec->ideapad)
214702b6b5b6SDavid Henningsson 		cxt5066_ideapad_automic(codec);
214802b6b5b6SDavid Henningsson 	else if (spec->thinkpad)
214902b6b5b6SDavid Henningsson 		cxt5066_thinkpad_automic(codec);
215002b6b5b6SDavid Henningsson 	else if (spec->hp_laptop)
215102b6b5b6SDavid Henningsson 		cxt5066_hp_laptop_automic(codec);
2152a1d6906eSDavid Henningsson 	else if (spec->asus)
2153a1d6906eSDavid Henningsson 		cxt5066_asus_automic(codec);
215402b6b5b6SDavid Henningsson }
215502b6b5b6SDavid Henningsson 
21560fb67e98SDaniel Drake /* unsolicited event for jack sensing */
215702b6b5b6SDavid Henningsson static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
215895a618bdSEinar Rünkaru {
215902b6b5b6SDavid Henningsson 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
216095a618bdSEinar Rünkaru 	switch (res >> 26) {
216195a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
216295a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
216395a618bdSEinar Rünkaru 		break;
216495a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
216502b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
216695a618bdSEinar Rünkaru 		break;
216795a618bdSEinar Rünkaru 	}
216895a618bdSEinar Rünkaru }
216995a618bdSEinar Rünkaru 
21707b2bfdbcSJens Taprogge 
21710fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
21720fb67e98SDaniel Drake 	.num_items = 5,
21730fb67e98SDaniel Drake 	.items = {
21740fb67e98SDaniel Drake 		{ "0dB",  0 },
21750fb67e98SDaniel Drake 		{ "10dB", 1 },
21760fb67e98SDaniel Drake 		{ "20dB", 2 },
21770fb67e98SDaniel Drake 		{ "30dB", 3 },
21780fb67e98SDaniel Drake 		{ "40dB", 4 },
21790fb67e98SDaniel Drake 	},
21800fb67e98SDaniel Drake };
21810fb67e98SDaniel Drake 
2182cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2183c4cfe66cSDaniel Drake {
2184c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2185cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2186c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2187c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2188c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
21897b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2190cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2191cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2192cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2193cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2194cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2195cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2196cfd3d8dcSGreg Alexander 	}
2197c4cfe66cSDaniel Drake }
2198c4cfe66cSDaniel Drake 
21990fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
22000fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
22010fb67e98SDaniel Drake {
22020fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
22030fb67e98SDaniel Drake }
22040fb67e98SDaniel Drake 
22050fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
22060fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
22070fb67e98SDaniel Drake {
22080fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2209c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2210c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
22110fb67e98SDaniel Drake 	return 0;
22120fb67e98SDaniel Drake }
22130fb67e98SDaniel Drake 
22140fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
22150fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
22160fb67e98SDaniel Drake {
22170fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2218c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22190fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
22200fb67e98SDaniel Drake 	unsigned int idx;
22210fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
22220fb67e98SDaniel Drake 	if (idx >= imux->num_items)
22230fb67e98SDaniel Drake 		idx = imux->num_items - 1;
22240fb67e98SDaniel Drake 
2225c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2226c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2227c4cfe66cSDaniel Drake 	return 1;
2228c4cfe66cSDaniel Drake }
22290fb67e98SDaniel Drake 
2230f6a2491cSAndy Robinson static void conexant_check_dig_outs(struct hda_codec *codec,
223134cbe3a6STakashi Iwai 				    const hda_nid_t *dig_pins,
2232f6a2491cSAndy Robinson 				    int num_pins)
2233f6a2491cSAndy Robinson {
2234f6a2491cSAndy Robinson 	struct conexant_spec *spec = codec->spec;
2235f6a2491cSAndy Robinson 	hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
2236f6a2491cSAndy Robinson 	int i;
2237f6a2491cSAndy Robinson 
2238f6a2491cSAndy Robinson 	for (i = 0; i < num_pins; i++, dig_pins++) {
2239f6a2491cSAndy Robinson 		unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
2240f6a2491cSAndy Robinson 		if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
2241f6a2491cSAndy Robinson 			continue;
2242f6a2491cSAndy Robinson 		if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
2243f6a2491cSAndy Robinson 			continue;
2244f6a2491cSAndy Robinson 	}
2245f6a2491cSAndy Robinson }
2246f6a2491cSAndy Robinson 
224734cbe3a6STakashi Iwai static const struct hda_input_mux cxt5066_capture_source = {
22480fb67e98SDaniel Drake 	.num_items = 4,
22490fb67e98SDaniel Drake 	.items = {
22500fb67e98SDaniel Drake 		{ "Mic B", 0 },
22510fb67e98SDaniel Drake 		{ "Mic C", 1 },
22520fb67e98SDaniel Drake 		{ "Mic E", 2 },
22530fb67e98SDaniel Drake 		{ "Mic F", 3 },
22540fb67e98SDaniel Drake 	},
22550fb67e98SDaniel Drake };
22560fb67e98SDaniel Drake 
225734cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
22580fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
22590fb67e98SDaniel Drake 	.values = {
22600fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
22610fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
22620fb67e98SDaniel Drake 		0
22630fb67e98SDaniel Drake 	},
22640fb67e98SDaniel Drake };
22650fb67e98SDaniel Drake 
226634cbe3a6STakashi Iwai static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
22670fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
22680fb67e98SDaniel Drake 	.values = {
22690fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
22700fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
22710fb67e98SDaniel Drake 		0
22720fb67e98SDaniel Drake 	},
22730fb67e98SDaniel Drake };
22740fb67e98SDaniel Drake 
227534cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
22760fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
22770fb67e98SDaniel Drake 	{}
22780fb67e98SDaniel Drake };
22790fb67e98SDaniel Drake 
228034cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_mixers[] = {
22810fb67e98SDaniel Drake 	{
22820fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
22830fb67e98SDaniel Drake 		.name = "Master Playback Switch",
22840fb67e98SDaniel Drake 		.info = cxt_eapd_info,
22850fb67e98SDaniel Drake 		.get = cxt_eapd_get,
22860fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
22870fb67e98SDaniel Drake 		.private_value = 0x1d,
22880fb67e98SDaniel Drake 	},
22890fb67e98SDaniel Drake 
22900fb67e98SDaniel Drake 	{
22910fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2292c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
22930fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
22940fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
22950fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
22960fb67e98SDaniel Drake 	},
22970fb67e98SDaniel Drake 
22980fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
22990fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
23000fb67e98SDaniel Drake 	{}
23010fb67e98SDaniel Drake };
23020fb67e98SDaniel Drake 
230334cbe3a6STakashi Iwai static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2304254bba6aSEinar Rünkaru 	{
2305254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
230628c4edb7SDavid Henningsson 		.name = "Internal Mic Boost Capture Enum",
2307254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2308254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2309254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2310254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2311254bba6aSEinar Rünkaru 	},
2312254bba6aSEinar Rünkaru 	{}
2313254bba6aSEinar Rünkaru };
2314254bba6aSEinar Rünkaru 
231534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs[] = {
23160fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
23170fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
23180fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
23190fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
23200fb67e98SDaniel Drake 
23210fb67e98SDaniel Drake 	/* Speakers  */
23220fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23230fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23240fb67e98SDaniel Drake 
23250fb67e98SDaniel Drake 	/* HP, Amp  */
23260fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23270fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23280fb67e98SDaniel Drake 
23290fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
23300fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23310fb67e98SDaniel Drake 
23320fb67e98SDaniel Drake 	/* DAC1 */
23330fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
23340fb67e98SDaniel Drake 
23350fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
23360fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
23370fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
23380fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
23390fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
23400fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
23410fb67e98SDaniel Drake 
23420fb67e98SDaniel Drake 	/* no digital microphone support yet */
23430fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23440fb67e98SDaniel Drake 
23450fb67e98SDaniel Drake 	/* Audio input selector */
23460fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
23470fb67e98SDaniel Drake 
23480fb67e98SDaniel Drake 	/* SPDIF route: PCM */
23490fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
23500fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
23510fb67e98SDaniel Drake 
23520fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23530fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23540fb67e98SDaniel Drake 
23550fb67e98SDaniel Drake 	/* EAPD */
23560fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
23570fb67e98SDaniel Drake 
23580fb67e98SDaniel Drake 	/* not handling these yet */
23590fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23600fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23610fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23620fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23630fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23640fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23650fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23660fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
23670fb67e98SDaniel Drake 	{ } /* end */
23680fb67e98SDaniel Drake };
23690fb67e98SDaniel Drake 
237034cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_vostro[] = {
237195a618bdSEinar Rünkaru 	/* Port A: headphones */
237295a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237395a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
237495a618bdSEinar Rünkaru 
237595a618bdSEinar Rünkaru 	/* Port B: external microphone */
237695a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237795a618bdSEinar Rünkaru 
237895a618bdSEinar Rünkaru 	/* Port C: unused */
237995a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
238095a618bdSEinar Rünkaru 
238195a618bdSEinar Rünkaru 	/* Port D: unused */
238295a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
238395a618bdSEinar Rünkaru 
238495a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
238595a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
238695a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
238795a618bdSEinar Rünkaru 
238895a618bdSEinar Rünkaru 	/* Port F: unused */
238995a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
239095a618bdSEinar Rünkaru 
239195a618bdSEinar Rünkaru 	/* Port G: internal speakers */
239295a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
239395a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
239495a618bdSEinar Rünkaru 
239595a618bdSEinar Rünkaru 	/* DAC1 */
239695a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
239795a618bdSEinar Rünkaru 
239895a618bdSEinar Rünkaru 	/* DAC2: unused */
239995a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
240095a618bdSEinar Rünkaru 
240195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
240295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
240395a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
240495a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
240595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
240695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
240795a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
240895a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
240995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
241095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
241195a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
241295a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
241395a618bdSEinar Rünkaru 
241495a618bdSEinar Rünkaru 	/* Digital microphone port */
241595a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
241695a618bdSEinar Rünkaru 
241795a618bdSEinar Rünkaru 	/* Audio input selectors */
241895a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
241995a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
242095a618bdSEinar Rünkaru 
242195a618bdSEinar Rünkaru 	/* Disable SPDIF */
242295a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
242395a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
242495a618bdSEinar Rünkaru 
242595a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
242695a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
242795a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
242895a618bdSEinar Rünkaru 	{ } /* end */
242995a618bdSEinar Rünkaru };
243095a618bdSEinar Rünkaru 
243134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
2432cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2433cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2434cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2435cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2436cfd3d8dcSGreg Alexander 
2437cfd3d8dcSGreg Alexander 	/* Speakers  */
2438cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2439cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2440cfd3d8dcSGreg Alexander 
2441cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2442cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2443cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2444cfd3d8dcSGreg Alexander 
2445cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2446cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2447cfd3d8dcSGreg Alexander 
2448cfd3d8dcSGreg Alexander 	/* DAC1 */
2449cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2450cfd3d8dcSGreg Alexander 
2451cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2452cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2453cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2454cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2455cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2456cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2457cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2458cfd3d8dcSGreg Alexander 
2459cfd3d8dcSGreg Alexander 	/* Audio input selector */
2460cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2461cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2462cfd3d8dcSGreg Alexander 
2463cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2464cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2465cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2466cfd3d8dcSGreg Alexander 
2467cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2468cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2469cfd3d8dcSGreg Alexander 
2470cfd3d8dcSGreg Alexander 	/* internal microphone */
247128c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
2472cfd3d8dcSGreg Alexander 
2473cfd3d8dcSGreg Alexander 	/* EAPD */
2474cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2475cfd3d8dcSGreg Alexander 
2476cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2477cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2478cfd3d8dcSGreg Alexander 	{ } /* end */
2479cfd3d8dcSGreg Alexander };
2480cfd3d8dcSGreg Alexander 
248134cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
24827b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
24837b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
24847b2bfdbcSJens Taprogge 
24857b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
24867b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
24877b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
24887b2bfdbcSJens Taprogge 
24897b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
24907b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24917b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
24927b2bfdbcSJens Taprogge 
24937b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
24947b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24957b2bfdbcSJens Taprogge 
24967b2bfdbcSJens Taprogge 	/* Port C: Mic */
24977b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
24987b2bfdbcSJens Taprogge 
24997b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
25007b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
25017b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
25027b2bfdbcSJens Taprogge 
25037b2bfdbcSJens Taprogge 	/* DAC1 */
25047b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
25057b2bfdbcSJens Taprogge 
25067b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
25077b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
25087b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
25097b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
25107b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
25117b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
25127b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
25137b2bfdbcSJens Taprogge 
25147b2bfdbcSJens Taprogge 	/* Audio input selector */
25157b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
25167b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
25177b2bfdbcSJens Taprogge 
25187b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
25197b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
25207b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
25217b2bfdbcSJens Taprogge 
25227b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25237b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25247b2bfdbcSJens Taprogge 
25257b2bfdbcSJens Taprogge 	/* internal microphone */
252628c4edb7SDavid Henningsson 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
25277b2bfdbcSJens Taprogge 
25287b2bfdbcSJens Taprogge 	/* EAPD */
25297b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
25307b2bfdbcSJens Taprogge 
25317b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
25327b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
25337b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
25347b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
25357b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
25367b2bfdbcSJens Taprogge 	{ } /* end */
25377b2bfdbcSJens Taprogge };
25387b2bfdbcSJens Taprogge 
253934cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
25400fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
25410fb67e98SDaniel Drake 	{ } /* end */
25420fb67e98SDaniel Drake };
25430fb67e98SDaniel Drake 
2544048e78a5SDavid Henningsson 
254534cbe3a6STakashi Iwai static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
2546048e78a5SDavid Henningsson 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
2547048e78a5SDavid Henningsson 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2548048e78a5SDavid Henningsson 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2549048e78a5SDavid Henningsson 	{ } /* end */
2550048e78a5SDavid Henningsson };
2551048e78a5SDavid Henningsson 
25520fb67e98SDaniel Drake /* initialize jack-sensing, too */
25530fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
25540fb67e98SDaniel Drake {
25550fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
25560fb67e98SDaniel Drake 	conexant_init(codec);
25570fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
25580fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
255902b6b5b6SDavid Henningsson 		cxt5066_automic(codec);
25600fb67e98SDaniel Drake 	}
2561c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
25620fb67e98SDaniel Drake 	return 0;
25630fb67e98SDaniel Drake }
25640fb67e98SDaniel Drake 
25650fb67e98SDaniel Drake enum {
25660fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
25670fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
25681feba3b7SDavid Henningsson 	CXT5066_DELL_VOSTRO,	/* Dell Vostro 1015i */
2569cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
25707b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
2571a1d6906eSDavid Henningsson 	CXT5066_ASUS,		/* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
2572048e78a5SDavid Henningsson 	CXT5066_HP_LAPTOP,      /* HP Laptop */
2573fea4a4f9STakashi Iwai 	CXT5066_AUTO,		/* BIOS auto-parser */
25740fb67e98SDaniel Drake 	CXT5066_MODELS
25750fb67e98SDaniel Drake };
25760fb67e98SDaniel Drake 
2577ea734963STakashi Iwai static const char * const cxt5066_models[CXT5066_MODELS] = {
25780fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
25790fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
25801feba3b7SDavid Henningsson 	[CXT5066_DELL_VOSTRO]	= "dell-vostro",
2581cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
25827b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
2583a1d6906eSDavid Henningsson 	[CXT5066_ASUS]		= "asus",
2584048e78a5SDavid Henningsson 	[CXT5066_HP_LAPTOP]	= "hp-laptop",
2585fea4a4f9STakashi Iwai 	[CXT5066_AUTO]		= "auto",
25860fb67e98SDaniel Drake };
25870fb67e98SDaniel Drake 
258834cbe3a6STakashi Iwai static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
258900cd0bb7STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
25901feba3b7SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
25918a96b1e0SDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
2592ca6cd851SDaniel T Chen 	SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
2593231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2594ebbd224cSDavid Henningsson 	SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
2595048e78a5SDavid Henningsson 	SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
2596f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
2597a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
2598f6a2491cSAndy Robinson 	SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
25992ca9cac9SAnisse Astier 	SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
26005637edb2SDavid Henningsson 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
26015637edb2SDavid Henningsson 		      CXT5066_LAPTOP),
26024d155641STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
2603ef61d4e6SManoj Iyer 	SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
260419593875SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
2605d2859fd4SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
2606a1d6906eSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
26070fb67e98SDaniel Drake 	{}
26080fb67e98SDaniel Drake };
26090fb67e98SDaniel Drake 
26100fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
26110fb67e98SDaniel Drake {
26120fb67e98SDaniel Drake 	struct conexant_spec *spec;
26130fb67e98SDaniel Drake 	int board_config;
26140fb67e98SDaniel Drake 
2615fea4a4f9STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
2616fea4a4f9STakashi Iwai 						  cxt5066_models, cxt5066_cfg_tbl);
2617fea4a4f9STakashi Iwai 	if (board_config < 0)
2618c82693dbSTakashi Iwai 		board_config = CXT5066_AUTO; /* model=auto as default */
2619fea4a4f9STakashi Iwai 	if (board_config == CXT5066_AUTO)
2620fea4a4f9STakashi Iwai 		return patch_conexant_auto(codec);
2621fea4a4f9STakashi Iwai 
26220fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
26230fb67e98SDaniel Drake 	if (!spec)
26240fb67e98SDaniel Drake 		return -ENOMEM;
26250fb67e98SDaniel Drake 	codec->spec = spec;
26260fb67e98SDaniel Drake 
26270fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
262875f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
26290fb67e98SDaniel Drake 
26300fb67e98SDaniel Drake 	spec->dell_automute = 0;
26310fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
26320fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
26330fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
2634f6a2491cSAndy Robinson 	conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
2635f6a2491cSAndy Robinson 	    ARRAY_SIZE(cxt5066_digout_pin_nids));
26360fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
26370fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
26380fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
26390fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
26400fb67e98SDaniel Drake 
26410fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
26420fb67e98SDaniel Drake 
26430fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
26440fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
26450fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
26460fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
26470fb67e98SDaniel Drake 	spec->cur_adc = 0;
26480fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
26490fb67e98SDaniel Drake 
26503507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
26513507e2a8STakashi Iwai 
26520fb67e98SDaniel Drake 	switch (board_config) {
26530fb67e98SDaniel Drake 	default:
26540fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
26550fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
26560fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
26570fb67e98SDaniel Drake 		break;
26580fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
26590fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
26600fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
26610fb67e98SDaniel Drake 
26620fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
26630fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
26640fb67e98SDaniel Drake 		spec->num_init_verbs++;
26650fb67e98SDaniel Drake 		spec->dell_automute = 1;
26660fb67e98SDaniel Drake 		break;
2667a1d6906eSDavid Henningsson 	case CXT5066_ASUS:
2668048e78a5SDavid Henningsson 	case CXT5066_HP_LAPTOP:
2669048e78a5SDavid Henningsson 		codec->patch_ops.init = cxt5066_init;
267002b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2671048e78a5SDavid Henningsson 		spec->init_verbs[spec->num_init_verbs] =
2672048e78a5SDavid Henningsson 			cxt5066_init_verbs_hp_laptop;
2673048e78a5SDavid Henningsson 		spec->num_init_verbs++;
2674a1d6906eSDavid Henningsson 		spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
2675a1d6906eSDavid Henningsson 		spec->asus = board_config == CXT5066_ASUS;
2676048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2677048e78a5SDavid Henningsson 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2678048e78a5SDavid Henningsson 		/* no S/PDIF out */
2679f6a2491cSAndy Robinson 		if (board_config == CXT5066_HP_LAPTOP)
2680048e78a5SDavid Henningsson 			spec->multiout.dig_out_nid = 0;
2681048e78a5SDavid Henningsson 		/* input source automatically selected */
2682048e78a5SDavid Henningsson 		spec->input_mux = NULL;
2683048e78a5SDavid Henningsson 		spec->port_d_mode = 0;
2684048e78a5SDavid Henningsson 		spec->mic_boost = 3; /* default 30dB gain */
2685048e78a5SDavid Henningsson 		break;
2686048e78a5SDavid Henningsson 
26871feba3b7SDavid Henningsson 	case CXT5066_DELL_VOSTRO:
268875f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
268902b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
269095a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
26913a00c660STakashi Iwai 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
269295a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2693254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
269495a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
2695254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
2696c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
269795a618bdSEinar Rünkaru 
269895a618bdSEinar Rünkaru 		/* no S/PDIF out */
269995a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
270095a618bdSEinar Rünkaru 
270195a618bdSEinar Rünkaru 		/* input source automatically selected */
270295a618bdSEinar Rünkaru 		spec->input_mux = NULL;
270395a618bdSEinar Rünkaru 		break;
2704cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
2705cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
270602b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
2707cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
2708cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2709cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
2710cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
2711cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
2712cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
2713cfd3d8dcSGreg Alexander 
2714cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
2715cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
2716cfd3d8dcSGreg Alexander 
2717cfd3d8dcSGreg Alexander 		/* input source automatically selected */
2718cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
2719cfd3d8dcSGreg Alexander 		break;
27207b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
27217b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
272202b6b5b6SDavid Henningsson 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
27237b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
27247b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
27257b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
27267b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
27277b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
27287b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
27297b2bfdbcSJens Taprogge 
27307b2bfdbcSJens Taprogge 		/* no S/PDIF out */
27317b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
27327b2bfdbcSJens Taprogge 
27337b2bfdbcSJens Taprogge 		/* input source automatically selected */
27347b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
27357b2bfdbcSJens Taprogge 		break;
27360fb67e98SDaniel Drake 	}
27370fb67e98SDaniel Drake 
27383507e2a8STakashi Iwai 	if (spec->beep_amp)
2739a86b1a2cSTakashi Iwai 		snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
27403507e2a8STakashi Iwai 
27410fb67e98SDaniel Drake 	return 0;
27420fb67e98SDaniel Drake }
2743461e2c78STakashi Iwai 
2744bf92d1d5STakashi Iwai #endif /* ENABLE_CXT_STATIC_QUIRKS */
2745bf92d1d5STakashi Iwai 
2746bf92d1d5STakashi Iwai 
2747461e2c78STakashi Iwai /*
2748f2e5731dSTakashi Iwai  * Automatic parser for CX20641 & co
2749f2e5731dSTakashi Iwai  */
2750f2e5731dSTakashi Iwai 
2751f2e5731dSTakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
2752f2e5731dSTakashi Iwai static void cx_auto_parse_beep(struct hda_codec *codec)
2753f2e5731dSTakashi Iwai {
2754f2e5731dSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
2755f2e5731dSTakashi Iwai 	hda_nid_t nid, end_nid;
2756f2e5731dSTakashi Iwai 
2757f2e5731dSTakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
2758f2e5731dSTakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++)
2759f2e5731dSTakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
2760f2e5731dSTakashi Iwai 			set_beep_amp(spec, nid, 0, HDA_OUTPUT);
2761f2e5731dSTakashi Iwai 			break;
2762f2e5731dSTakashi Iwai 		}
2763f2e5731dSTakashi Iwai }
2764f2e5731dSTakashi Iwai #else
2765f2e5731dSTakashi Iwai #define cx_auto_parse_beep(codec)
2766f2e5731dSTakashi Iwai #endif
2767f2e5731dSTakashi Iwai 
2768254f2968STakashi Iwai /* parse EAPDs */
276919110595STakashi Iwai static void cx_auto_parse_eapd(struct hda_codec *codec)
277019110595STakashi Iwai {
277119110595STakashi Iwai 	struct conexant_spec *spec = codec->spec;
277219110595STakashi Iwai 	hda_nid_t nid, end_nid;
277319110595STakashi Iwai 
277419110595STakashi Iwai 	end_nid = codec->start_nid + codec->num_nodes;
277519110595STakashi Iwai 	for (nid = codec->start_nid; nid < end_nid; nid++) {
277619110595STakashi Iwai 		if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
277719110595STakashi Iwai 			continue;
277819110595STakashi Iwai 		if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
277919110595STakashi Iwai 			continue;
278019110595STakashi Iwai 		spec->eapds[spec->num_eapds++] = nid;
278119110595STakashi Iwai 		if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
278219110595STakashi Iwai 			break;
278319110595STakashi Iwai 	}
2784254f2968STakashi Iwai 
2785254f2968STakashi Iwai 	/* NOTE: below is a wild guess; if we have more than two EAPDs,
2786254f2968STakashi Iwai 	 * it's a new chip, where EAPDs are supposed to be associated to
2787254f2968STakashi Iwai 	 * pins, and we can control EAPD per pin.
2788254f2968STakashi Iwai 	 * OTOH, if only one or two EAPDs are found, it's an old chip,
2789254f2968STakashi Iwai 	 * thus it might control over all pins.
2790254f2968STakashi Iwai 	 */
2791aed523f1STakashi Iwai 	if (spec->num_eapds > 2)
2792ff359b14STakashi Iwai 		spec->dynamic_eapd = 1;
2793f2e5731dSTakashi Iwai }
2794f2e5731dSTakashi Iwai 
2795da339866STakashi Iwai static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
2796da339866STakashi Iwai 			      hda_nid_t *pins, bool on)
2797f2e5731dSTakashi Iwai {
2798f2e5731dSTakashi Iwai 	int i;
2799f2e5731dSTakashi Iwai 	for (i = 0; i < num_pins; i++) {
2800f2e5731dSTakashi Iwai 		if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
2801f2e5731dSTakashi Iwai 			snd_hda_codec_write(codec, pins[i], 0,
2802da339866STakashi Iwai 					    AC_VERB_SET_EAPD_BTLENABLE,
2803da339866STakashi Iwai 					    on ? 0x02 : 0);
2804f2e5731dSTakashi Iwai 	}
2805f2e5731dSTakashi Iwai }
2806f2e5731dSTakashi Iwai 
2807527c73baSTakashi Iwai /* turn on/off EAPD according to Master switch */
2808527c73baSTakashi Iwai static void cx_auto_vmaster_hook(void *private_data, int enabled)
2809527c73baSTakashi Iwai {
2810527c73baSTakashi Iwai 	struct hda_codec *codec = private_data;
2811527c73baSTakashi Iwai 	struct conexant_spec *spec = codec->spec;
2812527c73baSTakashi Iwai 
2813527c73baSTakashi Iwai 	cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
2814527c73baSTakashi Iwai }
2815527c73baSTakashi Iwai 
2816f2e5731dSTakashi Iwai static int cx_auto_build_controls(struct hda_codec *codec)
2817f2e5731dSTakashi Iwai {
2818f2e5731dSTakashi Iwai 	int err;
2819f2e5731dSTakashi Iwai 
2820aed523f1STakashi Iwai 	err = snd_hda_gen_build_controls(codec);
2821f2e5731dSTakashi Iwai 	if (err < 0)
2822f2e5731dSTakashi Iwai 		return err;
2823f2e5731dSTakashi Iwai 
2824aed523f1STakashi Iwai 	err = add_beep_ctls(codec);
2825aed523f1STakashi Iwai 	if (err < 0)
2826aed523f1STakashi Iwai 		return err;
282722ce5f74STakashi Iwai 
282822ce5f74STakashi Iwai 	return 0;
282922ce5f74STakashi Iwai }
283022ce5f74STakashi Iwai 
2831ff359b14STakashi Iwai static int cx_auto_init(struct hda_codec *codec)
2832ff359b14STakashi Iwai {
2833ff359b14STakashi Iwai 	struct conexant_spec *spec = codec->spec;
2834ff359b14STakashi Iwai 	snd_hda_gen_init(codec);
2835ff359b14STakashi Iwai 	if (!spec->dynamic_eapd)
2836ff359b14STakashi Iwai 		cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
2837e4c3bce2SDavid Henningsson 
2838e4c3bce2SDavid Henningsson 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
2839e4c3bce2SDavid Henningsson 
2840ff359b14STakashi Iwai 	return 0;
2841ff359b14STakashi Iwai }
2842ff359b14STakashi Iwai 
284308cf680cSDavid Henningsson static void cx_auto_free(struct hda_codec *codec)
284408cf680cSDavid Henningsson {
284508cf680cSDavid Henningsson 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_FREE);
284608cf680cSDavid Henningsson 	snd_hda_gen_free(codec);
284708cf680cSDavid Henningsson }
284808cf680cSDavid Henningsson 
284934cbe3a6STakashi Iwai static const struct hda_codec_ops cx_auto_patch_ops = {
2850f2e5731dSTakashi Iwai 	.build_controls = cx_auto_build_controls,
2851aed523f1STakashi Iwai 	.build_pcms = snd_hda_gen_build_pcms,
2852ff359b14STakashi Iwai 	.init = cx_auto_init,
285308cf680cSDavid Henningsson 	.free = cx_auto_free,
285429adc4b9SDavid Henningsson 	.unsol_event = snd_hda_jack_unsol_event,
2855164a7adaSTakashi Iwai #ifdef CONFIG_PM
2856164a7adaSTakashi Iwai 	.check_power_status = snd_hda_gen_check_power_status,
2857164a7adaSTakashi Iwai #endif
2858f2e5731dSTakashi Iwai };
2859f2e5731dSTakashi Iwai 
2860e92d4b08STakashi Iwai /*
2861e92d4b08STakashi Iwai  * pin fix-up
2862e92d4b08STakashi Iwai  */
286318dcd304SDavid Henningsson enum {
286418dcd304SDavid Henningsson 	CXT_PINCFG_LENOVO_X200,
2865d3980110STakashi Iwai 	CXT_PINCFG_LENOVO_TP410,
2866239fb862SHuacai Chen 	CXT_PINCFG_LEMOTE_A1004,
2867239fb862SHuacai Chen 	CXT_PINCFG_LEMOTE_A1205,
286818dcd304SDavid Henningsson 	CXT_FIXUP_STEREO_DMIC,
2869239fb862SHuacai Chen 	CXT_FIXUP_INC_MIC_BOOST,
2870e4c3bce2SDavid Henningsson 	CXT_FIXUP_HEADPHONE_MIC_PIN,
2871e4c3bce2SDavid Henningsson 	CXT_FIXUP_HEADPHONE_MIC,
28724a437044STakashi Iwai 	CXT_FIXUP_GPIO1,
287308cf680cSDavid Henningsson 	CXT_FIXUP_THINKPAD_ACPI,
28743a00c660STakashi Iwai 	CXT_FIXUP_OLPC_XO,
2875*ad7725d3STakashi Iwai 	CXT_FIXUP_CAP_MIX_AMP,
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 
3208*ad7725d3STakashi Iwai /*
3209*ad7725d3STakashi Iwai  * Fix max input level on mixer widget to 0dB
3210*ad7725d3STakashi Iwai  * (originally it has 0x2b steps with 0dB offset 0x14)
3211*ad7725d3STakashi Iwai  */
3212*ad7725d3STakashi Iwai static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
3213*ad7725d3STakashi Iwai 				  const struct hda_fixup *fix, int action)
3214*ad7725d3STakashi Iwai {
3215*ad7725d3STakashi Iwai 	snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
3216*ad7725d3STakashi Iwai 				  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
3217*ad7725d3STakashi Iwai 				  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3218*ad7725d3STakashi Iwai 				  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3219*ad7725d3STakashi Iwai 				  (1 << AC_AMPCAP_MUTE_SHIFT));
3220*ad7725d3STakashi 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 	},
3310*ad7725d3STakashi Iwai 	[CXT_FIXUP_CAP_MIX_AMP] = {
3311*ad7725d3STakashi Iwai 		.type = HDA_FIXUP_FUNC,
3312*ad7725d3STakashi Iwai 		.v.func = cxt_fixup_cap_mix_amp,
3313*ad7725d3STakashi Iwai 	},
3314*ad7725d3STakashi Iwai };
3315*ad7725d3STakashi Iwai 
3316*ad7725d3STakashi Iwai static const struct snd_pci_quirk cxt5045_fixups[] = {
3317*ad7725d3STakashi Iwai 	/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
3318*ad7725d3STakashi Iwai 	 * really bad sound over 0dB on NID 0x17.
3319*ad7725d3STakashi Iwai 	 */
3320*ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
3321*ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
3322*ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
3323*ad7725d3STakashi Iwai 	SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
3324*ad7725d3STakashi Iwai 	{}
3325*ad7725d3STakashi Iwai };
3326*ad7725d3STakashi Iwai 
3327*ad7725d3STakashi Iwai static const struct hda_model_fixup cxt5045_fixup_models[] = {
3328*ad7725d3STakashi Iwai 	{ .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
3329*ad7725d3STakashi Iwai 	{}
3330e92d4b08STakashi Iwai };
3331e92d4b08STakashi Iwai 
3332d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5051_fixups[] = {
3333e92d4b08STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
3334e92d4b08STakashi Iwai 	{}
3335e92d4b08STakashi Iwai };
3336e92d4b08STakashi Iwai 
3337a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5051_fixup_models[] = {
3338a2dd933dSTakashi Iwai 	{ .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
3339a2dd933dSTakashi Iwai 	{}
3340a2dd933dSTakashi Iwai };
3341a2dd933dSTakashi Iwai 
3342d70f3632STakashi Iwai static const struct snd_pci_quirk cxt5066_fixups[] = {
334363a077e2STakashi Iwai 	SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
33444a437044STakashi Iwai 	SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
3345e4c3bce2SDavid Henningsson 	SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
33463a00c660STakashi Iwai 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
3347d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
3348d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
3349d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
3350d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
3351d70f3632STakashi Iwai 	SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
3352a555bb8cSDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
335388d57606SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
335418dcd304SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
3355e4db0952SFelix Kaechele 	SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
3356b3c5dce8SDavid Henningsson 	SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
33572fd3f170SHui Wang 	SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
3358239fb862SHuacai Chen 	SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
3359239fb862SHuacai Chen 	SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
3360f2e5731dSTakashi Iwai 	{}
3361f2e5731dSTakashi Iwai };
3362f2e5731dSTakashi Iwai 
3363a2dd933dSTakashi Iwai static const struct hda_model_fixup cxt5066_fixup_models[] = {
3364a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
3365a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
3366a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
3367a2dd933dSTakashi Iwai 	{ .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
3368a2dd933dSTakashi Iwai 	{ .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
3369a2dd933dSTakashi Iwai 	{ .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
33703a00c660STakashi Iwai 	{ .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
3371a2dd933dSTakashi Iwai 	{}
3372a2dd933dSTakashi Iwai };
3373a2dd933dSTakashi Iwai 
33743868137eSTakashi Iwai /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
33753868137eSTakashi Iwai  * can be created (bko#42825)
33763868137eSTakashi Iwai  */
33773868137eSTakashi Iwai static void add_cx5051_fake_mutes(struct hda_codec *codec)
33783868137eSTakashi Iwai {
33793868137eSTakashi Iwai 	static hda_nid_t out_nids[] = {
33803868137eSTakashi Iwai 		0x10, 0x11, 0
33813868137eSTakashi Iwai 	};
33823868137eSTakashi Iwai 	hda_nid_t *p;
33833868137eSTakashi Iwai 
33843868137eSTakashi Iwai 	for (p = out_nids; *p; p++)
33853868137eSTakashi Iwai 		snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
33863868137eSTakashi Iwai 					  AC_AMPCAP_MIN_MUTE |
33873868137eSTakashi Iwai 					  query_amp_caps(codec, *p, HDA_OUTPUT));
33883868137eSTakashi Iwai }
33893868137eSTakashi Iwai 
3390f2e5731dSTakashi Iwai static int patch_conexant_auto(struct hda_codec *codec)
3391f2e5731dSTakashi Iwai {
3392f2e5731dSTakashi Iwai 	struct conexant_spec *spec;
3393f2e5731dSTakashi Iwai 	int err;
3394f2e5731dSTakashi Iwai 
33951f8458a2STakashi Iwai 	printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
33961f8458a2STakashi Iwai 	       codec->chip_name);
33971f8458a2STakashi Iwai 
3398f2e5731dSTakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3399f2e5731dSTakashi Iwai 	if (!spec)
3400f2e5731dSTakashi Iwai 		return -ENOMEM;
3401aed523f1STakashi Iwai 	snd_hda_gen_spec_init(&spec->gen);
3402f2e5731dSTakashi Iwai 	codec->spec = spec;
3403e92d4b08STakashi Iwai 
3404aed523f1STakashi Iwai 	cx_auto_parse_beep(codec);
3405aed523f1STakashi Iwai 	cx_auto_parse_eapd(codec);
3406ff359b14STakashi Iwai 	spec->gen.own_eapd_ctl = 1;
3407ff359b14STakashi Iwai 	if (spec->dynamic_eapd)
3408aed523f1STakashi Iwai 		spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
3409e92d4b08STakashi Iwai 
34106b452142STakashi Iwai 	switch (codec->vendor_id) {
34116b452142STakashi Iwai 	case 0x14f15045:
34124f32456eSMichael Karcher 		codec->single_adc_amp = 1;
3413*ad7725d3STakashi Iwai 		snd_hda_pick_fixup(codec, cxt5045_fixup_models,
3414*ad7725d3STakashi Iwai 				   cxt5045_fixups, cxt_fixups);
34156b452142STakashi Iwai 		break;
3416164a7adaSTakashi Iwai 	case 0x14f15047:
3417164a7adaSTakashi Iwai 		codec->pin_amp_workaround = 1;
3418164a7adaSTakashi Iwai 		spec->gen.mixer_nid = 0x19;
3419164a7adaSTakashi Iwai 		break;
34203868137eSTakashi Iwai 	case 0x14f15051:
34213868137eSTakashi Iwai 		add_cx5051_fake_mutes(codec);
342251969d62SMichael Karcher 		codec->pin_amp_workaround = 1;
3423a2dd933dSTakashi Iwai 		snd_hda_pick_fixup(codec, cxt5051_fixup_models,
3424a2dd933dSTakashi Iwai 				   cxt5051_fixups, cxt_fixups);
34253868137eSTakashi Iwai 		break;
342651969d62SMichael Karcher 	default:
342751969d62SMichael Karcher 		codec->pin_amp_workaround = 1;
3428a2dd933dSTakashi Iwai 		snd_hda_pick_fixup(codec, cxt5066_fixup_models,
3429a2dd933dSTakashi Iwai 				   cxt5066_fixups, cxt_fixups);
343023d30f28STakashi Iwai 		break;
34316b452142STakashi Iwai 	}
34326b452142STakashi Iwai 
3433f29735cbSTakashi Iwai 	/* Show mute-led control only on HP laptops
3434f29735cbSTakashi Iwai 	 * This is a sort of white-list: on HP laptops, EAPD corresponds
3435f29735cbSTakashi Iwai 	 * only to the mute-LED without actualy amp function.  Meanwhile,
3436f29735cbSTakashi Iwai 	 * others may use EAPD really as an amp switch, so it might be
3437f29735cbSTakashi Iwai 	 * not good to expose it blindly.
3438527c73baSTakashi Iwai 	 */
3439f29735cbSTakashi Iwai 	switch (codec->subsystem_id >> 16) {
3440f29735cbSTakashi Iwai 	case 0x103c:
3441aed523f1STakashi Iwai 		spec->gen.vmaster_mute_enum = 1;
3442f29735cbSTakashi Iwai 		break;
3443f29735cbSTakashi Iwai 	}
3444527c73baSTakashi Iwai 
3445aed523f1STakashi Iwai 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
3446aed523f1STakashi Iwai 
3447e4c3bce2SDavid Henningsson 	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
3448e4c3bce2SDavid Henningsson 				       spec->parse_flags);
344922ce5f74STakashi Iwai 	if (err < 0)
3450aed523f1STakashi Iwai 		goto error;
3451aed523f1STakashi Iwai 
3452aed523f1STakashi Iwai 	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
3453aed523f1STakashi Iwai 	if (err < 0)
3454aed523f1STakashi Iwai 		goto error;
3455aed523f1STakashi Iwai 
3456f2e5731dSTakashi Iwai 	codec->patch_ops = cx_auto_patch_ops;
34574f2864a4STakashi Iwai 
34584f2864a4STakashi Iwai 	/* Some laptops with Conexant chips show stalls in S3 resume,
34594f2864a4STakashi Iwai 	 * which falls into the single-cmd mode.
34604f2864a4STakashi Iwai 	 * Better to make reset, then.
34614f2864a4STakashi Iwai 	 */
34624f2864a4STakashi Iwai 	if (!codec->bus->sync_write) {
34634f2864a4STakashi Iwai 		snd_printd("hda_codec: "
34644f2864a4STakashi Iwai 			   "Enable sync_write for stable communication\n");
34654f2864a4STakashi Iwai 		codec->bus->sync_write = 1;
34664f2864a4STakashi Iwai 		codec->bus->allow_bus_reset = 1;
34674f2864a4STakashi Iwai 	}
34684f2864a4STakashi Iwai 
3469e4c3bce2SDavid Henningsson 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
3470e4c3bce2SDavid Henningsson 
3471f2e5731dSTakashi Iwai 	return 0;
3472aed523f1STakashi Iwai 
3473aed523f1STakashi Iwai  error:
347408cf680cSDavid Henningsson 	cx_auto_free(codec);
3475aed523f1STakashi Iwai 	return err;
3476f2e5731dSTakashi Iwai }
3477f2e5731dSTakashi Iwai 
3478bf92d1d5STakashi Iwai #ifndef ENABLE_CXT_STATIC_QUIRKS
3479bf92d1d5STakashi Iwai #define patch_cxt5045	patch_conexant_auto
3480bf92d1d5STakashi Iwai #define patch_cxt5047	patch_conexant_auto
3481bf92d1d5STakashi Iwai #define patch_cxt5051	patch_conexant_auto
3482bf92d1d5STakashi Iwai #define patch_cxt5066	patch_conexant_auto
3483bf92d1d5STakashi Iwai #endif
3484bf92d1d5STakashi Iwai 
3485f2e5731dSTakashi Iwai /*
3486461e2c78STakashi Iwai  */
3487461e2c78STakashi Iwai 
348834cbe3a6STakashi Iwai static const struct hda_codec_preset snd_hda_preset_conexant[] = {
348982f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
349082f30040STobin Davis 	  .patch = patch_cxt5045 },
349182f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
349282f30040STobin Davis 	  .patch = patch_cxt5047 },
3493461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3494461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
34950fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
34960fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
349795a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
349895a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3499850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3500850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
35017b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
35027b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
3503f0ca89b0SDavid Henningsson 	{ .id = 0x14f1506c, .name = "CX20588",
3504f0ca89b0SDavid Henningsson 	  .patch = patch_cxt5066 },
35056da8b516SDavid Henningsson 	{ .id = 0x14f1506e, .name = "CX20590",
35066da8b516SDavid Henningsson 	  .patch = patch_cxt5066 },
3507f2e5731dSTakashi Iwai 	{ .id = 0x14f15097, .name = "CX20631",
3508f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3509f2e5731dSTakashi Iwai 	{ .id = 0x14f15098, .name = "CX20632",
3510f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3511f2e5731dSTakashi Iwai 	{ .id = 0x14f150a1, .name = "CX20641",
3512f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3513f2e5731dSTakashi Iwai 	{ .id = 0x14f150a2, .name = "CX20642",
3514f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3515f2e5731dSTakashi Iwai 	{ .id = 0x14f150ab, .name = "CX20651",
3516f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3517f2e5731dSTakashi Iwai 	{ .id = 0x14f150ac, .name = "CX20652",
3518f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3519f2e5731dSTakashi Iwai 	{ .id = 0x14f150b8, .name = "CX20664",
3520f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
3521f2e5731dSTakashi Iwai 	{ .id = 0x14f150b9, .name = "CX20665",
3522f2e5731dSTakashi Iwai 	  .patch = patch_conexant_auto },
35232d825fd8STakashi Iwai 	{ .id = 0x14f1510f, .name = "CX20751/2",
35242d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
35252d825fd8STakashi Iwai 	{ .id = 0x14f15110, .name = "CX20751/2",
35262d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
35272d825fd8STakashi Iwai 	{ .id = 0x14f15111, .name = "CX20753/4",
35282d825fd8STakashi Iwai 	  .patch = patch_conexant_auto },
352942c364acSTakashi Iwai 	{ .id = 0x14f15113, .name = "CX20755",
353042c364acSTakashi Iwai 	  .patch = patch_conexant_auto },
353142c364acSTakashi Iwai 	{ .id = 0x14f15114, .name = "CX20756",
353242c364acSTakashi Iwai 	  .patch = patch_conexant_auto },
353342c364acSTakashi Iwai 	{ .id = 0x14f15115, .name = "CX20757",
353442c364acSTakashi Iwai 	  .patch = patch_conexant_auto },
35358f42d769STakashi Iwai 	{ .id = 0x14f151d7, .name = "CX20952",
35368f42d769STakashi Iwai 	  .patch = patch_conexant_auto },
3537c9b443d4STobin Davis 	{} /* terminator */
3538c9b443d4STobin Davis };
35391289e9e8STakashi Iwai 
35401289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
35411289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
35421289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
35430fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
354495a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3545850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
35467b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
3547f0ca89b0SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506c");
35486da8b516SDavid Henningsson MODULE_ALIAS("snd-hda-codec-id:14f1506e");
3549f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15097");
3550f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15098");
3551f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a1");
3552f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150a2");
3553f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ab");
3554f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150ac");
3555f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b8");
3556f2e5731dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f150b9");
35572d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f1510f");
35582d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15110");
35592d825fd8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15111");
356042c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15113");
356142c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15114");
356242c364acSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15115");
35638f42d769STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f151d7");
35641289e9e8STakashi Iwai 
35651289e9e8STakashi Iwai MODULE_LICENSE("GPL");
35661289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
35671289e9e8STakashi Iwai 
35681289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
35691289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
35701289e9e8STakashi Iwai 	.owner = THIS_MODULE,
35711289e9e8STakashi Iwai };
35721289e9e8STakashi Iwai 
35731289e9e8STakashi Iwai static int __init patch_conexant_init(void)
35741289e9e8STakashi Iwai {
35751289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
35761289e9e8STakashi Iwai }
35771289e9e8STakashi Iwai 
35781289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
35791289e9e8STakashi Iwai {
35801289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
35811289e9e8STakashi Iwai }
35821289e9e8STakashi Iwai 
35831289e9e8STakashi Iwai module_init(patch_conexant_init)
35841289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3585