xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision 6f0ef6ea1d11ef242de584e345355b0de756fcb2)
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 */
1343507e2a8STakashi Iwai 
1353507e2a8STakashi Iwai 	unsigned int beep_amp;
136c9b443d4STobin Davis };
137c9b443d4STobin Davis 
138c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
139c9b443d4STobin Davis 				      struct hda_codec *codec,
140c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
141c9b443d4STobin Davis {
142c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1439a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1449a08160bSTakashi Iwai 					     hinfo);
145c9b443d4STobin Davis }
146c9b443d4STobin Davis 
147c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
148c9b443d4STobin Davis 					 struct hda_codec *codec,
149c9b443d4STobin Davis 					 unsigned int stream_tag,
150c9b443d4STobin Davis 					 unsigned int format,
151c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
152c9b443d4STobin Davis {
153c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
154c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
155c9b443d4STobin Davis 						stream_tag,
156c9b443d4STobin Davis 						format, substream);
157c9b443d4STobin Davis }
158c9b443d4STobin Davis 
159c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
160c9b443d4STobin Davis 					 struct hda_codec *codec,
161c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
162c9b443d4STobin Davis {
163c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
164c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
165c9b443d4STobin Davis }
166c9b443d4STobin Davis 
167c9b443d4STobin Davis /*
168c9b443d4STobin Davis  * Digital out
169c9b443d4STobin Davis  */
170c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
171c9b443d4STobin Davis 					  struct hda_codec *codec,
172c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
173c9b443d4STobin Davis {
174c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
175c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
176c9b443d4STobin Davis }
177c9b443d4STobin Davis 
178c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
179c9b443d4STobin Davis 					 struct hda_codec *codec,
180c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
181c9b443d4STobin Davis {
182c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
183c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
184c9b443d4STobin Davis }
185c9b443d4STobin Davis 
1866b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1876b97eb45STakashi Iwai 					 struct hda_codec *codec,
1886b97eb45STakashi Iwai 					 unsigned int stream_tag,
1896b97eb45STakashi Iwai 					 unsigned int format,
1906b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1916b97eb45STakashi Iwai {
1926b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1936b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1946b97eb45STakashi Iwai 					     stream_tag,
1956b97eb45STakashi Iwai 					     format, substream);
1966b97eb45STakashi Iwai }
1976b97eb45STakashi Iwai 
198c9b443d4STobin Davis /*
199c9b443d4STobin Davis  * Analog capture
200c9b443d4STobin Davis  */
201c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
202c9b443d4STobin Davis 				      struct hda_codec *codec,
203c9b443d4STobin Davis 				      unsigned int stream_tag,
204c9b443d4STobin Davis 				      unsigned int format,
205c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
206c9b443d4STobin Davis {
207c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
20875f8991dSDaniel Drake 	if (spec->capture_prepare)
20975f8991dSDaniel Drake 		spec->capture_prepare(codec);
210c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
211c9b443d4STobin Davis 				   stream_tag, 0, format);
212c9b443d4STobin Davis 	return 0;
213c9b443d4STobin Davis }
214c9b443d4STobin Davis 
215c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
216c9b443d4STobin Davis 				      struct hda_codec *codec,
217c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
218c9b443d4STobin Davis {
219c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
220888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
22175f8991dSDaniel Drake 	if (spec->capture_cleanup)
22275f8991dSDaniel Drake 		spec->capture_cleanup(codec);
223c9b443d4STobin Davis 	return 0;
224c9b443d4STobin Davis }
225c9b443d4STobin Davis 
226c9b443d4STobin Davis 
227c9b443d4STobin Davis 
228c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
229c9b443d4STobin Davis 	.substreams = 1,
230c9b443d4STobin Davis 	.channels_min = 2,
231c9b443d4STobin Davis 	.channels_max = 2,
232c9b443d4STobin Davis 	.nid = 0, /* fill later */
233c9b443d4STobin Davis 	.ops = {
234c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
235c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
236c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
237c9b443d4STobin Davis 	},
238c9b443d4STobin Davis };
239c9b443d4STobin Davis 
240c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
241c9b443d4STobin Davis 	.substreams = 1,
242c9b443d4STobin Davis 	.channels_min = 2,
243c9b443d4STobin Davis 	.channels_max = 2,
244c9b443d4STobin Davis 	.nid = 0, /* fill later */
245c9b443d4STobin Davis 	.ops = {
246c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
247c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
248c9b443d4STobin Davis 	},
249c9b443d4STobin Davis };
250c9b443d4STobin Davis 
251c9b443d4STobin Davis 
252c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_playback = {
253c9b443d4STobin Davis 	.substreams = 1,
254c9b443d4STobin Davis 	.channels_min = 2,
255c9b443d4STobin Davis 	.channels_max = 2,
256c9b443d4STobin Davis 	.nid = 0, /* fill later */
257c9b443d4STobin Davis 	.ops = {
258c9b443d4STobin Davis 		.open = conexant_dig_playback_pcm_open,
2596b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2606b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
261c9b443d4STobin Davis 	},
262c9b443d4STobin Davis };
263c9b443d4STobin Davis 
264c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
265c9b443d4STobin Davis 	.substreams = 1,
266c9b443d4STobin Davis 	.channels_min = 2,
267c9b443d4STobin Davis 	.channels_max = 2,
268c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
269c9b443d4STobin Davis };
270c9b443d4STobin Davis 
271461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
272461e2c78STakashi Iwai 				      struct hda_codec *codec,
273461e2c78STakashi Iwai 				      unsigned int stream_tag,
274461e2c78STakashi Iwai 				      unsigned int format,
275461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
276461e2c78STakashi Iwai {
277461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
278461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
279461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
280461e2c78STakashi Iwai 	spec->cur_adc_format = format;
281461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
282461e2c78STakashi Iwai 	return 0;
283461e2c78STakashi Iwai }
284461e2c78STakashi Iwai 
285461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
286461e2c78STakashi Iwai 				      struct hda_codec *codec,
287461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
288461e2c78STakashi Iwai {
289461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
290888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
291461e2c78STakashi Iwai 	spec->cur_adc = 0;
292461e2c78STakashi Iwai 	return 0;
293461e2c78STakashi Iwai }
294461e2c78STakashi Iwai 
295461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
296461e2c78STakashi Iwai 	.substreams = 1,
297461e2c78STakashi Iwai 	.channels_min = 2,
298461e2c78STakashi Iwai 	.channels_max = 2,
299461e2c78STakashi Iwai 	.nid = 0, /* fill later */
300461e2c78STakashi Iwai 	.ops = {
301461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
302461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
303461e2c78STakashi Iwai 	},
304461e2c78STakashi Iwai };
305461e2c78STakashi Iwai 
306c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
307c9b443d4STobin Davis {
308c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
309c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
310c9b443d4STobin Davis 
311c9b443d4STobin Davis 	codec->num_pcms = 1;
312c9b443d4STobin Davis 	codec->pcm_info = info;
313c9b443d4STobin Davis 
314c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
315c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
316c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
317c9b443d4STobin Davis 		spec->multiout.max_channels;
318c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
319c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
320461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
321461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
322461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
323461e2c78STakashi Iwai 	else
324461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
325461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
326c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
327c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
328c9b443d4STobin Davis 
329c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
330c9b443d4STobin Davis 		info++;
331c9b443d4STobin Davis 		codec->num_pcms++;
332c9b443d4STobin Davis 		info->name = "Conexant Digital";
3337ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
334c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
335c9b443d4STobin Davis 			conexant_pcm_digital_playback;
336c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
337c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
338c9b443d4STobin Davis 		if (spec->dig_in_nid) {
339c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
340c9b443d4STobin Davis 				conexant_pcm_digital_capture;
341c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
342c9b443d4STobin Davis 				spec->dig_in_nid;
343c9b443d4STobin Davis 		}
344c9b443d4STobin Davis 	}
345c9b443d4STobin Davis 
346c9b443d4STobin Davis 	return 0;
347c9b443d4STobin Davis }
348c9b443d4STobin Davis 
349c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
350c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
351c9b443d4STobin Davis {
352c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
354c9b443d4STobin Davis 
355c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
356c9b443d4STobin Davis }
357c9b443d4STobin Davis 
358c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
359c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
360c9b443d4STobin Davis {
361c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
362c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
363c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
364c9b443d4STobin Davis 
365c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
366c9b443d4STobin Davis 	return 0;
367c9b443d4STobin Davis }
368c9b443d4STobin Davis 
369c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
370c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
371c9b443d4STobin Davis {
372c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
373c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
374c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
375c9b443d4STobin Davis 
376c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
377c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
378c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
379c9b443d4STobin Davis }
380c9b443d4STobin Davis 
3818c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
38295c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack)
38395c09099STakashi Iwai {
38495c09099STakashi Iwai 	struct conexant_jack *jacks = jack->private_data;
38595c09099STakashi Iwai 	jacks->nid = 0;
38695c09099STakashi Iwai 	jacks->jack = NULL;
38795c09099STakashi Iwai }
38895c09099STakashi Iwai 
389bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
390bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
391bc7a166dSUlrich Dangel {
392bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
393bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
394bc7a166dSUlrich Dangel 	const char *name;
39595c09099STakashi Iwai 	int err;
396bc7a166dSUlrich Dangel 
397bc7a166dSUlrich Dangel 	spec = codec->spec;
398bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
399bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
400bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
401bc7a166dSUlrich Dangel 
402bc7a166dSUlrich Dangel 	if (!jack)
403bc7a166dSUlrich Dangel 		return -ENOMEM;
404bc7a166dSUlrich Dangel 
405bc7a166dSUlrich Dangel 	jack->nid = nid;
406bc7a166dSUlrich Dangel 	jack->type = type;
407bc7a166dSUlrich Dangel 
40895c09099STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
40995c09099STakashi Iwai 	if (err < 0)
41095c09099STakashi Iwai 		return err;
41195c09099STakashi Iwai 	jack->jack->private_data = jack;
41295c09099STakashi Iwai 	jack->jack->private_free = conexant_free_jack_priv;
41395c09099STakashi Iwai 	return 0;
414bc7a166dSUlrich Dangel }
415bc7a166dSUlrich Dangel 
416bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
417bc7a166dSUlrich Dangel {
418bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
419bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
420bc7a166dSUlrich Dangel 
421bc7a166dSUlrich Dangel 	if (jacks) {
422bc7a166dSUlrich Dangel 		int i;
423bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
424bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
425bc7a166dSUlrich Dangel 				unsigned int present;
426d56757abSTakashi Iwai 				present = snd_hda_jack_detect(codec, nid);
427bc7a166dSUlrich Dangel 
428bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
429bc7a166dSUlrich Dangel 
430bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
431bc7a166dSUlrich Dangel 						present);
432bc7a166dSUlrich Dangel 			}
433bc7a166dSUlrich Dangel 			jacks++;
434bc7a166dSUlrich Dangel 		}
435bc7a166dSUlrich Dangel 	}
436bc7a166dSUlrich Dangel }
437bc7a166dSUlrich Dangel 
438bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
439bc7a166dSUlrich Dangel {
440bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
441bc7a166dSUlrich Dangel 	int i;
442bc7a166dSUlrich Dangel 
443bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
444bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
445bc7a166dSUlrich Dangel 
446bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
447bc7a166dSUlrich Dangel 		while (hv->nid) {
448bc7a166dSUlrich Dangel 			int err = 0;
449bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
450bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
451bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
452bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
453bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
454bc7a166dSUlrich Dangel 				break;
455bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
456bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
457bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
458bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
459bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
460bc7a166dSUlrich Dangel 				break;
461bc7a166dSUlrich Dangel 			}
462bc7a166dSUlrich Dangel 			if (err < 0)
463bc7a166dSUlrich Dangel 				return err;
464bc7a166dSUlrich Dangel 			++hv;
465bc7a166dSUlrich Dangel 		}
466bc7a166dSUlrich Dangel 	}
467bc7a166dSUlrich Dangel 	return 0;
468bc7a166dSUlrich Dangel 
469bc7a166dSUlrich Dangel }
4705801f992STakashi Iwai #else
4715801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
4725801f992STakashi Iwai {
4735801f992STakashi Iwai }
4745801f992STakashi Iwai 
4755801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
4765801f992STakashi Iwai {
4775801f992STakashi Iwai 	return 0;
4785801f992STakashi Iwai }
4795801f992STakashi Iwai #endif
480bc7a166dSUlrich Dangel 
481c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
482c9b443d4STobin Davis {
483c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
484c9b443d4STobin Davis 	int i;
485c9b443d4STobin Davis 
486c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
487c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
488c9b443d4STobin Davis 	return 0;
489c9b443d4STobin Davis }
490c9b443d4STobin Davis 
491c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
492c9b443d4STobin Davis {
4938c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
494bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
495bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
496bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
497bc7a166dSUlrich Dangel 		int i;
49895c09099STakashi Iwai 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
49995c09099STakashi Iwai 			if (jacks->jack)
50095c09099STakashi Iwai 				snd_device_free(codec->bus->card, jacks->jack);
50195c09099STakashi Iwai 		}
502bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
503bc7a166dSUlrich Dangel 	}
504bc7a166dSUlrich Dangel #endif
505c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
506c9b443d4STobin Davis 	kfree(codec->spec);
507c9b443d4STobin Davis }
508c9b443d4STobin Davis 
509b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
510b880c74aSTakashi Iwai 	{
511b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
512b880c74aSTakashi Iwai 		.name = "Capture Source",
513b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
514b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
515b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
516b880c74aSTakashi Iwai 	},
517b880c74aSTakashi Iwai 	{}
518b880c74aSTakashi Iwai };
519b880c74aSTakashi Iwai 
5203507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5213507e2a8STakashi Iwai /* additional beep mixers; the actual parameters are overwritten at build */
5223507e2a8STakashi Iwai static struct snd_kcontrol_new cxt_beep_mixer[] = {
5233507e2a8STakashi Iwai 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
5243507e2a8STakashi Iwai 	HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
5253507e2a8STakashi Iwai 	{ } /* end */
5263507e2a8STakashi Iwai };
5273507e2a8STakashi Iwai #endif
5283507e2a8STakashi Iwai 
529dd5746a8STakashi Iwai static const char *slave_vols[] = {
530dd5746a8STakashi Iwai 	"Headphone Playback Volume",
531dd5746a8STakashi Iwai 	"Speaker Playback Volume",
532dd5746a8STakashi Iwai 	NULL
533dd5746a8STakashi Iwai };
534dd5746a8STakashi Iwai 
535dd5746a8STakashi Iwai static const char *slave_sws[] = {
536dd5746a8STakashi Iwai 	"Headphone Playback Switch",
537dd5746a8STakashi Iwai 	"Speaker Playback Switch",
538dd5746a8STakashi Iwai 	NULL
539dd5746a8STakashi Iwai };
540dd5746a8STakashi Iwai 
541c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
542c9b443d4STobin Davis {
543c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
544c9b443d4STobin Davis 	unsigned int i;
545c9b443d4STobin Davis 	int err;
546c9b443d4STobin Davis 
547c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
548c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
549c9b443d4STobin Davis 		if (err < 0)
550c9b443d4STobin Davis 			return err;
551c9b443d4STobin Davis 	}
552c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
553c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
554c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
555c9b443d4STobin Davis 		if (err < 0)
556c9b443d4STobin Davis 			return err;
5579a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5589a08160bSTakashi Iwai 						    &spec->multiout);
5599a08160bSTakashi Iwai 		if (err < 0)
5609a08160bSTakashi Iwai 			return err;
5619a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
562c9b443d4STobin Davis 	}
563c9b443d4STobin Davis 	if (spec->dig_in_nid) {
564c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
565c9b443d4STobin Davis 		if (err < 0)
566c9b443d4STobin Davis 			return err;
567c9b443d4STobin Davis 	}
568dd5746a8STakashi Iwai 
569dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
570dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
571dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
572dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
573dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
574dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
575dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
576dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
577dd5746a8STakashi Iwai 		if (err < 0)
578dd5746a8STakashi Iwai 			return err;
579dd5746a8STakashi Iwai 	}
580dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
581dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
582dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
583dd5746a8STakashi Iwai 					  NULL, slave_sws);
584dd5746a8STakashi Iwai 		if (err < 0)
585dd5746a8STakashi Iwai 			return err;
586dd5746a8STakashi Iwai 	}
587dd5746a8STakashi Iwai 
588b880c74aSTakashi Iwai 	if (spec->input_mux) {
589b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
590b880c74aSTakashi Iwai 		if (err < 0)
591b880c74aSTakashi Iwai 			return err;
592b880c74aSTakashi Iwai 	}
593b880c74aSTakashi Iwai 
5943507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
5953507e2a8STakashi Iwai 	/* create beep controls if needed */
5963507e2a8STakashi Iwai 	if (spec->beep_amp) {
5973507e2a8STakashi Iwai 		struct snd_kcontrol_new *knew;
5983507e2a8STakashi Iwai 		for (knew = cxt_beep_mixer; knew->name; knew++) {
5993507e2a8STakashi Iwai 			struct snd_kcontrol *kctl;
6003507e2a8STakashi Iwai 			kctl = snd_ctl_new1(knew, codec);
6013507e2a8STakashi Iwai 			if (!kctl)
6023507e2a8STakashi Iwai 				return -ENOMEM;
6033507e2a8STakashi Iwai 			kctl->private_value = spec->beep_amp;
6043507e2a8STakashi Iwai 			err = snd_hda_ctl_add(codec, 0, kctl);
6053507e2a8STakashi Iwai 			if (err < 0)
6063507e2a8STakashi Iwai 				return err;
6073507e2a8STakashi Iwai 		}
6083507e2a8STakashi Iwai 	}
6093507e2a8STakashi Iwai #endif
6103507e2a8STakashi Iwai 
611c9b443d4STobin Davis 	return 0;
612c9b443d4STobin Davis }
613c9b443d4STobin Davis 
614697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
615697c373eSTakashi Iwai static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
616697c373eSTakashi Iwai {
617697c373eSTakashi Iwai 	snd_hda_shutup_pins(codec);
618697c373eSTakashi Iwai 	return 0;
619697c373eSTakashi Iwai }
620697c373eSTakashi Iwai #endif
621697c373eSTakashi Iwai 
622c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
623c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
624c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
625c9b443d4STobin Davis 	.init = conexant_init,
626c9b443d4STobin Davis 	.free = conexant_free,
627697c373eSTakashi Iwai #ifdef CONFIG_SND_HDA_POWER_SAVE
628697c373eSTakashi Iwai 	.suspend = conexant_suspend,
629697c373eSTakashi Iwai #endif
630697c373eSTakashi Iwai 	.reboot_notify = snd_hda_shutup_pins,
631c9b443d4STobin Davis };
632c9b443d4STobin Davis 
6333507e2a8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_BEEP
6343507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) \
6353507e2a8STakashi Iwai 	((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
6363507e2a8STakashi Iwai #else
6373507e2a8STakashi Iwai #define set_beep_amp(spec, nid, idx, dir) /* NOP */
6383507e2a8STakashi Iwai #endif
6393507e2a8STakashi Iwai 
640c9b443d4STobin Davis /*
641c9b443d4STobin Davis  * EAPD control
642c9b443d4STobin Davis  * the private value = nid | (invert << 8)
643c9b443d4STobin Davis  */
644c9b443d4STobin Davis 
645a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
646c9b443d4STobin Davis 
64782f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
648c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
649c9b443d4STobin Davis {
650c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
652c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
653c9b443d4STobin Davis 	if (invert)
654c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
655c9b443d4STobin Davis 	else
656c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
657c9b443d4STobin Davis 	return 0;
65882f30040STobin Davis 
659c9b443d4STobin Davis }
660c9b443d4STobin Davis 
66182f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
662c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
663c9b443d4STobin Davis {
664c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
665c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
666c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
667c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
668c9b443d4STobin Davis 	unsigned int eapd;
66982f30040STobin Davis 
67068ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
671c9b443d4STobin Davis 	if (invert)
672c9b443d4STobin Davis 		eapd = !eapd;
67382beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
674c9b443d4STobin Davis 		return 0;
67582f30040STobin Davis 
676c9b443d4STobin Davis 	spec->cur_eapd = eapd;
67782beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
678c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
679c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
680c9b443d4STobin Davis 	return 1;
681c9b443d4STobin Davis }
682c9b443d4STobin Davis 
68386d72bdfSTakashi Iwai /* controls for test mode */
68486d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
68586d72bdfSTakashi Iwai 
68682f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
68782f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
68882f30040STobin Davis 	  .info = cxt_eapd_info, \
68982f30040STobin Davis 	  .get = cxt_eapd_get, \
69082f30040STobin Davis 	  .put = cxt_eapd_put, \
69182f30040STobin Davis 	  .private_value = nid | (mask<<16) }
69282f30040STobin Davis 
69382f30040STobin Davis 
69482f30040STobin Davis 
695c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
696c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
697c9b443d4STobin Davis {
698c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
699c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
700c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
701c9b443d4STobin Davis 				    spec->num_channel_mode);
702c9b443d4STobin Davis }
703c9b443d4STobin Davis 
704c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
705c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
706c9b443d4STobin Davis {
707c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
708c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
709c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
710c9b443d4STobin Davis 				   spec->num_channel_mode,
711c9b443d4STobin Davis 				   spec->multiout.max_channels);
712c9b443d4STobin Davis }
713c9b443d4STobin Davis 
714c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
715c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
716c9b443d4STobin Davis {
717c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
719c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
720c9b443d4STobin Davis 				      spec->num_channel_mode,
721c9b443d4STobin Davis 				      &spec->multiout.max_channels);
722c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
723c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
724c9b443d4STobin Davis 	return err;
725c9b443d4STobin Davis }
726c9b443d4STobin Davis 
727c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
728c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
729c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
730c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
731c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
732c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
733c9b443d4STobin Davis 
73486d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
73586d72bdfSTakashi Iwai 
736c9b443d4STobin Davis /* Conexant 5045 specific */
737c9b443d4STobin Davis 
738c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
739c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
740c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
741cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
742c9b443d4STobin Davis 
7435cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
7445cd57529STobin Davis 	{ 2, NULL },
7455cd57529STobin Davis };
746c9b443d4STobin Davis 
747c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
748c9b443d4STobin Davis 	.num_items = 2,
749c9b443d4STobin Davis 	.items = {
75082f30040STobin Davis 		{ "IntMic", 0x1 },
751f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
752c9b443d4STobin Davis 	}
753c9b443d4STobin Davis };
754c9b443d4STobin Davis 
7555218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
75622e14130SLukasz Marcinowski 	.num_items = 5,
7575218c892SJiang Zhe 	.items = {
7585218c892SJiang Zhe 		{ "IntMic", 0x1 },
7595218c892SJiang Zhe 		{ "ExtMic", 0x2 },
7605218c892SJiang Zhe 		{ "LineIn", 0x3 },
76122e14130SLukasz Marcinowski 		{ "CD",     0x4 },
76222e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
7635218c892SJiang Zhe 	}
7645218c892SJiang Zhe };
7655218c892SJiang Zhe 
7662de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
7672de3c232SJiang zhe 	.num_items = 2,
7682de3c232SJiang zhe 	.items = {
7692de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7702de3c232SJiang zhe 		{ "IntMic", 0x2 },
7712de3c232SJiang zhe 	}
7722de3c232SJiang zhe };
7732de3c232SJiang zhe 
774c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
775c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
776c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
777c9b443d4STobin Davis {
778c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
779c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
78082f30040STobin Davis 	unsigned int bits;
781c9b443d4STobin Davis 
78282f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
783c9b443d4STobin Davis 		return 0;
784c9b443d4STobin Davis 
78582f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
78682f30040STobin Davis 	 * the headphone jack
78782f30040STobin Davis 	 */
78847fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
78947fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
79047fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7917f29673bSTobin Davis 
79247fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
79347fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
79447fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
795c9b443d4STobin Davis 	return 1;
796c9b443d4STobin Davis }
797c9b443d4STobin Davis 
798c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
799cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
800cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
801cca3b371STakashi Iwai 	.values = {
802cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
803cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
804cca3b371STakashi Iwai 		0
805cca3b371STakashi Iwai 	},
806cca3b371STakashi Iwai };
807c9b443d4STobin Davis 
8087f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
8097f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
8107f29673bSTobin Davis {
8117f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
8127f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
8137f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
8147f29673bSTobin Davis 		{}
8157f29673bSTobin Davis 	};
8167f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
8177f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
8187f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
8197f29673bSTobin Davis 		{}
8207f29673bSTobin Davis 	};
8217f29673bSTobin Davis 	unsigned int present;
8227f29673bSTobin Davis 
823d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
8247f29673bSTobin Davis 	if (present)
8257f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
8267f29673bSTobin Davis 	else
8277f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
8287f29673bSTobin Davis }
8297f29673bSTobin Davis 
830c9b443d4STobin Davis 
831c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
832c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
833c9b443d4STobin Davis {
83482f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
835dd87da1cSTobin Davis 	unsigned int bits;
836c9b443d4STobin Davis 
837d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
838dd87da1cSTobin Davis 
83947fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
84047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
84147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
842c9b443d4STobin Davis }
843c9b443d4STobin Davis 
844c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
845c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
846c9b443d4STobin Davis 				   unsigned int res)
847c9b443d4STobin Davis {
848c9b443d4STobin Davis 	res >>= 26;
849c9b443d4STobin Davis 	switch (res) {
850c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
851c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
852c9b443d4STobin Davis 		break;
8537f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
8547f29673bSTobin Davis 		cxt5045_hp_automic(codec);
8557f29673bSTobin Davis 		break;
8567f29673bSTobin Davis 
857c9b443d4STobin Davis 	}
858c9b443d4STobin Davis }
859c9b443d4STobin Davis 
860c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
861c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
862c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
863c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
864c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
865c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
866c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
867c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
868c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
869c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
870c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
871cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
872c9b443d4STobin Davis 	{
873c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
874c9b443d4STobin Davis 		.name = "Master Playback Switch",
87582f30040STobin Davis 		.info = cxt_eapd_info,
87682f30040STobin Davis 		.get = cxt_eapd_get,
877c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
87882f30040STobin Davis 		.private_value = 0x10,
879c9b443d4STobin Davis 	},
880c9b443d4STobin Davis 
881c9b443d4STobin Davis 	{}
882c9b443d4STobin Davis };
883c9b443d4STobin Davis 
8845218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
88522e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
88622e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
88722e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
88822e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
88922e14130SLukasz Marcinowski 
8905218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8915218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8925218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8935218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8945218c892SJiang Zhe 
89522e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
89622e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
89722e14130SLukasz Marcinowski 
8985218c892SJiang Zhe 	{}
8995218c892SJiang Zhe };
9005218c892SJiang Zhe 
9012de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
9022de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
9032de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
9042de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
9052de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
9062de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
9072de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
9082de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
9092de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
9102de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
9112de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
9122de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
9132de3c232SJiang zhe 	{
9142de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
9152de3c232SJiang zhe 		.name = "Master Playback Switch",
9162de3c232SJiang zhe 		.info = cxt_eapd_info,
9172de3c232SJiang zhe 		.get = cxt_eapd_get,
9182de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
9192de3c232SJiang zhe 		.private_value = 0x10,
9202de3c232SJiang zhe 	},
9212de3c232SJiang zhe 
9222de3c232SJiang zhe 	{}
9232de3c232SJiang zhe };
9242de3c232SJiang zhe 
925c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
926c9b443d4STobin Davis 	/* Line in, Mic */
9274090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9287f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
929c9b443d4STobin Davis 	/* HP, Amp  */
930c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
931c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
93282f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
933c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
934c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
935c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
936c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
937c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
938c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
93982f30040STobin Davis 	/* Record selector: Int mic */
9407f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
94182f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
942c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
943c9b443d4STobin Davis 	/* SPDIF route: PCM */
944cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
945c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
946c9b443d4STobin Davis 	/* EAPD */
94782f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
948c9b443d4STobin Davis 	{ } /* end */
949c9b443d4STobin Davis };
950c9b443d4STobin Davis 
9515218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
9525218c892SJiang Zhe 	/* Int Mic, Mic */
9535218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9545218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
9555218c892SJiang Zhe 	/* Line In,HP, Amp  */
9565218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9575218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
9585218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9595218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
9605218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
9615218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9625218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
9635218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
9645218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
9655218c892SJiang Zhe 	/* Record selector: Int mic */
9665218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
9675218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
9685218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9695218c892SJiang Zhe 	/* SPDIF route: PCM */
970cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9715218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9725218c892SJiang Zhe 	/* EAPD */
9735218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9745218c892SJiang Zhe 	{ } /* end */
9755218c892SJiang Zhe };
9767f29673bSTobin Davis 
9777f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9787f29673bSTobin Davis 	/* pin sensing on HP jack */
9797f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
980d3091fadSTakashi Iwai 	{ } /* end */
9817f29673bSTobin Davis };
9827f29673bSTobin Davis 
9837f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9847f29673bSTobin Davis 	/* pin sensing on HP jack */
9857f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
986d3091fadSTakashi Iwai 	{ } /* end */
9877f29673bSTobin Davis };
9887f29673bSTobin Davis 
989c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
990c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
991c9b443d4STobin Davis  * configuration.
992c9b443d4STobin Davis  */
993c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
994c9b443d4STobin Davis 	.num_items = 5,
995c9b443d4STobin Davis 	.items = {
996c9b443d4STobin Davis 		{ "MIXER", 0x0 },
997c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
998c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
999c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
1000c9b443d4STobin Davis 		{ "CD pin", 0x4 },
1001c9b443d4STobin Davis         },
1002c9b443d4STobin Davis };
1003c9b443d4STobin Davis 
1004c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
1005c9b443d4STobin Davis 
1006c9b443d4STobin Davis 	/* Output controls */
1007c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1008c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
10097f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
10107f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
10117f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
10127f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1013c9b443d4STobin Davis 
1014c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1015c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
1016c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
1017c9b443d4STobin Davis 
101882f30040STobin Davis 	/* EAPD Switch Control */
101982f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
102082f30040STobin Davis 
1021c9b443d4STobin Davis 	/* Loopback mixer controls */
1022c9b443d4STobin Davis 
10237f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
10247f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
10257f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
10267f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
10277f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
10287f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
10297f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
10307f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
10317f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
10327f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
1033c9b443d4STobin Davis 	{
1034c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1035c9b443d4STobin Davis 		.name = "Input Source",
1036c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1037c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1038c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1039c9b443d4STobin Davis 	},
1040fb3409e7STobin Davis 	/* Audio input controls */
1041fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
1042fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
1043fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
1044fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
1045fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
1046fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
1047fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
1048fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
1049fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
1050fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
1051c9b443d4STobin Davis 	{ } /* end */
1052c9b443d4STobin Davis };
1053c9b443d4STobin Davis 
1054c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
10557f29673bSTobin Davis 	/* Set connections */
10567f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
10577f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
10587f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
1059c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1060c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
10617f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1062c9b443d4STobin Davis 
1063c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1064c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1065c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1066c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1067c9b443d4STobin Davis 	 * control.
1068c9b443d4STobin Davis 	 */
1069cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1070cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1071c9b443d4STobin Davis 
1072c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1073c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1074c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1075c9b443d4STobin Davis 
1076c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1077c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1078c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1079c9b443d4STobin Davis 	 * input/output buffers as needed.
1080c9b443d4STobin Davis 	 */
1081c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1082c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1083c9b443d4STobin Davis 
1084c9b443d4STobin Davis 	/* Mute capture amp left and right */
1085c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1086c9b443d4STobin Davis 
1087c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1088c9b443d4STobin Davis 	 * pin)
1089c9b443d4STobin Davis 	 */
1090c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10917f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1092c9b443d4STobin Davis 
1093c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1094c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1095c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1096c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1097c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1098c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1099c9b443d4STobin Davis 
1100c9b443d4STobin Davis 	{ }
1101c9b443d4STobin Davis };
1102c9b443d4STobin Davis #endif
1103c9b443d4STobin Davis 
1104c9b443d4STobin Davis 
1105c9b443d4STobin Davis /* initialize jack-sensing, too */
1106c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1107c9b443d4STobin Davis {
1108c9b443d4STobin Davis 	conexant_init(codec);
1109c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1110c9b443d4STobin Davis 	return 0;
1111c9b443d4STobin Davis }
1112c9b443d4STobin Davis 
1113c9b443d4STobin Davis 
1114c9b443d4STobin Davis enum {
111515908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
111615908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
111715908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
11185218c892SJiang Zhe 	CXT5045_BENQ,
11192de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1120c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1121c9b443d4STobin Davis 	CXT5045_TEST,
1122c9b443d4STobin Davis #endif
1123f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1124c9b443d4STobin Davis };
1125c9b443d4STobin Davis 
1126f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
112715908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
112815908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
112915908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
11305218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
11312de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1132c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1133f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1134c9b443d4STobin Davis #endif
1135f5fcc13cSTakashi Iwai };
1136c9b443d4STobin Davis 
1137f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
11382de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1139dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1140dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
11416a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
11425218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
114315908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
114415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
11459e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
11469e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
114715908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
114815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
114915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1150dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1151dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
115215908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1153c9b443d4STobin Davis 	{}
1154c9b443d4STobin Davis };
1155c9b443d4STobin Davis 
1156c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1157c9b443d4STobin Davis {
1158c9b443d4STobin Davis 	struct conexant_spec *spec;
1159c9b443d4STobin Davis 	int board_config;
1160c9b443d4STobin Davis 
1161c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1162c9b443d4STobin Davis 	if (!spec)
1163c9b443d4STobin Davis 		return -ENOMEM;
1164c9b443d4STobin Davis 	codec->spec = spec;
11659421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1166c9b443d4STobin Davis 
1167c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1168c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1169c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1170c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1171c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1172c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1173c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1174c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1175c9b443d4STobin Davis 	spec->num_mixers = 1;
1176c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1177c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1178c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1179c9b443d4STobin Davis 	spec->spdif_route = 0;
11803507e2a8STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
11813507e2a8STakashi Iwai 	spec->channel_mode = cxt5045_modes;
11825cd57529STobin Davis 
11833507e2a8STakashi Iwai 	set_beep_amp(spec, 0x16, 0, 1);
1184c9b443d4STobin Davis 
1185c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1186c9b443d4STobin Davis 
1187f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1188f5fcc13cSTakashi Iwai 						  cxt5045_models,
1189f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1190c9b443d4STobin Davis 	switch (board_config) {
119115908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11927f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1193c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1194c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11957f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11967f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11977f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11987f29673bSTobin Davis 		break;
119915908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
120086376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12017f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
12027f29673bSTobin Davis 		spec->num_init_verbs = 2;
12037f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1204c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1205c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1206c9b443d4STobin Davis 		break;
120715908c36SMarc Boucher 	default:
120815908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
120915908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
121015908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
121115908c36SMarc Boucher 		spec->num_init_verbs = 3;
121215908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
121315908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
121415908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
121515908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
121615908c36SMarc Boucher 		break;
12175218c892SJiang Zhe 	case CXT5045_BENQ:
12185218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12195218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
12205218c892SJiang Zhe 		spec->num_init_verbs = 1;
12215218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
12225218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
12235218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
12245218c892SJiang Zhe 		spec->num_mixers = 2;
12255218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
12265218c892SJiang Zhe 		break;
12272de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
12282de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
12292de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
12302de3c232SJiang zhe 		spec->num_init_verbs = 2;
12312de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
12322de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
12332de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
12342de3c232SJiang zhe 		break;
1235c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1236c9b443d4STobin Davis 	case CXT5045_TEST:
1237c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1238c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1239c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
124015908c36SMarc Boucher 		break;
124115908c36SMarc Boucher 
1242c9b443d4STobin Davis #endif
1243c9b443d4STobin Davis 	}
124448ecb7e8STakashi Iwai 
1245031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1246031005f7STakashi Iwai 	case 0x103c:
12478f0f5ff6SDaniel T Chen 	case 0x1631:
12480b587fc4SDaniel T Chen 	case 0x1734:
12490ebf9e36SDaniel T Chen 	case 0x17aa:
12500ebf9e36SDaniel T Chen 		/* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
12510ebf9e36SDaniel T Chen 		 * really bad sound over 0dB on NID 0x17. Fix max PCM level to
12520ebf9e36SDaniel T Chen 		 * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
125348ecb7e8STakashi Iwai 		 */
125448ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
125548ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
125648ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
125748ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
125848ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1259031005f7STakashi Iwai 		break;
1260031005f7STakashi Iwai 	}
126148ecb7e8STakashi Iwai 
12623507e2a8STakashi Iwai 	if (spec->beep_amp)
12633507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
12643507e2a8STakashi Iwai 
1265c9b443d4STobin Davis 	return 0;
1266c9b443d4STobin Davis }
1267c9b443d4STobin Davis 
1268c9b443d4STobin Davis 
1269c9b443d4STobin Davis /* Conexant 5047 specific */
127082f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1271c9b443d4STobin Davis 
12725b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1273c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1274c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1275c9b443d4STobin Davis 
12765cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12775cd57529STobin Davis 	{ 2, NULL },
12785cd57529STobin Davis };
1279c9b443d4STobin Davis 
128082f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
128182f30040STobin Davis 	.num_items = 2,
128282f30040STobin Davis 	.items = {
128382f30040STobin Davis 		{ "ExtMic", 0x2 },
128482f30040STobin Davis 		{ "Line-In", 0x1 },
1285c9b443d4STobin Davis 	}
1286c9b443d4STobin Davis };
1287c9b443d4STobin Davis 
1288c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1289c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1290c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1291c9b443d4STobin Davis {
1292c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1293c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
129482f30040STobin Davis 	unsigned int bits;
1295c9b443d4STobin Davis 
129682f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1297c9b443d4STobin Davis 		return 0;
1298c9b443d4STobin Davis 
129982f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
130082f30040STobin Davis 	 * the headphone jack
130182f30040STobin Davis 	 */
130247fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
13033b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
13043b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
13053b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
13063b7523fcSTakashi Iwai 	 */
13075d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
130847fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
130947fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
131047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
131147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1312c9b443d4STobin Davis 	return 1;
1313c9b443d4STobin Davis }
1314c9b443d4STobin Davis 
1315c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1316c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1317c9b443d4STobin Davis {
131882f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1319dd87da1cSTobin Davis 	unsigned int bits;
1320c9b443d4STobin Davis 
1321d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1322dd87da1cSTobin Davis 
132347fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
13243b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13255d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
132647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1327c9b443d4STobin Davis }
1328c9b443d4STobin Davis 
1329c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1330c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1331c9b443d4STobin Davis {
1332c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
13339f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13349f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1335c9b443d4STobin Davis 		{}
1336c9b443d4STobin Davis 	};
1337c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
13389f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
13399f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1340c9b443d4STobin Davis 		{}
1341c9b443d4STobin Davis 	};
1342c9b443d4STobin Davis 	unsigned int present;
1343c9b443d4STobin Davis 
1344d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1345c9b443d4STobin Davis 	if (present)
1346c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1347c9b443d4STobin Davis 	else
1348c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1349c9b443d4STobin Davis }
1350c9b443d4STobin Davis 
1351c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1352c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1353c9b443d4STobin Davis 				  unsigned int res)
1354c9b443d4STobin Davis {
13559f113e0eSMarc Boucher 	switch (res >> 26) {
1356c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1357c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1358c9b443d4STobin Davis 		break;
1359c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1360c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1361c9b443d4STobin Davis 		break;
1362c9b443d4STobin Davis 	}
1363c9b443d4STobin Davis }
1364c9b443d4STobin Davis 
1365df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1366df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1367df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1368df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1369c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1370c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1371c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1372c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
137382f30040STobin Davis 	{
137482f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
137582f30040STobin Davis 		.name = "Master Playback Switch",
137682f30040STobin Davis 		.info = cxt_eapd_info,
137782f30040STobin Davis 		.get = cxt_eapd_get,
1378c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1379c9b443d4STobin Davis 		.private_value = 0x13,
1380c9b443d4STobin Davis 	},
1381c9b443d4STobin Davis 
1382c9b443d4STobin Davis 	{}
1383c9b443d4STobin Davis };
1384c9b443d4STobin Davis 
1385df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13863b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13875d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1388df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1389df481e41STakashi Iwai 	{}
1390df481e41STakashi Iwai };
1391df481e41STakashi Iwai 
1392df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1393c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1394c9b443d4STobin Davis 	{ } /* end */
1395c9b443d4STobin Davis };
1396c9b443d4STobin Davis 
1397c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1398c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1399c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1400c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1401c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
14027f29673bSTobin Davis 	/* HP, Speaker  */
1403b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
14045b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
14055b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
14067f29673bSTobin Davis 	/* Record selector: Mic */
14077f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
14087f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
14097f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
14107f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1411c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1412c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1413c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1414c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1415c9b443d4STobin Davis 	/* SPDIF route: PCM */
1416c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
141782f30040STobin Davis 	/* Enable unsolicited events */
141882f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
141982f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1420c9b443d4STobin Davis 	{ } /* end */
1421c9b443d4STobin Davis };
1422c9b443d4STobin Davis 
1423c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1424c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
14253b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1426c9b443d4STobin Davis 	{}
1427c9b443d4STobin Davis };
1428c9b443d4STobin Davis 
1429c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1430c9b443d4STobin Davis  * configuration.
1431c9b443d4STobin Davis  */
1432c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1433c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
143482f30040STobin Davis 	.num_items = 4,
1435c9b443d4STobin Davis 	.items = {
143682f30040STobin Davis 		{ "LINE1 pin", 0x0 },
143782f30040STobin Davis 		{ "MIC1 pin", 0x1 },
143882f30040STobin Davis 		{ "MIC2 pin", 0x2 },
143982f30040STobin Davis 		{ "CD pin", 0x3 },
1440c9b443d4STobin Davis         },
1441c9b443d4STobin Davis };
1442c9b443d4STobin Davis 
1443c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1444c9b443d4STobin Davis 
1445c9b443d4STobin Davis 	/* Output only controls */
144682f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
144782f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
144882f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
144982f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1450c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1451c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1452c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1453c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
145482f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
145582f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
145682f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
145782f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1458c9b443d4STobin Davis 
1459c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1460c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1461c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1462c9b443d4STobin Davis 
146382f30040STobin Davis 	/* EAPD Switch Control */
146482f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
146582f30040STobin Davis 
1466c9b443d4STobin Davis 	/* Loopback mixer controls */
146782f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
146882f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
146982f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
147082f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
147182f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
147282f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
147382f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
147482f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1475c9b443d4STobin Davis 
147682f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
147782f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
147882f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
147982f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
148082f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
148182f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
148282f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
148382f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1484c9b443d4STobin Davis 	{
1485c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1486c9b443d4STobin Davis 		.name = "Input Source",
1487c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1488c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1489c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1490c9b443d4STobin Davis 	},
1491854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14929f113e0eSMarc Boucher 
1493c9b443d4STobin Davis 	{ } /* end */
1494c9b443d4STobin Davis };
1495c9b443d4STobin Davis 
1496c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1497c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1498c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1499c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1500c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1501c9b443d4STobin Davis 
1502c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1503c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1504c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1505c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1506c9b443d4STobin Davis 	 * control.
1507c9b443d4STobin Davis 	 */
1508c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1509c9b443d4STobin Davis 
1510c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1511c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1512c9b443d4STobin Davis 	 */
1513c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1514c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1515c9b443d4STobin Davis 
1516c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1517c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1518c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1519c9b443d4STobin Davis 
1520c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1521c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1522c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1523c9b443d4STobin Davis 	 * input/output buffers as needed.
1524c9b443d4STobin Davis 	 */
1525c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1526c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1527c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1528c9b443d4STobin Davis 
1529c9b443d4STobin Davis 	/* Mute capture amp left and right */
1530c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1531c9b443d4STobin Davis 
1532c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1533c9b443d4STobin Davis 	 * pin)
1534c9b443d4STobin Davis 	 */
1535c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1536c9b443d4STobin Davis 
1537c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1538c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1539c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1540c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1541c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1542c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1543c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1544c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1545c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1546c9b443d4STobin Davis 
1547c9b443d4STobin Davis 	{ }
1548c9b443d4STobin Davis };
1549c9b443d4STobin Davis #endif
1550c9b443d4STobin Davis 
1551c9b443d4STobin Davis 
1552c9b443d4STobin Davis /* initialize jack-sensing, too */
1553c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1554c9b443d4STobin Davis {
1555c9b443d4STobin Davis 	conexant_init(codec);
1556c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1557c9b443d4STobin Davis 	return 0;
1558c9b443d4STobin Davis }
1559c9b443d4STobin Davis 
1560c9b443d4STobin Davis 
1561c9b443d4STobin Davis enum {
1562f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1563f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1564f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1565c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1566c9b443d4STobin Davis 	CXT5047_TEST,
1567c9b443d4STobin Davis #endif
1568f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1569c9b443d4STobin Davis };
1570c9b443d4STobin Davis 
1571f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1572f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1573f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1574f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1575c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1576f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1577c9b443d4STobin Davis #endif
1578f5fcc13cSTakashi Iwai };
1579c9b443d4STobin Davis 
1580f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1581ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1582dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1583dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1584f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1585c9b443d4STobin Davis 	{}
1586c9b443d4STobin Davis };
1587c9b443d4STobin Davis 
1588c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1589c9b443d4STobin Davis {
1590c9b443d4STobin Davis 	struct conexant_spec *spec;
1591c9b443d4STobin Davis 	int board_config;
1592c9b443d4STobin Davis 
1593c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1594c9b443d4STobin Davis 	if (!spec)
1595c9b443d4STobin Davis 		return -ENOMEM;
1596c9b443d4STobin Davis 	codec->spec = spec;
15979421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1598c9b443d4STobin Davis 
1599c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1600c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1601c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1602c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1603c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1604c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1605c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1606c9b443d4STobin Davis 	spec->num_mixers = 1;
1607df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1608c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1609c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1610c9b443d4STobin Davis 	spec->spdif_route = 0;
16115cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
16125cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1613c9b443d4STobin Davis 
1614c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1615c9b443d4STobin Davis 
1616f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1617f5fcc13cSTakashi Iwai 						  cxt5047_models,
1618f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1619c9b443d4STobin Davis 	switch (board_config) {
1620c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1621df481e41STakashi Iwai 		spec->num_mixers = 2;
1622df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1623df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1624c9b443d4STobin Davis 		break;
1625c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1626df481e41STakashi Iwai 		spec->num_mixers = 2;
1627df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1628fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1629c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1630c9b443d4STobin Davis 		break;
1631c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
163282f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1633df481e41STakashi Iwai 		spec->num_mixers = 2;
1634df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1635c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1636c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1637fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1638c9b443d4STobin Davis 		break;
1639c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1640c9b443d4STobin Davis 	case CXT5047_TEST:
1641c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1642c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1643c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1644fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1645c9b443d4STobin Davis #endif
1646c9b443d4STobin Davis 	}
1647dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1648025f206cSDaniel T Chen 
1649025f206cSDaniel T Chen 	switch (codec->subsystem_id >> 16) {
1650025f206cSDaniel T Chen 	case 0x103c:
1651025f206cSDaniel T Chen 		/* HP laptops have really bad sound over 0 dB on NID 0x10.
1652025f206cSDaniel T Chen 		 * Fix max PCM level to 0 dB (originally it has 0x1e steps
1653025f206cSDaniel T Chen 		 * with 0 dB offset 0x17)
1654025f206cSDaniel T Chen 		 */
1655025f206cSDaniel T Chen 		snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
1656025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
1657025f206cSDaniel T Chen 					  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
1658025f206cSDaniel T Chen 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
1659025f206cSDaniel T Chen 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1660025f206cSDaniel T Chen 		break;
1661025f206cSDaniel T Chen 	}
1662025f206cSDaniel T Chen 
1663c9b443d4STobin Davis 	return 0;
1664c9b443d4STobin Davis }
1665c9b443d4STobin Davis 
1666461e2c78STakashi Iwai /* Conexant 5051 specific */
1667461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1668461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1669461e2c78STakashi Iwai 
1670461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1671461e2c78STakashi Iwai 	{ 2, NULL },
1672461e2c78STakashi Iwai };
1673461e2c78STakashi Iwai 
1674461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1675461e2c78STakashi Iwai {
1676461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1677461e2c78STakashi Iwai 	unsigned int pinctl;
167823d2df5bSTakashi Iwai 	/* headphone pin */
167923d2df5bSTakashi Iwai 	pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
168023d2df5bSTakashi Iwai 	snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
168123d2df5bSTakashi Iwai 			    pinctl);
168223d2df5bSTakashi Iwai 	/* speaker pin */
1683461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1684461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1685461e2c78STakashi Iwai 			    pinctl);
1686f7154de2SHerton Ronaldo Krzesinski 	/* on ideapad there is an aditional speaker (subwoofer) to mute */
1687f7154de2SHerton Ronaldo Krzesinski 	if (spec->ideapad)
1688f7154de2SHerton Ronaldo Krzesinski 		snd_hda_codec_write(codec, 0x1b, 0,
1689f7154de2SHerton Ronaldo Krzesinski 				    AC_VERB_SET_PIN_WIDGET_CONTROL,
1690f7154de2SHerton Ronaldo Krzesinski 				    pinctl);
1691461e2c78STakashi Iwai }
1692461e2c78STakashi Iwai 
1693461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1694461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1695461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1696461e2c78STakashi Iwai {
1697461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1698461e2c78STakashi Iwai 
1699461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1700461e2c78STakashi Iwai 		return 0;
1701461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1702461e2c78STakashi Iwai 	return 1;
1703461e2c78STakashi Iwai }
1704461e2c78STakashi Iwai 
1705461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1706461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1707461e2c78STakashi Iwai {
170879d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1709461e2c78STakashi Iwai 	unsigned int present;
1710461e2c78STakashi Iwai 
1711faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTB))
171279d7d533STakashi Iwai 		return;
1713d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1714461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1715461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1716461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1717461e2c78STakashi Iwai }
1718461e2c78STakashi Iwai 
1719461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1720461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1721461e2c78STakashi Iwai {
1722461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1723461e2c78STakashi Iwai 	unsigned int present;
1724461e2c78STakashi Iwai 	hda_nid_t new_adc;
1725461e2c78STakashi Iwai 
1726faddaa5dSTakashi Iwai 	if (!(spec->auto_mic & AUTO_MIC_PORTC))
172779d7d533STakashi Iwai 		return;
1728d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1729461e2c78STakashi Iwai 	if (present)
1730461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1731461e2c78STakashi Iwai 	else
1732461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1733461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1734461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1735461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1736f0cea797STakashi Iwai 		__snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
1737461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1738461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1739461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1740461e2c78STakashi Iwai 					   spec->cur_adc_format);
1741461e2c78STakashi Iwai 	}
1742461e2c78STakashi Iwai }
1743461e2c78STakashi Iwai 
1744461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1745461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1746461e2c78STakashi Iwai {
1747461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1748461e2c78STakashi Iwai 
1749d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1750461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1751461e2c78STakashi Iwai }
1752461e2c78STakashi Iwai 
1753461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1754461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1755461e2c78STakashi Iwai 				   unsigned int res)
1756461e2c78STakashi Iwai {
1757acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1758461e2c78STakashi Iwai 	switch (res >> 26) {
1759461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1760461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1761461e2c78STakashi Iwai 		break;
1762461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1763461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1764461e2c78STakashi Iwai 		break;
1765461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1766461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1767461e2c78STakashi Iwai 		break;
1768461e2c78STakashi Iwai 	}
1769acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1770461e2c78STakashi Iwai }
1771461e2c78STakashi Iwai 
17722c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
1773461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1774461e2c78STakashi Iwai 	{
1775461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1776461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1777461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1778461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1779461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1780461e2c78STakashi Iwai 		.private_value = 0x1a,
1781461e2c78STakashi Iwai 	},
17822c7a3fb3STakashi Iwai 	{}
17832c7a3fb3STakashi Iwai };
1784461e2c78STakashi Iwai 
17852c7a3fb3STakashi Iwai static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
17862c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
17872c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
17882c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
17892c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
17902c7a3fb3STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
17912c7a3fb3STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1792461e2c78STakashi Iwai 	{}
1793461e2c78STakashi Iwai };
1794461e2c78STakashi Iwai 
1795461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1796461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1797461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1798461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1799461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1800461e2c78STakashi Iwai 	{}
1801461e2c78STakashi Iwai };
1802461e2c78STakashi Iwai 
180379d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
18044e4ac600STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
18054e4ac600STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
180679d7d533STakashi Iwai 	{}
180779d7d533STakashi Iwai };
180879d7d533STakashi Iwai 
1809cd9d95a5SKen Prox static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
18105f6c3de6STakashi Iwai 	HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
18115f6c3de6STakashi Iwai 	HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
1812cd9d95a5SKen Prox 	{}
1813cd9d95a5SKen Prox };
1814cd9d95a5SKen Prox 
1815faddaa5dSTakashi Iwai static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
1816faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1817faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1818faddaa5dSTakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1819faddaa5dSTakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1820faddaa5dSTakashi Iwai 	{}
1821faddaa5dSTakashi Iwai };
1822faddaa5dSTakashi Iwai 
1823461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1824461e2c78STakashi Iwai 	/* Line in, Mic */
1825461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1826461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1827461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1828461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1829461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1830461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1831461e2c78STakashi Iwai 	/* SPK  */
1832461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1833461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1834461e2c78STakashi Iwai 	/* HP, Amp  */
1835461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1836461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1837461e2c78STakashi Iwai 	/* DAC1 */
1838461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1839461e2c78STakashi Iwai 	/* Record selector: Int mic */
1840461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1841461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1842461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1843461e2c78STakashi Iwai 	/* SPDIF route: PCM */
18441965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1845461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1846461e2c78STakashi Iwai 	/* EAPD */
1847461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1848461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1849461e2c78STakashi Iwai 	{ } /* end */
1850461e2c78STakashi Iwai };
1851461e2c78STakashi Iwai 
185279d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
185379d7d533STakashi Iwai 	/* Line in, Mic */
185479d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
185579d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
185679d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
185779d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
185879d7d533STakashi Iwai 	/* SPK  */
185979d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
186079d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
186179d7d533STakashi Iwai 	/* HP, Amp  */
186279d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186379d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
186479d7d533STakashi Iwai 	/* DAC1 */
186579d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
186679d7d533STakashi Iwai 	/* Record selector: Int mic */
186779d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
186879d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
186979d7d533STakashi Iwai 	/* SPDIF route: PCM */
187079d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
187179d7d533STakashi Iwai 	/* EAPD */
187279d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
187379d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
187479d7d533STakashi Iwai 	{ } /* end */
187579d7d533STakashi Iwai };
187679d7d533STakashi Iwai 
187727e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
187827e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
187927e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
188027e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
188127e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
188227e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
188327e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
188427e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
188527e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
188627e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
188727e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
188827e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
188927e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
189027e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
189127e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
189227e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
189327e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
189427e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
189527e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
189627e08988SAristeu Sergio Rozanski Filho 	/* Record selector: Int mic */
189727e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
189827e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
189927e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
190027e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
19011965c441SPierre-Louis Bossart 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
190227e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
190327e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
190427e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
190527e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
190627e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
190727e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
190827e08988SAristeu Sergio Rozanski Filho };
190927e08988SAristeu Sergio Rozanski Filho 
1910cd9d95a5SKen Prox static struct hda_verb cxt5051_f700_init_verbs[] = {
1911cd9d95a5SKen Prox 	/* Line in, Mic */
191230ed7ed1STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1913cd9d95a5SKen Prox 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1914cd9d95a5SKen Prox 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1915cd9d95a5SKen Prox 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1916cd9d95a5SKen Prox 	/* SPK  */
1917cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1918cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1919cd9d95a5SKen Prox 	/* HP, Amp  */
1920cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1921cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1922cd9d95a5SKen Prox 	/* DAC1 */
1923cd9d95a5SKen Prox 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1924cd9d95a5SKen Prox 	/* Record selector: Int mic */
1925cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1926cd9d95a5SKen Prox 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1927cd9d95a5SKen Prox 	/* SPDIF route: PCM */
1928cd9d95a5SKen Prox 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1929cd9d95a5SKen Prox 	/* EAPD */
1930cd9d95a5SKen Prox 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1931cd9d95a5SKen Prox 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1932cd9d95a5SKen Prox 	{ } /* end */
1933cd9d95a5SKen Prox };
1934cd9d95a5SKen Prox 
19356953e552STakashi Iwai static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
19366953e552STakashi Iwai 				 unsigned int event)
19376953e552STakashi Iwai {
19386953e552STakashi Iwai 	snd_hda_codec_write(codec, nid, 0,
19396953e552STakashi Iwai 			    AC_VERB_SET_UNSOLICITED_ENABLE,
19406953e552STakashi Iwai 			    AC_USRSP_EN | event);
19416953e552STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
19426953e552STakashi Iwai 	conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
19436953e552STakashi Iwai 	conexant_report_jack(codec, nid);
19446953e552STakashi Iwai #endif
19456953e552STakashi Iwai }
19466953e552STakashi Iwai 
1947f7154de2SHerton Ronaldo Krzesinski static struct hda_verb cxt5051_ideapad_init_verbs[] = {
1948f7154de2SHerton Ronaldo Krzesinski 	/* Subwoofer */
1949f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1950f7154de2SHerton Ronaldo Krzesinski 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
1951f7154de2SHerton Ronaldo Krzesinski 	{ } /* end */
1952f7154de2SHerton Ronaldo Krzesinski };
1953f7154de2SHerton Ronaldo Krzesinski 
1954461e2c78STakashi Iwai /* initialize jack-sensing, too */
1955461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1956461e2c78STakashi Iwai {
19576953e552STakashi Iwai 	struct conexant_spec *spec = codec->spec;
19586953e552STakashi Iwai 
1959461e2c78STakashi Iwai 	conexant_init(codec);
1960acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
19616953e552STakashi Iwai 
19626953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTB)
19636953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
19646953e552STakashi Iwai 	if (spec->auto_mic & AUTO_MIC_PORTC)
19656953e552STakashi Iwai 		cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
19666953e552STakashi Iwai 
1967461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1968461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1969461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1970461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1971461e2c78STakashi Iwai 	}
1972461e2c78STakashi Iwai 	return 0;
1973461e2c78STakashi Iwai }
1974461e2c78STakashi Iwai 
1975461e2c78STakashi Iwai 
1976461e2c78STakashi Iwai enum {
1977461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1978461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
197979d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
19801965c441SPierre-Louis Bossart 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1981cd9d95a5SKen Prox 	CXT5051_F700,       /* HP Compaq Presario F700 */
1982faddaa5dSTakashi Iwai 	CXT5051_TOSHIBA,	/* Toshiba M300 & co */
1983f7154de2SHerton Ronaldo Krzesinski 	CXT5051_IDEAPAD,	/* Lenovo IdeaPad Y430 */
1984461e2c78STakashi Iwai 	CXT5051_MODELS
1985461e2c78STakashi Iwai };
1986461e2c78STakashi Iwai 
1987461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1988461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1989461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
199079d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
199127e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
19925f6c3de6STakashi Iwai 	[CXT5051_F700]          = "hp-700",
1993faddaa5dSTakashi Iwai 	[CXT5051_TOSHIBA]	= "toshiba",
1994f7154de2SHerton Ronaldo Krzesinski 	[CXT5051_IDEAPAD]	= "ideapad",
1995461e2c78STakashi Iwai };
1996461e2c78STakashi Iwai 
1997461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
199879d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
19991812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
20005f6c3de6STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
2001faddaa5dSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
2002461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
2003461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
2004461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
200527e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
2006f7154de2SHerton Ronaldo Krzesinski 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
2007461e2c78STakashi Iwai 	{}
2008461e2c78STakashi Iwai };
2009461e2c78STakashi Iwai 
2010461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
2011461e2c78STakashi Iwai {
2012461e2c78STakashi Iwai 	struct conexant_spec *spec;
2013461e2c78STakashi Iwai 	int board_config;
2014461e2c78STakashi Iwai 
2015461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2016461e2c78STakashi Iwai 	if (!spec)
2017461e2c78STakashi Iwai 		return -ENOMEM;
2018461e2c78STakashi Iwai 	codec->spec = spec;
20199421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
2020461e2c78STakashi Iwai 
2021461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
2022461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
2023461e2c78STakashi Iwai 
2024461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
2025461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
2026461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
2027461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
2028461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
2029461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
20302c7a3fb3STakashi Iwai 	spec->num_mixers = 2;
20312c7a3fb3STakashi Iwai 	spec->mixers[0] = cxt5051_capture_mixers;
20322c7a3fb3STakashi Iwai 	spec->mixers[1] = cxt5051_playback_mixers;
2033461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
2034461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
2035461e2c78STakashi Iwai 	spec->spdif_route = 0;
2036461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
2037461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
2038461e2c78STakashi Iwai 	spec->cur_adc = 0;
2039461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
2040461e2c78STakashi Iwai 
20413507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
20423507e2a8STakashi Iwai 
204379d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
204479d7d533STakashi Iwai 
2045461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
2046461e2c78STakashi Iwai 						  cxt5051_models,
2047461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
2048faddaa5dSTakashi Iwai 	spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
2049461e2c78STakashi Iwai 	switch (board_config) {
2050461e2c78STakashi Iwai 	case CXT5051_HP:
2051461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
2052461e2c78STakashi Iwai 		break;
205379d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
205479d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
205579d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2056faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
205779d7d533STakashi Iwai 		break;
205827e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
205927e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2060607bc3e4SJerone Young 		/* Thinkpad X301 does not have S/PDIF wired and no ability
2061607bc3e4SJerone Young 		   to use a docking station. */
2062607bc3e4SJerone Young 		if (codec->subsystem_id == 0x17aa211f)
2063607bc3e4SJerone Young 			spec->multiout.dig_out_nid = 0;
2064461e2c78STakashi Iwai 		break;
2065cd9d95a5SKen Prox 	case CXT5051_F700:
2066cd9d95a5SKen Prox 		spec->init_verbs[0] = cxt5051_f700_init_verbs;
2067cd9d95a5SKen Prox 		spec->mixers[0] = cxt5051_f700_mixers;
2068faddaa5dSTakashi Iwai 		spec->auto_mic = 0;
2069faddaa5dSTakashi Iwai 		break;
2070faddaa5dSTakashi Iwai 	case CXT5051_TOSHIBA:
2071faddaa5dSTakashi Iwai 		spec->mixers[0] = cxt5051_toshiba_mixers;
2072faddaa5dSTakashi Iwai 		spec->auto_mic = AUTO_MIC_PORTB;
2073cd9d95a5SKen Prox 		break;
2074f7154de2SHerton Ronaldo Krzesinski 	case CXT5051_IDEAPAD:
2075f7154de2SHerton Ronaldo Krzesinski 		spec->init_verbs[spec->num_init_verbs++] =
2076f7154de2SHerton Ronaldo Krzesinski 			cxt5051_ideapad_init_verbs;
2077f7154de2SHerton Ronaldo Krzesinski 		spec->ideapad = 1;
2078f7154de2SHerton Ronaldo Krzesinski 		break;
2079461e2c78STakashi Iwai 	}
2080461e2c78STakashi Iwai 
20813507e2a8STakashi Iwai 	if (spec->beep_amp)
20823507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
20833507e2a8STakashi Iwai 
2084461e2c78STakashi Iwai 	return 0;
2085461e2c78STakashi Iwai }
2086461e2c78STakashi Iwai 
20870fb67e98SDaniel Drake /* Conexant 5066 specific */
20880fb67e98SDaniel Drake 
20890fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
20900fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
20910fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
20920fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT	0x21
20930fb67e98SDaniel Drake 
2094dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
2095dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
2096dbaccc0cSDaniel Drake  * the DC input range of the codec. */
2097dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
2098dbaccc0cSDaniel Drake 
20990fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
21000fb67e98SDaniel Drake 	{ 2, NULL },
21010fb67e98SDaniel Drake };
21020fb67e98SDaniel Drake 
21030fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
21040fb67e98SDaniel Drake {
21050fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
21060fb67e98SDaniel Drake 	unsigned int pinctl;
21070fb67e98SDaniel Drake 
21080fb67e98SDaniel Drake 	snd_printdd("CXT5066: update speaker, hp_present=%d\n",
21090fb67e98SDaniel Drake 		spec->hp_present);
21100fb67e98SDaniel Drake 
21110fb67e98SDaniel Drake 	/* Port A (HP) */
21120fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
21130fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21140fb67e98SDaniel Drake 			pinctl);
21150fb67e98SDaniel Drake 
21160fb67e98SDaniel Drake 	/* Port D (HP/LO) */
21170fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
21180fb67e98SDaniel Drake 		? spec->port_d_mode : 0;
21197b2bfdbcSJens Taprogge 	/* Mute if Port A is connected on Thinkpad */
21207b2bfdbcSJens Taprogge 	if (spec->thinkpad && (spec->hp_present & 1))
21217b2bfdbcSJens Taprogge 		pinctl = 0;
21220fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21230fb67e98SDaniel Drake 			pinctl);
21240fb67e98SDaniel Drake 
21250fb67e98SDaniel Drake 	/* CLASS_D AMP */
21260fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
21270fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
21280fb67e98SDaniel Drake 			pinctl);
21290fb67e98SDaniel Drake 
21300fb67e98SDaniel Drake 	if (spec->dell_automute) {
21310fb67e98SDaniel Drake 		/* DELL AIO Port Rule: PortA > PortD > IntSpk */
21320fb67e98SDaniel Drake 		pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
21330fb67e98SDaniel Drake 			? PIN_OUT : 0;
21340fb67e98SDaniel Drake 		snd_hda_codec_write(codec, 0x1c, 0,
21350fb67e98SDaniel Drake 			AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
21360fb67e98SDaniel Drake 	}
21370fb67e98SDaniel Drake }
21380fb67e98SDaniel Drake 
21390fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
21400fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
21410fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
21420fb67e98SDaniel Drake {
21430fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21440fb67e98SDaniel Drake 
21450fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
21460fb67e98SDaniel Drake 		return 0;
21470fb67e98SDaniel Drake 
21480fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
21490fb67e98SDaniel Drake 	return 1;
21500fb67e98SDaniel Drake }
21510fb67e98SDaniel Drake 
2152c4cfe66cSDaniel Drake static const struct hda_input_mux cxt5066_olpc_dc_bias = {
2153c4cfe66cSDaniel Drake 	.num_items = 3,
2154c4cfe66cSDaniel Drake 	.items = {
2155c4cfe66cSDaniel Drake 		{ "Off", PIN_IN },
2156c4cfe66cSDaniel Drake 		{ "50%", PIN_VREF50 },
2157c4cfe66cSDaniel Drake 		{ "80%", PIN_VREF80 },
2158c4cfe66cSDaniel Drake 	},
2159c4cfe66cSDaniel Drake };
2160c4cfe66cSDaniel Drake 
2161c4cfe66cSDaniel Drake static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
2162c4cfe66cSDaniel Drake {
2163c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2164c4cfe66cSDaniel Drake 	/* Even though port F is the DC input, the bias is controlled on port B.
2165c4cfe66cSDaniel Drake 	 * we also leave that port as an active input (but unselected) in DC mode
2166c4cfe66cSDaniel Drake 	 * just in case that is necessary to make the bias setting take effect. */
2167c4cfe66cSDaniel Drake 	return snd_hda_codec_write_cache(codec, 0x1a, 0,
2168c4cfe66cSDaniel Drake 		AC_VERB_SET_PIN_WIDGET_CONTROL,
2169c4cfe66cSDaniel Drake 		cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
2170c4cfe66cSDaniel Drake }
2171c4cfe66cSDaniel Drake 
217275f8991dSDaniel Drake /* OLPC defers mic widget control until when capture is started because the
217375f8991dSDaniel Drake  * microphone LED comes on as soon as these settings are put in place. if we
217475f8991dSDaniel Drake  * did this before recording, it would give the false indication that recording
217575f8991dSDaniel Drake  * is happening when it is not. */
217675f8991dSDaniel Drake static void cxt5066_olpc_select_mic(struct hda_codec *codec)
21770fb67e98SDaniel Drake {
2178dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
217975f8991dSDaniel Drake 	if (!spec->recording)
218075f8991dSDaniel Drake 		return;
21810fb67e98SDaniel Drake 
2182c4cfe66cSDaniel Drake 	if (spec->dc_enable) {
2183c4cfe66cSDaniel Drake 		/* in DC mode we ignore presence detection and just use the jack
2184c4cfe66cSDaniel Drake 		 * through our special DC port */
2185c4cfe66cSDaniel Drake 		const struct hda_verb enable_dc_mode[] = {
2186c4cfe66cSDaniel Drake 			/* disble internal mic, port C */
2187c4cfe66cSDaniel Drake 			{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2188c4cfe66cSDaniel Drake 
2189c4cfe66cSDaniel Drake 			/* enable DC capture, port F */
2190c4cfe66cSDaniel Drake 			{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2191c4cfe66cSDaniel Drake 			{},
2192c4cfe66cSDaniel Drake 		};
2193c4cfe66cSDaniel Drake 
2194c4cfe66cSDaniel Drake 		snd_hda_sequence_write(codec, enable_dc_mode);
2195c4cfe66cSDaniel Drake 		/* port B input disabled (and bias set) through the following call */
2196c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
2197c4cfe66cSDaniel Drake 		return;
2198c4cfe66cSDaniel Drake 	}
2199c4cfe66cSDaniel Drake 
2200c4cfe66cSDaniel Drake 	/* disable DC (port F) */
2201c4cfe66cSDaniel Drake 	snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
2202c4cfe66cSDaniel Drake 
220375f8991dSDaniel Drake 	/* external mic, port B */
220475f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
220575f8991dSDaniel Drake 		spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
22060fb67e98SDaniel Drake 
220775f8991dSDaniel Drake 	/* internal mic, port C */
220875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
220975f8991dSDaniel Drake 		spec->ext_mic_present ? 0 : PIN_VREF80);
221075f8991dSDaniel Drake }
22110fb67e98SDaniel Drake 
221275f8991dSDaniel Drake /* toggle input of built-in and mic jack appropriately */
221375f8991dSDaniel Drake static void cxt5066_olpc_automic(struct hda_codec *codec)
221475f8991dSDaniel Drake {
221575f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
22160fb67e98SDaniel Drake 	unsigned int present;
22170fb67e98SDaniel Drake 
2218c4cfe66cSDaniel Drake 	if (spec->dc_enable) /* don't do presence detection in DC mode */
2219c4cfe66cSDaniel Drake 		return;
2220c4cfe66cSDaniel Drake 
222175f8991dSDaniel Drake 	present = snd_hda_codec_read(codec, 0x1a, 0,
222275f8991dSDaniel Drake 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
222375f8991dSDaniel Drake 	if (present)
22240fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
222575f8991dSDaniel Drake 	else
22260fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
222775f8991dSDaniel Drake 
222875f8991dSDaniel Drake 	snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
222975f8991dSDaniel Drake 		present ? 0 : 1);
223075f8991dSDaniel Drake 	spec->ext_mic_present = !!present;
223175f8991dSDaniel Drake 
223275f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
22330fb67e98SDaniel Drake }
22340fb67e98SDaniel Drake 
223595a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
223695a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
223795a618bdSEinar Rünkaru {
223895a618bdSEinar Rünkaru 	unsigned int present;
223995a618bdSEinar Rünkaru 
224095a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
224195a618bdSEinar Rünkaru 		/* enable external mic, port B */
224275f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
224395a618bdSEinar Rünkaru 
224495a618bdSEinar Rünkaru 		/* switch to external mic input */
224595a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
224695a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
224795a618bdSEinar Rünkaru 
224895a618bdSEinar Rünkaru 		/* disable internal digital mic */
224995a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
225095a618bdSEinar Rünkaru 		{}
225195a618bdSEinar Rünkaru 	};
225295a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
225395a618bdSEinar Rünkaru 		/* enable internal mic, port C */
225495a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
225595a618bdSEinar Rünkaru 
225695a618bdSEinar Rünkaru 		/* switch to internal mic input */
225795a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
225895a618bdSEinar Rünkaru 
225995a618bdSEinar Rünkaru 		/* disable external mic, port B */
226095a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
226195a618bdSEinar Rünkaru 		{}
226295a618bdSEinar Rünkaru 	};
226395a618bdSEinar Rünkaru 
226495a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
226595a618bdSEinar Rünkaru 	if (present) {
226695a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
226795a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
226895a618bdSEinar Rünkaru 	} else {
226995a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
227095a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
227195a618bdSEinar Rünkaru 	}
227295a618bdSEinar Rünkaru }
227395a618bdSEinar Rünkaru 
2274cfd3d8dcSGreg Alexander /* toggle input of built-in digital mic and mic jack appropriately */
2275cfd3d8dcSGreg Alexander static void cxt5066_ideapad_automic(struct hda_codec *codec)
2276cfd3d8dcSGreg Alexander {
2277cfd3d8dcSGreg Alexander 	unsigned int present;
2278cfd3d8dcSGreg Alexander 
2279cfd3d8dcSGreg Alexander 	struct hda_verb ext_mic_present[] = {
2280cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
2281cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
2282cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2283cfd3d8dcSGreg Alexander 		{}
2284cfd3d8dcSGreg Alexander 	};
2285cfd3d8dcSGreg Alexander 	static struct hda_verb ext_mic_absent[] = {
2286cfd3d8dcSGreg Alexander 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
2287cfd3d8dcSGreg Alexander 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2288cfd3d8dcSGreg Alexander 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2289cfd3d8dcSGreg Alexander 		{}
2290cfd3d8dcSGreg Alexander 	};
2291cfd3d8dcSGreg Alexander 
2292cfd3d8dcSGreg Alexander 	present = snd_hda_jack_detect(codec, 0x1b);
2293cfd3d8dcSGreg Alexander 	if (present) {
2294cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone detected\n");
2295cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_present);
2296cfd3d8dcSGreg Alexander 	} else {
2297cfd3d8dcSGreg Alexander 		snd_printdd("CXT5066: external microphone absent\n");
2298cfd3d8dcSGreg Alexander 		snd_hda_sequence_write(codec, ext_mic_absent);
2299cfd3d8dcSGreg Alexander 	}
2300cfd3d8dcSGreg Alexander }
2301cfd3d8dcSGreg Alexander 
23027b2bfdbcSJens Taprogge /* toggle input of built-in digital mic and mic jack appropriately
23037b2bfdbcSJens Taprogge    order is: external mic -> dock mic -> interal mic */
23047b2bfdbcSJens Taprogge static void cxt5066_thinkpad_automic(struct hda_codec *codec)
23057b2bfdbcSJens Taprogge {
23067b2bfdbcSJens Taprogge 	unsigned int ext_present, dock_present;
23077b2bfdbcSJens Taprogge 
23087b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_present[] = {
23097b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23107b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
23117b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23127b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23137b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23147b2bfdbcSJens Taprogge 		{}
23157b2bfdbcSJens Taprogge 	};
23167b2bfdbcSJens Taprogge 	static struct hda_verb dock_mic_present[] = {
23177b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
23187b2bfdbcSJens Taprogge 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
23197b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23207b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23217b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23227b2bfdbcSJens Taprogge 		{}
23237b2bfdbcSJens Taprogge 	};
23247b2bfdbcSJens Taprogge 	static struct hda_verb ext_mic_absent[] = {
23257b2bfdbcSJens Taprogge 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
23267b2bfdbcSJens Taprogge 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
23277b2bfdbcSJens Taprogge 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23287b2bfdbcSJens Taprogge 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23297b2bfdbcSJens Taprogge 		{}
23307b2bfdbcSJens Taprogge 	};
23317b2bfdbcSJens Taprogge 
23327b2bfdbcSJens Taprogge 	ext_present = snd_hda_jack_detect(codec, 0x1b);
23337b2bfdbcSJens Taprogge 	dock_present = snd_hda_jack_detect(codec, 0x1a);
23347b2bfdbcSJens Taprogge 	if (ext_present) {
23357b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone detected\n");
23367b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_present);
23377b2bfdbcSJens Taprogge 	} else if (dock_present) {
23387b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: dock microphone detected\n");
23397b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, dock_mic_present);
23407b2bfdbcSJens Taprogge 	} else {
23417b2bfdbcSJens Taprogge 		snd_printdd("CXT5066: external microphone absent\n");
23427b2bfdbcSJens Taprogge 		snd_hda_sequence_write(codec, ext_mic_absent);
23437b2bfdbcSJens Taprogge 	}
23447b2bfdbcSJens Taprogge }
23457b2bfdbcSJens Taprogge 
23460fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
23470fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
23480fb67e98SDaniel Drake {
23490fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
23500fb67e98SDaniel Drake 	unsigned int portA, portD;
23510fb67e98SDaniel Drake 
23520fb67e98SDaniel Drake 	/* Port A */
2353d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
23540fb67e98SDaniel Drake 
23550fb67e98SDaniel Drake 	/* Port D */
2356d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
23570fb67e98SDaniel Drake 
23587b2bfdbcSJens Taprogge 	spec->hp_present = !!(portA);
23597b2bfdbcSJens Taprogge 	spec->hp_present |= portD ? 2 : 0;
23600fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
23610fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
23620fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
23630fb67e98SDaniel Drake }
23640fb67e98SDaniel Drake 
23650fb67e98SDaniel Drake /* unsolicited event for jack sensing */
236675f8991dSDaniel Drake static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
23670fb67e98SDaniel Drake {
2368c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
23690fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
23700fb67e98SDaniel Drake 	switch (res >> 26) {
23710fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
23720fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
23730fb67e98SDaniel Drake 		break;
23740fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
2375c4cfe66cSDaniel Drake 		/* ignore mic events in DC mode; we're always using the jack */
2376c4cfe66cSDaniel Drake 		if (!spec->dc_enable)
237775f8991dSDaniel Drake 			cxt5066_olpc_automic(codec);
23780fb67e98SDaniel Drake 		break;
23790fb67e98SDaniel Drake 	}
23800fb67e98SDaniel Drake }
23810fb67e98SDaniel Drake 
238295a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
238395a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
238495a618bdSEinar Rünkaru {
238595a618bdSEinar Rünkaru 	snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
238695a618bdSEinar Rünkaru 	switch (res >> 26) {
238795a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
238895a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
238995a618bdSEinar Rünkaru 		break;
239095a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
239195a618bdSEinar Rünkaru 		cxt5066_vostro_automic(codec);
239295a618bdSEinar Rünkaru 		break;
239395a618bdSEinar Rünkaru 	}
239495a618bdSEinar Rünkaru }
239595a618bdSEinar Rünkaru 
2396cfd3d8dcSGreg Alexander /* unsolicited event for jack sensing */
2397cfd3d8dcSGreg Alexander static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
2398cfd3d8dcSGreg Alexander {
2399cfd3d8dcSGreg Alexander 	snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
2400cfd3d8dcSGreg Alexander 	switch (res >> 26) {
2401cfd3d8dcSGreg Alexander 	case CONEXANT_HP_EVENT:
2402cfd3d8dcSGreg Alexander 		cxt5066_hp_automute(codec);
2403cfd3d8dcSGreg Alexander 		break;
2404cfd3d8dcSGreg Alexander 	case CONEXANT_MIC_EVENT:
2405cfd3d8dcSGreg Alexander 		cxt5066_ideapad_automic(codec);
2406cfd3d8dcSGreg Alexander 		break;
2407cfd3d8dcSGreg Alexander 	}
2408cfd3d8dcSGreg Alexander }
2409cfd3d8dcSGreg Alexander 
24107b2bfdbcSJens Taprogge /* unsolicited event for jack sensing */
24117b2bfdbcSJens Taprogge static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
24127b2bfdbcSJens Taprogge {
24137b2bfdbcSJens Taprogge 	snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
24147b2bfdbcSJens Taprogge 	switch (res >> 26) {
24157b2bfdbcSJens Taprogge 	case CONEXANT_HP_EVENT:
24167b2bfdbcSJens Taprogge 		cxt5066_hp_automute(codec);
24177b2bfdbcSJens Taprogge 		break;
24187b2bfdbcSJens Taprogge 	case CONEXANT_MIC_EVENT:
24197b2bfdbcSJens Taprogge 		cxt5066_thinkpad_automic(codec);
24207b2bfdbcSJens Taprogge 		break;
24217b2bfdbcSJens Taprogge 	}
24227b2bfdbcSJens Taprogge }
24237b2bfdbcSJens Taprogge 
24240fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
24250fb67e98SDaniel Drake 	.num_items = 5,
24260fb67e98SDaniel Drake 	.items = {
24270fb67e98SDaniel Drake 		{ "0dB",  0 },
24280fb67e98SDaniel Drake 		{ "10dB", 1 },
24290fb67e98SDaniel Drake 		{ "20dB", 2 },
24300fb67e98SDaniel Drake 		{ "30dB", 3 },
24310fb67e98SDaniel Drake 		{ "40dB", 4 },
24320fb67e98SDaniel Drake 	},
24330fb67e98SDaniel Drake };
24340fb67e98SDaniel Drake 
2435cfd3d8dcSGreg Alexander static void cxt5066_set_mic_boost(struct hda_codec *codec)
2436c4cfe66cSDaniel Drake {
2437c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2438cfd3d8dcSGreg Alexander 	snd_hda_codec_write_cache(codec, 0x17, 0,
2439c4cfe66cSDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2440c4cfe66cSDaniel Drake 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
2441c4cfe66cSDaniel Drake 			cxt5066_analog_mic_boost.items[spec->mic_boost].index);
24427b2bfdbcSJens Taprogge 	if (spec->ideapad || spec->thinkpad) {
2443cfd3d8dcSGreg Alexander 		/* adjust the internal mic as well...it is not through 0x17 */
2444cfd3d8dcSGreg Alexander 		snd_hda_codec_write_cache(codec, 0x23, 0,
2445cfd3d8dcSGreg Alexander 			AC_VERB_SET_AMP_GAIN_MUTE,
2446cfd3d8dcSGreg Alexander 			AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
2447cfd3d8dcSGreg Alexander 				cxt5066_analog_mic_boost.
2448cfd3d8dcSGreg Alexander 					items[spec->mic_boost].index);
2449cfd3d8dcSGreg Alexander 	}
2450c4cfe66cSDaniel Drake }
2451c4cfe66cSDaniel Drake 
24520fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
24530fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
24540fb67e98SDaniel Drake {
24550fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
24560fb67e98SDaniel Drake }
24570fb67e98SDaniel Drake 
24580fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
24590fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24600fb67e98SDaniel Drake {
24610fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2462c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2463c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->mic_boost;
24640fb67e98SDaniel Drake 	return 0;
24650fb67e98SDaniel Drake }
24660fb67e98SDaniel Drake 
24670fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
24680fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
24690fb67e98SDaniel Drake {
24700fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2471c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
24720fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
24730fb67e98SDaniel Drake 	unsigned int idx;
24740fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
24750fb67e98SDaniel Drake 	if (idx >= imux->num_items)
24760fb67e98SDaniel Drake 		idx = imux->num_items - 1;
24770fb67e98SDaniel Drake 
2478c4cfe66cSDaniel Drake 	spec->mic_boost = idx;
2479c4cfe66cSDaniel Drake 	if (!spec->dc_enable)
2480c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
2481c4cfe66cSDaniel Drake 	return 1;
2482c4cfe66cSDaniel Drake }
24830fb67e98SDaniel Drake 
2484c4cfe66cSDaniel Drake static void cxt5066_enable_dc(struct hda_codec *codec)
2485c4cfe66cSDaniel Drake {
2486c4cfe66cSDaniel Drake 	const struct hda_verb enable_dc_mode[] = {
2487c4cfe66cSDaniel Drake 		/* disable gain */
2488c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2489c4cfe66cSDaniel Drake 
2490c4cfe66cSDaniel Drake 		/* switch to DC input */
2491c4cfe66cSDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 3},
2492c4cfe66cSDaniel Drake 		{}
2493c4cfe66cSDaniel Drake 	};
2494c4cfe66cSDaniel Drake 
2495c4cfe66cSDaniel Drake 	/* configure as input source */
2496c4cfe66cSDaniel Drake 	snd_hda_sequence_write(codec, enable_dc_mode);
2497c4cfe66cSDaniel Drake 	cxt5066_olpc_select_mic(codec); /* also sets configured bias */
2498c4cfe66cSDaniel Drake }
2499c4cfe66cSDaniel Drake 
2500c4cfe66cSDaniel Drake static void cxt5066_disable_dc(struct hda_codec *codec)
2501c4cfe66cSDaniel Drake {
2502c4cfe66cSDaniel Drake 	/* reconfigure input source */
2503c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
2504c4cfe66cSDaniel Drake 	/* automic also selects the right mic if we're recording */
2505c4cfe66cSDaniel Drake 	cxt5066_olpc_automic(codec);
2506c4cfe66cSDaniel Drake }
2507c4cfe66cSDaniel Drake 
2508c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
2509c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2510c4cfe66cSDaniel Drake {
2511c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2512c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2513c4cfe66cSDaniel Drake 	ucontrol->value.integer.value[0] = spec->dc_enable;
2514c4cfe66cSDaniel Drake 	return 0;
2515c4cfe66cSDaniel Drake }
2516c4cfe66cSDaniel Drake 
2517c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
2518c4cfe66cSDaniel Drake 			     struct snd_ctl_elem_value *ucontrol)
2519c4cfe66cSDaniel Drake {
2520c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2521c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2522c4cfe66cSDaniel Drake 	int dc_enable = !!ucontrol->value.integer.value[0];
2523c4cfe66cSDaniel Drake 
2524c4cfe66cSDaniel Drake 	if (dc_enable == spec->dc_enable)
2525c4cfe66cSDaniel Drake 		return 0;
2526c4cfe66cSDaniel Drake 
2527c4cfe66cSDaniel Drake 	spec->dc_enable = dc_enable;
2528c4cfe66cSDaniel Drake 	if (dc_enable)
2529c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
2530c4cfe66cSDaniel Drake 	else
2531c4cfe66cSDaniel Drake 		cxt5066_disable_dc(codec);
2532c4cfe66cSDaniel Drake 
2533c4cfe66cSDaniel Drake 	return 1;
2534c4cfe66cSDaniel Drake }
2535c4cfe66cSDaniel Drake 
2536c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
2537c4cfe66cSDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
2538c4cfe66cSDaniel Drake {
2539c4cfe66cSDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
2540c4cfe66cSDaniel Drake }
2541c4cfe66cSDaniel Drake 
2542c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
2543c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2544c4cfe66cSDaniel Drake {
2545c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2546c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2547c4cfe66cSDaniel Drake 	ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
2548c4cfe66cSDaniel Drake 	return 0;
2549c4cfe66cSDaniel Drake }
2550c4cfe66cSDaniel Drake 
2551c4cfe66cSDaniel Drake static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
2552c4cfe66cSDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
2553c4cfe66cSDaniel Drake {
2554c4cfe66cSDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2555c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
2556c4cfe66cSDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
2557c4cfe66cSDaniel Drake 	unsigned int idx;
2558c4cfe66cSDaniel Drake 
2559c4cfe66cSDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
2560c4cfe66cSDaniel Drake 	if (idx >= imux->num_items)
2561c4cfe66cSDaniel Drake 		idx = imux->num_items - 1;
2562c4cfe66cSDaniel Drake 
2563c4cfe66cSDaniel Drake 	spec->dc_input_bias = idx;
2564c4cfe66cSDaniel Drake 	if (spec->dc_enable)
2565c4cfe66cSDaniel Drake 		cxt5066_set_olpc_dc_bias(codec);
25660fb67e98SDaniel Drake 	return 1;
25670fb67e98SDaniel Drake }
25680fb67e98SDaniel Drake 
256975f8991dSDaniel Drake static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
257075f8991dSDaniel Drake {
257175f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
257275f8991dSDaniel Drake 	/* mark as recording and configure the microphone widget so that the
257375f8991dSDaniel Drake 	 * recording LED comes on. */
257475f8991dSDaniel Drake 	spec->recording = 1;
257575f8991dSDaniel Drake 	cxt5066_olpc_select_mic(codec);
257675f8991dSDaniel Drake }
257775f8991dSDaniel Drake 
257875f8991dSDaniel Drake static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
257975f8991dSDaniel Drake {
258075f8991dSDaniel Drake 	struct conexant_spec *spec = codec->spec;
258175f8991dSDaniel Drake 	const struct hda_verb disable_mics[] = {
258275f8991dSDaniel Drake 		/* disable external mic, port B */
258375f8991dSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
258475f8991dSDaniel Drake 
258575f8991dSDaniel Drake 		/* disble internal mic, port C */
258675f8991dSDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2587c4cfe66cSDaniel Drake 
2588c4cfe66cSDaniel Drake 		/* disable DC capture, port F */
2589c4cfe66cSDaniel Drake 		{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
259075f8991dSDaniel Drake 		{},
259175f8991dSDaniel Drake 	};
259275f8991dSDaniel Drake 
259375f8991dSDaniel Drake 	snd_hda_sequence_write(codec, disable_mics);
259475f8991dSDaniel Drake 	spec->recording = 0;
259575f8991dSDaniel Drake }
259675f8991dSDaniel Drake 
25970fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
25980fb67e98SDaniel Drake 	.num_items = 4,
25990fb67e98SDaniel Drake 	.items = {
26000fb67e98SDaniel Drake 		{ "Mic B", 0 },
26010fb67e98SDaniel Drake 		{ "Mic C", 1 },
26020fb67e98SDaniel Drake 		{ "Mic E", 2 },
26030fb67e98SDaniel Drake 		{ "Mic F", 3 },
26040fb67e98SDaniel Drake 	},
26050fb67e98SDaniel Drake };
26060fb67e98SDaniel Drake 
26070fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
26080fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
26090fb67e98SDaniel Drake 	.values = {
26100fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26110fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26120fb67e98SDaniel Drake 		0
26130fb67e98SDaniel Drake 	},
26140fb67e98SDaniel Drake };
26150fb67e98SDaniel Drake 
26160fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
26170fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
26180fb67e98SDaniel Drake 	.values = {
26190fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
26200fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
26210fb67e98SDaniel Drake 		0
26220fb67e98SDaniel Drake 	},
26230fb67e98SDaniel Drake };
26240fb67e98SDaniel Drake 
26250fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
26260fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
26270fb67e98SDaniel Drake 	{}
26280fb67e98SDaniel Drake };
26290fb67e98SDaniel Drake 
26300fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
26310fb67e98SDaniel Drake 	{
26320fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26330fb67e98SDaniel Drake 		.name = "Master Playback Volume",
26340fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
26350fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
26360fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
26375e26dfd0SJaroslav Kysela 		.subdevice = HDA_SUBDEV_AMP_FLAG,
26380fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
26390fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
26400fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
26410fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
26420fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
26430fb67e98SDaniel Drake 		.private_value =
26440fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
26450fb67e98SDaniel Drake 	},
26460fb67e98SDaniel Drake 	{}
26470fb67e98SDaniel Drake };
26480fb67e98SDaniel Drake 
2649c4cfe66cSDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
2650c4cfe66cSDaniel Drake 	{
2651c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2652c4cfe66cSDaniel Drake 		.name = "DC Mode Enable Switch",
2653c4cfe66cSDaniel Drake 		.info = snd_ctl_boolean_mono_info,
2654c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_get,
2655c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_put,
2656c4cfe66cSDaniel Drake 	},
2657c4cfe66cSDaniel Drake 	{
2658c4cfe66cSDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2659c4cfe66cSDaniel Drake 		.name = "DC Input Bias Enum",
2660c4cfe66cSDaniel Drake 		.info = cxt5066_olpc_dc_bias_enum_info,
2661c4cfe66cSDaniel Drake 		.get = cxt5066_olpc_dc_bias_enum_get,
2662c4cfe66cSDaniel Drake 		.put = cxt5066_olpc_dc_bias_enum_put,
2663c4cfe66cSDaniel Drake 	},
2664c4cfe66cSDaniel Drake 	{}
2665c4cfe66cSDaniel Drake };
2666c4cfe66cSDaniel Drake 
26670fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
26680fb67e98SDaniel Drake 	{
26690fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
26700fb67e98SDaniel Drake 		.name = "Master Playback Switch",
26710fb67e98SDaniel Drake 		.info = cxt_eapd_info,
26720fb67e98SDaniel Drake 		.get = cxt_eapd_get,
26730fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
26740fb67e98SDaniel Drake 		.private_value = 0x1d,
26750fb67e98SDaniel Drake 	},
26760fb67e98SDaniel Drake 
26770fb67e98SDaniel Drake 	{
26780fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2679c4cfe66cSDaniel Drake 		.name = "Analog Mic Boost Capture Enum",
26800fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
26810fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
26820fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
26830fb67e98SDaniel Drake 	},
26840fb67e98SDaniel Drake 
26850fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
26860fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
26870fb67e98SDaniel Drake 	{}
26880fb67e98SDaniel Drake };
26890fb67e98SDaniel Drake 
2690254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2691254bba6aSEinar Rünkaru 	{
2692254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2693254bba6aSEinar Rünkaru 		.name = "Int Mic Boost Capture Enum",
2694254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2695254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2696254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2697254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2698254bba6aSEinar Rünkaru 	},
2699254bba6aSEinar Rünkaru 	{}
2700254bba6aSEinar Rünkaru };
2701254bba6aSEinar Rünkaru 
27020fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
27030fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
27040fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
27050fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
27060fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
27070fb67e98SDaniel Drake 
27080fb67e98SDaniel Drake 	/* Speakers  */
27090fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27100fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27110fb67e98SDaniel Drake 
27120fb67e98SDaniel Drake 	/* HP, Amp  */
27130fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27140fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27150fb67e98SDaniel Drake 
27160fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27170fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27180fb67e98SDaniel Drake 
27190fb67e98SDaniel Drake 	/* DAC1 */
27200fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27210fb67e98SDaniel Drake 
27220fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
27230fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27240fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27250fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
27260fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27270fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
27280fb67e98SDaniel Drake 
27290fb67e98SDaniel Drake 	/* no digital microphone support yet */
27300fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27310fb67e98SDaniel Drake 
27320fb67e98SDaniel Drake 	/* Audio input selector */
27330fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
27340fb67e98SDaniel Drake 
27350fb67e98SDaniel Drake 	/* SPDIF route: PCM */
27360fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
27370fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
27380fb67e98SDaniel Drake 
27390fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27400fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27410fb67e98SDaniel Drake 
27420fb67e98SDaniel Drake 	/* EAPD */
27430fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27440fb67e98SDaniel Drake 
27450fb67e98SDaniel Drake 	/* not handling these yet */
27460fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27470fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27480fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27490fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27500fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27510fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27520fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27530fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
27540fb67e98SDaniel Drake 	{ } /* end */
27550fb67e98SDaniel Drake };
27560fb67e98SDaniel Drake 
27570fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
27580fb67e98SDaniel Drake 	/* Port A: headphones */
27590fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
27600fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27610fb67e98SDaniel Drake 
27620fb67e98SDaniel Drake 	/* Port B: external microphone */
276375f8991dSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27640fb67e98SDaniel Drake 
27650fb67e98SDaniel Drake 	/* Port C: internal microphone */
276675f8991dSDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27670fb67e98SDaniel Drake 
27680fb67e98SDaniel Drake 	/* Port D: unused */
27690fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27700fb67e98SDaniel Drake 
27710fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
27720fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27730fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
27740fb67e98SDaniel Drake 
2775c4cfe66cSDaniel Drake 	/* Port F: external DC input through microphone port */
27760fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
27770fb67e98SDaniel Drake 
27780fb67e98SDaniel Drake 	/* Port G: internal speakers */
27790fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
27800fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
27810fb67e98SDaniel Drake 
27820fb67e98SDaniel Drake 	/* DAC1 */
27830fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
27840fb67e98SDaniel Drake 
27850fb67e98SDaniel Drake 	/* DAC2: unused */
27860fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
27870fb67e98SDaniel Drake 
27880fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
27890fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27900fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27910fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27920fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27930fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27940fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27950fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
27960fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
27970fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
27980fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
27990fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
28000fb67e98SDaniel Drake 
28010fb67e98SDaniel Drake 	/* Disable digital microphone port */
28020fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28030fb67e98SDaniel Drake 
28040fb67e98SDaniel Drake 	/* Audio input selectors */
28050fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
28060fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
28070fb67e98SDaniel Drake 
28080fb67e98SDaniel Drake 	/* Disable SPDIF */
28090fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28100fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
28110fb67e98SDaniel Drake 
28120fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
28130fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
28140fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
28150fb67e98SDaniel Drake 	{ } /* end */
28160fb67e98SDaniel Drake };
28170fb67e98SDaniel Drake 
281895a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
281995a618bdSEinar Rünkaru 	/* Port A: headphones */
282095a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
282195a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
282295a618bdSEinar Rünkaru 
282395a618bdSEinar Rünkaru 	/* Port B: external microphone */
282495a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
282595a618bdSEinar Rünkaru 
282695a618bdSEinar Rünkaru 	/* Port C: unused */
282795a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
282895a618bdSEinar Rünkaru 
282995a618bdSEinar Rünkaru 	/* Port D: unused */
283095a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283195a618bdSEinar Rünkaru 
283295a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
283395a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283495a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
283595a618bdSEinar Rünkaru 
283695a618bdSEinar Rünkaru 	/* Port F: unused */
283795a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
283895a618bdSEinar Rünkaru 
283995a618bdSEinar Rünkaru 	/* Port G: internal speakers */
284095a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
284195a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
284295a618bdSEinar Rünkaru 
284395a618bdSEinar Rünkaru 	/* DAC1 */
284495a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
284595a618bdSEinar Rünkaru 
284695a618bdSEinar Rünkaru 	/* DAC2: unused */
284795a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
284895a618bdSEinar Rünkaru 
284995a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
285095a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
285195a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
285295a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
285395a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
285495a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
285595a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
285695a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
285795a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
285895a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
285995a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
286095a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
286195a618bdSEinar Rünkaru 
286295a618bdSEinar Rünkaru 	/* Digital microphone port */
286395a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
286495a618bdSEinar Rünkaru 
286595a618bdSEinar Rünkaru 	/* Audio input selectors */
286695a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
286795a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
286895a618bdSEinar Rünkaru 
286995a618bdSEinar Rünkaru 	/* Disable SPDIF */
287095a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
287195a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
287295a618bdSEinar Rünkaru 
287395a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
287495a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
287595a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
287695a618bdSEinar Rünkaru 	{ } /* end */
287795a618bdSEinar Rünkaru };
287895a618bdSEinar Rünkaru 
2879cfd3d8dcSGreg Alexander static struct hda_verb cxt5066_init_verbs_ideapad[] = {
2880cfd3d8dcSGreg Alexander 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
2881cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
2882cfd3d8dcSGreg Alexander 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
2883cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
2884cfd3d8dcSGreg Alexander 
2885cfd3d8dcSGreg Alexander 	/* Speakers  */
2886cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2887cfd3d8dcSGreg Alexander 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2888cfd3d8dcSGreg Alexander 
2889cfd3d8dcSGreg Alexander 	/* HP, Amp  */
2890cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2891cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2892cfd3d8dcSGreg Alexander 
2893cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2894cfd3d8dcSGreg Alexander 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
2895cfd3d8dcSGreg Alexander 
2896cfd3d8dcSGreg Alexander 	/* DAC1 */
2897cfd3d8dcSGreg Alexander 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2898cfd3d8dcSGreg Alexander 
2899cfd3d8dcSGreg Alexander 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
2900cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
2901cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2902cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
2903cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
2904cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
2905cfd3d8dcSGreg Alexander 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
2906cfd3d8dcSGreg Alexander 
2907cfd3d8dcSGreg Alexander 	/* Audio input selector */
2908cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
2909cfd3d8dcSGreg Alexander 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
2910cfd3d8dcSGreg Alexander 
2911cfd3d8dcSGreg Alexander 	/* SPDIF route: PCM */
2912cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
2913cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
2914cfd3d8dcSGreg Alexander 
2915cfd3d8dcSGreg Alexander 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2916cfd3d8dcSGreg Alexander 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2917cfd3d8dcSGreg Alexander 
2918cfd3d8dcSGreg Alexander 	/* internal microphone */
2919cfd3d8dcSGreg Alexander 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
2920cfd3d8dcSGreg Alexander 
2921cfd3d8dcSGreg Alexander 	/* EAPD */
2922cfd3d8dcSGreg Alexander 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
2923cfd3d8dcSGreg Alexander 
2924cfd3d8dcSGreg Alexander 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
2925cfd3d8dcSGreg Alexander 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
2926cfd3d8dcSGreg Alexander 	{ } /* end */
2927cfd3d8dcSGreg Alexander };
2928cfd3d8dcSGreg Alexander 
29297b2bfdbcSJens Taprogge static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
29307b2bfdbcSJens Taprogge 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
29317b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
29327b2bfdbcSJens Taprogge 
29337b2bfdbcSJens Taprogge 	/* Port G: internal speakers  */
29347b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29357b2bfdbcSJens Taprogge 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29367b2bfdbcSJens Taprogge 
29377b2bfdbcSJens Taprogge 	/* Port A: HP, Amp  */
29387b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29397b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29407b2bfdbcSJens Taprogge 
29417b2bfdbcSJens Taprogge 	/* Port B: Mic Dock */
29427b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29437b2bfdbcSJens Taprogge 
29447b2bfdbcSJens Taprogge 	/* Port C: Mic */
29457b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29467b2bfdbcSJens Taprogge 
29477b2bfdbcSJens Taprogge 	/* Port D: HP Dock, Amp */
29487b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
29497b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
29507b2bfdbcSJens Taprogge 
29517b2bfdbcSJens Taprogge 	/* DAC1 */
29527b2bfdbcSJens Taprogge 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
29537b2bfdbcSJens Taprogge 
29547b2bfdbcSJens Taprogge 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
29557b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
29567b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
29577b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
29587b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
29597b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
29607b2bfdbcSJens Taprogge 	{0x14, AC_VERB_SET_CONNECT_SEL, 2},	/* default to internal mic */
29617b2bfdbcSJens Taprogge 
29627b2bfdbcSJens Taprogge 	/* Audio input selector */
29637b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
29647b2bfdbcSJens Taprogge 	{0x17, AC_VERB_SET_CONNECT_SEL, 1},	/* route ext mic */
29657b2bfdbcSJens Taprogge 
29667b2bfdbcSJens Taprogge 	/* SPDIF route: PCM */
29677b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
29687b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
29697b2bfdbcSJens Taprogge 
29707b2bfdbcSJens Taprogge 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29717b2bfdbcSJens Taprogge 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29727b2bfdbcSJens Taprogge 
29737b2bfdbcSJens Taprogge 	/* internal microphone */
29747b2bfdbcSJens Taprogge 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
29757b2bfdbcSJens Taprogge 
29767b2bfdbcSJens Taprogge 	/* EAPD */
29777b2bfdbcSJens Taprogge 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
29787b2bfdbcSJens Taprogge 
29797b2bfdbcSJens Taprogge 	/* enable unsolicited events for Port A, B, C and D */
29807b2bfdbcSJens Taprogge 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29817b2bfdbcSJens Taprogge 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
29827b2bfdbcSJens Taprogge 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29837b2bfdbcSJens Taprogge 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
29847b2bfdbcSJens Taprogge 	{ } /* end */
29857b2bfdbcSJens Taprogge };
29867b2bfdbcSJens Taprogge 
29870fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
29880fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
29890fb67e98SDaniel Drake 	{ } /* end */
29900fb67e98SDaniel Drake };
29910fb67e98SDaniel Drake 
29920fb67e98SDaniel Drake /* initialize jack-sensing, too */
29930fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
29940fb67e98SDaniel Drake {
2995254bba6aSEinar Rünkaru 	struct conexant_spec *spec = codec->spec;
2996254bba6aSEinar Rünkaru 
29970fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
29980fb67e98SDaniel Drake 	conexant_init(codec);
29990fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
30000fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
3001254bba6aSEinar Rünkaru 		if (spec->dell_vostro)
3002254bba6aSEinar Rünkaru 			cxt5066_vostro_automic(codec);
3003cfd3d8dcSGreg Alexander 		else if (spec->ideapad)
3004cfd3d8dcSGreg Alexander 			cxt5066_ideapad_automic(codec);
30057b2bfdbcSJens Taprogge 		else if (spec->thinkpad)
30067b2bfdbcSJens Taprogge 			cxt5066_thinkpad_automic(codec);
30070fb67e98SDaniel Drake 	}
3008c4cfe66cSDaniel Drake 	cxt5066_set_mic_boost(codec);
30090fb67e98SDaniel Drake 	return 0;
30100fb67e98SDaniel Drake }
30110fb67e98SDaniel Drake 
301275f8991dSDaniel Drake static int cxt5066_olpc_init(struct hda_codec *codec)
301375f8991dSDaniel Drake {
3014c4cfe66cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
301575f8991dSDaniel Drake 	snd_printdd("CXT5066: init\n");
301675f8991dSDaniel Drake 	conexant_init(codec);
301775f8991dSDaniel Drake 	cxt5066_hp_automute(codec);
3018c4cfe66cSDaniel Drake 	if (!spec->dc_enable) {
3019c4cfe66cSDaniel Drake 		cxt5066_set_mic_boost(codec);
302075f8991dSDaniel Drake 		cxt5066_olpc_automic(codec);
3021c4cfe66cSDaniel Drake 	} else {
3022c4cfe66cSDaniel Drake 		cxt5066_enable_dc(codec);
3023c4cfe66cSDaniel Drake 	}
302475f8991dSDaniel Drake 	return 0;
302575f8991dSDaniel Drake }
302675f8991dSDaniel Drake 
30270fb67e98SDaniel Drake enum {
30280fb67e98SDaniel Drake 	CXT5066_LAPTOP,		/* Laptops w/ EAPD support */
30290fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
30300fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
303195a618bdSEinar Rünkaru 	CXT5066_DELL_VOSTO,	/* Dell Vostro 1015i */
3032cfd3d8dcSGreg Alexander 	CXT5066_IDEAPAD,	/* Lenovo IdeaPad U150 */
30337b2bfdbcSJens Taprogge 	CXT5066_THINKPAD,	/* Lenovo ThinkPad T410s, others? */
30340fb67e98SDaniel Drake 	CXT5066_MODELS
30350fb67e98SDaniel Drake };
30360fb67e98SDaniel Drake 
30370fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = {
30380fb67e98SDaniel Drake 	[CXT5066_LAPTOP]	= "laptop",
30390fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
30400fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
3041cfd3d8dcSGreg Alexander 	[CXT5066_DELL_VOSTO]    = "dell-vostro",
3042cfd3d8dcSGreg Alexander 	[CXT5066_IDEAPAD]	= "ideapad",
30437b2bfdbcSJens Taprogge 	[CXT5066_THINKPAD]	= "thinkpad",
30440fb67e98SDaniel Drake };
30450fb67e98SDaniel Drake 
30460fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
30470fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
30480fb67e98SDaniel Drake 		      CXT5066_LAPTOP),
30490fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
30500fb67e98SDaniel Drake 		      CXT5066_DELL_LAPTOP),
3051798a8a15SDaniel Drake 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
3052c3e68fadSTakashi Iwai 	SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTO),
305395a618bdSEinar Rünkaru 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
3054231f50bcSAnisse Astier 	SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
3055c5366681SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
30564442dd46SDaniel T Chen 	SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
30570217f149SAndrej Gelenberg 	SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
3058badf18b5SAndreas Herrmann 	SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
3059a39e33ebSJerone Young 	SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
30607b2bfdbcSJens Taprogge  	SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3061ab85457fSJerone Young  	SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G series", CXT5066_IDEAPAD),
3062*6f0ef6eaSJerone Young 	SND_PCI_QUIRK(0x17aa, 0x390a, "Lenovo S10-3t", CXT5066_IDEAPAD),
3063ab85457fSJerone Young 	SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G series (AMD)", CXT5066_IDEAPAD),
3064ab85457fSJerone Young 	SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
30650fb67e98SDaniel Drake 	{}
30660fb67e98SDaniel Drake };
30670fb67e98SDaniel Drake 
30680fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
30690fb67e98SDaniel Drake {
30700fb67e98SDaniel Drake 	struct conexant_spec *spec;
30710fb67e98SDaniel Drake 	int board_config;
30720fb67e98SDaniel Drake 
30730fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
30740fb67e98SDaniel Drake 	if (!spec)
30750fb67e98SDaniel Drake 		return -ENOMEM;
30760fb67e98SDaniel Drake 	codec->spec = spec;
30770fb67e98SDaniel Drake 
30780fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
307975f8991dSDaniel Drake 	codec->patch_ops.init = conexant_init;
30800fb67e98SDaniel Drake 
30810fb67e98SDaniel Drake 	spec->dell_automute = 0;
30820fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
30830fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
30840fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
30850fb67e98SDaniel Drake 	spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
30860fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
30870fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
30880fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
30890fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
30900fb67e98SDaniel Drake 
30910fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
30920fb67e98SDaniel Drake 
30930fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
30940fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
30950fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
30960fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
30970fb67e98SDaniel Drake 	spec->cur_adc = 0;
30980fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
30990fb67e98SDaniel Drake 
31003507e2a8STakashi Iwai 	set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
31013507e2a8STakashi Iwai 
31020fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
31030fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
31040fb67e98SDaniel Drake 	switch (board_config) {
31050fb67e98SDaniel Drake 	default:
31060fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
31070fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31080fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31090fb67e98SDaniel Drake 		break;
31100fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
31110fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31120fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31130fb67e98SDaniel Drake 
31140fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
31150fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
31160fb67e98SDaniel Drake 		spec->num_init_verbs++;
31170fb67e98SDaniel Drake 		spec->dell_automute = 1;
31180fb67e98SDaniel Drake 		break;
31190fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
312075f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_olpc_init;
312175f8991dSDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
31220fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
31230fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
3124c4cfe66cSDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
31250fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31260fb67e98SDaniel Drake 		spec->port_d_mode = 0;
3127c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
31280fb67e98SDaniel Drake 
31290fb67e98SDaniel Drake 		/* no S/PDIF out */
31300fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
31310fb67e98SDaniel Drake 
31320fb67e98SDaniel Drake 		/* input source automatically selected */
31330fb67e98SDaniel Drake 		spec->input_mux = NULL;
313475f8991dSDaniel Drake 
313575f8991dSDaniel Drake 		/* our capture hooks which allow us to turn on the microphone LED
313675f8991dSDaniel Drake 		 * at the right time */
313775f8991dSDaniel Drake 		spec->capture_prepare = cxt5066_olpc_capture_prepare;
313875f8991dSDaniel Drake 		spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
31390fb67e98SDaniel Drake 		break;
314095a618bdSEinar Rünkaru 	case CXT5066_DELL_VOSTO:
314175f8991dSDaniel Drake 		codec->patch_ops.init = cxt5066_init;
314295a618bdSEinar Rünkaru 		codec->patch_ops.unsol_event = cxt5066_vostro_event;
314395a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
314495a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
314595a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3146254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
314795a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
3148254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
3149c4cfe66cSDaniel Drake 		spec->mic_boost = 3; /* default 30dB gain */
315095a618bdSEinar Rünkaru 
315195a618bdSEinar Rünkaru 		/* no S/PDIF out */
315295a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
315395a618bdSEinar Rünkaru 
315495a618bdSEinar Rünkaru 		/* input source automatically selected */
315595a618bdSEinar Rünkaru 		spec->input_mux = NULL;
315695a618bdSEinar Rünkaru 		break;
3157cfd3d8dcSGreg Alexander 	case CXT5066_IDEAPAD:
3158cfd3d8dcSGreg Alexander 		codec->patch_ops.init = cxt5066_init;
3159cfd3d8dcSGreg Alexander 		codec->patch_ops.unsol_event = cxt5066_ideapad_event;
3160cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
3161cfd3d8dcSGreg Alexander 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
3162cfd3d8dcSGreg Alexander 		spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
3163cfd3d8dcSGreg Alexander 		spec->port_d_mode = 0;
3164cfd3d8dcSGreg Alexander 		spec->ideapad = 1;
3165cfd3d8dcSGreg Alexander 		spec->mic_boost = 2;	/* default 20dB gain */
3166cfd3d8dcSGreg Alexander 
3167cfd3d8dcSGreg Alexander 		/* no S/PDIF out */
3168cfd3d8dcSGreg Alexander 		spec->multiout.dig_out_nid = 0;
3169cfd3d8dcSGreg Alexander 
3170cfd3d8dcSGreg Alexander 		/* input source automatically selected */
3171cfd3d8dcSGreg Alexander 		spec->input_mux = NULL;
3172cfd3d8dcSGreg Alexander 		break;
31737b2bfdbcSJens Taprogge 	case CXT5066_THINKPAD:
31747b2bfdbcSJens Taprogge 		codec->patch_ops.init = cxt5066_init;
31757b2bfdbcSJens Taprogge 		codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
31767b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
31777b2bfdbcSJens Taprogge 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
31787b2bfdbcSJens Taprogge 		spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
31797b2bfdbcSJens Taprogge 		spec->thinkpad = 1;
31807b2bfdbcSJens Taprogge 		spec->port_d_mode = PIN_OUT;
31817b2bfdbcSJens Taprogge 		spec->mic_boost = 2;	/* default 20dB gain */
31827b2bfdbcSJens Taprogge 
31837b2bfdbcSJens Taprogge 		/* no S/PDIF out */
31847b2bfdbcSJens Taprogge 		spec->multiout.dig_out_nid = 0;
31857b2bfdbcSJens Taprogge 
31867b2bfdbcSJens Taprogge 		/* input source automatically selected */
31877b2bfdbcSJens Taprogge 		spec->input_mux = NULL;
31887b2bfdbcSJens Taprogge 		break;
31890fb67e98SDaniel Drake 	}
31900fb67e98SDaniel Drake 
31913507e2a8STakashi Iwai 	if (spec->beep_amp)
31923507e2a8STakashi Iwai 		snd_hda_attach_beep_device(codec, spec->beep_amp);
31933507e2a8STakashi Iwai 
31940fb67e98SDaniel Drake 	return 0;
31950fb67e98SDaniel Drake }
3196461e2c78STakashi Iwai 
3197461e2c78STakashi Iwai /*
3198461e2c78STakashi Iwai  */
3199461e2c78STakashi Iwai 
32001289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
320182f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
320282f30040STobin Davis 	  .patch = patch_cxt5045 },
320382f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
320482f30040STobin Davis 	  .patch = patch_cxt5047 },
3205461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
3206461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
32070fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
32080fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
320995a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
321095a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
3211850eab9dSTakashi Iwai 	{ .id = 0x14f15068, .name = "CX20584",
3212850eab9dSTakashi Iwai 	  .patch = patch_cxt5066 },
32137b2bfdbcSJens Taprogge 	{ .id = 0x14f15069, .name = "CX20585",
32147b2bfdbcSJens Taprogge 	  .patch = patch_cxt5066 },
3215c9b443d4STobin Davis 	{} /* terminator */
3216c9b443d4STobin Davis };
32171289e9e8STakashi Iwai 
32181289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
32191289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
32201289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
32210fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
322295a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
3223850eab9dSTakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15068");
32247b2bfdbcSJens Taprogge MODULE_ALIAS("snd-hda-codec-id:14f15069");
32251289e9e8STakashi Iwai 
32261289e9e8STakashi Iwai MODULE_LICENSE("GPL");
32271289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
32281289e9e8STakashi Iwai 
32291289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
32301289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
32311289e9e8STakashi Iwai 	.owner = THIS_MODULE,
32321289e9e8STakashi Iwai };
32331289e9e8STakashi Iwai 
32341289e9e8STakashi Iwai static int __init patch_conexant_init(void)
32351289e9e8STakashi Iwai {
32361289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
32371289e9e8STakashi Iwai }
32381289e9e8STakashi Iwai 
32391289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
32401289e9e8STakashi Iwai {
32411289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
32421289e9e8STakashi Iwai }
32431289e9e8STakashi Iwai 
32441289e9e8STakashi Iwai module_init(patch_conexant_init)
32451289e9e8STakashi Iwai module_exit(patch_conexant_exit)
3246