xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision f7154de220f14073ef0d76638f85e254ad2e202f)
1c9b443d4STobin Davis /*
2c9b443d4STobin Davis  * HD audio interface patch for Conexant HDA audio codec
3c9b443d4STobin Davis  *
4c9b443d4STobin Davis  * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
5c9b443d4STobin Davis  * 		      Takashi Iwai <tiwai@suse.de>
6c9b443d4STobin Davis  * 		      Tobin Davis  <tdavis@dsl-only.net>
7c9b443d4STobin Davis  *
8c9b443d4STobin Davis  *  This driver is free software; you can redistribute it and/or modify
9c9b443d4STobin Davis  *  it under the terms of the GNU General Public License as published by
10c9b443d4STobin Davis  *  the Free Software Foundation; either version 2 of the License, or
11c9b443d4STobin Davis  *  (at your option) any later version.
12c9b443d4STobin Davis  *
13c9b443d4STobin Davis  *  This driver is distributed in the hope that it will be useful,
14c9b443d4STobin Davis  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15c9b443d4STobin Davis  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c9b443d4STobin Davis  *  GNU General Public License for more details.
17c9b443d4STobin Davis  *
18c9b443d4STobin Davis  *  You should have received a copy of the GNU General Public License
19c9b443d4STobin Davis  *  along with this program; if not, write to the Free Software
20c9b443d4STobin Davis  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21c9b443d4STobin Davis  */
22c9b443d4STobin Davis 
23c9b443d4STobin Davis #include <linux/init.h>
24c9b443d4STobin Davis #include <linux/delay.h>
25c9b443d4STobin Davis #include <linux/slab.h>
26c9b443d4STobin Davis #include <linux/pci.h>
27c9b443d4STobin Davis #include <sound/core.h>
28bc7a166dSUlrich Dangel #include <sound/jack.h>
29bc7a166dSUlrich Dangel 
30c9b443d4STobin Davis #include "hda_codec.h"
31c9b443d4STobin Davis #include "hda_local.h"
32c0f8faf0SEinar Rünkaru #include "hda_beep.h"
33c9b443d4STobin Davis 
34c9b443d4STobin Davis #define CXT_PIN_DIR_IN              0x00
35c9b443d4STobin Davis #define CXT_PIN_DIR_OUT             0x01
36c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT           0x02
37c9b443d4STobin Davis #define CXT_PIN_DIR_IN_NOMICBIAS    0x03
38c9b443d4STobin Davis #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
39c9b443d4STobin Davis 
40c9b443d4STobin Davis #define CONEXANT_HP_EVENT	0x37
41c9b443d4STobin Davis #define CONEXANT_MIC_EVENT	0x38
42c9b443d4STobin Davis 
43bc7a166dSUlrich Dangel /* Conexant 5051 specific */
44c9b443d4STobin Davis 
45ecda0cffSTakashi Iwai #define CXT5051_SPDIF_OUT	0x12
46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
48bc7a166dSUlrich Dangel 
49faddaa5dSTakashi Iwai #define AUTO_MIC_PORTB		(1 << 1)
50faddaa5dSTakashi Iwai #define AUTO_MIC_PORTC		(1 << 2)
51bc7a166dSUlrich Dangel 
52bc7a166dSUlrich Dangel struct conexant_jack {
53bc7a166dSUlrich Dangel 
54bc7a166dSUlrich Dangel 	hda_nid_t nid;
55bc7a166dSUlrich Dangel 	int type;
56bc7a166dSUlrich Dangel 	struct snd_jack *jack;
57bc7a166dSUlrich Dangel 
58bc7a166dSUlrich Dangel };
59c9b443d4STobin Davis 
60c9b443d4STobin Davis struct conexant_spec {
61c9b443d4STobin Davis 
62c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
63c9b443d4STobin Davis 	int num_mixers;
64dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
65c9b443d4STobin Davis 
66c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
67c9b443d4STobin Davis 						 * don't forget NULL
68c9b443d4STobin Davis 						 * termination!
69c9b443d4STobin Davis 						 */
70c9b443d4STobin Davis 	unsigned int num_init_verbs;
71c9b443d4STobin Davis 
72c9b443d4STobin Davis 	/* playback */
73c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
74c9b443d4STobin Davis 					 * max_channels, dacs must be set
75c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
76c9b443d4STobin Davis 					 */
77c9b443d4STobin Davis 	unsigned int cur_eapd;
7882f30040STobin Davis 	unsigned int hp_present;
79faddaa5dSTakashi Iwai 	unsigned int auto_mic;
80c9b443d4STobin Davis 	unsigned int need_dac_fix;
81c9b443d4STobin Davis 
82c9b443d4STobin Davis 	/* capture */
83c9b443d4STobin Davis 	unsigned int num_adc_nids;
84c9b443d4STobin Davis 	hda_nid_t *adc_nids;
85c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
86c9b443d4STobin Davis 
87461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
88461e2c78STakashi Iwai 	hda_nid_t cur_adc;
89461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
90461e2c78STakashi Iwai 	unsigned int cur_adc_format;
91461e2c78STakashi Iwai 
92c9b443d4STobin Davis 	/* capture source */
93c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
94c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
95c9b443d4STobin Davis 	unsigned int cur_mux[3];
96c9b443d4STobin Davis 
97c9b443d4STobin Davis 	/* channel model */
98c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
99c9b443d4STobin Davis 	int num_channel_mode;
100c9b443d4STobin Davis 
101c9b443d4STobin Davis 	/* PCM information */
102c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
103c9b443d4STobin Davis 
104c9b443d4STobin Davis 	unsigned int spdif_route;
105c9b443d4STobin Davis 
106bc7a166dSUlrich Dangel 	/* jack detection */
107bc7a166dSUlrich Dangel 	struct snd_array jacks;
108bc7a166dSUlrich Dangel 
109c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
110c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
111c9b443d4STobin Davis 	struct hda_input_mux private_imux;
11241923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
113c9b443d4STobin Davis 
1140fb67e98SDaniel Drake 	unsigned int dell_automute;
1150fb67e98SDaniel Drake 	unsigned int port_d_mode;
116cfd3d8dcSGreg Alexander 	unsigned int dell_vostro:1;
117cfd3d8dcSGreg Alexander 	unsigned int ideapad:1;
1187b2bfdbcSJens Taprogge 	unsigned int thinkpad:1;
11975f8991dSDaniel Drake 
12075f8991dSDaniel Drake 	unsigned int ext_mic_present;
12175f8991dSDaniel Drake 	unsigned int recording;
12275f8991dSDaniel Drake 	void (*capture_prepare)(struct hda_codec *codec);
12375f8991dSDaniel Drake 	void (*capture_cleanup)(struct hda_codec *codec);
124c4cfe66cSDaniel Drake 
125c4cfe66cSDaniel Drake 	/* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
126c4cfe66cSDaniel Drake 	 * through the microphone jack.
127c4cfe66cSDaniel Drake 	 * When the user enables this through a mixer switch, both internal and
128c4cfe66cSDaniel Drake 	 * external microphones are disabled. Gain is fixed at 0dB. In this mode,
129c4cfe66cSDaniel Drake 	 * we also allow the bias to be configured through a separate mixer
130c4cfe66cSDaniel Drake 	 * control. */
131c4cfe66cSDaniel Drake 	unsigned int dc_enable;
132c4cfe66cSDaniel Drake 	unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
133c4cfe66cSDaniel Drake 	unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
134c9b443d4STobin Davis };
135c9b443d4STobin Davis 
136c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
137c9b443d4STobin Davis 				      struct hda_codec *codec,
138c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
139c9b443d4STobin Davis {
140c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1419a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1429a08160bSTakashi Iwai 					     hinfo);
143c9b443d4STobin Davis }
144c9b443d4STobin Davis 
145c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
146c9b443d4STobin Davis 					 struct hda_codec *codec,
147c9b443d4STobin Davis 					 unsigned int stream_tag,
148c9b443d4STobin Davis 					 unsigned int format,
149c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
150c9b443d4STobin Davis {
151c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
152c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
153c9b443d4STobin Davis 						stream_tag,
154c9b443d4STobin Davis 						format, substream);
155c9b443d4STobin Davis }
156c9b443d4STobin Davis 
157c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
158c9b443d4STobin Davis 					 struct hda_codec *codec,
159c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
160c9b443d4STobin Davis {
161c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
162c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
163c9b443d4STobin Davis }
164c9b443d4STobin Davis 
165c9b443d4STobin Davis /*
166c9b443d4STobin Davis  * Digital out
167c9b443d4STobin Davis  */
168c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
169c9b443d4STobin Davis 					  struct hda_codec *codec,
170c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
171c9b443d4STobin Davis {
172c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
173c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
174c9b443d4STobin Davis }
175c9b443d4STobin Davis 
176c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
177c9b443d4STobin Davis 					 struct hda_codec *codec,
178c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
179c9b443d4STobin Davis {
180c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
181c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
182c9b443d4STobin Davis }
183c9b443d4STobin Davis 
1846b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1856b97eb45STakashi Iwai 					 struct hda_codec *codec,
1866b97eb45STakashi Iwai 					 unsigned int stream_tag,
1876b97eb45STakashi Iwai 					 unsigned int format,
1886b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1896b97eb45STakashi Iwai {
1906b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1916b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1926b97eb45STakashi Iwai 					     stream_tag,
1936b97eb45STakashi Iwai 					     format, substream);
1946b97eb45STakashi Iwai }
1956b97eb45STakashi Iwai 
196c9b443d4STobin Davis /*
197c9b443d4STobin Davis  * Analog capture
198c9b443d4STobin Davis  */
199c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
200c9b443d4STobin Davis 				      struct hda_codec *codec,
201c9b443d4STobin Davis 				      unsigned int stream_tag,
202c9b443d4STobin Davis 				      unsigned int format,
203c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
204c9b443d4STobin Davis {
205c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
20675f8991dSDaniel Drake 	if (spec->capture_prepare)
20775f8991dSDaniel Drake 		spec->capture_prepare(codec);
208c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
209c9b443d4STobin Davis 				   stream_tag, 0, format);
210c9b443d4STobin Davis 	return 0;
211c9b443d4STobin Davis }
212c9b443d4STobin Davis 
213c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
214c9b443d4STobin Davis 				      struct hda_codec *codec,
215c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
216c9b443d4STobin Davis {
217c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
218888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
21975f8991dSDaniel Drake 	if (spec->capture_cleanup)
22075f8991dSDaniel Drake 		spec->capture_cleanup(codec);
221c9b443d4STobin Davis 	return 0;
222c9b443d4STobin Davis }
223c9b443d4STobin Davis 
224c9b443d4STobin Davis 
225c9b443d4STobin Davis 
226c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
227c9b443d4STobin Davis 	.substreams = 1,
228c9b443d4STobin Davis 	.channels_min = 2,
229c9b443d4STobin Davis 	.channels_max = 2,
230c9b443d4STobin Davis 	.nid = 0, /* fill later */
231c9b443d4STobin Davis 	.ops = {
232c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
233c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
234c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
235c9b443d4STobin Davis 	},
236c9b443d4STobin Davis };
237c9b443d4STobin Davis 
238c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
239c9b443d4STobin Davis 	.substreams = 1,
240c9b443d4STobin Davis 	.channels_min = 2,
241c9b443d4STobin Davis 	.channels_max = 2,
242c9b443d4STobin Davis 	.nid = 0, /* fill later */
243c9b443d4STobin Davis 	.ops = {
244c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
245c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
246c9b443d4STobin Davis 	},
247c9b443d4STobin Davis };
248c9b443d4STobin Davis 
249c9b443d4STobin Davis 
250c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
251c9b443d4STobin Davis 	.substreams = 1,
252c9b443d4STobin Davis 	.channels_min = 2,
253c9b443d4STobin Davis 	.channels_max = 2,
254c9b443d4STobin Davis 	.nid = 0, /* fill later */
255c9b443d4STobin Davis 	.ops = {
256c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2576b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2586b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
259c9b443d4STobin Davis 	},
260c9b443d4STobin Davis };
261c9b443d4STobin Davis 
262c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
263c9b443d4STobin Davis 	.substreams = 1,
264c9b443d4STobin Davis 	.channels_min = 2,
265c9b443d4STobin Davis 	.channels_max = 2,
266c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
267c9b443d4STobin Davis };
268c9b443d4STobin Davis 
269461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
270461e2c78STakashi Iwai 				      struct hda_codec *codec,
271461e2c78STakashi Iwai 				      unsigned int stream_tag,
272461e2c78STakashi Iwai 				      unsigned int format,
273461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
274461e2c78STakashi Iwai {
275461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
276461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
277461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
278461e2c78STakashi Iwai 	spec->cur_adc_format = format;
279461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
280461e2c78STakashi Iwai 	return 0;
281461e2c78STakashi Iwai }
282461e2c78STakashi Iwai 
283461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
284461e2c78STakashi Iwai 				      struct hda_codec *codec,
285461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
286461e2c78STakashi Iwai {
287461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
288888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
289461e2c78STakashi Iwai 	spec->cur_adc = 0;
290461e2c78STakashi Iwai 	return 0;
291461e2c78STakashi Iwai }
292461e2c78STakashi Iwai 
293461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
294461e2c78STakashi Iwai 	.substreams = 1,
295461e2c78STakashi Iwai 	.channels_min = 2,
296461e2c78STakashi Iwai 	.channels_max = 2,
297461e2c78STakashi Iwai 	.nid = 0, /* fill later */
298461e2c78STakashi Iwai 	.ops = {
299461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
300461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
301461e2c78STakashi Iwai 	},
302461e2c78STakashi Iwai };
303461e2c78STakashi Iwai 
304c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
305c9b443d4STobin Davis {
306c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
307c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
308c9b443d4STobin Davis 
309c9b443d4STobin Davis 	codec->num_pcms = 1;
310c9b443d4STobin Davis 	codec->pcm_info = info;
311c9b443d4STobin Davis 
312c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
313c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
314c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
315c9b443d4STobin Davis 		spec->multiout.max_channels;
316c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
317c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
318461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
319461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
320461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
321461e2c78STakashi Iwai 	else
322461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
323461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
324c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
325c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
326c9b443d4STobin Davis 
327c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
328c9b443d4STobin Davis 		info++;
329c9b443d4STobin Davis 		codec->num_pcms++;
330c9b443d4STobin Davis 		info->name = "Conexant Digital";
3317ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
332c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
333c9b443d4STobin Davis 			conexant_pcm_digital_playback;
334c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
335c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
336c9b443d4STobin Davis 		if (spec->dig_in_nid) {
337c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
338c9b443d4STobin Davis 				conexant_pcm_digital_capture;
339c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
340c9b443d4STobin Davis 				spec->dig_in_nid;
341c9b443d4STobin Davis 		}
342c9b443d4STobin Davis 	}
343c9b443d4STobin Davis 
344c9b443d4STobin Davis 	return 0;
345c9b443d4STobin Davis }
346c9b443d4STobin Davis 
347c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
348c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
349c9b443d4STobin Davis {
350c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
351c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
352c9b443d4STobin Davis 
353c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
354c9b443d4STobin Davis }
355c9b443d4STobin Davis 
356c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
357c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
358c9b443d4STobin Davis {
359c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
361c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
362c9b443d4STobin Davis 
363c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
364c9b443d4STobin Davis 	return 0;
365c9b443d4STobin Davis }
366c9b443d4STobin Davis 
367c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
368c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
369c9b443d4STobin Davis {
370c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
371c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
372c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
373c9b443d4STobin Davis 
374c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
375c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
376c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
377c9b443d4STobin Davis }
378c9b443d4STobin Davis 
3798c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
38095c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack)
38195c09099STakashi Iwai {
38295c09099STakashi Iwai 	struct conexant_jack *jacks = jack->private_data;
38395c09099STakashi Iwai 	jacks->nid = 0;
38495c09099STakashi Iwai 	jacks->jack = NULL;
38595c09099STakashi Iwai }
38695c09099STakashi Iwai 
387bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
388bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
389bc7a166dSUlrich Dangel {
390bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
391bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
392bc7a166dSUlrich Dangel 	const char *name;
39395c09099STakashi Iwai 	int err;
394bc7a166dSUlrich Dangel 
395bc7a166dSUlrich Dangel 	spec = codec->spec;
396bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
397bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
398bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
399bc7a166dSUlrich Dangel 
400bc7a166dSUlrich Dangel 	if (!jack)
401bc7a166dSUlrich Dangel 		return -ENOMEM;
402bc7a166dSUlrich Dangel 
403bc7a166dSUlrich Dangel 	jack->nid = nid;
404bc7a166dSUlrich Dangel 	jack->type = type;
405bc7a166dSUlrich Dangel 
40695c09099STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
40795c09099STakashi Iwai 	if (err < 0)
40895c09099STakashi Iwai 		return err;
40995c09099STakashi Iwai 	jack->jack->private_data = jack;
41095c09099STakashi Iwai 	jack->jack->private_free = conexant_free_jack_priv;
41195c09099STakashi Iwai 	return 0;
412bc7a166dSUlrich Dangel }
413bc7a166dSUlrich Dangel 
414bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
415bc7a166dSUlrich Dangel {
416bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
417bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
418bc7a166dSUlrich Dangel 
419bc7a166dSUlrich Dangel 	if (jacks) {
420bc7a166dSUlrich Dangel 		int i;
421bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
422bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
423bc7a166dSUlrich Dangel 				unsigned int present;
424d56757abSTakashi Iwai 				present = snd_hda_jack_detect(codec, nid);
425bc7a166dSUlrich Dangel 
426bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
427bc7a166dSUlrich Dangel 
428bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
429bc7a166dSUlrich Dangel 						present);
430bc7a166dSUlrich Dangel 			}
431bc7a166dSUlrich Dangel 			jacks++;
432bc7a166dSUlrich Dangel 		}
433bc7a166dSUlrich Dangel 	}
434bc7a166dSUlrich Dangel }
435bc7a166dSUlrich Dangel 
436bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
437bc7a166dSUlrich Dangel {
438bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
439bc7a166dSUlrich Dangel 	int i;
440bc7a166dSUlrich Dangel 
441bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
442bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
443bc7a166dSUlrich Dangel 
444bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
445bc7a166dSUlrich Dangel 		while (hv->nid) {
446bc7a166dSUlrich Dangel 			int err = 0;
447bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
448bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
449bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
450bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
451bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
452bc7a166dSUlrich Dangel 				break;
453bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
454bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
455bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
456bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
457bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
458bc7a166dSUlrich Dangel 				break;
459bc7a166dSUlrich Dangel 			}
460bc7a166dSUlrich Dangel 			if (err < 0)
461bc7a166dSUlrich Dangel 				return err;
462bc7a166dSUlrich Dangel 			++hv;
463bc7a166dSUlrich Dangel 		}
464bc7a166dSUlrich Dangel 	}
465bc7a166dSUlrich Dangel 	return 0;
466bc7a166dSUlrich Dangel 
467bc7a166dSUlrich Dangel }
4685801f992STakashi Iwai #else
4695801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
4705801f992STakashi Iwai {
4715801f992STakashi Iwai }
4725801f992STakashi Iwai 
4735801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
4745801f992STakashi Iwai {
4755801f992STakashi Iwai 	return 0;
4765801f992STakashi Iwai }
4775801f992STakashi Iwai #endif
478bc7a166dSUlrich Dangel 
479c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
480c9b443d4STobin Davis {
481c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
482c9b443d4STobin Davis 	int i;
483c9b443d4STobin Davis 
484c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
485c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
486c9b443d4STobin Davis 	return 0;
487c9b443d4STobin Davis }
488c9b443d4STobin Davis 
489c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
490c9b443d4STobin Davis {
4918c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
492bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
493bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
494bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
495bc7a166dSUlrich Dangel 		int i;
49695c09099STakashi Iwai 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
49795c09099STakashi Iwai 			if (jacks->jack)
49895c09099STakashi Iwai 				snd_device_free(codec->bus->card, jacks->jack);
49995c09099STakashi Iwai 		}
500bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
501bc7a166dSUlrich Dangel 	}
502bc7a166dSUlrich Dangel #endif
503c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
504c9b443d4STobin Davis 	kfree(codec->spec);
505c9b443d4STobin Davis }
506c9b443d4STobin Davis 
507b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
508b880c74aSTakashi Iwai 	{
509b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
510b880c74aSTakashi Iwai 		.name = "Capture Source",
511b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
512b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
513b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
514b880c74aSTakashi Iwai 	},
515b880c74aSTakashi Iwai 	{}
516b880c74aSTakashi Iwai };
517b880c74aSTakashi Iwai 
518dd5746a8STakashi Iwai static const char *slave_vols[] = {
519dd5746a8STakashi Iwai 	"Headphone Playback Volume",
520dd5746a8STakashi Iwai 	"Speaker Playback Volume",
521dd5746a8STakashi Iwai 	NULL
522dd5746a8STakashi Iwai };
523dd5746a8STakashi Iwai 
524dd5746a8STakashi Iwai static const char *slave_sws[] = {
525dd5746a8STakashi Iwai 	"Headphone Playback Switch",
526dd5746a8STakashi Iwai 	"Speaker Playback Switch",
527dd5746a8STakashi Iwai 	NULL
528dd5746a8STakashi Iwai };
529dd5746a8STakashi Iwai 
530c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
531c9b443d4STobin Davis {
532c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
533c9b443d4STobin Davis 	unsigned int i;
534c9b443d4STobin Davis 	int err;
535c9b443d4STobin Davis 
536c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
537c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
538c9b443d4STobin Davis 		if (err < 0)
539c9b443d4STobin Davis 			return err;
540c9b443d4STobin Davis 	}
541c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
542c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
543c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
544c9b443d4STobin Davis 		if (err < 0)
545c9b443d4STobin Davis 			return err;
5469a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5479a08160bSTakashi Iwai 						    &spec->multiout);
5489a08160bSTakashi Iwai 		if (err < 0)
5499a08160bSTakashi Iwai 			return err;
5509a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
551c9b443d4STobin Davis 	}
552c9b443d4STobin Davis 	if (spec->dig_in_nid) {
553c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
554c9b443d4STobin Davis 		if (err < 0)
555c9b443d4STobin Davis 			return err;
556c9b443d4STobin Davis 	}
557dd5746a8STakashi Iwai 
558dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
559dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
560dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
561dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
562dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
563dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
564dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
565dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
566dd5746a8STakashi Iwai 		if (err < 0)
567dd5746a8STakashi Iwai 			return err;
568dd5746a8STakashi Iwai 	}
569dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
570dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
571dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
572dd5746a8STakashi Iwai 					  NULL, slave_sws);
573dd5746a8STakashi Iwai 		if (err < 0)
574dd5746a8STakashi Iwai 			return err;
575dd5746a8STakashi Iwai 	}
576dd5746a8STakashi Iwai 
577b880c74aSTakashi Iwai 	if (spec->input_mux) {
578b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
579b880c74aSTakashi Iwai 		if (err < 0)
580b880c74aSTakashi Iwai 			return err;
581b880c74aSTakashi Iwai 	}
582b880c74aSTakashi Iwai 
583c9b443d4STobin Davis 	return 0;
584c9b443d4STobin Davis }
585c9b443d4STobin Davis 
586c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
587c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
588c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
589c9b443d4STobin Davis 	.init = conexant_init,
590c9b443d4STobin Davis 	.free = conexant_free,
591c9b443d4STobin Davis };
592c9b443d4STobin Davis 
593c9b443d4STobin Davis /*
594c9b443d4STobin Davis  * EAPD control
595c9b443d4STobin Davis  * the private value = nid | (invert << 8)
596c9b443d4STobin Davis  */
597c9b443d4STobin Davis 
598a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
599c9b443d4STobin Davis 
60082f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
601c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
602c9b443d4STobin Davis {
603c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
605c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
606c9b443d4STobin Davis 	if (invert)
607c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
608c9b443d4STobin Davis 	else
609c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
610c9b443d4STobin Davis 	return 0;
61182f30040STobin Davis 
612c9b443d4STobin Davis }
613c9b443d4STobin Davis 
61482f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
615c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
616c9b443d4STobin Davis {
617c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
618c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
619c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
620c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
621c9b443d4STobin Davis 	unsigned int eapd;
62282f30040STobin Davis 
62368ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
624c9b443d4STobin Davis 	if (invert)
625c9b443d4STobin Davis 		eapd = !eapd;
62682beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
627c9b443d4STobin Davis 		return 0;
62882f30040STobin Davis 
629c9b443d4STobin Davis 	spec->cur_eapd = eapd;
63082beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
631c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
632c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
633c9b443d4STobin Davis 	return 1;
634c9b443d4STobin Davis }
635c9b443d4STobin Davis 
63686d72bdfSTakashi Iwai /* controls for test mode */
63786d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
63886d72bdfSTakashi Iwai 
63982f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
64082f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
64182f30040STobin Davis 	  .info = cxt_eapd_info, \
64282f30040STobin Davis 	  .get = cxt_eapd_get, \
64382f30040STobin Davis 	  .put = cxt_eapd_put, \
64482f30040STobin Davis 	  .private_value = nid | (mask<<16) }
64582f30040STobin Davis 
64682f30040STobin Davis 
64782f30040STobin Davis 
648c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
649c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
650c9b443d4STobin Davis {
651c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
653c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
654c9b443d4STobin Davis 				    spec->num_channel_mode);
655c9b443d4STobin Davis }
656c9b443d4STobin Davis 
657c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
658c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
659c9b443d4STobin Davis {
660c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
662c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
663c9b443d4STobin Davis 				   spec->num_channel_mode,
664c9b443d4STobin Davis 				   spec->multiout.max_channels);
665c9b443d4STobin Davis }
666c9b443d4STobin Davis 
667c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
668c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
669c9b443d4STobin Davis {
670c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
672c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
673c9b443d4STobin Davis 				      spec->num_channel_mode,
674c9b443d4STobin Davis 				      &spec->multiout.max_channels);
675c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
676c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
677c9b443d4STobin Davis 	return err;
678c9b443d4STobin Davis }
679c9b443d4STobin Davis 
680c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
681c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
682c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
683c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
684c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
685c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
686c9b443d4STobin Davis 
68786d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
68886d72bdfSTakashi Iwai 
689c9b443d4STobin Davis /* Conexant 5045 specific */
690c9b443d4STobin Davis 
691c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
692c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
693c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
694cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
695c9b443d4STobin Davis 
6965cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
6975cd57529STobin Davis 	{ 2, NULL },
6985cd57529STobin Davis };
699c9b443d4STobin Davis 
700c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
701c9b443d4STobin Davis 	.num_items = 2,
702c9b443d4STobin Davis 	.items = {
70382f30040STobin Davis 		{ "IntMic", 0x1 },
704f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
705c9b443d4STobin Davis 	}
706c9b443d4STobin Davis };
707c9b443d4STobin Davis 
7085218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
70922e14130SLukasz Marcinowski 	.num_items = 5,
7105218c892SJiang Zhe 	.items = {
7115218c892SJiang Zhe 		{ "IntMic", 0x1 },
7125218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7135218c892SJiang Zhe 		{ "LineIn", 0x3 },
71422e14130SLukasz Marcinowski 		{ "CD",     0x4 },
71522e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7165218c892SJiang Zhe 	}
7175218c892SJiang Zhe };
7185218c892SJiang Zhe 
7192de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
7202de3c232SJiang zhe 	.num_items = 2,
7212de3c232SJiang zhe 	.items = {
7222de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7232de3c232SJiang zhe 		{ "IntMic", 0x2 },
7242de3c232SJiang zhe 	}
7252de3c232SJiang zhe };
7262de3c232SJiang zhe 
727c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
728c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
729c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
730c9b443d4STobin Davis {
731c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
732c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
73382f30040STobin Davis 	unsigned int bits;
734c9b443d4STobin Davis 
73582f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
736c9b443d4STobin Davis 		return 0;
737c9b443d4STobin Davis 
73882f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
73982f30040STobin Davis 	 * the headphone jack
74082f30040STobin Davis 	 */
74147fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
74247fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
74347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7447f29673bSTobin Davis 
74547fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
74647fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
74747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
748c9b443d4STobin Davis 	return 1;
749c9b443d4STobin Davis }
750c9b443d4STobin Davis 
751c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
752cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
753cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
754cca3b371STakashi Iwai 	.values = {
755cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
756cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
757cca3b371STakashi Iwai 		0
758cca3b371STakashi Iwai 	},
759cca3b371STakashi Iwai };
760c9b443d4STobin Davis 
7617f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7627f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7637f29673bSTobin Davis {
7647f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
7657f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7667f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7677f29673bSTobin Davis 		{}
7687f29673bSTobin Davis 	};
7697f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
7707f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7717f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7727f29673bSTobin Davis 		{}
7737f29673bSTobin Davis 	};
7747f29673bSTobin Davis 	unsigned int present;
7757f29673bSTobin Davis 
776d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7777f29673bSTobin Davis 	if (present)
7787f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7797f29673bSTobin Davis 	else
7807f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7817f29673bSTobin Davis }
7827f29673bSTobin Davis 
783c9b443d4STobin Davis 
784c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
785c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
786c9b443d4STobin Davis {
78782f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
788dd87da1cSTobin Davis 	unsigned int bits;
789c9b443d4STobin Davis 
790d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
791dd87da1cSTobin Davis 
79247fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
79347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
79447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
795c9b443d4STobin Davis }
796c9b443d4STobin Davis 
797c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
798c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
799c9b443d4STobin Davis 				   unsigned int res)
800c9b443d4STobin Davis {
801c9b443d4STobin Davis 	res >>= 26;
802c9b443d4STobin Davis 	switch (res) {
803c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
804c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
805c9b443d4STobin Davis 		break;
8067f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8077f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8087f29673bSTobin Davis 		break;
8097f29673bSTobin Davis 
810c9b443d4STobin Davis 	}
811c9b443d4STobin Davis }
812c9b443d4STobin Davis 
813c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
814c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
815c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
816c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
817c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
818c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
819c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
820c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
821c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
822c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
823c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
824cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
825c9b443d4STobin Davis 	{
826c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
827c9b443d4STobin Davis 		.name = "Master Playback Switch",
82882f30040STobin Davis 		.info = cxt_eapd_info,
82982f30040STobin Davis 		.get = cxt_eapd_get,
830c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
83182f30040STobin Davis 		.private_value = 0x10,
832c9b443d4STobin Davis 	},
833c9b443d4STobin Davis 
834c9b443d4STobin Davis 	{}
835c9b443d4STobin Davis };
836c9b443d4STobin Davis 
8375218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
83822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
83922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
84022e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
84122e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
84222e14130SLukasz Marcinowski 
8435218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8445218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8455218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8465218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8475218c892SJiang Zhe 
84822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
84922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
85022e14130SLukasz Marcinowski 
8515218c892SJiang Zhe 	{}
8525218c892SJiang Zhe };
8535218c892SJiang Zhe 
8542de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
8552de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8562de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8572de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8582de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8592de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8602de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
8612de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8622de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8632de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8642de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8652de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8662de3c232SJiang zhe 	{
8672de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8682de3c232SJiang zhe 		.name = "Master Playback Switch",
8692de3c232SJiang zhe 		.info = cxt_eapd_info,
8702de3c232SJiang zhe 		.get = cxt_eapd_get,
8712de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8722de3c232SJiang zhe 		.private_value = 0x10,
8732de3c232SJiang zhe 	},
8742de3c232SJiang zhe 
8752de3c232SJiang zhe 	{}
8762de3c232SJiang zhe };
8772de3c232SJiang zhe 
878c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
879c9b443d4STobin Davis 	/* Line in, Mic */
8804090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8817f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
882c9b443d4STobin Davis 	/* HP, Amp  */
883c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
884c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
88582f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
886c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
887c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
888c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
889c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
890c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
891c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
89282f30040STobin Davis 	/* Record selector: Int mic */
8937f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
89482f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
895c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
896c9b443d4STobin Davis 	/* SPDIF route: PCM */
897cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
898c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
899c9b443d4STobin Davis 	/* EAPD */
90082f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
901c9b443d4STobin Davis 	{ } /* end */
902c9b443d4STobin Davis };
903c9b443d4STobin Davis 
9045218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
9055218c892SJiang Zhe 	/* Int Mic, Mic */
9065218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9075218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9085218c892SJiang Zhe 	/* Line In,HP, Amp  */
9095218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9105218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9115218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9125218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9135218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9145218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9155218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9165218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9175218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9185218c892SJiang Zhe 	/* Record selector: Int mic */
9195218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9205218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9215218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9225218c892SJiang Zhe 	/* SPDIF route: PCM */
923cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9245218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9255218c892SJiang Zhe 	/* EAPD */
9265218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9275218c892SJiang Zhe 	{ } /* end */
9285218c892SJiang Zhe };
9297f29673bSTobin Davis 
9307f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9317f29673bSTobin Davis 	/* pin sensing on HP jack */
9327f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
933d3091fadSTakashi Iwai 	{ } /* end */
9347f29673bSTobin Davis };
9357f29673bSTobin Davis 
9367f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9377f29673bSTobin Davis 	/* pin sensing on HP jack */
9387f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
939d3091fadSTakashi Iwai 	{ } /* end */
9407f29673bSTobin Davis };
9417f29673bSTobin Davis 
942c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
943c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
944c9b443d4STobin Davis  * configuration.
945c9b443d4STobin Davis  */
946c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
947c9b443d4STobin Davis 	.num_items = 5,
948c9b443d4STobin Davis 	.items = {
949c9b443d4STobin Davis 		{ "MIXER", 0x0 },
950c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
951c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
952c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
953c9b443d4STobin Davis 		{ "CD pin", 0x4 },
954c9b443d4STobin Davis         },
955c9b443d4STobin Davis };
956c9b443d4STobin Davis 
957c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
958c9b443d4STobin Davis 
959c9b443d4STobin Davis 	/* Output controls */
960c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
961c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9627f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9637f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9647f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9657f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
966c9b443d4STobin Davis 
967c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
968c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
969c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
970c9b443d4STobin Davis 
97182f30040STobin Davis 	/* EAPD Switch Control */
97282f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
97382f30040STobin Davis 
974c9b443d4STobin Davis 	/* Loopback mixer controls */
975c9b443d4STobin Davis 
9767f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9777f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9787f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9797f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9807f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9817f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9827f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9837f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9847f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9857f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
986c9b443d4STobin Davis 	{
987c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
988c9b443d4STobin Davis 		.name = "Input Source",
989c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
990c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
991c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
992c9b443d4STobin Davis 	},
993fb3409e7STobin Davis 	/* Audio input controls */
994fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
995fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
996fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
997fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
998fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
999fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1000fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1001fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1002fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1003fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1004c9b443d4STobin Davis 	{ } /* end */
1005c9b443d4STobin Davis };
1006c9b443d4STobin Davis 
1007c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
10087f29673bSTobin Davis 	/* Set connections */
10097f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10107f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10117f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1012c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1013c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10147f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1015c9b443d4STobin Davis 
1016c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1017c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1018c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1019c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1020c9b443d4STobin Davis 	 * control.
1021c9b443d4STobin Davis 	 */
1022cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1023cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1024c9b443d4STobin Davis 
1025c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1026c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1027c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1028c9b443d4STobin Davis 
1029c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1030c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1031c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1032c9b443d4STobin Davis 	 * input/output buffers as needed.
1033c9b443d4STobin Davis 	 */
1034c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1035c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1036c9b443d4STobin Davis 
1037c9b443d4STobin Davis 	/* Mute capture amp left and right */
1038c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1039c9b443d4STobin Davis 
1040c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1041c9b443d4STobin Davis 	 * pin)
1042c9b443d4STobin Davis 	 */
1043c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10447f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1045c9b443d4STobin Davis 
1046c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1047c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1048c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1049c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1050c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1051c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1052c9b443d4STobin Davis 
1053c9b443d4STobin Davis 	{ }
1054c9b443d4STobin Davis };
1055c9b443d4STobin Davis #endif
1056c9b443d4STobin Davis 
1057c9b443d4STobin Davis 
1058c9b443d4STobin Davis /* initialize jack-sensing, too */
1059c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1060c9b443d4STobin Davis {
1061c9b443d4STobin Davis 	conexant_init(codec);
1062c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1063c9b443d4STobin Davis 	return 0;
1064c9b443d4STobin Davis }
1065c9b443d4STobin Davis 
1066c9b443d4STobin Davis 
1067c9b443d4STobin Davis enum {
106815908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
106915908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
107015908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10715218c892SJiang Zhe 	CXT5045_BENQ,
10722de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1073c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1074c9b443d4STobin Davis 	CXT5045_TEST,
1075c9b443d4STobin Davis #endif
1076f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1077c9b443d4STobin Davis };
1078c9b443d4STobin Davis 
1079f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
108015908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
108115908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
108215908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10835218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10842de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1085c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1086f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1087c9b443d4STobin Davis #endif
1088f5fcc13cSTakashi Iwai };
1089c9b443d4STobin Davis 
1090f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10912de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1092dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1093dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
10946a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10955218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
109615908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
109715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10989e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10999e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
110015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
110115908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
110215908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1103dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1104dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
110515908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1106c9b443d4STobin Davis 	{}
1107c9b443d4STobin Davis };
1108c9b443d4STobin Davis 
1109c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1110c9b443d4STobin Davis {
1111c9b443d4STobin Davis 	struct conexant_spec *spec;
1112c9b443d4STobin Davis 	int board_config;
1113c9b443d4STobin Davis 
1114c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1115c9b443d4STobin Davis 	if (!spec)
1116c9b443d4STobin Davis 		return -ENOMEM;
1117c9b443d4STobin Davis 	codec->spec = spec;
11189421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1119c9b443d4STobin Davis 
1120c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1121c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1122c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1123c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1124c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1125c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1126c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1127c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1128c9b443d4STobin Davis 	spec->num_mixers = 1;
1129c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1130c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1131c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1132c9b443d4STobin Davis 	spec->spdif_route = 0;
11335cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
11345cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
11355cd57529STobin Davis 
1136c9b443d4STobin Davis 
1137c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1138c9b443d4STobin Davis 
1139f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1140f5fcc13cSTakashi Iwai 						  cxt5045_models,
1141f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1142c9b443d4STobin Davis 	switch (board_config) {
114315908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11447f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1145c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1146c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11477f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11487f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11497f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11507f29673bSTobin Davis 		break;
115115908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
115286376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11537f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11547f29673bSTobin Davis 		spec->num_init_verbs = 2;
11557f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1156c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1157c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1158c9b443d4STobin Davis 		break;
115915908c36SMarc Boucher 	default:
116015908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
116115908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
116215908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
116315908c36SMarc Boucher 		spec->num_init_verbs = 3;
116415908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
116515908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
116615908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
116715908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
116815908c36SMarc Boucher 		break;
11695218c892SJiang Zhe 	case CXT5045_BENQ:
11705218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11715218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11725218c892SJiang Zhe 		spec->num_init_verbs = 1;
11735218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11745218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11755218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11765218c892SJiang Zhe 		spec->num_mixers = 2;
11775218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11785218c892SJiang Zhe 		break;
11792de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11802de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11812de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11822de3c232SJiang zhe 		spec->num_init_verbs = 2;
11832de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11842de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11852de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11862de3c232SJiang zhe 		break;
1187c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1188c9b443d4STobin Davis 	case CXT5045_TEST:
1189c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1190c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1191c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
119215908c36SMarc Boucher 		break;
119315908c36SMarc Boucher 
1194c9b443d4STobin Davis #endif
1195c9b443d4STobin Davis 	}
119648ecb7e8STakashi Iwai 
1197031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1198031005f7STakashi Iwai 	case 0x103c:
11998f0f5ff6SDaniel T Chen 	case 0x1631:
12000b587fc4SDaniel T Chen 	case 0x1734:
12010ebf9e36SDaniel T Chen 	case 0x17aa:
12020ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12030ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12040ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
120548ecb7e8STakashi Iwai 		 */
120648ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
120748ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
120848ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
120948ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
121048ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1211031005f7STakashi Iwai 		break;
1212031005f7STakashi Iwai 	}
121348ecb7e8STakashi Iwai 
1214c9b443d4STobin Davis 	return 0;
1215c9b443d4STobin Davis }
1216c9b443d4STobin Davis 
1217c9b443d4STobin Davis 
1218c9b443d4STobin Davis /* Conexant 5047 specific */
121982f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1220c9b443d4STobin Davis 
12215b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1222c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1223c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1224c9b443d4STobin Davis 
12255cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12265cd57529STobin Davis 	{ 2, NULL },
12275cd57529STobin Davis };
1228c9b443d4STobin Davis 
122982f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
123082f30040STobin Davis 	.num_items = 2,
123182f30040STobin Davis 	.items = {
123282f30040STobin Davis 		{ "ExtMic", 0x2 },
123382f30040STobin Davis 		{ "Line-In", 0x1 },
1234c9b443d4STobin Davis 	}
1235c9b443d4STobin Davis };
1236c9b443d4STobin Davis 
1237c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1238c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1239c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1240c9b443d4STobin Davis {
1241c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1242c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
124382f30040STobin Davis 	unsigned int bits;
1244c9b443d4STobin Davis 
124582f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1246c9b443d4STobin Davis 		return 0;
1247c9b443d4STobin Davis 
124882f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
124982f30040STobin Davis 	 * the headphone jack
125082f30040STobin Davis 	 */
125147fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12523b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12533b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12543b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12553b7523fcSTakashi Iwai 	 */
12565d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
125747fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
125847fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
125947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
126047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1261c9b443d4STobin Davis 	return 1;
1262c9b443d4STobin Davis }
1263c9b443d4STobin Davis 
1264c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1265c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1266c9b443d4STobin Davis {
126782f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1268dd87da1cSTobin Davis 	unsigned int bits;
1269c9b443d4STobin Davis 
1270d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1271dd87da1cSTobin Davis 
127247fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12733b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12745d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
127547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1276c9b443d4STobin Davis }
1277c9b443d4STobin Davis 
1278c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1279c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1280c9b443d4STobin Davis {
1281c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
12829f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12839f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1284c9b443d4STobin Davis 		{}
1285c9b443d4STobin Davis 	};
1286c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
12879f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12889f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1289c9b443d4STobin Davis 		{}
1290c9b443d4STobin Davis 	};
1291c9b443d4STobin Davis 	unsigned int present;
1292c9b443d4STobin Davis 
1293d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1294c9b443d4STobin Davis 	if (present)
1295c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1296c9b443d4STobin Davis 	else
1297c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1298c9b443d4STobin Davis }
1299c9b443d4STobin Davis 
1300c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1301c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1302c9b443d4STobin Davis 				  unsigned int res)
1303c9b443d4STobin Davis {
13049f113e0eSMarc Boucher 	switch (res >> 26) {
1305c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1306c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1307c9b443d4STobin Davis 		break;
1308c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1309c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1310c9b443d4STobin Davis 		break;
1311c9b443d4STobin Davis 	}
1312c9b443d4STobin Davis }
1313c9b443d4STobin Davis 
1314df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1315df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1316df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1317df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1318c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1319c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1320c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1321c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
132282f30040STobin Davis 	{
132382f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
132482f30040STobin Davis 		.name = "Master Playback Switch",
132582f30040STobin Davis 		.info = cxt_eapd_info,
132682f30040STobin Davis 		.get = cxt_eapd_get,
1327c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1328c9b443d4STobin Davis 		.private_value = 0x13,
1329c9b443d4STobin Davis 	},
1330c9b443d4STobin Davis 
1331c9b443d4STobin Davis 	{}
1332c9b443d4STobin Davis };
1333c9b443d4STobin Davis 
1334df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13353b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13365d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1337df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1338df481e41STakashi Iwai 	{}
1339df481e41STakashi Iwai };
1340df481e41STakashi Iwai 
1341df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1342c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1343c9b443d4STobin Davis 	{ } /* end */
1344c9b443d4STobin Davis };
1345c9b443d4STobin Davis 
1346c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1347c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1348c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1349c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1350c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13517f29673bSTobin Davis 	/* HP, Speaker  */
1352b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13535b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13545b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13557f29673bSTobin Davis 	/* Record selector: Mic */
13567f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13577f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13587f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13597f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1360c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1361c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1362c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1363c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1364c9b443d4STobin Davis 	/* SPDIF route: PCM */
1365c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
136682f30040STobin Davis 	/* Enable unsolicited events */
136782f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
136882f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1369c9b443d4STobin Davis 	{ } /* end */
1370c9b443d4STobin Davis };
1371c9b443d4STobin Davis 
1372c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1373c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
13743b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1375c9b443d4STobin Davis 	{}
1376c9b443d4STobin Davis };
1377c9b443d4STobin Davis 
1378c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1379c9b443d4STobin Davis  * configuration.
1380c9b443d4STobin Davis  */
1381c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1382c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
138382f30040STobin Davis 	.num_items = 4,
1384c9b443d4STobin Davis 	.items = {
138582f30040STobin Davis 		{ "LINE1 pin", 0x0 },
138682f30040STobin Davis 		{ "MIC1 pin", 0x1 },
138782f30040STobin Davis 		{ "MIC2 pin", 0x2 },
138882f30040STobin Davis 		{ "CD pin", 0x3 },
1389c9b443d4STobin Davis         },
1390c9b443d4STobin Davis };
1391c9b443d4STobin Davis 
1392c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1393c9b443d4STobin Davis 
1394c9b443d4STobin Davis 	/* Output only controls */
139582f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
139682f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
139782f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
139882f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1399c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1400c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1401c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1402c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
140382f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
140482f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
140582f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
140682f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1407c9b443d4STobin Davis 
1408c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1409c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1410c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1411c9b443d4STobin Davis 
141282f30040STobin Davis 	/* EAPD Switch Control */
141382f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
141482f30040STobin Davis 
1415c9b443d4STobin Davis 	/* Loopback mixer controls */
141682f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
141782f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
141882f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
141982f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
142082f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
142182f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
142282f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
142382f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1424c9b443d4STobin Davis 
142582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
142682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
142782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
142882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
142982f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
143082f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
143182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
143282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1433c9b443d4STobin Davis 	{
1434c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1435c9b443d4STobin Davis 		.name = "Input Source",
1436c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1437c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1438c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1439c9b443d4STobin Davis 	},
1440854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14419f113e0eSMarc Boucher 
1442c9b443d4STobin Davis 	{ } /* end */
1443c9b443d4STobin Davis };
1444c9b443d4STobin Davis 
1445c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1446c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1447c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1448c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1449c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1450c9b443d4STobin Davis 
1451c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1452c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1453c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1454c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1455c9b443d4STobin Davis 	 * control.
1456c9b443d4STobin Davis 	 */
1457c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1458c9b443d4STobin Davis 
1459c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1460c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1461c9b443d4STobin Davis 	 */
1462c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1463c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1464c9b443d4STobin Davis 
1465c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1466c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1467c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1468c9b443d4STobin Davis 
1469c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1470c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1471c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1472c9b443d4STobin Davis 	 * input/output buffers as needed.
1473c9b443d4STobin Davis 	 */
1474c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1475c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1476c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1477c9b443d4STobin Davis 
1478c9b443d4STobin Davis 	/* Mute capture amp left and right */
1479c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1480c9b443d4STobin Davis 
1481c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1482c9b443d4STobin Davis 	 * pin)
1483c9b443d4STobin Davis 	 */
1484c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1485c9b443d4STobin Davis 
1486c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1487c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1488c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1489c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1490c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1491c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1492c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1493c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1494c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1495c9b443d4STobin Davis 
1496c9b443d4STobin Davis 	{ }
1497c9b443d4STobin Davis };
1498c9b443d4STobin Davis #endif
1499c9b443d4STobin Davis 
1500c9b443d4STobin Davis 
1501c9b443d4STobin Davis /* initialize jack-sensing, too */
1502c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1503c9b443d4STobin Davis {
1504c9b443d4STobin Davis 	conexant_init(codec);
1505c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1506c9b443d4STobin Davis 	return 0;
1507c9b443d4STobin Davis }
1508c9b443d4STobin Davis 
1509c9b443d4STobin Davis 
1510c9b443d4STobin Davis enum {
1511f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1512f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1513f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1514c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1515c9b443d4STobin Davis 	CXT5047_TEST,
1516c9b443d4STobin Davis #endif
1517f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1518c9b443d4STobin Davis };
1519c9b443d4STobin Davis 
1520f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1521f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1522f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1523f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1524c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1525f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1526c9b443d4STobin Davis #endif
1527f5fcc13cSTakashi Iwai };
1528c9b443d4STobin Davis 
1529f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1530ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1531dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1532dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1533f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1534c9b443d4STobin Davis 	{}
1535c9b443d4STobin Davis };
1536c9b443d4STobin Davis 
1537c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1538c9b443d4STobin Davis {
1539c9b443d4STobin Davis 	struct conexant_spec *spec;
1540c9b443d4STobin Davis 	int board_config;
1541c9b443d4STobin Davis 
1542c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1543c9b443d4STobin Davis 	if (!spec)
1544c9b443d4STobin Davis 		return -ENOMEM;
1545c9b443d4STobin Davis 	codec->spec = spec;
15469421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1547c9b443d4STobin Davis 
1548c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1549c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1550c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1551c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1552c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1553c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1554c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1555c9b443d4STobin Davis 	spec->num_mixers = 1;
1556df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1557c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1558c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1559c9b443d4STobin Davis 	spec->spdif_route = 0;
15605cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15615cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1562c9b443d4STobin Davis 
1563c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1564c9b443d4STobin Davis 
1565f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1566f5fcc13cSTakashi Iwai 						  cxt5047_models,
1567f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1568c9b443d4STobin Davis 	switch (board_config) {
1569c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1570df481e41STakashi Iwai 		spec->num_mixers = 2;
1571df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1572df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1573c9b443d4STobin Davis 		break;
1574c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1575df481e41STakashi Iwai 		spec->num_mixers = 2;
1576df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1577fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1578c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1579c9b443d4STobin Davis 		break;
1580c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
158182f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1582df481e41STakashi Iwai 		spec->num_mixers = 2;
1583df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1584c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1585c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1586fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1587c9b443d4STobin Davis 		break;
1588c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1589c9b443d4STobin Davis 	case CXT5047_TEST:
1590c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1591c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1592c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1593fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1594c9b443d4STobin Davis #endif
1595c9b443d4STobin Davis 	}
1596dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1597025f206cSDaniel T Chen 
1598025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1599025f206cSDaniel T Chen 	case 0x103c:
1600025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1601025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1602025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1603025f206cSDaniel T Chen 		 */
1604025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1605025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1606025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1607025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1608025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1609025f206cSDaniel T Chen 		break;
1610025f206cSDaniel T Chen 	}
1611025f206cSDaniel T Chen 
1612c9b443d4STobin Davis 	return 0;
1613c9b443d4STobin Davis }
1614c9b443d4STobin Davis 
1615461e2c78STakashi Iwai /* Conexant 5051 specific */
1616461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1617461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1618461e2c78STakashi Iwai 
1619461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1620461e2c78STakashi Iwai 	{ 2, NULL },
1621461e2c78STakashi Iwai };
1622461e2c78STakashi Iwai 
1623461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1624461e2c78STakashi Iwai {
1625461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1626461e2c78STakashi Iwai 	unsigned int pinctl;
162723d2df5bSTakashi Iwai 	/* headphone pin */
162823d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
162923d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
163023d2df5bSTakashi Iwai 			    pinctl);
163123d2df5bSTakashi Iwai 	/* speaker pin */
1632461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1633461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1634461e2c78STakashi Iwai 			    pinctl);
1635*f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1636*f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1637*f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1638*f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1639*f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1640461e2c78STakashi Iwai }
1641461e2c78STakashi Iwai 
1642461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1643461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1644461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1645461e2c78STakashi Iwai {
1646461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1647461e2c78STakashi Iwai 
1648461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1649461e2c78STakashi Iwai 		return 0;
1650461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1651461e2c78STakashi Iwai 	return 1;
1652461e2c78STakashi Iwai }
1653461e2c78STakashi Iwai 
1654461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1655461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1656461e2c78STakashi Iwai {
165779d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1658461e2c78STakashi Iwai 	unsigned int present;
1659461e2c78STakashi Iwai 
1660faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
166179d7d533STakashi Iwai 		return;
1662d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1663461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1664461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1665461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1666461e2c78STakashi Iwai }
1667461e2c78STakashi Iwai 
1668461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1669461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1670461e2c78STakashi Iwai {
1671461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1672461e2c78STakashi Iwai 	unsigned int present;
1673461e2c78STakashi Iwai 	hda_nid_t new_adc;
1674461e2c78STakashi Iwai 
1675faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
167679d7d533STakashi Iwai 		return;
1677d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1678461e2c78STakashi Iwai 	if (present)
1679461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1680461e2c78STakashi Iwai 	else
1681461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1682461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1683461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1684461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1685888afa15STakashi Iwai 		snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1686461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1687461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1688461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1689461e2c78STakashi Iwai 					   spec->cur_adc_format);
1690461e2c78STakashi Iwai 	}
1691461e2c78STakashi Iwai }
1692461e2c78STakashi Iwai 
1693461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1694461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1695461e2c78STakashi Iwai {
1696461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1697461e2c78STakashi Iwai 
1698d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1699461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1700461e2c78STakashi Iwai }
1701461e2c78STakashi Iwai 
1702461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1703461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1704461e2c78STakashi Iwai 				   unsigned int res)
1705461e2c78STakashi Iwai {
1706acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1707461e2c78STakashi Iwai 	switch (res >> 26) {
1708461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1709461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1710461e2c78STakashi Iwai 		break;
1711461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1712461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1713461e2c78STakashi Iwai 		break;
1714461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1715461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1716461e2c78STakashi Iwai 		break;
1717461e2c78STakashi Iwai 	}
1718acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1719461e2c78STakashi Iwai }
1720461e2c78STakashi Iwai 
17212c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1722461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1723461e2c78STakashi Iwai 	{
1724461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1725461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1726461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1727461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1728461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1729461e2c78STakashi Iwai 		.private_value = 0x1a,
1730461e2c78STakashi Iwai 	},
17312c7a3fb3STakashi Iwai 	{}
17322c7a3fb3STakashi Iwai };
1733461e2c78STakashi Iwai 
17342c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17352c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17362c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17372c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
17382c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
17392c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17402c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1741461e2c78STakashi Iwai 	{}
1742461e2c78STakashi Iwai };
1743461e2c78STakashi Iwai 
1744461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1745461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1746461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1747461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1748461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1749461e2c78STakashi Iwai 	{}
1750461e2c78STakashi Iwai };
1751461e2c78STakashi Iwai 
175279d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
17534e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
17544e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
175579d7d533STakashi Iwai 	{}
175679d7d533STakashi Iwai };
175779d7d533STakashi Iwai 
1758cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
17595f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
17605f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1761cd9d95a5SKen Prox 	{}
1762cd9d95a5SKen Prox };
1763cd9d95a5SKen Prox 
1764faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1765faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1766faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1767faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1768faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1769faddaa5dSTakashi Iwai 	{}
1770faddaa5dSTakashi Iwai };
1771faddaa5dSTakashi Iwai 
1772461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1773461e2c78STakashi Iwai 	/* Line in, Mic */
1774461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1775461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1776461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1777461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1778461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1779461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1780461e2c78STakashi Iwai 	/* SPK  */
1781461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1782461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1783461e2c78STakashi Iwai 	/* HP, Amp  */
1784461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1785461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1786461e2c78STakashi Iwai 	/* DAC1 */
1787461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1788461e2c78STakashi Iwai 	/* Record selector: Int mic */
1789461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1790461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1791461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1792461e2c78STakashi Iwai 	/* SPDIF route: PCM */
17931965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1794461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1795461e2c78STakashi Iwai 	/* EAPD */
1796461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1797461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1798461e2c78STakashi Iwai 	{ } /* end */
1799461e2c78STakashi Iwai };
1800461e2c78STakashi Iwai 
180179d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
180279d7d533STakashi Iwai 	/* Line in, Mic */
180379d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
180479d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
180579d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
180679d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
180779d7d533STakashi Iwai 	/* SPK  */
180879d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
180979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
181079d7d533STakashi Iwai 	/* HP, Amp  */
181179d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
181279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
181379d7d533STakashi Iwai 	/* DAC1 */
181479d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
181579d7d533STakashi Iwai 	/* Record selector: Int mic */
181679d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
181779d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
181879d7d533STakashi Iwai 	/* SPDIF route: PCM */
181979d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
182079d7d533STakashi Iwai 	/* EAPD */
182179d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
182279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
182379d7d533STakashi Iwai 	{ } /* end */
182479d7d533STakashi Iwai };
182579d7d533STakashi Iwai 
182627e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
182727e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
182827e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
182927e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
183027e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
183127e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
183227e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
183327e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
183427e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
183527e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
183627e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
183727e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
183827e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
183927e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
184027e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
184127e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
184227e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
184327e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
184427e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
184527e08988SAristeu Sergio Rozanski Filho 	/* Record selector: Int mic */
184627e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
184727e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
184827e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
184927e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
18501965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
185127e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
185227e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
185327e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
185427e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
185527e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
185627e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
185727e08988SAristeu Sergio Rozanski Filho };
185827e08988SAristeu Sergio Rozanski Filho 
1859cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = {
1860cd9d95a5SKen Prox 	/* Line in, Mic */
186130ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1862cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1863cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1864cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1865cd9d95a5SKen Prox 	/* SPK  */
1866cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1867cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1868cd9d95a5SKen Prox 	/* HP, Amp  */
1869cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1870cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1871cd9d95a5SKen Prox 	/* DAC1 */
1872cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1873cd9d95a5SKen Prox 	/* Record selector: Int mic */
1874cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1875cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1876cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1877cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1878cd9d95a5SKen Prox 	/* EAPD */
1879cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1880cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1881cd9d95a5SKen Prox 	{ } /* end */
1882cd9d95a5SKen Prox };
1883cd9d95a5SKen Prox 
18846953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
18856953e552STakashi Iwai 				 unsigned int event)
18866953e552STakashi Iwai {
18876953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
18886953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
18896953e552STakashi Iwai 			    AC_USRSP_EN | event);
18906953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
18916953e552STakashi Iwai 	conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
18926953e552STakashi Iwai 	conexant_report_jack(codec, nid);
18936953e552STakashi Iwai #endif
18946953e552STakashi Iwai }
18956953e552STakashi Iwai 
1896*f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1897*f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1898*f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1899*f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1900*f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1901*f7154de2SHerton Ronaldo Krzesinski };
1902*f7154de2SHerton Ronaldo Krzesinski 
1903461e2c78STakashi Iwai /* initialize jack-sensing, too */
1904461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1905461e2c78STakashi Iwai {
19066953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19076953e552STakashi Iwai 
1908461e2c78STakashi Iwai 	conexant_init(codec);
1909acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19106953e552STakashi Iwai 
19116953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19126953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19136953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19146953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19156953e552STakashi Iwai 
1916461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1917461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1918461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1919461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1920461e2c78STakashi Iwai 	}
1921461e2c78STakashi Iwai 	return 0;
1922461e2c78STakashi Iwai }
1923461e2c78STakashi Iwai 
1924461e2c78STakashi Iwai 
1925461e2c78STakashi Iwai enum {
1926461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1927461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
192879d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19291965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1930cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1931faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1932*f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
1933461e2c78STakashi Iwai 	CXT5051_MODELS
1934461e2c78STakashi Iwai };
1935461e2c78STakashi Iwai 
1936461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1937461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1938461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
193979d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
194027e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19415f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1942faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1943*f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
1944461e2c78STakashi Iwai };
1945461e2c78STakashi Iwai 
1946461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
194779d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19481812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
19495f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
1950faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
1951461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1952461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1953461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
195427e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1955*f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
1956461e2c78STakashi Iwai 	{}
1957461e2c78STakashi Iwai };
1958461e2c78STakashi Iwai 
1959461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1960461e2c78STakashi Iwai {
1961461e2c78STakashi Iwai 	struct conexant_spec *spec;
1962461e2c78STakashi Iwai 	int board_config;
1963461e2c78STakashi Iwai 
1964461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1965461e2c78STakashi Iwai 	if (!spec)
1966461e2c78STakashi Iwai 		return -ENOMEM;
1967461e2c78STakashi Iwai 	codec->spec = spec;
19689421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1969461e2c78STakashi Iwai 
1970461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1971461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1972461e2c78STakashi Iwai 
1973461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1974461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1975461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1976461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1977461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1978461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
19792c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
19802c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
19812c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
1982461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1983461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1984461e2c78STakashi Iwai 	spec->spdif_route = 0;
1985461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1986461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1987461e2c78STakashi Iwai 	spec->cur_adc = 0;
1988461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1989461e2c78STakashi Iwai 
199079d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
199179d7d533STakashi Iwai 
1992461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1993461e2c78STakashi Iwai 						  cxt5051_models,
1994461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1995faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
1996461e2c78STakashi Iwai 	switch (board_config) {
1997461e2c78STakashi Iwai 	case CXT5051_HP:
1998461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1999461e2c78STakashi Iwai 		break;
200079d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
200179d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
200279d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2003faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
200479d7d533STakashi Iwai 		break;
200527e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
200627e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2007461e2c78STakashi Iwai 		break;
2008cd9d95a5SKen Prox 	case CXT5051_F700:
2009cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2010cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2011faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2012faddaa5dSTakashi Iwai 		break;
2013faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2014faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2015faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2016cd9d95a5SKen Prox 		break;
2017*f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2018*f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2019*f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2020*f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2021*f7154de2SHerton Ronaldo Krzesinski 		break;
2022461e2c78STakashi Iwai 	}
2023461e2c78STakashi Iwai 
2024461e2c78STakashi Iwai 	return 0;
2025461e2c78STakashi Iwai }
2026461e2c78STakashi Iwai 
20270fb67e98SDaniel Drake /* Conexant 5066 specific */
20280fb67e98SDaniel Drake 
20290fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
20300fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
20310fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
20320fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT	0x21
20330fb67e98SDaniel Drake 
2034dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2035dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2036dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2037dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2038dbaccc0cSDaniel Drake 
20390fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
20400fb67e98SDaniel Drake 	{ 2, NULL },
20410fb67e98SDaniel Drake };
20420fb67e98SDaniel Drake 
20430fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
20440fb67e98SDaniel Drake {
20450fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20460fb67e98SDaniel Drake 	unsigned int pinctl;
20470fb67e98SDaniel Drake 
20480fb67e98SDaniel Drake 	snd_printdd("CXT5066: update speaker, hp_present=%d\n",
20490fb67e98SDaniel Drake 		spec->hp_present);
20500fb67e98SDaniel Drake 
20510fb67e98SDaniel Drake 	/* Port A (HP) */
20520fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
20530fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20540fb67e98SDaniel Drake 			pinctl);
20550fb67e98SDaniel Drake 
20560fb67e98SDaniel Drake 	/* Port D (HP/LO) */
20570fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
20580fb67e98SDaniel Drake 		? spec->port_d_mode : 0;
20597b2bfdbcSJens Taprogge 	/* Mute if Port A is connected on Thinkpad */
20607b2bfdbcSJens Taprogge 	if (spec->thinkpad && (spec->hp_present & 1))
20617b2bfdbcSJens Taprogge 		pinctl = 0;
20620fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20630fb67e98SDaniel Drake 			pinctl);
20640fb67e98SDaniel Drake 
20650fb67e98SDaniel Drake 	/* CLASS_D AMP */
20660fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
20670fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
20680fb67e98SDaniel Drake 			pinctl);
20690fb67e98SDaniel Drake 
20700fb67e98SDaniel Drake 	if (spec->dell_automute) {
20710fb67e98SDaniel Drake 		/* DELL AIO Port Rule: PortA > PortD > IntSpk */
20720fb67e98SDaniel Drake 		pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
20730fb67e98SDaniel Drake 			? PIN_OUT : 0;
20740fb67e98SDaniel Drake 		snd_hda_codec_write(codec, 0x1c, 0,
20750fb67e98SDaniel Drake 			AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
20760fb67e98SDaniel Drake 	}
20770fb67e98SDaniel Drake }
20780fb67e98SDaniel Drake 
20790fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
20800fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
20810fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
20820fb67e98SDaniel Drake {
20830fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
20840fb67e98SDaniel Drake 
20850fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
20860fb67e98SDaniel Drake 		return 0;
20870fb67e98SDaniel Drake 
20880fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
20890fb67e98SDaniel Drake 	return 1;
20900fb67e98SDaniel Drake }
20910fb67e98SDaniel Drake 
2092c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2093c4cfe66cSDaniel Drake 	.num_items = 3,
2094c4cfe66cSDaniel Drake 	.items = {
2095c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2096c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2097c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2098c4cfe66cSDaniel Drake 	},
2099c4cfe66cSDaniel Drake };
2100c4cfe66cSDaniel Drake 
2101c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2102c4cfe66cSDaniel Drake {
2103c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2104c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2105c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2106c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2107c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2108c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2109c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2110c4cfe66cSDaniel Drake }
2111c4cfe66cSDaniel Drake 
211275f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
211375f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
211475f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
211575f8991dSDaniel Drake  * is happening when it is not. */
211675f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21170fb67e98SDaniel Drake {
2118dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
211975f8991dSDaniel Drake 	if (!spec->recording)
212075f8991dSDaniel Drake 		return;
21210fb67e98SDaniel Drake 
2122c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2123c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2124c4cfe66cSDaniel Drake 		 * through our special DC port */
2125c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2126c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2127c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2128c4cfe66cSDaniel Drake 
2129c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2130c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2131c4cfe66cSDaniel Drake 			{},
2132c4cfe66cSDaniel Drake 		};
2133c4cfe66cSDaniel Drake 
2134c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2135c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2136c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2137c4cfe66cSDaniel Drake 		return;
2138c4cfe66cSDaniel Drake 	}
2139c4cfe66cSDaniel Drake 
2140c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2141c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2142c4cfe66cSDaniel Drake 
214375f8991dSDaniel Drake 	/* external mic, port B */
214475f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
214575f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
21460fb67e98SDaniel Drake 
214775f8991dSDaniel Drake 	/* internal mic, port C */
214875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
214975f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
215075f8991dSDaniel Drake }
21510fb67e98SDaniel Drake 
215275f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
215375f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
215475f8991dSDaniel Drake {
215575f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
21560fb67e98SDaniel Drake 	unsigned int present;
21570fb67e98SDaniel Drake 
2158c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2159c4cfe66cSDaniel Drake 		return;
2160c4cfe66cSDaniel Drake 
216175f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
216275f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
216375f8991dSDaniel Drake 	if (present)
21640fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
216575f8991dSDaniel Drake 	else
21660fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
216775f8991dSDaniel Drake 
216875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
216975f8991dSDaniel Drake 		present ? 0 : 1);
217075f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
217175f8991dSDaniel Drake 
217275f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
21730fb67e98SDaniel Drake }
21740fb67e98SDaniel Drake 
217595a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
217695a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
217795a618bdSEinar Rünkaru {
217895a618bdSEinar Rünkaru 	unsigned int present;
217995a618bdSEinar Rünkaru 
218095a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
218195a618bdSEinar Rünkaru 		/* enable external mic, port B */
218275f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
218395a618bdSEinar Rünkaru 
218495a618bdSEinar Rünkaru 		/* switch to external mic input */
218595a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
218695a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
218795a618bdSEinar Rünkaru 
218895a618bdSEinar Rünkaru 		/* disable internal digital mic */
218995a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
219095a618bdSEinar Rünkaru 		{}
219195a618bdSEinar Rünkaru 	};
219295a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
219395a618bdSEinar Rünkaru 		/* enable internal mic, port C */
219495a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
219595a618bdSEinar Rünkaru 
219695a618bdSEinar Rünkaru 		/* switch to internal mic input */
219795a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
219895a618bdSEinar Rünkaru 
219995a618bdSEinar Rünkaru 		/* disable external mic, port B */
220095a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
220195a618bdSEinar Rünkaru 		{}
220295a618bdSEinar Rünkaru 	};
220395a618bdSEinar Rünkaru 
220495a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
220595a618bdSEinar Rünkaru 	if (present) {
220695a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
220795a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
220895a618bdSEinar Rünkaru 	} else {
220995a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
221095a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
221195a618bdSEinar Rünkaru 	}
221295a618bdSEinar Rünkaru }
221395a618bdSEinar Rünkaru 
2214cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2215cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2216cfd3d8dcSGreg Alexander {
2217cfd3d8dcSGreg Alexander 	unsigned int present;
2218cfd3d8dcSGreg Alexander 
2219cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2220cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2221cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2222cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2223cfd3d8dcSGreg Alexander 		{}
2224cfd3d8dcSGreg Alexander 	};
2225cfd3d8dcSGreg Alexander 	static struct hda_verb ext_mic_absent[] = {
2226cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2227cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2228cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2229cfd3d8dcSGreg Alexander 		{}
2230cfd3d8dcSGreg Alexander 	};
2231cfd3d8dcSGreg Alexander 
2232cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2233cfd3d8dcSGreg Alexander 	if (present) {
2234cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2235cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2236cfd3d8dcSGreg Alexander 	} else {
2237cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2238cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2239cfd3d8dcSGreg Alexander 	}
2240cfd3d8dcSGreg Alexander }
2241cfd3d8dcSGreg Alexander 
22427b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
22437b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
22447b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
22457b2bfdbcSJens Taprogge {
22467b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
22477b2bfdbcSJens Taprogge 
22487b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_present[] = {
22497b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
22507b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
22517b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
22527b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22537b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22547b2bfdbcSJens Taprogge 		{}
22557b2bfdbcSJens Taprogge 	};
22567b2bfdbcSJens Taprogge 	static struct hda_verb dock_mic_present[] = {
22577b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
22587b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
22597b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
22607b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22617b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22627b2bfdbcSJens Taprogge 		{}
22637b2bfdbcSJens Taprogge 	};
22647b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_absent[] = {
22657b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
22667b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
22677b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22687b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22697b2bfdbcSJens Taprogge 		{}
22707b2bfdbcSJens Taprogge 	};
22717b2bfdbcSJens Taprogge 
22727b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
22737b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
22747b2bfdbcSJens Taprogge 	if (ext_present) {
22757b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
22767b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
22777b2bfdbcSJens Taprogge 	} else if (dock_present) {
22787b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
22797b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
22807b2bfdbcSJens Taprogge 	} else {
22817b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
22827b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
22837b2bfdbcSJens Taprogge 	}
22847b2bfdbcSJens Taprogge }
22857b2bfdbcSJens Taprogge 
22860fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
22870fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
22880fb67e98SDaniel Drake {
22890fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
22900fb67e98SDaniel Drake 	unsigned int portA, portD;
22910fb67e98SDaniel Drake 
22920fb67e98SDaniel Drake 	/* Port A */
2293d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
22940fb67e98SDaniel Drake 
22950fb67e98SDaniel Drake 	/* Port D */
2296d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
22970fb67e98SDaniel Drake 
22987b2bfdbcSJens Taprogge 	spec->hp_present = !!(portA);
22997b2bfdbcSJens Taprogge 	spec->hp_present |= portD ? 2 : 0;
23000fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23010fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23020fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23030fb67e98SDaniel Drake }
23040fb67e98SDaniel Drake 
23050fb67e98SDaniel Drake /* unsolicited event for jack sensing */
230675f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23070fb67e98SDaniel Drake {
2308c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23090fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23100fb67e98SDaniel Drake 	switch (res >> 26) {
23110fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
23120fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
23130fb67e98SDaniel Drake 		break;
23140fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2315c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2316c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
231775f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
23180fb67e98SDaniel Drake 		break;
23190fb67e98SDaniel Drake 	}
23200fb67e98SDaniel Drake }
23210fb67e98SDaniel Drake 
232295a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
232395a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
232495a618bdSEinar Rünkaru {
232595a618bdSEinar Rünkaru 	snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
232695a618bdSEinar Rünkaru 	switch (res >> 26) {
232795a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
232895a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
232995a618bdSEinar Rünkaru 		break;
233095a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
233195a618bdSEinar Rünkaru 		cxt5066_vostro_automic(codec);
233295a618bdSEinar Rünkaru 		break;
233395a618bdSEinar Rünkaru 	}
233495a618bdSEinar Rünkaru }
233595a618bdSEinar Rünkaru 
2336cfd3d8dcSGreg Alexander /* unsolicited event for jack sensing */
2337cfd3d8dcSGreg Alexander static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2338cfd3d8dcSGreg Alexander {
2339cfd3d8dcSGreg Alexander 	snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2340cfd3d8dcSGreg Alexander 	switch (res >> 26) {
2341cfd3d8dcSGreg Alexander 	case CONEXANT_HP_EVENT:
2342cfd3d8dcSGreg Alexander 		cxt5066_hp_automute(codec);
2343cfd3d8dcSGreg Alexander 		break;
2344cfd3d8dcSGreg Alexander 	case CONEXANT_MIC_EVENT:
2345cfd3d8dcSGreg Alexander 		cxt5066_ideapad_automic(codec);
2346cfd3d8dcSGreg Alexander 		break;
2347cfd3d8dcSGreg Alexander 	}
2348cfd3d8dcSGreg Alexander }
2349cfd3d8dcSGreg Alexander 
23507b2bfdbcSJens Taprogge /* unsolicited event for jack sensing */
23517b2bfdbcSJens Taprogge static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
23527b2bfdbcSJens Taprogge {
23537b2bfdbcSJens Taprogge 	snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
23547b2bfdbcSJens Taprogge 	switch (res >> 26) {
23557b2bfdbcSJens Taprogge 	case CONEXANT_HP_EVENT:
23567b2bfdbcSJens Taprogge 		cxt5066_hp_automute(codec);
23577b2bfdbcSJens Taprogge 		break;
23587b2bfdbcSJens Taprogge 	case CONEXANT_MIC_EVENT:
23597b2bfdbcSJens Taprogge 		cxt5066_thinkpad_automic(codec);
23607b2bfdbcSJens Taprogge 		break;
23617b2bfdbcSJens Taprogge 	}
23627b2bfdbcSJens Taprogge }
23637b2bfdbcSJens Taprogge 
23640fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
23650fb67e98SDaniel Drake 	.num_items = 5,
23660fb67e98SDaniel Drake 	.items = {
23670fb67e98SDaniel Drake 		{ "0dB",  0 },
23680fb67e98SDaniel Drake 		{ "10dB", 1 },
23690fb67e98SDaniel Drake 		{ "20dB", 2 },
23700fb67e98SDaniel Drake 		{ "30dB", 3 },
23710fb67e98SDaniel Drake 		{ "40dB", 4 },
23720fb67e98SDaniel Drake 	},
23730fb67e98SDaniel Drake };
23740fb67e98SDaniel Drake 
2375cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2376c4cfe66cSDaniel Drake {
2377c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2378cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2379c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2380c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2381c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
23827b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2383cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2384cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2385cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2386cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2387cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2388cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2389cfd3d8dcSGreg Alexander 	}
2390c4cfe66cSDaniel Drake }
2391c4cfe66cSDaniel Drake 
23920fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
23930fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
23940fb67e98SDaniel Drake {
23950fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
23960fb67e98SDaniel Drake }
23970fb67e98SDaniel Drake 
23980fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
23990fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24000fb67e98SDaniel Drake {
24010fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2402c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2403c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24040fb67e98SDaniel Drake 	return 0;
24050fb67e98SDaniel Drake }
24060fb67e98SDaniel Drake 
24070fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24080fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24090fb67e98SDaniel Drake {
24100fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2411c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24120fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24130fb67e98SDaniel Drake 	unsigned int idx;
24140fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24150fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24160fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24170fb67e98SDaniel Drake 
2418c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2419c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2420c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2421c4cfe66cSDaniel Drake 	return 1;
2422c4cfe66cSDaniel Drake }
24230fb67e98SDaniel Drake 
2424c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2425c4cfe66cSDaniel Drake {
2426c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2427c4cfe66cSDaniel Drake 		/* disable gain */
2428c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2429c4cfe66cSDaniel Drake 
2430c4cfe66cSDaniel Drake 		/* switch to DC input */
2431c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2432c4cfe66cSDaniel Drake 		{}
2433c4cfe66cSDaniel Drake 	};
2434c4cfe66cSDaniel Drake 
2435c4cfe66cSDaniel Drake 	/* configure as input source */
2436c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2437c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2438c4cfe66cSDaniel Drake }
2439c4cfe66cSDaniel Drake 
2440c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2441c4cfe66cSDaniel Drake {
2442c4cfe66cSDaniel Drake 	/* reconfigure input source */
2443c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2444c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2445c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2446c4cfe66cSDaniel Drake }
2447c4cfe66cSDaniel Drake 
2448c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2449c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2450c4cfe66cSDaniel Drake {
2451c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2452c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2453c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2454c4cfe66cSDaniel Drake 	return 0;
2455c4cfe66cSDaniel Drake }
2456c4cfe66cSDaniel Drake 
2457c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2458c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2459c4cfe66cSDaniel Drake {
2460c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2461c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2462c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2463c4cfe66cSDaniel Drake 
2464c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2465c4cfe66cSDaniel Drake 		return 0;
2466c4cfe66cSDaniel Drake 
2467c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2468c4cfe66cSDaniel Drake 	if (dc_enable)
2469c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2470c4cfe66cSDaniel Drake 	else
2471c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2472c4cfe66cSDaniel Drake 
2473c4cfe66cSDaniel Drake 	return 1;
2474c4cfe66cSDaniel Drake }
2475c4cfe66cSDaniel Drake 
2476c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2477c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2478c4cfe66cSDaniel Drake {
2479c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2480c4cfe66cSDaniel Drake }
2481c4cfe66cSDaniel Drake 
2482c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2483c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2484c4cfe66cSDaniel Drake {
2485c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2486c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2487c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2488c4cfe66cSDaniel Drake 	return 0;
2489c4cfe66cSDaniel Drake }
2490c4cfe66cSDaniel Drake 
2491c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2492c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2493c4cfe66cSDaniel Drake {
2494c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2495c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2496c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2497c4cfe66cSDaniel Drake 	unsigned int idx;
2498c4cfe66cSDaniel Drake 
2499c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2500c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2501c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2502c4cfe66cSDaniel Drake 
2503c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2504c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2505c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25060fb67e98SDaniel Drake 	return 1;
25070fb67e98SDaniel Drake }
25080fb67e98SDaniel Drake 
250975f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
251075f8991dSDaniel Drake {
251175f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
251275f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
251375f8991dSDaniel Drake 	 * recording LED comes on. */
251475f8991dSDaniel Drake 	spec->recording = 1;
251575f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
251675f8991dSDaniel Drake }
251775f8991dSDaniel Drake 
251875f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
251975f8991dSDaniel Drake {
252075f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
252175f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
252275f8991dSDaniel Drake 		/* disable external mic, port B */
252375f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
252475f8991dSDaniel Drake 
252575f8991dSDaniel Drake 		/* disble internal mic, port C */
252675f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2527c4cfe66cSDaniel Drake 
2528c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2529c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
253075f8991dSDaniel Drake 		{},
253175f8991dSDaniel Drake 	};
253275f8991dSDaniel Drake 
253375f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
253475f8991dSDaniel Drake 	spec->recording = 0;
253575f8991dSDaniel Drake }
253675f8991dSDaniel Drake 
25370fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
25380fb67e98SDaniel Drake 	.num_items = 4,
25390fb67e98SDaniel Drake 	.items = {
25400fb67e98SDaniel Drake 		{ "Mic B", 0 },
25410fb67e98SDaniel Drake 		{ "Mic C", 1 },
25420fb67e98SDaniel Drake 		{ "Mic E", 2 },
25430fb67e98SDaniel Drake 		{ "Mic F", 3 },
25440fb67e98SDaniel Drake 	},
25450fb67e98SDaniel Drake };
25460fb67e98SDaniel Drake 
25470fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
25480fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
25490fb67e98SDaniel Drake 	.values = {
25500fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
25510fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
25520fb67e98SDaniel Drake 		0
25530fb67e98SDaniel Drake 	},
25540fb67e98SDaniel Drake };
25550fb67e98SDaniel Drake 
25560fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
25570fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
25580fb67e98SDaniel Drake 	.values = {
25590fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
25600fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
25610fb67e98SDaniel Drake 		0
25620fb67e98SDaniel Drake 	},
25630fb67e98SDaniel Drake };
25640fb67e98SDaniel Drake 
25650fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
25660fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
25670fb67e98SDaniel Drake 	{}
25680fb67e98SDaniel Drake };
25690fb67e98SDaniel Drake 
25700fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
25710fb67e98SDaniel Drake 	{
25720fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
25730fb67e98SDaniel Drake 		.name = "Master Playback Volume",
25740fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
25750fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
25760fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
25775e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
25780fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
25790fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
25800fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
25810fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
25820fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
25830fb67e98SDaniel Drake 		.private_value =
25840fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
25850fb67e98SDaniel Drake 	},
25860fb67e98SDaniel Drake 	{}
25870fb67e98SDaniel Drake };
25880fb67e98SDaniel Drake 
2589c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2590c4cfe66cSDaniel Drake 	{
2591c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2592c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2593c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2594c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2595c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2596c4cfe66cSDaniel Drake 	},
2597c4cfe66cSDaniel Drake 	{
2598c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2599c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2600c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2601c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2602c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2603c4cfe66cSDaniel Drake 	},
2604c4cfe66cSDaniel Drake 	{}
2605c4cfe66cSDaniel Drake };
2606c4cfe66cSDaniel Drake 
26070fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
26080fb67e98SDaniel Drake 	{
26090fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26100fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26110fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26120fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26130fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26140fb67e98SDaniel Drake 		.private_value = 0x1d,
26150fb67e98SDaniel Drake 	},
26160fb67e98SDaniel Drake 
26170fb67e98SDaniel Drake 	{
26180fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2619c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
26200fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
26210fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
26220fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
26230fb67e98SDaniel Drake 	},
26240fb67e98SDaniel Drake 
26250fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
26260fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
26270fb67e98SDaniel Drake 	{}
26280fb67e98SDaniel Drake };
26290fb67e98SDaniel Drake 
2630254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2631254bba6aSEinar Rünkaru 	{
2632254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2633254bba6aSEinar Rünkaru 		.name = "Int Mic Boost Capture Enum",
2634254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2635254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2636254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2637254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2638254bba6aSEinar Rünkaru 	},
2639c0f8faf0SEinar Rünkaru 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2640254bba6aSEinar Rünkaru 	{}
2641254bba6aSEinar Rünkaru };
2642254bba6aSEinar Rünkaru 
26430fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
26440fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
26450fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
26460fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
26470fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
26480fb67e98SDaniel Drake 
26490fb67e98SDaniel Drake 	/* Speakers  */
26500fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26510fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26520fb67e98SDaniel Drake 
26530fb67e98SDaniel Drake 	/* HP, Amp  */
26540fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
26550fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26560fb67e98SDaniel Drake 
26570fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
26580fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
26590fb67e98SDaniel Drake 
26600fb67e98SDaniel Drake 	/* DAC1 */
26610fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
26620fb67e98SDaniel Drake 
26630fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
26640fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
26650fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
26660fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
26670fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
26680fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
26690fb67e98SDaniel Drake 
26700fb67e98SDaniel Drake 	/* no digital microphone support yet */
26710fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
26720fb67e98SDaniel Drake 
26730fb67e98SDaniel Drake 	/* Audio input selector */
26740fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
26750fb67e98SDaniel Drake 
26760fb67e98SDaniel Drake 	/* SPDIF route: PCM */
26770fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
26780fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
26790fb67e98SDaniel Drake 
26800fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26810fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
26820fb67e98SDaniel Drake 
26830fb67e98SDaniel Drake 	/* EAPD */
26840fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
26850fb67e98SDaniel Drake 
26860fb67e98SDaniel Drake 	/* not handling these yet */
26870fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26880fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26890fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26900fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26910fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26920fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26930fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26940fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
26950fb67e98SDaniel Drake 	{ } /* end */
26960fb67e98SDaniel Drake };
26970fb67e98SDaniel Drake 
26980fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
26990fb67e98SDaniel Drake 	/* Port A: headphones */
27000fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27010fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27020fb67e98SDaniel Drake 
27030fb67e98SDaniel Drake 	/* Port B: external microphone */
270475f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27050fb67e98SDaniel Drake 
27060fb67e98SDaniel Drake 	/* Port C: internal microphone */
270775f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27080fb67e98SDaniel Drake 
27090fb67e98SDaniel Drake 	/* Port D: unused */
27100fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27110fb67e98SDaniel Drake 
27120fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27130fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27140fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27150fb67e98SDaniel Drake 
2716c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27170fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27180fb67e98SDaniel Drake 
27190fb67e98SDaniel Drake 	/* Port G: internal speakers */
27200fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27210fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27220fb67e98SDaniel Drake 
27230fb67e98SDaniel Drake 	/* DAC1 */
27240fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27250fb67e98SDaniel Drake 
27260fb67e98SDaniel Drake 	/* DAC2: unused */
27270fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
27280fb67e98SDaniel Drake 
27290fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27300fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27310fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27320fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27330fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27340fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27350fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27360fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27370fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27380fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27390fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27400fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27410fb67e98SDaniel Drake 
27420fb67e98SDaniel Drake 	/* Disable digital microphone port */
27430fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27440fb67e98SDaniel Drake 
27450fb67e98SDaniel Drake 	/* Audio input selectors */
27460fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27470fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
27480fb67e98SDaniel Drake 
27490fb67e98SDaniel Drake 	/* Disable SPDIF */
27500fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27510fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27520fb67e98SDaniel Drake 
27530fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
27540fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
27550fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
27560fb67e98SDaniel Drake 	{ } /* end */
27570fb67e98SDaniel Drake };
27580fb67e98SDaniel Drake 
275995a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
276095a618bdSEinar Rünkaru 	/* Port A: headphones */
276195a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
276295a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
276395a618bdSEinar Rünkaru 
276495a618bdSEinar Rünkaru 	/* Port B: external microphone */
276595a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
276695a618bdSEinar Rünkaru 
276795a618bdSEinar Rünkaru 	/* Port C: unused */
276895a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
276995a618bdSEinar Rünkaru 
277095a618bdSEinar Rünkaru 	/* Port D: unused */
277195a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
277295a618bdSEinar Rünkaru 
277395a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
277495a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
277595a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
277695a618bdSEinar Rünkaru 
277795a618bdSEinar Rünkaru 	/* Port F: unused */
277895a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
277995a618bdSEinar Rünkaru 
278095a618bdSEinar Rünkaru 	/* Port G: internal speakers */
278195a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
278295a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
278395a618bdSEinar Rünkaru 
278495a618bdSEinar Rünkaru 	/* DAC1 */
278595a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
278695a618bdSEinar Rünkaru 
278795a618bdSEinar Rünkaru 	/* DAC2: unused */
278895a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
278995a618bdSEinar Rünkaru 
279095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
279195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
279295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
279395a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
279495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
279595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
279695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
279795a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
279895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
279995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
280095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
280195a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
280295a618bdSEinar Rünkaru 
280395a618bdSEinar Rünkaru 	/* Digital microphone port */
280495a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
280595a618bdSEinar Rünkaru 
280695a618bdSEinar Rünkaru 	/* Audio input selectors */
280795a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
280895a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
280995a618bdSEinar Rünkaru 
281095a618bdSEinar Rünkaru 	/* Disable SPDIF */
281195a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
281295a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
281395a618bdSEinar Rünkaru 
281495a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
281595a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
281695a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
281795a618bdSEinar Rünkaru 	{ } /* end */
281895a618bdSEinar Rünkaru };
281995a618bdSEinar Rünkaru 
2820cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2821cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2822cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2823cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2824cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2825cfd3d8dcSGreg Alexander 
2826cfd3d8dcSGreg Alexander 	/* Speakers  */
2827cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2828cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2829cfd3d8dcSGreg Alexander 
2830cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2831cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2832cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2833cfd3d8dcSGreg Alexander 
2834cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2835cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2836cfd3d8dcSGreg Alexander 
2837cfd3d8dcSGreg Alexander 	/* DAC1 */
2838cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2839cfd3d8dcSGreg Alexander 
2840cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2841cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2842cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2843cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2844cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2845cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2846cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2847cfd3d8dcSGreg Alexander 
2848cfd3d8dcSGreg Alexander 	/* Audio input selector */
2849cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2850cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2851cfd3d8dcSGreg Alexander 
2852cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2853cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2854cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2855cfd3d8dcSGreg Alexander 
2856cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2857cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2858cfd3d8dcSGreg Alexander 
2859cfd3d8dcSGreg Alexander 	/* internal microphone */
2860cfd3d8dcSGreg Alexander 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2861cfd3d8dcSGreg Alexander 
2862cfd3d8dcSGreg Alexander 	/* EAPD */
2863cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2864cfd3d8dcSGreg Alexander 
2865cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2866cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2867cfd3d8dcSGreg Alexander 	{ } /* end */
2868cfd3d8dcSGreg Alexander };
2869cfd3d8dcSGreg Alexander 
28707b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
28717b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
28727b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
28737b2bfdbcSJens Taprogge 
28747b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
28757b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
28767b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28777b2bfdbcSJens Taprogge 
28787b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
28797b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28807b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28817b2bfdbcSJens Taprogge 
28827b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
28837b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28847b2bfdbcSJens Taprogge 
28857b2bfdbcSJens Taprogge 	/* Port C: Mic */
28867b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28877b2bfdbcSJens Taprogge 
28887b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
28897b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28907b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
28917b2bfdbcSJens Taprogge 
28927b2bfdbcSJens Taprogge 	/* DAC1 */
28937b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
28947b2bfdbcSJens Taprogge 
28957b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
28967b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
28977b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
28987b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
28997b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29007b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29017b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29027b2bfdbcSJens Taprogge 
29037b2bfdbcSJens Taprogge 	/* Audio input selector */
29047b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29057b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29067b2bfdbcSJens Taprogge 
29077b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29087b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29097b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29107b2bfdbcSJens Taprogge 
29117b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29127b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29137b2bfdbcSJens Taprogge 
29147b2bfdbcSJens Taprogge 	/* internal microphone */
29157b2bfdbcSJens Taprogge 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
29167b2bfdbcSJens Taprogge 
29177b2bfdbcSJens Taprogge 	/* EAPD */
29187b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
29197b2bfdbcSJens Taprogge 
29207b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
29217b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29227b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29237b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29247b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29257b2bfdbcSJens Taprogge 	{ } /* end */
29267b2bfdbcSJens Taprogge };
29277b2bfdbcSJens Taprogge 
29280fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
29290fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29300fb67e98SDaniel Drake 	{ } /* end */
29310fb67e98SDaniel Drake };
29320fb67e98SDaniel Drake 
29330fb67e98SDaniel Drake /* initialize jack-sensing, too */
29340fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
29350fb67e98SDaniel Drake {
2936254bba6aSEinar Rünkaru 	struct conexant_spec *spec = codec->spec;
2937254bba6aSEinar Rünkaru 
29380fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
29390fb67e98SDaniel Drake 	conexant_init(codec);
29400fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
29410fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
2942254bba6aSEinar Rünkaru 		if (spec->dell_vostro)
2943254bba6aSEinar Rünkaru 			cxt5066_vostro_automic(codec);
2944cfd3d8dcSGreg Alexander 		else if (spec->ideapad)
2945cfd3d8dcSGreg Alexander 			cxt5066_ideapad_automic(codec);
29467b2bfdbcSJens Taprogge 		else if (spec->thinkpad)
29477b2bfdbcSJens Taprogge 			cxt5066_thinkpad_automic(codec);
29480fb67e98SDaniel Drake 	}
2949c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
29500fb67e98SDaniel Drake 	return 0;
29510fb67e98SDaniel Drake }
29520fb67e98SDaniel Drake 
295375f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
295475f8991dSDaniel Drake {
2955c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
295675f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
295775f8991dSDaniel Drake 	conexant_init(codec);
295875f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
2959c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
2960c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
296175f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
2962c4cfe66cSDaniel Drake 	} else {
2963c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2964c4cfe66cSDaniel Drake 	}
296575f8991dSDaniel Drake 	return 0;
296675f8991dSDaniel Drake }
296775f8991dSDaniel Drake 
29680fb67e98SDaniel Drake enum {
29690fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
29700fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
29710fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
297295a618bdSEinar Rünkaru 	CXT5066_DELL_VOSTO,	/* Dell Vostro 1015i */
2973cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
29747b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
29750fb67e98SDaniel Drake 	CXT5066_MODELS
29760fb67e98SDaniel Drake };
29770fb67e98SDaniel Drake 
29780fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = {
29790fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
29800fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
29810fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
2982cfd3d8dcSGreg Alexander 	[CXT5066_DELL_VOSTO]    = "dell-vostro",
2983cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
29847b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
29850fb67e98SDaniel Drake };
29860fb67e98SDaniel Drake 
29870fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
29880fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
29890fb67e98SDaniel Drake 		      CXT5066_LAPTOP),
29900fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
29910fb67e98SDaniel Drake 		      CXT5066_DELL_LAPTOP),
2992798a8a15SDaniel Drake 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
299395a618bdSEinar Rünkaru 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
2994231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
2995c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
29964442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
29970217f149SAndrej Gelenberg 	SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
2998badf18b5SAndreas Herrmann 	SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
2999a39e33ebSJerone Young 	SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
3000cfd3d8dcSGreg Alexander 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
30017b2bfdbcSJens Taprogge 	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
30020fb67e98SDaniel Drake 	{}
30030fb67e98SDaniel Drake };
30040fb67e98SDaniel Drake 
30050fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
30060fb67e98SDaniel Drake {
30070fb67e98SDaniel Drake 	struct conexant_spec *spec;
30080fb67e98SDaniel Drake 	int board_config;
30090fb67e98SDaniel Drake 
30100fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
30110fb67e98SDaniel Drake 	if (!spec)
30120fb67e98SDaniel Drake 		return -ENOMEM;
30130fb67e98SDaniel Drake 	codec->spec = spec;
30140fb67e98SDaniel Drake 
30150fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
301675f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
30170fb67e98SDaniel Drake 
30180fb67e98SDaniel Drake 	spec->dell_automute = 0;
30190fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
30200fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
30210fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
30220fb67e98SDaniel Drake 	spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
30230fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
30240fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
30250fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
30260fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
30270fb67e98SDaniel Drake 
30280fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
30290fb67e98SDaniel Drake 
30300fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
30310fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
30320fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
30330fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
30340fb67e98SDaniel Drake 	spec->cur_adc = 0;
30350fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
30360fb67e98SDaniel Drake 
30370fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
30380fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
30390fb67e98SDaniel Drake 	switch (board_config) {
30400fb67e98SDaniel Drake 	default:
30410fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
30420fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
30430fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30440fb67e98SDaniel Drake 		break;
30450fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
30460fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
30470fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30480fb67e98SDaniel Drake 
30490fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
30500fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
30510fb67e98SDaniel Drake 		spec->num_init_verbs++;
30520fb67e98SDaniel Drake 		spec->dell_automute = 1;
30530fb67e98SDaniel Drake 		break;
30540fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
305575f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
305675f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
30570fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
30580fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3059c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
30600fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
30610fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3062c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
30630fb67e98SDaniel Drake 
30640fb67e98SDaniel Drake 		/* no S/PDIF out */
30650fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
30660fb67e98SDaniel Drake 
30670fb67e98SDaniel Drake 		/* input source automatically selected */
30680fb67e98SDaniel Drake 		spec->input_mux = NULL;
306975f8991dSDaniel Drake 
307075f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
307175f8991dSDaniel Drake 		 * at the right time */
307275f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
307375f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
30740fb67e98SDaniel Drake 		break;
307595a618bdSEinar Rünkaru 	case CXT5066_DELL_VOSTO:
307675f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
307795a618bdSEinar Rünkaru 		codec->patch_ops.unsol_event = cxt5066_vostro_event;
307895a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
307995a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
308095a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3081254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
308295a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3083254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3084c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
3085c0f8faf0SEinar Rünkaru 		snd_hda_attach_beep_device(codec, 0x13);
308695a618bdSEinar Rünkaru 
308795a618bdSEinar Rünkaru 		/* no S/PDIF out */
308895a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
308995a618bdSEinar Rünkaru 
309095a618bdSEinar Rünkaru 		/* input source automatically selected */
309195a618bdSEinar Rünkaru 		spec->input_mux = NULL;
309295a618bdSEinar Rünkaru 		break;
3093cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3094cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
3095cfd3d8dcSGreg Alexander 		codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3096cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3097cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3098cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3099cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3100cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3101cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3102cfd3d8dcSGreg Alexander 
3103cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3104cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3105cfd3d8dcSGreg Alexander 
3106cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3107cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3108cfd3d8dcSGreg Alexander 		break;
31097b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
31107b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
31117b2bfdbcSJens Taprogge 		codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
31127b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31137b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31147b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
31157b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
31167b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
31177b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
31187b2bfdbcSJens Taprogge 
31197b2bfdbcSJens Taprogge 		/* no S/PDIF out */
31207b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
31217b2bfdbcSJens Taprogge 
31227b2bfdbcSJens Taprogge 		/* input source automatically selected */
31237b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
31247b2bfdbcSJens Taprogge 		break;
31250fb67e98SDaniel Drake 	}
31260fb67e98SDaniel Drake 
31270fb67e98SDaniel Drake 	return 0;
31280fb67e98SDaniel Drake }
3129461e2c78STakashi Iwai 
3130461e2c78STakashi Iwai /*
3131461e2c78STakashi Iwai  */
3132461e2c78STakashi Iwai 
31331289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
313482f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
313582f30040STobin Davis 	  .patch = patch_cxt5045 },
313682f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
313782f30040STobin Davis 	  .patch = patch_cxt5047 },
3138461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3139461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
31400fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
31410fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
314295a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
314395a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
31447b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
31457b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
3146c9b443d4STobin Davis 	{} /* terminator */
3147c9b443d4STobin Davis };
31481289e9e8STakashi Iwai 
31491289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
31501289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
31511289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
31520fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
315395a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
31547b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
31551289e9e8STakashi Iwai 
31561289e9e8STakashi Iwai MODULE_LICENSE("GPL");
31571289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
31581289e9e8STakashi Iwai 
31591289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
31601289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
31611289e9e8STakashi Iwai 	.owner = THIS_MODULE,
31621289e9e8STakashi Iwai };
31631289e9e8STakashi Iwai 
31641289e9e8STakashi Iwai static int __init patch_conexant_init(void)
31651289e9e8STakashi Iwai {
31661289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
31671289e9e8STakashi Iwai }
31681289e9e8STakashi Iwai 
31691289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
31701289e9e8STakashi Iwai {
31711289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
31721289e9e8STakashi Iwai }
31731289e9e8STakashi Iwai 
31741289e9e8STakashi Iwai module_init(patch_conexant_init)
31751289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3176