xref: /openbmc/linux/sound/pci/hda/patch_conexant.c (revision c0f8faf0c7cd497ec7c1d61e1e9424f4384c1f68)
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"
32*c0f8faf0SEinar 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 
45bc7a166dSUlrich Dangel #define CXT5051_SPDIF_OUT	0x1C
46bc7a166dSUlrich Dangel #define CXT5051_PORTB_EVENT	0x38
47bc7a166dSUlrich Dangel #define CXT5051_PORTC_EVENT	0x39
48bc7a166dSUlrich Dangel 
49bc7a166dSUlrich Dangel 
50bc7a166dSUlrich Dangel struct conexant_jack {
51bc7a166dSUlrich Dangel 
52bc7a166dSUlrich Dangel 	hda_nid_t nid;
53bc7a166dSUlrich Dangel 	int type;
54bc7a166dSUlrich Dangel 	struct snd_jack *jack;
55bc7a166dSUlrich Dangel 
56bc7a166dSUlrich Dangel };
57c9b443d4STobin Davis 
58c9b443d4STobin Davis struct conexant_spec {
59c9b443d4STobin Davis 
60c9b443d4STobin Davis 	struct snd_kcontrol_new *mixers[5];
61c9b443d4STobin Davis 	int num_mixers;
62dd5746a8STakashi Iwai 	hda_nid_t vmaster_nid;
63c9b443d4STobin Davis 
64c9b443d4STobin Davis 	const struct hda_verb *init_verbs[5];	/* initialization verbs
65c9b443d4STobin Davis 						 * don't forget NULL
66c9b443d4STobin Davis 						 * termination!
67c9b443d4STobin Davis 						 */
68c9b443d4STobin Davis 	unsigned int num_init_verbs;
69c9b443d4STobin Davis 
70c9b443d4STobin Davis 	/* playback */
71c9b443d4STobin Davis 	struct hda_multi_out multiout;	/* playback set-up
72c9b443d4STobin Davis 					 * max_channels, dacs must be set
73c9b443d4STobin Davis 					 * dig_out_nid and hp_nid are optional
74c9b443d4STobin Davis 					 */
75c9b443d4STobin Davis 	unsigned int cur_eapd;
7682f30040STobin Davis 	unsigned int hp_present;
7779d7d533STakashi Iwai 	unsigned int no_auto_mic;
78c9b443d4STobin Davis 	unsigned int need_dac_fix;
79c9b443d4STobin Davis 
80c9b443d4STobin Davis 	/* capture */
81c9b443d4STobin Davis 	unsigned int num_adc_nids;
82c9b443d4STobin Davis 	hda_nid_t *adc_nids;
83c9b443d4STobin Davis 	hda_nid_t dig_in_nid;		/* digital-in NID; optional */
84c9b443d4STobin Davis 
85461e2c78STakashi Iwai 	unsigned int cur_adc_idx;
86461e2c78STakashi Iwai 	hda_nid_t cur_adc;
87461e2c78STakashi Iwai 	unsigned int cur_adc_stream_tag;
88461e2c78STakashi Iwai 	unsigned int cur_adc_format;
89461e2c78STakashi Iwai 
90c9b443d4STobin Davis 	/* capture source */
91c9b443d4STobin Davis 	const struct hda_input_mux *input_mux;
92c9b443d4STobin Davis 	hda_nid_t *capsrc_nids;
93c9b443d4STobin Davis 	unsigned int cur_mux[3];
94c9b443d4STobin Davis 
95c9b443d4STobin Davis 	/* channel model */
96c9b443d4STobin Davis 	const struct hda_channel_mode *channel_mode;
97c9b443d4STobin Davis 	int num_channel_mode;
98c9b443d4STobin Davis 
99c9b443d4STobin Davis 	/* PCM information */
100c9b443d4STobin Davis 	struct hda_pcm pcm_rec[2];	/* used in build_pcms() */
101c9b443d4STobin Davis 
102c9b443d4STobin Davis 	unsigned int spdif_route;
103c9b443d4STobin Davis 
104bc7a166dSUlrich Dangel 	/* jack detection */
105bc7a166dSUlrich Dangel 	struct snd_array jacks;
106bc7a166dSUlrich Dangel 
107c9b443d4STobin Davis 	/* dynamic controls, init_verbs and input_mux */
108c9b443d4STobin Davis 	struct auto_pin_cfg autocfg;
109c9b443d4STobin Davis 	struct hda_input_mux private_imux;
11041923e44STakashi Iwai 	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
111c9b443d4STobin Davis 
1120fb67e98SDaniel Drake 	unsigned int dell_automute;
1130fb67e98SDaniel Drake 	unsigned int port_d_mode;
114dbaccc0cSDaniel Drake 	unsigned char ext_mic_bias;
115254bba6aSEinar Rünkaru 	unsigned int dell_vostro;
116c9b443d4STobin Davis };
117c9b443d4STobin Davis 
118c9b443d4STobin Davis static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
119c9b443d4STobin Davis 				      struct hda_codec *codec,
120c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
121c9b443d4STobin Davis {
122c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
1239a08160bSTakashi Iwai 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1249a08160bSTakashi Iwai 					     hinfo);
125c9b443d4STobin Davis }
126c9b443d4STobin Davis 
127c9b443d4STobin Davis static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
128c9b443d4STobin Davis 					 struct hda_codec *codec,
129c9b443d4STobin Davis 					 unsigned int stream_tag,
130c9b443d4STobin Davis 					 unsigned int format,
131c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
132c9b443d4STobin Davis {
133c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
134c9b443d4STobin Davis 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
135c9b443d4STobin Davis 						stream_tag,
136c9b443d4STobin Davis 						format, substream);
137c9b443d4STobin Davis }
138c9b443d4STobin Davis 
139c9b443d4STobin Davis static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
140c9b443d4STobin Davis 					 struct hda_codec *codec,
141c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
142c9b443d4STobin Davis {
143c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
144c9b443d4STobin Davis 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
145c9b443d4STobin Davis }
146c9b443d4STobin Davis 
147c9b443d4STobin Davis /*
148c9b443d4STobin Davis  * Digital out
149c9b443d4STobin Davis  */
150c9b443d4STobin Davis static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
151c9b443d4STobin Davis 					  struct hda_codec *codec,
152c9b443d4STobin Davis 					  struct snd_pcm_substream *substream)
153c9b443d4STobin Davis {
154c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
155c9b443d4STobin Davis 	return snd_hda_multi_out_dig_open(codec, &spec->multiout);
156c9b443d4STobin Davis }
157c9b443d4STobin Davis 
158c9b443d4STobin Davis static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
159c9b443d4STobin Davis 					 struct hda_codec *codec,
160c9b443d4STobin Davis 					 struct snd_pcm_substream *substream)
161c9b443d4STobin Davis {
162c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
163c9b443d4STobin Davis 	return snd_hda_multi_out_dig_close(codec, &spec->multiout);
164c9b443d4STobin Davis }
165c9b443d4STobin Davis 
1666b97eb45STakashi Iwai static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1676b97eb45STakashi Iwai 					 struct hda_codec *codec,
1686b97eb45STakashi Iwai 					 unsigned int stream_tag,
1696b97eb45STakashi Iwai 					 unsigned int format,
1706b97eb45STakashi Iwai 					 struct snd_pcm_substream *substream)
1716b97eb45STakashi Iwai {
1726b97eb45STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1736b97eb45STakashi Iwai 	return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1746b97eb45STakashi Iwai 					     stream_tag,
1756b97eb45STakashi Iwai 					     format, substream);
1766b97eb45STakashi Iwai }
1776b97eb45STakashi Iwai 
178c9b443d4STobin Davis /*
179c9b443d4STobin Davis  * Analog capture
180c9b443d4STobin Davis  */
181c9b443d4STobin Davis static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
182c9b443d4STobin Davis 				      struct hda_codec *codec,
183c9b443d4STobin Davis 				      unsigned int stream_tag,
184c9b443d4STobin Davis 				      unsigned int format,
185c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
186c9b443d4STobin Davis {
187c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
188c9b443d4STobin Davis 	snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
189c9b443d4STobin Davis 				   stream_tag, 0, format);
190c9b443d4STobin Davis 	return 0;
191c9b443d4STobin Davis }
192c9b443d4STobin Davis 
193c9b443d4STobin Davis static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
194c9b443d4STobin Davis 				      struct hda_codec *codec,
195c9b443d4STobin Davis 				      struct snd_pcm_substream *substream)
196c9b443d4STobin Davis {
197c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
198888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
199c9b443d4STobin Davis 	return 0;
200c9b443d4STobin Davis }
201c9b443d4STobin Davis 
202c9b443d4STobin Davis 
203c9b443d4STobin Davis 
204c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_playback = {
205c9b443d4STobin Davis 	.substreams = 1,
206c9b443d4STobin Davis 	.channels_min = 2,
207c9b443d4STobin Davis 	.channels_max = 2,
208c9b443d4STobin Davis 	.nid = 0, /* fill later */
209c9b443d4STobin Davis 	.ops = {
210c9b443d4STobin Davis 		.open = conexant_playback_pcm_open,
211c9b443d4STobin Davis 		.prepare = conexant_playback_pcm_prepare,
212c9b443d4STobin Davis 		.cleanup = conexant_playback_pcm_cleanup
213c9b443d4STobin Davis 	},
214c9b443d4STobin Davis };
215c9b443d4STobin Davis 
216c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_analog_capture = {
217c9b443d4STobin Davis 	.substreams = 1,
218c9b443d4STobin Davis 	.channels_min = 2,
219c9b443d4STobin Davis 	.channels_max = 2,
220c9b443d4STobin Davis 	.nid = 0, /* fill later */
221c9b443d4STobin Davis 	.ops = {
222c9b443d4STobin Davis 		.prepare = conexant_capture_pcm_prepare,
223c9b443d4STobin Davis 		.cleanup = conexant_capture_pcm_cleanup
224c9b443d4STobin Davis 	},
225c9b443d4STobin Davis };
226c9b443d4STobin Davis 
227c9b443d4STobin Davis 
228c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_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_dig_playback_pcm_open,
2356b97eb45STakashi Iwai 		.close = conexant_dig_playback_pcm_close,
2366b97eb45STakashi Iwai 		.prepare = conexant_dig_playback_pcm_prepare
237c9b443d4STobin Davis 	},
238c9b443d4STobin Davis };
239c9b443d4STobin Davis 
240c9b443d4STobin Davis static struct hda_pcm_stream conexant_pcm_digital_capture = {
241c9b443d4STobin Davis 	.substreams = 1,
242c9b443d4STobin Davis 	.channels_min = 2,
243c9b443d4STobin Davis 	.channels_max = 2,
244c9b443d4STobin Davis 	/* NID is set in alc_build_pcms */
245c9b443d4STobin Davis };
246c9b443d4STobin Davis 
247461e2c78STakashi Iwai static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
248461e2c78STakashi Iwai 				      struct hda_codec *codec,
249461e2c78STakashi Iwai 				      unsigned int stream_tag,
250461e2c78STakashi Iwai 				      unsigned int format,
251461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
252461e2c78STakashi Iwai {
253461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
254461e2c78STakashi Iwai 	spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
255461e2c78STakashi Iwai 	spec->cur_adc_stream_tag = stream_tag;
256461e2c78STakashi Iwai 	spec->cur_adc_format = format;
257461e2c78STakashi Iwai 	snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
258461e2c78STakashi Iwai 	return 0;
259461e2c78STakashi Iwai }
260461e2c78STakashi Iwai 
261461e2c78STakashi Iwai static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
262461e2c78STakashi Iwai 				      struct hda_codec *codec,
263461e2c78STakashi Iwai 				      struct snd_pcm_substream *substream)
264461e2c78STakashi Iwai {
265461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
266888afa15STakashi Iwai 	snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
267461e2c78STakashi Iwai 	spec->cur_adc = 0;
268461e2c78STakashi Iwai 	return 0;
269461e2c78STakashi Iwai }
270461e2c78STakashi Iwai 
271461e2c78STakashi Iwai static struct hda_pcm_stream cx5051_pcm_analog_capture = {
272461e2c78STakashi Iwai 	.substreams = 1,
273461e2c78STakashi Iwai 	.channels_min = 2,
274461e2c78STakashi Iwai 	.channels_max = 2,
275461e2c78STakashi Iwai 	.nid = 0, /* fill later */
276461e2c78STakashi Iwai 	.ops = {
277461e2c78STakashi Iwai 		.prepare = cx5051_capture_pcm_prepare,
278461e2c78STakashi Iwai 		.cleanup = cx5051_capture_pcm_cleanup
279461e2c78STakashi Iwai 	},
280461e2c78STakashi Iwai };
281461e2c78STakashi Iwai 
282c9b443d4STobin Davis static int conexant_build_pcms(struct hda_codec *codec)
283c9b443d4STobin Davis {
284c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
285c9b443d4STobin Davis 	struct hda_pcm *info = spec->pcm_rec;
286c9b443d4STobin Davis 
287c9b443d4STobin Davis 	codec->num_pcms = 1;
288c9b443d4STobin Davis 	codec->pcm_info = info;
289c9b443d4STobin Davis 
290c9b443d4STobin Davis 	info->name = "CONEXANT Analog";
291c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
292c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
293c9b443d4STobin Davis 		spec->multiout.max_channels;
294c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
295c9b443d4STobin Davis 		spec->multiout.dac_nids[0];
296461e2c78STakashi Iwai 	if (codec->vendor_id == 0x14f15051)
297461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
298461e2c78STakashi Iwai 			cx5051_pcm_analog_capture;
299461e2c78STakashi Iwai 	else
300461e2c78STakashi Iwai 		info->stream[SNDRV_PCM_STREAM_CAPTURE] =
301461e2c78STakashi Iwai 			conexant_pcm_analog_capture;
302c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
303c9b443d4STobin Davis 	info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
304c9b443d4STobin Davis 
305c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
306c9b443d4STobin Davis 		info++;
307c9b443d4STobin Davis 		codec->num_pcms++;
308c9b443d4STobin Davis 		info->name = "Conexant Digital";
3097ba72ba1STakashi Iwai 		info->pcm_type = HDA_PCM_TYPE_SPDIF;
310c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
311c9b443d4STobin Davis 			conexant_pcm_digital_playback;
312c9b443d4STobin Davis 		info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
313c9b443d4STobin Davis 			spec->multiout.dig_out_nid;
314c9b443d4STobin Davis 		if (spec->dig_in_nid) {
315c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE] =
316c9b443d4STobin Davis 				conexant_pcm_digital_capture;
317c9b443d4STobin Davis 			info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
318c9b443d4STobin Davis 				spec->dig_in_nid;
319c9b443d4STobin Davis 		}
320c9b443d4STobin Davis 	}
321c9b443d4STobin Davis 
322c9b443d4STobin Davis 	return 0;
323c9b443d4STobin Davis }
324c9b443d4STobin Davis 
325c9b443d4STobin Davis static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
326c9b443d4STobin Davis 	       			  struct snd_ctl_elem_info *uinfo)
327c9b443d4STobin Davis {
328c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
330c9b443d4STobin Davis 
331c9b443d4STobin Davis 	return snd_hda_input_mux_info(spec->input_mux, uinfo);
332c9b443d4STobin Davis }
333c9b443d4STobin Davis 
334c9b443d4STobin Davis static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
335c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
336c9b443d4STobin Davis {
337c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
338c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
339c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
340c9b443d4STobin Davis 
341c9b443d4STobin Davis 	ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
342c9b443d4STobin Davis 	return 0;
343c9b443d4STobin Davis }
344c9b443d4STobin Davis 
345c9b443d4STobin Davis static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
346c9b443d4STobin Davis 				 struct snd_ctl_elem_value *ucontrol)
347c9b443d4STobin Davis {
348c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
349c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
350c9b443d4STobin Davis 	unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
351c9b443d4STobin Davis 
352c9b443d4STobin Davis 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
353c9b443d4STobin Davis 				     spec->capsrc_nids[adc_idx],
354c9b443d4STobin Davis 				     &spec->cur_mux[adc_idx]);
355c9b443d4STobin Davis }
356c9b443d4STobin Davis 
3578c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
35895c09099STakashi Iwai static void conexant_free_jack_priv(struct snd_jack *jack)
35995c09099STakashi Iwai {
36095c09099STakashi Iwai 	struct conexant_jack *jacks = jack->private_data;
36195c09099STakashi Iwai 	jacks->nid = 0;
36295c09099STakashi Iwai 	jacks->jack = NULL;
36395c09099STakashi Iwai }
36495c09099STakashi Iwai 
365bc7a166dSUlrich Dangel static int conexant_add_jack(struct hda_codec *codec,
366bc7a166dSUlrich Dangel 		hda_nid_t nid, int type)
367bc7a166dSUlrich Dangel {
368bc7a166dSUlrich Dangel 	struct conexant_spec *spec;
369bc7a166dSUlrich Dangel 	struct conexant_jack *jack;
370bc7a166dSUlrich Dangel 	const char *name;
37195c09099STakashi Iwai 	int err;
372bc7a166dSUlrich Dangel 
373bc7a166dSUlrich Dangel 	spec = codec->spec;
374bc7a166dSUlrich Dangel 	snd_array_init(&spec->jacks, sizeof(*jack), 32);
375bc7a166dSUlrich Dangel 	jack = snd_array_new(&spec->jacks);
376bc7a166dSUlrich Dangel 	name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
377bc7a166dSUlrich Dangel 
378bc7a166dSUlrich Dangel 	if (!jack)
379bc7a166dSUlrich Dangel 		return -ENOMEM;
380bc7a166dSUlrich Dangel 
381bc7a166dSUlrich Dangel 	jack->nid = nid;
382bc7a166dSUlrich Dangel 	jack->type = type;
383bc7a166dSUlrich Dangel 
38495c09099STakashi Iwai 	err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
38595c09099STakashi Iwai 	if (err < 0)
38695c09099STakashi Iwai 		return err;
38795c09099STakashi Iwai 	jack->jack->private_data = jack;
38895c09099STakashi Iwai 	jack->jack->private_free = conexant_free_jack_priv;
38995c09099STakashi Iwai 	return 0;
390bc7a166dSUlrich Dangel }
391bc7a166dSUlrich Dangel 
392bc7a166dSUlrich Dangel static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
393bc7a166dSUlrich Dangel {
394bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
395bc7a166dSUlrich Dangel 	struct conexant_jack *jacks = spec->jacks.list;
396bc7a166dSUlrich Dangel 
397bc7a166dSUlrich Dangel 	if (jacks) {
398bc7a166dSUlrich Dangel 		int i;
399bc7a166dSUlrich Dangel 		for (i = 0; i < spec->jacks.used; i++) {
400bc7a166dSUlrich Dangel 			if (jacks->nid == nid) {
401bc7a166dSUlrich Dangel 				unsigned int present;
402d56757abSTakashi Iwai 				present = snd_hda_jack_detect(codec, nid);
403bc7a166dSUlrich Dangel 
404bc7a166dSUlrich Dangel 				present = (present) ? jacks->type : 0 ;
405bc7a166dSUlrich Dangel 
406bc7a166dSUlrich Dangel 				snd_jack_report(jacks->jack,
407bc7a166dSUlrich Dangel 						present);
408bc7a166dSUlrich Dangel 			}
409bc7a166dSUlrich Dangel 			jacks++;
410bc7a166dSUlrich Dangel 		}
411bc7a166dSUlrich Dangel 	}
412bc7a166dSUlrich Dangel }
413bc7a166dSUlrich Dangel 
414bc7a166dSUlrich Dangel static int conexant_init_jacks(struct hda_codec *codec)
415bc7a166dSUlrich Dangel {
416bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
417bc7a166dSUlrich Dangel 	int i;
418bc7a166dSUlrich Dangel 
419bc7a166dSUlrich Dangel 	for (i = 0; i < spec->num_init_verbs; i++) {
420bc7a166dSUlrich Dangel 		const struct hda_verb *hv;
421bc7a166dSUlrich Dangel 
422bc7a166dSUlrich Dangel 		hv = spec->init_verbs[i];
423bc7a166dSUlrich Dangel 		while (hv->nid) {
424bc7a166dSUlrich Dangel 			int err = 0;
425bc7a166dSUlrich Dangel 			switch (hv->param ^ AC_USRSP_EN) {
426bc7a166dSUlrich Dangel 			case CONEXANT_HP_EVENT:
427bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
428bc7a166dSUlrich Dangel 						SND_JACK_HEADPHONE);
429bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
430bc7a166dSUlrich Dangel 				break;
431bc7a166dSUlrich Dangel 			case CXT5051_PORTC_EVENT:
432bc7a166dSUlrich Dangel 			case CONEXANT_MIC_EVENT:
433bc7a166dSUlrich Dangel 				err = conexant_add_jack(codec, hv->nid,
434bc7a166dSUlrich Dangel 						SND_JACK_MICROPHONE);
435bc7a166dSUlrich Dangel 				conexant_report_jack(codec, hv->nid);
436bc7a166dSUlrich Dangel 				break;
437bc7a166dSUlrich Dangel 			}
438bc7a166dSUlrich Dangel 			if (err < 0)
439bc7a166dSUlrich Dangel 				return err;
440bc7a166dSUlrich Dangel 			++hv;
441bc7a166dSUlrich Dangel 		}
442bc7a166dSUlrich Dangel 	}
443bc7a166dSUlrich Dangel 	return 0;
444bc7a166dSUlrich Dangel 
445bc7a166dSUlrich Dangel }
4465801f992STakashi Iwai #else
4475801f992STakashi Iwai static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
4485801f992STakashi Iwai {
4495801f992STakashi Iwai }
4505801f992STakashi Iwai 
4515801f992STakashi Iwai static inline int conexant_init_jacks(struct hda_codec *codec)
4525801f992STakashi Iwai {
4535801f992STakashi Iwai 	return 0;
4545801f992STakashi Iwai }
4555801f992STakashi Iwai #endif
456bc7a166dSUlrich Dangel 
457c9b443d4STobin Davis static int conexant_init(struct hda_codec *codec)
458c9b443d4STobin Davis {
459c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
460c9b443d4STobin Davis 	int i;
461c9b443d4STobin Davis 
462c9b443d4STobin Davis 	for (i = 0; i < spec->num_init_verbs; i++)
463c9b443d4STobin Davis 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
464c9b443d4STobin Davis 	return 0;
465c9b443d4STobin Davis }
466c9b443d4STobin Davis 
467c9b443d4STobin Davis static void conexant_free(struct hda_codec *codec)
468c9b443d4STobin Davis {
4698c8145b8STakashi Iwai #ifdef CONFIG_SND_HDA_INPUT_JACK
470bc7a166dSUlrich Dangel 	struct conexant_spec *spec = codec->spec;
471bc7a166dSUlrich Dangel 	if (spec->jacks.list) {
472bc7a166dSUlrich Dangel 		struct conexant_jack *jacks = spec->jacks.list;
473bc7a166dSUlrich Dangel 		int i;
47495c09099STakashi Iwai 		for (i = 0; i < spec->jacks.used; i++, jacks++) {
47595c09099STakashi Iwai 			if (jacks->jack)
47695c09099STakashi Iwai 				snd_device_free(codec->bus->card, jacks->jack);
47795c09099STakashi Iwai 		}
478bc7a166dSUlrich Dangel 		snd_array_free(&spec->jacks);
479bc7a166dSUlrich Dangel 	}
480bc7a166dSUlrich Dangel #endif
481*c0f8faf0SEinar Rünkaru 	snd_hda_detach_beep_device(codec);
482c9b443d4STobin Davis 	kfree(codec->spec);
483c9b443d4STobin Davis }
484c9b443d4STobin Davis 
485b880c74aSTakashi Iwai static struct snd_kcontrol_new cxt_capture_mixers[] = {
486b880c74aSTakashi Iwai 	{
487b880c74aSTakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
488b880c74aSTakashi Iwai 		.name = "Capture Source",
489b880c74aSTakashi Iwai 		.info = conexant_mux_enum_info,
490b880c74aSTakashi Iwai 		.get = conexant_mux_enum_get,
491b880c74aSTakashi Iwai 		.put = conexant_mux_enum_put
492b880c74aSTakashi Iwai 	},
493b880c74aSTakashi Iwai 	{}
494b880c74aSTakashi Iwai };
495b880c74aSTakashi Iwai 
496dd5746a8STakashi Iwai static const char *slave_vols[] = {
497dd5746a8STakashi Iwai 	"Headphone Playback Volume",
498dd5746a8STakashi Iwai 	"Speaker Playback Volume",
499dd5746a8STakashi Iwai 	NULL
500dd5746a8STakashi Iwai };
501dd5746a8STakashi Iwai 
502dd5746a8STakashi Iwai static const char *slave_sws[] = {
503dd5746a8STakashi Iwai 	"Headphone Playback Switch",
504dd5746a8STakashi Iwai 	"Speaker Playback Switch",
505dd5746a8STakashi Iwai 	NULL
506dd5746a8STakashi Iwai };
507dd5746a8STakashi Iwai 
508c9b443d4STobin Davis static int conexant_build_controls(struct hda_codec *codec)
509c9b443d4STobin Davis {
510c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
511c9b443d4STobin Davis 	unsigned int i;
512c9b443d4STobin Davis 	int err;
513c9b443d4STobin Davis 
514c9b443d4STobin Davis 	for (i = 0; i < spec->num_mixers; i++) {
515c9b443d4STobin Davis 		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
516c9b443d4STobin Davis 		if (err < 0)
517c9b443d4STobin Davis 			return err;
518c9b443d4STobin Davis 	}
519c9b443d4STobin Davis 	if (spec->multiout.dig_out_nid) {
520c9b443d4STobin Davis 		err = snd_hda_create_spdif_out_ctls(codec,
521c9b443d4STobin Davis 						    spec->multiout.dig_out_nid);
522c9b443d4STobin Davis 		if (err < 0)
523c9b443d4STobin Davis 			return err;
5249a08160bSTakashi Iwai 		err = snd_hda_create_spdif_share_sw(codec,
5259a08160bSTakashi Iwai 						    &spec->multiout);
5269a08160bSTakashi Iwai 		if (err < 0)
5279a08160bSTakashi Iwai 			return err;
5289a08160bSTakashi Iwai 		spec->multiout.share_spdif = 1;
529c9b443d4STobin Davis 	}
530c9b443d4STobin Davis 	if (spec->dig_in_nid) {
531c9b443d4STobin Davis 		err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
532c9b443d4STobin Davis 		if (err < 0)
533c9b443d4STobin Davis 			return err;
534c9b443d4STobin Davis 	}
535dd5746a8STakashi Iwai 
536dd5746a8STakashi Iwai 	/* if we have no master control, let's create it */
537dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
538dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
539dd5746a8STakashi Iwai 		unsigned int vmaster_tlv[4];
540dd5746a8STakashi Iwai 		snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
541dd5746a8STakashi Iwai 					HDA_OUTPUT, vmaster_tlv);
542dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Volume",
543dd5746a8STakashi Iwai 					  vmaster_tlv, slave_vols);
544dd5746a8STakashi Iwai 		if (err < 0)
545dd5746a8STakashi Iwai 			return err;
546dd5746a8STakashi Iwai 	}
547dd5746a8STakashi Iwai 	if (spec->vmaster_nid &&
548dd5746a8STakashi Iwai 	    !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
549dd5746a8STakashi Iwai 		err = snd_hda_add_vmaster(codec, "Master Playback Switch",
550dd5746a8STakashi Iwai 					  NULL, slave_sws);
551dd5746a8STakashi Iwai 		if (err < 0)
552dd5746a8STakashi Iwai 			return err;
553dd5746a8STakashi Iwai 	}
554dd5746a8STakashi Iwai 
555b880c74aSTakashi Iwai 	if (spec->input_mux) {
556b880c74aSTakashi Iwai 		err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
557b880c74aSTakashi Iwai 		if (err < 0)
558b880c74aSTakashi Iwai 			return err;
559b880c74aSTakashi Iwai 	}
560b880c74aSTakashi Iwai 
561c9b443d4STobin Davis 	return 0;
562c9b443d4STobin Davis }
563c9b443d4STobin Davis 
564c9b443d4STobin Davis static struct hda_codec_ops conexant_patch_ops = {
565c9b443d4STobin Davis 	.build_controls = conexant_build_controls,
566c9b443d4STobin Davis 	.build_pcms = conexant_build_pcms,
567c9b443d4STobin Davis 	.init = conexant_init,
568c9b443d4STobin Davis 	.free = conexant_free,
569c9b443d4STobin Davis };
570c9b443d4STobin Davis 
571c9b443d4STobin Davis /*
572c9b443d4STobin Davis  * EAPD control
573c9b443d4STobin Davis  * the private value = nid | (invert << 8)
574c9b443d4STobin Davis  */
575c9b443d4STobin Davis 
576a5ce8890STakashi Iwai #define cxt_eapd_info		snd_ctl_boolean_mono_info
577c9b443d4STobin Davis 
57882f30040STobin Davis static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
579c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
580c9b443d4STobin Davis {
581c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
582c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
583c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
584c9b443d4STobin Davis 	if (invert)
585c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = !spec->cur_eapd;
586c9b443d4STobin Davis 	else
587c9b443d4STobin Davis 		ucontrol->value.integer.value[0] = spec->cur_eapd;
588c9b443d4STobin Davis 	return 0;
58982f30040STobin Davis 
590c9b443d4STobin Davis }
591c9b443d4STobin Davis 
59282f30040STobin Davis static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
593c9b443d4STobin Davis 			     struct snd_ctl_elem_value *ucontrol)
594c9b443d4STobin Davis {
595c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
596c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
597c9b443d4STobin Davis 	int invert = (kcontrol->private_value >> 8) & 1;
598c9b443d4STobin Davis 	hda_nid_t nid = kcontrol->private_value & 0xff;
599c9b443d4STobin Davis 	unsigned int eapd;
60082f30040STobin Davis 
60168ea7b2fSTakashi Iwai 	eapd = !!ucontrol->value.integer.value[0];
602c9b443d4STobin Davis 	if (invert)
603c9b443d4STobin Davis 		eapd = !eapd;
60482beb8fdSTakashi Iwai 	if (eapd == spec->cur_eapd)
605c9b443d4STobin Davis 		return 0;
60682f30040STobin Davis 
607c9b443d4STobin Davis 	spec->cur_eapd = eapd;
60882beb8fdSTakashi Iwai 	snd_hda_codec_write_cache(codec, nid,
609c9b443d4STobin Davis 				  0, AC_VERB_SET_EAPD_BTLENABLE,
610c9b443d4STobin Davis 				  eapd ? 0x02 : 0x00);
611c9b443d4STobin Davis 	return 1;
612c9b443d4STobin Davis }
613c9b443d4STobin Davis 
61486d72bdfSTakashi Iwai /* controls for test mode */
61586d72bdfSTakashi Iwai #ifdef CONFIG_SND_DEBUG
61686d72bdfSTakashi Iwai 
61782f30040STobin Davis #define CXT_EAPD_SWITCH(xname, nid, mask) \
61882f30040STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
61982f30040STobin Davis 	  .info = cxt_eapd_info, \
62082f30040STobin Davis 	  .get = cxt_eapd_get, \
62182f30040STobin Davis 	  .put = cxt_eapd_put, \
62282f30040STobin Davis 	  .private_value = nid | (mask<<16) }
62382f30040STobin Davis 
62482f30040STobin Davis 
62582f30040STobin Davis 
626c9b443d4STobin Davis static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
627c9b443d4STobin Davis 				 struct snd_ctl_elem_info *uinfo)
628c9b443d4STobin Davis {
629c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
631c9b443d4STobin Davis 	return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
632c9b443d4STobin Davis 				    spec->num_channel_mode);
633c9b443d4STobin Davis }
634c9b443d4STobin Davis 
635c9b443d4STobin Davis static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
636c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
637c9b443d4STobin Davis {
638c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
640c9b443d4STobin Davis 	return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
641c9b443d4STobin Davis 				   spec->num_channel_mode,
642c9b443d4STobin Davis 				   spec->multiout.max_channels);
643c9b443d4STobin Davis }
644c9b443d4STobin Davis 
645c9b443d4STobin Davis static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
646c9b443d4STobin Davis 				struct snd_ctl_elem_value *ucontrol)
647c9b443d4STobin Davis {
648c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
649c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
650c9b443d4STobin Davis 	int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
651c9b443d4STobin Davis 				      spec->num_channel_mode,
652c9b443d4STobin Davis 				      &spec->multiout.max_channels);
653c9b443d4STobin Davis 	if (err >= 0 && spec->need_dac_fix)
654c9b443d4STobin Davis 		spec->multiout.num_dacs = spec->multiout.max_channels / 2;
655c9b443d4STobin Davis 	return err;
656c9b443d4STobin Davis }
657c9b443d4STobin Davis 
658c9b443d4STobin Davis #define CXT_PIN_MODE(xname, nid, dir) \
659c9b443d4STobin Davis 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0,  \
660c9b443d4STobin Davis 	  .info = conexant_ch_mode_info, \
661c9b443d4STobin Davis 	  .get = conexant_ch_mode_get, \
662c9b443d4STobin Davis 	  .put = conexant_ch_mode_put, \
663c9b443d4STobin Davis 	  .private_value = nid | (dir<<16) }
664c9b443d4STobin Davis 
66586d72bdfSTakashi Iwai #endif /* CONFIG_SND_DEBUG */
66686d72bdfSTakashi Iwai 
667c9b443d4STobin Davis /* Conexant 5045 specific */
668c9b443d4STobin Davis 
669c9b443d4STobin Davis static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
670c9b443d4STobin Davis static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
671c9b443d4STobin Davis static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
672cbef9789STakashi Iwai #define CXT5045_SPDIF_OUT	0x18
673c9b443d4STobin Davis 
6745cd57529STobin Davis static struct hda_channel_mode cxt5045_modes[1] = {
6755cd57529STobin Davis 	{ 2, NULL },
6765cd57529STobin Davis };
677c9b443d4STobin Davis 
678c9b443d4STobin Davis static struct hda_input_mux cxt5045_capture_source = {
679c9b443d4STobin Davis 	.num_items = 2,
680c9b443d4STobin Davis 	.items = {
68182f30040STobin Davis 		{ "IntMic", 0x1 },
682f4beee94SJiang zhe 		{ "ExtMic", 0x2 },
683c9b443d4STobin Davis 	}
684c9b443d4STobin Davis };
685c9b443d4STobin Davis 
6865218c892SJiang Zhe static struct hda_input_mux cxt5045_capture_source_benq = {
68722e14130SLukasz Marcinowski 	.num_items = 5,
6885218c892SJiang Zhe 	.items = {
6895218c892SJiang Zhe 		{ "IntMic", 0x1 },
6905218c892SJiang Zhe 		{ "ExtMic", 0x2 },
6915218c892SJiang Zhe 		{ "LineIn", 0x3 },
69222e14130SLukasz Marcinowski 		{ "CD",     0x4 },
69322e14130SLukasz Marcinowski 		{ "Mixer",  0x0 },
6945218c892SJiang Zhe 	}
6955218c892SJiang Zhe };
6965218c892SJiang Zhe 
6972de3c232SJiang zhe static struct hda_input_mux cxt5045_capture_source_hp530 = {
6982de3c232SJiang zhe 	.num_items = 2,
6992de3c232SJiang zhe 	.items = {
7002de3c232SJiang zhe 		{ "ExtMic", 0x1 },
7012de3c232SJiang zhe 		{ "IntMic", 0x2 },
7022de3c232SJiang zhe 	}
7032de3c232SJiang zhe };
7042de3c232SJiang zhe 
705c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
706c9b443d4STobin Davis static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
707c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
708c9b443d4STobin Davis {
709c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
71182f30040STobin Davis 	unsigned int bits;
712c9b443d4STobin Davis 
71382f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
714c9b443d4STobin Davis 		return 0;
715c9b443d4STobin Davis 
71682f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
71782f30040STobin Davis 	 * the headphone jack
71882f30040STobin Davis 	 */
71947fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
72047fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
72147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
7227f29673bSTobin Davis 
72347fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
72447fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
72547fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
726c9b443d4STobin Davis 	return 1;
727c9b443d4STobin Davis }
728c9b443d4STobin Davis 
729c9b443d4STobin Davis /* bind volumes of both NID 0x10 and 0x11 */
730cca3b371STakashi Iwai static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
731cca3b371STakashi Iwai 	.ops = &snd_hda_bind_vol,
732cca3b371STakashi Iwai 	.values = {
733cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
734cca3b371STakashi Iwai 		HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
735cca3b371STakashi Iwai 		0
736cca3b371STakashi Iwai 	},
737cca3b371STakashi Iwai };
738c9b443d4STobin Davis 
7397f29673bSTobin Davis /* toggle input of built-in and mic jack appropriately */
7407f29673bSTobin Davis static void cxt5045_hp_automic(struct hda_codec *codec)
7417f29673bSTobin Davis {
7427f29673bSTobin Davis 	static struct hda_verb mic_jack_on[] = {
7437f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7447f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7457f29673bSTobin Davis 		{}
7467f29673bSTobin Davis 	};
7477f29673bSTobin Davis 	static struct hda_verb mic_jack_off[] = {
7487f29673bSTobin Davis 		{0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
7497f29673bSTobin Davis 		{0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
7507f29673bSTobin Davis 		{}
7517f29673bSTobin Davis 	};
7527f29673bSTobin Davis 	unsigned int present;
7537f29673bSTobin Davis 
754d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x12);
7557f29673bSTobin Davis 	if (present)
7567f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
7577f29673bSTobin Davis 	else
7587f29673bSTobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
7597f29673bSTobin Davis }
7607f29673bSTobin Davis 
761c9b443d4STobin Davis 
762c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
763c9b443d4STobin Davis static void cxt5045_hp_automute(struct hda_codec *codec)
764c9b443d4STobin Davis {
76582f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
766dd87da1cSTobin Davis 	unsigned int bits;
767c9b443d4STobin Davis 
768d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x11);
769dd87da1cSTobin Davis 
77047fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
77147fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
77247fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
773c9b443d4STobin Davis }
774c9b443d4STobin Davis 
775c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
776c9b443d4STobin Davis static void cxt5045_hp_unsol_event(struct hda_codec *codec,
777c9b443d4STobin Davis 				   unsigned int res)
778c9b443d4STobin Davis {
779c9b443d4STobin Davis 	res >>= 26;
780c9b443d4STobin Davis 	switch (res) {
781c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
782c9b443d4STobin Davis 		cxt5045_hp_automute(codec);
783c9b443d4STobin Davis 		break;
7847f29673bSTobin Davis 	case CONEXANT_MIC_EVENT:
7857f29673bSTobin Davis 		cxt5045_hp_automic(codec);
7867f29673bSTobin Davis 		break;
7877f29673bSTobin Davis 
788c9b443d4STobin Davis 	}
789c9b443d4STobin Davis }
790c9b443d4STobin Davis 
791c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_mixers[] = {
792c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
793c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
794c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
795c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
796c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
797c8229c38STakashi Iwai 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
798c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
799c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
800c8229c38STakashi Iwai 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
801c8229c38STakashi Iwai 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
802cca3b371STakashi Iwai 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
803c9b443d4STobin Davis 	{
804c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
805c9b443d4STobin Davis 		.name = "Master Playback Switch",
80682f30040STobin Davis 		.info = cxt_eapd_info,
80782f30040STobin Davis 		.get = cxt_eapd_get,
808c9b443d4STobin Davis 		.put = cxt5045_hp_master_sw_put,
80982f30040STobin Davis 		.private_value = 0x10,
810c9b443d4STobin Davis 	},
811c9b443d4STobin Davis 
812c9b443d4STobin Davis 	{}
813c9b443d4STobin Davis };
814c9b443d4STobin Davis 
8155218c892SJiang Zhe static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
81622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
81722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
81822e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
81922e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
82022e14130SLukasz Marcinowski 
8215218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
8225218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
8235218c892SJiang Zhe 	HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
8245218c892SJiang Zhe 	HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
8255218c892SJiang Zhe 
82622e14130SLukasz Marcinowski 	HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
82722e14130SLukasz Marcinowski 	HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
82822e14130SLukasz Marcinowski 
8295218c892SJiang Zhe 	{}
8305218c892SJiang Zhe };
8315218c892SJiang Zhe 
8322de3c232SJiang zhe static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
8332de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
8342de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
8352de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
8362de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
8372de3c232SJiang zhe 	HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
8382de3c232SJiang zhe 	HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
8392de3c232SJiang zhe 	HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
8402de3c232SJiang zhe 	HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
8412de3c232SJiang zhe 	HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
8422de3c232SJiang zhe 	HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
8432de3c232SJiang zhe 	HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
8442de3c232SJiang zhe 	{
8452de3c232SJiang zhe 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8462de3c232SJiang zhe 		.name = "Master Playback Switch",
8472de3c232SJiang zhe 		.info = cxt_eapd_info,
8482de3c232SJiang zhe 		.get = cxt_eapd_get,
8492de3c232SJiang zhe 		.put = cxt5045_hp_master_sw_put,
8502de3c232SJiang zhe 		.private_value = 0x10,
8512de3c232SJiang zhe 	},
8522de3c232SJiang zhe 
8532de3c232SJiang zhe 	{}
8542de3c232SJiang zhe };
8552de3c232SJiang zhe 
856c9b443d4STobin Davis static struct hda_verb cxt5045_init_verbs[] = {
857c9b443d4STobin Davis 	/* Line in, Mic */
8584090dffbSTakashi Iwai 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8597f29673bSTobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
860c9b443d4STobin Davis 	/* HP, Amp  */
861c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
862c8229c38STakashi Iwai 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
86382f30040STobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
864c8229c38STakashi Iwai 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
865c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
866c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
867c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
868c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
869c8229c38STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
87082f30040STobin Davis 	/* Record selector: Int mic */
8717f29673bSTobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
87282f30040STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
873c9b443d4STobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
874c9b443d4STobin Davis 	/* SPDIF route: PCM */
875cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
876c9b443d4STobin Davis 	{ 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
877c9b443d4STobin Davis 	/* EAPD */
87882f30040STobin Davis 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
879c9b443d4STobin Davis 	{ } /* end */
880c9b443d4STobin Davis };
881c9b443d4STobin Davis 
8825218c892SJiang Zhe static struct hda_verb cxt5045_benq_init_verbs[] = {
8835218c892SJiang Zhe 	/* Int Mic, Mic */
8845218c892SJiang Zhe 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8855218c892SJiang Zhe 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
8865218c892SJiang Zhe 	/* Line In,HP, Amp  */
8875218c892SJiang Zhe 	{0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8885218c892SJiang Zhe 	{0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
8895218c892SJiang Zhe 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
8905218c892SJiang Zhe 	{0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
8915218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8925218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8935218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8945218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8955218c892SJiang Zhe 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8965218c892SJiang Zhe 	/* Record selector: Int mic */
8975218c892SJiang Zhe 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
8985218c892SJiang Zhe 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
8995218c892SJiang Zhe 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
9005218c892SJiang Zhe 	/* SPDIF route: PCM */
901cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9025218c892SJiang Zhe 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
9035218c892SJiang Zhe 	/* EAPD */
9045218c892SJiang Zhe 	{0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
9055218c892SJiang Zhe 	{ } /* end */
9065218c892SJiang Zhe };
9077f29673bSTobin Davis 
9087f29673bSTobin Davis static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
9097f29673bSTobin Davis 	/* pin sensing on HP jack */
9107f29673bSTobin Davis 	{0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
911d3091fadSTakashi Iwai 	{ } /* end */
9127f29673bSTobin Davis };
9137f29673bSTobin Davis 
9147f29673bSTobin Davis static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
9157f29673bSTobin Davis 	/* pin sensing on HP jack */
9167f29673bSTobin Davis 	{0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
917d3091fadSTakashi Iwai 	{ } /* end */
9187f29673bSTobin Davis };
9197f29673bSTobin Davis 
920c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
921c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
922c9b443d4STobin Davis  * configuration.
923c9b443d4STobin Davis  */
924c9b443d4STobin Davis static struct hda_input_mux cxt5045_test_capture_source = {
925c9b443d4STobin Davis 	.num_items = 5,
926c9b443d4STobin Davis 	.items = {
927c9b443d4STobin Davis 		{ "MIXER", 0x0 },
928c9b443d4STobin Davis 		{ "MIC1 pin", 0x1 },
929c9b443d4STobin Davis 		{ "LINE1 pin", 0x2 },
930c9b443d4STobin Davis 		{ "HP-OUT pin", 0x3 },
931c9b443d4STobin Davis 		{ "CD pin", 0x4 },
932c9b443d4STobin Davis         },
933c9b443d4STobin Davis };
934c9b443d4STobin Davis 
935c9b443d4STobin Davis static struct snd_kcontrol_new cxt5045_test_mixer[] = {
936c9b443d4STobin Davis 
937c9b443d4STobin Davis 	/* Output controls */
938c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
939c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
9407f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
9417f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
9427f29673bSTobin Davis 	HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
9437f29673bSTobin Davis 	HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
944c9b443d4STobin Davis 
945c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
946c9b443d4STobin Davis 	CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
947c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
948c9b443d4STobin Davis 
94982f30040STobin Davis 	/* EAPD Switch Control */
95082f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
95182f30040STobin Davis 
952c9b443d4STobin Davis 	/* Loopback mixer controls */
953c9b443d4STobin Davis 
9547f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
9557f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
9567f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
9577f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
9587f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
9597f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
9607f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
9617f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
9627f29673bSTobin Davis 	HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
9637f29673bSTobin Davis 	HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
964c9b443d4STobin Davis 	{
965c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
966c9b443d4STobin Davis 		.name = "Input Source",
967c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
968c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
969c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
970c9b443d4STobin Davis 	},
971fb3409e7STobin Davis 	/* Audio input controls */
972fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
973fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
974fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
975fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
976fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
977fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
978fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
979fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
980fb3409e7STobin Davis 	HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
981fb3409e7STobin Davis 	HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
982c9b443d4STobin Davis 	{ } /* end */
983c9b443d4STobin Davis };
984c9b443d4STobin Davis 
985c9b443d4STobin Davis static struct hda_verb cxt5045_test_init_verbs[] = {
9867f29673bSTobin Davis 	/* Set connections */
9877f29673bSTobin Davis 	{ 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
9887f29673bSTobin Davis 	{ 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
9897f29673bSTobin Davis 	{ 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
990c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
991c9b443d4STobin Davis 	{0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9927f29673bSTobin Davis 	{0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
993c9b443d4STobin Davis 
994c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
995c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
996c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
997c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
998c9b443d4STobin Davis 	 * control.
999c9b443d4STobin Davis 	 */
1000cbef9789STakashi Iwai 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1001cbef9789STakashi Iwai 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1002c9b443d4STobin Davis 
1003c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1004c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1005c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1006c9b443d4STobin Davis 
1007c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1008c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1009c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1010c9b443d4STobin Davis 	 * input/output buffers as needed.
1011c9b443d4STobin Davis 	 */
1012c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1013c9b443d4STobin Davis 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1014c9b443d4STobin Davis 
1015c9b443d4STobin Davis 	/* Mute capture amp left and right */
1016c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1017c9b443d4STobin Davis 
1018c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1019c9b443d4STobin Davis 	 * pin)
1020c9b443d4STobin Davis 	 */
1021c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
10227f29673bSTobin Davis 	{0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
1023c9b443d4STobin Davis 
1024c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1025c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
1026c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
1027c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
1028c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
1029c9b443d4STobin Davis 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1030c9b443d4STobin Davis 
1031c9b443d4STobin Davis 	{ }
1032c9b443d4STobin Davis };
1033c9b443d4STobin Davis #endif
1034c9b443d4STobin Davis 
1035c9b443d4STobin Davis 
1036c9b443d4STobin Davis /* initialize jack-sensing, too */
1037c9b443d4STobin Davis static int cxt5045_init(struct hda_codec *codec)
1038c9b443d4STobin Davis {
1039c9b443d4STobin Davis 	conexant_init(codec);
1040c9b443d4STobin Davis 	cxt5045_hp_automute(codec);
1041c9b443d4STobin Davis 	return 0;
1042c9b443d4STobin Davis }
1043c9b443d4STobin Davis 
1044c9b443d4STobin Davis 
1045c9b443d4STobin Davis enum {
104615908c36SMarc Boucher 	CXT5045_LAPTOP_HPSENSE,
104715908c36SMarc Boucher 	CXT5045_LAPTOP_MICSENSE,
104815908c36SMarc Boucher 	CXT5045_LAPTOP_HPMICSENSE,
10495218c892SJiang Zhe 	CXT5045_BENQ,
10502de3c232SJiang zhe 	CXT5045_LAPTOP_HP530,
1051c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1052c9b443d4STobin Davis 	CXT5045_TEST,
1053c9b443d4STobin Davis #endif
1054f5fcc13cSTakashi Iwai 	CXT5045_MODELS
1055c9b443d4STobin Davis };
1056c9b443d4STobin Davis 
1057f5fcc13cSTakashi Iwai static const char *cxt5045_models[CXT5045_MODELS] = {
105815908c36SMarc Boucher 	[CXT5045_LAPTOP_HPSENSE]	= "laptop-hpsense",
105915908c36SMarc Boucher 	[CXT5045_LAPTOP_MICSENSE]	= "laptop-micsense",
106015908c36SMarc Boucher 	[CXT5045_LAPTOP_HPMICSENSE]	= "laptop-hpmicsense",
10615218c892SJiang Zhe 	[CXT5045_BENQ]			= "benq",
10622de3c232SJiang zhe 	[CXT5045_LAPTOP_HP530]		= "laptop-hp530",
1063c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1064f5fcc13cSTakashi Iwai 	[CXT5045_TEST]		= "test",
1065c9b443d4STobin Davis #endif
1066f5fcc13cSTakashi Iwai };
1067c9b443d4STobin Davis 
1068f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
10692de3c232SJiang zhe 	SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1070dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1071dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPSENSE),
10726a9dccd6STakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
10735218c892SJiang Zhe 	SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
107415908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
107515908c36SMarc Boucher 	SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
10769e464154STakashi Iwai 	SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
10779e464154STakashi Iwai 		      CXT5045_LAPTOP_HPMICSENSE),
107815908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
107915908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
108015908c36SMarc Boucher 	SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1081dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1082dea0a509STakashi Iwai 			   CXT5045_LAPTOP_HPMICSENSE),
108315908c36SMarc Boucher 	SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1084c9b443d4STobin Davis 	{}
1085c9b443d4STobin Davis };
1086c9b443d4STobin Davis 
1087c9b443d4STobin Davis static int patch_cxt5045(struct hda_codec *codec)
1088c9b443d4STobin Davis {
1089c9b443d4STobin Davis 	struct conexant_spec *spec;
1090c9b443d4STobin Davis 	int board_config;
1091c9b443d4STobin Davis 
1092c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1093c9b443d4STobin Davis 	if (!spec)
1094c9b443d4STobin Davis 		return -ENOMEM;
1095c9b443d4STobin Davis 	codec->spec = spec;
10969421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1097c9b443d4STobin Davis 
1098c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1099c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
1100c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5045_dac_nids;
1101c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
1102c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1103c9b443d4STobin Davis 	spec->adc_nids = cxt5045_adc_nids;
1104c9b443d4STobin Davis 	spec->capsrc_nids = cxt5045_capsrc_nids;
1105c9b443d4STobin Davis 	spec->input_mux = &cxt5045_capture_source;
1106c9b443d4STobin Davis 	spec->num_mixers = 1;
1107c9b443d4STobin Davis 	spec->mixers[0] = cxt5045_mixers;
1108c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1109c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5045_init_verbs;
1110c9b443d4STobin Davis 	spec->spdif_route = 0;
11115cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
11125cd57529STobin Davis 	spec->channel_mode = cxt5045_modes,
11135cd57529STobin Davis 
1114c9b443d4STobin Davis 
1115c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1116c9b443d4STobin Davis 
1117f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
1118f5fcc13cSTakashi Iwai 						  cxt5045_models,
1119f5fcc13cSTakashi Iwai 						  cxt5045_cfg_tbl);
1120c9b443d4STobin Davis 	switch (board_config) {
112115908c36SMarc Boucher 	case CXT5045_LAPTOP_HPSENSE:
11227f29673bSTobin Davis 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
1123c9b443d4STobin Davis 		spec->input_mux = &cxt5045_capture_source;
1124c9b443d4STobin Davis 		spec->num_init_verbs = 2;
11257f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11267f29673bSTobin Davis 		spec->mixers[0] = cxt5045_mixers;
11277f29673bSTobin Davis 		codec->patch_ops.init = cxt5045_init;
11287f29673bSTobin Davis 		break;
112915908c36SMarc Boucher 	case CXT5045_LAPTOP_MICSENSE:
113086376df6STakashi Iwai 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11317f29673bSTobin Davis 		spec->input_mux = &cxt5045_capture_source;
11327f29673bSTobin Davis 		spec->num_init_verbs = 2;
11337f29673bSTobin Davis 		spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
1134c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_mixers;
1135c9b443d4STobin Davis 		codec->patch_ops.init = cxt5045_init;
1136c9b443d4STobin Davis 		break;
113715908c36SMarc Boucher 	default:
113815908c36SMarc Boucher 	case CXT5045_LAPTOP_HPMICSENSE:
113915908c36SMarc Boucher 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
114015908c36SMarc Boucher 		spec->input_mux = &cxt5045_capture_source;
114115908c36SMarc Boucher 		spec->num_init_verbs = 3;
114215908c36SMarc Boucher 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
114315908c36SMarc Boucher 		spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
114415908c36SMarc Boucher 		spec->mixers[0] = cxt5045_mixers;
114515908c36SMarc Boucher 		codec->patch_ops.init = cxt5045_init;
114615908c36SMarc Boucher 		break;
11475218c892SJiang Zhe 	case CXT5045_BENQ:
11485218c892SJiang Zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11495218c892SJiang Zhe 		spec->input_mux = &cxt5045_capture_source_benq;
11505218c892SJiang Zhe 		spec->num_init_verbs = 1;
11515218c892SJiang Zhe 		spec->init_verbs[0] = cxt5045_benq_init_verbs;
11525218c892SJiang Zhe 		spec->mixers[0] = cxt5045_mixers;
11535218c892SJiang Zhe 		spec->mixers[1] = cxt5045_benq_mixers;
11545218c892SJiang Zhe 		spec->num_mixers = 2;
11555218c892SJiang Zhe 		codec->patch_ops.init = cxt5045_init;
11565218c892SJiang Zhe 		break;
11572de3c232SJiang zhe 	case CXT5045_LAPTOP_HP530:
11582de3c232SJiang zhe 		codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
11592de3c232SJiang zhe 		spec->input_mux = &cxt5045_capture_source_hp530;
11602de3c232SJiang zhe 		spec->num_init_verbs = 2;
11612de3c232SJiang zhe 		spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
11622de3c232SJiang zhe 		spec->mixers[0] = cxt5045_mixers_hp530;
11632de3c232SJiang zhe 		codec->patch_ops.init = cxt5045_init;
11642de3c232SJiang zhe 		break;
1165c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1166c9b443d4STobin Davis 	case CXT5045_TEST:
1167c9b443d4STobin Davis 		spec->input_mux = &cxt5045_test_capture_source;
1168c9b443d4STobin Davis 		spec->mixers[0] = cxt5045_test_mixer;
1169c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5045_test_init_verbs;
117015908c36SMarc Boucher 		break;
117115908c36SMarc Boucher 
1172c9b443d4STobin Davis #endif
1173c9b443d4STobin Davis 	}
117448ecb7e8STakashi Iwai 
1175031005f7STakashi Iwai 	switch (codec->subsystem_id >> 16) {
1176031005f7STakashi Iwai 	case 0x103c:
11770b587fc4SDaniel T Chen 	case 0x1734:
11780b587fc4SDaniel T Chen 		/* HP & Fujitsu-Siemens laptops have really bad sound over 0dB
11790b587fc4SDaniel T Chen 		 * on NID 0x17. Fix max PCM level to 0 dB
11800b587fc4SDaniel T Chen 		 * (originally it has 0x2b steps with 0dB offset 0x14)
118148ecb7e8STakashi Iwai 		 */
118248ecb7e8STakashi Iwai 		snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
118348ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
118448ecb7e8STakashi Iwai 					  (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
118548ecb7e8STakashi Iwai 					  (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
118648ecb7e8STakashi Iwai 					  (1 << AC_AMPCAP_MUTE_SHIFT));
1187031005f7STakashi Iwai 		break;
1188031005f7STakashi Iwai 	}
118948ecb7e8STakashi Iwai 
1190c9b443d4STobin Davis 	return 0;
1191c9b443d4STobin Davis }
1192c9b443d4STobin Davis 
1193c9b443d4STobin Davis 
1194c9b443d4STobin Davis /* Conexant 5047 specific */
119582f30040STobin Davis #define CXT5047_SPDIF_OUT	0x11
1196c9b443d4STobin Davis 
11975b3a7440STakashi Iwai static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1198c9b443d4STobin Davis static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1199c9b443d4STobin Davis static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1200c9b443d4STobin Davis 
12015cd57529STobin Davis static struct hda_channel_mode cxt5047_modes[1] = {
12025cd57529STobin Davis 	{ 2, NULL },
12035cd57529STobin Davis };
1204c9b443d4STobin Davis 
120582f30040STobin Davis static struct hda_input_mux cxt5047_toshiba_capture_source = {
120682f30040STobin Davis 	.num_items = 2,
120782f30040STobin Davis 	.items = {
120882f30040STobin Davis 		{ "ExtMic", 0x2 },
120982f30040STobin Davis 		{ "Line-In", 0x1 },
1210c9b443d4STobin Davis 	}
1211c9b443d4STobin Davis };
1212c9b443d4STobin Davis 
1213c9b443d4STobin Davis /* turn on/off EAPD (+ mute HP) as a master switch */
1214c9b443d4STobin Davis static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1215c9b443d4STobin Davis 				    struct snd_ctl_elem_value *ucontrol)
1216c9b443d4STobin Davis {
1217c9b443d4STobin Davis 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1218c9b443d4STobin Davis 	struct conexant_spec *spec = codec->spec;
121982f30040STobin Davis 	unsigned int bits;
1220c9b443d4STobin Davis 
122182f30040STobin Davis 	if (!cxt_eapd_put(kcontrol, ucontrol))
1222c9b443d4STobin Davis 		return 0;
1223c9b443d4STobin Davis 
122482f30040STobin Davis 	/* toggle internal speakers mute depending of presence of
122582f30040STobin Davis 	 * the headphone jack
122682f30040STobin Davis 	 */
122747fd830aSTakashi Iwai 	bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
12283b7523fcSTakashi Iwai 	/* NOTE: Conexat codec needs the index for *OUTPUT* amp of
12293b7523fcSTakashi Iwai 	 * pin widgets unlike other codecs.  In this case, we need to
12303b7523fcSTakashi Iwai 	 * set index 0x01 for the volume from the mixer amp 0x19.
12313b7523fcSTakashi Iwai 	 */
12325d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
123347fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
123447fd830aSTakashi Iwai 	bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
123547fd830aSTakashi Iwai 	snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
123647fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1237c9b443d4STobin Davis 	return 1;
1238c9b443d4STobin Davis }
1239c9b443d4STobin Davis 
1240c9b443d4STobin Davis /* mute internal speaker if HP is plugged */
1241c9b443d4STobin Davis static void cxt5047_hp_automute(struct hda_codec *codec)
1242c9b443d4STobin Davis {
124382f30040STobin Davis 	struct conexant_spec *spec = codec->spec;
1244dd87da1cSTobin Davis 	unsigned int bits;
1245c9b443d4STobin Davis 
1246d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x13);
1247dd87da1cSTobin Davis 
124847fd830aSTakashi Iwai 	bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
12493b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
12505d75bc55SGregorio Guidi 	snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
125147fd830aSTakashi Iwai 				 HDA_AMP_MUTE, bits);
1252c9b443d4STobin Davis }
1253c9b443d4STobin Davis 
1254c9b443d4STobin Davis /* toggle input of built-in and mic jack appropriately */
1255c9b443d4STobin Davis static void cxt5047_hp_automic(struct hda_codec *codec)
1256c9b443d4STobin Davis {
1257c9b443d4STobin Davis 	static struct hda_verb mic_jack_on[] = {
12589f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12599f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1260c9b443d4STobin Davis 		{}
1261c9b443d4STobin Davis 	};
1262c9b443d4STobin Davis 	static struct hda_verb mic_jack_off[] = {
12639f113e0eSMarc Boucher 		{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
12649f113e0eSMarc Boucher 		{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1265c9b443d4STobin Davis 		{}
1266c9b443d4STobin Davis 	};
1267c9b443d4STobin Davis 	unsigned int present;
1268c9b443d4STobin Davis 
1269d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x15);
1270c9b443d4STobin Davis 	if (present)
1271c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_on);
1272c9b443d4STobin Davis 	else
1273c9b443d4STobin Davis 		snd_hda_sequence_write(codec, mic_jack_off);
1274c9b443d4STobin Davis }
1275c9b443d4STobin Davis 
1276c9b443d4STobin Davis /* unsolicited event for HP jack sensing */
1277c9b443d4STobin Davis static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1278c9b443d4STobin Davis 				  unsigned int res)
1279c9b443d4STobin Davis {
12809f113e0eSMarc Boucher 	switch (res >> 26) {
1281c9b443d4STobin Davis 	case CONEXANT_HP_EVENT:
1282c9b443d4STobin Davis 		cxt5047_hp_automute(codec);
1283c9b443d4STobin Davis 		break;
1284c9b443d4STobin Davis 	case CONEXANT_MIC_EVENT:
1285c9b443d4STobin Davis 		cxt5047_hp_automic(codec);
1286c9b443d4STobin Davis 		break;
1287c9b443d4STobin Davis 	}
1288c9b443d4STobin Davis }
1289c9b443d4STobin Davis 
1290df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1291df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1292df481e41STakashi Iwai 	HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1293df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1294c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1295c9b443d4STobin Davis 	HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1296c9b443d4STobin Davis 	HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1297c9b443d4STobin Davis 	HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
129882f30040STobin Davis 	{
129982f30040STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
130082f30040STobin Davis 		.name = "Master Playback Switch",
130182f30040STobin Davis 		.info = cxt_eapd_info,
130282f30040STobin Davis 		.get = cxt_eapd_get,
1303c9b443d4STobin Davis 		.put = cxt5047_hp_master_sw_put,
1304c9b443d4STobin Davis 		.private_value = 0x13,
1305c9b443d4STobin Davis 	},
1306c9b443d4STobin Davis 
1307c9b443d4STobin Davis 	{}
1308c9b443d4STobin Davis };
1309c9b443d4STobin Davis 
1310df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
13113b7523fcSTakashi Iwai 	/* See the note in cxt5047_hp_master_sw_put */
13125d75bc55SGregorio Guidi 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1313df481e41STakashi Iwai 	HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1314df481e41STakashi Iwai 	{}
1315df481e41STakashi Iwai };
1316df481e41STakashi Iwai 
1317df481e41STakashi Iwai static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1318c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1319c9b443d4STobin Davis 	{ } /* end */
1320c9b443d4STobin Davis };
1321c9b443d4STobin Davis 
1322c9b443d4STobin Davis static struct hda_verb cxt5047_init_verbs[] = {
1323c9b443d4STobin Davis 	/* Line in, Mic, Built-in Mic */
1324c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
1325c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1326c9b443d4STobin Davis 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
13277f29673bSTobin Davis 	/* HP, Speaker  */
1328b7589cebSTobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
13295b3a7440STakashi Iwai 	{0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
13305b3a7440STakashi Iwai 	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
13317f29673bSTobin Davis 	/* Record selector: Mic */
13327f29673bSTobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL,0x03},
13337f29673bSTobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE,
13347f29673bSTobin Davis 	 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
13357f29673bSTobin Davis 	{0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
1336c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1337c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
1338c9b443d4STobin Davis 	{0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
1339c9b443d4STobin Davis 	 AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
1340c9b443d4STobin Davis 	/* SPDIF route: PCM */
1341c9b443d4STobin Davis 	{ 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
134282f30040STobin Davis 	/* Enable unsolicited events */
134382f30040STobin Davis 	{0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
134482f30040STobin Davis 	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1345c9b443d4STobin Davis 	{ } /* end */
1346c9b443d4STobin Davis };
1347c9b443d4STobin Davis 
1348c9b443d4STobin Davis /* configuration for Toshiba Laptops */
1349c9b443d4STobin Davis static struct hda_verb cxt5047_toshiba_init_verbs[] = {
13503b628867STakashi Iwai 	{0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1351c9b443d4STobin Davis 	{}
1352c9b443d4STobin Davis };
1353c9b443d4STobin Davis 
1354c9b443d4STobin Davis /* Test configuration for debugging, modelled after the ALC260 test
1355c9b443d4STobin Davis  * configuration.
1356c9b443d4STobin Davis  */
1357c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1358c9b443d4STobin Davis static struct hda_input_mux cxt5047_test_capture_source = {
135982f30040STobin Davis 	.num_items = 4,
1360c9b443d4STobin Davis 	.items = {
136182f30040STobin Davis 		{ "LINE1 pin", 0x0 },
136282f30040STobin Davis 		{ "MIC1 pin", 0x1 },
136382f30040STobin Davis 		{ "MIC2 pin", 0x2 },
136482f30040STobin Davis 		{ "CD pin", 0x3 },
1365c9b443d4STobin Davis         },
1366c9b443d4STobin Davis };
1367c9b443d4STobin Davis 
1368c9b443d4STobin Davis static struct snd_kcontrol_new cxt5047_test_mixer[] = {
1369c9b443d4STobin Davis 
1370c9b443d4STobin Davis 	/* Output only controls */
137182f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
137282f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
137382f30040STobin Davis 	HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
137482f30040STobin Davis 	HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
1375c9b443d4STobin Davis 	HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1376c9b443d4STobin Davis 	HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1377c9b443d4STobin Davis 	HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1378c9b443d4STobin Davis 	HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
137982f30040STobin Davis 	HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
138082f30040STobin Davis 	HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
138182f30040STobin Davis 	HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
138282f30040STobin Davis 	HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
1383c9b443d4STobin Davis 
1384c9b443d4STobin Davis 	/* Modes for retasking pin widgets */
1385c9b443d4STobin Davis 	CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
1386c9b443d4STobin Davis 	CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
1387c9b443d4STobin Davis 
138882f30040STobin Davis 	/* EAPD Switch Control */
138982f30040STobin Davis 	CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
139082f30040STobin Davis 
1391c9b443d4STobin Davis 	/* Loopback mixer controls */
139282f30040STobin Davis 	HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
139382f30040STobin Davis 	HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
139482f30040STobin Davis 	HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
139582f30040STobin Davis 	HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
139682f30040STobin Davis 	HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
139782f30040STobin Davis 	HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
139882f30040STobin Davis 	HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
139982f30040STobin Davis 	HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
1400c9b443d4STobin Davis 
140182f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
140282f30040STobin Davis 	HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
140382f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
140482f30040STobin Davis 	HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
140582f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
140682f30040STobin Davis 	HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
140782f30040STobin Davis 	HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
140882f30040STobin Davis 	HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
1409c9b443d4STobin Davis 	{
1410c9b443d4STobin Davis 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1411c9b443d4STobin Davis 		.name = "Input Source",
1412c9b443d4STobin Davis 		.info = conexant_mux_enum_info,
1413c9b443d4STobin Davis 		.get = conexant_mux_enum_get,
1414c9b443d4STobin Davis 		.put = conexant_mux_enum_put,
1415c9b443d4STobin Davis 	},
1416854206b0STakashi Iwai 	HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
14179f113e0eSMarc Boucher 
1418c9b443d4STobin Davis 	{ } /* end */
1419c9b443d4STobin Davis };
1420c9b443d4STobin Davis 
1421c9b443d4STobin Davis static struct hda_verb cxt5047_test_init_verbs[] = {
1422c9b443d4STobin Davis 	/* Enable retasking pins as output, initially without power amp */
1423c9b443d4STobin Davis 	{0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1424c9b443d4STobin Davis 	{0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1425c9b443d4STobin Davis 	{0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1426c9b443d4STobin Davis 
1427c9b443d4STobin Davis 	/* Disable digital (SPDIF) pins initially, but users can enable
1428c9b443d4STobin Davis 	 * them via a mixer switch.  In the case of SPDIF-out, this initverb
1429c9b443d4STobin Davis 	 * payload also sets the generation to 0, output to be in "consumer"
1430c9b443d4STobin Davis 	 * PCM format, copyright asserted, no pre-emphasis and no validity
1431c9b443d4STobin Davis 	 * control.
1432c9b443d4STobin Davis 	 */
1433c9b443d4STobin Davis 	{0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
1434c9b443d4STobin Davis 
1435c9b443d4STobin Davis 	/* Ensure mic1, mic2, line1 pin widgets take input from the
1436c9b443d4STobin Davis 	 * OUT1 sum bus when acting as an output.
1437c9b443d4STobin Davis 	 */
1438c9b443d4STobin Davis 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0},
1439c9b443d4STobin Davis 	{0x1b, AC_VERB_SET_CONNECT_SEL, 0},
1440c9b443d4STobin Davis 
1441c9b443d4STobin Davis 	/* Start with output sum widgets muted and their output gains at min */
1442c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1443c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
1444c9b443d4STobin Davis 
1445c9b443d4STobin Davis 	/* Unmute retasking pin widget output buffers since the default
1446c9b443d4STobin Davis 	 * state appears to be output.  As the pin mode is changed by the
1447c9b443d4STobin Davis 	 * user the pin mode control will take care of enabling the pin's
1448c9b443d4STobin Davis 	 * input/output buffers as needed.
1449c9b443d4STobin Davis 	 */
1450c9b443d4STobin Davis 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1451c9b443d4STobin Davis 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1452c9b443d4STobin Davis 	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1453c9b443d4STobin Davis 
1454c9b443d4STobin Davis 	/* Mute capture amp left and right */
1455c9b443d4STobin Davis 	{0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
1456c9b443d4STobin Davis 
1457c9b443d4STobin Davis 	/* Set ADC connection select to match default mixer setting (mic1
1458c9b443d4STobin Davis 	 * pin)
1459c9b443d4STobin Davis 	 */
1460c9b443d4STobin Davis 	{0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
1461c9b443d4STobin Davis 
1462c9b443d4STobin Davis 	/* Mute all inputs to mixer widget (even unconnected ones) */
1463c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
1464c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
1465c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
1466c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
1467c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
1468c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
1469c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
1470c9b443d4STobin Davis 	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
1471c9b443d4STobin Davis 
1472c9b443d4STobin Davis 	{ }
1473c9b443d4STobin Davis };
1474c9b443d4STobin Davis #endif
1475c9b443d4STobin Davis 
1476c9b443d4STobin Davis 
1477c9b443d4STobin Davis /* initialize jack-sensing, too */
1478c9b443d4STobin Davis static int cxt5047_hp_init(struct hda_codec *codec)
1479c9b443d4STobin Davis {
1480c9b443d4STobin Davis 	conexant_init(codec);
1481c9b443d4STobin Davis 	cxt5047_hp_automute(codec);
1482c9b443d4STobin Davis 	return 0;
1483c9b443d4STobin Davis }
1484c9b443d4STobin Davis 
1485c9b443d4STobin Davis 
1486c9b443d4STobin Davis enum {
1487f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP,		/* Laptops w/o EAPD support */
1488f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_HP,	/* Some HP laptops */
1489f5fcc13cSTakashi Iwai 	CXT5047_LAPTOP_EAPD,	/* Laptops with EAPD support */
1490c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1491c9b443d4STobin Davis 	CXT5047_TEST,
1492c9b443d4STobin Davis #endif
1493f5fcc13cSTakashi Iwai 	CXT5047_MODELS
1494c9b443d4STobin Davis };
1495c9b443d4STobin Davis 
1496f5fcc13cSTakashi Iwai static const char *cxt5047_models[CXT5047_MODELS] = {
1497f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP]	= "laptop",
1498f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_HP]	= "laptop-hp",
1499f5fcc13cSTakashi Iwai 	[CXT5047_LAPTOP_EAPD]	= "laptop-eapd",
1500c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1501f5fcc13cSTakashi Iwai 	[CXT5047_TEST]		= "test",
1502c9b443d4STobin Davis #endif
1503f5fcc13cSTakashi Iwai };
1504c9b443d4STobin Davis 
1505f5fcc13cSTakashi Iwai static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1506ac3e3741STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1507dea0a509STakashi Iwai 	SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1508dea0a509STakashi Iwai 			   CXT5047_LAPTOP),
1509f5fcc13cSTakashi Iwai 	SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1510c9b443d4STobin Davis 	{}
1511c9b443d4STobin Davis };
1512c9b443d4STobin Davis 
1513c9b443d4STobin Davis static int patch_cxt5047(struct hda_codec *codec)
1514c9b443d4STobin Davis {
1515c9b443d4STobin Davis 	struct conexant_spec *spec;
1516c9b443d4STobin Davis 	int board_config;
1517c9b443d4STobin Davis 
1518c9b443d4STobin Davis 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1519c9b443d4STobin Davis 	if (!spec)
1520c9b443d4STobin Davis 		return -ENOMEM;
1521c9b443d4STobin Davis 	codec->spec = spec;
15229421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1523c9b443d4STobin Davis 
1524c9b443d4STobin Davis 	spec->multiout.max_channels = 2;
1525c9b443d4STobin Davis 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
1526c9b443d4STobin Davis 	spec->multiout.dac_nids = cxt5047_dac_nids;
1527c9b443d4STobin Davis 	spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
1528c9b443d4STobin Davis 	spec->num_adc_nids = 1;
1529c9b443d4STobin Davis 	spec->adc_nids = cxt5047_adc_nids;
1530c9b443d4STobin Davis 	spec->capsrc_nids = cxt5047_capsrc_nids;
1531c9b443d4STobin Davis 	spec->num_mixers = 1;
1532df481e41STakashi Iwai 	spec->mixers[0] = cxt5047_base_mixers;
1533c9b443d4STobin Davis 	spec->num_init_verbs = 1;
1534c9b443d4STobin Davis 	spec->init_verbs[0] = cxt5047_init_verbs;
1535c9b443d4STobin Davis 	spec->spdif_route = 0;
15365cd57529STobin Davis 	spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
15375cd57529STobin Davis 	spec->channel_mode = cxt5047_modes,
1538c9b443d4STobin Davis 
1539c9b443d4STobin Davis 	codec->patch_ops = conexant_patch_ops;
1540c9b443d4STobin Davis 
1541f5fcc13cSTakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
1542f5fcc13cSTakashi Iwai 						  cxt5047_models,
1543f5fcc13cSTakashi Iwai 						  cxt5047_cfg_tbl);
1544c9b443d4STobin Davis 	switch (board_config) {
1545c9b443d4STobin Davis 	case CXT5047_LAPTOP:
1546df481e41STakashi Iwai 		spec->num_mixers = 2;
1547df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1548df481e41STakashi Iwai 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1549c9b443d4STobin Davis 		break;
1550c9b443d4STobin Davis 	case CXT5047_LAPTOP_HP:
1551df481e41STakashi Iwai 		spec->num_mixers = 2;
1552df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_only_mixers;
1553fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1554c9b443d4STobin Davis 		codec->patch_ops.init = cxt5047_hp_init;
1555c9b443d4STobin Davis 		break;
1556c9b443d4STobin Davis 	case CXT5047_LAPTOP_EAPD:
155782f30040STobin Davis 		spec->input_mux = &cxt5047_toshiba_capture_source;
1558df481e41STakashi Iwai 		spec->num_mixers = 2;
1559df481e41STakashi Iwai 		spec->mixers[1] = cxt5047_hp_spk_mixers;
1560c9b443d4STobin Davis 		spec->num_init_verbs = 2;
1561c9b443d4STobin Davis 		spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1562fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1563c9b443d4STobin Davis 		break;
1564c9b443d4STobin Davis #ifdef CONFIG_SND_DEBUG
1565c9b443d4STobin Davis 	case CXT5047_TEST:
1566c9b443d4STobin Davis 		spec->input_mux = &cxt5047_test_capture_source;
1567c9b443d4STobin Davis 		spec->mixers[0] = cxt5047_test_mixer;
1568c9b443d4STobin Davis 		spec->init_verbs[0] = cxt5047_test_init_verbs;
1569fb3409e7STobin Davis 		codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1570c9b443d4STobin Davis #endif
1571c9b443d4STobin Davis 	}
1572dd5746a8STakashi Iwai 	spec->vmaster_nid = 0x13;
1573c9b443d4STobin Davis 	return 0;
1574c9b443d4STobin Davis }
1575c9b443d4STobin Davis 
1576461e2c78STakashi Iwai /* Conexant 5051 specific */
1577461e2c78STakashi Iwai static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
1578461e2c78STakashi Iwai static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
1579461e2c78STakashi Iwai 
1580461e2c78STakashi Iwai static struct hda_channel_mode cxt5051_modes[1] = {
1581461e2c78STakashi Iwai 	{ 2, NULL },
1582461e2c78STakashi Iwai };
1583461e2c78STakashi Iwai 
1584461e2c78STakashi Iwai static void cxt5051_update_speaker(struct hda_codec *codec)
1585461e2c78STakashi Iwai {
1586461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1587461e2c78STakashi Iwai 	unsigned int pinctl;
1588461e2c78STakashi Iwai 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
1589461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
1590461e2c78STakashi Iwai 			    pinctl);
1591461e2c78STakashi Iwai }
1592461e2c78STakashi Iwai 
1593461e2c78STakashi Iwai /* turn on/off EAPD (+ mute HP) as a master switch */
1594461e2c78STakashi Iwai static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1595461e2c78STakashi Iwai 				    struct snd_ctl_elem_value *ucontrol)
1596461e2c78STakashi Iwai {
1597461e2c78STakashi Iwai 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1598461e2c78STakashi Iwai 
1599461e2c78STakashi Iwai 	if (!cxt_eapd_put(kcontrol, ucontrol))
1600461e2c78STakashi Iwai 		return 0;
1601461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1602461e2c78STakashi Iwai 	return 1;
1603461e2c78STakashi Iwai }
1604461e2c78STakashi Iwai 
1605461e2c78STakashi Iwai /* toggle input of built-in and mic jack appropriately */
1606461e2c78STakashi Iwai static void cxt5051_portb_automic(struct hda_codec *codec)
1607461e2c78STakashi Iwai {
160879d7d533STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1609461e2c78STakashi Iwai 	unsigned int present;
1610461e2c78STakashi Iwai 
161179d7d533STakashi Iwai 	if (spec->no_auto_mic)
161279d7d533STakashi Iwai 		return;
1613d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x17);
1614461e2c78STakashi Iwai 	snd_hda_codec_write(codec, 0x14, 0,
1615461e2c78STakashi Iwai 			    AC_VERB_SET_CONNECT_SEL,
1616461e2c78STakashi Iwai 			    present ? 0x01 : 0x00);
1617461e2c78STakashi Iwai }
1618461e2c78STakashi Iwai 
1619461e2c78STakashi Iwai /* switch the current ADC according to the jack state */
1620461e2c78STakashi Iwai static void cxt5051_portc_automic(struct hda_codec *codec)
1621461e2c78STakashi Iwai {
1622461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1623461e2c78STakashi Iwai 	unsigned int present;
1624461e2c78STakashi Iwai 	hda_nid_t new_adc;
1625461e2c78STakashi Iwai 
162679d7d533STakashi Iwai 	if (spec->no_auto_mic)
162779d7d533STakashi Iwai 		return;
1628d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x18);
1629461e2c78STakashi Iwai 	if (present)
1630461e2c78STakashi Iwai 		spec->cur_adc_idx = 1;
1631461e2c78STakashi Iwai 	else
1632461e2c78STakashi Iwai 		spec->cur_adc_idx = 0;
1633461e2c78STakashi Iwai 	new_adc = spec->adc_nids[spec->cur_adc_idx];
1634461e2c78STakashi Iwai 	if (spec->cur_adc && spec->cur_adc != new_adc) {
1635461e2c78STakashi Iwai 		/* stream is running, let's swap the current ADC */
1636888afa15STakashi Iwai 		snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1637461e2c78STakashi Iwai 		spec->cur_adc = new_adc;
1638461e2c78STakashi Iwai 		snd_hda_codec_setup_stream(codec, new_adc,
1639461e2c78STakashi Iwai 					   spec->cur_adc_stream_tag, 0,
1640461e2c78STakashi Iwai 					   spec->cur_adc_format);
1641461e2c78STakashi Iwai 	}
1642461e2c78STakashi Iwai }
1643461e2c78STakashi Iwai 
1644461e2c78STakashi Iwai /* mute internal speaker if HP is plugged */
1645461e2c78STakashi Iwai static void cxt5051_hp_automute(struct hda_codec *codec)
1646461e2c78STakashi Iwai {
1647461e2c78STakashi Iwai 	struct conexant_spec *spec = codec->spec;
1648461e2c78STakashi Iwai 
1649d56757abSTakashi Iwai 	spec->hp_present = snd_hda_jack_detect(codec, 0x16);
1650461e2c78STakashi Iwai 	cxt5051_update_speaker(codec);
1651461e2c78STakashi Iwai }
1652461e2c78STakashi Iwai 
1653461e2c78STakashi Iwai /* unsolicited event for HP jack sensing */
1654461e2c78STakashi Iwai static void cxt5051_hp_unsol_event(struct hda_codec *codec,
1655461e2c78STakashi Iwai 				   unsigned int res)
1656461e2c78STakashi Iwai {
1657acf26c0cSUlrich Dangel 	int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
1658461e2c78STakashi Iwai 	switch (res >> 26) {
1659461e2c78STakashi Iwai 	case CONEXANT_HP_EVENT:
1660461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1661461e2c78STakashi Iwai 		break;
1662461e2c78STakashi Iwai 	case CXT5051_PORTB_EVENT:
1663461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1664461e2c78STakashi Iwai 		break;
1665461e2c78STakashi Iwai 	case CXT5051_PORTC_EVENT:
1666461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1667461e2c78STakashi Iwai 		break;
1668461e2c78STakashi Iwai 	}
1669acf26c0cSUlrich Dangel 	conexant_report_jack(codec, nid);
1670461e2c78STakashi Iwai }
1671461e2c78STakashi Iwai 
1672461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_mixers[] = {
1673461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1674461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1675461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
1676461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
1677461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
1678461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
1679461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1680461e2c78STakashi Iwai 	{
1681461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1682461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1683461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1684461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1685461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1686461e2c78STakashi Iwai 		.private_value = 0x1a,
1687461e2c78STakashi Iwai 	},
1688461e2c78STakashi Iwai 
1689461e2c78STakashi Iwai 	{}
1690461e2c78STakashi Iwai };
1691461e2c78STakashi Iwai 
1692461e2c78STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1693461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
1694461e2c78STakashi Iwai 	HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
1695461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
1696461e2c78STakashi Iwai 	HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
1697461e2c78STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1698461e2c78STakashi Iwai 	{
1699461e2c78STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1700461e2c78STakashi Iwai 		.name = "Master Playback Switch",
1701461e2c78STakashi Iwai 		.info = cxt_eapd_info,
1702461e2c78STakashi Iwai 		.get = cxt_eapd_get,
1703461e2c78STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
1704461e2c78STakashi Iwai 		.private_value = 0x1a,
1705461e2c78STakashi Iwai 	},
1706461e2c78STakashi Iwai 
1707461e2c78STakashi Iwai 	{}
1708461e2c78STakashi Iwai };
1709461e2c78STakashi Iwai 
171079d7d533STakashi Iwai static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
171179d7d533STakashi Iwai 	HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
171279d7d533STakashi Iwai 	HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
171379d7d533STakashi Iwai 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
171479d7d533STakashi Iwai 	{
171579d7d533STakashi Iwai 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
171679d7d533STakashi Iwai 		.name = "Master Playback Switch",
171779d7d533STakashi Iwai 		.info = cxt_eapd_info,
171879d7d533STakashi Iwai 		.get = cxt_eapd_get,
171979d7d533STakashi Iwai 		.put = cxt5051_hp_master_sw_put,
172079d7d533STakashi Iwai 		.private_value = 0x1a,
172179d7d533STakashi Iwai 	},
172279d7d533STakashi Iwai 
172379d7d533STakashi Iwai 	{}
172479d7d533STakashi Iwai };
172579d7d533STakashi Iwai 
1726461e2c78STakashi Iwai static struct hda_verb cxt5051_init_verbs[] = {
1727461e2c78STakashi Iwai 	/* Line in, Mic */
1728461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1729461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1730461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1731461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1732461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1733461e2c78STakashi Iwai 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1734461e2c78STakashi Iwai 	/* SPK  */
1735461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1736461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1737461e2c78STakashi Iwai 	/* HP, Amp  */
1738461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1739461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1740461e2c78STakashi Iwai 	/* DAC1 */
1741461e2c78STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1742461e2c78STakashi Iwai 	/* Record selector: Int mic */
1743461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1744461e2c78STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1745461e2c78STakashi Iwai 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1746461e2c78STakashi Iwai 	/* SPDIF route: PCM */
1747461e2c78STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1748461e2c78STakashi Iwai 	/* EAPD */
1749461e2c78STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1750461e2c78STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1751461e2c78STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1752461e2c78STakashi Iwai 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1753461e2c78STakashi Iwai 	{ } /* end */
1754461e2c78STakashi Iwai };
1755461e2c78STakashi Iwai 
175679d7d533STakashi Iwai static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
175779d7d533STakashi Iwai 	/* Line in, Mic */
175879d7d533STakashi Iwai 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
175979d7d533STakashi Iwai 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
176079d7d533STakashi Iwai 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
176179d7d533STakashi Iwai 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
176279d7d533STakashi Iwai 	/* SPK  */
176379d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
176479d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
176579d7d533STakashi Iwai 	/* HP, Amp  */
176679d7d533STakashi Iwai 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
176779d7d533STakashi Iwai 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
176879d7d533STakashi Iwai 	/* DAC1 */
176979d7d533STakashi Iwai 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
177079d7d533STakashi Iwai 	/* Record selector: Int mic */
177179d7d533STakashi Iwai 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
177279d7d533STakashi Iwai 	{0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
177379d7d533STakashi Iwai 	/* SPDIF route: PCM */
177479d7d533STakashi Iwai 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
177579d7d533STakashi Iwai 	/* EAPD */
177679d7d533STakashi Iwai 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
177779d7d533STakashi Iwai 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
177879d7d533STakashi Iwai 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
177979d7d533STakashi Iwai 	{ } /* end */
178079d7d533STakashi Iwai };
178179d7d533STakashi Iwai 
178227e08988SAristeu Sergio Rozanski Filho static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
178327e08988SAristeu Sergio Rozanski Filho 	/* Line in, Mic */
178427e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
178527e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
178627e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
178727e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
178827e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
178927e08988SAristeu Sergio Rozanski Filho 	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
179027e08988SAristeu Sergio Rozanski Filho 	/* SPK  */
179127e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
179227e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
179327e08988SAristeu Sergio Rozanski Filho 	/* HP, Amp  */
179427e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
179527e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
179627e08988SAristeu Sergio Rozanski Filho 	/* Docking HP */
179727e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
179827e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
179927e08988SAristeu Sergio Rozanski Filho 	/* DAC1 */
180027e08988SAristeu Sergio Rozanski Filho 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
180127e08988SAristeu Sergio Rozanski Filho 	/* Record selector: Int mic */
180227e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
180327e08988SAristeu Sergio Rozanski Filho 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
180427e08988SAristeu Sergio Rozanski Filho 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
180527e08988SAristeu Sergio Rozanski Filho 	/* SPDIF route: PCM */
180627e08988SAristeu Sergio Rozanski Filho 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
180727e08988SAristeu Sergio Rozanski Filho 	/* EAPD */
180827e08988SAristeu Sergio Rozanski Filho 	{0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
180927e08988SAristeu Sergio Rozanski Filho 	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
181027e08988SAristeu Sergio Rozanski Filho 	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
181127e08988SAristeu Sergio Rozanski Filho 	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
181227e08988SAristeu Sergio Rozanski Filho 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
181327e08988SAristeu Sergio Rozanski Filho 	{ } /* end */
181427e08988SAristeu Sergio Rozanski Filho };
181527e08988SAristeu Sergio Rozanski Filho 
1816461e2c78STakashi Iwai /* initialize jack-sensing, too */
1817461e2c78STakashi Iwai static int cxt5051_init(struct hda_codec *codec)
1818461e2c78STakashi Iwai {
1819461e2c78STakashi Iwai 	conexant_init(codec);
1820acf26c0cSUlrich Dangel 	conexant_init_jacks(codec);
1821461e2c78STakashi Iwai 	if (codec->patch_ops.unsol_event) {
1822461e2c78STakashi Iwai 		cxt5051_hp_automute(codec);
1823461e2c78STakashi Iwai 		cxt5051_portb_automic(codec);
1824461e2c78STakashi Iwai 		cxt5051_portc_automic(codec);
1825461e2c78STakashi Iwai 	}
1826461e2c78STakashi Iwai 	return 0;
1827461e2c78STakashi Iwai }
1828461e2c78STakashi Iwai 
1829461e2c78STakashi Iwai 
1830461e2c78STakashi Iwai enum {
1831461e2c78STakashi Iwai 	CXT5051_LAPTOP,	 /* Laptops w/ EAPD support */
1832461e2c78STakashi Iwai 	CXT5051_HP,	/* no docking */
183379d7d533STakashi Iwai 	CXT5051_HP_DV6736,	/* HP without mic switch */
183427e08988SAristeu Sergio Rozanski Filho 	CXT5051_LENOVO_X200,	/* Lenovo X200 laptop */
1835461e2c78STakashi Iwai 	CXT5051_MODELS
1836461e2c78STakashi Iwai };
1837461e2c78STakashi Iwai 
1838461e2c78STakashi Iwai static const char *cxt5051_models[CXT5051_MODELS] = {
1839461e2c78STakashi Iwai 	[CXT5051_LAPTOP]	= "laptop",
1840461e2c78STakashi Iwai 	[CXT5051_HP]		= "hp",
184179d7d533STakashi Iwai 	[CXT5051_HP_DV6736]	= "hp-dv6736",
184227e08988SAristeu Sergio Rozanski Filho 	[CXT5051_LENOVO_X200]	= "lenovo-x200",
1843461e2c78STakashi Iwai };
1844461e2c78STakashi Iwai 
1845461e2c78STakashi Iwai static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
184679d7d533STakashi Iwai 	SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
18471812e67cSTony Vroon 	SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
1848461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1849461e2c78STakashi Iwai 		      CXT5051_LAPTOP),
1850461e2c78STakashi Iwai 	SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
185127e08988SAristeu Sergio Rozanski Filho 	SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1852461e2c78STakashi Iwai 	{}
1853461e2c78STakashi Iwai };
1854461e2c78STakashi Iwai 
1855461e2c78STakashi Iwai static int patch_cxt5051(struct hda_codec *codec)
1856461e2c78STakashi Iwai {
1857461e2c78STakashi Iwai 	struct conexant_spec *spec;
1858461e2c78STakashi Iwai 	int board_config;
1859461e2c78STakashi Iwai 
1860461e2c78STakashi Iwai 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1861461e2c78STakashi Iwai 	if (!spec)
1862461e2c78STakashi Iwai 		return -ENOMEM;
1863461e2c78STakashi Iwai 	codec->spec = spec;
18649421f954STakashi Iwai 	codec->pin_amp_workaround = 1;
1865461e2c78STakashi Iwai 
1866461e2c78STakashi Iwai 	codec->patch_ops = conexant_patch_ops;
1867461e2c78STakashi Iwai 	codec->patch_ops.init = cxt5051_init;
1868461e2c78STakashi Iwai 
1869461e2c78STakashi Iwai 	spec->multiout.max_channels = 2;
1870461e2c78STakashi Iwai 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
1871461e2c78STakashi Iwai 	spec->multiout.dac_nids = cxt5051_dac_nids;
1872461e2c78STakashi Iwai 	spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
1873461e2c78STakashi Iwai 	spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
1874461e2c78STakashi Iwai 	spec->adc_nids = cxt5051_adc_nids;
1875461e2c78STakashi Iwai 	spec->num_mixers = 1;
1876461e2c78STakashi Iwai 	spec->mixers[0] = cxt5051_mixers;
1877461e2c78STakashi Iwai 	spec->num_init_verbs = 1;
1878461e2c78STakashi Iwai 	spec->init_verbs[0] = cxt5051_init_verbs;
1879461e2c78STakashi Iwai 	spec->spdif_route = 0;
1880461e2c78STakashi Iwai 	spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
1881461e2c78STakashi Iwai 	spec->channel_mode = cxt5051_modes;
1882461e2c78STakashi Iwai 	spec->cur_adc = 0;
1883461e2c78STakashi Iwai 	spec->cur_adc_idx = 0;
1884461e2c78STakashi Iwai 
188579d7d533STakashi Iwai 	codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
188679d7d533STakashi Iwai 
1887461e2c78STakashi Iwai 	board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1888461e2c78STakashi Iwai 						  cxt5051_models,
1889461e2c78STakashi Iwai 						  cxt5051_cfg_tbl);
1890461e2c78STakashi Iwai 	switch (board_config) {
1891461e2c78STakashi Iwai 	case CXT5051_HP:
1892461e2c78STakashi Iwai 		spec->mixers[0] = cxt5051_hp_mixers;
1893461e2c78STakashi Iwai 		break;
189479d7d533STakashi Iwai 	case CXT5051_HP_DV6736:
189579d7d533STakashi Iwai 		spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
189679d7d533STakashi Iwai 		spec->mixers[0] = cxt5051_hp_dv6736_mixers;
189779d7d533STakashi Iwai 		spec->no_auto_mic = 1;
189879d7d533STakashi Iwai 		break;
189927e08988SAristeu Sergio Rozanski Filho 	case CXT5051_LENOVO_X200:
190027e08988SAristeu Sergio Rozanski Filho 		spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1901461e2c78STakashi Iwai 		break;
1902461e2c78STakashi Iwai 	}
1903461e2c78STakashi Iwai 
1904461e2c78STakashi Iwai 	return 0;
1905461e2c78STakashi Iwai }
1906461e2c78STakashi Iwai 
19070fb67e98SDaniel Drake /* Conexant 5066 specific */
19080fb67e98SDaniel Drake 
19090fb67e98SDaniel Drake static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
19100fb67e98SDaniel Drake static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
19110fb67e98SDaniel Drake static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
19120fb67e98SDaniel Drake #define CXT5066_SPDIF_OUT	0x21
19130fb67e98SDaniel Drake 
1914dbaccc0cSDaniel Drake /* OLPC's microphone port is DC coupled for use with external sensors,
1915dbaccc0cSDaniel Drake  * therefore we use a 50% mic bias in order to center the input signal with
1916dbaccc0cSDaniel Drake  * the DC input range of the codec. */
1917dbaccc0cSDaniel Drake #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
1918dbaccc0cSDaniel Drake 
19190fb67e98SDaniel Drake static struct hda_channel_mode cxt5066_modes[1] = {
19200fb67e98SDaniel Drake 	{ 2, NULL },
19210fb67e98SDaniel Drake };
19220fb67e98SDaniel Drake 
19230fb67e98SDaniel Drake static void cxt5066_update_speaker(struct hda_codec *codec)
19240fb67e98SDaniel Drake {
19250fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
19260fb67e98SDaniel Drake 	unsigned int pinctl;
19270fb67e98SDaniel Drake 
19280fb67e98SDaniel Drake 	snd_printdd("CXT5066: update speaker, hp_present=%d\n",
19290fb67e98SDaniel Drake 		spec->hp_present);
19300fb67e98SDaniel Drake 
19310fb67e98SDaniel Drake 	/* Port A (HP) */
19320fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
19330fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
19340fb67e98SDaniel Drake 			pinctl);
19350fb67e98SDaniel Drake 
19360fb67e98SDaniel Drake 	/* Port D (HP/LO) */
19370fb67e98SDaniel Drake 	pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
19380fb67e98SDaniel Drake 		? spec->port_d_mode : 0;
19390fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
19400fb67e98SDaniel Drake 			pinctl);
19410fb67e98SDaniel Drake 
19420fb67e98SDaniel Drake 	/* CLASS_D AMP */
19430fb67e98SDaniel Drake 	pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
19440fb67e98SDaniel Drake 	snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
19450fb67e98SDaniel Drake 			pinctl);
19460fb67e98SDaniel Drake 
19470fb67e98SDaniel Drake 	if (spec->dell_automute) {
19480fb67e98SDaniel Drake 		/* DELL AIO Port Rule: PortA > PortD > IntSpk */
19490fb67e98SDaniel Drake 		pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
19500fb67e98SDaniel Drake 			? PIN_OUT : 0;
19510fb67e98SDaniel Drake 		snd_hda_codec_write(codec, 0x1c, 0,
19520fb67e98SDaniel Drake 			AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
19530fb67e98SDaniel Drake 	}
19540fb67e98SDaniel Drake }
19550fb67e98SDaniel Drake 
19560fb67e98SDaniel Drake /* turn on/off EAPD (+ mute HP) as a master switch */
19570fb67e98SDaniel Drake static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
19580fb67e98SDaniel Drake 				    struct snd_ctl_elem_value *ucontrol)
19590fb67e98SDaniel Drake {
19600fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
19610fb67e98SDaniel Drake 
19620fb67e98SDaniel Drake 	if (!cxt_eapd_put(kcontrol, ucontrol))
19630fb67e98SDaniel Drake 		return 0;
19640fb67e98SDaniel Drake 
19650fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
19660fb67e98SDaniel Drake 	return 1;
19670fb67e98SDaniel Drake }
19680fb67e98SDaniel Drake 
19690fb67e98SDaniel Drake /* toggle input of built-in and mic jack appropriately */
19700fb67e98SDaniel Drake static void cxt5066_automic(struct hda_codec *codec)
19710fb67e98SDaniel Drake {
1972dbaccc0cSDaniel Drake 	struct conexant_spec *spec = codec->spec;
1973dbaccc0cSDaniel Drake 	struct hda_verb ext_mic_present[] = {
19740fb67e98SDaniel Drake 		/* enable external mic, port B */
1975dbaccc0cSDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
19760fb67e98SDaniel Drake 
19770fb67e98SDaniel Drake 		/* switch to external mic input */
19780fb67e98SDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
19790fb67e98SDaniel Drake 
19800fb67e98SDaniel Drake 		/* disable internal mic, port C */
19810fb67e98SDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
19820fb67e98SDaniel Drake 		{}
19830fb67e98SDaniel Drake 	};
19840fb67e98SDaniel Drake 	static struct hda_verb ext_mic_absent[] = {
19850fb67e98SDaniel Drake 		/* enable internal mic, port C */
19860fb67e98SDaniel Drake 		{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
19870fb67e98SDaniel Drake 
19880fb67e98SDaniel Drake 		/* switch to internal mic input */
19890fb67e98SDaniel Drake 		{0x17, AC_VERB_SET_CONNECT_SEL, 1},
19900fb67e98SDaniel Drake 
19910fb67e98SDaniel Drake 		/* disable external mic, port B */
19920fb67e98SDaniel Drake 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
19930fb67e98SDaniel Drake 		{}
19940fb67e98SDaniel Drake 	};
19950fb67e98SDaniel Drake 	unsigned int present;
19960fb67e98SDaniel Drake 
1997d56757abSTakashi Iwai 	present = snd_hda_jack_detect(codec, 0x1a);
19980fb67e98SDaniel Drake 	if (present) {
19990fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone detected\n");
20000fb67e98SDaniel Drake 		snd_hda_sequence_write(codec, ext_mic_present);
20010fb67e98SDaniel Drake 	} else {
20020fb67e98SDaniel Drake 		snd_printdd("CXT5066: external microphone absent\n");
20030fb67e98SDaniel Drake 		snd_hda_sequence_write(codec, ext_mic_absent);
20040fb67e98SDaniel Drake 	}
20050fb67e98SDaniel Drake }
20060fb67e98SDaniel Drake 
200795a618bdSEinar Rünkaru /* toggle input of built-in digital mic and mic jack appropriately */
200895a618bdSEinar Rünkaru static void cxt5066_vostro_automic(struct hda_codec *codec)
200995a618bdSEinar Rünkaru {
201095a618bdSEinar Rünkaru 	struct conexant_spec *spec = codec->spec;
201195a618bdSEinar Rünkaru 	unsigned int present;
201295a618bdSEinar Rünkaru 
201395a618bdSEinar Rünkaru 	struct hda_verb ext_mic_present[] = {
201495a618bdSEinar Rünkaru 		/* enable external mic, port B */
201595a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, spec->ext_mic_bias},
201695a618bdSEinar Rünkaru 
201795a618bdSEinar Rünkaru 		/* switch to external mic input */
201895a618bdSEinar Rünkaru 		{0x17, AC_VERB_SET_CONNECT_SEL, 0},
201995a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 0},
202095a618bdSEinar Rünkaru 
202195a618bdSEinar Rünkaru 		/* disable internal digital mic */
202295a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
202395a618bdSEinar Rünkaru 		{}
202495a618bdSEinar Rünkaru 	};
202595a618bdSEinar Rünkaru 	static struct hda_verb ext_mic_absent[] = {
202695a618bdSEinar Rünkaru 		/* enable internal mic, port C */
202795a618bdSEinar Rünkaru 		{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
202895a618bdSEinar Rünkaru 
202995a618bdSEinar Rünkaru 		/* switch to internal mic input */
203095a618bdSEinar Rünkaru 		{0x14, AC_VERB_SET_CONNECT_SEL, 2},
203195a618bdSEinar Rünkaru 
203295a618bdSEinar Rünkaru 		/* disable external mic, port B */
203395a618bdSEinar Rünkaru 		{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
203495a618bdSEinar Rünkaru 		{}
203595a618bdSEinar Rünkaru 	};
203695a618bdSEinar Rünkaru 
203795a618bdSEinar Rünkaru 	present = snd_hda_jack_detect(codec, 0x1a);
203895a618bdSEinar Rünkaru 	if (present) {
203995a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone detected\n");
204095a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_present);
204195a618bdSEinar Rünkaru 	} else {
204295a618bdSEinar Rünkaru 		snd_printdd("CXT5066: external microphone absent\n");
204395a618bdSEinar Rünkaru 		snd_hda_sequence_write(codec, ext_mic_absent);
204495a618bdSEinar Rünkaru 	}
204595a618bdSEinar Rünkaru }
204695a618bdSEinar Rünkaru 
20470fb67e98SDaniel Drake /* mute internal speaker if HP is plugged */
20480fb67e98SDaniel Drake static void cxt5066_hp_automute(struct hda_codec *codec)
20490fb67e98SDaniel Drake {
20500fb67e98SDaniel Drake 	struct conexant_spec *spec = codec->spec;
20510fb67e98SDaniel Drake 	unsigned int portA, portD;
20520fb67e98SDaniel Drake 
20530fb67e98SDaniel Drake 	/* Port A */
2054d56757abSTakashi Iwai 	portA = snd_hda_jack_detect(codec, 0x19);
20550fb67e98SDaniel Drake 
20560fb67e98SDaniel Drake 	/* Port D */
2057d56757abSTakashi Iwai 	portD = snd_hda_jack_detect(codec, 0x1c);
20580fb67e98SDaniel Drake 
20590fb67e98SDaniel Drake 	spec->hp_present = !!(portA | portD);
20600fb67e98SDaniel Drake 	snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
20610fb67e98SDaniel Drake 		portA, portD, spec->hp_present);
20620fb67e98SDaniel Drake 	cxt5066_update_speaker(codec);
20630fb67e98SDaniel Drake }
20640fb67e98SDaniel Drake 
20650fb67e98SDaniel Drake /* unsolicited event for jack sensing */
20660fb67e98SDaniel Drake static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
20670fb67e98SDaniel Drake {
20680fb67e98SDaniel Drake 	snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
20690fb67e98SDaniel Drake 	switch (res >> 26) {
20700fb67e98SDaniel Drake 	case CONEXANT_HP_EVENT:
20710fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
20720fb67e98SDaniel Drake 		break;
20730fb67e98SDaniel Drake 	case CONEXANT_MIC_EVENT:
20740fb67e98SDaniel Drake 		cxt5066_automic(codec);
20750fb67e98SDaniel Drake 		break;
20760fb67e98SDaniel Drake 	}
20770fb67e98SDaniel Drake }
20780fb67e98SDaniel Drake 
207995a618bdSEinar Rünkaru /* unsolicited event for jack sensing */
208095a618bdSEinar Rünkaru static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
208195a618bdSEinar Rünkaru {
208295a618bdSEinar Rünkaru 	snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
208395a618bdSEinar Rünkaru 	switch (res >> 26) {
208495a618bdSEinar Rünkaru 	case CONEXANT_HP_EVENT:
208595a618bdSEinar Rünkaru 		cxt5066_hp_automute(codec);
208695a618bdSEinar Rünkaru 		break;
208795a618bdSEinar Rünkaru 	case CONEXANT_MIC_EVENT:
208895a618bdSEinar Rünkaru 		cxt5066_vostro_automic(codec);
208995a618bdSEinar Rünkaru 		break;
209095a618bdSEinar Rünkaru 	}
209195a618bdSEinar Rünkaru }
209295a618bdSEinar Rünkaru 
20930fb67e98SDaniel Drake static const struct hda_input_mux cxt5066_analog_mic_boost = {
20940fb67e98SDaniel Drake 	.num_items = 5,
20950fb67e98SDaniel Drake 	.items = {
20960fb67e98SDaniel Drake 		{ "0dB",  0 },
20970fb67e98SDaniel Drake 		{ "10dB", 1 },
20980fb67e98SDaniel Drake 		{ "20dB", 2 },
20990fb67e98SDaniel Drake 		{ "30dB", 3 },
21000fb67e98SDaniel Drake 		{ "40dB", 4 },
21010fb67e98SDaniel Drake 	},
21020fb67e98SDaniel Drake };
21030fb67e98SDaniel Drake 
21040fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
21050fb67e98SDaniel Drake 					   struct snd_ctl_elem_info *uinfo)
21060fb67e98SDaniel Drake {
21070fb67e98SDaniel Drake 	return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
21080fb67e98SDaniel Drake }
21090fb67e98SDaniel Drake 
21100fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
21110fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
21120fb67e98SDaniel Drake {
21130fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21140fb67e98SDaniel Drake 	int val;
2115254bba6aSEinar Rünkaru 	hda_nid_t nid = kcontrol->private_value & 0xff;
2116254bba6aSEinar Rünkaru 	int inout = (kcontrol->private_value & 0x100) ?
2117254bba6aSEinar Rünkaru 		AC_AMP_GET_INPUT : AC_AMP_GET_OUTPUT;
21180fb67e98SDaniel Drake 
2119254bba6aSEinar Rünkaru 	val = snd_hda_codec_read(codec, nid, 0,
2120254bba6aSEinar Rünkaru 		AC_VERB_GET_AMP_GAIN_MUTE, inout);
21210fb67e98SDaniel Drake 
21220fb67e98SDaniel Drake 	ucontrol->value.enumerated.item[0] = val & AC_AMP_GAIN;
21230fb67e98SDaniel Drake 	return 0;
21240fb67e98SDaniel Drake }
21250fb67e98SDaniel Drake 
21260fb67e98SDaniel Drake static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
21270fb67e98SDaniel Drake 					  struct snd_ctl_elem_value *ucontrol)
21280fb67e98SDaniel Drake {
21290fb67e98SDaniel Drake 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
21300fb67e98SDaniel Drake 	const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
21310fb67e98SDaniel Drake 	unsigned int idx;
2132254bba6aSEinar Rünkaru 	hda_nid_t nid = kcontrol->private_value & 0xff;
2133254bba6aSEinar Rünkaru 	int inout = (kcontrol->private_value & 0x100) ?
2134254bba6aSEinar Rünkaru 		AC_AMP_SET_INPUT : AC_AMP_SET_OUTPUT;
21350fb67e98SDaniel Drake 
21360fb67e98SDaniel Drake 	if (!imux->num_items)
21370fb67e98SDaniel Drake 		return 0;
21380fb67e98SDaniel Drake 	idx = ucontrol->value.enumerated.item[0];
21390fb67e98SDaniel Drake 	if (idx >= imux->num_items)
21400fb67e98SDaniel Drake 		idx = imux->num_items - 1;
21410fb67e98SDaniel Drake 
2142254bba6aSEinar Rünkaru 	snd_hda_codec_write_cache(codec, nid, 0,
21430fb67e98SDaniel Drake 		AC_VERB_SET_AMP_GAIN_MUTE,
2144254bba6aSEinar Rünkaru 		AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | inout |
21450fb67e98SDaniel Drake 			imux->items[idx].index);
21460fb67e98SDaniel Drake 
21470fb67e98SDaniel Drake 	return 1;
21480fb67e98SDaniel Drake }
21490fb67e98SDaniel Drake 
21500fb67e98SDaniel Drake static struct hda_input_mux cxt5066_capture_source = {
21510fb67e98SDaniel Drake 	.num_items = 4,
21520fb67e98SDaniel Drake 	.items = {
21530fb67e98SDaniel Drake 		{ "Mic B", 0 },
21540fb67e98SDaniel Drake 		{ "Mic C", 1 },
21550fb67e98SDaniel Drake 		{ "Mic E", 2 },
21560fb67e98SDaniel Drake 		{ "Mic F", 3 },
21570fb67e98SDaniel Drake 	},
21580fb67e98SDaniel Drake };
21590fb67e98SDaniel Drake 
21600fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
21610fb67e98SDaniel Drake 	.ops = &snd_hda_bind_vol,
21620fb67e98SDaniel Drake 	.values = {
21630fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
21640fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
21650fb67e98SDaniel Drake 		0
21660fb67e98SDaniel Drake 	},
21670fb67e98SDaniel Drake };
21680fb67e98SDaniel Drake 
21690fb67e98SDaniel Drake static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
21700fb67e98SDaniel Drake 	.ops = &snd_hda_bind_sw,
21710fb67e98SDaniel Drake 	.values = {
21720fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
21730fb67e98SDaniel Drake 		HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
21740fb67e98SDaniel Drake 		0
21750fb67e98SDaniel Drake 	},
21760fb67e98SDaniel Drake };
21770fb67e98SDaniel Drake 
21780fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master[] = {
21790fb67e98SDaniel Drake 	HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
21800fb67e98SDaniel Drake 	{}
21810fb67e98SDaniel Drake };
21820fb67e98SDaniel Drake 
21830fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
21840fb67e98SDaniel Drake 	{
21850fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
21860fb67e98SDaniel Drake 		.name = "Master Playback Volume",
21870fb67e98SDaniel Drake 		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
21880fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_READ |
21890fb67e98SDaniel Drake 				  SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
21900fb67e98SDaniel Drake 		.info = snd_hda_mixer_amp_volume_info,
21910fb67e98SDaniel Drake 		.get = snd_hda_mixer_amp_volume_get,
21920fb67e98SDaniel Drake 		.put = snd_hda_mixer_amp_volume_put,
21930fb67e98SDaniel Drake 		.tlv = { .c = snd_hda_mixer_amp_tlv },
21940fb67e98SDaniel Drake 		/* offset by 28 volume steps to limit minimum gain to -46dB */
21950fb67e98SDaniel Drake 		.private_value =
21960fb67e98SDaniel Drake 			HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
21970fb67e98SDaniel Drake 	},
21980fb67e98SDaniel Drake 	{}
21990fb67e98SDaniel Drake };
22000fb67e98SDaniel Drake 
22010fb67e98SDaniel Drake static struct snd_kcontrol_new cxt5066_mixers[] = {
22020fb67e98SDaniel Drake 	{
22030fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
22040fb67e98SDaniel Drake 		.name = "Master Playback Switch",
22050fb67e98SDaniel Drake 		.info = cxt_eapd_info,
22060fb67e98SDaniel Drake 		.get = cxt_eapd_get,
22070fb67e98SDaniel Drake 		.put = cxt5066_hp_master_sw_put,
22080fb67e98SDaniel Drake 		.private_value = 0x1d,
22090fb67e98SDaniel Drake 	},
22100fb67e98SDaniel Drake 
22110fb67e98SDaniel Drake 	{
22120fb67e98SDaniel Drake 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2213254bba6aSEinar Rünkaru 		.name = "Ext Mic Boost Capture Enum",
22140fb67e98SDaniel Drake 		.info = cxt5066_mic_boost_mux_enum_info,
22150fb67e98SDaniel Drake 		.get = cxt5066_mic_boost_mux_enum_get,
22160fb67e98SDaniel Drake 		.put = cxt5066_mic_boost_mux_enum_put,
2217254bba6aSEinar Rünkaru 		.private_value = 0x17,
22180fb67e98SDaniel Drake 	},
22190fb67e98SDaniel Drake 
22200fb67e98SDaniel Drake 	HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
22210fb67e98SDaniel Drake 	HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
22220fb67e98SDaniel Drake 	{}
22230fb67e98SDaniel Drake };
22240fb67e98SDaniel Drake 
2225254bba6aSEinar Rünkaru static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
2226254bba6aSEinar Rünkaru 	{
2227254bba6aSEinar Rünkaru 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2228254bba6aSEinar Rünkaru 		.name = "Int Mic Boost Capture Enum",
2229254bba6aSEinar Rünkaru 		.info = cxt5066_mic_boost_mux_enum_info,
2230254bba6aSEinar Rünkaru 		.get = cxt5066_mic_boost_mux_enum_get,
2231254bba6aSEinar Rünkaru 		.put = cxt5066_mic_boost_mux_enum_put,
2232254bba6aSEinar Rünkaru 		.private_value = 0x23 | 0x100,
2233254bba6aSEinar Rünkaru 	},
2234*c0f8faf0SEinar Rünkaru 	HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
2235254bba6aSEinar Rünkaru 	{}
2236254bba6aSEinar Rünkaru };
2237254bba6aSEinar Rünkaru 
22380fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs[] = {
22390fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
22400fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
22410fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
22420fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
22430fb67e98SDaniel Drake 
22440fb67e98SDaniel Drake 	/* Speakers  */
22450fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
22460fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
22470fb67e98SDaniel Drake 
22480fb67e98SDaniel Drake 	/* HP, Amp  */
22490fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
22500fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
22510fb67e98SDaniel Drake 
22520fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
22530fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
22540fb67e98SDaniel Drake 
22550fb67e98SDaniel Drake 	/* DAC1 */
22560fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
22570fb67e98SDaniel Drake 
22580fb67e98SDaniel Drake 	/* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
22590fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
22600fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
22610fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
22620fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
22630fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
22640fb67e98SDaniel Drake 
22650fb67e98SDaniel Drake 	/* no digital microphone support yet */
22660fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
22670fb67e98SDaniel Drake 
22680fb67e98SDaniel Drake 	/* Audio input selector */
22690fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
22700fb67e98SDaniel Drake 
22710fb67e98SDaniel Drake 	/* SPDIF route: PCM */
22720fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
22730fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
22740fb67e98SDaniel Drake 
22750fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
22760fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
22770fb67e98SDaniel Drake 
22780fb67e98SDaniel Drake 	/* EAPD */
22790fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
22800fb67e98SDaniel Drake 
22810fb67e98SDaniel Drake 	/* not handling these yet */
22820fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22830fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22840fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22850fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22860fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22870fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22880fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22890fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
22900fb67e98SDaniel Drake 	{ } /* end */
22910fb67e98SDaniel Drake };
22920fb67e98SDaniel Drake 
22930fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_olpc[] = {
22940fb67e98SDaniel Drake 	/* Port A: headphones */
22950fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
22960fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
22970fb67e98SDaniel Drake 
22980fb67e98SDaniel Drake 	/* Port B: external microphone */
2299dbaccc0cSDaniel Drake 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, CXT5066_OLPC_EXT_MIC_BIAS},
23000fb67e98SDaniel Drake 
23010fb67e98SDaniel Drake 	/* Port C: internal microphone */
23020fb67e98SDaniel Drake 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
23030fb67e98SDaniel Drake 
23040fb67e98SDaniel Drake 	/* Port D: unused */
23050fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23060fb67e98SDaniel Drake 
23070fb67e98SDaniel Drake 	/* Port E: unused, but has primary EAPD */
23080fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23090fb67e98SDaniel Drake 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
23100fb67e98SDaniel Drake 
23110fb67e98SDaniel Drake 	/* Port F: unused */
23120fb67e98SDaniel Drake 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23130fb67e98SDaniel Drake 
23140fb67e98SDaniel Drake 	/* Port G: internal speakers */
23150fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
23160fb67e98SDaniel Drake 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
23170fb67e98SDaniel Drake 
23180fb67e98SDaniel Drake 	/* DAC1 */
23190fb67e98SDaniel Drake 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
23200fb67e98SDaniel Drake 
23210fb67e98SDaniel Drake 	/* DAC2: unused */
23220fb67e98SDaniel Drake 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
23230fb67e98SDaniel Drake 
23240fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
23250fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
23260fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
23270fb67e98SDaniel Drake 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
23280fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
23290fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
23300fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
23310fb67e98SDaniel Drake 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
23320fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
23330fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
23340fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
23350fb67e98SDaniel Drake 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
23360fb67e98SDaniel Drake 
23370fb67e98SDaniel Drake 	/* Disable digital microphone port */
23380fb67e98SDaniel Drake 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23390fb67e98SDaniel Drake 
23400fb67e98SDaniel Drake 	/* Audio input selectors */
23410fb67e98SDaniel Drake 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
23420fb67e98SDaniel Drake 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
23430fb67e98SDaniel Drake 
23440fb67e98SDaniel Drake 	/* Disable SPDIF */
23450fb67e98SDaniel Drake 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23460fb67e98SDaniel Drake 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
23470fb67e98SDaniel Drake 
23480fb67e98SDaniel Drake 	/* enable unsolicited events for Port A and B */
23490fb67e98SDaniel Drake 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
23500fb67e98SDaniel Drake 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
23510fb67e98SDaniel Drake 	{ } /* end */
23520fb67e98SDaniel Drake };
23530fb67e98SDaniel Drake 
235495a618bdSEinar Rünkaru static struct hda_verb cxt5066_init_verbs_vostro[] = {
235595a618bdSEinar Rünkaru 	/* Port A: headphones */
235695a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
235795a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
235895a618bdSEinar Rünkaru 
235995a618bdSEinar Rünkaru 	/* Port B: external microphone */
236095a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
236195a618bdSEinar Rünkaru 
236295a618bdSEinar Rünkaru 	/* Port C: unused */
236395a618bdSEinar Rünkaru 	{0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
236495a618bdSEinar Rünkaru 
236595a618bdSEinar Rünkaru 	/* Port D: unused */
236695a618bdSEinar Rünkaru 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
236795a618bdSEinar Rünkaru 
236895a618bdSEinar Rünkaru 	/* Port E: unused, but has primary EAPD */
236995a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237095a618bdSEinar Rünkaru 	{0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
237195a618bdSEinar Rünkaru 
237295a618bdSEinar Rünkaru 	/* Port F: unused */
237395a618bdSEinar Rünkaru 	{0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
237495a618bdSEinar Rünkaru 
237595a618bdSEinar Rünkaru 	/* Port G: internal speakers */
237695a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
237795a618bdSEinar Rünkaru 	{0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
237895a618bdSEinar Rünkaru 
237995a618bdSEinar Rünkaru 	/* DAC1 */
238095a618bdSEinar Rünkaru 	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
238195a618bdSEinar Rünkaru 
238295a618bdSEinar Rünkaru 	/* DAC2: unused */
238395a618bdSEinar Rünkaru 	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
238495a618bdSEinar Rünkaru 
238595a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
238695a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
238795a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
238895a618bdSEinar Rünkaru 	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
238995a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
239095a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
239195a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
239295a618bdSEinar Rünkaru 	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
239395a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
239495a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
239595a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
239695a618bdSEinar Rünkaru 	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
239795a618bdSEinar Rünkaru 
239895a618bdSEinar Rünkaru 	/* Digital microphone port */
239995a618bdSEinar Rünkaru 	{0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
240095a618bdSEinar Rünkaru 
240195a618bdSEinar Rünkaru 	/* Audio input selectors */
240295a618bdSEinar Rünkaru 	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
240395a618bdSEinar Rünkaru 	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
240495a618bdSEinar Rünkaru 
240595a618bdSEinar Rünkaru 	/* Disable SPDIF */
240695a618bdSEinar Rünkaru 	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
240795a618bdSEinar Rünkaru 	{0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
240895a618bdSEinar Rünkaru 
240995a618bdSEinar Rünkaru 	/* enable unsolicited events for Port A and B */
241095a618bdSEinar Rünkaru 	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
241195a618bdSEinar Rünkaru 	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
241295a618bdSEinar Rünkaru 	{ } /* end */
241395a618bdSEinar Rünkaru };
241495a618bdSEinar Rünkaru 
24150fb67e98SDaniel Drake static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
24160fb67e98SDaniel Drake 	{0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
24170fb67e98SDaniel Drake 	{ } /* end */
24180fb67e98SDaniel Drake };
24190fb67e98SDaniel Drake 
24200fb67e98SDaniel Drake /* initialize jack-sensing, too */
24210fb67e98SDaniel Drake static int cxt5066_init(struct hda_codec *codec)
24220fb67e98SDaniel Drake {
2423254bba6aSEinar Rünkaru 	struct conexant_spec *spec = codec->spec;
2424254bba6aSEinar Rünkaru 
24250fb67e98SDaniel Drake 	snd_printdd("CXT5066: init\n");
24260fb67e98SDaniel Drake 	conexant_init(codec);
24270fb67e98SDaniel Drake 	if (codec->patch_ops.unsol_event) {
24280fb67e98SDaniel Drake 		cxt5066_hp_automute(codec);
2429254bba6aSEinar Rünkaru 		if (spec->dell_vostro)
2430254bba6aSEinar Rünkaru 			cxt5066_vostro_automic(codec);
2431254bba6aSEinar Rünkaru 		else
24320fb67e98SDaniel Drake 			cxt5066_automic(codec);
24330fb67e98SDaniel Drake 	}
24340fb67e98SDaniel Drake 	return 0;
24350fb67e98SDaniel Drake }
24360fb67e98SDaniel Drake 
24370fb67e98SDaniel Drake enum {
24380fb67e98SDaniel Drake 	CXT5066_LAPTOP,			/* Laptops w/ EAPD support */
24390fb67e98SDaniel Drake 	CXT5066_DELL_LAPTOP,	/* Dell Laptop */
24400fb67e98SDaniel Drake 	CXT5066_OLPC_XO_1_5,	/* OLPC XO 1.5 */
244195a618bdSEinar Rünkaru 	CXT5066_DELL_VOSTO,	/* Dell Vostro 1015i */
24420fb67e98SDaniel Drake 	CXT5066_MODELS
24430fb67e98SDaniel Drake };
24440fb67e98SDaniel Drake 
24450fb67e98SDaniel Drake static const char *cxt5066_models[CXT5066_MODELS] = {
24460fb67e98SDaniel Drake 	[CXT5066_LAPTOP]		= "laptop",
24470fb67e98SDaniel Drake 	[CXT5066_DELL_LAPTOP]	= "dell-laptop",
24480fb67e98SDaniel Drake 	[CXT5066_OLPC_XO_1_5]	= "olpc-xo-1_5",
244995a618bdSEinar Rünkaru 	[CXT5066_DELL_VOSTO]    = "dell-vostro"
24500fb67e98SDaniel Drake };
24510fb67e98SDaniel Drake 
24520fb67e98SDaniel Drake static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
24530fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
24540fb67e98SDaniel Drake 		      CXT5066_LAPTOP),
24550fb67e98SDaniel Drake 	SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
24560fb67e98SDaniel Drake 		      CXT5066_DELL_LAPTOP),
2457798a8a15SDaniel Drake 	SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
245895a618bdSEinar Rünkaru 	SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
24590fb67e98SDaniel Drake 	{}
24600fb67e98SDaniel Drake };
24610fb67e98SDaniel Drake 
24620fb67e98SDaniel Drake static int patch_cxt5066(struct hda_codec *codec)
24630fb67e98SDaniel Drake {
24640fb67e98SDaniel Drake 	struct conexant_spec *spec;
24650fb67e98SDaniel Drake 	int board_config;
24660fb67e98SDaniel Drake 
24670fb67e98SDaniel Drake 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
24680fb67e98SDaniel Drake 	if (!spec)
24690fb67e98SDaniel Drake 		return -ENOMEM;
24700fb67e98SDaniel Drake 	codec->spec = spec;
24710fb67e98SDaniel Drake 
24720fb67e98SDaniel Drake 	codec->patch_ops = conexant_patch_ops;
24730fb67e98SDaniel Drake 	codec->patch_ops.init = cxt5066_init;
24740fb67e98SDaniel Drake 
24750fb67e98SDaniel Drake 	spec->dell_automute = 0;
24760fb67e98SDaniel Drake 	spec->multiout.max_channels = 2;
24770fb67e98SDaniel Drake 	spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
24780fb67e98SDaniel Drake 	spec->multiout.dac_nids = cxt5066_dac_nids;
24790fb67e98SDaniel Drake 	spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
24800fb67e98SDaniel Drake 	spec->num_adc_nids = 1;
24810fb67e98SDaniel Drake 	spec->adc_nids = cxt5066_adc_nids;
24820fb67e98SDaniel Drake 	spec->capsrc_nids = cxt5066_capsrc_nids;
24830fb67e98SDaniel Drake 	spec->input_mux = &cxt5066_capture_source;
24840fb67e98SDaniel Drake 
24850fb67e98SDaniel Drake 	spec->port_d_mode = PIN_HP;
2486dbaccc0cSDaniel Drake 	spec->ext_mic_bias = PIN_VREF80;
24870fb67e98SDaniel Drake 
24880fb67e98SDaniel Drake 	spec->num_init_verbs = 1;
24890fb67e98SDaniel Drake 	spec->init_verbs[0] = cxt5066_init_verbs;
24900fb67e98SDaniel Drake 	spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
24910fb67e98SDaniel Drake 	spec->channel_mode = cxt5066_modes;
24920fb67e98SDaniel Drake 	spec->cur_adc = 0;
24930fb67e98SDaniel Drake 	spec->cur_adc_idx = 0;
24940fb67e98SDaniel Drake 
24950fb67e98SDaniel Drake 	board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
24960fb67e98SDaniel Drake 						  cxt5066_models, cxt5066_cfg_tbl);
24970fb67e98SDaniel Drake 	switch (board_config) {
24980fb67e98SDaniel Drake 	default:
24990fb67e98SDaniel Drake 	case CXT5066_LAPTOP:
25000fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
25010fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
25020fb67e98SDaniel Drake 		break;
25030fb67e98SDaniel Drake 	case CXT5066_DELL_LAPTOP:
25040fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
25050fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
25060fb67e98SDaniel Drake 
25070fb67e98SDaniel Drake 		spec->port_d_mode = PIN_OUT;
25080fb67e98SDaniel Drake 		spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
25090fb67e98SDaniel Drake 		spec->num_init_verbs++;
25100fb67e98SDaniel Drake 		spec->dell_automute = 1;
25110fb67e98SDaniel Drake 		break;
25120fb67e98SDaniel Drake 	case CXT5066_OLPC_XO_1_5:
25130fb67e98SDaniel Drake 		codec->patch_ops.unsol_event = cxt5066_unsol_event;
25140fb67e98SDaniel Drake 		spec->init_verbs[0] = cxt5066_init_verbs_olpc;
25150fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
25160fb67e98SDaniel Drake 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
25170fb67e98SDaniel Drake 		spec->port_d_mode = 0;
2518dbaccc0cSDaniel Drake 		spec->ext_mic_bias = CXT5066_OLPC_EXT_MIC_BIAS;
25190fb67e98SDaniel Drake 
25200fb67e98SDaniel Drake 		/* no S/PDIF out */
25210fb67e98SDaniel Drake 		spec->multiout.dig_out_nid = 0;
25220fb67e98SDaniel Drake 
25230fb67e98SDaniel Drake 		/* input source automatically selected */
25240fb67e98SDaniel Drake 		spec->input_mux = NULL;
25250fb67e98SDaniel Drake 		break;
252695a618bdSEinar Rünkaru 	case CXT5066_DELL_VOSTO:
252795a618bdSEinar Rünkaru 		codec->patch_ops.unsol_event = cxt5066_vostro_event;
252895a618bdSEinar Rünkaru 		spec->init_verbs[0] = cxt5066_init_verbs_vostro;
252995a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
253095a618bdSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_mixers;
2531254bba6aSEinar Rünkaru 		spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
253295a618bdSEinar Rünkaru 		spec->port_d_mode = 0;
2533254bba6aSEinar Rünkaru 		spec->dell_vostro = 1;
2534*c0f8faf0SEinar Rünkaru 		snd_hda_attach_beep_device(codec, 0x13);
253595a618bdSEinar Rünkaru 
253695a618bdSEinar Rünkaru 		/* no S/PDIF out */
253795a618bdSEinar Rünkaru 		spec->multiout.dig_out_nid = 0;
253895a618bdSEinar Rünkaru 
253995a618bdSEinar Rünkaru 		/* input source automatically selected */
254095a618bdSEinar Rünkaru 		spec->input_mux = NULL;
254195a618bdSEinar Rünkaru 		break;
25420fb67e98SDaniel Drake 	}
25430fb67e98SDaniel Drake 
25440fb67e98SDaniel Drake 	return 0;
25450fb67e98SDaniel Drake }
2546461e2c78STakashi Iwai 
2547461e2c78STakashi Iwai /*
2548461e2c78STakashi Iwai  */
2549461e2c78STakashi Iwai 
25501289e9e8STakashi Iwai static struct hda_codec_preset snd_hda_preset_conexant[] = {
255182f30040STobin Davis 	{ .id = 0x14f15045, .name = "CX20549 (Venice)",
255282f30040STobin Davis 	  .patch = patch_cxt5045 },
255382f30040STobin Davis 	{ .id = 0x14f15047, .name = "CX20551 (Waikiki)",
255482f30040STobin Davis 	  .patch = patch_cxt5047 },
2555461e2c78STakashi Iwai 	{ .id = 0x14f15051, .name = "CX20561 (Hermosa)",
2556461e2c78STakashi Iwai 	  .patch = patch_cxt5051 },
25570fb67e98SDaniel Drake 	{ .id = 0x14f15066, .name = "CX20582 (Pebble)",
25580fb67e98SDaniel Drake 	  .patch = patch_cxt5066 },
255995a618bdSEinar Rünkaru 	{ .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
256095a618bdSEinar Rünkaru 	  .patch = patch_cxt5066 },
2561c9b443d4STobin Davis 	{} /* terminator */
2562c9b443d4STobin Davis };
25631289e9e8STakashi Iwai 
25641289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15045");
25651289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15047");
25661289e9e8STakashi Iwai MODULE_ALIAS("snd-hda-codec-id:14f15051");
25670fb67e98SDaniel Drake MODULE_ALIAS("snd-hda-codec-id:14f15066");
256895a618bdSEinar Rünkaru MODULE_ALIAS("snd-hda-codec-id:14f15067");
25691289e9e8STakashi Iwai 
25701289e9e8STakashi Iwai MODULE_LICENSE("GPL");
25711289e9e8STakashi Iwai MODULE_DESCRIPTION("Conexant HD-audio codec");
25721289e9e8STakashi Iwai 
25731289e9e8STakashi Iwai static struct hda_codec_preset_list conexant_list = {
25741289e9e8STakashi Iwai 	.preset = snd_hda_preset_conexant,
25751289e9e8STakashi Iwai 	.owner = THIS_MODULE,
25761289e9e8STakashi Iwai };
25771289e9e8STakashi Iwai 
25781289e9e8STakashi Iwai static int __init patch_conexant_init(void)
25791289e9e8STakashi Iwai {
25801289e9e8STakashi Iwai 	return snd_hda_add_codec_preset(&conexant_list);
25811289e9e8STakashi Iwai }
25821289e9e8STakashi Iwai 
25831289e9e8STakashi Iwai static void __exit patch_conexant_exit(void)
25841289e9e8STakashi Iwai {
25851289e9e8STakashi Iwai 	snd_hda_delete_codec_preset(&conexant_list);
25861289e9e8STakashi Iwai }
25871289e9e8STakashi Iwai 
25881289e9e8STakashi Iwai module_init(patch_conexant_init)
25891289e9e8STakashi Iwai module_exit(patch_conexant_exit)
2590